core_t2.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. #ifndef __ALPHA_T2__H__
  2. #define __ALPHA_T2__H__
  3. #include <linux/types.h>
  4. #include <linux/spinlock.h>
  5. #include <asm/compiler.h>
  6. #include <asm/system.h>
  7. /*
  8. * T2 is the internal name for the core logic chipset which provides
  9. * memory controller and PCI access for the SABLE-based systems.
  10. *
  11. * This file is based on:
  12. *
  13. * SABLE I/O Specification
  14. * Revision/Update Information: 1.3
  15. *
  16. * jestabro@amt.tay1.dec.com Initial Version.
  17. *
  18. */
  19. #define T2_MEM_R1_MASK 0x07ffffff /* Mem sparse region 1 mask is 26 bits */
  20. /* GAMMA-SABLE is a SABLE with EV5-based CPUs */
  21. /* All LYNX machines, EV4 or EV5, use the GAMMA bias also */
  22. #define _GAMMA_BIAS 0x8000000000UL
  23. #if defined(CONFIG_ALPHA_GENERIC)
  24. #define GAMMA_BIAS alpha_mv.sys.t2.gamma_bias
  25. #elif defined(CONFIG_ALPHA_GAMMA)
  26. #define GAMMA_BIAS _GAMMA_BIAS
  27. #else
  28. #define GAMMA_BIAS 0
  29. #endif
  30. /*
  31. * Memory spaces:
  32. */
  33. #define T2_CONF (IDENT_ADDR + GAMMA_BIAS + 0x390000000UL)
  34. #define T2_IO (IDENT_ADDR + GAMMA_BIAS + 0x3a0000000UL)
  35. #define T2_SPARSE_MEM (IDENT_ADDR + GAMMA_BIAS + 0x200000000UL)
  36. #define T2_DENSE_MEM (IDENT_ADDR + GAMMA_BIAS + 0x3c0000000UL)
  37. #define T2_IOCSR (IDENT_ADDR + GAMMA_BIAS + 0x38e000000UL)
  38. #define T2_CERR1 (IDENT_ADDR + GAMMA_BIAS + 0x38e000020UL)
  39. #define T2_CERR2 (IDENT_ADDR + GAMMA_BIAS + 0x38e000040UL)
  40. #define T2_CERR3 (IDENT_ADDR + GAMMA_BIAS + 0x38e000060UL)
  41. #define T2_PERR1 (IDENT_ADDR + GAMMA_BIAS + 0x38e000080UL)
  42. #define T2_PERR2 (IDENT_ADDR + GAMMA_BIAS + 0x38e0000a0UL)
  43. #define T2_PSCR (IDENT_ADDR + GAMMA_BIAS + 0x38e0000c0UL)
  44. #define T2_HAE_1 (IDENT_ADDR + GAMMA_BIAS + 0x38e0000e0UL)
  45. #define T2_HAE_2 (IDENT_ADDR + GAMMA_BIAS + 0x38e000100UL)
  46. #define T2_HBASE (IDENT_ADDR + GAMMA_BIAS + 0x38e000120UL)
  47. #define T2_WBASE1 (IDENT_ADDR + GAMMA_BIAS + 0x38e000140UL)
  48. #define T2_WMASK1 (IDENT_ADDR + GAMMA_BIAS + 0x38e000160UL)
  49. #define T2_TBASE1 (IDENT_ADDR + GAMMA_BIAS + 0x38e000180UL)
  50. #define T2_WBASE2 (IDENT_ADDR + GAMMA_BIAS + 0x38e0001a0UL)
  51. #define T2_WMASK2 (IDENT_ADDR + GAMMA_BIAS + 0x38e0001c0UL)
  52. #define T2_TBASE2 (IDENT_ADDR + GAMMA_BIAS + 0x38e0001e0UL)
  53. #define T2_TLBBR (IDENT_ADDR + GAMMA_BIAS + 0x38e000200UL)
  54. #define T2_IVR (IDENT_ADDR + GAMMA_BIAS + 0x38e000220UL)
  55. #define T2_HAE_3 (IDENT_ADDR + GAMMA_BIAS + 0x38e000240UL)
  56. #define T2_HAE_4 (IDENT_ADDR + GAMMA_BIAS + 0x38e000260UL)
  57. /* The CSRs below are T3/T4 only */
  58. #define T2_WBASE3 (IDENT_ADDR + GAMMA_BIAS + 0x38e000280UL)
  59. #define T2_WMASK3 (IDENT_ADDR + GAMMA_BIAS + 0x38e0002a0UL)
  60. #define T2_TBASE3 (IDENT_ADDR + GAMMA_BIAS + 0x38e0002c0UL)
  61. #define T2_TDR0 (IDENT_ADDR + GAMMA_BIAS + 0x38e000300UL)
  62. #define T2_TDR1 (IDENT_ADDR + GAMMA_BIAS + 0x38e000320UL)
  63. #define T2_TDR2 (IDENT_ADDR + GAMMA_BIAS + 0x38e000340UL)
  64. #define T2_TDR3 (IDENT_ADDR + GAMMA_BIAS + 0x38e000360UL)
  65. #define T2_TDR4 (IDENT_ADDR + GAMMA_BIAS + 0x38e000380UL)
  66. #define T2_TDR5 (IDENT_ADDR + GAMMA_BIAS + 0x38e0003a0UL)
  67. #define T2_TDR6 (IDENT_ADDR + GAMMA_BIAS + 0x38e0003c0UL)
  68. #define T2_TDR7 (IDENT_ADDR + GAMMA_BIAS + 0x38e0003e0UL)
  69. #define T2_WBASE4 (IDENT_ADDR + GAMMA_BIAS + 0x38e000400UL)
  70. #define T2_WMASK4 (IDENT_ADDR + GAMMA_BIAS + 0x38e000420UL)
  71. #define T2_TBASE4 (IDENT_ADDR + GAMMA_BIAS + 0x38e000440UL)
  72. #define T2_AIR (IDENT_ADDR + GAMMA_BIAS + 0x38e000460UL)
  73. #define T2_VAR (IDENT_ADDR + GAMMA_BIAS + 0x38e000480UL)
  74. #define T2_DIR (IDENT_ADDR + GAMMA_BIAS + 0x38e0004a0UL)
  75. #define T2_ICE (IDENT_ADDR + GAMMA_BIAS + 0x38e0004c0UL)
  76. #define T2_HAE_ADDRESS T2_HAE_1
  77. /* T2 CSRs are in the non-cachable primary IO space from 3.8000.0000 to
  78. 3.8fff.ffff
  79. *
  80. * +--------------+ 3 8000 0000
  81. * | CPU 0 CSRs |
  82. * +--------------+ 3 8100 0000
  83. * | CPU 1 CSRs |
  84. * +--------------+ 3 8200 0000
  85. * | CPU 2 CSRs |
  86. * +--------------+ 3 8300 0000
  87. * | CPU 3 CSRs |
  88. * +--------------+ 3 8400 0000
  89. * | CPU Reserved |
  90. * +--------------+ 3 8700 0000
  91. * | Mem Reserved |
  92. * +--------------+ 3 8800 0000
  93. * | Mem 0 CSRs |
  94. * +--------------+ 3 8900 0000
  95. * | Mem 1 CSRs |
  96. * +--------------+ 3 8a00 0000
  97. * | Mem 2 CSRs |
  98. * +--------------+ 3 8b00 0000
  99. * | Mem 3 CSRs |
  100. * +--------------+ 3 8c00 0000
  101. * | Mem Reserved |
  102. * +--------------+ 3 8e00 0000
  103. * | PCI Bridge |
  104. * +--------------+ 3 8f00 0000
  105. * | Expansion IO |
  106. * +--------------+ 3 9000 0000
  107. *
  108. *
  109. */
  110. #define T2_CPU0_BASE (IDENT_ADDR + GAMMA_BIAS + 0x380000000L)
  111. #define T2_CPU1_BASE (IDENT_ADDR + GAMMA_BIAS + 0x381000000L)
  112. #define T2_CPU2_BASE (IDENT_ADDR + GAMMA_BIAS + 0x382000000L)
  113. #define T2_CPU3_BASE (IDENT_ADDR + GAMMA_BIAS + 0x383000000L)
  114. #define T2_CPUn_BASE(n) (T2_CPU0_BASE + (((n)&3) * 0x001000000L))
  115. #define T2_MEM0_BASE (IDENT_ADDR + GAMMA_BIAS + 0x388000000L)
  116. #define T2_MEM1_BASE (IDENT_ADDR + GAMMA_BIAS + 0x389000000L)
  117. #define T2_MEM2_BASE (IDENT_ADDR + GAMMA_BIAS + 0x38a000000L)
  118. #define T2_MEM3_BASE (IDENT_ADDR + GAMMA_BIAS + 0x38b000000L)
  119. /*
  120. * Sable CPU Module CSRS
  121. *
  122. * These are CSRs for hardware other than the CPU chip on the CPU module.
  123. * The CPU module has Backup Cache control logic, Cbus control logic, and
  124. * interrupt control logic on it. There is a duplicate tag store to speed
  125. * up maintaining cache coherency.
  126. */
  127. struct sable_cpu_csr {
  128. unsigned long bcc; long fill_00[3]; /* Backup Cache Control */
  129. unsigned long bcce; long fill_01[3]; /* Backup Cache Correctable Error */
  130. unsigned long bccea; long fill_02[3]; /* B-Cache Corr Err Address Latch */
  131. unsigned long bcue; long fill_03[3]; /* B-Cache Uncorrectable Error */
  132. unsigned long bcuea; long fill_04[3]; /* B-Cache Uncorr Err Addr Latch */
  133. unsigned long dter; long fill_05[3]; /* Duplicate Tag Error */
  134. unsigned long cbctl; long fill_06[3]; /* CBus Control */
  135. unsigned long cbe; long fill_07[3]; /* CBus Error */
  136. unsigned long cbeal; long fill_08[3]; /* CBus Error Addr Latch low */
  137. unsigned long cbeah; long fill_09[3]; /* CBus Error Addr Latch high */
  138. unsigned long pmbx; long fill_10[3]; /* Processor Mailbox */
  139. unsigned long ipir; long fill_11[3]; /* Inter-Processor Int Request */
  140. unsigned long sic; long fill_12[3]; /* System Interrupt Clear */
  141. unsigned long adlk; long fill_13[3]; /* Address Lock (LDxL/STxC) */
  142. unsigned long madrl; long fill_14[3]; /* CBus Miss Address */
  143. unsigned long rev; long fill_15[3]; /* CMIC Revision */
  144. };
  145. /*
  146. * Data structure for handling T2 machine checks:
  147. */
  148. struct el_t2_frame_header {
  149. unsigned int elcf_fid; /* Frame ID (from above) */
  150. unsigned int elcf_size; /* Size of frame in bytes */
  151. };
  152. struct el_t2_procdata_mcheck {
  153. unsigned long elfmc_paltemp[32]; /* PAL TEMP REGS. */
  154. /* EV4-specific fields */
  155. unsigned long elfmc_exc_addr; /* Addr of excepting insn. */
  156. unsigned long elfmc_exc_sum; /* Summary of arith traps. */
  157. unsigned long elfmc_exc_mask; /* Exception mask (from exc_sum). */
  158. unsigned long elfmc_iccsr; /* IBox hardware enables. */
  159. unsigned long elfmc_pal_base; /* Base address for PALcode. */
  160. unsigned long elfmc_hier; /* Hardware Interrupt Enable. */
  161. unsigned long elfmc_hirr; /* Hardware Interrupt Request. */
  162. unsigned long elfmc_mm_csr; /* D-stream fault info. */
  163. unsigned long elfmc_dc_stat; /* D-cache status (ECC/Parity Err). */
  164. unsigned long elfmc_dc_addr; /* EV3 Phys Addr for ECC/DPERR. */
  165. unsigned long elfmc_abox_ctl; /* ABox Control Register. */
  166. unsigned long elfmc_biu_stat; /* BIU Status. */
  167. unsigned long elfmc_biu_addr; /* BUI Address. */
  168. unsigned long elfmc_biu_ctl; /* BIU Control. */
  169. unsigned long elfmc_fill_syndrome; /* For correcting ECC errors. */
  170. unsigned long elfmc_fill_addr;/* Cache block which was being read. */
  171. unsigned long elfmc_va; /* Effective VA of fault or miss. */
  172. unsigned long elfmc_bc_tag; /* Backup Cache Tag Probe Results. */
  173. };
  174. /*
  175. * Sable processor specific Machine Check Data segment.
  176. */
  177. struct el_t2_logout_header {
  178. unsigned int elfl_size; /* size in bytes of logout area. */
  179. unsigned int elfl_sbz1:31; /* Should be zero. */
  180. unsigned int elfl_retry:1; /* Retry flag. */
  181. unsigned int elfl_procoffset; /* Processor-specific offset. */
  182. unsigned int elfl_sysoffset; /* Offset of system-specific. */
  183. unsigned int elfl_error_type; /* PAL error type code. */
  184. unsigned int elfl_frame_rev; /* PAL Frame revision. */
  185. };
  186. struct el_t2_sysdata_mcheck {
  187. unsigned long elcmc_bcc; /* CSR 0 */
  188. unsigned long elcmc_bcce; /* CSR 1 */
  189. unsigned long elcmc_bccea; /* CSR 2 */
  190. unsigned long elcmc_bcue; /* CSR 3 */
  191. unsigned long elcmc_bcuea; /* CSR 4 */
  192. unsigned long elcmc_dter; /* CSR 5 */
  193. unsigned long elcmc_cbctl; /* CSR 6 */
  194. unsigned long elcmc_cbe; /* CSR 7 */
  195. unsigned long elcmc_cbeal; /* CSR 8 */
  196. unsigned long elcmc_cbeah; /* CSR 9 */
  197. unsigned long elcmc_pmbx; /* CSR 10 */
  198. unsigned long elcmc_ipir; /* CSR 11 */
  199. unsigned long elcmc_sic; /* CSR 12 */
  200. unsigned long elcmc_adlk; /* CSR 13 */
  201. unsigned long elcmc_madrl; /* CSR 14 */
  202. unsigned long elcmc_crrev4; /* CSR 15 */
  203. };
  204. /*
  205. * Sable memory error frame - sable pfms section 3.42
  206. */
  207. struct el_t2_data_memory {
  208. struct el_t2_frame_header elcm_hdr; /* ID$MEM-FERR = 0x08 */
  209. unsigned int elcm_module; /* Module id. */
  210. unsigned int elcm_res04; /* Reserved. */
  211. unsigned long elcm_merr; /* CSR0: Error Reg 1. */
  212. unsigned long elcm_mcmd1; /* CSR1: Command Trap 1. */
  213. unsigned long elcm_mcmd2; /* CSR2: Command Trap 2. */
  214. unsigned long elcm_mconf; /* CSR3: Configuration. */
  215. unsigned long elcm_medc1; /* CSR4: EDC Status 1. */
  216. unsigned long elcm_medc2; /* CSR5: EDC Status 2. */
  217. unsigned long elcm_medcc; /* CSR6: EDC Control. */
  218. unsigned long elcm_msctl; /* CSR7: Stream Buffer Control. */
  219. unsigned long elcm_mref; /* CSR8: Refresh Control. */
  220. unsigned long elcm_filter; /* CSR9: CRD Filter Control. */
  221. };
  222. /*
  223. * Sable other CPU error frame - sable pfms section 3.43
  224. */
  225. struct el_t2_data_other_cpu {
  226. short elco_cpuid; /* CPU ID */
  227. short elco_res02[3];
  228. unsigned long elco_bcc; /* CSR 0 */
  229. unsigned long elco_bcce; /* CSR 1 */
  230. unsigned long elco_bccea; /* CSR 2 */
  231. unsigned long elco_bcue; /* CSR 3 */
  232. unsigned long elco_bcuea; /* CSR 4 */
  233. unsigned long elco_dter; /* CSR 5 */
  234. unsigned long elco_cbctl; /* CSR 6 */
  235. unsigned long elco_cbe; /* CSR 7 */
  236. unsigned long elco_cbeal; /* CSR 8 */
  237. unsigned long elco_cbeah; /* CSR 9 */
  238. unsigned long elco_pmbx; /* CSR 10 */
  239. unsigned long elco_ipir; /* CSR 11 */
  240. unsigned long elco_sic; /* CSR 12 */
  241. unsigned long elco_adlk; /* CSR 13 */
  242. unsigned long elco_madrl; /* CSR 14 */
  243. unsigned long elco_crrev4; /* CSR 15 */
  244. };
  245. /*
  246. * Sable other CPU error frame - sable pfms section 3.44
  247. */
  248. struct el_t2_data_t2{
  249. struct el_t2_frame_header elct_hdr; /* ID$T2-FRAME */
  250. unsigned long elct_iocsr; /* IO Control and Status Register */
  251. unsigned long elct_cerr1; /* Cbus Error Register 1 */
  252. unsigned long elct_cerr2; /* Cbus Error Register 2 */
  253. unsigned long elct_cerr3; /* Cbus Error Register 3 */
  254. unsigned long elct_perr1; /* PCI Error Register 1 */
  255. unsigned long elct_perr2; /* PCI Error Register 2 */
  256. unsigned long elct_hae0_1; /* High Address Extension Register 1 */
  257. unsigned long elct_hae0_2; /* High Address Extension Register 2 */
  258. unsigned long elct_hbase; /* High Base Register */
  259. unsigned long elct_wbase1; /* Window Base Register 1 */
  260. unsigned long elct_wmask1; /* Window Mask Register 1 */
  261. unsigned long elct_tbase1; /* Translated Base Register 1 */
  262. unsigned long elct_wbase2; /* Window Base Register 2 */
  263. unsigned long elct_wmask2; /* Window Mask Register 2 */
  264. unsigned long elct_tbase2; /* Translated Base Register 2 */
  265. unsigned long elct_tdr0; /* TLB Data Register 0 */
  266. unsigned long elct_tdr1; /* TLB Data Register 1 */
  267. unsigned long elct_tdr2; /* TLB Data Register 2 */
  268. unsigned long elct_tdr3; /* TLB Data Register 3 */
  269. unsigned long elct_tdr4; /* TLB Data Register 4 */
  270. unsigned long elct_tdr5; /* TLB Data Register 5 */
  271. unsigned long elct_tdr6; /* TLB Data Register 6 */
  272. unsigned long elct_tdr7; /* TLB Data Register 7 */
  273. };
  274. /*
  275. * Sable error log data structure - sable pfms section 3.40
  276. */
  277. struct el_t2_data_corrected {
  278. unsigned long elcpb_biu_stat;
  279. unsigned long elcpb_biu_addr;
  280. unsigned long elcpb_biu_ctl;
  281. unsigned long elcpb_fill_syndrome;
  282. unsigned long elcpb_fill_addr;
  283. unsigned long elcpb_bc_tag;
  284. };
  285. /*
  286. * Sable error log data structure
  287. * Note there are 4 memory slots on sable (see t2.h)
  288. */
  289. struct el_t2_frame_mcheck {
  290. struct el_t2_frame_header elfmc_header; /* ID$P-FRAME_MCHECK */
  291. struct el_t2_logout_header elfmc_hdr;
  292. struct el_t2_procdata_mcheck elfmc_procdata;
  293. struct el_t2_sysdata_mcheck elfmc_sysdata;
  294. struct el_t2_data_t2 elfmc_t2data;
  295. struct el_t2_data_memory elfmc_memdata[4];
  296. struct el_t2_frame_header elfmc_footer; /* empty */
  297. };
  298. /*
  299. * Sable error log data structures on memory errors
  300. */
  301. struct el_t2_frame_corrected {
  302. struct el_t2_frame_header elfcc_header; /* ID$P-BC-COR */
  303. struct el_t2_logout_header elfcc_hdr;
  304. struct el_t2_data_corrected elfcc_procdata;
  305. /* struct el_t2_data_t2 elfcc_t2data; */
  306. /* struct el_t2_data_memory elfcc_memdata[4]; */
  307. struct el_t2_frame_header elfcc_footer; /* empty */
  308. };
  309. #ifdef __KERNEL__
  310. #ifndef __EXTERN_INLINE
  311. #define __EXTERN_INLINE extern inline
  312. #define __IO_EXTERN_INLINE
  313. #endif
  314. /*
  315. * I/O functions:
  316. *
  317. * T2 (the core logic PCI/memory support chipset for the SABLE
  318. * series of processors uses a sparse address mapping scheme to
  319. * get at PCI memory and I/O.
  320. */
  321. #define vip volatile int *
  322. #define vuip volatile unsigned int *
  323. static inline u8 t2_inb(unsigned long addr)
  324. {
  325. long result = *(vip) ((addr << 5) + T2_IO + 0x00);
  326. return __kernel_extbl(result, addr & 3);
  327. }
  328. static inline void t2_outb(u8 b, unsigned long addr)
  329. {
  330. unsigned long w;
  331. w = __kernel_insbl(b, addr & 3);
  332. *(vuip) ((addr << 5) + T2_IO + 0x00) = w;
  333. mb();
  334. }
  335. static inline u16 t2_inw(unsigned long addr)
  336. {
  337. long result = *(vip) ((addr << 5) + T2_IO + 0x08);
  338. return __kernel_extwl(result, addr & 3);
  339. }
  340. static inline void t2_outw(u16 b, unsigned long addr)
  341. {
  342. unsigned long w;
  343. w = __kernel_inswl(b, addr & 3);
  344. *(vuip) ((addr << 5) + T2_IO + 0x08) = w;
  345. mb();
  346. }
  347. static inline u32 t2_inl(unsigned long addr)
  348. {
  349. return *(vuip) ((addr << 5) + T2_IO + 0x18);
  350. }
  351. static inline void t2_outl(u32 b, unsigned long addr)
  352. {
  353. *(vuip) ((addr << 5) + T2_IO + 0x18) = b;
  354. mb();
  355. }
  356. /*
  357. * Memory functions.
  358. *
  359. * For reading and writing 8 and 16 bit quantities we need to
  360. * go through one of the three sparse address mapping regions
  361. * and use the HAE_MEM CSR to provide some bits of the address.
  362. * The following few routines use only sparse address region 1
  363. * which gives 1Gbyte of accessible space which relates exactly
  364. * to the amount of PCI memory mapping *into* system address space.
  365. * See p 6-17 of the specification but it looks something like this:
  366. *
  367. * 21164 Address:
  368. *
  369. * 3 2 1
  370. * 9876543210987654321098765432109876543210
  371. * 1ZZZZ0.PCI.QW.Address............BBLL
  372. *
  373. * ZZ = SBZ
  374. * BB = Byte offset
  375. * LL = Transfer length
  376. *
  377. * PCI Address:
  378. *
  379. * 3 2 1
  380. * 10987654321098765432109876543210
  381. * HHH....PCI.QW.Address........ 00
  382. *
  383. * HHH = 31:29 HAE_MEM CSR
  384. *
  385. */
  386. #define t2_set_hae { \
  387. msb = addr >> 27; \
  388. addr &= T2_MEM_R1_MASK; \
  389. set_hae(msb); \
  390. }
  391. static DEFINE_SPINLOCK(t2_hae_lock);
  392. /*
  393. * NOTE: take T2_DENSE_MEM off in each readX/writeX routine, since
  394. * they may be called directly, rather than through the
  395. * ioreadNN/iowriteNN routines.
  396. */
  397. __EXTERN_INLINE u8 t2_readb(const volatile void __iomem *xaddr)
  398. {
  399. unsigned long addr = (unsigned long) xaddr - T2_DENSE_MEM;
  400. unsigned long result, msb;
  401. unsigned long flags;
  402. spin_lock_irqsave(&t2_hae_lock, flags);
  403. t2_set_hae;
  404. result = *(vip) ((addr << 5) + T2_SPARSE_MEM + 0x00);
  405. spin_unlock_irqrestore(&t2_hae_lock, flags);
  406. return __kernel_extbl(result, addr & 3);
  407. }
  408. __EXTERN_INLINE u16 t2_readw(const volatile void __iomem *xaddr)
  409. {
  410. unsigned long addr = (unsigned long) xaddr - T2_DENSE_MEM;
  411. unsigned long result, msb;
  412. unsigned long flags;
  413. spin_lock_irqsave(&t2_hae_lock, flags);
  414. t2_set_hae;
  415. result = *(vuip) ((addr << 5) + T2_SPARSE_MEM + 0x08);
  416. spin_unlock_irqrestore(&t2_hae_lock, flags);
  417. return __kernel_extwl(result, addr & 3);
  418. }
  419. /*
  420. * On SABLE with T2, we must use SPARSE memory even for 32-bit access,
  421. * because we cannot access all of DENSE without changing its HAE.
  422. */
  423. __EXTERN_INLINE u32 t2_readl(const volatile void __iomem *xaddr)
  424. {
  425. unsigned long addr = (unsigned long) xaddr - T2_DENSE_MEM;
  426. unsigned long result, msb;
  427. unsigned long flags;
  428. spin_lock_irqsave(&t2_hae_lock, flags);
  429. t2_set_hae;
  430. result = *(vuip) ((addr << 5) + T2_SPARSE_MEM + 0x18);
  431. spin_unlock_irqrestore(&t2_hae_lock, flags);
  432. return result & 0xffffffffUL;
  433. }
  434. __EXTERN_INLINE u64 t2_readq(const volatile void __iomem *xaddr)
  435. {
  436. unsigned long addr = (unsigned long) xaddr - T2_DENSE_MEM;
  437. unsigned long r0, r1, work, msb;
  438. unsigned long flags;
  439. spin_lock_irqsave(&t2_hae_lock, flags);
  440. t2_set_hae;
  441. work = (addr << 5) + T2_SPARSE_MEM + 0x18;
  442. r0 = *(vuip)(work);
  443. r1 = *(vuip)(work + (4 << 5));
  444. spin_unlock_irqrestore(&t2_hae_lock, flags);
  445. return r1 << 32 | r0;
  446. }
  447. __EXTERN_INLINE void t2_writeb(u8 b, volatile void __iomem *xaddr)
  448. {
  449. unsigned long addr = (unsigned long) xaddr - T2_DENSE_MEM;
  450. unsigned long msb, w;
  451. unsigned long flags;
  452. spin_lock_irqsave(&t2_hae_lock, flags);
  453. t2_set_hae;
  454. w = __kernel_insbl(b, addr & 3);
  455. *(vuip) ((addr << 5) + T2_SPARSE_MEM + 0x00) = w;
  456. spin_unlock_irqrestore(&t2_hae_lock, flags);
  457. }
  458. __EXTERN_INLINE void t2_writew(u16 b, volatile void __iomem *xaddr)
  459. {
  460. unsigned long addr = (unsigned long) xaddr - T2_DENSE_MEM;
  461. unsigned long msb, w;
  462. unsigned long flags;
  463. spin_lock_irqsave(&t2_hae_lock, flags);
  464. t2_set_hae;
  465. w = __kernel_inswl(b, addr & 3);
  466. *(vuip) ((addr << 5) + T2_SPARSE_MEM + 0x08) = w;
  467. spin_unlock_irqrestore(&t2_hae_lock, flags);
  468. }
  469. /*
  470. * On SABLE with T2, we must use SPARSE memory even for 32-bit access,
  471. * because we cannot access all of DENSE without changing its HAE.
  472. */
  473. __EXTERN_INLINE void t2_writel(u32 b, volatile void __iomem *xaddr)
  474. {
  475. unsigned long addr = (unsigned long) xaddr - T2_DENSE_MEM;
  476. unsigned long msb;
  477. unsigned long flags;
  478. spin_lock_irqsave(&t2_hae_lock, flags);
  479. t2_set_hae;
  480. *(vuip) ((addr << 5) + T2_SPARSE_MEM + 0x18) = b;
  481. spin_unlock_irqrestore(&t2_hae_lock, flags);
  482. }
  483. __EXTERN_INLINE void t2_writeq(u64 b, volatile void __iomem *xaddr)
  484. {
  485. unsigned long addr = (unsigned long) xaddr - T2_DENSE_MEM;
  486. unsigned long msb, work;
  487. unsigned long flags;
  488. spin_lock_irqsave(&t2_hae_lock, flags);
  489. t2_set_hae;
  490. work = (addr << 5) + T2_SPARSE_MEM + 0x18;
  491. *(vuip)work = b;
  492. *(vuip)(work + (4 << 5)) = b >> 32;
  493. spin_unlock_irqrestore(&t2_hae_lock, flags);
  494. }
  495. __EXTERN_INLINE void __iomem *t2_ioportmap(unsigned long addr)
  496. {
  497. return (void __iomem *)(addr + T2_IO);
  498. }
  499. __EXTERN_INLINE void __iomem *t2_ioremap(unsigned long addr,
  500. unsigned long size)
  501. {
  502. return (void __iomem *)(addr + T2_DENSE_MEM);
  503. }
  504. __EXTERN_INLINE int t2_is_ioaddr(unsigned long addr)
  505. {
  506. return (long)addr >= 0;
  507. }
  508. __EXTERN_INLINE int t2_is_mmio(const volatile void __iomem *addr)
  509. {
  510. return (unsigned long)addr >= T2_DENSE_MEM;
  511. }
  512. /* New-style ioread interface. The mmio routines are so ugly for T2 that
  513. it doesn't make sense to merge the pio and mmio routines. */
  514. #define IOPORT(OS, NS) \
  515. __EXTERN_INLINE unsigned int t2_ioread##NS(void __iomem *xaddr) \
  516. { \
  517. if (t2_is_mmio(xaddr)) \
  518. return t2_read##OS(xaddr); \
  519. else \
  520. return t2_in##OS((unsigned long)xaddr - T2_IO); \
  521. } \
  522. __EXTERN_INLINE void t2_iowrite##NS(u##NS b, void __iomem *xaddr) \
  523. { \
  524. if (t2_is_mmio(xaddr)) \
  525. t2_write##OS(b, xaddr); \
  526. else \
  527. t2_out##OS(b, (unsigned long)xaddr - T2_IO); \
  528. }
  529. IOPORT(b, 8)
  530. IOPORT(w, 16)
  531. IOPORT(l, 32)
  532. #undef IOPORT
  533. #undef vip
  534. #undef vuip
  535. #undef __IO_PREFIX
  536. #define __IO_PREFIX t2
  537. #define t2_trivial_rw_bw 0
  538. #define t2_trivial_rw_lq 0
  539. #define t2_trivial_io_bw 0
  540. #define t2_trivial_io_lq 0
  541. #define t2_trivial_iounmap 1
  542. #include <asm/io_trivial.h>
  543. #ifdef __IO_EXTERN_INLINE
  544. #undef __EXTERN_INLINE
  545. #undef __IO_EXTERN_INLINE
  546. #endif
  547. #endif /* __KERNEL__ */
  548. #endif /* __ALPHA_T2__H__ */