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