Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 2 | /* Various workarounds for chipset bugs. |
| 3 | This code runs very early and can't use the regular PCI subsystem |
| 4 | The entries are keyed to PCI bridges which usually identify chipsets |
| 5 | uniquely. |
| 6 | This is only for whole classes of chipsets with specific problems which |
| 7 | need early invasive action (e.g. before the timers are initialized). |
| 8 | Most PCI device specific workarounds can be done later and should be |
| 9 | in standard PCI quirks |
| 10 | Mainboard specific bugs should be handled by DMI entries. |
| 11 | CPU specific bugs in setup.c */ |
| 12 | |
| 13 | #include <linux/pci.h> |
| 14 | #include <linux/acpi.h> |
Lukas Wunner | abb2baf | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 15 | #include <linux/delay.h> |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 16 | #include <linux/pci_ids.h> |
Lukas Wunner | abb2baf | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 17 | #include <linux/bcma/bcma.h> |
| 18 | #include <linux/bcma/bcma_regs.h> |
Lukas Wunner | 630b3af | 2017-08-01 14:10:41 +0200 | [diff] [blame] | 19 | #include <linux/platform_data/x86/apple.h> |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 20 | #include <drm/i915_drm.h> |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 21 | #include <asm/pci-direct.h> |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 22 | #include <asm/dma.h> |
Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 23 | #include <asm/io_apic.h> |
| 24 | #include <asm/apic.h> |
Feng Tang | 6218791 | 2014-04-24 16:18:18 +0800 | [diff] [blame] | 25 | #include <asm/hpet.h> |
FUJITA Tomonori | 46a7fa2 | 2008-07-11 10:23:42 +0900 | [diff] [blame] | 26 | #include <asm/iommu.h> |
Joerg Roedel | 1d9b16d | 2008-11-27 18:39:15 +0100 | [diff] [blame] | 27 | #include <asm/gart.h> |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 28 | #include <asm/irq_remapping.h> |
Lukas Wunner | abb2baf | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 29 | #include <asm/early_ioremap.h> |
| 30 | |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 31 | static void __init fix_hypertransport_config(int num, int slot, int func) |
| 32 | { |
| 33 | u32 htcfg; |
| 34 | /* |
| 35 | * we found a hypertransport bus |
| 36 | * make sure that we are broadcasting |
| 37 | * interrupts to all cpus on the ht bus |
| 38 | * if we're using extended apic ids |
| 39 | */ |
| 40 | htcfg = read_pci_config(num, slot, func, 0x68); |
| 41 | if (htcfg & (1 << 18)) { |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 42 | printk(KERN_INFO "Detected use of extended apic ids " |
| 43 | "on hypertransport bus\n"); |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 44 | if ((htcfg & (1 << 17)) == 0) { |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 45 | printk(KERN_INFO "Enabling hypertransport extended " |
| 46 | "apic interrupt broadcast\n"); |
| 47 | printk(KERN_INFO "Note this is a bios bug, " |
| 48 | "please contact your hw vendor\n"); |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 49 | htcfg |= (1 << 17); |
| 50 | write_pci_config(num, slot, func, 0x68, htcfg); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | |
| 55 | } |
| 56 | |
| 57 | static void __init via_bugs(int num, int slot, int func) |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 58 | { |
Joerg Roedel | 966396d | 2007-10-24 12:49:48 +0200 | [diff] [blame] | 59 | #ifdef CONFIG_GART_IOMMU |
Yinghai Lu | c987d12 | 2008-06-24 22:14:09 -0700 | [diff] [blame] | 60 | if ((max_pfn > MAX_DMA32_PFN || force_iommu) && |
Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 61 | !gart_iommu_aperture_allowed) { |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 62 | printk(KERN_INFO |
Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 63 | "Looks like a VIA chipset. Disabling IOMMU." |
| 64 | " Override with iommu=allowed\n"); |
Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 65 | gart_iommu_aperture_disabled = 1; |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 66 | } |
| 67 | #endif |
| 68 | } |
| 69 | |
| 70 | #ifdef CONFIG_ACPI |
Jeff Garzik | 03d0d20 | 2007-10-27 20:57:43 +0200 | [diff] [blame] | 71 | #ifdef CONFIG_X86_IO_APIC |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 72 | |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 73 | static int __init nvidia_hpet_check(struct acpi_table_header *header) |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 74 | { |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 75 | return 0; |
| 76 | } |
Jeff Garzik | 03d0d20 | 2007-10-27 20:57:43 +0200 | [diff] [blame] | 77 | #endif /* CONFIG_X86_IO_APIC */ |
| 78 | #endif /* CONFIG_ACPI */ |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 79 | |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 80 | static void __init nvidia_bugs(int num, int slot, int func) |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 81 | { |
| 82 | #ifdef CONFIG_ACPI |
Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_X86_IO_APIC |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 84 | /* |
Lukas Wunner | 447d29d | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 85 | * Only applies to Nvidia root ports (bus 0) and not to |
| 86 | * Nvidia graphics cards with PCI ports on secondary buses. |
| 87 | */ |
| 88 | if (num) |
| 89 | return; |
| 90 | |
| 91 | /* |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 92 | * All timer overrides on Nvidia are |
| 93 | * wrong unless HPET is enabled. |
Andi Kleen | fa18f47 | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 94 | * Unfortunately that's not true on many Asus boards. |
| 95 | * We don't know yet how to detect this automatically, but |
| 96 | * at least allow a command line override. |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 97 | */ |
Andi Kleen | fa18f47 | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 98 | if (acpi_use_timer_override) |
| 99 | return; |
| 100 | |
Len Brown | fe69933 | 2007-03-08 18:28:32 -0500 | [diff] [blame] | 101 | if (acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check)) { |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 102 | acpi_skip_timer_override = 1; |
| 103 | printk(KERN_INFO "Nvidia board " |
| 104 | "detected. Ignoring ACPI " |
| 105 | "timer override.\n"); |
Andi Kleen | fa18f47 | 2006-11-14 16:57:46 +0100 | [diff] [blame] | 106 | printk(KERN_INFO "If you got timer trouble " |
| 107 | "try acpi_use_timer_override\n"); |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 108 | } |
| 109 | #endif |
Andi Kleen | 54ef340 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 110 | #endif |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 111 | /* RED-PEN skip them on mptables too? */ |
| 112 | |
| 113 | } |
| 114 | |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 115 | #if defined(CONFIG_ACPI) && defined(CONFIG_X86_IO_APIC) |
| 116 | static u32 __init ati_ixp4x0_rev(int num, int slot, int func) |
Andreas Herrmann | 33fb0e4 | 2008-10-07 00:11:22 +0200 | [diff] [blame] | 117 | { |
| 118 | u32 d; |
| 119 | u8 b; |
| 120 | |
| 121 | b = read_pci_config_byte(num, slot, func, 0xac); |
| 122 | b &= ~(1<<5); |
| 123 | write_pci_config_byte(num, slot, func, 0xac, b); |
| 124 | |
| 125 | d = read_pci_config(num, slot, func, 0x70); |
| 126 | d |= 1<<8; |
| 127 | write_pci_config(num, slot, func, 0x70, d); |
| 128 | |
| 129 | d = read_pci_config(num, slot, func, 0x8); |
| 130 | d &= 0xff; |
| 131 | return d; |
| 132 | } |
| 133 | |
| 134 | static void __init ati_bugs(int num, int slot, int func) |
| 135 | { |
Andreas Herrmann | 33fb0e4 | 2008-10-07 00:11:22 +0200 | [diff] [blame] | 136 | u32 d; |
| 137 | u8 b; |
| 138 | |
| 139 | if (acpi_use_timer_override) |
| 140 | return; |
| 141 | |
| 142 | d = ati_ixp4x0_rev(num, slot, func); |
| 143 | if (d < 0x82) |
| 144 | acpi_skip_timer_override = 1; |
| 145 | else { |
| 146 | /* check for IRQ0 interrupt swap */ |
| 147 | outb(0x72, 0xcd6); b = inb(0xcd7); |
| 148 | if (!(b & 0x2)) |
| 149 | acpi_skip_timer_override = 1; |
| 150 | } |
| 151 | |
| 152 | if (acpi_skip_timer_override) { |
| 153 | printk(KERN_INFO "SB4X0 revision 0x%x\n", d); |
| 154 | printk(KERN_INFO "Ignoring ACPI timer override.\n"); |
| 155 | printk(KERN_INFO "If you got timer trouble " |
| 156 | "try acpi_use_timer_override\n"); |
| 157 | } |
Andreas Herrmann | 33fb0e4 | 2008-10-07 00:11:22 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 160 | static u32 __init ati_sbx00_rev(int num, int slot, int func) |
| 161 | { |
Andreas Herrmann | 7f74f8f | 2011-02-24 15:53:46 +0100 | [diff] [blame] | 162 | u32 d; |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 163 | |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 164 | d = read_pci_config(num, slot, func, 0x8); |
| 165 | d &= 0xff; |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 166 | |
| 167 | return d; |
| 168 | } |
| 169 | |
| 170 | static void __init ati_bugs_contd(int num, int slot, int func) |
| 171 | { |
| 172 | u32 d, rev; |
| 173 | |
Andreas Herrmann | 7f74f8f | 2011-02-24 15:53:46 +0100 | [diff] [blame] | 174 | rev = ati_sbx00_rev(num, slot, func); |
| 175 | if (rev >= 0x40) |
| 176 | acpi_fix_pin2_polarity = 1; |
| 177 | |
Andreas Herrmann | 1d3e09a | 2011-03-15 15:31:37 +0100 | [diff] [blame] | 178 | /* |
| 179 | * SB600: revisions 0x11, 0x12, 0x13, 0x14, ... |
| 180 | * SB700: revisions 0x39, 0x3a, ... |
| 181 | * SB800: revisions 0x40, 0x41, ... |
| 182 | */ |
| 183 | if (rev >= 0x39) |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 184 | return; |
| 185 | |
Andreas Herrmann | 7f74f8f | 2011-02-24 15:53:46 +0100 | [diff] [blame] | 186 | if (acpi_use_timer_override) |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 187 | return; |
| 188 | |
| 189 | /* check for IRQ0 interrupt swap */ |
| 190 | d = read_pci_config(num, slot, func, 0x64); |
| 191 | if (!(d & (1<<14))) |
| 192 | acpi_skip_timer_override = 1; |
| 193 | |
| 194 | if (acpi_skip_timer_override) { |
| 195 | printk(KERN_INFO "SB600 revision 0x%x\n", rev); |
| 196 | printk(KERN_INFO "Ignoring ACPI timer override.\n"); |
| 197 | printk(KERN_INFO "If you got timer trouble " |
| 198 | "try acpi_use_timer_override\n"); |
| 199 | } |
| 200 | } |
| 201 | #else |
| 202 | static void __init ati_bugs(int num, int slot, int func) |
| 203 | { |
| 204 | } |
| 205 | |
| 206 | static void __init ati_bugs_contd(int num, int slot, int func) |
| 207 | { |
| 208 | } |
| 209 | #endif |
| 210 | |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 211 | static void __init intel_remapping_check(int num, int slot, int func) |
| 212 | { |
| 213 | u8 revision; |
Neil Horman | 803075d | 2013-07-17 07:13:59 -0400 | [diff] [blame] | 214 | u16 device; |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 215 | |
Neil Horman | 803075d | 2013-07-17 07:13:59 -0400 | [diff] [blame] | 216 | device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID); |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 217 | revision = read_pci_config_byte(num, slot, func, PCI_REVISION_ID); |
| 218 | |
| 219 | /* |
Neil Horman | 6f8a1b3 | 2014-03-12 14:44:33 -0400 | [diff] [blame] | 220 | * Revision <= 13 of all triggering devices id in this quirk |
| 221 | * have a problem draining interrupts when irq remapping is |
| 222 | * enabled, and should be flagged as broken. Additionally |
| 223 | * revision 0x22 of device id 0x3405 has this problem. |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 224 | */ |
Neil Horman | 6f8a1b3 | 2014-03-12 14:44:33 -0400 | [diff] [blame] | 225 | if (revision <= 0x13) |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 226 | set_irq_remapping_broken(); |
Neil Horman | 6f8a1b3 | 2014-03-12 14:44:33 -0400 | [diff] [blame] | 227 | else if (device == 0x3405 && revision == 0x22) |
Neil Horman | 803075d | 2013-07-17 07:13:59 -0400 | [diff] [blame] | 228 | set_irq_remapping_broken(); |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 229 | } |
| 230 | |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 231 | /* |
| 232 | * Systems with Intel graphics controllers set aside memory exclusively |
| 233 | * for gfx driver use. This memory is not marked in the E820 as reserved |
| 234 | * or as RAM, and so is subject to overlap from E820 manipulation later |
| 235 | * in the boot process. On some systems, MMIO space is allocated on top, |
| 236 | * despite the efforts of the "RAM buffer" approach, which simply rounds |
| 237 | * memory boundaries up to 64M to try to catch space that may decode |
| 238 | * as RAM and so is not suitable for MMIO. |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 239 | */ |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 240 | |
Ville Syrjälä | 86e5876 | 2014-04-13 12:45:03 +0300 | [diff] [blame] | 241 | #define KB(x) ((x) * 1024UL) |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 242 | #define MB(x) (KB (KB (x))) |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 243 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 244 | static resource_size_t __init i830_tseg_size(void) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 245 | { |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 246 | u8 esmramc = read_pci_config_byte(0, 0, 0, I830_ESMRAMC); |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 247 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 248 | if (!(esmramc & TSEG_ENABLE)) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 249 | return 0; |
| 250 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 251 | if (esmramc & I830_TSEG_SIZE_1M) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 252 | return MB(1); |
| 253 | else |
| 254 | return KB(512); |
| 255 | } |
| 256 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 257 | static resource_size_t __init i845_tseg_size(void) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 258 | { |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 259 | u8 esmramc = read_pci_config_byte(0, 0, 0, I845_ESMRAMC); |
| 260 | u8 tseg_size = esmramc & I845_TSEG_SIZE_MASK; |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 261 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 262 | if (!(esmramc & TSEG_ENABLE)) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 263 | return 0; |
| 264 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 265 | switch (tseg_size) { |
| 266 | case I845_TSEG_SIZE_512K: return KB(512); |
| 267 | case I845_TSEG_SIZE_1M: return MB(1); |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 268 | default: |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 269 | WARN(1, "Unknown ESMRAMC value: %x!\n", esmramc); |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 270 | } |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 271 | return 0; |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 272 | } |
| 273 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 274 | static resource_size_t __init i85x_tseg_size(void) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 275 | { |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 276 | u8 esmramc = read_pci_config_byte(0, 0, 0, I85X_ESMRAMC); |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 277 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 278 | if (!(esmramc & TSEG_ENABLE)) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 279 | return 0; |
| 280 | |
| 281 | return MB(1); |
| 282 | } |
| 283 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 284 | static resource_size_t __init i830_mem_size(void) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 285 | { |
| 286 | return read_pci_config_byte(0, 0, 0, I830_DRB3) * MB(32); |
| 287 | } |
| 288 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 289 | static resource_size_t __init i85x_mem_size(void) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 290 | { |
| 291 | return read_pci_config_byte(0, 0, 1, I85X_DRB3) * MB(32); |
| 292 | } |
| 293 | |
| 294 | /* |
| 295 | * On 830/845/85x the stolen memory base isn't available in any |
| 296 | * register. We need to calculate it as TOM-TSEG_SIZE-stolen_size. |
| 297 | */ |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 298 | static resource_size_t __init i830_stolen_base(int num, int slot, int func, |
| 299 | resource_size_t stolen_size) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 300 | { |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 301 | return i830_mem_size() - i830_tseg_size() - stolen_size; |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 302 | } |
| 303 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 304 | static resource_size_t __init i845_stolen_base(int num, int slot, int func, |
| 305 | resource_size_t stolen_size) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 306 | { |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 307 | return i830_mem_size() - i845_tseg_size() - stolen_size; |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 310 | static resource_size_t __init i85x_stolen_base(int num, int slot, int func, |
| 311 | resource_size_t stolen_size) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 312 | { |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 313 | return i85x_mem_size() - i85x_tseg_size() - stolen_size; |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 314 | } |
| 315 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 316 | static resource_size_t __init i865_stolen_base(int num, int slot, int func, |
| 317 | resource_size_t stolen_size) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 318 | { |
Ville Syrjälä | d721b02 | 2016-08-08 13:58:39 +0300 | [diff] [blame] | 319 | u16 toud = 0; |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 320 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 321 | toud = read_pci_config_16(0, 0, 0, I865_TOUD); |
| 322 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 323 | return toud * KB(64) + i845_tseg_size(); |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 324 | } |
| 325 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 326 | static resource_size_t __init gen3_stolen_base(int num, int slot, int func, |
| 327 | resource_size_t stolen_size) |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 328 | { |
| 329 | u32 bsm; |
| 330 | |
| 331 | /* Almost universally we can find the Graphics Base of Stolen Memory |
| 332 | * at register BSM (0x5c) in the igfx configuration space. On a few |
| 333 | * (desktop) machines this is also mirrored in the bridge device at |
| 334 | * different locations, or in the MCHBAR. |
| 335 | */ |
| 336 | bsm = read_pci_config(num, slot, func, INTEL_BSM); |
| 337 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 338 | return bsm & INTEL_BSM_MASK; |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Paulo Zanoni | db0c8d8 | 2018-05-04 13:32:51 -0700 | [diff] [blame] | 341 | static resource_size_t __init gen11_stolen_base(int num, int slot, int func, |
| 342 | resource_size_t stolen_size) |
| 343 | { |
| 344 | u64 bsm; |
| 345 | |
| 346 | bsm = read_pci_config(num, slot, func, INTEL_GEN11_BSM_DW0); |
| 347 | bsm &= INTEL_BSM_MASK; |
| 348 | bsm |= (u64)read_pci_config(num, slot, func, INTEL_GEN11_BSM_DW1) << 32; |
| 349 | |
| 350 | return bsm; |
| 351 | } |
| 352 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 353 | static resource_size_t __init i830_stolen_size(int num, int slot, int func) |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 354 | { |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 355 | u16 gmch_ctrl; |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 356 | u16 gms; |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 357 | |
| 358 | gmch_ctrl = read_pci_config_16(0, 0, 0, I830_GMCH_CTRL); |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 359 | gms = gmch_ctrl & I830_GMCH_GMS_MASK; |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 360 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 361 | switch (gms) { |
| 362 | case I830_GMCH_GMS_STOLEN_512: return KB(512); |
| 363 | case I830_GMCH_GMS_STOLEN_1024: return MB(1); |
| 364 | case I830_GMCH_GMS_STOLEN_8192: return MB(8); |
| 365 | /* local memory isn't part of the normal address space */ |
| 366 | case I830_GMCH_GMS_LOCAL: return 0; |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 367 | default: |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 368 | WARN(1, "Unknown GMCH_CTRL value: %x!\n", gmch_ctrl); |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 369 | } |
| 370 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 371 | return 0; |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 372 | } |
| 373 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 374 | static resource_size_t __init gen3_stolen_size(int num, int slot, int func) |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 375 | { |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 376 | u16 gmch_ctrl; |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 377 | u16 gms; |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 378 | |
| 379 | gmch_ctrl = read_pci_config_16(0, 0, 0, I830_GMCH_CTRL); |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 380 | gms = gmch_ctrl & I855_GMCH_GMS_MASK; |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 381 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 382 | switch (gms) { |
| 383 | case I855_GMCH_GMS_STOLEN_1M: return MB(1); |
| 384 | case I855_GMCH_GMS_STOLEN_4M: return MB(4); |
| 385 | case I855_GMCH_GMS_STOLEN_8M: return MB(8); |
| 386 | case I855_GMCH_GMS_STOLEN_16M: return MB(16); |
| 387 | case I855_GMCH_GMS_STOLEN_32M: return MB(32); |
| 388 | case I915_GMCH_GMS_STOLEN_48M: return MB(48); |
| 389 | case I915_GMCH_GMS_STOLEN_64M: return MB(64); |
| 390 | case G33_GMCH_GMS_STOLEN_128M: return MB(128); |
| 391 | case G33_GMCH_GMS_STOLEN_256M: return MB(256); |
| 392 | case INTEL_GMCH_GMS_STOLEN_96M: return MB(96); |
| 393 | case INTEL_GMCH_GMS_STOLEN_160M:return MB(160); |
| 394 | case INTEL_GMCH_GMS_STOLEN_224M:return MB(224); |
| 395 | case INTEL_GMCH_GMS_STOLEN_352M:return MB(352); |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 396 | default: |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 397 | WARN(1, "Unknown GMCH_CTRL value: %x!\n", gmch_ctrl); |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 400 | return 0; |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 403 | static resource_size_t __init gen6_stolen_size(int num, int slot, int func) |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 404 | { |
| 405 | u16 gmch_ctrl; |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 406 | u16 gms; |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 407 | |
| 408 | gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL); |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 409 | gms = (gmch_ctrl >> SNB_GMCH_GMS_SHIFT) & SNB_GMCH_GMS_MASK; |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 410 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 411 | return gms * MB(32); |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 414 | static resource_size_t __init gen8_stolen_size(int num, int slot, int func) |
Ben Widawsky | 9459d25 | 2013-11-03 16:53:55 -0800 | [diff] [blame] | 415 | { |
| 416 | u16 gmch_ctrl; |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 417 | u16 gms; |
Ben Widawsky | 9459d25 | 2013-11-03 16:53:55 -0800 | [diff] [blame] | 418 | |
| 419 | gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL); |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 420 | gms = (gmch_ctrl >> BDW_GMCH_GMS_SHIFT) & BDW_GMCH_GMS_MASK; |
| 421 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 422 | return gms * MB(32); |
Ben Widawsky | 9459d25 | 2013-11-03 16:53:55 -0800 | [diff] [blame] | 423 | } |
| 424 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 425 | static resource_size_t __init chv_stolen_size(int num, int slot, int func) |
Damien Lespiau | 3e3b2c3 | 2014-05-08 22:19:41 +0300 | [diff] [blame] | 426 | { |
| 427 | u16 gmch_ctrl; |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 428 | u16 gms; |
Damien Lespiau | 3e3b2c3 | 2014-05-08 22:19:41 +0300 | [diff] [blame] | 429 | |
| 430 | gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL); |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 431 | gms = (gmch_ctrl >> SNB_GMCH_GMS_SHIFT) & SNB_GMCH_GMS_MASK; |
Damien Lespiau | 3e3b2c3 | 2014-05-08 22:19:41 +0300 | [diff] [blame] | 432 | |
| 433 | /* |
| 434 | * 0x0 to 0x10: 32MB increments starting at 0MB |
| 435 | * 0x11 to 0x16: 4MB increments starting at 8MB |
| 436 | * 0x17 to 0x1d: 4MB increments start at 36MB |
| 437 | */ |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 438 | if (gms < 0x11) |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 439 | return gms * MB(32); |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 440 | else if (gms < 0x17) |
Matthew Auld | 3b51b6f | 2017-12-11 15:18:16 +0000 | [diff] [blame] | 441 | return (gms - 0x11) * MB(4) + MB(8); |
Damien Lespiau | 3e3b2c3 | 2014-05-08 22:19:41 +0300 | [diff] [blame] | 442 | else |
Matthew Auld | 3b51b6f | 2017-12-11 15:18:16 +0000 | [diff] [blame] | 443 | return (gms - 0x17) * MB(4) + MB(36); |
Damien Lespiau | 3e3b2c3 | 2014-05-08 22:19:41 +0300 | [diff] [blame] | 444 | } |
Ville Syrjälä | 52ca704 | 2014-02-05 21:28:58 +0200 | [diff] [blame] | 445 | |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 446 | static resource_size_t __init gen9_stolen_size(int num, int slot, int func) |
Damien Lespiau | 6637501 | 2014-01-09 18:02:46 +0000 | [diff] [blame] | 447 | { |
| 448 | u16 gmch_ctrl; |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 449 | u16 gms; |
Damien Lespiau | 6637501 | 2014-01-09 18:02:46 +0000 | [diff] [blame] | 450 | |
| 451 | gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL); |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 452 | gms = (gmch_ctrl >> BDW_GMCH_GMS_SHIFT) & BDW_GMCH_GMS_MASK; |
Damien Lespiau | 6637501 | 2014-01-09 18:02:46 +0000 | [diff] [blame] | 453 | |
Joonas Lahtinen | c0dd346 | 2016-04-22 13:29:26 +0300 | [diff] [blame] | 454 | /* 0x0 to 0xef: 32MB increments starting at 0MB */ |
| 455 | /* 0xf0 to 0xfe: 4MB increments starting at 4MB */ |
| 456 | if (gms < 0xf0) |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 457 | return gms * MB(32); |
Damien Lespiau | 6637501 | 2014-01-09 18:02:46 +0000 | [diff] [blame] | 458 | else |
Matthew Auld | 3b51b6f | 2017-12-11 15:18:16 +0000 | [diff] [blame] | 459 | return (gms - 0xf0) * MB(4) + MB(4); |
Damien Lespiau | 6637501 | 2014-01-09 18:02:46 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 462 | struct intel_early_ops { |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 463 | resource_size_t (*stolen_size)(int num, int slot, int func); |
| 464 | resource_size_t (*stolen_base)(int num, int slot, int func, |
| 465 | resource_size_t size); |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 466 | }; |
| 467 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 468 | static const struct intel_early_ops i830_early_ops __initconst = { |
| 469 | .stolen_base = i830_stolen_base, |
| 470 | .stolen_size = i830_stolen_size, |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 471 | }; |
| 472 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 473 | static const struct intel_early_ops i845_early_ops __initconst = { |
| 474 | .stolen_base = i845_stolen_base, |
| 475 | .stolen_size = i830_stolen_size, |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 476 | }; |
| 477 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 478 | static const struct intel_early_ops i85x_early_ops __initconst = { |
| 479 | .stolen_base = i85x_stolen_base, |
| 480 | .stolen_size = gen3_stolen_size, |
Ville Syrjälä | a4dff76 | 2014-02-05 21:28:59 +0200 | [diff] [blame] | 481 | }; |
| 482 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 483 | static const struct intel_early_ops i865_early_ops __initconst = { |
| 484 | .stolen_base = i865_stolen_base, |
| 485 | .stolen_size = gen3_stolen_size, |
Ville Syrjälä | 52ca704 | 2014-02-05 21:28:58 +0200 | [diff] [blame] | 486 | }; |
| 487 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 488 | static const struct intel_early_ops gen3_early_ops __initconst = { |
| 489 | .stolen_base = gen3_stolen_base, |
| 490 | .stolen_size = gen3_stolen_size, |
Ville Syrjälä | 52ca704 | 2014-02-05 21:28:58 +0200 | [diff] [blame] | 491 | }; |
| 492 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 493 | static const struct intel_early_ops gen6_early_ops __initconst = { |
| 494 | .stolen_base = gen3_stolen_base, |
| 495 | .stolen_size = gen6_stolen_size, |
Ville Syrjälä | 52ca704 | 2014-02-05 21:28:58 +0200 | [diff] [blame] | 496 | }; |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 497 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 498 | static const struct intel_early_ops gen8_early_ops __initconst = { |
| 499 | .stolen_base = gen3_stolen_base, |
| 500 | .stolen_size = gen8_stolen_size, |
Damien Lespiau | 6637501 | 2014-01-09 18:02:46 +0000 | [diff] [blame] | 501 | }; |
| 502 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 503 | static const struct intel_early_ops gen9_early_ops __initconst = { |
| 504 | .stolen_base = gen3_stolen_base, |
| 505 | .stolen_size = gen9_stolen_size, |
Damien Lespiau | 3e3b2c3 | 2014-05-08 22:19:41 +0300 | [diff] [blame] | 506 | }; |
| 507 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 508 | static const struct intel_early_ops chv_early_ops __initconst = { |
| 509 | .stolen_base = gen3_stolen_base, |
| 510 | .stolen_size = chv_stolen_size, |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 511 | }; |
| 512 | |
Paulo Zanoni | db0c8d8 | 2018-05-04 13:32:51 -0700 | [diff] [blame] | 513 | static const struct intel_early_ops gen11_early_ops __initconst = { |
| 514 | .stolen_base = gen11_stolen_base, |
| 515 | .stolen_size = gen9_stolen_size, |
| 516 | }; |
| 517 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 518 | static const struct pci_device_id intel_early_ids[] __initconst = { |
| 519 | INTEL_I830_IDS(&i830_early_ops), |
| 520 | INTEL_I845G_IDS(&i845_early_ops), |
| 521 | INTEL_I85X_IDS(&i85x_early_ops), |
| 522 | INTEL_I865G_IDS(&i865_early_ops), |
| 523 | INTEL_I915G_IDS(&gen3_early_ops), |
| 524 | INTEL_I915GM_IDS(&gen3_early_ops), |
| 525 | INTEL_I945G_IDS(&gen3_early_ops), |
| 526 | INTEL_I945GM_IDS(&gen3_early_ops), |
Carlos Santa | 8d9c20e | 2016-08-17 12:30:37 -0700 | [diff] [blame] | 527 | INTEL_VLV_IDS(&gen6_early_ops), |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 528 | INTEL_PINEVIEW_G_IDS(&gen3_early_ops), |
| 529 | INTEL_PINEVIEW_M_IDS(&gen3_early_ops), |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 530 | INTEL_I965G_IDS(&gen3_early_ops), |
| 531 | INTEL_G33_IDS(&gen3_early_ops), |
| 532 | INTEL_I965GM_IDS(&gen3_early_ops), |
| 533 | INTEL_GM45_IDS(&gen3_early_ops), |
| 534 | INTEL_G45_IDS(&gen3_early_ops), |
| 535 | INTEL_IRONLAKE_D_IDS(&gen3_early_ops), |
| 536 | INTEL_IRONLAKE_M_IDS(&gen3_early_ops), |
| 537 | INTEL_SNB_D_IDS(&gen6_early_ops), |
| 538 | INTEL_SNB_M_IDS(&gen6_early_ops), |
| 539 | INTEL_IVB_M_IDS(&gen6_early_ops), |
| 540 | INTEL_IVB_D_IDS(&gen6_early_ops), |
Carlos Santa | 8d9c20e | 2016-08-17 12:30:37 -0700 | [diff] [blame] | 541 | INTEL_HSW_IDS(&gen6_early_ops), |
| 542 | INTEL_BDW_IDS(&gen8_early_ops), |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 543 | INTEL_CHV_IDS(&chv_early_ops), |
| 544 | INTEL_SKL_IDS(&gen9_early_ops), |
| 545 | INTEL_BXT_IDS(&gen9_early_ops), |
| 546 | INTEL_KBL_IDS(&gen9_early_ops), |
Lucas De Marchi | 33aa69e | 2017-12-13 12:04:25 -0800 | [diff] [blame] | 547 | INTEL_CFL_IDS(&gen9_early_ops), |
Paulo Zanoni | bc384c7 | 2017-01-24 16:47:22 -0200 | [diff] [blame] | 548 | INTEL_GLK_IDS(&gen9_early_ops), |
Paulo Zanoni | 2e1e9d4 | 2017-07-05 18:00:45 -0700 | [diff] [blame] | 549 | INTEL_CNL_IDS(&gen9_early_ops), |
Paulo Zanoni | db0c8d8 | 2018-05-04 13:32:51 -0700 | [diff] [blame] | 550 | INTEL_ICL_11_IDS(&gen11_early_ops), |
Rodrigo Vivi | d53fef0 | 2019-03-15 12:19:38 -0700 | [diff] [blame] | 551 | INTEL_EHL_IDS(&gen11_early_ops), |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 552 | }; |
| 553 | |
Matthew Auld | 55f56fc | 2017-12-11 15:18:15 +0000 | [diff] [blame] | 554 | struct resource intel_graphics_stolen_res __ro_after_init = DEFINE_RES_MEM(0, 0); |
| 555 | EXPORT_SYMBOL(intel_graphics_stolen_res); |
| 556 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 557 | static void __init |
| 558 | intel_graphics_stolen(int num, int slot, int func, |
| 559 | const struct intel_early_ops *early_ops) |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 560 | { |
Joonas Lahtinen | 6f9fa99 | 2017-12-11 15:18:14 +0000 | [diff] [blame] | 561 | resource_size_t base, size; |
| 562 | resource_size_t end; |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 563 | |
| 564 | size = early_ops->stolen_size(num, slot, func); |
| 565 | base = early_ops->stolen_base(num, slot, func, size); |
| 566 | |
| 567 | if (!size || !base) |
| 568 | return; |
| 569 | |
Chris Wilson | 01e5d3b | 2016-05-09 17:39:42 +0100 | [diff] [blame] | 570 | end = base + size - 1; |
Matthew Auld | 55f56fc | 2017-12-11 15:18:15 +0000 | [diff] [blame] | 571 | |
| 572 | intel_graphics_stolen_res.start = base; |
| 573 | intel_graphics_stolen_res.end = end; |
| 574 | |
| 575 | printk(KERN_INFO "Reserving Intel graphics memory at %pR\n", |
| 576 | &intel_graphics_stolen_res); |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 577 | |
| 578 | /* Mark this space as reserved */ |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 579 | e820__range_add(base, size, E820_TYPE_RESERVED); |
Ingo Molnar | f9748fa | 2017-01-28 18:00:35 +0100 | [diff] [blame] | 580 | e820__update_table(e820_table); |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static void __init intel_graphics_quirks(int num, int slot, int func) |
| 584 | { |
| 585 | const struct intel_early_ops *early_ops; |
| 586 | u16 device; |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 587 | int i; |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 588 | |
| 589 | device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID); |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 590 | |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 591 | for (i = 0; i < ARRAY_SIZE(intel_early_ids); i++) { |
| 592 | kernel_ulong_t driver_data = intel_early_ids[i].driver_data; |
| 593 | |
| 594 | if (intel_early_ids[i].device != device) |
| 595 | continue; |
| 596 | |
| 597 | early_ops = (typeof(early_ops))driver_data; |
| 598 | |
| 599 | intel_graphics_stolen(num, slot, func, early_ops); |
| 600 | |
| 601 | return; |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
Feng Tang | 6218791 | 2014-04-24 16:18:18 +0800 | [diff] [blame] | 605 | static void __init force_disable_hpet(int num, int slot, int func) |
| 606 | { |
| 607 | #ifdef CONFIG_HPET_TIMER |
Jan Beulich | 3d45ac4 | 2015-10-19 04:35:44 -0600 | [diff] [blame] | 608 | boot_hpet_disable = true; |
Feng Tang | 6218791 | 2014-04-24 16:18:18 +0800 | [diff] [blame] | 609 | pr_info("x86/hpet: Will disable the HPET for this platform because it's not reliable\n"); |
| 610 | #endif |
| 611 | } |
| 612 | |
Lukas Wunner | abb2baf | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 613 | #define BCM4331_MMIO_SIZE 16384 |
| 614 | #define BCM4331_PM_CAP 0x40 |
| 615 | #define bcma_aread32(reg) ioread32(mmio + 1 * BCMA_CORE_SIZE + reg) |
| 616 | #define bcma_awrite32(reg, val) iowrite32(val, mmio + 1 * BCMA_CORE_SIZE + reg) |
| 617 | |
| 618 | static void __init apple_airport_reset(int bus, int slot, int func) |
| 619 | { |
| 620 | void __iomem *mmio; |
| 621 | u16 pmcsr; |
| 622 | u64 addr; |
| 623 | int i; |
| 624 | |
Lukas Wunner | 630b3af | 2017-08-01 14:10:41 +0200 | [diff] [blame] | 625 | if (!x86_apple_machine) |
Lukas Wunner | abb2baf | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 626 | return; |
| 627 | |
| 628 | /* Card may have been put into PCI_D3hot by grub quirk */ |
| 629 | pmcsr = read_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL); |
| 630 | |
| 631 | if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0) { |
| 632 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
| 633 | write_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL, pmcsr); |
| 634 | mdelay(10); |
| 635 | |
| 636 | pmcsr = read_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL); |
| 637 | if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0) { |
Joe Perches | a7a3153 | 2018-05-09 08:15:45 -0700 | [diff] [blame] | 638 | pr_err("pci 0000:%02x:%02x.%d: Cannot power up Apple AirPort card\n", |
| 639 | bus, slot, func); |
Lukas Wunner | abb2baf | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 640 | return; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | addr = read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_0); |
| 645 | addr |= (u64)read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_1) << 32; |
| 646 | addr &= PCI_BASE_ADDRESS_MEM_MASK; |
| 647 | |
| 648 | mmio = early_ioremap(addr, BCM4331_MMIO_SIZE); |
| 649 | if (!mmio) { |
Joe Perches | a7a3153 | 2018-05-09 08:15:45 -0700 | [diff] [blame] | 650 | pr_err("pci 0000:%02x:%02x.%d: Cannot iomap Apple AirPort card\n", |
| 651 | bus, slot, func); |
Lukas Wunner | abb2baf | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 652 | return; |
| 653 | } |
| 654 | |
| 655 | pr_info("Resetting Apple AirPort card (left enabled by EFI)\n"); |
| 656 | |
| 657 | for (i = 0; bcma_aread32(BCMA_RESET_ST) && i < 30; i++) |
| 658 | udelay(10); |
| 659 | |
| 660 | bcma_awrite32(BCMA_RESET_CTL, BCMA_RESET_CTL_RESET); |
| 661 | bcma_aread32(BCMA_RESET_CTL); |
| 662 | udelay(1); |
| 663 | |
| 664 | bcma_awrite32(BCMA_RESET_CTL, 0); |
| 665 | bcma_aread32(BCMA_RESET_CTL); |
| 666 | udelay(10); |
| 667 | |
| 668 | early_iounmap(mmio, BCM4331_MMIO_SIZE); |
| 669 | } |
Feng Tang | 6218791 | 2014-04-24 16:18:18 +0800 | [diff] [blame] | 670 | |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 671 | #define QFLAG_APPLY_ONCE 0x1 |
| 672 | #define QFLAG_APPLIED 0x2 |
| 673 | #define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED) |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 674 | struct chipset { |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 675 | u32 vendor; |
| 676 | u32 device; |
| 677 | u32 class; |
| 678 | u32 class_mask; |
| 679 | u32 flags; |
| 680 | void (*f)(int num, int slot, int func); |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 681 | }; |
| 682 | |
Andrew Morton | c993c73 | 2007-04-08 16:04:03 -0700 | [diff] [blame] | 683 | static struct chipset early_qrk[] __initdata = { |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 684 | { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, |
| 685 | PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs }, |
| 686 | { PCI_VENDOR_ID_VIA, PCI_ANY_ID, |
| 687 | PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs }, |
Neil Horman | c6b4832 | 2008-01-30 13:31:25 +0100 | [diff] [blame] | 688 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB, |
| 689 | PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config }, |
Andreas Herrmann | 33fb0e4 | 2008-10-07 00:11:22 +0200 | [diff] [blame] | 690 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS, |
| 691 | PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs }, |
Andreas Herrmann | 26adcfb | 2008-10-14 21:01:15 +0200 | [diff] [blame] | 692 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS, |
| 693 | PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs_contd }, |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 694 | { PCI_VENDOR_ID_INTEL, 0x3403, PCI_CLASS_BRIDGE_HOST, |
| 695 | PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check }, |
Neil Horman | 803075d | 2013-07-17 07:13:59 -0400 | [diff] [blame] | 696 | { PCI_VENDOR_ID_INTEL, 0x3405, PCI_CLASS_BRIDGE_HOST, |
| 697 | PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check }, |
Neil Horman | 03bbcb2 | 2013-04-16 16:38:32 -0400 | [diff] [blame] | 698 | { PCI_VENDOR_ID_INTEL, 0x3406, PCI_CLASS_BRIDGE_HOST, |
| 699 | PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check }, |
Jesse Barnes | 814c5f1 | 2013-07-26 13:32:52 -0700 | [diff] [blame] | 700 | { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID, |
Joonas Lahtinen | ee0629c | 2016-04-22 13:45:49 +0300 | [diff] [blame] | 701 | QFLAG_APPLY_ONCE, intel_graphics_quirks }, |
Feng Tang | 6218791 | 2014-04-24 16:18:18 +0800 | [diff] [blame] | 702 | /* |
Feng Tang | b58d930 | 2015-06-15 17:40:01 +0800 | [diff] [blame] | 703 | * HPET on the current version of the Baytrail platform has accuracy |
| 704 | * problems: it will halt in deep idle state - so we disable it. |
| 705 | * |
| 706 | * More details can be found in section 18.10.1.3 of the datasheet: |
| 707 | * |
| 708 | * http://www.intel.com/content/dam/www/public/us/en/documents/datasheets/atom-z8000-datasheet-vol-1.pdf |
Feng Tang | 6218791 | 2014-04-24 16:18:18 +0800 | [diff] [blame] | 709 | */ |
| 710 | { PCI_VENDOR_ID_INTEL, 0x0f00, |
| 711 | PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet}, |
Lukas Wunner | abb2baf | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 712 | { PCI_VENDOR_ID_BROADCOM, 0x4331, |
| 713 | PCI_CLASS_NETWORK_OTHER, PCI_ANY_ID, 0, apple_airport_reset}, |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 714 | {} |
| 715 | }; |
| 716 | |
Lukas Wunner | 850c321 | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 717 | static void __init early_pci_scan_bus(int bus); |
| 718 | |
Jesse Barnes | 15650a2 | 2008-06-16 15:29:45 -0700 | [diff] [blame] | 719 | /** |
| 720 | * check_dev_quirk - apply early quirks to a given PCI device |
| 721 | * @num: bus number |
| 722 | * @slot: slot number |
| 723 | * @func: PCI function |
| 724 | * |
| 725 | * Check the vendor & device ID against the early quirks table. |
| 726 | * |
Lukas Wunner | 850c321 | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 727 | * If the device is single function, let early_pci_scan_bus() know so we don't |
Jesse Barnes | 15650a2 | 2008-06-16 15:29:45 -0700 | [diff] [blame] | 728 | * poke at this device again. |
| 729 | */ |
| 730 | static int __init check_dev_quirk(int num, int slot, int func) |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 731 | { |
| 732 | u16 class; |
| 733 | u16 vendor; |
| 734 | u16 device; |
| 735 | u8 type; |
Lukas Wunner | 850c321 | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 736 | u8 sec; |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 737 | int i; |
| 738 | |
| 739 | class = read_pci_config_16(num, slot, func, PCI_CLASS_DEVICE); |
| 740 | |
| 741 | if (class == 0xffff) |
Jesse Barnes | 15650a2 | 2008-06-16 15:29:45 -0700 | [diff] [blame] | 742 | return -1; /* no class, treat as single function */ |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 743 | |
| 744 | vendor = read_pci_config_16(num, slot, func, PCI_VENDOR_ID); |
| 745 | |
| 746 | device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID); |
| 747 | |
| 748 | for (i = 0; early_qrk[i].f != NULL; i++) { |
| 749 | if (((early_qrk[i].vendor == PCI_ANY_ID) || |
| 750 | (early_qrk[i].vendor == vendor)) && |
| 751 | ((early_qrk[i].device == PCI_ANY_ID) || |
| 752 | (early_qrk[i].device == device)) && |
| 753 | (!((early_qrk[i].class ^ class) & |
| 754 | early_qrk[i].class_mask))) { |
| 755 | if ((early_qrk[i].flags & |
| 756 | QFLAG_DONE) != QFLAG_DONE) |
| 757 | early_qrk[i].f(num, slot, func); |
| 758 | early_qrk[i].flags |= QFLAG_APPLIED; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | type = read_pci_config_byte(num, slot, func, |
| 763 | PCI_HEADER_TYPE); |
Lukas Wunner | 850c321 | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 764 | |
| 765 | if ((type & 0x7f) == PCI_HEADER_TYPE_BRIDGE) { |
| 766 | sec = read_pci_config_byte(num, slot, func, PCI_SECONDARY_BUS); |
| 767 | if (sec > num) |
| 768 | early_pci_scan_bus(sec); |
| 769 | } |
| 770 | |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 771 | if (!(type & 0x80)) |
Jesse Barnes | 15650a2 | 2008-06-16 15:29:45 -0700 | [diff] [blame] | 772 | return -1; |
| 773 | |
| 774 | return 0; |
Neil Horman | 7bcbc78 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 775 | } |
| 776 | |
Lukas Wunner | 850c321 | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 777 | static void __init early_pci_scan_bus(int bus) |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 778 | { |
Andi Kleen | 8659c40 | 2009-01-09 12:17:39 -0800 | [diff] [blame] | 779 | int slot, func; |
Andi Kleen | 0637a70 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 780 | |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 781 | /* Poor man's PCI discovery */ |
Andi Kleen | 8659c40 | 2009-01-09 12:17:39 -0800 | [diff] [blame] | 782 | for (slot = 0; slot < 32; slot++) |
| 783 | for (func = 0; func < 8; func++) { |
| 784 | /* Only probe function 0 on single fn devices */ |
Lukas Wunner | 850c321 | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 785 | if (check_dev_quirk(bus, slot, func)) |
Andi Kleen | 8659c40 | 2009-01-09 12:17:39 -0800 | [diff] [blame] | 786 | break; |
| 787 | } |
Andi Kleen | dfa4698 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 788 | } |
Lukas Wunner | 850c321 | 2016-06-12 12:31:53 +0200 | [diff] [blame] | 789 | |
| 790 | void __init early_quirks(void) |
| 791 | { |
| 792 | if (!early_pci_allowed()) |
| 793 | return; |
| 794 | |
| 795 | early_pci_scan_bus(0); |
| 796 | } |