io_32.h 9.3 KB

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