io_32.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #ifndef __SPARC_IO_H
  2. #define __SPARC_IO_H
  3. #include <linux/kernel.h>
  4. #include <linux/types.h>
  5. #include <linux/ioport.h> /* struct resource */
  6. #include <asm/page.h> /* IO address mapping routines need this */
  7. #include <asm/system.h>
  8. #define page_to_phys(page) (((page) - mem_map) << PAGE_SHIFT)
  9. static inline u32 flip_dword (u32 l)
  10. {
  11. return ((l&0xff)<<24) | (((l>>8)&0xff)<<16) | (((l>>16)&0xff)<<8)| ((l>>24)&0xff);
  12. }
  13. static inline u16 flip_word (u16 w)
  14. {
  15. return ((w&0xff) << 8) | ((w>>8)&0xff);
  16. }
  17. #define mmiowb()
  18. /*
  19. * Memory mapped I/O to PCI
  20. */
  21. static inline u8 __raw_readb(const volatile void __iomem *addr)
  22. {
  23. return *(__force volatile u8 *)addr;
  24. }
  25. static inline u16 __raw_readw(const volatile void __iomem *addr)
  26. {
  27. return *(__force volatile u16 *)addr;
  28. }
  29. static inline u32 __raw_readl(const volatile void __iomem *addr)
  30. {
  31. return *(__force volatile u32 *)addr;
  32. }
  33. static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
  34. {
  35. *(__force volatile u8 *)addr = b;
  36. }
  37. static inline void __raw_writew(u16 w, volatile void __iomem *addr)
  38. {
  39. *(__force volatile u16 *)addr = w;
  40. }
  41. static inline void __raw_writel(u32 l, volatile void __iomem *addr)
  42. {
  43. *(__force volatile u32 *)addr = l;
  44. }
  45. static inline u8 __readb(const volatile void __iomem *addr)
  46. {
  47. return *(__force volatile u8 *)addr;
  48. }
  49. static inline u16 __readw(const volatile void __iomem *addr)
  50. {
  51. return flip_word(*(__force volatile u16 *)addr);
  52. }
  53. static inline u32 __readl(const volatile void __iomem *addr)
  54. {
  55. return flip_dword(*(__force volatile u32 *)addr);
  56. }
  57. static inline void __writeb(u8 b, volatile void __iomem *addr)
  58. {
  59. *(__force volatile u8 *)addr = b;
  60. }
  61. static inline void __writew(u16 w, volatile void __iomem *addr)
  62. {
  63. *(__force volatile u16 *)addr = flip_word(w);
  64. }
  65. static inline void __writel(u32 l, volatile void __iomem *addr)
  66. {
  67. *(__force volatile u32 *)addr = flip_dword(l);
  68. }
  69. #define readb(__addr) __readb(__addr)
  70. #define readw(__addr) __readw(__addr)
  71. #define readl(__addr) __readl(__addr)
  72. #define readb_relaxed(__addr) readb(__addr)
  73. #define readw_relaxed(__addr) readw(__addr)
  74. #define readl_relaxed(__addr) readl(__addr)
  75. #define writeb(__b, __addr) __writeb((__b),(__addr))
  76. #define writew(__w, __addr) __writew((__w),(__addr))
  77. #define writel(__l, __addr) __writel((__l),(__addr))
  78. /*
  79. * I/O space operations
  80. *
  81. * Arrangement on a Sun is somewhat complicated.
  82. *
  83. * First of all, we want to use standard Linux drivers
  84. * for keyboard, PC serial, etc. These drivers think
  85. * they access I/O space and use inb/outb.
  86. * On the other hand, EBus bridge accepts PCI *memory*
  87. * cycles and converts them into ISA *I/O* cycles.
  88. * Ergo, we want inb & outb to generate PCI memory cycles.
  89. *
  90. * If we want to issue PCI *I/O* cycles, we do this
  91. * with a low 64K fixed window in PCIC. This window gets
  92. * mapped somewhere into virtual kernel space and we
  93. * can use inb/outb again.
  94. */
  95. #define inb_local(__addr) __readb((void __iomem *)(unsigned long)(__addr))
  96. #define inb(__addr) __readb((void __iomem *)(unsigned long)(__addr))
  97. #define inw(__addr) __readw((void __iomem *)(unsigned long)(__addr))
  98. #define inl(__addr) __readl((void __iomem *)(unsigned long)(__addr))
  99. #define outb_local(__b, __addr) __writeb(__b, (void __iomem *)(unsigned long)(__addr))
  100. #define outb(__b, __addr) __writeb(__b, (void __iomem *)(unsigned long)(__addr))
  101. #define outw(__w, __addr) __writew(__w, (void __iomem *)(unsigned long)(__addr))
  102. #define outl(__l, __addr) __writel(__l, (void __iomem *)(unsigned long)(__addr))
  103. #define inb_p(__addr) inb(__addr)
  104. #define outb_p(__b, __addr) outb(__b, __addr)
  105. #define inw_p(__addr) inw(__addr)
  106. #define outw_p(__w, __addr) outw(__w, __addr)
  107. #define inl_p(__addr) inl(__addr)
  108. #define outl_p(__l, __addr) outl(__l, __addr)
  109. void outsb(unsigned long addr, const void *src, unsigned long cnt);
  110. void outsw(unsigned long addr, const void *src, unsigned long cnt);
  111. void outsl(unsigned long addr, const void *src, unsigned long cnt);
  112. void insb(unsigned long addr, void *dst, unsigned long count);
  113. void insw(unsigned long addr, void *dst, unsigned long count);
  114. void insl(unsigned long addr, void *dst, unsigned long count);
  115. #define IO_SPACE_LIMIT 0xffffffff
  116. /*
  117. * SBus accessors.
  118. *
  119. * SBus has only one, memory mapped, I/O space.
  120. * We do not need to flip bytes for SBus of course.
  121. */
  122. static inline u8 _sbus_readb(const volatile void __iomem *addr)
  123. {
  124. return *(__force volatile u8 *)addr;
  125. }
  126. static inline u16 _sbus_readw(const volatile void __iomem *addr)
  127. {
  128. return *(__force volatile u16 *)addr;
  129. }
  130. static inline u32 _sbus_readl(const volatile void __iomem *addr)
  131. {
  132. return *(__force volatile u32 *)addr;
  133. }
  134. static inline void _sbus_writeb(u8 b, volatile void __iomem *addr)
  135. {
  136. *(__force volatile u8 *)addr = b;
  137. }
  138. static inline void _sbus_writew(u16 w, volatile void __iomem *addr)
  139. {
  140. *(__force volatile u16 *)addr = w;
  141. }
  142. static inline void _sbus_writel(u32 l, volatile void __iomem *addr)
  143. {
  144. *(__force volatile u32 *)addr = l;
  145. }
  146. /*
  147. * The only reason for #define's is to hide casts to unsigned long.
  148. */
  149. #define sbus_readb(__addr) _sbus_readb(__addr)
  150. #define sbus_readw(__addr) _sbus_readw(__addr)
  151. #define sbus_readl(__addr) _sbus_readl(__addr)
  152. #define sbus_writeb(__b, __addr) _sbus_writeb(__b, __addr)
  153. #define sbus_writew(__w, __addr) _sbus_writew(__w, __addr)
  154. #define sbus_writel(__l, __addr) _sbus_writel(__l, __addr)
  155. static inline void sbus_memset_io(volatile void __iomem *__dst, int c, __kernel_size_t n)
  156. {
  157. while(n--) {
  158. sbus_writeb(c, __dst);
  159. __dst++;
  160. }
  161. }
  162. static inline void
  163. _memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
  164. {
  165. volatile void __iomem *d = dst;
  166. while (n--) {
  167. writeb(c, d);
  168. d++;
  169. }
  170. }
  171. #define memset_io(d,c,sz) _memset_io(d,c,sz)
  172. static inline void
  173. _memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
  174. {
  175. char *d = dst;
  176. while (n--) {
  177. char tmp = readb(src);
  178. *d++ = tmp;
  179. src++;
  180. }
  181. }
  182. #define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
  183. static inline void
  184. _memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n)
  185. {
  186. const char *s = src;
  187. volatile void __iomem *d = dst;
  188. while (n--) {
  189. char tmp = *s++;
  190. writeb(tmp, d);
  191. d++;
  192. }
  193. }
  194. #define memcpy_toio(d,s,sz) _memcpy_toio(d,s,sz)
  195. #ifdef __KERNEL__
  196. /*
  197. * Bus number may be embedded in the higher bits of the physical address.
  198. * This is why we have no bus number argument to ioremap().
  199. */
  200. extern void __iomem *ioremap(unsigned long offset, unsigned long size);
  201. #define ioremap_nocache(X,Y) ioremap((X),(Y))
  202. #define ioremap_wc(X,Y) ioremap((X),(Y))
  203. extern void iounmap(volatile void __iomem *addr);
  204. #define ioread8(X) readb(X)
  205. #define ioread16(X) readw(X)
  206. #define ioread32(X) readl(X)
  207. #define iowrite8(val,X) writeb(val,X)
  208. #define iowrite16(val,X) writew(val,X)
  209. #define iowrite32(val,X) writel(val,X)
  210. static inline void ioread8_rep(void __iomem *port, void *buf, unsigned long count)
  211. {
  212. insb((unsigned long __force)port, buf, count);
  213. }
  214. static inline void ioread16_rep(void __iomem *port, void *buf, unsigned long count)
  215. {
  216. insw((unsigned long __force)port, buf, count);
  217. }
  218. static inline void ioread32_rep(void __iomem *port, void *buf, unsigned long count)
  219. {
  220. insl((unsigned long __force)port, buf, count);
  221. }
  222. static inline void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count)
  223. {
  224. outsb((unsigned long __force)port, buf, count);
  225. }
  226. static inline void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count)
  227. {
  228. outsw((unsigned long __force)port, buf, count);
  229. }
  230. static inline void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count)
  231. {
  232. outsl((unsigned long __force)port, buf, count);
  233. }
  234. /* Create a virtual mapping cookie for an IO port range */
  235. extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
  236. extern void ioport_unmap(void __iomem *);
  237. /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
  238. struct pci_dev;
  239. extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
  240. extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
  241. /*
  242. * At the moment, we do not use CMOS_READ anywhere outside of rtc.c,
  243. * so rtc_port is static in it. This should not change unless a new
  244. * hardware pops up.
  245. */
  246. #define RTC_PORT(x) (rtc_port + (x))
  247. #define RTC_ALWAYS_BCD 0
  248. static inline int sbus_can_dma_64bit(void)
  249. {
  250. return 0; /* actually, sparc_cpu_model==sun4d */
  251. }
  252. static inline int sbus_can_burst64(void)
  253. {
  254. return 0; /* actually, sparc_cpu_model==sun4d */
  255. }
  256. struct device;
  257. extern void sbus_set_sbus64(struct device *, int);
  258. #endif
  259. #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
  260. /*
  261. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  262. * access
  263. */
  264. #define xlate_dev_mem_ptr(p) __va(p)
  265. /*
  266. * Convert a virtual cached pointer to an uncached pointer
  267. */
  268. #define xlate_dev_kmem_ptr(p) p
  269. #endif /* !(__SPARC_IO_H) */