pci_sabre.c 43 KB

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