blob: a39b6db030cc07348e4ffc126d388e4be24b3344 [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>
Harry Pan43dcbfd2016-08-11 14:35:04 +080016#include <stddef.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070017
Lee Leahy32471722015-04-20 15:20:28 -070018/*
19 * Host Memory Map:
Lee Leahy77ff0b12015-05-05 15:07:29 -070020 *
21 * +--------------------------+ BMBOUND_HI
22 * | Usable DRAM |
23 * +--------------------------+ 4GiB
24 * | PCI Address Space |
25 * +--------------------------+ BMBOUND
26 * | TPM |
27 * +--------------------------+ IMR2
28 * | TXE |
29 * +--------------------------+ IMR1
30 * | iGD |
31 * +--------------------------+
32 * | GTT |
33 * +--------------------------+ SMMRRH, IRM0
34 * | TSEG |
35 * +--------------------------+ SMMRRL
36 * | Usable DRAM |
37 * +--------------------------+ 0
38 *
39 * Note that there are really only a few regions that need to enumerated w.r.t.
Frans Hendriksb81dcc62018-12-10 10:30:37 +010040 * coreboot's resource model:
Lee Leahy77ff0b12015-05-05 15:07:29 -070041 *
42 * +--------------------------+ BMBOUND_HI
43 * | Cacheable/Usable |
44 * +--------------------------+ 4GiB
45 *
46 * +--------------------------+ BMBOUND
47 * | Uncacheable/Reserved |
48 * +--------------------------+ SMMRRH
49 * | Cacheable/Reserved |
50 * +--------------------------+ SMMRRL
51 * | Cacheable/Usable |
52 * +--------------------------+ 0
53 */
Angel Pons3a713c02020-07-26 22:28:37 +020054#define RES_IN_KiB(r) ((r) >> 10)
Lee Leahy77ff0b12015-05-05 15:07:29 -070055
56uint32_t nc_read_top_of_low_memory(void)
57{
Kyösti Mälkkifcbbb912020-04-20 10:21:39 +030058 static uint32_t tolm;
Harry Pan43dcbfd2016-08-11 14:35:04 +080059
60 if (tolm)
61 return tolm;
62
63 tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
64
65 return tolm;
Lee Leahy77ff0b12015-05-05 15:07:29 -070066}
67
Elyes HAOUASb13fac32018-05-24 22:29:44 +020068static void nc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070069{
70 unsigned long mmconf;
Lee Leahy32471722015-04-20 15:20:28 -070071 unsigned long bmbound_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070072 unsigned long bmbound_hi;
Kyösti Mälkki14222d82019-08-05 15:10:18 +030073 uintptr_t smm_base;
Lee Leahy32471722015-04-20 15:20:28 -070074 size_t smm_size;
75 unsigned long tseg_base_k;
76 unsigned long tseg_top_k;
77 unsigned long fsp_res_base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070078 unsigned long base_k, size_k;
79 const unsigned long four_gig_kib = (4 << (30 - 10));
Frans Hendriksc6d672f2018-10-30 15:07:39 +010080 void *fsp_reserved_memory_area;
Lee Leahy77ff0b12015-05-05 15:07:29 -070081 int index = 0;
82
83 /* Read standard PCI resources. */
84 pci_dev_read_resources(dev);
85
Lee Leahy32471722015-04-20 15:20:28 -070086 /* Determine TSEG data */
87 smm_region(&smm_base, &smm_size);
Angel Pons3a713c02020-07-26 22:28:37 +020088 tseg_base_k = RES_IN_KiB(smm_base);
89 tseg_top_k = tseg_base_k + RES_IN_KiB(smm_size);
Lee Leahy32471722015-04-20 15:20:28 -070090
91 /* Determine the base of the FSP reserved memory */
Frans Hendriksc6d672f2018-10-30 15:07:39 +010092 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
93 if (fsp_reserved_memory_area) {
Angel Pons31d6cd72020-07-26 22:31:45 +020094 fsp_res_base_k = RES_IN_KiB((unsigned int)fsp_reserved_memory_area);
Frans Hendriksc6d672f2018-10-30 15:07:39 +010095 } else {
Martin Roth26f97f92021-10-01 14:53:22 -060096 /* If no FSP reserved area */
Frans Hendriksc6d672f2018-10-30 15:07:39 +010097 fsp_res_base_k = tseg_base_k;
98 }
Lee Leahy32471722015-04-20 15:20:28 -070099
Lee Leahy77ff0b12015-05-05 15:07:29 -0700100 /* PCIe memory-mapped config space access - 256 MiB. */
101 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300102 mmio_resource_kb(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700103
104 /* 0 -> 0xa0000 */
Angel Pons3a713c02020-07-26 22:28:37 +0200105 base_k = RES_IN_KiB(0);
106 size_k = RES_IN_KiB(0xa0000) - base_k;
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300107 ram_resource_kb(dev, index++, base_k, size_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700108
Frans Hendriksc6d672f2018-10-30 15:07:39 +0100109 /* High memory -> fsp_res_base - cacheable and usable */
Angel Pons3a713c02020-07-26 22:28:37 +0200110 base_k = RES_IN_KiB(0x100000);
Lee Leahy32471722015-04-20 15:20:28 -0700111 size_k = fsp_res_base_k - base_k;
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300112 ram_resource_kb(dev, index++, base_k, size_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700113
Lee Leahy32471722015-04-20 15:20:28 -0700114 /* fsp_res_base -> tseg_top - Reserved */
115 base_k = fsp_res_base_k;
116 size_k = tseg_top_k - base_k;
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300117 reserved_ram_resource_kb(dev, index++, base_k, size_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700118
Lee Leahy32471722015-04-20 15:20:28 -0700119 /* TSEG TOP -> bmbound is memory backed mmio. */
Angel Pons3a713c02020-07-26 22:28:37 +0200120 bmbound_k = RES_IN_KiB(nc_read_top_of_low_memory());
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300121 mmio_resource_kb(dev, index++, tseg_top_k, bmbound_k - tseg_top_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700122
Lee Leahy32471722015-04-20 15:20:28 -0700123 /*
124 * The BMBOUND_HI register matches register bits of 31:24 with address
125 * bits of 35:28. Therefore, shift register to align properly.
126 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700127 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
Angel Pons3a713c02020-07-26 22:28:37 +0200128 bmbound_hi = RES_IN_KiB(bmbound_hi) << 4;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700129 if (bmbound_hi > four_gig_kib)
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300130 ram_resource_kb(dev, index++, four_gig_kib, bmbound_hi - four_gig_kib);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700131
Lee Leahy32471722015-04-20 15:20:28 -0700132 /*
133 * Reserve everything between A segment and 1MB:
Lee Leahy77ff0b12015-05-05 15:07:29 -0700134 *
135 * 0xa0000 - 0xbffff: legacy VGA
136 * 0xc0000 - 0xfffff: RAM
137 */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300138 mmio_resource_kb(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
139 reserved_ram_resource_kb(dev, index++, (0xc0000 >> 10), (0x100000 - 0xc0000) >> 10);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700140
Frans Hendriksd97eb642018-11-26 11:01:56 +0100141 /*
142 * Reserve local APIC
143 */
Angel Pons3a713c02020-07-26 22:28:37 +0200144 base_k = RES_IN_KiB(LAPIC_DEFAULT_BASE);
145 size_k = RES_IN_KiB(0x00100000);
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300146 mmio_resource_kb(dev, index++, base_k, size_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700147}
148
Kyösti Mälkkid06f8002021-01-27 20:25:51 +0200149static void nc_generate_ssdt(const struct device *dev)
150{
151 generate_cpu_entries(dev);
152
153 acpigen_write_scope("\\");
154 acpigen_write_name_dword("TOLM", nc_read_top_of_low_memory());
155 acpigen_pop_len();
156}
157
Lee Leahy77ff0b12015-05-05 15:07:29 -0700158static struct device_operations nc_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200159 .read_resources = nc_read_resources,
Kyösti Mälkkid06f8002021-01-27 20:25:51 +0200160 .acpi_fill_ssdt = nc_generate_ssdt,
Nico Huber68680dd2020-03-31 17:34:52 +0200161 .ops_pci = &soc_pci_ops,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700162};
163
164static const struct pci_driver nc_driver __pci_driver = {
165 .ops = &nc_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100166 .vendor = PCI_VID_INTEL,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700167 .device = SOC_DEVID,
168};