pci_sabre.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  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_B) &&
  245. (bus == pbm->pci_first_busno) &&
  246. PCI_SLOT(devfn) > 8) ||
  247. ((pbm == &pbm->parent->pbm_A) &&
  248. (bus == pbm->pci_first_busno) &&
  249. PCI_SLOT(devfn) > 8));
  250. }
  251. static int __sabre_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  252. int where, int size, u32 *value)
  253. {
  254. struct pci_pbm_info *pbm = bus_dev->sysdata;
  255. unsigned char bus = bus_dev->number;
  256. u32 *addr;
  257. u16 tmp16;
  258. u8 tmp8;
  259. switch (size) {
  260. case 1:
  261. *value = 0xff;
  262. break;
  263. case 2:
  264. *value = 0xffff;
  265. break;
  266. case 4:
  267. *value = 0xffffffff;
  268. break;
  269. }
  270. addr = sabre_pci_config_mkaddr(pbm, bus, devfn, where);
  271. if (!addr)
  272. return PCIBIOS_SUCCESSFUL;
  273. if (__sabre_out_of_range(pbm, bus, devfn))
  274. return PCIBIOS_SUCCESSFUL;
  275. switch (size) {
  276. case 1:
  277. pci_config_read8((u8 *) addr, &tmp8);
  278. *value = tmp8;
  279. break;
  280. case 2:
  281. if (where & 0x01) {
  282. printk("pci_read_config_word: misaligned reg [%x]\n",
  283. where);
  284. return PCIBIOS_SUCCESSFUL;
  285. }
  286. pci_config_read16((u16 *) addr, &tmp16);
  287. *value = tmp16;
  288. break;
  289. case 4:
  290. if (where & 0x03) {
  291. printk("pci_read_config_dword: misaligned reg [%x]\n",
  292. where);
  293. return PCIBIOS_SUCCESSFUL;
  294. }
  295. pci_config_read32(addr, value);
  296. break;
  297. }
  298. return PCIBIOS_SUCCESSFUL;
  299. }
  300. static int sabre_read_pci_cfg(struct pci_bus *bus, unsigned int devfn,
  301. int where, int size, u32 *value)
  302. {
  303. if (!bus->number && sabre_out_of_range(devfn)) {
  304. switch (size) {
  305. case 1:
  306. *value = 0xff;
  307. break;
  308. case 2:
  309. *value = 0xffff;
  310. break;
  311. case 4:
  312. *value = 0xffffffff;
  313. break;
  314. }
  315. return PCIBIOS_SUCCESSFUL;
  316. }
  317. if (bus->number || PCI_SLOT(devfn))
  318. return __sabre_read_pci_cfg(bus, devfn, where, size, value);
  319. /* When accessing PCI config space of the PCI controller itself (bus
  320. * 0, device slot 0, function 0) there are restrictions. Each
  321. * register must be accessed as it's natural size. Thus, for example
  322. * the Vendor ID must be accessed as a 16-bit quantity.
  323. */
  324. switch (size) {
  325. case 1:
  326. if (where < 8) {
  327. u32 tmp32;
  328. u16 tmp16;
  329. __sabre_read_pci_cfg(bus, devfn, where & ~1, 2, &tmp32);
  330. tmp16 = (u16) tmp32;
  331. if (where & 1)
  332. *value = tmp16 >> 8;
  333. else
  334. *value = tmp16 & 0xff;
  335. } else
  336. return __sabre_read_pci_cfg(bus, devfn, where, 1, value);
  337. break;
  338. case 2:
  339. if (where < 8)
  340. return __sabre_read_pci_cfg(bus, devfn, where, 2, value);
  341. else {
  342. u32 tmp32;
  343. u8 tmp8;
  344. __sabre_read_pci_cfg(bus, devfn, where, 1, &tmp32);
  345. tmp8 = (u8) tmp32;
  346. *value = tmp8;
  347. __sabre_read_pci_cfg(bus, devfn, where + 1, 1, &tmp32);
  348. tmp8 = (u8) tmp32;
  349. *value |= tmp8 << 8;
  350. }
  351. break;
  352. case 4: {
  353. u32 tmp32;
  354. u16 tmp16;
  355. sabre_read_pci_cfg(bus, devfn, where, 2, &tmp32);
  356. tmp16 = (u16) tmp32;
  357. *value = tmp16;
  358. sabre_read_pci_cfg(bus, devfn, where + 2, 2, &tmp32);
  359. tmp16 = (u16) tmp32;
  360. *value |= tmp16 << 16;
  361. break;
  362. }
  363. }
  364. return PCIBIOS_SUCCESSFUL;
  365. }
  366. static int __sabre_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  367. int where, int size, u32 value)
  368. {
  369. struct pci_pbm_info *pbm = bus_dev->sysdata;
  370. unsigned char bus = bus_dev->number;
  371. u32 *addr;
  372. addr = sabre_pci_config_mkaddr(pbm, bus, devfn, where);
  373. if (!addr)
  374. return PCIBIOS_SUCCESSFUL;
  375. if (__sabre_out_of_range(pbm, bus, devfn))
  376. return PCIBIOS_SUCCESSFUL;
  377. switch (size) {
  378. case 1:
  379. pci_config_write8((u8 *) addr, value);
  380. break;
  381. case 2:
  382. if (where & 0x01) {
  383. printk("pci_write_config_word: misaligned reg [%x]\n",
  384. where);
  385. return PCIBIOS_SUCCESSFUL;
  386. }
  387. pci_config_write16((u16 *) addr, value);
  388. break;
  389. case 4:
  390. if (where & 0x03) {
  391. printk("pci_write_config_dword: misaligned reg [%x]\n",
  392. where);
  393. return PCIBIOS_SUCCESSFUL;
  394. }
  395. pci_config_write32(addr, value);
  396. break;
  397. }
  398. return PCIBIOS_SUCCESSFUL;
  399. }
  400. static int sabre_write_pci_cfg(struct pci_bus *bus, unsigned int devfn,
  401. int where, int size, u32 value)
  402. {
  403. if (bus->number)
  404. return __sabre_write_pci_cfg(bus, devfn, where, size, value);
  405. if (sabre_out_of_range(devfn))
  406. return PCIBIOS_SUCCESSFUL;
  407. switch (size) {
  408. case 1:
  409. if (where < 8) {
  410. u32 tmp32;
  411. u16 tmp16;
  412. __sabre_read_pci_cfg(bus, devfn, where & ~1, 2, &tmp32);
  413. tmp16 = (u16) tmp32;
  414. if (where & 1) {
  415. value &= 0x00ff;
  416. value |= tmp16 << 8;
  417. } else {
  418. value &= 0xff00;
  419. value |= tmp16;
  420. }
  421. tmp32 = (u32) tmp16;
  422. return __sabre_write_pci_cfg(bus, devfn, where & ~1, 2, tmp32);
  423. } else
  424. return __sabre_write_pci_cfg(bus, devfn, where, 1, value);
  425. break;
  426. case 2:
  427. if (where < 8)
  428. return __sabre_write_pci_cfg(bus, devfn, where, 2, value);
  429. else {
  430. __sabre_write_pci_cfg(bus, devfn, where, 1, value & 0xff);
  431. __sabre_write_pci_cfg(bus, devfn, where + 1, 1, value >> 8);
  432. }
  433. break;
  434. case 4:
  435. sabre_write_pci_cfg(bus, devfn, where, 2, value & 0xffff);
  436. sabre_write_pci_cfg(bus, devfn, where + 2, 2, value >> 16);
  437. break;
  438. }
  439. return PCIBIOS_SUCCESSFUL;
  440. }
  441. static struct pci_ops sabre_ops = {
  442. .read = sabre_read_pci_cfg,
  443. .write = sabre_write_pci_cfg,
  444. };
  445. static unsigned long sabre_pcislot_imap_offset(unsigned long ino)
  446. {
  447. unsigned int bus = (ino & 0x10) >> 4;
  448. unsigned int slot = (ino & 0x0c) >> 2;
  449. if (bus == 0)
  450. return SABRE_IMAP_A_SLOT0 + (slot * 8);
  451. else
  452. return SABRE_IMAP_B_SLOT0 + (slot * 8);
  453. }
  454. static unsigned long __onboard_imap_off[] = {
  455. /*0x20*/ SABRE_IMAP_SCSI,
  456. /*0x21*/ SABRE_IMAP_ETH,
  457. /*0x22*/ SABRE_IMAP_BPP,
  458. /*0x23*/ SABRE_IMAP_AU_REC,
  459. /*0x24*/ SABRE_IMAP_AU_PLAY,
  460. /*0x25*/ SABRE_IMAP_PFAIL,
  461. /*0x26*/ SABRE_IMAP_KMS,
  462. /*0x27*/ SABRE_IMAP_FLPY,
  463. /*0x28*/ SABRE_IMAP_SHW,
  464. /*0x29*/ SABRE_IMAP_KBD,
  465. /*0x2a*/ SABRE_IMAP_MS,
  466. /*0x2b*/ SABRE_IMAP_SER,
  467. /*0x2c*/ 0 /* reserved */,
  468. /*0x2d*/ 0 /* reserved */,
  469. /*0x2e*/ SABRE_IMAP_UE,
  470. /*0x2f*/ SABRE_IMAP_CE,
  471. /*0x30*/ SABRE_IMAP_PCIERR,
  472. };
  473. #define SABRE_ONBOARD_IRQ_BASE 0x20
  474. #define SABRE_ONBOARD_IRQ_LAST 0x30
  475. #define sabre_onboard_imap_offset(__ino) \
  476. __onboard_imap_off[(__ino) - SABRE_ONBOARD_IRQ_BASE]
  477. #define sabre_iclr_offset(ino) \
  478. ((ino & 0x20) ? (SABRE_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
  479. (SABRE_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
  480. /* When a device lives behind a bridge deeper in the PCI bus topology
  481. * than APB, a special sequence must run to make sure all pending DMA
  482. * transfers at the time of IRQ delivery are visible in the coherency
  483. * domain by the cpu. This sequence is to perform a read on the far
  484. * side of the non-APB bridge, then perform a read of Sabre's DMA
  485. * write-sync register.
  486. */
  487. static void sabre_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
  488. {
  489. struct pci_dev *pdev = _arg1;
  490. unsigned long sync_reg = (unsigned long) _arg2;
  491. u16 _unused;
  492. pci_read_config_word(pdev, PCI_VENDOR_ID, &_unused);
  493. sabre_read(sync_reg);
  494. }
  495. static unsigned int sabre_irq_build(struct pci_pbm_info *pbm,
  496. struct pci_dev *pdev,
  497. unsigned int ino)
  498. {
  499. unsigned long imap, iclr;
  500. unsigned long imap_off, iclr_off;
  501. int inofixup = 0;
  502. int virt_irq;
  503. ino &= PCI_IRQ_INO;
  504. if (ino < SABRE_ONBOARD_IRQ_BASE) {
  505. /* PCI slot */
  506. imap_off = sabre_pcislot_imap_offset(ino);
  507. } else {
  508. /* onboard device */
  509. if (ino > SABRE_ONBOARD_IRQ_LAST) {
  510. prom_printf("sabre_irq_build: Wacky INO [%x]\n", ino);
  511. prom_halt();
  512. }
  513. imap_off = sabre_onboard_imap_offset(ino);
  514. }
  515. /* Now build the IRQ bucket. */
  516. imap = pbm->controller_regs + imap_off;
  517. imap += 4;
  518. iclr_off = sabre_iclr_offset(ino);
  519. iclr = pbm->controller_regs + iclr_off;
  520. iclr += 4;
  521. if ((ino & 0x20) == 0)
  522. inofixup = ino & 0x03;
  523. virt_irq = build_irq(inofixup, iclr, imap);
  524. if (pdev) {
  525. struct pcidev_cookie *pcp = pdev->sysdata;
  526. if (pdev->bus->number != pcp->pbm->pci_first_busno) {
  527. struct pci_controller_info *p = pcp->pbm->parent;
  528. irq_install_pre_handler(virt_irq,
  529. sabre_wsync_handler,
  530. pdev,
  531. (void *)
  532. p->pbm_A.controller_regs +
  533. SABRE_WRSYNC);
  534. }
  535. }
  536. return virt_irq;
  537. }
  538. /* SABRE error handling support. */
  539. static void sabre_check_iommu_error(struct pci_controller_info *p,
  540. unsigned long afsr,
  541. unsigned long afar)
  542. {
  543. struct pci_iommu *iommu = p->pbm_A.iommu;
  544. unsigned long iommu_tag[16];
  545. unsigned long iommu_data[16];
  546. unsigned long flags;
  547. u64 control;
  548. int i;
  549. spin_lock_irqsave(&iommu->lock, flags);
  550. control = sabre_read(iommu->iommu_control);
  551. if (control & SABRE_IOMMUCTRL_ERR) {
  552. char *type_string;
  553. /* Clear the error encountered bit.
  554. * NOTE: On Sabre this is write 1 to clear,
  555. * which is different from Psycho.
  556. */
  557. sabre_write(iommu->iommu_control, control);
  558. switch((control & SABRE_IOMMUCTRL_ERRSTS) >> 25UL) {
  559. case 1:
  560. type_string = "Invalid Error";
  561. break;
  562. case 3:
  563. type_string = "ECC Error";
  564. break;
  565. default:
  566. type_string = "Unknown";
  567. break;
  568. };
  569. printk("SABRE%d: IOMMU Error, type[%s]\n",
  570. p->index, type_string);
  571. /* Enter diagnostic mode and probe for error'd
  572. * entries in the IOTLB.
  573. */
  574. control &= ~(SABRE_IOMMUCTRL_ERRSTS | SABRE_IOMMUCTRL_ERR);
  575. sabre_write(iommu->iommu_control,
  576. (control | SABRE_IOMMUCTRL_DENAB));
  577. for (i = 0; i < 16; i++) {
  578. unsigned long base = p->pbm_A.controller_regs;
  579. iommu_tag[i] =
  580. sabre_read(base + SABRE_IOMMU_TAG + (i * 8UL));
  581. iommu_data[i] =
  582. sabre_read(base + SABRE_IOMMU_DATA + (i * 8UL));
  583. sabre_write(base + SABRE_IOMMU_TAG + (i * 8UL), 0);
  584. sabre_write(base + SABRE_IOMMU_DATA + (i * 8UL), 0);
  585. }
  586. sabre_write(iommu->iommu_control, control);
  587. for (i = 0; i < 16; i++) {
  588. unsigned long tag, data;
  589. tag = iommu_tag[i];
  590. if (!(tag & SABRE_IOMMUTAG_ERR))
  591. continue;
  592. data = iommu_data[i];
  593. switch((tag & SABRE_IOMMUTAG_ERRSTS) >> 23UL) {
  594. case 1:
  595. type_string = "Invalid Error";
  596. break;
  597. case 3:
  598. type_string = "ECC Error";
  599. break;
  600. default:
  601. type_string = "Unknown";
  602. break;
  603. };
  604. printk("SABRE%d: IOMMU TAG(%d)[RAW(%016lx)error(%s)wr(%d)sz(%dK)vpg(%08lx)]\n",
  605. p->index, i, tag, type_string,
  606. ((tag & SABRE_IOMMUTAG_WRITE) ? 1 : 0),
  607. ((tag & SABRE_IOMMUTAG_SIZE) ? 64 : 8),
  608. ((tag & SABRE_IOMMUTAG_VPN) << IOMMU_PAGE_SHIFT));
  609. printk("SABRE%d: IOMMU DATA(%d)[RAW(%016lx)valid(%d)used(%d)cache(%d)ppg(%016lx)\n",
  610. p->index, i, data,
  611. ((data & SABRE_IOMMUDATA_VALID) ? 1 : 0),
  612. ((data & SABRE_IOMMUDATA_USED) ? 1 : 0),
  613. ((data & SABRE_IOMMUDATA_CACHE) ? 1 : 0),
  614. ((data & SABRE_IOMMUDATA_PPN) << IOMMU_PAGE_SHIFT));
  615. }
  616. }
  617. spin_unlock_irqrestore(&iommu->lock, flags);
  618. }
  619. static irqreturn_t sabre_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
  620. {
  621. struct pci_controller_info *p = dev_id;
  622. unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_UE_AFSR;
  623. unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
  624. unsigned long afsr, afar, error_bits;
  625. int reported;
  626. /* Latch uncorrectable error status. */
  627. afar = sabre_read(afar_reg);
  628. afsr = sabre_read(afsr_reg);
  629. /* Clear the primary/secondary error status bits. */
  630. error_bits = afsr &
  631. (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
  632. SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
  633. SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE);
  634. if (!error_bits)
  635. return IRQ_NONE;
  636. sabre_write(afsr_reg, error_bits);
  637. /* Log the error. */
  638. printk("SABRE%d: Uncorrectable Error, primary error type[%s%s]\n",
  639. p->index,
  640. ((error_bits & SABRE_UEAFSR_PDRD) ?
  641. "DMA Read" :
  642. ((error_bits & SABRE_UEAFSR_PDWR) ?
  643. "DMA Write" : "???")),
  644. ((error_bits & SABRE_UEAFSR_PDTE) ?
  645. ":Translation Error" : ""));
  646. printk("SABRE%d: bytemask[%04lx] dword_offset[%lx] was_block(%d)\n",
  647. p->index,
  648. (afsr & SABRE_UEAFSR_BMSK) >> 32UL,
  649. (afsr & SABRE_UEAFSR_OFF) >> 29UL,
  650. ((afsr & SABRE_UEAFSR_BLK) ? 1 : 0));
  651. printk("SABRE%d: UE AFAR [%016lx]\n", p->index, afar);
  652. printk("SABRE%d: UE Secondary errors [", p->index);
  653. reported = 0;
  654. if (afsr & SABRE_UEAFSR_SDRD) {
  655. reported++;
  656. printk("(DMA Read)");
  657. }
  658. if (afsr & SABRE_UEAFSR_SDWR) {
  659. reported++;
  660. printk("(DMA Write)");
  661. }
  662. if (afsr & SABRE_UEAFSR_SDTE) {
  663. reported++;
  664. printk("(Translation Error)");
  665. }
  666. if (!reported)
  667. printk("(none)");
  668. printk("]\n");
  669. /* Interrogate IOMMU for error status. */
  670. sabre_check_iommu_error(p, afsr, afar);
  671. return IRQ_HANDLED;
  672. }
  673. static irqreturn_t sabre_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
  674. {
  675. struct pci_controller_info *p = dev_id;
  676. unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_CE_AFSR;
  677. unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
  678. unsigned long afsr, afar, error_bits;
  679. int reported;
  680. /* Latch error status. */
  681. afar = sabre_read(afar_reg);
  682. afsr = sabre_read(afsr_reg);
  683. /* Clear primary/secondary error status bits. */
  684. error_bits = afsr &
  685. (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
  686. SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR);
  687. if (!error_bits)
  688. return IRQ_NONE;
  689. sabre_write(afsr_reg, error_bits);
  690. /* Log the error. */
  691. printk("SABRE%d: Correctable Error, primary error type[%s]\n",
  692. p->index,
  693. ((error_bits & SABRE_CEAFSR_PDRD) ?
  694. "DMA Read" :
  695. ((error_bits & SABRE_CEAFSR_PDWR) ?
  696. "DMA Write" : "???")));
  697. /* XXX Use syndrome and afar to print out module string just like
  698. * XXX UDB CE trap handler does... -DaveM
  699. */
  700. printk("SABRE%d: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
  701. "was_block(%d)\n",
  702. p->index,
  703. (afsr & SABRE_CEAFSR_ESYND) >> 48UL,
  704. (afsr & SABRE_CEAFSR_BMSK) >> 32UL,
  705. (afsr & SABRE_CEAFSR_OFF) >> 29UL,
  706. ((afsr & SABRE_CEAFSR_BLK) ? 1 : 0));
  707. printk("SABRE%d: CE AFAR [%016lx]\n", p->index, afar);
  708. printk("SABRE%d: CE Secondary errors [", p->index);
  709. reported = 0;
  710. if (afsr & SABRE_CEAFSR_SDRD) {
  711. reported++;
  712. printk("(DMA Read)");
  713. }
  714. if (afsr & SABRE_CEAFSR_SDWR) {
  715. reported++;
  716. printk("(DMA Write)");
  717. }
  718. if (!reported)
  719. printk("(none)");
  720. printk("]\n");
  721. return IRQ_HANDLED;
  722. }
  723. static irqreturn_t sabre_pcierr_intr_other(struct pci_controller_info *p)
  724. {
  725. unsigned long csr_reg, csr, csr_error_bits;
  726. irqreturn_t ret = IRQ_NONE;
  727. u16 stat;
  728. csr_reg = p->pbm_A.controller_regs + SABRE_PCICTRL;
  729. csr = sabre_read(csr_reg);
  730. csr_error_bits =
  731. csr & SABRE_PCICTRL_SERR;
  732. if (csr_error_bits) {
  733. /* Clear the errors. */
  734. sabre_write(csr_reg, csr);
  735. /* Log 'em. */
  736. if (csr_error_bits & SABRE_PCICTRL_SERR)
  737. printk("SABRE%d: PCI SERR signal asserted.\n",
  738. p->index);
  739. ret = IRQ_HANDLED;
  740. }
  741. pci_read_config_word(sabre_root_bus->self,
  742. PCI_STATUS, &stat);
  743. if (stat & (PCI_STATUS_PARITY |
  744. PCI_STATUS_SIG_TARGET_ABORT |
  745. PCI_STATUS_REC_TARGET_ABORT |
  746. PCI_STATUS_REC_MASTER_ABORT |
  747. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  748. printk("SABRE%d: PCI bus error, PCI_STATUS[%04x]\n",
  749. p->index, stat);
  750. pci_write_config_word(sabre_root_bus->self,
  751. PCI_STATUS, 0xffff);
  752. ret = IRQ_HANDLED;
  753. }
  754. return ret;
  755. }
  756. static irqreturn_t sabre_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
  757. {
  758. struct pci_controller_info *p = dev_id;
  759. unsigned long afsr_reg, afar_reg;
  760. unsigned long afsr, afar, error_bits;
  761. int reported;
  762. afsr_reg = p->pbm_A.controller_regs + SABRE_PIOAFSR;
  763. afar_reg = p->pbm_A.controller_regs + SABRE_PIOAFAR;
  764. /* Latch error status. */
  765. afar = sabre_read(afar_reg);
  766. afsr = sabre_read(afsr_reg);
  767. /* Clear primary/secondary error status bits. */
  768. error_bits = afsr &
  769. (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_PTA |
  770. SABRE_PIOAFSR_PRTRY | SABRE_PIOAFSR_PPERR |
  771. SABRE_PIOAFSR_SMA | SABRE_PIOAFSR_STA |
  772. SABRE_PIOAFSR_SRTRY | SABRE_PIOAFSR_SPERR);
  773. if (!error_bits)
  774. return sabre_pcierr_intr_other(p);
  775. sabre_write(afsr_reg, error_bits);
  776. /* Log the error. */
  777. printk("SABRE%d: PCI Error, primary error type[%s]\n",
  778. p->index,
  779. (((error_bits & SABRE_PIOAFSR_PMA) ?
  780. "Master Abort" :
  781. ((error_bits & SABRE_PIOAFSR_PTA) ?
  782. "Target Abort" :
  783. ((error_bits & SABRE_PIOAFSR_PRTRY) ?
  784. "Excessive Retries" :
  785. ((error_bits & SABRE_PIOAFSR_PPERR) ?
  786. "Parity Error" : "???"))))));
  787. printk("SABRE%d: bytemask[%04lx] was_block(%d)\n",
  788. p->index,
  789. (afsr & SABRE_PIOAFSR_BMSK) >> 32UL,
  790. (afsr & SABRE_PIOAFSR_BLK) ? 1 : 0);
  791. printk("SABRE%d: PCI AFAR [%016lx]\n", p->index, afar);
  792. printk("SABRE%d: PCI Secondary errors [", p->index);
  793. reported = 0;
  794. if (afsr & SABRE_PIOAFSR_SMA) {
  795. reported++;
  796. printk("(Master Abort)");
  797. }
  798. if (afsr & SABRE_PIOAFSR_STA) {
  799. reported++;
  800. printk("(Target Abort)");
  801. }
  802. if (afsr & SABRE_PIOAFSR_SRTRY) {
  803. reported++;
  804. printk("(Excessive Retries)");
  805. }
  806. if (afsr & SABRE_PIOAFSR_SPERR) {
  807. reported++;
  808. printk("(Parity Error)");
  809. }
  810. if (!reported)
  811. printk("(none)");
  812. printk("]\n");
  813. /* For the error types shown, scan both PCI buses for devices
  814. * which have logged that error type.
  815. */
  816. /* If we see a Target Abort, this could be the result of an
  817. * IOMMU translation error of some sort. It is extremely
  818. * useful to log this information as usually it indicates
  819. * a bug in the IOMMU support code or a PCI device driver.
  820. */
  821. if (error_bits & (SABRE_PIOAFSR_PTA | SABRE_PIOAFSR_STA)) {
  822. sabre_check_iommu_error(p, afsr, afar);
  823. pci_scan_for_target_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
  824. pci_scan_for_target_abort(p, &p->pbm_B, p->pbm_B.pci_bus);
  825. }
  826. if (error_bits & (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_SMA)) {
  827. pci_scan_for_master_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
  828. pci_scan_for_master_abort(p, &p->pbm_B, p->pbm_B.pci_bus);
  829. }
  830. /* For excessive retries, SABRE/PBM will abort the device
  831. * and there is no way to specifically check for excessive
  832. * retries in the config space status registers. So what
  833. * we hope is that we'll catch it via the master/target
  834. * abort events.
  835. */
  836. if (error_bits & (SABRE_PIOAFSR_PPERR | SABRE_PIOAFSR_SPERR)) {
  837. pci_scan_for_parity_error(p, &p->pbm_A, p->pbm_A.pci_bus);
  838. pci_scan_for_parity_error(p, &p->pbm_B, p->pbm_B.pci_bus);
  839. }
  840. return IRQ_HANDLED;
  841. }
  842. /* XXX What about PowerFail/PowerManagement??? -DaveM */
  843. #define SABRE_UE_INO 0x2e
  844. #define SABRE_CE_INO 0x2f
  845. #define SABRE_PCIERR_INO 0x30
  846. static void sabre_register_error_handlers(struct pci_controller_info *p)
  847. {
  848. struct pci_pbm_info *pbm = &p->pbm_A; /* arbitrary */
  849. unsigned long base = pbm->controller_regs;
  850. unsigned long irq, portid = pbm->portid;
  851. u64 tmp;
  852. /* We clear the error bits in the appropriate AFSR before
  853. * registering the handler so that we don't get spurious
  854. * interrupts.
  855. */
  856. sabre_write(base + SABRE_UE_AFSR,
  857. (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
  858. SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
  859. SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE));
  860. irq = sabre_irq_build(pbm, NULL, (portid << 6) | SABRE_UE_INO);
  861. if (request_irq(irq, sabre_ue_intr,
  862. SA_SHIRQ, "SABRE UE", p) < 0) {
  863. prom_printf("SABRE%d: Cannot register UE interrupt.\n",
  864. p->index);
  865. prom_halt();
  866. }
  867. sabre_write(base + SABRE_CE_AFSR,
  868. (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
  869. SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR));
  870. irq = sabre_irq_build(pbm, NULL, (portid << 6) | SABRE_CE_INO);
  871. if (request_irq(irq, sabre_ce_intr,
  872. SA_SHIRQ, "SABRE CE", p) < 0) {
  873. prom_printf("SABRE%d: Cannot register CE interrupt.\n",
  874. p->index);
  875. prom_halt();
  876. }
  877. irq = sabre_irq_build(pbm, NULL, (portid << 6) | SABRE_PCIERR_INO);
  878. if (request_irq(irq, sabre_pcierr_intr,
  879. SA_SHIRQ, "SABRE PCIERR", p) < 0) {
  880. prom_printf("SABRE%d: Cannot register PciERR interrupt.\n",
  881. p->index);
  882. prom_halt();
  883. }
  884. tmp = sabre_read(base + SABRE_PCICTRL);
  885. tmp |= SABRE_PCICTRL_ERREN;
  886. sabre_write(base + SABRE_PCICTRL, tmp);
  887. }
  888. static void sabre_resource_adjust(struct pci_dev *pdev,
  889. struct resource *res,
  890. struct resource *root)
  891. {
  892. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  893. unsigned long base;
  894. if (res->flags & IORESOURCE_IO)
  895. base = pbm->controller_regs + SABRE_IOSPACE;
  896. else
  897. base = pbm->controller_regs + SABRE_MEMSPACE;
  898. res->start += base;
  899. res->end += base;
  900. }
  901. static void sabre_base_address_update(struct pci_dev *pdev, int resource)
  902. {
  903. struct pcidev_cookie *pcp = pdev->sysdata;
  904. struct pci_pbm_info *pbm = pcp->pbm;
  905. struct resource *res;
  906. unsigned long base;
  907. u32 reg;
  908. int where, size, is_64bit;
  909. res = &pdev->resource[resource];
  910. if (resource < 6) {
  911. where = PCI_BASE_ADDRESS_0 + (resource * 4);
  912. } else if (resource == PCI_ROM_RESOURCE) {
  913. where = pdev->rom_base_reg;
  914. } else {
  915. /* Somebody might have asked allocation of a non-standard resource */
  916. return;
  917. }
  918. is_64bit = 0;
  919. if (res->flags & IORESOURCE_IO)
  920. base = pbm->controller_regs + SABRE_IOSPACE;
  921. else {
  922. base = pbm->controller_regs + SABRE_MEMSPACE;
  923. if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
  924. == PCI_BASE_ADDRESS_MEM_TYPE_64)
  925. is_64bit = 1;
  926. }
  927. size = res->end - res->start;
  928. pci_read_config_dword(pdev, where, &reg);
  929. reg = ((reg & size) |
  930. (((u32)(res->start - base)) & ~size));
  931. if (resource == PCI_ROM_RESOURCE) {
  932. reg |= PCI_ROM_ADDRESS_ENABLE;
  933. res->flags |= IORESOURCE_ROM_ENABLE;
  934. }
  935. pci_write_config_dword(pdev, where, reg);
  936. /* This knows that the upper 32-bits of the address
  937. * must be zero. Our PCI common layer enforces this.
  938. */
  939. if (is_64bit)
  940. pci_write_config_dword(pdev, where + 4, 0);
  941. }
  942. static void apb_init(struct pci_controller_info *p, struct pci_bus *sabre_bus)
  943. {
  944. struct pci_dev *pdev;
  945. list_for_each_entry(pdev, &sabre_bus->devices, bus_list) {
  946. if (pdev->vendor == PCI_VENDOR_ID_SUN &&
  947. pdev->device == PCI_DEVICE_ID_SUN_SIMBA) {
  948. u32 word32;
  949. u16 word16;
  950. sabre_read_pci_cfg(pdev->bus, pdev->devfn,
  951. PCI_COMMAND, 2, &word32);
  952. word16 = (u16) word32;
  953. word16 |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
  954. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
  955. PCI_COMMAND_IO;
  956. word32 = (u32) word16;
  957. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  958. PCI_COMMAND, 2, word32);
  959. /* Status register bits are "write 1 to clear". */
  960. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  961. PCI_STATUS, 2, 0xffff);
  962. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  963. PCI_SEC_STATUS, 2, 0xffff);
  964. /* Use a primary/seconday latency timer value
  965. * of 64.
  966. */
  967. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  968. PCI_LATENCY_TIMER, 1, 64);
  969. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  970. PCI_SEC_LATENCY_TIMER, 1, 64);
  971. /* Enable reporting/forwarding of master aborts,
  972. * parity, and SERR.
  973. */
  974. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  975. PCI_BRIDGE_CONTROL, 1,
  976. (PCI_BRIDGE_CTL_PARITY |
  977. PCI_BRIDGE_CTL_SERR |
  978. PCI_BRIDGE_CTL_MASTER_ABORT));
  979. }
  980. }
  981. }
  982. static struct pcidev_cookie *alloc_bridge_cookie(struct pci_pbm_info *pbm)
  983. {
  984. struct pcidev_cookie *cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
  985. if (!cookie) {
  986. prom_printf("SABRE: Critical allocation failure.\n");
  987. prom_halt();
  988. }
  989. /* All we care about is the PBM. */
  990. cookie->pbm = pbm;
  991. return cookie;
  992. }
  993. static void sabre_scan_bus(struct pci_controller_info *p)
  994. {
  995. static int once;
  996. struct pci_bus *sabre_bus, *pbus;
  997. struct pci_pbm_info *pbm;
  998. struct pcidev_cookie *cookie;
  999. int sabres_scanned;
  1000. /* The APB bridge speaks to the Sabre host PCI bridge
  1001. * at 66Mhz, but the front side of APB runs at 33Mhz
  1002. * for both segments.
  1003. */
  1004. p->pbm_A.is_66mhz_capable = 0;
  1005. p->pbm_B.is_66mhz_capable = 0;
  1006. /* This driver has not been verified to handle
  1007. * multiple SABREs yet, so trap this.
  1008. *
  1009. * Also note that the SABRE host bridge is hardwired
  1010. * to live at bus 0.
  1011. */
  1012. if (once != 0) {
  1013. prom_printf("SABRE: Multiple controllers unsupported.\n");
  1014. prom_halt();
  1015. }
  1016. once++;
  1017. cookie = alloc_bridge_cookie(&p->pbm_A);
  1018. sabre_bus = pci_scan_bus(p->pci_first_busno,
  1019. p->pci_ops,
  1020. &p->pbm_A);
  1021. pci_fixup_host_bridge_self(sabre_bus);
  1022. sabre_bus->self->sysdata = cookie;
  1023. sabre_root_bus = sabre_bus;
  1024. apb_init(p, sabre_bus);
  1025. sabres_scanned = 0;
  1026. list_for_each_entry(pbus, &sabre_bus->children, node) {
  1027. if (pbus->number == p->pbm_A.pci_first_busno) {
  1028. pbm = &p->pbm_A;
  1029. } else if (pbus->number == p->pbm_B.pci_first_busno) {
  1030. pbm = &p->pbm_B;
  1031. } else
  1032. continue;
  1033. cookie = alloc_bridge_cookie(pbm);
  1034. pbus->self->sysdata = cookie;
  1035. sabres_scanned++;
  1036. pbus->sysdata = pbm;
  1037. pbm->pci_bus = pbus;
  1038. pci_fill_in_pbm_cookies(pbus, pbm, pbm->prom_node);
  1039. pci_record_assignments(pbm, pbus);
  1040. pci_assign_unassigned(pbm, pbus);
  1041. pci_fixup_irq(pbm, pbus);
  1042. pci_determine_66mhz_disposition(pbm, pbus);
  1043. pci_setup_busmastering(pbm, pbus);
  1044. }
  1045. if (!sabres_scanned) {
  1046. /* Hummingbird, no APBs. */
  1047. pbm = &p->pbm_A;
  1048. sabre_bus->sysdata = pbm;
  1049. pbm->pci_bus = sabre_bus;
  1050. pci_fill_in_pbm_cookies(sabre_bus, pbm, pbm->prom_node);
  1051. pci_record_assignments(pbm, sabre_bus);
  1052. pci_assign_unassigned(pbm, sabre_bus);
  1053. pci_fixup_irq(pbm, sabre_bus);
  1054. pci_determine_66mhz_disposition(pbm, sabre_bus);
  1055. pci_setup_busmastering(pbm, sabre_bus);
  1056. }
  1057. sabre_register_error_handlers(p);
  1058. }
  1059. static void sabre_iommu_init(struct pci_controller_info *p,
  1060. int tsbsize, unsigned long dvma_offset,
  1061. u32 dma_mask)
  1062. {
  1063. struct pci_iommu *iommu = p->pbm_A.iommu;
  1064. unsigned long i;
  1065. u64 control;
  1066. /* Register addresses. */
  1067. iommu->iommu_control = p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL;
  1068. iommu->iommu_tsbbase = p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE;
  1069. iommu->iommu_flush = p->pbm_A.controller_regs + SABRE_IOMMU_FLUSH;
  1070. iommu->write_complete_reg = p->pbm_A.controller_regs + SABRE_WRSYNC;
  1071. /* Sabre's IOMMU lacks ctx flushing. */
  1072. iommu->iommu_ctxflush = 0;
  1073. /* Invalidate TLB Entries. */
  1074. control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
  1075. control |= SABRE_IOMMUCTRL_DENAB;
  1076. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
  1077. for(i = 0; i < 16; i++) {
  1078. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TAG + (i * 8UL), 0);
  1079. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_DATA + (i * 8UL), 0);
  1080. }
  1081. /* Leave diag mode enabled for full-flushing done
  1082. * in pci_iommu.c
  1083. */
  1084. pci_iommu_table_init(iommu, tsbsize * 1024 * 8, dvma_offset, dma_mask);
  1085. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE,
  1086. __pa(iommu->page_table));
  1087. control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
  1088. control &= ~(SABRE_IOMMUCTRL_TSBSZ | SABRE_IOMMUCTRL_TBWSZ);
  1089. control |= SABRE_IOMMUCTRL_ENAB;
  1090. switch(tsbsize) {
  1091. case 64:
  1092. control |= SABRE_IOMMU_TSBSZ_64K;
  1093. break;
  1094. case 128:
  1095. control |= SABRE_IOMMU_TSBSZ_128K;
  1096. break;
  1097. default:
  1098. prom_printf("iommu_init: Illegal TSB size %d\n", tsbsize);
  1099. prom_halt();
  1100. break;
  1101. }
  1102. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
  1103. }
  1104. static void pbm_register_toplevel_resources(struct pci_controller_info *p,
  1105. struct pci_pbm_info *pbm)
  1106. {
  1107. char *name = pbm->name;
  1108. unsigned long ibase = p->pbm_A.controller_regs + SABRE_IOSPACE;
  1109. unsigned long mbase = p->pbm_A.controller_regs + SABRE_MEMSPACE;
  1110. unsigned int devfn;
  1111. unsigned long first, last, i;
  1112. u8 *addr, map;
  1113. sprintf(name, "SABRE%d PBM%c",
  1114. p->index,
  1115. (pbm == &p->pbm_A ? 'A' : 'B'));
  1116. pbm->io_space.name = pbm->mem_space.name = name;
  1117. devfn = PCI_DEVFN(1, (pbm == &p->pbm_A) ? 0 : 1);
  1118. addr = sabre_pci_config_mkaddr(pbm, 0, devfn, APB_IO_ADDRESS_MAP);
  1119. map = 0;
  1120. pci_config_read8(addr, &map);
  1121. first = 8;
  1122. last = 0;
  1123. for (i = 0; i < 8; i++) {
  1124. if ((map & (1 << i)) != 0) {
  1125. if (first > i)
  1126. first = i;
  1127. if (last < i)
  1128. last = i;
  1129. }
  1130. }
  1131. pbm->io_space.start = ibase + (first << 21UL);
  1132. pbm->io_space.end = ibase + (last << 21UL) + ((1 << 21UL) - 1);
  1133. pbm->io_space.flags = IORESOURCE_IO;
  1134. addr = sabre_pci_config_mkaddr(pbm, 0, devfn, APB_MEM_ADDRESS_MAP);
  1135. map = 0;
  1136. pci_config_read8(addr, &map);
  1137. first = 8;
  1138. last = 0;
  1139. for (i = 0; i < 8; i++) {
  1140. if ((map & (1 << i)) != 0) {
  1141. if (first > i)
  1142. first = i;
  1143. if (last < i)
  1144. last = i;
  1145. }
  1146. }
  1147. pbm->mem_space.start = mbase + (first << 29UL);
  1148. pbm->mem_space.end = mbase + (last << 29UL) + ((1 << 29UL) - 1);
  1149. pbm->mem_space.flags = IORESOURCE_MEM;
  1150. if (request_resource(&ioport_resource, &pbm->io_space) < 0) {
  1151. prom_printf("Cannot register PBM-%c's IO space.\n",
  1152. (pbm == &p->pbm_A ? 'A' : 'B'));
  1153. prom_halt();
  1154. }
  1155. if (request_resource(&iomem_resource, &pbm->mem_space) < 0) {
  1156. prom_printf("Cannot register PBM-%c's MEM space.\n",
  1157. (pbm == &p->pbm_A ? 'A' : 'B'));
  1158. prom_halt();
  1159. }
  1160. /* Register legacy regions if this PBM covers that area. */
  1161. if (pbm->io_space.start == ibase &&
  1162. pbm->mem_space.start == mbase)
  1163. pci_register_legacy_regions(&pbm->io_space,
  1164. &pbm->mem_space);
  1165. }
  1166. static void sabre_pbm_init(struct pci_controller_info *p, struct device_node *dp, u32 dma_begin)
  1167. {
  1168. struct pci_pbm_info *pbm;
  1169. struct device_node *node;
  1170. struct property *prop;
  1171. u32 *busrange;
  1172. int len, simbas_found;
  1173. simbas_found = 0;
  1174. node = dp->child;
  1175. while (node != NULL) {
  1176. if (strcmp(node->name, "pci"))
  1177. goto next_pci;
  1178. prop = of_find_property(node, "model", NULL);
  1179. if (!prop || strncmp(prop->value, "SUNW,simba", prop->length))
  1180. goto next_pci;
  1181. simbas_found++;
  1182. prop = of_find_property(node, "bus-range", NULL);
  1183. busrange = prop->value;
  1184. if (busrange[0] == 1)
  1185. pbm = &p->pbm_B;
  1186. else
  1187. pbm = &p->pbm_A;
  1188. pbm->name = node->full_name;
  1189. printk("%s: SABRE PCI Bus Module\n", pbm->name);
  1190. pbm->chip_type = PBM_CHIP_TYPE_SABRE;
  1191. pbm->parent = p;
  1192. pbm->prom_node = node;
  1193. pbm->pci_first_slot = 1;
  1194. pbm->pci_first_busno = busrange[0];
  1195. pbm->pci_last_busno = busrange[1];
  1196. prop = of_find_property(node, "ranges", &len);
  1197. if (prop) {
  1198. pbm->pbm_ranges = prop->value;
  1199. pbm->num_pbm_ranges =
  1200. (len / sizeof(struct linux_prom_pci_ranges));
  1201. } else {
  1202. pbm->num_pbm_ranges = 0;
  1203. }
  1204. prop = of_find_property(node, "interrupt-map", &len);
  1205. if (prop) {
  1206. pbm->pbm_intmap = prop->value;
  1207. pbm->num_pbm_intmap =
  1208. (len / sizeof(struct linux_prom_pci_intmap));
  1209. prop = of_find_property(node, "interrupt-map-mask",
  1210. NULL);
  1211. pbm->pbm_intmask = prop->value;
  1212. } else {
  1213. pbm->num_pbm_intmap = 0;
  1214. }
  1215. pbm_register_toplevel_resources(p, pbm);
  1216. next_pci:
  1217. node = node->sibling;
  1218. }
  1219. if (simbas_found == 0) {
  1220. /* No APBs underneath, probably this is a hummingbird
  1221. * system.
  1222. */
  1223. pbm = &p->pbm_A;
  1224. pbm->parent = p;
  1225. pbm->prom_node = dp;
  1226. pbm->pci_first_busno = p->pci_first_busno;
  1227. pbm->pci_last_busno = p->pci_last_busno;
  1228. prop = of_find_property(dp, "ranges", &len);
  1229. if (prop) {
  1230. pbm->pbm_ranges = prop->value;
  1231. pbm->num_pbm_ranges =
  1232. (len / sizeof(struct linux_prom_pci_ranges));
  1233. } else {
  1234. pbm->num_pbm_ranges = 0;
  1235. }
  1236. prop = of_find_property(dp, "interrupt-map", &len);
  1237. if (prop) {
  1238. pbm->pbm_intmap = prop->value;
  1239. pbm->num_pbm_intmap =
  1240. (len / sizeof(struct linux_prom_pci_intmap));
  1241. prop = of_find_property(dp, "interrupt-map-mask",
  1242. NULL);
  1243. pbm->pbm_intmask = prop->value;
  1244. } else {
  1245. pbm->num_pbm_intmap = 0;
  1246. }
  1247. pbm->name = dp->full_name;
  1248. printk("%s: SABRE PCI Bus Module\n", pbm->name);
  1249. pbm->io_space.name = pbm->mem_space.name = pbm->name;
  1250. /* Hack up top-level resources. */
  1251. pbm->io_space.start = p->pbm_A.controller_regs + SABRE_IOSPACE;
  1252. pbm->io_space.end = pbm->io_space.start + (1UL << 24) - 1UL;
  1253. pbm->io_space.flags = IORESOURCE_IO;
  1254. pbm->mem_space.start = p->pbm_A.controller_regs + SABRE_MEMSPACE;
  1255. pbm->mem_space.end = pbm->mem_space.start + (unsigned long)dma_begin - 1UL;
  1256. pbm->mem_space.flags = IORESOURCE_MEM;
  1257. if (request_resource(&ioport_resource, &pbm->io_space) < 0) {
  1258. prom_printf("Cannot register Hummingbird's IO space.\n");
  1259. prom_halt();
  1260. }
  1261. if (request_resource(&iomem_resource, &pbm->mem_space) < 0) {
  1262. prom_printf("Cannot register Hummingbird's MEM space.\n");
  1263. prom_halt();
  1264. }
  1265. pci_register_legacy_regions(&pbm->io_space,
  1266. &pbm->mem_space);
  1267. }
  1268. }
  1269. void sabre_init(struct device_node *dp, char *model_name)
  1270. {
  1271. struct linux_prom64_registers *pr_regs;
  1272. struct pci_controller_info *p;
  1273. struct pci_iommu *iommu;
  1274. struct property *prop;
  1275. int tsbsize;
  1276. u32 *busrange;
  1277. u32 *vdma;
  1278. u32 upa_portid, dma_mask;
  1279. u64 clear_irq;
  1280. hummingbird_p = 0;
  1281. if (!strcmp(model_name, "pci108e,a001"))
  1282. hummingbird_p = 1;
  1283. else if (!strcmp(model_name, "SUNW,sabre")) {
  1284. prop = of_find_property(dp, "compatible", NULL);
  1285. if (prop) {
  1286. const char *compat = prop->value;
  1287. if (!strcmp(compat, "pci108e,a001"))
  1288. hummingbird_p = 1;
  1289. }
  1290. if (!hummingbird_p) {
  1291. struct device_node *dp;
  1292. /* Of course, Sun has to encode things a thousand
  1293. * different ways, inconsistently.
  1294. */
  1295. cpu_find_by_instance(0, &dp, NULL);
  1296. if (!strcmp(dp->name, "SUNW,UltraSPARC-IIe"))
  1297. hummingbird_p = 1;
  1298. }
  1299. }
  1300. p = kzalloc(sizeof(*p), GFP_ATOMIC);
  1301. if (!p) {
  1302. prom_printf("SABRE: Error, kmalloc(pci_controller_info) failed.\n");
  1303. prom_halt();
  1304. }
  1305. iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
  1306. if (!iommu) {
  1307. prom_printf("SABRE: Error, kmalloc(pci_iommu) failed.\n");
  1308. prom_halt();
  1309. }
  1310. p->pbm_A.iommu = p->pbm_B.iommu = iommu;
  1311. upa_portid = 0xff;
  1312. prop = of_find_property(dp, "upa-portid", NULL);
  1313. if (prop)
  1314. upa_portid = *(u32 *) prop->value;
  1315. p->next = pci_controller_root;
  1316. pci_controller_root = p;
  1317. p->pbm_A.portid = upa_portid;
  1318. p->pbm_B.portid = upa_portid;
  1319. p->index = pci_num_controllers++;
  1320. p->pbms_same_domain = 1;
  1321. p->scan_bus = sabre_scan_bus;
  1322. p->irq_build = sabre_irq_build;
  1323. p->base_address_update = sabre_base_address_update;
  1324. p->resource_adjust = sabre_resource_adjust;
  1325. p->pci_ops = &sabre_ops;
  1326. /*
  1327. * Map in SABRE register set and report the presence of this SABRE.
  1328. */
  1329. prop = of_find_property(dp, "reg", NULL);
  1330. pr_regs = prop->value;
  1331. /*
  1332. * First REG in property is base of entire SABRE register space.
  1333. */
  1334. p->pbm_A.controller_regs = pr_regs[0].phys_addr;
  1335. p->pbm_B.controller_regs = pr_regs[0].phys_addr;
  1336. /* Clear interrupts */
  1337. /* PCI first */
  1338. for (clear_irq = SABRE_ICLR_A_SLOT0; clear_irq < SABRE_ICLR_B_SLOT0 + 0x80; clear_irq += 8)
  1339. sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
  1340. /* Then OBIO */
  1341. for (clear_irq = SABRE_ICLR_SCSI; clear_irq < SABRE_ICLR_SCSI + 0x80; clear_irq += 8)
  1342. sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
  1343. /* Error interrupts are enabled later after the bus scan. */
  1344. sabre_write(p->pbm_A.controller_regs + SABRE_PCICTRL,
  1345. (SABRE_PCICTRL_MRLEN | SABRE_PCICTRL_SERR |
  1346. SABRE_PCICTRL_ARBPARK | SABRE_PCICTRL_AEN));
  1347. /* Now map in PCI config space for entire SABRE. */
  1348. p->pbm_A.config_space = p->pbm_B.config_space =
  1349. (p->pbm_A.controller_regs + SABRE_CONFIGSPACE);
  1350. prop = of_find_property(dp, "virtual-dma", NULL);
  1351. vdma = prop->value;
  1352. dma_mask = vdma[0];
  1353. switch(vdma[1]) {
  1354. case 0x20000000:
  1355. dma_mask |= 0x1fffffff;
  1356. tsbsize = 64;
  1357. break;
  1358. case 0x40000000:
  1359. dma_mask |= 0x3fffffff;
  1360. tsbsize = 128;
  1361. break;
  1362. case 0x80000000:
  1363. dma_mask |= 0x7fffffff;
  1364. tsbsize = 128;
  1365. break;
  1366. default:
  1367. prom_printf("SABRE: strange virtual-dma size.\n");
  1368. prom_halt();
  1369. }
  1370. sabre_iommu_init(p, tsbsize, vdma[0], dma_mask);
  1371. prop = of_find_property(dp, "bus-range", NULL);
  1372. busrange = prop->value;
  1373. p->pci_first_busno = busrange[0];
  1374. p->pci_last_busno = busrange[1];
  1375. /*
  1376. * Look for APB underneath.
  1377. */
  1378. sabre_pbm_init(p, dp, vdma[0]);
  1379. }