io.h 14 KB

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