pci_sabre.c 50 KB

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