io.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  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, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_IO_H
  15. #define _ASM_TILE_IO_H
  16. #include <linux/kernel.h>
  17. #include <linux/bug.h>
  18. #include <asm/page.h>
  19. #define IO_SPACE_LIMIT 0xfffffffful
  20. /*
  21. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  22. * access.
  23. */
  24. #define xlate_dev_mem_ptr(p) __va(p)
  25. /*
  26. * Convert a virtual cached pointer to an uncached pointer.
  27. */
  28. #define xlate_dev_kmem_ptr(p) p
  29. /*
  30. * Change "struct page" to physical address.
  31. */
  32. #define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
  33. /*
  34. * Some places try to pass in an loff_t for PHYSADDR (?!), so we cast it to
  35. * long before casting it to a pointer to avoid compiler warnings.
  36. */
  37. #if CHIP_HAS_MMIO()
  38. extern void __iomem *ioremap(resource_size_t offset, unsigned long size);
  39. extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size,
  40. pgprot_t pgprot);
  41. extern void iounmap(volatile void __iomem *addr);
  42. #else
  43. #define ioremap(physaddr, size) ((void __iomem *)(unsigned long)(physaddr))
  44. #define iounmap(addr) ((void)0)
  45. #endif
  46. #define ioremap_nocache(physaddr, size) ioremap(physaddr, size)
  47. #define ioremap_writethrough(physaddr, size) ioremap(physaddr, size)
  48. #define ioremap_fullcache(physaddr, size) ioremap(physaddr, size)
  49. #define mmiowb()
  50. /* Conversion between virtual and physical mappings. */
  51. #define mm_ptov(addr) ((void *)phys_to_virt(addr))
  52. #define mm_vtop(addr) ((unsigned long)virt_to_phys(addr))
  53. #ifdef CONFIG_PCI
  54. extern u8 _tile_readb(unsigned long addr);
  55. extern u16 _tile_readw(unsigned long addr);
  56. extern u32 _tile_readl(unsigned long addr);
  57. extern u64 _tile_readq(unsigned long addr);
  58. extern void _tile_writeb(u8 val, unsigned long addr);
  59. extern void _tile_writew(u16 val, unsigned long addr);
  60. extern void _tile_writel(u32 val, unsigned long addr);
  61. extern void _tile_writeq(u64 val, unsigned long addr);
  62. #else
  63. /*
  64. * The Tile architecture does not support IOMEM unless PCI is enabled.
  65. * Unfortunately we can't yet simply not declare these methods,
  66. * since some generic code that compiles into the kernel, but
  67. * we never run, uses them unconditionally.
  68. */
  69. static inline int iomem_panic(void)
  70. {
  71. panic("readb/writeb and friends do not exist on tile without PCI");
  72. return 0;
  73. }
  74. static inline u8 _tile_readb(unsigned long addr)
  75. {
  76. return iomem_panic();
  77. }
  78. static inline u16 _tile_readw(unsigned long addr)
  79. {
  80. return iomem_panic();
  81. }
  82. static inline u32 _tile_readl(unsigned long addr)
  83. {
  84. return iomem_panic();
  85. }
  86. static inline u64 _tile_readq(unsigned long addr)
  87. {
  88. return iomem_panic();
  89. }
  90. static inline void _tile_writeb(u8 val, unsigned long addr)
  91. {
  92. iomem_panic();
  93. }
  94. static inline void _tile_writew(u16 val, unsigned long addr)
  95. {
  96. iomem_panic();
  97. }
  98. static inline void _tile_writel(u32 val, unsigned long addr)
  99. {
  100. iomem_panic();
  101. }
  102. static inline void _tile_writeq(u64 val, unsigned long addr)
  103. {
  104. iomem_panic();
  105. }
  106. #endif
  107. #define readb(addr) _tile_readb((unsigned long)addr)
  108. #define readw(addr) _tile_readw((unsigned long)addr)
  109. #define readl(addr) _tile_readl((unsigned long)addr)
  110. #define readq(addr) _tile_readq((unsigned long)addr)
  111. #define writeb(val, addr) _tile_writeb(val, (unsigned long)addr)
  112. #define writew(val, addr) _tile_writew(val, (unsigned long)addr)
  113. #define writel(val, addr) _tile_writel(val, (unsigned long)addr)
  114. #define writeq(val, addr) _tile_writeq(val, (unsigned long)addr)
  115. #define __raw_readb readb
  116. #define __raw_readw readw
  117. #define __raw_readl readl
  118. #define __raw_readq readq
  119. #define __raw_writeb writeb
  120. #define __raw_writew writew
  121. #define __raw_writel writel
  122. #define __raw_writeq writeq
  123. #define readb_relaxed readb
  124. #define readw_relaxed readw
  125. #define readl_relaxed readl
  126. #define readq_relaxed readq
  127. #define ioread8 readb
  128. #define ioread16 readw
  129. #define ioread32 readl
  130. #define ioread64 readq
  131. #define iowrite8 writeb
  132. #define iowrite16 writew
  133. #define iowrite32 writel
  134. #define iowrite64 writeq
  135. static inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
  136. size_t len)
  137. {
  138. int x;
  139. BUG_ON((unsigned long)src & 0x3);
  140. for (x = 0; x < len; x += 4)
  141. *(u32 *)(dst + x) = readl(src + x);
  142. }
  143. static inline void memcpy_toio(volatile void __iomem *dst, const void *src,
  144. size_t len)
  145. {
  146. int x;
  147. BUG_ON((unsigned long)dst & 0x3);
  148. for (x = 0; x < len; x += 4)
  149. writel(*(u32 *)(src + x), dst + x);
  150. }
  151. /*
  152. * The Tile architecture does not support IOPORT, even with PCI.
  153. * Unfortunately we can't yet simply not declare these methods,
  154. * since some generic code that compiles into the kernel, but
  155. * we never run, uses them unconditionally.
  156. */
  157. static inline long ioport_panic(void)
  158. {
  159. panic("inb/outb and friends do not exist on tile");
  160. return 0;
  161. }
  162. static inline void __iomem *ioport_map(unsigned long port, unsigned int len)
  163. {
  164. return (void __iomem *) ioport_panic();
  165. }
  166. static inline void ioport_unmap(void __iomem *addr)
  167. {
  168. ioport_panic();
  169. }
  170. static inline u8 inb(unsigned long addr)
  171. {
  172. return ioport_panic();
  173. }
  174. static inline u16 inw(unsigned long addr)
  175. {
  176. return ioport_panic();
  177. }
  178. static inline u32 inl(unsigned long addr)
  179. {
  180. return ioport_panic();
  181. }
  182. static inline void outb(u8 b, unsigned long addr)
  183. {
  184. ioport_panic();
  185. }
  186. static inline void outw(u16 b, unsigned long addr)
  187. {
  188. ioport_panic();
  189. }
  190. static inline void outl(u32 b, unsigned long addr)
  191. {
  192. ioport_panic();
  193. }
  194. #define inb_p(addr) inb(addr)
  195. #define inw_p(addr) inw(addr)
  196. #define inl_p(addr) inl(addr)
  197. #define outb_p(x, addr) outb((x), (addr))
  198. #define outw_p(x, addr) outw((x), (addr))
  199. #define outl_p(x, addr) outl((x), (addr))
  200. static inline void insb(unsigned long addr, void *buffer, int count)
  201. {
  202. ioport_panic();
  203. }
  204. static inline void insw(unsigned long addr, void *buffer, int count)
  205. {
  206. ioport_panic();
  207. }
  208. static inline void insl(unsigned long addr, void *buffer, int count)
  209. {
  210. ioport_panic();
  211. }
  212. static inline void outsb(unsigned long addr, const void *buffer, int count)
  213. {
  214. ioport_panic();
  215. }
  216. static inline void outsw(unsigned long addr, const void *buffer, int count)
  217. {
  218. ioport_panic();
  219. }
  220. static inline void outsl(unsigned long addr, const void *buffer, int count)
  221. {
  222. ioport_panic();
  223. }
  224. #define ioread8_rep(p, dst, count) \
  225. insb((unsigned long) (p), (dst), (count))
  226. #define ioread16_rep(p, dst, count) \
  227. insw((unsigned long) (p), (dst), (count))
  228. #define ioread32_rep(p, dst, count) \
  229. insl((unsigned long) (p), (dst), (count))
  230. #define iowrite8_rep(p, src, count) \
  231. outsb((unsigned long) (p), (src), (count))
  232. #define iowrite16_rep(p, src, count) \
  233. outsw((unsigned long) (p), (src), (count))
  234. #define iowrite32_rep(p, src, count) \
  235. outsl((unsigned long) (p), (src), (count))
  236. #endif /* _ASM_TILE_IO_H */