Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 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. |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <arch/io.h> |
| 18 | #include <stdint.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 24 | #include <cpu/cpu.h> |
| 25 | #include <boot/tables.h> |
| 26 | #include <arch/acpi.h> |
| 27 | #include <cbmem.h> |
Arthur Heymans | aade90e | 2018-01-25 00:33:45 +0100 | [diff] [blame] | 28 | #include <cpu/intel/smm/gen1/smi.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 29 | #include "chip.h" |
| 30 | #include "gm45.h" |
Vladimir Serbinenko | 06667a5 | 2014-08-12 09:07:13 +0200 | [diff] [blame] | 31 | #include "arch/acpi.h" |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 32 | |
Vladimir Serbinenko | 8c22057 | 2014-08-16 14:18:21 +0200 | [diff] [blame] | 33 | /* Reserve segments A and B: |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 34 | * |
| 35 | * 0xa0000 - 0xbffff: legacy VGA |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 36 | */ |
| 37 | static const int legacy_hole_base_k = 0xa0000 / 1024; |
Vladimir Serbinenko | 8c22057 | 2014-08-16 14:18:21 +0200 | [diff] [blame] | 38 | static const int legacy_hole_size_k = 128; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 39 | |
| 40 | static int decode_pcie_bar(u32 *const base, u32 *const len) |
| 41 | { |
| 42 | *base = 0; |
| 43 | *len = 0; |
| 44 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 45 | struct device *dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 46 | if (!dev) |
| 47 | return 0; |
| 48 | |
| 49 | const u32 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO); |
| 50 | |
| 51 | if (!(pciexbar_reg & (1 << 0))) |
| 52 | return 0; |
| 53 | |
| 54 | switch ((pciexbar_reg >> 1) & 3) { |
| 55 | case 0: /* 256MB */ |
| 56 | *base = pciexbar_reg & (0x0f << 28); |
| 57 | *len = 256 * 1024 * 1024; |
| 58 | return 1; |
| 59 | case 1: /* 128M */ |
| 60 | *base = pciexbar_reg & (0x1f << 27); |
| 61 | *len = 128 * 1024 * 1024; |
| 62 | return 1; |
| 63 | case 2: /* 64M */ |
| 64 | *base = pciexbar_reg & (0x3f << 26); |
| 65 | *len = 64 * 1024 * 1024; |
| 66 | return 1; |
| 67 | } |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 72 | static void mch_domain_read_resources(struct device *dev) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 73 | { |
| 74 | u64 tom, touud; |
Nico Huber | ca3e121 | 2017-10-02 20:07:53 +0200 | [diff] [blame] | 75 | u32 tomk, tolud, uma_sizek = 0; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 76 | u32 pcie_config_base, pcie_config_size; |
| 77 | |
| 78 | /* Total Memory 2GB example: |
| 79 | * |
| 80 | * 00000000 0000MB-2014MB 2014MB RAM (writeback) |
| 81 | * 7de00000 2014MB-2016MB 2MB GFX GTT (uncached) |
| 82 | * 7e000000 2016MB-2048MB 32MB GFX UMA (uncached) |
| 83 | * 80000000 2048MB TOLUD |
| 84 | * 80000000 2048MB TOM |
| 85 | * |
| 86 | * Total Memory 4GB example: |
| 87 | * |
| 88 | * 00000000 0000MB-3038MB 3038MB RAM (writeback) |
| 89 | * bde00000 3038MB-3040MB 2MB GFX GTT (uncached) |
| 90 | * be000000 3040MB-3072MB 32MB GFX UMA (uncached) |
| 91 | * be000000 3072MB TOLUD |
| 92 | * 100000000 4096MB TOM |
| 93 | * 100000000 4096MB-5120MB 1024MB RAM (writeback) |
| 94 | * 140000000 5120MB TOUUD |
| 95 | */ |
| 96 | |
| 97 | pci_domain_read_resources(dev); |
| 98 | |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 99 | struct device *mch = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 100 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 101 | /* Top of Upper Usable DRAM, including remap */ |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 102 | touud = pci_read_config16(mch, D0F0_TOUUD); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 103 | touud <<= 20; |
| 104 | |
| 105 | /* Top of Lower Usable DRAM */ |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 106 | tolud = pci_read_config16(mch, D0F0_TOLUD) & 0xfff0; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 107 | tolud <<= 16; |
| 108 | |
| 109 | /* Top of Memory - does not account for any UMA */ |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 110 | tom = pci_read_config16(mch, D0F0_TOM) & 0x1ff; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 111 | tom <<= 27; |
| 112 | |
| 113 | printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n", |
| 114 | touud, tolud, tom); |
| 115 | |
| 116 | tomk = tolud >> 10; |
| 117 | |
| 118 | /* Graphics memory comes next */ |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 119 | const u16 ggc = pci_read_config16(mch, D0F0_GGC); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 120 | if (!(ggc & 2)) { |
| 121 | printk(BIOS_DEBUG, "IGD decoded, subtracting "); |
| 122 | |
| 123 | /* Graphics memory */ |
| 124 | const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf); |
Arthur Heymans | 8b76605 | 2018-01-24 23:25:13 +0100 | [diff] [blame] | 125 | printk(BIOS_DEBUG, "%uM UMA, ", gms_sizek >> 10); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 126 | tomk -= gms_sizek; |
| 127 | |
| 128 | /* GTT Graphics Stolen Memory Size (GGMS) */ |
| 129 | const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf); |
Arthur Heymans | 8b76605 | 2018-01-24 23:25:13 +0100 | [diff] [blame] | 130 | printk(BIOS_DEBUG, "%uM GTT", gsm_sizek >> 10); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 131 | tomk -= gsm_sizek; |
| 132 | |
| 133 | uma_sizek = gms_sizek + gsm_sizek; |
| 134 | } |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 135 | const u8 esmramc = pci_read_config8(mch, D0F0_ESMRAMC); |
Arthur Heymans | 8b76605 | 2018-01-24 23:25:13 +0100 | [diff] [blame] | 136 | const u32 tseg_sizek = decode_tseg_size(esmramc); |
| 137 | printk(BIOS_DEBUG, " and %uM TSEG\n", tseg_sizek >> 10); |
| 138 | tomk -= tseg_sizek; |
| 139 | uma_sizek += tseg_sizek; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 140 | |
Nico Huber | ca3e121 | 2017-10-02 20:07:53 +0200 | [diff] [blame] | 141 | printk(BIOS_INFO, "Available memory below 4GB: %uM\n", tomk >> 10); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 142 | |
| 143 | /* Report the memory regions */ |
| 144 | ram_resource(dev, 3, 0, legacy_hole_base_k); |
| 145 | ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k, |
Nico Huber | ca3e121 | 2017-10-02 20:07:53 +0200 | [diff] [blame] | 146 | (tomk - (legacy_hole_base_k + legacy_hole_size_k))); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 147 | |
| 148 | /* |
| 149 | * If >= 4GB installed then memory from TOLUD to 4GB |
| 150 | * is remapped above TOM, TOUUD will account for both |
| 151 | */ |
| 152 | touud >>= 10; /* Convert to KB */ |
| 153 | if (touud > 4096 * 1024) { |
| 154 | ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024)); |
| 155 | printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", |
| 156 | (touud >> 10) - 4096); |
| 157 | } |
| 158 | |
| 159 | printk(BIOS_DEBUG, "Adding UMA memory area base=0x%llx " |
| 160 | "size=0x%llx\n", ((u64)tomk) << 10, ((u64)uma_sizek) << 10); |
| 161 | /* Don't use uma_resource() as our UMA touches the PCI hole. */ |
| 162 | fixed_mem_resource(dev, 6, tomk, uma_sizek, IORESOURCE_RESERVE); |
| 163 | |
| 164 | if (decode_pcie_bar(&pcie_config_base, &pcie_config_size)) { |
| 165 | printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x " |
| 166 | "size=0x%x\n", pcie_config_base, pcie_config_size); |
| 167 | fixed_mem_resource(dev, 7, pcie_config_base >> 10, |
| 168 | pcie_config_size >> 10, IORESOURCE_RESERVE); |
| 169 | } |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 172 | static void mch_domain_set_resources(struct device *dev) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 173 | { |
| 174 | struct resource *resource; |
| 175 | int i; |
| 176 | |
| 177 | for (i = 3; i < 8; ++i) { |
| 178 | /* Report read resources. */ |
Vladimir Serbinenko | 40412c6 | 2014-11-12 00:09:20 +0100 | [diff] [blame] | 179 | resource = probe_resource(dev, i); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 180 | if (resource) |
| 181 | report_resource_stored(dev, resource, ""); |
| 182 | } |
| 183 | |
| 184 | assign_resources(dev->link_list); |
| 185 | } |
| 186 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 187 | static void mch_domain_init(struct device *dev) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 188 | { |
| 189 | u32 reg32; |
| 190 | |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 191 | struct device *mch = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 192 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 193 | /* Enable SERR */ |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 194 | reg32 = pci_read_config32(mch, PCI_COMMAND); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 195 | reg32 |= PCI_COMMAND_SERR; |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 196 | pci_write_config32(mch, PCI_COMMAND, reg32); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 197 | } |
| 198 | |
Arthur Heymans | e798e6a | 2017-12-23 23:09:54 +0100 | [diff] [blame] | 199 | static const char *northbridge_acpi_name(const struct device *dev) |
| 200 | { |
| 201 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 202 | return "PCI0"; |
| 203 | |
| 204 | if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0) |
| 205 | return NULL; |
| 206 | |
| 207 | switch (dev->path.pci.devfn) { |
| 208 | case PCI_DEVFN(0, 0): |
| 209 | return "MCHC"; |
| 210 | } |
| 211 | |
| 212 | return NULL; |
| 213 | } |
| 214 | |
Arthur Heymans | aade90e | 2018-01-25 00:33:45 +0100 | [diff] [blame] | 215 | u32 northbridge_get_tseg_base(void) |
| 216 | { |
| 217 | return (u32)smm_region_start(); |
| 218 | } |
| 219 | |
| 220 | u32 northbridge_get_tseg_size(void) |
| 221 | { |
| 222 | const u8 esmramc = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), |
| 223 | D0F0_ESMRAMC); |
| 224 | return decode_tseg_size(esmramc) << 10; |
| 225 | } |
| 226 | |
| 227 | void northbridge_write_smram(u8 smram) |
| 228 | { |
| 229 | pci_write_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), D0F0_SMRAM, smram); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * Really doesn't belong here but will go away with parallel mp init, |
| 234 | * so let it be here for a while... |
| 235 | */ |
| 236 | int cpu_get_apic_id_map(int *apic_id_map) |
| 237 | { |
| 238 | unsigned int i; |
| 239 | |
| 240 | /* Logical processors (threads) per core */ |
| 241 | const struct cpuid_result cpuid1 = cpuid(1); |
| 242 | /* Read number of cores. */ |
| 243 | const char cores = (cpuid1.ebx >> 16) & 0xf; |
| 244 | |
| 245 | /* TODO in parallel MP cpuid(1).ebx */ |
| 246 | for (i = 0; i < cores; i++) |
| 247 | apic_id_map[i] = i; |
| 248 | |
| 249 | return cores; |
| 250 | } |
| 251 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 252 | static struct device_operations pci_domain_ops = { |
| 253 | .read_resources = mch_domain_read_resources, |
| 254 | .set_resources = mch_domain_set_resources, |
| 255 | .enable_resources = NULL, |
| 256 | .init = mch_domain_init, |
| 257 | .scan_bus = pci_domain_scan_bus, |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 258 | .write_acpi_tables = northbridge_write_acpi_tables, |
| 259 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Arthur Heymans | e798e6a | 2017-12-23 23:09:54 +0100 | [diff] [blame] | 260 | .acpi_name = northbridge_acpi_name, |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 264 | static void cpu_bus_init(struct device *dev) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 265 | { |
| 266 | initialize_cpus(dev->link_list); |
| 267 | } |
| 268 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 269 | static struct device_operations cpu_bus_ops = { |
Edward O'Callaghan | 9f74462 | 2014-10-31 08:12:34 +1100 | [diff] [blame] | 270 | .read_resources = DEVICE_NOOP, |
| 271 | .set_resources = DEVICE_NOOP, |
| 272 | .enable_resources = DEVICE_NOOP, |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 273 | .init = cpu_bus_init, |
| 274 | .scan_bus = 0, |
| 275 | }; |
| 276 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 277 | static void enable_dev(struct device *dev) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 278 | { |
| 279 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 280 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 281 | dev->ops = &pci_domain_ops; |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 282 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 283 | dev->ops = &cpu_bus_ops; |
| 284 | } |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | static void gm45_init(void *const chip_info) |
| 288 | { |
| 289 | int dev, fn, bit_base; |
| 290 | |
| 291 | struct device *const d0f0 = dev_find_slot(0, 0); |
| 292 | |
| 293 | /* Hide internal functions based on devicetree info. */ |
| 294 | for (dev = 3; dev > 0; --dev) { |
| 295 | switch (dev) { |
| 296 | case 3: /* ME */ |
| 297 | fn = 3; |
| 298 | bit_base = 6; |
| 299 | break; |
| 300 | case 2: /* IGD */ |
| 301 | fn = 1; |
| 302 | bit_base = 3; |
| 303 | break; |
| 304 | case 1: /* PEG */ |
| 305 | fn = 0; |
| 306 | bit_base = 1; |
| 307 | break; |
| 308 | } |
| 309 | for (; fn >= 0; --fn) { |
| 310 | const struct device *const d = |
| 311 | dev_find_slot(0, PCI_DEVFN(dev, fn)); |
Nico Huber | 2dc15e9 | 2016-02-04 18:59:48 +0100 | [diff] [blame] | 312 | if (!d || d->enabled) continue; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 313 | const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN); |
| 314 | pci_write_config32(d0f0, D0F0_DEVEN, |
| 315 | deven & ~(1 << (bit_base + fn))); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN); |
| 320 | if (!(deven & (0xf << 6))) |
| 321 | pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14)); |
| 322 | } |
| 323 | |
| 324 | struct chip_operations northbridge_intel_gm45_ops = { |
| 325 | CHIP_NAME("Intel GM45 Northbridge") |
| 326 | .enable_dev = enable_dev, |
| 327 | .init = gm45_init, |
| 328 | }; |