io_64.h 11 KB

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