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