io.h 14 KB

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