Skip to content

Commit a67462f

Browse files
kwilczynskibjorn-helgaas
authored andcommitted
PCI: Refactor pci_ioremap_bar() and pci_ioremap_wc_bar()
pci_ioremap_bar() and pci_ioremap_wc_bar() shared similar implementations but differed in unimportant ways. Align them by adding a shared helper, __pci_ioremap_resource(). Upgrade warning message to error level, since it indicates a driver defect. Remove WARN_ON() from WC path in favor of the error message. [bhelgaas: commit log, use ioremap() since pci_iomap_range() doesn't add anything] Link: https://lore.kernel.org/r/20210713102436.304693-1-kw@linux.com Signed-off-by: Krzysztof Wilczyński <kw@linux.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent e73f0f0 commit a67462f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

drivers/pci/pci.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,32 +206,36 @@ int pci_status_get_and_clear_errors(struct pci_dev *pdev)
206206
EXPORT_SYMBOL_GPL(pci_status_get_and_clear_errors);
207207

208208
#ifdef CONFIG_HAS_IOMEM
209-
void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar)
209+
static void __iomem *__pci_ioremap_resource(struct pci_dev *pdev, int bar,
210+
bool write_combine)
210211
{
211212
struct resource *res = &pdev->resource[bar];
213+
resource_size_t start = res->start;
214+
resource_size_t size = resource_size(res);
212215

213216
/*
214217
* Make sure the BAR is actually a memory resource, not an IO resource
215218
*/
216219
if (res->flags & IORESOURCE_UNSET || !(res->flags & IORESOURCE_MEM)) {
217-
pci_warn(pdev, "can't ioremap BAR %d: %pR\n", bar, res);
220+
pci_err(pdev, "can't ioremap BAR %d: %pR\n", bar, res);
218221
return NULL;
219222
}
220-
return ioremap(res->start, resource_size(res));
223+
224+
if (write_combine)
225+
return ioremap_wc(start, size);
226+
227+
return ioremap(start, size);
228+
}
229+
230+
void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar)
231+
{
232+
return __pci_ioremap_resource(pdev, bar, false);
221233
}
222234
EXPORT_SYMBOL_GPL(pci_ioremap_bar);
223235

224236
void __iomem *pci_ioremap_wc_bar(struct pci_dev *pdev, int bar)
225237
{
226-
/*
227-
* Make sure the BAR is actually a memory resource, not an IO resource
228-
*/
229-
if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
230-
WARN_ON(1);
231-
return NULL;
232-
}
233-
return ioremap_wc(pci_resource_start(pdev, bar),
234-
pci_resource_len(pdev, bar));
238+
return __pci_ioremap_resource(pdev, bar, true);
235239
}
236240
EXPORT_SYMBOL_GPL(pci_ioremap_wc_bar);
237241
#endif

0 commit comments

Comments
 (0)