Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Firmware replacement code. |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 3 | * |
Pavel Machek | 8caac56 | 2008-11-26 17:15:27 +0100 | [diff] [blame] | 4 | * Work around broken BIOSes that don't set an aperture, only set the |
| 5 | * aperture in the AGP bridge, or set too small aperture. |
| 6 | * |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 7 | * If all fails map the aperture over some low memory. This is cheaper than |
| 8 | * doing bounce buffering. The memory is lost. This is done at early boot |
| 9 | * because only the bootmem allocator can allocate 32+MB. |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Copyright 2002 Andi Kleen, SuSE Labs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | */ |
Bjorn Helgaas | a5d3244 | 2014-04-28 15:16:33 -0600 | [diff] [blame] | 13 | #define pr_fmt(fmt) "AGP: " fmt |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/init.h> |
Yinghai Lu | 32e3f2b | 2010-12-17 16:58:40 -0800 | [diff] [blame] | 18 | #include <linux/memblock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/mmzone.h> |
| 20 | #include <linux/pci_ids.h> |
| 21 | #include <linux/pci.h> |
| 22 | #include <linux/bitops.h> |
Pavel Machek | 2050d45 | 2008-03-13 23:05:41 +0100 | [diff] [blame] | 23 | #include <linux/suspend.h> |
Ingo Molnar | 66441bd | 2017-01-27 10:27:10 +0100 | [diff] [blame] | 24 | #include <asm/e820/api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/io.h> |
FUJITA Tomonori | 46a7fa2 | 2008-07-11 10:23:42 +0900 | [diff] [blame] | 26 | #include <asm/iommu.h> |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 27 | #include <asm/gart.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/pci-direct.h> |
Andi Kleen | ca8642f | 2006-01-11 22:44:27 +0100 | [diff] [blame] | 29 | #include <asm/dma.h> |
Andreas Herrmann | 23ac4ae | 2010-09-17 18:03:43 +0200 | [diff] [blame] | 30 | #include <asm/amd_nb.h> |
FUJITA Tomonori | de95762 | 2009-11-10 19:46:14 +0900 | [diff] [blame] | 31 | #include <asm/x86_init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Joerg Roedel | c387aa3 | 2011-04-18 15:45:43 +0200 | [diff] [blame] | 33 | /* |
| 34 | * Using 512M as goal, in case kexec will load kernel_big |
| 35 | * that will do the on-position decompress, and could overlap with |
| 36 | * with the gart aperture that is used. |
| 37 | * Sequence: |
| 38 | * kernel_small |
| 39 | * ==> kexec (with kdump trigger path or gart still enabled) |
| 40 | * ==> kernel_small (gart area become e820_reserved) |
| 41 | * ==> kexec (with kdump trigger path or gart still enabled) |
| 42 | * ==> kerne_big (uncompressed size will be big than 64M or 128M) |
| 43 | * So don't use 512M below as gart iommu, leave the space for kernel |
| 44 | * code for safe. |
| 45 | */ |
| 46 | #define GART_MIN_ADDR (512ULL << 20) |
| 47 | #define GART_MAX_ADDR (1ULL << 32) |
| 48 | |
Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 49 | int gart_iommu_aperture; |
Pavel Machek | 7de6a4c | 2008-03-13 11:03:58 +0100 | [diff] [blame] | 50 | int gart_iommu_aperture_disabled __initdata; |
| 51 | int gart_iommu_aperture_allowed __initdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | int fallback_aper_order __initdata = 1; /* 64MB */ |
Pavel Machek | 7de6a4c | 2008-03-13 11:03:58 +0100 | [diff] [blame] | 54 | int fallback_aper_force __initdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | int fix_aperture __initdata = 1; |
| 57 | |
Andrew Morton | 42442ed | 2005-06-08 15:49:25 -0700 | [diff] [blame] | 58 | /* This code runs before the PCI subsystem is initialized, so just |
| 59 | access the northbridge directly. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 61 | static u32 __init allocate_aperture(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | u32 aper_size; |
Yinghai Lu | 32e3f2b | 2010-12-17 16:58:40 -0800 | [diff] [blame] | 64 | unsigned long addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Yinghai Lu | 7677b2e | 2008-04-14 20:40:37 -0700 | [diff] [blame] | 66 | /* aper_size should <= 1G */ |
| 67 | if (fallback_aper_order > 5) |
| 68 | fallback_aper_order = 5; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 69 | aper_size = (32 * 1024 * 1024) << fallback_aper_order; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 71 | /* |
| 72 | * Aperture has to be naturally aligned. This means a 2GB aperture |
| 73 | * won't have much chance of finding a place in the lower 4GB of |
| 74 | * memory. Unfortunately we cannot move it up because that would |
| 75 | * make the IOMMU useless. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | */ |
Joerg Roedel | c387aa3 | 2011-04-18 15:45:43 +0200 | [diff] [blame] | 77 | addr = memblock_find_in_range(GART_MIN_ADDR, GART_MAX_ADDR, |
| 78 | aper_size, aper_size); |
Wang YanQing | 26bfc54 | 2013-04-16 09:37:34 +0800 | [diff] [blame] | 79 | if (!addr) { |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 80 | pr_err("Cannot allocate aperture memory hole [mem %#010lx-%#010lx] (%uKB)\n", |
| 81 | addr, addr + aper_size - 1, aper_size >> 10); |
Yinghai Lu | 32e3f2b | 2010-12-17 16:58:40 -0800 | [diff] [blame] | 82 | return 0; |
| 83 | } |
Tejun Heo | 24aa078 | 2011-07-12 11:16:06 +0200 | [diff] [blame] | 84 | memblock_reserve(addr, aper_size); |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 85 | pr_info("Mapping aperture over RAM [mem %#010lx-%#010lx] (%uKB)\n", |
| 86 | addr, addr + aper_size - 1, aper_size >> 10); |
Yinghai Lu | 32e3f2b | 2010-12-17 16:58:40 -0800 | [diff] [blame] | 87 | register_nosave_region(addr >> PAGE_SHIFT, |
| 88 | (addr+aper_size) >> PAGE_SHIFT); |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 89 | |
Yinghai Lu | 32e3f2b | 2010-12-17 16:58:40 -0800 | [diff] [blame] | 90 | return (u32)addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Andrew Morton | 42442ed | 2005-06-08 15:49:25 -0700 | [diff] [blame] | 94 | /* Find a PCI capability */ |
Pavel Machek | dd564d0 | 2008-05-27 18:03:56 +0200 | [diff] [blame] | 95 | static u32 __init find_cap(int bus, int slot, int func, int cap) |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 96 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | int bytes; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 98 | u8 pos; |
| 99 | |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 100 | if (!(read_pci_config_16(bus, slot, func, PCI_STATUS) & |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 101 | PCI_STATUS_CAP_LIST)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return 0; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 103 | |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 104 | pos = read_pci_config_byte(bus, slot, func, PCI_CAPABILITY_LIST); |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 105 | for (bytes = 0; bytes < 48 && pos >= 0x40; bytes++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | u8 id; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 107 | |
| 108 | pos &= ~3; |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 109 | id = read_pci_config_byte(bus, slot, func, pos+PCI_CAP_LIST_ID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | if (id == 0xff) |
| 111 | break; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 112 | if (id == cap) |
| 113 | return pos; |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 114 | pos = read_pci_config_byte(bus, slot, func, |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 115 | pos+PCI_CAP_LIST_NEXT); |
| 116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | return 0; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | /* Read a standard AGPv3 bridge header */ |
Pavel Machek | dd564d0 | 2008-05-27 18:03:56 +0200 | [diff] [blame] | 121 | static u32 __init read_agp(int bus, int slot, int func, int cap, u32 *order) |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 122 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | u32 apsize; |
| 124 | u32 apsizereg; |
| 125 | int nbits; |
| 126 | u32 aper_low, aper_hi; |
| 127 | u64 aper; |
Yinghai Lu | 1edc1ab | 2008-04-13 01:11:41 -0700 | [diff] [blame] | 128 | u32 old_order; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 130 | pr_info("pci 0000:%02x:%02x:%02x: AGP bridge\n", bus, slot, func); |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 131 | apsizereg = read_pci_config_16(bus, slot, func, cap + 0x14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | if (apsizereg == 0xffffffff) { |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 133 | pr_err("pci 0000:%02x:%02x.%d: APSIZE unreadable\n", |
| 134 | bus, slot, func); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
Yinghai Lu | 1edc1ab | 2008-04-13 01:11:41 -0700 | [diff] [blame] | 138 | /* old_order could be the value from NB gart setting */ |
| 139 | old_order = *order; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | apsize = apsizereg & 0xfff; |
| 142 | /* Some BIOS use weird encodings not in the AGPv3 table. */ |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 143 | if (apsize & 0xff) |
| 144 | apsize |= 0xf00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | nbits = hweight16(apsize); |
| 146 | *order = 7 - nbits; |
| 147 | if ((int)*order < 0) /* < 32MB */ |
| 148 | *order = 0; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 149 | |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 150 | aper_low = read_pci_config(bus, slot, func, 0x10); |
| 151 | aper_hi = read_pci_config(bus, slot, func, 0x14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | aper = (aper_low & ~((1<<22)-1)) | ((u64)aper_hi << 32); |
| 153 | |
Yinghai Lu | 1edc1ab | 2008-04-13 01:11:41 -0700 | [diff] [blame] | 154 | /* |
| 155 | * On some sick chips, APSIZE is 0. It means it wants 4G |
| 156 | * so let double check that order, and lets trust AMD NB settings: |
| 157 | */ |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 158 | pr_info("pci 0000:%02x:%02x.%d: AGP aperture [bus addr %#010Lx-%#010Lx] (old size %uMB)\n", |
| 159 | bus, slot, func, aper, aper + (32ULL << (old_order + 20)) - 1, |
| 160 | 32 << old_order); |
Yinghai Lu | 8c9fd91 | 2008-04-13 18:42:31 -0700 | [diff] [blame] | 161 | if (aper + (32ULL<<(20 + *order)) > 0x100000000ULL) { |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 162 | pr_info("pci 0000:%02x:%02x.%d: AGP aperture size %uMB (APSIZE %#x) is not right, using settings from NB\n", |
| 163 | bus, slot, func, 32 << *order, apsizereg); |
Yinghai Lu | 1edc1ab | 2008-04-13 01:11:41 -0700 | [diff] [blame] | 164 | *order = old_order; |
| 165 | } |
| 166 | |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 167 | pr_info("pci 0000:%02x:%02x.%d: AGP aperture [bus addr %#010Lx-%#010Lx] (%uMB, APSIZE %#x)\n", |
| 168 | bus, slot, func, aper, aper + (32ULL << (*order + 20)) - 1, |
Bjorn Helgaas | a5d3244 | 2014-04-28 15:16:33 -0600 | [diff] [blame] | 169 | 32 << *order, apsizereg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Yinghai Lu | 8c9fd91 | 2008-04-13 18:42:31 -0700 | [diff] [blame] | 171 | if (!aperture_valid(aper, (32*1024*1024) << *order, 32<<20)) |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 172 | return 0; |
| 173 | return (u32)aper; |
| 174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 176 | /* |
| 177 | * Look for an AGP bridge. Windows only expects the aperture in the |
| 178 | * AGP bridge and some BIOS forget to initialize the Northbridge too. |
| 179 | * Work around this here. |
| 180 | * |
| 181 | * Do an PCI bus scan by hand because we're running before the PCI |
| 182 | * subsystem. |
| 183 | * |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 184 | * All AMD AGP bridges are AGPv3 compliant, so we can do this scan |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 185 | * generically. It's probably overkill to always scan all slots because |
| 186 | * the AGP bridges should be always an own bus on the HT hierarchy, |
| 187 | * but do it here for future safety. |
| 188 | */ |
Pavel Machek | dd564d0 | 2008-05-27 18:03:56 +0200 | [diff] [blame] | 189 | static u32 __init search_agp_bridge(u32 *order, int *valid_agp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 191 | int bus, slot, func; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | /* Poor man's PCI discovery */ |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 194 | for (bus = 0; bus < 256; bus++) { |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 195 | for (slot = 0; slot < 32; slot++) { |
| 196 | for (func = 0; func < 8; func++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | u32 class, cap; |
| 198 | u8 type; |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 199 | class = read_pci_config(bus, slot, func, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | PCI_CLASS_REVISION); |
| 201 | if (class == 0xffffffff) |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 202 | break; |
| 203 | |
| 204 | switch (class >> 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | case PCI_CLASS_BRIDGE_HOST: |
| 206 | case PCI_CLASS_BRIDGE_OTHER: /* needed? */ |
| 207 | /* AGP bridge? */ |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 208 | cap = find_cap(bus, slot, func, |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 209 | PCI_CAP_ID_AGP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | if (!cap) |
| 211 | break; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 212 | *valid_agp = 1; |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 213 | return read_agp(bus, slot, func, cap, |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 214 | order); |
| 215 | } |
| 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | /* No multi-function device? */ |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 218 | type = read_pci_config_byte(bus, slot, func, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | PCI_HEADER_TYPE); |
| 220 | if (!(type & 0x80)) |
| 221 | break; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 222 | } |
| 223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
Bjorn Helgaas | a5d3244 | 2014-04-28 15:16:33 -0600 | [diff] [blame] | 225 | pr_info("No AGP bridge found\n"); |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | return 0; |
| 228 | } |
| 229 | |
Kees Cook | 4cc7ecb7 | 2016-03-17 14:23:00 -0700 | [diff] [blame] | 230 | static bool gart_fix_e820 __initdata = true; |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 231 | |
| 232 | static int __init parse_gart_mem(char *p) |
| 233 | { |
Kees Cook | 4cc7ecb7 | 2016-03-17 14:23:00 -0700 | [diff] [blame] | 234 | return kstrtobool(p, &gart_fix_e820); |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 235 | } |
| 236 | early_param("gart_fix_e820", parse_gart_mem); |
| 237 | |
| 238 | void __init early_gart_iommu_check(void) |
| 239 | { |
| 240 | /* |
| 241 | * in case it is enabled before, esp for kexec/kdump, |
| 242 | * previous kernel already enable that. memset called |
| 243 | * by allocate_aperture/__alloc_bootmem_nopanic cause restart. |
| 244 | * or second kernel have different position for GART hole. and new |
| 245 | * kernel could use hole as RAM that is still used by GART set by |
| 246 | * first kernel |
| 247 | * or BIOS forget to put that in reserved. |
| 248 | * try to update e820 to make that region as reserved. |
| 249 | */ |
Andi Kleen | fa10ba6 | 2010-07-20 15:19:49 -0700 | [diff] [blame] | 250 | u32 agp_aper_order = 0; |
Yinghai Lu | f3eee54 | 2009-12-14 11:52:15 +0900 | [diff] [blame] | 251 | int i, fix, slot, valid_agp = 0; |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 252 | u32 ctl; |
| 253 | u32 aper_size = 0, aper_order = 0, last_aper_order = 0; |
| 254 | u64 aper_base = 0, last_aper_base = 0; |
Pavel Machek | fa5b8a3 | 2008-05-26 20:40:47 +0200 | [diff] [blame] | 255 | int aper_enabled = 0, last_aper_enabled = 0, last_valid = 0; |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 256 | |
Aravind Gopalakrishnan | 1b45742 | 2015-04-07 16:46:37 -0500 | [diff] [blame] | 257 | if (!amd_gart_present()) |
| 258 | return; |
| 259 | |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 260 | if (!early_pci_allowed()) |
| 261 | return; |
| 262 | |
Pavel Machek | fa5b8a3 | 2008-05-26 20:40:47 +0200 | [diff] [blame] | 263 | /* This is mostly duplicate of iommu_hole_init */ |
Andi Kleen | fa10ba6 | 2010-07-20 15:19:49 -0700 | [diff] [blame] | 264 | search_agp_bridge(&agp_aper_order, &valid_agp); |
Yinghai Lu | f3eee54 | 2009-12-14 11:52:15 +0900 | [diff] [blame] | 265 | |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 266 | fix = 0; |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 267 | for (i = 0; amd_nb_bus_dev_ranges[i].dev_limit; i++) { |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 268 | int bus; |
| 269 | int dev_base, dev_limit; |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 270 | |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 271 | bus = amd_nb_bus_dev_ranges[i].bus; |
| 272 | dev_base = amd_nb_bus_dev_ranges[i].dev_base; |
| 273 | dev_limit = amd_nb_bus_dev_ranges[i].dev_limit; |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 274 | |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 275 | for (slot = dev_base; slot < dev_limit; slot++) { |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 276 | if (!early_is_amd_nb(read_pci_config(bus, slot, 3, 0x00))) |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 277 | continue; |
| 278 | |
| 279 | ctl = read_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL); |
Borislav Petkov | 57ab43e | 2010-09-03 18:39:39 +0200 | [diff] [blame] | 280 | aper_enabled = ctl & GARTEN; |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 281 | aper_order = (ctl >> 1) & 7; |
| 282 | aper_size = (32 * 1024 * 1024) << aper_order; |
| 283 | aper_base = read_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE) & 0x7fff; |
| 284 | aper_base <<= 25; |
| 285 | |
Pavel Machek | fa5b8a3 | 2008-05-26 20:40:47 +0200 | [diff] [blame] | 286 | if (last_valid) { |
| 287 | if ((aper_order != last_aper_order) || |
| 288 | (aper_base != last_aper_base) || |
| 289 | (aper_enabled != last_aper_enabled)) { |
| 290 | fix = 1; |
| 291 | break; |
| 292 | } |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 293 | } |
Pavel Machek | fa5b8a3 | 2008-05-26 20:40:47 +0200 | [diff] [blame] | 294 | |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 295 | last_aper_order = aper_order; |
| 296 | last_aper_base = aper_base; |
| 297 | last_aper_enabled = aper_enabled; |
Pavel Machek | fa5b8a3 | 2008-05-26 20:40:47 +0200 | [diff] [blame] | 298 | last_valid = 1; |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 299 | } |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | if (!fix && !aper_enabled) |
| 303 | return; |
| 304 | |
| 305 | if (!aper_base || !aper_size || aper_base + aper_size > 0x100000000UL) |
| 306 | fix = 1; |
| 307 | |
| 308 | if (gart_fix_e820 && !fix && aper_enabled) { |
Ingo Molnar | 3bce64f | 2017-01-28 14:14:25 +0100 | [diff] [blame] | 309 | if (e820__mapped_any(aper_base, aper_base + aper_size, |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 310 | E820_TYPE_RAM)) { |
Pavel Machek | 0abbc78 | 2008-05-20 16:27:17 +0200 | [diff] [blame] | 311 | /* reserve it, so we can reuse it in second kernel */ |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 312 | pr_info("e820: reserve [mem %#010Lx-%#010Lx] for GART\n", |
| 313 | aper_base, aper_base + aper_size - 1); |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 314 | e820__range_add(aper_base, aper_size, E820_TYPE_RESERVED); |
Ingo Molnar | 6464d29 | 2017-01-28 14:03:04 +0100 | [diff] [blame] | 315 | e820__update_table_print(); |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 316 | } |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 317 | } |
| 318 | |
Yinghai Lu | f3eee54 | 2009-12-14 11:52:15 +0900 | [diff] [blame] | 319 | if (valid_agp) |
Pavel Machek | 4f384f8 | 2008-05-26 21:17:30 +0200 | [diff] [blame] | 320 | return; |
| 321 | |
Yinghai Lu | f3eee54 | 2009-12-14 11:52:15 +0900 | [diff] [blame] | 322 | /* disable them all at first */ |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 323 | for (i = 0; i < amd_nb_bus_dev_ranges[i].dev_limit; i++) { |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 324 | int bus; |
| 325 | int dev_base, dev_limit; |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 326 | |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 327 | bus = amd_nb_bus_dev_ranges[i].bus; |
| 328 | dev_base = amd_nb_bus_dev_ranges[i].dev_base; |
| 329 | dev_limit = amd_nb_bus_dev_ranges[i].dev_limit; |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 330 | |
| 331 | for (slot = dev_base; slot < dev_limit; slot++) { |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 332 | if (!early_is_amd_nb(read_pci_config(bus, slot, 3, 0x00))) |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 333 | continue; |
| 334 | |
| 335 | ctl = read_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL); |
Borislav Petkov | 57ab43e | 2010-09-03 18:39:39 +0200 | [diff] [blame] | 336 | ctl &= ~GARTEN; |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 337 | write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, ctl); |
| 338 | } |
Yinghai Lu | aaf2304 | 2008-01-30 13:33:09 +0100 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | } |
| 342 | |
Yinghai Lu | 8c9fd91 | 2008-04-13 18:42:31 -0700 | [diff] [blame] | 343 | static int __initdata printed_gart_size_msg; |
| 344 | |
Konrad Rzeszutek Wilk | 480125b | 2010-08-26 13:57:57 -0400 | [diff] [blame] | 345 | int __init gart_iommu_hole_init(void) |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 346 | { |
Yinghai Lu | 8c9fd91 | 2008-04-13 18:42:31 -0700 | [diff] [blame] | 347 | u32 agp_aper_base = 0, agp_aper_order = 0; |
Andi Kleen | 50895c5 | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 348 | u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | u64 aper_base, last_aper_base = 0; |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 350 | int fix, slot, valid_agp = 0; |
| 351 | int i, node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Aravind Gopalakrishnan | 1b45742 | 2015-04-07 16:46:37 -0500 | [diff] [blame] | 353 | if (!amd_gart_present()) |
| 354 | return -ENODEV; |
| 355 | |
Joerg Roedel | 0440d4c | 2007-10-24 12:49:50 +0200 | [diff] [blame] | 356 | if (gart_iommu_aperture_disabled || !fix_aperture || |
| 357 | !early_pci_allowed()) |
Konrad Rzeszutek Wilk | 480125b | 2010-08-26 13:57:57 -0400 | [diff] [blame] | 358 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Bjorn Helgaas | a5d3244 | 2014-04-28 15:16:33 -0600 | [diff] [blame] | 360 | pr_info("Checking aperture...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
Yinghai Lu | 8c9fd91 | 2008-04-13 18:42:31 -0700 | [diff] [blame] | 362 | if (!fallback_aper_force) |
| 363 | agp_aper_base = search_agp_bridge(&agp_aper_order, &valid_agp); |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | fix = 0; |
Yinghai Lu | 47db4c3 | 2008-01-30 13:33:18 +0100 | [diff] [blame] | 366 | node = 0; |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 367 | for (i = 0; i < amd_nb_bus_dev_ranges[i].dev_limit; i++) { |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 368 | int bus; |
| 369 | int dev_base, dev_limit; |
Joerg Roedel | 4b83873 | 2010-04-07 12:57:35 +0200 | [diff] [blame] | 370 | u32 ctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 372 | bus = amd_nb_bus_dev_ranges[i].bus; |
| 373 | dev_base = amd_nb_bus_dev_ranges[i].dev_base; |
| 374 | dev_limit = amd_nb_bus_dev_ranges[i].dev_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 376 | for (slot = dev_base; slot < dev_limit; slot++) { |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 377 | if (!early_is_amd_nb(read_pci_config(bus, slot, 3, 0x00))) |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 378 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 380 | iommu_detected = 1; |
| 381 | gart_iommu_aperture = 1; |
FUJITA Tomonori | de95762 | 2009-11-10 19:46:14 +0900 | [diff] [blame] | 382 | x86_init.iommu.iommu_init = gart_iommu_init; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 383 | |
Joerg Roedel | 4b83873 | 2010-04-07 12:57:35 +0200 | [diff] [blame] | 384 | ctl = read_pci_config(bus, slot, 3, |
| 385 | AMD64_GARTAPERTURECTL); |
| 386 | |
| 387 | /* |
| 388 | * Before we do anything else disable the GART. It may |
| 389 | * still be enabled if we boot into a crash-kernel here. |
| 390 | * Reconfiguring the GART while it is enabled could have |
| 391 | * unknown side-effects. |
| 392 | */ |
| 393 | ctl &= ~GARTEN; |
| 394 | write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, ctl); |
| 395 | |
| 396 | aper_order = (ctl >> 1) & 7; |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 397 | aper_size = (32 * 1024 * 1024) << aper_order; |
| 398 | aper_base = read_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE) & 0x7fff; |
| 399 | aper_base <<= 25; |
| 400 | |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 401 | pr_info("Node %d: aperture [bus addr %#010Lx-%#010Lx] (%uMB)\n", |
| 402 | node, aper_base, aper_base + aper_size - 1, |
| 403 | aper_size >> 20); |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 404 | node++; |
| 405 | |
| 406 | if (!aperture_valid(aper_base, aper_size, 64<<20)) { |
| 407 | if (valid_agp && agp_aper_base && |
| 408 | agp_aper_base == aper_base && |
| 409 | agp_aper_order == aper_order) { |
| 410 | /* the same between two setting from NB and agp */ |
Yinghai Lu | c987d12 | 2008-06-24 22:14:09 -0700 | [diff] [blame] | 411 | if (!no_iommu && |
| 412 | max_pfn > MAX_DMA32_PFN && |
| 413 | !printed_gart_size_msg) { |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 414 | pr_err("you are using iommu with agp, but GART size is less than 64MB\n"); |
Bjorn Helgaas | a5d3244 | 2014-04-28 15:16:33 -0600 | [diff] [blame] | 415 | pr_err("please increase GART size in your BIOS setup\n"); |
| 416 | pr_err("if BIOS doesn't have that option, contact your HW vendor!\n"); |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 417 | printed_gart_size_msg = 1; |
| 418 | } |
| 419 | } else { |
| 420 | fix = 1; |
| 421 | goto out; |
Yinghai Lu | 8c9fd91 | 2008-04-13 18:42:31 -0700 | [diff] [blame] | 422 | } |
Yinghai Lu | 8c9fd91 | 2008-04-13 18:42:31 -0700 | [diff] [blame] | 423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 425 | if ((last_aper_order && aper_order != last_aper_order) || |
| 426 | (last_aper_base && aper_base != last_aper_base)) { |
| 427 | fix = 1; |
| 428 | goto out; |
| 429 | } |
| 430 | last_aper_order = aper_order; |
| 431 | last_aper_base = aper_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 435 | out: |
Aaron Durbin | 56dd669 | 2006-09-26 10:52:40 +0200 | [diff] [blame] | 436 | if (!fix && !fallback_aper_force) { |
Bjorn Helgaas | 707d4ee | 2014-03-18 14:26:12 -0600 | [diff] [blame] | 437 | if (last_aper_base) |
Konrad Rzeszutek Wilk | 480125b | 2010-08-26 13:57:57 -0400 | [diff] [blame] | 438 | return 1; |
Konrad Rzeszutek Wilk | 480125b | 2010-08-26 13:57:57 -0400 | [diff] [blame] | 439 | return 0; |
Aaron Durbin | 56dd669 | 2006-09-26 10:52:40 +0200 | [diff] [blame] | 440 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Yinghai Lu | 8c9fd91 | 2008-04-13 18:42:31 -0700 | [diff] [blame] | 442 | if (!fallback_aper_force) { |
| 443 | aper_alloc = agp_aper_base; |
| 444 | aper_order = agp_aper_order; |
| 445 | } |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 446 | |
| 447 | if (aper_alloc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | /* Got the aperture from the AGP bridge */ |
Yinghai Lu | c987d12 | 2008-06-24 22:14:09 -0700 | [diff] [blame] | 449 | } else if ((!no_iommu && max_pfn > MAX_DMA32_PFN) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | force_iommu || |
| 451 | valid_agp || |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 452 | fallback_aper_force) { |
Aravind Gopalakrishnan | 1b45742 | 2015-04-07 16:46:37 -0500 | [diff] [blame] | 453 | pr_info("Your BIOS doesn't leave an aperture memory hole\n"); |
Bjorn Helgaas | a5d3244 | 2014-04-28 15:16:33 -0600 | [diff] [blame] | 454 | pr_info("Please enable the IOMMU option in the BIOS setup\n"); |
Bjorn Helgaas | c96ec95 | 2014-04-14 15:29:19 -0600 | [diff] [blame] | 455 | pr_info("This costs you %dMB of RAM\n", |
Bjorn Helgaas | a5d3244 | 2014-04-28 15:16:33 -0600 | [diff] [blame] | 456 | 32 << fallback_aper_order); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
| 458 | aper_order = fallback_aper_order; |
| 459 | aper_alloc = allocate_aperture(); |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 460 | if (!aper_alloc) { |
| 461 | /* |
| 462 | * Could disable AGP and IOMMU here, but it's |
| 463 | * probably not worth it. But the later users |
| 464 | * cannot deal with bad apertures and turning |
| 465 | * on the aperture over memory causes very |
| 466 | * strange problems, so it's better to panic |
| 467 | * early. |
| 468 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | panic("Not enough memory for aperture"); |
| 470 | } |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 471 | } else { |
Konrad Rzeszutek Wilk | 480125b | 2010-08-26 13:57:57 -0400 | [diff] [blame] | 472 | return 0; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | /* Fix up the north bridges */ |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 476 | for (i = 0; i < amd_nb_bus_dev_ranges[i].dev_limit; i++) { |
Borislav Petkov | 260133a | 2010-09-03 18:39:40 +0200 | [diff] [blame] | 477 | int bus, dev_base, dev_limit; |
| 478 | |
| 479 | /* |
| 480 | * Don't enable translation yet but enable GART IO and CPU |
| 481 | * accesses and set DISTLBWALKPRB since GART table memory is UC. |
| 482 | */ |
Joerg Roedel | c34151a | 2011-04-18 15:45:45 +0200 | [diff] [blame] | 483 | u32 ctl = aper_order << 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 485 | bus = amd_nb_bus_dev_ranges[i].bus; |
| 486 | dev_base = amd_nb_bus_dev_ranges[i].dev_base; |
| 487 | dev_limit = amd_nb_bus_dev_ranges[i].dev_limit; |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 488 | for (slot = dev_base; slot < dev_limit; slot++) { |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 489 | if (!early_is_amd_nb(read_pci_config(bus, slot, 3, 0x00))) |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 490 | continue; |
| 491 | |
Borislav Petkov | 260133a | 2010-09-03 18:39:40 +0200 | [diff] [blame] | 492 | write_pci_config(bus, slot, 3, AMD64_GARTAPERTURECTL, ctl); |
Yinghai Lu | 55c0d72 | 2008-04-19 01:31:11 -0700 | [diff] [blame] | 493 | write_pci_config(bus, slot, 3, AMD64_GARTAPERTUREBASE, aper_alloc >> 25); |
| 494 | } |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 495 | } |
Rafael J. Wysocki | 6703f6d | 2008-06-10 00:10:48 +0200 | [diff] [blame] | 496 | |
| 497 | set_up_gart_resume(aper_order, aper_alloc); |
Konrad Rzeszutek Wilk | 480125b | 2010-08-26 13:57:57 -0400 | [diff] [blame] | 498 | |
| 499 | return 1; |
Ingo Molnar | c140df9 | 2008-01-30 13:30:09 +0100 | [diff] [blame] | 500 | } |