jensen.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ALPHA_JENSEN_H
  3. #define __ALPHA_JENSEN_H
  4. #include <asm/compiler.h>
  5. /*
  6. * Defines for the AlphaPC EISA IO and memory address space.
  7. */
  8. /*
  9. * NOTE! The memory operations do not set any memory barriers, as it's
  10. * not needed for cases like a frame buffer that is essentially memory-like.
  11. * You need to do them by hand if the operations depend on ordering.
  12. *
  13. * Similarly, the port IO operations do a "mb" only after a write operation:
  14. * if an mb is needed before (as in the case of doing memory mapped IO
  15. * first, and then a port IO operation to the same device), it needs to be
  16. * done by hand.
  17. *
  18. * After the above has bitten me 100 times, I'll give up and just do the
  19. * mb all the time, but right now I'm hoping this will work out. Avoiding
  20. * mb's may potentially be a noticeable speed improvement, but I can't
  21. * honestly say I've tested it.
  22. *
  23. * Handling interrupts that need to do mb's to synchronize to non-interrupts
  24. * is another fun race area. Don't do it (because if you do, I'll have to
  25. * do *everything* with interrupts disabled, ugh).
  26. */
  27. /*
  28. * EISA Interrupt Acknowledge address
  29. */
  30. #define EISA_INTA (IDENT_ADDR + 0x100000000UL)
  31. /*
  32. * FEPROM addresses
  33. */
  34. #define EISA_FEPROM0 (IDENT_ADDR + 0x180000000UL)
  35. #define EISA_FEPROM1 (IDENT_ADDR + 0x1A0000000UL)
  36. /*
  37. * VL82C106 base address
  38. */
  39. #define EISA_VL82C106 (IDENT_ADDR + 0x1C0000000UL)
  40. /*
  41. * EISA "Host Address Extension" address (bits 25-31 of the EISA address)
  42. */
  43. #define EISA_HAE (IDENT_ADDR + 0x1D0000000UL)
  44. /*
  45. * "SYSCTL" register address
  46. */
  47. #define EISA_SYSCTL (IDENT_ADDR + 0x1E0000000UL)
  48. /*
  49. * "spare" register address
  50. */
  51. #define EISA_SPARE (IDENT_ADDR + 0x1F0000000UL)
  52. /*
  53. * EISA memory address offset
  54. */
  55. #define EISA_MEM (IDENT_ADDR + 0x200000000UL)
  56. /*
  57. * EISA IO address offset
  58. */
  59. #define EISA_IO (IDENT_ADDR + 0x300000000UL)
  60. #ifdef __KERNEL__
  61. #ifndef __EXTERN_INLINE
  62. #define __EXTERN_INLINE extern inline
  63. #define __IO_EXTERN_INLINE
  64. #endif
  65. /*
  66. * Handle the "host address register". This needs to be set
  67. * to the high 7 bits of the EISA address. This is also needed
  68. * for EISA IO addresses, which are only 16 bits wide (the
  69. * hae needs to be set to 0).
  70. *
  71. * HAE isn't needed for the local IO operations, though.
  72. */
  73. #define JENSEN_HAE_ADDRESS EISA_HAE
  74. #define JENSEN_HAE_MASK 0x1ffffff
  75. __EXTERN_INLINE void jensen_set_hae(unsigned long addr)
  76. {
  77. /* hae on the Jensen is bits 31:25 shifted right */
  78. addr >>= 25;
  79. if (addr != alpha_mv.hae_cache)
  80. set_hae(addr);
  81. }
  82. #define vuip volatile unsigned int *
  83. #define vulp volatile unsigned long *
  84. /*
  85. * IO functions
  86. *
  87. * The "local" functions are those that don't go out to the EISA bus,
  88. * but instead act on the VL82C106 chip directly.. This is mainly the
  89. * keyboard, RTC, printer and first two serial lines..
  90. *
  91. * The local stuff makes for some complications, but it seems to be
  92. * gone in the PCI version. I hope I can get DEC suckered^H^H^H^H^H^H^H^H
  93. * convinced that I need one of the newer machines.
  94. */
  95. __EXTERN_INLINE unsigned int jensen_local_inb(unsigned long addr)
  96. {
  97. return 0xff & *(vuip)((addr << 9) + EISA_VL82C106);
  98. }
  99. __EXTERN_INLINE void jensen_local_outb(u8 b, unsigned long addr)
  100. {
  101. *(vuip)((addr << 9) + EISA_VL82C106) = b;
  102. mb();
  103. }
  104. __EXTERN_INLINE unsigned int jensen_bus_inb(unsigned long addr)
  105. {
  106. long result;
  107. jensen_set_hae(0);
  108. result = *(volatile int *)((addr << 7) + EISA_IO + 0x00);
  109. return __kernel_extbl(result, addr & 3);
  110. }
  111. __EXTERN_INLINE void jensen_bus_outb(u8 b, unsigned long addr)
  112. {
  113. jensen_set_hae(0);
  114. *(vuip)((addr << 7) + EISA_IO + 0x00) = b * 0x01010101;
  115. mb();
  116. }
  117. /*
  118. * It seems gcc is not very good at optimizing away logical
  119. * operations that result in operations across inline functions.
  120. * Which is why this is a macro.
  121. */
  122. #define jensen_is_local(addr) ( \
  123. /* keyboard */ (addr == 0x60 || addr == 0x64) || \
  124. /* RTC */ (addr == 0x170 || addr == 0x171) || \
  125. /* mb COM2 */ (addr >= 0x2f8 && addr <= 0x2ff) || \
  126. /* mb LPT1 */ (addr >= 0x3bc && addr <= 0x3be) || \
  127. /* mb COM2 */ (addr >= 0x3f8 && addr <= 0x3ff))
  128. __EXTERN_INLINE u8 jensen_inb(unsigned long addr)
  129. {
  130. if (jensen_is_local(addr))
  131. return jensen_local_inb(addr);
  132. else
  133. return jensen_bus_inb(addr);
  134. }
  135. __EXTERN_INLINE void jensen_outb(u8 b, unsigned long addr)
  136. {
  137. if (jensen_is_local(addr))
  138. jensen_local_outb(b, addr);
  139. else
  140. jensen_bus_outb(b, addr);
  141. }
  142. __EXTERN_INLINE u16 jensen_inw(unsigned long addr)
  143. {
  144. long result;
  145. jensen_set_hae(0);
  146. result = *(volatile int *) ((addr << 7) + EISA_IO + 0x20);
  147. result >>= (addr & 3) * 8;
  148. return 0xffffUL & result;
  149. }
  150. __EXTERN_INLINE u32 jensen_inl(unsigned long addr)
  151. {
  152. jensen_set_hae(0);
  153. return *(vuip) ((addr << 7) + EISA_IO + 0x60);
  154. }
  155. __EXTERN_INLINE u64 jensen_inq(unsigned long addr)
  156. {
  157. jensen_set_hae(0);
  158. return *(vulp) ((addr << 7) + EISA_IO + 0x60);
  159. }
  160. __EXTERN_INLINE void jensen_outw(u16 b, unsigned long addr)
  161. {
  162. jensen_set_hae(0);
  163. *(vuip) ((addr << 7) + EISA_IO + 0x20) = b * 0x00010001;
  164. mb();
  165. }
  166. __EXTERN_INLINE void jensen_outl(u32 b, unsigned long addr)
  167. {
  168. jensen_set_hae(0);
  169. *(vuip) ((addr << 7) + EISA_IO + 0x60) = b;
  170. mb();
  171. }
  172. __EXTERN_INLINE void jensen_outq(u64 b, unsigned long addr)
  173. {
  174. jensen_set_hae(0);
  175. *(vulp) ((addr << 7) + EISA_IO + 0x60) = b;
  176. mb();
  177. }
  178. /*
  179. * Memory functions.
  180. */
  181. __EXTERN_INLINE u8 jensen_readb(const volatile void __iomem *xaddr)
  182. {
  183. unsigned long addr = (unsigned long) xaddr;
  184. long result;
  185. jensen_set_hae(addr);
  186. addr &= JENSEN_HAE_MASK;
  187. result = *(volatile int *) ((addr << 7) + EISA_MEM + 0x00);
  188. result >>= (addr & 3) * 8;
  189. return 0xffUL & result;
  190. }
  191. __EXTERN_INLINE u16 jensen_readw(const volatile void __iomem *xaddr)
  192. {
  193. unsigned long addr = (unsigned long) xaddr;
  194. long result;
  195. jensen_set_hae(addr);
  196. addr &= JENSEN_HAE_MASK;
  197. result = *(volatile int *) ((addr << 7) + EISA_MEM + 0x20);
  198. result >>= (addr & 3) * 8;
  199. return 0xffffUL & result;
  200. }
  201. __EXTERN_INLINE u32 jensen_readl(const volatile void __iomem *xaddr)
  202. {
  203. unsigned long addr = (unsigned long) xaddr;
  204. jensen_set_hae(addr);
  205. addr &= JENSEN_HAE_MASK;
  206. return *(vuip) ((addr << 7) + EISA_MEM + 0x60);
  207. }
  208. __EXTERN_INLINE u64 jensen_readq(const volatile void __iomem *xaddr)
  209. {
  210. unsigned long addr = (unsigned long) xaddr;
  211. unsigned long r0, r1;
  212. jensen_set_hae(addr);
  213. addr &= JENSEN_HAE_MASK;
  214. addr = (addr << 7) + EISA_MEM + 0x60;
  215. r0 = *(vuip) (addr);
  216. r1 = *(vuip) (addr + (4 << 7));
  217. return r1 << 32 | r0;
  218. }
  219. __EXTERN_INLINE void jensen_writeb(u8 b, volatile void __iomem *xaddr)
  220. {
  221. unsigned long addr = (unsigned long) xaddr;
  222. jensen_set_hae(addr);
  223. addr &= JENSEN_HAE_MASK;
  224. *(vuip) ((addr << 7) + EISA_MEM + 0x00) = b * 0x01010101;
  225. }
  226. __EXTERN_INLINE void jensen_writew(u16 b, volatile void __iomem *xaddr)
  227. {
  228. unsigned long addr = (unsigned long) xaddr;
  229. jensen_set_hae(addr);
  230. addr &= JENSEN_HAE_MASK;
  231. *(vuip) ((addr << 7) + EISA_MEM + 0x20) = b * 0x00010001;
  232. }
  233. __EXTERN_INLINE void jensen_writel(u32 b, volatile void __iomem *xaddr)
  234. {
  235. unsigned long addr = (unsigned long) xaddr;
  236. jensen_set_hae(addr);
  237. addr &= JENSEN_HAE_MASK;
  238. *(vuip) ((addr << 7) + EISA_MEM + 0x60) = b;
  239. }
  240. __EXTERN_INLINE void jensen_writeq(u64 b, volatile void __iomem *xaddr)
  241. {
  242. unsigned long addr = (unsigned long) xaddr;
  243. jensen_set_hae(addr);
  244. addr &= JENSEN_HAE_MASK;
  245. addr = (addr << 7) + EISA_MEM + 0x60;
  246. *(vuip) (addr) = b;
  247. *(vuip) (addr + (4 << 7)) = b >> 32;
  248. }
  249. __EXTERN_INLINE void __iomem *jensen_ioportmap(unsigned long addr)
  250. {
  251. return (void __iomem *)addr;
  252. }
  253. __EXTERN_INLINE void __iomem *jensen_ioremap(unsigned long addr,
  254. unsigned long size)
  255. {
  256. return (void __iomem *)(addr + 0x100000000ul);
  257. }
  258. __EXTERN_INLINE int jensen_is_ioaddr(unsigned long addr)
  259. {
  260. return (long)addr >= 0;
  261. }
  262. __EXTERN_INLINE int jensen_is_mmio(const volatile void __iomem *addr)
  263. {
  264. return (unsigned long)addr >= 0x100000000ul;
  265. }
  266. /* New-style ioread interface. All the routines are so ugly for Jensen
  267. that it doesn't make sense to merge them. */
  268. #define IOPORT(OS, NS) \
  269. __EXTERN_INLINE u##NS jensen_ioread##NS(const void __iomem *xaddr) \
  270. { \
  271. if (jensen_is_mmio(xaddr)) \
  272. return jensen_read##OS(xaddr - 0x100000000ul); \
  273. else \
  274. return jensen_in##OS((unsigned long)xaddr); \
  275. } \
  276. __EXTERN_INLINE void jensen_iowrite##NS(u##NS b, void __iomem *xaddr) \
  277. { \
  278. if (jensen_is_mmio(xaddr)) \
  279. jensen_write##OS(b, xaddr - 0x100000000ul); \
  280. else \
  281. jensen_out##OS(b, (unsigned long)xaddr); \
  282. }
  283. IOPORT(b, 8)
  284. IOPORT(w, 16)
  285. IOPORT(l, 32)
  286. IOPORT(q, 64)
  287. #undef IOPORT
  288. #undef vuip
  289. #undef vulp
  290. #undef __IO_PREFIX
  291. #define __IO_PREFIX jensen
  292. #define jensen_trivial_rw_bw 0
  293. #define jensen_trivial_rw_lq 0
  294. #define jensen_trivial_io_bw 0
  295. #define jensen_trivial_io_lq 0
  296. #define jensen_trivial_iounmap 1
  297. #include <asm/io_trivial.h>
  298. #ifdef __IO_EXTERN_INLINE
  299. #undef __EXTERN_INLINE
  300. #undef __IO_EXTERN_INLINE
  301. #endif
  302. #endif /* __KERNEL__ */
  303. #endif /* __ALPHA_JENSEN_H */