blob: 310ce4d552496059795fc26a3c4ce186accf9471 [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>
Kyösti Mälkkid06f8002021-01-27 20:25:51 +020013#include <vendorcode/google/chromeos/chromeos.h>
Aaron Durbin191570d2013-09-24 12:41:08 -050014
Angel Pons26b49cc2020-07-07 17:17:51 +020015/*
16 * Host Memory Map:
Aaron Durbin191570d2013-09-24 12:41:08 -050017 *
18 * +--------------------------+ BMBOUND_HI
19 * | Usable DRAM |
20 * +--------------------------+ 4GiB
21 * | PCI Address Space |
22 * +--------------------------+ BMBOUND
23 * | TPM |
24 * +--------------------------+ IMR2
25 * | TXE |
26 * +--------------------------+ IMR1
27 * | iGD |
28 * +--------------------------+
29 * | GTT |
30 * +--------------------------+ SMMRRH, IRM0
31 * | TSEG |
32 * +--------------------------+ SMMRRL
33 * | Usable DRAM |
34 * +--------------------------+ 0
35 *
36 * Note that there are really only a few regions that need to enumerated w.r.t.
Martin Roth99a3bba2014-12-07 14:57:26 -070037 * coreboot's resource model:
Aaron Durbin191570d2013-09-24 12:41:08 -050038 *
39 * +--------------------------+ BMBOUND_HI
40 * | Cacheable/Usable |
41 * +--------------------------+ 4GiB
42 *
43 * +--------------------------+ BMBOUND
44 * | Uncacheable/Reserved |
45 * +--------------------------+ SMMRRH
46 * | Cacheable/Reserved |
47 * +--------------------------+ SMMRRL
48 * | Cacheable/Usable |
49 * +--------------------------+ 0
50 */
51#define RES_IN_KiB(r) ((r) >> 10)
52
Duncan Laurie1f52f512013-11-04 17:02:45 -080053uint32_t nc_read_top_of_low_memory(void)
54{
Kyösti Mälkkifcbbb912020-04-20 10:21:39 +030055 static uint32_t tolm;
Matt DeVillierf05d2e12017-06-06 23:56:18 -050056
57 if (tolm)
58 return tolm;
59
60 tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
61
62 return tolm;
Duncan Laurie1f52f512013-11-04 17:02:45 -080063}
64
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020065static void nc_read_resources(struct device *dev)
Aaron Durbin191570d2013-09-24 12:41:08 -050066{
67 unsigned long mmconf;
Angel Pons32b93c92020-07-26 22:36:49 +020068 unsigned long bmbound_k;
Aaron Durbin191570d2013-09-24 12:41:08 -050069 unsigned long bmbound_hi;
70 unsigned long smmrrh;
71 unsigned long smmrrl;
72 unsigned long base_k, size_k;
73 const unsigned long four_gig_kib = (4 << (30 - 10));
74 int index = 0;
75
76 /* Read standard PCI resources. */
77 pci_dev_read_resources(dev);
78
79 /* PCIe memory-mapped config space access - 256 MiB. */
80 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
81 mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024);
82
Kein Yuan35110232014-02-22 12:26:55 -080083 /* 0 -> 0xa0000 */
84 base_k = RES_IN_KiB(0);
Aaron Durbin191570d2013-09-24 12:41:08 -050085 size_k = RES_IN_KiB(0xa0000) - base_k;
86 ram_resource(dev, index++, base_k, size_k);
87
88 /* The SMMRR registers are 1MiB granularity with smmrrh being
89 * inclusive of the SMM region. */
90 smmrrl = (iosf_bunit_read(BUNIT_SMRRL) & 0xffff) << 10;
91 smmrrh = ((iosf_bunit_read(BUNIT_SMRRH) & 0xffff) + 1) << 10;
92
93 /* 0xc0000 -> smrrl - cacheable and usable */
94 base_k = RES_IN_KiB(0xc0000);
95 size_k = smmrrl - base_k;
96 ram_resource(dev, index++, base_k, size_k);
97
98 if (smmrrh > smmrrl)
99 reserved_ram_resource(dev, index++, smmrrl, smmrrh - smmrrl);
100
101 /* All address space between bmbound and smmrrh is unusable. */
Angel Pons32b93c92020-07-26 22:36:49 +0200102 bmbound_k = RES_IN_KiB(nc_read_top_of_low_memory());
103 mmio_resource(dev, index++, smmrrh, bmbound_k - smmrrh);
Aaron Durbin191570d2013-09-24 12:41:08 -0500104
Angel Ponsbdd3d5f2020-07-26 22:41:43 +0200105 /*
106 * The BMBOUND_HI register matches register bits of 31:24 with address
107 * bits of 35:28. Therefore, shift register to align properly.
108 */
Aaron Durbin191570d2013-09-24 12:41:08 -0500109 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
110 bmbound_hi = RES_IN_KiB(bmbound_hi) << 4;
111 if (bmbound_hi > four_gig_kib)
Angel Pons7bef2ee2020-07-26 22:35:12 +0200112 ram_resource(dev, index++, four_gig_kib, bmbound_hi - four_gig_kib);
Duncan Lauriee7e78d62013-11-03 19:38:12 -0800113
Angel Ponsbdd3d5f2020-07-26 22:41:43 +0200114 /*
115 * Reserve everything between A segment and 1MB:
Duncan Lauriee7e78d62013-11-03 19:38:12 -0800116 *
117 * 0xa0000 - 0xbffff: legacy VGA
118 * 0xc0000 - 0xfffff: RAM
119 */
120 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
Angel Pons7bef2ee2020-07-26 22:35:12 +0200121 reserved_ram_resource(dev, index++, (0xc0000 >> 10), (0x100000 - 0xc0000) >> 10);
Kein Yuan35110232014-02-22 12:26:55 -0800122
Julius Wernercd49cce2019-03-05 16:53:33 -0800123 if (CONFIG(CHROMEOS))
Frans Hendriksef05dc82018-11-27 10:35:16 +0100124 chromeos_reserve_ram_oops(dev, index++);
Aaron Durbin191570d2013-09-24 12:41:08 -0500125}
126
Kyösti Mälkkid06f8002021-01-27 20:25:51 +0200127static void nc_generate_ssdt(const struct device *dev)
128{
129 generate_cpu_entries(dev);
130
131 acpigen_write_scope("\\");
132 acpigen_write_name_dword("TOLM", nc_read_top_of_low_memory());
133 acpigen_pop_len();
134}
135
Aaron Durbin191570d2013-09-24 12:41:08 -0500136static struct device_operations nc_ops = {
137 .read_resources = nc_read_resources,
Kyösti Mälkkid06f8002021-01-27 20:25:51 +0200138 .acpi_fill_ssdt = nc_generate_ssdt,
Aaron Durbin191570d2013-09-24 12:41:08 -0500139 .ops_pci = &soc_pci_ops,
140};
141
142static const struct pci_driver nc_driver __pci_driver = {
143 .ops = &nc_ops,
144 .vendor = PCI_VENDOR_ID_INTEL,
145 .device = SOC_DEVID,
146};