Angel Pons | ba38f37 | 2020-04-05 15:46:45 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 4 | #include <cbmem.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 5 | #include <cpu/x86/smm.h> |
| 6 | #include <device/device.h> |
| 7 | #include <device/pci.h> |
| 8 | #include <device/pci_ids.h> |
Frans Hendriks | d97eb64 | 2018-11-26 11:01:56 +0100 | [diff] [blame] | 9 | #include <cpu/x86/lapic.h> |
Kyösti Mälkki | b2a5f0b | 2019-08-04 19:54:32 +0300 | [diff] [blame] | 10 | #include <cpu/x86/smm.h> |
Aaron Durbin | 789f2b6 | 2015-09-09 17:05:06 -0500 | [diff] [blame] | 11 | #include <fsp/util.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 12 | #include <soc/iomap.h> |
| 13 | #include <soc/iosf.h> |
| 14 | #include <soc/pci_devs.h> |
| 15 | #include <soc/ramstage.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 16 | #include <vendorcode/google/chromeos/chromeos.h> |
Harry Pan | 43dcbfd | 2016-08-11 14:35:04 +0800 | [diff] [blame] | 17 | #include <stddef.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 18 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 19 | /* |
| 20 | * Host Memory Map: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 21 | * |
| 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 Hendriks | b81dcc6 | 2018-12-10 10:30:37 +0100 | [diff] [blame] | 41 | * coreboot's resource model: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 42 | * |
| 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 | */ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 55 | #define RES_IN_KIB(r) ((r) >> 10) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 56 | |
| 57 | uint32_t nc_read_top_of_low_memory(void) |
| 58 | { |
Kyösti Mälkki | fcbbb91 | 2020-04-20 10:21:39 +0300 | [diff] [blame] | 59 | static uint32_t tolm; |
Harry Pan | 43dcbfd | 2016-08-11 14:35:04 +0800 | [diff] [blame] | 60 | |
| 61 | if (tolm) |
| 62 | return tolm; |
| 63 | |
| 64 | tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1); |
| 65 | |
| 66 | return tolm; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 69 | static void nc_read_resources(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 70 | { |
| 71 | unsigned long mmconf; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 72 | unsigned long bmbound_k; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 73 | unsigned long bmbound_hi; |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 74 | uintptr_t smm_base; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 75 | size_t smm_size; |
| 76 | unsigned long tseg_base_k; |
| 77 | unsigned long tseg_top_k; |
| 78 | unsigned long fsp_res_base_k; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 79 | unsigned long base_k, size_k; |
| 80 | const unsigned long four_gig_kib = (4 << (30 - 10)); |
Frans Hendriks | c6d672f | 2018-10-30 15:07:39 +0100 | [diff] [blame] | 81 | void *fsp_reserved_memory_area; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 82 | int index = 0; |
| 83 | |
| 84 | /* Read standard PCI resources. */ |
| 85 | pci_dev_read_resources(dev); |
| 86 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 87 | /* Determine TSEG data */ |
| 88 | smm_region(&smm_base, &smm_size); |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 89 | tseg_base_k = RES_IN_KIB(smm_base); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 90 | tseg_top_k = tseg_base_k + RES_IN_KIB(smm_size); |
| 91 | |
| 92 | /* Determine the base of the FSP reserved memory */ |
Frans Hendriks | c6d672f | 2018-10-30 15:07:39 +0100 | [diff] [blame] | 93 | fsp_reserved_memory_area = cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY); |
| 94 | if (fsp_reserved_memory_area) { |
| 95 | fsp_res_base_k = |
| 96 | RES_IN_KIB((unsigned int)fsp_reserved_memory_area); |
| 97 | } else { |
| 98 | /* If no FSP reserverd area */ |
| 99 | fsp_res_base_k = tseg_base_k; |
| 100 | } |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 101 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 102 | /* PCIe memory-mapped config space access - 256 MiB. */ |
| 103 | mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 104 | mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KIB(mmconf), 256 * 1024); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 105 | |
| 106 | /* 0 -> 0xa0000 */ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 107 | base_k = RES_IN_KIB(0); |
| 108 | size_k = RES_IN_KIB(0xa0000) - base_k; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 109 | ram_resource(dev, index++, base_k, size_k); |
| 110 | |
Frans Hendriks | c6d672f | 2018-10-30 15:07:39 +0100 | [diff] [blame] | 111 | /* High memory -> fsp_res_base - cacheable and usable */ |
| 112 | base_k = RES_IN_KIB(0x100000); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 113 | size_k = fsp_res_base_k - base_k; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 114 | ram_resource(dev, index++, base_k, size_k); |
| 115 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 116 | /* fsp_res_base -> tseg_top - Reserved */ |
| 117 | base_k = fsp_res_base_k; |
| 118 | size_k = tseg_top_k - base_k; |
| 119 | reserved_ram_resource(dev, index++, base_k, size_k); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 120 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 121 | /* TSEG TOP -> bmbound is memory backed mmio. */ |
| 122 | bmbound_k = RES_IN_KIB(nc_read_top_of_low_memory()); |
| 123 | mmio_resource(dev, index++, tseg_top_k, bmbound_k - tseg_top_k); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 124 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 125 | /* |
| 126 | * The BMBOUND_HI register matches register bits of 31:24 with address |
| 127 | * bits of 35:28. Therefore, shift register to align properly. |
| 128 | */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 129 | bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 130 | bmbound_hi = RES_IN_KIB(bmbound_hi) << 4; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 131 | if (bmbound_hi > four_gig_kib) |
| 132 | ram_resource(dev, index++, four_gig_kib, |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 133 | bmbound_hi - four_gig_kib); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 134 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 135 | /* |
| 136 | * Reserve everything between A segment and 1MB: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 137 | * |
| 138 | * 0xa0000 - 0xbffff: legacy VGA |
| 139 | * 0xc0000 - 0xfffff: RAM |
| 140 | */ |
| 141 | mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10); |
| 142 | reserved_ram_resource(dev, index++, (0xc0000 >> 10), |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 143 | (0x100000 - 0xc0000) >> 10); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 144 | |
Frans Hendriks | d97eb64 | 2018-11-26 11:01:56 +0100 | [diff] [blame] | 145 | /* |
| 146 | * Reserve local APIC |
| 147 | */ |
| 148 | base_k = RES_IN_KIB(LAPIC_DEFAULT_BASE); |
| 149 | size_k = RES_IN_KIB(0x00100000); |
| 150 | mmio_resource(dev, index++, base_k, size_k); |
| 151 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 152 | if (CONFIG(CHROMEOS)) |
Frans Hendriks | ed7780d | 2018-12-14 07:49:18 +0100 | [diff] [blame] | 153 | chromeos_reserve_ram_oops(dev, index++); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static struct device_operations nc_ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 157 | .acpi_fill_ssdt = generate_cpu_entries, |
| 158 | .read_resources = nc_read_resources, |
| 159 | .ops_pci = &soc_pci_ops, |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | static const struct pci_driver nc_driver __pci_driver = { |
| 163 | .ops = &nc_ops, |
| 164 | .vendor = PCI_VENDOR_ID_INTEL, |
| 165 | .device = SOC_DEVID, |
| 166 | }; |