2 * Implement the default iomap interfaces
4 * (C) Copyright 2004 Linus Torvalds
9 #include <linux/export.h>
13 * pci_iomap_range - create a virtual mapping cookie for a PCI BAR
14 * @dev: PCI device that owns the BAR
16 * @offset: map memory at the given offset in BAR
17 * @maxlen: max length of the memory to map
19 * Using this function you will get a __iomem address to your device BAR.
20 * You can access it using ioread*() and iowrite*(). These functions hide
21 * the details if this is a MMIO or PIO address space and will just do what
22 * you expect from them in the correct way.
24 * @maxlen specifies the maximum length to map. If you want to get access to
25 * the complete BAR from offset to the end, pass %0 here.
27 void __iomem *pci_iomap_range(struct pci_dev *dev,
32 resource_size_t start = pci_resource_start(dev, bar);
33 resource_size_t len = pci_resource_len(dev, bar);
34 unsigned long flags = pci_resource_flags(dev, bar);
36 if (len <= offset || !start)
40 if (maxlen && len > maxlen)
42 if (flags & IORESOURCE_IO)
43 return __pci_ioport_map(dev, start, len);
44 if (flags & IORESOURCE_MEM) {
45 if (flags & IORESOURCE_CACHEABLE)
46 return ioremap(start, len);
47 return ioremap_nocache(start, len);
52 EXPORT_SYMBOL(pci_iomap_range);
55 * pci_iomap - create a virtual mapping cookie for a PCI BAR
56 * @dev: PCI device that owns the BAR
58 * @maxlen: length of the memory to map
60 * Using this function you will get a __iomem address to your device BAR.
61 * You can access it using ioread*() and iowrite*(). These functions hide
62 * the details if this is a MMIO or PIO address space and will just do what
63 * you expect from them in the correct way.
65 * @maxlen specifies the maximum length to map. If you want to get access to
66 * the complete BAR without checking for its length first, pass %0 here.
68 void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
70 return pci_iomap_range(dev, bar, 0, maxlen);
72 EXPORT_SYMBOL(pci_iomap);
73 #endif /* CONFIG_PCI */