Angel Pons | c3f58f6 | 2020-04-05 15:46:41 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 2 | |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 3 | #include <device/device.h> |
| 4 | #include <device/pci.h> |
| 5 | #include <device/pci_ids.h> |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 6 | #include <vendorcode/google/chromeos/chromeos.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 7 | #include <acpi/acpi.h> |
Elyes HAOUAS | eb7e166 | 2020-07-10 10:49:26 +0200 | [diff] [blame] | 8 | #include <stdint.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 9 | #include <soc/iomap.h> |
| 10 | #include <soc/iosf.h> |
| 11 | #include <soc/pci_devs.h> |
| 12 | #include <soc/ramstage.h> |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 13 | |
Angel Pons | 26b49cc | 2020-07-07 17:17:51 +0200 | [diff] [blame] | 14 | /* |
| 15 | * Host Memory Map: |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 16 | * |
| 17 | * +--------------------------+ BMBOUND_HI |
| 18 | * | Usable DRAM | |
| 19 | * +--------------------------+ 4GiB |
| 20 | * | PCI Address Space | |
| 21 | * +--------------------------+ BMBOUND |
| 22 | * | TPM | |
| 23 | * +--------------------------+ IMR2 |
| 24 | * | TXE | |
| 25 | * +--------------------------+ IMR1 |
| 26 | * | iGD | |
| 27 | * +--------------------------+ |
| 28 | * | GTT | |
| 29 | * +--------------------------+ SMMRRH, IRM0 |
| 30 | * | TSEG | |
| 31 | * +--------------------------+ SMMRRL |
| 32 | * | Usable DRAM | |
| 33 | * +--------------------------+ 0 |
| 34 | * |
| 35 | * Note that there are really only a few regions that need to enumerated w.r.t. |
Martin Roth | 99a3bba | 2014-12-07 14:57:26 -0700 | [diff] [blame] | 36 | * coreboot's resource model: |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 37 | * |
| 38 | * +--------------------------+ BMBOUND_HI |
| 39 | * | Cacheable/Usable | |
| 40 | * +--------------------------+ 4GiB |
| 41 | * |
| 42 | * +--------------------------+ BMBOUND |
| 43 | * | Uncacheable/Reserved | |
| 44 | * +--------------------------+ SMMRRH |
| 45 | * | Cacheable/Reserved | |
| 46 | * +--------------------------+ SMMRRL |
| 47 | * | Cacheable/Usable | |
| 48 | * +--------------------------+ 0 |
| 49 | */ |
| 50 | #define RES_IN_KiB(r) ((r) >> 10) |
| 51 | |
Duncan Laurie | 1f52f51 | 2013-11-04 17:02:45 -0800 | [diff] [blame] | 52 | uint32_t nc_read_top_of_low_memory(void) |
| 53 | { |
Kyösti Mälkki | fcbbb91 | 2020-04-20 10:21:39 +0300 | [diff] [blame] | 54 | static uint32_t tolm; |
Matt DeVillier | f05d2e1 | 2017-06-06 23:56:18 -0500 | [diff] [blame] | 55 | |
| 56 | if (tolm) |
| 57 | return tolm; |
| 58 | |
| 59 | tolm = iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1); |
| 60 | |
| 61 | return tolm; |
Duncan Laurie | 1f52f51 | 2013-11-04 17:02:45 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 64 | static void nc_read_resources(struct device *dev) |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 65 | { |
| 66 | unsigned long mmconf; |
| 67 | unsigned long bmbound; |
| 68 | unsigned long bmbound_hi; |
| 69 | unsigned long smmrrh; |
| 70 | unsigned long smmrrl; |
| 71 | unsigned long base_k, size_k; |
| 72 | const unsigned long four_gig_kib = (4 << (30 - 10)); |
| 73 | int index = 0; |
| 74 | |
| 75 | /* Read standard PCI resources. */ |
| 76 | pci_dev_read_resources(dev); |
| 77 | |
| 78 | /* PCIe memory-mapped config space access - 256 MiB. */ |
| 79 | mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1); |
| 80 | mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024); |
| 81 | |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 82 | /* 0 -> 0xa0000 */ |
| 83 | base_k = RES_IN_KiB(0); |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 84 | size_k = RES_IN_KiB(0xa0000) - base_k; |
| 85 | ram_resource(dev, index++, base_k, size_k); |
| 86 | |
| 87 | /* The SMMRR registers are 1MiB granularity with smmrrh being |
| 88 | * inclusive of the SMM region. */ |
| 89 | smmrrl = (iosf_bunit_read(BUNIT_SMRRL) & 0xffff) << 10; |
| 90 | smmrrh = ((iosf_bunit_read(BUNIT_SMRRH) & 0xffff) + 1) << 10; |
| 91 | |
| 92 | /* 0xc0000 -> smrrl - cacheable and usable */ |
| 93 | base_k = RES_IN_KiB(0xc0000); |
| 94 | size_k = smmrrl - base_k; |
| 95 | ram_resource(dev, index++, base_k, size_k); |
| 96 | |
| 97 | if (smmrrh > smmrrl) |
| 98 | reserved_ram_resource(dev, index++, smmrrl, smmrrh - smmrrl); |
| 99 | |
| 100 | /* All address space between bmbound and smmrrh is unusable. */ |
Duncan Laurie | 1f52f51 | 2013-11-04 17:02:45 -0800 | [diff] [blame] | 101 | bmbound = RES_IN_KiB(nc_read_top_of_low_memory()); |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 102 | mmio_resource(dev, index++, smmrrh, bmbound - smmrrh); |
| 103 | |
| 104 | /* The BMBOUND_HI register matches register bits of 31:24 with address |
| 105 | * bits of 35:28. Therefore, shift register to align properly. */ |
| 106 | bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1); |
| 107 | bmbound_hi = RES_IN_KiB(bmbound_hi) << 4; |
| 108 | if (bmbound_hi > four_gig_kib) |
| 109 | ram_resource(dev, index++, four_gig_kib, |
| 110 | bmbound_hi - four_gig_kib); |
Duncan Laurie | e7e78d6 | 2013-11-03 19:38:12 -0800 | [diff] [blame] | 111 | |
| 112 | /* Reserve everything between A segment and 1MB: |
| 113 | * |
| 114 | * 0xa0000 - 0xbffff: legacy VGA |
| 115 | * 0xc0000 - 0xfffff: RAM |
| 116 | */ |
| 117 | mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10); |
| 118 | reserved_ram_resource(dev, index++, (0xc0000 >> 10), |
| 119 | (0x100000 - 0xc0000) >> 10); |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 120 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 121 | if (CONFIG(CHROMEOS)) |
Frans Hendriks | ef05dc8 | 2018-11-27 10:35:16 +0100 | [diff] [blame] | 122 | chromeos_reserve_ram_oops(dev, index++); |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 123 | } |
| 124 | |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 125 | static struct device_operations nc_ops = { |
| 126 | .read_resources = nc_read_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 127 | .acpi_fill_ssdt = generate_cpu_entries, |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 128 | .ops_pci = &soc_pci_ops, |
| 129 | }; |
| 130 | |
| 131 | static const struct pci_driver nc_driver __pci_driver = { |
| 132 | .ops = &nc_ops, |
| 133 | .vendor = PCI_VENDOR_ID_INTEL, |
| 134 | .device = SOC_DEVID, |
| 135 | }; |