Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus
[deliverable/linux.git] / lib / pci_iomap.c
CommitLineData
66eab4df
MT
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/**
eb29d8d2 13 * pci_iomap_range - create a virtual mapping cookie for a PCI BAR
66eab4df
MT
14 * @dev: PCI device that owns the BAR
15 * @bar: BAR number
eb29d8d2
MT
16 * @offset: map memory at the given offset in BAR
17 * @maxlen: max length of the memory to map
66eab4df
MT
18 *
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.
23 *
24 * @maxlen specifies the maximum length to map. If you want to get access to
eb29d8d2 25 * the complete BAR from offset to the end, pass %0 here.
66eab4df 26 * */
eb29d8d2
MT
27void __iomem *pci_iomap_range(struct pci_dev *dev,
28 int bar,
29 unsigned long offset,
30 unsigned long maxlen)
66eab4df
MT
31{
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);
35
eb29d8d2 36 if (len <= offset || !start)
66eab4df 37 return NULL;
eb29d8d2
MT
38 len -= offset;
39 start += offset;
66eab4df
MT
40 if (maxlen && len > maxlen)
41 len = maxlen;
42 if (flags & IORESOURCE_IO)
b923650b 43 return __pci_ioport_map(dev, start, len);
92b19ff5
DW
44 if (flags & IORESOURCE_MEM)
45 return ioremap(start, len);
66eab4df
MT
46 /* What? */
47 return NULL;
48}
eb29d8d2 49EXPORT_SYMBOL(pci_iomap_range);
66eab4df 50
1b3d4200
LR
51/**
52 * pci_iomap_wc_range - create a virtual WC mapping cookie for a PCI BAR
53 * @dev: PCI device that owns the BAR
54 * @bar: BAR number
55 * @offset: map memory at the given offset in BAR
56 * @maxlen: max length of the memory to map
57 *
58 * Using this function you will get a __iomem address to your device BAR.
59 * You can access it using ioread*() and iowrite*(). These functions hide
60 * the details if this is a MMIO or PIO address space and will just do what
61 * you expect from them in the correct way. When possible write combining
62 * is used.
63 *
64 * @maxlen specifies the maximum length to map. If you want to get access to
65 * the complete BAR from offset to the end, pass %0 here.
66 * */
67void __iomem *pci_iomap_wc_range(struct pci_dev *dev,
68 int bar,
69 unsigned long offset,
70 unsigned long maxlen)
71{
72 resource_size_t start = pci_resource_start(dev, bar);
73 resource_size_t len = pci_resource_len(dev, bar);
74 unsigned long flags = pci_resource_flags(dev, bar);
75
76
77 if (flags & IORESOURCE_IO)
78 return NULL;
79
80 if (len <= offset || !start)
81 return NULL;
82
83 len -= offset;
84 start += offset;
85 if (maxlen && len > maxlen)
86 len = maxlen;
87
88 if (flags & IORESOURCE_MEM)
89 return ioremap_wc(start, len);
90
91 /* What? */
92 return NULL;
93}
94EXPORT_SYMBOL_GPL(pci_iomap_wc_range);
95
eb29d8d2
MT
96/**
97 * pci_iomap - create a virtual mapping cookie for a PCI BAR
98 * @dev: PCI device that owns the BAR
99 * @bar: BAR number
100 * @maxlen: length of the memory to map
101 *
102 * Using this function you will get a __iomem address to your device BAR.
103 * You can access it using ioread*() and iowrite*(). These functions hide
104 * the details if this is a MMIO or PIO address space and will just do what
105 * you expect from them in the correct way.
106 *
107 * @maxlen specifies the maximum length to map. If you want to get access to
108 * the complete BAR without checking for its length first, pass %0 here.
109 * */
110void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
111{
112 return pci_iomap_range(dev, bar, 0, maxlen);
113}
66eab4df 114EXPORT_SYMBOL(pci_iomap);
1b3d4200
LR
115
116/**
117 * pci_iomap_wc - create a virtual WC mapping cookie for a PCI BAR
118 * @dev: PCI device that owns the BAR
119 * @bar: BAR number
120 * @maxlen: length of the memory to map
121 *
122 * Using this function you will get a __iomem address to your device BAR.
123 * You can access it using ioread*() and iowrite*(). These functions hide
124 * the details if this is a MMIO or PIO address space and will just do what
125 * you expect from them in the correct way. When possible write combining
126 * is used.
127 *
128 * @maxlen specifies the maximum length to map. If you want to get access to
129 * the complete BAR without checking for its length first, pass %0 here.
130 * */
131void __iomem *pci_iomap_wc(struct pci_dev *dev, int bar, unsigned long maxlen)
132{
133 return pci_iomap_wc_range(dev, bar, 0, maxlen);
134}
135EXPORT_SYMBOL_GPL(pci_iomap_wc);
66eab4df 136#endif /* CONFIG_PCI */
This page took 0.198665 seconds and 5 git commands to generate.