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 <device/device.h>
6 #include <device/pci.h>
7 #include <device/pci_ids.h>
8 #include <stdint.h>
9 #include <soc/iomap.h>
10 #include <soc/iosf.h>
11 #include <soc/pci_devs.h>
12 #include <soc/ramstage.h>
13 
14 /*
15  * Host Memory Map:
16  *
17  * +--------------------------+ BMBOUND_HI
18  * | Usable DRAM |
19  * +--------------------------+ 4GiB
20  * | PCI Address Space |
21  * +--------------------------+ BMBOUND
22  * | TPM |
23  * +--------------------------+ IMR2
24  * | TXE |
25  * +--------------------------+ IMR1
26  * | iGD |
27  * +--------------------------+
28  * | GTT |
29  * +--------------------------+ SMMRRH, IRM0
30  * | TSEG |
31  * +--------------------------+ SMMRRL
32  * | Usable DRAM |
33  * +--------------------------+ 0
34  *
35  * Note that there are really only a few regions that need to enumerated w.r.t.
36  * coreboot's resource model:
37  *
38  * +--------------------------+ BMBOUND_HI
39  * | Cacheable/Usable |
40  * +--------------------------+ 4GiB
41  *
42  * +--------------------------+ BMBOUND
43  * | Uncacheable/Reserved |
44  * +--------------------------+ SMMRRH
45  * | Cacheable/Reserved |
46  * +--------------------------+ SMMRRL
47  * | Cacheable/Usable |
48  * +--------------------------+ 0
49  */
50 #define RES_IN_KiB(r) ((r) >> 10)
51 
53 {
54  static uint32_t tolm;
55 
56  if (tolm)
57  return tolm;
58 
59  tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
60 
61  return tolm;
62 }
63 
64 static void nc_read_resources(struct device *dev)
65 {
66  unsigned long mmconf;
67  unsigned long bmbound_k;
68  unsigned long bmbound_hi;
69  unsigned long smmrrh;
70  unsigned long smmrrl;
71  unsigned long base_k, size_k;
72  const unsigned long four_gig_kib = (4 << (30 - 10));
73  int index = 0;
74 
75  /* Read standard PCI resources. */
77 
78  /* PCIe memory-mapped config space access - 256 MiB. */
79  mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
80  mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024);
81 
82  /* 0 -> 0xa0000 */
83  base_k = RES_IN_KiB(0);
84  size_k = RES_IN_KiB(0xa0000) - base_k;
85  ram_resource(dev, index++, base_k, size_k);
86 
87  /* The SMMRR registers are 1MiB granularity with smmrrh being
88  * inclusive of the SMM region. */
89  smmrrl = (iosf_bunit_read(BUNIT_SMRRL) & 0xffff) << 10;
90  smmrrh = ((iosf_bunit_read(BUNIT_SMRRH) & 0xffff) + 1) << 10;
91 
92  /* 0xc0000 -> smrrl - cacheable and usable */
93  base_k = RES_IN_KiB(0xc0000);
94  size_k = smmrrl - base_k;
95  ram_resource(dev, index++, base_k, size_k);
96 
97  if (smmrrh > smmrrl)
98  reserved_ram_resource(dev, index++, smmrrl, smmrrh - smmrrl);
99 
100  /* All address space between bmbound and smmrrh is unusable. */
101  bmbound_k = RES_IN_KiB(nc_read_top_of_low_memory());
102  mmio_resource(dev, index++, smmrrh, bmbound_k - smmrrh);
103 
104  /*
105  * The BMBOUND_HI register matches register bits of 31:24 with address
106  * bits of 35:28. Therefore, shift register to align properly.
107  */
108  bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
109  bmbound_hi = RES_IN_KiB(bmbound_hi) << 4;
110  if (bmbound_hi > four_gig_kib)
111  ram_resource(dev, index++, four_gig_kib, bmbound_hi - four_gig_kib);
112 
113  /*
114  * Reserve everything between A segment and 1MB:
115  *
116  * 0xa0000 - 0xbffff: legacy VGA
117  * 0xc0000 - 0xfffff: RAM
118  */
119  mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
120  reserved_ram_resource(dev, index++, (0xc0000 >> 10), (0x100000 - 0xc0000) >> 10);
121 }
122 
123 static void nc_generate_ssdt(const struct device *dev)
124 {
126 
127  acpigen_write_scope("\\");
129  acpigen_pop_len();
130 }
131 
132 static struct device_operations nc_ops = {
134  .acpi_fill_ssdt = nc_generate_ssdt,
135  .ops_pci = &soc_pci_ops,
136 };
137 
138 static const struct pci_driver nc_driver __pci_driver = {
139  .ops = &nc_ops,
140  .vendor = PCI_VID_INTEL,
141  .device = SOC_DEVID,
142 };
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
#define BUNIT_SMRRL
Definition: iosf.h:190
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
#define BUNIT_SMRRH
Definition: iosf.h:191
#define RES_IN_KiB(r)
Definition: northcluster.c:50
static const struct pci_driver nc_driver __pci_driver
Definition: northcluster.c:138
uint32_t nc_read_top_of_low_memory(void)
Definition: northcluster.c:52
static struct device_operations nc_ops
Definition: northcluster.c:132
static void nc_read_resources(struct device *dev)
Definition: northcluster.c:64
static void nc_generate_ssdt(const struct device *dev)
Definition: northcluster.c:123
void generate_cpu_entries(const struct device *device)
Definition: acpi.c:334
#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
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
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107