pci_sabre.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597
  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 "pci_impl.h"
  21. #include "iommu_common.h"
  22. /* All SABRE registers are 64-bits. The following accessor
  23. * routines are how they are accessed. The REG parameter
  24. * is a physical address.
  25. */
  26. #define sabre_read(__reg) \
  27. ({ u64 __ret; \
  28. __asm__ __volatile__("ldxa [%1] %2, %0" \
  29. : "=r" (__ret) \
  30. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  31. : "memory"); \
  32. __ret; \
  33. })
  34. #define sabre_write(__reg, __val) \
  35. __asm__ __volatile__("stxa %0, [%1] %2" \
  36. : /* no outputs */ \
  37. : "r" (__val), "r" (__reg), \
  38. "i" (ASI_PHYS_BYPASS_EC_E) \
  39. : "memory")
  40. /* SABRE PCI controller register offsets and definitions. */
  41. #define SABRE_UE_AFSR 0x0030UL
  42. #define SABRE_UEAFSR_PDRD 0x4000000000000000UL /* Primary PCI DMA Read */
  43. #define SABRE_UEAFSR_PDWR 0x2000000000000000UL /* Primary PCI DMA Write */
  44. #define SABRE_UEAFSR_SDRD 0x0800000000000000UL /* Secondary PCI DMA Read */
  45. #define SABRE_UEAFSR_SDWR 0x0400000000000000UL /* Secondary PCI DMA Write */
  46. #define SABRE_UEAFSR_SDTE 0x0200000000000000UL /* Secondary DMA Translation Error */
  47. #define SABRE_UEAFSR_PDTE 0x0100000000000000UL /* Primary DMA Translation Error */
  48. #define SABRE_UEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask */
  49. #define SABRE_UEAFSR_OFF 0x00000000e0000000UL /* Offset (AFAR bits [5:3] */
  50. #define SABRE_UEAFSR_BLK 0x0000000000800000UL /* Was block operation */
  51. #define SABRE_UECE_AFAR 0x0038UL
  52. #define SABRE_CE_AFSR 0x0040UL
  53. #define SABRE_CEAFSR_PDRD 0x4000000000000000UL /* Primary PCI DMA Read */
  54. #define SABRE_CEAFSR_PDWR 0x2000000000000000UL /* Primary PCI DMA Write */
  55. #define SABRE_CEAFSR_SDRD 0x0800000000000000UL /* Secondary PCI DMA Read */
  56. #define SABRE_CEAFSR_SDWR 0x0400000000000000UL /* Secondary PCI DMA Write */
  57. #define SABRE_CEAFSR_ESYND 0x00ff000000000000UL /* ECC Syndrome */
  58. #define SABRE_CEAFSR_BMSK 0x0000ffff00000000UL /* Bytemask */
  59. #define SABRE_CEAFSR_OFF 0x00000000e0000000UL /* Offset */
  60. #define SABRE_CEAFSR_BLK 0x0000000000800000UL /* Was block operation */
  61. #define SABRE_UECE_AFAR_ALIAS 0x0048UL /* Aliases to 0x0038 */
  62. #define SABRE_IOMMU_CONTROL 0x0200UL
  63. #define SABRE_IOMMUCTRL_ERRSTS 0x0000000006000000UL /* Error status bits */
  64. #define SABRE_IOMMUCTRL_ERR 0x0000000001000000UL /* Error present in IOTLB */
  65. #define SABRE_IOMMUCTRL_LCKEN 0x0000000000800000UL /* IOTLB lock enable */
  66. #define SABRE_IOMMUCTRL_LCKPTR 0x0000000000780000UL /* IOTLB lock pointer */
  67. #define SABRE_IOMMUCTRL_TSBSZ 0x0000000000070000UL /* TSB Size */
  68. #define SABRE_IOMMU_TSBSZ_1K 0x0000000000000000
  69. #define SABRE_IOMMU_TSBSZ_2K 0x0000000000010000
  70. #define SABRE_IOMMU_TSBSZ_4K 0x0000000000020000
  71. #define SABRE_IOMMU_TSBSZ_8K 0x0000000000030000
  72. #define SABRE_IOMMU_TSBSZ_16K 0x0000000000040000
  73. #define SABRE_IOMMU_TSBSZ_32K 0x0000000000050000
  74. #define SABRE_IOMMU_TSBSZ_64K 0x0000000000060000
  75. #define SABRE_IOMMU_TSBSZ_128K 0x0000000000070000
  76. #define SABRE_IOMMUCTRL_TBWSZ 0x0000000000000004UL /* TSB assumed page size */
  77. #define SABRE_IOMMUCTRL_DENAB 0x0000000000000002UL /* Diagnostic Mode Enable */
  78. #define SABRE_IOMMUCTRL_ENAB 0x0000000000000001UL /* IOMMU Enable */
  79. #define SABRE_IOMMU_TSBBASE 0x0208UL
  80. #define SABRE_IOMMU_FLUSH 0x0210UL
  81. #define SABRE_IMAP_A_SLOT0 0x0c00UL
  82. #define SABRE_IMAP_B_SLOT0 0x0c20UL
  83. #define SABRE_IMAP_SCSI 0x1000UL
  84. #define SABRE_IMAP_ETH 0x1008UL
  85. #define SABRE_IMAP_BPP 0x1010UL
  86. #define SABRE_IMAP_AU_REC 0x1018UL
  87. #define SABRE_IMAP_AU_PLAY 0x1020UL
  88. #define SABRE_IMAP_PFAIL 0x1028UL
  89. #define SABRE_IMAP_KMS 0x1030UL
  90. #define SABRE_IMAP_FLPY 0x1038UL
  91. #define SABRE_IMAP_SHW 0x1040UL
  92. #define SABRE_IMAP_KBD 0x1048UL
  93. #define SABRE_IMAP_MS 0x1050UL
  94. #define SABRE_IMAP_SER 0x1058UL
  95. #define SABRE_IMAP_UE 0x1070UL
  96. #define SABRE_IMAP_CE 0x1078UL
  97. #define SABRE_IMAP_PCIERR 0x1080UL
  98. #define SABRE_IMAP_GFX 0x1098UL
  99. #define SABRE_IMAP_EUPA 0x10a0UL
  100. #define SABRE_ICLR_A_SLOT0 0x1400UL
  101. #define SABRE_ICLR_B_SLOT0 0x1480UL
  102. #define SABRE_ICLR_SCSI 0x1800UL
  103. #define SABRE_ICLR_ETH 0x1808UL
  104. #define SABRE_ICLR_BPP 0x1810UL
  105. #define SABRE_ICLR_AU_REC 0x1818UL
  106. #define SABRE_ICLR_AU_PLAY 0x1820UL
  107. #define SABRE_ICLR_PFAIL 0x1828UL
  108. #define SABRE_ICLR_KMS 0x1830UL
  109. #define SABRE_ICLR_FLPY 0x1838UL
  110. #define SABRE_ICLR_SHW 0x1840UL
  111. #define SABRE_ICLR_KBD 0x1848UL
  112. #define SABRE_ICLR_MS 0x1850UL
  113. #define SABRE_ICLR_SER 0x1858UL
  114. #define SABRE_ICLR_UE 0x1870UL
  115. #define SABRE_ICLR_CE 0x1878UL
  116. #define SABRE_ICLR_PCIERR 0x1880UL
  117. #define SABRE_WRSYNC 0x1c20UL
  118. #define SABRE_PCICTRL 0x2000UL
  119. #define SABRE_PCICTRL_MRLEN 0x0000001000000000UL /* Use MemoryReadLine for block loads/stores */
  120. #define SABRE_PCICTRL_SERR 0x0000000400000000UL /* Set when SERR asserted on PCI bus */
  121. #define SABRE_PCICTRL_ARBPARK 0x0000000000200000UL /* Bus Parking 0=Ultra-IIi 1=prev-bus-owner */
  122. #define SABRE_PCICTRL_CPUPRIO 0x0000000000100000UL /* Ultra-IIi granted every other bus cycle */
  123. #define SABRE_PCICTRL_ARBPRIO 0x00000000000f0000UL /* Slot which is granted every other bus cycle */
  124. #define SABRE_PCICTRL_ERREN 0x0000000000000100UL /* PCI Error Interrupt Enable */
  125. #define SABRE_PCICTRL_RTRYWE 0x0000000000000080UL /* DMA Flow Control 0=wait-if-possible 1=retry */
  126. #define SABRE_PCICTRL_AEN 0x000000000000000fUL /* Slot PCI arbitration enables */
  127. #define SABRE_PIOAFSR 0x2010UL
  128. #define SABRE_PIOAFSR_PMA 0x8000000000000000UL /* Primary Master Abort */
  129. #define SABRE_PIOAFSR_PTA 0x4000000000000000UL /* Primary Target Abort */
  130. #define SABRE_PIOAFSR_PRTRY 0x2000000000000000UL /* Primary Excessive Retries */
  131. #define SABRE_PIOAFSR_PPERR 0x1000000000000000UL /* Primary Parity Error */
  132. #define SABRE_PIOAFSR_SMA 0x0800000000000000UL /* Secondary Master Abort */
  133. #define SABRE_PIOAFSR_STA 0x0400000000000000UL /* Secondary Target Abort */
  134. #define SABRE_PIOAFSR_SRTRY 0x0200000000000000UL /* Secondary Excessive Retries */
  135. #define SABRE_PIOAFSR_SPERR 0x0100000000000000UL /* Secondary Parity Error */
  136. #define SABRE_PIOAFSR_BMSK 0x0000ffff00000000UL /* Byte Mask */
  137. #define SABRE_PIOAFSR_BLK 0x0000000080000000UL /* Was Block Operation */
  138. #define SABRE_PIOAFAR 0x2018UL
  139. #define SABRE_PCIDIAG 0x2020UL
  140. #define SABRE_PCIDIAG_DRTRY 0x0000000000000040UL /* Disable PIO Retry Limit */
  141. #define SABRE_PCIDIAG_IPAPAR 0x0000000000000008UL /* Invert PIO Address Parity */
  142. #define SABRE_PCIDIAG_IPDPAR 0x0000000000000004UL /* Invert PIO Data Parity */
  143. #define SABRE_PCIDIAG_IDDPAR 0x0000000000000002UL /* Invert DMA Data Parity */
  144. #define SABRE_PCIDIAG_ELPBK 0x0000000000000001UL /* Loopback Enable - not supported */
  145. #define SABRE_PCITASR 0x2028UL
  146. #define SABRE_PCITASR_EF 0x0000000000000080UL /* Respond to 0xe0000000-0xffffffff */
  147. #define SABRE_PCITASR_CD 0x0000000000000040UL /* Respond to 0xc0000000-0xdfffffff */
  148. #define SABRE_PCITASR_AB 0x0000000000000020UL /* Respond to 0xa0000000-0xbfffffff */
  149. #define SABRE_PCITASR_89 0x0000000000000010UL /* Respond to 0x80000000-0x9fffffff */
  150. #define SABRE_PCITASR_67 0x0000000000000008UL /* Respond to 0x60000000-0x7fffffff */
  151. #define SABRE_PCITASR_45 0x0000000000000004UL /* Respond to 0x40000000-0x5fffffff */
  152. #define SABRE_PCITASR_23 0x0000000000000002UL /* Respond to 0x20000000-0x3fffffff */
  153. #define SABRE_PCITASR_01 0x0000000000000001UL /* Respond to 0x00000000-0x1fffffff */
  154. #define SABRE_PIOBUF_DIAG 0x5000UL
  155. #define SABRE_DMABUF_DIAGLO 0x5100UL
  156. #define SABRE_DMABUF_DIAGHI 0x51c0UL
  157. #define SABRE_IMAP_GFX_ALIAS 0x6000UL /* Aliases to 0x1098 */
  158. #define SABRE_IMAP_EUPA_ALIAS 0x8000UL /* Aliases to 0x10a0 */
  159. #define SABRE_IOMMU_VADIAG 0xa400UL
  160. #define SABRE_IOMMU_TCDIAG 0xa408UL
  161. #define SABRE_IOMMU_TAG 0xa580UL
  162. #define SABRE_IOMMUTAG_ERRSTS 0x0000000001800000UL /* Error status bits */
  163. #define SABRE_IOMMUTAG_ERR 0x0000000000400000UL /* Error present */
  164. #define SABRE_IOMMUTAG_WRITE 0x0000000000200000UL /* Page is writable */
  165. #define SABRE_IOMMUTAG_STREAM 0x0000000000100000UL /* Streamable bit - unused */
  166. #define SABRE_IOMMUTAG_SIZE 0x0000000000080000UL /* 0=8k 1=16k */
  167. #define SABRE_IOMMUTAG_VPN 0x000000000007ffffUL /* Virtual Page Number [31:13] */
  168. #define SABRE_IOMMU_DATA 0xa600UL
  169. #define SABRE_IOMMUDATA_VALID 0x0000000040000000UL /* Valid */
  170. #define SABRE_IOMMUDATA_USED 0x0000000020000000UL /* Used (for LRU algorithm) */
  171. #define SABRE_IOMMUDATA_CACHE 0x0000000010000000UL /* Cacheable */
  172. #define SABRE_IOMMUDATA_PPN 0x00000000001fffffUL /* Physical Page Number [33:13] */
  173. #define SABRE_PCI_IRQSTATE 0xa800UL
  174. #define SABRE_OBIO_IRQSTATE 0xa808UL
  175. #define SABRE_FFBCFG 0xf000UL
  176. #define SABRE_FFBCFG_SPRQS 0x000000000f000000 /* Slave P_RQST queue size */
  177. #define SABRE_FFBCFG_ONEREAD 0x0000000000004000 /* Slave supports one outstanding read */
  178. #define SABRE_MCCTRL0 0xf010UL
  179. #define SABRE_MCCTRL0_RENAB 0x0000000080000000 /* Refresh Enable */
  180. #define SABRE_MCCTRL0_EENAB 0x0000000010000000 /* Enable all ECC functions */
  181. #define SABRE_MCCTRL0_11BIT 0x0000000000001000 /* Enable 11-bit column addressing */
  182. #define SABRE_MCCTRL0_DPP 0x0000000000000f00 /* DIMM Pair Present Bits */
  183. #define SABRE_MCCTRL0_RINTVL 0x00000000000000ff /* Refresh Interval */
  184. #define SABRE_MCCTRL1 0xf018UL
  185. #define SABRE_MCCTRL1_AMDC 0x0000000038000000 /* Advance Memdata Clock */
  186. #define SABRE_MCCTRL1_ARDC 0x0000000007000000 /* Advance DRAM Read Data Clock */
  187. #define SABRE_MCCTRL1_CSR 0x0000000000e00000 /* CAS to RAS delay for CBR refresh */
  188. #define SABRE_MCCTRL1_CASRW 0x00000000001c0000 /* CAS length for read/write */
  189. #define SABRE_MCCTRL1_RCD 0x0000000000038000 /* RAS to CAS delay */
  190. #define SABRE_MCCTRL1_CP 0x0000000000007000 /* CAS Precharge */
  191. #define SABRE_MCCTRL1_RP 0x0000000000000e00 /* RAS Precharge */
  192. #define SABRE_MCCTRL1_RAS 0x00000000000001c0 /* Length of RAS for refresh */
  193. #define SABRE_MCCTRL1_CASRW2 0x0000000000000038 /* Must be same as CASRW */
  194. #define SABRE_MCCTRL1_RSC 0x0000000000000007 /* RAS after CAS hold time */
  195. #define SABRE_RESETCTRL 0xf020UL
  196. #define SABRE_CONFIGSPACE 0x001000000UL
  197. #define SABRE_IOSPACE 0x002000000UL
  198. #define SABRE_IOSPACE_SIZE 0x000ffffffUL
  199. #define SABRE_MEMSPACE 0x100000000UL
  200. #define SABRE_MEMSPACE_SIZE 0x07fffffffUL
  201. /* UltraSparc-IIi Programmer's Manual, page 325, PCI
  202. * configuration space address format:
  203. *
  204. * 32 24 23 16 15 11 10 8 7 2 1 0
  205. * ---------------------------------------------------------
  206. * |0 0 0 0 0 0 0 0 1| bus | device | function | reg | 0 0 |
  207. * ---------------------------------------------------------
  208. */
  209. #define SABRE_CONFIG_BASE(PBM) \
  210. ((PBM)->config_space | (1UL << 24))
  211. #define SABRE_CONFIG_ENCODE(BUS, DEVFN, REG) \
  212. (((unsigned long)(BUS) << 16) | \
  213. ((unsigned long)(DEVFN) << 8) | \
  214. ((unsigned long)(REG)))
  215. static int hummingbird_p;
  216. static struct pci_bus *sabre_root_bus;
  217. static void *sabre_pci_config_mkaddr(struct pci_pbm_info *pbm,
  218. unsigned char bus,
  219. unsigned int devfn,
  220. int where)
  221. {
  222. if (!pbm)
  223. return NULL;
  224. return (void *)
  225. (SABRE_CONFIG_BASE(pbm) |
  226. SABRE_CONFIG_ENCODE(bus, devfn, where));
  227. }
  228. static int sabre_out_of_range(unsigned char devfn)
  229. {
  230. if (hummingbird_p)
  231. return 0;
  232. return (((PCI_SLOT(devfn) == 0) && (PCI_FUNC(devfn) > 0)) ||
  233. ((PCI_SLOT(devfn) == 1) && (PCI_FUNC(devfn) > 1)) ||
  234. (PCI_SLOT(devfn) > 1));
  235. }
  236. static int __sabre_out_of_range(struct pci_pbm_info *pbm,
  237. unsigned char bus,
  238. unsigned char devfn)
  239. {
  240. if (hummingbird_p)
  241. return 0;
  242. return ((pbm->parent == 0) ||
  243. ((pbm == &pbm->parent->pbm_B) &&
  244. (bus == pbm->pci_first_busno) &&
  245. PCI_SLOT(devfn) > 8) ||
  246. ((pbm == &pbm->parent->pbm_A) &&
  247. (bus == pbm->pci_first_busno) &&
  248. PCI_SLOT(devfn) > 8));
  249. }
  250. static int __sabre_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  251. int where, int size, u32 *value)
  252. {
  253. struct pci_pbm_info *pbm = bus_dev->sysdata;
  254. unsigned char bus = bus_dev->number;
  255. u32 *addr;
  256. u16 tmp16;
  257. u8 tmp8;
  258. switch (size) {
  259. case 1:
  260. *value = 0xff;
  261. break;
  262. case 2:
  263. *value = 0xffff;
  264. break;
  265. case 4:
  266. *value = 0xffffffff;
  267. break;
  268. }
  269. addr = sabre_pci_config_mkaddr(pbm, bus, devfn, where);
  270. if (!addr)
  271. return PCIBIOS_SUCCESSFUL;
  272. if (__sabre_out_of_range(pbm, bus, devfn))
  273. return PCIBIOS_SUCCESSFUL;
  274. switch (size) {
  275. case 1:
  276. pci_config_read8((u8 *) addr, &tmp8);
  277. *value = tmp8;
  278. break;
  279. case 2:
  280. if (where & 0x01) {
  281. printk("pci_read_config_word: misaligned reg [%x]\n",
  282. where);
  283. return PCIBIOS_SUCCESSFUL;
  284. }
  285. pci_config_read16((u16 *) addr, &tmp16);
  286. *value = tmp16;
  287. break;
  288. case 4:
  289. if (where & 0x03) {
  290. printk("pci_read_config_dword: misaligned reg [%x]\n",
  291. where);
  292. return PCIBIOS_SUCCESSFUL;
  293. }
  294. pci_config_read32(addr, value);
  295. break;
  296. }
  297. return PCIBIOS_SUCCESSFUL;
  298. }
  299. static int sabre_read_pci_cfg(struct pci_bus *bus, unsigned int devfn,
  300. int where, int size, u32 *value)
  301. {
  302. if (!bus->number && sabre_out_of_range(devfn)) {
  303. switch (size) {
  304. case 1:
  305. *value = 0xff;
  306. break;
  307. case 2:
  308. *value = 0xffff;
  309. break;
  310. case 4:
  311. *value = 0xffffffff;
  312. break;
  313. }
  314. return PCIBIOS_SUCCESSFUL;
  315. }
  316. if (bus->number || PCI_SLOT(devfn))
  317. return __sabre_read_pci_cfg(bus, devfn, where, size, value);
  318. /* When accessing PCI config space of the PCI controller itself (bus
  319. * 0, device slot 0, function 0) there are restrictions. Each
  320. * register must be accessed as it's natural size. Thus, for example
  321. * the Vendor ID must be accessed as a 16-bit quantity.
  322. */
  323. switch (size) {
  324. case 1:
  325. if (where < 8) {
  326. u32 tmp32;
  327. u16 tmp16;
  328. __sabre_read_pci_cfg(bus, devfn, where & ~1, 2, &tmp32);
  329. tmp16 = (u16) tmp32;
  330. if (where & 1)
  331. *value = tmp16 >> 8;
  332. else
  333. *value = tmp16 & 0xff;
  334. } else
  335. return __sabre_read_pci_cfg(bus, devfn, where, 1, value);
  336. break;
  337. case 2:
  338. if (where < 8)
  339. return __sabre_read_pci_cfg(bus, devfn, where, 2, value);
  340. else {
  341. u32 tmp32;
  342. u8 tmp8;
  343. __sabre_read_pci_cfg(bus, devfn, where, 1, &tmp32);
  344. tmp8 = (u8) tmp32;
  345. *value = tmp8;
  346. __sabre_read_pci_cfg(bus, devfn, where + 1, 1, &tmp32);
  347. tmp8 = (u8) tmp32;
  348. *value |= tmp8 << 8;
  349. }
  350. break;
  351. case 4: {
  352. u32 tmp32;
  353. u16 tmp16;
  354. sabre_read_pci_cfg(bus, devfn, where, 2, &tmp32);
  355. tmp16 = (u16) tmp32;
  356. *value = tmp16;
  357. sabre_read_pci_cfg(bus, devfn, where + 2, 2, &tmp32);
  358. tmp16 = (u16) tmp32;
  359. *value |= tmp16 << 16;
  360. break;
  361. }
  362. }
  363. return PCIBIOS_SUCCESSFUL;
  364. }
  365. static int __sabre_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  366. int where, int size, u32 value)
  367. {
  368. struct pci_pbm_info *pbm = bus_dev->sysdata;
  369. unsigned char bus = bus_dev->number;
  370. u32 *addr;
  371. addr = sabre_pci_config_mkaddr(pbm, bus, devfn, where);
  372. if (!addr)
  373. return PCIBIOS_SUCCESSFUL;
  374. if (__sabre_out_of_range(pbm, bus, devfn))
  375. return PCIBIOS_SUCCESSFUL;
  376. switch (size) {
  377. case 1:
  378. pci_config_write8((u8 *) addr, value);
  379. break;
  380. case 2:
  381. if (where & 0x01) {
  382. printk("pci_write_config_word: misaligned reg [%x]\n",
  383. where);
  384. return PCIBIOS_SUCCESSFUL;
  385. }
  386. pci_config_write16((u16 *) addr, value);
  387. break;
  388. case 4:
  389. if (where & 0x03) {
  390. printk("pci_write_config_dword: misaligned reg [%x]\n",
  391. where);
  392. return PCIBIOS_SUCCESSFUL;
  393. }
  394. pci_config_write32(addr, value);
  395. break;
  396. }
  397. return PCIBIOS_SUCCESSFUL;
  398. }
  399. static int sabre_write_pci_cfg(struct pci_bus *bus, unsigned int devfn,
  400. int where, int size, u32 value)
  401. {
  402. if (bus->number)
  403. return __sabre_write_pci_cfg(bus, devfn, where, size, value);
  404. if (sabre_out_of_range(devfn))
  405. return PCIBIOS_SUCCESSFUL;
  406. switch (size) {
  407. case 1:
  408. if (where < 8) {
  409. u32 tmp32;
  410. u16 tmp16;
  411. __sabre_read_pci_cfg(bus, devfn, where & ~1, 2, &tmp32);
  412. tmp16 = (u16) tmp32;
  413. if (where & 1) {
  414. value &= 0x00ff;
  415. value |= tmp16 << 8;
  416. } else {
  417. value &= 0xff00;
  418. value |= tmp16;
  419. }
  420. tmp32 = (u32) tmp16;
  421. return __sabre_write_pci_cfg(bus, devfn, where & ~1, 2, tmp32);
  422. } else
  423. return __sabre_write_pci_cfg(bus, devfn, where, 1, value);
  424. break;
  425. case 2:
  426. if (where < 8)
  427. return __sabre_write_pci_cfg(bus, devfn, where, 2, value);
  428. else {
  429. __sabre_write_pci_cfg(bus, devfn, where, 1, value & 0xff);
  430. __sabre_write_pci_cfg(bus, devfn, where + 1, 1, value >> 8);
  431. }
  432. break;
  433. case 4:
  434. sabre_write_pci_cfg(bus, devfn, where, 2, value & 0xffff);
  435. sabre_write_pci_cfg(bus, devfn, where + 2, 2, value >> 16);
  436. break;
  437. }
  438. return PCIBIOS_SUCCESSFUL;
  439. }
  440. static struct pci_ops sabre_ops = {
  441. .read = sabre_read_pci_cfg,
  442. .write = sabre_write_pci_cfg,
  443. };
  444. static unsigned long sabre_pcislot_imap_offset(unsigned long ino)
  445. {
  446. unsigned int bus = (ino & 0x10) >> 4;
  447. unsigned int slot = (ino & 0x0c) >> 2;
  448. if (bus == 0)
  449. return SABRE_IMAP_A_SLOT0 + (slot * 8);
  450. else
  451. return SABRE_IMAP_B_SLOT0 + (slot * 8);
  452. }
  453. static unsigned long __onboard_imap_off[] = {
  454. /*0x20*/ SABRE_IMAP_SCSI,
  455. /*0x21*/ SABRE_IMAP_ETH,
  456. /*0x22*/ SABRE_IMAP_BPP,
  457. /*0x23*/ SABRE_IMAP_AU_REC,
  458. /*0x24*/ SABRE_IMAP_AU_PLAY,
  459. /*0x25*/ SABRE_IMAP_PFAIL,
  460. /*0x26*/ SABRE_IMAP_KMS,
  461. /*0x27*/ SABRE_IMAP_FLPY,
  462. /*0x28*/ SABRE_IMAP_SHW,
  463. /*0x29*/ SABRE_IMAP_KBD,
  464. /*0x2a*/ SABRE_IMAP_MS,
  465. /*0x2b*/ SABRE_IMAP_SER,
  466. /*0x2c*/ 0 /* reserved */,
  467. /*0x2d*/ 0 /* reserved */,
  468. /*0x2e*/ SABRE_IMAP_UE,
  469. /*0x2f*/ SABRE_IMAP_CE,
  470. /*0x30*/ SABRE_IMAP_PCIERR,
  471. };
  472. #define SABRE_ONBOARD_IRQ_BASE 0x20
  473. #define SABRE_ONBOARD_IRQ_LAST 0x30
  474. #define sabre_onboard_imap_offset(__ino) \
  475. __onboard_imap_off[(__ino) - SABRE_ONBOARD_IRQ_BASE]
  476. #define sabre_iclr_offset(ino) \
  477. ((ino & 0x20) ? (SABRE_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
  478. (SABRE_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
  479. /* When a device lives behind a bridge deeper in the PCI bus topology
  480. * than APB, a special sequence must run to make sure all pending DMA
  481. * transfers at the time of IRQ delivery are visible in the coherency
  482. * domain by the cpu. This sequence is to perform a read on the far
  483. * side of the non-APB bridge, then perform a read of Sabre's DMA
  484. * write-sync register.
  485. */
  486. static void sabre_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
  487. {
  488. struct pci_dev *pdev = _arg1;
  489. unsigned long sync_reg = (unsigned long) _arg2;
  490. u16 _unused;
  491. pci_read_config_word(pdev, PCI_VENDOR_ID, &_unused);
  492. sabre_read(sync_reg);
  493. }
  494. static unsigned int sabre_irq_build(struct pci_pbm_info *pbm,
  495. struct pci_dev *pdev,
  496. unsigned int ino)
  497. {
  498. unsigned long imap, iclr;
  499. unsigned long imap_off, iclr_off;
  500. int inofixup = 0;
  501. int virt_irq;
  502. ino &= PCI_IRQ_INO;
  503. if (ino < SABRE_ONBOARD_IRQ_BASE) {
  504. /* PCI slot */
  505. imap_off = sabre_pcislot_imap_offset(ino);
  506. } else {
  507. /* onboard device */
  508. if (ino > SABRE_ONBOARD_IRQ_LAST) {
  509. prom_printf("sabre_irq_build: Wacky INO [%x]\n", ino);
  510. prom_halt();
  511. }
  512. imap_off = sabre_onboard_imap_offset(ino);
  513. }
  514. /* Now build the IRQ bucket. */
  515. imap = pbm->controller_regs + imap_off;
  516. imap += 4;
  517. iclr_off = sabre_iclr_offset(ino);
  518. iclr = pbm->controller_regs + iclr_off;
  519. iclr += 4;
  520. if ((ino & 0x20) == 0)
  521. inofixup = ino & 0x03;
  522. virt_irq = build_irq(inofixup, iclr, imap);
  523. if (pdev) {
  524. struct pcidev_cookie *pcp = pdev->sysdata;
  525. if (pdev->bus->number != pcp->pbm->pci_first_busno) {
  526. struct pci_controller_info *p = pcp->pbm->parent;
  527. irq_install_pre_handler(virt_irq,
  528. sabre_wsync_handler,
  529. pdev,
  530. (void *)
  531. p->pbm_A.controller_regs +
  532. SABRE_WRSYNC);
  533. }
  534. }
  535. return virt_irq;
  536. }
  537. /* SABRE error handling support. */
  538. static void sabre_check_iommu_error(struct pci_controller_info *p,
  539. unsigned long afsr,
  540. unsigned long afar)
  541. {
  542. struct pci_iommu *iommu = p->pbm_A.iommu;
  543. unsigned long iommu_tag[16];
  544. unsigned long iommu_data[16];
  545. unsigned long flags;
  546. u64 control;
  547. int i;
  548. spin_lock_irqsave(&iommu->lock, flags);
  549. control = sabre_read(iommu->iommu_control);
  550. if (control & SABRE_IOMMUCTRL_ERR) {
  551. char *type_string;
  552. /* Clear the error encountered bit.
  553. * NOTE: On Sabre this is write 1 to clear,
  554. * which is different from Psycho.
  555. */
  556. sabre_write(iommu->iommu_control, control);
  557. switch((control & SABRE_IOMMUCTRL_ERRSTS) >> 25UL) {
  558. case 1:
  559. type_string = "Invalid Error";
  560. break;
  561. case 3:
  562. type_string = "ECC Error";
  563. break;
  564. default:
  565. type_string = "Unknown";
  566. break;
  567. };
  568. printk("SABRE%d: IOMMU Error, type[%s]\n",
  569. p->index, type_string);
  570. /* Enter diagnostic mode and probe for error'd
  571. * entries in the IOTLB.
  572. */
  573. control &= ~(SABRE_IOMMUCTRL_ERRSTS | SABRE_IOMMUCTRL_ERR);
  574. sabre_write(iommu->iommu_control,
  575. (control | SABRE_IOMMUCTRL_DENAB));
  576. for (i = 0; i < 16; i++) {
  577. unsigned long base = p->pbm_A.controller_regs;
  578. iommu_tag[i] =
  579. sabre_read(base + SABRE_IOMMU_TAG + (i * 8UL));
  580. iommu_data[i] =
  581. sabre_read(base + SABRE_IOMMU_DATA + (i * 8UL));
  582. sabre_write(base + SABRE_IOMMU_TAG + (i * 8UL), 0);
  583. sabre_write(base + SABRE_IOMMU_DATA + (i * 8UL), 0);
  584. }
  585. sabre_write(iommu->iommu_control, control);
  586. for (i = 0; i < 16; i++) {
  587. unsigned long tag, data;
  588. tag = iommu_tag[i];
  589. if (!(tag & SABRE_IOMMUTAG_ERR))
  590. continue;
  591. data = iommu_data[i];
  592. switch((tag & SABRE_IOMMUTAG_ERRSTS) >> 23UL) {
  593. case 1:
  594. type_string = "Invalid Error";
  595. break;
  596. case 3:
  597. type_string = "ECC Error";
  598. break;
  599. default:
  600. type_string = "Unknown";
  601. break;
  602. };
  603. printk("SABRE%d: IOMMU TAG(%d)[RAW(%016lx)error(%s)wr(%d)sz(%dK)vpg(%08lx)]\n",
  604. p->index, i, tag, type_string,
  605. ((tag & SABRE_IOMMUTAG_WRITE) ? 1 : 0),
  606. ((tag & SABRE_IOMMUTAG_SIZE) ? 64 : 8),
  607. ((tag & SABRE_IOMMUTAG_VPN) << IOMMU_PAGE_SHIFT));
  608. printk("SABRE%d: IOMMU DATA(%d)[RAW(%016lx)valid(%d)used(%d)cache(%d)ppg(%016lx)\n",
  609. p->index, i, data,
  610. ((data & SABRE_IOMMUDATA_VALID) ? 1 : 0),
  611. ((data & SABRE_IOMMUDATA_USED) ? 1 : 0),
  612. ((data & SABRE_IOMMUDATA_CACHE) ? 1 : 0),
  613. ((data & SABRE_IOMMUDATA_PPN) << IOMMU_PAGE_SHIFT));
  614. }
  615. }
  616. spin_unlock_irqrestore(&iommu->lock, flags);
  617. }
  618. static irqreturn_t sabre_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
  619. {
  620. struct pci_controller_info *p = dev_id;
  621. unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_UE_AFSR;
  622. unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
  623. unsigned long afsr, afar, error_bits;
  624. int reported;
  625. /* Latch uncorrectable error status. */
  626. afar = sabre_read(afar_reg);
  627. afsr = sabre_read(afsr_reg);
  628. /* Clear the primary/secondary error status bits. */
  629. error_bits = afsr &
  630. (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
  631. SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
  632. SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE);
  633. if (!error_bits)
  634. return IRQ_NONE;
  635. sabre_write(afsr_reg, error_bits);
  636. /* Log the error. */
  637. printk("SABRE%d: Uncorrectable Error, primary error type[%s%s]\n",
  638. p->index,
  639. ((error_bits & SABRE_UEAFSR_PDRD) ?
  640. "DMA Read" :
  641. ((error_bits & SABRE_UEAFSR_PDWR) ?
  642. "DMA Write" : "???")),
  643. ((error_bits & SABRE_UEAFSR_PDTE) ?
  644. ":Translation Error" : ""));
  645. printk("SABRE%d: bytemask[%04lx] dword_offset[%lx] was_block(%d)\n",
  646. p->index,
  647. (afsr & SABRE_UEAFSR_BMSK) >> 32UL,
  648. (afsr & SABRE_UEAFSR_OFF) >> 29UL,
  649. ((afsr & SABRE_UEAFSR_BLK) ? 1 : 0));
  650. printk("SABRE%d: UE AFAR [%016lx]\n", p->index, afar);
  651. printk("SABRE%d: UE Secondary errors [", p->index);
  652. reported = 0;
  653. if (afsr & SABRE_UEAFSR_SDRD) {
  654. reported++;
  655. printk("(DMA Read)");
  656. }
  657. if (afsr & SABRE_UEAFSR_SDWR) {
  658. reported++;
  659. printk("(DMA Write)");
  660. }
  661. if (afsr & SABRE_UEAFSR_SDTE) {
  662. reported++;
  663. printk("(Translation Error)");
  664. }
  665. if (!reported)
  666. printk("(none)");
  667. printk("]\n");
  668. /* Interrogate IOMMU for error status. */
  669. sabre_check_iommu_error(p, afsr, afar);
  670. return IRQ_HANDLED;
  671. }
  672. static irqreturn_t sabre_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
  673. {
  674. struct pci_controller_info *p = dev_id;
  675. unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_CE_AFSR;
  676. unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
  677. unsigned long afsr, afar, error_bits;
  678. int reported;
  679. /* Latch error status. */
  680. afar = sabre_read(afar_reg);
  681. afsr = sabre_read(afsr_reg);
  682. /* Clear primary/secondary error status bits. */
  683. error_bits = afsr &
  684. (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
  685. SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR);
  686. if (!error_bits)
  687. return IRQ_NONE;
  688. sabre_write(afsr_reg, error_bits);
  689. /* Log the error. */
  690. printk("SABRE%d: Correctable Error, primary error type[%s]\n",
  691. p->index,
  692. ((error_bits & SABRE_CEAFSR_PDRD) ?
  693. "DMA Read" :
  694. ((error_bits & SABRE_CEAFSR_PDWR) ?
  695. "DMA Write" : "???")));
  696. /* XXX Use syndrome and afar to print out module string just like
  697. * XXX UDB CE trap handler does... -DaveM
  698. */
  699. printk("SABRE%d: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
  700. "was_block(%d)\n",
  701. p->index,
  702. (afsr & SABRE_CEAFSR_ESYND) >> 48UL,
  703. (afsr & SABRE_CEAFSR_BMSK) >> 32UL,
  704. (afsr & SABRE_CEAFSR_OFF) >> 29UL,
  705. ((afsr & SABRE_CEAFSR_BLK) ? 1 : 0));
  706. printk("SABRE%d: CE AFAR [%016lx]\n", p->index, afar);
  707. printk("SABRE%d: CE Secondary errors [", p->index);
  708. reported = 0;
  709. if (afsr & SABRE_CEAFSR_SDRD) {
  710. reported++;
  711. printk("(DMA Read)");
  712. }
  713. if (afsr & SABRE_CEAFSR_SDWR) {
  714. reported++;
  715. printk("(DMA Write)");
  716. }
  717. if (!reported)
  718. printk("(none)");
  719. printk("]\n");
  720. return IRQ_HANDLED;
  721. }
  722. static irqreturn_t sabre_pcierr_intr_other(struct pci_controller_info *p)
  723. {
  724. unsigned long csr_reg, csr, csr_error_bits;
  725. irqreturn_t ret = IRQ_NONE;
  726. u16 stat;
  727. csr_reg = p->pbm_A.controller_regs + SABRE_PCICTRL;
  728. csr = sabre_read(csr_reg);
  729. csr_error_bits =
  730. csr & SABRE_PCICTRL_SERR;
  731. if (csr_error_bits) {
  732. /* Clear the errors. */
  733. sabre_write(csr_reg, csr);
  734. /* Log 'em. */
  735. if (csr_error_bits & SABRE_PCICTRL_SERR)
  736. printk("SABRE%d: PCI SERR signal asserted.\n",
  737. p->index);
  738. ret = IRQ_HANDLED;
  739. }
  740. pci_read_config_word(sabre_root_bus->self,
  741. PCI_STATUS, &stat);
  742. if (stat & (PCI_STATUS_PARITY |
  743. PCI_STATUS_SIG_TARGET_ABORT |
  744. PCI_STATUS_REC_TARGET_ABORT |
  745. PCI_STATUS_REC_MASTER_ABORT |
  746. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  747. printk("SABRE%d: PCI bus error, PCI_STATUS[%04x]\n",
  748. p->index, stat);
  749. pci_write_config_word(sabre_root_bus->self,
  750. PCI_STATUS, 0xffff);
  751. ret = IRQ_HANDLED;
  752. }
  753. return ret;
  754. }
  755. static irqreturn_t sabre_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
  756. {
  757. struct pci_controller_info *p = dev_id;
  758. unsigned long afsr_reg, afar_reg;
  759. unsigned long afsr, afar, error_bits;
  760. int reported;
  761. afsr_reg = p->pbm_A.controller_regs + SABRE_PIOAFSR;
  762. afar_reg = p->pbm_A.controller_regs + SABRE_PIOAFAR;
  763. /* Latch error status. */
  764. afar = sabre_read(afar_reg);
  765. afsr = sabre_read(afsr_reg);
  766. /* Clear primary/secondary error status bits. */
  767. error_bits = afsr &
  768. (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_PTA |
  769. SABRE_PIOAFSR_PRTRY | SABRE_PIOAFSR_PPERR |
  770. SABRE_PIOAFSR_SMA | SABRE_PIOAFSR_STA |
  771. SABRE_PIOAFSR_SRTRY | SABRE_PIOAFSR_SPERR);
  772. if (!error_bits)
  773. return sabre_pcierr_intr_other(p);
  774. sabre_write(afsr_reg, error_bits);
  775. /* Log the error. */
  776. printk("SABRE%d: PCI Error, primary error type[%s]\n",
  777. p->index,
  778. (((error_bits & SABRE_PIOAFSR_PMA) ?
  779. "Master Abort" :
  780. ((error_bits & SABRE_PIOAFSR_PTA) ?
  781. "Target Abort" :
  782. ((error_bits & SABRE_PIOAFSR_PRTRY) ?
  783. "Excessive Retries" :
  784. ((error_bits & SABRE_PIOAFSR_PPERR) ?
  785. "Parity Error" : "???"))))));
  786. printk("SABRE%d: bytemask[%04lx] was_block(%d)\n",
  787. p->index,
  788. (afsr & SABRE_PIOAFSR_BMSK) >> 32UL,
  789. (afsr & SABRE_PIOAFSR_BLK) ? 1 : 0);
  790. printk("SABRE%d: PCI AFAR [%016lx]\n", p->index, afar);
  791. printk("SABRE%d: PCI Secondary errors [", p->index);
  792. reported = 0;
  793. if (afsr & SABRE_PIOAFSR_SMA) {
  794. reported++;
  795. printk("(Master Abort)");
  796. }
  797. if (afsr & SABRE_PIOAFSR_STA) {
  798. reported++;
  799. printk("(Target Abort)");
  800. }
  801. if (afsr & SABRE_PIOAFSR_SRTRY) {
  802. reported++;
  803. printk("(Excessive Retries)");
  804. }
  805. if (afsr & SABRE_PIOAFSR_SPERR) {
  806. reported++;
  807. printk("(Parity Error)");
  808. }
  809. if (!reported)
  810. printk("(none)");
  811. printk("]\n");
  812. /* For the error types shown, scan both PCI buses for devices
  813. * which have logged that error type.
  814. */
  815. /* If we see a Target Abort, this could be the result of an
  816. * IOMMU translation error of some sort. It is extremely
  817. * useful to log this information as usually it indicates
  818. * a bug in the IOMMU support code or a PCI device driver.
  819. */
  820. if (error_bits & (SABRE_PIOAFSR_PTA | SABRE_PIOAFSR_STA)) {
  821. sabre_check_iommu_error(p, afsr, afar);
  822. pci_scan_for_target_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
  823. pci_scan_for_target_abort(p, &p->pbm_B, p->pbm_B.pci_bus);
  824. }
  825. if (error_bits & (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_SMA)) {
  826. pci_scan_for_master_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
  827. pci_scan_for_master_abort(p, &p->pbm_B, p->pbm_B.pci_bus);
  828. }
  829. /* For excessive retries, SABRE/PBM will abort the device
  830. * and there is no way to specifically check for excessive
  831. * retries in the config space status registers. So what
  832. * we hope is that we'll catch it via the master/target
  833. * abort events.
  834. */
  835. if (error_bits & (SABRE_PIOAFSR_PPERR | SABRE_PIOAFSR_SPERR)) {
  836. pci_scan_for_parity_error(p, &p->pbm_A, p->pbm_A.pci_bus);
  837. pci_scan_for_parity_error(p, &p->pbm_B, p->pbm_B.pci_bus);
  838. }
  839. return IRQ_HANDLED;
  840. }
  841. /* XXX What about PowerFail/PowerManagement??? -DaveM */
  842. #define SABRE_UE_INO 0x2e
  843. #define SABRE_CE_INO 0x2f
  844. #define SABRE_PCIERR_INO 0x30
  845. static void sabre_register_error_handlers(struct pci_controller_info *p)
  846. {
  847. struct pci_pbm_info *pbm = &p->pbm_A; /* arbitrary */
  848. unsigned long base = pbm->controller_regs;
  849. unsigned long irq, portid = pbm->portid;
  850. u64 tmp;
  851. /* We clear the error bits in the appropriate AFSR before
  852. * registering the handler so that we don't get spurious
  853. * interrupts.
  854. */
  855. sabre_write(base + SABRE_UE_AFSR,
  856. (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
  857. SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
  858. SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE));
  859. irq = sabre_irq_build(pbm, NULL, (portid << 6) | SABRE_UE_INO);
  860. if (request_irq(irq, sabre_ue_intr,
  861. SA_SHIRQ, "SABRE UE", p) < 0) {
  862. prom_printf("SABRE%d: Cannot register UE interrupt.\n",
  863. p->index);
  864. prom_halt();
  865. }
  866. sabre_write(base + SABRE_CE_AFSR,
  867. (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
  868. SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR));
  869. irq = sabre_irq_build(pbm, NULL, (portid << 6) | SABRE_CE_INO);
  870. if (request_irq(irq, sabre_ce_intr,
  871. SA_SHIRQ, "SABRE CE", p) < 0) {
  872. prom_printf("SABRE%d: Cannot register CE interrupt.\n",
  873. p->index);
  874. prom_halt();
  875. }
  876. irq = sabre_irq_build(pbm, NULL, (portid << 6) | SABRE_PCIERR_INO);
  877. if (request_irq(irq, sabre_pcierr_intr,
  878. SA_SHIRQ, "SABRE PCIERR", p) < 0) {
  879. prom_printf("SABRE%d: Cannot register PciERR interrupt.\n",
  880. p->index);
  881. prom_halt();
  882. }
  883. tmp = sabre_read(base + SABRE_PCICTRL);
  884. tmp |= SABRE_PCICTRL_ERREN;
  885. sabre_write(base + SABRE_PCICTRL, tmp);
  886. }
  887. static void sabre_resource_adjust(struct pci_dev *pdev,
  888. struct resource *res,
  889. struct resource *root)
  890. {
  891. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  892. unsigned long base;
  893. if (res->flags & IORESOURCE_IO)
  894. base = pbm->controller_regs + SABRE_IOSPACE;
  895. else
  896. base = pbm->controller_regs + SABRE_MEMSPACE;
  897. res->start += base;
  898. res->end += base;
  899. }
  900. static void sabre_base_address_update(struct pci_dev *pdev, int resource)
  901. {
  902. struct pcidev_cookie *pcp = pdev->sysdata;
  903. struct pci_pbm_info *pbm = pcp->pbm;
  904. struct resource *res;
  905. unsigned long base;
  906. u32 reg;
  907. int where, size, is_64bit;
  908. res = &pdev->resource[resource];
  909. if (resource < 6) {
  910. where = PCI_BASE_ADDRESS_0 + (resource * 4);
  911. } else if (resource == PCI_ROM_RESOURCE) {
  912. where = pdev->rom_base_reg;
  913. } else {
  914. /* Somebody might have asked allocation of a non-standard resource */
  915. return;
  916. }
  917. is_64bit = 0;
  918. if (res->flags & IORESOURCE_IO)
  919. base = pbm->controller_regs + SABRE_IOSPACE;
  920. else {
  921. base = pbm->controller_regs + SABRE_MEMSPACE;
  922. if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
  923. == PCI_BASE_ADDRESS_MEM_TYPE_64)
  924. is_64bit = 1;
  925. }
  926. size = res->end - res->start;
  927. pci_read_config_dword(pdev, where, &reg);
  928. reg = ((reg & size) |
  929. (((u32)(res->start - base)) & ~size));
  930. if (resource == PCI_ROM_RESOURCE) {
  931. reg |= PCI_ROM_ADDRESS_ENABLE;
  932. res->flags |= IORESOURCE_ROM_ENABLE;
  933. }
  934. pci_write_config_dword(pdev, where, reg);
  935. /* This knows that the upper 32-bits of the address
  936. * must be zero. Our PCI common layer enforces this.
  937. */
  938. if (is_64bit)
  939. pci_write_config_dword(pdev, where + 4, 0);
  940. }
  941. static void apb_init(struct pci_controller_info *p, struct pci_bus *sabre_bus)
  942. {
  943. struct pci_dev *pdev;
  944. list_for_each_entry(pdev, &sabre_bus->devices, bus_list) {
  945. if (pdev->vendor == PCI_VENDOR_ID_SUN &&
  946. pdev->device == PCI_DEVICE_ID_SUN_SIMBA) {
  947. u32 word32;
  948. u16 word16;
  949. sabre_read_pci_cfg(pdev->bus, pdev->devfn,
  950. PCI_COMMAND, 2, &word32);
  951. word16 = (u16) word32;
  952. word16 |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
  953. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
  954. PCI_COMMAND_IO;
  955. word32 = (u32) word16;
  956. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  957. PCI_COMMAND, 2, word32);
  958. /* Status register bits are "write 1 to clear". */
  959. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  960. PCI_STATUS, 2, 0xffff);
  961. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  962. PCI_SEC_STATUS, 2, 0xffff);
  963. /* Use a primary/seconday latency timer value
  964. * of 64.
  965. */
  966. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  967. PCI_LATENCY_TIMER, 1, 64);
  968. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  969. PCI_SEC_LATENCY_TIMER, 1, 64);
  970. /* Enable reporting/forwarding of master aborts,
  971. * parity, and SERR.
  972. */
  973. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  974. PCI_BRIDGE_CONTROL, 1,
  975. (PCI_BRIDGE_CTL_PARITY |
  976. PCI_BRIDGE_CTL_SERR |
  977. PCI_BRIDGE_CTL_MASTER_ABORT));
  978. }
  979. }
  980. }
  981. static struct pcidev_cookie *alloc_bridge_cookie(struct pci_pbm_info *pbm)
  982. {
  983. struct pcidev_cookie *cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
  984. if (!cookie) {
  985. prom_printf("SABRE: Critical allocation failure.\n");
  986. prom_halt();
  987. }
  988. /* All we care about is the PBM. */
  989. cookie->pbm = pbm;
  990. return cookie;
  991. }
  992. static void sabre_scan_bus(struct pci_controller_info *p)
  993. {
  994. static int once;
  995. struct pci_bus *sabre_bus, *pbus;
  996. struct pci_pbm_info *pbm;
  997. struct pcidev_cookie *cookie;
  998. int sabres_scanned;
  999. /* The APB bridge speaks to the Sabre host PCI bridge
  1000. * at 66Mhz, but the front side of APB runs at 33Mhz
  1001. * for both segments.
  1002. */
  1003. p->pbm_A.is_66mhz_capable = 0;
  1004. p->pbm_B.is_66mhz_capable = 0;
  1005. /* This driver has not been verified to handle
  1006. * multiple SABREs yet, so trap this.
  1007. *
  1008. * Also note that the SABRE host bridge is hardwired
  1009. * to live at bus 0.
  1010. */
  1011. if (once != 0) {
  1012. prom_printf("SABRE: Multiple controllers unsupported.\n");
  1013. prom_halt();
  1014. }
  1015. once++;
  1016. cookie = alloc_bridge_cookie(&p->pbm_A);
  1017. sabre_bus = pci_scan_bus(p->pci_first_busno,
  1018. p->pci_ops,
  1019. &p->pbm_A);
  1020. pci_fixup_host_bridge_self(sabre_bus);
  1021. sabre_bus->self->sysdata = cookie;
  1022. sabre_root_bus = sabre_bus;
  1023. apb_init(p, sabre_bus);
  1024. sabres_scanned = 0;
  1025. list_for_each_entry(pbus, &sabre_bus->children, node) {
  1026. if (pbus->number == p->pbm_A.pci_first_busno) {
  1027. pbm = &p->pbm_A;
  1028. } else if (pbus->number == p->pbm_B.pci_first_busno) {
  1029. pbm = &p->pbm_B;
  1030. } else
  1031. continue;
  1032. cookie = alloc_bridge_cookie(pbm);
  1033. pbus->self->sysdata = cookie;
  1034. sabres_scanned++;
  1035. pbus->sysdata = pbm;
  1036. pbm->pci_bus = pbus;
  1037. pci_fill_in_pbm_cookies(pbus, pbm, pbm->prom_node);
  1038. pci_record_assignments(pbm, pbus);
  1039. pci_assign_unassigned(pbm, pbus);
  1040. pci_fixup_irq(pbm, pbus);
  1041. pci_determine_66mhz_disposition(pbm, pbus);
  1042. pci_setup_busmastering(pbm, pbus);
  1043. }
  1044. if (!sabres_scanned) {
  1045. /* Hummingbird, no APBs. */
  1046. pbm = &p->pbm_A;
  1047. sabre_bus->sysdata = pbm;
  1048. pbm->pci_bus = sabre_bus;
  1049. pci_fill_in_pbm_cookies(sabre_bus, pbm, pbm->prom_node);
  1050. pci_record_assignments(pbm, sabre_bus);
  1051. pci_assign_unassigned(pbm, sabre_bus);
  1052. pci_fixup_irq(pbm, sabre_bus);
  1053. pci_determine_66mhz_disposition(pbm, sabre_bus);
  1054. pci_setup_busmastering(pbm, sabre_bus);
  1055. }
  1056. sabre_register_error_handlers(p);
  1057. }
  1058. static void sabre_iommu_init(struct pci_controller_info *p,
  1059. int tsbsize, unsigned long dvma_offset,
  1060. u32 dma_mask)
  1061. {
  1062. struct pci_iommu *iommu = p->pbm_A.iommu;
  1063. unsigned long i;
  1064. u64 control;
  1065. /* Register addresses. */
  1066. iommu->iommu_control = p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL;
  1067. iommu->iommu_tsbbase = p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE;
  1068. iommu->iommu_flush = p->pbm_A.controller_regs + SABRE_IOMMU_FLUSH;
  1069. iommu->write_complete_reg = p->pbm_A.controller_regs + SABRE_WRSYNC;
  1070. /* Sabre's IOMMU lacks ctx flushing. */
  1071. iommu->iommu_ctxflush = 0;
  1072. /* Invalidate TLB Entries. */
  1073. control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
  1074. control |= SABRE_IOMMUCTRL_DENAB;
  1075. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
  1076. for(i = 0; i < 16; i++) {
  1077. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TAG + (i * 8UL), 0);
  1078. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_DATA + (i * 8UL), 0);
  1079. }
  1080. /* Leave diag mode enabled for full-flushing done
  1081. * in pci_iommu.c
  1082. */
  1083. pci_iommu_table_init(iommu, tsbsize * 1024 * 8, dvma_offset, dma_mask);
  1084. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE,
  1085. __pa(iommu->page_table));
  1086. control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
  1087. control &= ~(SABRE_IOMMUCTRL_TSBSZ | SABRE_IOMMUCTRL_TBWSZ);
  1088. control |= SABRE_IOMMUCTRL_ENAB;
  1089. switch(tsbsize) {
  1090. case 64:
  1091. control |= SABRE_IOMMU_TSBSZ_64K;
  1092. break;
  1093. case 128:
  1094. control |= SABRE_IOMMU_TSBSZ_128K;
  1095. break;
  1096. default:
  1097. prom_printf("iommu_init: Illegal TSB size %d\n", tsbsize);
  1098. prom_halt();
  1099. break;
  1100. }
  1101. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
  1102. }
  1103. static void pbm_register_toplevel_resources(struct pci_controller_info *p,
  1104. struct pci_pbm_info *pbm)
  1105. {
  1106. char *name = pbm->name;
  1107. unsigned long ibase = p->pbm_A.controller_regs + SABRE_IOSPACE;
  1108. unsigned long mbase = p->pbm_A.controller_regs + SABRE_MEMSPACE;
  1109. unsigned int devfn;
  1110. unsigned long first, last, i;
  1111. u8 *addr, map;
  1112. sprintf(name, "SABRE%d PBM%c",
  1113. p->index,
  1114. (pbm == &p->pbm_A ? 'A' : 'B'));
  1115. pbm->io_space.name = pbm->mem_space.name = name;
  1116. devfn = PCI_DEVFN(1, (pbm == &p->pbm_A) ? 0 : 1);
  1117. addr = sabre_pci_config_mkaddr(pbm, 0, devfn, APB_IO_ADDRESS_MAP);
  1118. map = 0;
  1119. pci_config_read8(addr, &map);
  1120. first = 8;
  1121. last = 0;
  1122. for (i = 0; i < 8; i++) {
  1123. if ((map & (1 << i)) != 0) {
  1124. if (first > i)
  1125. first = i;
  1126. if (last < i)
  1127. last = i;
  1128. }
  1129. }
  1130. pbm->io_space.start = ibase + (first << 21UL);
  1131. pbm->io_space.end = ibase + (last << 21UL) + ((1 << 21UL) - 1);
  1132. pbm->io_space.flags = IORESOURCE_IO;
  1133. addr = sabre_pci_config_mkaddr(pbm, 0, devfn, APB_MEM_ADDRESS_MAP);
  1134. map = 0;
  1135. pci_config_read8(addr, &map);
  1136. first = 8;
  1137. last = 0;
  1138. for (i = 0; i < 8; i++) {
  1139. if ((map & (1 << i)) != 0) {
  1140. if (first > i)
  1141. first = i;
  1142. if (last < i)
  1143. last = i;
  1144. }
  1145. }
  1146. pbm->mem_space.start = mbase + (first << 29UL);
  1147. pbm->mem_space.end = mbase + (last << 29UL) + ((1 << 29UL) - 1);
  1148. pbm->mem_space.flags = IORESOURCE_MEM;
  1149. if (request_resource(&ioport_resource, &pbm->io_space) < 0) {
  1150. prom_printf("Cannot register PBM-%c's IO space.\n",
  1151. (pbm == &p->pbm_A ? 'A' : 'B'));
  1152. prom_halt();
  1153. }
  1154. if (request_resource(&iomem_resource, &pbm->mem_space) < 0) {
  1155. prom_printf("Cannot register PBM-%c's MEM space.\n",
  1156. (pbm == &p->pbm_A ? 'A' : 'B'));
  1157. prom_halt();
  1158. }
  1159. /* Register legacy regions if this PBM covers that area. */
  1160. if (pbm->io_space.start == ibase &&
  1161. pbm->mem_space.start == mbase)
  1162. pci_register_legacy_regions(&pbm->io_space,
  1163. &pbm->mem_space);
  1164. }
  1165. static void sabre_pbm_init(struct pci_controller_info *p, int sabre_node, u32 dma_begin)
  1166. {
  1167. struct pci_pbm_info *pbm;
  1168. char namebuf[128];
  1169. u32 busrange[2];
  1170. int node, simbas_found;
  1171. simbas_found = 0;
  1172. node = prom_getchild(sabre_node);
  1173. while ((node = prom_searchsiblings(node, "pci")) != 0) {
  1174. int err;
  1175. err = prom_getproperty(node, "model", namebuf, sizeof(namebuf));
  1176. if ((err <= 0) || strncmp(namebuf, "SUNW,simba", err))
  1177. goto next_pci;
  1178. err = prom_getproperty(node, "bus-range",
  1179. (char *)&busrange[0], sizeof(busrange));
  1180. if (err == 0 || err == -1) {
  1181. prom_printf("APB: Error, cannot get PCI bus-range.\n");
  1182. prom_halt();
  1183. }
  1184. simbas_found++;
  1185. if (busrange[0] == 1)
  1186. pbm = &p->pbm_B;
  1187. else
  1188. pbm = &p->pbm_A;
  1189. pbm->chip_type = PBM_CHIP_TYPE_SABRE;
  1190. pbm->parent = p;
  1191. pbm->prom_node = node;
  1192. pbm->pci_first_slot = 1;
  1193. pbm->pci_first_busno = busrange[0];
  1194. pbm->pci_last_busno = busrange[1];
  1195. prom_getstring(node, "name", pbm->prom_name, sizeof(pbm->prom_name));
  1196. err = prom_getproperty(node, "ranges",
  1197. (char *)pbm->pbm_ranges,
  1198. sizeof(pbm->pbm_ranges));
  1199. if (err != -1)
  1200. pbm->num_pbm_ranges =
  1201. (err / sizeof(struct linux_prom_pci_ranges));
  1202. else
  1203. pbm->num_pbm_ranges = 0;
  1204. err = prom_getproperty(node, "interrupt-map",
  1205. (char *)pbm->pbm_intmap,
  1206. sizeof(pbm->pbm_intmap));
  1207. if (err != -1) {
  1208. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  1209. err = prom_getproperty(node, "interrupt-map-mask",
  1210. (char *)&pbm->pbm_intmask,
  1211. sizeof(pbm->pbm_intmask));
  1212. if (err == -1) {
  1213. prom_printf("APB: Fatal error, no interrupt-map-mask.\n");
  1214. prom_halt();
  1215. }
  1216. } else {
  1217. pbm->num_pbm_intmap = 0;
  1218. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  1219. }
  1220. pbm_register_toplevel_resources(p, pbm);
  1221. next_pci:
  1222. node = prom_getsibling(node);
  1223. if (!node)
  1224. break;
  1225. }
  1226. if (simbas_found == 0) {
  1227. int err;
  1228. /* No APBs underneath, probably this is a hummingbird
  1229. * system.
  1230. */
  1231. pbm = &p->pbm_A;
  1232. pbm->parent = p;
  1233. pbm->prom_node = sabre_node;
  1234. pbm->pci_first_busno = p->pci_first_busno;
  1235. pbm->pci_last_busno = p->pci_last_busno;
  1236. prom_getstring(sabre_node, "name", pbm->prom_name, sizeof(pbm->prom_name));
  1237. err = prom_getproperty(sabre_node, "ranges",
  1238. (char *) pbm->pbm_ranges,
  1239. sizeof(pbm->pbm_ranges));
  1240. if (err != -1)
  1241. pbm->num_pbm_ranges =
  1242. (err / sizeof(struct linux_prom_pci_ranges));
  1243. else
  1244. pbm->num_pbm_ranges = 0;
  1245. err = prom_getproperty(sabre_node, "interrupt-map",
  1246. (char *) pbm->pbm_intmap,
  1247. sizeof(pbm->pbm_intmap));
  1248. if (err != -1) {
  1249. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  1250. err = prom_getproperty(sabre_node, "interrupt-map-mask",
  1251. (char *)&pbm->pbm_intmask,
  1252. sizeof(pbm->pbm_intmask));
  1253. if (err == -1) {
  1254. prom_printf("Hummingbird: Fatal error, no interrupt-map-mask.\n");
  1255. prom_halt();
  1256. }
  1257. } else {
  1258. pbm->num_pbm_intmap = 0;
  1259. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  1260. }
  1261. sprintf(pbm->name, "SABRE%d PBM%c", p->index,
  1262. (pbm == &p->pbm_A ? 'A' : 'B'));
  1263. pbm->io_space.name = pbm->mem_space.name = pbm->name;
  1264. /* Hack up top-level resources. */
  1265. pbm->io_space.start = p->pbm_A.controller_regs + SABRE_IOSPACE;
  1266. pbm->io_space.end = pbm->io_space.start + (1UL << 24) - 1UL;
  1267. pbm->io_space.flags = IORESOURCE_IO;
  1268. pbm->mem_space.start = p->pbm_A.controller_regs + SABRE_MEMSPACE;
  1269. pbm->mem_space.end = pbm->mem_space.start + (unsigned long)dma_begin - 1UL;
  1270. pbm->mem_space.flags = IORESOURCE_MEM;
  1271. if (request_resource(&ioport_resource, &pbm->io_space) < 0) {
  1272. prom_printf("Cannot register Hummingbird's IO space.\n");
  1273. prom_halt();
  1274. }
  1275. if (request_resource(&iomem_resource, &pbm->mem_space) < 0) {
  1276. prom_printf("Cannot register Hummingbird's MEM space.\n");
  1277. prom_halt();
  1278. }
  1279. pci_register_legacy_regions(&pbm->io_space,
  1280. &pbm->mem_space);
  1281. }
  1282. }
  1283. void sabre_init(int pnode, char *model_name)
  1284. {
  1285. struct linux_prom64_registers pr_regs[2];
  1286. struct pci_controller_info *p;
  1287. struct pci_iommu *iommu;
  1288. int tsbsize, err;
  1289. u32 busrange[2];
  1290. u32 vdma[2];
  1291. u32 upa_portid, dma_mask;
  1292. u64 clear_irq;
  1293. hummingbird_p = 0;
  1294. if (!strcmp(model_name, "pci108e,a001"))
  1295. hummingbird_p = 1;
  1296. else if (!strcmp(model_name, "SUNW,sabre")) {
  1297. char compat[64];
  1298. if (prom_getproperty(pnode, "compatible",
  1299. compat, sizeof(compat)) > 0 &&
  1300. !strcmp(compat, "pci108e,a001")) {
  1301. hummingbird_p = 1;
  1302. } else {
  1303. int cpu_node;
  1304. /* Of course, Sun has to encode things a thousand
  1305. * different ways, inconsistently.
  1306. */
  1307. cpu_find_by_instance(0, &cpu_node, NULL);
  1308. if (prom_getproperty(cpu_node, "name",
  1309. compat, sizeof(compat)) > 0 &&
  1310. !strcmp(compat, "SUNW,UltraSPARC-IIe"))
  1311. hummingbird_p = 1;
  1312. }
  1313. }
  1314. p = kzalloc(sizeof(*p), GFP_ATOMIC);
  1315. if (!p) {
  1316. prom_printf("SABRE: Error, kmalloc(pci_controller_info) failed.\n");
  1317. prom_halt();
  1318. }
  1319. iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
  1320. if (!iommu) {
  1321. prom_printf("SABRE: Error, kmalloc(pci_iommu) failed.\n");
  1322. prom_halt();
  1323. }
  1324. p->pbm_A.iommu = p->pbm_B.iommu = iommu;
  1325. upa_portid = prom_getintdefault(pnode, "upa-portid", 0xff);
  1326. p->next = pci_controller_root;
  1327. pci_controller_root = p;
  1328. p->pbm_A.portid = upa_portid;
  1329. p->pbm_B.portid = upa_portid;
  1330. p->index = pci_num_controllers++;
  1331. p->pbms_same_domain = 1;
  1332. p->scan_bus = sabre_scan_bus;
  1333. p->irq_build = sabre_irq_build;
  1334. p->base_address_update = sabre_base_address_update;
  1335. p->resource_adjust = sabre_resource_adjust;
  1336. p->pci_ops = &sabre_ops;
  1337. /*
  1338. * Map in SABRE register set and report the presence of this SABRE.
  1339. */
  1340. err = prom_getproperty(pnode, "reg",
  1341. (char *)&pr_regs[0], sizeof(pr_regs));
  1342. if(err == 0 || err == -1) {
  1343. prom_printf("SABRE: Error, cannot get U2P registers "
  1344. "from PROM.\n");
  1345. prom_halt();
  1346. }
  1347. /*
  1348. * First REG in property is base of entire SABRE register space.
  1349. */
  1350. p->pbm_A.controller_regs = pr_regs[0].phys_addr;
  1351. p->pbm_B.controller_regs = pr_regs[0].phys_addr;
  1352. printk("PCI: Found SABRE, main regs at %016lx\n",
  1353. p->pbm_A.controller_regs);
  1354. /* Clear interrupts */
  1355. /* PCI first */
  1356. for (clear_irq = SABRE_ICLR_A_SLOT0; clear_irq < SABRE_ICLR_B_SLOT0 + 0x80; clear_irq += 8)
  1357. sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
  1358. /* Then OBIO */
  1359. for (clear_irq = SABRE_ICLR_SCSI; clear_irq < SABRE_ICLR_SCSI + 0x80; clear_irq += 8)
  1360. sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
  1361. /* Error interrupts are enabled later after the bus scan. */
  1362. sabre_write(p->pbm_A.controller_regs + SABRE_PCICTRL,
  1363. (SABRE_PCICTRL_MRLEN | SABRE_PCICTRL_SERR |
  1364. SABRE_PCICTRL_ARBPARK | SABRE_PCICTRL_AEN));
  1365. /* Now map in PCI config space for entire SABRE. */
  1366. p->pbm_A.config_space = p->pbm_B.config_space =
  1367. (p->pbm_A.controller_regs + SABRE_CONFIGSPACE);
  1368. printk("SABRE: Shared PCI config space at %016lx\n",
  1369. p->pbm_A.config_space);
  1370. err = prom_getproperty(pnode, "virtual-dma",
  1371. (char *)&vdma[0], sizeof(vdma));
  1372. if(err == 0 || err == -1) {
  1373. prom_printf("SABRE: Error, cannot get virtual-dma property "
  1374. "from PROM.\n");
  1375. prom_halt();
  1376. }
  1377. dma_mask = vdma[0];
  1378. switch(vdma[1]) {
  1379. case 0x20000000:
  1380. dma_mask |= 0x1fffffff;
  1381. tsbsize = 64;
  1382. break;
  1383. case 0x40000000:
  1384. dma_mask |= 0x3fffffff;
  1385. tsbsize = 128;
  1386. break;
  1387. case 0x80000000:
  1388. dma_mask |= 0x7fffffff;
  1389. tsbsize = 128;
  1390. break;
  1391. default:
  1392. prom_printf("SABRE: strange virtual-dma size.\n");
  1393. prom_halt();
  1394. }
  1395. sabre_iommu_init(p, tsbsize, vdma[0], dma_mask);
  1396. printk("SABRE: DVMA at %08x [%08x]\n", vdma[0], vdma[1]);
  1397. err = prom_getproperty(pnode, "bus-range",
  1398. (char *)&busrange[0], sizeof(busrange));
  1399. if(err == 0 || err == -1) {
  1400. prom_printf("SABRE: Error, cannot get PCI bus-range "
  1401. " from PROM.\n");
  1402. prom_halt();
  1403. }
  1404. p->pci_first_busno = busrange[0];
  1405. p->pci_last_busno = busrange[1];
  1406. /*
  1407. * Look for APB underneath.
  1408. */
  1409. sabre_pbm_init(p, pnode, vdma[0]);
  1410. }