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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $Id: pci_psycho.c,v 1.30.2.3 2002/03/03 10:31:56 davem Exp $
  2.  * pci_psycho.c: PSYCHO/U2P specific PCI controller support.
  3.  *
  4.  * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@caipfs.rutgers.edu)
  5.  * Copyright (C) 1998, 1999 Eddie C. Dost   (ecd@skynet.be)
  6.  * Copyright (C) 1999 Jakub Jelinek   (jakub@redhat.com)
  7.  */
  8. #include <linux/kernel.h>
  9. #include <linux/types.h>
  10. #include <linux/pci.h>
  11. #include <linux/init.h>
  12. #include <linux/slab.h>
  13. #include <asm/pbm.h>
  14. #include <asm/iommu.h>
  15. #include <asm/irq.h>
  16. #include <asm/starfire.h>
  17. #include "pci_impl.h"
  18. #include "iommu_common.h"
  19. /* All PSYCHO registers are 64-bits.  The following accessor
  20.  * routines are how they are accessed.  The REG parameter
  21.  * is a physical address.
  22.  */
  23. #define psycho_read(__reg) 
  24. ({ u64 __ret; 
  25. __asm__ __volatile__("ldxa [%1] %2, %0" 
  26.      : "=r" (__ret) 
  27.      : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) 
  28.      : "memory"); 
  29. __ret; 
  30. })
  31. #define psycho_write(__reg, __val) 
  32. __asm__ __volatile__("stxa %0, [%1] %2" 
  33.      : /* no outputs */ 
  34.      : "r" (__val), "r" (__reg), 
  35.        "i" (ASI_PHYS_BYPASS_EC_E) 
  36.      : "memory")
  37. /* Misc. PSYCHO PCI controller register offsets and definitions. */
  38. #define PSYCHO_CONTROL 0x0010UL
  39. #define  PSYCHO_CONTROL_IMPL  0xf000000000000000 /* Implementation of this PSYCHO*/
  40. #define  PSYCHO_CONTROL_VER  0x0f00000000000000 /* Version of this PSYCHO       */
  41. #define  PSYCHO_CONTROL_MID  0x00f8000000000000 /* UPA Module ID of PSYCHO      */
  42. #define  PSYCHO_CONTROL_IGN  0x0007c00000000000 /* Interrupt Group Number       */
  43. #define  PSYCHO_CONTROL_RESV     0x00003ffffffffff0 /* Reserved                     */
  44. #define  PSYCHO_CONTROL_APCKEN  0x0000000000000008 /* Address Parity Check Enable  */
  45. #define  PSYCHO_CONTROL_APERR  0x0000000000000004 /* Incoming System Addr Parerr  */
  46. #define  PSYCHO_CONTROL_IAP  0x0000000000000002 /* Invert UPA Parity            */
  47. #define  PSYCHO_CONTROL_MODE  0x0000000000000001 /* PSYCHO clock mode            */
  48. #define PSYCHO_PCIA_CTRL 0x2000UL
  49. #define PSYCHO_PCIB_CTRL 0x4000UL
  50. #define  PSYCHO_PCICTRL_RESV1  0xfffffff000000000 /* Reserved                     */
  51. #define  PSYCHO_PCICTRL_SBH_ERR  0x0000000800000000 /* Streaming byte hole error    */
  52. #define  PSYCHO_PCICTRL_SERR  0x0000000400000000 /* SERR signal asserted         */
  53. #define  PSYCHO_PCICTRL_SPEED  0x0000000200000000 /* PCI speed (1 is U2P clock)   */
  54. #define  PSYCHO_PCICTRL_RESV2  0x00000001ffc00000 /* Reserved                     */
  55. #define  PSYCHO_PCICTRL_ARB_PARK 0x0000000000200000 /* PCI arbitration parking      */
  56. #define  PSYCHO_PCICTRL_RESV3  0x00000000001ff800 /* Reserved                     */
  57. #define  PSYCHO_PCICTRL_SBH_INT  0x0000000000000400 /* Streaming byte hole int enab */
  58. #define  PSYCHO_PCICTRL_WEN  0x0000000000000200 /* Power Mgmt Wake Enable       */
  59. #define  PSYCHO_PCICTRL_EEN  0x0000000000000100 /* PCI Error Interrupt Enable   */
  60. #define  PSYCHO_PCICTRL_RESV4  0x00000000000000c0 /* Reserved                     */
  61. #define  PSYCHO_PCICTRL_AEN  0x000000000000003f /* PCI DVMA Arbitration Enable  */
  62. /* U2P Programmer's Manual, page 13-55, configuration space
  63.  * address format:
  64.  * 
  65.  *  32             24 23 16 15    11 10       8 7   2  1 0
  66.  * ---------------------------------------------------------
  67.  * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 |
  68.  * ---------------------------------------------------------
  69.  */
  70. #define PSYCHO_CONFIG_BASE(PBM)
  71. ((PBM)->config_space | (1UL << 24))
  72. #define PSYCHO_CONFIG_ENCODE(BUS, DEVFN, REG)
  73. (((unsigned long)(BUS)   << 16) |
  74.  ((unsigned long)(DEVFN) << 8)  |
  75.  ((unsigned long)(REG)))
  76. static void *psycho_pci_config_mkaddr(struct pci_pbm_info *pbm,
  77.       unsigned char bus,
  78.       unsigned int devfn,
  79.       int where)
  80. {
  81. if (!pbm)
  82. return NULL;
  83. return (void *)
  84. (PSYCHO_CONFIG_BASE(pbm) |
  85.  PSYCHO_CONFIG_ENCODE(bus, devfn, where));
  86. }
  87. static int psycho_out_of_range(struct pci_pbm_info *pbm,
  88.        unsigned char bus,
  89.        unsigned char devfn)
  90. {
  91. return ((pbm->parent == 0) ||
  92. ((pbm == &pbm->parent->pbm_B) &&
  93.  (bus == pbm->pci_first_busno) &&
  94.  PCI_SLOT(devfn) > 8) ||
  95. ((pbm == &pbm->parent->pbm_A) &&
  96.  (bus == pbm->pci_first_busno) &&
  97.  PCI_SLOT(devfn) > 8));
  98. }
  99. /* PSYCHO PCI configuration space accessors. */
  100. static int psycho_read_byte(struct pci_dev *dev, int where, u8 *value)
  101. {
  102. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  103. unsigned char bus = dev->bus->number;
  104. unsigned int devfn = dev->devfn;
  105. u8 *addr;
  106. *value = 0xff;
  107. addr = psycho_pci_config_mkaddr(pbm, bus, devfn, where);
  108. if (!addr)
  109. return PCIBIOS_SUCCESSFUL;
  110. if (psycho_out_of_range(pbm, bus, devfn))
  111. return PCIBIOS_SUCCESSFUL;
  112. pci_config_read8(addr, value);
  113. return PCIBIOS_SUCCESSFUL;
  114. }
  115. static int psycho_read_word(struct pci_dev *dev, int where, u16 *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. u16 *addr;
  121. *value = 0xffff;
  122. addr = psycho_pci_config_mkaddr(pbm, bus, devfn, where);
  123. if (!addr)
  124. return PCIBIOS_SUCCESSFUL;
  125. if (psycho_out_of_range(pbm, bus, devfn))
  126. return PCIBIOS_SUCCESSFUL;
  127. if (where & 0x01) {
  128. printk("pcibios_read_config_word: misaligned reg [%x]n",
  129.        where);
  130. return PCIBIOS_SUCCESSFUL;
  131. }
  132. pci_config_read16(addr, value);
  133. return PCIBIOS_SUCCESSFUL;
  134. }
  135. static int psycho_read_dword(struct pci_dev *dev, int where, u32 *value)
  136. {
  137. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  138. unsigned char bus = dev->bus->number;
  139. unsigned int devfn = dev->devfn;
  140. u32 *addr;
  141. *value = 0xffffffff;
  142. addr = psycho_pci_config_mkaddr(pbm, bus, devfn, where);
  143. if (!addr)
  144. return PCIBIOS_SUCCESSFUL;
  145. if (psycho_out_of_range(pbm, bus, devfn))
  146. return PCIBIOS_SUCCESSFUL;
  147. if (where & 0x03) {
  148. printk("pcibios_read_config_dword: misaligned reg [%x]n",
  149.        where);
  150. return PCIBIOS_SUCCESSFUL;
  151. }
  152. pci_config_read32(addr, value);
  153. return PCIBIOS_SUCCESSFUL;
  154. }
  155. static int psycho_write_byte(struct pci_dev *dev, int where, u8 value)
  156. {
  157. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  158. unsigned char bus = dev->bus->number;
  159. unsigned int devfn = dev->devfn;
  160. u8 *addr;
  161. addr = psycho_pci_config_mkaddr(pbm, bus, devfn, where);
  162. if (!addr)
  163. return PCIBIOS_SUCCESSFUL;
  164. if (psycho_out_of_range(pbm, bus, devfn))
  165. return PCIBIOS_SUCCESSFUL;
  166. pci_config_write8(addr, value);
  167. return PCIBIOS_SUCCESSFUL;
  168. }
  169. static int psycho_write_word(struct pci_dev *dev, int where, u16 value)
  170. {
  171. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  172. unsigned char bus = dev->bus->number;
  173. unsigned int devfn = dev->devfn;
  174. u16 *addr;
  175. addr = psycho_pci_config_mkaddr(pbm, bus, devfn, where);
  176. if (!addr)
  177. return PCIBIOS_SUCCESSFUL;
  178. if (psycho_out_of_range(pbm, bus, devfn))
  179. return PCIBIOS_SUCCESSFUL;
  180. if (where & 0x01) {
  181. printk("pcibios_write_config_word: misaligned reg [%x]n",
  182.        where);
  183. return PCIBIOS_SUCCESSFUL;
  184. }
  185. pci_config_write16(addr, value);
  186. return PCIBIOS_SUCCESSFUL;
  187. }
  188. static int psycho_write_dword(struct pci_dev *dev, int where, u32 value)
  189. {
  190. struct pci_pbm_info *pbm = pci_bus2pbm[dev->bus->number];
  191. unsigned char bus = dev->bus->number;
  192. unsigned int devfn = dev->devfn;
  193. u32 *addr;
  194. addr = psycho_pci_config_mkaddr(pbm, bus, devfn, where);
  195. if (!addr)
  196. return PCIBIOS_SUCCESSFUL;
  197. if (psycho_out_of_range(pbm, bus, devfn))
  198. return PCIBIOS_SUCCESSFUL;
  199. if (where & 0x03) {
  200. printk("pcibios_write_config_dword: misaligned reg [%x]n",
  201.        where);
  202. return PCIBIOS_SUCCESSFUL;
  203. }
  204. pci_config_write32(addr, value);
  205. return PCIBIOS_SUCCESSFUL;
  206. }
  207. static struct pci_ops psycho_ops = {
  208. psycho_read_byte,
  209. psycho_read_word,
  210. psycho_read_dword,
  211. psycho_write_byte,
  212. psycho_write_word,
  213. psycho_write_dword
  214. };
  215. /* PSYCHO interrupt mapping support. */
  216. #define PSYCHO_IMAP_A_SLOT0 0x0c00UL
  217. #define PSYCHO_IMAP_B_SLOT0 0x0c20UL
  218. static unsigned long psycho_pcislot_imap_offset(unsigned long ino)
  219. {
  220. unsigned int bus =  (ino & 0x10) >> 4;
  221. unsigned int slot = (ino & 0x0c) >> 2;
  222. if (bus == 0)
  223. return PSYCHO_IMAP_A_SLOT0 + (slot * 8);
  224. else
  225. return PSYCHO_IMAP_B_SLOT0 + (slot * 8);
  226. }
  227. #define PSYCHO_IMAP_SCSI 0x1000UL
  228. #define PSYCHO_IMAP_ETH 0x1008UL
  229. #define PSYCHO_IMAP_BPP 0x1010UL
  230. #define PSYCHO_IMAP_AU_REC 0x1018UL
  231. #define PSYCHO_IMAP_AU_PLAY 0x1020UL
  232. #define PSYCHO_IMAP_PFAIL 0x1028UL
  233. #define PSYCHO_IMAP_KMS 0x1030UL
  234. #define PSYCHO_IMAP_FLPY 0x1038UL
  235. #define PSYCHO_IMAP_SHW 0x1040UL
  236. #define PSYCHO_IMAP_KBD 0x1048UL
  237. #define PSYCHO_IMAP_MS 0x1050UL
  238. #define PSYCHO_IMAP_SER 0x1058UL
  239. #define PSYCHO_IMAP_TIM0 0x1060UL
  240. #define PSYCHO_IMAP_TIM1 0x1068UL
  241. #define PSYCHO_IMAP_UE 0x1070UL
  242. #define PSYCHO_IMAP_CE 0x1078UL
  243. #define PSYCHO_IMAP_A_ERR 0x1080UL
  244. #define PSYCHO_IMAP_B_ERR 0x1088UL
  245. #define PSYCHO_IMAP_PMGMT 0x1090UL
  246. #define PSYCHO_IMAP_GFX 0x1098UL
  247. #define PSYCHO_IMAP_EUPA 0x10a0UL
  248. static unsigned long __onboard_imap_off[] = {
  249. /*0x20*/ PSYCHO_IMAP_SCSI,
  250. /*0x21*/ PSYCHO_IMAP_ETH,
  251. /*0x22*/ PSYCHO_IMAP_BPP,
  252. /*0x23*/ PSYCHO_IMAP_AU_REC,
  253. /*0x24*/ PSYCHO_IMAP_AU_PLAY,
  254. /*0x25*/ PSYCHO_IMAP_PFAIL,
  255. /*0x26*/ PSYCHO_IMAP_KMS,
  256. /*0x27*/ PSYCHO_IMAP_FLPY,
  257. /*0x28*/ PSYCHO_IMAP_SHW,
  258. /*0x29*/ PSYCHO_IMAP_KBD,
  259. /*0x2a*/ PSYCHO_IMAP_MS,
  260. /*0x2b*/ PSYCHO_IMAP_SER,
  261. /*0x2c*/ PSYCHO_IMAP_TIM0,
  262. /*0x2d*/ PSYCHO_IMAP_TIM1,
  263. /*0x2e*/ PSYCHO_IMAP_UE,
  264. /*0x2f*/ PSYCHO_IMAP_CE,
  265. /*0x30*/ PSYCHO_IMAP_A_ERR,
  266. /*0x31*/ PSYCHO_IMAP_B_ERR,
  267. /*0x32*/ PSYCHO_IMAP_PMGMT
  268. };
  269. #define PSYCHO_ONBOARD_IRQ_BASE 0x20
  270. #define PSYCHO_ONBOARD_IRQ_LAST 0x32
  271. #define psycho_onboard_imap_offset(__ino) 
  272. __onboard_imap_off[(__ino) - PSYCHO_ONBOARD_IRQ_BASE]
  273. #define PSYCHO_ICLR_A_SLOT0 0x1400UL
  274. #define PSYCHO_ICLR_SCSI 0x1800UL
  275. #define psycho_iclr_offset(ino)       
  276. ((ino & 0x20) ? (PSYCHO_ICLR_SCSI + (((ino) & 0x1f) << 3)) :  
  277. (PSYCHO_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
  278. /* PCI PSYCHO INO number to Sparc PIL level. */
  279. static unsigned char psycho_pil_table[] = {
  280. /*0x00*/0, 0, 0, 0, /* PCI A slot 0  Int A, B, C, D */
  281. /*0x04*/0, 0, 0, 0, /* PCI A slot 1  Int A, B, C, D */
  282. /*0x08*/0, 0, 0, 0, /* PCI A slot 2  Int A, B, C, D */
  283. /*0x0c*/0, 0, 0, 0, /* PCI A slot 3  Int A, B, C, D */
  284. /*0x10*/0, 0, 0, 0, /* PCI B slot 0  Int A, B, C, D */
  285. /*0x14*/0, 0, 0, 0, /* PCI B slot 1  Int A, B, C, D */
  286. /*0x18*/0, 0, 0, 0, /* PCI B slot 2  Int A, B, C, D */
  287. /*0x1c*/0, 0, 0, 0, /* PCI B slot 3  Int A, B, C, D */
  288. /*0x20*/4, /* SCSI */
  289. /*0x21*/5, /* Ethernet */
  290. /*0x22*/8, /* Parallel Port */
  291. /*0x23*/13, /* Audio Record */
  292. /*0x24*/14, /* Audio Playback */
  293. /*0x25*/15, /* PowerFail */
  294. /*0x26*/4, /* second SCSI */
  295. /*0x27*/11, /* Floppy */
  296. /*0x28*/4, /* Spare Hardware */
  297. /*0x29*/9, /* Keyboard */
  298. /*0x2a*/4, /* Mouse */
  299. /*0x2b*/12, /* Serial */
  300. /*0x2c*/10, /* Timer 0 */
  301. /*0x2d*/11, /* Timer 1 */
  302. /*0x2e*/15, /* Uncorrectable ECC */
  303. /*0x2f*/15, /* Correctable ECC */
  304. /*0x30*/15, /* PCI Bus A Error */
  305. /*0x31*/15, /* PCI Bus B Error */
  306. /*0x32*/15, /* Power Management */
  307. };
  308. static int __init psycho_ino_to_pil(struct pci_dev *pdev, unsigned int ino)
  309. {
  310. int ret;
  311. ret = psycho_pil_table[ino];
  312. if (ret == 0 && pdev == NULL) {
  313. ret = 4;
  314. } else if (ret == 0) {
  315. switch ((pdev->class >> 16) & 0xff) {
  316. case PCI_BASE_CLASS_STORAGE:
  317. ret = 4;
  318. break;
  319. case PCI_BASE_CLASS_NETWORK:
  320. ret = 6;
  321. break;
  322. case PCI_BASE_CLASS_DISPLAY:
  323. ret = 9;
  324. break;
  325. case PCI_BASE_CLASS_MULTIMEDIA:
  326. case PCI_BASE_CLASS_MEMORY:
  327. case PCI_BASE_CLASS_BRIDGE:
  328. case PCI_BASE_CLASS_SERIAL:
  329. ret = 10;
  330. break;
  331. default:
  332. ret = 4;
  333. break;
  334. };
  335. }
  336. return ret;
  337. }
  338. static unsigned int __init psycho_irq_build(struct pci_pbm_info *pbm,
  339.     struct pci_dev *pdev,
  340.     unsigned int ino)
  341. {
  342. struct pci_controller_info *p = pbm->parent;
  343. struct ino_bucket *bucket;
  344. unsigned long imap, iclr;
  345. unsigned long imap_off, iclr_off;
  346. int pil, inofixup = 0;
  347. ino &= PCI_IRQ_INO;
  348. if (ino < PSYCHO_ONBOARD_IRQ_BASE) {
  349. /* PCI slot */
  350. imap_off = psycho_pcislot_imap_offset(ino);
  351. } else {
  352. /* Onboard device */
  353. if (ino > PSYCHO_ONBOARD_IRQ_LAST) {
  354. prom_printf("psycho_irq_build: Wacky INO [%x]n", ino);
  355. prom_halt();
  356. }
  357. imap_off = psycho_onboard_imap_offset(ino);
  358. }
  359. /* Now build the IRQ bucket. */
  360. pil = psycho_ino_to_pil(pdev, ino);
  361. if (PIL_RESERVED(pil))
  362. BUG();
  363. imap = p->controller_regs + imap_off;
  364. imap += 4;
  365. iclr_off = psycho_iclr_offset(ino);
  366. iclr = p->controller_regs + iclr_off;
  367. iclr += 4;
  368. if ((ino & 0x20) == 0)
  369. inofixup = ino & 0x03;
  370. bucket = __bucket(build_irq(pil, inofixup, iclr, imap));
  371. bucket->flags |= IBF_PCI;
  372. return __irq(bucket);
  373. }
  374. /* PSYCHO error handling support. */
  375. enum psycho_error_type {
  376. UE_ERR, CE_ERR, PCI_ERR
  377. };
  378. /* Helper function of IOMMU error checking, which checks out
  379.  * the state of the streaming buffers.  The IOMMU lock is
  380.  * held when this is called.
  381.  *
  382.  * For the PCI error case we know which PBM (and thus which
  383.  * streaming buffer) caused the error, but for the uncorrectable
  384.  * error case we do not.  So we always check both streaming caches.
  385.  */
  386. #define PSYCHO_STRBUF_CONTROL_A 0x2800UL
  387. #define PSYCHO_STRBUF_CONTROL_B 0x4800UL
  388. #define  PSYCHO_STRBUF_CTRL_LPTR    0x00000000000000f0 /* LRU Lock Pointer */
  389. #define  PSYCHO_STRBUF_CTRL_LENAB   0x0000000000000008 /* LRU Lock Enable */
  390. #define  PSYCHO_STRBUF_CTRL_RRDIS   0x0000000000000004 /* Rerun Disable */
  391. #define  PSYCHO_STRBUF_CTRL_DENAB   0x0000000000000002 /* Diagnostic Mode Enable */
  392. #define  PSYCHO_STRBUF_CTRL_ENAB    0x0000000000000001 /* Streaming Buffer Enable */
  393. #define PSYCHO_STRBUF_FLUSH_A   0x2808UL
  394. #define PSYCHO_STRBUF_FLUSH_B   0x4808UL
  395. #define PSYCHO_STRBUF_FSYNC_A   0x2810UL
  396. #define PSYCHO_STRBUF_FSYNC_B   0x4810UL
  397. #define PSYCHO_STC_DATA_A 0xb000UL
  398. #define PSYCHO_STC_DATA_B 0xc000UL
  399. #define PSYCHO_STC_ERR_A 0xb400UL
  400. #define PSYCHO_STC_ERR_B 0xc400UL
  401. #define  PSYCHO_STCERR_WRITE  0x0000000000000002 /* Write Error */
  402. #define  PSYCHO_STCERR_READ  0x0000000000000001 /* Read Error */
  403. #define PSYCHO_STC_TAG_A 0xb800UL
  404. #define PSYCHO_STC_TAG_B 0xc800UL
  405. #define  PSYCHO_STCTAG_PPN  0x0fffffff00000000 /* Physical Page Number */
  406. #define  PSYCHO_STCTAG_VPN  0x00000000ffffe000 /* Virtual Page Number */
  407. #define  PSYCHO_STCTAG_VALID  0x0000000000000002 /* Valid */
  408. #define  PSYCHO_STCTAG_WRITE  0x0000000000000001 /* Writable */
  409. #define PSYCHO_STC_LINE_A 0xb900UL
  410. #define PSYCHO_STC_LINE_B 0xc900UL
  411. #define  PSYCHO_STCLINE_LINDX  0x0000000001e00000 /* LRU Index */
  412. #define  PSYCHO_STCLINE_SPTR  0x00000000001f8000 /* Dirty Data Start Pointer */
  413. #define  PSYCHO_STCLINE_LADDR  0x0000000000007f00 /* Line Address */
  414. #define  PSYCHO_STCLINE_EPTR  0x00000000000000fc /* Dirty Data End Pointer */
  415. #define  PSYCHO_STCLINE_VALID  0x0000000000000002 /* Valid */
  416. #define  PSYCHO_STCLINE_FOFN  0x0000000000000001 /* Fetch Outstanding / Flush Necessary */
  417. static spinlock_t stc_buf_lock = SPIN_LOCK_UNLOCKED;
  418. static unsigned long stc_error_buf[128];
  419. static unsigned long stc_tag_buf[16];
  420. static unsigned long stc_line_buf[16];
  421. static void __psycho_check_one_stc(struct pci_controller_info *p,
  422.    struct pci_pbm_info *pbm,
  423.    int is_pbm_a)
  424. {
  425. struct pci_strbuf *strbuf = &pbm->stc;
  426. unsigned long regbase = p->controller_regs;
  427. unsigned long err_base, tag_base, line_base;
  428. u64 control;
  429. int i;
  430. if (is_pbm_a) {
  431. err_base = regbase + PSYCHO_STC_ERR_A;
  432. tag_base = regbase + PSYCHO_STC_TAG_A;
  433. line_base = regbase + PSYCHO_STC_LINE_A;
  434. } else {
  435. err_base = regbase + PSYCHO_STC_ERR_A;
  436. tag_base = regbase + PSYCHO_STC_TAG_A;
  437. line_base = regbase + PSYCHO_STC_LINE_A;
  438. }
  439. spin_lock(&stc_buf_lock);
  440. /* This is __REALLY__ dangerous.  When we put the
  441.  * streaming buffer into diagnostic mode to probe
  442.  * it's tags and error status, we _must_ clear all
  443.  * of the line tag valid bits before re-enabling
  444.  * the streaming buffer.  If any dirty data lives
  445.  * in the STC when we do this, we will end up
  446.  * invalidating it before it has a chance to reach
  447.  * main memory.
  448.  */
  449. control = psycho_read(strbuf->strbuf_control);
  450. psycho_write(strbuf->strbuf_control,
  451.      (control | PSYCHO_STRBUF_CTRL_DENAB));
  452. for (i = 0; i < 128; i++) {
  453. unsigned long val;
  454. val = psycho_read(err_base + (i * 8UL));
  455. psycho_write(err_base + (i * 8UL), 0UL);
  456. stc_error_buf[i] = val;
  457. }
  458. for (i = 0; i < 16; i++) {
  459. stc_tag_buf[i] = psycho_read(tag_base + (i * 8UL));
  460. stc_line_buf[i] = psycho_read(line_base + (i * 8UL));
  461. psycho_write(tag_base + (i * 8UL), 0UL);
  462. psycho_write(line_base + (i * 8UL), 0UL);
  463. }
  464. /* OK, state is logged, exit diagnostic mode. */
  465. psycho_write(strbuf->strbuf_control, control);
  466. for (i = 0; i < 16; i++) {
  467. int j, saw_error, first, last;
  468. saw_error = 0;
  469. first = i * 8;
  470. last = first + 8;
  471. for (j = first; j < last; j++) {
  472. unsigned long errval = stc_error_buf[j];
  473. if (errval != 0) {
  474. saw_error++;
  475. printk("PSYCHO%d(PBM%c): STC_ERR(%d)[wr(%d)rd(%d)]n",
  476.        p->index,
  477.        (is_pbm_a ? 'A' : 'B'),
  478.        j,
  479.        (errval & PSYCHO_STCERR_WRITE) ? 1 : 0,
  480.        (errval & PSYCHO_STCERR_READ) ? 1 : 0);
  481. }
  482. }
  483. if (saw_error != 0) {
  484. unsigned long tagval = stc_tag_buf[i];
  485. unsigned long lineval = stc_line_buf[i];
  486. printk("PSYCHO%d(PBM%c): STC_TAG(%d)[PA(%016lx)VA(%08lx)V(%d)W(%d)]n",
  487.        p->index,
  488.        (is_pbm_a ? 'A' : 'B'),
  489.        i,
  490.        ((tagval & PSYCHO_STCTAG_PPN) >> 19UL),
  491.        (tagval & PSYCHO_STCTAG_VPN),
  492.        ((tagval & PSYCHO_STCTAG_VALID) ? 1 : 0),
  493.        ((tagval & PSYCHO_STCTAG_WRITE) ? 1 : 0));
  494. printk("PSYCHO%d(PBM%c): STC_LINE(%d)[LIDX(%lx)SP(%lx)LADDR(%lx)EP(%lx)"
  495.        "V(%d)FOFN(%d)]n",
  496.        p->index,
  497.        (is_pbm_a ? 'A' : 'B'),
  498.        i,
  499.        ((lineval & PSYCHO_STCLINE_LINDX) >> 21UL),
  500.        ((lineval & PSYCHO_STCLINE_SPTR) >> 15UL),
  501.        ((lineval & PSYCHO_STCLINE_LADDR) >> 8UL),
  502.        ((lineval & PSYCHO_STCLINE_EPTR) >> 2UL),
  503.        ((lineval & PSYCHO_STCLINE_VALID) ? 1 : 0),
  504.        ((lineval & PSYCHO_STCLINE_FOFN) ? 1 : 0));
  505. }
  506. }
  507. spin_unlock(&stc_buf_lock);
  508. }
  509. static void __psycho_check_stc_error(struct pci_controller_info *p,
  510.      unsigned long afsr,
  511.      unsigned long afar,
  512.      enum psycho_error_type type)
  513. {
  514. struct pci_pbm_info *pbm;
  515. pbm = &p->pbm_A;
  516. if (pbm->stc.strbuf_enabled)
  517. __psycho_check_one_stc(p, pbm, 1);
  518. pbm = &p->pbm_B;
  519. if (pbm->stc.strbuf_enabled)
  520. __psycho_check_one_stc(p, pbm, 0);
  521. }
  522. /* When an Uncorrectable Error or a PCI Error happens, we
  523.  * interrogate the IOMMU state to see if it is the cause.
  524.  */
  525. #define PSYCHO_IOMMU_CONTROL 0x0200UL
  526. #define  PSYCHO_IOMMU_CTRL_RESV     0xfffffffff9000000 /* Reserved                      */
  527. #define  PSYCHO_IOMMU_CTRL_XLTESTAT 0x0000000006000000 /* Translation Error Status      */
  528. #define  PSYCHO_IOMMU_CTRL_XLTEERR  0x0000000001000000 /* Translation Error encountered */
  529. #define  PSYCHO_IOMMU_CTRL_LCKEN    0x0000000000800000 /* Enable translation locking    */
  530. #define  PSYCHO_IOMMU_CTRL_LCKPTR   0x0000000000780000 /* Translation lock pointer      */
  531. #define  PSYCHO_IOMMU_CTRL_TSBSZ    0x0000000000070000 /* TSB Size                      */
  532. #define  PSYCHO_IOMMU_TSBSZ_1K      0x0000000000000000 /* TSB Table 1024 8-byte entries */
  533. #define  PSYCHO_IOMMU_TSBSZ_2K      0x0000000000010000 /* TSB Table 2048 8-byte entries */
  534. #define  PSYCHO_IOMMU_TSBSZ_4K      0x0000000000020000 /* TSB Table 4096 8-byte entries */
  535. #define  PSYCHO_IOMMU_TSBSZ_8K      0x0000000000030000 /* TSB Table 8192 8-byte entries */
  536. #define  PSYCHO_IOMMU_TSBSZ_16K     0x0000000000040000 /* TSB Table 16k 8-byte entries  */
  537. #define  PSYCHO_IOMMU_TSBSZ_32K     0x0000000000050000 /* TSB Table 32k 8-byte entries  */
  538. #define  PSYCHO_IOMMU_TSBSZ_64K     0x0000000000060000 /* TSB Table 64k 8-byte entries  */
  539. #define  PSYCHO_IOMMU_TSBSZ_128K    0x0000000000070000 /* TSB Table 128k 8-byte entries */
  540. #define  PSYCHO_IOMMU_CTRL_RESV2    0x000000000000fff8 /* Reserved                      */
  541. #define  PSYCHO_IOMMU_CTRL_TBWSZ    0x0000000000000004 /* Assumed page size, 0=8k 1=64k */
  542. #define  PSYCHO_IOMMU_CTRL_DENAB    0x0000000000000002 /* Diagnostic mode enable        */
  543. #define  PSYCHO_IOMMU_CTRL_ENAB     0x0000000000000001 /* IOMMU Enable                  */
  544. #define PSYCHO_IOMMU_TSBBASE 0x0208UL
  545. #define PSYCHO_IOMMU_FLUSH 0x0210UL
  546. #define PSYCHO_IOMMU_TAG 0xa580UL
  547. #define  PSYCHO_IOMMU_TAG_ERRSTS (0x3UL << 23UL)
  548. #define  PSYCHO_IOMMU_TAG_ERR  (0x1UL << 22UL)
  549. #define  PSYCHO_IOMMU_TAG_WRITE  (0x1UL << 21UL)
  550. #define  PSYCHO_IOMMU_TAG_STREAM (0x1UL << 20UL)
  551. #define  PSYCHO_IOMMU_TAG_SIZE  (0x1UL << 19UL)
  552. #define  PSYCHO_IOMMU_TAG_VPAGE  0x7ffffUL
  553. #define PSYCHO_IOMMU_DATA 0xa600UL
  554. #define  PSYCHO_IOMMU_DATA_VALID (1UL << 30UL)
  555. #define  PSYCHO_IOMMU_DATA_CACHE (1UL << 28UL)
  556. #define  PSYCHO_IOMMU_DATA_PPAGE 0xfffffffUL
  557. static void psycho_check_iommu_error(struct pci_controller_info *p,
  558.      unsigned long afsr,
  559.      unsigned long afar,
  560.      enum psycho_error_type type)
  561. {
  562. struct pci_iommu *iommu = p->pbm_A.iommu;
  563. unsigned long iommu_tag[16];
  564. unsigned long iommu_data[16];
  565. unsigned long flags;
  566. u64 control;
  567. int i;
  568. spin_lock_irqsave(&iommu->lock, flags);
  569. control = psycho_read(iommu->iommu_control);
  570. if (control & PSYCHO_IOMMU_CTRL_XLTEERR) {
  571. char *type_string;
  572. /* Clear the error encountered bit. */
  573. control &= ~PSYCHO_IOMMU_CTRL_XLTEERR;
  574. psycho_write(iommu->iommu_control, control);
  575. switch((control & PSYCHO_IOMMU_CTRL_XLTESTAT) >> 25UL) {
  576. case 0:
  577. type_string = "Protection Error";
  578. break;
  579. case 1:
  580. type_string = "Invalid Error";
  581. break;
  582. case 2:
  583. type_string = "TimeOut Error";
  584. break;
  585. case 3:
  586. default:
  587. type_string = "ECC Error";
  588. break;
  589. };
  590. printk("PSYCHO%d: IOMMU Error, type[%s]n",
  591.        p->index, type_string);
  592. /* Put the IOMMU into diagnostic mode and probe
  593.  * it's TLB for entries with error status.
  594.  *
  595.  * It is very possible for another DVMA to occur
  596.  * while we do this probe, and corrupt the system
  597.  * further.  But we are so screwed at this point
  598.  * that we are likely to crash hard anyways, so
  599.  * get as much diagnostic information to the
  600.  * console as we can.
  601.  */
  602. psycho_write(iommu->iommu_control,
  603.      control | PSYCHO_IOMMU_CTRL_DENAB);
  604. for (i = 0; i < 16; i++) {
  605. unsigned long base = p->controller_regs;
  606. iommu_tag[i] =
  607. psycho_read(base + PSYCHO_IOMMU_TAG + (i * 8UL));
  608. iommu_data[i] =
  609. psycho_read(base + PSYCHO_IOMMU_DATA + (i * 8UL));
  610. /* Now clear out the entry. */
  611. psycho_write(base + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  612. psycho_write(base + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  613. }
  614. /* Leave diagnostic mode. */
  615. psycho_write(iommu->iommu_control, control);
  616. for (i = 0; i < 16; i++) {
  617. unsigned long tag, data;
  618. tag = iommu_tag[i];
  619. if (!(tag & PSYCHO_IOMMU_TAG_ERR))
  620. continue;
  621. data = iommu_data[i];
  622. switch((tag & PSYCHO_IOMMU_TAG_ERRSTS) >> 23UL) {
  623. case 0:
  624. type_string = "Protection Error";
  625. break;
  626. case 1:
  627. type_string = "Invalid Error";
  628. break;
  629. case 2:
  630. type_string = "TimeOut Error";
  631. break;
  632. case 3:
  633. default:
  634. type_string = "ECC Error";
  635. break;
  636. };
  637. printk("PSYCHO%d: IOMMU TAG(%d)[error(%s) wr(%d) str(%d) sz(%dK) vpg(%08lx)]n",
  638.        p->index, i, type_string,
  639.        ((tag & PSYCHO_IOMMU_TAG_WRITE) ? 1 : 0),
  640.        ((tag & PSYCHO_IOMMU_TAG_STREAM) ? 1 : 0),
  641.        ((tag & PSYCHO_IOMMU_TAG_SIZE) ? 64 : 8),
  642.        (tag & PSYCHO_IOMMU_TAG_VPAGE) << IOMMU_PAGE_SHIFT);
  643. printk("PSYCHO%d: IOMMU DATA(%d)[valid(%d) cache(%d) ppg(%016lx)]n",
  644.        p->index, i,
  645.        ((data & PSYCHO_IOMMU_DATA_VALID) ? 1 : 0),
  646.        ((data & PSYCHO_IOMMU_DATA_CACHE) ? 1 : 0),
  647.        (data & PSYCHO_IOMMU_DATA_PPAGE) << IOMMU_PAGE_SHIFT);
  648. }
  649. }
  650. __psycho_check_stc_error(p, afsr, afar, type);
  651. spin_unlock_irqrestore(&iommu->lock, flags);
  652. }
  653. /* Uncorrectable Errors.  Cause of the error and the address are
  654.  * recorded in the UE_AFSR and UE_AFAR of PSYCHO.  They are errors
  655.  * relating to UPA interface transactions.
  656.  */
  657. #define PSYCHO_UE_AFSR 0x0030UL
  658. #define  PSYCHO_UEAFSR_PPIO 0x8000000000000000 /* Primary PIO is cause         */
  659. #define  PSYCHO_UEAFSR_PDRD 0x4000000000000000 /* Primary DVMA read is cause   */
  660. #define  PSYCHO_UEAFSR_PDWR 0x2000000000000000 /* Primary DVMA write is cause  */
  661. #define  PSYCHO_UEAFSR_SPIO 0x1000000000000000 /* Secondary PIO is cause       */
  662. #define  PSYCHO_UEAFSR_SDRD 0x0800000000000000 /* Secondary DVMA read is cause */
  663. #define  PSYCHO_UEAFSR_SDWR 0x0400000000000000 /* Secondary DVMA write is cause*/
  664. #define  PSYCHO_UEAFSR_RESV1 0x03ff000000000000 /* Reserved                     */
  665. #define  PSYCHO_UEAFSR_BMSK 0x0000ffff00000000 /* Bytemask of failed transfer  */
  666. #define  PSYCHO_UEAFSR_DOFF 0x00000000e0000000 /* Doubleword Offset            */
  667. #define  PSYCHO_UEAFSR_MID 0x000000001f000000 /* UPA MID causing the fault    */
  668. #define  PSYCHO_UEAFSR_BLK 0x0000000000800000 /* Trans was block operation    */
  669. #define  PSYCHO_UEAFSR_RESV2 0x00000000007fffff /* Reserved                     */
  670. #define PSYCHO_UE_AFAR 0x0038UL
  671. static void psycho_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
  672. {
  673. struct pci_controller_info *p = dev_id;
  674. unsigned long afsr_reg = p->controller_regs + PSYCHO_UE_AFSR;
  675. unsigned long afar_reg = p->controller_regs + PSYCHO_UE_AFAR;
  676. unsigned long afsr, afar, error_bits;
  677. int reported;
  678. /* Latch uncorrectable error status. */
  679. afar = psycho_read(afar_reg);
  680. afsr = psycho_read(afsr_reg);
  681. /* Clear the primary/secondary error status bits. */
  682. error_bits = afsr &
  683. (PSYCHO_UEAFSR_PPIO | PSYCHO_UEAFSR_PDRD | PSYCHO_UEAFSR_PDWR |
  684.  PSYCHO_UEAFSR_SPIO | PSYCHO_UEAFSR_SDRD | PSYCHO_UEAFSR_SDWR);
  685. if (!error_bits)
  686. return;
  687. psycho_write(afsr_reg, error_bits);
  688. /* Log the error. */
  689. printk("PSYCHO%d: Uncorrectable Error, primary error type[%s]n",
  690.        p->index,
  691.        (((error_bits & PSYCHO_UEAFSR_PPIO) ?
  692.  "PIO" :
  693.  ((error_bits & PSYCHO_UEAFSR_PDRD) ?
  694.   "DMA Read" :
  695.   ((error_bits & PSYCHO_UEAFSR_PDWR) ?
  696.    "DMA Write" : "???")))));
  697. printk("PSYCHO%d: bytemask[%04lx] dword_offset[%lx] UPA_MID[%02lx] was_block(%d)n",
  698.        p->index,
  699.        (afsr & PSYCHO_UEAFSR_BMSK) >> 32UL,
  700.        (afsr & PSYCHO_UEAFSR_DOFF) >> 29UL,
  701.        (afsr & PSYCHO_UEAFSR_MID) >> 24UL,
  702.        ((afsr & PSYCHO_UEAFSR_BLK) ? 1 : 0));
  703. printk("PSYCHO%d: UE AFAR [%016lx]n", p->index, afar);
  704. printk("PSYCHO%d: UE Secondary errors [", p->index);
  705. reported = 0;
  706. if (afsr & PSYCHO_UEAFSR_SPIO) {
  707. reported++;
  708. printk("(PIO)");
  709. }
  710. if (afsr & PSYCHO_UEAFSR_SDRD) {
  711. reported++;
  712. printk("(DMA Read)");
  713. }
  714. if (afsr & PSYCHO_UEAFSR_SDWR) {
  715. reported++;
  716. printk("(DMA Write)");
  717. }
  718. if (!reported)
  719. printk("(none)");
  720. printk("]n");
  721. /* Interrogate IOMMU for error status. */
  722. psycho_check_iommu_error(p, afsr, afar, UE_ERR);
  723. }
  724. /* Correctable Errors. */
  725. #define PSYCHO_CE_AFSR 0x0040UL
  726. #define  PSYCHO_CEAFSR_PPIO 0x8000000000000000 /* Primary PIO is cause         */
  727. #define  PSYCHO_CEAFSR_PDRD 0x4000000000000000 /* Primary DVMA read is cause   */
  728. #define  PSYCHO_CEAFSR_PDWR 0x2000000000000000 /* Primary DVMA write is cause  */
  729. #define  PSYCHO_CEAFSR_SPIO 0x1000000000000000 /* Secondary PIO is cause       */
  730. #define  PSYCHO_CEAFSR_SDRD 0x0800000000000000 /* Secondary DVMA read is cause */
  731. #define  PSYCHO_CEAFSR_SDWR 0x0400000000000000 /* Secondary DVMA write is cause*/
  732. #define  PSYCHO_CEAFSR_RESV1 0x0300000000000000 /* Reserved                     */
  733. #define  PSYCHO_CEAFSR_ESYND 0x00ff000000000000 /* Syndrome Bits                */
  734. #define  PSYCHO_CEAFSR_BMSK 0x0000ffff00000000 /* Bytemask of failed transfer  */
  735. #define  PSYCHO_CEAFSR_DOFF 0x00000000e0000000 /* Double Offset                */
  736. #define  PSYCHO_CEAFSR_MID 0x000000001f000000 /* UPA MID causing the fault    */
  737. #define  PSYCHO_CEAFSR_BLK 0x0000000000800000 /* Trans was block operation    */
  738. #define  PSYCHO_CEAFSR_RESV2 0x00000000007fffff /* Reserved                     */
  739. #define PSYCHO_CE_AFAR 0x0040UL
  740. static void psycho_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
  741. {
  742. struct pci_controller_info *p = dev_id;
  743. unsigned long afsr_reg = p->controller_regs + PSYCHO_CE_AFSR;
  744. unsigned long afar_reg = p->controller_regs + PSYCHO_CE_AFAR;
  745. unsigned long afsr, afar, error_bits;
  746. int reported;
  747. /* Latch error status. */
  748. afar = psycho_read(afar_reg);
  749. afsr = psycho_read(afsr_reg);
  750. /* Clear primary/secondary error status bits. */
  751. error_bits = afsr &
  752. (PSYCHO_CEAFSR_PPIO | PSYCHO_CEAFSR_PDRD | PSYCHO_CEAFSR_PDWR |
  753.  PSYCHO_CEAFSR_SPIO | PSYCHO_CEAFSR_SDRD | PSYCHO_CEAFSR_SDWR);
  754. if (!error_bits)
  755. return;
  756. psycho_write(afsr_reg, error_bits);
  757. /* Log the error. */
  758. printk("PSYCHO%d: Correctable Error, primary error type[%s]n",
  759.        p->index,
  760.        (((error_bits & PSYCHO_CEAFSR_PPIO) ?
  761.  "PIO" :
  762.  ((error_bits & PSYCHO_CEAFSR_PDRD) ?
  763.   "DMA Read" :
  764.   ((error_bits & PSYCHO_CEAFSR_PDWR) ?
  765.    "DMA Write" : "???")))));
  766. /* XXX Use syndrome and afar to print out module string just like
  767.  * XXX UDB CE trap handler does... -DaveM
  768.  */
  769. printk("PSYCHO%d: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
  770.        "UPA_MID[%02lx] was_block(%d)n",
  771.        p->index,
  772.        (afsr & PSYCHO_CEAFSR_ESYND) >> 48UL,
  773.        (afsr & PSYCHO_CEAFSR_BMSK) >> 32UL,
  774.        (afsr & PSYCHO_CEAFSR_DOFF) >> 29UL,
  775.        (afsr & PSYCHO_CEAFSR_MID) >> 24UL,
  776.        ((afsr & PSYCHO_CEAFSR_BLK) ? 1 : 0));
  777. printk("PSYCHO%d: CE AFAR [%016lx]n", p->index, afar);
  778. printk("PSYCHO%d: CE Secondary errors [", p->index);
  779. reported = 0;
  780. if (afsr & PSYCHO_CEAFSR_SPIO) {
  781. reported++;
  782. printk("(PIO)");
  783. }
  784. if (afsr & PSYCHO_CEAFSR_SDRD) {
  785. reported++;
  786. printk("(DMA Read)");
  787. }
  788. if (afsr & PSYCHO_CEAFSR_SDWR) {
  789. reported++;
  790. printk("(DMA Write)");
  791. }
  792. if (!reported)
  793. printk("(none)");
  794. printk("]n");
  795. }
  796. /* PCI Errors.  They are signalled by the PCI bus module since they
  797.  * are assosciated with a specific bus segment.
  798.  */
  799. #define PSYCHO_PCI_AFSR_A 0x2010UL
  800. #define PSYCHO_PCI_AFSR_B 0x4010UL
  801. #define  PSYCHO_PCIAFSR_PMA 0x8000000000000000 /* Primary Master Abort Error   */
  802. #define  PSYCHO_PCIAFSR_PTA 0x4000000000000000 /* Primary Target Abort Error   */
  803. #define  PSYCHO_PCIAFSR_PRTRY 0x2000000000000000 /* Primary Excessive Retries    */
  804. #define  PSYCHO_PCIAFSR_PPERR 0x1000000000000000 /* Primary Parity Error         */
  805. #define  PSYCHO_PCIAFSR_SMA 0x0800000000000000 /* Secondary Master Abort Error */
  806. #define  PSYCHO_PCIAFSR_STA 0x0400000000000000 /* Secondary Target Abort Error */
  807. #define  PSYCHO_PCIAFSR_SRTRY 0x0200000000000000 /* Secondary Excessive Retries  */
  808. #define  PSYCHO_PCIAFSR_SPERR 0x0100000000000000 /* Secondary Parity Error       */
  809. #define  PSYCHO_PCIAFSR_RESV1 0x00ff000000000000 /* Reserved                     */
  810. #define  PSYCHO_PCIAFSR_BMSK 0x0000ffff00000000 /* Bytemask of failed transfer  */
  811. #define  PSYCHO_PCIAFSR_BLK 0x0000000080000000 /* Trans was block operation    */
  812. #define  PSYCHO_PCIAFSR_RESV2 0x0000000040000000 /* Reserved                     */
  813. #define  PSYCHO_PCIAFSR_MID 0x000000003e000000 /* MID causing the error        */
  814. #define  PSYCHO_PCIAFSR_RESV3 0x0000000001ffffff /* Reserved                     */
  815. #define PSYCHO_PCI_AFAR_A 0x2018UL
  816. #define PSYCHO_PCI_AFAR_B 0x4018UL
  817. static void psycho_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
  818. {
  819. struct pci_pbm_info *pbm = dev_id;
  820. struct pci_controller_info *p = pbm->parent;
  821. unsigned long afsr_reg, afar_reg;
  822. unsigned long afsr, afar, error_bits;
  823. int is_pbm_a, reported;
  824. is_pbm_a = (pbm == &pbm->parent->pbm_A);
  825. if (is_pbm_a) {
  826. afsr_reg = p->controller_regs + PSYCHO_PCI_AFSR_A;
  827. afar_reg = p->controller_regs + PSYCHO_PCI_AFAR_A;
  828. } else {
  829. afsr_reg = p->controller_regs + PSYCHO_PCI_AFSR_B;
  830. afar_reg = p->controller_regs + PSYCHO_PCI_AFAR_B;
  831. }
  832. /* Latch error status. */
  833. afar = psycho_read(afar_reg);
  834. afsr = psycho_read(afsr_reg);
  835. /* Clear primary/secondary error status bits. */
  836. error_bits = afsr &
  837. (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_PTA |
  838.  PSYCHO_PCIAFSR_PRTRY | PSYCHO_PCIAFSR_PPERR |
  839.  PSYCHO_PCIAFSR_SMA | PSYCHO_PCIAFSR_STA |
  840.  PSYCHO_PCIAFSR_SRTRY | PSYCHO_PCIAFSR_SPERR);
  841. if (!error_bits)
  842. return;
  843. psycho_write(afsr_reg, error_bits);
  844. /* Log the error. */
  845. printk("PSYCHO%d(PBM%c): PCI Error, primary error type[%s]n",
  846.        p->index, (is_pbm_a ? 'A' : 'B'),
  847.        (((error_bits & PSYCHO_PCIAFSR_PMA) ?
  848.  "Master Abort" :
  849.  ((error_bits & PSYCHO_PCIAFSR_PTA) ?
  850.   "Target Abort" :
  851.   ((error_bits & PSYCHO_PCIAFSR_PRTRY) ?
  852.    "Excessive Retries" :
  853.    ((error_bits & PSYCHO_PCIAFSR_PPERR) ?
  854.     "Parity Error" : "???"))))));
  855. printk("PSYCHO%d(PBM%c): bytemask[%04lx] UPA_MID[%02lx] was_block(%d)n",
  856.        p->index, (is_pbm_a ? 'A' : 'B'),
  857.        (afsr & PSYCHO_PCIAFSR_BMSK) >> 32UL,
  858.        (afsr & PSYCHO_PCIAFSR_MID) >> 25UL,
  859.        (afsr & PSYCHO_PCIAFSR_BLK) ? 1 : 0);
  860. printk("PSYCHO%d(PBM%c): PCI AFAR [%016lx]n",
  861.        p->index, (is_pbm_a ? 'A' : 'B'), afar);
  862. printk("PSYCHO%d(PBM%c): PCI Secondary errors [",
  863.        p->index, (is_pbm_a ? 'A' : 'B'));
  864. reported = 0;
  865. if (afsr & PSYCHO_PCIAFSR_SMA) {
  866. reported++;
  867. printk("(Master Abort)");
  868. }
  869. if (afsr & PSYCHO_PCIAFSR_STA) {
  870. reported++;
  871. printk("(Target Abort)");
  872. }
  873. if (afsr & PSYCHO_PCIAFSR_SRTRY) {
  874. reported++;
  875. printk("(Excessive Retries)");
  876. }
  877. if (afsr & PSYCHO_PCIAFSR_SPERR) {
  878. reported++;
  879. printk("(Parity Error)");
  880. }
  881. if (!reported)
  882. printk("(none)");
  883. printk("]n");
  884. /* For the error types shown, scan PBM's PCI bus for devices
  885.  * which have logged that error type.
  886.  */
  887. /* If we see a Target Abort, this could be the result of an
  888.  * IOMMU translation error of some sort.  It is extremely
  889.  * useful to log this information as usually it indicates
  890.  * a bug in the IOMMU support code or a PCI device driver.
  891.  */
  892. if (error_bits & (PSYCHO_PCIAFSR_PTA | PSYCHO_PCIAFSR_STA)) {
  893. psycho_check_iommu_error(p, afsr, afar, PCI_ERR);
  894. pci_scan_for_target_abort(p, pbm, pbm->pci_bus);
  895. }
  896. if (error_bits & (PSYCHO_PCIAFSR_PMA | PSYCHO_PCIAFSR_SMA))
  897. pci_scan_for_master_abort(p, pbm, pbm->pci_bus);
  898. /* For excessive retries, PSYCHO/PBM will abort the device
  899.  * and there is no way to specifically check for excessive
  900.  * retries in the config space status registers.  So what
  901.  * we hope is that we'll catch it via the master/target
  902.  * abort events.
  903.  */
  904. if (error_bits & (PSYCHO_PCIAFSR_PPERR | PSYCHO_PCIAFSR_SPERR))
  905. pci_scan_for_parity_error(p, pbm, pbm->pci_bus);
  906. }
  907. /* XXX What about PowerFail/PowerManagement??? -DaveM */
  908. #define PSYCHO_ECC_CTRL 0x0020
  909. #define  PSYCHO_ECCCTRL_EE  0x8000000000000000 /* Enable ECC Checking */
  910. #define  PSYCHO_ECCCTRL_UE  0x4000000000000000 /* Enable UE Interrupts */
  911. #define  PSYCHO_ECCCTRL_CE  0x2000000000000000 /* Enable CE INterrupts */
  912. #define PSYCHO_UE_INO 0x2e
  913. #define PSYCHO_CE_INO 0x2f
  914. #define PSYCHO_PCIERR_A_INO 0x30
  915. #define PSYCHO_PCIERR_B_INO 0x31
  916. static void __init psycho_register_error_handlers(struct pci_controller_info *p)
  917. {
  918. struct pci_pbm_info *pbm = &p->pbm_A; /* arbitrary */
  919. unsigned long base = p->controller_regs;
  920. unsigned int irq, portid = p->portid;
  921. u64 tmp;
  922. /* Build IRQs and register handlers. */
  923. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_UE_INO);
  924. if (request_irq(irq, psycho_ue_intr,
  925. SA_SHIRQ, "PSYCHO UE", p) < 0) {
  926. prom_printf("PSYCHO%d: Cannot register UE interrupt.n",
  927.     p->index);
  928. prom_halt();
  929. }
  930. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_CE_INO);
  931. if (request_irq(irq, psycho_ce_intr,
  932. SA_SHIRQ, "PSYCHO CE", p) < 0) {
  933. prom_printf("PSYCHO%d: Cannot register CE interrupt.n",
  934.     p->index);
  935. prom_halt();
  936. }
  937. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_PCIERR_A_INO);
  938. if (request_irq(irq, psycho_pcierr_intr,
  939. SA_SHIRQ, "PSYCHO PCIERR", &p->pbm_A) < 0) {
  940. prom_printf("PSYCHO%d(PBMA): Cannot register PciERR interrupt.n",
  941.     p->index);
  942. prom_halt();
  943. }
  944. irq = psycho_irq_build(pbm, NULL, (portid << 6) | PSYCHO_PCIERR_B_INO);
  945. if (request_irq(irq, psycho_pcierr_intr,
  946. SA_SHIRQ, "PSYCHO PCIERR", &p->pbm_B) < 0) {
  947. prom_printf("PSYCHO%d(PBMB): Cannot register PciERR interrupt.n",
  948.     p->index);
  949. prom_halt();
  950. }
  951. /* Enable UE and CE interrupts for controller. */
  952. psycho_write(base + PSYCHO_ECC_CTRL,
  953.      (PSYCHO_ECCCTRL_EE |
  954.       PSYCHO_ECCCTRL_UE |
  955.       PSYCHO_ECCCTRL_CE));
  956. /* Enable PCI Error interrupts and clear error
  957.  * bits for each PBM.
  958.  */
  959. tmp = psycho_read(base + PSYCHO_PCIA_CTRL);
  960. tmp |= (PSYCHO_PCICTRL_SBH_ERR |
  961. PSYCHO_PCICTRL_SERR |
  962. PSYCHO_PCICTRL_SBH_INT |
  963. PSYCHO_PCICTRL_EEN);
  964. psycho_write(base + PSYCHO_PCIA_CTRL, tmp);
  965.      
  966. tmp = psycho_read(base + PSYCHO_PCIB_CTRL);
  967. tmp |= (PSYCHO_PCICTRL_SBH_ERR |
  968. PSYCHO_PCICTRL_SERR |
  969. PSYCHO_PCICTRL_SBH_INT |
  970. PSYCHO_PCICTRL_EEN);
  971. psycho_write(base + PSYCHO_PCIB_CTRL, tmp);
  972. }
  973. /* PSYCHO boot time probing and initialization. */
  974. static void __init psycho_resource_adjust(struct pci_dev *pdev,
  975.   struct resource *res,
  976.   struct resource *root)
  977. {
  978. res->start += root->start;
  979. res->end += root->start;
  980. }
  981. static void __init psycho_base_address_update(struct pci_dev *pdev, int resource)
  982. {
  983. struct pcidev_cookie *pcp = pdev->sysdata;
  984. struct pci_pbm_info *pbm = pcp->pbm;
  985. struct resource *res, *root;
  986. u32 reg;
  987. int where, size, is_64bit;
  988. res = &pdev->resource[resource];
  989. if (resource < 6) {
  990. where = PCI_BASE_ADDRESS_0 + (resource * 4);
  991. } else if (resource == PCI_ROM_RESOURCE) {
  992. where = pdev->rom_base_reg;
  993. } else {
  994. /* Somebody might have asked allocation of a non-standard resource */
  995. return;
  996. }
  997. is_64bit = 0;
  998. if (res->flags & IORESOURCE_IO)
  999. root = &pbm->io_space;
  1000. else {
  1001. root = &pbm->mem_space;
  1002. if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
  1003.     == PCI_BASE_ADDRESS_MEM_TYPE_64)
  1004. is_64bit = 1;
  1005. }
  1006. size = res->end - res->start;
  1007. pci_read_config_dword(pdev, where, &reg);
  1008. reg = ((reg & size) |
  1009.        (((u32)(res->start - root->start)) & ~size));
  1010. if (resource == PCI_ROM_RESOURCE) {
  1011. reg |= PCI_ROM_ADDRESS_ENABLE;
  1012. res->flags |= PCI_ROM_ADDRESS_ENABLE;
  1013. }
  1014. pci_write_config_dword(pdev, where, reg);
  1015. /* This knows that the upper 32-bits of the address
  1016.  * must be zero.  Our PCI common layer enforces this.
  1017.  */
  1018. if (is_64bit)
  1019. pci_write_config_dword(pdev, where + 4, 0);
  1020. }
  1021. /* We have to do the config space accesses by hand, thus... */
  1022. #define PBM_BRIDGE_BUS 0x40
  1023. #define PBM_BRIDGE_SUBORDINATE 0x41
  1024. static void __init pbm_renumber(struct pci_pbm_info *pbm, u8 orig_busno)
  1025. {
  1026. u8 *addr, busno;
  1027. int nbus;
  1028. busno = pci_highest_busnum;
  1029. nbus = pbm->pci_last_busno - pbm->pci_first_busno;
  1030. addr = psycho_pci_config_mkaddr(pbm, orig_busno,
  1031. 0, PBM_BRIDGE_BUS);
  1032. pci_config_write8(addr, busno);
  1033. addr = psycho_pci_config_mkaddr(pbm, busno,
  1034. 0, PBM_BRIDGE_SUBORDINATE);
  1035. pci_config_write8(addr, busno + nbus);
  1036. pbm->pci_first_busno = busno;
  1037. pbm->pci_last_busno = busno + nbus;
  1038. pci_highest_busnum = busno + nbus + 1;
  1039. do {
  1040. pci_bus2pbm[busno++] = pbm;
  1041. } while (nbus--);
  1042. }
  1043. /* We have to do the config space accesses by hand here since
  1044.  * the pci_bus2pbm array is not ready yet.
  1045.  */
  1046. static void __init pbm_pci_bridge_renumber(struct pci_pbm_info *pbm,
  1047.    u8 busno)
  1048. {
  1049. u32 devfn, l, class;
  1050. u8 hdr_type;
  1051. int is_multi = 0;
  1052. for(devfn = 0; devfn < 0xff; ++devfn) {
  1053. u32 *dwaddr;
  1054. u8 *baddr;
  1055. if (PCI_FUNC(devfn) != 0 && is_multi == 0)
  1056. continue;
  1057. /* Anything there? */
  1058. dwaddr = psycho_pci_config_mkaddr(pbm, busno, devfn, PCI_VENDOR_ID);
  1059. l = 0xffffffff;
  1060. pci_config_read32(dwaddr, &l);
  1061. if (l == 0xffffffff || l == 0x00000000 ||
  1062.     l == 0x0000ffff || l == 0xffff0000) {
  1063. is_multi = 0;
  1064. continue;
  1065. }
  1066. baddr = psycho_pci_config_mkaddr(pbm, busno, devfn, PCI_HEADER_TYPE);
  1067. pci_config_read8(baddr, &hdr_type);
  1068. if (PCI_FUNC(devfn) == 0)
  1069. is_multi = hdr_type & 0x80;
  1070. dwaddr = psycho_pci_config_mkaddr(pbm, busno, devfn, PCI_CLASS_REVISION);
  1071. class = 0xffffffff;
  1072. pci_config_read32(dwaddr, &class);
  1073. if ((class >> 16) == PCI_CLASS_BRIDGE_PCI) {
  1074. u32 buses = 0xffffffff;
  1075. dwaddr = psycho_pci_config_mkaddr(pbm, busno, devfn,
  1076.   PCI_PRIMARY_BUS);
  1077. pci_config_read32(dwaddr, &buses);
  1078. pbm_pci_bridge_renumber(pbm, (buses >> 8) & 0xff);
  1079. buses &= 0xff000000;
  1080. pci_config_write32(dwaddr, buses);
  1081. }
  1082. }
  1083. }
  1084. static void __init pbm_bridge_reconfigure(struct pci_controller_info *p)
  1085. {
  1086. struct pci_pbm_info *pbm;
  1087. u8 *addr;
  1088. /* Clear out primary/secondary/subordinate bus numbers on
  1089.  * all PCI-to-PCI bridges under each PBM.  The generic bus
  1090.  * probing will fix them up.
  1091.  */
  1092. pbm_pci_bridge_renumber(&p->pbm_B, p->pbm_B.pci_first_busno);
  1093. pbm_pci_bridge_renumber(&p->pbm_A, p->pbm_A.pci_first_busno);
  1094. /* Move PBM A out of the way. */
  1095. pbm = &p->pbm_A;
  1096. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1097. 0, PBM_BRIDGE_BUS);
  1098. pci_config_write8(addr, 0xff);
  1099. addr = psycho_pci_config_mkaddr(pbm, 0xff,
  1100. 0, PBM_BRIDGE_SUBORDINATE);
  1101. pci_config_write8(addr, 0xff);
  1102. /* Now we can safely renumber both PBMs. */
  1103. pbm_renumber(&p->pbm_B, p->pbm_B.pci_first_busno);
  1104. pbm_renumber(&p->pbm_A, 0xff);
  1105. }
  1106. static void __init pbm_config_busmastering(struct pci_pbm_info *pbm)
  1107. {
  1108. u8 *addr;
  1109. /* Set cache-line size to 64 bytes, this is actually
  1110.  * a nop but I do it for completeness.
  1111.  */
  1112. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1113. 0, PCI_CACHE_LINE_SIZE);
  1114. pci_config_write8(addr, 64 / sizeof(u32));
  1115. /* Set PBM latency timer to 64 PCI clocks. */
  1116. addr = psycho_pci_config_mkaddr(pbm, pbm->pci_first_busno,
  1117. 0, PCI_LATENCY_TIMER);
  1118. pci_config_write8(addr, 64);
  1119. }
  1120. static void __init pbm_scan_bus(struct pci_controller_info *p,
  1121. struct pci_pbm_info *pbm)
  1122. {
  1123. struct pcidev_cookie *cookie = kmalloc(sizeof(*cookie), GFP_KERNEL);
  1124. if (!cookie) {
  1125. prom_printf("PSYCHO: Critical allocation failure.n");
  1126. prom_halt();
  1127. }
  1128. /* All we care about is the PBM. */
  1129. memset(cookie, 0, sizeof(*cookie));
  1130. cookie->pbm = pbm;
  1131. pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno,
  1132.     p->pci_ops,
  1133.     pbm);
  1134. pci_fixup_host_bridge_self(pbm->pci_bus);
  1135. pbm->pci_bus->self->sysdata = cookie;
  1136. pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
  1137. pci_record_assignments(pbm, pbm->pci_bus);
  1138. pci_assign_unassigned(pbm, pbm->pci_bus);
  1139. pci_fixup_irq(pbm, pbm->pci_bus);
  1140. pci_determine_66mhz_disposition(pbm, pbm->pci_bus);
  1141. pci_setup_busmastering(pbm, pbm->pci_bus);
  1142. }
  1143. static void __init psycho_scan_bus(struct pci_controller_info *p)
  1144. {
  1145. pbm_bridge_reconfigure(p);
  1146. pbm_config_busmastering(&p->pbm_B);
  1147. p->pbm_B.is_66mhz_capable = 0;
  1148. pbm_config_busmastering(&p->pbm_A);
  1149. p->pbm_A.is_66mhz_capable = 1;
  1150. pbm_scan_bus(p, &p->pbm_B);
  1151. pbm_scan_bus(p, &p->pbm_A);
  1152. /* After the PCI bus scan is complete, we can register
  1153.  * the error interrupt handlers.
  1154.  */
  1155. psycho_register_error_handlers(p);
  1156. }
  1157. static void __init psycho_iommu_init(struct pci_controller_info *p)
  1158. {
  1159. struct pci_iommu *iommu = p->pbm_A.iommu;
  1160. unsigned long tsbbase, i;
  1161. u64 control;
  1162. /* Setup initial software IOMMU state. */
  1163. spin_lock_init(&iommu->lock);
  1164. iommu->iommu_cur_ctx = 0;
  1165. /* Register addresses. */
  1166. iommu->iommu_control  = p->controller_regs + PSYCHO_IOMMU_CONTROL;
  1167. iommu->iommu_tsbbase  = p->controller_regs + PSYCHO_IOMMU_TSBBASE;
  1168. iommu->iommu_flush    = p->controller_regs + PSYCHO_IOMMU_FLUSH;
  1169. /* PSYCHO's IOMMU lacks ctx flushing. */
  1170. iommu->iommu_ctxflush = 0;
  1171. /* We use the main control register of PSYCHO as the write
  1172.  * completion register.
  1173.  */
  1174. iommu->write_complete_reg = p->controller_regs + PSYCHO_CONTROL;
  1175. /*
  1176.  * Invalidate TLB Entries.
  1177.  */
  1178. control = psycho_read(p->controller_regs + PSYCHO_IOMMU_CONTROL);
  1179. control |= PSYCHO_IOMMU_CTRL_DENAB;
  1180. psycho_write(p->controller_regs + PSYCHO_IOMMU_CONTROL, control);
  1181. for(i = 0; i < 16; i++) {
  1182. psycho_write(p->controller_regs + PSYCHO_IOMMU_TAG + (i * 8UL), 0);
  1183. psycho_write(p->controller_regs + PSYCHO_IOMMU_DATA + (i * 8UL), 0);
  1184. }
  1185. /* Leave diag mode enabled for full-flushing done
  1186.  * in pci_iommu.c
  1187.  */
  1188. /* Using assumed page size 8K with 128K entries we need 1MB iommu page
  1189.  * table (128K ioptes * 8 bytes per iopte).  This is
  1190.  * page order 7 on UltraSparc.
  1191.  */
  1192. tsbbase = __get_free_pages(GFP_KERNEL, get_order(IO_TSB_SIZE));
  1193. if (!tsbbase) {
  1194. prom_printf("PSYCHO_IOMMU: Error, gfp(tsb) failed.n");
  1195. prom_halt();
  1196. }
  1197. iommu->page_table = (iopte_t *)tsbbase;
  1198. iommu->page_table_sz_bits = 17;
  1199. iommu->page_table_map_base = 0xc0000000;
  1200. iommu->dma_addr_mask = 0xffffffff;
  1201. memset((char *)tsbbase, 0, IO_TSB_SIZE);
  1202. /* We start with no consistent mappings. */
  1203. iommu->lowest_consistent_map =
  1204. 1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS);
  1205. for (i = 0; i < PBM_NCLUSTERS; i++) {
  1206. iommu->alloc_info[i].flush = 0;
  1207. iommu->alloc_info[i].next = 0;
  1208. }
  1209. psycho_write(p->controller_regs + PSYCHO_IOMMU_TSBBASE, __pa(tsbbase));
  1210. control = psycho_read(p->controller_regs + PSYCHO_IOMMU_CONTROL);
  1211. control &= ~(PSYCHO_IOMMU_CTRL_TSBSZ | PSYCHO_IOMMU_CTRL_TBWSZ);
  1212. control |= (PSYCHO_IOMMU_TSBSZ_128K | PSYCHO_IOMMU_CTRL_ENAB);
  1213. psycho_write(p->controller_regs + PSYCHO_IOMMU_CONTROL, control);
  1214. /* If necessary, hook us up for starfire IRQ translations. */
  1215. if(this_is_starfire)
  1216. p->starfire_cookie = starfire_hookup(p->portid);
  1217. else
  1218. p->starfire_cookie = NULL;
  1219. }
  1220. #define PSYCHO_IRQ_RETRY 0x1a00UL
  1221. #define PSYCHO_PCIA_DIAG 0x2020UL
  1222. #define PSYCHO_PCIB_DIAG 0x4020UL
  1223. #define  PSYCHO_PCIDIAG_RESV  0xffffffffffffff80 /* Reserved                     */
  1224. #define  PSYCHO_PCIDIAG_DRETRY  0x0000000000000040 /* Disable retry limit          */
  1225. #define  PSYCHO_PCIDIAG_DISYNC  0x0000000000000020 /* Disable DMA wr / irq sync    */
  1226. #define  PSYCHO_PCIDIAG_DDWSYNC  0x0000000000000010 /* Disable DMA wr / PIO rd sync */
  1227. #define  PSYCHO_PCIDIAG_IDDPAR  0x0000000000000008 /* Invert DMA data parity       */
  1228. #define  PSYCHO_PCIDIAG_IPDPAR  0x0000000000000004 /* Invert PIO data parity       */
  1229. #define  PSYCHO_PCIDIAG_IPAPAR  0x0000000000000002 /* Invert PIO address parity    */
  1230. #define  PSYCHO_PCIDIAG_LPBACK  0x0000000000000001 /* Enable loopback mode         */
  1231. static void psycho_controller_hwinit(struct pci_controller_info *p)
  1232. {
  1233. u64 tmp;
  1234. /* PROM sets the IRQ retry value too low, increase it. */
  1235. psycho_write(p->controller_regs + PSYCHO_IRQ_RETRY, 0xff);
  1236. /* Enable arbiter for all PCI slots. */
  1237. tmp = psycho_read(p->controller_regs + PSYCHO_PCIA_CTRL);
  1238. tmp |= PSYCHO_PCICTRL_AEN;
  1239. psycho_write(p->controller_regs + PSYCHO_PCIA_CTRL, tmp);
  1240. tmp = psycho_read(p->controller_regs + PSYCHO_PCIB_CTRL);
  1241. tmp |= PSYCHO_PCICTRL_AEN;
  1242. psycho_write(p->controller_regs + PSYCHO_PCIB_CTRL, tmp);
  1243. /* Disable DMA write / PIO read synchronization on
  1244.  * both PCI bus segments.
  1245.  * [ U2P Erratum 1243770, STP2223BGA data sheet ]
  1246.  */
  1247. tmp = psycho_read(p->controller_regs + PSYCHO_PCIA_DIAG);
  1248. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  1249. psycho_write(p->controller_regs + PSYCHO_PCIA_DIAG, tmp);
  1250. tmp = psycho_read(p->controller_regs + PSYCHO_PCIB_DIAG);
  1251. tmp |= PSYCHO_PCIDIAG_DDWSYNC;
  1252. psycho_write(p->controller_regs + PSYCHO_PCIB_DIAG, tmp);
  1253. }
  1254. static void __init pbm_register_toplevel_resources(struct pci_controller_info *p,
  1255.    struct pci_pbm_info *pbm)
  1256. {
  1257. char *name = pbm->name;
  1258. sprintf(name, "PSYCHO%d PBM%c",
  1259. p->index,
  1260. (pbm == &p->pbm_A ? 'A' : 'B'));
  1261. pbm->io_space.name = pbm->mem_space.name = name;
  1262. request_resource(&ioport_resource, &pbm->io_space);
  1263. request_resource(&iomem_resource, &pbm->mem_space);
  1264. pci_register_legacy_regions(&pbm->io_space,
  1265.     &pbm->mem_space);
  1266. }
  1267. static void psycho_pbm_strbuf_init(struct pci_controller_info *p,
  1268.    struct pci_pbm_info *pbm,
  1269.    int is_pbm_a)
  1270. {
  1271. unsigned long base = p->controller_regs;
  1272. u64 control;
  1273. if (is_pbm_a) {
  1274. pbm->stc.strbuf_control  = base + PSYCHO_STRBUF_CONTROL_A;
  1275. pbm->stc.strbuf_pflush   = base + PSYCHO_STRBUF_FLUSH_A;
  1276. pbm->stc.strbuf_fsync    = base + PSYCHO_STRBUF_FSYNC_A;
  1277. } else {
  1278. pbm->stc.strbuf_control  = base + PSYCHO_STRBUF_CONTROL_B;
  1279. pbm->stc.strbuf_pflush   = base + PSYCHO_STRBUF_FLUSH_B;
  1280. pbm->stc.strbuf_fsync    = base + PSYCHO_STRBUF_FSYNC_B;
  1281. }
  1282. /* PSYCHO's streaming buffer lacks ctx flushing. */
  1283. pbm->stc.strbuf_ctxflush      = 0;
  1284. pbm->stc.strbuf_ctxmatch_base = 0;
  1285. pbm->stc.strbuf_flushflag = (volatile unsigned long *)
  1286. ((((unsigned long)&pbm->stc.__flushflag_buf[0])
  1287.   + 63UL)
  1288.  & ~63UL);
  1289. pbm->stc.strbuf_flushflag_pa = (unsigned long)
  1290. __pa(pbm->stc.strbuf_flushflag);
  1291. /* Enable the streaming buffer.  We have to be careful
  1292.  * just in case OBP left it with LRU locking enabled.
  1293.  *
  1294.  * It is possible to control if PBM will be rerun on
  1295.  * line misses.  Currently I just retain whatever setting
  1296.  * OBP left us with.  All checks so far show it having
  1297.  * a value of zero.
  1298.  */
  1299. #undef PSYCHO_STRBUF_RERUN_ENABLE
  1300. #undef PSYCHO_STRBUF_RERUN_DISABLE
  1301. control = psycho_read(pbm->stc.strbuf_control);
  1302. control |= PSYCHO_STRBUF_CTRL_ENAB;
  1303. control &= ~(PSYCHO_STRBUF_CTRL_LENAB | PSYCHO_STRBUF_CTRL_LPTR);
  1304. #ifdef PSYCHO_STRBUF_RERUN_ENABLE
  1305. control &= ~(PSYCHO_STRBUF_CTRL_RRDIS);
  1306. #else
  1307. #ifdef PSYCHO_STRBUF_RERUN_DISABLE
  1308. control |= PSYCHO_STRBUF_CTRL_RRDIS;
  1309. #endif
  1310. #endif
  1311. psycho_write(pbm->stc.strbuf_control, control);
  1312. pbm->stc.strbuf_enabled = 1;
  1313. }
  1314. #define PSYCHO_IOSPACE_A 0x002000000UL
  1315. #define PSYCHO_IOSPACE_B 0x002010000UL
  1316. #define PSYCHO_IOSPACE_SIZE 0x00000ffffUL
  1317. #define PSYCHO_MEMSPACE_A 0x100000000UL
  1318. #define PSYCHO_MEMSPACE_B 0x180000000UL
  1319. #define PSYCHO_MEMSPACE_SIZE 0x07fffffffUL
  1320. static void psycho_pbm_init(struct pci_controller_info *p,
  1321.     int prom_node, int is_pbm_a)
  1322. {
  1323. unsigned int busrange[2];
  1324. struct pci_pbm_info *pbm;
  1325. int err;
  1326. if (is_pbm_a) {
  1327. pbm = &p->pbm_A;
  1328. pbm->pci_first_slot = 1;
  1329. pbm->io_space.start = p->controller_regs + PSYCHO_IOSPACE_A;
  1330. pbm->mem_space.start = p->controller_regs + PSYCHO_MEMSPACE_A;
  1331. } else {
  1332. pbm = &p->pbm_B;
  1333. pbm->pci_first_slot = 2;
  1334. pbm->io_space.start = p->controller_regs + PSYCHO_IOSPACE_B;
  1335. pbm->mem_space.start = p->controller_regs + PSYCHO_MEMSPACE_B;
  1336. }
  1337. pbm->io_space.end = pbm->io_space.start + PSYCHO_IOSPACE_SIZE;
  1338. pbm->io_space.flags = IORESOURCE_IO;
  1339. pbm->mem_space.end = pbm->mem_space.start + PSYCHO_MEMSPACE_SIZE;
  1340. pbm->mem_space.flags = IORESOURCE_MEM;
  1341. pbm_register_toplevel_resources(p, pbm);
  1342. pbm->parent = p;
  1343. pbm->prom_node = prom_node;
  1344. prom_getstring(prom_node, "name",
  1345.        pbm->prom_name,
  1346.        sizeof(pbm->prom_name));
  1347. err = prom_getproperty(prom_node, "ranges",
  1348.        (char *)pbm->pbm_ranges,
  1349.        sizeof(pbm->pbm_ranges));
  1350. if (err != -1)
  1351. pbm->num_pbm_ranges =
  1352. (err / sizeof(struct linux_prom_pci_ranges));
  1353. else
  1354. pbm->num_pbm_ranges = 0;
  1355. err = prom_getproperty(prom_node, "interrupt-map",
  1356.        (char *)pbm->pbm_intmap,
  1357.        sizeof(pbm->pbm_intmap));
  1358. if (err != -1) {
  1359. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  1360. err = prom_getproperty(prom_node, "interrupt-map-mask",
  1361.        (char *)&pbm->pbm_intmask,
  1362.        sizeof(pbm->pbm_intmask));
  1363. if (err == -1) {
  1364. prom_printf("PSYCHO-PBM: Fatal error, no "
  1365.     "interrupt-map-mask.n");
  1366. prom_halt();
  1367. }
  1368. } else {
  1369. pbm->num_pbm_intmap = 0;
  1370. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  1371. }
  1372. err = prom_getproperty(prom_node, "bus-range",
  1373.        (char *)&busrange[0],
  1374.        sizeof(busrange));
  1375. if (err == 0 || err == -1) {
  1376. prom_printf("PSYCHO-PBM: Fatal error, no bus-range.n");
  1377. prom_halt();
  1378. }
  1379. pbm->pci_first_busno = busrange[0];
  1380. pbm->pci_last_busno = busrange[1];
  1381. psycho_pbm_strbuf_init(p, pbm, is_pbm_a);
  1382. }
  1383. #define PSYCHO_CONFIGSPACE 0x001000000UL
  1384. void __init psycho_init(int node, char *model_name)
  1385. {
  1386. struct linux_prom64_registers pr_regs[3];
  1387. struct pci_controller_info *p;
  1388. struct pci_iommu *iommu;
  1389. unsigned long flags;
  1390. u32 upa_portid;
  1391. int is_pbm_a, err;
  1392. upa_portid = prom_getintdefault(node, "upa-portid", 0xff);
  1393. spin_lock_irqsave(&pci_controller_lock, flags);
  1394. for(p = pci_controller_root; p; p = p->next) {
  1395. if (p->portid == upa_portid) {
  1396. spin_unlock_irqrestore(&pci_controller_lock, flags);
  1397. is_pbm_a = (p->pbm_A.prom_node == 0);
  1398. psycho_pbm_init(p, node, is_pbm_a);
  1399. return;
  1400. }
  1401. }
  1402. spin_unlock_irqrestore(&pci_controller_lock, flags);
  1403. p = kmalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  1404. if (!p) {
  1405. prom_printf("PSYCHO: Fatal memory allocation error.n");
  1406. prom_halt();
  1407. }
  1408. memset(p, 0, sizeof(*p));
  1409. iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
  1410. if (!iommu) {
  1411. prom_printf("PSYCHO: Fatal memory allocation error.n");
  1412. prom_halt();
  1413. }
  1414. memset(iommu, 0, sizeof(*iommu));
  1415. p->pbm_A.iommu = p->pbm_B.iommu = iommu;
  1416. spin_lock_irqsave(&pci_controller_lock, flags);
  1417. p->next = pci_controller_root;
  1418. pci_controller_root = p;
  1419. spin_unlock_irqrestore(&pci_controller_lock, flags);
  1420. p->portid = upa_portid;
  1421. p->index = pci_num_controllers++;
  1422. p->pbms_same_domain = 0;
  1423. p->scan_bus = psycho_scan_bus;
  1424. p->irq_build = psycho_irq_build;
  1425. p->base_address_update = psycho_base_address_update;
  1426. p->resource_adjust = psycho_resource_adjust;
  1427. p->pci_ops = &psycho_ops;
  1428. err = prom_getproperty(node, "reg",
  1429.        (char *)&pr_regs[0],
  1430.        sizeof(pr_regs));
  1431. if (err == 0 || err == -1) {
  1432. prom_printf("PSYCHO: Fatal error, no reg property.n");
  1433. prom_halt();
  1434. }
  1435. p->controller_regs = pr_regs[2].phys_addr;
  1436. printk("PCI: Found PSYCHO, control regs at %016lxn",
  1437.        p->controller_regs);
  1438. p->pbm_A.config_space = p->pbm_B.config_space =
  1439. (pr_regs[2].phys_addr + PSYCHO_CONFIGSPACE);
  1440. printk("PSYCHO: Shared PCI config space at %016lxn",
  1441.        p->pbm_A.config_space);
  1442. /*
  1443.  * Psycho's PCI MEM space is mapped to a 2GB aligned area, so
  1444.  * we need to adjust our MEM space mask.
  1445.  */
  1446. pci_memspace_mask = 0x7fffffffUL;
  1447. psycho_controller_hwinit(p);
  1448. psycho_iommu_init(p);
  1449. is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000);
  1450. psycho_pbm_init(p, node, is_pbm_a);
  1451. }