Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: Set ROM shadow location in arch code, not in PCI core

IORESOURCE_ROM_SHADOW means there is a copy of a device's option ROM in
RAM. The existence of such a copy and its location are arch-specific.
Previously the IORESOURCE_ROM_SHADOW flag was set in arch code, but the
0xC0000-0xDFFFF location was hard-coded into the PCI core.

If we're using a shadow copy in RAM, disable the ROM BAR and release the
address space it was consuming. Move the location information from the PCI
core to the arch code that sets IORESOURCE_ROM_SHADOW. Save the location
of the RAM copy in the struct resource for PCI_ROM_RESOURCE.

After this change, pci_map_rom() will call pci_assign_resource() and
pci_enable_rom() for these IORESOURCE_ROM_SHADOW resources, which we did
not do before. This is safe because:

- pci_assign_resource() will do nothing because the resource is marked
IORESOURCE_PCI_FIXED, which means we can't move it, and

- pci_enable_rom() will not turn on the ROM BAR's enable bit because the
resource is marked IORESOURCE_ROM_SHADOW, which means it is in RAM
rather than in PCI memory space.

Storing the location in the struct resource means "lspci" will show the
shadow location, not the value from the ROM BAR.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

+33 -24
+16 -6
arch/ia64/pci/fixup.c
··· 17 17 * 18 18 * The standard boot ROM sequence for an x86 machine uses the BIOS 19 19 * to select an initial video card for boot display. This boot video 20 - * card will have it's BIOS copied to C0000 in system RAM. 20 + * card will have its BIOS copied to 0xC0000 in system RAM. 21 21 * IORESOURCE_ROM_SHADOW is used to associate the boot video 22 22 * card with this copy. On laptops this copy has to be used since 23 23 * the main ROM may be compressed or combined with another image. 24 24 * See pci_map_rom() for use of this flag. Before marking the device 25 25 * with IORESOURCE_ROM_SHADOW check if a vga_default_device is already set 26 - * by either arch cde or vga-arbitration, if so only apply the fixup to this 27 - * already determined primary video card. 26 + * by either arch code or vga-arbitration; if so only apply the fixup to this 27 + * already-determined primary video card. 28 28 */ 29 29 30 30 static void pci_fixup_video(struct pci_dev *pdev) ··· 32 32 struct pci_dev *bridge; 33 33 struct pci_bus *bus; 34 34 u16 config; 35 + struct resource *res; 35 36 36 37 if ((strcmp(ia64_platform_name, "dig") != 0) 37 38 && (strcmp(ia64_platform_name, "hpzx1") != 0)) ··· 62 61 if (!vga_default_device() || pdev == vga_default_device()) { 63 62 pci_read_config_word(pdev, PCI_COMMAND, &config); 64 63 if (config & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) { 65 - pdev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_SHADOW | 66 - IORESOURCE_PCI_FIXED; 67 - dev_printk(KERN_DEBUG, &pdev->dev, "Video device with shadowed ROM\n"); 64 + res = &pdev->resource[PCI_ROM_RESOURCE]; 65 + 66 + pci_disable_rom(pdev); 67 + if (res->parent) 68 + release_resource(res); 69 + 70 + res->start = 0xC0000; 71 + res->end = res->start + 0x20000 - 1; 72 + res->flags = IORESOURCE_MEM | IORESOURCE_ROM_SHADOW | 73 + IORESOURCE_PCI_FIXED; 74 + dev_info(&pdev->dev, "Video device with shadowed ROM at %pR\n", 75 + res); 68 76 } 69 77 } 70 78 }
+16 -6
arch/x86/pci/fixup.c
··· 297 297 * 298 298 * The standard boot ROM sequence for an x86 machine uses the BIOS 299 299 * to select an initial video card for boot display. This boot video 300 - * card will have it's BIOS copied to C0000 in system RAM. 300 + * card will have its BIOS copied to 0xC0000 in system RAM. 301 301 * IORESOURCE_ROM_SHADOW is used to associate the boot video 302 302 * card with this copy. On laptops this copy has to be used since 303 303 * the main ROM may be compressed or combined with another image. 304 304 * See pci_map_rom() for use of this flag. Before marking the device 305 305 * with IORESOURCE_ROM_SHADOW check if a vga_default_device is already set 306 - * by either arch cde or vga-arbitration, if so only apply the fixup to this 307 - * already determined primary video card. 306 + * by either arch code or vga-arbitration; if so only apply the fixup to this 307 + * already-determined primary video card. 308 308 */ 309 309 310 310 static void pci_fixup_video(struct pci_dev *pdev) ··· 312 312 struct pci_dev *bridge; 313 313 struct pci_bus *bus; 314 314 u16 config; 315 + struct resource *res; 315 316 316 317 /* Is VGA routed to us? */ 317 318 bus = pdev->bus; ··· 337 336 if (!vga_default_device() || pdev == vga_default_device()) { 338 337 pci_read_config_word(pdev, PCI_COMMAND, &config); 339 338 if (config & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) { 340 - pdev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_SHADOW | 341 - IORESOURCE_PCI_FIXED; 342 - dev_printk(KERN_DEBUG, &pdev->dev, "Video device with shadowed ROM\n"); 339 + res = &pdev->resource[PCI_ROM_RESOURCE]; 340 + 341 + pci_disable_rom(pdev); 342 + if (res->parent) 343 + release_resource(res); 344 + 345 + res->start = 0xC0000; 346 + res->end = res->start + 0x20000 - 1; 347 + res->flags = IORESOURCE_MEM | IORESOURCE_ROM_SHADOW | 348 + IORESOURCE_PCI_FIXED; 349 + dev_info(&pdev->dev, "Video device with shadowed ROM at %pR\n", 350 + res); 343 351 } 344 352 } 345 353 }
-11
drivers/pci/rom.c
··· 128 128 loff_t start; 129 129 void __iomem *rom; 130 130 131 - /* 132 - * IORESOURCE_ROM_SHADOW set on x86, x86_64 and IA64 supports legacy 133 - * memory map if the VGA enable bit of the Bridge Control register is 134 - * set for embedded VGA. 135 - */ 136 - if (res->flags & IORESOURCE_ROM_SHADOW) { 137 - /* primary video rom always starts here */ 138 - start = (loff_t)0xC0000; 139 - *size = 0x20000; /* cover C000:0 through E000:0 */ 140 - } else { 141 131 if (res->flags & 142 132 (IORESOURCE_ROM_COPY | IORESOURCE_ROM_BIOS_COPY)) { 143 133 *size = pci_resource_len(pdev, PCI_ROM_RESOURCE); ··· 147 157 if (pci_enable_rom(pdev)) 148 158 return NULL; 149 159 } 150 - } 151 160 152 161 rom = ioremap(start, *size); 153 162 if (!rom) {
+1 -1
include/linux/ioport.h
··· 98 98 99 99 /* PCI ROM control bits (IORESOURCE_BITS) */ 100 100 #define IORESOURCE_ROM_ENABLE (1<<0) /* ROM is enabled, same as PCI_ROM_ADDRESS_ENABLE */ 101 - #define IORESOURCE_ROM_SHADOW (1<<1) /* ROM is copy at C000:0 */ 101 + #define IORESOURCE_ROM_SHADOW (1<<1) /* Use RAM image, not ROM BAR */ 102 102 #define IORESOURCE_ROM_COPY (1<<2) /* ROM is alloc'd copy, resource field overlaid */ 103 103 #define IORESOURCE_ROM_BIOS_COPY (1<<3) /* ROM is BIOS copy, resource field overlaid */ 104 104