1 /* 2 * linux/include/asm-m68k/io.h 3 * 4 * 4/1/00 RZ: - rewritten to avoid clashes between ISA/PCI and other 5 * IO access 6 * - added Q40 support 7 * - added skeleton for GG-II and Amiga PCMCIA 8 * 2/3/01 RZ: - moved a few more defs into raw_io.h 9 * 10 * inX/outX should not be used by any driver unless it does 11 * ISA access. Other drivers should use function defined in raw_io.h 12 * or define its own macros on top of these. 13 * 14 * inX(),outX() are for ISA I/O 15 * isa_readX(),isa_writeX() are for ISA memory 16 */ 17 18 #ifndef _IO_H 19 #define _IO_H 20 21 #ifdef __KERNEL__ 22 23 #include <linux/compiler.h> 24 #include <asm/raw_io.h> 25 #include <asm/virtconvert.h> 26 27 #include <asm-generic/iomap.h> 28 29 #ifdef CONFIG_ATARI 30 #include <asm/atarihw.h> 31 #endif 32 33 34 /* 35 * IO/MEM definitions for various ISA bridges 36 */ 37 38 39 #ifdef CONFIG_Q40 40 41 #define q40_isa_io_base 0xff400000 42 #define q40_isa_mem_base 0xff800000 43 44 #define Q40_ISA_IO_B(ioaddr) (q40_isa_io_base+1+4*((unsigned long)(ioaddr))) 45 #define Q40_ISA_IO_W(ioaddr) (q40_isa_io_base+ 4*((unsigned long)(ioaddr))) 46 #define Q40_ISA_MEM_B(madr) (q40_isa_mem_base+1+4*((unsigned long)(madr))) 47 #define Q40_ISA_MEM_W(madr) (q40_isa_mem_base+ 4*((unsigned long)(madr))) 48 49 #define MULTI_ISA 0 50 #endif /* Q40 */ 51 52 #ifdef CONFIG_AMIGA_PCMCIA 53 #include <asm/amigayle.h> 54 55 #define AG_ISA_IO_B(ioaddr) ( GAYLE_IO+(ioaddr)+(((ioaddr)&1)*GAYLE_ODD) ) 56 #define AG_ISA_IO_W(ioaddr) ( GAYLE_IO+(ioaddr) ) 57 58 #ifndef MULTI_ISA 59 #define MULTI_ISA 0 60 #else 61 #undef MULTI_ISA 62 #define MULTI_ISA 1 63 #endif 64 #endif /* AMIGA_PCMCIA */ 65 66 #ifdef CONFIG_ATARI_ROM_ISA 67 68 #define enec_isa_read_base 0xfffa0000 69 #define enec_isa_write_base 0xfffb0000 70 71 #define ENEC_ISA_IO_B(ioaddr) (enec_isa_read_base+((((unsigned long)(ioaddr))&0x7F)<<9)) 72 #define ENEC_ISA_IO_W(ioaddr) (enec_isa_read_base+((((unsigned long)(ioaddr))&0x7F)<<9)) 73 #define ENEC_ISA_MEM_B(madr) (enec_isa_read_base+((((unsigned long)(madr))&0x7F)<<9)) 74 #define ENEC_ISA_MEM_W(madr) (enec_isa_read_base+((((unsigned long)(madr))&0x7F)<<9)) 75 76 #ifndef MULTI_ISA 77 #define MULTI_ISA 0 78 #else 79 #undef MULTI_ISA 80 #define MULTI_ISA 1 81 #endif 82 #endif /* ATARI_ROM_ISA */ 83 84 85 #if defined(CONFIG_PCI) && defined(CONFIG_COLDFIRE) 86 87 #define HAVE_ARCH_PIO_SIZE 88 #define PIO_OFFSET 0 89 #define PIO_MASK 0xffff 90 #define PIO_RESERVED 0x10000 91 92 u8 mcf_pci_inb(u32 addr); 93 u16 mcf_pci_inw(u32 addr); 94 u32 mcf_pci_inl(u32 addr); 95 void mcf_pci_insb(u32 addr, u8 *buf, u32 len); 96 void mcf_pci_insw(u32 addr, u16 *buf, u32 len); 97 void mcf_pci_insl(u32 addr, u32 *buf, u32 len); 98 99 void mcf_pci_outb(u8 v, u32 addr); 100 void mcf_pci_outw(u16 v, u32 addr); 101 void mcf_pci_outl(u32 v, u32 addr); 102 void mcf_pci_outsb(u32 addr, const u8 *buf, u32 len); 103 void mcf_pci_outsw(u32 addr, const u16 *buf, u32 len); 104 void mcf_pci_outsl(u32 addr, const u32 *buf, u32 len); 105 106 #define inb mcf_pci_inb 107 #define inb_p mcf_pci_inb 108 #define inw mcf_pci_inw 109 #define inw_p mcf_pci_inw 110 #define inl mcf_pci_inl 111 #define inl_p mcf_pci_inl 112 #define insb mcf_pci_insb 113 #define insw mcf_pci_insw 114 #define insl mcf_pci_insl 115 116 #define outb mcf_pci_outb 117 #define outb_p mcf_pci_outb 118 #define outw mcf_pci_outw 119 #define outw_p mcf_pci_outw 120 #define outl mcf_pci_outl 121 #define outl_p mcf_pci_outl 122 #define outsb mcf_pci_outsb 123 #define outsw mcf_pci_outsw 124 #define outsl mcf_pci_outsl 125 126 #define readb(addr) in_8(addr) 127 #define writeb(v, addr) out_8((addr), (v)) 128 #define readw(addr) in_le16(addr) 129 #define writew(v, addr) out_le16((addr), (v)) 130 131 #elif defined(CONFIG_ISA) || defined(CONFIG_ATARI_ROM_ISA) 132 133 #if MULTI_ISA == 0 134 #undef MULTI_ISA 135 #endif 136 137 #define ISA_TYPE_Q40 (1) 138 #define ISA_TYPE_AG (2) 139 #define ISA_TYPE_ENEC (3) 140 141 #if defined(CONFIG_Q40) && !defined(MULTI_ISA) 142 #define ISA_TYPE ISA_TYPE_Q40 143 #define ISA_SEX 0 144 #endif 145 #if defined(CONFIG_AMIGA_PCMCIA) && !defined(MULTI_ISA) 146 #define ISA_TYPE ISA_TYPE_AG 147 #define ISA_SEX 1 148 #endif 149 #if defined(CONFIG_ATARI_ROM_ISA) && !defined(MULTI_ISA) 150 #define ISA_TYPE ISA_TYPE_ENEC 151 #define ISA_SEX 0 152 #endif 153 154 #ifdef MULTI_ISA 155 extern int isa_type; 156 extern int isa_sex; 157 158 #define ISA_TYPE isa_type 159 #define ISA_SEX isa_sex 160 #endif 161 162 /* 163 * define inline addr translation functions. Normally only one variant will 164 * be compiled in so the case statement will be optimised away 165 */ 166 167 static inline u8 __iomem *isa_itb(unsigned long addr) 168 { 169 switch(ISA_TYPE) 170 { 171 #ifdef CONFIG_Q40 172 case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_IO_B(addr); 173 #endif 174 #ifdef CONFIG_AMIGA_PCMCIA 175 case ISA_TYPE_AG: return (u8 __iomem *)AG_ISA_IO_B(addr); 176 #endif 177 #ifdef CONFIG_ATARI_ROM_ISA 178 case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_IO_B(addr); 179 #endif 180 default: return NULL; /* avoid warnings, just in case */ 181 } 182 } 183 static inline u16 __iomem *isa_itw(unsigned long addr) 184 { 185 switch(ISA_TYPE) 186 { 187 #ifdef CONFIG_Q40 188 case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_IO_W(addr); 189 #endif 190 #ifdef CONFIG_AMIGA_PCMCIA 191 case ISA_TYPE_AG: return (u16 __iomem *)AG_ISA_IO_W(addr); 192 #endif 193 #ifdef CONFIG_ATARI_ROM_ISA 194 case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_IO_W(addr); 195 #endif 196 default: return NULL; /* avoid warnings, just in case */ 197 } 198 } 199 static inline u32 __iomem *isa_itl(unsigned long addr) 200 { 201 switch(ISA_TYPE) 202 { 203 #ifdef CONFIG_AMIGA_PCMCIA 204 case ISA_TYPE_AG: return (u32 __iomem *)AG_ISA_IO_W(addr); 205 #endif 206 default: return 0; /* avoid warnings, just in case */ 207 } 208 } 209 static inline u8 __iomem *isa_mtb(unsigned long addr) 210 { 211 switch(ISA_TYPE) 212 { 213 #ifdef CONFIG_Q40 214 case ISA_TYPE_Q40: return (u8 __iomem *)Q40_ISA_MEM_B(addr); 215 #endif 216 #ifdef CONFIG_AMIGA_PCMCIA 217 case ISA_TYPE_AG: return (u8 __iomem *)addr; 218 #endif 219 #ifdef CONFIG_ATARI_ROM_ISA 220 case ISA_TYPE_ENEC: return (u8 __iomem *)ENEC_ISA_MEM_B(addr); 221 #endif 222 default: return NULL; /* avoid warnings, just in case */ 223 } 224 } 225 static inline u16 __iomem *isa_mtw(unsigned long addr) 226 { 227 switch(ISA_TYPE) 228 { 229 #ifdef CONFIG_Q40 230 case ISA_TYPE_Q40: return (u16 __iomem *)Q40_ISA_MEM_W(addr); 231 #endif 232 #ifdef CONFIG_AMIGA_PCMCIA 233 case ISA_TYPE_AG: return (u16 __iomem *)addr; 234 #endif 235 #ifdef CONFIG_ATARI_ROM_ISA 236 case ISA_TYPE_ENEC: return (u16 __iomem *)ENEC_ISA_MEM_W(addr); 237 #endif 238 default: return NULL; /* avoid warnings, just in case */ 239 } 240 } 241 242 243 #define isa_inb(port) in_8(isa_itb(port)) 244 #define isa_inw(port) (ISA_SEX ? in_be16(isa_itw(port)) : in_le16(isa_itw(port))) 245 #define isa_inl(port) (ISA_SEX ? in_be32(isa_itl(port)) : in_le32(isa_itl(port))) 246 #define isa_outb(val,port) out_8(isa_itb(port),(val)) 247 #define isa_outw(val,port) (ISA_SEX ? out_be16(isa_itw(port),(val)) : out_le16(isa_itw(port),(val))) 248 #define isa_outl(val,port) (ISA_SEX ? out_be32(isa_itl(port),(val)) : out_le32(isa_itl(port),(val))) 249 250 #define isa_readb(p) in_8(isa_mtb((unsigned long)(p))) 251 #define isa_readw(p) \ 252 (ISA_SEX ? in_be16(isa_mtw((unsigned long)(p))) \ 253 : in_le16(isa_mtw((unsigned long)(p)))) 254 #define isa_writeb(val,p) out_8(isa_mtb((unsigned long)(p)),(val)) 255 #define isa_writew(val,p) \ 256 (ISA_SEX ? out_be16(isa_mtw((unsigned long)(p)),(val)) \ 257 : out_le16(isa_mtw((unsigned long)(p)),(val))) 258 259 #ifdef CONFIG_ATARI_ROM_ISA 260 #define isa_rom_inb(port) rom_in_8(isa_itb(port)) 261 #define isa_rom_inw(port) \ 262 (ISA_SEX ? rom_in_be16(isa_itw(port)) \ 263 : rom_in_le16(isa_itw(port))) 264 265 #define isa_rom_outb(val, port) rom_out_8(isa_itb(port), (val)) 266 #define isa_rom_outw(val, port) \ 267 (ISA_SEX ? rom_out_be16(isa_itw(port), (val)) \ 268 : rom_out_le16(isa_itw(port), (val))) 269 270 #define isa_rom_readb(p) rom_in_8(isa_mtb((unsigned long)(p))) 271 #define isa_rom_readw(p) \ 272 (ISA_SEX ? rom_in_be16(isa_mtw((unsigned long)(p))) \ 273 : rom_in_le16(isa_mtw((unsigned long)(p)))) 274 #define isa_rom_readw_swap(p) \ 275 (ISA_SEX ? rom_in_le16(isa_mtw((unsigned long)(p))) \ 276 : rom_in_be16(isa_mtw((unsigned long)(p)))) 277 #define isa_rom_readw_raw(p) rom_in_be16(isa_mtw((unsigned long)(p))) 278 279 #define isa_rom_writeb(val, p) rom_out_8(isa_mtb((unsigned long)(p)), (val)) 280 #define isa_rom_writew(val, p) \ 281 (ISA_SEX ? rom_out_be16(isa_mtw((unsigned long)(p)), (val)) \ 282 : rom_out_le16(isa_mtw((unsigned long)(p)), (val))) 283 #define isa_rom_writew_swap(val, p) \ 284 (ISA_SEX ? rom_out_le16(isa_mtw((unsigned long)(p)), (val)) \ 285 : rom_out_be16(isa_mtw((unsigned long)(p)), (val))) 286 #define isa_rom_writew_raw(val, p) rom_out_be16(isa_mtw((unsigned long)(p)), (val)) 287 #endif /* CONFIG_ATARI_ROM_ISA */ 288 289 static inline void isa_delay(void) 290 { 291 switch(ISA_TYPE) 292 { 293 #ifdef CONFIG_Q40 294 case ISA_TYPE_Q40: isa_outb(0,0x80); break; 295 #endif 296 #ifdef CONFIG_AMIGA_PCMCIA 297 case ISA_TYPE_AG: break; 298 #endif 299 #ifdef CONFIG_ATARI_ROM_ISA 300 case ISA_TYPE_ENEC: break; 301 #endif 302 default: break; /* avoid warnings */ 303 } 304 } 305 306 #define isa_inb_p(p) ({u8 v=isa_inb(p);isa_delay();v;}) 307 #define isa_outb_p(v,p) ({isa_outb((v),(p));isa_delay();}) 308 #define isa_inw_p(p) ({u16 v=isa_inw(p);isa_delay();v;}) 309 #define isa_outw_p(v,p) ({isa_outw((v),(p));isa_delay();}) 310 #define isa_inl_p(p) ({u32 v=isa_inl(p);isa_delay();v;}) 311 #define isa_outl_p(v,p) ({isa_outl((v),(p));isa_delay();}) 312 313 #define isa_insb(port, buf, nr) raw_insb(isa_itb(port), (u8 *)(buf), (nr)) 314 #define isa_outsb(port, buf, nr) raw_outsb(isa_itb(port), (u8 *)(buf), (nr)) 315 316 #define isa_insw(port, buf, nr) \ 317 (ISA_SEX ? raw_insw(isa_itw(port), (u16 *)(buf), (nr)) : \ 318 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr))) 319 320 #define isa_outsw(port, buf, nr) \ 321 (ISA_SEX ? raw_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \ 322 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr))) 323 324 #define isa_insl(port, buf, nr) \ 325 (ISA_SEX ? raw_insl(isa_itl(port), (u32 *)(buf), (nr)) : \ 326 raw_insw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1)) 327 328 #define isa_outsl(port, buf, nr) \ 329 (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) : \ 330 raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1)) 331 332 333 #ifdef CONFIG_ATARI_ROM_ISA 334 #define isa_rom_inb_p(p) ({ u8 _v = isa_rom_inb(p); isa_delay(); _v; }) 335 #define isa_rom_inw_p(p) ({ u16 _v = isa_rom_inw(p); isa_delay(); _v; }) 336 #define isa_rom_outb_p(v, p) ({ isa_rom_outb((v), (p)); isa_delay(); }) 337 #define isa_rom_outw_p(v, p) ({ isa_rom_outw((v), (p)); isa_delay(); }) 338 339 #define isa_rom_insb(port, buf, nr) raw_rom_insb(isa_itb(port), (u8 *)(buf), (nr)) 340 341 #define isa_rom_insw(port, buf, nr) \ 342 (ISA_SEX ? raw_rom_insw(isa_itw(port), (u16 *)(buf), (nr)) : \ 343 raw_rom_insw_swapw(isa_itw(port), (u16 *)(buf), (nr))) 344 345 #define isa_rom_outsb(port, buf, nr) raw_rom_outsb(isa_itb(port), (u8 *)(buf), (nr)) 346 347 #define isa_rom_outsw(port, buf, nr) \ 348 (ISA_SEX ? raw_rom_outsw(isa_itw(port), (u16 *)(buf), (nr)) : \ 349 raw_rom_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr))) 350 #endif /* CONFIG_ATARI_ROM_ISA */ 351 352 #endif /* CONFIG_ISA || CONFIG_ATARI_ROM_ISA */ 353 354 355 #if defined(CONFIG_ISA) && !defined(CONFIG_ATARI_ROM_ISA) 356 #define inb isa_inb 357 #define inb_p isa_inb_p 358 #define outb isa_outb 359 #define outb_p isa_outb_p 360 #define inw isa_inw 361 #define inw_p isa_inw_p 362 #define outw isa_outw 363 #define outw_p isa_outw_p 364 #define inl isa_inl 365 #define inl_p isa_inl_p 366 #define outl isa_outl 367 #define outl_p isa_outl_p 368 #define insb isa_insb 369 #define insw isa_insw 370 #define insl isa_insl 371 #define outsb isa_outsb 372 #define outsw isa_outsw 373 #define outsl isa_outsl 374 #define readb isa_readb 375 #define readw isa_readw 376 #define writeb isa_writeb 377 #define writew isa_writew 378 #endif /* CONFIG_ISA && !CONFIG_ATARI_ROM_ISA */ 379 380 #ifdef CONFIG_ATARI_ROM_ISA 381 /* 382 * kernel with both ROM port ISA and IDE compiled in, those have 383 * conflicting defs for in/out. Simply consider port < 1024 384 * ROM port ISA and everything else regular ISA for IDE. read,write defined 385 * below. 386 */ 387 #define inb(port) ((port) < 1024 ? isa_rom_inb(port) : in_8(port)) 388 #define inb_p(port) ((port) < 1024 ? isa_rom_inb_p(port) : in_8(port)) 389 #define inw(port) ((port) < 1024 ? isa_rom_inw(port) : in_le16(port)) 390 #define inw_p(port) ((port) < 1024 ? isa_rom_inw_p(port) : in_le16(port)) 391 #define inl isa_inl 392 #define inl_p isa_inl_p 393 394 #define outb(val, port) ((port) < 1024 ? isa_rom_outb((val), (port)) : out_8((port), (val))) 395 #define outb_p(val, port) ((port) < 1024 ? isa_rom_outb_p((val), (port)) : out_8((port), (val))) 396 #define outw(val, port) ((port) < 1024 ? isa_rom_outw((val), (port)) : out_le16((port), (val))) 397 #define outw_p(val, port) ((port) < 1024 ? isa_rom_outw_p((val), (port)) : out_le16((port), (val))) 398 #define outl isa_outl 399 #define outl_p isa_outl_p 400 401 #define insb(port, buf, nr) ((port) < 1024 ? isa_rom_insb((port), (buf), (nr)) : isa_insb((port), (buf), (nr))) 402 #define insw(port, buf, nr) ((port) < 1024 ? isa_rom_insw((port), (buf), (nr)) : isa_insw((port), (buf), (nr))) 403 #define insl isa_insl 404 #define outsb(port, buf, nr) ((port) < 1024 ? isa_rom_outsb((port), (buf), (nr)) : isa_outsb((port), (buf), (nr))) 405 #define outsw(port, buf, nr) ((port) < 1024 ? isa_rom_outsw((port), (buf), (nr)) : isa_outsw((port), (buf), (nr))) 406 #define outsl isa_outsl 407 408 #define readb(addr) in_8(addr) 409 #define writeb(val, addr) out_8((addr), (val)) 410 #define readw(addr) in_le16(addr) 411 #define writew(val, addr) out_le16((addr), (val)) 412 #endif /* CONFIG_ATARI_ROM_ISA */ 413 414 #if !defined(CONFIG_ISA) && !defined(CONFIG_ATARI_ROM_ISA) 415 /* 416 * We need to define dummy functions for GENERIC_IOMAP support. 417 */ 418 #define inb(port) 0xff 419 #define inb_p(port) 0xff 420 #define outb(val,port) ((void)0) 421 #define outb_p(val,port) ((void)0) 422 #define inw(port) 0xffff 423 #define inw_p(port) 0xffff 424 #define outw(val,port) ((void)0) 425 #define outw_p(val,port) ((void)0) 426 #define inl(port) 0xffffffffUL 427 #define inl_p(port) 0xffffffffUL 428 #define outl(val,port) ((void)0) 429 #define outl_p(val,port) ((void)0) 430 431 #define insb(port,buf,nr) ((void)0) 432 #define outsb(port,buf,nr) ((void)0) 433 #define insw(port,buf,nr) ((void)0) 434 #define outsw(port,buf,nr) ((void)0) 435 #define insl(port,buf,nr) ((void)0) 436 #define outsl(port,buf,nr) ((void)0) 437 438 /* 439 * These should be valid on any ioremap()ed region 440 */ 441 #define readb(addr) in_8(addr) 442 #define writeb(val,addr) out_8((addr),(val)) 443 #define readw(addr) in_le16(addr) 444 #define writew(val,addr) out_le16((addr),(val)) 445 446 #endif /* !CONFIG_ISA && !CONFIG_ATARI_ROM_ISA */ 447 448 #define readl(addr) in_le32(addr) 449 #define writel(val,addr) out_le32((addr),(val)) 450 451 #define readsb(port, buf, nr) raw_insb((port), (u8 *)(buf), (nr)) 452 #define readsw(port, buf, nr) raw_insw((port), (u16 *)(buf), (nr)) 453 #define readsl(port, buf, nr) raw_insl((port), (u32 *)(buf), (nr)) 454 #define writesb(port, buf, nr) raw_outsb((port), (u8 *)(buf), (nr)) 455 #define writesw(port, buf, nr) raw_outsw((port), (u16 *)(buf), (nr)) 456 #define writesl(port, buf, nr) raw_outsl((port), (u32 *)(buf), (nr)) 457 458 #define mmiowb() 459 460 static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size) 461 { 462 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER); 463 } 464 static inline void __iomem *ioremap_nocache(unsigned long physaddr, unsigned long size) 465 { 466 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER); 467 } 468 static inline void __iomem *ioremap_writethrough(unsigned long physaddr, 469 unsigned long size) 470 { 471 return __ioremap(physaddr, size, IOMAP_WRITETHROUGH); 472 } 473 static inline void __iomem *ioremap_fullcache(unsigned long physaddr, 474 unsigned long size) 475 { 476 return __ioremap(physaddr, size, IOMAP_FULL_CACHING); 477 } 478 479 static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count) 480 { 481 __builtin_memset((void __force *) addr, val, count); 482 } 483 static inline void memcpy_fromio(void *dst, const volatile void __iomem *src, int count) 484 { 485 __builtin_memcpy(dst, (void __force *) src, count); 486 } 487 static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count) 488 { 489 __builtin_memcpy((void __force *) dst, src, count); 490 } 491 492 #ifndef CONFIG_SUN3 493 #define IO_SPACE_LIMIT 0xffff 494 #else 495 #define IO_SPACE_LIMIT 0x0fffffff 496 #endif 497 498 #endif /* __KERNEL__ */ 499 500 #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1 501 502 /* 503 * Convert a physical pointer to a virtual kernel pointer for /dev/mem 504 * access 505 */ 506 #define xlate_dev_mem_ptr(p) __va(p) 507 508 /* 509 * Convert a virtual cached pointer to an uncached pointer 510 */ 511 #define xlate_dev_kmem_ptr(p) p 512 513 #define ioport_map(port, nr) ((void __iomem *)(port)) 514 515 #endif /* _IO_H */ 516