io.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. #ifndef _ASM_POWERPC_IO_H
  2. #define _ASM_POWERPC_IO_H
  3. #ifdef __KERNEL__
  4. /*
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. */
  10. /* Check of existence of legacy devices */
  11. extern int check_legacy_ioport(unsigned long base_port);
  12. #ifndef CONFIG_PPC64
  13. #include <asm-ppc/io.h>
  14. #else
  15. #include <linux/compiler.h>
  16. #include <asm/page.h>
  17. #include <asm/byteorder.h>
  18. #ifdef CONFIG_PPC_ISERIES
  19. #include <asm/iseries/iseries_io.h>
  20. #endif
  21. #include <asm/synch.h>
  22. #include <asm/delay.h>
  23. #include <asm-generic/iomap.h>
  24. #define __ide_mm_insw(p, a, c) _insw_ns((volatile u16 __iomem *)(p), (a), (c))
  25. #define __ide_mm_insl(p, a, c) _insl_ns((volatile u32 __iomem *)(p), (a), (c))
  26. #define __ide_mm_outsw(p, a, c) _outsw_ns((volatile u16 __iomem *)(p), (a), (c))
  27. #define __ide_mm_outsl(p, a, c) _outsl_ns((volatile u32 __iomem *)(p), (a), (c))
  28. #define SIO_CONFIG_RA 0x398
  29. #define SIO_CONFIG_RD 0x399
  30. #define SLOW_DOWN_IO
  31. extern unsigned long isa_io_base;
  32. extern unsigned long pci_io_base;
  33. extern unsigned long io_page_mask;
  34. #define MAX_ISA_PORT 0x10000
  35. #define _IO_IS_VALID(port) ((port) >= MAX_ISA_PORT || (1 << (port>>PAGE_SHIFT)) \
  36. & io_page_mask)
  37. #ifdef CONFIG_PPC_ISERIES
  38. /* __raw_* accessors aren't supported on iSeries */
  39. #define __raw_readb(addr) { BUG(); 0; }
  40. #define __raw_readw(addr) { BUG(); 0; }
  41. #define __raw_readl(addr) { BUG(); 0; }
  42. #define __raw_readq(addr) { BUG(); 0; }
  43. #define __raw_writeb(v, addr) { BUG(); 0; }
  44. #define __raw_writew(v, addr) { BUG(); 0; }
  45. #define __raw_writel(v, addr) { BUG(); 0; }
  46. #define __raw_writeq(v, addr) { BUG(); 0; }
  47. #define readb(addr) iSeries_Read_Byte(addr)
  48. #define readw(addr) iSeries_Read_Word(addr)
  49. #define readl(addr) iSeries_Read_Long(addr)
  50. #define writeb(data, addr) iSeries_Write_Byte((data),(addr))
  51. #define writew(data, addr) iSeries_Write_Word((data),(addr))
  52. #define writel(data, addr) iSeries_Write_Long((data),(addr))
  53. #define memset_io(a,b,c) iSeries_memset_io((a),(b),(c))
  54. #define memcpy_fromio(a,b,c) iSeries_memcpy_fromio((a), (b), (c))
  55. #define memcpy_toio(a,b,c) iSeries_memcpy_toio((a), (b), (c))
  56. #define inb(addr) readb(((void __iomem *)(long)(addr)))
  57. #define inw(addr) readw(((void __iomem *)(long)(addr)))
  58. #define inl(addr) readl(((void __iomem *)(long)(addr)))
  59. #define outb(data,addr) writeb(data,((void __iomem *)(long)(addr)))
  60. #define outw(data,addr) writew(data,((void __iomem *)(long)(addr)))
  61. #define outl(data,addr) writel(data,((void __iomem *)(long)(addr)))
  62. /*
  63. * The *_ns versions below don't do byte-swapping.
  64. * Neither do the standard versions now, these are just here
  65. * for older code.
  66. */
  67. #define insw_ns(port, buf, ns) _insw_ns((u16 __iomem *)((port)+pci_io_base), (buf), (ns))
  68. #define insl_ns(port, buf, nl) _insl_ns((u32 __iomem *)((port)+pci_io_base), (buf), (nl))
  69. #else
  70. static inline unsigned char __raw_readb(const volatile void __iomem *addr)
  71. {
  72. return *(volatile unsigned char __force *)addr;
  73. }
  74. static inline unsigned short __raw_readw(const volatile void __iomem *addr)
  75. {
  76. return *(volatile unsigned short __force *)addr;
  77. }
  78. static inline unsigned int __raw_readl(const volatile void __iomem *addr)
  79. {
  80. return *(volatile unsigned int __force *)addr;
  81. }
  82. static inline unsigned long __raw_readq(const volatile void __iomem *addr)
  83. {
  84. return *(volatile unsigned long __force *)addr;
  85. }
  86. static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr)
  87. {
  88. *(volatile unsigned char __force *)addr = v;
  89. }
  90. static inline void __raw_writew(unsigned short v, volatile void __iomem *addr)
  91. {
  92. *(volatile unsigned short __force *)addr = v;
  93. }
  94. static inline void __raw_writel(unsigned int v, volatile void __iomem *addr)
  95. {
  96. *(volatile unsigned int __force *)addr = v;
  97. }
  98. static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
  99. {
  100. *(volatile unsigned long __force *)addr = v;
  101. }
  102. #define readb(addr) eeh_readb(addr)
  103. #define readw(addr) eeh_readw(addr)
  104. #define readl(addr) eeh_readl(addr)
  105. #define readq(addr) eeh_readq(addr)
  106. #define writeb(data, addr) eeh_writeb((data), (addr))
  107. #define writew(data, addr) eeh_writew((data), (addr))
  108. #define writel(data, addr) eeh_writel((data), (addr))
  109. #define writeq(data, addr) eeh_writeq((data), (addr))
  110. #define memset_io(a,b,c) eeh_memset_io((a),(b),(c))
  111. #define memcpy_fromio(a,b,c) eeh_memcpy_fromio((a),(b),(c))
  112. #define memcpy_toio(a,b,c) eeh_memcpy_toio((a),(b),(c))
  113. #define inb(port) eeh_inb((unsigned long)port)
  114. #define outb(val, port) eeh_outb(val, (unsigned long)port)
  115. #define inw(port) eeh_inw((unsigned long)port)
  116. #define outw(val, port) eeh_outw(val, (unsigned long)port)
  117. #define inl(port) eeh_inl((unsigned long)port)
  118. #define outl(val, port) eeh_outl(val, (unsigned long)port)
  119. /*
  120. * The insw/outsw/insl/outsl macros don't do byte-swapping.
  121. * They are only used in practice for transferring buffers which
  122. * are arrays of bytes, and byte-swapping is not appropriate in
  123. * that case. - paulus */
  124. #define insb(port, buf, ns) eeh_insb((port), (buf), (ns))
  125. #define insw(port, buf, ns) eeh_insw_ns((port), (buf), (ns))
  126. #define insl(port, buf, nl) eeh_insl_ns((port), (buf), (nl))
  127. #define insw_ns(port, buf, ns) eeh_insw_ns((port), (buf), (ns))
  128. #define insl_ns(port, buf, nl) eeh_insl_ns((port), (buf), (nl))
  129. #define outsb(port, buf, ns) _outsb((u8 __iomem *)((port)+pci_io_base), (buf), (ns))
  130. #define outsw(port, buf, ns) _outsw_ns((u16 __iomem *)((port)+pci_io_base), (buf), (ns))
  131. #define outsl(port, buf, nl) _outsl_ns((u32 __iomem *)((port)+pci_io_base), (buf), (nl))
  132. #endif
  133. #define readb_relaxed(addr) readb(addr)
  134. #define readw_relaxed(addr) readw(addr)
  135. #define readl_relaxed(addr) readl(addr)
  136. #define readq_relaxed(addr) readq(addr)
  137. extern void _insb(volatile u8 __iomem *port, void *buf, int ns);
  138. extern void _outsb(volatile u8 __iomem *port, const void *buf, int ns);
  139. extern void _insw(volatile u16 __iomem *port, void *buf, int ns);
  140. extern void _outsw(volatile u16 __iomem *port, const void *buf, int ns);
  141. extern void _insl(volatile u32 __iomem *port, void *buf, int nl);
  142. extern void _outsl(volatile u32 __iomem *port, const void *buf, int nl);
  143. extern void _insw_ns(volatile u16 __iomem *port, void *buf, int ns);
  144. extern void _outsw_ns(volatile u16 __iomem *port, const void *buf, int ns);
  145. extern void _insl_ns(volatile u32 __iomem *port, void *buf, int nl);
  146. extern void _outsl_ns(volatile u32 __iomem *port, const void *buf, int nl);
  147. #define mmiowb()
  148. /*
  149. * output pause versions need a delay at least for the
  150. * w83c105 ide controller in a p610.
  151. */
  152. #define inb_p(port) inb(port)
  153. #define outb_p(val, port) (udelay(1), outb((val), (port)))
  154. #define inw_p(port) inw(port)
  155. #define outw_p(val, port) (udelay(1), outw((val), (port)))
  156. #define inl_p(port) inl(port)
  157. #define outl_p(val, port) (udelay(1), outl((val), (port)))
  158. /*
  159. * The *_ns versions below don't do byte-swapping.
  160. * Neither do the standard versions now, these are just here
  161. * for older code.
  162. */
  163. #define outsw_ns(port, buf, ns) _outsw_ns((u16 __iomem *)((port)+pci_io_base), (buf), (ns))
  164. #define outsl_ns(port, buf, nl) _outsl_ns((u32 __iomem *)((port)+pci_io_base), (buf), (nl))
  165. #define IO_SPACE_LIMIT ~(0UL)
  166. extern int __ioremap_explicit(unsigned long p_addr, unsigned long v_addr,
  167. unsigned long size, unsigned long flags);
  168. extern void __iomem *__ioremap(unsigned long address, unsigned long size,
  169. unsigned long flags);
  170. /**
  171. * ioremap - map bus memory into CPU space
  172. * @address: bus address of the memory
  173. * @size: size of the resource to map
  174. *
  175. * ioremap performs a platform specific sequence of operations to
  176. * make bus memory CPU accessible via the readb/readw/readl/writeb/
  177. * writew/writel functions and the other mmio helpers. The returned
  178. * address is not guaranteed to be usable directly as a virtual
  179. * address.
  180. */
  181. extern void __iomem *ioremap(unsigned long address, unsigned long size);
  182. #define ioremap_nocache(addr, size) ioremap((addr), (size))
  183. extern int iounmap_explicit(volatile void __iomem *addr, unsigned long size);
  184. extern void iounmap(volatile void __iomem *addr);
  185. extern void __iomem * reserve_phb_iospace(unsigned long size);
  186. /**
  187. * virt_to_phys - map virtual addresses to physical
  188. * @address: address to remap
  189. *
  190. * The returned physical address is the physical (CPU) mapping for
  191. * the memory address given. It is only valid to use this function on
  192. * addresses directly mapped or allocated via kmalloc.
  193. *
  194. * This function does not give bus mappings for DMA transfers. In
  195. * almost all conceivable cases a device driver should not be using
  196. * this function
  197. */
  198. static inline unsigned long virt_to_phys(volatile void * address)
  199. {
  200. return __pa((unsigned long)address);
  201. }
  202. /**
  203. * phys_to_virt - map physical address to virtual
  204. * @address: address to remap
  205. *
  206. * The returned virtual address is a current CPU mapping for
  207. * the memory address given. It is only valid to use this function on
  208. * addresses that have a kernel mapping
  209. *
  210. * This function does not handle bus mappings for DMA transfers. In
  211. * almost all conceivable cases a device driver should not be using
  212. * this function
  213. */
  214. static inline void * phys_to_virt(unsigned long address)
  215. {
  216. return (void *)__va(address);
  217. }
  218. /*
  219. * Change "struct page" to physical address.
  220. */
  221. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  222. /* We do NOT want virtual merging, it would put too much pressure on
  223. * our iommu allocator. Instead, we want drivers to be smart enough
  224. * to coalesce sglists that happen to have been mapped in a contiguous
  225. * way by the iommu
  226. */
  227. #define BIO_VMERGE_BOUNDARY 0
  228. static inline void iosync(void)
  229. {
  230. __asm__ __volatile__ ("sync" : : : "memory");
  231. }
  232. /* Enforce in-order execution of data I/O.
  233. * No distinction between read/write on PPC; use eieio for all three.
  234. */
  235. #define iobarrier_rw() eieio()
  236. #define iobarrier_r() eieio()
  237. #define iobarrier_w() eieio()
  238. /*
  239. * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
  240. * These routines do not perform EEH-related I/O address translation,
  241. * and should not be used directly by device drivers. Use inb/readb
  242. * instead.
  243. */
  244. static inline int in_8(const volatile unsigned char __iomem *addr)
  245. {
  246. int ret;
  247. __asm__ __volatile__("lbz%U1%X1 %0,%1; twi 0,%0,0; isync"
  248. : "=r" (ret) : "m" (*addr));
  249. return ret;
  250. }
  251. static inline void out_8(volatile unsigned char __iomem *addr, int val)
  252. {
  253. __asm__ __volatile__("stb%U0%X0 %1,%0; sync"
  254. : "=m" (*addr) : "r" (val));
  255. }
  256. static inline int in_le16(const volatile unsigned short __iomem *addr)
  257. {
  258. int ret;
  259. __asm__ __volatile__("lhbrx %0,0,%1; twi 0,%0,0; isync"
  260. : "=r" (ret) : "r" (addr), "m" (*addr));
  261. return ret;
  262. }
  263. static inline int in_be16(const volatile unsigned short __iomem *addr)
  264. {
  265. int ret;
  266. __asm__ __volatile__("lhz%U1%X1 %0,%1; twi 0,%0,0; isync"
  267. : "=r" (ret) : "m" (*addr));
  268. return ret;
  269. }
  270. static inline void out_le16(volatile unsigned short __iomem *addr, int val)
  271. {
  272. __asm__ __volatile__("sthbrx %1,0,%2; sync"
  273. : "=m" (*addr) : "r" (val), "r" (addr));
  274. }
  275. static inline void out_be16(volatile unsigned short __iomem *addr, int val)
  276. {
  277. __asm__ __volatile__("sth%U0%X0 %1,%0; sync"
  278. : "=m" (*addr) : "r" (val));
  279. }
  280. static inline unsigned in_le32(const volatile unsigned __iomem *addr)
  281. {
  282. unsigned ret;
  283. __asm__ __volatile__("lwbrx %0,0,%1; twi 0,%0,0; isync"
  284. : "=r" (ret) : "r" (addr), "m" (*addr));
  285. return ret;
  286. }
  287. static inline unsigned in_be32(const volatile unsigned __iomem *addr)
  288. {
  289. unsigned ret;
  290. __asm__ __volatile__("lwz%U1%X1 %0,%1; twi 0,%0,0; isync"
  291. : "=r" (ret) : "m" (*addr));
  292. return ret;
  293. }
  294. static inline void out_le32(volatile unsigned __iomem *addr, int val)
  295. {
  296. __asm__ __volatile__("stwbrx %1,0,%2; sync" : "=m" (*addr)
  297. : "r" (val), "r" (addr));
  298. }
  299. static inline void out_be32(volatile unsigned __iomem *addr, int val)
  300. {
  301. __asm__ __volatile__("stw%U0%X0 %1,%0; sync"
  302. : "=m" (*addr) : "r" (val));
  303. }
  304. static inline unsigned long in_le64(const volatile unsigned long __iomem *addr)
  305. {
  306. unsigned long tmp, ret;
  307. __asm__ __volatile__(
  308. "ld %1,0(%2)\n"
  309. "twi 0,%1,0\n"
  310. "isync\n"
  311. "rldimi %0,%1,5*8,1*8\n"
  312. "rldimi %0,%1,3*8,2*8\n"
  313. "rldimi %0,%1,1*8,3*8\n"
  314. "rldimi %0,%1,7*8,4*8\n"
  315. "rldicl %1,%1,32,0\n"
  316. "rlwimi %0,%1,8,8,31\n"
  317. "rlwimi %0,%1,24,16,23\n"
  318. : "=r" (ret) , "=r" (tmp) : "b" (addr) , "m" (*addr));
  319. return ret;
  320. }
  321. static inline unsigned long in_be64(const volatile unsigned long __iomem *addr)
  322. {
  323. unsigned long ret;
  324. __asm__ __volatile__("ld%U1%X1 %0,%1; twi 0,%0,0; isync"
  325. : "=r" (ret) : "m" (*addr));
  326. return ret;
  327. }
  328. static inline void out_le64(volatile unsigned long __iomem *addr, unsigned long val)
  329. {
  330. unsigned long tmp;
  331. __asm__ __volatile__(
  332. "rldimi %0,%1,5*8,1*8\n"
  333. "rldimi %0,%1,3*8,2*8\n"
  334. "rldimi %0,%1,1*8,3*8\n"
  335. "rldimi %0,%1,7*8,4*8\n"
  336. "rldicl %1,%1,32,0\n"
  337. "rlwimi %0,%1,8,8,31\n"
  338. "rlwimi %0,%1,24,16,23\n"
  339. "std %0,0(%3)\n"
  340. "sync"
  341. : "=&r" (tmp) , "=&r" (val) : "1" (val) , "b" (addr) , "m" (*addr));
  342. }
  343. static inline void out_be64(volatile unsigned long __iomem *addr, unsigned long val)
  344. {
  345. __asm__ __volatile__("std%U0%X0 %1,%0; sync" : "=m" (*addr) : "r" (val));
  346. }
  347. #ifndef CONFIG_PPC_ISERIES
  348. #include <asm/eeh.h>
  349. #endif
  350. /**
  351. * check_signature - find BIOS signatures
  352. * @io_addr: mmio address to check
  353. * @signature: signature block
  354. * @length: length of signature
  355. *
  356. * Perform a signature comparison with the mmio address io_addr. This
  357. * address should have been obtained by ioremap.
  358. * Returns 1 on a match.
  359. */
  360. static inline int check_signature(const volatile void __iomem * io_addr,
  361. const unsigned char *signature, int length)
  362. {
  363. int retval = 0;
  364. #ifndef CONFIG_PPC_ISERIES
  365. do {
  366. if (readb(io_addr) != *signature)
  367. goto out;
  368. io_addr++;
  369. signature++;
  370. length--;
  371. } while (length);
  372. retval = 1;
  373. out:
  374. #endif
  375. return retval;
  376. }
  377. /* Nothing to do */
  378. #define dma_cache_inv(_start,_size) do { } while (0)
  379. #define dma_cache_wback(_start,_size) do { } while (0)
  380. #define dma_cache_wback_inv(_start,_size) do { } while (0)
  381. /*
  382. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  383. * access
  384. */
  385. #define xlate_dev_mem_ptr(p) __va(p)
  386. /*
  387. * Convert a virtual cached pointer to an uncached pointer
  388. */
  389. #define xlate_dev_kmem_ptr(p) p
  390. #endif /* __KERNEL__ */
  391. #endif /* CONFIG_PPC64 */
  392. #endif /* _ASM_POWERPC_IO_H */