io.h 14 KB

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