jensen.h 8.3 KB

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