io_64.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. #ifndef __SPARC64_IO_H
  2. #define __SPARC64_IO_H
  3. #include <linux/kernel.h>
  4. #include <linux/compiler.h>
  5. #include <linux/types.h>
  6. #include <asm/page.h> /* IO address mapping routines need this */
  7. #include <asm/asi.h>
  8. #include <asm-generic/pci_iomap.h>
  9. /* BIO layer definitions. */
  10. extern unsigned long kern_base, kern_size;
  11. /* __raw_{read,write}{b,w,l,q} uses direct access.
  12. * Access the memory as big endian bypassing the cache
  13. * by using ASI_PHYS_BYPASS_EC_E
  14. */
  15. #define __raw_readb __raw_readb
  16. static inline u8 __raw_readb(const volatile void __iomem *addr)
  17. {
  18. u8 ret;
  19. __asm__ __volatile__("lduba\t[%1] %2, %0\t/* pci_raw_readb */"
  20. : "=r" (ret)
  21. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
  22. return ret;
  23. }
  24. #define __raw_readw __raw_readw
  25. static inline u16 __raw_readw(const volatile void __iomem *addr)
  26. {
  27. u16 ret;
  28. __asm__ __volatile__("lduha\t[%1] %2, %0\t/* pci_raw_readw */"
  29. : "=r" (ret)
  30. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
  31. return ret;
  32. }
  33. #define __raw_readl __raw_readl
  34. static inline u32 __raw_readl(const volatile void __iomem *addr)
  35. {
  36. u32 ret;
  37. __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* pci_raw_readl */"
  38. : "=r" (ret)
  39. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
  40. return ret;
  41. }
  42. #define __raw_readq __raw_readq
  43. static inline u64 __raw_readq(const volatile void __iomem *addr)
  44. {
  45. u64 ret;
  46. __asm__ __volatile__("ldxa\t[%1] %2, %0\t/* pci_raw_readq */"
  47. : "=r" (ret)
  48. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
  49. return ret;
  50. }
  51. #define __raw_writeb __raw_writeb
  52. static inline void __raw_writeb(u8 b, const volatile void __iomem *addr)
  53. {
  54. __asm__ __volatile__("stba\t%r0, [%1] %2\t/* pci_raw_writeb */"
  55. : /* no outputs */
  56. : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
  57. }
  58. #define __raw_writew __raw_writew
  59. static inline void __raw_writew(u16 w, const volatile void __iomem *addr)
  60. {
  61. __asm__ __volatile__("stha\t%r0, [%1] %2\t/* pci_raw_writew */"
  62. : /* no outputs */
  63. : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
  64. }
  65. #define __raw_writel __raw_writel
  66. static inline void __raw_writel(u32 l, const volatile void __iomem *addr)
  67. {
  68. __asm__ __volatile__("stwa\t%r0, [%1] %2\t/* pci_raw_writel */"
  69. : /* no outputs */
  70. : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
  71. }
  72. #define __raw_writeq __raw_writeq
  73. static inline void __raw_writeq(u64 q, const volatile void __iomem *addr)
  74. {
  75. __asm__ __volatile__("stxa\t%r0, [%1] %2\t/* pci_raw_writeq */"
  76. : /* no outputs */
  77. : "Jr" (q), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
  78. }
  79. /* Memory functions, same as I/O accesses on Ultra.
  80. * Access memory as little endian bypassing
  81. * the cache by using ASI_PHYS_BYPASS_EC_E_L
  82. */
  83. #define readb readb
  84. #define readb_relaxed readb
  85. static inline u8 readb(const volatile void __iomem *addr)
  86. { u8 ret;
  87. __asm__ __volatile__("lduba\t[%1] %2, %0\t/* pci_readb */"
  88. : "=r" (ret)
  89. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  90. : "memory");
  91. return ret;
  92. }
  93. #define readw readw
  94. #define readw_relaxed readw
  95. static inline u16 readw(const volatile void __iomem *addr)
  96. { u16 ret;
  97. __asm__ __volatile__("lduha\t[%1] %2, %0\t/* pci_readw */"
  98. : "=r" (ret)
  99. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  100. : "memory");
  101. return ret;
  102. }
  103. #define readl readl
  104. #define readl_relaxed readl
  105. static inline u32 readl(const volatile void __iomem *addr)
  106. { u32 ret;
  107. __asm__ __volatile__("lduwa\t[%1] %2, %0\t/* pci_readl */"
  108. : "=r" (ret)
  109. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  110. : "memory");
  111. return ret;
  112. }
  113. #define readq readq
  114. #define readq_relaxed readq
  115. static inline u64 readq(const volatile void __iomem *addr)
  116. { u64 ret;
  117. __asm__ __volatile__("ldxa\t[%1] %2, %0\t/* pci_readq */"
  118. : "=r" (ret)
  119. : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  120. : "memory");
  121. return ret;
  122. }
  123. #define writeb writeb
  124. #define writeb_relaxed writeb
  125. static inline void writeb(u8 b, volatile void __iomem *addr)
  126. {
  127. __asm__ __volatile__("stba\t%r0, [%1] %2\t/* pci_writeb */"
  128. : /* no outputs */
  129. : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  130. : "memory");
  131. }
  132. #define writew writew
  133. #define writew_relaxed writew
  134. static inline void writew(u16 w, volatile void __iomem *addr)
  135. {
  136. __asm__ __volatile__("stha\t%r0, [%1] %2\t/* pci_writew */"
  137. : /* no outputs */
  138. : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  139. : "memory");
  140. }
  141. #define writel writel
  142. #define writel_relaxed writel
  143. static inline void writel(u32 l, volatile void __iomem *addr)
  144. {
  145. __asm__ __volatile__("stwa\t%r0, [%1] %2\t/* pci_writel */"
  146. : /* no outputs */
  147. : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  148. : "memory");
  149. }
  150. #define writeq writeq
  151. #define writeq_relaxed writeq
  152. static inline void writeq(u64 q, volatile void __iomem *addr)
  153. {
  154. __asm__ __volatile__("stxa\t%r0, [%1] %2\t/* pci_writeq */"
  155. : /* no outputs */
  156. : "Jr" (q), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
  157. : "memory");
  158. }
  159. #define inb inb
  160. static inline u8 inb(unsigned long addr)
  161. {
  162. return readb((volatile void __iomem *)addr);
  163. }
  164. #define inw inw
  165. static inline u16 inw(unsigned long addr)
  166. {
  167. return readw((volatile void __iomem *)addr);
  168. }
  169. #define inl inl
  170. static inline u32 inl(unsigned long addr)
  171. {
  172. return readl((volatile void __iomem *)addr);
  173. }
  174. #define outb outb
  175. static inline void outb(u8 b, unsigned long addr)
  176. {
  177. writeb(b, (volatile void __iomem *)addr);
  178. }
  179. #define outw outw
  180. static inline void outw(u16 w, unsigned long addr)
  181. {
  182. writew(w, (volatile void __iomem *)addr);
  183. }
  184. #define outl outl
  185. static inline void outl(u32 l, unsigned long addr)
  186. {
  187. writel(l, (volatile void __iomem *)addr);
  188. }
  189. #define inb_p(__addr) inb(__addr)
  190. #define outb_p(__b, __addr) outb(__b, __addr)
  191. #define inw_p(__addr) inw(__addr)
  192. #define outw_p(__w, __addr) outw(__w, __addr)
  193. #define inl_p(__addr) inl(__addr)
  194. #define outl_p(__l, __addr) outl(__l, __addr)
  195. void outsb(unsigned long, const void *, unsigned long);
  196. void outsw(unsigned long, const void *, unsigned long);
  197. void outsl(unsigned long, const void *, unsigned long);
  198. void insb(unsigned long, void *, unsigned long);
  199. void insw(unsigned long, void *, unsigned long);
  200. void insl(unsigned long, void *, unsigned long);
  201. static inline void ioread8_rep(void __iomem *port, void *buf, unsigned long count)
  202. {
  203. insb((unsigned long __force)port, buf, count);
  204. }
  205. static inline void ioread16_rep(void __iomem *port, void *buf, unsigned long count)
  206. {
  207. insw((unsigned long __force)port, buf, count);
  208. }
  209. static inline void ioread32_rep(void __iomem *port, void *buf, unsigned long count)
  210. {
  211. insl((unsigned long __force)port, buf, count);
  212. }
  213. static inline void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count)
  214. {
  215. outsb((unsigned long __force)port, buf, count);
  216. }
  217. static inline void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count)
  218. {
  219. outsw((unsigned long __force)port, buf, count);
  220. }
  221. static inline void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count)
  222. {
  223. outsl((unsigned long __force)port, buf, count);
  224. }
  225. /* Valid I/O Space regions are anywhere, because each PCI bus supported
  226. * can live in an arbitrary area of the physical address range.
  227. */
  228. #define IO_SPACE_LIMIT 0xffffffffffffffffUL
  229. /* Now, SBUS variants, only difference from PCI is that we do
  230. * not use little-endian ASIs.
  231. */
  232. static inline u8 sbus_readb(const volatile void __iomem *addr)
  233. {
  234. return __raw_readb(addr);
  235. }
  236. static inline u16 sbus_readw(const volatile void __iomem *addr)
  237. {
  238. return __raw_readw(addr);
  239. }
  240. static inline u32 sbus_readl(const volatile void __iomem *addr)
  241. {
  242. return __raw_readl(addr);
  243. }
  244. static inline u64 sbus_readq(const volatile void __iomem *addr)
  245. {
  246. return __raw_readq(addr);
  247. }
  248. static inline void sbus_writeb(u8 b, volatile void __iomem *addr)
  249. {
  250. __raw_writeb(b, addr);
  251. }
  252. static inline void sbus_writew(u16 w, volatile void __iomem *addr)
  253. {
  254. __raw_writew(w, addr);
  255. }
  256. static inline void sbus_writel(u32 l, volatile void __iomem *addr)
  257. {
  258. __raw_writel(l, addr);
  259. }
  260. static inline void sbus_writeq(u64 q, volatile void __iomem *addr)
  261. {
  262. __raw_writeq(q, addr);
  263. }
  264. static inline void sbus_memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
  265. {
  266. while(n--) {
  267. sbus_writeb(c, dst);
  268. dst++;
  269. }
  270. }
  271. static inline void memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
  272. {
  273. volatile void __iomem *d = dst;
  274. while (n--) {
  275. writeb(c, d);
  276. d++;
  277. }
  278. }
  279. static inline void sbus_memcpy_fromio(void *dst, const volatile void __iomem *src,
  280. __kernel_size_t n)
  281. {
  282. char *d = dst;
  283. while (n--) {
  284. char tmp = sbus_readb(src);
  285. *d++ = tmp;
  286. src++;
  287. }
  288. }
  289. static inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
  290. __kernel_size_t n)
  291. {
  292. char *d = dst;
  293. while (n--) {
  294. char tmp = readb(src);
  295. *d++ = tmp;
  296. src++;
  297. }
  298. }
  299. static inline void sbus_memcpy_toio(volatile void __iomem *dst, const void *src,
  300. __kernel_size_t n)
  301. {
  302. const char *s = src;
  303. volatile void __iomem *d = dst;
  304. while (n--) {
  305. char tmp = *s++;
  306. sbus_writeb(tmp, d);
  307. d++;
  308. }
  309. }
  310. static inline void memcpy_toio(volatile void __iomem *dst, const void *src,
  311. __kernel_size_t n)
  312. {
  313. const char *s = src;
  314. volatile void __iomem *d = dst;
  315. while (n--) {
  316. char tmp = *s++;
  317. writeb(tmp, d);
  318. d++;
  319. }
  320. }
  321. #define mmiowb()
  322. #ifdef __KERNEL__
  323. /* On sparc64 we have the whole physical IO address space accessible
  324. * using physically addressed loads and stores, so this does nothing.
  325. */
  326. static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
  327. {
  328. return (void __iomem *)offset;
  329. }
  330. #define ioremap_nocache(X,Y) ioremap((X),(Y))
  331. #define ioremap_wc(X,Y) ioremap((X),(Y))
  332. #define ioremap_wt(X,Y) ioremap((X),(Y))
  333. static inline void iounmap(volatile void __iomem *addr)
  334. {
  335. }
  336. #define ioread8 readb
  337. #define ioread16 readw
  338. #define ioread16be __raw_readw
  339. #define ioread32 readl
  340. #define ioread32be __raw_readl
  341. #define iowrite8 writeb
  342. #define iowrite16 writew
  343. #define iowrite16be __raw_writew
  344. #define iowrite32 writel
  345. #define iowrite32be __raw_writel
  346. /* Create a virtual mapping cookie for an IO port range */
  347. void __iomem *ioport_map(unsigned long port, unsigned int nr);
  348. void ioport_unmap(void __iomem *);
  349. /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
  350. struct pci_dev;
  351. void pci_iounmap(struct pci_dev *dev, void __iomem *);
  352. static inline int sbus_can_dma_64bit(void)
  353. {
  354. return 1;
  355. }
  356. static inline int sbus_can_burst64(void)
  357. {
  358. return 1;
  359. }
  360. struct device;
  361. void sbus_set_sbus64(struct device *, int);
  362. /*
  363. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  364. * access
  365. */
  366. #define xlate_dev_mem_ptr(p) __va(p)
  367. /*
  368. * Convert a virtual cached pointer to an uncached pointer
  369. */
  370. #define xlate_dev_kmem_ptr(p) p
  371. #endif
  372. #endif /* !(__SPARC64_IO_H) */