pci_sabre.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. /* pci_sabre.c: Sabre specific PCI controller support.
  2. *
  3. * Copyright (C) 1997, 1998, 1999, 2007 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be)
  5. * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/types.h>
  9. #include <linux/pci.h>
  10. #include <linux/init.h>
  11. #include <linux/slab.h>
  12. #include <linux/interrupt.h>
  13. #include <asm/apb.h>
  14. #include <asm/pbm.h>
  15. #include <asm/iommu.h>
  16. #include <asm/irq.h>
  17. #include <asm/smp.h>
  18. #include <asm/oplib.h>
  19. #include <asm/prom.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_A) &&
  244. (bus == pbm->pci_first_busno) &&
  245. PCI_SLOT(devfn) > 8));
  246. }
  247. static int __sabre_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
  248. int where, int size, u32 *value)
  249. {
  250. struct pci_pbm_info *pbm = bus_dev->sysdata;
  251. unsigned char bus = bus_dev->number;
  252. u32 *addr;
  253. u16 tmp16;
  254. u8 tmp8;
  255. switch (size) {
  256. case 1:
  257. *value = 0xff;
  258. break;
  259. case 2:
  260. *value = 0xffff;
  261. break;
  262. case 4:
  263. *value = 0xffffffff;
  264. break;
  265. }
  266. addr = sabre_pci_config_mkaddr(pbm, bus, devfn, where);
  267. if (!addr)
  268. return PCIBIOS_SUCCESSFUL;
  269. if (__sabre_out_of_range(pbm, bus, devfn))
  270. return PCIBIOS_SUCCESSFUL;
  271. switch (size) {
  272. case 1:
  273. pci_config_read8((u8 *) addr, &tmp8);
  274. *value = tmp8;
  275. break;
  276. case 2:
  277. if (where & 0x01) {
  278. printk("pci_read_config_word: misaligned reg [%x]\n",
  279. where);
  280. return PCIBIOS_SUCCESSFUL;
  281. }
  282. pci_config_read16((u16 *) addr, &tmp16);
  283. *value = tmp16;
  284. break;
  285. case 4:
  286. if (where & 0x03) {
  287. printk("pci_read_config_dword: misaligned reg [%x]\n",
  288. where);
  289. return PCIBIOS_SUCCESSFUL;
  290. }
  291. pci_config_read32(addr, value);
  292. break;
  293. }
  294. return PCIBIOS_SUCCESSFUL;
  295. }
  296. static int sabre_read_pci_cfg(struct pci_bus *bus, unsigned int devfn,
  297. int where, int size, u32 *value)
  298. {
  299. struct pci_pbm_info *pbm = bus->sysdata;
  300. if (bus == pbm->pci_bus && devfn == 0x00)
  301. return pci_host_bridge_read_pci_cfg(bus, devfn, where,
  302. size, value);
  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. struct pci_pbm_info *pbm = bus->sysdata;
  404. if (bus == pbm->pci_bus && devfn == 0x00)
  405. return pci_host_bridge_write_pci_cfg(bus, devfn, where,
  406. size, value);
  407. if (bus->number)
  408. return __sabre_write_pci_cfg(bus, devfn, where, size, value);
  409. if (sabre_out_of_range(devfn))
  410. return PCIBIOS_SUCCESSFUL;
  411. switch (size) {
  412. case 1:
  413. if (where < 8) {
  414. u32 tmp32;
  415. u16 tmp16;
  416. __sabre_read_pci_cfg(bus, devfn, where & ~1, 2, &tmp32);
  417. tmp16 = (u16) tmp32;
  418. if (where & 1) {
  419. value &= 0x00ff;
  420. value |= tmp16 << 8;
  421. } else {
  422. value &= 0xff00;
  423. value |= tmp16;
  424. }
  425. tmp32 = (u32) tmp16;
  426. return __sabre_write_pci_cfg(bus, devfn, where & ~1, 2, tmp32);
  427. } else
  428. return __sabre_write_pci_cfg(bus, devfn, where, 1, value);
  429. break;
  430. case 2:
  431. if (where < 8)
  432. return __sabre_write_pci_cfg(bus, devfn, where, 2, value);
  433. else {
  434. __sabre_write_pci_cfg(bus, devfn, where, 1, value & 0xff);
  435. __sabre_write_pci_cfg(bus, devfn, where + 1, 1, value >> 8);
  436. }
  437. break;
  438. case 4:
  439. sabre_write_pci_cfg(bus, devfn, where, 2, value & 0xffff);
  440. sabre_write_pci_cfg(bus, devfn, where + 2, 2, value >> 16);
  441. break;
  442. }
  443. return PCIBIOS_SUCCESSFUL;
  444. }
  445. static struct pci_ops sabre_ops = {
  446. .read = sabre_read_pci_cfg,
  447. .write = sabre_write_pci_cfg,
  448. };
  449. /* SABRE error handling support. */
  450. static void sabre_check_iommu_error(struct pci_controller_info *p,
  451. unsigned long afsr,
  452. unsigned long afar)
  453. {
  454. struct iommu *iommu = p->pbm_A.iommu;
  455. unsigned long iommu_tag[16];
  456. unsigned long iommu_data[16];
  457. unsigned long flags;
  458. u64 control;
  459. int i;
  460. spin_lock_irqsave(&iommu->lock, flags);
  461. control = sabre_read(iommu->iommu_control);
  462. if (control & SABRE_IOMMUCTRL_ERR) {
  463. char *type_string;
  464. /* Clear the error encountered bit.
  465. * NOTE: On Sabre this is write 1 to clear,
  466. * which is different from Psycho.
  467. */
  468. sabre_write(iommu->iommu_control, control);
  469. switch((control & SABRE_IOMMUCTRL_ERRSTS) >> 25UL) {
  470. case 1:
  471. type_string = "Invalid Error";
  472. break;
  473. case 3:
  474. type_string = "ECC Error";
  475. break;
  476. default:
  477. type_string = "Unknown";
  478. break;
  479. };
  480. printk("SABRE%d: IOMMU Error, type[%s]\n",
  481. p->index, type_string);
  482. /* Enter diagnostic mode and probe for error'd
  483. * entries in the IOTLB.
  484. */
  485. control &= ~(SABRE_IOMMUCTRL_ERRSTS | SABRE_IOMMUCTRL_ERR);
  486. sabre_write(iommu->iommu_control,
  487. (control | SABRE_IOMMUCTRL_DENAB));
  488. for (i = 0; i < 16; i++) {
  489. unsigned long base = p->pbm_A.controller_regs;
  490. iommu_tag[i] =
  491. sabre_read(base + SABRE_IOMMU_TAG + (i * 8UL));
  492. iommu_data[i] =
  493. sabre_read(base + SABRE_IOMMU_DATA + (i * 8UL));
  494. sabre_write(base + SABRE_IOMMU_TAG + (i * 8UL), 0);
  495. sabre_write(base + SABRE_IOMMU_DATA + (i * 8UL), 0);
  496. }
  497. sabre_write(iommu->iommu_control, control);
  498. for (i = 0; i < 16; i++) {
  499. unsigned long tag, data;
  500. tag = iommu_tag[i];
  501. if (!(tag & SABRE_IOMMUTAG_ERR))
  502. continue;
  503. data = iommu_data[i];
  504. switch((tag & SABRE_IOMMUTAG_ERRSTS) >> 23UL) {
  505. case 1:
  506. type_string = "Invalid Error";
  507. break;
  508. case 3:
  509. type_string = "ECC Error";
  510. break;
  511. default:
  512. type_string = "Unknown";
  513. break;
  514. };
  515. printk("SABRE%d: IOMMU TAG(%d)[RAW(%016lx)error(%s)wr(%d)sz(%dK)vpg(%08lx)]\n",
  516. p->index, i, tag, type_string,
  517. ((tag & SABRE_IOMMUTAG_WRITE) ? 1 : 0),
  518. ((tag & SABRE_IOMMUTAG_SIZE) ? 64 : 8),
  519. ((tag & SABRE_IOMMUTAG_VPN) << IOMMU_PAGE_SHIFT));
  520. printk("SABRE%d: IOMMU DATA(%d)[RAW(%016lx)valid(%d)used(%d)cache(%d)ppg(%016lx)\n",
  521. p->index, i, data,
  522. ((data & SABRE_IOMMUDATA_VALID) ? 1 : 0),
  523. ((data & SABRE_IOMMUDATA_USED) ? 1 : 0),
  524. ((data & SABRE_IOMMUDATA_CACHE) ? 1 : 0),
  525. ((data & SABRE_IOMMUDATA_PPN) << IOMMU_PAGE_SHIFT));
  526. }
  527. }
  528. spin_unlock_irqrestore(&iommu->lock, flags);
  529. }
  530. static irqreturn_t sabre_ue_intr(int irq, void *dev_id)
  531. {
  532. struct pci_controller_info *p = dev_id;
  533. unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_UE_AFSR;
  534. unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
  535. unsigned long afsr, afar, error_bits;
  536. int reported;
  537. /* Latch uncorrectable error status. */
  538. afar = sabre_read(afar_reg);
  539. afsr = sabre_read(afsr_reg);
  540. /* Clear the primary/secondary error status bits. */
  541. error_bits = afsr &
  542. (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
  543. SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
  544. SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE);
  545. if (!error_bits)
  546. return IRQ_NONE;
  547. sabre_write(afsr_reg, error_bits);
  548. /* Log the error. */
  549. printk("SABRE%d: Uncorrectable Error, primary error type[%s%s]\n",
  550. p->index,
  551. ((error_bits & SABRE_UEAFSR_PDRD) ?
  552. "DMA Read" :
  553. ((error_bits & SABRE_UEAFSR_PDWR) ?
  554. "DMA Write" : "???")),
  555. ((error_bits & SABRE_UEAFSR_PDTE) ?
  556. ":Translation Error" : ""));
  557. printk("SABRE%d: bytemask[%04lx] dword_offset[%lx] was_block(%d)\n",
  558. p->index,
  559. (afsr & SABRE_UEAFSR_BMSK) >> 32UL,
  560. (afsr & SABRE_UEAFSR_OFF) >> 29UL,
  561. ((afsr & SABRE_UEAFSR_BLK) ? 1 : 0));
  562. printk("SABRE%d: UE AFAR [%016lx]\n", p->index, afar);
  563. printk("SABRE%d: UE Secondary errors [", p->index);
  564. reported = 0;
  565. if (afsr & SABRE_UEAFSR_SDRD) {
  566. reported++;
  567. printk("(DMA Read)");
  568. }
  569. if (afsr & SABRE_UEAFSR_SDWR) {
  570. reported++;
  571. printk("(DMA Write)");
  572. }
  573. if (afsr & SABRE_UEAFSR_SDTE) {
  574. reported++;
  575. printk("(Translation Error)");
  576. }
  577. if (!reported)
  578. printk("(none)");
  579. printk("]\n");
  580. /* Interrogate IOMMU for error status. */
  581. sabre_check_iommu_error(p, afsr, afar);
  582. return IRQ_HANDLED;
  583. }
  584. static irqreturn_t sabre_ce_intr(int irq, void *dev_id)
  585. {
  586. struct pci_controller_info *p = dev_id;
  587. unsigned long afsr_reg = p->pbm_A.controller_regs + SABRE_CE_AFSR;
  588. unsigned long afar_reg = p->pbm_A.controller_regs + SABRE_UECE_AFAR;
  589. unsigned long afsr, afar, error_bits;
  590. int reported;
  591. /* Latch error status. */
  592. afar = sabre_read(afar_reg);
  593. afsr = sabre_read(afsr_reg);
  594. /* Clear primary/secondary error status bits. */
  595. error_bits = afsr &
  596. (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
  597. SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR);
  598. if (!error_bits)
  599. return IRQ_NONE;
  600. sabre_write(afsr_reg, error_bits);
  601. /* Log the error. */
  602. printk("SABRE%d: Correctable Error, primary error type[%s]\n",
  603. p->index,
  604. ((error_bits & SABRE_CEAFSR_PDRD) ?
  605. "DMA Read" :
  606. ((error_bits & SABRE_CEAFSR_PDWR) ?
  607. "DMA Write" : "???")));
  608. /* XXX Use syndrome and afar to print out module string just like
  609. * XXX UDB CE trap handler does... -DaveM
  610. */
  611. printk("SABRE%d: syndrome[%02lx] bytemask[%04lx] dword_offset[%lx] "
  612. "was_block(%d)\n",
  613. p->index,
  614. (afsr & SABRE_CEAFSR_ESYND) >> 48UL,
  615. (afsr & SABRE_CEAFSR_BMSK) >> 32UL,
  616. (afsr & SABRE_CEAFSR_OFF) >> 29UL,
  617. ((afsr & SABRE_CEAFSR_BLK) ? 1 : 0));
  618. printk("SABRE%d: CE AFAR [%016lx]\n", p->index, afar);
  619. printk("SABRE%d: CE Secondary errors [", p->index);
  620. reported = 0;
  621. if (afsr & SABRE_CEAFSR_SDRD) {
  622. reported++;
  623. printk("(DMA Read)");
  624. }
  625. if (afsr & SABRE_CEAFSR_SDWR) {
  626. reported++;
  627. printk("(DMA Write)");
  628. }
  629. if (!reported)
  630. printk("(none)");
  631. printk("]\n");
  632. return IRQ_HANDLED;
  633. }
  634. static irqreturn_t sabre_pcierr_intr_other(struct pci_controller_info *p)
  635. {
  636. unsigned long csr_reg, csr, csr_error_bits;
  637. irqreturn_t ret = IRQ_NONE;
  638. u16 stat;
  639. csr_reg = p->pbm_A.controller_regs + SABRE_PCICTRL;
  640. csr = sabre_read(csr_reg);
  641. csr_error_bits =
  642. csr & SABRE_PCICTRL_SERR;
  643. if (csr_error_bits) {
  644. /* Clear the errors. */
  645. sabre_write(csr_reg, csr);
  646. /* Log 'em. */
  647. if (csr_error_bits & SABRE_PCICTRL_SERR)
  648. printk("SABRE%d: PCI SERR signal asserted.\n",
  649. p->index);
  650. ret = IRQ_HANDLED;
  651. }
  652. pci_bus_read_config_word(sabre_root_bus, 0,
  653. PCI_STATUS, &stat);
  654. if (stat & (PCI_STATUS_PARITY |
  655. PCI_STATUS_SIG_TARGET_ABORT |
  656. PCI_STATUS_REC_TARGET_ABORT |
  657. PCI_STATUS_REC_MASTER_ABORT |
  658. PCI_STATUS_SIG_SYSTEM_ERROR)) {
  659. printk("SABRE%d: PCI bus error, PCI_STATUS[%04x]\n",
  660. p->index, stat);
  661. pci_bus_write_config_word(sabre_root_bus, 0,
  662. PCI_STATUS, 0xffff);
  663. ret = IRQ_HANDLED;
  664. }
  665. return ret;
  666. }
  667. static irqreturn_t sabre_pcierr_intr(int irq, void *dev_id)
  668. {
  669. struct pci_controller_info *p = dev_id;
  670. unsigned long afsr_reg, afar_reg;
  671. unsigned long afsr, afar, error_bits;
  672. int reported;
  673. afsr_reg = p->pbm_A.controller_regs + SABRE_PIOAFSR;
  674. afar_reg = p->pbm_A.controller_regs + SABRE_PIOAFAR;
  675. /* Latch error status. */
  676. afar = sabre_read(afar_reg);
  677. afsr = sabre_read(afsr_reg);
  678. /* Clear primary/secondary error status bits. */
  679. error_bits = afsr &
  680. (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_PTA |
  681. SABRE_PIOAFSR_PRTRY | SABRE_PIOAFSR_PPERR |
  682. SABRE_PIOAFSR_SMA | SABRE_PIOAFSR_STA |
  683. SABRE_PIOAFSR_SRTRY | SABRE_PIOAFSR_SPERR);
  684. if (!error_bits)
  685. return sabre_pcierr_intr_other(p);
  686. sabre_write(afsr_reg, error_bits);
  687. /* Log the error. */
  688. printk("SABRE%d: PCI Error, primary error type[%s]\n",
  689. p->index,
  690. (((error_bits & SABRE_PIOAFSR_PMA) ?
  691. "Master Abort" :
  692. ((error_bits & SABRE_PIOAFSR_PTA) ?
  693. "Target Abort" :
  694. ((error_bits & SABRE_PIOAFSR_PRTRY) ?
  695. "Excessive Retries" :
  696. ((error_bits & SABRE_PIOAFSR_PPERR) ?
  697. "Parity Error" : "???"))))));
  698. printk("SABRE%d: bytemask[%04lx] was_block(%d)\n",
  699. p->index,
  700. (afsr & SABRE_PIOAFSR_BMSK) >> 32UL,
  701. (afsr & SABRE_PIOAFSR_BLK) ? 1 : 0);
  702. printk("SABRE%d: PCI AFAR [%016lx]\n", p->index, afar);
  703. printk("SABRE%d: PCI Secondary errors [", p->index);
  704. reported = 0;
  705. if (afsr & SABRE_PIOAFSR_SMA) {
  706. reported++;
  707. printk("(Master Abort)");
  708. }
  709. if (afsr & SABRE_PIOAFSR_STA) {
  710. reported++;
  711. printk("(Target Abort)");
  712. }
  713. if (afsr & SABRE_PIOAFSR_SRTRY) {
  714. reported++;
  715. printk("(Excessive Retries)");
  716. }
  717. if (afsr & SABRE_PIOAFSR_SPERR) {
  718. reported++;
  719. printk("(Parity Error)");
  720. }
  721. if (!reported)
  722. printk("(none)");
  723. printk("]\n");
  724. /* For the error types shown, scan both PCI buses for devices
  725. * which have logged that error type.
  726. */
  727. /* If we see a Target Abort, this could be the result of an
  728. * IOMMU translation error of some sort. It is extremely
  729. * useful to log this information as usually it indicates
  730. * a bug in the IOMMU support code or a PCI device driver.
  731. */
  732. if (error_bits & (SABRE_PIOAFSR_PTA | SABRE_PIOAFSR_STA)) {
  733. sabre_check_iommu_error(p, afsr, afar);
  734. pci_scan_for_target_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
  735. }
  736. if (error_bits & (SABRE_PIOAFSR_PMA | SABRE_PIOAFSR_SMA))
  737. pci_scan_for_master_abort(p, &p->pbm_A, p->pbm_A.pci_bus);
  738. /* For excessive retries, SABRE/PBM will abort the device
  739. * and there is no way to specifically check for excessive
  740. * retries in the config space status registers. So what
  741. * we hope is that we'll catch it via the master/target
  742. * abort events.
  743. */
  744. if (error_bits & (SABRE_PIOAFSR_PPERR | SABRE_PIOAFSR_SPERR))
  745. pci_scan_for_parity_error(p, &p->pbm_A, p->pbm_A.pci_bus);
  746. return IRQ_HANDLED;
  747. }
  748. static void sabre_register_error_handlers(struct pci_controller_info *p)
  749. {
  750. struct pci_pbm_info *pbm = &p->pbm_A; /* arbitrary */
  751. struct device_node *dp = pbm->prom_node;
  752. struct of_device *op;
  753. unsigned long base = pbm->controller_regs;
  754. u64 tmp;
  755. if (pbm->chip_type == PBM_CHIP_TYPE_SABRE)
  756. dp = dp->parent;
  757. op = of_find_device_by_node(dp);
  758. if (!op)
  759. return;
  760. /* Sabre/Hummingbird IRQ property layout is:
  761. * 0: PCI ERR
  762. * 1: UE ERR
  763. * 2: CE ERR
  764. * 3: POWER FAIL
  765. */
  766. if (op->num_irqs < 4)
  767. return;
  768. /* We clear the error bits in the appropriate AFSR before
  769. * registering the handler so that we don't get spurious
  770. * interrupts.
  771. */
  772. sabre_write(base + SABRE_UE_AFSR,
  773. (SABRE_UEAFSR_PDRD | SABRE_UEAFSR_PDWR |
  774. SABRE_UEAFSR_SDRD | SABRE_UEAFSR_SDWR |
  775. SABRE_UEAFSR_SDTE | SABRE_UEAFSR_PDTE));
  776. request_irq(op->irqs[1], sabre_ue_intr, IRQF_SHARED, "SABRE UE", p);
  777. sabre_write(base + SABRE_CE_AFSR,
  778. (SABRE_CEAFSR_PDRD | SABRE_CEAFSR_PDWR |
  779. SABRE_CEAFSR_SDRD | SABRE_CEAFSR_SDWR));
  780. request_irq(op->irqs[2], sabre_ce_intr, IRQF_SHARED, "SABRE CE", p);
  781. request_irq(op->irqs[0], sabre_pcierr_intr, IRQF_SHARED,
  782. "SABRE PCIERR", p);
  783. tmp = sabre_read(base + SABRE_PCICTRL);
  784. tmp |= SABRE_PCICTRL_ERREN;
  785. sabre_write(base + SABRE_PCICTRL, tmp);
  786. }
  787. static void apb_init(struct pci_controller_info *p, struct pci_bus *sabre_bus)
  788. {
  789. struct pci_dev *pdev;
  790. list_for_each_entry(pdev, &sabre_bus->devices, bus_list) {
  791. if (pdev->vendor == PCI_VENDOR_ID_SUN &&
  792. pdev->device == PCI_DEVICE_ID_SUN_SIMBA) {
  793. u16 word16;
  794. pci_read_config_word(pdev, PCI_COMMAND, &word16);
  795. word16 |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
  796. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
  797. PCI_COMMAND_IO;
  798. pci_write_config_word(pdev, PCI_COMMAND, word16);
  799. /* Status register bits are "write 1 to clear". */
  800. pci_write_config_word(pdev, PCI_STATUS, 0xffff);
  801. pci_write_config_word(pdev, PCI_SEC_STATUS, 0xffff);
  802. /* Use a primary/seconday latency timer value
  803. * of 64.
  804. */
  805. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 64);
  806. pci_write_config_byte(pdev, PCI_SEC_LATENCY_TIMER, 64);
  807. /* Enable reporting/forwarding of master aborts,
  808. * parity, and SERR.
  809. */
  810. pci_write_config_byte(pdev, PCI_BRIDGE_CONTROL,
  811. (PCI_BRIDGE_CTL_PARITY |
  812. PCI_BRIDGE_CTL_SERR |
  813. PCI_BRIDGE_CTL_MASTER_ABORT));
  814. }
  815. }
  816. }
  817. static void sabre_scan_bus(struct pci_controller_info *p)
  818. {
  819. static int once;
  820. struct pci_bus *pbus;
  821. /* The APB bridge speaks to the Sabre host PCI bridge
  822. * at 66Mhz, but the front side of APB runs at 33Mhz
  823. * for both segments.
  824. */
  825. p->pbm_A.is_66mhz_capable = 0;
  826. /* This driver has not been verified to handle
  827. * multiple SABREs yet, so trap this.
  828. *
  829. * Also note that the SABRE host bridge is hardwired
  830. * to live at bus 0.
  831. */
  832. if (once != 0) {
  833. prom_printf("SABRE: Multiple controllers unsupported.\n");
  834. prom_halt();
  835. }
  836. once++;
  837. pbus = pci_scan_one_pbm(&p->pbm_A);
  838. if (!pbus)
  839. return;
  840. sabre_root_bus = pbus;
  841. apb_init(p, pbus);
  842. sabre_register_error_handlers(p);
  843. }
  844. static void sabre_iommu_init(struct pci_controller_info *p,
  845. int tsbsize, unsigned long dvma_offset,
  846. u32 dma_mask)
  847. {
  848. struct iommu *iommu = p->pbm_A.iommu;
  849. unsigned long i;
  850. u64 control;
  851. /* Register addresses. */
  852. iommu->iommu_control = p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL;
  853. iommu->iommu_tsbbase = p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE;
  854. iommu->iommu_flush = p->pbm_A.controller_regs + SABRE_IOMMU_FLUSH;
  855. iommu->write_complete_reg = p->pbm_A.controller_regs + SABRE_WRSYNC;
  856. /* Sabre's IOMMU lacks ctx flushing. */
  857. iommu->iommu_ctxflush = 0;
  858. /* Invalidate TLB Entries. */
  859. control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
  860. control |= SABRE_IOMMUCTRL_DENAB;
  861. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
  862. for(i = 0; i < 16; i++) {
  863. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TAG + (i * 8UL), 0);
  864. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_DATA + (i * 8UL), 0);
  865. }
  866. /* Leave diag mode enabled for full-flushing done
  867. * in pci_iommu.c
  868. */
  869. pci_iommu_table_init(iommu, tsbsize * 1024 * 8, dvma_offset, dma_mask);
  870. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_TSBBASE,
  871. __pa(iommu->page_table));
  872. control = sabre_read(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL);
  873. control &= ~(SABRE_IOMMUCTRL_TSBSZ | SABRE_IOMMUCTRL_TBWSZ);
  874. control |= SABRE_IOMMUCTRL_ENAB;
  875. switch(tsbsize) {
  876. case 64:
  877. control |= SABRE_IOMMU_TSBSZ_64K;
  878. break;
  879. case 128:
  880. control |= SABRE_IOMMU_TSBSZ_128K;
  881. break;
  882. default:
  883. prom_printf("iommu_init: Illegal TSB size %d\n", tsbsize);
  884. prom_halt();
  885. break;
  886. }
  887. sabre_write(p->pbm_A.controller_regs + SABRE_IOMMU_CONTROL, control);
  888. }
  889. static void sabre_pbm_init(struct pci_controller_info *p, struct device_node *dp)
  890. {
  891. struct pci_pbm_info *pbm;
  892. pbm = &p->pbm_A;
  893. pbm->name = dp->full_name;
  894. printk("%s: SABRE PCI Bus Module\n", pbm->name);
  895. pbm->chip_type = PBM_CHIP_TYPE_SABRE;
  896. pbm->parent = p;
  897. pbm->prom_node = dp;
  898. pbm->pci_first_busno = p->pci_first_busno;
  899. pbm->pci_last_busno = p->pci_last_busno;
  900. pci_determine_mem_io_space(pbm);
  901. }
  902. void sabre_init(struct device_node *dp, char *model_name)
  903. {
  904. const struct linux_prom64_registers *pr_regs;
  905. struct pci_controller_info *p;
  906. struct iommu *iommu;
  907. int tsbsize;
  908. const u32 *busrange;
  909. const u32 *vdma;
  910. u32 upa_portid, dma_mask;
  911. u64 clear_irq;
  912. hummingbird_p = 0;
  913. if (!strcmp(model_name, "pci108e,a001"))
  914. hummingbird_p = 1;
  915. else if (!strcmp(model_name, "SUNW,sabre")) {
  916. const char *compat = of_get_property(dp, "compatible", NULL);
  917. if (compat && !strcmp(compat, "pci108e,a001"))
  918. hummingbird_p = 1;
  919. if (!hummingbird_p) {
  920. struct device_node *dp;
  921. /* Of course, Sun has to encode things a thousand
  922. * different ways, inconsistently.
  923. */
  924. cpu_find_by_instance(0, &dp, NULL);
  925. if (!strcmp(dp->name, "SUNW,UltraSPARC-IIe"))
  926. hummingbird_p = 1;
  927. }
  928. }
  929. p = kzalloc(sizeof(*p), GFP_ATOMIC);
  930. if (!p) {
  931. prom_printf("SABRE: Error, kmalloc(pci_controller_info) failed.\n");
  932. prom_halt();
  933. }
  934. iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
  935. if (!iommu) {
  936. prom_printf("SABRE: Error, kmalloc(pci_iommu) failed.\n");
  937. prom_halt();
  938. }
  939. p->pbm_A.iommu = iommu;
  940. upa_portid = of_getintprop_default(dp, "upa-portid", 0xff);
  941. p->next = pci_controller_root;
  942. pci_controller_root = p;
  943. p->pbm_A.portid = upa_portid;
  944. p->index = pci_num_controllers++;
  945. p->scan_bus = sabre_scan_bus;
  946. p->pci_ops = &sabre_ops;
  947. /*
  948. * Map in SABRE register set and report the presence of this SABRE.
  949. */
  950. pr_regs = of_get_property(dp, "reg", NULL);
  951. /*
  952. * First REG in property is base of entire SABRE register space.
  953. */
  954. p->pbm_A.controller_regs = pr_regs[0].phys_addr;
  955. /* Clear interrupts */
  956. /* PCI first */
  957. for (clear_irq = SABRE_ICLR_A_SLOT0; clear_irq < SABRE_ICLR_B_SLOT0 + 0x80; clear_irq += 8)
  958. sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
  959. /* Then OBIO */
  960. for (clear_irq = SABRE_ICLR_SCSI; clear_irq < SABRE_ICLR_SCSI + 0x80; clear_irq += 8)
  961. sabre_write(p->pbm_A.controller_regs + clear_irq, 0x0UL);
  962. /* Error interrupts are enabled later after the bus scan. */
  963. sabre_write(p->pbm_A.controller_regs + SABRE_PCICTRL,
  964. (SABRE_PCICTRL_MRLEN | SABRE_PCICTRL_SERR |
  965. SABRE_PCICTRL_ARBPARK | SABRE_PCICTRL_AEN));
  966. /* Now map in PCI config space for entire SABRE. */
  967. p->pbm_A.config_space =
  968. (p->pbm_A.controller_regs + SABRE_CONFIGSPACE);
  969. vdma = of_get_property(dp, "virtual-dma", NULL);
  970. dma_mask = vdma[0];
  971. switch(vdma[1]) {
  972. case 0x20000000:
  973. dma_mask |= 0x1fffffff;
  974. tsbsize = 64;
  975. break;
  976. case 0x40000000:
  977. dma_mask |= 0x3fffffff;
  978. tsbsize = 128;
  979. break;
  980. case 0x80000000:
  981. dma_mask |= 0x7fffffff;
  982. tsbsize = 128;
  983. break;
  984. default:
  985. prom_printf("SABRE: strange virtual-dma size.\n");
  986. prom_halt();
  987. }
  988. sabre_iommu_init(p, tsbsize, vdma[0], dma_mask);
  989. busrange = of_get_property(dp, "bus-range", NULL);
  990. p->pci_first_busno = busrange[0];
  991. p->pci_last_busno = busrange[1];
  992. /*
  993. * Look for APB underneath.
  994. */
  995. sabre_pbm_init(p, dp);
  996. }