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> |
| 28 | #include "chip.h" |
| 29 | #include "gm45.h" |
Vladimir Serbinenko | 06667a5 | 2014-08-12 09:07:13 +0200 | [diff] [blame] | 30 | #include "arch/acpi.h" |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 31 | |
Vladimir Serbinenko | 8c22057 | 2014-08-16 14:18:21 +0200 | [diff] [blame] | 32 | /* Reserve segments A and B: |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 33 | * |
| 34 | * 0xa0000 - 0xbffff: legacy VGA |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 35 | */ |
| 36 | static const int legacy_hole_base_k = 0xa0000 / 1024; |
Vladimir Serbinenko | 8c22057 | 2014-08-16 14:18:21 +0200 | [diff] [blame] | 37 | static const int legacy_hole_size_k = 128; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 38 | |
| 39 | static int decode_pcie_bar(u32 *const base, u32 *const len) |
| 40 | { |
| 41 | *base = 0; |
| 42 | *len = 0; |
| 43 | |
| 44 | const device_t dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 45 | if (!dev) |
| 46 | return 0; |
| 47 | |
| 48 | const u32 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO); |
| 49 | |
| 50 | if (!(pciexbar_reg & (1 << 0))) |
| 51 | return 0; |
| 52 | |
| 53 | switch ((pciexbar_reg >> 1) & 3) { |
| 54 | case 0: /* 256MB */ |
| 55 | *base = pciexbar_reg & (0x0f << 28); |
| 56 | *len = 256 * 1024 * 1024; |
| 57 | return 1; |
| 58 | case 1: /* 128M */ |
| 59 | *base = pciexbar_reg & (0x1f << 27); |
| 60 | *len = 128 * 1024 * 1024; |
| 61 | return 1; |
| 62 | case 2: /* 64M */ |
| 63 | *base = pciexbar_reg & (0x3f << 26); |
| 64 | *len = 64 * 1024 * 1024; |
| 65 | return 1; |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | static void mch_domain_read_resources(device_t dev) |
| 72 | { |
| 73 | u64 tom, touud; |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 74 | u32 tomk, tolud, uma_sizek = 0, usable_tomk; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 75 | u32 pcie_config_base, pcie_config_size; |
| 76 | |
| 77 | /* Total Memory 2GB example: |
| 78 | * |
| 79 | * 00000000 0000MB-2014MB 2014MB RAM (writeback) |
| 80 | * 7de00000 2014MB-2016MB 2MB GFX GTT (uncached) |
| 81 | * 7e000000 2016MB-2048MB 32MB GFX UMA (uncached) |
| 82 | * 80000000 2048MB TOLUD |
| 83 | * 80000000 2048MB TOM |
| 84 | * |
| 85 | * Total Memory 4GB example: |
| 86 | * |
| 87 | * 00000000 0000MB-3038MB 3038MB RAM (writeback) |
| 88 | * bde00000 3038MB-3040MB 2MB GFX GTT (uncached) |
| 89 | * be000000 3040MB-3072MB 32MB GFX UMA (uncached) |
| 90 | * be000000 3072MB TOLUD |
| 91 | * 100000000 4096MB TOM |
| 92 | * 100000000 4096MB-5120MB 1024MB RAM (writeback) |
| 93 | * 140000000 5120MB TOUUD |
| 94 | */ |
| 95 | |
| 96 | pci_domain_read_resources(dev); |
| 97 | |
| 98 | /* Top of Upper Usable DRAM, including remap */ |
| 99 | touud = pci_read_config16(dev, D0F0_TOUUD); |
| 100 | touud <<= 20; |
| 101 | |
| 102 | /* Top of Lower Usable DRAM */ |
| 103 | tolud = pci_read_config16(dev, D0F0_TOLUD) & 0xfff0; |
| 104 | tolud <<= 16; |
| 105 | |
| 106 | /* Top of Memory - does not account for any UMA */ |
| 107 | tom = pci_read_config16(dev, D0F0_TOM) & 0x1ff; |
| 108 | tom <<= 27; |
| 109 | |
| 110 | printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n", |
| 111 | touud, tolud, tom); |
| 112 | |
| 113 | tomk = tolud >> 10; |
| 114 | |
| 115 | /* Graphics memory comes next */ |
| 116 | const u16 ggc = pci_read_config16(dev, D0F0_GGC); |
| 117 | if (!(ggc & 2)) { |
| 118 | printk(BIOS_DEBUG, "IGD decoded, subtracting "); |
| 119 | |
| 120 | /* Graphics memory */ |
| 121 | const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf); |
| 122 | printk(BIOS_DEBUG, "%uM UMA", gms_sizek >> 10); |
| 123 | tomk -= gms_sizek; |
| 124 | |
| 125 | /* GTT Graphics Stolen Memory Size (GGMS) */ |
| 126 | const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf); |
| 127 | printk(BIOS_DEBUG, " and %uM GTT\n", gsm_sizek >> 10); |
| 128 | tomk -= gsm_sizek; |
| 129 | |
| 130 | uma_sizek = gms_sizek + gsm_sizek; |
| 131 | } |
| 132 | |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 133 | usable_tomk = ALIGN_DOWN(tomk, 64 << 10); |
| 134 | if (tomk - usable_tomk > (16 << 10)) |
| 135 | usable_tomk = tomk; |
| 136 | |
| 137 | printk(BIOS_INFO, "Available memory below 4GB: %uM\n", usable_tomk >> 10); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 138 | |
| 139 | /* Report the memory regions */ |
| 140 | ram_resource(dev, 3, 0, legacy_hole_base_k); |
| 141 | ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k, |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 142 | (usable_tomk - (legacy_hole_base_k + legacy_hole_size_k))); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 143 | |
| 144 | /* |
| 145 | * If >= 4GB installed then memory from TOLUD to 4GB |
| 146 | * is remapped above TOM, TOUUD will account for both |
| 147 | */ |
| 148 | touud >>= 10; /* Convert to KB */ |
| 149 | if (touud > 4096 * 1024) { |
| 150 | ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024)); |
| 151 | printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", |
| 152 | (touud >> 10) - 4096); |
| 153 | } |
| 154 | |
| 155 | printk(BIOS_DEBUG, "Adding UMA memory area base=0x%llx " |
| 156 | "size=0x%llx\n", ((u64)tomk) << 10, ((u64)uma_sizek) << 10); |
| 157 | /* Don't use uma_resource() as our UMA touches the PCI hole. */ |
| 158 | fixed_mem_resource(dev, 6, tomk, uma_sizek, IORESOURCE_RESERVE); |
| 159 | |
| 160 | if (decode_pcie_bar(&pcie_config_base, &pcie_config_size)) { |
| 161 | printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x " |
| 162 | "size=0x%x\n", pcie_config_base, pcie_config_size); |
| 163 | fixed_mem_resource(dev, 7, pcie_config_base >> 10, |
| 164 | pcie_config_size >> 10, IORESOURCE_RESERVE); |
| 165 | } |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static void mch_domain_set_resources(device_t dev) |
| 169 | { |
| 170 | struct resource *resource; |
| 171 | int i; |
| 172 | |
| 173 | for (i = 3; i < 8; ++i) { |
| 174 | /* Report read resources. */ |
Vladimir Serbinenko | 40412c6 | 2014-11-12 00:09:20 +0100 | [diff] [blame] | 175 | resource = probe_resource(dev, i); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 176 | if (resource) |
| 177 | report_resource_stored(dev, resource, ""); |
| 178 | } |
| 179 | |
| 180 | assign_resources(dev->link_list); |
| 181 | } |
| 182 | |
| 183 | static void mch_domain_init(device_t dev) |
| 184 | { |
| 185 | u32 reg32; |
| 186 | |
| 187 | /* Enable SERR */ |
| 188 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 189 | reg32 |= PCI_COMMAND_SERR; |
| 190 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 191 | } |
| 192 | |
| 193 | static struct device_operations pci_domain_ops = { |
| 194 | .read_resources = mch_domain_read_resources, |
| 195 | .set_resources = mch_domain_set_resources, |
| 196 | .enable_resources = NULL, |
| 197 | .init = mch_domain_init, |
| 198 | .scan_bus = pci_domain_scan_bus, |
Kyösti Mälkki | 872c922 | 2013-07-03 09:44:28 +0300 | [diff] [blame] | 199 | .ops_pci_bus = pci_bus_default_ops, |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 200 | .write_acpi_tables = northbridge_write_acpi_tables, |
| 201 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | |
| 205 | static void cpu_bus_init(device_t dev) |
| 206 | { |
| 207 | initialize_cpus(dev->link_list); |
| 208 | } |
| 209 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 210 | static struct device_operations cpu_bus_ops = { |
Edward O'Callaghan | 9f74462 | 2014-10-31 08:12:34 +1100 | [diff] [blame] | 211 | .read_resources = DEVICE_NOOP, |
| 212 | .set_resources = DEVICE_NOOP, |
| 213 | .enable_resources = DEVICE_NOOP, |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 214 | .init = cpu_bus_init, |
| 215 | .scan_bus = 0, |
| 216 | }; |
| 217 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 218 | static void enable_dev(device_t dev) |
| 219 | { |
| 220 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 221 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 222 | dev->ops = &pci_domain_ops; |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 223 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 224 | dev->ops = &cpu_bus_ops; |
| 225 | } |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static void gm45_init(void *const chip_info) |
| 229 | { |
| 230 | int dev, fn, bit_base; |
| 231 | |
| 232 | struct device *const d0f0 = dev_find_slot(0, 0); |
| 233 | |
| 234 | /* Hide internal functions based on devicetree info. */ |
| 235 | for (dev = 3; dev > 0; --dev) { |
| 236 | switch (dev) { |
| 237 | case 3: /* ME */ |
| 238 | fn = 3; |
| 239 | bit_base = 6; |
| 240 | break; |
| 241 | case 2: /* IGD */ |
| 242 | fn = 1; |
| 243 | bit_base = 3; |
| 244 | break; |
| 245 | case 1: /* PEG */ |
| 246 | fn = 0; |
| 247 | bit_base = 1; |
| 248 | break; |
| 249 | } |
| 250 | for (; fn >= 0; --fn) { |
| 251 | const struct device *const d = |
| 252 | dev_find_slot(0, PCI_DEVFN(dev, fn)); |
Nico Huber | 2dc15e9 | 2016-02-04 18:59:48 +0100 | [diff] [blame] | 253 | if (!d || d->enabled) continue; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 254 | const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN); |
| 255 | pci_write_config32(d0f0, D0F0_DEVEN, |
| 256 | deven & ~(1 << (bit_base + fn))); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN); |
| 261 | if (!(deven & (0xf << 6))) |
| 262 | pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14)); |
| 263 | } |
| 264 | |
| 265 | struct chip_operations northbridge_intel_gm45_ops = { |
| 266 | CHIP_NAME("Intel GM45 Northbridge") |
| 267 | .enable_dev = enable_dev, |
| 268 | .init = gm45_init, |
| 269 | }; |