blob: 3222faf814f6b4fb3521761c616beba78a1fcd2c [file] [log] [blame]
Angel Ponsba38f372020-04-05 15:46:45 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Lee Leahy77ff0b12015-05-05 15:07:29 -07003
Lee Leahy32471722015-04-20 15:20:28 -07004#include <arch/acpi.h>
5#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>
Frans Hendriksd97eb642018-11-26 11:01:56 +010010#include <cpu/x86/lapic.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +030011#include <cpu/x86/smm.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -050012#include <fsp/util.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070013#include <soc/iomap.h>
14#include <soc/iosf.h>
15#include <soc/pci_devs.h>
16#include <soc/ramstage.h>
Lee Leahy32471722015-04-20 15:20:28 -070017#include <vendorcode/google/chromeos/chromeos.h>
Harry Pan43dcbfd2016-08-11 14:35:04 +080018#include <stddef.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070019
Lee Leahy32471722015-04-20 15:20:28 -070020/*
21 * Host Memory Map:
Lee Leahy77ff0b12015-05-05 15:07:29 -070022 *
23 * +--------------------------+ BMBOUND_HI
24 * | Usable DRAM |
25 * +--------------------------+ 4GiB
26 * | PCI Address Space |
27 * +--------------------------+ BMBOUND
28 * | TPM |
29 * +--------------------------+ IMR2
30 * | TXE |
31 * +--------------------------+ IMR1
32 * | iGD |
33 * +--------------------------+
34 * | GTT |
35 * +--------------------------+ SMMRRH, IRM0
36 * | TSEG |
37 * +--------------------------+ SMMRRL
38 * | Usable DRAM |
39 * +--------------------------+ 0
40 *
41 * Note that there are really only a few regions that need to enumerated w.r.t.
Frans Hendriksb81dcc62018-12-10 10:30:37 +010042 * coreboot's resource model:
Lee Leahy77ff0b12015-05-05 15:07:29 -070043 *
44 * +--------------------------+ BMBOUND_HI
45 * | Cacheable/Usable |
46 * +--------------------------+ 4GiB
47 *
48 * +--------------------------+ BMBOUND
49 * | Uncacheable/Reserved |
50 * +--------------------------+ SMMRRH
51 * | Cacheable/Reserved |
52 * +--------------------------+ SMMRRL
53 * | Cacheable/Usable |
54 * +--------------------------+ 0
55 */
Lee Leahy32471722015-04-20 15:20:28 -070056#define RES_IN_KIB(r) ((r) >> 10)
Lee Leahy77ff0b12015-05-05 15:07:29 -070057
58uint32_t nc_read_top_of_low_memory(void)
59{
Kyösti Mälkki117cf2b2019-08-20 06:01:57 +030060 MAYBE_STATIC_BSS uint32_t tolm = 0;
Harry Pan43dcbfd2016-08-11 14:35:04 +080061
62 if (tolm)
63 return tolm;
64
65 tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
66
67 return tolm;
Lee Leahy77ff0b12015-05-05 15:07:29 -070068}
69
Elyes HAOUASb13fac32018-05-24 22:29:44 +020070static void nc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070071{
72 unsigned long mmconf;
Lee Leahy32471722015-04-20 15:20:28 -070073 unsigned long bmbound_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070074 unsigned long bmbound_hi;
Kyösti Mälkki14222d82019-08-05 15:10:18 +030075 uintptr_t smm_base;
Lee Leahy32471722015-04-20 15:20:28 -070076 size_t smm_size;
77 unsigned long tseg_base_k;
78 unsigned long tseg_top_k;
79 unsigned long fsp_res_base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070080 unsigned long base_k, size_k;
81 const unsigned long four_gig_kib = (4 << (30 - 10));
Frans Hendriksc6d672f2018-10-30 15:07:39 +010082 void *fsp_reserved_memory_area;
Lee Leahy77ff0b12015-05-05 15:07:29 -070083 int index = 0;
84
85 /* Read standard PCI resources. */
86 pci_dev_read_resources(dev);
87
Lee Leahy32471722015-04-20 15:20:28 -070088 /* Determine TSEG data */
89 smm_region(&smm_base, &smm_size);
Kyösti Mälkki14222d82019-08-05 15:10:18 +030090 tseg_base_k = RES_IN_KIB(smm_base);
Lee Leahy32471722015-04-20 15:20:28 -070091 tseg_top_k = tseg_base_k + RES_IN_KIB(smm_size);
92
93 /* Determine the base of the FSP reserved memory */
Frans Hendriksc6d672f2018-10-30 15:07:39 +010094 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
95 if (fsp_reserved_memory_area) {
96 fsp_res_base_k =
97 RES_IN_KIB((unsigned int)fsp_reserved_memory_area);
98 } else {
99 /* If no FSP reserverd area */
100 fsp_res_base_k = tseg_base_k;
101 }
Lee Leahy32471722015-04-20 15:20:28 -0700102
Lee Leahy77ff0b12015-05-05 15:07:29 -0700103 /* PCIe memory-mapped config space access - 256 MiB. */
104 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
Lee Leahy32471722015-04-20 15:20:28 -0700105 mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KIB(mmconf), 256 * 1024);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700106
107 /* 0 -> 0xa0000 */
Lee Leahy32471722015-04-20 15:20:28 -0700108 base_k = RES_IN_KIB(0);
109 size_k = RES_IN_KIB(0xa0000) - base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700110 ram_resource(dev, index++, base_k, size_k);
111
Frans Hendriksc6d672f2018-10-30 15:07:39 +0100112 /* High memory -> fsp_res_base - cacheable and usable */
113 base_k = RES_IN_KIB(0x100000);
Lee Leahy32471722015-04-20 15:20:28 -0700114 size_k = fsp_res_base_k - base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700115 ram_resource(dev, index++, base_k, size_k);
116
Lee Leahy32471722015-04-20 15:20:28 -0700117 /* fsp_res_base -> tseg_top - Reserved */
118 base_k = fsp_res_base_k;
119 size_k = tseg_top_k - base_k;
120 reserved_ram_resource(dev, index++, base_k, size_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700121
Lee Leahy32471722015-04-20 15:20:28 -0700122 /* TSEG TOP -> bmbound is memory backed mmio. */
123 bmbound_k = RES_IN_KIB(nc_read_top_of_low_memory());
124 mmio_resource(dev, index++, tseg_top_k, bmbound_k - tseg_top_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700125
Lee Leahy32471722015-04-20 15:20:28 -0700126 /*
127 * The BMBOUND_HI register matches register bits of 31:24 with address
128 * bits of 35:28. Therefore, shift register to align properly.
129 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700130 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
Lee Leahy32471722015-04-20 15:20:28 -0700131 bmbound_hi = RES_IN_KIB(bmbound_hi) << 4;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700132 if (bmbound_hi > four_gig_kib)
133 ram_resource(dev, index++, four_gig_kib,
Lee Leahy32471722015-04-20 15:20:28 -0700134 bmbound_hi - four_gig_kib);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700135
Lee Leahy32471722015-04-20 15:20:28 -0700136 /*
137 * Reserve everything between A segment and 1MB:
Lee Leahy77ff0b12015-05-05 15:07:29 -0700138 *
139 * 0xa0000 - 0xbffff: legacy VGA
140 * 0xc0000 - 0xfffff: RAM
141 */
142 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
143 reserved_ram_resource(dev, index++, (0xc0000 >> 10),
Lee Leahy32471722015-04-20 15:20:28 -0700144 (0x100000 - 0xc0000) >> 10);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700145
Frans Hendriksd97eb642018-11-26 11:01:56 +0100146 /*
147 * Reserve local APIC
148 */
149 base_k = RES_IN_KIB(LAPIC_DEFAULT_BASE);
150 size_k = RES_IN_KIB(0x00100000);
151 mmio_resource(dev, index++, base_k, size_k);
152
Julius Wernercd49cce2019-03-05 16:53:33 -0800153 if (CONFIG(CHROMEOS))
Frans Hendriksed7780d2018-12-14 07:49:18 +0100154 chromeos_reserve_ram_oops(dev, index++);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700155}
156
157static struct device_operations nc_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200158 .acpi_fill_ssdt = generate_cpu_entries,
159 .read_resources = nc_read_resources,
160 .ops_pci = &soc_pci_ops,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700161};
162
163static const struct pci_driver nc_driver __pci_driver = {
164 .ops = &nc_ops,
165 .vendor = PCI_VENDOR_ID_INTEL,
166 .device = SOC_DEVID,
167};