coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
northcluster.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpi.h>
4 #include <acpi/acpigen.h>
5 #include <cbmem.h>
6 #include <cpu/x86/smm.h>
7 #include <device/device.h>
8 #include <device/pci.h>
9 #include <device/pci_ids.h>
10 #include <cpu/x86/lapic_def.h>
11 #include <fsp/util.h>
12 #include <soc/iomap.h>
13 #include <soc/iosf.h>
14 #include <soc/pci_devs.h>
15 #include <soc/ramstage.h>
16 #include <stddef.h>
17 
18 /*
19  * Host Memory Map:
20  *
21  * +--------------------------+ BMBOUND_HI
22  * | Usable DRAM |
23  * +--------------------------+ 4GiB
24  * | PCI Address Space |
25  * +--------------------------+ BMBOUND
26  * | TPM |
27  * +--------------------------+ IMR2
28  * | TXE |
29  * +--------------------------+ IMR1
30  * | iGD |
31  * +--------------------------+
32  * | GTT |
33  * +--------------------------+ SMMRRH, IRM0
34  * | TSEG |
35  * +--------------------------+ SMMRRL
36  * | Usable DRAM |
37  * +--------------------------+ 0
38  *
39  * Note that there are really only a few regions that need to enumerated w.r.t.
40  * coreboot's resource model:
41  *
42  * +--------------------------+ BMBOUND_HI
43  * | Cacheable/Usable |
44  * +--------------------------+ 4GiB
45  *
46  * +--------------------------+ BMBOUND
47  * | Uncacheable/Reserved |
48  * +--------------------------+ SMMRRH
49  * | Cacheable/Reserved |
50  * +--------------------------+ SMMRRL
51  * | Cacheable/Usable |
52  * +--------------------------+ 0
53  */
54 #define RES_IN_KiB(r) ((r) >> 10)
55 
57 {
58  static uint32_t tolm;
59 
60  if (tolm)
61  return tolm;
62 
63  tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
64 
65  return tolm;
66 }
67 
68 static void nc_read_resources(struct device *dev)
69 {
70  unsigned long mmconf;
71  unsigned long bmbound_k;
72  unsigned long bmbound_hi;
73  uintptr_t smm_base;
74  size_t smm_size;
75  unsigned long tseg_base_k;
76  unsigned long tseg_top_k;
77  unsigned long fsp_res_base_k;
78  unsigned long base_k, size_k;
79  const unsigned long four_gig_kib = (4 << (30 - 10));
80  void *fsp_reserved_memory_area;
81  int index = 0;
82 
83  /* Read standard PCI resources. */
85 
86  /* Determine TSEG data */
87  smm_region(&smm_base, &smm_size);
88  tseg_base_k = RES_IN_KiB(smm_base);
89  tseg_top_k = tseg_base_k + RES_IN_KiB(smm_size);
90 
91  /* Determine the base of the FSP reserved memory */
92  fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
93  if (fsp_reserved_memory_area) {
94  fsp_res_base_k = RES_IN_KiB((unsigned int)fsp_reserved_memory_area);
95  } else {
96  /* If no FSP reserved area */
97  fsp_res_base_k = tseg_base_k;
98  }
99 
100  /* PCIe memory-mapped config space access - 256 MiB. */
101  mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
102  mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024);
103 
104  /* 0 -> 0xa0000 */
105  base_k = RES_IN_KiB(0);
106  size_k = RES_IN_KiB(0xa0000) - base_k;
107  ram_resource(dev, index++, base_k, size_k);
108 
109  /* High memory -> fsp_res_base - cacheable and usable */
110  base_k = RES_IN_KiB(0x100000);
111  size_k = fsp_res_base_k - base_k;
112  ram_resource(dev, index++, base_k, size_k);
113 
114  /* fsp_res_base -> tseg_top - Reserved */
115  base_k = fsp_res_base_k;
116  size_k = tseg_top_k - base_k;
117  reserved_ram_resource(dev, index++, base_k, size_k);
118 
119  /* TSEG TOP -> bmbound is memory backed mmio. */
120  bmbound_k = RES_IN_KiB(nc_read_top_of_low_memory());
121  mmio_resource(dev, index++, tseg_top_k, bmbound_k - tseg_top_k);
122 
123  /*
124  * The BMBOUND_HI register matches register bits of 31:24 with address
125  * bits of 35:28. Therefore, shift register to align properly.
126  */
127  bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
128  bmbound_hi = RES_IN_KiB(bmbound_hi) << 4;
129  if (bmbound_hi > four_gig_kib)
130  ram_resource(dev, index++, four_gig_kib, bmbound_hi - four_gig_kib);
131 
132  /*
133  * Reserve everything between A segment and 1MB:
134  *
135  * 0xa0000 - 0xbffff: legacy VGA
136  * 0xc0000 - 0xfffff: RAM
137  */
138  mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
139  reserved_ram_resource(dev, index++, (0xc0000 >> 10), (0x100000 - 0xc0000) >> 10);
140 
141  /*
142  * Reserve local APIC
143  */
144  base_k = RES_IN_KiB(LAPIC_DEFAULT_BASE);
145  size_k = RES_IN_KiB(0x00100000);
146  mmio_resource(dev, index++, base_k, size_k);
147 }
148 
149 static void nc_generate_ssdt(const struct device *dev)
150 {
152 
153  acpigen_write_scope("\\");
155  acpigen_pop_len();
156 }
157 
158 static struct device_operations nc_ops = {
160  .acpi_fill_ssdt = nc_generate_ssdt,
161  .ops_pci = &soc_pci_ops,
162 };
163 
164 static const struct pci_driver nc_driver __pci_driver = {
165  .ops = &nc_ops,
166  .vendor = PCI_VID_INTEL,
167  .device = SOC_DEVID,
168 };
void acpigen_pop_len(void)
Definition: acpigen.c:37
void acpigen_write_scope(const char *name)
Definition: acpigen.c:326
void acpigen_write_name_dword(const char *name, uint32_t val)
Definition: acpigen.c:158
uint32_t iosf_bunit_read(int reg)
Definition: iosf.c:39
#define BUNIT_BMBOUND
Definition: iosf.h:178
#define BUNIT_MMCONF_REG
Definition: iosf.h:185
#define BUNIT_BMBOUND_HI
Definition: iosf.h:184
uint32_t nc_read_top_of_low_memory(void)
Definition: northcluster.c:52
#define RES_IN_KiB(r)
Definition: northcluster.c:54
static const struct pci_driver nc_driver __pci_driver
Definition: northcluster.c:164
static struct device_operations nc_ops
Definition: northcluster.c:158
static void nc_read_resources(struct device *dev)
Definition: northcluster.c:68
static void nc_generate_ssdt(const struct device *dev)
Definition: northcluster.c:149
void * cbmem_find(u32 id)
Definition: imd_cbmem.c:166
#define CBMEM_ID_FSP_RESERVED_MEMORY
Definition: cbmem_id.h:25
void generate_cpu_entries(const struct device *device)
Definition: acpi.c:334
void smm_region(uintptr_t *start, size_t *size)
Definition: memmap.c:50
#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
#define LAPIC_DEFAULT_BASE
Definition: lapic_def.h:12
void pci_dev_read_resources(struct device *dev)
Definition: pci_device.c:534
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
struct pci_operations soc_pci_ops
Definition: chip.c:51
#define SOC_DEVID
Definition: pci_devs.h:108
unsigned int uint32_t
Definition: stdint.h:14
unsigned long uintptr_t
Definition: stdint.h:21
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107