PageRenderTime 71ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/sparc64/kernel/pci_schizo.c

https://bitbucket.org/evzijst/gittest
C | 2187 lines | 1685 code | 285 blank | 217 comment | 180 complexity | 133baa3529d308f3438ce82d39ee00c5 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  1. /* $Id: pci_schizo.c,v 1.24 2002/01/23 11:27:32 davem Exp $
  2. * pci_schizo.c: SCHIZO/TOMATILLO specific PCI controller support.
  3. *
  4. * Copyright (C) 2001, 2002, 2003 David S. Miller (davem@redhat.com)
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/types.h>
  8. #include <linux/pci.h>
  9. #include <linux/init.h>
  10. #include <linux/slab.h>
  11. #include <linux/interrupt.h>
  12. #include <asm/pbm.h>
  13. #include <asm/iommu.h>
  14. #include <asm/irq.h>
  15. #include <asm/upa.h>
  16. #include "pci_impl.h"
  17. #include "iommu_common.h"
  18. /* All SCHIZO registers are 64-bits. The following accessor
  19. * routines are how they are accessed. The REG parameter
  20. * is a physical address.
  21. */
  22. #define schizo_read(__reg) \
  23. ({ u64 __ret; \
  24. __asm__ __volatile__("ldxa [%1] %2, %0" \
  25. : "=r" (__ret) \
  26. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  27. : "memory"); \
  28. __ret; \
  29. })
  30. #define schizo_write(__reg, __val) \
  31. __asm__ __volatile__("stxa %0, [%1] %2" \
  32. : /* no outputs */ \
  33. : "r" (__val), "r" (__reg), \
  34. "i" (ASI_PHYS_BYPASS_EC_E) \
  35. : "memory")
  36. /* This is a convention that at least Excalibur and Merlin
  37. * follow. I suppose the SCHIZO used in Starcat and friends
  38. * will do similar.
  39. *
  40. * The only way I could see this changing is if the newlink
  41. * block requires more space in Schizo's address space than
  42. * they predicted, thus requiring an address space reorg when
  43. * the newer Schizo is taped out.
  44. */
  45. /* Streaming buffer control register. */
  46. #define SCHIZO_STRBUF_CTRL_LPTR 0x00000000000000f0UL /* LRU Lock Pointer */
  47. #define SCHIZO_STRBUF_CTRL_LENAB 0x0000000000000008UL /* LRU Lock Enable */
  48. #define SCHIZO_STRBUF_CTRL_RRDIS 0x0000000000000004UL /* Rerun Disable */
  49. #define SCHIZO_STRBUF_CTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
  50. #define SCHIZO_STRBUF_CTRL_ENAB 0x0000000000000001UL /* Streaming Buffer Enable */
  51. /* IOMMU control register. */
  52. #define SCHIZO_IOMMU_CTRL_RESV 0xfffffffff9000000UL /* Reserved */
  53. #define SCHIZO_IOMMU_CTRL_XLTESTAT 0x0000000006000000UL /* Translation Error Status */
  54. #define SCHIZO_IOMMU_CTRL_XLTEERR 0x0000000001000000UL /* Translation Error encountered */
  55. #define SCHIZO_IOMMU_CTRL_LCKEN 0x0000000000800000UL /* Enable translation locking */
  56. #define SCHIZO_IOMMU_CTRL_LCKPTR 0x0000000000780000UL /* Translation lock pointer */
  57. #define SCHIZO_IOMMU_CTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
  58. #define SCHIZO_IOMMU_TSBSZ_1K 0x0000000000000000UL /* TSB Table 1024 8-byte entries */
  59. #define SCHIZO_IOMMU_TSBSZ_2K 0x0000000000010000UL /* TSB Table 2048 8-byte entries */
  60. #define SCHIZO_IOMMU_TSBSZ_4K 0x0000000000020000UL /* TSB Table 4096 8-byte entries */
  61. #define SCHIZO_IOMMU_TSBSZ_8K 0x0000000000030000UL /* TSB Table 8192 8-byte entries */
  62. #define SCHIZO_IOMMU_TSBSZ_16K 0x0000000000040000UL /* TSB Table 16k 8-byte entries */
  63. #define SCHIZO_IOMMU_TSBSZ_32K 0x0000000000050000UL /* TSB Table 32k 8-byte entries */
  64. #define SCHIZO_IOMMU_TSBSZ_64K 0x0000000000060000UL /* TSB Table 64k 8-byte entries */
  65. #define SCHIZO_IOMMU_TSBSZ_128K 0x0000000000070000UL /* TSB Table 128k 8-byte entries */
  66. #define SCHIZO_IOMMU_CTRL_RESV2 0x000000000000fff8UL /* Reserved */
  67. #define SCHIZO_IOMMU_CTRL_TBWSZ 0x0000000000000004UL /* Assumed page size, 0=8k 1=64k */
  68. #define SCHIZO_IOMMU_CTRL_DENAB 0x0000000000000002UL /* Diagnostic mode enable */
  69. #define SCHIZO_IOMMU_CTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
  70. /* Schizo config space address format is nearly identical to
  71. * that of PSYCHO:
  72. *
  73. * 32 24 23 16 15 11 10 8 7 2 1 0
  74. * ---------------------------------------------------------
  75. * |0 0 0 0 0 0 0 0 0| bus | device | function | reg | 0 0 |
  76. * ---------------------------------------------------------
  77. */
  78. #define SCHIZO_CONFIG_BASE(PBM) ((PBM)->config_space)
  79. #define SCHIZO_CONFIG_ENCODE(BUS, DEVFN, REG) \
  80. (((unsigned long)(BUS) << 16) | \
  81. ((unsigned long)(DEVFN) << 8) | \
  82. ((unsigned long)(REG)))
  83. static void *schizo_pci_config_mkaddr(struct pci_pbm_info *pbm,
  84. unsigned char bus,
  85. unsigned int devfn,
  86. int where)
  87. {
  88. if (!pbm)
  89. return NULL;
  90. bus -= pbm->pci_first_busno;
  91. return (void *)
  92. (SCHIZO_CONFIG_BASE(pbm) |
  93. SCHIZO_CONFIG_ENCODE(bus, devfn, where));
  94. }
  95. /* Just make sure the bus number is in range. */
  96. static int schizo_out_of_range(struct pci_pbm_info *pbm,
  97. unsigned char bus,
  98. unsigned char devfn)
  99. {
  100. if (bus < pbm->pci_first_busno ||
  101. bus > pbm->pci_last_busno)
  102. return 1;
  103. return 0;
  104. }
  105. /* SCHIZO PCI configuration space accessors. */
  106. static int schizo_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  107. int where, int size, u32 *value)
  108. {
  109. struct pci_pbm_info *pbm = bus_dev->sysdata;
  110. unsigned char bus = bus_dev->number;
  111. u32 *addr;
  112. u16 tmp16;
  113. u8 tmp8;
  114. switch (size) {
  115. case 1:
  116. *value = 0xff;
  117. break;
  118. case 2:
  119. *value = 0xffff;
  120. break;
  121. case 4:
  122. *value = 0xffffffff;
  123. break;
  124. }
  125. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  126. if (!addr)
  127. return PCIBIOS_SUCCESSFUL;
  128. if (schizo_out_of_range(pbm, bus, devfn))
  129. return PCIBIOS_SUCCESSFUL;
  130. switch (size) {
  131. case 1:
  132. pci_config_read8((u8 *)addr, &tmp8);
  133. *value = tmp8;
  134. break;
  135. case 2:
  136. if (where & 0x01) {
  137. printk("pci_read_config_word: misaligned reg [%x]\n",
  138. where);
  139. return PCIBIOS_SUCCESSFUL;
  140. }
  141. pci_config_read16((u16 *)addr, &tmp16);
  142. *value = tmp16;
  143. break;
  144. case 4:
  145. if (where & 0x03) {
  146. printk("pci_read_config_dword: misaligned reg [%x]\n",
  147. where);
  148. return PCIBIOS_SUCCESSFUL;
  149. }
  150. pci_config_read32(addr, value);
  151. break;
  152. }
  153. return PCIBIOS_SUCCESSFUL;
  154. }
  155. static int schizo_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  156. int where, int size, u32 value)
  157. {
  158. struct pci_pbm_info *pbm = bus_dev->sysdata;
  159. unsigned char bus = bus_dev->number;
  160. u32 *addr;
  161. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  162. if (!addr)
  163. return PCIBIOS_SUCCESSFUL;
  164. if (schizo_out_of_range(pbm, bus, devfn))
  165. return PCIBIOS_SUCCESSFUL;
  166. switch (size) {
  167. case 1:
  168. pci_config_write8((u8 *)addr, value);
  169. break;
  170. case 2:
  171. if (where & 0x01) {
  172. printk("pci_write_config_word: misaligned reg [%x]\n",
  173. where);
  174. return PCIBIOS_SUCCESSFUL;
  175. }
  176. pci_config_write16((u16 *)addr, value);
  177. break;
  178. case 4:
  179. if (where & 0x03) {
  180. printk("pci_write_config_dword: misaligned reg [%x]\n",
  181. where);
  182. return PCIBIOS_SUCCESSFUL;
  183. }
  184. pci_config_write32(addr, value);
  185. }
  186. return PCIBIOS_SUCCESSFUL;
  187. }
  188. static struct pci_ops schizo_ops = {
  189. .read = schizo_read_pci_cfg,
  190. .write = schizo_write_pci_cfg,
  191. };
  192. /* SCHIZO interrupt mapping support. Unlike Psycho, for this controller the
  193. * imap/iclr registers are per-PBM.
  194. */
  195. #define SCHIZO_IMAP_BASE 0x1000UL
  196. #define SCHIZO_ICLR_BASE 0x1400UL
  197. static unsigned long schizo_imap_offset(unsigned long ino)
  198. {
  199. return SCHIZO_IMAP_BASE + (ino * 8UL);
  200. }
  201. static unsigned long schizo_iclr_offset(unsigned long ino)
  202. {
  203. return SCHIZO_ICLR_BASE + (ino * 8UL);
  204. }
  205. /* PCI SCHIZO INO number to Sparc PIL level. This table only matters for
  206. * INOs which will not have an associated PCI device struct, ie. onboard
  207. * EBUS devices and PCI controller internal error interrupts.
  208. */
  209. static unsigned char schizo_pil_table[] = {
  210. /*0x00*/0, 0, 0, 0, /* PCI slot 0 Int A, B, C, D */
  211. /*0x04*/0, 0, 0, 0, /* PCI slot 1 Int A, B, C, D */
  212. /*0x08*/0, 0, 0, 0, /* PCI slot 2 Int A, B, C, D */
  213. /*0x0c*/0, 0, 0, 0, /* PCI slot 3 Int A, B, C, D */
  214. /*0x10*/0, 0, 0, 0, /* PCI slot 4 Int A, B, C, D */
  215. /*0x14*/0, 0, 0, 0, /* PCI slot 5 Int A, B, C, D */
  216. /*0x18*/4, /* SCSI */
  217. /*0x19*/4, /* second SCSI */
  218. /*0x1a*/0, /* UNKNOWN */
  219. /*0x1b*/0, /* UNKNOWN */
  220. /*0x1c*/8, /* Parallel */
  221. /*0x1d*/5, /* Ethernet */
  222. /*0x1e*/8, /* Firewire-1394 */
  223. /*0x1f*/9, /* USB */
  224. /*0x20*/13, /* Audio Record */
  225. /*0x21*/14, /* Audio Playback */
  226. /*0x22*/12, /* Serial */
  227. /*0x23*/4, /* EBUS I2C */
  228. /*0x24*/10, /* RTC Clock */
  229. /*0x25*/11, /* Floppy */
  230. /*0x26*/0, /* UNKNOWN */
  231. /*0x27*/0, /* UNKNOWN */
  232. /*0x28*/0, /* UNKNOWN */
  233. /*0x29*/0, /* UNKNOWN */
  234. /*0x2a*/10, /* UPA 1 */
  235. /*0x2b*/10, /* UPA 2 */
  236. /*0x2c*/0, /* UNKNOWN */
  237. /*0x2d*/0, /* UNKNOWN */
  238. /*0x2e*/0, /* UNKNOWN */
  239. /*0x2f*/0, /* UNKNOWN */
  240. /*0x30*/15, /* Uncorrectable ECC */
  241. /*0x31*/15, /* Correctable ECC */
  242. /*0x32*/15, /* PCI Bus A Error */
  243. /*0x33*/15, /* PCI Bus B Error */
  244. /*0x34*/15, /* Safari Bus Error */
  245. /*0x35*/0, /* Reserved */
  246. /*0x36*/0, /* Reserved */
  247. /*0x37*/0, /* Reserved */
  248. /*0x38*/0, /* Reserved for NewLink */
  249. /*0x39*/0, /* Reserved for NewLink */
  250. /*0x3a*/0, /* Reserved for NewLink */
  251. /*0x3b*/0, /* Reserved for NewLink */
  252. /*0x3c*/0, /* Reserved for NewLink */
  253. /*0x3d*/0, /* Reserved for NewLink */
  254. /*0x3e*/0, /* Reserved for NewLink */
  255. /*0x3f*/0, /* Reserved for NewLink */
  256. };
  257. static int __init schizo_ino_to_pil(struct pci_dev *pdev, unsigned int ino)
  258. {
  259. int ret;
  260. if (pdev &&
  261. pdev->vendor == PCI_VENDOR_ID_SUN &&
  262. pdev->device == PCI_DEVICE_ID_SUN_RIO_USB)
  263. return 9;
  264. ret = schizo_pil_table[ino];
  265. if (ret == 0 && pdev == NULL) {
  266. ret = 4;
  267. } else if (ret == 0) {
  268. switch ((pdev->class >> 16) & 0xff) {
  269. case PCI_BASE_CLASS_STORAGE:
  270. ret = 4;
  271. break;
  272. case PCI_BASE_CLASS_NETWORK:
  273. ret = 6;
  274. break;
  275. case PCI_BASE_CLASS_DISPLAY:
  276. ret = 9;
  277. break;
  278. case PCI_BASE_CLASS_MULTIMEDIA:
  279. case PCI_BASE_CLASS_MEMORY:
  280. case PCI_BASE_CLASS_BRIDGE:
  281. case PCI_BASE_CLASS_SERIAL:
  282. ret = 10;
  283. break;
  284. default:
  285. ret = 4;
  286. break;
  287. };
  288. }
  289. return ret;
  290. }
  291. static unsigned int schizo_irq_build(struct pci_pbm_info *pbm,
  292. struct pci_dev *pdev,
  293. unsigned int ino)
  294. {
  295. struct ino_bucket *bucket;
  296. unsigned long imap, iclr;
  297. unsigned long imap_off, iclr_off;
  298. int pil, ign_fixup;
  299. ino &= PCI_IRQ_INO;
  300. imap_off = schizo_imap_offset(ino);
  301. /* Now build the IRQ bucket. */
  302. pil = schizo_ino_to_pil(pdev, ino);
  303. if (PIL_RESERVED(pil))
  304. BUG();
  305. imap = pbm->pbm_regs + imap_off;
  306. imap += 4;
  307. iclr_off = schizo_iclr_offset(ino);
  308. iclr = pbm->pbm_regs + iclr_off;
  309. iclr += 4;
  310. /* On Schizo, no inofixup occurs. This is because each
  311. * INO has it's own IMAP register. On Psycho and Sabre
  312. * there is only one IMAP register for each PCI slot even
  313. * though four different INOs can be generated by each
  314. * PCI slot.
  315. *
  316. * But, for JBUS variants (essentially, Tomatillo), we have
  317. * to fixup the lowest bit of the interrupt group number.
  318. */
  319. ign_fixup = 0;
  320. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
  321. if (pbm->portid & 1)
  322. ign_fixup = (1 << 6);
  323. }
  324. bucket = __bucket(build_irq(pil, ign_fixup, iclr, imap));
  325. bucket->flags |= IBF_PCI;
  326. return __irq(bucket);
  327. }
  328. /* SCHIZO error handling support. */
  329. enum schizo_error_type {
  330. UE_ERR, CE_ERR, PCI_ERR, SAFARI_ERR
  331. };
  332. static DEFINE_SPINLOCK(stc_buf_lock);
  333. static unsigned long stc_error_buf[128];
  334. static unsigned long stc_tag_buf[16];
  335. static unsigned long stc_line_buf[16];
  336. #define SCHIZO_UE_INO 0x30 /* Uncorrectable ECC error */
  337. #define SCHIZO_CE_INO 0x31 /* Correctable ECC error */
  338. #define SCHIZO_PCIERR_A_INO 0x32 /* PBM A PCI bus error */
  339. #define SCHIZO_PCIERR_B_INO 0x33 /* PBM B PCI bus error */
  340. #define SCHIZO_SERR_INO 0x34 /* Safari interface error */
  341. struct pci_pbm_info *pbm_for_ino(struct pci_controller_info *p, u32 ino)
  342. {
  343. ino &= IMAP_INO;
  344. if (p->pbm_A.ino_bitmap & (1UL << ino))
  345. return &p->pbm_A;
  346. if (p->pbm_B.ino_bitmap & (1UL << ino))
  347. return &p->pbm_B;
  348. printk("PCI%d: No ino_bitmap entry for ino[%x], bitmaps "
  349. "PBM_A[%016lx] PBM_B[%016lx]",
  350. p->index, ino,
  351. p->pbm_A.ino_bitmap,
  352. p->pbm_B.ino_bitmap);
  353. printk("PCI%d: Using PBM_A, report this problem immediately.\n",
  354. p->index);
  355. return &p->pbm_A;
  356. }
  357. static void schizo_clear_other_err_intr(struct pci_controller_info *p, int irq)
  358. {
  359. struct pci_pbm_info *pbm;
  360. struct ino_bucket *bucket;
  361. unsigned long iclr;
  362. /* Do not clear the interrupt for the other PCI bus.
  363. *
  364. * This "ACK both PBM IRQs" only needs to be performed
  365. * for chip-wide error interrupts.
  366. */
  367. if ((irq & IMAP_INO) == SCHIZO_PCIERR_A_INO ||
  368. (irq & IMAP_INO) == SCHIZO_PCIERR_B_INO)
  369. return;
  370. pbm = pbm_for_ino(p, irq);
  371. if (pbm == &p->pbm_A)
  372. pbm = &p->pbm_B;
  373. else
  374. pbm = &p->pbm_A;
  375. irq = schizo_irq_build(pbm, NULL,
  376. (pbm->portid << 6) | (irq & IMAP_INO));
  377. bucket = __bucket(irq);
  378. iclr = bucket->iclr;
  379. upa_writel(ICLR_IDLE, iclr);
  380. }
  381. #define SCHIZO_STC_ERR 0xb800UL /* --> 0xba00 */
  382. #define SCHIZO_STC_TAG 0xba00UL /* --> 0xba80 */
  383. #define SCHIZO_STC_LINE 0xbb00UL /* --> 0xbb80 */
  384. #define SCHIZO_STCERR_WRITE 0x2UL
  385. #define SCHIZO_STCERR_READ 0x1UL
  386. #define SCHIZO_STCTAG_PPN 0x3fffffff00000000UL
  387. #define SCHIZO_STCTAG_VPN 0x00000000ffffe000UL
  388. #define SCHIZO_STCTAG_VALID 0x8000000000000000UL
  389. #define SCHIZO_STCTAG_READ 0x4000000000000000UL
  390. #define SCHIZO_STCLINE_LINDX 0x0000000007800000UL
  391. #define SCHIZO_STCLINE_SPTR 0x000000000007e000UL
  392. #define SCHIZO_STCLINE_LADDR 0x0000000000001fc0UL
  393. #define SCHIZO_STCLINE_EPTR 0x000000000000003fUL
  394. #define SCHIZO_STCLINE_VALID 0x0000000000600000UL
  395. #define SCHIZO_STCLINE_FOFN 0x0000000000180000UL
  396. static void __schizo_check_stc_error_pbm(struct pci_pbm_info *pbm,
  397. enum schizo_error_type type)
  398. {
  399. struct pci_strbuf *strbuf = &pbm->stc;
  400. unsigned long regbase = pbm->pbm_regs;
  401. unsigned long err_base, tag_base, line_base;
  402. u64 control;
  403. int i;
  404. err_base = regbase + SCHIZO_STC_ERR;
  405. tag_base = regbase + SCHIZO_STC_TAG;
  406. line_base = regbase + SCHIZO_STC_LINE;
  407. spin_lock(&stc_buf_lock);
  408. /* This is __REALLY__ dangerous. When we put the
  409. * streaming buffer into diagnostic mode to probe
  410. * it's tags and error status, we _must_ clear all
  411. * of the line tag valid bits before re-enabling
  412. * the streaming buffer. If any dirty data lives
  413. * in the STC when we do this, we will end up
  414. * invalidating it before it has a chance to reach
  415. * main memory.
  416. */
  417. control = schizo_read(strbuf->strbuf_control);
  418. schizo_write(strbuf->strbuf_control,
  419. (control | SCHIZO_STRBUF_CTRL_DENAB));
  420. for (i = 0; i < 128; i++) {
  421. unsigned long val;
  422. val = schizo_read(err_base + (i * 8UL));
  423. schizo_write(err_base + (i * 8UL), 0UL);
  424. stc_error_buf[i] = val;
  425. }
  426. for (i = 0; i < 16; i++) {
  427. stc_tag_buf[i] = schizo_read(tag_base + (i * 8UL));
  428. stc_line_buf[i] = schizo_read(line_base + (i * 8UL));
  429. schizo_write(tag_base + (i * 8UL), 0UL);
  430. schizo_write(line_base + (i * 8UL), 0UL);
  431. }
  432. /* OK, state is logged, exit diagnostic mode. */
  433. schizo_write(strbuf->strbuf_control, control);
  434. for (i = 0; i < 16; i++) {
  435. int j, saw_error, first, last;
  436. saw_error = 0;
  437. first = i * 8;
  438. last = first + 8;
  439. for (j = first; j < last; j++) {
  440. unsigned long errval = stc_error_buf[j];
  441. if (errval != 0) {
  442. saw_error++;
  443. printk("%s: STC_ERR(%d)[wr(%d)rd(%d)]\n",
  444. pbm->name,
  445. j,
  446. (errval & SCHIZO_STCERR_WRITE) ? 1 : 0,
  447. (errval & SCHIZO_STCERR_READ) ? 1 : 0);
  448. }
  449. }
  450. if (saw_error != 0) {
  451. unsigned long tagval = stc_tag_buf[i];
  452. unsigned long lineval = stc_line_buf[i];
  453. printk("%s: STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)R(%d)]\n",
  454. pbm->name,
  455. i,
  456. ((tagval & SCHIZO_STCTAG_PPN) >> 19UL),
  457. (tagval & SCHIZO_STCTAG_VPN),
  458. ((tagval & SCHIZO_STCTAG_VALID) ? 1 : 0),
  459. ((tagval & SCHIZO_STCTAG_READ) ? 1 : 0));
  460. /* XXX Should spit out per-bank error information... -DaveM */
  461. printk("%s: STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
  462. "V(%d)FOFN(%d)]\n",
  463. pbm->name,
  464. i,
  465. ((lineval & SCHIZO_STCLINE_LINDX) >> 23UL),
  466. ((lineval & SCHIZO_STCLINE_SPTR) >> 13UL),
  467. ((lineval & SCHIZO_STCLINE_LADDR) >> 6UL),
  468. ((lineval & SCHIZO_STCLINE_EPTR) >> 0UL),
  469. ((lineval & SCHIZO_STCLINE_VALID) ? 1 : 0),
  470. ((lineval & SCHIZO_STCLINE_FOFN) ? 1 : 0));
  471. }
  472. }
  473. spin_unlock(&stc_buf_lock);
  474. }
  475. /* IOMMU is per-PBM in Schizo, so interrogate both for anonymous
  476. * controller level errors.
  477. */
  478. #define SCHIZO_IOMMU_TAG 0xa580UL
  479. #define SCHIZO_IOMMU_DATA 0xa600UL
  480. #define SCHIZO_IOMMU_TAG_CTXT 0x0000001ffe000000UL
  481. #define SCHIZO_IOMMU_TAG_ERRSTS 0x0000000001800000UL
  482. #define SCHIZO_IOMMU_TAG_ERR 0x0000000000400000UL
  483. #define SCHIZO_IOMMU_TAG_WRITE 0x0000000000200000UL
  484. #define SCHIZO_IOMMU_TAG_STREAM 0x0000000000100000UL
  485. #define SCHIZO_IOMMU_TAG_SIZE 0x0000000000080000UL
  486. #define SCHIZO_IOMMU_TAG_VPAGE 0x000000000007ffffUL
  487. #define SCHIZO_IOMMU_DATA_VALID 0x0000000100000000UL
  488. #define SCHIZO_IOMMU_DATA_CACHE 0x0000000040000000UL
  489. #define SCHIZO_IOMMU_DATA_PPAGE 0x000000003fffffffUL
  490. static void schizo_check_iommu_error_pbm(struct pci_pbm_info *pbm,
  491. enum schizo_error_type type)
  492. {
  493. struct pci_iommu *iommu = pbm->iommu;
  494. unsigned long iommu_tag[16];
  495. unsigned long iommu_data[16];
  496. unsigned long flags;
  497. u64 control;
  498. int i;
  499. spin_lock_irqsave(&iommu->lock, flags);
  500. control = schizo_read(iommu->iommu_control);
  501. if (control & SCHIZO_IOMMU_CTRL_XLTEERR) {
  502. unsigned long base;
  503. char *type_string;
  504. /* Clear the error encountered bit. */
  505. control &= ~SCHIZO_IOMMU_CTRL_XLTEERR;
  506. schizo_write(iommu->iommu_control, control);
  507. switch((control & SCHIZO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
  508. case 0:
  509. type_string = "Protection Error";
  510. break;
  511. case 1:
  512. type_string = "Invalid Error";
  513. break;
  514. case 2:
  515. type_string = "TimeOut Error";
  516. break;
  517. case 3:
  518. default:
  519. type_string = "ECC Error";
  520. break;
  521. };
  522. printk("%s: IOMMU Error, type[%s]\n",
  523. pbm->name, type_string);
  524. /* Put the IOMMU into diagnostic mode and probe
  525. * it's TLB for entries with error status.
  526. *
  527. * It is very possible for another DVMA to occur
  528. * while we do this probe, and corrupt the system
  529. * further. But we are so screwed at this point
  530. * that we are likely to crash hard anyways, so
  531. * get as much diagnostic information to the
  532. * console as we can.
  533. */
  534. schizo_write(iommu->iommu_control,
  535. control | SCHIZO_IOMMU_CTRL_DENAB);
  536. base = pbm->pbm_regs;
  537. for (i = 0; i < 16; i++) {
  538. iommu_tag[i] =
  539. schizo_read(base + SCHIZO_IOMMU_TAG + (i * 8UL));
  540. iommu_data[i] =
  541. schizo_read(base + SCHIZO_IOMMU_DATA + (i * 8UL));
  542. /* Now clear out the entry. */
  543. schizo_write(base + SCHIZO_IOMMU_TAG + (i * 8UL), 0);
  544. schizo_write(base + SCHIZO_IOMMU_DATA + (i * 8UL), 0);
  545. }
  546. /* Leave diagnostic mode. */
  547. schizo_write(iommu->iommu_control, control);
  548. for (i = 0; i < 16; i++) {
  549. unsigned long tag, data;
  550. tag = iommu_tag[i];
  551. if (!(tag & SCHIZO_IOMMU_TAG_ERR))
  552. continue;
  553. data = iommu_data[i];
  554. switch((tag & SCHIZO_IOMMU_TAG_ERRSTS) >> 23UL) {
  555. case 0:
  556. type_string = "Protection Error";
  557. break;
  558. case 1:
  559. type_string = "Invalid Error";
  560. break;
  561. case 2:
  562. type_string = "TimeOut Error";
  563. break;
  564. case 3:
  565. default:
  566. type_string = "ECC Error";
  567. break;
  568. };
  569. printk("%s: IOMMU TAG(%d)[error(%s) ctx(%x) wr(%d) str(%d) "
  570. "sz(%dK) vpg(%08lx)]\n",
  571. pbm->name, i, type_string,
  572. (int)((tag & SCHIZO_IOMMU_TAG_CTXT) >> 25UL),
  573. ((tag & SCHIZO_IOMMU_TAG_WRITE) ? 1 : 0),
  574. ((tag & SCHIZO_IOMMU_TAG_STREAM) ? 1 : 0),
  575. ((tag & SCHIZO_IOMMU_TAG_SIZE) ? 64 : 8),
  576. (tag & SCHIZO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
  577. printk("%s: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]\n",
  578. pbm->name, i,
  579. ((data & SCHIZO_IOMMU_DATA_VALID) ? 1 : 0),
  580. ((data & SCHIZO_IOMMU_DATA_CACHE) ? 1 : 0),
  581. (data & SCHIZO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
  582. }
  583. }
  584. if (pbm->stc.strbuf_enabled)
  585. __schizo_check_stc_error_pbm(pbm, type);
  586. spin_unlock_irqrestore(&iommu->lock, flags);
  587. }
  588. static void schizo_check_iommu_error(struct pci_controller_info *p,
  589. enum schizo_error_type type)
  590. {
  591. schizo_check_iommu_error_pbm(&p->pbm_A, type);
  592. schizo_check_iommu_error_pbm(&p->pbm_B, type);
  593. }
  594. /* Uncorrectable ECC error status gathering. */
  595. #define SCHIZO_UE_AFSR 0x10030UL
  596. #define SCHIZO_UE_AFAR 0x10038UL
  597. #define SCHIZO_UEAFSR_PPIO 0x8000000000000000UL /* Safari */
  598. #define SCHIZO_UEAFSR_PDRD 0x4000000000000000UL /* Safari/Tomatillo */
  599. #define SCHIZO_UEAFSR_PDWR 0x2000000000000000UL /* Safari */
  600. #define SCHIZO_UEAFSR_SPIO 0x1000000000000000UL /* Safari */
  601. #define SCHIZO_UEAFSR_SDMA 0x0800000000000000UL /* Safari/Tomatillo */
  602. #define SCHIZO_UEAFSR_ERRPNDG 0x0300000000000000UL /* Safari */
  603. #define SCHIZO_UEAFSR_BMSK 0x000003ff00000000UL /* Safari */
  604. #define SCHIZO_UEAFSR_QOFF 0x00000000c0000000UL /* Safari/Tomatillo */
  605. #define SCHIZO_UEAFSR_AID 0x000000001f000000UL /* Safari/Tomatillo */
  606. #define SCHIZO_UEAFSR_PARTIAL 0x0000000000800000UL /* Safari */
  607. #define SCHIZO_UEAFSR_OWNEDIN 0x0000000000400000UL /* Safari */
  608. #define SCHIZO_UEAFSR_MTAGSYND 0x00000000000f0000UL /* Safari */
  609. #define SCHIZO_UEAFSR_MTAG 0x000000000000e000UL /* Safari */
  610. #define SCHIZO_UEAFSR_ECCSYND 0x00000000000001ffUL /* Safari */
  611. static irqreturn_t schizo_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
  612. {
  613. struct pci_controller_info *p = dev_id;
  614. unsigned long afsr_reg = p->pbm_B.controller_regs + SCHIZO_UE_AFSR;
  615. unsigned long afar_reg = p->pbm_B.controller_regs + SCHIZO_UE_AFAR;
  616. unsigned long afsr, afar, error_bits;
  617. int reported, limit;
  618. /* Latch uncorrectable error status. */
  619. afar = schizo_read(afar_reg);
  620. /* If either of the error pending bits are set in the
  621. * AFSR, the error status is being actively updated by
  622. * the hardware and we must re-read to get a clean value.
  623. */
  624. limit = 1000;
  625. do {
  626. afsr = schizo_read(afsr_reg);
  627. } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
  628. /* Clear the primary/secondary error status bits. */
  629. error_bits = afsr &
  630. (SCHIZO_UEAFSR_PPIO | SCHIZO_UEAFSR_PDRD | SCHIZO_UEAFSR_PDWR |
  631. SCHIZO_UEAFSR_SPIO | SCHIZO_UEAFSR_SDMA);
  632. if (!error_bits)
  633. return IRQ_NONE;
  634. schizo_write(afsr_reg, error_bits);
  635. /* Log the error. */
  636. printk("PCI%d: Uncorrectable Error, primary error type[%s]\n",
  637. p->index,
  638. (((error_bits & SCHIZO_UEAFSR_PPIO) ?
  639. "PIO" :
  640. ((error_bits & SCHIZO_UEAFSR_PDRD) ?
  641. "DMA Read" :
  642. ((error_bits & SCHIZO_UEAFSR_PDWR) ?
  643. "DMA Write" : "???")))));
  644. printk("PCI%d: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]\n",
  645. p->index,
  646. (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
  647. (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
  648. (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
  649. printk("PCI%d: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]\n",
  650. p->index,
  651. (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
  652. (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
  653. (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
  654. (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
  655. (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
  656. printk("PCI%d: UE AFAR [%016lx]\n", p->index, afar);
  657. printk("PCI%d: UE Secondary errors [", p->index);
  658. reported = 0;
  659. if (afsr & SCHIZO_UEAFSR_SPIO) {
  660. reported++;
  661. printk("(PIO)");
  662. }
  663. if (afsr & SCHIZO_UEAFSR_SDMA) {
  664. reported++;
  665. printk("(DMA)");
  666. }
  667. if (!reported)
  668. printk("(none)");
  669. printk("]\n");
  670. /* Interrogate IOMMU for error status. */
  671. schizo_check_iommu_error(p, UE_ERR);
  672. schizo_clear_other_err_intr(p, irq);
  673. return IRQ_HANDLED;
  674. }
  675. #define SCHIZO_CE_AFSR 0x10040UL
  676. #define SCHIZO_CE_AFAR 0x10048UL
  677. #define SCHIZO_CEAFSR_PPIO 0x8000000000000000UL
  678. #define SCHIZO_CEAFSR_PDRD 0x4000000000000000UL
  679. #define SCHIZO_CEAFSR_PDWR 0x2000000000000000UL
  680. #define SCHIZO_CEAFSR_SPIO 0x1000000000000000UL
  681. #define SCHIZO_CEAFSR_SDMA 0x0800000000000000UL
  682. #define SCHIZO_CEAFSR_ERRPNDG 0x0300000000000000UL
  683. #define SCHIZO_CEAFSR_BMSK 0x000003ff00000000UL
  684. #define SCHIZO_CEAFSR_QOFF 0x00000000c0000000UL
  685. #define SCHIZO_CEAFSR_AID 0x000000001f000000UL
  686. #define SCHIZO_CEAFSR_PARTIAL 0x0000000000800000UL
  687. #define SCHIZO_CEAFSR_OWNEDIN 0x0000000000400000UL
  688. #define SCHIZO_CEAFSR_MTAGSYND 0x00000000000f0000UL
  689. #define SCHIZO_CEAFSR_MTAG 0x000000000000e000UL
  690. #define SCHIZO_CEAFSR_ECCSYND 0x00000000000001ffUL
  691. static irqreturn_t schizo_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
  692. {
  693. struct pci_controller_info *p = dev_id;
  694. unsigned long afsr_reg = p->pbm_B.controller_regs + SCHIZO_CE_AFSR;
  695. unsigned long afar_reg = p->pbm_B.controller_regs + SCHIZO_CE_AFAR;
  696. unsigned long afsr, afar, error_bits;
  697. int reported, limit;
  698. /* Latch error status. */
  699. afar = schizo_read(afar_reg);
  700. /* If either of the error pending bits are set in the
  701. * AFSR, the error status is being actively updated by
  702. * the hardware and we must re-read to get a clean value.
  703. */
  704. limit = 1000;
  705. do {
  706. afsr = schizo_read(afsr_reg);
  707. } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
  708. /* Clear primary/secondary error status bits. */
  709. error_bits = afsr &
  710. (SCHIZO_CEAFSR_PPIO | SCHIZO_CEAFSR_PDRD | SCHIZO_CEAFSR_PDWR |
  711. SCHIZO_CEAFSR_SPIO | SCHIZO_CEAFSR_SDMA);
  712. if (!error_bits)
  713. return IRQ_NONE;
  714. schizo_write(afsr_reg, error_bits);
  715. /* Log the error. */
  716. printk("PCI%d: Correctable Error, primary error type[%s]\n",
  717. p->index,
  718. (((error_bits & SCHIZO_CEAFSR_PPIO) ?
  719. "PIO" :
  720. ((error_bits & SCHIZO_CEAFSR_PDRD) ?
  721. "DMA Read" :
  722. ((error_bits & SCHIZO_CEAFSR_PDWR) ?
  723. "DMA Write" : "???")))));
  724. /* XXX Use syndrome and afar to print out module string just like
  725. * XXX UDB CE trap handler does... -DaveM
  726. */
  727. printk("PCI%d: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]\n",
  728. p->index,
  729. (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
  730. (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
  731. (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
  732. printk("PCI%d: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]\n",
  733. p->index,
  734. (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
  735. (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
  736. (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
  737. (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
  738. (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
  739. printk("PCI%d: CE AFAR [%016lx]\n", p->index, afar);
  740. printk("PCI%d: CE Secondary errors [", p->index);
  741. reported = 0;
  742. if (afsr & SCHIZO_CEAFSR_SPIO) {
  743. reported++;
  744. printk("(PIO)");
  745. }
  746. if (afsr & SCHIZO_CEAFSR_SDMA) {
  747. reported++;
  748. printk("(DMA)");
  749. }
  750. if (!reported)
  751. printk("(none)");
  752. printk("]\n");
  753. schizo_clear_other_err_intr(p, irq);
  754. return IRQ_HANDLED;
  755. }
  756. #define SCHIZO_PCI_AFSR 0x2010UL
  757. #define SCHIZO_PCI_AFAR 0x2018UL
  758. #define SCHIZO_PCIAFSR_PMA 0x8000000000000000UL /* Schizo/Tomatillo */
  759. #define SCHIZO_PCIAFSR_PTA 0x4000000000000000UL /* Schizo/Tomatillo */
  760. #define SCHIZO_PCIAFSR_PRTRY 0x2000000000000000UL /* Schizo/Tomatillo */
  761. #define SCHIZO_PCIAFSR_PPERR 0x1000000000000000UL /* Schizo/Tomatillo */
  762. #define SCHIZO_PCIAFSR_PTTO 0x0800000000000000UL /* Schizo/Tomatillo */
  763. #define SCHIZO_PCIAFSR_PUNUS 0x0400000000000000UL /* Schizo */
  764. #define SCHIZO_PCIAFSR_SMA 0x0200000000000000UL /* Schizo/Tomatillo */
  765. #define SCHIZO_PCIAFSR_STA 0x0100000000000000UL /* Schizo/Tomatillo */
  766. #define SCHIZO_PCIAFSR_SRTRY 0x0080000000000000UL /* Schizo/Tomatillo */
  767. #define SCHIZO_PCIAFSR_SPERR 0x0040000000000000UL /* Schizo/Tomatillo */
  768. #define SCHIZO_PCIAFSR_STTO 0x0020000000000000UL /* Schizo/Tomatillo */
  769. #define SCHIZO_PCIAFSR_SUNUS 0x0010000000000000UL /* Schizo */
  770. #define SCHIZO_PCIAFSR_BMSK 0x000003ff00000000UL /* Schizo/Tomatillo */
  771. #define SCHIZO_PCIAFSR_BLK 0x0000000080000000UL /* Schizo/Tomatillo */
  772. #define SCHIZO_PCIAFSR_CFG 0x0000000040000000UL /* Schizo/Tomatillo */
  773. #define SCHIZO_PCIAFSR_MEM 0x0000000020000000UL /* Schizo/Tomatillo */
  774. #define SCHIZO_PCIAFSR_IO 0x0000000010000000UL /* Schizo/Tomatillo */
  775. #define SCHIZO_PCI_CTRL (0x2000UL)
  776. #define SCHIZO_PCICTRL_BUS_UNUS (1UL << 63UL) /* Safari */
  777. #define SCHIZO_PCICTRL_ARB_PRIO (0x1ff << 52UL) /* Tomatillo */
  778. #define SCHIZO_PCICTRL_ESLCK (1UL << 51UL) /* Safari */
  779. #define SCHIZO_PCICTRL_ERRSLOT (7UL << 48UL) /* Safari */
  780. #define SCHIZO_PCICTRL_TTO_ERR (1UL << 38UL) /* Safari/Tomatillo */
  781. #define SCHIZO_PCICTRL_RTRY_ERR (1UL << 37UL) /* Safari/Tomatillo */
  782. #define SCHIZO_PCICTRL_DTO_ERR (1UL << 36UL) /* Safari/Tomatillo */
  783. #define SCHIZO_PCICTRL_SBH_ERR (1UL << 35UL) /* Safari */
  784. #define SCHIZO_PCICTRL_SERR (1UL << 34UL) /* Safari/Tomatillo */
  785. #define SCHIZO_PCICTRL_PCISPD (1UL << 33UL) /* Safari */
  786. #define SCHIZO_PCICTRL_MRM_PREF (1UL << 30UL) /* Tomatillo */
  787. #define SCHIZO_PCICTRL_RDO_PREF (1UL << 29UL) /* Tomatillo */
  788. #define SCHIZO_PCICTRL_RDL_PREF (1UL << 28UL) /* Tomatillo */
  789. #define SCHIZO_PCICTRL_PTO (3UL << 24UL) /* Safari/Tomatillo */
  790. #define SCHIZO_PCICTRL_PTO_SHIFT 24UL
  791. #define SCHIZO_PCICTRL_TRWSW (7UL << 21UL) /* Tomatillo */
  792. #define SCHIZO_PCICTRL_F_TGT_A (1UL << 20UL) /* Tomatillo */
  793. #define SCHIZO_PCICTRL_S_DTO_INT (1UL << 19UL) /* Safari */
  794. #define SCHIZO_PCICTRL_F_TGT_RT (1UL << 19UL) /* Tomatillo */
  795. #define SCHIZO_PCICTRL_SBH_INT (1UL << 18UL) /* Safari */
  796. #define SCHIZO_PCICTRL_T_DTO_INT (1UL << 18UL) /* Tomatillo */
  797. #define SCHIZO_PCICTRL_EEN (1UL << 17UL) /* Safari/Tomatillo */
  798. #define SCHIZO_PCICTRL_PARK (1UL << 16UL) /* Safari/Tomatillo */
  799. #define SCHIZO_PCICTRL_PCIRST (1UL << 8UL) /* Safari */
  800. #define SCHIZO_PCICTRL_ARB_S (0x3fUL << 0UL) /* Safari */
  801. #define SCHIZO_PCICTRL_ARB_T (0xffUL << 0UL) /* Tomatillo */
  802. static irqreturn_t schizo_pcierr_intr_other(struct pci_pbm_info *pbm)
  803. {
  804. unsigned long csr_reg, csr, csr_error_bits;
  805. irqreturn_t ret = IRQ_NONE;
  806. u16 stat;
  807. csr_reg = pbm->pbm_regs + SCHIZO_PCI_CTRL;
  808. csr = schizo_read(csr_reg);
  809. csr_error_bits =
  810. csr & (SCHIZO_PCICTRL_BUS_UNUS |
  811. SCHIZO_PCICTRL_TTO_ERR |
  812. SCHIZO_PCICTRL_RTRY_ERR |
  813. SCHIZO_PCICTRL_DTO_ERR |
  814. SCHIZO_PCICTRL_SBH_ERR |
  815. SCHIZO_PCICTRL_SERR);
  816. if (csr_error_bits) {
  817. /* Clear the errors. */
  818. schizo_write(csr_reg, csr);
  819. /* Log 'em. */
  820. if (csr_error_bits & SCHIZO_PCICTRL_BUS_UNUS)
  821. printk("%s: Bus unusable error asserted.\n",
  822. pbm->name);
  823. if (csr_error_bits & SCHIZO_PCICTRL_TTO_ERR)
  824. printk("%s: PCI TRDY# timeout error asserted.\n",
  825. pbm->name);
  826. if (csr_error_bits & SCHIZO_PCICTRL_RTRY_ERR)
  827. printk("%s: PCI excessive retry error asserted.\n",
  828. pbm->name);
  829. if (csr_error_bits & SCHIZO_PCICTRL_DTO_ERR)
  830. printk("%s: PCI discard timeout error asserted.\n",
  831. pbm->name);
  832. if (csr_error_bits & SCHIZO_PCICTRL_SBH_ERR)
  833. printk("%s: PCI streaming byte hole error asserted.\n",
  834. pbm->name);
  835. if (csr_error_bits & SCHIZO_PCICTRL_SERR)
  836. printk("%s: PCI SERR signal asserted.\n",
  837. pbm->name);
  838. ret = IRQ_HANDLED;
  839. }
  840. pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat);
  841. if (stat & (PCI_STATUS_PARITY |
  842. PCI_STATUS_SIG_TARGET_ABORT |
  843. PCI_STATUS_REC_TARGET_ABORT |
  844. PCI_STATUS_REC_MASTER_ABORT |
  845. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  846. printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
  847. pbm->name, stat);
  848. pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff);
  849. ret = IRQ_HANDLED;
  850. }
  851. return ret;
  852. }
  853. static irqreturn_t schizo_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
  854. {
  855. struct pci_pbm_info *pbm = dev_id;
  856. struct pci_controller_info *p = pbm->parent;
  857. unsigned long afsr_reg, afar_reg, base;
  858. unsigned long afsr, afar, error_bits;
  859. int reported;
  860. base = pbm->pbm_regs;
  861. afsr_reg = base + SCHIZO_PCI_AFSR;
  862. afar_reg = base + SCHIZO_PCI_AFAR;
  863. /* Latch error status. */
  864. afar = schizo_read(afar_reg);
  865. afsr = schizo_read(afsr_reg);
  866. /* Clear primary/secondary error status bits. */
  867. error_bits = afsr &
  868. (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  869. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  870. SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  871. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  872. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  873. SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS);
  874. if (!error_bits)
  875. return schizo_pcierr_intr_other(pbm);
  876. schizo_write(afsr_reg, error_bits);
  877. /* Log the error. */
  878. printk("%s: PCI Error, primary error type[%s]\n",
  879. pbm->name,
  880. (((error_bits & SCHIZO_PCIAFSR_PMA) ?
  881. "Master Abort" :
  882. ((error_bits & SCHIZO_PCIAFSR_PTA) ?
  883. "Target Abort" :
  884. ((error_bits & SCHIZO_PCIAFSR_PRTRY) ?
  885. "Excessive Retries" :
  886. ((error_bits & SCHIZO_PCIAFSR_PPERR) ?
  887. "Parity Error" :
  888. ((error_bits & SCHIZO_PCIAFSR_PTTO) ?
  889. "Timeout" :
  890. ((error_bits & SCHIZO_PCIAFSR_PUNUS) ?
  891. "Bus Unusable" : "???"))))))));
  892. printk("%s: bytemask[%04lx] was_block(%d) space(%s)\n",
  893. pbm->name,
  894. (afsr & SCHIZO_PCIAFSR_BMSK) >> 32UL,
  895. (afsr & SCHIZO_PCIAFSR_BLK) ? 1 : 0,
  896. ((afsr & SCHIZO_PCIAFSR_CFG) ?
  897. "Config" :
  898. ((afsr & SCHIZO_PCIAFSR_MEM) ?
  899. "Memory" :
  900. ((afsr & SCHIZO_PCIAFSR_IO) ?
  901. "I/O" : "???"))));
  902. printk("%s: PCI AFAR [%016lx]\n",
  903. pbm->name, afar);
  904. printk("%s: PCI Secondary errors [",
  905. pbm->name);
  906. reported = 0;
  907. if (afsr & SCHIZO_PCIAFSR_SMA) {
  908. reported++;
  909. printk("(Master Abort)");
  910. }
  911. if (afsr & SCHIZO_PCIAFSR_STA) {
  912. reported++;
  913. printk("(Target Abort)");
  914. }
  915. if (afsr & SCHIZO_PCIAFSR_SRTRY) {
  916. reported++;
  917. printk("(Excessive Retries)");
  918. }
  919. if (afsr & SCHIZO_PCIAFSR_SPERR) {
  920. reported++;
  921. printk("(Parity Error)");
  922. }
  923. if (afsr & SCHIZO_PCIAFSR_STTO) {
  924. reported++;
  925. printk("(Timeout)");
  926. }
  927. if (afsr & SCHIZO_PCIAFSR_SUNUS) {
  928. reported++;
  929. printk("(Bus Unusable)");
  930. }
  931. if (!reported)
  932. printk("(none)");
  933. printk("]\n");
  934. /* For the error types shown, scan PBM's PCI bus for devices
  935. * which have logged that error type.
  936. */
  937. /* If we see a Target Abort, this could be the result of an
  938. * IOMMU translation error of some sort. It is extremely
  939. * useful to log this information as usually it indicates
  940. * a bug in the IOMMU support code or a PCI device driver.
  941. */
  942. if (error_bits & (SCHIZO_PCIAFSR_PTA | SCHIZO_PCIAFSR_STA)) {
  943. schizo_check_iommu_error(p, PCI_ERR);
  944. pci_scan_for_target_abort(p, pbm, pbm->pci_bus);
  945. }
  946. if (error_bits & (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_SMA))
  947. pci_scan_for_master_abort(p, pbm, pbm->pci_bus);
  948. /* For excessive retries, PSYCHO/PBM will abort the device
  949. * and there is no way to specifically check for excessive
  950. * retries in the config space status registers. So what
  951. * we hope is that we'll catch it via the master/target
  952. * abort events.
  953. */
  954. if (error_bits & (SCHIZO_PCIAFSR_PPERR | SCHIZO_PCIAFSR_SPERR))
  955. pci_scan_for_parity_error(p, pbm, pbm->pci_bus);
  956. schizo_clear_other_err_intr(p, irq);
  957. return IRQ_HANDLED;
  958. }
  959. #define SCHIZO_SAFARI_ERRLOG 0x10018UL
  960. #define SAFARI_ERRLOG_ERROUT 0x8000000000000000UL
  961. #define BUS_ERROR_BADCMD 0x4000000000000000UL /* Schizo/Tomatillo */
  962. #define BUS_ERROR_SSMDIS 0x2000000000000000UL /* Safari */
  963. #define BUS_ERROR_BADMA 0x1000000000000000UL /* Safari */
  964. #define BUS_ERROR_BADMB 0x0800000000000000UL /* Safari */
  965. #define BUS_ERROR_BADMC 0x0400000000000000UL /* Safari */
  966. #define BUS_ERROR_SNOOP_GR 0x0000000000200000UL /* Tomatillo */
  967. #define BUS_ERROR_SNOOP_PCI 0x0000000000100000UL /* Tomatillo */
  968. #define BUS_ERROR_SNOOP_RD 0x0000000000080000UL /* Tomatillo */
  969. #define BUS_ERROR_SNOOP_RDS 0x0000000000020000UL /* Tomatillo */
  970. #define BUS_ERROR_SNOOP_RDSA 0x0000000000010000UL /* Tomatillo */
  971. #define BUS_ERROR_SNOOP_OWN 0x0000000000008000UL /* Tomatillo */
  972. #define BUS_ERROR_SNOOP_RDO 0x0000000000004000UL /* Tomatillo */
  973. #define BUS_ERROR_CPU1PS 0x0000000000002000UL /* Safari */
  974. #define BUS_ERROR_WDATA_PERR 0x0000000000002000UL /* Tomatillo */
  975. #define BUS_ERROR_CPU1PB 0x0000000000001000UL /* Safari */
  976. #define BUS_ERROR_CTRL_PERR 0x0000000000001000UL /* Tomatillo */
  977. #define BUS_ERROR_CPU0PS 0x0000000000000800UL /* Safari */
  978. #define BUS_ERROR_SNOOP_ERR 0x0000000000000800UL /* Tomatillo */
  979. #define BUS_ERROR_CPU0PB 0x0000000000000400UL /* Safari */
  980. #define BUS_ERROR_JBUS_ILL_B 0x0000000000000400UL /* Tomatillo */
  981. #define BUS_ERROR_CIQTO 0x0000000000000200UL /* Safari */
  982. #define BUS_ERROR_LPQTO 0x0000000000000100UL /* Safari */
  983. #define BUS_ERROR_JBUS_ILL_C 0x0000000000000100UL /* Tomatillo */
  984. #define BUS_ERROR_SFPQTO 0x0000000000000080UL /* Safari */
  985. #define BUS_ERROR_UFPQTO 0x0000000000000040UL /* Safari */
  986. #define BUS_ERROR_RD_PERR 0x0000000000000040UL /* Tomatillo */
  987. #define BUS_ERROR_APERR 0x0000000000000020UL /* Safari/Tomatillo */
  988. #define BUS_ERROR_UNMAP 0x0000000000000010UL /* Safari/Tomatillo */
  989. #define BUS_ERROR_BUSERR 0x0000000000000004UL /* Safari/Tomatillo */
  990. #define BUS_ERROR_TIMEOUT 0x0000000000000002UL /* Safari/Tomatillo */
  991. #define BUS_ERROR_ILL 0x0000000000000001UL /* Safari */
  992. /* We only expect UNMAP errors here. The rest of the Safari errors
  993. * are marked fatal and thus cause a system reset.
  994. */
  995. static irqreturn_t schizo_safarierr_intr(int irq, void *dev_id, struct pt_regs *regs)
  996. {
  997. struct pci_controller_info *p = dev_id;
  998. u64 errlog;
  999. errlog = schizo_read(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRLOG);
  1000. schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRLOG,
  1001. errlog & ~(SAFARI_ERRLOG_ERROUT));
  1002. if (!(errlog & BUS_ERROR_UNMAP)) {
  1003. printk("PCI%d: Unexpected Safari/JBUS error interrupt, errlog[%016lx]\n",
  1004. p->index, errlog);
  1005. schizo_clear_other_err_intr(p, irq);
  1006. return IRQ_HANDLED;
  1007. }
  1008. printk("PCI%d: Safari/JBUS interrupt, UNMAPPED error, interrogating IOMMUs.\n",
  1009. p->index);
  1010. schizo_check_iommu_error(p, SAFARI_ERR);
  1011. schizo_clear_other_err_intr(p, irq);
  1012. return IRQ_HANDLED;
  1013. }
  1014. /* Nearly identical to PSYCHO equivalents... */
  1015. #define SCHIZO_ECC_CTRL 0x10020UL
  1016. #define SCHIZO_ECCCTRL_EE 0x8000000000000000UL /* Enable ECC Checking */
  1017. #define SCHIZO_ECCCTRL_UE 0x4000000000000000UL /* Enable UE Interrupts */
  1018. #define SCHIZO_ECCCTRL_CE 0x2000000000000000UL /* Enable CE INterrupts */
  1019. #define SCHIZO_SAFARI_ERRCTRL 0x10008UL
  1020. #define SCHIZO_SAFERRCTRL_EN 0x8000000000000000UL
  1021. #define SCHIZO_SAFARI_IRQCTRL 0x10010UL
  1022. #define SCHIZO_SAFIRQCTRL_EN 0x8000000000000000UL
  1023. /* How the Tomatillo IRQs are routed around is pure guesswork here.
  1024. *
  1025. * All the Tomatillo devices I see in prtconf dumps seem to have only
  1026. * a single PCI bus unit attached to it. It would seem they are seperate
  1027. * devices because their PortID (ie. JBUS ID) values are all different
  1028. * and thus the registers are mapped to totally different locations.
  1029. *
  1030. * However, two Tomatillo's look "similar" in that the only difference
  1031. * in their PortID is the lowest bit.
  1032. *
  1033. * So if we were to ignore this lower bit, it certainly looks like two
  1034. * PCI bus units of the same Tomatillo. I still have not really
  1035. * figured this out...
  1036. */
  1037. static void __init tomatillo_register_error_handlers(struct pci_controller_info *p)
  1038. {
  1039. struct pci_pbm_info *pbm;
  1040. unsigned int irq;
  1041. struct ino_bucket *bucket;
  1042. u64 tmp, err_mask, err_no_mask;
  1043. /* Build IRQs and register handlers. */
  1044. pbm = pbm_for_ino(p, SCHIZO_UE_INO);
  1045. irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_UE_INO);
  1046. if (request_irq(irq, schizo_ue_intr,
  1047. SA_SHIRQ, "TOMATILLO UE", p) < 0) {
  1048. prom_printf("%s: Cannot register UE interrupt.\n",
  1049. pbm->name);
  1050. prom_halt();
  1051. }
  1052. bucket = __bucket(irq);
  1053. tmp = upa_readl(bucket->imap);
  1054. upa_writel(tmp, (pbm->pbm_regs +
  1055. schizo_imap_offset(SCHIZO_UE_INO) + 4));
  1056. pbm = pbm_for_ino(p, SCHIZO_CE_INO);
  1057. irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_CE_INO);
  1058. if (request_irq(irq, schizo_ce_intr,
  1059. SA_SHIRQ, "TOMATILLO CE", p) < 0) {
  1060. prom_printf("%s: Cannot register CE interrupt.\n",
  1061. pbm->name);
  1062. prom_halt();
  1063. }
  1064. bucket = __bucket(irq);
  1065. tmp = upa_readl(bucket->imap);
  1066. upa_writel(tmp, (pbm->pbm_regs +
  1067. schizo_imap_offset(SCHIZO_CE_INO) + 4));
  1068. pbm = pbm_for_ino(p, SCHIZO_PCIERR_A_INO);
  1069. irq = schizo_irq_build(pbm, NULL, ((pbm->portid << 6) |
  1070. SCHIZO_PCIERR_A_INO));
  1071. if (request_irq(irq, schizo_pcierr_intr,
  1072. SA_SHIRQ, "TOMATILLO PCIERR", pbm) < 0) {
  1073. prom_printf("%s: Cannot register PBM A PciERR interrupt.\n",
  1074. pbm->name);
  1075. prom_halt();
  1076. }
  1077. bucket = __bucket(irq);
  1078. tmp = upa_readl(bucket->imap);
  1079. upa_writel(tmp, (pbm->pbm_regs +
  1080. schizo_imap_offset(SCHIZO_PCIERR_A_INO) + 4));
  1081. pbm = pbm_for_ino(p, SCHIZO_PCIERR_B_INO);
  1082. irq = schizo_irq_build(pbm, NULL, ((pbm->portid << 6) |
  1083. SCHIZO_PCIERR_B_INO));
  1084. if (request_irq(irq, schizo_pcierr_intr,
  1085. SA_SHIRQ, "TOMATILLO PCIERR", pbm) < 0) {
  1086. prom_printf("%s: Cannot register PBM B PciERR interrupt.\n",
  1087. pbm->name);
  1088. prom_halt();
  1089. }
  1090. bucket = __bucket(irq);
  1091. tmp = upa_readl(bucket->imap);
  1092. upa_writel(tmp, (pbm->pbm_regs +
  1093. schizo_imap_offset(SCHIZO_PCIERR_B_INO) + 4));
  1094. pbm = pbm_for_ino(p, SCHIZO_SERR_INO);
  1095. irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_SERR_INO);
  1096. if (request_irq(irq, schizo_safarierr_intr,
  1097. SA_SHIRQ, "TOMATILLO SERR", p) < 0) {
  1098. prom_printf("%s: Cannot register SafariERR interrupt.\n",
  1099. pbm->name);
  1100. prom_halt();
  1101. }
  1102. bucket = __bucket(irq);
  1103. tmp = upa_readl(bucket->imap);
  1104. upa_writel(tmp, (pbm->pbm_regs +
  1105. schizo_imap_offset(SCHIZO_SERR_INO) + 4));
  1106. /* Enable UE and CE interrupts for controller. */
  1107. schizo_write(p->pbm_A.controller_regs + SCHIZO_ECC_CTRL,
  1108. (SCHIZO_ECCCTRL_EE |
  1109. SCHIZO_ECCCTRL_UE |
  1110. SCHIZO_ECCCTRL_CE));
  1111. schizo_write(p->pbm_B.controller_regs + SCHIZO_ECC_CTRL,
  1112. (SCHIZO_ECCCTRL_EE |
  1113. SCHIZO_ECCCTRL_UE |
  1114. SCHIZO_ECCCTRL_CE));
  1115. /* Enable PCI Error interrupts and clear error
  1116. * bits.
  1117. */
  1118. err_mask = (SCHIZO_PCICTRL_BUS_UNUS |
  1119. SCHIZO_PCICTRL_TTO_ERR |
  1120. SCHIZO_PCICTRL_RTRY_ERR |
  1121. SCHIZO_PCICTRL_SERR |
  1122. SCHIZO_PCICTRL_EEN);
  1123. err_no_mask = SCHIZO_PCICTRL_DTO_ERR;
  1124. tmp = schizo_read(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL);
  1125. tmp |= err_mask;
  1126. tmp &= ~err_no_mask;
  1127. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1128. tmp = schizo_read(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL);
  1129. tmp |= err_mask;
  1130. tmp &= ~err_no_mask;
  1131. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1132. err_mask = (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  1133. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  1134. SCHIZO_PCIAFSR_PTTO |
  1135. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  1136. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  1137. SCHIZO_PCIAFSR_STTO);
  1138. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_AFSR, err_mask);
  1139. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_AFSR, err_mask);
  1140. err_mask = (BUS_ERROR_BADCMD | BUS_ERROR_SNOOP_GR |
  1141. BUS_ERROR_SNOOP_PCI | BUS_ERROR_SNOOP_RD |
  1142. BUS_ERROR_SNOOP_RDS | BUS_ERROR_SNOOP_RDSA |
  1143. BUS_ERROR_SNOOP_OWN | BUS_ERROR_SNOOP_RDO |
  1144. BUS_ERROR_WDATA_PERR | BUS_ERROR_CTRL_PERR |
  1145. BUS_ERROR_SNOOP_ERR | BUS_ERROR_JBUS_ILL_B |
  1146. BUS_ERROR_JBUS_ILL_C | BUS_ERROR_RD_PERR |
  1147. BUS_ERROR_APERR | BUS_ERROR_UNMAP |
  1148. BUS_ERROR_BUSERR | BUS_ERROR_TIMEOUT);
  1149. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_ERRCTRL,
  1150. (SCHIZO_SAFERRCTRL_EN | err_mask));
  1151. schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_ERRCTRL,
  1152. (SCHIZO_SAFERRCTRL_EN | err_mask));
  1153. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_IRQCTRL,
  1154. (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
  1155. schizo_write(p->pbm_B.controller_regs + SCHIZO_SAFARI_IRQCTRL,
  1156. (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
  1157. }
  1158. static void __init schizo_register_error_handlers(struct pci_controller_info *p)
  1159. {
  1160. struct pci_pbm_info *pbm;
  1161. unsigned int irq;
  1162. struct ino_bucket *bucket;
  1163. u64 tmp, err_mask, err_no_mask;
  1164. /* Build IRQs and register handlers. */
  1165. pbm = pbm_for_ino(p, SCHIZO_UE_INO);
  1166. irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_UE_INO);
  1167. if (request_irq(irq, schizo_ue_intr,
  1168. SA_SHIRQ, "SCHIZO UE", p) < 0) {
  1169. prom_printf("%s: Cannot register UE interrupt.\n",
  1170. pbm->name);
  1171. prom_halt();
  1172. }
  1173. bucket = __bucket(irq);
  1174. tmp = upa_readl(bucket->imap);
  1175. upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_UE_INO) + 4));
  1176. pbm = pbm_for_ino(p, SCHIZO_CE_INO);
  1177. irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_CE_INO);
  1178. if (request_irq(irq, schizo_ce_intr,
  1179. SA_SHIRQ, "SCHIZO CE", p) < 0) {
  1180. prom_printf("%s: Cannot register CE interrupt.\n",
  1181. pbm->name);
  1182. prom_halt();
  1183. }
  1184. bucket = __bucket(irq);
  1185. tmp = upa_readl(bucket->imap);
  1186. upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_CE_INO) + 4));
  1187. pbm = pbm_for_ino(p, SCHIZO_PCIERR_A_INO);
  1188. irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_PCIERR_A_INO);
  1189. if (request_irq(irq, schizo_pcierr_intr,
  1190. SA_SHIRQ, "SCHIZO PCIERR", pbm) < 0) {
  1191. prom_printf("%s: Cannot register PBM A PciERR interrupt.\n",
  1192. pbm->name);
  1193. prom_halt();
  1194. }
  1195. bucket = __bucket(irq);
  1196. tmp = upa_readl(bucket->imap);
  1197. upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_PCIERR_A_INO) + 4));
  1198. pbm = pbm_for_ino(p, SCHIZO_PCIERR_B_INO);
  1199. irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_PCIERR_B_INO);
  1200. if (request_irq(irq, schizo_pcierr_intr,
  1201. SA_SHIRQ, "SCHIZO PCIERR", &p->pbm_B) < 0) {
  1202. prom_printf("%s: Cannot register PBM B PciERR interrupt.\n",
  1203. pbm->name);
  1204. prom_halt();
  1205. }
  1206. bucket = __bucket(irq);
  1207. tmp = upa_readl(bucket->imap);
  1208. upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_PCIERR_B_INO) + 4));
  1209. pbm = pbm_for_ino(p, SCHIZO_SERR_INO);
  1210. irq = schizo_irq_build(pbm, NULL, (pbm->portid << 6) | SCHIZO_SERR_INO);
  1211. if (request_irq(irq, schizo_safarierr_intr,
  1212. SA_SHIRQ, "SCHIZO SERR", p) < 0) {
  1213. prom_printf("%s: Cannot register SafariERR interrupt.\n",
  1214. pbm->name);
  1215. prom_halt();
  1216. }
  1217. bucket = __bucket(irq);
  1218. tmp = upa_readl(bucket->imap);
  1219. upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_SERR_INO) + 4));
  1220. /* Enable UE and CE interrupts for controller. */
  1221. schizo_write(p->pbm_A.controller_regs + SCHIZO_ECC_CTRL,
  1222. (SCHIZO_ECCCTRL_EE |
  1223. SCHIZO_ECCCTRL_UE |
  1224. SCHIZO_ECCCTRL_CE));
  1225. err_mask = (SCHIZO_PCICTRL_BUS_UNUS |
  1226. SCHIZO_PCICTRL_ESLCK |
  1227. SCHIZO_PCICTRL_TTO_ERR |
  1228. SCHIZO_PCICTRL_RTRY_ERR |
  1229. SCHIZO_PCICTRL_SBH_ERR |
  1230. SCHIZO_PCICTRL_SERR |
  1231. SCHIZO_PCICTRL_EEN);
  1232. err_no_mask = (SCHIZO_PCICTRL_DTO_ERR |
  1233. SCHIZO_PCICTRL_SBH_INT);
  1234. /* Enable PCI Error interrupts and clear error
  1235. * bits for each PBM.
  1236. */
  1237. tmp = schizo_read(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL);
  1238. tmp |= err_mask;
  1239. tmp &= ~err_no_mask;
  1240. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1241. schizo_write(p->pbm_A.pbm_regs + SCHIZO_PCI_AFSR,
  1242. (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  1243. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  1244. SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  1245. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  1246. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  1247. SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
  1248. tmp = schizo_read(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL);
  1249. tmp |= err_mask;
  1250. tmp &= ~err_no_mask;
  1251. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1252. schizo_write(p->pbm_B.pbm_regs + SCHIZO_PCI_AFSR,
  1253. (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  1254. SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  1255. SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  1256. SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  1257. SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  1258. SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
  1259. /* Make all Safari error conditions fatal except unmapped
  1260. * errors which we make generate interrupts.
  1261. */
  1262. err_mask = (BUS_ERROR_BADCMD | BUS_ERROR_SSMDIS |
  1263. BUS_ERROR_BADMA | BUS_ERROR_BADMB |
  1264. BUS_ERROR_BADMC |
  1265. BUS_ERROR_CPU1PS | BUS_ERROR_CPU1PB |
  1266. BUS_ERROR_CPU0PS | BUS_ERROR_CPU0PB |
  1267. BUS_ERROR_CIQTO |
  1268. BUS_ERROR_LPQTO | BUS_ERROR_SFPQTO |
  1269. BUS_ERROR_UFPQTO | BUS_ERROR_APERR |
  1270. BUS_ERROR_BUSERR | BUS_ERROR_TIMEOUT |
  1271. BUS_ERROR_ILL);
  1272. #if 1
  1273. /* XXX Something wrong with some Excalibur systems
  1274. * XXX Sun is shipping. The behavior on a 2-cpu
  1275. * XXX machine is that both CPU1 parity error bits
  1276. * XXX are set and are immediately set again when
  1277. * XXX their error status bits are cleared. Just
  1278. * XXX ignore them for now. -DaveM
  1279. */
  1280. err_mask &= ~(BUS_ERROR_CPU1PS | BUS_ERROR_CPU1PB |
  1281. BUS_ERROR_CPU0PS | BUS_ERROR_CPU0PB);
  1282. #endif
  1283. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_ERRCTRL,
  1284. (SCHIZO_SAFERRCTRL_EN | err_mask));
  1285. schizo_write(p->pbm_A.controller_regs + SCHIZO_SAFARI_IRQCTRL,
  1286. (SCHIZO_SAFIRQCTRL_EN | (BUS_ERROR_UNMAP)));
  1287. }
  1288. static void __init pbm_config_busmastering(struct pci_pbm_info *pbm)
  1289. {
  1290. u8 *addr;
  1291. /* Set cache-line size to 64 bytes, this is actually
  1292. * a nop but I do it for completeness.
  1293. */
  1294. addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1295. 0, PCI_CACHE_LINE_SIZE);
  1296. pci_config_write8(addr, 64 / sizeof(u32));
  1297. /* Set PBM latency timer to 64 PCI clocks. */
  1298. addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1299. 0, PCI_LATENCY_TIMER);
  1300. pci_config_write8(addr, 64);
  1301. }
  1302. static void __init pbm_scan_bus(struct pci_controller_info *p,
  1303. struct pci_pbm_info *pbm)
  1304. {
  1305. struct pcidev_cookie *cookie = kmalloc(sizeof(*cookie), GFP_KERNEL);
  1306. if (!cookie) {
  1307. prom_printf("%s: Critical allocation failure.\n", pbm->name);
  1308. prom_halt();
  1309. }
  1310. /* All we care about is the PBM. */
  1311. memset(cookie, 0, sizeof(*cookie));
  1312. cookie->pbm = pbm;
  1313. pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno,
  1314. p->pci_ops,
  1315. pbm);
  1316. pci_fixup_host_bridge_self(pbm->pci_bus);
  1317. pbm->pci_bus->self->sysdata = cookie;
  1318. pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
  1319. pci_record_assignments(pbm, pbm->pci_bus);
  1320. pci_assign_unassigned(pbm, pbm->pci_bus);
  1321. pci_fixup_irq(pbm, pbm->pci_bus);
  1322. pci_determine_66mhz_disposition(pbm, pbm->pci_bus);
  1323. pci_setup_busmastering(pbm, pbm->pci_bus);
  1324. }
  1325. static void __init __schizo_scan_bus(struct pci_controller_info *p,
  1326. int chip_type)
  1327. {
  1328. if (!p->pbm_B.prom_node || !p->pbm_A.prom_node) {
  1329. printk("PCI: Only one PCI bus module of controller found.\n");
  1330. printk("PCI: Ignoring entire controller.\n");
  1331. return;
  1332. }
  1333. pbm_config_busmastering(&p->pbm_B);
  1334. p->pbm_B.is_66mhz_capable =
  1335. prom_getbool(p->pbm_B.prom_node, "66mhz-capable");
  1336. pbm_config_busmastering(&p->pbm_A);
  1337. p->pbm_A.is_66mhz_capable =
  1338. prom_getbool(p->pbm_A.prom_node, "66mhz-capable");
  1339. pbm_scan_bus(p, &p->pbm_B);
  1340. pbm_scan_bus(p, &p->pbm_A);
  1341. /* After the PCI bus scan is complete, we can register
  1342. * the error interrupt handlers.
  1343. */
  1344. if (chip_type == PBM_CHIP_TYPE_TOMATILLO)
  1345. tomatillo_register_error_handlers(p);
  1346. else
  1347. schizo_register_error_handlers(p);
  1348. }
  1349. static void __init schizo_scan_bus(struct pci_controller_info *p)
  1350. {
  1351. __schizo_scan_bus(p, PBM_CHIP_TYPE_SCHIZO);
  1352. }
  1353. static void __init tomatillo_scan_bus(struct pci_controller_info *p)
  1354. {
  1355. __schizo_scan_bus(p, PBM_CHIP_TYPE_TOMATILLO);
  1356. }
  1357. static void __init schizo_base_address_update(struct pci_dev *pdev, int resource)
  1358. {
  1359. struct pcidev_cookie *pcp = pdev->sysdata;
  1360. struct pci_pbm_info *pbm = pcp->pbm;
  1361. struct resource *res, *root;
  1362. u32 reg;
  1363. int where, size, is_64bit;
  1364. res = &pdev->resource[resource];
  1365. if (resource < 6) {
  1366. where = PCI_BASE_ADDRESS_0 + (resource * 4);
  1367. } else if (resource == PCI_ROM_RESOURCE) {
  1368. where = pdev->rom_base_reg;
  1369. } else {
  1370. /* Somebody might have asked allocation of a non-standard resource */
  1371. return;
  1372. }
  1373. is_64bit = 0;
  1374. if (res->flags & IORESOURCE_IO)
  1375. root = &pbm->io_space;
  1376. else {
  1377. root = &pbm->mem_space;
  1378. if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
  1379. == PCI_BASE_ADDRESS_MEM_TYPE_64)
  1380. is_64bit = 1;
  1381. }
  1382. size = res->end - res->start;
  1383. pci_read_config_dword(pdev, where, &reg);
  1384. reg = ((reg & size) |
  1385. (((u32)(res->start - root->start)) & ~size));
  1386. if (resource == PCI_ROM_RESOURCE) {
  1387. reg |= PCI_ROM_ADDRESS_ENABLE;
  1388. res->flags |= IORESOURCE_ROM_ENABLE;
  1389. }
  1390. pci_write_config_dword(pdev, where, reg);
  1391. /* This knows that the upper 32-bits of the address
  1392. * must be zero. Our PCI common layer enforces this.
  1393. */
  1394. if (is_64bit)
  1395. pci_write_config_dword(pdev, where + 4, 0);
  1396. }
  1397. static void __init schizo_resource_adjust(struct pci_dev *pdev,
  1398. struct resource *res,
  1399. struct resource *root)
  1400. {
  1401. res->start += root->start;
  1402. res->end += root->start;
  1403. }
  1404. /* Use ranges property to determine where PCI MEM, I/O, and Config
  1405. * space are for this PCI bus module.
  1406. */
  1407. static void schizo_determine_mem_io_space(struct pci_pbm_info *pbm)
  1408. {
  1409. int i, saw_cfg, saw_mem, saw_io;
  1410. saw_cfg = saw_mem = saw_io = 0;
  1411. for (i = 0; i < pbm->num_pbm_ranges; i++) {
  1412. struct linux_prom_pci_ranges *pr = &pbm->pbm_ranges[i];
  1413. unsigned long a;
  1414. int type;
  1415. type = (pr->child_phys_hi >> 24) & 0x3;
  1416. a = (((unsigned long)pr->parent_phys_hi << 32UL) |
  1417. ((unsigned long)pr->parent_phys_lo << 0UL));
  1418. switch (type) {
  1419. case 0:
  1420. /* PCI config space, 16MB */
  1421. pbm->config_space = a;
  1422. saw_cfg = 1;
  1423. break;
  1424. case 1:
  1425. /* 16-bit IO space, 16MB */
  1426. pbm->io_space.start = a;
  1427. pbm->io_space.end = a + ((16UL*1024UL*1024UL) - 1UL);
  1428. pbm->io_space.flags = IORESOURCE_IO;
  1429. saw_io = 1;
  1430. break;
  1431. case 2:
  1432. /* 32-bit MEM space, 2GB */
  1433. pbm->mem_space.start = a;
  1434. pbm->mem_space.end = a + (0x80000000UL - 1UL);
  1435. pbm->mem_space.flags = IORESOURCE_MEM;
  1436. saw_mem = 1;
  1437. break;
  1438. default:
  1439. break;
  1440. };
  1441. }
  1442. if (!saw_cfg || !saw_io || !saw_mem) {
  1443. prom_printf("%s: Fatal error, missing %s PBM range.\n",
  1444. pbm->name,
  1445. ((!saw_cfg ?
  1446. "CFG" :
  1447. (!saw_io ?
  1448. "IO" : "MEM"))));
  1449. prom_halt();
  1450. }
  1451. printk("%s: PCI CFG[%lx] IO[%lx] MEM[%lx]\n",
  1452. pbm->name,
  1453. pbm->config_space,
  1454. pbm->io_space.start,
  1455. pbm->mem_space.start);
  1456. }
  1457. static void __init pbm_register_toplevel_resources(struct pci_controller_info *p,
  1458. struct pci_pbm_info *pbm)
  1459. {
  1460. pbm->io_space.name = pbm->mem_space.name = pbm->name;
  1461. request_resource(&ioport_resource, &pbm->io_space);
  1462. request_resource(&iomem_resource, &pbm->mem_space);
  1463. pci_register_legacy_regions(&pbm->io_space,
  1464. &pbm->mem_space);
  1465. }
  1466. #define SCHIZO_STRBUF_CONTROL (0x02800UL)
  1467. #define SCHIZO_STRBUF_FLUSH (0x02808UL)
  1468. #define SCHIZO_STRBUF_FSYNC (0x02810UL)
  1469. #define SCHIZO_STRBUF_CTXFLUSH (0x02818UL)
  1470. #define SCHIZO_STRBUF_CTXMATCH (0x10000UL)
  1471. static void schizo_pbm_strbuf_init(struct pci_pbm_info *pbm)
  1472. {
  1473. unsigned long base = pbm->pbm_regs;
  1474. u64 control;
  1475. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
  1476. /* TOMATILLO lacks streaming cache. */
  1477. return;
  1478. }
  1479. /* SCHIZO has context flushing. */
  1480. pbm->stc.strbuf_control = base + SCHIZO_STRBUF_CONTROL;
  1481. pbm->stc.strbuf_pflush = base + SCHIZO_STRBUF_FLUSH;
  1482. pbm->stc.strbuf_fsync = base + SCHIZO_STRBUF_FSYNC;
  1483. pbm->stc.strbuf_ctxflush = base + SCHIZO_STRBUF_CTXFLUSH;
  1484. pbm->stc.strbuf_ctxmatch_base = base + SCHIZO_STRBUF_CTXMATCH;
  1485. pbm->stc.strbuf_flushflag = (volatile unsigned long *)
  1486. ((((unsigned long)&pbm->stc.__flushflag_buf[0])
  1487. + 63UL)
  1488. & ~63UL);
  1489. pbm->stc.strbuf_flushflag_pa = (unsigned long)
  1490. __pa(pbm->stc.strbuf_flushflag);
  1491. /* Turn off LRU locking and diag mode, enable the
  1492. * streaming buffer and leave the rerun-disable
  1493. * setting however OBP set it.
  1494. */
  1495. control = schizo_read(pbm->stc.strbuf_control);
  1496. control &= ~(SCHIZO_STRBUF_CTRL_LPTR |
  1497. SCHIZO_STRBUF_CTRL_LENAB |
  1498. SCHIZO_STRBUF_CTRL_DENAB);
  1499. control |= SCHIZO_STRBUF_CTRL_ENAB;
  1500. schizo_write(pbm->stc.strbuf_control, control);
  1501. pbm->stc.strbuf_enabled = 1;
  1502. }
  1503. #define SCHIZO_IOMMU_CONTROL (0x00200UL)
  1504. #define SCHIZO_IOMMU_TSBBASE (0x00208UL)
  1505. #define SCHIZO_IOMMU_FLUSH (0x00210UL)
  1506. #define SCHIZO_IOMMU_CTXFLUSH (0x00218UL)
  1507. static void schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
  1508. {
  1509. struct pci_iommu *iommu = pbm->iommu;
  1510. unsigned long tsbbase, i, tagbase, database, order;
  1511. u32 vdma[2], dma_mask;
  1512. u64 control;
  1513. int err, tsbsize;
  1514. err = prom_getproperty(pbm->prom_node, "virtual-dma",
  1515. (char *)&vdma[0], sizeof(vdma));
  1516. if (err == 0 || err == -1) {
  1517. /* No property, use default values. */
  1518. vdma[0] = 0xc0000000;
  1519. vdma[1] = 0x40000000;
  1520. }
  1521. dma_mask = vdma[0];
  1522. switch (vdma[1]) {
  1523. case 0x20000000:
  1524. dma_mask |= 0x1fffffff;
  1525. tsbsize = 64;
  1526. break;
  1527. case 0x40000000:
  1528. dma_mask |= 0x3fffffff;
  1529. tsbsize = 128;
  1530. break;
  1531. case 0x80000000:
  1532. dma_mask |= 0x7fffffff;
  1533. tsbsize = 128;
  1534. break;
  1535. default:
  1536. prom_printf("SCHIZO: strange virtual-dma size.\n");
  1537. prom_halt();
  1538. };
  1539. /* Setup initial software IOMMU state. */
  1540. spin_lock_init(&iommu->lock);
  1541. iommu->iommu_cur_ctx = 0;
  1542. /* Register addresses, SCHIZO has iommu ctx flushing. */
  1543. iommu->iommu_control = pbm->pbm_regs + SCHIZO_IOMMU_CONTROL;
  1544. iommu->iommu_tsbbase = pbm->pbm_regs + SCHIZO_IOMMU_TSBBASE;
  1545. iommu->iommu_flush = pbm->pbm_regs + SCHIZO_IOMMU_FLUSH;
  1546. iommu->iommu_ctxflush = pbm->pbm_regs + SCHIZO_IOMMU_CTXFLUSH;
  1547. /* We use the main control/status register of SCHIZO as the write
  1548. * completion register.
  1549. */
  1550. iommu->write_complete_reg = pbm->controller_regs + 0x10000UL;
  1551. /*
  1552. * Invalidate TLB Entries.
  1553. */
  1554. control = schizo_read(iommu->iommu_control);
  1555. control |= SCHIZO_IOMMU_CTRL_DENAB;
  1556. schizo_write(iommu->iommu_control, control);
  1557. tagbase = SCHIZO_IOMMU_TAG, database = SCHIZO_IOMMU_DATA;
  1558. for(i = 0; i < 16; i++) {
  1559. schizo_write(pbm->pbm_regs + tagbase + (i * 8UL), 0);
  1560. schizo_write(pbm->pbm_regs + database + (i * 8UL), 0);
  1561. }
  1562. /* Leave diag mode enabled for full-flushing done
  1563. * in pci_iommu.c
  1564. */
  1565. iommu->dummy_page = __get_free_pages(GFP_KERNEL, 0);
  1566. if (!iommu->dummy_page) {
  1567. prom_printf("PSYCHO_IOMMU: Error, gfp(dummy_page) failed.\n");
  1568. prom_halt();
  1569. }
  1570. memset((void *)iommu->dummy_page, 0, PAGE_SIZE);
  1571. iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page);
  1572. /* Using assumed page size 8K with 128K entries we need 1MB iommu page
  1573. * table (128K ioptes * 8 bytes per iopte). This is
  1574. * page order 7 on UltraSparc.
  1575. */
  1576. order = get_order(tsbsize * 8 * 1024);
  1577. tsbbase = __get_free_pages(GFP_KERNEL, order);
  1578. if (!tsbbase) {
  1579. prom_printf("%s: Error, gfp(tsb) failed.\n", pbm->name);
  1580. prom_halt();
  1581. }
  1582. iommu->page_table = (iopte_t *)tsbbase;
  1583. iommu->page_table_map_base = vdma[0];
  1584. iommu->dma_addr_mask = dma_mask;
  1585. pci_iommu_table_init(iommu, PAGE_SIZE << order);
  1586. switch (tsbsize) {
  1587. case 64:
  1588. iommu->page_table_sz_bits = 16;
  1589. break;
  1590. case 128:
  1591. iommu->page_table_sz_bits = 17;
  1592. break;
  1593. default:
  1594. prom_printf("iommu_init: Illegal TSB size %d\n", tsbsize);
  1595. prom_halt();
  1596. break;
  1597. };
  1598. /* We start with no consistent mappings. */
  1599. iommu->lowest_consistent_map =
  1600. 1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS);
  1601. for (i = 0; i < PBM_NCLUSTERS; i++) {
  1602. iommu->alloc_info[i].flush = 0;
  1603. iommu->alloc_info[i].next = 0;
  1604. }
  1605. schizo_write(iommu->iommu_tsbbase, __pa(tsbbase));
  1606. control = schizo_read(iommu->iommu_control);
  1607. control &= ~(SCHIZO_IOMMU_CTRL_TSBSZ | SCHIZO_IOMMU_CTRL_TBWSZ);
  1608. switch (tsbsize) {
  1609. case 64:
  1610. control |= SCHIZO_IOMMU_TSBSZ_64K;
  1611. break;
  1612. case 128:
  1613. control |= SCHIZO_IOMMU_TSBSZ_128K;
  1614. break;
  1615. };
  1616. control |= SCHIZO_IOMMU_CTRL_ENAB;
  1617. schizo_write(iommu->iommu_control, control);
  1618. }
  1619. #define SCHIZO_PCI_IRQ_RETRY (0x1a00UL)
  1620. #define SCHIZO_IRQ_RETRY_INF 0xffUL
  1621. #define SCHIZO_PCI_DIAG (0x2020UL)
  1622. #define SCHIZO_PCIDIAG_D_BADECC (1UL << 10UL) /* Disable BAD ECC errors (Schizo) */
  1623. #define SCHIZO_PCIDIAG_D_BYPASS (1UL << 9UL) /* Disable MMU bypass mode (Schizo/Tomatillo) */
  1624. #define SCHIZO_PCIDIAG_D_TTO (1UL << 8UL) /* Disable TTO errors (Schizo/Tomatillo) */
  1625. #define SCHIZO_PCIDIAG_D_RTRYARB (1UL << 7UL) /* Disable retry arbitration (Schizo) */
  1626. #define SCHIZO_PCIDIAG_D_RETRY (1UL << 6UL) /* Disable retry limit (Schizo/Tomatillo) */
  1627. #define SCHIZO_PCIDIAG_D_INTSYNC (1UL << 5UL) /* Disable interrupt/DMA synch (Schizo/Tomatillo) */
  1628. #define SCHIZO_PCIDIAG_I_DMA_PARITY (1UL << 3UL) /* Invert DMA parity (Schizo/Tomatillo) */
  1629. #define SCHIZO_PCIDIAG_I_PIOD_PARITY (1UL << 2UL) /* Invert PIO data parity (Schizo/Tomatillo) */
  1630. #define SCHIZO_PCIDIAG_I_PIOA_PARITY (1UL << 1UL) /* Invert PIO address parity (Schizo/Tomatillo) */
  1631. #define TOMATILLO_PCI_IOC_CSR (0x2248UL)
  1632. #define TOMATILLO_IOC_PART_WPENAB 0x0000000000080000UL
  1633. #define TOMATILLO_IOC_RDMULT_PENAB 0x0000000000040000UL
  1634. #define TOMATILLO_IOC_RDONE_PENAB 0x0000000000020000UL
  1635. #define TOMATILLO_IOC_RDLINE_PENAB 0x0000000000010000UL
  1636. #define TOMATILLO_IOC_RDMULT_PLEN 0x000000000000c000UL
  1637. #define TOMATILLO_IOC_RDMULT_PLEN_SHIFT 14UL
  1638. #define TOMATILLO_IOC_RDONE_PLEN 0x0000000000003000UL
  1639. #define TOMATILLO_IOC_RDONE_PLEN_SHIFT 12UL
  1640. #define TOMATILLO_IOC_RDLINE_PLEN 0x0000000000000c00UL
  1641. #define TOMATILLO_IOC_RDLINE_PLEN_SHIFT 10UL
  1642. #define TOMATILLO_IOC_PREF_OFF 0x00000000000003f8UL
  1643. #define TOMATILLO_IOC_PREF_OFF_SHIFT 3UL
  1644. #define TOMATILLO_IOC_RDMULT_CPENAB 0x0000000000000004UL
  1645. #define TOMATILLO_IOC_RDONE_CPENAB 0x0000000000000002UL
  1646. #define TOMATILLO_IOC_RDLINE_CPENAB 0x0000000000000001UL
  1647. #define TOMATILLO_PCI_IOC_TDIAG (0x2250UL)
  1648. #define TOMATILLO_PCI_IOC_DDIAG (0x2290UL)
  1649. static void __init schizo_pbm_hw_init(struct pci_pbm_info *pbm)
  1650. {
  1651. u64 tmp;
  1652. /* Set IRQ retry to infinity. */
  1653. schizo_write(pbm->pbm_regs + SCHIZO_PCI_IRQ_RETRY,
  1654. SCHIZO_IRQ_RETRY_INF);
  1655. /* Enable arbiter for all PCI slots. Also, disable PCI interval
  1656. * timer so that DTO (Discard TimeOuts) are not reported because
  1657. * some Schizo revisions report them erroneously.
  1658. */
  1659. tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_CTRL);
  1660. if (pbm->chip_type == PBM_CHIP_TYPE_SCHIZO_PLUS &&
  1661. pbm->chip_version == 0x5 &&
  1662. pbm->chip_revision == 0x1)
  1663. tmp |= 0x0f;
  1664. else
  1665. tmp |= 0xff;
  1666. tmp &= ~SCHIZO_PCICTRL_PTO;
  1667. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO &&
  1668. pbm->chip_version >= 0x2)
  1669. tmp |= 0x3UL << SCHIZO_PCICTRL_PTO_SHIFT;
  1670. else
  1671. tmp |= 0x1UL << SCHIZO_PCICTRL_PTO_SHIFT;
  1672. if (!prom_getbool(pbm->prom_node, "no-bus-parking"))
  1673. tmp |= SCHIZO_PCICTRL_PARK;
  1674. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO &&
  1675. pbm->chip_version <= 0x1)
  1676. tmp |= (1UL << 61);
  1677. else
  1678. tmp &= ~(1UL << 61);
  1679. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO)
  1680. tmp |= (SCHIZO_PCICTRL_MRM_PREF |
  1681. SCHIZO_PCICTRL_RDO_PREF |
  1682. SCHIZO_PCICTRL_RDL_PREF);
  1683. schizo_write(pbm->pbm_regs + SCHIZO_PCI_CTRL, tmp);
  1684. tmp = schizo_read(pbm->pbm_regs + SCHIZO_PCI_DIAG);
  1685. tmp &= ~(SCHIZO_PCIDIAG_D_RTRYARB |
  1686. SCHIZO_PCIDIAG_D_RETRY |
  1687. SCHIZO_PCIDIAG_D_INTSYNC);
  1688. schizo_write(pbm->pbm_regs + SCHIZO_PCI_DIAG, tmp);
  1689. if (pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
  1690. /* Clear prefetch lengths to workaround a bug in
  1691. * Jalapeno...
  1692. */
  1693. tmp = (TOMATILLO_IOC_PART_WPENAB |
  1694. (1 << TOMATILLO_IOC_PREF_OFF_SHIFT) |
  1695. TOMATILLO_IOC_RDMULT_CPENAB |
  1696. TOMATILLO_IOC_RDONE_CPENAB |
  1697. TOMATILLO_IOC_RDLINE_CPENAB);
  1698. schizo_write(pbm->pbm_regs + TOMATILLO_PCI_IOC_CSR,
  1699. tmp);
  1700. }
  1701. }
  1702. static void __init schizo_pbm_init(struct pci_controller_info *p,
  1703. int prom_node, u32 portid,
  1704. int chip_type)
  1705. {
  1706. struct linux_prom64_registers pr_regs[4];
  1707. unsigned int busrange[2];
  1708. struct pci_pbm_info *pbm;
  1709. const char *chipset_name;
  1710. u32 ino_bitmap[2];
  1711. int is_pbm_a;
  1712. int err;
  1713. switch (chip_type) {
  1714. case PBM_CHIP_TYPE_TOMATILLO:
  1715. chipset_name = "TOMATILLO";
  1716. break;
  1717. case PBM_CHIP_TYPE_SCHIZO_PLUS:
  1718. chipset_name = "SCHIZO+";
  1719. break;
  1720. case PBM_CHIP_TYPE_SCHIZO:
  1721. default:
  1722. chipset_name = "SCHIZO";
  1723. break;
  1724. };
  1725. /* For SCHIZO, three OBP regs:
  1726. * 1) PBM controller regs
  1727. * 2) Schizo front-end controller regs (same for both PBMs)
  1728. * 3) PBM PCI config space
  1729. *
  1730. * For TOMATILLO, four OBP regs:
  1731. * 1) PBM controller regs
  1732. * 2) Tomatillo front-end controller regs
  1733. * 3) PBM PCI config space
  1734. * 4) Ichip regs
  1735. */
  1736. err = prom_getproperty(prom_node, "reg",
  1737. (char *)&pr_regs[0],
  1738. sizeof(pr_regs));
  1739. if (err == 0 || err == -1) {
  1740. prom_printf("%s: Fatal error, no reg property.\n",
  1741. chipset_name);
  1742. prom_halt();
  1743. }
  1744. is_pbm_a = ((pr_regs[0].phys_addr & 0x00700000) == 0x00600000);
  1745. if (is_pbm_a)
  1746. pbm = &p->pbm_A;
  1747. else
  1748. pbm = &p->pbm_B;
  1749. pbm->portid = portid;
  1750. pbm->parent = p;
  1751. pbm->prom_node = prom_node;
  1752. pbm->pci_first_slot = 1;
  1753. pbm->chip_type = chip_type;
  1754. pbm->chip_version =
  1755. prom_getintdefault(prom_node, "version#", 0);
  1756. pbm->chip_revision =
  1757. prom_getintdefault(prom_node, "module-revision#", 0);
  1758. pbm->pbm_regs = pr_regs[0].phys_addr;
  1759. pbm->controller_regs = pr_regs[1].phys_addr - 0x10000UL;
  1760. sprintf(pbm->name,
  1761. (chip_type == PBM_CHIP_TYPE_TOMATILLO ?
  1762. "TOMATILLO%d PBM%c" :
  1763. "SCHIZO%d PBM%c"),
  1764. p->index,
  1765. (pbm == &p->pbm_A ? 'A' : 'B'));
  1766. printk("%s: ver[%x:%x], portid %x, "
  1767. "cregs[%lx] pregs[%lx]\n",
  1768. pbm->name,
  1769. pbm->chip_version, pbm->chip_revision,
  1770. pbm->portid,
  1771. pbm->controller_regs,
  1772. pbm->pbm_regs);
  1773. schizo_pbm_hw_init(pbm);
  1774. prom_getstring(prom_node, "name",
  1775. pbm->prom_name,
  1776. sizeof(pbm->prom_name));
  1777. err = prom_getproperty(prom_node, "ranges",
  1778. (char *) pbm->pbm_ranges,
  1779. sizeof(pbm->pbm_ranges));
  1780. if (err == 0 || err == -1) {
  1781. prom_printf("%s: Fatal error, no ranges property.\n",
  1782. pbm->name);
  1783. prom_halt();
  1784. }
  1785. pbm->num_pbm_ranges =
  1786. (err / sizeof(struct linux_prom_pci_ranges));
  1787. schizo_determine_mem_io_space(pbm);
  1788. pbm_register_toplevel_resources(p, pbm);
  1789. err = prom_getproperty(prom_node, "interrupt-map",
  1790. (char *)pbm->pbm_intmap,
  1791. sizeof(pbm->pbm_intmap));
  1792. if (err != -1) {
  1793. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  1794. err = prom_getproperty(prom_node, "interrupt-map-mask",
  1795. (char *)&pbm->pbm_intmask,
  1796. sizeof(pbm->pbm_intmask));
  1797. if (err == -1) {
  1798. prom_printf("%s: Fatal error, no "
  1799. "interrupt-map-mask.\n", pbm->name);
  1800. prom_halt();
  1801. }
  1802. } else {
  1803. pbm->num_pbm_intmap = 0;
  1804. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  1805. }
  1806. err = prom_getproperty(prom_node, "ino-bitmap",
  1807. (char *) &ino_bitmap[0],
  1808. sizeof(ino_bitmap));
  1809. if (err == 0 || err == -1) {
  1810. prom_printf("%s: Fatal error, no ino-bitmap.\n", pbm->name);
  1811. prom_halt();
  1812. }
  1813. pbm->ino_bitmap = (((u64)ino_bitmap[1] << 32UL) |
  1814. ((u64)ino_bitmap[0] << 0UL));
  1815. err = prom_getproperty(prom_node, "bus-range",
  1816. (char *)&busrange[0],
  1817. sizeof(busrange));
  1818. if (err == 0 || err == -1) {
  1819. prom_printf("%s: Fatal error, no bus-range.\n", pbm->name);
  1820. prom_halt();
  1821. }
  1822. pbm->pci_first_busno = busrange[0];
  1823. pbm->pci_last_busno = busrange[1];
  1824. schizo_pbm_iommu_init(pbm);
  1825. schizo_pbm_strbuf_init(pbm);
  1826. }
  1827. static inline int portid_compare(u32 x, u32 y, int chip_type)
  1828. {
  1829. if (chip_type == PBM_CHIP_TYPE_TOMATILLO) {
  1830. if (x == (y ^ 1))
  1831. return 1;
  1832. return 0;
  1833. }
  1834. return (x == y);
  1835. }
  1836. static void __init __schizo_init(int node, char *model_name, int chip_type)
  1837. {
  1838. struct pci_controller_info *p;
  1839. struct pci_iommu *iommu;
  1840. int is_pbm_a;
  1841. u32 portid;
  1842. portid = prom_getintdefault(node, "portid", 0xff);
  1843. for(p = pci_controller_root; p; p = p->next) {
  1844. struct pci_pbm_info *pbm;
  1845. if (p->pbm_A.prom_node && p->pbm_B.prom_node)
  1846. continue;
  1847. pbm = (p->pbm_A.prom_node ?
  1848. &p->pbm_A :
  1849. &p->pbm_B);
  1850. if (portid_compare(pbm->portid, portid, chip_type)) {
  1851. is_pbm_a = (p->pbm_A.prom_node == 0);
  1852. schizo_pbm_init(p, node, portid, chip_type);
  1853. return;
  1854. }
  1855. }
  1856. p = kmalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  1857. if (!p) {
  1858. prom_printf("SCHIZO: Fatal memory allocation error.\n");
  1859. prom_halt();
  1860. }
  1861. memset(p, 0, sizeof(*p));
  1862. iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  1863. if (!iommu) {
  1864. prom_printf("SCHIZO: Fatal memory allocation error.\n");
  1865. prom_halt();
  1866. }
  1867. memset(iommu, 0, sizeof(*iommu));
  1868. p->pbm_A.iommu = iommu;
  1869. iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  1870. if (!iommu) {
  1871. prom_printf("SCHIZO: Fatal memory allocation error.\n");
  1872. prom_halt();
  1873. }
  1874. memset(iommu, 0, sizeof(*iommu));
  1875. p->pbm_B.iommu = iommu;
  1876. p->next = pci_controller_root;
  1877. pci_controller_root = p;
  1878. p->index = pci_num_controllers++;
  1879. p->pbms_same_domain = 0;
  1880. p->scan_bus = (chip_type == PBM_CHIP_TYPE_TOMATILLO ?
  1881. tomatillo_scan_bus :
  1882. schizo_scan_bus);
  1883. p->irq_build = schizo_irq_build;
  1884. p->base_address_update = schizo_base_address_update;
  1885. p->resource_adjust = schizo_resource_adjust;
  1886. p->pci_ops = &schizo_ops;
  1887. /* Like PSYCHO we have a 2GB aligned area for memory space. */
  1888. pci_memspace_mask = 0x7fffffffUL;
  1889. schizo_pbm_init(p, node, portid, chip_type);
  1890. }
  1891. void __init schizo_init(int node, char *model_name)
  1892. {
  1893. __schizo_init(node, model_name, PBM_CHIP_TYPE_SCHIZO);
  1894. }
  1895. void __init schizo_plus_init(int node, char *model_name)
  1896. {
  1897. __schizo_init(node, model_name, PBM_CHIP_TYPE_SCHIZO_PLUS);
  1898. }
  1899. void __init tomatillo_init(int node, char *model_name)
  1900. {
  1901. __schizo_init(node, model_name, PBM_CHIP_TYPE_TOMATILLO);
  1902. }