blob: 0ef58b24704d858d52651c69d72521a08f3c6567 [file] [log] [blame]
Angel Ponsba38f372020-04-05 15:46:45 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy77ff0b12015-05-05 15:07:29 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Kyösti Mälkkid06f8002021-01-27 20:25:51 +02004#include <acpi/acpigen.h>
Lee Leahy32471722015-04-20 15:20:28 -07005#include <cbmem.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07006#include <cpu/x86/smm.h>
7#include <device/device.h>
8#include <device/pci.h>
9#include <device/pci_ids.h>
Elyes HAOUAS32da3432020-05-17 17:15:31 +020010#include <cpu/x86/lapic_def.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -050011#include <fsp/util.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070012#include <soc/iomap.h>
13#include <soc/iosf.h>
14#include <soc/pci_devs.h>
15#include <soc/ramstage.h>
Lee Leahy32471722015-04-20 15:20:28 -070016#include <vendorcode/google/chromeos/chromeos.h>
Harry Pan43dcbfd2016-08-11 14:35:04 +080017#include <stddef.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070018
Lee Leahy32471722015-04-20 15:20:28 -070019/*
20 * Host Memory Map:
Lee Leahy77ff0b12015-05-05 15:07:29 -070021 *
22 * +--------------------------+ BMBOUND_HI
23 * | Usable DRAM |
24 * +--------------------------+ 4GiB
25 * | PCI Address Space |
26 * +--------------------------+ BMBOUND
27 * | TPM |
28 * +--------------------------+ IMR2
29 * | TXE |
30 * +--------------------------+ IMR1
31 * | iGD |
32 * +--------------------------+
33 * | GTT |
34 * +--------------------------+ SMMRRH, IRM0
35 * | TSEG |
36 * +--------------------------+ SMMRRL
37 * | Usable DRAM |
38 * +--------------------------+ 0
39 *
40 * Note that there are really only a few regions that need to enumerated w.r.t.
Frans Hendriksb81dcc62018-12-10 10:30:37 +010041 * coreboot's resource model:
Lee Leahy77ff0b12015-05-05 15:07:29 -070042 *
43 * +--------------------------+ BMBOUND_HI
44 * | Cacheable/Usable |
45 * +--------------------------+ 4GiB
46 *
47 * +--------------------------+ BMBOUND
48 * | Uncacheable/Reserved |
49 * +--------------------------+ SMMRRH
50 * | Cacheable/Reserved |
51 * +--------------------------+ SMMRRL
52 * | Cacheable/Usable |
53 * +--------------------------+ 0
54 */
Angel Pons3a713c02020-07-26 22:28:37 +020055#define RES_IN_KiB(r) ((r) >> 10)
Lee Leahy77ff0b12015-05-05 15:07:29 -070056
57uint32_t nc_read_top_of_low_memory(void)
58{
Kyösti Mälkkifcbbb912020-04-20 10:21:39 +030059 static uint32_t tolm;
Harry Pan43dcbfd2016-08-11 14:35:04 +080060
61 if (tolm)
62 return tolm;
63
64 tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
65
66 return tolm;
Lee Leahy77ff0b12015-05-05 15:07:29 -070067}
68
Elyes HAOUASb13fac32018-05-24 22:29:44 +020069static void nc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070070{
71 unsigned long mmconf;
Lee Leahy32471722015-04-20 15:20:28 -070072 unsigned long bmbound_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070073 unsigned long bmbound_hi;
Kyösti Mälkki14222d82019-08-05 15:10:18 +030074 uintptr_t smm_base;
Lee Leahy32471722015-04-20 15:20:28 -070075 size_t smm_size;
76 unsigned long tseg_base_k;
77 unsigned long tseg_top_k;
78 unsigned long fsp_res_base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070079 unsigned long base_k, size_k;
80 const unsigned long four_gig_kib = (4 << (30 - 10));
Frans Hendriksc6d672f2018-10-30 15:07:39 +010081 void *fsp_reserved_memory_area;
Lee Leahy77ff0b12015-05-05 15:07:29 -070082 int index = 0;
83
84 /* Read standard PCI resources. */
85 pci_dev_read_resources(dev);
86
Lee Leahy32471722015-04-20 15:20:28 -070087 /* Determine TSEG data */
88 smm_region(&smm_base, &smm_size);
Angel Pons3a713c02020-07-26 22:28:37 +020089 tseg_base_k = RES_IN_KiB(smm_base);
90 tseg_top_k = tseg_base_k + RES_IN_KiB(smm_size);
Lee Leahy32471722015-04-20 15:20:28 -070091
92 /* Determine the base of the FSP reserved memory */
Frans Hendriksc6d672f2018-10-30 15:07:39 +010093 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
94 if (fsp_reserved_memory_area) {
Angel Pons31d6cd72020-07-26 22:31:45 +020095 fsp_res_base_k = RES_IN_KiB((unsigned int)fsp_reserved_memory_area);
Frans Hendriksc6d672f2018-10-30 15:07:39 +010096 } else {
97 /* If no FSP reserverd area */
98 fsp_res_base_k = tseg_base_k;
99 }
Lee Leahy32471722015-04-20 15:20:28 -0700100
Lee Leahy77ff0b12015-05-05 15:07:29 -0700101 /* PCIe memory-mapped config space access - 256 MiB. */
102 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
Angel Pons3a713c02020-07-26 22:28:37 +0200103 mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700104
105 /* 0 -> 0xa0000 */
Angel Pons3a713c02020-07-26 22:28:37 +0200106 base_k = RES_IN_KiB(0);
107 size_k = RES_IN_KiB(0xa0000) - base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700108 ram_resource(dev, index++, base_k, size_k);
109
Frans Hendriksc6d672f2018-10-30 15:07:39 +0100110 /* High memory -> fsp_res_base - cacheable and usable */
Angel Pons3a713c02020-07-26 22:28:37 +0200111 base_k = RES_IN_KiB(0x100000);
Lee Leahy32471722015-04-20 15:20:28 -0700112 size_k = fsp_res_base_k - base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700113 ram_resource(dev, index++, base_k, size_k);
114
Lee Leahy32471722015-04-20 15:20:28 -0700115 /* fsp_res_base -> tseg_top - Reserved */
116 base_k = fsp_res_base_k;
117 size_k = tseg_top_k - base_k;
118 reserved_ram_resource(dev, index++, base_k, size_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700119
Lee Leahy32471722015-04-20 15:20:28 -0700120 /* TSEG TOP -> bmbound is memory backed mmio. */
Angel Pons3a713c02020-07-26 22:28:37 +0200121 bmbound_k = RES_IN_KiB(nc_read_top_of_low_memory());
Lee Leahy32471722015-04-20 15:20:28 -0700122 mmio_resource(dev, index++, tseg_top_k, bmbound_k - tseg_top_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700123
Lee Leahy32471722015-04-20 15:20:28 -0700124 /*
125 * The BMBOUND_HI register matches register bits of 31:24 with address
126 * bits of 35:28. Therefore, shift register to align properly.
127 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700128 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
Angel Pons3a713c02020-07-26 22:28:37 +0200129 bmbound_hi = RES_IN_KiB(bmbound_hi) << 4;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700130 if (bmbound_hi > four_gig_kib)
Angel Pons31d6cd72020-07-26 22:31:45 +0200131 ram_resource(dev, index++, four_gig_kib, bmbound_hi - four_gig_kib);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700132
Lee Leahy32471722015-04-20 15:20:28 -0700133 /*
134 * Reserve everything between A segment and 1MB:
Lee Leahy77ff0b12015-05-05 15:07:29 -0700135 *
136 * 0xa0000 - 0xbffff: legacy VGA
137 * 0xc0000 - 0xfffff: RAM
138 */
139 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
Angel Pons31d6cd72020-07-26 22:31:45 +0200140 reserved_ram_resource(dev, index++, (0xc0000 >> 10), (0x100000 - 0xc0000) >> 10);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700141
Frans Hendriksd97eb642018-11-26 11:01:56 +0100142 /*
143 * Reserve local APIC
144 */
Angel Pons3a713c02020-07-26 22:28:37 +0200145 base_k = RES_IN_KiB(LAPIC_DEFAULT_BASE);
146 size_k = RES_IN_KiB(0x00100000);
Frans Hendriksd97eb642018-11-26 11:01:56 +0100147 mmio_resource(dev, index++, base_k, size_k);
148
Julius Wernercd49cce2019-03-05 16:53:33 -0800149 if (CONFIG(CHROMEOS))
Frans Hendriksed7780d2018-12-14 07:49:18 +0100150 chromeos_reserve_ram_oops(dev, index++);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700151}
152
Kyösti Mälkkid06f8002021-01-27 20:25:51 +0200153static void nc_generate_ssdt(const struct device *dev)
154{
155 generate_cpu_entries(dev);
156
157 acpigen_write_scope("\\");
158 acpigen_write_name_dword("TOLM", nc_read_top_of_low_memory());
159 acpigen_pop_len();
160}
161
Lee Leahy77ff0b12015-05-05 15:07:29 -0700162static struct device_operations nc_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200163 .read_resources = nc_read_resources,
Kyösti Mälkkid06f8002021-01-27 20:25:51 +0200164 .acpi_fill_ssdt = nc_generate_ssdt,
Nico Huber68680dd2020-03-31 17:34:52 +0200165 .ops_pci = &soc_pci_ops,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700166};
167
168static const struct pci_driver nc_driver __pci_driver = {
169 .ops = &nc_ops,
170 .vendor = PCI_VENDOR_ID_INTEL,
171 .device = SOC_DEVID,
172};