2 +++ b/arch/powerpc/sysdev/rb_iomap.c
4 +#include <linux/init.h>
5 +#include <linux/pci.h>
9 +#define LOCALBUS_START 0x40000000
10 +#define LOCALBUS_MASK 0x007fffff
11 +#define LOCALBUS_REGMASK 0x001fffff
13 +static void __iomem *localbus_base;
15 +static inline int is_localbus(void __iomem *addr)
17 + return ((unsigned) addr & ~LOCALBUS_MASK) == LOCALBUS_START;
20 +static inline unsigned localbus_regoff(unsigned reg) {
21 + return (reg << 16) | (((reg ^ 8) & 8) << 17);
24 +static inline void __iomem *localbus_addr(void __iomem *addr)
26 + return localbus_base
27 + + ((unsigned) addr & LOCALBUS_MASK & ~LOCALBUS_REGMASK)
28 + + localbus_regoff((unsigned) addr & LOCALBUS_REGMASK);
31 +unsigned int ioread8(void __iomem *addr)
33 + if (is_localbus(addr))
34 + return in_be16(localbus_addr(addr)) >> 8;
37 +EXPORT_SYMBOL(ioread8);
39 +unsigned int ioread16(void __iomem *addr)
41 + if (is_localbus(addr))
42 + return le16_to_cpu(in_be16(localbus_addr(addr)));
45 +EXPORT_SYMBOL(ioread16);
47 +unsigned int ioread16be(void __iomem *addr)
49 + return in_be16(addr);
51 +EXPORT_SYMBOL(ioread16be);
53 +unsigned int ioread32(void __iomem *addr)
57 +EXPORT_SYMBOL(ioread32);
59 +unsigned int ioread32be(void __iomem *addr)
61 + return in_be32(addr);
63 +EXPORT_SYMBOL(ioread32be);
65 +void iowrite8(u8 val, void __iomem *addr)
67 + if (is_localbus(addr))
68 + out_be16(localbus_addr(addr), ((u16) val) << 8);
72 +EXPORT_SYMBOL(iowrite8);
74 +void iowrite16(u16 val, void __iomem *addr)
76 + if (is_localbus(addr))
77 + out_be16(localbus_addr(addr), cpu_to_le16(val));
81 +EXPORT_SYMBOL(iowrite16);
83 +void iowrite16be(u16 val, void __iomem *addr)
85 + out_be16(addr, val);
87 +EXPORT_SYMBOL(iowrite16be);
89 +void iowrite32(u32 val, void __iomem *addr)
93 +EXPORT_SYMBOL(iowrite32);
95 +void iowrite32be(u32 val, void __iomem *addr)
97 + out_be32(addr, val);
99 +EXPORT_SYMBOL(iowrite32be);
101 +void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
103 + if (is_localbus(addr)) {
105 + void *laddr = localbus_addr(addr);
108 + for (i = 0; i < count; ++i) {
109 + *buf++ = in_be16(laddr) >> 8;
112 + _insb((u8 __iomem *) addr, dst, count);
115 +EXPORT_SYMBOL(ioread8_rep);
117 +void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
119 + if (is_localbus(addr)) {
121 + void *laddr = localbus_addr(addr);
124 + for (i = 0; i < count; ++i) {
125 + *buf++ = in_be16(laddr);
128 + _insw_ns((u16 __iomem *) addr, dst, count);
131 +EXPORT_SYMBOL(ioread16_rep);
133 +void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
135 + _insl_ns((u32 __iomem *) addr, dst, count);
137 +EXPORT_SYMBOL(ioread32_rep);
139 +void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
141 + if (is_localbus(addr)) {
143 + void *laddr = localbus_addr(addr);
144 + const u8 *buf = src;
146 + for (i = 0; i < count; ++i) {
147 + out_be16(laddr, ((u16) *buf++) << 8);
150 + _outsb((u8 __iomem *) addr, src, count);
153 +EXPORT_SYMBOL(iowrite8_rep);
155 +void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
157 + if (is_localbus(addr)) {
159 + void *laddr = localbus_addr(addr);
160 + const u16 *buf = src;
162 + for (i = 0; i < count; ++i) {
163 + out_be16(laddr, *buf++);
166 + _outsw_ns((u16 __iomem *) addr, src, count);
169 +EXPORT_SYMBOL(iowrite16_rep);
171 +void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
173 + _outsl_ns((u32 __iomem *) addr, src, count);
175 +EXPORT_SYMBOL(iowrite32_rep);
177 +void __iomem *ioport_map(unsigned long port, unsigned int len)
179 + return (void __iomem *) (port + _IO_BASE);
181 +EXPORT_SYMBOL(ioport_unmap);
183 +void ioport_unmap(void __iomem *addr)
185 + /* Nothing to do */
187 +EXPORT_SYMBOL(ioport_map);
189 +void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
191 + unsigned long start = pci_resource_start(dev, bar);
192 + unsigned long len = pci_resource_len(dev, bar);
193 + unsigned long flags = pci_resource_flags(dev, bar);
197 + if (max && len > max)
199 + if (flags & IORESOURCE_IO)
200 + return ioport_map(start, len);
201 + if (flags & IORESOURCE_MEM)
202 + return ioremap(start, len);
206 +EXPORT_SYMBOL(pci_iomap);
208 +void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
210 + /* Nothing to do */
212 +EXPORT_SYMBOL(pci_iounmap);
214 +void __iomem *localbus_map(unsigned long addr, unsigned int len)
216 + if (!localbus_base)
217 + localbus_base = ioremap(addr & ~LOCALBUS_MASK,
218 + LOCALBUS_MASK + 1);
219 + return (void *) (LOCALBUS_START + (addr & LOCALBUS_MASK));
221 +EXPORT_SYMBOL(localbus_map);
223 +void localbus_unmap(void __iomem *addr)
226 +EXPORT_SYMBOL(localbus_unmap);