Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * ppc64 "iomap" interface implementation. |
| 3 | * |
| 4 | * (C) Copyright 2004 Linus Torvalds |
| 5 | */ |
| 6 | #include <linux/init.h> |
| 7 | #include <linux/pci.h> |
| 8 | #include <linux/mm.h> |
| 9 | #include <asm/io.h> |
| 10 | |
| 11 | /* |
| 12 | * Here comes the ppc64 implementation of the IOMAP |
| 13 | * interfaces. |
| 14 | */ |
| 15 | unsigned int fastcall ioread8(void __iomem *addr) |
| 16 | { |
| 17 | return readb(addr); |
| 18 | } |
| 19 | unsigned int fastcall ioread16(void __iomem *addr) |
| 20 | { |
| 21 | return readw(addr); |
| 22 | } |
Arthur Othieno | 7663753 | 2005-08-20 21:48:47 -0400 | [diff] [blame] | 23 | unsigned int fastcall ioread16be(void __iomem *addr) |
| 24 | { |
| 25 | return in_be16(addr); |
| 26 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | unsigned int fastcall ioread32(void __iomem *addr) |
| 28 | { |
| 29 | return readl(addr); |
| 30 | } |
Arthur Othieno | 7663753 | 2005-08-20 21:48:47 -0400 | [diff] [blame] | 31 | unsigned int fastcall ioread32be(void __iomem *addr) |
| 32 | { |
| 33 | return in_be32(addr); |
| 34 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | EXPORT_SYMBOL(ioread8); |
| 36 | EXPORT_SYMBOL(ioread16); |
Arthur Othieno | 7663753 | 2005-08-20 21:48:47 -0400 | [diff] [blame] | 37 | EXPORT_SYMBOL(ioread16be); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | EXPORT_SYMBOL(ioread32); |
Arthur Othieno | 7663753 | 2005-08-20 21:48:47 -0400 | [diff] [blame] | 39 | EXPORT_SYMBOL(ioread32be); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | void fastcall iowrite8(u8 val, void __iomem *addr) |
| 42 | { |
| 43 | writeb(val, addr); |
| 44 | } |
| 45 | void fastcall iowrite16(u16 val, void __iomem *addr) |
| 46 | { |
| 47 | writew(val, addr); |
| 48 | } |
Arthur Othieno | 7663753 | 2005-08-20 21:48:47 -0400 | [diff] [blame] | 49 | void fastcall iowrite16be(u16 val, void __iomem *addr) |
| 50 | { |
| 51 | out_be16(addr, val); |
| 52 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | void fastcall iowrite32(u32 val, void __iomem *addr) |
| 54 | { |
| 55 | writel(val, addr); |
| 56 | } |
Arthur Othieno | 7663753 | 2005-08-20 21:48:47 -0400 | [diff] [blame] | 57 | void fastcall iowrite32be(u32 val, void __iomem *addr) |
| 58 | { |
| 59 | out_be32(addr, val); |
| 60 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | EXPORT_SYMBOL(iowrite8); |
| 62 | EXPORT_SYMBOL(iowrite16); |
Arthur Othieno | 7663753 | 2005-08-20 21:48:47 -0400 | [diff] [blame] | 63 | EXPORT_SYMBOL(iowrite16be); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | EXPORT_SYMBOL(iowrite32); |
Arthur Othieno | 7663753 | 2005-08-20 21:48:47 -0400 | [diff] [blame] | 65 | EXPORT_SYMBOL(iowrite32be); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * These are the "repeat read/write" functions. Note the |
| 69 | * non-CPU byte order. We do things in "IO byteorder" |
| 70 | * here. |
| 71 | * |
| 72 | * FIXME! We could make these do EEH handling if we really |
| 73 | * wanted. Not clear if we do. |
| 74 | */ |
| 75 | void ioread8_rep(void __iomem *addr, void *dst, unsigned long count) |
| 76 | { |
viro@ZenIV.linux.org.uk | 6c9afc6 | 2005-09-09 16:50:43 +0100 | [diff] [blame] | 77 | _insb((u8 __iomem *) addr, dst, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | void ioread16_rep(void __iomem *addr, void *dst, unsigned long count) |
| 80 | { |
viro@ZenIV.linux.org.uk | 6c9afc6 | 2005-09-09 16:50:43 +0100 | [diff] [blame] | 81 | _insw_ns((u16 __iomem *) addr, dst, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | void ioread32_rep(void __iomem *addr, void *dst, unsigned long count) |
| 84 | { |
viro@ZenIV.linux.org.uk | 6c9afc6 | 2005-09-09 16:50:43 +0100 | [diff] [blame] | 85 | _insl_ns((u32 __iomem *) addr, dst, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | EXPORT_SYMBOL(ioread8_rep); |
| 88 | EXPORT_SYMBOL(ioread16_rep); |
| 89 | EXPORT_SYMBOL(ioread32_rep); |
| 90 | |
| 91 | void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count) |
| 92 | { |
viro@ZenIV.linux.org.uk | 6c9afc6 | 2005-09-09 16:50:43 +0100 | [diff] [blame] | 93 | _outsb((u8 __iomem *) addr, src, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count) |
| 96 | { |
viro@ZenIV.linux.org.uk | 6c9afc6 | 2005-09-09 16:50:43 +0100 | [diff] [blame] | 97 | _outsw_ns((u16 __iomem *) addr, src, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count) |
| 100 | { |
viro@ZenIV.linux.org.uk | 6c9afc6 | 2005-09-09 16:50:43 +0100 | [diff] [blame] | 101 | _outsl_ns((u32 __iomem *) addr, src, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | EXPORT_SYMBOL(iowrite8_rep); |
| 104 | EXPORT_SYMBOL(iowrite16_rep); |
| 105 | EXPORT_SYMBOL(iowrite32_rep); |
| 106 | |
| 107 | void __iomem *ioport_map(unsigned long port, unsigned int len) |
| 108 | { |
| 109 | if (!_IO_IS_VALID(port)) |
| 110 | return NULL; |
| 111 | return (void __iomem *) (port+pci_io_base); |
| 112 | } |
| 113 | |
| 114 | void ioport_unmap(void __iomem *addr) |
| 115 | { |
| 116 | /* Nothing to do */ |
| 117 | } |
| 118 | EXPORT_SYMBOL(ioport_map); |
| 119 | EXPORT_SYMBOL(ioport_unmap); |
| 120 | |
| 121 | void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max) |
| 122 | { |
| 123 | unsigned long start = pci_resource_start(dev, bar); |
| 124 | unsigned long len = pci_resource_len(dev, bar); |
| 125 | unsigned long flags = pci_resource_flags(dev, bar); |
| 126 | |
| 127 | if (!len) |
| 128 | return NULL; |
| 129 | if (max && len > max) |
| 130 | len = max; |
| 131 | if (flags & IORESOURCE_IO) |
| 132 | return ioport_map(start, len); |
| 133 | if (flags & IORESOURCE_MEM) |
| 134 | return ioremap(start, len); |
| 135 | /* What? */ |
| 136 | return NULL; |
| 137 | } |
| 138 | |
| 139 | void pci_iounmap(struct pci_dev *dev, void __iomem *addr) |
| 140 | { |
| 141 | /* Nothing to do */ |
| 142 | } |
| 143 | EXPORT_SYMBOL(pci_iomap); |
| 144 | EXPORT_SYMBOL(pci_iounmap); |