Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 4 | * |
| 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 Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 15 | #include <arch/acpi.h> |
| 16 | #include <cbmem.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 17 | #include <cpu/x86/smm.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
Frans Hendriks | d97eb64 | 2018-11-26 11:01:56 +0100 | [diff] [blame] | 21 | #include <cpu/x86/lapic.h> |
Kyösti Mälkki | b2a5f0b | 2019-08-04 19:54:32 +0300 | [diff] [blame] | 22 | #include <cpu/x86/smm.h> |
Aaron Durbin | 789f2b6 | 2015-09-09 17:05:06 -0500 | [diff] [blame] | 23 | #include <fsp/util.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 24 | #include <soc/iomap.h> |
| 25 | #include <soc/iosf.h> |
| 26 | #include <soc/pci_devs.h> |
| 27 | #include <soc/ramstage.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 28 | #include <vendorcode/google/chromeos/chromeos.h> |
Harry Pan | 43dcbfd | 2016-08-11 14:35:04 +0800 | [diff] [blame] | 29 | #include <stddef.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 30 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 31 | /* |
| 32 | * Host Memory Map: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 33 | * |
| 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 Hendriks | b81dcc6 | 2018-12-10 10:30:37 +0100 | [diff] [blame] | 53 | * coreboot's resource model: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 54 | * |
| 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 Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 67 | #define RES_IN_KIB(r) ((r) >> 10) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 68 | |
| 69 | uint32_t nc_read_top_of_low_memory(void) |
| 70 | { |
Kyösti Mälkki | 117cf2b | 2019-08-20 06:01:57 +0300 | [diff] [blame] | 71 | MAYBE_STATIC_BSS uint32_t tolm = 0; |
Harry Pan | 43dcbfd | 2016-08-11 14:35:04 +0800 | [diff] [blame] | 72 | |
| 73 | if (tolm) |
| 74 | return tolm; |
| 75 | |
| 76 | tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1); |
| 77 | |
| 78 | return tolm; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Elyes HAOUAS | b13fac3 | 2018-05-24 22:29:44 +0200 | [diff] [blame] | 81 | static void nc_read_resources(struct device *dev) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 82 | { |
| 83 | unsigned long mmconf; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 84 | unsigned long bmbound_k; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 85 | unsigned long bmbound_hi; |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 86 | uintptr_t smm_base; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 87 | size_t smm_size; |
| 88 | unsigned long tseg_base_k; |
| 89 | unsigned long tseg_top_k; |
| 90 | unsigned long fsp_res_base_k; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 91 | unsigned long base_k, size_k; |
| 92 | const unsigned long four_gig_kib = (4 << (30 - 10)); |
Frans Hendriks | c6d672f | 2018-10-30 15:07:39 +0100 | [diff] [blame] | 93 | void *fsp_reserved_memory_area; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 94 | int index = 0; |
| 95 | |
| 96 | /* Read standard PCI resources. */ |
| 97 | pci_dev_read_resources(dev); |
| 98 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 99 | /* Determine TSEG data */ |
| 100 | smm_region(&smm_base, &smm_size); |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 101 | tseg_base_k = RES_IN_KIB(smm_base); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 102 | tseg_top_k = tseg_base_k + RES_IN_KIB(smm_size); |
| 103 | |
| 104 | /* Determine the base of the FSP reserved memory */ |
Frans Hendriks | c6d672f | 2018-10-30 15:07:39 +0100 | [diff] [blame] | 105 | 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 Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 113 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 114 | /* PCIe memory-mapped config space access - 256 MiB. */ |
| 115 | mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 116 | mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KIB(mmconf), 256 * 1024); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 117 | |
| 118 | /* 0 -> 0xa0000 */ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 119 | base_k = RES_IN_KIB(0); |
| 120 | size_k = RES_IN_KIB(0xa0000) - base_k; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 121 | ram_resource(dev, index++, base_k, size_k); |
| 122 | |
Frans Hendriks | c6d672f | 2018-10-30 15:07:39 +0100 | [diff] [blame] | 123 | /* High memory -> fsp_res_base - cacheable and usable */ |
| 124 | base_k = RES_IN_KIB(0x100000); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 125 | size_k = fsp_res_base_k - base_k; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 126 | ram_resource(dev, index++, base_k, size_k); |
| 127 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 128 | /* 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 Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 132 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 133 | /* 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 Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 136 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 137 | /* |
| 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 Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 141 | bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 142 | bmbound_hi = RES_IN_KIB(bmbound_hi) << 4; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 143 | if (bmbound_hi > four_gig_kib) |
| 144 | ram_resource(dev, index++, four_gig_kib, |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 145 | bmbound_hi - four_gig_kib); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 146 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 147 | /* |
| 148 | * Reserve everything between A segment and 1MB: |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 149 | * |
| 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 Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 155 | (0x100000 - 0xc0000) >> 10); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 156 | |
Frans Hendriks | d97eb64 | 2018-11-26 11:01:56 +0100 | [diff] [blame] | 157 | /* |
| 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 Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 164 | if (CONFIG(CHROMEOS)) |
Frans Hendriks | ed7780d | 2018-12-14 07:49:18 +0100 | [diff] [blame] | 165 | chromeos_reserve_ram_oops(dev, index++); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static struct device_operations nc_ops = { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 169 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
| 170 | .read_resources = nc_read_resources, |
| 171 | .ops_pci = &soc_pci_ops, |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | static const struct pci_driver nc_driver __pci_driver = { |
| 175 | .ops = &nc_ops, |
| 176 | .vendor = PCI_VENDOR_ID_INTEL, |
| 177 | .device = SOC_DEVID, |
| 178 | }; |