coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
northbridge.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <arch/hpet.h>
4 #include <cbmem.h>
5 #include <console/console.h>
7 #include <device/pci_def.h>
8 #include <device/pci_ops.h>
9 #include <stdint.h>
10 #include <device/device.h>
11 #include <boot/tables.h>
12 #include <acpi/acpi.h>
14 #include <cpu/intel/smm_reloc.h>
15 
16 /*
17  * Reserve everything between A segment and 1MB:
18  *
19  * 0xa0000 - 0xbffff: legacy VGA
20  * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
21  * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
22  */
23 static const int legacy_hole_base_k = 0xa0000 / KiB;
24 
25 static void add_fixed_resources(struct device *dev, int index)
26 {
27  struct resource *resource;
28 
29  resource = new_resource(dev, index++);
31  resource->size = (resource_t) 0x00100000;
37 
39  reserved_ram_resource(dev, index++, 0xc0000 / KiB, (0x100000 - 0xc0000) / KiB);
40 }
41 
42 static void mch_domain_read_resources(struct device *dev)
43 {
44  u64 tom, touud;
45  u32 tomk, tolud, tseg_sizek;
46  u32 cbmem_topk, delta_cbmem;
47  u16 index;
48  const u32 top32memk = 4 * (GiB / KiB);
49 
50  struct device *mch = pcidev_on_root(0, 0);
51 
52  index = 3;
53 
55 
56  /* Top of Upper Usable DRAM, including remap */
57  touud = pci_read_config16(mch, TOUUD);
58  touud <<= 20;
59 
60  /* Top of Lower Usable DRAM */
61  tolud = pci_read_config16(mch, TOLUD) & 0xfff0;
62  tolud <<= 16;
63 
64  /* Top of Memory - does not account for any UMA */
65  tom = pci_read_config16(mch, TOM) & 0x01ff;
66  tom <<= 27;
67 
68  printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx ", touud, tolud, tom);
69 
70  tomk = tolud / KiB;
71 
72  /* Graphics memory */
73  const u16 ggc = pci_read_config16(mch, GGC);
74  const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf);
75  printk(BIOS_DEBUG, "%uM UMA", gms_sizek / KiB);
76  tomk -= gms_sizek;
77 
78  /* GTT Graphics Stolen Memory Size (GGMS) */
79  const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf);
80  printk(BIOS_DEBUG, " and %uM GTT\n", gsm_sizek / KiB);
81  tomk -= gsm_sizek;
82 
83  const u32 tseg_basek = pci_read_config32(mch, TSEG) / KiB;
84  const u32 igd_basek = pci_read_config32(mch, GBSM) / KiB;
85  const u32 gtt_basek = pci_read_config32(mch, BGSM) / KiB;
86 
87  /* Subtract TSEG size */
88  tseg_sizek = gtt_basek - tseg_basek;
89  tomk -= tseg_sizek;
90  printk(BIOS_DEBUG, "TSEG decoded, subtracting %dM\n", tseg_sizek / KiB);
91 
92  /* cbmem_top can be shifted downwards due to alignment.
93  Mark the region between cbmem_top and tomk as unusable */
94  cbmem_topk = (uint32_t)cbmem_top() / KiB;
95  delta_cbmem = tomk - cbmem_topk;
96  tomk -= delta_cbmem;
97 
98  printk(BIOS_DEBUG, "Unused RAM between cbmem_top and TOMK: 0x%xK\n", delta_cbmem);
99 
100  /* Report the memory regions */
101  ram_resource(dev, index++, 0, 0xa0000 / KiB);
102  ram_resource(dev, index++, 1 * MiB / KiB, tomk - 1 * MiB / KiB);
103  mmio_resource(dev, index++, tseg_basek, tseg_sizek);
104  mmio_resource(dev, index++, gtt_basek, gsm_sizek);
105  mmio_resource(dev, index++, igd_basek, gms_sizek);
106  reserved_ram_resource(dev, index++, cbmem_topk, delta_cbmem);
107 
108  /*
109  * If > 4GB installed then memory from TOLUD to 4GB
110  * is remapped above TOM, TOUUD will account for both
111  */
112  touud >>= 10; /* Convert to KB */
113  if (touud > top32memk) {
114  ram_resource(dev, index++, top32memk, touud - top32memk);
115  printk(BIOS_INFO, "Available memory above 4GB: %lluM\n",
116  (touud - top32memk) / KiB);
117  }
118 
119  mmconf_resource(dev, index++);
120 
121  add_fixed_resources(dev, index);
122 }
123 
125 {
126  struct device *dev = pcidev_on_root(0, 0);
127 
128  if (dev == NULL)
129  die("could not find pci 00:00.0!\n");
130 
131  pci_write_config8(dev, SMRAM, smram);
132 }
133 
134 static void mch_domain_set_resources(struct device *dev)
135 {
136  struct resource *res;
137 
138  for (res = dev->resource_list; res; res = res->next)
139  report_resource_stored(dev, res, "");
140 
142 }
143 
144 static void mch_domain_init(struct device *dev)
145 {
146  /* Enable SERR */
148 }
149 
150 static const char *northbridge_acpi_name(const struct device *dev)
151 {
152  if (dev->path.type == DEVICE_PATH_DOMAIN)
153  return "PCI0";
154 
155  if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
156  return NULL;
157 
158  switch (dev->path.pci.devfn) {
159  case PCI_DEVFN(0, 0):
160  return "MCHC";
161  }
162 
163  return NULL;
164 }
165 
166 static struct device_operations pci_domain_ops = {
168  .set_resources = mch_domain_set_resources,
169  .init = mch_domain_init,
170  .scan_bus = pci_domain_scan_bus,
171  .acpi_fill_ssdt = generate_cpu_entries,
172  .acpi_name = northbridge_acpi_name,
173 };
174 
175 static struct device_operations cpu_bus_ops = {
177  .set_resources = noop_set_resources,
178  .init = mp_cpu_bus_init,
179 };
180 
181 static void enable_dev(struct device *dev)
182 {
183  /* Set the operations if it is a special bus type */
184  if (dev->path.type == DEVICE_PATH_DOMAIN) {
185  dev->ops = &pci_domain_ops;
186  } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
187  dev->ops = &cpu_bus_ops;
188  }
189 }
190 
192  CHIP_NAME("Intel Pineview Northbridge")
193  .enable_dev = enable_dev,
194 };
#define HPET_BASE_ADDRESS
Definition: hpet.h:6
#define MiB
Definition: helpers.h:76
#define KiB
Definition: helpers.h:75
#define GiB
Definition: helpers.h:77
void * cbmem_top(void)
Definition: imd_cbmem.c:18
#define printk(level,...)
Definition: stdlib.h:16
void __noreturn die(const char *fmt,...)
Definition: die.c:17
void generate_cpu_entries(const struct device *device)
Definition: acpi.c:334
void assign_resources(struct bus *bus)
Assign the computed resources to the devices on the bus.
Definition: device.c:268
DEVTREE_CONST struct device * pcidev_on_root(uint8_t dev, uint8_t fn)
Definition: device_const.c:260
struct resource * new_resource(struct device *dev, unsigned int index)
See if a resource structure already exists for a given index and if not allocate one.
Definition: device_util.c:346
void mmconf_resource(struct device *dev, unsigned long index)
Definition: device_util.c:857
void report_resource_stored(struct device *dev, const struct resource *resource, const char *comment)
Print the resource that was just stored.
Definition: device_util.c:508
u32 decode_igd_memory_size(u32 gms)
Decodes used Graphics Mode Select (GMS) to kilobytes.
Definition: memmap.c:24
u32 decode_igd_gtt_size(u32 gsm)
Decodes used Graphics Stolen Memory (GSM) to kilobytes.
Definition: memmap.c:36
#define GGC
Definition: host_bridge.h:9
#define TOLUD
Definition: host_bridge.h:61
#define SMRAM
Definition: host_bridge.h:47
#define TOUUD
Definition: host_bridge.h:57
#define TSEG
Definition: host_bridge.h:60
#define TOM
Definition: host_bridge.h:56
#define BGSM
Definition: host_bridge.h:59
#define GBSM
#define CHIP_NAME(X)
Definition: device.h:32
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
static void mp_cpu_bus_init(struct device *dev)
Definition: device.h:240
#define ram_resource(dev, idx, basek, sizek)
Definition: device.h:321
#define mmio_resource(dev, idx, basek, sizek)
Definition: device.h:334
#define reserved_ram_resource(dev, idx, basek, sizek)
Definition: device.h:324
static __always_inline void pci_or_config16(const struct device *dev, u16 reg, u16 ormask)
Definition: pci_ops.h:180
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val)
Definition: pci_ops.h:64
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
void northbridge_write_smram(u8 smram)
Definition: northbridge.c:169
static struct device_operations cpu_bus_ops
Definition: northbridge.c:175
static struct device_operations pci_domain_ops
Definition: northbridge.c:166
static void enable_dev(struct device *dev)
Definition: northbridge.c:181
static void mch_domain_set_resources(struct device *dev)
Definition: northbridge.c:134
static const int legacy_hole_base_k
Definition: northbridge.c:23
static void mch_domain_read_resources(struct device *dev)
Definition: northbridge.c:42
static void add_fixed_resources(struct device *dev, int index)
Definition: northbridge.c:25
struct chip_operations northbridge_intel_pineview_ops
Definition: northbridge.c:191
static void mch_domain_init(struct device *dev)
Definition: northbridge.c:144
static const char * northbridge_acpi_name(const struct device *dev)
Definition: northbridge.c:150
@ DEVICE_PATH_PCI
Definition: path.h:9
@ DEVICE_PATH_CPU_CLUSTER
Definition: path.h:14
@ DEVICE_PATH_DOMAIN
Definition: path.h:13
#define PCI_COMMAND_SERR
Definition: pci_def.h:19
#define PCI_DEVFN(slot, func)
Definition: pci_def.h:548
#define PCI_COMMAND
Definition: pci_def.h:10
void pci_domain_read_resources(struct device *dev)
Definition: pci_device.c:547
void pci_domain_scan_bus(struct device *dev)
Scan a PCI domain.
Definition: pci_device.c:1610
#define IORESOURCE_RESERVE
Definition: resource.h:30
#define IORESOURCE_MEM
Definition: resource.h:10
#define IORESOURCE_STORED
Definition: resource.h:32
#define IORESOURCE_ASSIGNED
Definition: resource.h:34
u64 resource_t
Definition: resource.h:43
#define IORESOURCE_FIXED
Definition: resource.h:36
#define NULL
Definition: stddef.h:19
uint64_t u64
Definition: stdint.h:54
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
uint16_t secondary
Definition: device.h:84
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct pci_path pci
Definition: path.h:116
enum device_path_type type
Definition: path.h:114
Definition: device.h:107
struct device_path path
Definition: device.h:115
struct device_operations * ops
Definition: device.h:143
DEVTREE_CONST struct bus * bus
Definition: device.h:108
DEVTREE_CONST struct bus * link_list
Definition: device.h:139
DEVTREE_CONST struct resource * resource_list
Definition: device.h:134
unsigned int devfn
Definition: path.h:54
unsigned long flags
Definition: resource.h:49
resource_t base
Definition: resource.h:45
unsigned long index
Definition: resource.h:50
resource_t size
Definition: resource.h:46
DEVTREE_CONST struct resource * next
Definition: resource.h:48