Merge branch 'pci/resource'
- Refactor pci_ioremap_bar() and pci_ioremap_wc_bar() (Krzysztof Wilczyński) - Optimize pci_resource_len() to reduce kernel size (Zhen Lei) * pci/resource: PCI: Optimize pci_resource_len() to reduce kernel size PCI: Refactor pci_ioremap_bar() and pci_ioremap_wc_bar()
This commit is contained in:
@@ -212,32 +212,36 @@ int pci_status_get_and_clear_errors(struct pci_dev *pdev)
|
|||||||
EXPORT_SYMBOL_GPL(pci_status_get_and_clear_errors);
|
EXPORT_SYMBOL_GPL(pci_status_get_and_clear_errors);
|
||||||
|
|
||||||
#ifdef CONFIG_HAS_IOMEM
|
#ifdef CONFIG_HAS_IOMEM
|
||||||
void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar)
|
static void __iomem *__pci_ioremap_resource(struct pci_dev *pdev, int bar,
|
||||||
|
bool write_combine)
|
||||||
{
|
{
|
||||||
struct resource *res = &pdev->resource[bar];
|
struct resource *res = &pdev->resource[bar];
|
||||||
|
resource_size_t start = res->start;
|
||||||
|
resource_size_t size = resource_size(res);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure the BAR is actually a memory resource, not an IO resource
|
* Make sure the BAR is actually a memory resource, not an IO resource
|
||||||
*/
|
*/
|
||||||
if (res->flags & IORESOURCE_UNSET || !(res->flags & IORESOURCE_MEM)) {
|
if (res->flags & IORESOURCE_UNSET || !(res->flags & IORESOURCE_MEM)) {
|
||||||
pci_warn(pdev, "can't ioremap BAR %d: %pR\n", bar, res);
|
pci_err(pdev, "can't ioremap BAR %d: %pR\n", bar, res);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return ioremap(res->start, resource_size(res));
|
|
||||||
|
if (write_combine)
|
||||||
|
return ioremap_wc(start, size);
|
||||||
|
|
||||||
|
return ioremap(start, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar)
|
||||||
|
{
|
||||||
|
return __pci_ioremap_resource(pdev, bar, false);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(pci_ioremap_bar);
|
EXPORT_SYMBOL_GPL(pci_ioremap_bar);
|
||||||
|
|
||||||
void __iomem *pci_ioremap_wc_bar(struct pci_dev *pdev, int bar)
|
void __iomem *pci_ioremap_wc_bar(struct pci_dev *pdev, int bar)
|
||||||
{
|
{
|
||||||
/*
|
return __pci_ioremap_resource(pdev, bar, true);
|
||||||
* Make sure the BAR is actually a memory resource, not an IO resource
|
|
||||||
*/
|
|
||||||
if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
|
|
||||||
WARN_ON(1);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return ioremap_wc(pci_resource_start(pdev, bar),
|
|
||||||
pci_resource_len(pdev, bar));
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(pci_ioremap_wc_bar);
|
EXPORT_SYMBOL_GPL(pci_ioremap_wc_bar);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1891,9 +1891,7 @@ int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma);
|
|||||||
#define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end)
|
#define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end)
|
||||||
#define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags)
|
#define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags)
|
||||||
#define pci_resource_len(dev,bar) \
|
#define pci_resource_len(dev,bar) \
|
||||||
((pci_resource_start((dev), (bar)) == 0 && \
|
((pci_resource_end((dev), (bar)) == 0) ? 0 : \
|
||||||
pci_resource_end((dev), (bar)) == \
|
|
||||||
pci_resource_start((dev), (bar))) ? 0 : \
|
|
||||||
\
|
\
|
||||||
(pci_resource_end((dev), (bar)) - \
|
(pci_resource_end((dev), (bar)) - \
|
||||||
pci_resource_start((dev), (bar)) + 1))
|
pci_resource_start((dev), (bar)) + 1))
|
||||||
|
|||||||
Reference in New Issue
Block a user