blob: f8e3391f9e6ccd0c7c38d6aa9870849fed36e5b6 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy77ff0b12015-05-05 15:07:29 -07004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070013 */
14
Lee Leahy32471722015-04-20 15:20:28 -070015#include <arch/acpi.h>
16#include <cbmem.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070017#include <cpu/x86/smm.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
Frans Hendriksd97eb642018-11-26 11:01:56 +010021#include <cpu/x86/lapic.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +030022#include <cpu/x86/smm.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -050023#include <fsp/util.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070024#include <soc/iomap.h>
25#include <soc/iosf.h>
26#include <soc/pci_devs.h>
27#include <soc/ramstage.h>
Lee Leahy32471722015-04-20 15:20:28 -070028#include <vendorcode/google/chromeos/chromeos.h>
Harry Pan43dcbfd2016-08-11 14:35:04 +080029#include <stddef.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070030
Lee Leahy32471722015-04-20 15:20:28 -070031/*
32 * Host Memory Map:
Lee Leahy77ff0b12015-05-05 15:07:29 -070033 *
34 * +--------------------------+ BMBOUND_HI
35 * | Usable DRAM |
36 * +--------------------------+ 4GiB
37 * | PCI Address Space |
38 * +--------------------------+ BMBOUND
39 * | TPM |
40 * +--------------------------+ IMR2
41 * | TXE |
42 * +--------------------------+ IMR1
43 * | iGD |
44 * +--------------------------+
45 * | GTT |
46 * +--------------------------+ SMMRRH, IRM0
47 * | TSEG |
48 * +--------------------------+ SMMRRL
49 * | Usable DRAM |
50 * +--------------------------+ 0
51 *
52 * Note that there are really only a few regions that need to enumerated w.r.t.
Frans Hendriksb81dcc62018-12-10 10:30:37 +010053 * coreboot's resource model:
Lee Leahy77ff0b12015-05-05 15:07:29 -070054 *
55 * +--------------------------+ BMBOUND_HI
56 * | Cacheable/Usable |
57 * +--------------------------+ 4GiB
58 *
59 * +--------------------------+ BMBOUND
60 * | Uncacheable/Reserved |
61 * +--------------------------+ SMMRRH
62 * | Cacheable/Reserved |
63 * +--------------------------+ SMMRRL
64 * | Cacheable/Usable |
65 * +--------------------------+ 0
66 */
Lee Leahy32471722015-04-20 15:20:28 -070067#define RES_IN_KIB(r) ((r) >> 10)
Lee Leahy77ff0b12015-05-05 15:07:29 -070068
69uint32_t nc_read_top_of_low_memory(void)
70{
Kyösti Mälkki117cf2b2019-08-20 06:01:57 +030071 MAYBE_STATIC_BSS uint32_t tolm = 0;
Harry Pan43dcbfd2016-08-11 14:35:04 +080072
73 if (tolm)
74 return tolm;
75
76 tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1);
77
78 return tolm;
Lee Leahy77ff0b12015-05-05 15:07:29 -070079}
80
Elyes HAOUASb13fac32018-05-24 22:29:44 +020081static void nc_read_resources(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070082{
83 unsigned long mmconf;
Lee Leahy32471722015-04-20 15:20:28 -070084 unsigned long bmbound_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070085 unsigned long bmbound_hi;
Kyösti Mälkki14222d82019-08-05 15:10:18 +030086 uintptr_t smm_base;
Lee Leahy32471722015-04-20 15:20:28 -070087 size_t smm_size;
88 unsigned long tseg_base_k;
89 unsigned long tseg_top_k;
90 unsigned long fsp_res_base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -070091 unsigned long base_k, size_k;
92 const unsigned long four_gig_kib = (4 << (30 - 10));
Frans Hendriksc6d672f2018-10-30 15:07:39 +010093 void *fsp_reserved_memory_area;
Lee Leahy77ff0b12015-05-05 15:07:29 -070094 int index = 0;
95
96 /* Read standard PCI resources. */
97 pci_dev_read_resources(dev);
98
Lee Leahy32471722015-04-20 15:20:28 -070099 /* Determine TSEG data */
100 smm_region(&smm_base, &smm_size);
Kyösti Mälkki14222d82019-08-05 15:10:18 +0300101 tseg_base_k = RES_IN_KIB(smm_base);
Lee Leahy32471722015-04-20 15:20:28 -0700102 tseg_top_k = tseg_base_k + RES_IN_KIB(smm_size);
103
104 /* Determine the base of the FSP reserved memory */
Frans Hendriksc6d672f2018-10-30 15:07:39 +0100105 fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY);
106 if (fsp_reserved_memory_area) {
107 fsp_res_base_k =
108 RES_IN_KIB((unsigned int)fsp_reserved_memory_area);
109 } else {
110 /* If no FSP reserverd area */
111 fsp_res_base_k = tseg_base_k;
112 }
Lee Leahy32471722015-04-20 15:20:28 -0700113
Lee Leahy77ff0b12015-05-05 15:07:29 -0700114 /* PCIe memory-mapped config space access - 256 MiB. */
115 mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1);
Lee Leahy32471722015-04-20 15:20:28 -0700116 mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KIB(mmconf), 256 * 1024);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700117
118 /* 0 -> 0xa0000 */
Lee Leahy32471722015-04-20 15:20:28 -0700119 base_k = RES_IN_KIB(0);
120 size_k = RES_IN_KIB(0xa0000) - base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700121 ram_resource(dev, index++, base_k, size_k);
122
Frans Hendriksc6d672f2018-10-30 15:07:39 +0100123 /* High memory -> fsp_res_base - cacheable and usable */
124 base_k = RES_IN_KIB(0x100000);
Lee Leahy32471722015-04-20 15:20:28 -0700125 size_k = fsp_res_base_k - base_k;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700126 ram_resource(dev, index++, base_k, size_k);
127
Lee Leahy32471722015-04-20 15:20:28 -0700128 /* fsp_res_base -> tseg_top - Reserved */
129 base_k = fsp_res_base_k;
130 size_k = tseg_top_k - base_k;
131 reserved_ram_resource(dev, index++, base_k, size_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700132
Lee Leahy32471722015-04-20 15:20:28 -0700133 /* TSEG TOP -> bmbound is memory backed mmio. */
134 bmbound_k = RES_IN_KIB(nc_read_top_of_low_memory());
135 mmio_resource(dev, index++, tseg_top_k, bmbound_k - tseg_top_k);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700136
Lee Leahy32471722015-04-20 15:20:28 -0700137 /*
138 * The BMBOUND_HI register matches register bits of 31:24 with address
139 * bits of 35:28. Therefore, shift register to align properly.
140 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700141 bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1);
Lee Leahy32471722015-04-20 15:20:28 -0700142 bmbound_hi = RES_IN_KIB(bmbound_hi) << 4;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700143 if (bmbound_hi > four_gig_kib)
144 ram_resource(dev, index++, four_gig_kib,
Lee Leahy32471722015-04-20 15:20:28 -0700145 bmbound_hi - four_gig_kib);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700146
Lee Leahy32471722015-04-20 15:20:28 -0700147 /*
148 * Reserve everything between A segment and 1MB:
Lee Leahy77ff0b12015-05-05 15:07:29 -0700149 *
150 * 0xa0000 - 0xbffff: legacy VGA
151 * 0xc0000 - 0xfffff: RAM
152 */
153 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
154 reserved_ram_resource(dev, index++, (0xc0000 >> 10),
Lee Leahy32471722015-04-20 15:20:28 -0700155 (0x100000 - 0xc0000) >> 10);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700156
Frans Hendriksd97eb642018-11-26 11:01:56 +0100157 /*
158 * Reserve local APIC
159 */
160 base_k = RES_IN_KIB(LAPIC_DEFAULT_BASE);
161 size_k = RES_IN_KIB(0x00100000);
162 mmio_resource(dev, index++, base_k, size_k);
163
Julius Wernercd49cce2019-03-05 16:53:33 -0800164 if (CONFIG(CHROMEOS))
Frans Hendriksed7780d2018-12-14 07:49:18 +0100165 chromeos_reserve_ram_oops(dev, index++);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700166}
167
168static struct device_operations nc_ops = {
Lee Leahy32471722015-04-20 15:20:28 -0700169 .acpi_fill_ssdt_generator = generate_cpu_entries,
170 .read_resources = nc_read_resources,
171 .ops_pci = &soc_pci_ops,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700172};
173
174static const struct pci_driver nc_driver __pci_driver = {
175 .ops = &nc_ops,
176 .vendor = PCI_VENDOR_ID_INTEL,
177 .device = SOC_DEVID,
178};