Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * Copyright (C) 2015 Damien Zammit <damien@zamaudio.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 17 | #include <cbmem.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 18 | #include <console/console.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 19 | #include <device/pci_ops.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 23 | #include <stdlib.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 24 | #include <boot/tables.h> |
| 25 | #include <arch/acpi.h> |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 26 | #include <northbridge/intel/x4x/iomap.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 27 | #include <northbridge/intel/x4x/chip.h> |
| 28 | #include <northbridge/intel/x4x/x4x.h> |
Kyösti Mälkki | f091f4d | 2019-08-14 03:49:21 +0300 | [diff] [blame] | 29 | #include <cpu/intel/smm_reloc.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 30 | |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 31 | static const int legacy_hole_base_k = 0xa0000 / 1024; |
| 32 | |
Elyes HAOUAS | fea02e1 | 2018-02-08 14:59:03 +0100 | [diff] [blame] | 33 | static void mch_domain_read_resources(struct device *dev) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 34 | { |
Arthur Heymans | 4c65bfc | 2018-04-10 13:34:24 +0200 | [diff] [blame] | 35 | u8 index; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 36 | u64 tom, touud; |
Arthur Heymans | 4c65bfc | 2018-04-10 13:34:24 +0200 | [diff] [blame] | 37 | u32 tomk, tolud, delta_cbmem; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 38 | u32 pcie_config_base, pcie_config_size; |
| 39 | u32 uma_sizek = 0; |
| 40 | |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 41 | const u32 top32memk = 4 * (GiB / KiB); |
| 42 | index = 3; |
| 43 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 44 | pci_domain_read_resources(dev); |
| 45 | |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 46 | struct device *mch = pcidev_on_root(0, 0); |
Arthur Heymans | c6e13b6 | 2018-06-26 21:06:38 +0200 | [diff] [blame] | 47 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 48 | /* Top of Upper Usable DRAM, including remap */ |
Arthur Heymans | c6e13b6 | 2018-06-26 21:06:38 +0200 | [diff] [blame] | 49 | touud = pci_read_config16(mch, D0F0_TOUUD); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 50 | touud <<= 20; |
| 51 | |
| 52 | /* Top of Lower Usable DRAM */ |
Arthur Heymans | c6e13b6 | 2018-06-26 21:06:38 +0200 | [diff] [blame] | 53 | tolud = pci_read_config16(mch, D0F0_TOLUD) & 0xfff0; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 54 | tolud <<= 16; |
| 55 | |
| 56 | /* Top of Memory - does not account for any UMA */ |
Arthur Heymans | c6e13b6 | 2018-06-26 21:06:38 +0200 | [diff] [blame] | 57 | tom = pci_read_config16(mch, D0F0_TOM) & 0x01ff; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 58 | tom <<= 26; |
| 59 | |
| 60 | printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n", |
| 61 | touud, tolud, tom); |
| 62 | |
| 63 | tomk = tolud >> 10; |
| 64 | |
| 65 | /* Graphics memory comes next */ |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 66 | |
Arthur Heymans | c6e13b6 | 2018-06-26 21:06:38 +0200 | [diff] [blame] | 67 | const u16 ggc = pci_read_config16(mch, D0F0_GGC); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 68 | printk(BIOS_DEBUG, "IGD decoded, subtracting "); |
| 69 | |
| 70 | /* Graphics memory */ |
| 71 | const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf); |
| 72 | printk(BIOS_DEBUG, "%uM UMA", gms_sizek >> 10); |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 73 | tomk -= gms_sizek; |
| 74 | uma_sizek += gms_sizek; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 75 | |
| 76 | /* GTT Graphics Stolen Memory Size (GGMS) */ |
| 77 | const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf); |
| 78 | printk(BIOS_DEBUG, " and %uM GTT\n", gsm_sizek >> 10); |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 79 | tomk -= gsm_sizek; |
| 80 | uma_sizek += gsm_sizek; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 81 | |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 82 | printk(BIOS_DEBUG, "TSEG decoded, subtracting "); |
Arthur Heymans | 4c65bfc | 2018-04-10 13:34:24 +0200 | [diff] [blame] | 83 | const u32 tseg_sizek = decode_tseg_size( |
| 84 | pci_read_config8(dev, D0F0_ESMRAMC)) >> 10; |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 85 | uma_sizek += tseg_sizek; |
| 86 | tomk -= tseg_sizek; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 87 | |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 88 | printk(BIOS_DEBUG, "%dM\n", tseg_sizek >> 10); |
| 89 | |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 90 | /* cbmem_top can be shifted downwards due to alignment. |
| 91 | Mark the region between cbmem_top and tomk as unusable */ |
| 92 | delta_cbmem = tomk - ((uint32_t)cbmem_top() >> 10); |
| 93 | tomk -= delta_cbmem; |
| 94 | uma_sizek += delta_cbmem; |
| 95 | |
| 96 | printk(BIOS_DEBUG, "Unused RAM between cbmem_top and TOM: 0x%xK\n", |
| 97 | delta_cbmem); |
| 98 | |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 99 | printk(BIOS_INFO, "Available memory below 4GB: %uM\n", tomk >> 10); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 100 | |
| 101 | /* Report the memory regions */ |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 102 | ram_resource(dev, index++, 0, legacy_hole_base_k); |
| 103 | mmio_resource(dev, index++, legacy_hole_base_k, |
| 104 | (0xc0000 >> 10) - legacy_hole_base_k); |
| 105 | reserved_ram_resource(dev, index++, 0xc0000 >> 10, |
| 106 | (0x100000 - 0xc0000) >> 10); |
| 107 | ram_resource(dev, index++, 0x100000 >> 10, (tomk - (0x100000 >> 10))); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * If >= 4GB installed then memory from TOLUD to 4GB |
| 111 | * is remapped above TOM, TOUUD will account for both |
| 112 | */ |
| 113 | touud >>= 10; /* Convert to KB */ |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 114 | if (touud > top32memk) { |
| 115 | ram_resource(dev, index++, top32memk, touud - top32memk); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 116 | printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 117 | (touud - top32memk) >> 10); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | printk(BIOS_DEBUG, "Adding UMA memory area base=0x%08x " |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 121 | "size=0x%08x\n", tomk << 10, uma_sizek << 10); |
| 122 | uma_resource(dev, index++, tomk, uma_sizek); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 123 | |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 124 | /* Reserve high memory where the NB BARs are up to 4GiB */ |
| 125 | fixed_mem_resource(dev, index++, DEFAULT_HECIBAR >> 10, |
| 126 | top32memk - (DEFAULT_HECIBAR >> 10), |
| 127 | IORESOURCE_RESERVE); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 128 | |
| 129 | if (decode_pciebar(&pcie_config_base, &pcie_config_size)) { |
| 130 | printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x " |
| 131 | "size=0x%x\n", pcie_config_base, pcie_config_size); |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 132 | fixed_mem_resource(dev, index++, pcie_config_base >> 10, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 133 | pcie_config_size >> 10, IORESOURCE_RESERVE); |
| 134 | } |
| 135 | } |
| 136 | |
Elyes HAOUAS | fea02e1 | 2018-02-08 14:59:03 +0100 | [diff] [blame] | 137 | static void mch_domain_set_resources(struct device *dev) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 138 | { |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 139 | struct resource *res; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 140 | |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 141 | for (res = dev->resource_list; res; res = res->next) |
| 142 | report_resource_stored(dev, res, ""); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 143 | |
| 144 | assign_resources(dev->link_list); |
| 145 | } |
| 146 | |
Elyes HAOUAS | fea02e1 | 2018-02-08 14:59:03 +0100 | [diff] [blame] | 147 | static void mch_domain_init(struct device *dev) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 148 | { |
| 149 | u32 reg32; |
| 150 | |
| 151 | /* Enable SERR */ |
| 152 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 153 | reg32 |= PCI_COMMAND_SERR; |
| 154 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 155 | } |
| 156 | |
Arthur Heymans | a8a9f34 | 2017-12-24 08:11:13 +0100 | [diff] [blame] | 157 | static const char *northbridge_acpi_name(const struct device *dev) |
| 158 | { |
| 159 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 160 | return "PCI0"; |
| 161 | |
| 162 | if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0) |
| 163 | return NULL; |
| 164 | |
| 165 | switch (dev->path.pci.devfn) { |
| 166 | case PCI_DEVFN(0, 0): |
| 167 | return "MCHC"; |
| 168 | } |
| 169 | |
| 170 | return NULL; |
| 171 | } |
| 172 | |
Arthur Heymans | 4c65bfc | 2018-04-10 13:34:24 +0200 | [diff] [blame] | 173 | void northbridge_write_smram(u8 smram) |
| 174 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 175 | struct device *dev = pcidev_on_root(0, 0); |
Arthur Heymans | 4c65bfc | 2018-04-10 13:34:24 +0200 | [diff] [blame] | 176 | |
| 177 | if (dev == NULL) |
| 178 | die("could not find pci 00:00.0!\n"); |
| 179 | |
| 180 | pci_write_config8(dev, D0F0_SMRAM, smram); |
| 181 | } |
| 182 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 183 | static struct device_operations pci_domain_ops = { |
| 184 | .read_resources = mch_domain_read_resources, |
| 185 | .set_resources = mch_domain_set_resources, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 186 | .init = mch_domain_init, |
| 187 | .scan_bus = pci_domain_scan_bus, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 188 | .write_acpi_tables = northbridge_write_acpi_tables, |
| 189 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Arthur Heymans | a8a9f34 | 2017-12-24 08:11:13 +0100 | [diff] [blame] | 190 | .acpi_name = northbridge_acpi_name, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 191 | }; |
| 192 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 193 | static struct device_operations cpu_bus_ops = { |
| 194 | .read_resources = DEVICE_NOOP, |
| 195 | .set_resources = DEVICE_NOOP, |
| 196 | .enable_resources = DEVICE_NOOP, |
Kyösti Mälkki | b3267e0 | 2019-08-13 16:44:04 +0300 | [diff] [blame] | 197 | .init = mp_cpu_bus_init, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 198 | }; |
| 199 | |
Elyes HAOUAS | fea02e1 | 2018-02-08 14:59:03 +0100 | [diff] [blame] | 200 | static void enable_dev(struct device *dev) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 201 | { |
| 202 | /* Set the operations if it is a special bus type */ |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 203 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 204 | dev->ops = &pci_domain_ops; |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 205 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 206 | dev->ops = &cpu_bus_ops; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static void x4x_init(void *const chip_info) |
| 210 | { |
| 211 | int dev, fn, bit_base; |
| 212 | |
Kyösti Mälkki | 98a9174 | 2018-05-21 21:29:16 +0300 | [diff] [blame] | 213 | struct device *const d0f0 = pcidev_on_root(0x0, 0); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 214 | |
| 215 | /* Hide internal functions based on devicetree info. */ |
Arthur Heymans | 293445a | 2017-02-27 21:45:07 +0100 | [diff] [blame] | 216 | for (dev = 6; dev > 0; --dev) { |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 217 | switch (dev) { |
Arthur Heymans | 293445a | 2017-02-27 21:45:07 +0100 | [diff] [blame] | 218 | case 6: /* PEG1: only on P45 */ |
| 219 | fn = 0; |
| 220 | bit_base = 13; |
| 221 | break; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 222 | case 3: /* ME */ |
| 223 | fn = 3; |
| 224 | bit_base = 6; |
| 225 | break; |
| 226 | case 2: /* IGD */ |
| 227 | fn = 1; |
| 228 | bit_base = 3; |
| 229 | break; |
Arthur Heymans | 293445a | 2017-02-27 21:45:07 +0100 | [diff] [blame] | 230 | case 1: /* PEG0 */ |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 231 | fn = 0; |
| 232 | bit_base = 1; |
| 233 | break; |
Arthur Heymans | 293445a | 2017-02-27 21:45:07 +0100 | [diff] [blame] | 234 | case 4: /* Nothing to do */ |
| 235 | case 5: |
| 236 | continue; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 237 | } |
| 238 | for (; fn >= 0; --fn) { |
| 239 | const struct device *const d = |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 240 | pcidev_on_root(dev, fn); |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 241 | if (!d || d->enabled) |
| 242 | continue; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 243 | const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN); |
| 244 | pci_write_config32(d0f0, D0F0_DEVEN, |
| 245 | deven & ~(1 << (bit_base + fn))); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN); |
| 250 | if (!(deven & (0xf << 6))) |
| 251 | pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14)); |
| 252 | } |
| 253 | |
| 254 | struct chip_operations northbridge_intel_x4x_ops = { |
| 255 | CHIP_NAME("Intel 4-Series Northbridge") |
| 256 | .enable_dev = enable_dev, |
| 257 | .init = x4x_init, |
| 258 | }; |