aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pci_iomap.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2011-11-24 13:45:20 -0500
committerMichael S. Tsirkin <mst@redhat.com>2011-11-28 14:12:42 -0500
commit66eab4df288aaee75938ae99877c4f759fc6d56c (patch)
tree0b663bfe2d464a55c2a85b27140a53b32f261542 /lib/pci_iomap.c
parent4673ca8eb3690832e76371371955a8b02e1f59d4 (diff)
lib: add GENERIC_PCI_IOMAP
Many architectures want a generic pci_iomap but not the rest of iomap.c. Split that to a separate .c file and add a new config symbol. select automatically by GENERIC_IOMAP. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'lib/pci_iomap.c')
-rw-r--r--lib/pci_iomap.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/pci_iomap.c b/lib/pci_iomap.c
new file mode 100644
index 000000000000..4b0fdc22e688
--- /dev/null
+++ b/lib/pci_iomap.c
@@ -0,0 +1,48 @@
1/*
2 * Implement the default iomap interfaces
3 *
4 * (C) Copyright 2004 Linus Torvalds
5 */
6#include <linux/pci.h>
7#include <linux/io.h>
8
9#include <linux/export.h>
10
11#ifdef CONFIG_PCI
12/**
13 * pci_iomap - create a virtual mapping cookie for a PCI BAR
14 * @dev: PCI device that owns the BAR
15 * @bar: BAR number
16 * @maxlen: length of the memory to map
17 *
18 * Using this function you will get a __iomem address to your device BAR.
19 * You can access it using ioread*() and iowrite*(). These functions hide
20 * the details if this is a MMIO or PIO address space and will just do what
21 * you expect from them in the correct way.
22 *
23 * @maxlen specifies the maximum length to map. If you want to get access to
24 * the complete BAR without checking for its length first, pass %0 here.
25 * */
26void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
27{
28 resource_size_t start = pci_resource_start(dev, bar);
29 resource_size_t len = pci_resource_len(dev, bar);
30 unsigned long flags = pci_resource_flags(dev, bar);
31
32 if (!len || !start)
33 return NULL;
34 if (maxlen && len > maxlen)
35 len = maxlen;
36 if (flags & IORESOURCE_IO)
37 return ioport_map(start, len);
38 if (flags & IORESOURCE_MEM) {
39 if (flags & IORESOURCE_CACHEABLE)
40 return ioremap(start, len);
41 return ioremap_nocache(start, len);
42 }
43 /* What? */
44 return NULL;
45}
46
47EXPORT_SYMBOL(pci_iomap);
48#endif /* CONFIG_PCI */