blob: ca4651b72993a1606dd6bf6e63b0f0579010744e [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 */
Lee Leahy77ff0b12015-05-05 15:07:29 -070054uint32_t nc_read_top_of_low_memory(void)
55{
Kyösti Mälkkifcbbb912020-04-20 10:21:39 +030056 static uint32_t tolm;
Harry Pan43dcbfd2016-08-11 14:35:04 +080057
58 if (tolm)
59 return tolm;
60
61 tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
62
63 return tolm;
Lee Leahy77ff0b12015-05-05 15:07:29 -070064}
65
Elyes HAOUASb13fac32018-05-24 22:29:44 +020066static void nc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070067{
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +030068 uint64_t mmconf;
69 uint64_t bmbound;
70 uint64_t bmbound_hi;
Kyösti Mälkki14222d82019-08-05 15:10:18 +030071 uintptr_t smm_base;
Lee Leahy32471722015-04-20 15:20:28 -070072 size_t smm_size;
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +030073 uint64_t tseg_base;
74 uint64_t tseg_top;
75 uint64_t fsp_res_base;
Frans Hendriksc6d672f2018-10-30 15:07:39 +010076 void *fsp_reserved_memory_area;
Lee Leahy77ff0b12015-05-05 15:07:29 -070077 int index = 0;
78
79 /* Read standard PCI resources. */
80 pci_dev_read_resources(dev);
81
Lee Leahy32471722015-04-20 15:20:28 -070082 /* Determine TSEG data */
83 smm_region(&smm_base, &smm_size);
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +030084 tseg_base = smm_base;
85 tseg_top = tseg_base + smm_size;
Lee Leahy32471722015-04-20 15:20:28 -070086
87 /* Determine the base of the FSP reserved memory */
Frans Hendriksc6d672f2018-10-30 15:07:39 +010088 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
89 if (fsp_reserved_memory_area) {
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +030090 fsp_res_base = (uintptr_t)fsp_reserved_memory_area;
Frans Hendriksc6d672f2018-10-30 15:07:39 +010091 } else {
Martin Roth26f97f92021-10-01 14:53:22 -060092 /* If no FSP reserved area */
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +030093 fsp_res_base = tseg_base;
Frans Hendriksc6d672f2018-10-30 15:07:39 +010094 }
Lee Leahy32471722015-04-20 15:20:28 -070095
Lee Leahy77ff0b12015-05-05 15:07:29 -070096 /* PCIe memory-mapped config space access - 256 MiB. */
97 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
Kyösti Mälkki5a55a452021-06-24 20:49:05 +030098 mmio_range(dev, BUNIT_MMCONF_REG, mmconf, CONFIG_ECAM_MMCONF_BUS_NUMBER * MiB);
Lee Leahy77ff0b12015-05-05 15:07:29 -070099
100 /* 0 -> 0xa0000 */
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +0300101 ram_from_to(dev, index++, 0, 0xa0000);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700102
Frans Hendriksc6d672f2018-10-30 15:07:39 +0100103 /* High memory -> fsp_res_base - cacheable and usable */
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +0300104 ram_from_to(dev, index++, 1 * MiB, fsp_res_base);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700105
Lee Leahy32471722015-04-20 15:20:28 -0700106 /* fsp_res_base -> tseg_top - Reserved */
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +0300107 reserved_ram_from_to(dev, index++, fsp_res_base, tseg_top);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700108
Lee Leahy32471722015-04-20 15:20:28 -0700109 /* TSEG TOP -> bmbound is memory backed mmio. */
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +0300110 bmbound = nc_read_top_of_low_memory();
111 mmio_from_to(dev, index++, tseg_top, bmbound);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700112
Lee Leahy32471722015-04-20 15:20:28 -0700113 /*
114 * The BMBOUND_HI register matches register bits of 31:24 with address
115 * bits of 35:28. Therefore, shift register to align properly.
116 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700117 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +0300118 bmbound_hi <<= 4;
Kyösti Mälkki0a18d642021-06-28 21:43:31 +0300119 upper_ram_end(dev, index++, bmbound_hi);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700120
Lee Leahy32471722015-04-20 15:20:28 -0700121 /*
122 * Reserve everything between A segment and 1MB:
Lee Leahy77ff0b12015-05-05 15:07:29 -0700123 *
124 * 0xa0000 - 0xbffff: legacy VGA
125 * 0xc0000 - 0xfffff: RAM
126 */
Arthur Heymans43169fe2023-07-05 11:49:59 +0200127 mmio_from_to(dev, index++, 0xa0000, 0xc0000);
128 reserved_ram_from_to(dev, index++, 0xc0000, 1 * MiB);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700129
Frans Hendriksd97eb642018-11-26 11:01:56 +0100130 /*
131 * Reserve local APIC
132 */
Kyösti Mälkki5c3cbcd2021-06-25 13:02:55 +0300133 mmio_range(dev, index++, LAPIC_DEFAULT_BASE, 1 * MiB);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700134}
135
Kyösti Mälkkid06f8002021-01-27 20:25:51 +0200136static void nc_generate_ssdt(const struct device *dev)
137{
138 generate_cpu_entries(dev);
139
140 acpigen_write_scope("\\");
141 acpigen_write_name_dword("TOLM", nc_read_top_of_low_memory());
142 acpigen_pop_len();
143}
144
Lee Leahy77ff0b12015-05-05 15:07:29 -0700145static struct device_operations nc_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200146 .read_resources = nc_read_resources,
Kyösti Mälkkid06f8002021-01-27 20:25:51 +0200147 .acpi_fill_ssdt = nc_generate_ssdt,
Nico Huber68680dd2020-03-31 17:34:52 +0200148 .ops_pci = &soc_pci_ops,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700149};
150
151static const struct pci_driver nc_driver __pci_driver = {
152 .ops = &nc_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100153 .vendor = PCI_VID_INTEL,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700154 .device = SOC_DEVID,
155};