Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 2 | |
Arthur Heymans | 022d235 | 2022-05-06 12:10:39 +0200 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
| 4 | #include <acpi/acpigen.h> |
| 5 | #include <boot/tables.h> |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 6 | #include <cbmem.h> |
Angel Pons | b9bbed2 | 2020-08-03 15:11:55 +0200 | [diff] [blame] | 7 | #include <commonlib/helpers.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 8 | #include <console/console.h> |
Arthur Heymans | 022d235 | 2022-05-06 12:10:39 +0200 | [diff] [blame] | 9 | #include <cpu/cpu.h> |
| 10 | #include <cpu/intel/smm_reloc.h> |
| 11 | #include <device/device.h> |
Elyes HAOUAS | 748caed | 2019-12-19 17:02:08 +0100 | [diff] [blame] | 12 | #include <device/pci_def.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 13 | #include <device/pci_ops.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 14 | #include <stdint.h> |
Elyes HAOUAS | a1e22b8 | 2019-03-18 22:49:36 +0100 | [diff] [blame] | 15 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 16 | #include "chip.h" |
| 17 | #include "gm45.h" |
| 18 | |
Arthur Heymans | 022d235 | 2022-05-06 12:10:39 +0200 | [diff] [blame] | 19 | static uint64_t get_touud(void) |
| 20 | { |
| 21 | uint64_t touud = pci_read_config16(__pci_0_00_0, D0F0_TOUUD); |
| 22 | touud <<= 20; |
| 23 | return touud; |
| 24 | } |
| 25 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 26 | static void mch_domain_read_resources(struct device *dev) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 27 | { |
| 28 | u64 tom, touud; |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 29 | u32 tomk, tolud, uma_sizek = 0, delta_cbmem; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 30 | |
| 31 | /* Total Memory 2GB example: |
| 32 | * |
| 33 | * 00000000 0000MB-2014MB 2014MB RAM (writeback) |
| 34 | * 7de00000 2014MB-2016MB 2MB GFX GTT (uncached) |
| 35 | * 7e000000 2016MB-2048MB 32MB GFX UMA (uncached) |
| 36 | * 80000000 2048MB TOLUD |
| 37 | * 80000000 2048MB TOM |
| 38 | * |
| 39 | * Total Memory 4GB example: |
| 40 | * |
| 41 | * 00000000 0000MB-3038MB 3038MB RAM (writeback) |
| 42 | * bde00000 3038MB-3040MB 2MB GFX GTT (uncached) |
| 43 | * be000000 3040MB-3072MB 32MB GFX UMA (uncached) |
| 44 | * be000000 3072MB TOLUD |
| 45 | * 100000000 4096MB TOM |
| 46 | * 100000000 4096MB-5120MB 1024MB RAM (writeback) |
| 47 | * 140000000 5120MB TOUUD |
| 48 | */ |
| 49 | |
| 50 | pci_domain_read_resources(dev); |
| 51 | |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 52 | struct device *mch = pcidev_on_root(0, 0); |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 53 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 54 | /* Top of Upper Usable DRAM, including remap */ |
Arthur Heymans | 022d235 | 2022-05-06 12:10:39 +0200 | [diff] [blame] | 55 | touud = get_touud(); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 56 | |
| 57 | /* Top of Lower Usable DRAM */ |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 58 | tolud = pci_read_config16(mch, D0F0_TOLUD) & 0xfff0; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 59 | tolud <<= 16; |
| 60 | |
| 61 | /* Top of Memory - does not account for any UMA */ |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 62 | tom = pci_read_config16(mch, D0F0_TOM) & 0x1ff; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 63 | tom <<= 27; |
| 64 | |
| 65 | printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n", |
| 66 | touud, tolud, tom); |
| 67 | |
| 68 | tomk = tolud >> 10; |
| 69 | |
| 70 | /* Graphics memory comes next */ |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 71 | const u16 ggc = pci_read_config16(mch, D0F0_GGC); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 72 | if (!(ggc & 2)) { |
| 73 | printk(BIOS_DEBUG, "IGD decoded, subtracting "); |
| 74 | |
| 75 | /* Graphics memory */ |
| 76 | const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf); |
Arthur Heymans | 8b76605 | 2018-01-24 23:25:13 +0100 | [diff] [blame] | 77 | printk(BIOS_DEBUG, "%uM UMA, ", gms_sizek >> 10); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 78 | tomk -= gms_sizek; |
| 79 | |
| 80 | /* GTT Graphics Stolen Memory Size (GGMS) */ |
| 81 | const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf); |
Arthur Heymans | 8b76605 | 2018-01-24 23:25:13 +0100 | [diff] [blame] | 82 | printk(BIOS_DEBUG, "%uM GTT", gsm_sizek >> 10); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 83 | tomk -= gsm_sizek; |
| 84 | |
| 85 | uma_sizek = gms_sizek + gsm_sizek; |
| 86 | } |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 87 | const u8 esmramc = pci_read_config8(mch, D0F0_ESMRAMC); |
Arthur Heymans | 8b76605 | 2018-01-24 23:25:13 +0100 | [diff] [blame] | 88 | const u32 tseg_sizek = decode_tseg_size(esmramc); |
| 89 | printk(BIOS_DEBUG, " and %uM TSEG\n", tseg_sizek >> 10); |
| 90 | tomk -= tseg_sizek; |
| 91 | uma_sizek += tseg_sizek; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 92 | |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 93 | /* cbmem_top can be shifted downwards due to alignment. |
| 94 | Mark the region between cbmem_top and tomk as unusable */ |
Arthur Heymans | 98435ed | 2022-05-06 12:22:32 +0200 | [diff] [blame^] | 95 | delta_cbmem = tomk - ((uintptr_t)cbmem_top() >> 10); |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 96 | tomk -= delta_cbmem; |
| 97 | uma_sizek += delta_cbmem; |
| 98 | |
| 99 | printk(BIOS_DEBUG, "Unused RAM between cbmem_top and TOM: 0x%xK\n", |
| 100 | delta_cbmem); |
| 101 | |
Nico Huber | ca3e121 | 2017-10-02 20:07:53 +0200 | [diff] [blame] | 102 | printk(BIOS_INFO, "Available memory below 4GB: %uM\n", tomk >> 10); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 103 | |
Nico Huber | 58ba83f | 2021-01-17 21:50:55 +0100 | [diff] [blame] | 104 | /* Report lowest memory region */ |
| 105 | ram_resource(dev, 3, 0, 0xa0000 / KiB); |
| 106 | |
| 107 | /* |
| 108 | * Reserve everything between A segment and 1MB: |
| 109 | * |
| 110 | * 0xa0000 - 0xbffff: Legacy VGA |
| 111 | * 0xc0000 - 0xfffff: RAM |
| 112 | */ |
| 113 | mmio_resource(dev, 4, 0xa0000 / KiB, (0xc0000 - 0xa0000) / KiB); |
| 114 | reserved_ram_resource(dev, 5, 0xc0000 / KiB, (1*MiB - 0xc0000) / KiB); |
| 115 | |
| 116 | /* Report < 4GB memory */ |
| 117 | ram_resource(dev, 6, 1*MiB / KiB, tomk - 1*MiB / KiB); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * If >= 4GB installed then memory from TOLUD to 4GB |
| 121 | * is remapped above TOM, TOUUD will account for both |
| 122 | */ |
| 123 | touud >>= 10; /* Convert to KB */ |
| 124 | if (touud > 4096 * 1024) { |
Nico Huber | 58ba83f | 2021-01-17 21:50:55 +0100 | [diff] [blame] | 125 | ram_resource(dev, 7, 4096 * 1024, touud - (4096 * 1024)); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 126 | printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", |
| 127 | (touud >> 10) - 4096); |
| 128 | } |
| 129 | |
| 130 | printk(BIOS_DEBUG, "Adding UMA memory area base=0x%llx " |
| 131 | "size=0x%llx\n", ((u64)tomk) << 10, ((u64)uma_sizek) << 10); |
| 132 | /* Don't use uma_resource() as our UMA touches the PCI hole. */ |
Nico Huber | 58ba83f | 2021-01-17 21:50:55 +0100 | [diff] [blame] | 133 | fixed_mem_resource(dev, 8, tomk, uma_sizek, IORESOURCE_RESERVE); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 134 | |
Angel Pons | 1ac6f8b | 2021-01-20 13:13:26 +0100 | [diff] [blame] | 135 | mmconf_resource(dev, 9); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 136 | } |
| 137 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 138 | static void mch_domain_set_resources(struct device *dev) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 139 | { |
| 140 | struct resource *resource; |
| 141 | int i; |
| 142 | |
Nico Huber | 58ba83f | 2021-01-17 21:50:55 +0100 | [diff] [blame] | 143 | for (i = 3; i <= 9; ++i) { |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 144 | /* Report read resources. */ |
Vladimir Serbinenko | 40412c6 | 2014-11-12 00:09:20 +0100 | [diff] [blame] | 145 | resource = probe_resource(dev, i); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 146 | if (resource) |
| 147 | report_resource_stored(dev, resource, ""); |
| 148 | } |
| 149 | |
| 150 | assign_resources(dev->link_list); |
| 151 | } |
| 152 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 153 | static void mch_domain_init(struct device *dev) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 154 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 155 | struct device *mch = pcidev_on_root(0, 0); |
Arthur Heymans | 8908931 | 2018-06-26 21:01:40 +0200 | [diff] [blame] | 156 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 157 | /* Enable SERR */ |
Elyes HAOUAS | 5ac723e | 2020-04-29 09:09:12 +0200 | [diff] [blame] | 158 | pci_or_config16(mch, PCI_COMMAND, PCI_COMMAND_SERR); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Arthur Heymans | e798e6a | 2017-12-23 23:09:54 +0100 | [diff] [blame] | 161 | static const char *northbridge_acpi_name(const struct device *dev) |
| 162 | { |
| 163 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 164 | return "PCI0"; |
| 165 | |
| 166 | if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0) |
| 167 | return NULL; |
| 168 | |
| 169 | switch (dev->path.pci.devfn) { |
| 170 | case PCI_DEVFN(0, 0): |
| 171 | return "MCHC"; |
| 172 | } |
| 173 | |
| 174 | return NULL; |
| 175 | } |
| 176 | |
Arthur Heymans | aade90e | 2018-01-25 00:33:45 +0100 | [diff] [blame] | 177 | void northbridge_write_smram(u8 smram) |
| 178 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 179 | struct device *dev = pcidev_on_root(0, 0); |
Arthur Heymans | 48fa922 | 2018-11-19 13:08:01 +0100 | [diff] [blame] | 180 | |
| 181 | if (dev == NULL) |
| 182 | die("could not find pci 00:00.0!\n"); |
| 183 | |
| 184 | pci_write_config8(dev, D0F0_SMRAM, smram); |
Arthur Heymans | aade90e | 2018-01-25 00:33:45 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Arthur Heymans | 022d235 | 2022-05-06 12:10:39 +0200 | [diff] [blame] | 187 | static void set_above_4g_pci(const struct device *dev) |
| 188 | { |
| 189 | const uint64_t touud = get_touud(); |
| 190 | const uint64_t len = POWER_OF_2(cpu_phys_address_size()) - touud; |
| 191 | |
| 192 | const char *scope = acpi_device_path(dev); |
| 193 | acpigen_write_scope(scope); |
| 194 | acpigen_write_name_qword("A4GB", touud); |
| 195 | acpigen_write_name_qword("A4GS", len); |
| 196 | acpigen_pop_len(); |
| 197 | |
| 198 | printk(BIOS_DEBUG, "PCI space above 4GB MMIO is at 0x%llx, len = 0x%llx\n", touud, len); |
| 199 | } |
| 200 | |
| 201 | static void pci_domain_ssdt(const struct device *dev) |
| 202 | { |
| 203 | generate_cpu_entries(dev); |
| 204 | set_above_4g_pci(dev); |
| 205 | } |
| 206 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 207 | static struct device_operations pci_domain_ops = { |
| 208 | .read_resources = mch_domain_read_resources, |
| 209 | .set_resources = mch_domain_set_resources, |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 210 | .init = mch_domain_init, |
| 211 | .scan_bus = pci_domain_scan_bus, |
Vladimir Serbinenko | 33769a5 | 2014-08-30 22:39:20 +0200 | [diff] [blame] | 212 | .write_acpi_tables = northbridge_write_acpi_tables, |
Arthur Heymans | 022d235 | 2022-05-06 12:10:39 +0200 | [diff] [blame] | 213 | .acpi_fill_ssdt = pci_domain_ssdt, |
Arthur Heymans | e798e6a | 2017-12-23 23:09:54 +0100 | [diff] [blame] | 214 | .acpi_name = northbridge_acpi_name, |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 215 | }; |
| 216 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 217 | static struct device_operations cpu_bus_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 218 | .read_resources = noop_read_resources, |
| 219 | .set_resources = noop_set_resources, |
Kyösti Mälkki | b3267e0 | 2019-08-13 16:44:04 +0300 | [diff] [blame] | 220 | .init = mp_cpu_bus_init, |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 221 | }; |
| 222 | |
Elyes HAOUAS | 6dcdaaf | 2018-02-09 07:44:31 +0100 | [diff] [blame] | 223 | static void enable_dev(struct device *dev) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 224 | { |
| 225 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 226 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 227 | dev->ops = &pci_domain_ops; |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 228 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 229 | dev->ops = &cpu_bus_ops; |
| 230 | } |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static void gm45_init(void *const chip_info) |
| 234 | { |
| 235 | int dev, fn, bit_base; |
| 236 | |
Kyösti Mälkki | 98a9174 | 2018-05-21 21:29:16 +0300 | [diff] [blame] | 237 | struct device *const d0f0 = pcidev_on_root(0x0, 0); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 238 | |
| 239 | /* Hide internal functions based on devicetree info. */ |
| 240 | for (dev = 3; dev > 0; --dev) { |
| 241 | switch (dev) { |
| 242 | case 3: /* ME */ |
| 243 | fn = 3; |
| 244 | bit_base = 6; |
| 245 | break; |
| 246 | case 2: /* IGD */ |
| 247 | fn = 1; |
| 248 | bit_base = 3; |
| 249 | break; |
| 250 | case 1: /* PEG */ |
| 251 | fn = 0; |
| 252 | bit_base = 1; |
| 253 | break; |
| 254 | } |
| 255 | for (; fn >= 0; --fn) { |
Angel Pons | b053583 | 2020-06-08 11:46:58 +0200 | [diff] [blame] | 256 | const struct device *const d = pcidev_on_root(dev, fn); |
| 257 | if (!d || d->enabled) |
| 258 | continue; |
| 259 | /* FIXME: Using bitwise ops changes the binary */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 260 | pci_write_config32(d0f0, D0F0_DEVEN, |
Angel Pons | b053583 | 2020-06-08 11:46:58 +0200 | [diff] [blame] | 261 | pci_read_config32(d0f0, D0F0_DEVEN) & ~(1 << (bit_base + fn))); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN); |
| 266 | if (!(deven & (0xf << 6))) |
| 267 | pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14)); |
| 268 | } |
| 269 | |
| 270 | struct chip_operations northbridge_intel_gm45_ops = { |
| 271 | CHIP_NAME("Intel GM45 Northbridge") |
| 272 | .enable_dev = enable_dev, |
| 273 | .init = gm45_init, |
| 274 | }; |