pci_sabre.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708
  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. /* PCI SABRE INO number to Sparc PIL level. */
  480. static unsigned char sabre_pil_table[] = {
  481. /*0x00*/0, 0, 0, 0, /* PCI A slot 0 Int A, B, C, D */
  482. /*0x04*/0, 0, 0, 0, /* PCI A slot 1 Int A, B, C, D */
  483. /*0x08*/0, 0, 0, 0, /* PCI A slot 2 Int A, B, C, D */
  484. /*0x0c*/0, 0, 0, 0, /* PCI A slot 3 Int A, B, C, D */
  485. /*0x10*/0, 0, 0, 0, /* PCI B slot 0 Int A, B, C, D */
  486. /*0x14*/0, 0, 0, 0, /* PCI B slot 1 Int A, B, C, D */
  487. /*0x18*/0, 0, 0, 0, /* PCI B slot 2 Int A, B, C, D */
  488. /*0x1c*/0, 0, 0, 0, /* PCI B slot 3 Int A, B, C, D */
  489. /*0x20*/4, /* SCSI */
  490. /*0x21*/5, /* Ethernet */
  491. /*0x22*/8, /* Parallel Port */
  492. /*0x23*/13, /* Audio Record */
  493. /*0x24*/14, /* Audio Playback */
  494. /*0x25*/15, /* PowerFail */
  495. /*0x26*/4, /* second SCSI */
  496. /*0x27*/11, /* Floppy */
  497. /*0x28*/4, /* Spare Hardware */
  498. /*0x29*/9, /* Keyboard */
  499. /*0x2a*/4, /* Mouse */
  500. /*0x2b*/12, /* Serial */
  501. /*0x2c*/10, /* Timer 0 */
  502. /*0x2d*/11, /* Timer 1 */
  503. /*0x2e*/15, /* Uncorrectable ECC */
  504. /*0x2f*/15, /* Correctable ECC */
  505. /*0x30*/15, /* PCI Bus A Error */
  506. /*0x31*/15, /* PCI Bus B Error */
  507. /*0x32*/15, /* Power Management */
  508. };
  509. static int sabre_ino_to_pil(struct pci_dev *pdev, unsigned int ino)
  510. {
  511. int ret;
  512. if (pdev &&
  513. pdev->vendor == PCI_VENDOR_ID_SUN &&
  514. pdev->device == PCI_DEVICE_ID_SUN_RIO_USB)
  515. return 9;
  516. ret = sabre_pil_table[ino];
  517. if (ret == 0 && pdev == NULL) {
  518. ret = 4;
  519. } else if (ret == 0) {
  520. switch ((pdev->class >> 16) & 0xff) {
  521. case PCI_BASE_CLASS_STORAGE:
  522. ret = 4;
  523. break;
  524. case PCI_BASE_CLASS_NETWORK:
  525. ret = 6;
  526. break;
  527. case PCI_BASE_CLASS_DISPLAY:
  528. ret = 9;
  529. break;
  530. case PCI_BASE_CLASS_MULTIMEDIA:
  531. case PCI_BASE_CLASS_MEMORY:
  532. case PCI_BASE_CLASS_BRIDGE:
  533. case PCI_BASE_CLASS_SERIAL:
  534. ret = 10;
  535. break;
  536. default:
  537. ret = 4;
  538. break;
  539. };
  540. }
  541. return ret;
  542. }
  543. /* When a device lives behind a bridge deeper in the PCI bus topology
  544. * than APB, a special sequence must run to make sure all pending DMA
  545. * transfers at the time of IRQ delivery are visible in the coherency
  546. * domain by the cpu. This sequence is to perform a read on the far
  547. * side of the non-APB bridge, then perform a read of Sabre's DMA
  548. * write-sync register.
  549. */
  550. static void sabre_wsync_handler(struct ino_bucket *bucket, void *_arg1, void *_arg2)
  551. {
  552. struct pci_dev *pdev = _arg1;
  553. unsigned long sync_reg = (unsigned long) _arg2;
  554. u16 _unused;
  555. pci_read_config_word(pdev, PCI_VENDOR_ID, &_unused);
  556. sabre_read(sync_reg);
  557. }
  558. static unsigned int sabre_irq_build(struct pci_pbm_info *pbm,
  559. struct pci_dev *pdev,
  560. unsigned int ino)
  561. {
  562. struct ino_bucket *bucket;
  563. unsigned long imap, iclr;
  564. unsigned long imap_off, iclr_off;
  565. int pil, inofixup = 0;
  566. ino &= PCI_IRQ_INO;
  567. if (ino < SABRE_ONBOARD_IRQ_BASE) {
  568. /* PCI slot */
  569. imap_off = sabre_pcislot_imap_offset(ino);
  570. } else {
  571. /* onboard device */
  572. if (ino > SABRE_ONBOARD_IRQ_LAST) {
  573. prom_printf("sabre_irq_build: Wacky INO [%x]\n", ino);
  574. prom_halt();
  575. }
  576. imap_off = sabre_onboard_imap_offset(ino);
  577. }
  578. /* Now build the IRQ bucket. */
  579. pil = sabre_ino_to_pil(pdev, ino);
  580. if (PIL_RESERVED(pil))
  581. BUG();
  582. imap = pbm->controller_regs + imap_off;
  583. imap += 4;
  584. iclr_off = sabre_iclr_offset(ino);
  585. iclr = pbm->controller_regs + iclr_off;
  586. iclr += 4;
  587. if ((ino & 0x20) == 0)
  588. inofixup = ino & 0x03;
  589. bucket = __bucket(build_irq(pil, inofixup, iclr, imap));
  590. bucket->flags |= IBF_PCI;
  591. if (pdev) {
  592. struct pcidev_cookie *pcp = pdev->sysdata;
  593. if (pdev->bus->number != pcp->pbm->pci_first_busno) {
  594. struct pci_controller_info *p = pcp->pbm->parent;
  595. struct irq_desc *d = bucket->irq_info;
  596. d->pre_handler = sabre_wsync_handler;
  597. d->pre_handler_arg1 = pdev;
  598. d->pre_handler_arg2 = (void *)
  599. p->pbm_A.controller_regs + SABRE_WRSYNC;
  600. }
  601. }
  602. return __irq(bucket);
  603. }
  604. /* SABRE error handling support. */
  605. static void sabre_check_iommu_error(struct pci_controller_info *p,
  606. unsigned long afsr,
  607. unsigned long afar)
  608. {
  609. struct pci_iommu *iommu = p->pbm_A.iommu;
  610. unsigned long iommu_tag[16];
  611. unsigned long iommu_data[16];
  612. unsigned long flags;
  613. u64 control;
  614. int i;
  615. spin_lock_irqsave(&iommu->lock, flags);
  616. control = sabre_read(iommu->iommu_control);
  617. if (control & SABRE_IOMMUCTRL_ERR) {
  618. char *type_string;
  619. /* Clear the error encountered bit.
  620. * NOTE: On Sabre this is write 1 to clear,
  621. * which is different from Psycho.
  622. */
  623. sabre_write(iommu->iommu_control, control);
  624. switch((control & SABRE_IOMMUCTRL_ERRSTS) >> 25UL) {
  625. case 1:
  626. type_string = "Invalid Error";
  627. break;
  628. case 3:
  629. type_string = "ECC Error";
  630. break;
  631. default:
  632. type_string = "Unknown";
  633. break;
  634. };
  635. printk("SABRE%d: IOMMU Error, type[%s]\n",
  636. p->index, type_string);
  637. /* Enter diagnostic mode and probe for error'd
  638. * entries in the IOTLB.
  639. */
  640. control &= ~(SABRE_IOMMUCTRL_ERRSTS | SABRE_IOMMUCTRL_ERR);
  641. sabre_write(iommu->iommu_control,
  642. (control | SABRE_IOMMUCTRL_DENAB));
  643. for (i = 0; i < 16; i++) {
  644. unsigned long base = p->pbm_A.controller_regs;
  645. iommu_tag[i] =
  646. sabre_read(base + SABRE_IOMMU_TAG + (i * 8UL));
  647. iommu_data[i] =
  648. sabre_read(base + SABRE_IOMMU_DATA + (i * 8UL));
  649. sabre_write(base + SABRE_IOMMU_TAG + (i * 8UL), 0);
  650. sabre_write(base + SABRE_IOMMU_DATA + (i * 8UL), 0);
  651. }
  652. sabre_write(iommu->iommu_control, control);
  653. for (i = 0; i < 16; i++) {
  654. unsigned long tag, data;
  655. tag = iommu_tag[i];
  656. if (!(tag & SABRE_IOMMUTAG_ERR))
  657. continue;
  658. data = iommu_data[i];
  659. switch((tag & SABRE_IOMMUTAG_ERRSTS) >> 23UL) {
  660. case 1:
  661. type_string = "Invalid Error";
  662. break;
  663. case 3:
  664. type_string = "ECC Error";
  665. break;
  666. default:
  667. type_string = "Unknown";
  668. break;
  669. };
  670. printk("SABRE%d: IOMMU TAG(%d)[RAW(%016lx)error(%s)wr(%d)sz(%dK)vpg(%08lx)]\n",
  671. p->index, i, tag, type_string,
  672. ((tag & SABRE_IOMMUTAG_WRITE) ? 1 : 0),
  673. ((tag & SABRE_IOMMUTAG_SIZE) ? 64 : 8),
  674. ((tag & SABRE_IOMMUTAG_VPN) << IOMMU_PAGE_SHIFT));
  675. printk("SABRE%d: IOMMU DATA(%d)[RAW(%016lx)valid(%d)used(%d)cache(%d)ppg(%016lx)\n",
  676. p->index, i, data,
  677. ((data & SABRE_IOMMUDATA_VALID) ? 1 : 0),
  678. ((data & SABRE_IOMMUDATA_USED) ? 1 : 0),
  679. ((data & SABRE_IOMMUDATA_CACHE) ? 1 : 0),
  680. ((data & SABRE_IOMMUDATA_PPN) << IOMMU_PAGE_SHIFT));
  681. }
  682. }
  683. spin_unlock_irqrestore(&iommu->lock, flags);
  684. }
  685. static irqreturn_t sabre_ue_intr(int irq, void *dev_id, struct pt_regs *regs)
  686. {
  687. struct pci_controller_info *p = dev_id;
  688. unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_UE_AFSR;
  689. unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
  690. unsigned long afsr, afar, error_bits;
  691. int reported;
  692. /* Latch uncorrectable error status. */
  693. afar = sabre_read(afar_reg);
  694. afsr = sabre_read(afsr_reg);
  695. /* Clear the primary/secondary error status bits. */
  696. error_bits = afsr &
  697. (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
  698. SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
  699. SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE);
  700. if (!error_bits)
  701. return IRQ_NONE;
  702. sabre_write(afsr_reg, error_bits);
  703. /* Log the error. */
  704. printk("SABRE%d: Uncorrectable Error, primary error type[%s%s]\n",
  705. p->index,
  706. ((error_bits & SABRE_UEAFSR_PDRD) ?
  707. "DMA Read" :
  708. ((error_bits & SABRE_UEAFSR_PDWR) ?
  709. "DMA Write" : "???")),
  710. ((error_bits & SABRE_UEAFSR_PDTE) ?
  711. ":Translation Error" : ""));
  712. printk("SABRE%d: bytemask[%04lx] dword_offset[%lx] was_block(%d)\n",
  713. p->index,
  714. (afsr & SABRE_UEAFSR_BMSK) >> 32UL,
  715. (afsr & SABRE_UEAFSR_OFF) >> 29UL,
  716. ((afsr & SABRE_UEAFSR_BLK) ? 1 : 0));
  717. printk("SABRE%d: UE AFAR [%016lx]\n", p->index, afar);
  718. printk("SABRE%d: UE Secondary errors [", p->index);
  719. reported = 0;
  720. if (afsr & SABRE_UEAFSR_SDRD) {
  721. reported++;
  722. printk("(DMA Read)");
  723. }
  724. if (afsr & SABRE_UEAFSR_SDWR) {
  725. reported++;
  726. printk("(DMA Write)");
  727. }
  728. if (afsr & SABRE_UEAFSR_SDTE) {
  729. reported++;
  730. printk("(Translation Error)");
  731. }
  732. if (!reported)
  733. printk("(none)");
  734. printk("]\n");
  735. /* Interrogate IOMMU for error status. */
  736. sabre_check_iommu_error(p, afsr, afar);
  737. return IRQ_HANDLED;
  738. }
  739. static irqreturn_t sabre_ce_intr(int irq, void *dev_id, struct pt_regs *regs)
  740. {
  741. struct pci_controller_info *p = dev_id;
  742. unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_CE_AFSR;
  743. unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
  744. unsigned long afsr, afar, error_bits;
  745. int reported;
  746. /* Latch error status. */
  747. afar = sabre_read(afar_reg);
  748. afsr = sabre_read(afsr_reg);
  749. /* Clear primary/secondary error status bits. */
  750. error_bits = afsr &
  751. (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
  752. SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR);
  753. if (!error_bits)
  754. return IRQ_NONE;
  755. sabre_write(afsr_reg, error_bits);
  756. /* Log the error. */
  757. printk("SABRE%d: Correctable Error, primary error type[%s]\n",
  758. p->index,
  759. ((error_bits & SABRE_CEAFSR_PDRD) ?
  760. "DMA Read" :
  761. ((error_bits & SABRE_CEAFSR_PDWR) ?
  762. "DMA Write" : "???")));
  763. /* XXX Use syndrome and afar to print out module string just like
  764. * XXX UDB CE trap handler does... -DaveM
  765. */
  766. printk("SABRE%d: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
  767. "was_block(%d)\n",
  768. p->index,
  769. (afsr & SABRE_CEAFSR_ESYND) >> 48UL,
  770. (afsr & SABRE_CEAFSR_BMSK) >> 32UL,
  771. (afsr & SABRE_CEAFSR_OFF) >> 29UL,
  772. ((afsr & SABRE_CEAFSR_BLK) ? 1 : 0));
  773. printk("SABRE%d: CE AFAR [%016lx]\n", p->index, afar);
  774. printk("SABRE%d: CE Secondary errors [", p->index);
  775. reported = 0;
  776. if (afsr & SABRE_CEAFSR_SDRD) {
  777. reported++;
  778. printk("(DMA Read)");
  779. }
  780. if (afsr & SABRE_CEAFSR_SDWR) {
  781. reported++;
  782. printk("(DMA Write)");
  783. }
  784. if (!reported)
  785. printk("(none)");
  786. printk("]\n");
  787. return IRQ_HANDLED;
  788. }
  789. static irqreturn_t sabre_pcierr_intr_other(struct pci_controller_info *p)
  790. {
  791. unsigned long csr_reg, csr, csr_error_bits;
  792. irqreturn_t ret = IRQ_NONE;
  793. u16 stat;
  794. csr_reg = p->pbm_A.controller_regs + SABRE_PCICTRL;
  795. csr = sabre_read(csr_reg);
  796. csr_error_bits =
  797. csr & SABRE_PCICTRL_SERR;
  798. if (csr_error_bits) {
  799. /* Clear the errors. */
  800. sabre_write(csr_reg, csr);
  801. /* Log 'em. */
  802. if (csr_error_bits & SABRE_PCICTRL_SERR)
  803. printk("SABRE%d: PCI SERR signal asserted.\n",
  804. p->index);
  805. ret = IRQ_HANDLED;
  806. }
  807. pci_read_config_word(sabre_root_bus->self,
  808. PCI_STATUS, &stat);
  809. if (stat & (PCI_STATUS_PARITY |
  810. PCI_STATUS_SIG_TARGET_ABORT |
  811. PCI_STATUS_REC_TARGET_ABORT |
  812. PCI_STATUS_REC_MASTER_ABORT |
  813. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  814. printk("SABRE%d: PCI bus error, PCI_STATUS[%04x]\n",
  815. p->index, stat);
  816. pci_write_config_word(sabre_root_bus->self,
  817. PCI_STATUS, 0xffff);
  818. ret = IRQ_HANDLED;
  819. }
  820. return ret;
  821. }
  822. static irqreturn_t sabre_pcierr_intr(int irq, void *dev_id, struct pt_regs *regs)
  823. {
  824. struct pci_controller_info *p = dev_id;
  825. unsigned long afsr_reg, afar_reg;
  826. unsigned long afsr, afar, error_bits;
  827. int reported;
  828. afsr_reg = p->pbm_A.controller_regs + SABRE_PIOAFSR;
  829. afar_reg = p->pbm_A.controller_regs + SABRE_PIOAFAR;
  830. /* Latch error status. */
  831. afar = sabre_read(afar_reg);
  832. afsr = sabre_read(afsr_reg);
  833. /* Clear primary/secondary error status bits. */
  834. error_bits = afsr &
  835. (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_PTA |
  836. SABRE_PIOAFSR_PRTRY | SABRE_PIOAFSR_PPERR |
  837. SABRE_PIOAFSR_SMA | SABRE_PIOAFSR_STA |
  838. SABRE_PIOAFSR_SRTRY | SABRE_PIOAFSR_SPERR);
  839. if (!error_bits)
  840. return sabre_pcierr_intr_other(p);
  841. sabre_write(afsr_reg, error_bits);
  842. /* Log the error. */
  843. printk("SABRE%d: PCI Error, primary error type[%s]\n",
  844. p->index,
  845. (((error_bits & SABRE_PIOAFSR_PMA) ?
  846. "Master Abort" :
  847. ((error_bits & SABRE_PIOAFSR_PTA) ?
  848. "Target Abort" :
  849. ((error_bits & SABRE_PIOAFSR_PRTRY) ?
  850. "Excessive Retries" :
  851. ((error_bits & SABRE_PIOAFSR_PPERR) ?
  852. "Parity Error" : "???"))))));
  853. printk("SABRE%d: bytemask[%04lx] was_block(%d)\n",
  854. p->index,
  855. (afsr & SABRE_PIOAFSR_BMSK) >> 32UL,
  856. (afsr & SABRE_PIOAFSR_BLK) ? 1 : 0);
  857. printk("SABRE%d: PCI AFAR [%016lx]\n", p->index, afar);
  858. printk("SABRE%d: PCI Secondary errors [", p->index);
  859. reported = 0;
  860. if (afsr & SABRE_PIOAFSR_SMA) {
  861. reported++;
  862. printk("(Master Abort)");
  863. }
  864. if (afsr & SABRE_PIOAFSR_STA) {
  865. reported++;
  866. printk("(Target Abort)");
  867. }
  868. if (afsr & SABRE_PIOAFSR_SRTRY) {
  869. reported++;
  870. printk("(Excessive Retries)");
  871. }
  872. if (afsr & SABRE_PIOAFSR_SPERR) {
  873. reported++;
  874. printk("(Parity Error)");
  875. }
  876. if (!reported)
  877. printk("(none)");
  878. printk("]\n");
  879. /* For the error types shown, scan both PCI buses for devices
  880. * which have logged that error type.
  881. */
  882. /* If we see a Target Abort, this could be the result of an
  883. * IOMMU translation error of some sort. It is extremely
  884. * useful to log this information as usually it indicates
  885. * a bug in the IOMMU support code or a PCI device driver.
  886. */
  887. if (error_bits & (SABRE_PIOAFSR_PTA | SABRE_PIOAFSR_STA)) {
  888. sabre_check_iommu_error(p, afsr, afar);
  889. pci_scan_for_target_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
  890. pci_scan_for_target_abort(p, &p->pbm_B, p->pbm_B.pci_bus);
  891. }
  892. if (error_bits & (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_SMA)) {
  893. pci_scan_for_master_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
  894. pci_scan_for_master_abort(p, &p->pbm_B, p->pbm_B.pci_bus);
  895. }
  896. /* For excessive retries, SABRE/PBM will abort the device
  897. * and there is no way to specifically check for excessive
  898. * retries in the config space status registers. So what
  899. * we hope is that we'll catch it via the master/target
  900. * abort events.
  901. */
  902. if (error_bits & (SABRE_PIOAFSR_PPERR | SABRE_PIOAFSR_SPERR)) {
  903. pci_scan_for_parity_error(p, &p->pbm_A, p->pbm_A.pci_bus);
  904. pci_scan_for_parity_error(p, &p->pbm_B, p->pbm_B.pci_bus);
  905. }
  906. return IRQ_HANDLED;
  907. }
  908. /* XXX What about PowerFail/PowerManagement??? -DaveM */
  909. #define SABRE_UE_INO 0x2e
  910. #define SABRE_CE_INO 0x2f
  911. #define SABRE_PCIERR_INO 0x30
  912. static void sabre_register_error_handlers(struct pci_controller_info *p)
  913. {
  914. struct pci_pbm_info *pbm = &p->pbm_A; /* arbitrary */
  915. unsigned long base = pbm->controller_regs;
  916. unsigned long irq, portid = pbm->portid;
  917. u64 tmp;
  918. /* We clear the error bits in the appropriate AFSR before
  919. * registering the handler so that we don't get spurious
  920. * interrupts.
  921. */
  922. sabre_write(base + SABRE_UE_AFSR,
  923. (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
  924. SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
  925. SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE));
  926. irq = sabre_irq_build(pbm, NULL, (portid << 6) | SABRE_UE_INO);
  927. if (request_irq(irq, sabre_ue_intr,
  928. SA_SHIRQ, "SABRE UE", p) < 0) {
  929. prom_printf("SABRE%d: Cannot register UE interrupt.\n",
  930. p->index);
  931. prom_halt();
  932. }
  933. sabre_write(base + SABRE_CE_AFSR,
  934. (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
  935. SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR));
  936. irq = sabre_irq_build(pbm, NULL, (portid << 6) | SABRE_CE_INO);
  937. if (request_irq(irq, sabre_ce_intr,
  938. SA_SHIRQ, "SABRE CE", p) < 0) {
  939. prom_printf("SABRE%d: Cannot register CE interrupt.\n",
  940. p->index);
  941. prom_halt();
  942. }
  943. irq = sabre_irq_build(pbm, NULL, (portid << 6) | SABRE_PCIERR_INO);
  944. if (request_irq(irq, sabre_pcierr_intr,
  945. SA_SHIRQ, "SABRE PCIERR", p) < 0) {
  946. prom_printf("SABRE%d: Cannot register PciERR interrupt.\n",
  947. p->index);
  948. prom_halt();
  949. }
  950. tmp = sabre_read(base + SABRE_PCICTRL);
  951. tmp |= SABRE_PCICTRL_ERREN;
  952. sabre_write(base + SABRE_PCICTRL, tmp);
  953. }
  954. static void sabre_resource_adjust(struct pci_dev *pdev,
  955. struct resource *res,
  956. struct resource *root)
  957. {
  958. struct pci_pbm_info *pbm = pdev->bus->sysdata;
  959. unsigned long base;
  960. if (res->flags & IORESOURCE_IO)
  961. base = pbm->controller_regs + SABRE_IOSPACE;
  962. else
  963. base = pbm->controller_regs + SABRE_MEMSPACE;
  964. res->start += base;
  965. res->end += base;
  966. }
  967. static void sabre_base_address_update(struct pci_dev *pdev, int resource)
  968. {
  969. struct pcidev_cookie *pcp = pdev->sysdata;
  970. struct pci_pbm_info *pbm = pcp->pbm;
  971. struct resource *res;
  972. unsigned long base;
  973. u32 reg;
  974. int where, size, is_64bit;
  975. res = &pdev->resource[resource];
  976. if (resource < 6) {
  977. where = PCI_BASE_ADDRESS_0 + (resource * 4);
  978. } else if (resource == PCI_ROM_RESOURCE) {
  979. where = pdev->rom_base_reg;
  980. } else {
  981. /* Somebody might have asked allocation of a non-standard resource */
  982. return;
  983. }
  984. is_64bit = 0;
  985. if (res->flags & IORESOURCE_IO)
  986. base = pbm->controller_regs + SABRE_IOSPACE;
  987. else {
  988. base = pbm->controller_regs + SABRE_MEMSPACE;
  989. if ((res->flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
  990. == PCI_BASE_ADDRESS_MEM_TYPE_64)
  991. is_64bit = 1;
  992. }
  993. size = res->end - res->start;
  994. pci_read_config_dword(pdev, where, &reg);
  995. reg = ((reg & size) |
  996. (((u32)(res->start - base)) & ~size));
  997. if (resource == PCI_ROM_RESOURCE) {
  998. reg |= PCI_ROM_ADDRESS_ENABLE;
  999. res->flags |= IORESOURCE_ROM_ENABLE;
  1000. }
  1001. pci_write_config_dword(pdev, where, reg);
  1002. /* This knows that the upper 32-bits of the address
  1003. * must be zero. Our PCI common layer enforces this.
  1004. */
  1005. if (is_64bit)
  1006. pci_write_config_dword(pdev, where + 4, 0);
  1007. }
  1008. static void apb_init(struct pci_controller_info *p, struct pci_bus *sabre_bus)
  1009. {
  1010. struct pci_dev *pdev;
  1011. list_for_each_entry(pdev, &sabre_bus->devices, bus_list) {
  1012. if (pdev->vendor == PCI_VENDOR_ID_SUN &&
  1013. pdev->device == PCI_DEVICE_ID_SUN_SIMBA) {
  1014. u32 word32;
  1015. u16 word16;
  1016. sabre_read_pci_cfg(pdev->bus, pdev->devfn,
  1017. PCI_COMMAND, 2, &word32);
  1018. word16 = (u16) word32;
  1019. word16 |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
  1020. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
  1021. PCI_COMMAND_IO;
  1022. word32 = (u32) word16;
  1023. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  1024. PCI_COMMAND, 2, word32);
  1025. /* Status register bits are "write 1 to clear". */
  1026. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  1027. PCI_STATUS, 2, 0xffff);
  1028. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  1029. PCI_SEC_STATUS, 2, 0xffff);
  1030. /* Use a primary/seconday latency timer value
  1031. * of 64.
  1032. */
  1033. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  1034. PCI_LATENCY_TIMER, 1, 64);
  1035. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  1036. PCI_SEC_LATENCY_TIMER, 1, 64);
  1037. /* Enable reporting/forwarding of master aborts,
  1038. * parity, and SERR.
  1039. */
  1040. sabre_write_pci_cfg(pdev->bus, pdev->devfn,
  1041. PCI_BRIDGE_CONTROL, 1,
  1042. (PCI_BRIDGE_CTL_PARITY |
  1043. PCI_BRIDGE_CTL_SERR |
  1044. PCI_BRIDGE_CTL_MASTER_ABORT));
  1045. }
  1046. }
  1047. }
  1048. static struct pcidev_cookie *alloc_bridge_cookie(struct pci_pbm_info *pbm)
  1049. {
  1050. struct pcidev_cookie *cookie = kmalloc(sizeof(*cookie), GFP_KERNEL);
  1051. if (!cookie) {
  1052. prom_printf("SABRE: Critical allocation failure.\n");
  1053. prom_halt();
  1054. }
  1055. /* All we care about is the PBM. */
  1056. memset(cookie, 0, sizeof(*cookie));
  1057. cookie->pbm = pbm;
  1058. return cookie;
  1059. }
  1060. static void sabre_scan_bus(struct pci_controller_info *p)
  1061. {
  1062. static int once;
  1063. struct pci_bus *sabre_bus, *pbus;
  1064. struct pci_pbm_info *pbm;
  1065. struct pcidev_cookie *cookie;
  1066. int sabres_scanned;
  1067. /* The APB bridge speaks to the Sabre host PCI bridge
  1068. * at 66Mhz, but the front side of APB runs at 33Mhz
  1069. * for both segments.
  1070. */
  1071. p->pbm_A.is_66mhz_capable = 0;
  1072. p->pbm_B.is_66mhz_capable = 0;
  1073. /* This driver has not been verified to handle
  1074. * multiple SABREs yet, so trap this.
  1075. *
  1076. * Also note that the SABRE host bridge is hardwired
  1077. * to live at bus 0.
  1078. */
  1079. if (once != 0) {
  1080. prom_printf("SABRE: Multiple controllers unsupported.\n");
  1081. prom_halt();
  1082. }
  1083. once++;
  1084. cookie = alloc_bridge_cookie(&p->pbm_A);
  1085. sabre_bus = pci_scan_bus(p->pci_first_busno,
  1086. p->pci_ops,
  1087. &p->pbm_A);
  1088. pci_fixup_host_bridge_self(sabre_bus);
  1089. sabre_bus->self->sysdata = cookie;
  1090. sabre_root_bus = sabre_bus;
  1091. apb_init(p, sabre_bus);
  1092. sabres_scanned = 0;
  1093. list_for_each_entry(pbus, &sabre_bus->children, node) {
  1094. if (pbus->number == p->pbm_A.pci_first_busno) {
  1095. pbm = &p->pbm_A;
  1096. } else if (pbus->number == p->pbm_B.pci_first_busno) {
  1097. pbm = &p->pbm_B;
  1098. } else
  1099. continue;
  1100. cookie = alloc_bridge_cookie(pbm);
  1101. pbus->self->sysdata = cookie;
  1102. sabres_scanned++;
  1103. pbus->sysdata = pbm;
  1104. pbm->pci_bus = pbus;
  1105. pci_fill_in_pbm_cookies(pbus, pbm, pbm->prom_node);
  1106. pci_record_assignments(pbm, pbus);
  1107. pci_assign_unassigned(pbm, pbus);
  1108. pci_fixup_irq(pbm, pbus);
  1109. pci_determine_66mhz_disposition(pbm, pbus);
  1110. pci_setup_busmastering(pbm, pbus);
  1111. }
  1112. if (!sabres_scanned) {
  1113. /* Hummingbird, no APBs. */
  1114. pbm = &p->pbm_A;
  1115. sabre_bus->sysdata = pbm;
  1116. pbm->pci_bus = sabre_bus;
  1117. pci_fill_in_pbm_cookies(sabre_bus, pbm, pbm->prom_node);
  1118. pci_record_assignments(pbm, sabre_bus);
  1119. pci_assign_unassigned(pbm, sabre_bus);
  1120. pci_fixup_irq(pbm, sabre_bus);
  1121. pci_determine_66mhz_disposition(pbm, sabre_bus);
  1122. pci_setup_busmastering(pbm, sabre_bus);
  1123. }
  1124. sabre_register_error_handlers(p);
  1125. }
  1126. static void sabre_iommu_init(struct pci_controller_info *p,
  1127. int tsbsize, unsigned long dvma_offset,
  1128. u32 dma_mask)
  1129. {
  1130. struct pci_iommu *iommu = p->pbm_A.iommu;
  1131. unsigned long tsbbase, i, order;
  1132. u64 control;
  1133. /* Setup initial software IOMMU state. */
  1134. spin_lock_init(&iommu->lock);
  1135. iommu->ctx_lowest_free = 1;
  1136. /* Register addresses. */
  1137. iommu->iommu_control = p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL;
  1138. iommu->iommu_tsbbase = p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE;
  1139. iommu->iommu_flush = p->pbm_A.controller_regs + SABRE_IOMMU_FLUSH;
  1140. iommu->write_complete_reg = p->pbm_A.controller_regs + SABRE_WRSYNC;
  1141. /* Sabre's IOMMU lacks ctx flushing. */
  1142. iommu->iommu_ctxflush = 0;
  1143. /* Invalidate TLB Entries. */
  1144. control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
  1145. control |= SABRE_IOMMUCTRL_DENAB;
  1146. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
  1147. for(i = 0; i < 16; i++) {
  1148. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TAG + (i * 8UL), 0);
  1149. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_DATA + (i * 8UL), 0);
  1150. }
  1151. /* Leave diag mode enabled for full-flushing done
  1152. * in pci_iommu.c
  1153. */
  1154. iommu->dummy_page = __get_free_pages(GFP_KERNEL, 0);
  1155. if (!iommu->dummy_page) {
  1156. prom_printf("PSYCHO_IOMMU: Error, gfp(dummy_page) failed.\n");
  1157. prom_halt();
  1158. }
  1159. memset((void *)iommu->dummy_page, 0, PAGE_SIZE);
  1160. iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page);
  1161. tsbbase = __get_free_pages(GFP_KERNEL, order = get_order(tsbsize * 1024 * 8));
  1162. if (!tsbbase) {
  1163. prom_printf("SABRE_IOMMU: Error, gfp(tsb) failed.\n");
  1164. prom_halt();
  1165. }
  1166. iommu->page_table = (iopte_t *)tsbbase;
  1167. iommu->page_table_map_base = dvma_offset;
  1168. iommu->dma_addr_mask = dma_mask;
  1169. pci_iommu_table_init(iommu, PAGE_SIZE << order);
  1170. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE, __pa(tsbbase));
  1171. control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
  1172. control &= ~(SABRE_IOMMUCTRL_TSBSZ | SABRE_IOMMUCTRL_TBWSZ);
  1173. control |= SABRE_IOMMUCTRL_ENAB;
  1174. switch(tsbsize) {
  1175. case 64:
  1176. control |= SABRE_IOMMU_TSBSZ_64K;
  1177. iommu->page_table_sz_bits = 16;
  1178. break;
  1179. case 128:
  1180. control |= SABRE_IOMMU_TSBSZ_128K;
  1181. iommu->page_table_sz_bits = 17;
  1182. break;
  1183. default:
  1184. prom_printf("iommu_init: Illegal TSB size %d\n", tsbsize);
  1185. prom_halt();
  1186. break;
  1187. }
  1188. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
  1189. /* We start with no consistent mappings. */
  1190. iommu->lowest_consistent_map =
  1191. 1 << (iommu->page_table_sz_bits - PBM_LOGCLUSTERS);
  1192. for (i = 0; i < PBM_NCLUSTERS; i++) {
  1193. iommu->alloc_info[i].flush = 0;
  1194. iommu->alloc_info[i].next = 0;
  1195. }
  1196. }
  1197. static void pbm_register_toplevel_resources(struct pci_controller_info *p,
  1198. struct pci_pbm_info *pbm)
  1199. {
  1200. char *name = pbm->name;
  1201. unsigned long ibase = p->pbm_A.controller_regs + SABRE_IOSPACE;
  1202. unsigned long mbase = p->pbm_A.controller_regs + SABRE_MEMSPACE;
  1203. unsigned int devfn;
  1204. unsigned long first, last, i;
  1205. u8 *addr, map;
  1206. sprintf(name, "SABRE%d PBM%c",
  1207. p->index,
  1208. (pbm == &p->pbm_A ? 'A' : 'B'));
  1209. pbm->io_space.name = pbm->mem_space.name = name;
  1210. devfn = PCI_DEVFN(1, (pbm == &p->pbm_A) ? 0 : 1);
  1211. addr = sabre_pci_config_mkaddr(pbm, 0, devfn, APB_IO_ADDRESS_MAP);
  1212. map = 0;
  1213. pci_config_read8(addr, &map);
  1214. first = 8;
  1215. last = 0;
  1216. for (i = 0; i < 8; i++) {
  1217. if ((map & (1 << i)) != 0) {
  1218. if (first > i)
  1219. first = i;
  1220. if (last < i)
  1221. last = i;
  1222. }
  1223. }
  1224. pbm->io_space.start = ibase + (first << 21UL);
  1225. pbm->io_space.end = ibase + (last << 21UL) + ((1 << 21UL) - 1);
  1226. pbm->io_space.flags = IORESOURCE_IO;
  1227. addr = sabre_pci_config_mkaddr(pbm, 0, devfn, APB_MEM_ADDRESS_MAP);
  1228. map = 0;
  1229. pci_config_read8(addr, &map);
  1230. first = 8;
  1231. last = 0;
  1232. for (i = 0; i < 8; i++) {
  1233. if ((map & (1 << i)) != 0) {
  1234. if (first > i)
  1235. first = i;
  1236. if (last < i)
  1237. last = i;
  1238. }
  1239. }
  1240. pbm->mem_space.start = mbase + (first << 29UL);
  1241. pbm->mem_space.end = mbase + (last << 29UL) + ((1 << 29UL) - 1);
  1242. pbm->mem_space.flags = IORESOURCE_MEM;
  1243. if (request_resource(&ioport_resource, &pbm->io_space) < 0) {
  1244. prom_printf("Cannot register PBM-%c's IO space.\n",
  1245. (pbm == &p->pbm_A ? 'A' : 'B'));
  1246. prom_halt();
  1247. }
  1248. if (request_resource(&iomem_resource, &pbm->mem_space) < 0) {
  1249. prom_printf("Cannot register PBM-%c's MEM space.\n",
  1250. (pbm == &p->pbm_A ? 'A' : 'B'));
  1251. prom_halt();
  1252. }
  1253. /* Register legacy regions if this PBM covers that area. */
  1254. if (pbm->io_space.start == ibase &&
  1255. pbm->mem_space.start == mbase)
  1256. pci_register_legacy_regions(&pbm->io_space,
  1257. &pbm->mem_space);
  1258. }
  1259. static void sabre_pbm_init(struct pci_controller_info *p, int sabre_node, u32 dma_begin)
  1260. {
  1261. struct pci_pbm_info *pbm;
  1262. char namebuf[128];
  1263. u32 busrange[2];
  1264. int node, simbas_found;
  1265. simbas_found = 0;
  1266. node = prom_getchild(sabre_node);
  1267. while ((node = prom_searchsiblings(node, "pci")) != 0) {
  1268. int err;
  1269. err = prom_getproperty(node, "model", namebuf, sizeof(namebuf));
  1270. if ((err <= 0) || strncmp(namebuf, "SUNW,simba", err))
  1271. goto next_pci;
  1272. err = prom_getproperty(node, "bus-range",
  1273. (char *)&busrange[0], sizeof(busrange));
  1274. if (err == 0 || err == -1) {
  1275. prom_printf("APB: Error, cannot get PCI bus-range.\n");
  1276. prom_halt();
  1277. }
  1278. simbas_found++;
  1279. if (busrange[0] == 1)
  1280. pbm = &p->pbm_B;
  1281. else
  1282. pbm = &p->pbm_A;
  1283. pbm->chip_type = PBM_CHIP_TYPE_SABRE;
  1284. pbm->parent = p;
  1285. pbm->prom_node = node;
  1286. pbm->pci_first_slot = 1;
  1287. pbm->pci_first_busno = busrange[0];
  1288. pbm->pci_last_busno = busrange[1];
  1289. prom_getstring(node, "name", pbm->prom_name, sizeof(pbm->prom_name));
  1290. err = prom_getproperty(node, "ranges",
  1291. (char *)pbm->pbm_ranges,
  1292. sizeof(pbm->pbm_ranges));
  1293. if (err != -1)
  1294. pbm->num_pbm_ranges =
  1295. (err / sizeof(struct linux_prom_pci_ranges));
  1296. else
  1297. pbm->num_pbm_ranges = 0;
  1298. err = prom_getproperty(node, "interrupt-map",
  1299. (char *)pbm->pbm_intmap,
  1300. sizeof(pbm->pbm_intmap));
  1301. if (err != -1) {
  1302. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  1303. err = prom_getproperty(node, "interrupt-map-mask",
  1304. (char *)&pbm->pbm_intmask,
  1305. sizeof(pbm->pbm_intmask));
  1306. if (err == -1) {
  1307. prom_printf("APB: Fatal error, no interrupt-map-mask.\n");
  1308. prom_halt();
  1309. }
  1310. } else {
  1311. pbm->num_pbm_intmap = 0;
  1312. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  1313. }
  1314. pbm_register_toplevel_resources(p, pbm);
  1315. next_pci:
  1316. node = prom_getsibling(node);
  1317. if (!node)
  1318. break;
  1319. }
  1320. if (simbas_found == 0) {
  1321. int err;
  1322. /* No APBs underneath, probably this is a hummingbird
  1323. * system.
  1324. */
  1325. pbm = &p->pbm_A;
  1326. pbm->parent = p;
  1327. pbm->prom_node = sabre_node;
  1328. pbm->pci_first_busno = p->pci_first_busno;
  1329. pbm->pci_last_busno = p->pci_last_busno;
  1330. prom_getstring(sabre_node, "name", pbm->prom_name, sizeof(pbm->prom_name));
  1331. err = prom_getproperty(sabre_node, "ranges",
  1332. (char *) pbm->pbm_ranges,
  1333. sizeof(pbm->pbm_ranges));
  1334. if (err != -1)
  1335. pbm->num_pbm_ranges =
  1336. (err / sizeof(struct linux_prom_pci_ranges));
  1337. else
  1338. pbm->num_pbm_ranges = 0;
  1339. err = prom_getproperty(sabre_node, "interrupt-map",
  1340. (char *) pbm->pbm_intmap,
  1341. sizeof(pbm->pbm_intmap));
  1342. if (err != -1) {
  1343. pbm->num_pbm_intmap = (err / sizeof(struct linux_prom_pci_intmap));
  1344. err = prom_getproperty(sabre_node, "interrupt-map-mask",
  1345. (char *)&pbm->pbm_intmask,
  1346. sizeof(pbm->pbm_intmask));
  1347. if (err == -1) {
  1348. prom_printf("Hummingbird: Fatal error, no interrupt-map-mask.\n");
  1349. prom_halt();
  1350. }
  1351. } else {
  1352. pbm->num_pbm_intmap = 0;
  1353. memset(&pbm->pbm_intmask, 0, sizeof(pbm->pbm_intmask));
  1354. }
  1355. sprintf(pbm->name, "SABRE%d PBM%c", p->index,
  1356. (pbm == &p->pbm_A ? 'A' : 'B'));
  1357. pbm->io_space.name = pbm->mem_space.name = pbm->name;
  1358. /* Hack up top-level resources. */
  1359. pbm->io_space.start = p->pbm_A.controller_regs + SABRE_IOSPACE;
  1360. pbm->io_space.end = pbm->io_space.start + (1UL << 24) - 1UL;
  1361. pbm->io_space.flags = IORESOURCE_IO;
  1362. pbm->mem_space.start = p->pbm_A.controller_regs + SABRE_MEMSPACE;
  1363. pbm->mem_space.end = pbm->mem_space.start + (unsigned long)dma_begin - 1UL;
  1364. pbm->mem_space.flags = IORESOURCE_MEM;
  1365. if (request_resource(&ioport_resource, &pbm->io_space) < 0) {
  1366. prom_printf("Cannot register Hummingbird's IO space.\n");
  1367. prom_halt();
  1368. }
  1369. if (request_resource(&iomem_resource, &pbm->mem_space) < 0) {
  1370. prom_printf("Cannot register Hummingbird's MEM space.\n");
  1371. prom_halt();
  1372. }
  1373. pci_register_legacy_regions(&pbm->io_space,
  1374. &pbm->mem_space);
  1375. }
  1376. }
  1377. void sabre_init(int pnode, char *model_name)
  1378. {
  1379. struct linux_prom64_registers pr_regs[2];
  1380. struct pci_controller_info *p;
  1381. struct pci_iommu *iommu;
  1382. int tsbsize, err;
  1383. u32 busrange[2];
  1384. u32 vdma[2];
  1385. u32 upa_portid, dma_mask;
  1386. u64 clear_irq;
  1387. hummingbird_p = 0;
  1388. if (!strcmp(model_name, "pci108e,a001"))
  1389. hummingbird_p = 1;
  1390. else if (!strcmp(model_name, "SUNW,sabre")) {
  1391. char compat[64];
  1392. if (prom_getproperty(pnode, "compatible",
  1393. compat, sizeof(compat)) > 0 &&
  1394. !strcmp(compat, "pci108e,a001")) {
  1395. hummingbird_p = 1;
  1396. } else {
  1397. int cpu_node;
  1398. /* Of course, Sun has to encode things a thousand
  1399. * different ways, inconsistently.
  1400. */
  1401. cpu_find_by_instance(0, &cpu_node, NULL);
  1402. if (prom_getproperty(cpu_node, "name",
  1403. compat, sizeof(compat)) > 0 &&
  1404. !strcmp(compat, "SUNW,UltraSPARC-IIe"))
  1405. hummingbird_p = 1;
  1406. }
  1407. }
  1408. p = kmalloc(sizeof(*p), GFP_ATOMIC);
  1409. if (!p) {
  1410. prom_printf("SABRE: Error, kmalloc(pci_controller_info) failed.\n");
  1411. prom_halt();
  1412. }
  1413. memset(p, 0, sizeof(*p));
  1414. iommu = kmalloc(sizeof(*iommu), GFP_ATOMIC);
  1415. if (!iommu) {
  1416. prom_printf("SABRE: Error, kmalloc(pci_iommu) failed.\n");
  1417. prom_halt();
  1418. }
  1419. memset(iommu, 0, sizeof(*iommu));
  1420. p->pbm_A.iommu = p->pbm_B.iommu = iommu;
  1421. upa_portid = prom_getintdefault(pnode, "upa-portid", 0xff);
  1422. p->next = pci_controller_root;
  1423. pci_controller_root = p;
  1424. p->pbm_A.portid = upa_portid;
  1425. p->pbm_B.portid = upa_portid;
  1426. p->index = pci_num_controllers++;
  1427. p->pbms_same_domain = 1;
  1428. p->scan_bus = sabre_scan_bus;
  1429. p->irq_build = sabre_irq_build;
  1430. p->base_address_update = sabre_base_address_update;
  1431. p->resource_adjust = sabre_resource_adjust;
  1432. p->pci_ops = &sabre_ops;
  1433. /*
  1434. * Map in SABRE register set and report the presence of this SABRE.
  1435. */
  1436. err = prom_getproperty(pnode, "reg",
  1437. (char *)&pr_regs[0], sizeof(pr_regs));
  1438. if(err == 0 || err == -1) {
  1439. prom_printf("SABRE: Error, cannot get U2P registers "
  1440. "from PROM.\n");
  1441. prom_halt();
  1442. }
  1443. /*
  1444. * First REG in property is base of entire SABRE register space.
  1445. */
  1446. p->pbm_A.controller_regs = pr_regs[0].phys_addr;
  1447. p->pbm_B.controller_regs = pr_regs[0].phys_addr;
  1448. printk("PCI: Found SABRE, main regs at %016lx\n",
  1449. p->pbm_A.controller_regs);
  1450. /* Clear interrupts */
  1451. /* PCI first */
  1452. for (clear_irq = SABRE_ICLR_A_SLOT0; clear_irq < SABRE_ICLR_B_SLOT0 + 0x80; clear_irq += 8)
  1453. sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
  1454. /* Then OBIO */
  1455. for (clear_irq = SABRE_ICLR_SCSI; clear_irq < SABRE_ICLR_SCSI + 0x80; clear_irq += 8)
  1456. sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
  1457. /* Error interrupts are enabled later after the bus scan. */
  1458. sabre_write(p->pbm_A.controller_regs + SABRE_PCICTRL,
  1459. (SABRE_PCICTRL_MRLEN | SABRE_PCICTRL_SERR |
  1460. SABRE_PCICTRL_ARBPARK | SABRE_PCICTRL_AEN));
  1461. /* Now map in PCI config space for entire SABRE. */
  1462. p->pbm_A.config_space = p->pbm_B.config_space =
  1463. (p->pbm_A.controller_regs + SABRE_CONFIGSPACE);
  1464. printk("SABRE: Shared PCI config space at %016lx\n",
  1465. p->pbm_A.config_space);
  1466. err = prom_getproperty(pnode, "virtual-dma",
  1467. (char *)&vdma[0], sizeof(vdma));
  1468. if(err == 0 || err == -1) {
  1469. prom_printf("SABRE: Error, cannot get virtual-dma property "
  1470. "from PROM.\n");
  1471. prom_halt();
  1472. }
  1473. dma_mask = vdma[0];
  1474. switch(vdma[1]) {
  1475. case 0x20000000:
  1476. dma_mask |= 0x1fffffff;
  1477. tsbsize = 64;
  1478. break;
  1479. case 0x40000000:
  1480. dma_mask |= 0x3fffffff;
  1481. tsbsize = 128;
  1482. break;
  1483. case 0x80000000:
  1484. dma_mask |= 0x7fffffff;
  1485. tsbsize = 128;
  1486. break;
  1487. default:
  1488. prom_printf("SABRE: strange virtual-dma size.\n");
  1489. prom_halt();
  1490. }
  1491. sabre_iommu_init(p, tsbsize, vdma[0], dma_mask);
  1492. printk("SABRE: DVMA at %08x [%08x]\n", vdma[0], vdma[1]);
  1493. err = prom_getproperty(pnode, "bus-range",
  1494. (char *)&busrange[0], sizeof(busrange));
  1495. if(err == 0 || err == -1) {
  1496. prom_printf("SABRE: Error, cannot get PCI bus-range "
  1497. " from PROM.\n");
  1498. prom_halt();
  1499. }
  1500. p->pci_first_busno = busrange[0];
  1501. p->pci_last_busno = busrange[1];
  1502. /*
  1503. * Look for APB underneath.
  1504. */
  1505. sabre_pbm_init(p, pnode, vdma[0]);
  1506. }