io.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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_wc(physaddr, size) ioremap(physaddr, size)
  48. #define ioremap_writethrough(physaddr, size) ioremap(physaddr, size)
  49. #define ioremap_fullcache(physaddr, size) ioremap(physaddr, size)
  50. #define mmiowb()
  51. /* Conversion between virtual and physical mappings. */
  52. #define mm_ptov(addr) ((void *)phys_to_virt(addr))
  53. #define mm_vtop(addr) ((unsigned long)virt_to_phys(addr))
  54. #ifdef CONFIG_PCI
  55. extern u8 _tile_readb(unsigned long addr);
  56. extern u16 _tile_readw(unsigned long addr);
  57. extern u32 _tile_readl(unsigned long addr);
  58. extern u64 _tile_readq(unsigned long addr);
  59. extern void _tile_writeb(u8 val, unsigned long addr);
  60. extern void _tile_writew(u16 val, unsigned long addr);
  61. extern void _tile_writel(u32 val, unsigned long addr);
  62. extern void _tile_writeq(u64 val, unsigned long addr);
  63. #else
  64. /*
  65. * The Tile architecture does not support IOMEM unless PCI is enabled.
  66. * Unfortunately we can't yet simply not declare these methods,
  67. * since some generic code that compiles into the kernel, but
  68. * we never run, uses them unconditionally.
  69. */
  70. static inline int iomem_panic(void)
  71. {
  72. panic("readb/writeb and friends do not exist on tile without PCI");
  73. return 0;
  74. }
  75. static inline u8 _tile_readb(unsigned long addr)
  76. {
  77. return iomem_panic();
  78. }
  79. static inline u16 _tile_readw(unsigned long addr)
  80. {
  81. return iomem_panic();
  82. }
  83. static inline u32 _tile_readl(unsigned long addr)
  84. {
  85. return iomem_panic();
  86. }
  87. static inline u64 _tile_readq(unsigned long addr)
  88. {
  89. return iomem_panic();
  90. }
  91. static inline void _tile_writeb(u8 val, unsigned long addr)
  92. {
  93. iomem_panic();
  94. }
  95. static inline void _tile_writew(u16 val, unsigned long addr)
  96. {
  97. iomem_panic();
  98. }
  99. static inline void _tile_writel(u32 val, unsigned long addr)
  100. {
  101. iomem_panic();
  102. }
  103. static inline void _tile_writeq(u64 val, unsigned long addr)
  104. {
  105. iomem_panic();
  106. }
  107. #endif
  108. #define readb(addr) _tile_readb((unsigned long)addr)
  109. #define readw(addr) _tile_readw((unsigned long)addr)
  110. #define readl(addr) _tile_readl((unsigned long)addr)
  111. #define readq(addr) _tile_readq((unsigned long)addr)
  112. #define writeb(val, addr) _tile_writeb(val, (unsigned long)addr)
  113. #define writew(val, addr) _tile_writew(val, (unsigned long)addr)
  114. #define writel(val, addr) _tile_writel(val, (unsigned long)addr)
  115. #define writeq(val, addr) _tile_writeq(val, (unsigned long)addr)
  116. #define __raw_readb readb
  117. #define __raw_readw readw
  118. #define __raw_readl readl
  119. #define __raw_readq readq
  120. #define __raw_writeb writeb
  121. #define __raw_writew writew
  122. #define __raw_writel writel
  123. #define __raw_writeq writeq
  124. #define readb_relaxed readb
  125. #define readw_relaxed readw
  126. #define readl_relaxed readl
  127. #define readq_relaxed readq
  128. #define ioread8 readb
  129. #define ioread16 readw
  130. #define ioread32 readl
  131. #define ioread64 readq
  132. #define iowrite8 writeb
  133. #define iowrite16 writew
  134. #define iowrite32 writel
  135. #define iowrite64 writeq
  136. static inline void memset_io(void *dst, int val, size_t len)
  137. {
  138. int x;
  139. BUG_ON((unsigned long)dst & 0x3);
  140. val = (val & 0xff) * 0x01010101;
  141. for (x = 0; x < len; x += 4)
  142. writel(val, dst + x);
  143. }
  144. static inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
  145. size_t len)
  146. {
  147. int x;
  148. BUG_ON((unsigned long)src & 0x3);
  149. for (x = 0; x < len; x += 4)
  150. *(u32 *)(dst + x) = readl(src + x);
  151. }
  152. static inline void memcpy_toio(volatile void __iomem *dst, const void *src,
  153. size_t len)
  154. {
  155. int x;
  156. BUG_ON((unsigned long)dst & 0x3);
  157. for (x = 0; x < len; x += 4)
  158. writel(*(u32 *)(src + x), dst + x);
  159. }
  160. /*
  161. * The Tile architecture does not support IOPORT, even with PCI.
  162. * Unfortunately we can't yet simply not declare these methods,
  163. * since some generic code that compiles into the kernel, but
  164. * we never run, uses them unconditionally.
  165. */
  166. static inline long ioport_panic(void)
  167. {
  168. panic("inb/outb and friends do not exist on tile");
  169. return 0;
  170. }
  171. static inline void __iomem *ioport_map(unsigned long port, unsigned int len)
  172. {
  173. pr_info("ioport_map: mapping IO resources is unsupported on tile.\n");
  174. return NULL;
  175. }
  176. static inline void ioport_unmap(void __iomem *addr)
  177. {
  178. ioport_panic();
  179. }
  180. static inline u8 inb(unsigned long addr)
  181. {
  182. return ioport_panic();
  183. }
  184. static inline u16 inw(unsigned long addr)
  185. {
  186. return ioport_panic();
  187. }
  188. static inline u32 inl(unsigned long addr)
  189. {
  190. return ioport_panic();
  191. }
  192. static inline void outb(u8 b, unsigned long addr)
  193. {
  194. ioport_panic();
  195. }
  196. static inline void outw(u16 b, unsigned long addr)
  197. {
  198. ioport_panic();
  199. }
  200. static inline void outl(u32 b, unsigned long addr)
  201. {
  202. ioport_panic();
  203. }
  204. #define inb_p(addr) inb(addr)
  205. #define inw_p(addr) inw(addr)
  206. #define inl_p(addr) inl(addr)
  207. #define outb_p(x, addr) outb((x), (addr))
  208. #define outw_p(x, addr) outw((x), (addr))
  209. #define outl_p(x, addr) outl((x), (addr))
  210. static inline void insb(unsigned long addr, void *buffer, int count)
  211. {
  212. ioport_panic();
  213. }
  214. static inline void insw(unsigned long addr, void *buffer, int count)
  215. {
  216. ioport_panic();
  217. }
  218. static inline void insl(unsigned long addr, void *buffer, int count)
  219. {
  220. ioport_panic();
  221. }
  222. static inline void outsb(unsigned long addr, const void *buffer, int count)
  223. {
  224. ioport_panic();
  225. }
  226. static inline void outsw(unsigned long addr, const void *buffer, int count)
  227. {
  228. ioport_panic();
  229. }
  230. static inline void outsl(unsigned long addr, const void *buffer, int count)
  231. {
  232. ioport_panic();
  233. }
  234. #define ioread16be(addr) be16_to_cpu(ioread16(addr))
  235. #define ioread32be(addr) be32_to_cpu(ioread32(addr))
  236. #define iowrite16be(v, addr) iowrite16(be16_to_cpu(v), (addr))
  237. #define iowrite32be(v, addr) iowrite32(be32_to_cpu(v), (addr))
  238. #define ioread8_rep(p, dst, count) \
  239. insb((unsigned long) (p), (dst), (count))
  240. #define ioread16_rep(p, dst, count) \
  241. insw((unsigned long) (p), (dst), (count))
  242. #define ioread32_rep(p, dst, count) \
  243. insl((unsigned long) (p), (dst), (count))
  244. #define iowrite8_rep(p, src, count) \
  245. outsb((unsigned long) (p), (src), (count))
  246. #define iowrite16_rep(p, src, count) \
  247. outsw((unsigned long) (p), (src), (count))
  248. #define iowrite32_rep(p, src, count) \
  249. outsl((unsigned long) (p), (src), (count))
  250. #define virt_to_bus virt_to_phys
  251. #define bus_to_virt phys_to_virt
  252. #endif /* _ASM_TILE_IO_H */