pci_sabre.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. /* $Id: pci_sabre.c,v 1.42 2002/01/23 11:27:32 davem Exp $
  2. * pci_sabre.c: Sabre 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 <linux/interrupt.h>
  14. #include <asm/apb.h>
  15. #include <asm/pbm.h>
  16. #include <asm/iommu.h>
  17. #include <asm/irq.h>
  18. #include <asm/smp.h>
  19. #include <asm/oplib.h>
  20. #include <asm/prom.h>
  21. #include "pci_impl.h"
  22. #include "iommu_common.h"
  23. /* All SABRE registers are 64-bits. The following accessor
  24. * routines are how they are accessed. The REG parameter
  25. * is a physical address.
  26. */
  27. #define sabre_read(__reg) \
  28. ({ u64 __ret; \
  29. __asm__ __volatile__("ldxa [%1] %2, %0" \
  30. : "=r" (__ret) \
  31. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  32. : "memory"); \
  33. __ret; \
  34. })
  35. #define sabre_write(__reg, __val) \
  36. __asm__ __volatile__("stxa %0, [%1] %2" \
  37. : /* no outputs */ \
  38. : "r" (__val), "r" (__reg), \
  39. "i" (ASI_PHYS_BYPASS_EC_E) \
  40. : "memory")
  41. /* SABRE PCI controller register offsets and definitions. */
  42. #define SABRE_UE_AFSR 0x0030UL
  43. #define SABRE_UEAFSR_PDRD 0x4000000000000000UL /* Primary PCI DMA Read */
  44. #define SABRE_UEAFSR_PDWR 0x2000000000000000UL /* Primary PCI DMA Write */
  45. #define SABRE_UEAFSR_SDRD 0x0800000000000000UL /* Secondary PCI DMA Read */
  46. #define SABRE_UEAFSR_SDWR 0x0400000000000000UL /* Secondary PCI DMA Write */
  47. #define SABRE_UEAFSR_SDTE 0x0200000000000000UL /* Secondary DMA Translation Error */
  48. #define SABRE_UEAFSR_PDTE 0x0100000000000000UL /* Primary DMA Translation Error */
  49. #define SABRE_UEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask */
  50. #define SABRE_UEAFSR_OFF 0x00000000e0000000UL /* Offset (AFAR bits [5:3] */
  51. #define SABRE_UEAFSR_BLK 0x0000000000800000UL /* Was block operation */
  52. #define SABRE_UECE_AFAR 0x0038UL
  53. #define SABRE_CE_AFSR 0x0040UL
  54. #define SABRE_CEAFSR_PDRD 0x4000000000000000UL /* Primary PCI DMA Read */
  55. #define SABRE_CEAFSR_PDWR 0x2000000000000000UL /* Primary PCI DMA Write */
  56. #define SABRE_CEAFSR_SDRD 0x0800000000000000UL /* Secondary PCI DMA Read */
  57. #define SABRE_CEAFSR_SDWR 0x0400000000000000UL /* Secondary PCI DMA Write */
  58. #define SABRE_CEAFSR_ESYND 0x00ff000000000000UL /* ECC Syndrome */
  59. #define SABRE_CEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask */
  60. #define SABRE_CEAFSR_OFF 0x00000000e0000000UL /* Offset */
  61. #define SABRE_CEAFSR_BLK 0x0000000000800000UL /* Was block operation */
  62. #define SABRE_UECE_AFAR_ALIAS 0x0048UL /* Aliases to 0x0038 */
  63. #define SABRE_IOMMU_CONTROL 0x0200UL
  64. #define SABRE_IOMMUCTRL_ERRSTS 0x0000000006000000UL /* Error status bits */
  65. #define SABRE_IOMMUCTRL_ERR 0x0000000001000000UL /* Error present in IOTLB */
  66. #define SABRE_IOMMUCTRL_LCKEN 0x0000000000800000UL /* IOTLB lock enable */
  67. #define SABRE_IOMMUCTRL_LCKPTR 0x0000000000780000UL /* IOTLB lock pointer */
  68. #define SABRE_IOMMUCTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
  69. #define SABRE_IOMMU_TSBSZ_1K 0x0000000000000000
  70. #define SABRE_IOMMU_TSBSZ_2K 0x0000000000010000
  71. #define SABRE_IOMMU_TSBSZ_4K 0x0000000000020000
  72. #define SABRE_IOMMU_TSBSZ_8K 0x0000000000030000
  73. #define SABRE_IOMMU_TSBSZ_16K 0x0000000000040000
  74. #define SABRE_IOMMU_TSBSZ_32K 0x0000000000050000
  75. #define SABRE_IOMMU_TSBSZ_64K 0x0000000000060000
  76. #define SABRE_IOMMU_TSBSZ_128K 0x0000000000070000
  77. #define SABRE_IOMMUCTRL_TBWSZ 0x0000000000000004UL /* TSB assumed page size */
  78. #define SABRE_IOMMUCTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
  79. #define SABRE_IOMMUCTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
  80. #define SABRE_IOMMU_TSBBASE 0x0208UL
  81. #define SABRE_IOMMU_FLUSH 0x0210UL
  82. #define SABRE_IMAP_A_SLOT0 0x0c00UL
  83. #define SABRE_IMAP_B_SLOT0 0x0c20UL
  84. #define SABRE_IMAP_SCSI 0x1000UL
  85. #define SABRE_IMAP_ETH 0x1008UL
  86. #define SABRE_IMAP_BPP 0x1010UL
  87. #define SABRE_IMAP_AU_REC 0x1018UL
  88. #define SABRE_IMAP_AU_PLAY 0x1020UL
  89. #define SABRE_IMAP_PFAIL 0x1028UL
  90. #define SABRE_IMAP_KMS 0x1030UL
  91. #define SABRE_IMAP_FLPY 0x1038UL
  92. #define SABRE_IMAP_SHW 0x1040UL
  93. #define SABRE_IMAP_KBD 0x1048UL
  94. #define SABRE_IMAP_MS 0x1050UL
  95. #define SABRE_IMAP_SER 0x1058UL
  96. #define SABRE_IMAP_UE 0x1070UL
  97. #define SABRE_IMAP_CE 0x1078UL
  98. #define SABRE_IMAP_PCIERR 0x1080UL
  99. #define SABRE_IMAP_GFX 0x1098UL
  100. #define SABRE_IMAP_EUPA 0x10a0UL
  101. #define SABRE_ICLR_A_SLOT0 0x1400UL
  102. #define SABRE_ICLR_B_SLOT0 0x1480UL
  103. #define SABRE_ICLR_SCSI 0x1800UL
  104. #define SABRE_ICLR_ETH 0x1808UL
  105. #define SABRE_ICLR_BPP 0x1810UL
  106. #define SABRE_ICLR_AU_REC 0x1818UL
  107. #define SABRE_ICLR_AU_PLAY 0x1820UL
  108. #define SABRE_ICLR_PFAIL 0x1828UL
  109. #define SABRE_ICLR_KMS 0x1830UL
  110. #define SABRE_ICLR_FLPY 0x1838UL
  111. #define SABRE_ICLR_SHW 0x1840UL
  112. #define SABRE_ICLR_KBD 0x1848UL
  113. #define SABRE_ICLR_MS 0x1850UL
  114. #define SABRE_ICLR_SER 0x1858UL
  115. #define SABRE_ICLR_UE 0x1870UL
  116. #define SABRE_ICLR_CE 0x1878UL
  117. #define SABRE_ICLR_PCIERR 0x1880UL
  118. #define SABRE_WRSYNC 0x1c20UL
  119. #define SABRE_PCICTRL 0x2000UL
  120. #define SABRE_PCICTRL_MRLEN 0x0000001000000000UL /* Use MemoryReadLine for block loads/stores */
  121. #define SABRE_PCICTRL_SERR 0x0000000400000000UL /* Set when SERR asserted on PCI bus */
  122. #define SABRE_PCICTRL_ARBPARK 0x0000000000200000UL /* Bus Parking 0=Ultra-IIi 1=prev-bus-owner */
  123. #define SABRE_PCICTRL_CPUPRIO 0x0000000000100000UL /* Ultra-IIi granted every other bus cycle */
  124. #define SABRE_PCICTRL_ARBPRIO 0x00000000000f0000UL /* Slot which is granted every other bus cycle */
  125. #define SABRE_PCICTRL_ERREN 0x0000000000000100UL /* PCI Error Interrupt Enable */
  126. #define SABRE_PCICTRL_RTRYWE 0x0000000000000080UL /* DMA Flow Control 0=wait-if-possible 1=retry */
  127. #define SABRE_PCICTRL_AEN 0x000000000000000fUL /* Slot PCI arbitration enables */
  128. #define SABRE_PIOAFSR 0x2010UL
  129. #define SABRE_PIOAFSR_PMA 0x8000000000000000UL /* Primary Master Abort */
  130. #define SABRE_PIOAFSR_PTA 0x4000000000000000UL /* Primary Target Abort */
  131. #define SABRE_PIOAFSR_PRTRY 0x2000000000000000UL /* Primary Excessive Retries */
  132. #define SABRE_PIOAFSR_PPERR 0x1000000000000000UL /* Primary Parity Error */
  133. #define SABRE_PIOAFSR_SMA 0x0800000000000000UL /* Secondary Master Abort */
  134. #define SABRE_PIOAFSR_STA 0x0400000000000000UL /* Secondary Target Abort */
  135. #define SABRE_PIOAFSR_SRTRY 0x0200000000000000UL /* Secondary Excessive Retries */
  136. #define SABRE_PIOAFSR_SPERR 0x0100000000000000UL /* Secondary Parity Error */
  137. #define SABRE_PIOAFSR_BMSK 0x0000ffff00000000UL /* Byte Mask */
  138. #define SABRE_PIOAFSR_BLK 0x0000000080000000UL /* Was Block Operation */
  139. #define SABRE_PIOAFAR 0x2018UL
  140. #define SABRE_PCIDIAG 0x2020UL
  141. #define SABRE_PCIDIAG_DRTRY 0x0000000000000040UL /* Disable PIO Retry Limit */
  142. #define SABRE_PCIDIAG_IPAPAR 0x0000000000000008UL /* Invert PIO Address Parity */
  143. #define SABRE_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO Data Parity */
  144. #define SABRE_PCIDIAG_IDDPAR 0x0000000000000002UL /* Invert DMA Data Parity */
  145. #define SABRE_PCIDIAG_ELPBK 0x0000000000000001UL /* Loopback Enable - not supported */
  146. #define SABRE_PCITASR 0x2028UL
  147. #define SABRE_PCITASR_EF 0x0000000000000080UL /* Respond to 0xe0000000-0xffffffff */
  148. #define SABRE_PCITASR_CD 0x0000000000000040UL /* Respond to 0xc0000000-0xdfffffff */
  149. #define SABRE_PCITASR_AB 0x0000000000000020UL /* Respond to 0xa0000000-0xbfffffff */
  150. #define SABRE_PCITASR_89 0x0000000000000010UL /* Respond to 0x80000000-0x9fffffff */
  151. #define SABRE_PCITASR_67 0x0000000000000008UL /* Respond to 0x60000000-0x7fffffff */
  152. #define SABRE_PCITASR_45 0x0000000000000004UL /* Respond to 0x40000000-0x5fffffff */
  153. #define SABRE_PCITASR_23 0x0000000000000002UL /* Respond to 0x20000000-0x3fffffff */
  154. #define SABRE_PCITASR_01 0x0000000000000001UL /* Respond to 0x00000000-0x1fffffff */
  155. #define SABRE_PIOBUF_DIAG 0x5000UL
  156. #define SABRE_DMABUF_DIAGLO 0x5100UL
  157. #define SABRE_DMABUF_DIAGHI 0x51c0UL
  158. #define SABRE_IMAP_GFX_ALIAS 0x6000UL /* Aliases to 0x1098 */
  159. #define SABRE_IMAP_EUPA_ALIAS 0x8000UL /* Aliases to 0x10a0 */
  160. #define SABRE_IOMMU_VADIAG 0xa400UL
  161. #define SABRE_IOMMU_TCDIAG 0xa408UL
  162. #define SABRE_IOMMU_TAG 0xa580UL
  163. #define SABRE_IOMMUTAG_ERRSTS 0x0000000001800000UL /* Error status bits */
  164. #define SABRE_IOMMUTAG_ERR 0x0000000000400000UL /* Error present */
  165. #define SABRE_IOMMUTAG_WRITE 0x0000000000200000UL /* Page is writable */
  166. #define SABRE_IOMMUTAG_STREAM 0x0000000000100000UL /* Streamable bit - unused */
  167. #define SABRE_IOMMUTAG_SIZE 0x0000000000080000UL /* 0=8k 1=16k */
  168. #define SABRE_IOMMUTAG_VPN 0x000000000007ffffUL /* Virtual Page Number [31:13] */
  169. #define SABRE_IOMMU_DATA 0xa600UL
  170. #define SABRE_IOMMUDATA_VALID 0x0000000040000000UL /* Valid */
  171. #define SABRE_IOMMUDATA_USED 0x0000000020000000UL /* Used (for LRU algorithm) */
  172. #define SABRE_IOMMUDATA_CACHE 0x0000000010000000UL /* Cacheable */
  173. #define SABRE_IOMMUDATA_PPN 0x00000000001fffffUL /* Physical Page Number [33:13] */
  174. #define SABRE_PCI_IRQSTATE 0xa800UL
  175. #define SABRE_OBIO_IRQSTATE 0xa808UL
  176. #define SABRE_FFBCFG 0xf000UL
  177. #define SABRE_FFBCFG_SPRQS 0x000000000f000000 /* Slave P_RQST queue size */
  178. #define SABRE_FFBCFG_ONEREAD 0x0000000000004000 /* Slave supports one outstanding read */
  179. #define SABRE_MCCTRL0 0xf010UL
  180. #define SABRE_MCCTRL0_RENAB 0x0000000080000000 /* Refresh Enable */
  181. #define SABRE_MCCTRL0_EENAB 0x0000000010000000 /* Enable all ECC functions */
  182. #define SABRE_MCCTRL0_11BIT 0x0000000000001000 /* Enable 11-bit column addressing */
  183. #define SABRE_MCCTRL0_DPP 0x0000000000000f00 /* DIMM Pair Present Bits */
  184. #define SABRE_MCCTRL0_RINTVL 0x00000000000000ff /* Refresh Interval */
  185. #define SABRE_MCCTRL1 0xf018UL
  186. #define SABRE_MCCTRL1_AMDC 0x0000000038000000 /* Advance Memdata Clock */
  187. #define SABRE_MCCTRL1_ARDC 0x0000000007000000 /* Advance DRAM Read Data Clock */
  188. #define SABRE_MCCTRL1_CSR 0x0000000000e00000 /* CAS to RAS delay for CBR refresh */
  189. #define SABRE_MCCTRL1_CASRW 0x00000000001c0000 /* CAS length for read/write */
  190. #define SABRE_MCCTRL1_RCD 0x0000000000038000 /* RAS to CAS delay */
  191. #define SABRE_MCCTRL1_CP 0x0000000000007000 /* CAS Precharge */
  192. #define SABRE_MCCTRL1_RP 0x0000000000000e00 /* RAS Precharge */
  193. #define SABRE_MCCTRL1_RAS 0x00000000000001c0 /* Length of RAS for refresh */
  194. #define SABRE_MCCTRL1_CASRW2 0x0000000000000038 /* Must be same as CASRW */
  195. #define SABRE_MCCTRL1_RSC 0x0000000000000007 /* RAS after CAS hold time */
  196. #define SABRE_RESETCTRL 0xf020UL
  197. #define SABRE_CONFIGSPACE 0x001000000UL
  198. #define SABRE_IOSPACE 0x002000000UL
  199. #define SABRE_IOSPACE_SIZE 0x000ffffffUL
  200. #define SABRE_MEMSPACE 0x100000000UL
  201. #define SABRE_MEMSPACE_SIZE 0x07fffffffUL
  202. /* UltraSparc-IIi Programmer's Manual, page 325, PCI
  203. * configuration space address format:
  204. *
  205. * 32 24 23 16 15 11 10 8 7 2 1 0
  206. * ---------------------------------------------------------
  207. * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 |
  208. * ---------------------------------------------------------
  209. */
  210. #define SABRE_CONFIG_BASE(PBM) \
  211. ((PBM)->config_space | (1UL << 24))
  212. #define SABRE_CONFIG_ENCODE(BUS, DEVFN, REG) \
  213. (((unsigned long)(BUS) << 16) | \
  214. ((unsigned long)(DEVFN) << 8) | \
  215. ((unsigned long)(REG)))
  216. static int hummingbird_p;
  217. static struct pci_bus *sabre_root_bus;
  218. static void *sabre_pci_config_mkaddr(struct pci_pbm_info *pbm,
  219. unsigned char bus,
  220. unsigned int devfn,
  221. int where)
  222. {
  223. if (!pbm)
  224. return NULL;
  225. return (void *)
  226. (SABRE_CONFIG_BASE(pbm) |
  227. SABRE_CONFIG_ENCODE(bus, devfn, where));
  228. }
  229. static int sabre_out_of_range(unsigned char devfn)
  230. {
  231. if (hummingbird_p)
  232. return 0;
  233. return (((PCI_SLOT(devfn) == 0) && (PCI_FUNC(devfn) > 0)) ||
  234. ((PCI_SLOT(devfn) == 1) && (PCI_FUNC(devfn) > 1)) ||
  235. (PCI_SLOT(devfn) > 1));
  236. }
  237. static int __sabre_out_of_range(struct pci_pbm_info *pbm,
  238. unsigned char bus,
  239. unsigned char devfn)
  240. {
  241. if (hummingbird_p)
  242. return 0;
  243. return ((pbm->parent == 0) ||
  244. ((pbm == &pbm->parent->pbm_A) &&
  245. (bus == pbm->pci_first_busno) &&
  246. PCI_SLOT(devfn) > 8));
  247. }
  248. static int __sabre_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  249. int where, int size, u32 *value)
  250. {
  251. struct pci_pbm_info *pbm = bus_dev->sysdata;
  252. unsigned char bus = bus_dev->number;
  253. u32 *addr;
  254. u16 tmp16;
  255. u8 tmp8;
  256. switch (size) {
  257. case 1:
  258. *value = 0xff;
  259. break;
  260. case 2:
  261. *value = 0xffff;
  262. break;
  263. case 4:
  264. *value = 0xffffffff;
  265. break;
  266. }
  267. addr = sabre_pci_config_mkaddr(pbm, bus, devfn, where);
  268. if (!addr)
  269. return PCIBIOS_SUCCESSFUL;
  270. if (__sabre_out_of_range(pbm, bus, devfn))
  271. return PCIBIOS_SUCCESSFUL;
  272. switch (size) {
  273. case 1:
  274. pci_config_read8((u8 *) addr, &tmp8);
  275. *value = tmp8;
  276. break;
  277. case 2:
  278. if (where & 0x01) {
  279. printk("pci_read_config_word: misaligned reg [%x]\n",
  280. where);
  281. return PCIBIOS_SUCCESSFUL;
  282. }
  283. pci_config_read16((u16 *) addr, &tmp16);
  284. *value = tmp16;
  285. break;
  286. case 4:
  287. if (where & 0x03) {
  288. printk("pci_read_config_dword: misaligned reg [%x]\n",
  289. where);
  290. return PCIBIOS_SUCCESSFUL;
  291. }
  292. pci_config_read32(addr, value);
  293. break;
  294. }
  295. return PCIBIOS_SUCCESSFUL;
  296. }
  297. static int sabre_read_pci_cfg(struct pci_bus *bus, unsigned int devfn,
  298. int where, int size, u32 *value)
  299. {
  300. if (!bus->number && sabre_out_of_range(devfn)) {
  301. switch (size) {
  302. case 1:
  303. *value = 0xff;
  304. break;
  305. case 2:
  306. *value = 0xffff;
  307. break;
  308. case 4:
  309. *value = 0xffffffff;
  310. break;
  311. }
  312. return PCIBIOS_SUCCESSFUL;
  313. }
  314. if (bus->number || PCI_SLOT(devfn))
  315. return __sabre_read_pci_cfg(bus, devfn, where, size, value);
  316. /* When accessing PCI config space of the PCI controller itself (bus
  317. * 0, device slot 0, function 0) there are restrictions. Each
  318. * register must be accessed as it's natural size. Thus, for example
  319. * the Vendor ID must be accessed as a 16-bit quantity.
  320. */
  321. switch (size) {
  322. case 1:
  323. if (where < 8) {
  324. u32 tmp32;
  325. u16 tmp16;
  326. __sabre_read_pci_cfg(bus, devfn, where & ~1, 2, &tmp32);
  327. tmp16 = (u16) tmp32;
  328. if (where & 1)
  329. *value = tmp16 >> 8;
  330. else
  331. *value = tmp16 & 0xff;
  332. } else
  333. return __sabre_read_pci_cfg(bus, devfn, where, 1, value);
  334. break;
  335. case 2:
  336. if (where < 8)
  337. return __sabre_read_pci_cfg(bus, devfn, where, 2, value);
  338. else {
  339. u32 tmp32;
  340. u8 tmp8;
  341. __sabre_read_pci_cfg(bus, devfn, where, 1, &tmp32);
  342. tmp8 = (u8) tmp32;
  343. *value = tmp8;
  344. __sabre_read_pci_cfg(bus, devfn, where + 1, 1, &tmp32);
  345. tmp8 = (u8) tmp32;
  346. *value |= tmp8 << 8;
  347. }
  348. break;
  349. case 4: {
  350. u32 tmp32;
  351. u16 tmp16;
  352. sabre_read_pci_cfg(bus, devfn, where, 2, &tmp32);
  353. tmp16 = (u16) tmp32;
  354. *value = tmp16;
  355. sabre_read_pci_cfg(bus, devfn, where + 2, 2, &tmp32);
  356. tmp16 = (u16) tmp32;
  357. *value |= tmp16 << 16;
  358. break;
  359. }
  360. }
  361. return PCIBIOS_SUCCESSFUL;
  362. }
  363. static int __sabre_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  364. int where, int size, u32 value)
  365. {
  366. struct pci_pbm_info *pbm = bus_dev->sysdata;
  367. unsigned char bus = bus_dev->number;
  368. u32 *addr;
  369. addr = sabre_pci_config_mkaddr(pbm, bus, devfn, where);
  370. if (!addr)
  371. return PCIBIOS_SUCCESSFUL;
  372. if (__sabre_out_of_range(pbm, bus, devfn))
  373. return PCIBIOS_SUCCESSFUL;
  374. switch (size) {
  375. case 1:
  376. pci_config_write8((u8 *) addr, value);
  377. break;
  378. case 2:
  379. if (where & 0x01) {
  380. printk("pci_write_config_word: misaligned reg [%x]\n",
  381. where);
  382. return PCIBIOS_SUCCESSFUL;
  383. }
  384. pci_config_write16((u16 *) addr, value);
  385. break;
  386. case 4:
  387. if (where & 0x03) {
  388. printk("pci_write_config_dword: misaligned reg [%x]\n",
  389. where);
  390. return PCIBIOS_SUCCESSFUL;
  391. }
  392. pci_config_write32(addr, value);
  393. break;
  394. }
  395. return PCIBIOS_SUCCESSFUL;
  396. }
  397. static int sabre_write_pci_cfg(struct pci_bus *bus, unsigned int devfn,
  398. int where, int size, u32 value)
  399. {
  400. if (bus->number)
  401. return __sabre_write_pci_cfg(bus, devfn, where, size, value);
  402. if (sabre_out_of_range(devfn))
  403. return PCIBIOS_SUCCESSFUL;
  404. switch (size) {
  405. case 1:
  406. if (where < 8) {
  407. u32 tmp32;
  408. u16 tmp16;
  409. __sabre_read_pci_cfg(bus, devfn, where & ~1, 2, &tmp32);
  410. tmp16 = (u16) tmp32;
  411. if (where & 1) {
  412. value &= 0x00ff;
  413. value |= tmp16 << 8;
  414. } else {
  415. value &= 0xff00;
  416. value |= tmp16;
  417. }
  418. tmp32 = (u32) tmp16;
  419. return __sabre_write_pci_cfg(bus, devfn, where & ~1, 2, tmp32);
  420. } else
  421. return __sabre_write_pci_cfg(bus, devfn, where, 1, value);
  422. break;
  423. case 2:
  424. if (where < 8)
  425. return __sabre_write_pci_cfg(bus, devfn, where, 2, value);
  426. else {
  427. __sabre_write_pci_cfg(bus, devfn, where, 1, value & 0xff);
  428. __sabre_write_pci_cfg(bus, devfn, where + 1, 1, value >> 8);
  429. }
  430. break;
  431. case 4:
  432. sabre_write_pci_cfg(bus, devfn, where, 2, value & 0xffff);
  433. sabre_write_pci_cfg(bus, devfn, where + 2, 2, value >> 16);
  434. break;
  435. }
  436. return PCIBIOS_SUCCESSFUL;
  437. }
  438. static struct pci_ops sabre_ops = {
  439. .read = sabre_read_pci_cfg,
  440. .write = sabre_write_pci_cfg,
  441. };
  442. /* SABRE error handling support. */
  443. static void sabre_check_iommu_error(struct pci_controller_info *p,
  444. unsigned long afsr,
  445. unsigned long afar)
  446. {
  447. struct pci_iommu *iommu = p->pbm_A.iommu;
  448. unsigned long iommu_tag[16];
  449. unsigned long iommu_data[16];
  450. unsigned long flags;
  451. u64 control;
  452. int i;
  453. spin_lock_irqsave(&iommu->lock, flags);
  454. control = sabre_read(iommu->iommu_control);
  455. if (control & SABRE_IOMMUCTRL_ERR) {
  456. char *type_string;
  457. /* Clear the error encountered bit.
  458. * NOTE: On Sabre this is write 1 to clear,
  459. * which is different from Psycho.
  460. */
  461. sabre_write(iommu->iommu_control, control);
  462. switch((control & SABRE_IOMMUCTRL_ERRSTS) >> 25UL) {
  463. case 1:
  464. type_string = "Invalid Error";
  465. break;
  466. case 3:
  467. type_string = "ECC Error";
  468. break;
  469. default:
  470. type_string = "Unknown";
  471. break;
  472. };
  473. printk("SABRE%d: IOMMU Error, type[%s]\n",
  474. p->index, type_string);
  475. /* Enter diagnostic mode and probe for error'd
  476. * entries in the IOTLB.
  477. */
  478. control &= ~(SABRE_IOMMUCTRL_ERRSTS | SABRE_IOMMUCTRL_ERR);
  479. sabre_write(iommu->iommu_control,
  480. (control | SABRE_IOMMUCTRL_DENAB));
  481. for (i = 0; i < 16; i++) {
  482. unsigned long base = p->pbm_A.controller_regs;
  483. iommu_tag[i] =
  484. sabre_read(base + SABRE_IOMMU_TAG + (i * 8UL));
  485. iommu_data[i] =
  486. sabre_read(base + SABRE_IOMMU_DATA + (i * 8UL));
  487. sabre_write(base + SABRE_IOMMU_TAG + (i * 8UL), 0);
  488. sabre_write(base + SABRE_IOMMU_DATA + (i * 8UL), 0);
  489. }
  490. sabre_write(iommu->iommu_control, control);
  491. for (i = 0; i < 16; i++) {
  492. unsigned long tag, data;
  493. tag = iommu_tag[i];
  494. if (!(tag & SABRE_IOMMUTAG_ERR))
  495. continue;
  496. data = iommu_data[i];
  497. switch((tag & SABRE_IOMMUTAG_ERRSTS) >> 23UL) {
  498. case 1:
  499. type_string = "Invalid Error";
  500. break;
  501. case 3:
  502. type_string = "ECC Error";
  503. break;
  504. default:
  505. type_string = "Unknown";
  506. break;
  507. };
  508. printk("SABRE%d: IOMMU TAG(%d)[RAW(%016lx)error(%s)wr(%d)sz(%dK)vpg(%08lx)]\n",
  509. p->index, i, tag, type_string,
  510. ((tag & SABRE_IOMMUTAG_WRITE) ? 1 : 0),
  511. ((tag & SABRE_IOMMUTAG_SIZE) ? 64 : 8),
  512. ((tag & SABRE_IOMMUTAG_VPN) << IOMMU_PAGE_SHIFT));
  513. printk("SABRE%d: IOMMU DATA(%d)[RAW(%016lx)valid(%d)used(%d)cache(%d)ppg(%016lx)\n",
  514. p->index, i, data,
  515. ((data & SABRE_IOMMUDATA_VALID) ? 1 : 0),
  516. ((data & SABRE_IOMMUDATA_USED) ? 1 : 0),
  517. ((data & SABRE_IOMMUDATA_CACHE) ? 1 : 0),
  518. ((data & SABRE_IOMMUDATA_PPN) << IOMMU_PAGE_SHIFT));
  519. }
  520. }
  521. spin_unlock_irqrestore(&iommu->lock, flags);
  522. }
  523. static irqreturn_t sabre_ue_intr(int irq, void *dev_id)
  524. {
  525. struct pci_controller_info *p = dev_id;
  526. unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_UE_AFSR;
  527. unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
  528. unsigned long afsr, afar, error_bits;
  529. int reported;
  530. /* Latch uncorrectable error status. */
  531. afar = sabre_read(afar_reg);
  532. afsr = sabre_read(afsr_reg);
  533. /* Clear the primary/secondary error status bits. */
  534. error_bits = afsr &
  535. (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
  536. SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
  537. SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE);
  538. if (!error_bits)
  539. return IRQ_NONE;
  540. sabre_write(afsr_reg, error_bits);
  541. /* Log the error. */
  542. printk("SABRE%d: Uncorrectable Error, primary error type[%s%s]\n",
  543. p->index,
  544. ((error_bits & SABRE_UEAFSR_PDRD) ?
  545. "DMA Read" :
  546. ((error_bits & SABRE_UEAFSR_PDWR) ?
  547. "DMA Write" : "???")),
  548. ((error_bits & SABRE_UEAFSR_PDTE) ?
  549. ":Translation Error" : ""));
  550. printk("SABRE%d: bytemask[%04lx] dword_offset[%lx] was_block(%d)\n",
  551. p->index,
  552. (afsr & SABRE_UEAFSR_BMSK) >> 32UL,
  553. (afsr & SABRE_UEAFSR_OFF) >> 29UL,
  554. ((afsr & SABRE_UEAFSR_BLK) ? 1 : 0));
  555. printk("SABRE%d: UE AFAR [%016lx]\n", p->index, afar);
  556. printk("SABRE%d: UE Secondary errors [", p->index);
  557. reported = 0;
  558. if (afsr & SABRE_UEAFSR_SDRD) {
  559. reported++;
  560. printk("(DMA Read)");
  561. }
  562. if (afsr & SABRE_UEAFSR_SDWR) {
  563. reported++;
  564. printk("(DMA Write)");
  565. }
  566. if (afsr & SABRE_UEAFSR_SDTE) {
  567. reported++;
  568. printk("(Translation Error)");
  569. }
  570. if (!reported)
  571. printk("(none)");
  572. printk("]\n");
  573. /* Interrogate IOMMU for error status. */
  574. sabre_check_iommu_error(p, afsr, afar);
  575. return IRQ_HANDLED;
  576. }
  577. static irqreturn_t sabre_ce_intr(int irq, void *dev_id)
  578. {
  579. struct pci_controller_info *p = dev_id;
  580. unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_CE_AFSR;
  581. unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
  582. unsigned long afsr, afar, error_bits;
  583. int reported;
  584. /* Latch error status. */
  585. afar = sabre_read(afar_reg);
  586. afsr = sabre_read(afsr_reg);
  587. /* Clear primary/secondary error status bits. */
  588. error_bits = afsr &
  589. (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
  590. SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR);
  591. if (!error_bits)
  592. return IRQ_NONE;
  593. sabre_write(afsr_reg, error_bits);
  594. /* Log the error. */
  595. printk("SABRE%d: Correctable Error, primary error type[%s]\n",
  596. p->index,
  597. ((error_bits & SABRE_CEAFSR_PDRD) ?
  598. "DMA Read" :
  599. ((error_bits & SABRE_CEAFSR_PDWR) ?
  600. "DMA Write" : "???")));
  601. /* XXX Use syndrome and afar to print out module string just like
  602. * XXX UDB CE trap handler does... -DaveM
  603. */
  604. printk("SABRE%d: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
  605. "was_block(%d)\n",
  606. p->index,
  607. (afsr & SABRE_CEAFSR_ESYND) >> 48UL,
  608. (afsr & SABRE_CEAFSR_BMSK) >> 32UL,
  609. (afsr & SABRE_CEAFSR_OFF) >> 29UL,
  610. ((afsr & SABRE_CEAFSR_BLK) ? 1 : 0));
  611. printk("SABRE%d: CE AFAR [%016lx]\n", p->index, afar);
  612. printk("SABRE%d: CE Secondary errors [", p->index);
  613. reported = 0;
  614. if (afsr & SABRE_CEAFSR_SDRD) {
  615. reported++;
  616. printk("(DMA Read)");
  617. }
  618. if (afsr & SABRE_CEAFSR_SDWR) {
  619. reported++;
  620. printk("(DMA Write)");
  621. }
  622. if (!reported)
  623. printk("(none)");
  624. printk("]\n");
  625. return IRQ_HANDLED;
  626. }
  627. static irqreturn_t sabre_pcierr_intr_other(struct pci_controller_info *p)
  628. {
  629. unsigned long csr_reg, csr, csr_error_bits;
  630. irqreturn_t ret = IRQ_NONE;
  631. u16 stat;
  632. csr_reg = p->pbm_A.controller_regs + SABRE_PCICTRL;
  633. csr = sabre_read(csr_reg);
  634. csr_error_bits =
  635. csr & SABRE_PCICTRL_SERR;
  636. if (csr_error_bits) {
  637. /* Clear the errors. */
  638. sabre_write(csr_reg, csr);
  639. /* Log 'em. */
  640. if (csr_error_bits & SABRE_PCICTRL_SERR)
  641. printk("SABRE%d: PCI SERR signal asserted.\n",
  642. p->index);
  643. ret = IRQ_HANDLED;
  644. }
  645. pci_bus_read_config_word(sabre_root_bus, 0,
  646. PCI_STATUS, &stat);
  647. if (stat & (PCI_STATUS_PARITY |
  648. PCI_STATUS_SIG_TARGET_ABORT |
  649. PCI_STATUS_REC_TARGET_ABORT |
  650. PCI_STATUS_REC_MASTER_ABORT |
  651. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  652. printk("SABRE%d: PCI bus error, PCI_STATUS[%04x]\n",
  653. p->index, stat);
  654. pci_bus_write_config_word(sabre_root_bus, 0,
  655. PCI_STATUS, 0xffff);
  656. ret = IRQ_HANDLED;
  657. }
  658. return ret;
  659. }
  660. static irqreturn_t sabre_pcierr_intr(int irq, void *dev_id)
  661. {
  662. struct pci_controller_info *p = dev_id;
  663. unsigned long afsr_reg, afar_reg;
  664. unsigned long afsr, afar, error_bits;
  665. int reported;
  666. afsr_reg = p->pbm_A.controller_regs + SABRE_PIOAFSR;
  667. afar_reg = p->pbm_A.controller_regs + SABRE_PIOAFAR;
  668. /* Latch error status. */
  669. afar = sabre_read(afar_reg);
  670. afsr = sabre_read(afsr_reg);
  671. /* Clear primary/secondary error status bits. */
  672. error_bits = afsr &
  673. (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_PTA |
  674. SABRE_PIOAFSR_PRTRY | SABRE_PIOAFSR_PPERR |
  675. SABRE_PIOAFSR_SMA | SABRE_PIOAFSR_STA |
  676. SABRE_PIOAFSR_SRTRY | SABRE_PIOAFSR_SPERR);
  677. if (!error_bits)
  678. return sabre_pcierr_intr_other(p);
  679. sabre_write(afsr_reg, error_bits);
  680. /* Log the error. */
  681. printk("SABRE%d: PCI Error, primary error type[%s]\n",
  682. p->index,
  683. (((error_bits & SABRE_PIOAFSR_PMA) ?
  684. "Master Abort" :
  685. ((error_bits & SABRE_PIOAFSR_PTA) ?
  686. "Target Abort" :
  687. ((error_bits & SABRE_PIOAFSR_PRTRY) ?
  688. "Excessive Retries" :
  689. ((error_bits & SABRE_PIOAFSR_PPERR) ?
  690. "Parity Error" : "???"))))));
  691. printk("SABRE%d: bytemask[%04lx] was_block(%d)\n",
  692. p->index,
  693. (afsr & SABRE_PIOAFSR_BMSK) >> 32UL,
  694. (afsr & SABRE_PIOAFSR_BLK) ? 1 : 0);
  695. printk("SABRE%d: PCI AFAR [%016lx]\n", p->index, afar);
  696. printk("SABRE%d: PCI Secondary errors [", p->index);
  697. reported = 0;
  698. if (afsr & SABRE_PIOAFSR_SMA) {
  699. reported++;
  700. printk("(Master Abort)");
  701. }
  702. if (afsr & SABRE_PIOAFSR_STA) {
  703. reported++;
  704. printk("(Target Abort)");
  705. }
  706. if (afsr & SABRE_PIOAFSR_SRTRY) {
  707. reported++;
  708. printk("(Excessive Retries)");
  709. }
  710. if (afsr & SABRE_PIOAFSR_SPERR) {
  711. reported++;
  712. printk("(Parity Error)");
  713. }
  714. if (!reported)
  715. printk("(none)");
  716. printk("]\n");
  717. /* For the error types shown, scan both PCI buses for devices
  718. * which have logged that error type.
  719. */
  720. /* If we see a Target Abort, this could be the result of an
  721. * IOMMU translation error of some sort. It is extremely
  722. * useful to log this information as usually it indicates
  723. * a bug in the IOMMU support code or a PCI device driver.
  724. */
  725. if (error_bits & (SABRE_PIOAFSR_PTA | SABRE_PIOAFSR_STA)) {
  726. sabre_check_iommu_error(p, afsr, afar);
  727. pci_scan_for_target_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
  728. }
  729. if (error_bits & (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_SMA))
  730. pci_scan_for_master_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
  731. /* For excessive retries, SABRE/PBM will abort the device
  732. * and there is no way to specifically check for excessive
  733. * retries in the config space status registers. So what
  734. * we hope is that we'll catch it via the master/target
  735. * abort events.
  736. */
  737. if (error_bits & (SABRE_PIOAFSR_PPERR | SABRE_PIOAFSR_SPERR))
  738. pci_scan_for_parity_error(p, &p->pbm_A, p->pbm_A.pci_bus);
  739. return IRQ_HANDLED;
  740. }
  741. static void sabre_register_error_handlers(struct pci_controller_info *p)
  742. {
  743. struct pci_pbm_info *pbm = &p->pbm_A; /* arbitrary */
  744. struct device_node *dp = pbm->prom_node;
  745. struct of_device *op;
  746. unsigned long base = pbm->controller_regs;
  747. u64 tmp;
  748. if (pbm->chip_type == PBM_CHIP_TYPE_SABRE)
  749. dp = dp->parent;
  750. op = of_find_device_by_node(dp);
  751. if (!op)
  752. return;
  753. /* Sabre/Hummingbird IRQ property layout is:
  754. * 0: PCI ERR
  755. * 1: UE ERR
  756. * 2: CE ERR
  757. * 3: POWER FAIL
  758. */
  759. if (op->num_irqs < 4)
  760. return;
  761. /* We clear the error bits in the appropriate AFSR before
  762. * registering the handler so that we don't get spurious
  763. * interrupts.
  764. */
  765. sabre_write(base + SABRE_UE_AFSR,
  766. (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
  767. SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
  768. SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE));
  769. request_irq(op->irqs[1], sabre_ue_intr, IRQF_SHARED, "SABRE UE", p);
  770. sabre_write(base + SABRE_CE_AFSR,
  771. (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
  772. SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR));
  773. request_irq(op->irqs[2], sabre_ce_intr, IRQF_SHARED, "SABRE CE", p);
  774. request_irq(op->irqs[0], sabre_pcierr_intr, IRQF_SHARED,
  775. "SABRE PCIERR", p);
  776. tmp = sabre_read(base + SABRE_PCICTRL);
  777. tmp |= SABRE_PCICTRL_ERREN;
  778. sabre_write(base + SABRE_PCICTRL, tmp);
  779. }
  780. static void apb_init(struct pci_controller_info *p, struct pci_bus *sabre_bus)
  781. {
  782. struct pci_dev *pdev;
  783. list_for_each_entry(pdev, &sabre_bus->devices, bus_list) {
  784. if (pdev->vendor == PCI_VENDOR_ID_SUN &&
  785. pdev->device == PCI_DEVICE_ID_SUN_SIMBA) {
  786. u16 word16;
  787. pci_read_config_word(pdev, PCI_COMMAND, &word16);
  788. word16 |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
  789. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
  790. PCI_COMMAND_IO;
  791. pci_write_config_word(pdev, PCI_COMMAND, word16);
  792. /* Status register bits are "write 1 to clear". */
  793. pci_write_config_word(pdev, PCI_STATUS, 0xffff);
  794. pci_write_config_word(pdev, PCI_SEC_STATUS, 0xffff);
  795. /* Use a primary/seconday latency timer value
  796. * of 64.
  797. */
  798. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 64);
  799. pci_write_config_byte(pdev, PCI_SEC_LATENCY_TIMER, 64);
  800. /* Enable reporting/forwarding of master aborts,
  801. * parity, and SERR.
  802. */
  803. pci_write_config_byte(pdev, PCI_BRIDGE_CONTROL,
  804. (PCI_BRIDGE_CTL_PARITY |
  805. PCI_BRIDGE_CTL_SERR |
  806. PCI_BRIDGE_CTL_MASTER_ABORT));
  807. }
  808. }
  809. }
  810. static void sabre_scan_bus(struct pci_controller_info *p)
  811. {
  812. static int once;
  813. struct pci_bus *pbus;
  814. /* The APB bridge speaks to the Sabre host PCI bridge
  815. * at 66Mhz, but the front side of APB runs at 33Mhz
  816. * for both segments.
  817. */
  818. p->pbm_A.is_66mhz_capable = 0;
  819. /* This driver has not been verified to handle
  820. * multiple SABREs yet, so trap this.
  821. *
  822. * Also note that the SABRE host bridge is hardwired
  823. * to live at bus 0.
  824. */
  825. if (once != 0) {
  826. prom_printf("SABRE: Multiple controllers unsupported.\n");
  827. prom_halt();
  828. }
  829. once++;
  830. pbus = pci_scan_one_pbm(&p->pbm_A);
  831. if (!pbus)
  832. return;
  833. sabre_root_bus = pbus;
  834. apb_init(p, pbus);
  835. sabre_register_error_handlers(p);
  836. }
  837. static void sabre_iommu_init(struct pci_controller_info *p,
  838. int tsbsize, unsigned long dvma_offset,
  839. u32 dma_mask)
  840. {
  841. struct pci_iommu *iommu = p->pbm_A.iommu;
  842. unsigned long i;
  843. u64 control;
  844. /* Register addresses. */
  845. iommu->iommu_control = p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL;
  846. iommu->iommu_tsbbase = p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE;
  847. iommu->iommu_flush = p->pbm_A.controller_regs + SABRE_IOMMU_FLUSH;
  848. iommu->write_complete_reg = p->pbm_A.controller_regs + SABRE_WRSYNC;
  849. /* Sabre's IOMMU lacks ctx flushing. */
  850. iommu->iommu_ctxflush = 0;
  851. /* Invalidate TLB Entries. */
  852. control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
  853. control |= SABRE_IOMMUCTRL_DENAB;
  854. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
  855. for(i = 0; i < 16; i++) {
  856. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TAG + (i * 8UL), 0);
  857. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_DATA + (i * 8UL), 0);
  858. }
  859. /* Leave diag mode enabled for full-flushing done
  860. * in pci_iommu.c
  861. */
  862. pci_iommu_table_init(iommu, tsbsize * 1024 * 8, dvma_offset, dma_mask);
  863. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE,
  864. __pa(iommu->page_table));
  865. control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
  866. control &= ~(SABRE_IOMMUCTRL_TSBSZ | SABRE_IOMMUCTRL_TBWSZ);
  867. control |= SABRE_IOMMUCTRL_ENAB;
  868. switch(tsbsize) {
  869. case 64:
  870. control |= SABRE_IOMMU_TSBSZ_64K;
  871. break;
  872. case 128:
  873. control |= SABRE_IOMMU_TSBSZ_128K;
  874. break;
  875. default:
  876. prom_printf("iommu_init: Illegal TSB size %d\n", tsbsize);
  877. prom_halt();
  878. break;
  879. }
  880. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
  881. }
  882. static void sabre_pbm_init(struct pci_controller_info *p, struct device_node *dp)
  883. {
  884. struct pci_pbm_info *pbm;
  885. pbm = &p->pbm_A;
  886. pbm->name = dp->full_name;
  887. printk("%s: SABRE PCI Bus Module\n", pbm->name);
  888. pbm->chip_type = PBM_CHIP_TYPE_SABRE;
  889. pbm->parent = p;
  890. pbm->prom_node = dp;
  891. pbm->pci_first_slot = 1;
  892. pbm->pci_first_busno = p->pci_first_busno;
  893. pbm->pci_last_busno = p->pci_last_busno;
  894. pci_determine_mem_io_space(pbm);
  895. }
  896. void sabre_init(struct device_node *dp, char *model_name)
  897. {
  898. struct linux_prom64_registers *pr_regs;
  899. struct pci_controller_info *p;
  900. struct pci_iommu *iommu;
  901. int tsbsize;
  902. u32 *busrange;
  903. u32 *vdma;
  904. u32 upa_portid, dma_mask;
  905. u64 clear_irq;
  906. hummingbird_p = 0;
  907. if (!strcmp(model_name, "pci108e,a001"))
  908. hummingbird_p = 1;
  909. else if (!strcmp(model_name, "SUNW,sabre")) {
  910. const char *compat = of_get_property(dp, "compatible", NULL);
  911. if (compat && !strcmp(compat, "pci108e,a001"))
  912. hummingbird_p = 1;
  913. if (!hummingbird_p) {
  914. struct device_node *dp;
  915. /* Of course, Sun has to encode things a thousand
  916. * different ways, inconsistently.
  917. */
  918. cpu_find_by_instance(0, &dp, NULL);
  919. if (!strcmp(dp->name, "SUNW,UltraSPARC-IIe"))
  920. hummingbird_p = 1;
  921. }
  922. }
  923. p = kzalloc(sizeof(*p), GFP_ATOMIC);
  924. if (!p) {
  925. prom_printf("SABRE: Error, kmalloc(pci_controller_info) failed.\n");
  926. prom_halt();
  927. }
  928. iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
  929. if (!iommu) {
  930. prom_printf("SABRE: Error, kmalloc(pci_iommu) failed.\n");
  931. prom_halt();
  932. }
  933. p->pbm_A.iommu = iommu;
  934. upa_portid = of_getintprop_default(dp, "upa-portid", 0xff);
  935. p->next = pci_controller_root;
  936. pci_controller_root = p;
  937. p->pbm_A.portid = upa_portid;
  938. p->index = pci_num_controllers++;
  939. p->scan_bus = sabre_scan_bus;
  940. p->pci_ops = &sabre_ops;
  941. /*
  942. * Map in SABRE register set and report the presence of this SABRE.
  943. */
  944. pr_regs = of_get_property(dp, "reg", NULL);
  945. /*
  946. * First REG in property is base of entire SABRE register space.
  947. */
  948. p->pbm_A.controller_regs = pr_regs[0].phys_addr;
  949. /* Clear interrupts */
  950. /* PCI first */
  951. for (clear_irq = SABRE_ICLR_A_SLOT0; clear_irq < SABRE_ICLR_B_SLOT0 + 0x80; clear_irq += 8)
  952. sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
  953. /* Then OBIO */
  954. for (clear_irq = SABRE_ICLR_SCSI; clear_irq < SABRE_ICLR_SCSI + 0x80; clear_irq += 8)
  955. sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
  956. /* Error interrupts are enabled later after the bus scan. */
  957. sabre_write(p->pbm_A.controller_regs + SABRE_PCICTRL,
  958. (SABRE_PCICTRL_MRLEN | SABRE_PCICTRL_SERR |
  959. SABRE_PCICTRL_ARBPARK | SABRE_PCICTRL_AEN));
  960. /* Now map in PCI config space for entire SABRE. */
  961. p->pbm_A.config_space =
  962. (p->pbm_A.controller_regs + SABRE_CONFIGSPACE);
  963. vdma = of_get_property(dp, "virtual-dma", NULL);
  964. dma_mask = vdma[0];
  965. switch(vdma[1]) {
  966. case 0x20000000:
  967. dma_mask |= 0x1fffffff;
  968. tsbsize = 64;
  969. break;
  970. case 0x40000000:
  971. dma_mask |= 0x3fffffff;
  972. tsbsize = 128;
  973. break;
  974. case 0x80000000:
  975. dma_mask |= 0x7fffffff;
  976. tsbsize = 128;
  977. break;
  978. default:
  979. prom_printf("SABRE: strange virtual-dma size.\n");
  980. prom_halt();
  981. }
  982. sabre_iommu_init(p, tsbsize, vdma[0], dma_mask);
  983. busrange = of_get_property(dp, "bus-range", NULL);
  984. p->pci_first_busno = busrange[0];
  985. p->pci_last_busno = busrange[1];
  986. /*
  987. * Look for APB underneath.
  988. */
  989. sabre_pbm_init(p, dp);
  990. }