aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/rom.c
diff options
context:
space:
mode:
authorMatthew Garrett <matthew.garrett@nebula.com>2013-03-26 17:25:54 -0400
committerBjorn Helgaas <bhelgaas@google.com>2013-03-26 19:19:41 -0400
commitfffe01f7a768d07cc50ace71abe28fbf2f786a43 (patch)
tree6e20b8c21f80d5d27f473e59fdb1696e165fbe1e /drivers/pci/rom.c
parent8bb9660418e05bb1845ac1a2428444d78e322cc7 (diff)
PCI: Add PCI ROM helper for platform-provided ROM images
It turns out that some UEFI systems provide apparently an apparently valid PCI ROM BAR that turns out to contain garbage, so the attempt in 547b52463 to prefer the ROM from the BAR actually breaks a different set of machines. As Linus pointed out, the graphics drivers are probably in the best position to make this judgement, so this basically reverts 547b52463 and f9a37be0f and adds a new helper function. Followup patches will add support to nouveau and radeon for probing this ROM source if they can't find a ROM from some other source. [bhelgaas: added reporter and bugzilla pointers, s/f4eb5ff05/547b52463] Reference: https://bugzilla.redhat.com/show_bug.cgi?id=927451 Reference: http://lkml.kernel.org/r/kg69ef$vdb$1@ger.gmane.org Reported-by: Mantas Mikulėnas <grawity@gmail.com> Reported-by: Chris Murphy <bugzilla@colorremedies.com> Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/rom.c')
-rw-r--r--drivers/pci/rom.c67
1 files changed, 31 insertions, 36 deletions
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index b41ac7756a4b..c5d0a08a8747 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -100,27 +100,6 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
100 return min((size_t)(image - rom), size); 100 return min((size_t)(image - rom), size);
101} 101}
102 102
103static loff_t pci_find_rom(struct pci_dev *pdev, size_t *size)
104{
105 struct resource *res = &pdev->resource[PCI_ROM_RESOURCE];
106 loff_t start;
107
108 /* assign the ROM an address if it doesn't have one */
109 if (res->parent == NULL && pci_assign_resource(pdev, PCI_ROM_RESOURCE))
110 return 0;
111 start = pci_resource_start(pdev, PCI_ROM_RESOURCE);
112 *size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
113
114 if (*size == 0)
115 return 0;
116
117 /* Enable ROM space decodes */
118 if (pci_enable_rom(pdev))
119 return 0;
120
121 return start;
122}
123
124/** 103/**
125 * pci_map_rom - map a PCI ROM to kernel space 104 * pci_map_rom - map a PCI ROM to kernel space
126 * @pdev: pointer to pci device struct 105 * @pdev: pointer to pci device struct
@@ -135,7 +114,7 @@ static loff_t pci_find_rom(struct pci_dev *pdev, size_t *size)
135void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size) 114void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
136{ 115{
137 struct resource *res = &pdev->resource[PCI_ROM_RESOURCE]; 116 struct resource *res = &pdev->resource[PCI_ROM_RESOURCE];
138 loff_t start = 0; 117 loff_t start;
139 void __iomem *rom; 118 void __iomem *rom;
140 119
141 /* 120 /*
@@ -154,21 +133,21 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
154 return (void __iomem *)(unsigned long) 133 return (void __iomem *)(unsigned long)
155 pci_resource_start(pdev, PCI_ROM_RESOURCE); 134 pci_resource_start(pdev, PCI_ROM_RESOURCE);
156 } else { 135 } else {
157 start = pci_find_rom(pdev, size); 136 /* assign the ROM an address if it doesn't have one */
158 } 137 if (res->parent == NULL &&
159 } 138 pci_assign_resource(pdev,PCI_ROM_RESOURCE))
139 return NULL;
140 start = pci_resource_start(pdev, PCI_ROM_RESOURCE);
141 *size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
142 if (*size == 0)
143 return NULL;
160 144
161 /* 145 /* Enable ROM space decodes */
162 * Some devices may provide ROMs via a source other than the BAR 146 if (pci_enable_rom(pdev))
163 */ 147 return NULL;
164 if (!start && pdev->rom && pdev->romlen) { 148 }
165 *size = pdev->romlen;
166 return phys_to_virt(pdev->rom);
167 } 149 }
168 150
169 if (!start)
170 return NULL;
171
172 rom = ioremap(start, *size); 151 rom = ioremap(start, *size);
173 if (!rom) { 152 if (!rom) {
174 /* restore enable if ioremap fails */ 153 /* restore enable if ioremap fails */
@@ -202,8 +181,7 @@ void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom)
202 if (res->flags & (IORESOURCE_ROM_COPY | IORESOURCE_ROM_BIOS_COPY)) 181 if (res->flags & (IORESOURCE_ROM_COPY | IORESOURCE_ROM_BIOS_COPY))
203 return; 182 return;
204 183
205 if (!pdev->rom || !pdev->romlen) 184 iounmap(rom);
206 iounmap(rom);
207 185
208 /* Disable again before continuing, leave enabled if pci=rom */ 186 /* Disable again before continuing, leave enabled if pci=rom */
209 if (!(res->flags & (IORESOURCE_ROM_ENABLE | IORESOURCE_ROM_SHADOW))) 187 if (!(res->flags & (IORESOURCE_ROM_ENABLE | IORESOURCE_ROM_SHADOW)))
@@ -227,7 +205,24 @@ void pci_cleanup_rom(struct pci_dev *pdev)
227 } 205 }
228} 206}
229 207
208/**
209 * pci_platform_rom - provides a pointer to any ROM image provided by the
210 * platform
211 * @pdev: pointer to pci device struct
212 * @size: pointer to receive size of pci window over ROM
213 */
214void __iomem *pci_platform_rom(struct pci_dev *pdev, size_t *size)
215{
216 if (pdev->rom && pdev->romlen) {
217 *size = pdev->romlen;
218 return phys_to_virt((phys_addr_t)pdev->rom);
219 }
220
221 return NULL;
222}
223
230EXPORT_SYMBOL(pci_map_rom); 224EXPORT_SYMBOL(pci_map_rom);
231EXPORT_SYMBOL(pci_unmap_rom); 225EXPORT_SYMBOL(pci_unmap_rom);
232EXPORT_SYMBOL_GPL(pci_enable_rom); 226EXPORT_SYMBOL_GPL(pci_enable_rom);
233EXPORT_SYMBOL_GPL(pci_disable_rom); 227EXPORT_SYMBOL_GPL(pci_disable_rom);
228EXPORT_SYMBOL(pci_platform_rom);