blob: 27562eae83ef323344290af2331f9609c9bda5a9 [file] [log] [blame]
Damien Zammit43a1f782015-08-19 15:16:59 +10001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 secunet Security Networks AG
5 * Copyright (C) 2015 Damien Zammit <damien@zamaudio.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#define __SIMPLE_DEVICE__
19
Damien Zammit5680faf2016-01-22 22:12:30 +110020#include <cbmem.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100021#include <commonlib/helpers.h>
22#include <stdint.h>
23#include <arch/io.h>
24#include <device/pci_def.h>
25#include <console/console.h>
26#include <northbridge/intel/x4x/x4x.h>
27
28/** Decodes used Graphics Mode Select (GMS) to kilobytes. */
29u32 decode_igd_memory_size(const u32 gms)
30{
31 static const u16 ggc2uma[] = { 0, 0, 0, 0, 0,
32 32, 48, 64, 128, 256, 96, 160, 224, 352 };
33
34 if (gms > ARRAY_SIZE(ggc2uma))
35 die("Bad Graphics Mode Select (GMS) setting.\n");
36
37 return ggc2uma[gms] << 10;
38}
39
40/** Decodes used GTT Graphics Memory Size (GGMS) to kilobytes. */
41u32 decode_igd_gtt_size(const u32 gsm)
42{
43 static const u8 ggc2gtt[] = { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4};
44
45 if (gsm > ARRAY_SIZE(ggc2gtt))
46 die("Bad GTT Graphics Memory Size (GGMS) setting.\n");
47
48 return ggc2gtt[gsm] << 10;
49}
50
51u8 decode_pciebar(u32 *const base, u32 *const len)
52{
53 *base = 0;
54 *len = 0;
55 const pci_devfn_t dev = PCI_DEV(0,0,0);
56 u32 pciexbar = 0;
57 u32 pciexbar_reg;
58 u32 reg32;
59 int max_buses;
60 const struct {
61 u16 num_buses;
62 u32 addr_mask;
63 } busmask[] = {
64 {256, 0xf0000000},
65 {128, 0xf8000000},
66 {64, 0xfc000000},
67 {0, 0},
68 };
69
70 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
71
72 if (!(pciexbar_reg & 1)) {
73 printk(BIOS_WARNING, "WARNING: MMCONF not set\n");
74 return 0;
75 }
76
77 reg32 = (pciexbar_reg >> 1) & 3;
78 pciexbar = pciexbar_reg & busmask[reg32].addr_mask;
79 max_buses = busmask[reg32].num_buses;
80
81 if (!pciexbar) {
82 printk(BIOS_WARNING, "WARNING: pciexbar invalid\n");
83 return 0;
84 }
85
86 *base = pciexbar;
87 *len = max_buses << 20;
88 return 1;
89}
Damien Zammit5680faf2016-01-22 22:12:30 +110090
91void *cbmem_top(void)
92{
93 u32 ramtop = pci_read_config32(PCI_DEV(0,0,0), D0F0_TSEG);
94 return (void*)(ramtop);
95}