core_lca.c 14 KB

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