core_lca.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /*
  2. * linux/arch/alpha/kernel/core_lca.c
  3. *
  4. * Written by David Mosberger (davidm@cs.arizona.edu) with some code
  5. * taken from Dave Rusling's (david.rusling@reo.mts.dec.com) 32-bit
  6. * bios code.
  7. *
  8. * Code common to all LCA core logic chips.
  9. */
  10. #define __EXTERN_INLINE inline
  11. #include <asm/io.h>
  12. #include <asm/core_lca.h>
  13. #undef __EXTERN_INLINE
  14. #include <linux/types.h>
  15. #include <linux/pci.h>
  16. #include <linux/init.h>
  17. #include <linux/tty.h>
  18. #include <asm/ptrace.h>
  19. #include <asm/irq_regs.h>
  20. #include <asm/smp.h>
  21. #include "proto.h"
  22. #include "pci_impl.h"
  23. /*
  24. * BIOS32-style PCI interface:
  25. */
  26. /*
  27. * Machine check reasons. Defined according to PALcode sources
  28. * (osf.h and platform.h).
  29. */
  30. #define MCHK_K_TPERR 0x0080
  31. #define MCHK_K_TCPERR 0x0082
  32. #define MCHK_K_HERR 0x0084
  33. #define MCHK_K_ECC_C 0x0086
  34. #define MCHK_K_ECC_NC 0x0088
  35. #define MCHK_K_UNKNOWN 0x008A
  36. #define MCHK_K_CACKSOFT 0x008C
  37. #define MCHK_K_BUGCHECK 0x008E
  38. #define MCHK_K_OS_BUGCHECK 0x0090
  39. #define MCHK_K_DCPERR 0x0092
  40. #define MCHK_K_ICPERR 0x0094
  41. /*
  42. * Platform-specific machine-check reasons:
  43. */
  44. #define MCHK_K_SIO_SERR 0x204 /* all platforms so far */
  45. #define MCHK_K_SIO_IOCHK 0x206 /* all platforms so far */
  46. #define MCHK_K_DCSR 0x208 /* all but Noname */
  47. /*
  48. * Given a bus, device, and function number, compute resulting
  49. * configuration space address and setup the LCA_IOC_CONF register
  50. * accordingly. It is therefore not safe to have concurrent
  51. * invocations to configuration space access routines, but there
  52. * really shouldn't be any need for this.
  53. *
  54. * Type 0:
  55. *
  56. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  57. * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
  58. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  59. * | | | | | | | | | | | | | | | | | | | | | | | |F|F|F|R|R|R|R|R|R|0|0|
  60. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  61. *
  62. * 31:11 Device select bit.
  63. * 10:8 Function number
  64. * 7:2 Register number
  65. *
  66. * Type 1:
  67. *
  68. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  69. * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
  70. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  71. * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  72. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  73. *
  74. * 31:24 reserved
  75. * 23:16 bus number (8 bits = 128 possible buses)
  76. * 15:11 Device number (5 bits)
  77. * 10:8 function number
  78. * 7:2 register number
  79. *
  80. * Notes:
  81. * The function number selects which function of a multi-function device
  82. * (e.g., SCSI and Ethernet).
  83. *
  84. * The register selects a DWORD (32 bit) register offset. Hence it
  85. * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  86. * bits.
  87. */
  88. static int
  89. mk_conf_addr(struct pci_bus *pbus, unsigned int device_fn, int where,
  90. unsigned long *pci_addr)
  91. {
  92. unsigned long addr;
  93. u8 bus = pbus->number;
  94. if (bus == 0) {
  95. int device = device_fn >> 3;
  96. int func = device_fn & 0x7;
  97. /* Type 0 configuration cycle. */
  98. if (device > 12) {
  99. return -1;
  100. }
  101. *(vulp)LCA_IOC_CONF = 0;
  102. addr = (1 << (11 + device)) | (func << 8) | where;
  103. } else {
  104. /* Type 1 configuration cycle. */
  105. *(vulp)LCA_IOC_CONF = 1;
  106. addr = (bus << 16) | (device_fn << 8) | where;
  107. }
  108. *pci_addr = addr;
  109. return 0;
  110. }
  111. static unsigned int
  112. conf_read(unsigned long addr)
  113. {
  114. unsigned long flags, code, stat0;
  115. unsigned int value;
  116. local_irq_save(flags);
  117. /* Reset status register to avoid losing errors. */
  118. stat0 = *(vulp)LCA_IOC_STAT0;
  119. *(vulp)LCA_IOC_STAT0 = stat0;
  120. mb();
  121. /* Access configuration space. */
  122. value = *(vuip)addr;
  123. draina();
  124. stat0 = *(vulp)LCA_IOC_STAT0;
  125. if (stat0 & LCA_IOC_STAT0_ERR) {
  126. code = ((stat0 >> LCA_IOC_STAT0_CODE_SHIFT)
  127. & LCA_IOC_STAT0_CODE_MASK);
  128. if (code != 1) {
  129. printk("lca.c:conf_read: got stat0=%lx\n", stat0);
  130. }
  131. /* Reset error status. */
  132. *(vulp)LCA_IOC_STAT0 = stat0;
  133. mb();
  134. /* Reset machine check. */
  135. wrmces(0x7);
  136. value = 0xffffffff;
  137. }
  138. local_irq_restore(flags);
  139. return value;
  140. }
  141. static void
  142. conf_write(unsigned long addr, unsigned int value)
  143. {
  144. unsigned long flags, code, stat0;
  145. local_irq_save(flags); /* avoid getting hit by machine check */
  146. /* Reset status register to avoid losing errors. */
  147. stat0 = *(vulp)LCA_IOC_STAT0;
  148. *(vulp)LCA_IOC_STAT0 = stat0;
  149. mb();
  150. /* Access configuration space. */
  151. *(vuip)addr = value;
  152. draina();
  153. stat0 = *(vulp)LCA_IOC_STAT0;
  154. if (stat0 & LCA_IOC_STAT0_ERR) {
  155. code = ((stat0 >> LCA_IOC_STAT0_CODE_SHIFT)
  156. & LCA_IOC_STAT0_CODE_MASK);
  157. if (code != 1) {
  158. printk("lca.c:conf_write: got stat0=%lx\n", stat0);
  159. }
  160. /* Reset error status. */
  161. *(vulp)LCA_IOC_STAT0 = stat0;
  162. mb();
  163. /* Reset machine check. */
  164. wrmces(0x7);
  165. }
  166. local_irq_restore(flags);
  167. }
  168. static int
  169. lca_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  170. int size, u32 *value)
  171. {
  172. unsigned long addr, pci_addr;
  173. long mask;
  174. int shift;
  175. if (mk_conf_addr(bus, devfn, where, &pci_addr))
  176. return PCIBIOS_DEVICE_NOT_FOUND;
  177. shift = (where & 3) * 8;
  178. mask = (size - 1) * 8;
  179. addr = (pci_addr << 5) + mask + LCA_CONF;
  180. *value = conf_read(addr) >> (shift);
  181. return PCIBIOS_SUCCESSFUL;
  182. }
  183. static int
  184. lca_write_config(struct pci_bus *bus, unsigned int devfn, int where, int size,
  185. u32 value)
  186. {
  187. unsigned long addr, pci_addr;
  188. long mask;
  189. if (mk_conf_addr(bus, devfn, where, &pci_addr))
  190. return PCIBIOS_DEVICE_NOT_FOUND;
  191. mask = (size - 1) * 8;
  192. addr = (pci_addr << 5) + mask + LCA_CONF;
  193. conf_write(addr, value << ((where & 3) * 8));
  194. return PCIBIOS_SUCCESSFUL;
  195. }
  196. struct pci_ops lca_pci_ops =
  197. {
  198. .read = lca_read_config,
  199. .write = lca_write_config,
  200. };
  201. void
  202. lca_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
  203. {
  204. wmb();
  205. *(vulp)LCA_IOC_TBIA = 0;
  206. mb();
  207. }
  208. void __init
  209. lca_init_arch(void)
  210. {
  211. struct pci_controller *hose;
  212. /*
  213. * Create our single hose.
  214. */
  215. pci_isa_hose = hose = alloc_pci_controller();
  216. hose->io_space = &ioport_resource;
  217. hose->mem_space = &iomem_resource;
  218. hose->index = 0;
  219. hose->sparse_mem_base = LCA_SPARSE_MEM - IDENT_ADDR;
  220. hose->dense_mem_base = LCA_DENSE_MEM - IDENT_ADDR;
  221. hose->sparse_io_base = LCA_IO - IDENT_ADDR;
  222. hose->dense_io_base = 0;
  223. /*
  224. * Set up the PCI to main memory translation windows.
  225. *
  226. * Mimic the SRM settings for the direct-map window.
  227. * Window 0 is scatter-gather 8MB at 8MB (for isa).
  228. * Window 1 is direct access 1GB at 1GB.
  229. *
  230. * Note that we do not try to save any of the DMA window CSRs
  231. * before setting them, since we cannot read those CSRs on LCA.
  232. */
  233. hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
  234. hose->sg_pci = NULL;
  235. __direct_map_base = 0x40000000;
  236. __direct_map_size = 0x40000000;
  237. *(vulp)LCA_IOC_W_BASE0 = hose->sg_isa->dma_base | (3UL << 32);
  238. *(vulp)LCA_IOC_W_MASK0 = (hose->sg_isa->size - 1) & 0xfff00000;
  239. *(vulp)LCA_IOC_T_BASE0 = virt_to_phys(hose->sg_isa->ptes);
  240. *(vulp)LCA_IOC_W_BASE1 = __direct_map_base | (2UL << 32);
  241. *(vulp)LCA_IOC_W_MASK1 = (__direct_map_size - 1) & 0xfff00000;
  242. *(vulp)LCA_IOC_T_BASE1 = 0;
  243. *(vulp)LCA_IOC_TB_ENA = 0x80;
  244. lca_pci_tbi(hose, 0, -1);
  245. /*
  246. * Disable PCI parity for now. The NCR53c810 chip has
  247. * troubles meeting the PCI spec which results in
  248. * data parity errors.
  249. */
  250. *(vulp)LCA_IOC_PAR_DIS = 1UL<<5;
  251. /*
  252. * Finally, set up for restoring the correct HAE if using SRM.
  253. * Again, since we cannot read many of the CSRs on the LCA,
  254. * one of which happens to be the HAE, we save the value that
  255. * the SRM will expect...
  256. */
  257. if (alpha_using_srm)
  258. srm_hae = 0x80000000UL;
  259. }
  260. /*
  261. * Constants used during machine-check handling. I suppose these
  262. * could be moved into lca.h but I don't see much reason why anybody
  263. * else would want to use them.
  264. */
  265. #define ESR_EAV (1UL<< 0) /* error address valid */
  266. #define ESR_CEE (1UL<< 1) /* correctable error */
  267. #define ESR_UEE (1UL<< 2) /* uncorrectable error */
  268. #define ESR_WRE (1UL<< 3) /* write-error */
  269. #define ESR_SOR (1UL<< 4) /* error source */
  270. #define ESR_CTE (1UL<< 7) /* cache-tag error */
  271. #define ESR_MSE (1UL<< 9) /* multiple soft errors */
  272. #define ESR_MHE (1UL<<10) /* multiple hard errors */
  273. #define ESR_NXM (1UL<<12) /* non-existent memory */
  274. #define IOC_ERR ( 1<<4) /* ioc logs an error */
  275. #define IOC_CMD_SHIFT 0
  276. #define IOC_CMD (0xf<<IOC_CMD_SHIFT)
  277. #define IOC_CODE_SHIFT 8
  278. #define IOC_CODE (0xf<<IOC_CODE_SHIFT)
  279. #define IOC_LOST ( 1<<5)
  280. #define IOC_P_NBR ((__u32) ~((1<<13) - 1))
  281. static void
  282. mem_error(unsigned long esr, unsigned long ear)
  283. {
  284. printk(" %s %s error to %s occurred at address %x\n",
  285. ((esr & ESR_CEE) ? "Correctable" :
  286. (esr & ESR_UEE) ? "Uncorrectable" : "A"),
  287. (esr & ESR_WRE) ? "write" : "read",
  288. (esr & ESR_SOR) ? "memory" : "b-cache",
  289. (unsigned) (ear & 0x1ffffff8));
  290. if (esr & ESR_CTE) {
  291. printk(" A b-cache tag parity error was detected.\n");
  292. }
  293. if (esr & ESR_MSE) {
  294. printk(" Several other correctable errors occurred.\n");
  295. }
  296. if (esr & ESR_MHE) {
  297. printk(" Several other uncorrectable errors occurred.\n");
  298. }
  299. if (esr & ESR_NXM) {
  300. printk(" Attempted to access non-existent memory.\n");
  301. }
  302. }
  303. static void
  304. ioc_error(__u32 stat0, __u32 stat1)
  305. {
  306. static const char * const pci_cmd[] = {
  307. "Interrupt Acknowledge", "Special", "I/O Read", "I/O Write",
  308. "Rsvd 1", "Rsvd 2", "Memory Read", "Memory Write", "Rsvd3",
  309. "Rsvd4", "Configuration Read", "Configuration Write",
  310. "Memory Read Multiple", "Dual Address", "Memory Read Line",
  311. "Memory Write and Invalidate"
  312. };
  313. static const char * const err_name[] = {
  314. "exceeded retry limit", "no device", "bad data parity",
  315. "target abort", "bad address parity", "page table read error",
  316. "invalid page", "data error"
  317. };
  318. unsigned code = (stat0 & IOC_CODE) >> IOC_CODE_SHIFT;
  319. unsigned cmd = (stat0 & IOC_CMD) >> IOC_CMD_SHIFT;
  320. printk(" %s initiated PCI %s cycle to address %x"
  321. " failed due to %s.\n",
  322. code > 3 ? "PCI" : "CPU", pci_cmd[cmd], stat1, err_name[code]);
  323. if (code == 5 || code == 6) {
  324. printk(" (Error occurred at PCI memory address %x.)\n",
  325. (stat0 & ~IOC_P_NBR));
  326. }
  327. if (stat0 & IOC_LOST) {
  328. printk(" Other PCI errors occurred simultaneously.\n");
  329. }
  330. }
  331. void
  332. lca_machine_check(unsigned long vector, unsigned long la_ptr)
  333. {
  334. const char * reason;
  335. union el_lca el;
  336. el.c = (struct el_common *) la_ptr;
  337. wrmces(rdmces()); /* reset machine check pending flag */
  338. printk(KERN_CRIT "LCA machine check: vector=%#lx pc=%#lx code=%#x\n",
  339. vector, get_irq_regs()->pc, (unsigned int) el.c->code);
  340. /*
  341. * The first quadword after the common header always seems to
  342. * be the machine check reason---don't know why this isn't
  343. * part of the common header instead. In the case of a long
  344. * logout frame, the upper 32 bits is the machine check
  345. * revision level, which we ignore for now.
  346. */
  347. switch ((unsigned int) el.c->code) {
  348. case MCHK_K_TPERR: reason = "tag parity error"; break;
  349. case MCHK_K_TCPERR: reason = "tag control parity error"; break;
  350. case MCHK_K_HERR: reason = "access to non-existent memory"; break;
  351. case MCHK_K_ECC_C: reason = "correctable ECC error"; break;
  352. case MCHK_K_ECC_NC: reason = "non-correctable ECC error"; break;
  353. case MCHK_K_CACKSOFT: reason = "MCHK_K_CACKSOFT"; break;
  354. case MCHK_K_BUGCHECK: reason = "illegal exception in PAL mode"; break;
  355. case MCHK_K_OS_BUGCHECK: reason = "callsys in kernel mode"; break;
  356. case MCHK_K_DCPERR: reason = "d-cache parity error"; break;
  357. case MCHK_K_ICPERR: reason = "i-cache parity error"; break;
  358. case MCHK_K_SIO_SERR: reason = "SIO SERR occurred on PCI bus"; break;
  359. case MCHK_K_SIO_IOCHK: reason = "SIO IOCHK occurred on ISA bus"; break;
  360. case MCHK_K_DCSR: reason = "MCHK_K_DCSR"; break;
  361. case MCHK_K_UNKNOWN:
  362. default: reason = "unknown"; break;
  363. }
  364. switch (el.c->size) {
  365. case sizeof(struct el_lca_mcheck_short):
  366. printk(KERN_CRIT
  367. " Reason: %s (short frame%s, dc_stat=%#lx):\n",
  368. reason, el.c->retry ? ", retryable" : "",
  369. el.s->dc_stat);
  370. if (el.s->esr & ESR_EAV) {
  371. mem_error(el.s->esr, el.s->ear);
  372. }
  373. if (el.s->ioc_stat0 & IOC_ERR) {
  374. ioc_error(el.s->ioc_stat0, el.s->ioc_stat1);
  375. }
  376. break;
  377. case sizeof(struct el_lca_mcheck_long):
  378. printk(KERN_CRIT " Reason: %s (long frame%s):\n",
  379. reason, el.c->retry ? ", retryable" : "");
  380. printk(KERN_CRIT
  381. " reason: %#lx exc_addr: %#lx dc_stat: %#lx\n",
  382. el.l->pt[0], el.l->exc_addr, el.l->dc_stat);
  383. printk(KERN_CRIT " car: %#lx\n", el.l->car);
  384. if (el.l->esr & ESR_EAV) {
  385. mem_error(el.l->esr, el.l->ear);
  386. }
  387. if (el.l->ioc_stat0 & IOC_ERR) {
  388. ioc_error(el.l->ioc_stat0, el.l->ioc_stat1);
  389. }
  390. break;
  391. default:
  392. printk(KERN_CRIT " Unknown errorlog size %d\n", el.c->size);
  393. }
  394. /* Dump the logout area to give all info. */
  395. #ifdef CONFIG_VERBOSE_MCHECK
  396. if (alpha_verbose_mcheck > 1) {
  397. unsigned long * ptr = (unsigned long *) la_ptr;
  398. long i;
  399. for (i = 0; i < el.c->size / sizeof(long); i += 2) {
  400. printk(KERN_CRIT " +%8lx %016lx %016lx\n",
  401. i*sizeof(long), ptr[i], ptr[i+1]);
  402. }
  403. }
  404. #endif /* CONFIG_VERBOSE_MCHECK */
  405. }
  406. /*
  407. * The following routines are needed to support the SPEED changing
  408. * necessary to successfully manage the thermal problem on the AlphaBook1.
  409. */
  410. void
  411. lca_clock_print(void)
  412. {
  413. long pmr_reg;
  414. pmr_reg = LCA_READ_PMR;
  415. printk("Status of clock control:\n");
  416. printk("\tPrimary clock divisor\t0x%lx\n", LCA_GET_PRIMARY(pmr_reg));
  417. printk("\tOverride clock divisor\t0x%lx\n", LCA_GET_OVERRIDE(pmr_reg));
  418. printk("\tInterrupt override is %s\n",
  419. (pmr_reg & LCA_PMR_INTO) ? "on" : "off");
  420. printk("\tDMA override is %s\n",
  421. (pmr_reg & LCA_PMR_DMAO) ? "on" : "off");
  422. }
  423. int
  424. lca_get_clock(void)
  425. {
  426. long pmr_reg;
  427. pmr_reg = LCA_READ_PMR;
  428. return(LCA_GET_PRIMARY(pmr_reg));
  429. }
  430. void
  431. lca_clock_fiddle(int divisor)
  432. {
  433. long pmr_reg;
  434. pmr_reg = LCA_READ_PMR;
  435. LCA_SET_PRIMARY_CLOCK(pmr_reg, divisor);
  436. /* lca_norm_clock = divisor; */
  437. LCA_WRITE_PMR(pmr_reg);
  438. mb();
  439. }