blob: 5b728e7313f924d76a800831006708abce498cb3 [file] [log] [blame]
Angel Ponsc3f58f62020-04-05 15:46:41 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin191570d2013-09-24 12:41:08 -05002
Kyösti Mälkkid06f8002021-01-27 20:25:51 +02003#include <acpi/acpi.h>
4#include <acpi/acpigen.h>
Aaron Durbin191570d2013-09-24 12:41:08 -05005#include <device/device.h>
6#include <device/pci.h>
7#include <device/pci_ids.h>
Elyes HAOUASeb7e1662020-07-10 10:49:26 +02008#include <stdint.h>
Julius Werner18ea2d32014-10-07 16:42:17 -07009#include <soc/iomap.h>
10#include <soc/iosf.h>
11#include <soc/pci_devs.h>
12#include <soc/ramstage.h>
Aaron Durbin191570d2013-09-24 12:41:08 -050013
Angel Pons26b49cc2020-07-07 17:17:51 +020014/*
15 * Host Memory Map:
Aaron Durbin191570d2013-09-24 12:41:08 -050016 *
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.
Martin Roth99a3bba2014-12-07 14:57:26 -070036 * coreboot's resource model:
Aaron Durbin191570d2013-09-24 12:41:08 -050037 *
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
Duncan Laurie1f52f512013-11-04 17:02:45 -080052uint32_t nc_read_top_of_low_memory(void)
53{
Kyösti Mälkkifcbbb912020-04-20 10:21:39 +030054 static uint32_t tolm;
Matt DeVillierf05d2e12017-06-06 23:56:18 -050055
56 if (tolm)
57 return tolm;
58
59 tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
60
61 return tolm;
Duncan Laurie1f52f512013-11-04 17:02:45 -080062}
63
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020064static void nc_read_resources(struct device *dev)
Aaron Durbin191570d2013-09-24 12:41:08 -050065{
66 unsigned long mmconf;
Angel Pons32b93c92020-07-26 22:36:49 +020067 unsigned long bmbound_k;
Aaron Durbin191570d2013-09-24 12:41:08 -050068 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. */
76 pci_dev_read_resources(dev);
77
78 /* PCIe memory-mapped config space access - 256 MiB. */
79 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
Kyösti Mälkki27d62992022-05-24 20:25:58 +030080 mmio_resource_kb(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024);
Aaron Durbin191570d2013-09-24 12:41:08 -050081
Kein Yuan35110232014-02-22 12:26:55 -080082 /* 0 -> 0xa0000 */
83 base_k = RES_IN_KiB(0);
Aaron Durbin191570d2013-09-24 12:41:08 -050084 size_k = RES_IN_KiB(0xa0000) - base_k;
Kyösti Mälkki27d62992022-05-24 20:25:58 +030085 ram_resource_kb(dev, index++, base_k, size_k);
Aaron Durbin191570d2013-09-24 12:41:08 -050086
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;
Kyösti Mälkki27d62992022-05-24 20:25:58 +030095 ram_resource_kb(dev, index++, base_k, size_k);
Aaron Durbin191570d2013-09-24 12:41:08 -050096
97 if (smmrrh > smmrrl)
Kyösti Mälkki27d62992022-05-24 20:25:58 +030098 reserved_ram_resource_kb(dev, index++, smmrrl, smmrrh - smmrrl);
Aaron Durbin191570d2013-09-24 12:41:08 -050099
100 /* All address space between bmbound and smmrrh is unusable. */
Angel Pons32b93c92020-07-26 22:36:49 +0200101 bmbound_k = RES_IN_KiB(nc_read_top_of_low_memory());
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300102 mmio_resource_kb(dev, index++, smmrrh, bmbound_k - smmrrh);
Aaron Durbin191570d2013-09-24 12:41:08 -0500103
Angel Ponsbdd3d5f2020-07-26 22:41:43 +0200104 /*
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 */
Aaron Durbin191570d2013-09-24 12:41:08 -0500108 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)
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300111 ram_resource_kb(dev, index++, four_gig_kib, bmbound_hi - four_gig_kib);
Duncan Lauriee7e78d62013-11-03 19:38:12 -0800112
Angel Ponsbdd3d5f2020-07-26 22:41:43 +0200113 /*
114 * Reserve everything between A segment and 1MB:
Duncan Lauriee7e78d62013-11-03 19:38:12 -0800115 *
116 * 0xa0000 - 0xbffff: legacy VGA
117 * 0xc0000 - 0xfffff: RAM
118 */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300119 mmio_resource_kb(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
120 reserved_ram_resource_kb(dev, index++, (0xc0000 >> 10), (0x100000 - 0xc0000) >> 10);
Aaron Durbin191570d2013-09-24 12:41:08 -0500121}
122
Kyösti Mälkkid06f8002021-01-27 20:25:51 +0200123static void nc_generate_ssdt(const struct device *dev)
124{
125 generate_cpu_entries(dev);
126
127 acpigen_write_scope("\\");
128 acpigen_write_name_dword("TOLM", nc_read_top_of_low_memory());
129 acpigen_pop_len();
130}
131
Aaron Durbin191570d2013-09-24 12:41:08 -0500132static struct device_operations nc_ops = {
133 .read_resources = nc_read_resources,
Kyösti Mälkkid06f8002021-01-27 20:25:51 +0200134 .acpi_fill_ssdt = nc_generate_ssdt,
Aaron Durbin191570d2013-09-24 12:41:08 -0500135 .ops_pci = &soc_pci_ops,
136};
137
138static const struct pci_driver nc_driver __pci_driver = {
139 .ops = &nc_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100140 .vendor = PCI_VID_INTEL,
Aaron Durbin191570d2013-09-24 12:41:08 -0500141 .device = SOC_DEVID,
142};