core_cia.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. /*
  2. * linux/arch/alpha/kernel/core_cia.c
  3. *
  4. * Written by David A Rusling (david.rusling@reo.mts.dec.com).
  5. * December 1995.
  6. *
  7. * Copyright (C) 1995 David A Rusling
  8. * Copyright (C) 1997, 1998 Jay Estabrook
  9. * Copyright (C) 1998, 1999, 2000 Richard Henderson
  10. *
  11. * Code common to all CIA core logic chips.
  12. */
  13. #define __EXTERN_INLINE inline
  14. #include <asm/io.h>
  15. #include <asm/core_cia.h>
  16. #undef __EXTERN_INLINE
  17. #include <linux/types.h>
  18. #include <linux/pci.h>
  19. #include <linux/sched.h>
  20. #include <linux/init.h>
  21. #include <linux/bootmem.h>
  22. #include <asm/ptrace.h>
  23. #include "proto.h"
  24. #include "pci_impl.h"
  25. /*
  26. * NOTE: Herein lie back-to-back mb instructions. They are magic.
  27. * One plausible explanation is that the i/o controller does not properly
  28. * handle the system transaction. Another involves timing. Ho hum.
  29. */
  30. #define DEBUG_CONFIG 0
  31. #if DEBUG_CONFIG
  32. # define DBGC(args) printk args
  33. #else
  34. # define DBGC(args)
  35. #endif
  36. #define vip volatile int *
  37. /*
  38. * Given a bus, device, and function number, compute resulting
  39. * configuration space address. It is therefore not safe to have
  40. * concurrent invocations to configuration space access routines, but
  41. * there really shouldn't be any need for this.
  42. *
  43. * Type 0:
  44. *
  45. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  46. * 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
  47. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  48. * | | |D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|0|
  49. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  50. *
  51. * 31:11 Device select bit.
  52. * 10:8 Function number
  53. * 7:2 Register number
  54. *
  55. * Type 1:
  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. * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  61. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  62. *
  63. * 31:24 reserved
  64. * 23:16 bus number (8 bits = 128 possible buses)
  65. * 15:11 Device number (5 bits)
  66. * 10:8 function number
  67. * 7:2 register number
  68. *
  69. * Notes:
  70. * The function number selects which function of a multi-function device
  71. * (e.g., SCSI and Ethernet).
  72. *
  73. * The register selects a DWORD (32 bit) register offset. Hence it
  74. * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  75. * bits.
  76. */
  77. static int
  78. mk_conf_addr(struct pci_bus *bus_dev, unsigned int device_fn, int where,
  79. unsigned long *pci_addr, unsigned char *type1)
  80. {
  81. u8 bus = bus_dev->number;
  82. *type1 = (bus != 0);
  83. *pci_addr = (bus << 16) | (device_fn << 8) | where;
  84. DBGC(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x,"
  85. " returning address 0x%p\n"
  86. bus, device_fn, where, *pci_addr));
  87. return 0;
  88. }
  89. static unsigned int
  90. conf_read(unsigned long addr, unsigned char type1)
  91. {
  92. unsigned long flags;
  93. int stat0, value;
  94. int cia_cfg = 0;
  95. DBGC(("conf_read(addr=0x%lx, type1=%d) ", addr, type1));
  96. local_irq_save(flags);
  97. /* Reset status register to avoid losing errors. */
  98. stat0 = *(vip)CIA_IOC_CIA_ERR;
  99. *(vip)CIA_IOC_CIA_ERR = stat0;
  100. mb();
  101. *(vip)CIA_IOC_CIA_ERR; /* re-read to force write */
  102. /* If Type1 access, must set CIA CFG. */
  103. if (type1) {
  104. cia_cfg = *(vip)CIA_IOC_CFG;
  105. *(vip)CIA_IOC_CFG = (cia_cfg & ~3) | 1;
  106. mb();
  107. *(vip)CIA_IOC_CFG;
  108. }
  109. mb();
  110. draina();
  111. mcheck_expected(0) = 1;
  112. mcheck_taken(0) = 0;
  113. mb();
  114. /* Access configuration space. */
  115. value = *(vip)addr;
  116. mb();
  117. mb(); /* magic */
  118. if (mcheck_taken(0)) {
  119. mcheck_taken(0) = 0;
  120. value = 0xffffffff;
  121. mb();
  122. }
  123. mcheck_expected(0) = 0;
  124. mb();
  125. /* If Type1 access, must reset IOC CFG so normal IO space ops work. */
  126. if (type1) {
  127. *(vip)CIA_IOC_CFG = cia_cfg;
  128. mb();
  129. *(vip)CIA_IOC_CFG;
  130. }
  131. local_irq_restore(flags);
  132. DBGC(("done\n"));
  133. return value;
  134. }
  135. static void
  136. conf_write(unsigned long addr, unsigned int value, unsigned char type1)
  137. {
  138. unsigned long flags;
  139. int stat0, cia_cfg = 0;
  140. DBGC(("conf_write(addr=0x%lx, type1=%d) ", addr, type1));
  141. local_irq_save(flags);
  142. /* Reset status register to avoid losing errors. */
  143. stat0 = *(vip)CIA_IOC_CIA_ERR;
  144. *(vip)CIA_IOC_CIA_ERR = stat0;
  145. mb();
  146. *(vip)CIA_IOC_CIA_ERR; /* re-read to force write */
  147. /* If Type1 access, must set CIA CFG. */
  148. if (type1) {
  149. cia_cfg = *(vip)CIA_IOC_CFG;
  150. *(vip)CIA_IOC_CFG = (cia_cfg & ~3) | 1;
  151. mb();
  152. *(vip)CIA_IOC_CFG;
  153. }
  154. mb();
  155. draina();
  156. mcheck_expected(0) = 1;
  157. mcheck_taken(0) = 0;
  158. mb();
  159. /* Access configuration space. */
  160. *(vip)addr = value;
  161. mb();
  162. *(vip)addr; /* read back to force the write */
  163. mcheck_expected(0) = 0;
  164. mb();
  165. /* If Type1 access, must reset IOC CFG so normal IO space ops work. */
  166. if (type1) {
  167. *(vip)CIA_IOC_CFG = cia_cfg;
  168. mb();
  169. *(vip)CIA_IOC_CFG;
  170. }
  171. local_irq_restore(flags);
  172. DBGC(("done\n"));
  173. }
  174. static int
  175. cia_read_config(struct pci_bus *bus, unsigned int devfn, int where, int size,
  176. u32 *value)
  177. {
  178. unsigned long addr, pci_addr;
  179. long mask;
  180. unsigned char type1;
  181. int shift;
  182. if (mk_conf_addr(bus, devfn, where, &pci_addr, &type1))
  183. return PCIBIOS_DEVICE_NOT_FOUND;
  184. mask = (size - 1) * 8;
  185. shift = (where & 3) * 8;
  186. addr = (pci_addr << 5) + mask + CIA_CONF;
  187. *value = conf_read(addr, type1) >> (shift);
  188. return PCIBIOS_SUCCESSFUL;
  189. }
  190. static int
  191. cia_write_config(struct pci_bus *bus, unsigned int devfn, int where, int size,
  192. u32 value)
  193. {
  194. unsigned long addr, pci_addr;
  195. long mask;
  196. unsigned char type1;
  197. if (mk_conf_addr(bus, devfn, where, &pci_addr, &type1))
  198. return PCIBIOS_DEVICE_NOT_FOUND;
  199. mask = (size - 1) * 8;
  200. addr = (pci_addr << 5) + mask + CIA_CONF;
  201. conf_write(addr, value << ((where & 3) * 8), type1);
  202. return PCIBIOS_SUCCESSFUL;
  203. }
  204. struct pci_ops cia_pci_ops =
  205. {
  206. .read = cia_read_config,
  207. .write = cia_write_config,
  208. };
  209. /*
  210. * CIA Pass 1 and PYXIS Pass 1 and 2 have a broken scatter-gather tlb.
  211. * It cannot be invalidated. Rather than hard code the pass numbers,
  212. * actually try the tbia to see if it works.
  213. */
  214. void
  215. cia_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
  216. {
  217. wmb();
  218. *(vip)CIA_IOC_PCI_TBIA = 3; /* Flush all locked and unlocked. */
  219. mb();
  220. *(vip)CIA_IOC_PCI_TBIA;
  221. }
  222. /*
  223. * On PYXIS, even if the tbia works, we cannot use it. It effectively locks
  224. * the chip (as well as direct write to the tag registers) if there is a
  225. * SG DMA operation in progress. This is true at least for PYXIS rev. 1,
  226. * so always use the method below.
  227. */
  228. /*
  229. * This is the method NT and NetBSD use.
  230. *
  231. * Allocate mappings, and put the chip into DMA loopback mode to read a
  232. * garbage page. This works by causing TLB misses, causing old entries to
  233. * be purged to make room for the new entries coming in for the garbage page.
  234. */
  235. #define CIA_BROKEN_TBIA_BASE 0x30000000
  236. #define CIA_BROKEN_TBIA_SIZE 1024
  237. /* Always called with interrupts disabled */
  238. void
  239. cia_pci_tbi_try2(struct pci_controller *hose,
  240. dma_addr_t start, dma_addr_t end)
  241. {
  242. void __iomem *bus_addr;
  243. int ctrl;
  244. /* Put the chip into PCI loopback mode. */
  245. mb();
  246. ctrl = *(vip)CIA_IOC_CIA_CTRL;
  247. *(vip)CIA_IOC_CIA_CTRL = ctrl | CIA_CTRL_PCI_LOOP_EN;
  248. mb();
  249. *(vip)CIA_IOC_CIA_CTRL;
  250. mb();
  251. /* Read from PCI dense memory space at TBI_ADDR, skipping 32k on
  252. each read. This forces SG TLB misses. NetBSD claims that the
  253. TLB entries are not quite LRU, meaning that we need to read more
  254. times than there are actual tags. The 2117x docs claim strict
  255. round-robin. Oh well, we've come this far... */
  256. /* Even better - as seen on the PYXIS rev 1 the TLB tags 0-3 can
  257. be filled by the TLB misses *only once* after being invalidated
  258. (by tbia or direct write). Next misses won't update them even
  259. though the lock bits are cleared. Tags 4-7 are "quite LRU" though,
  260. so use them and read at window 3 base exactly 4 times. Reading
  261. more sometimes makes the chip crazy. -ink */
  262. bus_addr = cia_ioremap(CIA_BROKEN_TBIA_BASE, 32768 * 4);
  263. cia_readl(bus_addr + 0x00000);
  264. cia_readl(bus_addr + 0x08000);
  265. cia_readl(bus_addr + 0x10000);
  266. cia_readl(bus_addr + 0x18000);
  267. cia_iounmap(bus_addr);
  268. /* Restore normal PCI operation. */
  269. mb();
  270. *(vip)CIA_IOC_CIA_CTRL = ctrl;
  271. mb();
  272. *(vip)CIA_IOC_CIA_CTRL;
  273. mb();
  274. }
  275. static inline void
  276. cia_prepare_tbia_workaround(int window)
  277. {
  278. unsigned long *ppte, pte;
  279. long i;
  280. /* Use minimal 1K map. */
  281. ppte = __alloc_bootmem(CIA_BROKEN_TBIA_SIZE, 32768, 0);
  282. pte = (virt_to_phys(ppte) >> (PAGE_SHIFT - 1)) | 1;
  283. for (i = 0; i < CIA_BROKEN_TBIA_SIZE / sizeof(unsigned long); ++i)
  284. ppte[i] = pte;
  285. *(vip)CIA_IOC_PCI_Wn_BASE(window) = CIA_BROKEN_TBIA_BASE | 3;
  286. *(vip)CIA_IOC_PCI_Wn_MASK(window)
  287. = (CIA_BROKEN_TBIA_SIZE*1024 - 1) & 0xfff00000;
  288. *(vip)CIA_IOC_PCI_Tn_BASE(window) = virt_to_phys(ppte) >> 2;
  289. }
  290. static void __init
  291. verify_tb_operation(void)
  292. {
  293. static int page[PAGE_SIZE/4]
  294. __attribute__((aligned(PAGE_SIZE)))
  295. __initdata = { 0 };
  296. struct pci_iommu_arena *arena = pci_isa_hose->sg_isa;
  297. int ctrl, addr0, tag0, pte0, data0;
  298. int temp, use_tbia_try2 = 0;
  299. void __iomem *bus_addr;
  300. /* pyxis -- tbia is broken */
  301. if (pci_isa_hose->dense_io_base)
  302. use_tbia_try2 = 1;
  303. /* Put the chip into PCI loopback mode. */
  304. mb();
  305. ctrl = *(vip)CIA_IOC_CIA_CTRL;
  306. *(vip)CIA_IOC_CIA_CTRL = ctrl | CIA_CTRL_PCI_LOOP_EN;
  307. mb();
  308. *(vip)CIA_IOC_CIA_CTRL;
  309. mb();
  310. /* Write a valid entry directly into the TLB registers. */
  311. addr0 = arena->dma_base;
  312. tag0 = addr0 | 1;
  313. pte0 = (virt_to_phys(page) >> (PAGE_SHIFT - 1)) | 1;
  314. *(vip)CIA_IOC_TB_TAGn(0) = tag0;
  315. *(vip)CIA_IOC_TB_TAGn(1) = 0;
  316. *(vip)CIA_IOC_TB_TAGn(2) = 0;
  317. *(vip)CIA_IOC_TB_TAGn(3) = 0;
  318. *(vip)CIA_IOC_TB_TAGn(4) = 0;
  319. *(vip)CIA_IOC_TB_TAGn(5) = 0;
  320. *(vip)CIA_IOC_TB_TAGn(6) = 0;
  321. *(vip)CIA_IOC_TB_TAGn(7) = 0;
  322. *(vip)CIA_IOC_TBn_PAGEm(0,0) = pte0;
  323. *(vip)CIA_IOC_TBn_PAGEm(0,1) = 0;
  324. *(vip)CIA_IOC_TBn_PAGEm(0,2) = 0;
  325. *(vip)CIA_IOC_TBn_PAGEm(0,3) = 0;
  326. mb();
  327. /* Get a usable bus address */
  328. bus_addr = cia_ioremap(addr0, 8*PAGE_SIZE);
  329. /* First, verify we can read back what we've written. If
  330. this fails, we can't be sure of any of the other testing
  331. we're going to do, so bail. */
  332. /* ??? Actually, we could do the work with machine checks.
  333. By passing this register update test, we pretty much
  334. guarantee that cia_pci_tbi_try1 works. If this test
  335. fails, cia_pci_tbi_try2 might still work. */
  336. temp = *(vip)CIA_IOC_TB_TAGn(0);
  337. if (temp != tag0) {
  338. printk("pci: failed tb register update test "
  339. "(tag0 %#x != %#x)\n", temp, tag0);
  340. goto failed;
  341. }
  342. temp = *(vip)CIA_IOC_TB_TAGn(1);
  343. if (temp != 0) {
  344. printk("pci: failed tb register update test "
  345. "(tag1 %#x != 0)\n", temp);
  346. goto failed;
  347. }
  348. temp = *(vip)CIA_IOC_TBn_PAGEm(0,0);
  349. if (temp != pte0) {
  350. printk("pci: failed tb register update test "
  351. "(pte0 %#x != %#x)\n", temp, pte0);
  352. goto failed;
  353. }
  354. printk("pci: passed tb register update test\n");
  355. /* Second, verify we can actually do I/O through this entry. */
  356. data0 = 0xdeadbeef;
  357. page[0] = data0;
  358. mcheck_expected(0) = 1;
  359. mcheck_taken(0) = 0;
  360. mb();
  361. temp = cia_readl(bus_addr);
  362. mb();
  363. mcheck_expected(0) = 0;
  364. mb();
  365. if (mcheck_taken(0)) {
  366. printk("pci: failed sg loopback i/o read test (mcheck)\n");
  367. goto failed;
  368. }
  369. if (temp != data0) {
  370. printk("pci: failed sg loopback i/o read test "
  371. "(%#x != %#x)\n", temp, data0);
  372. goto failed;
  373. }
  374. printk("pci: passed sg loopback i/o read test\n");
  375. /* Third, try to invalidate the TLB. */
  376. if (! use_tbia_try2) {
  377. cia_pci_tbi(arena->hose, 0, -1);
  378. temp = *(vip)CIA_IOC_TB_TAGn(0);
  379. if (temp & 1) {
  380. use_tbia_try2 = 1;
  381. printk("pci: failed tbia test; workaround available\n");
  382. } else {
  383. printk("pci: passed tbia test\n");
  384. }
  385. }
  386. /* Fourth, verify the TLB snoops the EV5's caches when
  387. doing a tlb fill. */
  388. data0 = 0x5adda15e;
  389. page[0] = data0;
  390. arena->ptes[4] = pte0;
  391. mcheck_expected(0) = 1;
  392. mcheck_taken(0) = 0;
  393. mb();
  394. temp = cia_readl(bus_addr + 4*PAGE_SIZE);
  395. mb();
  396. mcheck_expected(0) = 0;
  397. mb();
  398. if (mcheck_taken(0)) {
  399. printk("pci: failed pte write cache snoop test (mcheck)\n");
  400. goto failed;
  401. }
  402. if (temp != data0) {
  403. printk("pci: failed pte write cache snoop test "
  404. "(%#x != %#x)\n", temp, data0);
  405. goto failed;
  406. }
  407. printk("pci: passed pte write cache snoop test\n");
  408. /* Fifth, verify that a previously invalid PTE entry gets
  409. filled from the page table. */
  410. data0 = 0xabcdef12;
  411. page[0] = data0;
  412. arena->ptes[5] = pte0;
  413. mcheck_expected(0) = 1;
  414. mcheck_taken(0) = 0;
  415. mb();
  416. temp = cia_readl(bus_addr + 5*PAGE_SIZE);
  417. mb();
  418. mcheck_expected(0) = 0;
  419. mb();
  420. if (mcheck_taken(0)) {
  421. printk("pci: failed valid tag invalid pte reload test "
  422. "(mcheck; workaround available)\n");
  423. /* Work around this bug by aligning new allocations
  424. on 4 page boundaries. */
  425. arena->align_entry = 4;
  426. } else if (temp != data0) {
  427. printk("pci: failed valid tag invalid pte reload test "
  428. "(%#x != %#x)\n", temp, data0);
  429. goto failed;
  430. } else {
  431. printk("pci: passed valid tag invalid pte reload test\n");
  432. }
  433. /* Sixth, verify machine checks are working. Test invalid
  434. pte under the same valid tag as we used above. */
  435. mcheck_expected(0) = 1;
  436. mcheck_taken(0) = 0;
  437. mb();
  438. temp = cia_readl(bus_addr + 6*PAGE_SIZE);
  439. mb();
  440. mcheck_expected(0) = 0;
  441. mb();
  442. printk("pci: %s pci machine check test\n",
  443. mcheck_taken(0) ? "passed" : "failed");
  444. /* Clean up after the tests. */
  445. arena->ptes[4] = 0;
  446. arena->ptes[5] = 0;
  447. if (use_tbia_try2) {
  448. alpha_mv.mv_pci_tbi = cia_pci_tbi_try2;
  449. /* Tags 0-3 must be disabled if we use this workaraund. */
  450. wmb();
  451. *(vip)CIA_IOC_TB_TAGn(0) = 2;
  452. *(vip)CIA_IOC_TB_TAGn(1) = 2;
  453. *(vip)CIA_IOC_TB_TAGn(2) = 2;
  454. *(vip)CIA_IOC_TB_TAGn(3) = 2;
  455. printk("pci: tbia workaround enabled\n");
  456. }
  457. alpha_mv.mv_pci_tbi(arena->hose, 0, -1);
  458. exit:
  459. /* unmap the bus addr */
  460. cia_iounmap(bus_addr);
  461. /* Restore normal PCI operation. */
  462. mb();
  463. *(vip)CIA_IOC_CIA_CTRL = ctrl;
  464. mb();
  465. *(vip)CIA_IOC_CIA_CTRL;
  466. mb();
  467. return;
  468. failed:
  469. printk("pci: disabling sg translation window\n");
  470. *(vip)CIA_IOC_PCI_W0_BASE = 0;
  471. *(vip)CIA_IOC_PCI_W1_BASE = 0;
  472. pci_isa_hose->sg_isa = NULL;
  473. alpha_mv.mv_pci_tbi = NULL;
  474. goto exit;
  475. }
  476. #if defined(ALPHA_RESTORE_SRM_SETUP)
  477. /* Save CIA configuration data as the console had it set up. */
  478. struct
  479. {
  480. unsigned int hae_mem;
  481. unsigned int hae_io;
  482. unsigned int pci_dac_offset;
  483. unsigned int err_mask;
  484. unsigned int cia_ctrl;
  485. unsigned int cia_cnfg;
  486. struct {
  487. unsigned int w_base;
  488. unsigned int w_mask;
  489. unsigned int t_base;
  490. } window[4];
  491. } saved_config __attribute((common));
  492. void
  493. cia_save_srm_settings(int is_pyxis)
  494. {
  495. int i;
  496. /* Save some important registers. */
  497. saved_config.err_mask = *(vip)CIA_IOC_ERR_MASK;
  498. saved_config.cia_ctrl = *(vip)CIA_IOC_CIA_CTRL;
  499. saved_config.hae_mem = *(vip)CIA_IOC_HAE_MEM;
  500. saved_config.hae_io = *(vip)CIA_IOC_HAE_IO;
  501. saved_config.pci_dac_offset = *(vip)CIA_IOC_PCI_W_DAC;
  502. if (is_pyxis)
  503. saved_config.cia_cnfg = *(vip)CIA_IOC_CIA_CNFG;
  504. else
  505. saved_config.cia_cnfg = 0;
  506. /* Save DMA windows configuration. */
  507. for (i = 0; i < 4; i++) {
  508. saved_config.window[i].w_base = *(vip)CIA_IOC_PCI_Wn_BASE(i);
  509. saved_config.window[i].w_mask = *(vip)CIA_IOC_PCI_Wn_MASK(i);
  510. saved_config.window[i].t_base = *(vip)CIA_IOC_PCI_Tn_BASE(i);
  511. }
  512. mb();
  513. }
  514. void
  515. cia_restore_srm_settings(void)
  516. {
  517. int i;
  518. for (i = 0; i < 4; i++) {
  519. *(vip)CIA_IOC_PCI_Wn_BASE(i) = saved_config.window[i].w_base;
  520. *(vip)CIA_IOC_PCI_Wn_MASK(i) = saved_config.window[i].w_mask;
  521. *(vip)CIA_IOC_PCI_Tn_BASE(i) = saved_config.window[i].t_base;
  522. }
  523. *(vip)CIA_IOC_HAE_MEM = saved_config.hae_mem;
  524. *(vip)CIA_IOC_HAE_IO = saved_config.hae_io;
  525. *(vip)CIA_IOC_PCI_W_DAC = saved_config.pci_dac_offset;
  526. *(vip)CIA_IOC_ERR_MASK = saved_config.err_mask;
  527. *(vip)CIA_IOC_CIA_CTRL = saved_config.cia_ctrl;
  528. if (saved_config.cia_cnfg) /* Must be pyxis. */
  529. *(vip)CIA_IOC_CIA_CNFG = saved_config.cia_cnfg;
  530. mb();
  531. }
  532. #else /* ALPHA_RESTORE_SRM_SETUP */
  533. #define cia_save_srm_settings(p) do {} while (0)
  534. #define cia_restore_srm_settings() do {} while (0)
  535. #endif /* ALPHA_RESTORE_SRM_SETUP */
  536. static void __init
  537. do_init_arch(int is_pyxis)
  538. {
  539. struct pci_controller *hose;
  540. int temp, cia_rev, tbia_window;
  541. cia_rev = *(vip)CIA_IOC_CIA_REV & CIA_REV_MASK;
  542. printk("pci: cia revision %d%s\n",
  543. cia_rev, is_pyxis ? " (pyxis)" : "");
  544. if (alpha_using_srm)
  545. cia_save_srm_settings(is_pyxis);
  546. /* Set up error reporting. */
  547. temp = *(vip)CIA_IOC_ERR_MASK;
  548. temp &= ~(CIA_ERR_CPU_PE | CIA_ERR_MEM_NEM | CIA_ERR_PA_PTE_INV
  549. | CIA_ERR_RCVD_MAS_ABT | CIA_ERR_RCVD_TAR_ABT);
  550. *(vip)CIA_IOC_ERR_MASK = temp;
  551. /* Clear all currently pending errors. */
  552. temp = *(vip)CIA_IOC_CIA_ERR;
  553. *(vip)CIA_IOC_CIA_ERR = temp;
  554. /* Turn on mchecks. */
  555. temp = *(vip)CIA_IOC_CIA_CTRL;
  556. temp |= CIA_CTRL_FILL_ERR_EN | CIA_CTRL_MCHK_ERR_EN;
  557. *(vip)CIA_IOC_CIA_CTRL = temp;
  558. /* Clear the CFG register, which gets used for PCI config space
  559. accesses. That is the way we want to use it, and we do not
  560. want to depend on what ARC or SRM might have left behind. */
  561. *(vip)CIA_IOC_CFG = 0;
  562. /* Zero the HAEs. */
  563. *(vip)CIA_IOC_HAE_MEM = 0;
  564. *(vip)CIA_IOC_HAE_IO = 0;
  565. /* For PYXIS, we always use BWX bus and i/o accesses. To that end,
  566. make sure they're enabled on the controller. At the same time,
  567. enable the monster window. */
  568. if (is_pyxis) {
  569. temp = *(vip)CIA_IOC_CIA_CNFG;
  570. temp |= CIA_CNFG_IOA_BWEN | CIA_CNFG_PCI_MWEN;
  571. *(vip)CIA_IOC_CIA_CNFG = temp;
  572. }
  573. /* Synchronize with all previous changes. */
  574. mb();
  575. *(vip)CIA_IOC_CIA_REV;
  576. /*
  577. * Create our single hose.
  578. */
  579. pci_isa_hose = hose = alloc_pci_controller();
  580. hose->io_space = &ioport_resource;
  581. hose->mem_space = &iomem_resource;
  582. hose->index = 0;
  583. if (! is_pyxis) {
  584. struct resource *hae_mem = alloc_resource();
  585. hose->mem_space = hae_mem;
  586. hae_mem->start = 0;
  587. hae_mem->end = CIA_MEM_R1_MASK;
  588. hae_mem->name = pci_hae0_name;
  589. hae_mem->flags = IORESOURCE_MEM;
  590. if (request_resource(&iomem_resource, hae_mem) < 0)
  591. printk(KERN_ERR "Failed to request HAE_MEM\n");
  592. hose->sparse_mem_base = CIA_SPARSE_MEM - IDENT_ADDR;
  593. hose->dense_mem_base = CIA_DENSE_MEM - IDENT_ADDR;
  594. hose->sparse_io_base = CIA_IO - IDENT_ADDR;
  595. hose->dense_io_base = 0;
  596. } else {
  597. hose->sparse_mem_base = 0;
  598. hose->dense_mem_base = CIA_BW_MEM - IDENT_ADDR;
  599. hose->sparse_io_base = 0;
  600. hose->dense_io_base = CIA_BW_IO - IDENT_ADDR;
  601. }
  602. /*
  603. * Set up the PCI to main memory translation windows.
  604. *
  605. * Window 0 is S/G 8MB at 8MB (for isa)
  606. * Window 1 is S/G 1MB at 768MB (for tbia) (unused for CIA rev 1)
  607. * Window 2 is direct access 2GB at 2GB
  608. * Window 3 is DAC access 4GB at 8GB (or S/G for tbia if CIA rev 1)
  609. *
  610. * ??? NetBSD hints that page tables must be aligned to 32K,
  611. * possibly due to a hardware bug. This is over-aligned
  612. * from the 8K alignment one would expect for an 8MB window.
  613. * No description of what revisions affected.
  614. */
  615. hose->sg_pci = NULL;
  616. hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 32768);
  617. __direct_map_base = 0x80000000;
  618. __direct_map_size = 0x80000000;
  619. *(vip)CIA_IOC_PCI_W0_BASE = hose->sg_isa->dma_base | 3;
  620. *(vip)CIA_IOC_PCI_W0_MASK = (hose->sg_isa->size - 1) & 0xfff00000;
  621. *(vip)CIA_IOC_PCI_T0_BASE = virt_to_phys(hose->sg_isa->ptes) >> 2;
  622. *(vip)CIA_IOC_PCI_W2_BASE = __direct_map_base | 1;
  623. *(vip)CIA_IOC_PCI_W2_MASK = (__direct_map_size - 1) & 0xfff00000;
  624. *(vip)CIA_IOC_PCI_T2_BASE = 0 >> 2;
  625. /* On PYXIS we have the monster window, selected by bit 40, so
  626. there is no need for window3 to be enabled.
  627. On CIA, we don't have true arbitrary addressing -- bits <39:32>
  628. are compared against W_DAC. We can, however, directly map 4GB,
  629. which is better than before. However, due to assumptions made
  630. elsewhere, we should not claim that we support DAC unless that
  631. 4GB covers all of physical memory.
  632. On CIA rev 1, apparently W1 and W2 can't be used for SG.
  633. At least, there are reports that it doesn't work for Alcor.
  634. In that case, we have no choice but to use W3 for the TBIA
  635. workaround, which means we can't use DAC at all. */
  636. tbia_window = 1;
  637. if (is_pyxis) {
  638. *(vip)CIA_IOC_PCI_W3_BASE = 0;
  639. } else if (cia_rev == 1) {
  640. *(vip)CIA_IOC_PCI_W1_BASE = 0;
  641. tbia_window = 3;
  642. } else if (max_low_pfn > (0x100000000UL >> PAGE_SHIFT)) {
  643. *(vip)CIA_IOC_PCI_W3_BASE = 0;
  644. } else {
  645. *(vip)CIA_IOC_PCI_W3_BASE = 0x00000000 | 1 | 8;
  646. *(vip)CIA_IOC_PCI_W3_MASK = 0xfff00000;
  647. *(vip)CIA_IOC_PCI_T3_BASE = 0 >> 2;
  648. alpha_mv.pci_dac_offset = 0x200000000UL;
  649. *(vip)CIA_IOC_PCI_W_DAC = alpha_mv.pci_dac_offset >> 32;
  650. }
  651. /* Prepare workaround for apparently broken tbia. */
  652. cia_prepare_tbia_workaround(tbia_window);
  653. }
  654. void __init
  655. cia_init_arch(void)
  656. {
  657. do_init_arch(0);
  658. }
  659. void __init
  660. pyxis_init_arch(void)
  661. {
  662. /* On pyxis machines we can precisely calculate the
  663. CPU clock frequency using pyxis real time counter.
  664. It's especially useful for SX164 with broken RTC.
  665. Both CPU and chipset are driven by the single 16.666M
  666. or 16.667M crystal oscillator. PYXIS_RT_COUNT clock is
  667. 66.66 MHz. -ink */
  668. unsigned int cc0, cc1;
  669. unsigned long pyxis_cc;
  670. __asm__ __volatile__ ("rpcc %0" : "=r"(cc0));
  671. pyxis_cc = *(vulp)PYXIS_RT_COUNT;
  672. do { } while(*(vulp)PYXIS_RT_COUNT - pyxis_cc < 4096);
  673. __asm__ __volatile__ ("rpcc %0" : "=r"(cc1));
  674. cc1 -= cc0;
  675. hwrpb->cycle_freq = ((cc1 >> 11) * 100000000UL) / 3;
  676. hwrpb_update_checksum(hwrpb);
  677. do_init_arch(1);
  678. }
  679. void
  680. cia_kill_arch(int mode)
  681. {
  682. if (alpha_using_srm)
  683. cia_restore_srm_settings();
  684. }
  685. void __init
  686. cia_init_pci(void)
  687. {
  688. /* Must delay this from init_arch, as we need machine checks. */
  689. verify_tb_operation();
  690. common_init_pci();
  691. }
  692. static inline void
  693. cia_pci_clr_err(void)
  694. {
  695. int jd;
  696. jd = *(vip)CIA_IOC_CIA_ERR;
  697. *(vip)CIA_IOC_CIA_ERR = jd;
  698. mb();
  699. *(vip)CIA_IOC_CIA_ERR; /* re-read to force write. */
  700. }
  701. #ifdef CONFIG_VERBOSE_MCHECK
  702. static void
  703. cia_decode_pci_error(struct el_CIA_sysdata_mcheck *cia, const char *msg)
  704. {
  705. static const char * const pci_cmd_desc[16] = {
  706. "Interrupt Acknowledge", "Special Cycle", "I/O Read",
  707. "I/O Write", "Reserved 0x4", "Reserved 0x5", "Memory Read",
  708. "Memory Write", "Reserved 0x8", "Reserved 0x9",
  709. "Configuration Read", "Configuration Write",
  710. "Memory Read Multiple", "Dual Address Cycle",
  711. "Memory Read Line", "Memory Write and Invalidate"
  712. };
  713. if (cia->cia_err & (CIA_ERR_COR_ERR
  714. | CIA_ERR_UN_COR_ERR
  715. | CIA_ERR_MEM_NEM
  716. | CIA_ERR_PA_PTE_INV)) {
  717. static const char * const window_desc[6] = {
  718. "No window active", "Window 0 hit", "Window 1 hit",
  719. "Window 2 hit", "Window 3 hit", "Monster window hit"
  720. };
  721. const char *window;
  722. const char *cmd;
  723. unsigned long addr, tmp;
  724. int lock, dac;
  725. cmd = pci_cmd_desc[cia->pci_err0 & 0x7];
  726. lock = (cia->pci_err0 >> 4) & 1;
  727. dac = (cia->pci_err0 >> 5) & 1;
  728. tmp = (cia->pci_err0 >> 8) & 0x1F;
  729. tmp = ffs(tmp);
  730. window = window_desc[tmp];
  731. addr = cia->pci_err1;
  732. if (dac) {
  733. tmp = *(vip)CIA_IOC_PCI_W_DAC & 0xFFUL;
  734. addr |= tmp << 32;
  735. }
  736. printk(KERN_CRIT "CIA machine check: %s\n", msg);
  737. printk(KERN_CRIT " DMA command: %s\n", cmd);
  738. printk(KERN_CRIT " PCI address: %#010lx\n", addr);
  739. printk(KERN_CRIT " %s, Lock: %d, DAC: %d\n",
  740. window, lock, dac);
  741. } else if (cia->cia_err & (CIA_ERR_PERR
  742. | CIA_ERR_PCI_ADDR_PE
  743. | CIA_ERR_RCVD_MAS_ABT
  744. | CIA_ERR_RCVD_TAR_ABT
  745. | CIA_ERR_IOA_TIMEOUT)) {
  746. static const char * const master_st_desc[16] = {
  747. "Idle", "Drive bus", "Address step cycle",
  748. "Address cycle", "Data cycle", "Last read data cycle",
  749. "Last write data cycle", "Read stop cycle",
  750. "Write stop cycle", "Read turnaround cycle",
  751. "Write turnaround cycle", "Reserved 0xB",
  752. "Reserved 0xC", "Reserved 0xD", "Reserved 0xE",
  753. "Unknown state"
  754. };
  755. static const char * const target_st_desc[16] = {
  756. "Idle", "Busy", "Read data cycle", "Write data cycle",
  757. "Read stop cycle", "Write stop cycle",
  758. "Read turnaround cycle", "Write turnaround cycle",
  759. "Read wait cycle", "Write wait cycle",
  760. "Reserved 0xA", "Reserved 0xB", "Reserved 0xC",
  761. "Reserved 0xD", "Reserved 0xE", "Unknown state"
  762. };
  763. const char *cmd;
  764. const char *master, *target;
  765. unsigned long addr, tmp;
  766. int dac;
  767. master = master_st_desc[(cia->pci_err0 >> 16) & 0xF];
  768. target = target_st_desc[(cia->pci_err0 >> 20) & 0xF];
  769. cmd = pci_cmd_desc[(cia->pci_err0 >> 24) & 0xF];
  770. dac = (cia->pci_err0 >> 28) & 1;
  771. addr = cia->pci_err2;
  772. if (dac) {
  773. tmp = *(volatile int *)CIA_IOC_PCI_W_DAC & 0xFFUL;
  774. addr |= tmp << 32;
  775. }
  776. printk(KERN_CRIT "CIA machine check: %s\n", msg);
  777. printk(KERN_CRIT " PCI command: %s\n", cmd);
  778. printk(KERN_CRIT " Master state: %s, Target state: %s\n",
  779. master, target);
  780. printk(KERN_CRIT " PCI address: %#010lx, DAC: %d\n",
  781. addr, dac);
  782. } else {
  783. printk(KERN_CRIT "CIA machine check: %s\n", msg);
  784. printk(KERN_CRIT " Unknown PCI error\n");
  785. printk(KERN_CRIT " PCI_ERR0 = %#08lx", cia->pci_err0);
  786. printk(KERN_CRIT " PCI_ERR1 = %#08lx", cia->pci_err1);
  787. printk(KERN_CRIT " PCI_ERR2 = %#08lx", cia->pci_err2);
  788. }
  789. }
  790. static void
  791. cia_decode_mem_error(struct el_CIA_sysdata_mcheck *cia, const char *msg)
  792. {
  793. unsigned long mem_port_addr;
  794. unsigned long mem_port_mask;
  795. const char *mem_port_cmd;
  796. const char *seq_state;
  797. const char *set_select;
  798. unsigned long tmp;
  799. /* If this is a DMA command, also decode the PCI bits. */
  800. if ((cia->mem_err1 >> 20) & 1)
  801. cia_decode_pci_error(cia, msg);
  802. else
  803. printk(KERN_CRIT "CIA machine check: %s\n", msg);
  804. mem_port_addr = cia->mem_err0 & 0xfffffff0;
  805. mem_port_addr |= (cia->mem_err1 & 0x83UL) << 32;
  806. mem_port_mask = (cia->mem_err1 >> 12) & 0xF;
  807. tmp = (cia->mem_err1 >> 8) & 0xF;
  808. tmp |= ((cia->mem_err1 >> 20) & 1) << 4;
  809. if ((tmp & 0x1E) == 0x06)
  810. mem_port_cmd = "WRITE BLOCK or WRITE BLOCK LOCK";
  811. else if ((tmp & 0x1C) == 0x08)
  812. mem_port_cmd = "READ MISS or READ MISS MODIFY";
  813. else if (tmp == 0x1C)
  814. mem_port_cmd = "BC VICTIM";
  815. else if ((tmp & 0x1E) == 0x0E)
  816. mem_port_cmd = "READ MISS MODIFY";
  817. else if ((tmp & 0x1C) == 0x18)
  818. mem_port_cmd = "DMA READ or DMA READ MODIFY";
  819. else if ((tmp & 0x1E) == 0x12)
  820. mem_port_cmd = "DMA WRITE";
  821. else
  822. mem_port_cmd = "Unknown";
  823. tmp = (cia->mem_err1 >> 16) & 0xF;
  824. switch (tmp) {
  825. case 0x0:
  826. seq_state = "Idle";
  827. break;
  828. case 0x1:
  829. seq_state = "DMA READ or DMA WRITE";
  830. break;
  831. case 0x2: case 0x3:
  832. seq_state = "READ MISS (or READ MISS MODIFY) with victim";
  833. break;
  834. case 0x4: case 0x5: case 0x6:
  835. seq_state = "READ MISS (or READ MISS MODIFY) with no victim";
  836. break;
  837. case 0x8: case 0x9: case 0xB:
  838. seq_state = "Refresh";
  839. break;
  840. case 0xC:
  841. seq_state = "Idle, waiting for DMA pending read";
  842. break;
  843. case 0xE: case 0xF:
  844. seq_state = "Idle, ras precharge";
  845. break;
  846. default:
  847. seq_state = "Unknown";
  848. break;
  849. }
  850. tmp = (cia->mem_err1 >> 24) & 0x1F;
  851. switch (tmp) {
  852. case 0x00: set_select = "Set 0 selected"; break;
  853. case 0x01: set_select = "Set 1 selected"; break;
  854. case 0x02: set_select = "Set 2 selected"; break;
  855. case 0x03: set_select = "Set 3 selected"; break;
  856. case 0x04: set_select = "Set 4 selected"; break;
  857. case 0x05: set_select = "Set 5 selected"; break;
  858. case 0x06: set_select = "Set 6 selected"; break;
  859. case 0x07: set_select = "Set 7 selected"; break;
  860. case 0x08: set_select = "Set 8 selected"; break;
  861. case 0x09: set_select = "Set 9 selected"; break;
  862. case 0x0A: set_select = "Set A selected"; break;
  863. case 0x0B: set_select = "Set B selected"; break;
  864. case 0x0C: set_select = "Set C selected"; break;
  865. case 0x0D: set_select = "Set D selected"; break;
  866. case 0x0E: set_select = "Set E selected"; break;
  867. case 0x0F: set_select = "Set F selected"; break;
  868. case 0x10: set_select = "No set selected"; break;
  869. case 0x1F: set_select = "Refresh cycle"; break;
  870. default: set_select = "Unknown"; break;
  871. }
  872. printk(KERN_CRIT " Memory port command: %s\n", mem_port_cmd);
  873. printk(KERN_CRIT " Memory port address: %#010lx, mask: %#lx\n",
  874. mem_port_addr, mem_port_mask);
  875. printk(KERN_CRIT " Memory sequencer state: %s\n", seq_state);
  876. printk(KERN_CRIT " Memory set: %s\n", set_select);
  877. }
  878. static void
  879. cia_decode_ecc_error(struct el_CIA_sysdata_mcheck *cia, const char *msg)
  880. {
  881. long syn;
  882. long i;
  883. const char *fmt;
  884. cia_decode_mem_error(cia, msg);
  885. syn = cia->cia_syn & 0xff;
  886. if (syn == (syn & -syn)) {
  887. fmt = KERN_CRIT " ECC syndrome %#x -- check bit %d\n";
  888. i = ffs(syn) - 1;
  889. } else {
  890. static unsigned char const data_bit[64] = {
  891. 0xCE, 0xCB, 0xD3, 0xD5,
  892. 0xD6, 0xD9, 0xDA, 0xDC,
  893. 0x23, 0x25, 0x26, 0x29,
  894. 0x2A, 0x2C, 0x31, 0x34,
  895. 0x0E, 0x0B, 0x13, 0x15,
  896. 0x16, 0x19, 0x1A, 0x1C,
  897. 0xE3, 0xE5, 0xE6, 0xE9,
  898. 0xEA, 0xEC, 0xF1, 0xF4,
  899. 0x4F, 0x4A, 0x52, 0x54,
  900. 0x57, 0x58, 0x5B, 0x5D,
  901. 0xA2, 0xA4, 0xA7, 0xA8,
  902. 0xAB, 0xAD, 0xB0, 0xB5,
  903. 0x8F, 0x8A, 0x92, 0x94,
  904. 0x97, 0x98, 0x9B, 0x9D,
  905. 0x62, 0x64, 0x67, 0x68,
  906. 0x6B, 0x6D, 0x70, 0x75
  907. };
  908. for (i = 0; i < 64; ++i)
  909. if (data_bit[i] == syn)
  910. break;
  911. if (i < 64)
  912. fmt = KERN_CRIT " ECC syndrome %#x -- data bit %d\n";
  913. else
  914. fmt = KERN_CRIT " ECC syndrome %#x -- unknown bit\n";
  915. }
  916. printk (fmt, syn, i);
  917. }
  918. static void
  919. cia_decode_parity_error(struct el_CIA_sysdata_mcheck *cia)
  920. {
  921. static const char * const cmd_desc[16] = {
  922. "NOP", "LOCK", "FETCH", "FETCH_M", "MEMORY BARRIER",
  923. "SET DIRTY", "WRITE BLOCK", "WRITE BLOCK LOCK",
  924. "READ MISS0", "READ MISS1", "READ MISS MOD0",
  925. "READ MISS MOD1", "BCACHE VICTIM", "Spare",
  926. "READ MISS MOD STC0", "READ MISS MOD STC1"
  927. };
  928. unsigned long addr;
  929. unsigned long mask;
  930. const char *cmd;
  931. int par;
  932. addr = cia->cpu_err0 & 0xfffffff0;
  933. addr |= (cia->cpu_err1 & 0x83UL) << 32;
  934. cmd = cmd_desc[(cia->cpu_err1 >> 8) & 0xF];
  935. mask = (cia->cpu_err1 >> 12) & 0xF;
  936. par = (cia->cpu_err1 >> 21) & 1;
  937. printk(KERN_CRIT "CIA machine check: System bus parity error\n");
  938. printk(KERN_CRIT " Command: %s, Parity bit: %d\n", cmd, par);
  939. printk(KERN_CRIT " Address: %#010lx, Mask: %#lx\n", addr, mask);
  940. }
  941. #endif /* CONFIG_VERBOSE_MCHECK */
  942. static int
  943. cia_decode_mchk(unsigned long la_ptr)
  944. {
  945. struct el_common *com;
  946. struct el_CIA_sysdata_mcheck *cia;
  947. com = (void *)la_ptr;
  948. cia = (void *)(la_ptr + com->sys_offset);
  949. if ((cia->cia_err & CIA_ERR_VALID) == 0)
  950. return 0;
  951. #ifdef CONFIG_VERBOSE_MCHECK
  952. if (!alpha_verbose_mcheck)
  953. return 1;
  954. switch (ffs(cia->cia_err & 0xfff) - 1) {
  955. case 0: /* CIA_ERR_COR_ERR */
  956. cia_decode_ecc_error(cia, "Corrected ECC error");
  957. break;
  958. case 1: /* CIA_ERR_UN_COR_ERR */
  959. cia_decode_ecc_error(cia, "Uncorrected ECC error");
  960. break;
  961. case 2: /* CIA_ERR_CPU_PE */
  962. cia_decode_parity_error(cia);
  963. break;
  964. case 3: /* CIA_ERR_MEM_NEM */
  965. cia_decode_mem_error(cia, "Access to nonexistent memory");
  966. break;
  967. case 4: /* CIA_ERR_PCI_SERR */
  968. cia_decode_pci_error(cia, "PCI bus system error");
  969. break;
  970. case 5: /* CIA_ERR_PERR */
  971. cia_decode_pci_error(cia, "PCI data parity error");
  972. break;
  973. case 6: /* CIA_ERR_PCI_ADDR_PE */
  974. cia_decode_pci_error(cia, "PCI address parity error");
  975. break;
  976. case 7: /* CIA_ERR_RCVD_MAS_ABT */
  977. cia_decode_pci_error(cia, "PCI master abort");
  978. break;
  979. case 8: /* CIA_ERR_RCVD_TAR_ABT */
  980. cia_decode_pci_error(cia, "PCI target abort");
  981. break;
  982. case 9: /* CIA_ERR_PA_PTE_INV */
  983. cia_decode_pci_error(cia, "PCI invalid PTE");
  984. break;
  985. case 10: /* CIA_ERR_FROM_WRT_ERR */
  986. cia_decode_mem_error(cia, "Write to flash ROM attempted");
  987. break;
  988. case 11: /* CIA_ERR_IOA_TIMEOUT */
  989. cia_decode_pci_error(cia, "I/O timeout");
  990. break;
  991. }
  992. if (cia->cia_err & CIA_ERR_LOST_CORR_ERR)
  993. printk(KERN_CRIT "CIA lost machine check: "
  994. "Correctable ECC error\n");
  995. if (cia->cia_err & CIA_ERR_LOST_UN_CORR_ERR)
  996. printk(KERN_CRIT "CIA lost machine check: "
  997. "Uncorrectable ECC error\n");
  998. if (cia->cia_err & CIA_ERR_LOST_CPU_PE)
  999. printk(KERN_CRIT "CIA lost machine check: "
  1000. "System bus parity error\n");
  1001. if (cia->cia_err & CIA_ERR_LOST_MEM_NEM)
  1002. printk(KERN_CRIT "CIA lost machine check: "
  1003. "Access to nonexistent memory\n");
  1004. if (cia->cia_err & CIA_ERR_LOST_PERR)
  1005. printk(KERN_CRIT "CIA lost machine check: "
  1006. "PCI data parity error\n");
  1007. if (cia->cia_err & CIA_ERR_LOST_PCI_ADDR_PE)
  1008. printk(KERN_CRIT "CIA lost machine check: "
  1009. "PCI address parity error\n");
  1010. if (cia->cia_err & CIA_ERR_LOST_RCVD_MAS_ABT)
  1011. printk(KERN_CRIT "CIA lost machine check: "
  1012. "PCI master abort\n");
  1013. if (cia->cia_err & CIA_ERR_LOST_RCVD_TAR_ABT)
  1014. printk(KERN_CRIT "CIA lost machine check: "
  1015. "PCI target abort\n");
  1016. if (cia->cia_err & CIA_ERR_LOST_PA_PTE_INV)
  1017. printk(KERN_CRIT "CIA lost machine check: "
  1018. "PCI invalid PTE\n");
  1019. if (cia->cia_err & CIA_ERR_LOST_FROM_WRT_ERR)
  1020. printk(KERN_CRIT "CIA lost machine check: "
  1021. "Write to flash ROM attempted\n");
  1022. if (cia->cia_err & CIA_ERR_LOST_IOA_TIMEOUT)
  1023. printk(KERN_CRIT "CIA lost machine check: "
  1024. "I/O timeout\n");
  1025. #endif /* CONFIG_VERBOSE_MCHECK */
  1026. return 1;
  1027. }
  1028. void
  1029. cia_machine_check(unsigned long vector, unsigned long la_ptr)
  1030. {
  1031. int expected;
  1032. /* Clear the error before any reporting. */
  1033. mb();
  1034. mb(); /* magic */
  1035. draina();
  1036. cia_pci_clr_err();
  1037. wrmces(rdmces()); /* reset machine check pending flag. */
  1038. mb();
  1039. expected = mcheck_expected(0);
  1040. if (!expected && vector == 0x660)
  1041. expected = cia_decode_mchk(la_ptr);
  1042. process_mcheck_info(vector, la_ptr, "CIA", expected);
  1043. }