pci_schizo.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:59k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $Id: pci_schizo.c,v 1.23.2.2 2002/03/11 07:55:24 davem Exp $
  2.  * pci_schizo.c: SCHIZO specific PCI controller support.
  3.  *
  4.  * Copyright (C) 2001 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 <asm/pbm.h>
  12. #include <asm/iommu.h>
  13. #include <asm/irq.h>
  14. #include <asm/upa.h>
  15. #include "pci_impl.h"
  16. #include "iommu_common.h"
  17. /* All SCHIZO registers are 64-bits.  The following accessor
  18.  * routines are how they are accessed.  The REG parameter
  19.  * is a physical address.
  20.  */
  21. #define schizo_read(__reg) 
  22. ({ u64 __ret; 
  23. __asm__ __volatile__("ldxa [%1] %2, %0" 
  24.      : "=r" (__ret) 
  25.      : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) 
  26.      : "memory"); 
  27. __ret; 
  28. })
  29. #define schizo_write(__reg, __val) 
  30. __asm__ __volatile__("stxa %0, [%1] %2" 
  31.      : /* no outputs */ 
  32.      : "r" (__val), "r" (__reg), 
  33.        "i" (ASI_PHYS_BYPASS_EC_E) 
  34.      : "memory")
  35. /* This is a convention that at least Excalibur and Merlin
  36.  * follow.  I suppose the SCHIZO used in Starcat and friends
  37.  * will do similar.
  38.  *
  39.  * The only way I could see this changing is if the newlink
  40.  * block requires more space in Schizo's address space than
  41.  * they predicted, thus requiring an address space reorg when
  42.  * the newer Schizo is taped out.
  43.  *
  44.  * These offsets look weird because I keep in p->controller_regs
  45.  * the second PROM register property minus 0x10000 which is the
  46.  * base of the Safari and UPA64S registers of SCHIZO.
  47.  */
  48. #define SCHIZO_PBM_A_REGS_OFF (0x600000UL - 0x400000UL)
  49. #define SCHIZO_PBM_B_REGS_OFF (0x700000UL - 0x400000UL)
  50. /* Streaming buffer control register. */
  51. #define SCHIZO_STRBUF_CTRL_LPTR    0x00000000000000f0UL /* LRU Lock Pointer */
  52. #define SCHIZO_STRBUF_CTRL_LENAB   0x0000000000000008UL /* LRU Lock Enable */
  53. #define SCHIZO_STRBUF_CTRL_RRDIS   0x0000000000000004UL /* Rerun Disable */
  54. #define SCHIZO_STRBUF_CTRL_DENAB   0x0000000000000002UL /* Diagnostic Mode Enable */
  55. #define SCHIZO_STRBUF_CTRL_ENAB    0x0000000000000001UL /* Streaming Buffer Enable */
  56. /* IOMMU control register. */
  57. #define SCHIZO_IOMMU_CTRL_RESV     0xfffffffff9000000 /* Reserved                      */
  58. #define SCHIZO_IOMMU_CTRL_XLTESTAT 0x0000000006000000 /* Translation Error Status      */
  59. #define SCHIZO_IOMMU_CTRL_XLTEERR  0x0000000001000000 /* Translation Error encountered */
  60. #define SCHIZO_IOMMU_CTRL_LCKEN    0x0000000000800000 /* Enable translation locking    */
  61. #define SCHIZO_IOMMU_CTRL_LCKPTR   0x0000000000780000 /* Translation lock pointer      */
  62. #define SCHIZO_IOMMU_CTRL_TSBSZ    0x0000000000070000 /* TSB Size                      */
  63. #define SCHIZO_IOMMU_TSBSZ_1K      0x0000000000000000 /* TSB Table 1024 8-byte entries */
  64. #define SCHIZO_IOMMU_TSBSZ_2K      0x0000000000010000 /* TSB Table 2048 8-byte entries */
  65. #define SCHIZO_IOMMU_TSBSZ_4K      0x0000000000020000 /* TSB Table 4096 8-byte entries */
  66. #define SCHIZO_IOMMU_TSBSZ_8K      0x0000000000030000 /* TSB Table 8192 8-byte entries */
  67. #define SCHIZO_IOMMU_TSBSZ_16K     0x0000000000040000 /* TSB Table 16k 8-byte entries  */
  68. #define SCHIZO_IOMMU_TSBSZ_32K     0x0000000000050000 /* TSB Table 32k 8-byte entries  */
  69. #define SCHIZO_IOMMU_TSBSZ_64K     0x0000000000060000 /* TSB Table 64k 8-byte entries  */
  70. #define SCHIZO_IOMMU_TSBSZ_128K    0x0000000000070000 /* TSB Table 128k 8-byte entries */
  71. #define SCHIZO_IOMMU_CTRL_RESV2    0x000000000000fff8 /* Reserved                      */
  72. #define SCHIZO_IOMMU_CTRL_TBWSZ    0x0000000000000004 /* Assumed page size, 0=8k 1=64k */
  73. #define SCHIZO_IOMMU_CTRL_DENAB    0x0000000000000002 /* Diagnostic mode enable        */
  74. #define SCHIZO_IOMMU_CTRL_ENAB     0x0000000000000001 /* IOMMU Enable                  */
  75. /* Schizo config space address format is nearly identical to
  76.  * that of PSYCHO:
  77.  *
  78.  *  32             24 23 16 15    11 10       8 7   2  1 0
  79.  * ---------------------------------------------------------
  80.  * |0 0 0 0 0 0 0 0 0| bus | device | function | reg | 0 0 |
  81.  * ---------------------------------------------------------
  82.  */
  83. #define SCHIZO_CONFIG_BASE(PBM) ((PBM)->config_space)
  84. #define SCHIZO_CONFIG_ENCODE(BUS, DEVFN, REG)
  85. (((unsigned long)(BUS)   << 16) |
  86.  ((unsigned long)(DEVFN) << 8)  |
  87.  ((unsigned long)(REG)))
  88. static void *schizo_pci_config_mkaddr(struct pci_pbm_info *pbm,
  89.       unsigned char bus,
  90.       unsigned int devfn,
  91.       int where)
  92. {
  93. if (!pbm)
  94. return NULL;
  95. return (void *)
  96. (SCHIZO_CONFIG_BASE(pbm) |
  97.  SCHIZO_CONFIG_ENCODE(bus, devfn, where));
  98. }
  99. /* 4 slots on pbm A, and 6 slots on pbm B.  In both cases
  100.  * slot 0 is the SCHIZO host bridge itself.
  101.  */
  102. static int schizo_out_of_range(struct pci_pbm_info *pbm,
  103.        unsigned char bus,
  104.        unsigned char devfn)
  105. {
  106. return ((pbm->parent == 0) ||
  107. ((pbm == &pbm->parent->pbm_B) &&
  108.  (bus == pbm->pci_first_busno) &&
  109.  PCI_SLOT(devfn) > 6) ||
  110. ((pbm == &pbm->parent->pbm_A) &&
  111.  (bus == pbm->pci_first_busno) &&
  112.  PCI_SLOT(devfn) > 4));
  113. }
  114. /* SCHIZO PCI configuration space accessors. */
  115. static int schizo_read_byte(struct pci_dev *dev, int where, u8 *value)
  116. {
  117. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  118. unsigned char bus = dev->bus->number;
  119. unsigned int devfn = dev->devfn;
  120. u8 *addr;
  121. *value = 0xff;
  122. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  123. if (!addr)
  124. return PCIBIOS_SUCCESSFUL;
  125. if (schizo_out_of_range(pbm, bus, devfn))
  126. return PCIBIOS_SUCCESSFUL;
  127. pci_config_read8(addr, value);
  128. return PCIBIOS_SUCCESSFUL;
  129. }
  130. static int schizo_read_word(struct pci_dev *dev, int where, u16 *value)
  131. {
  132. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  133. unsigned char bus = dev->bus->number;
  134. unsigned int devfn = dev->devfn;
  135. u16 *addr;
  136. *value = 0xffff;
  137. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  138. if (!addr)
  139. return PCIBIOS_SUCCESSFUL;
  140. if (schizo_out_of_range(pbm, bus, devfn))
  141. return PCIBIOS_SUCCESSFUL;
  142. if (where & 0x01) {
  143. printk("pcibios_read_config_word: misaligned reg [%x]n",
  144.        where);
  145. return PCIBIOS_SUCCESSFUL;
  146. }
  147. pci_config_read16(addr, value);
  148. return PCIBIOS_SUCCESSFUL;
  149. }
  150. static int schizo_read_dword(struct pci_dev *dev, int where, u32 *value)
  151. {
  152. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  153. unsigned char bus = dev->bus->number;
  154. unsigned int devfn = dev->devfn;
  155. u32 *addr;
  156. *value = 0xffffffff;
  157. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  158. if (!addr)
  159. return PCIBIOS_SUCCESSFUL;
  160. if (schizo_out_of_range(pbm, bus, devfn))
  161. return PCIBIOS_SUCCESSFUL;
  162. if (where & 0x03) {
  163. printk("pcibios_read_config_dword: misaligned reg [%x]n",
  164.        where);
  165. return PCIBIOS_SUCCESSFUL;
  166. }
  167. pci_config_read32(addr, value);
  168. return PCIBIOS_SUCCESSFUL;
  169. }
  170. static int schizo_write_byte(struct pci_dev *dev, int where, u8 value)
  171. {
  172. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  173. unsigned char bus = dev->bus->number;
  174. unsigned int devfn = dev->devfn;
  175. u8 *addr;
  176. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  177. if (!addr)
  178. return PCIBIOS_SUCCESSFUL;
  179. if (schizo_out_of_range(pbm, bus, devfn))
  180. return PCIBIOS_SUCCESSFUL;
  181. pci_config_write8(addr, value);
  182. return PCIBIOS_SUCCESSFUL;
  183. }
  184. static int schizo_write_word(struct pci_dev *dev, int where, u16 value)
  185. {
  186. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  187. unsigned char bus = dev->bus->number;
  188. unsigned int devfn = dev->devfn;
  189. u16 *addr;
  190. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  191. if (!addr)
  192. return PCIBIOS_SUCCESSFUL;
  193. if (schizo_out_of_range(pbm, bus, devfn))
  194. return PCIBIOS_SUCCESSFUL;
  195. if (where & 0x01) {
  196. printk("pcibios_write_config_word: misaligned reg [%x]n",
  197.        where);
  198. return PCIBIOS_SUCCESSFUL;
  199. }
  200. pci_config_write16(addr, value);
  201. return PCIBIOS_SUCCESSFUL;
  202. }
  203. static int schizo_write_dword(struct pci_dev *dev, int where, u32 value)
  204. {
  205. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  206. unsigned char bus = dev->bus->number;
  207. unsigned int devfn = dev->devfn;
  208. u32 *addr;
  209. addr = schizo_pci_config_mkaddr(pbm, bus, devfn, where);
  210. if (!addr)
  211. return PCIBIOS_SUCCESSFUL;
  212. if (schizo_out_of_range(pbm, bus, devfn))
  213. return PCIBIOS_SUCCESSFUL;
  214. if (where & 0x03) {
  215. printk("pcibios_write_config_dword: misaligned reg [%x]n",
  216.        where);
  217. return PCIBIOS_SUCCESSFUL;
  218. }
  219. pci_config_write32(addr, value);
  220. return PCIBIOS_SUCCESSFUL;
  221. }
  222. static struct pci_ops schizo_ops = {
  223. schizo_read_byte,
  224. schizo_read_word,
  225. schizo_read_dword,
  226. schizo_write_byte,
  227. schizo_write_word,
  228. schizo_write_dword
  229. };
  230. /* SCHIZO interrupt mapping support.  Unlike Psycho, for this controller the
  231.  * imap/iclr registers are per-PBM.
  232.  */
  233. #define SCHIZO_IMAP_BASE 0x1000UL
  234. #define SCHIZO_ICLR_BASE 0x1400UL
  235. static unsigned long schizo_imap_offset(unsigned long ino)
  236. {
  237. return SCHIZO_IMAP_BASE + (ino * 8UL);
  238. }
  239. static unsigned long schizo_iclr_offset(unsigned long ino)
  240. {
  241. return SCHIZO_ICLR_BASE + (ino * 8UL);
  242. }
  243. /* PCI SCHIZO INO number to Sparc PIL level.  This table only matters for
  244.  * INOs which will not have an associated PCI device struct, ie. onboard
  245.  * EBUS devices and PCI controller internal error interrupts.
  246.  */
  247. static unsigned char schizo_pil_table[] = {
  248. /*0x00*/0, 0, 0, 0, /* PCI slot 0  Int A, B, C, D */
  249. /*0x04*/0, 0, 0, 0, /* PCI slot 1  Int A, B, C, D */
  250. /*0x08*/0, 0, 0, 0, /* PCI slot 2  Int A, B, C, D */
  251. /*0x0c*/0, 0, 0, 0, /* PCI slot 3  Int A, B, C, D */
  252. /*0x10*/0, 0, 0, 0, /* PCI slot 4  Int A, B, C, D */
  253. /*0x14*/0, 0, 0, 0, /* PCI slot 5  Int A, B, C, D */
  254. /*0x18*/4, /* SCSI */
  255. /*0x19*/4, /* second SCSI */
  256. /*0x1a*/0, /* UNKNOWN */
  257. /*0x1b*/0, /* UNKNOWN */
  258. /*0x1c*/8, /* Parallel */
  259. /*0x1d*/5, /* Ethernet */
  260. /*0x1e*/8, /* Firewire-1394 */
  261. /*0x1f*/9, /* USB */
  262. /*0x20*/13, /* Audio Record */
  263. /*0x21*/14, /* Audio Playback */
  264. /*0x22*/12, /* Serial */
  265. /*0x23*/4, /* EBUS I2C  */
  266. /*0x24*/10, /* RTC Clock */
  267. /*0x25*/11, /* Floppy */
  268. /*0x26*/0, /* UNKNOWN */
  269. /*0x27*/0, /* UNKNOWN */
  270. /*0x28*/0, /* UNKNOWN */
  271. /*0x29*/0, /* UNKNOWN */
  272. /*0x2a*/10, /* UPA 1 */
  273. /*0x2b*/10, /* UPA 2 */
  274. /*0x2c*/0, /* UNKNOWN */
  275. /*0x2d*/0, /* UNKNOWN */
  276. /*0x2e*/0, /* UNKNOWN */
  277. /*0x2f*/0, /* UNKNOWN */
  278. /*0x30*/15, /* Uncorrectable ECC */
  279. /*0x31*/15, /* Correctable ECC */
  280. /*0x32*/15, /* PCI Bus A Error */
  281. /*0x33*/15, /* PCI Bus B Error */
  282. /*0x34*/15, /* Safari Bus Error */
  283. /*0x35*/0, /* Reserved */
  284. /*0x36*/0, /* Reserved */
  285. /*0x37*/0, /* Reserved */
  286. /*0x38*/0, /* Reserved for NewLink */
  287. /*0x39*/0, /* Reserved for NewLink */
  288. /*0x3a*/0, /* Reserved for NewLink */
  289. /*0x3b*/0, /* Reserved for NewLink */
  290. /*0x3c*/0, /* Reserved for NewLink */
  291. /*0x3d*/0, /* Reserved for NewLink */
  292. /*0x3e*/0, /* Reserved for NewLink */
  293. /*0x3f*/0, /* Reserved for NewLink */
  294. };
  295. static int __init schizo_ino_to_pil(struct pci_dev *pdev, unsigned int ino)
  296. {
  297. int ret;
  298. if (pdev &&
  299.     pdev->vendor == PCI_VENDOR_ID_SUN &&
  300.     pdev->device == PCI_DEVICE_ID_SUN_RIO_USB)
  301. return 9;
  302. ret = schizo_pil_table[ino];
  303. if (ret == 0 && pdev == NULL) {
  304. ret = 4;
  305. } else if (ret == 0) {
  306. switch ((pdev->class >> 16) & 0xff) {
  307. case PCI_BASE_CLASS_STORAGE:
  308. ret = 4;
  309. break;
  310. case PCI_BASE_CLASS_NETWORK:
  311. ret = 6;
  312. break;
  313. case PCI_BASE_CLASS_DISPLAY:
  314. ret = 9;
  315. break;
  316. case PCI_BASE_CLASS_MULTIMEDIA:
  317. case PCI_BASE_CLASS_MEMORY:
  318. case PCI_BASE_CLASS_BRIDGE:
  319. case PCI_BASE_CLASS_SERIAL:
  320. ret = 10;
  321. break;
  322. default:
  323. ret = 4;
  324. break;
  325. };
  326. }
  327. return ret;
  328. }
  329. static unsigned int __init schizo_irq_build(struct pci_pbm_info *pbm,
  330.     struct pci_dev *pdev,
  331.     unsigned int ino)
  332. {
  333. struct pci_controller_info *p = pbm->parent;
  334. struct ino_bucket *bucket;
  335. unsigned long imap, iclr, pbm_off;
  336. unsigned long imap_off, iclr_off;
  337. int pil;
  338. if (pbm == &p->pbm_A)
  339. pbm_off = SCHIZO_PBM_A_REGS_OFF;
  340. else
  341. pbm_off = SCHIZO_PBM_B_REGS_OFF;
  342. ino &= PCI_IRQ_INO;
  343. imap_off = schizo_imap_offset(ino);
  344. /* Now build the IRQ bucket. */
  345. pil = schizo_ino_to_pil(pdev, ino);
  346. if (PIL_RESERVED(pil))
  347. BUG();
  348. imap = p->controller_regs + pbm_off + imap_off;
  349. imap += 4;
  350. iclr_off = schizo_iclr_offset(ino);
  351. iclr = p->controller_regs + pbm_off + iclr_off;
  352. iclr += 4;
  353. /* On Schizo, no inofixup occurs.  This is because each
  354.  * INO has it's own IMAP register.  On Psycho and Sabre
  355.  * there is only one IMAP register for each PCI slot even
  356.  * though four different INOs can be generated by each
  357.  * PCI slot.
  358.  */
  359. bucket = __bucket(build_irq(pil, 0, iclr, imap));
  360. bucket->flags |= IBF_PCI;
  361. return __irq(bucket);
  362. }
  363. /* SCHIZO error handling support. */
  364. enum schizo_error_type {
  365. UE_ERR, CE_ERR, PCI_ERR, SAFARI_ERR
  366. };
  367. static spinlock_t stc_buf_lock = SPIN_LOCK_UNLOCKED;
  368. static unsigned long stc_error_buf[128];
  369. static unsigned long stc_tag_buf[16];
  370. static unsigned long stc_line_buf[16];
  371. static void schizo_clear_other_err_intr(int irq)
  372. {
  373. struct ino_bucket *bucket = __bucket(irq);
  374. unsigned long iclr = bucket->iclr;
  375. iclr += (SCHIZO_PBM_B_REGS_OFF - SCHIZO_PBM_A_REGS_OFF);
  376. upa_writel(ICLR_IDLE, iclr);
  377. }
  378. #define SCHIZO_STC_ERR 0xb800UL /* --> 0xba00 */
  379. #define SCHIZO_STC_TAG 0xba00UL /* --> 0xba80 */
  380. #define SCHIZO_STC_LINE 0xbb00UL /* --> 0xbb80 */
  381. #define SCHIZO_STCERR_WRITE 0x2UL
  382. #define SCHIZO_STCERR_READ 0x1UL
  383. #define SCHIZO_STCTAG_PPN 0x3fffffff00000000UL
  384. #define SCHIZO_STCTAG_VPN 0x00000000ffffe000UL
  385. #define SCHIZO_STCTAG_VALID 0x8000000000000000UL
  386. #define SCHIZO_STCTAG_READ 0x4000000000000000UL
  387. #define SCHIZO_STCLINE_LINDX 0x0000000007800000UL
  388. #define SCHIZO_STCLINE_SPTR 0x000000000007e000UL
  389. #define SCHIZO_STCLINE_LADDR 0x0000000000001fc0UL
  390. #define SCHIZO_STCLINE_EPTR 0x000000000000003fUL
  391. #define SCHIZO_STCLINE_VALID 0x0000000000600000UL
  392. #define SCHIZO_STCLINE_FOFN 0x0000000000180000UL
  393. static void __schizo_check_stc_error_pbm(struct pci_pbm_info *pbm,
  394.  enum schizo_error_type type)
  395. {
  396. struct pci_controller_info *p = pbm->parent;
  397. struct pci_strbuf *strbuf = &pbm->stc;
  398. unsigned long regbase = p->controller_regs;
  399. unsigned long err_base, tag_base, line_base;
  400. u64 control;
  401. char pbm_name = (pbm == &p->pbm_A ? 'A' : 'B');
  402. int i;
  403. if (pbm == &p->pbm_A)
  404. regbase += SCHIZO_PBM_A_REGS_OFF;
  405. else
  406. regbase += SCHIZO_PBM_B_REGS_OFF;
  407. err_base = regbase + SCHIZO_STC_ERR;
  408. tag_base = regbase + SCHIZO_STC_TAG;
  409. line_base = regbase + SCHIZO_STC_LINE;
  410. spin_lock(&stc_buf_lock);
  411. /* This is __REALLY__ dangerous.  When we put the
  412.  * streaming buffer into diagnostic mode to probe
  413.  * it's tags and error status, we _must_ clear all
  414.  * of the line tag valid bits before re-enabling
  415.  * the streaming buffer.  If any dirty data lives
  416.  * in the STC when we do this, we will end up
  417.  * invalidating it before it has a chance to reach
  418.  * main memory.
  419.  */
  420. control = schizo_read(strbuf->strbuf_control);
  421. schizo_write(strbuf->strbuf_control,
  422.      (control | SCHIZO_STRBUF_CTRL_DENAB));
  423. for (i = 0; i < 128; i++) {
  424. unsigned long val;
  425. val = schizo_read(err_base + (i * 8UL));
  426. schizo_write(err_base + (i * 8UL), 0UL);
  427. stc_error_buf[i] = val;
  428. }
  429. for (i = 0; i < 16; i++) {
  430. stc_tag_buf[i] = schizo_read(tag_base + (i * 8UL));
  431. stc_line_buf[i] = schizo_read(line_base + (i * 8UL));
  432. schizo_write(tag_base + (i * 8UL), 0UL);
  433. schizo_write(line_base + (i * 8UL), 0UL);
  434. }
  435. /* OK, state is logged, exit diagnostic mode. */
  436. schizo_write(strbuf->strbuf_control, control);
  437. for (i = 0; i < 16; i++) {
  438. int j, saw_error, first, last;
  439. saw_error = 0;
  440. first = i * 8;
  441. last = first + 8;
  442. for (j = first; j < last; j++) {
  443. unsigned long errval = stc_error_buf[j];
  444. if (errval != 0) {
  445. saw_error++;
  446. printk("SCHIZO%d: PBM-%c STC_ERR(%d)[wr(%d)rd(%d)]n",
  447.        p->index, pbm_name,
  448.        j,
  449.        (errval & SCHIZO_STCERR_WRITE) ? 1 : 0,
  450.        (errval & SCHIZO_STCERR_READ) ? 1 : 0);
  451. }
  452. }
  453. if (saw_error != 0) {
  454. unsigned long tagval = stc_tag_buf[i];
  455. unsigned long lineval = stc_line_buf[i];
  456. printk("SCHIZO%d: PBM-%c STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)R(%d)]n",
  457.        p->index, pbm_name,
  458.        i,
  459.        ((tagval & SCHIZO_STCTAG_PPN) >> 19UL),
  460.        (tagval & SCHIZO_STCTAG_VPN),
  461.        ((tagval & SCHIZO_STCTAG_VALID) ? 1 : 0),
  462.        ((tagval & SCHIZO_STCTAG_READ) ? 1 : 0));
  463. /* XXX Should spit out per-bank error information... -DaveM */
  464. printk("SCHIZO%d: PBM-%c STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
  465.        "V(%d)FOFN(%d)]n",
  466.        p->index, pbm_name,
  467.        i,
  468.        ((lineval & SCHIZO_STCLINE_LINDX) >> 23UL),
  469.        ((lineval & SCHIZO_STCLINE_SPTR) >> 13UL),
  470.        ((lineval & SCHIZO_STCLINE_LADDR) >> 6UL),
  471.        ((lineval & SCHIZO_STCLINE_EPTR) >> 0UL),
  472.        ((lineval & SCHIZO_STCLINE_VALID) ? 1 : 0),
  473.        ((lineval & SCHIZO_STCLINE_FOFN) ? 1 : 0));
  474. }
  475. }
  476. spin_unlock(&stc_buf_lock);
  477. }
  478. /* IOMMU is per-PBM in Schizo, so interrogate both for anonymous
  479.  * controller level errors.
  480.  */
  481. #define SCHIZO_IOMMU_TAG 0xa580UL
  482. #define SCHIZO_IOMMU_DATA 0xa600UL
  483. #define SCHIZO_IOMMU_TAG_CTXT 0x0000001ffe000000UL
  484. #define SCHIZO_IOMMU_TAG_ERRSTS 0x0000000001800000UL
  485. #define SCHIZO_IOMMU_TAG_ERR 0x0000000000400000UL
  486. #define SCHIZO_IOMMU_TAG_WRITE 0x0000000000200000UL
  487. #define SCHIZO_IOMMU_TAG_STREAM 0x0000000000100000UL
  488. #define SCHIZO_IOMMU_TAG_SIZE 0x0000000000080000UL
  489. #define SCHIZO_IOMMU_TAG_VPAGE 0x000000000007ffffUL
  490. #define SCHIZO_IOMMU_DATA_VALID 0x0000000100000000UL
  491. #define SCHIZO_IOMMU_DATA_CACHE 0x0000000040000000UL
  492. #define SCHIZO_IOMMU_DATA_PPAGE 0x000000003fffffffUL
  493. static void schizo_check_iommu_error_pbm(struct pci_pbm_info *pbm,
  494.  enum schizo_error_type type)
  495. {
  496. struct pci_controller_info *p = pbm->parent;
  497. struct pci_iommu *iommu = pbm->iommu;
  498. unsigned long iommu_tag[16];
  499. unsigned long iommu_data[16];
  500. unsigned long flags;
  501. u64 control;
  502. char pbm_name = (pbm == &p->pbm_A ? 'A' : 'B');
  503. int i;
  504. spin_lock_irqsave(&iommu->lock, flags);
  505. control = schizo_read(iommu->iommu_control);
  506. if (control & SCHIZO_IOMMU_CTRL_XLTEERR) {
  507. unsigned long base;
  508. char *type_string;
  509. /* Clear the error encountered bit. */
  510. control &= ~SCHIZO_IOMMU_CTRL_XLTEERR;
  511. schizo_write(iommu->iommu_control, control);
  512. switch((control & SCHIZO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
  513. case 0:
  514. type_string = "Protection Error";
  515. break;
  516. case 1:
  517. type_string = "Invalid Error";
  518. break;
  519. case 2:
  520. type_string = "TimeOut Error";
  521. break;
  522. case 3:
  523. default:
  524. type_string = "ECC Error";
  525. break;
  526. };
  527. printk("SCHIZO%d: PBM-%c IOMMU Error, type[%s]n",
  528.        p->index, pbm_name, type_string);
  529. /* Put the IOMMU into diagnostic mode and probe
  530.  * it's TLB for entries with error status.
  531.  *
  532.  * It is very possible for another DVMA to occur
  533.  * while we do this probe, and corrupt the system
  534.  * further.  But we are so screwed at this point
  535.  * that we are likely to crash hard anyways, so
  536.  * get as much diagnostic information to the
  537.  * console as we can.
  538.  */
  539. schizo_write(iommu->iommu_control,
  540.      control | SCHIZO_IOMMU_CTRL_DENAB);
  541. base = p->controller_regs;
  542. if (pbm == &p->pbm_A)
  543. base += SCHIZO_PBM_A_REGS_OFF;
  544. else
  545. base += SCHIZO_PBM_B_REGS_OFF;
  546. for (i = 0; i < 16; i++) {
  547. iommu_tag[i] =
  548. schizo_read(base + SCHIZO_IOMMU_TAG + (i * 8UL));
  549. iommu_data[i] =
  550. schizo_read(base + SCHIZO_IOMMU_DATA + (i * 8UL));
  551. /* Now clear out the entry. */
  552. schizo_write(base + SCHIZO_IOMMU_TAG + (i * 8UL), 0);
  553. schizo_write(base + SCHIZO_IOMMU_DATA + (i * 8UL), 0);
  554. }
  555. /* Leave diagnostic mode. */
  556. schizo_write(iommu->iommu_control, control);
  557. for (i = 0; i < 16; i++) {
  558. unsigned long tag, data;
  559. tag = iommu_tag[i];
  560. if (!(tag & SCHIZO_IOMMU_TAG_ERR))
  561. continue;
  562. data = iommu_data[i];
  563. switch((tag & SCHIZO_IOMMU_TAG_ERRSTS) >> 23UL) {
  564. case 0:
  565. type_string = "Protection Error";
  566. break;
  567. case 1:
  568. type_string = "Invalid Error";
  569. break;
  570. case 2:
  571. type_string = "TimeOut Error";
  572. break;
  573. case 3:
  574. default:
  575. type_string = "ECC Error";
  576. break;
  577. };
  578. printk("SCHIZO%d: PBM-%c IOMMU TAG(%d)[error(%s) ctx(%x) wr(%d) str(%d) "
  579.        "sz(%dK) vpg(%08lx)]n",
  580.        p->index, pbm_name, i, type_string,
  581.        (int)((tag & SCHIZO_IOMMU_TAG_CTXT) >> 25UL),
  582.        ((tag & SCHIZO_IOMMU_TAG_WRITE) ? 1 : 0),
  583.        ((tag & SCHIZO_IOMMU_TAG_STREAM) ? 1 : 0),
  584.        ((tag & SCHIZO_IOMMU_TAG_SIZE) ? 64 : 8),
  585.        (tag & SCHIZO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
  586. printk("SCHIZO%d: PBM-%c IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]n",
  587.        p->index, pbm_name, i,
  588.        ((data & SCHIZO_IOMMU_DATA_VALID) ? 1 : 0),
  589.        ((data & SCHIZO_IOMMU_DATA_CACHE) ? 1 : 0),
  590.        (data & SCHIZO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
  591. }
  592. }
  593. __schizo_check_stc_error_pbm(pbm, type);
  594. spin_unlock_irqrestore(&iommu->lock, flags);
  595. }
  596. static void schizo_check_iommu_error(struct pci_controller_info *p,
  597.      enum schizo_error_type type)
  598. {
  599. schizo_check_iommu_error_pbm(&p->pbm_A, type);
  600. schizo_check_iommu_error_pbm(&p->pbm_B, type);
  601. }
  602. /* Uncorrectable ECC error status gathering. */
  603. #define SCHIZO_UE_AFSR 0x10030UL
  604. #define SCHIZO_UE_AFAR 0x10038UL
  605. #define SCHIZO_UEAFSR_PPIO 0x8000000000000000UL
  606. #define SCHIZO_UEAFSR_PDRD 0x4000000000000000UL
  607. #define SCHIZO_UEAFSR_PDWR 0x2000000000000000UL
  608. #define SCHIZO_UEAFSR_SPIO 0x1000000000000000UL
  609. #define SCHIZO_UEAFSR_SDMA 0x0800000000000000UL
  610. #define SCHIZO_UEAFSR_ERRPNDG 0x0300000000000000UL
  611. #define SCHIZO_UEAFSR_BMSK 0x000003ff00000000UL
  612. #define SCHIZO_UEAFSR_QOFF 0x00000000c0000000UL
  613. #define SCHIZO_UEAFSR_AID 0x000000001f000000UL
  614. #define SCHIZO_UEAFSR_PARTIAL 0x0000000000800000UL
  615. #define SCHIZO_UEAFSR_OWNEDIN 0x0000000000400000UL
  616. #define SCHIZO_UEAFSR_MTAGSYND 0x00000000000f0000UL
  617. #define SCHIZO_UEAFSR_MTAG 0x000000000000e000UL
  618. #define SCHIZO_UEAFSR_ECCSYND 0x00000000000001ffUL
  619. static void schizo_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
  620. {
  621. struct pci_controller_info *p = dev_id;
  622. unsigned long afsr_reg = p->controller_regs + SCHIZO_UE_AFSR;
  623. unsigned long afar_reg = p->controller_regs + SCHIZO_UE_AFAR;
  624. unsigned long afsr, afar, error_bits;
  625. int reported, limit;
  626. /* Latch uncorrectable error status. */
  627. afar = schizo_read(afar_reg);
  628. /* If either of the error pending bits are set in the
  629.  * AFSR, the error status is being actively updated by
  630.  * the hardware and we must re-read to get a clean value.
  631.  */
  632. limit = 1000;
  633. do {
  634. afsr = schizo_read(afsr_reg);
  635. } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
  636. /* Clear the primary/secondary error status bits. */
  637. error_bits = afsr &
  638. (SCHIZO_UEAFSR_PPIO | SCHIZO_UEAFSR_PDRD | SCHIZO_UEAFSR_PDWR |
  639.  SCHIZO_UEAFSR_SPIO | SCHIZO_UEAFSR_SDMA);
  640. if (!error_bits)
  641. return;
  642. schizo_write(afsr_reg, error_bits);
  643. /* Log the error. */
  644. printk("SCHIZO%d: Uncorrectable Error, primary error type[%s]n",
  645.        p->index,
  646.        (((error_bits & SCHIZO_UEAFSR_PPIO) ?
  647.  "PIO" :
  648.  ((error_bits & SCHIZO_UEAFSR_PDRD) ?
  649.   "DMA Read" :
  650.   ((error_bits & SCHIZO_UEAFSR_PDWR) ?
  651.    "DMA Write" : "???")))));
  652. printk("SCHIZO%d: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]n",
  653.        p->index,
  654.        (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
  655.        (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
  656.        (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
  657. printk("SCHIZO%d: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]n",
  658.        p->index,
  659.        (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
  660.        (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
  661.        (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
  662.        (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
  663.        (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
  664. printk("SCHIZO%d: UE AFAR [%016lx]n", p->index, afar);
  665. printk("SCHIZO%d: UE Secondary errors [", p->index);
  666. reported = 0;
  667. if (afsr & SCHIZO_UEAFSR_SPIO) {
  668. reported++;
  669. printk("(PIO)");
  670. }
  671. if (afsr & SCHIZO_UEAFSR_SDMA) {
  672. reported++;
  673. printk("(DMA)");
  674. }
  675. if (!reported)
  676. printk("(none)");
  677. printk("]n");
  678. /* Interrogate IOMMU for error status. */
  679. schizo_check_iommu_error(p, UE_ERR);
  680. schizo_clear_other_err_intr(irq);
  681. }
  682. #define SCHIZO_CE_AFSR 0x10040UL
  683. #define SCHIZO_CE_AFAR 0x10048UL
  684. #define SCHIZO_CEAFSR_PPIO 0x8000000000000000UL
  685. #define SCHIZO_CEAFSR_PDRD 0x4000000000000000UL
  686. #define SCHIZO_CEAFSR_PDWR 0x2000000000000000UL
  687. #define SCHIZO_CEAFSR_SPIO 0x1000000000000000UL
  688. #define SCHIZO_CEAFSR_SDMA 0x0800000000000000UL
  689. #define SCHIZO_CEAFSR_ERRPNDG 0x0300000000000000UL
  690. #define SCHIZO_CEAFSR_BMSK 0x000003ff00000000UL
  691. #define SCHIZO_CEAFSR_QOFF 0x00000000c0000000UL
  692. #define SCHIZO_CEAFSR_AID 0x000000001f000000UL
  693. #define SCHIZO_CEAFSR_PARTIAL 0x0000000000800000UL
  694. #define SCHIZO_CEAFSR_OWNEDIN 0x0000000000400000UL
  695. #define SCHIZO_CEAFSR_MTAGSYND 0x00000000000f0000UL
  696. #define SCHIZO_CEAFSR_MTAG 0x000000000000e000UL
  697. #define SCHIZO_CEAFSR_ECCSYND 0x00000000000001ffUL
  698. static void schizo_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
  699. {
  700. struct pci_controller_info *p = dev_id;
  701. unsigned long afsr_reg = p->controller_regs + SCHIZO_CE_AFSR;
  702. unsigned long afar_reg = p->controller_regs + SCHIZO_CE_AFAR;
  703. unsigned long afsr, afar, error_bits;
  704. int reported, limit;
  705. /* Latch error status. */
  706. afar = schizo_read(afar_reg);
  707. /* If either of the error pending bits are set in the
  708.  * AFSR, the error status is being actively updated by
  709.  * the hardware and we must re-read to get a clean value.
  710.  */
  711. limit = 1000;
  712. do {
  713. afsr = schizo_read(afsr_reg);
  714. } while ((afsr & SCHIZO_UEAFSR_ERRPNDG) != 0 && --limit);
  715. /* Clear primary/secondary error status bits. */
  716. error_bits = afsr &
  717. (SCHIZO_CEAFSR_PPIO | SCHIZO_CEAFSR_PDRD | SCHIZO_CEAFSR_PDWR |
  718.  SCHIZO_CEAFSR_SPIO | SCHIZO_CEAFSR_SDMA);
  719. if (!error_bits)
  720. return;
  721. schizo_write(afsr_reg, error_bits);
  722. /* Log the error. */
  723. printk("SCHIZO%d: Correctable Error, primary error type[%s]n",
  724.        p->index,
  725.        (((error_bits & SCHIZO_CEAFSR_PPIO) ?
  726.  "PIO" :
  727.  ((error_bits & SCHIZO_CEAFSR_PDRD) ?
  728.   "DMA Read" :
  729.   ((error_bits & SCHIZO_CEAFSR_PDWR) ?
  730.    "DMA Write" : "???")))));
  731. /* XXX Use syndrome and afar to print out module string just like
  732.  * XXX UDB CE trap handler does... -DaveM
  733.  */
  734. printk("SCHIZO%d: bytemask[%04lx] qword_offset[%lx] SAFARI_AID[%02lx]n",
  735.        p->index,
  736.        (afsr & SCHIZO_UEAFSR_BMSK) >> 32UL,
  737.        (afsr & SCHIZO_UEAFSR_QOFF) >> 30UL,
  738.        (afsr & SCHIZO_UEAFSR_AID) >> 24UL);
  739. printk("SCHIZO%d: partial[%d] owned_in[%d] mtag[%lx] mtag_synd[%lx] ecc_sync[%lx]n",
  740.        p->index,
  741.        (afsr & SCHIZO_UEAFSR_PARTIAL) ? 1 : 0,
  742.        (afsr & SCHIZO_UEAFSR_OWNEDIN) ? 1 : 0,
  743.        (afsr & SCHIZO_UEAFSR_MTAG) >> 13UL,
  744.        (afsr & SCHIZO_UEAFSR_MTAGSYND) >> 16UL,
  745.        (afsr & SCHIZO_UEAFSR_ECCSYND) >> 0UL);
  746. printk("SCHIZO%d: CE AFAR [%016lx]n", p->index, afar);
  747. printk("SCHIZO%d: CE Secondary errors [", p->index);
  748. reported = 0;
  749. if (afsr & SCHIZO_CEAFSR_SPIO) {
  750. reported++;
  751. printk("(PIO)");
  752. }
  753. if (afsr & SCHIZO_CEAFSR_SDMA) {
  754. reported++;
  755. printk("(DMA)");
  756. }
  757. if (!reported)
  758. printk("(none)");
  759. printk("]n");
  760. schizo_clear_other_err_intr(irq);
  761. }
  762. #define SCHIZO_PCI_AFSR 0x2010UL
  763. #define SCHIZO_PCI_AFAR 0x2018UL
  764. #define SCHIZO_PCIAFSR_PMA 0x8000000000000000UL
  765. #define SCHIZO_PCIAFSR_PTA 0x4000000000000000UL
  766. #define SCHIZO_PCIAFSR_PRTRY 0x2000000000000000UL
  767. #define SCHIZO_PCIAFSR_PPERR 0x1000000000000000UL
  768. #define SCHIZO_PCIAFSR_PTTO 0x0800000000000000UL
  769. #define SCHIZO_PCIAFSR_PUNUS 0x0400000000000000UL
  770. #define SCHIZO_PCIAFSR_SMA 0x0200000000000000UL
  771. #define SCHIZO_PCIAFSR_STA 0x0100000000000000UL
  772. #define SCHIZO_PCIAFSR_SRTRY 0x0080000000000000UL
  773. #define SCHIZO_PCIAFSR_SPERR 0x0040000000000000UL
  774. #define SCHIZO_PCIAFSR_STTO 0x0020000000000000UL
  775. #define SCHIZO_PCIAFSR_SUNUS 0x0010000000000000UL
  776. #define SCHIZO_PCIAFSR_BMSK 0x000003ff00000000UL
  777. #define SCHIZO_PCIAFSR_BLK 0x0000000080000000UL
  778. #define SCHIZO_PCIAFSR_CFG 0x0000000040000000UL
  779. #define SCHIZO_PCIAFSR_MEM 0x0000000020000000UL
  780. #define SCHIZO_PCIAFSR_IO 0x0000000010000000UL
  781. static void schizo_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
  782. {
  783. struct pci_pbm_info *pbm = dev_id;
  784. struct pci_controller_info *p = pbm->parent;
  785. unsigned long afsr_reg, afar_reg, base;
  786. unsigned long afsr, afar, error_bits;
  787. int reported;
  788. char pbm_name;
  789. base = p->controller_regs;
  790. if (pbm == &pbm->parent->pbm_A) {
  791. base += SCHIZO_PBM_A_REGS_OFF;
  792. pbm_name = 'A';
  793. } else {
  794. base += SCHIZO_PBM_B_REGS_OFF;
  795. pbm_name = 'B';
  796. }
  797. afsr_reg = base + SCHIZO_PCI_AFSR;
  798. afar_reg = base + SCHIZO_PCI_AFAR;
  799. /* Latch error status. */
  800. afar = schizo_read(afar_reg);
  801. afsr = schizo_read(afsr_reg);
  802. /* Clear primary/secondary error status bits. */
  803. error_bits = afsr &
  804. (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  805.  SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  806.  SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  807.  SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  808.  SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  809.  SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS);
  810. if (!error_bits)
  811. return;
  812. schizo_write(afsr_reg, error_bits);
  813. /* Log the error. */
  814. printk("SCHIZO%d: PBM-%c PCI Error, primary error type[%s]n",
  815.        p->index, pbm_name,
  816.        (((error_bits & SCHIZO_PCIAFSR_PMA) ?
  817.  "Master Abort" :
  818.  ((error_bits & SCHIZO_PCIAFSR_PTA) ?
  819.   "Target Abort" :
  820.   ((error_bits & SCHIZO_PCIAFSR_PRTRY) ?
  821.    "Excessive Retries" :
  822.    ((error_bits & SCHIZO_PCIAFSR_PPERR) ?
  823.     "Parity Error" :
  824.     ((error_bits & SCHIZO_PCIAFSR_PTTO) ?
  825.      "Timeout" :
  826.      ((error_bits & SCHIZO_PCIAFSR_PUNUS) ?
  827.       "Bus Unusable" : "???"))))))));
  828. printk("SCHIZO%d: PBM-%c bytemask[%04lx] was_block(%d) space(%s)n",
  829.        p->index, pbm_name,
  830.        (afsr & SCHIZO_PCIAFSR_BMSK) >> 32UL,
  831.        (afsr & SCHIZO_PCIAFSR_BLK) ? 1 : 0,
  832.        ((afsr & SCHIZO_PCIAFSR_CFG) ?
  833. "Config" :
  834. ((afsr & SCHIZO_PCIAFSR_MEM) ?
  835.  "Memory" :
  836.  ((afsr & SCHIZO_PCIAFSR_IO) ?
  837.   "I/O" : "???"))));
  838. printk("SCHIZO%d: PBM-%c PCI AFAR [%016lx]n",
  839.        p->index, pbm_name, afar);
  840. printk("SCHIZO%d: PBM-%c PCI Secondary errors [",
  841.        p->index, pbm_name);
  842. reported = 0;
  843. if (afsr & SCHIZO_PCIAFSR_SMA) {
  844. reported++;
  845. printk("(Master Abort)");
  846. }
  847. if (afsr & SCHIZO_PCIAFSR_STA) {
  848. reported++;
  849. printk("(Target Abort)");
  850. }
  851. if (afsr & SCHIZO_PCIAFSR_SRTRY) {
  852. reported++;
  853. printk("(Excessive Retries)");
  854. }
  855. if (afsr & SCHIZO_PCIAFSR_SPERR) {
  856. reported++;
  857. printk("(Parity Error)");
  858. }
  859. if (afsr & SCHIZO_PCIAFSR_STTO) {
  860. reported++;
  861. printk("(Timeout)");
  862. }
  863. if (afsr & SCHIZO_PCIAFSR_SUNUS) {
  864. reported++;
  865. printk("(Bus Unusable)");
  866. }
  867. if (!reported)
  868. printk("(none)");
  869. printk("]n");
  870. /* For the error types shown, scan PBM's PCI bus for devices
  871.  * which have logged that error type.
  872.  */
  873. /* If we see a Target Abort, this could be the result of an
  874.  * IOMMU translation error of some sort.  It is extremely
  875.  * useful to log this information as usually it indicates
  876.  * a bug in the IOMMU support code or a PCI device driver.
  877.  */
  878. if (error_bits & (SCHIZO_PCIAFSR_PTA | SCHIZO_PCIAFSR_STA)) {
  879. schizo_check_iommu_error(p, PCI_ERR);
  880. pci_scan_for_target_abort(p, pbm, pbm->pci_bus);
  881. }
  882. if (error_bits & (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_SMA))
  883. pci_scan_for_master_abort(p, pbm, pbm->pci_bus);
  884. /* For excessive retries, PSYCHO/PBM will abort the device
  885.  * and there is no way to specifically check for excessive
  886.  * retries in the config space status registers.  So what
  887.  * we hope is that we'll catch it via the master/target
  888.  * abort events.
  889.  */
  890. if (error_bits & (SCHIZO_PCIAFSR_PPERR | SCHIZO_PCIAFSR_SPERR))
  891. pci_scan_for_parity_error(p, pbm, pbm->pci_bus);
  892. schizo_clear_other_err_intr(irq);
  893. }
  894. #define SCHIZO_SAFARI_ERRLOG 0x10018UL
  895. #define SAFARI_ERRLOG_ERROUT 0x8000000000000000UL
  896. #define SAFARI_ERROR_BADCMD 0x4000000000000000UL
  897. #define SAFARI_ERROR_SSMDIS 0x2000000000000000UL
  898. #define SAFARI_ERROR_BADMA 0x1000000000000000UL
  899. #define SAFARI_ERROR_BADMB 0x0800000000000000UL
  900. #define SAFARI_ERROR_BADMC 0x0400000000000000UL
  901. #define SAFARI_ERROR_CPU1PS 0x0000000000002000UL
  902. #define SAFARI_ERROR_CPU1PB 0x0000000000001000UL
  903. #define SAFARI_ERROR_CPU0PS 0x0000000000000800UL
  904. #define SAFARI_ERROR_CPU0PB 0x0000000000000400UL
  905. #define SAFARI_ERROR_CIQTO 0x0000000000000200UL
  906. #define SAFARI_ERROR_LPQTO 0x0000000000000100UL
  907. #define SAFARI_ERROR_SFPQTO 0x0000000000000080UL
  908. #define SAFARI_ERROR_UFPQTO 0x0000000000000040UL
  909. #define SAFARI_ERROR_APERR 0x0000000000000020UL
  910. #define SAFARI_ERROR_UNMAP 0x0000000000000010UL
  911. #define SAFARI_ERROR_BUSERR 0x0000000000000004UL
  912. #define SAFARI_ERROR_TIMEOUT 0x0000000000000002UL
  913. #define SAFARI_ERROR_ILL 0x0000000000000001UL
  914. /* We only expect UNMAP errors here.  The rest of the Safari errors
  915.  * are marked fatal and thus cause a system reset.
  916.  */
  917. static void schizo_safarierr_intr(int irq, void *dev_id, struct pt_regs *regs)
  918. {
  919. struct pci_controller_info *p = dev_id;
  920. u64 errlog;
  921. errlog = schizo_read(p->controller_regs + SCHIZO_SAFARI_ERRLOG);
  922. schizo_write(p->controller_regs + SCHIZO_SAFARI_ERRLOG,
  923.      errlog & ~(SAFARI_ERRLOG_ERROUT));
  924. if (!(errlog & SAFARI_ERROR_UNMAP)) {
  925. printk("SCHIZO%d: Unexpected Safari error interrupt, errlog[%016lx]n",
  926.        p->index, errlog);
  927. schizo_clear_other_err_intr(irq);
  928. return;
  929. }
  930. printk("SCHIZO%d: Safari interrupt, UNMAPPED error, interrogating IOMMUs.n",
  931.        p->index);
  932. schizo_check_iommu_error(p, SAFARI_ERR);
  933. schizo_clear_other_err_intr(irq);
  934. }
  935. /* Nearly identical to PSYCHO equivalents... */
  936. #define SCHIZO_ECC_CTRL 0x10020UL
  937. #define  SCHIZO_ECCCTRL_EE  0x8000000000000000 /* Enable ECC Checking */
  938. #define  SCHIZO_ECCCTRL_UE  0x4000000000000000 /* Enable UE Interrupts */
  939. #define  SCHIZO_ECCCTRL_CE  0x2000000000000000 /* Enable CE INterrupts */
  940. #define SCHIZO_SAFARI_ERRCTRL 0x10008UL
  941. #define  SCHIZO_SAFERRCTRL_EN  0x8000000000000000UL
  942. #define SCHIZO_SAFARI_IRQCTRL 0x10010UL
  943. #define  SCHIZO_SAFIRQCTRL_EN  0x8000000000000000UL
  944. #define SCHIZO_UE_INO 0x30 /* Uncorrectable ECC error */
  945. #define SCHIZO_CE_INO 0x31 /* Correctable ECC error */
  946. #define SCHIZO_PCIERR_A_INO 0x32 /* PBM A PCI bus error */
  947. #define SCHIZO_PCIERR_B_INO 0x33 /* PBM B PCI bus error */
  948. #define SCHIZO_SERR_INO 0x34 /* Safari interface error */
  949. #define SCHIZO_PCIA_CTRL (SCHIZO_PBM_A_REGS_OFF + 0x2000UL)
  950. #define SCHIZO_PCIB_CTRL (SCHIZO_PBM_B_REGS_OFF + 0x2000UL)
  951. #define SCHIZO_PCICTRL_BUS_UNUS (1UL << 63UL)
  952. #define SCHIZO_PCICTRL_ESLCK (1UL << 51UL)
  953. #define SCHIZO_PCICTRL_ERRSLOT (7UL << 48UL)
  954. #define SCHIZO_PCICTRL_TTO_ERR (1UL << 38UL)
  955. #define SCHIZO_PCICTRL_RTRY_ERR (1UL << 37UL)
  956. #define SCHIZO_PCICTRL_DTO_ERR (1UL << 36UL)
  957. #define SCHIZO_PCICTRL_SBH_ERR (1UL << 35UL)
  958. #define SCHIZO_PCICTRL_SERR (1UL << 34UL)
  959. #define SCHIZO_PCICTRL_PCISPD (1UL << 33UL)
  960. #define SCHIZO_PCICTRL_PTO (3UL << 24UL)
  961. #define SCHIZO_PCICTRL_DTO_INT (1UL << 19UL)
  962. #define SCHIZO_PCICTRL_SBH_INT (1UL << 18UL)
  963. #define SCHIZO_PCICTRL_EEN (1UL << 17UL)
  964. #define SCHIZO_PCICTRL_PARK (1UL << 16UL)
  965. #define SCHIZO_PCICTRL_PCIRST (1UL <<  8UL)
  966. #define SCHIZO_PCICTRL_ARB (0x3fUL << 0UL)
  967. static void __init schizo_register_error_handlers(struct pci_controller_info *p)
  968. {
  969. struct pci_pbm_info *pbm_a = &p->pbm_A;
  970. struct pci_pbm_info *pbm_b = &p->pbm_B;
  971. unsigned long base = p->controller_regs;
  972. unsigned int irq, portid = p->portid;
  973. struct ino_bucket *bucket;
  974. u64 tmp;
  975. /* Build IRQs and register handlers. */
  976. irq = schizo_irq_build(pbm_b, NULL, (portid << 6) | SCHIZO_UE_INO);
  977. if (request_irq(irq, schizo_ue_intr,
  978. SA_SHIRQ, "SCHIZO UE", p) < 0) {
  979. prom_printf("SCHIZO%d: Cannot register UE interrupt.n",
  980.     p->index);
  981. prom_halt();
  982. }
  983. bucket = __bucket(irq);
  984. tmp = readl(bucket->imap);
  985. upa_writel(tmp, (base + SCHIZO_PBM_B_REGS_OFF + schizo_imap_offset(SCHIZO_UE_INO) + 4));
  986. irq = schizo_irq_build(pbm_b, NULL, (portid << 6) | SCHIZO_CE_INO);
  987. if (request_irq(irq, schizo_ce_intr,
  988. SA_SHIRQ, "SCHIZO CE", p) < 0) {
  989. prom_printf("SCHIZO%d: Cannot register CE interrupt.n",
  990.     p->index);
  991. prom_halt();
  992. }
  993. bucket = __bucket(irq);
  994. tmp = upa_readl(bucket->imap);
  995. upa_writel(tmp, (base + SCHIZO_PBM_B_REGS_OFF + schizo_imap_offset(SCHIZO_CE_INO) + 4));
  996. irq = schizo_irq_build(pbm_a, NULL, (portid << 6) | SCHIZO_PCIERR_A_INO);
  997. if (request_irq(irq, schizo_pcierr_intr,
  998. SA_SHIRQ, "SCHIZO PCIERR", pbm_a) < 0) {
  999. prom_printf("SCHIZO%d(PBMA): Cannot register PciERR interrupt.n",
  1000.     p->index);
  1001. prom_halt();
  1002. }
  1003. bucket = __bucket(irq);
  1004. tmp = upa_readl(bucket->imap);
  1005. upa_writel(tmp, (base + SCHIZO_PBM_A_REGS_OFF + schizo_imap_offset(SCHIZO_PCIERR_A_INO) + 4));
  1006. irq = schizo_irq_build(pbm_b, NULL, (portid << 6) | SCHIZO_PCIERR_B_INO);
  1007. if (request_irq(irq, schizo_pcierr_intr,
  1008. SA_SHIRQ, "SCHIZO PCIERR", pbm_b) < 0) {
  1009. prom_printf("SCHIZO%d(PBMB): Cannot register PciERR interrupt.n",
  1010.     p->index);
  1011. prom_halt();
  1012. }
  1013. bucket = __bucket(irq);
  1014. tmp = upa_readl(bucket->imap);
  1015. upa_writel(tmp, (base + SCHIZO_PBM_B_REGS_OFF + schizo_imap_offset(SCHIZO_PCIERR_B_INO) + 4));
  1016. irq = schizo_irq_build(pbm_b, NULL, (portid << 6) | SCHIZO_SERR_INO);
  1017. if (request_irq(irq, schizo_safarierr_intr,
  1018. SA_SHIRQ, "SCHIZO SERR", p) < 0) {
  1019. prom_printf("SCHIZO%d(PBMB): Cannot register SafariERR interrupt.n",
  1020.     p->index);
  1021. prom_halt();
  1022. }
  1023. bucket = __bucket(irq);
  1024. tmp = upa_readl(bucket->imap);
  1025. upa_writel(tmp, (base + SCHIZO_PBM_B_REGS_OFF + schizo_imap_offset(SCHIZO_SERR_INO) + 4));
  1026. /* Enable UE and CE interrupts for controller. */
  1027. schizo_write(base + SCHIZO_ECC_CTRL,
  1028.      (SCHIZO_ECCCTRL_EE |
  1029.       SCHIZO_ECCCTRL_UE |
  1030.       SCHIZO_ECCCTRL_CE));
  1031. /* Enable PCI Error interrupts and clear error
  1032.  * bits for each PBM.
  1033.  */
  1034. tmp = schizo_read(base + SCHIZO_PCIA_CTRL);
  1035. tmp |= (SCHIZO_PCICTRL_BUS_UNUS |
  1036. SCHIZO_PCICTRL_ESLCK |
  1037. SCHIZO_PCICTRL_TTO_ERR |
  1038. SCHIZO_PCICTRL_RTRY_ERR |
  1039. SCHIZO_PCICTRL_DTO_ERR |
  1040. SCHIZO_PCICTRL_SBH_ERR |
  1041. SCHIZO_PCICTRL_SERR |
  1042. SCHIZO_PCICTRL_SBH_INT |
  1043. SCHIZO_PCICTRL_EEN);
  1044. schizo_write(base + SCHIZO_PCIA_CTRL, tmp);
  1045. tmp = schizo_read(base + SCHIZO_PCIB_CTRL);
  1046. tmp |= (SCHIZO_PCICTRL_BUS_UNUS |
  1047. SCHIZO_PCICTRL_ESLCK |
  1048. SCHIZO_PCICTRL_TTO_ERR |
  1049. SCHIZO_PCICTRL_RTRY_ERR |
  1050. SCHIZO_PCICTRL_DTO_ERR |
  1051. SCHIZO_PCICTRL_SBH_ERR |
  1052. SCHIZO_PCICTRL_SERR |
  1053. SCHIZO_PCICTRL_SBH_INT |
  1054. SCHIZO_PCICTRL_EEN);
  1055. schizo_write(base + SCHIZO_PCIB_CTRL, tmp);
  1056. schizo_write(base + SCHIZO_PBM_A_REGS_OFF + SCHIZO_PCI_AFSR,
  1057.      (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  1058.       SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  1059.       SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  1060.       SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  1061.       SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  1062.       SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
  1063. schizo_write(base + SCHIZO_PBM_B_REGS_OFF + SCHIZO_PCI_AFSR,
  1064.      (SCHIZO_PCIAFSR_PMA | SCHIZO_PCIAFSR_PTA |
  1065.       SCHIZO_PCIAFSR_PRTRY | SCHIZO_PCIAFSR_PPERR |
  1066.       SCHIZO_PCIAFSR_PTTO | SCHIZO_PCIAFSR_PUNUS |
  1067.       SCHIZO_PCIAFSR_SMA | SCHIZO_PCIAFSR_STA |
  1068.       SCHIZO_PCIAFSR_SRTRY | SCHIZO_PCIAFSR_SPERR |
  1069.       SCHIZO_PCIAFSR_STTO | SCHIZO_PCIAFSR_SUNUS));
  1070. /* Make all Safari error conditions fatal except unmapped errors
  1071.  * which we make generate interrupts.
  1072.  */
  1073. #if 1
  1074. /* XXX Something wrong with some Excalibur systems
  1075.  * XXX Sun is shipping.  The behavior on a 2-cpu
  1076.  * XXX machine is that both CPU1 parity error bits
  1077.  * XXX are set and are immediately set again when
  1078.  * XXX their error status bits are cleared.  Just
  1079.  * XXX ignore them for now.  -DaveM
  1080.  */
  1081. schizo_write(base + SCHIZO_SAFARI_ERRCTRL,
  1082.      (SCHIZO_SAFERRCTRL_EN |
  1083.       (SAFARI_ERROR_BADCMD | SAFARI_ERROR_SSMDIS |
  1084.        SAFARI_ERROR_BADMA | SAFARI_ERROR_BADMB |
  1085.        SAFARI_ERROR_BADMC |
  1086.        SAFARI_ERROR_CIQTO |
  1087.        SAFARI_ERROR_LPQTO | SAFARI_ERROR_SFPQTO |
  1088.        SAFARI_ERROR_UFPQTO | SAFARI_ERROR_APERR |
  1089.        SAFARI_ERROR_BUSERR | SAFARI_ERROR_TIMEOUT |
  1090.        SAFARI_ERROR_ILL)));
  1091. #else
  1092. schizo_write(base + SCHIZO_SAFARI_ERRCTRL,
  1093.      (SCHIZO_SAFERRCTRL_EN |
  1094.       (SAFARI_ERROR_BADCMD | SAFARI_ERROR_SSMDIS |
  1095.        SAFARI_ERROR_BADMA | SAFARI_ERROR_BADMB |
  1096.        SAFARI_ERROR_BADMC |
  1097.        SAFARI_ERROR_CPU1PS | SAFARI_ERROR_CPU1PB |
  1098.        SAFARI_ERROR_CPU0PS | SAFARI_ERROR_CPU0PB |
  1099.        SAFARI_ERROR_CIQTO |
  1100.        SAFARI_ERROR_LPQTO | SAFARI_ERROR_SFPQTO |
  1101.        SAFARI_ERROR_UFPQTO | SAFARI_ERROR_APERR |
  1102.        SAFARI_ERROR_BUSERR | SAFARI_ERROR_TIMEOUT |
  1103.        SAFARI_ERROR_ILL)));
  1104. #endif
  1105. schizo_write(base + SCHIZO_SAFARI_IRQCTRL,
  1106.      (SCHIZO_SAFIRQCTRL_EN | (SAFARI_ERROR_UNMAP)));
  1107. }
  1108. /* We have to do the config space accesses by hand, thus... */
  1109. #define PBM_BRIDGE_BUS 0x40
  1110. #define PBM_BRIDGE_SUBORDINATE 0x41
  1111. static void __init pbm_renumber(struct pci_pbm_info *pbm, u8 orig_busno)
  1112. {
  1113. u8 *addr, busno;
  1114. int nbus;
  1115. busno = pci_highest_busnum;
  1116. nbus = pbm->pci_last_busno - pbm->pci_first_busno;
  1117. addr = schizo_pci_config_mkaddr(pbm, orig_busno,
  1118. 0, PBM_BRIDGE_BUS);
  1119. pci_config_write8(addr, busno);
  1120. addr = schizo_pci_config_mkaddr(pbm, busno,
  1121. 0, PBM_BRIDGE_SUBORDINATE);
  1122. pci_config_write8(addr, busno + nbus);
  1123. pbm->pci_first_busno = busno;
  1124. pbm->pci_last_busno = busno + nbus;
  1125. pci_highest_busnum = busno + nbus + 1;
  1126. do {
  1127. pci_bus2pbm[busno++] = pbm;
  1128. } while (nbus--);
  1129. }
  1130. /* We have to do the config space accesses by hand here since
  1131.  * the pci_bus2pbm array is not ready yet.
  1132.  */
  1133. static void __init pbm_pci_bridge_renumber(struct pci_pbm_info *pbm,
  1134.    u8 busno)
  1135. {
  1136. u32 devfn, l, class;
  1137. u8 hdr_type;
  1138. int is_multi = 0;
  1139. for(devfn = 0; devfn < 0xff; ++devfn) {
  1140. u32 *dwaddr;
  1141. u8 *baddr;
  1142. if (PCI_FUNC(devfn) != 0 && is_multi == 0)
  1143. continue;
  1144. /* Anything there? */
  1145. dwaddr = schizo_pci_config_mkaddr(pbm, busno, devfn, PCI_VENDOR_ID);
  1146. l = 0xffffffff;
  1147. pci_config_read32(dwaddr, &l);
  1148. if (l == 0xffffffff || l == 0x00000000 ||
  1149.     l == 0x0000ffff || l == 0xffff0000) {
  1150. is_multi = 0;
  1151. continue;
  1152. }
  1153. baddr = schizo_pci_config_mkaddr(pbm, busno, devfn, PCI_HEADER_TYPE);
  1154. pci_config_read8(baddr, &hdr_type);
  1155. if (PCI_FUNC(devfn) == 0)
  1156. is_multi = hdr_type & 0x80;
  1157. dwaddr = schizo_pci_config_mkaddr(pbm, busno, devfn, PCI_CLASS_REVISION);
  1158. class = 0xffffffff;
  1159. pci_config_read32(dwaddr, &class);
  1160. if ((class >> 16) == PCI_CLASS_BRIDGE_PCI) {
  1161. u32 buses = 0xffffffff;
  1162. dwaddr = schizo_pci_config_mkaddr(pbm, busno, devfn,
  1163.   PCI_PRIMARY_BUS);
  1164. pci_config_read32(dwaddr, &buses);
  1165. pbm_pci_bridge_renumber(pbm, (buses >> 8) & 0xff);
  1166. buses &= 0xff000000;
  1167. pci_config_write32(dwaddr, buses);
  1168. }
  1169. }
  1170. }
  1171. static void __init pbm_bridge_reconfigure(struct pci_controller_info *p)
  1172. {
  1173. struct pci_pbm_info *pbm;
  1174. u8 *addr;
  1175. /* Clear out primary/secondary/subordinate bus numbers on
  1176.  * all PCI-to-PCI bridges under each PBM.  The generic bus
  1177.  * probing will fix them up.
  1178.  */
  1179. pbm_pci_bridge_renumber(&p->pbm_B, p->pbm_B.pci_first_busno);
  1180. pbm_pci_bridge_renumber(&p->pbm_A, p->pbm_A.pci_first_busno);
  1181. /* Move PBM A out of the way. */
  1182. pbm = &p->pbm_A;
  1183. addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1184. 0, PBM_BRIDGE_BUS);
  1185. pci_config_write8(addr, 0xff);
  1186. addr = schizo_pci_config_mkaddr(pbm, 0xff,
  1187. 0, PBM_BRIDGE_SUBORDINATE);
  1188. pci_config_write8(addr, 0xff);
  1189. /* Now we can safely renumber both PBMs. */
  1190. pbm_renumber(&p->pbm_B, p->pbm_B.pci_first_busno);
  1191. pbm_renumber(&p->pbm_A, 0xff);
  1192. }
  1193. static void __init pbm_config_busmastering(struct pci_pbm_info *pbm)
  1194. {
  1195. u8 *addr;
  1196. /* Set cache-line size to 64 bytes, this is actually
  1197.  * a nop but I do it for completeness.
  1198.  */
  1199. addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1200. 0, PCI_CACHE_LINE_SIZE);
  1201. pci_config_write8(addr, 64 / sizeof(u32));
  1202. /* Set PBM latency timer to 64 PCI clocks. */
  1203. addr = schizo_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1204. 0, PCI_LATENCY_TIMER);
  1205. pci_config_write8(addr, 64);
  1206. }
  1207. static void __init pbm_scan_bus(struct pci_controller_info *p,
  1208. struct pci_pbm_info *pbm)
  1209. {
  1210. struct pcidev_cookie *cookie = kmalloc(sizeof(*cookie), GFP_KERNEL);
  1211. if (!cookie) {
  1212. prom_printf("SCHIZO: Critical allocation failure.n");
  1213. prom_halt();
  1214. }
  1215. /* All we care about is the PBM. */
  1216. memset(cookie, 0, sizeof(*cookie));
  1217. cookie->pbm = pbm;
  1218. pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno,
  1219.     p->pci_ops,
  1220.     pbm);
  1221. pci_fixup_host_bridge_self(pbm->pci_bus);
  1222. pbm->pci_bus->self->sysdata = cookie;
  1223. pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
  1224. pci_record_assignments(pbm, pbm->pci_bus);
  1225. pci_assign_unassigned(pbm, pbm->pci_bus);
  1226. pci_fixup_irq(pbm, pbm->pci_bus);
  1227. pci_determine_66mhz_disposition(pbm, pbm->pci_bus);
  1228. pci_setup_busmastering(pbm, pbm->pci_bus);
  1229. }
  1230. static void __init schizo_scan_bus(struct pci_controller_info *p)
  1231. {
  1232. pbm_bridge_reconfigure(p);
  1233. pbm_config_busmastering(&p->pbm_B);
  1234. p->pbm_B.is_66mhz_capable = 0;
  1235. pbm_config_busmastering(&p->pbm_A);
  1236. p->pbm_A.is_66mhz_capable = 1;
  1237. pbm_scan_bus(p, &p->pbm_B);
  1238. pbm_scan_bus(p, &p->pbm_A);
  1239. /* After the PCI bus scan is complete, we can register
  1240.  * the error interrupt handlers.
  1241.  */
  1242. schizo_register_error_handlers(p);
  1243. }
  1244. static void __init schizo_base_address_update(struct pci_dev *pdev, int resource)
  1245. {
  1246. struct pcidev_cookie *pcp = pdev->sysdata;
  1247. struct pci_pbm_info *pbm = pcp->pbm;
  1248. struct resource *res, *root;
  1249. u32 reg;
  1250. int where, size, is_64bit;
  1251. res = &pdev->resource[resource];
  1252. if (resource < 6) {
  1253. where = PCI_BASE_ADDRESS_0 + (resource * 4);
  1254. } else if (resource == PCI_ROM_RESOURCE) {
  1255. where = pdev->rom_base_reg;
  1256. } else {
  1257. /* Somebody might have asked allocation of a non-standard resource */
  1258. return;
  1259. }
  1260. is_64bit = 0;
  1261. if (res->flags & IORESOURCE_IO)
  1262. root = &pbm->io_space;
  1263. else {
  1264. root = &pbm->mem_space;
  1265. if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
  1266.     == PCI_BASE_ADDRESS_MEM_TYPE_64)
  1267. is_64bit = 1;
  1268. }
  1269. size = res->end - res->start;
  1270. pci_read_config_dword(pdev, where, &reg);
  1271. reg = ((reg & size) |
  1272.        (((u32)(res->start - root->start)) & ~size));
  1273. if (resource == PCI_ROM_RESOURCE) {
  1274. reg |= PCI_ROM_ADDRESS_ENABLE;
  1275. res->flags |= PCI_ROM_ADDRESS_ENABLE;
  1276. }
  1277. pci_write_config_dword(pdev, where, reg);
  1278. /* This knows that the upper 32-bits of the address
  1279.  * must be zero.  Our PCI common layer enforces this.
  1280.  */
  1281. if (is_64bit)
  1282. pci_write_config_dword(pdev, where + 4, 0);
  1283. }
  1284. static void __init schizo_resource_adjust(struct pci_dev *pdev,
  1285.   struct resource *res,
  1286.   struct resource *root)
  1287. {
  1288. res->start += root->start;
  1289. res->end += root->start;
  1290. }
  1291. /* Interrogate Safari match/mask registers to figure out where
  1292.  * PCI MEM, I/O, and Config space are for this PCI bus module.
  1293.  */
  1294. #define SCHIZO_PCI_A_MEM_MATCH 0x00040UL
  1295. #define SCHIZO_PCI_A_MEM_MASK 0x00048UL
  1296. #define SCHIZO_PCI_A_IO_MATCH 0x00050UL
  1297. #define SCHIZO_PCI_A_IO_MASK 0x00058UL
  1298. #define SCHIZO_PCI_B_MEM_MATCH 0x00060UL
  1299. #define SCHIZO_PCI_B_MEM_MASK 0x00068UL
  1300. #define SCHIZO_PCI_B_IO_MATCH 0x00070UL
  1301. #define SCHIZO_PCI_B_IO_MASK 0x00078UL
  1302. static void schizo_determine_mem_io_space(struct pci_pbm_info *pbm,
  1303.   int is_pbm_a, unsigned long reg_base)
  1304. {
  1305. u64 mem_match, mem_mask;
  1306. u64 io_match;
  1307. u64 a;
  1308. if (is_pbm_a) {
  1309. mem_match = reg_base + SCHIZO_PCI_A_MEM_MATCH;
  1310. io_match = reg_base + SCHIZO_PCI_A_IO_MATCH;
  1311. } else {
  1312. mem_match = reg_base + SCHIZO_PCI_B_MEM_MATCH;
  1313. io_match = reg_base + SCHIZO_PCI_B_IO_MATCH;
  1314. }
  1315. mem_mask = mem_match + 0x8UL;
  1316. a = schizo_read(mem_match) & ~0x8000000000000000UL;
  1317. /* It should be 2GB in size but the decode is set for the full
  1318.  * 4GB so we have to add the 2G by hand.
  1319.  */
  1320. pbm->mem_space.start = a;
  1321. pbm->mem_space.end = a + 0x80000000;
  1322. pbm->mem_space.flags = IORESOURCE_MEM;
  1323. /* This 32MB area is divided into two pieces.  The first
  1324.  * 16MB is Config space, the next 16MB is I/O space.
  1325.  */
  1326. a = schizo_read(io_match) & ~0x8000000000000000UL;
  1327. pbm->config_space = a;
  1328. printk("SCHIZO PBM%c: Local PCI config space at %016lxn",
  1329.        (is_pbm_a ? 'A' : 'B'), pbm->config_space);
  1330. a += (16UL * 1024UL * 1024UL);
  1331. pbm->io_space.start = a;
  1332. pbm->io_space.end = a + ((16UL * 1024UL * 1024UL) - 1UL);
  1333. pbm->io_space.flags = IORESOURCE_IO;
  1334. }
  1335. static void __init pbm_register_toplevel_resources(struct pci_controller_info *p,
  1336.    struct pci_pbm_info *pbm)
  1337. {
  1338. char *name = pbm->name;
  1339. sprintf(name, "SCHIZO%d PBM%c",
  1340. p->index,
  1341. (pbm == &p->pbm_A ? 'A' : 'B'));
  1342. pbm->io_space.name = pbm->mem_space.name = name;
  1343. request_resource(&ioport_resource, &pbm->io_space);
  1344. request_resource(&iomem_resource, &pbm->mem_space);
  1345. pci_register_legacy_regions(&pbm->io_space,
  1346.     &pbm->mem_space);
  1347. }
  1348. #define SCHIZO_STRBUF_CONTROL_A (SCHIZO_PBM_A_REGS_OFF + 0x02800UL)
  1349. #define SCHIZO_STRBUF_FLUSH_A (SCHIZO_PBM_A_REGS_OFF + 0x02808UL)
  1350. #define SCHIZO_STRBUF_FSYNC_A (SCHIZO_PBM_A_REGS_OFF + 0x02810UL)
  1351. #define SCHIZO_STRBUF_CTXFLUSH_A (SCHIZO_PBM_A_REGS_OFF + 0x02818UL)
  1352. #define SCHIZO_STRBUF_CTXMATCH_A (SCHIZO_PBM_A_REGS_OFF + 0x10000UL)
  1353. #define SCHIZO_STRBUF_CONTROL_B (SCHIZO_PBM_B_REGS_OFF + 0x02800UL)
  1354. #define SCHIZO_STRBUF_FLUSH_B (SCHIZO_PBM_B_REGS_OFF + 0x02808UL)
  1355. #define SCHIZO_STRBUF_FSYNC_B (SCHIZO_PBM_B_REGS_OFF + 0x02810UL)
  1356. #define SCHIZO_STRBUF_CTXFLUSH_B (SCHIZO_PBM_B_REGS_OFF + 0x02818UL)
  1357. #define SCHIZO_STRBUF_CTXMATCH_B (SCHIZO_PBM_B_REGS_OFF + 0x10000UL)
  1358. static void schizo_pbm_strbuf_init(struct pci_controller_info *p,
  1359.    struct pci_pbm_info *pbm,
  1360.    int is_pbm_a)
  1361. {
  1362. unsigned long base = p->controller_regs;
  1363. u64 control;
  1364. /* SCHIZO has context flushing. */
  1365. if (is_pbm_a) {
  1366. pbm->stc.strbuf_control = base + SCHIZO_STRBUF_CONTROL_A;
  1367. pbm->stc.strbuf_pflush = base + SCHIZO_STRBUF_FLUSH_A;
  1368. pbm->stc.strbuf_fsync = base + SCHIZO_STRBUF_FSYNC_A;
  1369. pbm->stc.strbuf_ctxflush = base + SCHIZO_STRBUF_CTXFLUSH_A;
  1370. pbm->stc.strbuf_ctxmatch_base = base + SCHIZO_STRBUF_CTXMATCH_A;
  1371. } else {
  1372. pbm->stc.strbuf_control = base + SCHIZO_STRBUF_CONTROL_B;
  1373. pbm->stc.strbuf_pflush = base + SCHIZO_STRBUF_FLUSH_B;
  1374. pbm->stc.strbuf_fsync = base + SCHIZO_STRBUF_FSYNC_B;
  1375. pbm->stc.strbuf_ctxflush = base + SCHIZO_STRBUF_CTXFLUSH_B;
  1376. pbm->stc.strbuf_ctxmatch_base = base + SCHIZO_STRBUF_CTXMATCH_B;
  1377. }
  1378. pbm->stc.strbuf_flushflag = (volatile unsigned long *)
  1379. ((((unsigned long)&pbm->stc.__flushflag_buf[0])
  1380.   + 63UL)
  1381.  & ~63UL);
  1382. pbm->stc.strbuf_flushflag_pa = (unsigned long)
  1383. __pa(pbm->stc.strbuf_flushflag);
  1384. /* Turn off LRU locking and diag mode, enable the
  1385.  * streaming buffer and leave the rerun-disable
  1386.  * setting however OBP set it.
  1387.  */
  1388. control = schizo_read(pbm->stc.strbuf_control);
  1389. control &= ~(SCHIZO_STRBUF_CTRL_LPTR |
  1390.      SCHIZO_STRBUF_CTRL_LENAB |
  1391.      SCHIZO_STRBUF_CTRL_DENAB);
  1392. control |= SCHIZO_STRBUF_CTRL_ENAB;
  1393. schizo_write(pbm->stc.strbuf_control, control);
  1394. pbm->stc.strbuf_enabled = 1;
  1395. }
  1396. #define SCHIZO_IOMMU_CONTROL_A (SCHIZO_PBM_A_REGS_OFF + 0x00200UL)
  1397. #define SCHIZO_IOMMU_TSBBASE_A (SCHIZO_PBM_A_REGS_OFF + 0x00208UL)
  1398. #define SCHIZO_IOMMU_FLUSH_A (SCHIZO_PBM_A_REGS_OFF + 0x00210UL)
  1399. #define SCHIZO_IOMMU_CTXFLUSH_A (SCHIZO_PBM_A_REGS_OFF + 0x00218UL)
  1400. #define SCHIZO_IOMMU_TAG_A (SCHIZO_PBM_A_REGS_OFF + 0x0a580UL)
  1401. #define SCHIZO_IOMMU_DATA_A (SCHIZO_PBM_A_REGS_OFF + 0x0a600UL)
  1402. #define SCHIZO_IOMMU_CONTROL_B (SCHIZO_PBM_B_REGS_OFF + 0x00200UL)
  1403. #define SCHIZO_IOMMU_TSBBASE_B (SCHIZO_PBM_B_REGS_OFF + 0x00208UL)
  1404. #define SCHIZO_IOMMU_FLUSH_B (SCHIZO_PBM_B_REGS_OFF + 0x00210UL)
  1405. #define SCHIZO_IOMMU_CTXFLUSH_B (SCHIZO_PBM_B_REGS_OFF + 0x00218UL)
  1406. #define SCHIZO_IOMMU_TAG_B (SCHIZO_PBM_B_REGS_OFF + 0x0a580UL)
  1407. #define SCHIZO_IOMMU_DATA_B (SCHIZO_PBM_B_REGS_OFF + 0x0a600UL)
  1408. static void schizo_pbm_iommu_init(struct pci_controller_info *p,
  1409.   struct pci_pbm_info *pbm,
  1410.   int is_pbm_a)
  1411. {
  1412. struct pci_iommu *iommu = pbm->iommu;
  1413. unsigned long tsbbase, i, tagbase, database;
  1414. u64 control;
  1415. /* Setup initial software IOMMU state. */
  1416. spin_lock_init(&iommu->lock);
  1417. iommu->iommu_cur_ctx = 0;
  1418. /* Register addresses, SCHIZO has iommu ctx flushing. */
  1419. if (is_pbm_a) {
  1420. iommu->iommu_control  = p->controller_regs + SCHIZO_IOMMU_CONTROL_A;
  1421. iommu->iommu_tsbbase  = p->controller_regs + SCHIZO_IOMMU_TSBBASE_A;
  1422. iommu->iommu_flush    = p->controller_regs + SCHIZO_IOMMU_FLUSH_A;
  1423. iommu->iommu_ctxflush = p->controller_regs + SCHIZO_IOMMU_CTXFLUSH_A;
  1424. } else {
  1425. iommu->iommu_control  = p->controller_regs + SCHIZO_IOMMU_CONTROL_B;
  1426. iommu->iommu_tsbbase  = p->controller_regs + SCHIZO_IOMMU_TSBBASE_B;
  1427. iommu->iommu_flush    = p->controller_regs + SCHIZO_IOMMU_FLUSH_B;
  1428. iommu->iommu_ctxflush = p->controller_regs + SCHIZO_IOMMU_CTXFLUSH_B;
  1429. }
  1430. /* We use the main control/status register of SCHIZO as the write
  1431.  * completion register.
  1432.  */
  1433. iommu->write_complete_reg = p->controller_regs + 0x10000UL;
  1434. /*
  1435.  * Invalidate TLB Entries.
  1436.  */
  1437. control = schizo_read(iommu->iommu_control);
  1438. control |= SCHIZO_IOMMU_CTRL_DENAB;
  1439. schizo_write(iommu->iommu_control, control);
  1440. if (is_pbm_a)
  1441. tagbase = SCHIZO_IOMMU_TAG_A, database = SCHIZO_IOMMU_DATA_A;
  1442. else
  1443. tagbase = SCHIZO_IOMMU_TAG_B, database = SCHIZO_IOMMU_DATA_B;
  1444. for(i = 0; i < 16; i++) {
  1445. schizo_write(p->controller_regs + tagbase + (i * 8UL), 0);
  1446. schizo_write(p->controller_regs + database + (i * 8UL), 0);
  1447. }
  1448. /* Leave diag mode enabled for full-flushing done
  1449.  * in pci_iommu.c
  1450.  */
  1451. /* Using assumed page size 8K with 128K entries we need 1MB iommu page
  1452.  * table (128K ioptes * 8 bytes per iopte).  This is
  1453.  * page order 7 on UltraSparc.
  1454.  */
  1455. tsbbase = __get_free_pages(GFP_KERNEL, get_order(IO_TSB_SIZE));
  1456. if (!tsbbase) {
  1457. prom_printf("SCHIZO_IOMMU: Error, gfp(tsb) failed.n");
  1458. prom_halt();
  1459. }
  1460. iommu->page_table = (iopte_t *)tsbbase;
  1461. iommu->page_table_sz_bits = 17;
  1462. iommu->page_table_map_base = 0xc0000000;
  1463. iommu->dma_addr_mask = 0xffffffff;
  1464. memset((char *)tsbbase, 0, IO_TSB_SIZE);
  1465. /* We start with no consistent mappings. */
  1466. iommu->lowest_consistent_map =
  1467. 1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS);
  1468. for (i = 0; i < PBM_NCLUSTERS; i++) {
  1469. iommu->alloc_info[i].flush = 0;
  1470. iommu->alloc_info[i].next = 0;
  1471. }
  1472. schizo_write(iommu->iommu_tsbbase, __pa(tsbbase));
  1473. control = schizo_read(iommu->iommu_control);
  1474. control &= ~(SCHIZO_IOMMU_CTRL_TSBSZ | SCHIZO_IOMMU_CTRL_TBWSZ);
  1475. control |= (SCHIZO_IOMMU_TSBSZ_128K | SCHIZO_IOMMU_CTRL_ENAB);
  1476. schizo_write(iommu->iommu_control, control);
  1477. }
  1478. static void schizo_pbm_init(struct pci_controller_info *p,
  1479.     int prom_node, int is_pbm_a)
  1480. {
  1481. unsigned int busrange[2];
  1482. struct pci_pbm_info *pbm;
  1483. int err;
  1484. if (is_pbm_a)
  1485. pbm = &p->pbm_A;
  1486. else
  1487. pbm = &p->pbm_B;
  1488. schizo_determine_mem_io_space(pbm, is_pbm_a, p->controller_regs);
  1489. pbm_register_toplevel_resources(p, pbm);
  1490. pbm->parent = p;
  1491. pbm->prom_node = prom_node;
  1492. pbm->pci_first_slot = 1;
  1493. prom_getstring(prom_node, "name",
  1494.        pbm->prom_name,
  1495.        sizeof(pbm->prom_name));
  1496. err = prom_getproperty(prom_node, "ranges",
  1497.        (char *) pbm->pbm_ranges,
  1498.        sizeof(pbm->pbm_ranges));
  1499. if (err != -1)
  1500. pbm->num_pbm_ranges =
  1501. (err / sizeof(struct linux_prom_pci_ranges));
  1502. else
  1503. pbm->num_pbm_ranges = 0;
  1504. err = prom_getproperty(prom_node, "interrupt-map",
  1505.        (char *)pbm->pbm_intmap,
  1506.        sizeof(pbm->pbm_intmap));
  1507. if (err != -1) {
  1508. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  1509. err = prom_getproperty(prom_node, "interrupt-map-mask",
  1510.        (char *)&pbm->pbm_intmask,
  1511.        sizeof(pbm->pbm_intmask));
  1512. if (err == -1) {
  1513. prom_printf("SCHIZO-PBM: Fatal error, no "
  1514.     "interrupt-map-mask.n");
  1515. prom_halt();
  1516. }
  1517. } else {
  1518. pbm->num_pbm_intmap = 0;
  1519. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  1520. }
  1521. err = prom_getproperty(prom_node, "bus-range",
  1522.        (char *)&busrange[0],
  1523.        sizeof(busrange));
  1524. if (err == 0 || err == -1) {
  1525. prom_printf("SCHIZO-PBM: Fatal error, no bus-range.n");
  1526. prom_halt();
  1527. }
  1528. pbm->pci_first_busno = busrange[0];
  1529. pbm->pci_last_busno = busrange[1];
  1530. schizo_pbm_iommu_init(p, pbm, is_pbm_a);
  1531. schizo_pbm_strbuf_init(p, pbm, is_pbm_a);
  1532. }
  1533. #define SCHIZO_PCIA_IRQ_RETRY (SCHIZO_PBM_A_REGS_OFF + 0x1a00UL)
  1534. #define SCHIZO_PCIB_IRQ_RETRY (SCHIZO_PBM_B_REGS_OFF + 0x1a00UL)
  1535. #define  SCHIZO_IRQ_RETRY_INF  0xffUL
  1536. #define SCHIZO_PCIA_DIAG (SCHIZO_PBM_A_REGS_OFF + 0x2020UL)
  1537. #define SCHIZO_PCIB_DIAG (SCHIZO_PBM_B_REGS_OFF + 0x2020UL)
  1538. #define  SCHIZO_PCIDIAG_D_BADECC (1UL << 10UL) /* Disable BAD ECC errors */
  1539. #define  SCHIZO_PCIDIAG_D_BYPASS (1UL <<  9UL) /* Disable MMU bypass mode */
  1540. #define  SCHIZO_PCIDIAG_D_TTO (1UL <<  8UL) /* Disable TTO errors */
  1541. #define  SCHIZO_PCIDIAG_D_RTRYARB (1UL <<  7UL) /* Disable retry arbitration */
  1542. #define  SCHIZO_PCIDIAG_D_RETRY (1UL <<  6UL) /* Disable retry limit */
  1543. #define  SCHIZO_PCIDIAG_D_INTSYNC (1UL <<  5UL) /* Disable interrupt/DMA synch */
  1544. #define  SCHIZO_PCIDIAG_I_DMA_PARITY (1UL <<  3UL) /* Invert DMA parity */
  1545. #define  SCHIZO_PCIDIAG_I_PIOD_PARITY (1UL <<  2UL) /* Invert PIO data parity */
  1546. #define  SCHIZO_PCIDIAG_I_PIOA_PARITY (1UL <<  1U)L /* Invert PIO address parity */
  1547. static void schizo_controller_hwinit(struct pci_controller_info *p)
  1548. {
  1549. unsigned long pbm_a_base, pbm_b_base;
  1550. u64 tmp;
  1551. pbm_a_base = p->controller_regs + SCHIZO_PBM_A_REGS_OFF;
  1552. pbm_b_base = p->controller_regs + SCHIZO_PBM_B_REGS_OFF;
  1553. /* Set IRQ retry to infinity. */
  1554. schizo_write(p->controller_regs + SCHIZO_PCIA_IRQ_RETRY,
  1555.      SCHIZO_IRQ_RETRY_INF);
  1556. schizo_write(p->controller_regs + SCHIZO_PCIB_IRQ_RETRY,
  1557.      SCHIZO_IRQ_RETRY_INF);
  1558. /* Enable arbiter for all PCI slots.  Also, disable PCI interval
  1559.  * timer so that DTO (Discard TimeOuts) are not reported because
  1560.  * some Schizo revisions report them erroneously.
  1561.  */
  1562. tmp = schizo_read(p->controller_regs + SCHIZO_PCIA_CTRL);
  1563. tmp |= SCHIZO_PCICTRL_ARB;
  1564. tmp &= ~SCHIZO_PCICTRL_PTO;
  1565. schizo_write(p->controller_regs + SCHIZO_PCIA_CTRL, tmp);
  1566. tmp = schizo_read(p->controller_regs + SCHIZO_PCIB_CTRL);
  1567. tmp |= SCHIZO_PCICTRL_ARB;
  1568. tmp &= ~SCHIZO_PCICTRL_PTO;
  1569. schizo_write(p->controller_regs + SCHIZO_PCIB_CTRL, tmp);
  1570. /* Disable TTO error reporting (won't happen anyway since we
  1571.  * disabled the PCI interval timer above) and retry arbitration
  1572.  * (can cause hangs in some Schizo revisions).
  1573.  */
  1574. tmp = schizo_read(p->controller_regs + SCHIZO_PCIA_DIAG);
  1575. tmp |= (SCHIZO_PCIDIAG_D_TTO | SCHIZO_PCIDIAG_D_RTRYARB);
  1576. schizo_write(p->controller_regs + SCHIZO_PCIA_DIAG, tmp);
  1577. tmp = schizo_read(p->controller_regs + SCHIZO_PCIB_DIAG);
  1578. tmp |= (SCHIZO_PCIDIAG_D_TTO | SCHIZO_PCIDIAG_D_RTRYARB);
  1579. schizo_write(p->controller_regs + SCHIZO_PCIB_DIAG, tmp);
  1580. }
  1581. void __init schizo_init(int node, char *model_name)
  1582. {
  1583. struct linux_prom64_registers pr_regs[3];
  1584. struct pci_controller_info *p;
  1585. struct pci_iommu *iommu;
  1586. unsigned long flags;
  1587. u32 portid;
  1588. int is_pbm_a, err;
  1589. portid = prom_getintdefault(node, "portid", 0xff);
  1590. spin_lock_irqsave(&pci_controller_lock, flags);
  1591. for(p = pci_controller_root; p; p = p->next) {
  1592. if (p->portid == portid) {
  1593. spin_unlock_irqrestore(&pci_controller_lock, flags);
  1594. is_pbm_a = (p->pbm_A.prom_node == 0);
  1595. schizo_pbm_init(p, node, is_pbm_a);
  1596. return;
  1597. }
  1598. }
  1599. spin_unlock_irqrestore(&pci_controller_lock, flags);
  1600. p = kmalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  1601. if (!p) {
  1602. prom_printf("SCHIZO: Fatal memory allocation error.n");
  1603. prom_halt();
  1604. }
  1605. memset(p, 0, sizeof(*p));
  1606. iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  1607. if (!iommu) {
  1608. prom_printf("SCHIZO: Fatal memory allocation error.n");
  1609. prom_halt();
  1610. }
  1611. memset(iommu, 0, sizeof(*iommu));
  1612. p->pbm_A.iommu = iommu;
  1613. iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  1614. if (!iommu) {
  1615. prom_printf("SCHIZO: Fatal memory allocation error.n");
  1616. prom_halt();
  1617. }
  1618. memset(iommu, 0, sizeof(*iommu));
  1619. p->pbm_B.iommu = iommu;
  1620. spin_lock_irqsave(&pci_controller_lock, flags);
  1621. p->next = pci_controller_root;
  1622. pci_controller_root = p;
  1623. spin_unlock_irqrestore(&pci_controller_lock, flags);
  1624. p->portid = portid;
  1625. p->index = pci_num_controllers++;
  1626. p->pbms_same_domain = 0;
  1627. p->scan_bus = schizo_scan_bus;
  1628. p->irq_build = schizo_irq_build;
  1629. p->base_address_update = schizo_base_address_update;
  1630. p->resource_adjust = schizo_resource_adjust;
  1631. p->pci_ops = &schizo_ops;
  1632. /* Three OBP regs:
  1633.  * 1) PBM controller regs
  1634.  * 2) Schizo front-end controller regs (same for both PBMs)
  1635.  * 3) PBM PCI config space
  1636.  */
  1637. err = prom_getproperty(node, "reg",
  1638.        (char *)&pr_regs[0],
  1639.        sizeof(pr_regs));
  1640. if (err == 0 || err == -1) {
  1641. prom_printf("SCHIZO: Fatal error, no reg property.n");
  1642. prom_halt();
  1643. }
  1644. p->controller_regs = pr_regs[1].phys_addr - 0x10000UL;
  1645. printk("PCI: Found SCHIZO, control regs at %016lxn",
  1646.        p->controller_regs);
  1647. /* Like PSYCHO we have a 2GB aligned area for memory space. */
  1648. pci_memspace_mask = 0x7fffffffUL;
  1649. /* Init core controller. */
  1650. schizo_controller_hwinit(p);
  1651. is_pbm_a = ((pr_regs[0].phys_addr & 0x00700000) == 0x00600000);
  1652. schizo_pbm_init(p, node, is_pbm_a);
  1653. }