00001
00002
00003
00004
00005
00006 #include <linux/pci.h>
00007 #include <linux/io.h>
00008
00009 #include <linux/module.h>
00010
00011 #ifdef DDE_LINUX
00012 #include "local.h"
00013 #endif
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef HAVE_ARCH_PIO_SIZE
00030
00031
00032
00033
00034
00035
00036
00037 #define PIO_OFFSET 0x10000UL
00038 #define PIO_MASK 0x0ffffUL
00039 #define PIO_RESERVED 0x40000UL
00040 #endif
00041
00042 static void bad_io_access(unsigned long port, const char *access)
00043 {
00044 static int count = 10;
00045 if (count) {
00046 count--;
00047 WARN(1, KERN_ERR "Bad IO access at port %#lx (%s)\n", port, access);
00048 }
00049 }
00050
00051
00052
00053
00054 #ifdef DDE_LINUX
00055
00056
00057
00058 #define IO_COND(addr, is_pio, is_mmio) do { \
00059 unsigned long port = (unsigned long __force)addr; \
00060 if (port > PIO_OFFSET && port < PIO_RESERVED) { \
00061 port &= PIO_MASK; \
00062 is_pio; \
00063 } else { \
00064 is_mmio; \
00065 } \
00066 } while (0)
00067 #else
00068 #define IO_COND(addr, is_pio, is_mmio) do { \
00069 unsigned long port = (unsigned long __force)addr; \
00070 if (port >= PIO_RESERVED) { \
00071 is_mmio; \
00072 } else if (port > PIO_OFFSET) { \
00073 port &= PIO_MASK; \
00074 is_pio; \
00075 } else \
00076 bad_io_access(port, #is_pio ); \
00077 } while (0)
00078 #endif
00079
00080 #ifndef pio_read16be
00081 #define pio_read16be(port) swab16(inw(port))
00082 #define pio_read32be(port) swab32(inl(port))
00083 #endif
00084
00085 #ifndef mmio_read16be
00086 #define mmio_read16be(addr) be16_to_cpu(__raw_readw(addr))
00087 #define mmio_read32be(addr) be32_to_cpu(__raw_readl(addr))
00088 #endif
00089
00090 unsigned int ioread8(void __iomem *addr)
00091 {
00092 IO_COND(addr, return inb(port), return readb(addr));
00093 return 0xff;
00094 }
00095 unsigned int ioread16(void __iomem *addr)
00096 {
00097 IO_COND(addr, return inw(port), return readw(addr));
00098 return 0xffff;
00099 }
00100 unsigned int ioread16be(void __iomem *addr)
00101 {
00102 IO_COND(addr, return pio_read16be(port), return mmio_read16be(addr));
00103 return 0xffff;
00104 }
00105 unsigned int ioread32(void __iomem *addr)
00106 {
00107 IO_COND(addr, return inl(port), return readl(addr));
00108 return 0xffffffff;
00109 }
00110 unsigned int ioread32be(void __iomem *addr)
00111 {
00112 IO_COND(addr, return pio_read32be(port), return mmio_read32be(addr));
00113 return 0xffffffff;
00114 }
00115 EXPORT_SYMBOL(ioread8);
00116 EXPORT_SYMBOL(ioread16);
00117 EXPORT_SYMBOL(ioread16be);
00118 EXPORT_SYMBOL(ioread32);
00119 EXPORT_SYMBOL(ioread32be);
00120
00121 #ifndef pio_write16be
00122 #define pio_write16be(val,port) outw(swab16(val),port)
00123 #define pio_write32be(val,port) outl(swab32(val),port)
00124 #endif
00125
00126 #ifndef mmio_write16be
00127 #define mmio_write16be(val,port) __raw_writew(be16_to_cpu(val),port)
00128 #define mmio_write32be(val,port) __raw_writel(be32_to_cpu(val),port)
00129 #endif
00130
00131 void iowrite8(u8 val, void __iomem *addr)
00132 {
00133 IO_COND(addr, outb(val,port), writeb(val, addr));
00134 }
00135 void iowrite16(u16 val, void __iomem *addr)
00136 {
00137 IO_COND(addr, outw(val,port), writew(val, addr));
00138 }
00139 void iowrite16be(u16 val, void __iomem *addr)
00140 {
00141 IO_COND(addr, pio_write16be(val,port), mmio_write16be(val, addr));
00142 }
00143 void iowrite32(u32 val, void __iomem *addr)
00144 {
00145 IO_COND(addr, outl(val,port), writel(val, addr));
00146 }
00147 void iowrite32be(u32 val, void __iomem *addr)
00148 {
00149 IO_COND(addr, pio_write32be(val,port), mmio_write32be(val, addr));
00150 }
00151 EXPORT_SYMBOL(iowrite8);
00152 EXPORT_SYMBOL(iowrite16);
00153 EXPORT_SYMBOL(iowrite16be);
00154 EXPORT_SYMBOL(iowrite32);
00155 EXPORT_SYMBOL(iowrite32be);
00156
00157
00158
00159
00160
00161
00162
00163 #ifndef mmio_insb
00164 static inline void mmio_insb(void __iomem *addr, u8 *dst, int count)
00165 {
00166 while (--count >= 0) {
00167 u8 data = __raw_readb(addr);
00168 *dst = data;
00169 dst++;
00170 }
00171 }
00172 static inline void mmio_insw(void __iomem *addr, u16 *dst, int count)
00173 {
00174 while (--count >= 0) {
00175 u16 data = __raw_readw(addr);
00176 *dst = data;
00177 dst++;
00178 }
00179 }
00180 static inline void mmio_insl(void __iomem *addr, u32 *dst, int count)
00181 {
00182 while (--count >= 0) {
00183 u32 data = __raw_readl(addr);
00184 *dst = data;
00185 dst++;
00186 }
00187 }
00188 #endif
00189
00190 #ifndef mmio_outsb
00191 static inline void mmio_outsb(void __iomem *addr, const u8 *src, int count)
00192 {
00193 while (--count >= 0) {
00194 __raw_writeb(*src, addr);
00195 src++;
00196 }
00197 }
00198 static inline void mmio_outsw(void __iomem *addr, const u16 *src, int count)
00199 {
00200 while (--count >= 0) {
00201 __raw_writew(*src, addr);
00202 src++;
00203 }
00204 }
00205 static inline void mmio_outsl(void __iomem *addr, const u32 *src, int count)
00206 {
00207 while (--count >= 0) {
00208 __raw_writel(*src, addr);
00209 src++;
00210 }
00211 }
00212 #endif
00213
00214 void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
00215 {
00216 IO_COND(addr, insb(port,dst,count), mmio_insb(addr, dst, count));
00217 }
00218 void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
00219 {
00220 IO_COND(addr, insw(port,dst,count), mmio_insw(addr, dst, count));
00221 }
00222 void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
00223 {
00224 IO_COND(addr, insl(port,dst,count), mmio_insl(addr, dst, count));
00225 }
00226 EXPORT_SYMBOL(ioread8_rep);
00227 EXPORT_SYMBOL(ioread16_rep);
00228 EXPORT_SYMBOL(ioread32_rep);
00229
00230 void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
00231 {
00232 IO_COND(addr, outsb(port, src, count), mmio_outsb(addr, src, count));
00233 }
00234 void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
00235 {
00236 IO_COND(addr, outsw(port, src, count), mmio_outsw(addr, src, count));
00237 }
00238 void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
00239 {
00240 IO_COND(addr, outsl(port, src,count), mmio_outsl(addr, src, count));
00241 }
00242 EXPORT_SYMBOL(iowrite8_rep);
00243 EXPORT_SYMBOL(iowrite16_rep);
00244 EXPORT_SYMBOL(iowrite32_rep);
00245
00246
00247 void __iomem *ioport_map(unsigned long port, unsigned int nr)
00248 {
00249 if (port > PIO_MASK)
00250 return NULL;
00251 return (void __iomem *) (unsigned long) (port + PIO_OFFSET);
00252 }
00253
00254 void ioport_unmap(void __iomem *addr)
00255 {
00256
00257 }
00258 EXPORT_SYMBOL(ioport_map);
00259 EXPORT_SYMBOL(ioport_unmap);
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
00276 {
00277 resource_size_t start = pci_resource_start(dev, bar);
00278 resource_size_t len = pci_resource_len(dev, bar);
00279 unsigned long flags = pci_resource_flags(dev, bar);
00280
00281 if (!len || !start)
00282 return NULL;
00283 if (maxlen && len > maxlen)
00284 len = maxlen;
00285 if (flags & IORESOURCE_IO)
00286 return ioport_map(start, len);
00287 if (flags & IORESOURCE_MEM) {
00288 if (flags & IORESOURCE_CACHEABLE)
00289 return ioremap(start, len);
00290 return ioremap_nocache(start, len);
00291 }
00292
00293 return NULL;
00294 }
00295
00296 void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
00297 {
00298 IO_COND(addr, , iounmap(addr));
00299 }
00300 EXPORT_SYMBOL(pci_iomap);
00301 EXPORT_SYMBOL(pci_iounmap);