Skip to content

Commit 1278c9f

Browse files
sumitsemwalgregkh
authored andcommitted
PCI: Add comments about ROM BAR updating
From: Bjorn Helgaas <bhelgaas@google.com> [ Upstream commit 0b457dde3cf8b7c76a60f8e960f21bbd4abdc416 ] pci_update_resource() updates a hardware BAR so its address matches the kernel's struct resource UNLESS it's a disabled ROM BAR. We only update those when we enable the ROM. It's not obvious from the code why ROM BARs should be handled specially. Apparently there are Matrox devices with defective ROM BARs that read as zero when disabled. That means that if pci_enable_rom() reads the disabled BAR, sets PCI_ROM_ADDRESS_ENABLE (without re-inserting the address), and writes it back, it would enable the ROM at address zero. Add comments and references to explain why we can't make the code look more rational. The code changes are from 755528c ("Ignore disabled ROM resources at setup") and 8085ce0 ("[PATCH] Fix PCI ROM mapping"). Link: https://lkml.org/lkml/2005/8/30/138 Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [sumits: minor fixup in rom.c for 4.4.y] Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cef498a commit 1278c9f

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

drivers/pci/rom.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ int pci_enable_rom(struct pci_dev *pdev)
3131
if (!res->flags)
3232
return -1;
3333

34+
/*
35+
* Ideally pci_update_resource() would update the ROM BAR address,
36+
* and we would only set the enable bit here. But apparently some
37+
* devices have buggy ROM BARs that read as zero when disabled.
38+
*/
3439
pcibios_resource_to_bus(pdev->bus, &region, res);
3540
pci_read_config_dword(pdev, pdev->rom_base_reg, &rom_addr);
3641
rom_addr &= ~PCI_ROM_ADDRESS_MASK;

drivers/pci/setup-res.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ static void pci_std_update_resource(struct pci_dev *dev, int resno)
6868
if (resno < PCI_ROM_RESOURCE) {
6969
reg = PCI_BASE_ADDRESS_0 + 4 * resno;
7070
} else if (resno == PCI_ROM_RESOURCE) {
71+
72+
/*
73+
* Apparently some Matrox devices have ROM BARs that read
74+
* as zero when disabled, so don't update ROM BARs unless
75+
* they're enabled. See https://lkml.org/lkml/2005/8/30/138.
76+
*/
7177
if (!(res->flags & IORESOURCE_ROM_ENABLE))
7278
return;
7379

0 commit comments

Comments
 (0)