Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <cpu/x86/smm.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 21 | #include <vendorcode/google/chromeos/chromeos.h> |
Vladimir Serbinenko | 7fb149d | 2014-10-08 22:56:27 +0200 | [diff] [blame] | 22 | #include <arch/acpi.h> |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 23 | |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 24 | #include <soc/iomap.h> |
| 25 | #include <soc/iosf.h> |
| 26 | #include <soc/pci_devs.h> |
| 27 | #include <soc/ramstage.h> |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 28 | |
| 29 | /* Host Memory Map: |
| 30 | * |
| 31 | * +--------------------------+ BMBOUND_HI |
| 32 | * | Usable DRAM | |
| 33 | * +--------------------------+ 4GiB |
| 34 | * | PCI Address Space | |
| 35 | * +--------------------------+ BMBOUND |
| 36 | * | TPM | |
| 37 | * +--------------------------+ IMR2 |
| 38 | * | TXE | |
| 39 | * +--------------------------+ IMR1 |
| 40 | * | iGD | |
| 41 | * +--------------------------+ |
| 42 | * | GTT | |
| 43 | * +--------------------------+ SMMRRH, IRM0 |
| 44 | * | TSEG | |
| 45 | * +--------------------------+ SMMRRL |
| 46 | * | Usable DRAM | |
| 47 | * +--------------------------+ 0 |
| 48 | * |
| 49 | * 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] | 50 | * coreboot's resource model: |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 51 | * |
| 52 | * +--------------------------+ BMBOUND_HI |
| 53 | * | Cacheable/Usable | |
| 54 | * +--------------------------+ 4GiB |
| 55 | * |
| 56 | * +--------------------------+ BMBOUND |
| 57 | * | Uncacheable/Reserved | |
| 58 | * +--------------------------+ SMMRRH |
| 59 | * | Cacheable/Reserved | |
| 60 | * +--------------------------+ SMMRRL |
| 61 | * | Cacheable/Usable | |
| 62 | * +--------------------------+ 0 |
| 63 | */ |
| 64 | #define RES_IN_KiB(r) ((r) >> 10) |
| 65 | |
Duncan Laurie | 1f52f51 | 2013-11-04 17:02:45 -0800 | [diff] [blame] | 66 | uint32_t nc_read_top_of_low_memory(void) |
| 67 | { |
| 68 | return iosf_bunit_read(BUNIT_BMBOUND) & ~((1 << 27) - 1); |
| 69 | } |
| 70 | |
Aaron Durbin | eb2eedf | 2013-10-25 09:12:45 -0500 | [diff] [blame] | 71 | static void nc_read_resources(device_t dev) |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 72 | { |
| 73 | unsigned long mmconf; |
| 74 | unsigned long bmbound; |
| 75 | unsigned long bmbound_hi; |
| 76 | unsigned long smmrrh; |
| 77 | unsigned long smmrrl; |
| 78 | unsigned long base_k, size_k; |
| 79 | const unsigned long four_gig_kib = (4 << (30 - 10)); |
| 80 | int index = 0; |
| 81 | |
| 82 | /* Read standard PCI resources. */ |
| 83 | pci_dev_read_resources(dev); |
| 84 | |
| 85 | /* PCIe memory-mapped config space access - 256 MiB. */ |
| 86 | mmconf = iosf_bunit_read(BUNIT_MMCONF_REG) & ~((1 << 28) - 1); |
| 87 | mmio_resource(dev, BUNIT_MMCONF_REG, RES_IN_KiB(mmconf), 256 * 1024); |
| 88 | |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 89 | /* 0 -> 0xa0000 */ |
| 90 | base_k = RES_IN_KiB(0); |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 91 | size_k = RES_IN_KiB(0xa0000) - base_k; |
| 92 | ram_resource(dev, index++, base_k, size_k); |
| 93 | |
| 94 | /* The SMMRR registers are 1MiB granularity with smmrrh being |
| 95 | * inclusive of the SMM region. */ |
| 96 | smmrrl = (iosf_bunit_read(BUNIT_SMRRL) & 0xffff) << 10; |
| 97 | smmrrh = ((iosf_bunit_read(BUNIT_SMRRH) & 0xffff) + 1) << 10; |
| 98 | |
| 99 | /* 0xc0000 -> smrrl - cacheable and usable */ |
| 100 | base_k = RES_IN_KiB(0xc0000); |
| 101 | size_k = smmrrl - base_k; |
| 102 | ram_resource(dev, index++, base_k, size_k); |
| 103 | |
| 104 | if (smmrrh > smmrrl) |
| 105 | reserved_ram_resource(dev, index++, smmrrl, smmrrh - smmrrl); |
| 106 | |
| 107 | /* All address space between bmbound and smmrrh is unusable. */ |
Duncan Laurie | 1f52f51 | 2013-11-04 17:02:45 -0800 | [diff] [blame] | 108 | bmbound = RES_IN_KiB(nc_read_top_of_low_memory()); |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 109 | mmio_resource(dev, index++, smmrrh, bmbound - smmrrh); |
| 110 | |
| 111 | /* The BMBOUND_HI register matches register bits of 31:24 with address |
| 112 | * bits of 35:28. Therefore, shift register to align properly. */ |
| 113 | bmbound_hi = iosf_bunit_read(BUNIT_BMBOUND_HI) & ~((1 << 24) - 1); |
| 114 | bmbound_hi = RES_IN_KiB(bmbound_hi) << 4; |
| 115 | if (bmbound_hi > four_gig_kib) |
| 116 | ram_resource(dev, index++, four_gig_kib, |
| 117 | bmbound_hi - four_gig_kib); |
Duncan Laurie | e7e78d6 | 2013-11-03 19:38:12 -0800 | [diff] [blame] | 118 | |
| 119 | /* Reserve everything between A segment and 1MB: |
| 120 | * |
| 121 | * 0xa0000 - 0xbffff: legacy VGA |
| 122 | * 0xc0000 - 0xfffff: RAM |
| 123 | */ |
| 124 | mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10); |
| 125 | reserved_ram_resource(dev, index++, (0xc0000 >> 10), |
| 126 | (0x100000 - 0xc0000) >> 10); |
Kein Yuan | 3511023 | 2014-02-22 12:26:55 -0800 | [diff] [blame] | 127 | |
| 128 | chromeos_reserve_ram_oops(dev, index++); |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 129 | } |
| 130 | |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 131 | static struct device_operations nc_ops = { |
| 132 | .read_resources = nc_read_resources, |
Vladimir Serbinenko | 7fb149d | 2014-10-08 22:56:27 +0200 | [diff] [blame] | 133 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Aaron Durbin | 191570d | 2013-09-24 12:41:08 -0500 | [diff] [blame] | 134 | .set_resources = NULL, |
| 135 | .enable_resources = NULL, |
| 136 | .init = NULL, |
| 137 | .enable = NULL, |
| 138 | .scan_bus = NULL, |
| 139 | .ops_pci = &soc_pci_ops, |
| 140 | }; |
| 141 | |
| 142 | static const struct pci_driver nc_driver __pci_driver = { |
| 143 | .ops = &nc_ops, |
| 144 | .vendor = PCI_VENDOR_ID_INTEL, |
| 145 | .device = SOC_DEVID, |
| 146 | }; |