blob: c5afa426f674dd0760fe6a7b962e3b28897b3640 [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
Aaron Durbin191570d2013-09-24 12:41:08 -05003#include <device/device.h>
4#include <device/pci.h>
5#include <device/pci_ids.h>
Kein Yuan35110232014-02-22 12:26:55 -08006#include <vendorcode/google/chromeos/chromeos.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07007#include <acpi/acpi.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;
67 unsigned long bmbound;
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. */
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);
80 mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024);
81
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;
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. */
Duncan Laurie1f52f512013-11-04 17:02:45 -0800101 bmbound = RES_IN_KiB(nc_read_top_of_low_memory());
Aaron Durbin191570d2013-09-24 12:41:08 -0500102 mmio_resource(dev, index++, smmrrh, bmbound - smmrrh);
103
104 /* The BMBOUND_HI register matches register bits of 31:24 with address
105 * bits of 35:28. Therefore, shift register to align properly. */
106 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
107 bmbound_hi = RES_IN_KiB(bmbound_hi) << 4;
108 if (bmbound_hi > four_gig_kib)
109 ram_resource(dev, index++, four_gig_kib,
110 bmbound_hi - four_gig_kib);
Duncan Lauriee7e78d62013-11-03 19:38:12 -0800111
112 /* Reserve everything between A segment and 1MB:
113 *
114 * 0xa0000 - 0xbffff: legacy VGA
115 * 0xc0000 - 0xfffff: RAM
116 */
117 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
118 reserved_ram_resource(dev, index++, (0xc0000 >> 10),
119 (0x100000 - 0xc0000) >> 10);
Kein Yuan35110232014-02-22 12:26:55 -0800120
Julius Wernercd49cce2019-03-05 16:53:33 -0800121 if (CONFIG(CHROMEOS))
Frans Hendriksef05dc82018-11-27 10:35:16 +0100122 chromeos_reserve_ram_oops(dev, index++);
Aaron Durbin191570d2013-09-24 12:41:08 -0500123}
124
Aaron Durbin191570d2013-09-24 12:41:08 -0500125static struct device_operations nc_ops = {
126 .read_resources = nc_read_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200127 .acpi_fill_ssdt = generate_cpu_entries,
Aaron Durbin191570d2013-09-24 12:41:08 -0500128 .ops_pci = &soc_pci_ops,
129};
130
131static const struct pci_driver nc_driver __pci_driver = {
132 .ops = &nc_ops,
133 .vendor = PCI_VENDOR_ID_INTEL,
134 .device = SOC_DEVID,
135};