2 * iomap.c - Implement iomap interface for PA-RISC
3 * Copyright (c) 2004 Matthew Wilcox
6 #include <linux/ioport.h>
11 * The iomap space on 32-bit PA-RISC is intended to look like this:
12 * 00000000-7fffffff virtual mapped IO
13 * 80000000-8fffffff ISA/EISA port space that can't be virtually mapped
14 * 90000000-9fffffff Dino port space
15 * a0000000-afffffff Astro port space
16 * b0000000-bfffffff PAT port space
17 * c0000000-cfffffff non-swapped memory IO
18 * f0000000-ffffffff legacy IO memory pointers
20 * For the moment, here's what it looks like:
21 * 80000000-8fffffff All ISA/EISA port space
22 * f0000000-ffffffff legacy IO memory pointers
24 * On 64-bit, everything is extended, so:
25 * 8000000000000000-8fffffffffffffff All ISA/EISA port space
26 * f000000000000000-ffffffffffffffff legacy IO memory pointers
30 * Technically, this should be 'if (VMALLOC_START < addr < VMALLOC_END),
31 * but that's slow and we know it'll be within the first 2GB.
34 #define INDIRECT_ADDR(addr) (((unsigned long)(addr) & 1UL<<63) != 0)
35 #define ADDR_TO_REGION(addr) (((unsigned long)addr >> 60) & 7)
36 #define IOPORT_MAP_BASE (8UL << 60)
38 #define INDIRECT_ADDR(addr) (((unsigned long)(addr) & 1UL<<31) != 0)
39 #define ADDR_TO_REGION(addr) (((unsigned long)addr >> 28) & 7)
40 #define IOPORT_MAP_BASE (8UL << 28)
44 unsigned int (*read8
)(void __iomem
*);
45 unsigned int (*read16
)(void __iomem
*);
46 unsigned int (*read32
)(void __iomem
*);
47 void (*write8
)(u8
, void __iomem
*);
48 void (*write16
)(u16
, void __iomem
*);
49 void (*write32
)(u32
, void __iomem
*);
50 void (*read8r
)(void __iomem
*, void *, unsigned long);
51 void (*read16r
)(void __iomem
*, void *, unsigned long);
52 void (*read32r
)(void __iomem
*, void *, unsigned long);
53 void (*write8r
)(void __iomem
*, const void *, unsigned long);
54 void (*write16r
)(void __iomem
*, const void *, unsigned long);
55 void (*write32r
)(void __iomem
*, const void *, unsigned long);
58 /* Generic ioport ops. To be replaced later by specific dino/elroy/wax code */
60 #define ADDR2PORT(addr) ((unsigned long __force)(addr) & 0xffffff)
62 static unsigned int ioport_read8(void __iomem
*addr
)
64 return inb(ADDR2PORT(addr
));
67 static unsigned int ioport_read16(void __iomem
*addr
)
69 return inw(ADDR2PORT(addr
));
72 static unsigned int ioport_read32(void __iomem
*addr
)
74 return inl(ADDR2PORT(addr
));
77 static void ioport_write8(u8 datum
, void __iomem
*addr
)
79 outb(datum
, ADDR2PORT(addr
));
82 static void ioport_write16(u16 datum
, void __iomem
*addr
)
84 outw(datum
, ADDR2PORT(addr
));
87 static void ioport_write32(u32 datum
, void __iomem
*addr
)
89 outl(datum
, ADDR2PORT(addr
));
92 static void ioport_read8r(void __iomem
*addr
, void *dst
, unsigned long count
)
94 insb(ADDR2PORT(addr
), dst
, count
);
97 static void ioport_read16r(void __iomem
*addr
, void *dst
, unsigned long count
)
99 insw(ADDR2PORT(addr
), dst
, count
);
102 static void ioport_read32r(void __iomem
*addr
, void *dst
, unsigned long count
)
104 insl(ADDR2PORT(addr
), dst
, count
);
107 static void ioport_write8r(void __iomem
*addr
, const void *s
, unsigned long n
)
109 outsb(ADDR2PORT(addr
), s
, n
);
112 static void ioport_write16r(void __iomem
*addr
, const void *s
, unsigned long n
)
114 outsw(ADDR2PORT(addr
), s
, n
);
117 static void ioport_write32r(void __iomem
*addr
, const void *s
, unsigned long n
)
119 outsl(ADDR2PORT(addr
), s
, n
);
122 static const struct iomap_ops ioport_ops
= {
137 /* Legacy I/O memory ops */
139 static unsigned int iomem_read8(void __iomem
*addr
)
144 static unsigned int iomem_read16(void __iomem
*addr
)
149 static unsigned int iomem_read32(void __iomem
*addr
)
154 static void iomem_write8(u8 datum
, void __iomem
*addr
)
159 static void iomem_write16(u16 datum
, void __iomem
*addr
)
164 static void iomem_write32(u32 datum
, void __iomem
*addr
)
169 static void iomem_read8r(void __iomem
*addr
, void *dst
, unsigned long count
)
172 *(u8
*)dst
= __raw_readb(addr
);
177 static void iomem_read16r(void __iomem
*addr
, void *dst
, unsigned long count
)
180 *(u16
*)dst
= __raw_readw(addr
);
185 static void iomem_read32r(void __iomem
*addr
, void *dst
, unsigned long count
)
188 *(u32
*)dst
= __raw_readl(addr
);
193 static void iomem_write8r(void __iomem
*addr
, const void *s
, unsigned long n
)
196 __raw_writeb(*(u8
*)s
, addr
);
201 static void iomem_write16r(void __iomem
*addr
, const void *s
, unsigned long n
)
204 __raw_writew(*(u16
*)s
, addr
);
209 static void iomem_write32r(void __iomem
*addr
, const void *s
, unsigned long n
)
212 __raw_writel(*(u32
*)s
, addr
);
217 static const struct iomap_ops iomem_ops
= {
232 const struct iomap_ops
*iomap_ops
[8] = {
234 #ifdef CONFIG_DEBUG_IOREMAP
242 unsigned int ioread8(void __iomem
*addr
)
244 if (unlikely(INDIRECT_ADDR(addr
)))
245 return iomap_ops
[ADDR_TO_REGION(addr
)]->read8(addr
);
246 return *((u8
*)addr
);
249 unsigned int ioread16(void __iomem
*addr
)
251 if (unlikely(INDIRECT_ADDR(addr
)))
252 return iomap_ops
[ADDR_TO_REGION(addr
)]->read16(addr
);
253 return le16_to_cpup((u16
*)addr
);
256 unsigned int ioread32(void __iomem
*addr
)
258 if (unlikely(INDIRECT_ADDR(addr
)))
259 return iomap_ops
[ADDR_TO_REGION(addr
)]->read32(addr
);
260 return le32_to_cpup((u32
*)addr
);
263 void iowrite8(u8 datum
, void __iomem
*addr
)
265 if (unlikely(INDIRECT_ADDR(addr
))) {
266 iomap_ops
[ADDR_TO_REGION(addr
)]->write8(datum
, addr
);
268 *((u8
*)addr
) = datum
;
272 void iowrite16(u16 datum
, void __iomem
*addr
)
274 if (unlikely(INDIRECT_ADDR(addr
))) {
275 iomap_ops
[ADDR_TO_REGION(addr
)]->write16(datum
, addr
);
277 *((u16
*)addr
) = cpu_to_le16(datum
);
281 void iowrite32(u32 datum
, void __iomem
*addr
)
283 if (unlikely(INDIRECT_ADDR(addr
))) {
284 iomap_ops
[ADDR_TO_REGION(addr
)]->write32(datum
, addr
);
286 *((u32
*)addr
) = cpu_to_le32(datum
);
290 /* Repeating interfaces */
292 void ioread8_rep(void __iomem
*addr
, void *dst
, unsigned long count
)
294 if (unlikely(INDIRECT_ADDR(addr
))) {
295 iomap_ops
[ADDR_TO_REGION(addr
)]->read8r(addr
, dst
, count
);
298 *(u8
*)dst
= *(u8
*)addr
;
304 void ioread16_rep(void __iomem
*addr
, void *dst
, unsigned long count
)
306 if (unlikely(INDIRECT_ADDR(addr
))) {
307 iomap_ops
[ADDR_TO_REGION(addr
)]->read16r(addr
, dst
, count
);
310 *(u16
*)dst
= *(u16
*)addr
;
316 void ioread32_rep(void __iomem
*addr
, void *dst
, unsigned long count
)
318 if (unlikely(INDIRECT_ADDR(addr
))) {
319 iomap_ops
[ADDR_TO_REGION(addr
)]->read32r(addr
, dst
, count
);
322 *(u32
*)dst
= *(u32
*)addr
;
328 void iowrite8_rep(void __iomem
*addr
, const void *src
, unsigned long count
)
330 if (unlikely(INDIRECT_ADDR(addr
))) {
331 iomap_ops
[ADDR_TO_REGION(addr
)]->write8r(addr
, src
, count
);
334 *(u8
*)addr
= *(u8
*)src
;
340 void iowrite16_rep(void __iomem
*addr
, const void *src
, unsigned long count
)
342 if (unlikely(INDIRECT_ADDR(addr
))) {
343 iomap_ops
[ADDR_TO_REGION(addr
)]->write16r(addr
, src
, count
);
346 *(u16
*)addr
= *(u16
*)src
;
352 void iowrite32_rep(void __iomem
*addr
, const void *src
, unsigned long count
)
354 if (unlikely(INDIRECT_ADDR(addr
))) {
355 iomap_ops
[ADDR_TO_REGION(addr
)]->write32r(addr
, src
, count
);
358 *(u32
*)addr
= *(u32
*)src
;
364 /* Mapping interfaces */
366 void __iomem
*ioport_map(unsigned long port
, unsigned int nr
)
368 return (void __iomem
*)(IOPORT_MAP_BASE
| port
);
371 void ioport_unmap(void __iomem
*addr
)
373 if (!INDIRECT_ADDR(addr
)) {
378 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
379 void __iomem
*pci_iomap(struct pci_dev
*dev
, int bar
, unsigned long maxlen
)
381 unsigned long start
= pci_resource_start(dev
, bar
);
382 unsigned long len
= pci_resource_len(dev
, bar
);
383 unsigned long flags
= pci_resource_flags(dev
, bar
);
387 if (maxlen
&& len
> maxlen
)
389 if (flags
& IORESOURCE_IO
)
390 return ioport_map(start
, len
);
391 if (flags
& IORESOURCE_MEM
) {
392 if (flags
& IORESOURCE_CACHEABLE
)
393 return ioremap(start
, len
);
394 return ioremap_nocache(start
, len
);
400 void pci_iounmap(struct pci_dev
*dev
, void __iomem
* addr
)
402 if (!INDIRECT_ADDR(addr
)) {
407 EXPORT_SYMBOL(ioread8
);
408 EXPORT_SYMBOL(ioread16
);
409 EXPORT_SYMBOL(ioread32
);
410 EXPORT_SYMBOL(iowrite8
);
411 EXPORT_SYMBOL(iowrite16
);
412 EXPORT_SYMBOL(iowrite32
);
413 EXPORT_SYMBOL(ioread8_rep
);
414 EXPORT_SYMBOL(ioread16_rep
);
415 EXPORT_SYMBOL(ioread32_rep
);
416 EXPORT_SYMBOL(iowrite8_rep
);
417 EXPORT_SYMBOL(iowrite16_rep
);
418 EXPORT_SYMBOL(iowrite32_rep
);
419 EXPORT_SYMBOL(ioport_map
);
420 EXPORT_SYMBOL(ioport_unmap
);
421 EXPORT_SYMBOL(pci_iomap
);
422 EXPORT_SYMBOL(pci_iounmap
);