core_lca.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ALPHA_LCA__H__
  3. #define __ALPHA_LCA__H__
  4. #include <asm/compiler.h>
  5. #include <asm/mce.h>
  6. /*
  7. * Low Cost Alpha (LCA) definitions (these apply to 21066 and 21068,
  8. * for example).
  9. *
  10. * This file is based on:
  11. *
  12. * DECchip 21066 and DECchip 21068 Alpha AXP Microprocessors
  13. * Hardware Reference Manual; Digital Equipment Corp.; May 1994;
  14. * Maynard, MA; Order Number: EC-N2681-71.
  15. */
  16. /*
  17. * NOTE: The LCA uses a Host Address Extension (HAE) register to access
  18. * PCI addresses that are beyond the first 27 bits of address
  19. * space. Updating the HAE requires an external cycle (and
  20. * a memory barrier), which tends to be slow. Instead of updating
  21. * it on each sparse memory access, we keep the current HAE value
  22. * cached in variable cache_hae. Only if the cached HAE differs
  23. * from the desired HAE value do we actually updated HAE register.
  24. * The HAE register is preserved by the interrupt handler entry/exit
  25. * code, so this scheme works even in the presence of interrupts.
  26. *
  27. * Dense memory space doesn't require the HAE, but is restricted to
  28. * aligned 32 and 64 bit accesses. Special Cycle and Interrupt
  29. * Acknowledge cycles may also require the use of the HAE. The LCA
  30. * limits I/O address space to the bottom 24 bits of address space,
  31. * but this easily covers the 16 bit ISA I/O address space.
  32. */
  33. /*
  34. * NOTE 2! The memory operations do not set any memory barriers, as
  35. * it's not needed for cases like a frame buffer that is essentially
  36. * memory-like. You need to do them by hand if the operations depend
  37. * on ordering.
  38. *
  39. * Similarly, the port I/O operations do a "mb" only after a write
  40. * operation: if an mb is needed before (as in the case of doing
  41. * memory mapped I/O first, and then a port I/O operation to the same
  42. * device), it needs to be done by hand.
  43. *
  44. * After the above has bitten me 100 times, I'll give up and just do
  45. * the mb all the time, but right now I'm hoping this will work out.
  46. * Avoiding mb's may potentially be a noticeable speed improvement,
  47. * but I can't honestly say I've tested it.
  48. *
  49. * Handling interrupts that need to do mb's to synchronize to
  50. * non-interrupts is another fun race area. Don't do it (because if
  51. * you do, I'll have to do *everything* with interrupts disabled,
  52. * ugh).
  53. */
  54. /*
  55. * Memory Controller registers:
  56. */
  57. #define LCA_MEM_BCR0 (IDENT_ADDR + 0x120000000UL)
  58. #define LCA_MEM_BCR1 (IDENT_ADDR + 0x120000008UL)
  59. #define LCA_MEM_BCR2 (IDENT_ADDR + 0x120000010UL)
  60. #define LCA_MEM_BCR3 (IDENT_ADDR + 0x120000018UL)
  61. #define LCA_MEM_BMR0 (IDENT_ADDR + 0x120000020UL)
  62. #define LCA_MEM_BMR1 (IDENT_ADDR + 0x120000028UL)
  63. #define LCA_MEM_BMR2 (IDENT_ADDR + 0x120000030UL)
  64. #define LCA_MEM_BMR3 (IDENT_ADDR + 0x120000038UL)
  65. #define LCA_MEM_BTR0 (IDENT_ADDR + 0x120000040UL)
  66. #define LCA_MEM_BTR1 (IDENT_ADDR + 0x120000048UL)
  67. #define LCA_MEM_BTR2 (IDENT_ADDR + 0x120000050UL)
  68. #define LCA_MEM_BTR3 (IDENT_ADDR + 0x120000058UL)
  69. #define LCA_MEM_GTR (IDENT_ADDR + 0x120000060UL)
  70. #define LCA_MEM_ESR (IDENT_ADDR + 0x120000068UL)
  71. #define LCA_MEM_EAR (IDENT_ADDR + 0x120000070UL)
  72. #define LCA_MEM_CAR (IDENT_ADDR + 0x120000078UL)
  73. #define LCA_MEM_VGR (IDENT_ADDR + 0x120000080UL)
  74. #define LCA_MEM_PLM (IDENT_ADDR + 0x120000088UL)
  75. #define LCA_MEM_FOR (IDENT_ADDR + 0x120000090UL)
  76. /*
  77. * I/O Controller registers:
  78. */
  79. #define LCA_IOC_HAE (IDENT_ADDR + 0x180000000UL)
  80. #define LCA_IOC_CONF (IDENT_ADDR + 0x180000020UL)
  81. #define LCA_IOC_STAT0 (IDENT_ADDR + 0x180000040UL)
  82. #define LCA_IOC_STAT1 (IDENT_ADDR + 0x180000060UL)
  83. #define LCA_IOC_TBIA (IDENT_ADDR + 0x180000080UL)
  84. #define LCA_IOC_TB_ENA (IDENT_ADDR + 0x1800000a0UL)
  85. #define LCA_IOC_SFT_RST (IDENT_ADDR + 0x1800000c0UL)
  86. #define LCA_IOC_PAR_DIS (IDENT_ADDR + 0x1800000e0UL)
  87. #define LCA_IOC_W_BASE0 (IDENT_ADDR + 0x180000100UL)
  88. #define LCA_IOC_W_BASE1 (IDENT_ADDR + 0x180000120UL)
  89. #define LCA_IOC_W_MASK0 (IDENT_ADDR + 0x180000140UL)
  90. #define LCA_IOC_W_MASK1 (IDENT_ADDR + 0x180000160UL)
  91. #define LCA_IOC_T_BASE0 (IDENT_ADDR + 0x180000180UL)
  92. #define LCA_IOC_T_BASE1 (IDENT_ADDR + 0x1800001a0UL)
  93. #define LCA_IOC_TB_TAG0 (IDENT_ADDR + 0x188000000UL)
  94. #define LCA_IOC_TB_TAG1 (IDENT_ADDR + 0x188000020UL)
  95. #define LCA_IOC_TB_TAG2 (IDENT_ADDR + 0x188000040UL)
  96. #define LCA_IOC_TB_TAG3 (IDENT_ADDR + 0x188000060UL)
  97. #define LCA_IOC_TB_TAG4 (IDENT_ADDR + 0x188000070UL)
  98. #define LCA_IOC_TB_TAG5 (IDENT_ADDR + 0x1880000a0UL)
  99. #define LCA_IOC_TB_TAG6 (IDENT_ADDR + 0x1880000c0UL)
  100. #define LCA_IOC_TB_TAG7 (IDENT_ADDR + 0x1880000e0UL)
  101. /*
  102. * Memory spaces:
  103. */
  104. #define LCA_IACK_SC (IDENT_ADDR + 0x1a0000000UL)
  105. #define LCA_CONF (IDENT_ADDR + 0x1e0000000UL)
  106. #define LCA_IO (IDENT_ADDR + 0x1c0000000UL)
  107. #define LCA_SPARSE_MEM (IDENT_ADDR + 0x200000000UL)
  108. #define LCA_DENSE_MEM (IDENT_ADDR + 0x300000000UL)
  109. /*
  110. * Bit definitions for I/O Controller status register 0:
  111. */
  112. #define LCA_IOC_STAT0_CMD 0xf
  113. #define LCA_IOC_STAT0_ERR (1<<4)
  114. #define LCA_IOC_STAT0_LOST (1<<5)
  115. #define LCA_IOC_STAT0_THIT (1<<6)
  116. #define LCA_IOC_STAT0_TREF (1<<7)
  117. #define LCA_IOC_STAT0_CODE_SHIFT 8
  118. #define LCA_IOC_STAT0_CODE_MASK 0x7
  119. #define LCA_IOC_STAT0_P_NBR_SHIFT 13
  120. #define LCA_IOC_STAT0_P_NBR_MASK 0x7ffff
  121. #define LCA_HAE_ADDRESS LCA_IOC_HAE
  122. /* LCA PMR Power Management register defines */
  123. #define LCA_PMR_ADDR (IDENT_ADDR + 0x120000098UL)
  124. #define LCA_PMR_PDIV 0x7 /* Primary clock divisor */
  125. #define LCA_PMR_ODIV 0x38 /* Override clock divisor */
  126. #define LCA_PMR_INTO 0x40 /* Interrupt override */
  127. #define LCA_PMR_DMAO 0x80 /* DMA override */
  128. #define LCA_PMR_OCCEB 0xffff0000L /* Override cycle counter - even bits */
  129. #define LCA_PMR_OCCOB 0xffff000000000000L /* Override cycle counter - even bits */
  130. #define LCA_PMR_PRIMARY_MASK 0xfffffffffffffff8L
  131. /* LCA PMR Macros */
  132. #define LCA_READ_PMR (*(volatile unsigned long *)LCA_PMR_ADDR)
  133. #define LCA_WRITE_PMR(d) (*((volatile unsigned long *)LCA_PMR_ADDR) = (d))
  134. #define LCA_GET_PRIMARY(r) ((r) & LCA_PMR_PDIV)
  135. #define LCA_GET_OVERRIDE(r) (((r) >> 3) & LCA_PMR_PDIV)
  136. #define LCA_SET_PRIMARY_CLOCK(r, c) ((r) = (((r) & LCA_PMR_PRIMARY_MASK)|(c)))
  137. /* LCA PMR Divisor values */
  138. #define LCA_PMR_DIV_1 0x0
  139. #define LCA_PMR_DIV_1_5 0x1
  140. #define LCA_PMR_DIV_2 0x2
  141. #define LCA_PMR_DIV_4 0x3
  142. #define LCA_PMR_DIV_8 0x4
  143. #define LCA_PMR_DIV_16 0x5
  144. #define LCA_PMR_DIV_MIN DIV_1
  145. #define LCA_PMR_DIV_MAX DIV_16
  146. /*
  147. * Data structure for handling LCA machine checks. Correctable errors
  148. * result in a short logout frame, uncorrectable ones in a long one.
  149. */
  150. struct el_lca_mcheck_short {
  151. struct el_common h; /* common logout header */
  152. unsigned long esr; /* error-status register */
  153. unsigned long ear; /* error-address register */
  154. unsigned long dc_stat; /* dcache status register */
  155. unsigned long ioc_stat0; /* I/O controller status register 0 */
  156. unsigned long ioc_stat1; /* I/O controller status register 1 */
  157. };
  158. struct el_lca_mcheck_long {
  159. struct el_common h; /* common logout header */
  160. unsigned long pt[31]; /* PAL temps */
  161. unsigned long exc_addr; /* exception address */
  162. unsigned long pad1[3];
  163. unsigned long pal_base; /* PALcode base address */
  164. unsigned long hier; /* hw interrupt enable */
  165. unsigned long hirr; /* hw interrupt request */
  166. unsigned long mm_csr; /* MMU control & status */
  167. unsigned long dc_stat; /* data cache status */
  168. unsigned long dc_addr; /* data cache addr register */
  169. unsigned long abox_ctl; /* address box control register */
  170. unsigned long esr; /* error status register */
  171. unsigned long ear; /* error address register */
  172. unsigned long car; /* cache control register */
  173. unsigned long ioc_stat0; /* I/O controller status register 0 */
  174. unsigned long ioc_stat1; /* I/O controller status register 1 */
  175. unsigned long va; /* virtual address register */
  176. };
  177. union el_lca {
  178. struct el_common * c;
  179. struct el_lca_mcheck_long * l;
  180. struct el_lca_mcheck_short * s;
  181. };
  182. #ifdef __KERNEL__
  183. #ifndef __EXTERN_INLINE
  184. #define __EXTERN_INLINE extern inline
  185. #define __IO_EXTERN_INLINE
  186. #endif
  187. /*
  188. * I/O functions:
  189. *
  190. * Unlike Jensen, the Noname machines have no concept of local
  191. * I/O---everything goes over the PCI bus.
  192. *
  193. * There is plenty room for optimization here. In particular,
  194. * the Alpha's insb/insw/extb/extw should be useful in moving
  195. * data to/from the right byte-lanes.
  196. */
  197. #define vip volatile int __force *
  198. #define vuip volatile unsigned int __force *
  199. #define vulp volatile unsigned long __force *
  200. #define LCA_SET_HAE \
  201. do { \
  202. if (addr >= (1UL << 24)) { \
  203. unsigned long msb = addr & 0xf8000000; \
  204. addr -= msb; \
  205. set_hae(msb); \
  206. } \
  207. } while (0)
  208. __EXTERN_INLINE unsigned int lca_ioread8(void __iomem *xaddr)
  209. {
  210. unsigned long addr = (unsigned long) xaddr;
  211. unsigned long result, base_and_type;
  212. if (addr >= LCA_DENSE_MEM) {
  213. addr -= LCA_DENSE_MEM;
  214. LCA_SET_HAE;
  215. base_and_type = LCA_SPARSE_MEM + 0x00;
  216. } else {
  217. addr -= LCA_IO;
  218. base_and_type = LCA_IO + 0x00;
  219. }
  220. result = *(vip) ((addr << 5) + base_and_type);
  221. return __kernel_extbl(result, addr & 3);
  222. }
  223. __EXTERN_INLINE void lca_iowrite8(u8 b, void __iomem *xaddr)
  224. {
  225. unsigned long addr = (unsigned long) xaddr;
  226. unsigned long w, base_and_type;
  227. if (addr >= LCA_DENSE_MEM) {
  228. addr -= LCA_DENSE_MEM;
  229. LCA_SET_HAE;
  230. base_and_type = LCA_SPARSE_MEM + 0x00;
  231. } else {
  232. addr -= LCA_IO;
  233. base_and_type = LCA_IO + 0x00;
  234. }
  235. w = __kernel_insbl(b, addr & 3);
  236. *(vuip) ((addr << 5) + base_and_type) = w;
  237. }
  238. __EXTERN_INLINE unsigned int lca_ioread16(void __iomem *xaddr)
  239. {
  240. unsigned long addr = (unsigned long) xaddr;
  241. unsigned long result, base_and_type;
  242. if (addr >= LCA_DENSE_MEM) {
  243. addr -= LCA_DENSE_MEM;
  244. LCA_SET_HAE;
  245. base_and_type = LCA_SPARSE_MEM + 0x08;
  246. } else {
  247. addr -= LCA_IO;
  248. base_and_type = LCA_IO + 0x08;
  249. }
  250. result = *(vip) ((addr << 5) + base_and_type);
  251. return __kernel_extwl(result, addr & 3);
  252. }
  253. __EXTERN_INLINE void lca_iowrite16(u16 b, void __iomem *xaddr)
  254. {
  255. unsigned long addr = (unsigned long) xaddr;
  256. unsigned long w, base_and_type;
  257. if (addr >= LCA_DENSE_MEM) {
  258. addr -= LCA_DENSE_MEM;
  259. LCA_SET_HAE;
  260. base_and_type = LCA_SPARSE_MEM + 0x08;
  261. } else {
  262. addr -= LCA_IO;
  263. base_and_type = LCA_IO + 0x08;
  264. }
  265. w = __kernel_inswl(b, addr & 3);
  266. *(vuip) ((addr << 5) + base_and_type) = w;
  267. }
  268. __EXTERN_INLINE unsigned int lca_ioread32(void __iomem *xaddr)
  269. {
  270. unsigned long addr = (unsigned long) xaddr;
  271. if (addr < LCA_DENSE_MEM)
  272. addr = ((addr - LCA_IO) << 5) + LCA_IO + 0x18;
  273. return *(vuip)addr;
  274. }
  275. __EXTERN_INLINE void lca_iowrite32(u32 b, void __iomem *xaddr)
  276. {
  277. unsigned long addr = (unsigned long) xaddr;
  278. if (addr < LCA_DENSE_MEM)
  279. addr = ((addr - LCA_IO) << 5) + LCA_IO + 0x18;
  280. *(vuip)addr = b;
  281. }
  282. __EXTERN_INLINE void __iomem *lca_ioportmap(unsigned long addr)
  283. {
  284. return (void __iomem *)(addr + LCA_IO);
  285. }
  286. __EXTERN_INLINE void __iomem *lca_ioremap(unsigned long addr,
  287. unsigned long size)
  288. {
  289. return (void __iomem *)(addr + LCA_DENSE_MEM);
  290. }
  291. __EXTERN_INLINE int lca_is_ioaddr(unsigned long addr)
  292. {
  293. return addr >= IDENT_ADDR + 0x120000000UL;
  294. }
  295. __EXTERN_INLINE int lca_is_mmio(const volatile void __iomem *addr)
  296. {
  297. return (unsigned long)addr >= LCA_DENSE_MEM;
  298. }
  299. #undef vip
  300. #undef vuip
  301. #undef vulp
  302. #undef __IO_PREFIX
  303. #define __IO_PREFIX lca
  304. #define lca_trivial_rw_bw 2
  305. #define lca_trivial_rw_lq 1
  306. #define lca_trivial_io_bw 0
  307. #define lca_trivial_io_lq 0
  308. #define lca_trivial_iounmap 1
  309. #include <asm/io_trivial.h>
  310. #ifdef __IO_EXTERN_INLINE
  311. #undef __EXTERN_INLINE
  312. #undef __IO_EXTERN_INLINE
  313. #endif
  314. #endif /* __KERNEL__ */
  315. #endif /* __ALPHA_LCA__H__ */