dino.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. ** DINO manager
  4. **
  5. ** (c) Copyright 1999 Red Hat Software
  6. ** (c) Copyright 1999 SuSE GmbH
  7. ** (c) Copyright 1999,2000 Hewlett-Packard Company
  8. ** (c) Copyright 2000 Grant Grundler
  9. ** (c) Copyright 2006-2019 Helge Deller
  10. **
  11. **
  12. ** This module provides access to Dino PCI bus (config/IOport spaces)
  13. ** and helps manage Dino IRQ lines.
  14. **
  15. ** Dino interrupt handling is a bit complicated.
  16. ** Dino always writes to the broadcast EIR via irr0 for now.
  17. ** (BIG WARNING: using broadcast EIR is a really bad thing for SMP!)
  18. ** Only one processor interrupt is used for the 11 IRQ line
  19. ** inputs to dino.
  20. **
  21. ** The different between Built-in Dino and Card-Mode
  22. ** dino is in chip initialization and pci device initialization.
  23. **
  24. ** Linux drivers can only use Card-Mode Dino if pci devices I/O port
  25. ** BARs are configured and used by the driver. Programming MMIO address
  26. ** requires substantial knowledge of available Host I/O address ranges
  27. ** is currently not supported. Port/Config accessor functions are the
  28. ** same. "BIOS" differences are handled within the existing routines.
  29. */
  30. /* Changes :
  31. ** 2001-06-14 : Clement Moyroud ([email protected])
  32. ** - added support for the integrated RS232.
  33. */
  34. /*
  35. ** TODO: create a virtual address for each Dino HPA.
  36. ** GSC code might be able to do this since IODC data tells us
  37. ** how many pages are used. PCI subsystem could (must?) do this
  38. ** for PCI drivers devices which implement/use MMIO registers.
  39. */
  40. #include <linux/delay.h>
  41. #include <linux/types.h>
  42. #include <linux/kernel.h>
  43. #include <linux/pci.h>
  44. #include <linux/init.h>
  45. #include <linux/ioport.h>
  46. #include <linux/slab.h>
  47. #include <linux/interrupt.h> /* for struct irqaction */
  48. #include <linux/spinlock.h> /* for spinlock_t and prototypes */
  49. #include <asm/pdc.h>
  50. #include <asm/page.h>
  51. #include <asm/io.h>
  52. #include <asm/hardware.h>
  53. #include "gsc.h"
  54. #include "iommu.h"
  55. #undef DINO_DEBUG
  56. #ifdef DINO_DEBUG
  57. #define DBG(x...) printk(x)
  58. #else
  59. #define DBG(x...)
  60. #endif
  61. /*
  62. ** Config accessor functions only pass in the 8-bit bus number
  63. ** and not the 8-bit "PCI Segment" number. Each Dino will be
  64. ** assigned a PCI bus number based on "when" it's discovered.
  65. **
  66. ** The "secondary" bus number is set to this before calling
  67. ** pci_scan_bus(). If any PPB's are present, the scan will
  68. ** discover them and update the "secondary" and "subordinate"
  69. ** fields in Dino's pci_bus structure.
  70. **
  71. ** Changes in the configuration *will* result in a different
  72. ** bus number for each dino.
  73. */
  74. #define is_card_dino(id) ((id)->hw_type == HPHW_A_DMA)
  75. #define is_cujo(id) ((id)->hversion == 0x682)
  76. #define DINO_IAR0 0x004
  77. #define DINO_IODC_ADDR 0x008
  78. #define DINO_IODC_DATA_0 0x008
  79. #define DINO_IODC_DATA_1 0x008
  80. #define DINO_IRR0 0x00C
  81. #define DINO_IAR1 0x010
  82. #define DINO_IRR1 0x014
  83. #define DINO_IMR 0x018
  84. #define DINO_IPR 0x01C
  85. #define DINO_TOC_ADDR 0x020
  86. #define DINO_ICR 0x024
  87. #define DINO_ILR 0x028
  88. #define DINO_IO_COMMAND 0x030
  89. #define DINO_IO_STATUS 0x034
  90. #define DINO_IO_CONTROL 0x038
  91. #define DINO_IO_GSC_ERR_RESP 0x040
  92. #define DINO_IO_ERR_INFO 0x044
  93. #define DINO_IO_PCI_ERR_RESP 0x048
  94. #define DINO_IO_FBB_EN 0x05c
  95. #define DINO_IO_ADDR_EN 0x060
  96. #define DINO_PCI_ADDR 0x064
  97. #define DINO_CONFIG_DATA 0x068
  98. #define DINO_IO_DATA 0x06c
  99. #define DINO_MEM_DATA 0x070 /* Dino 3.x only */
  100. #define DINO_GSC2X_CONFIG 0x7b4
  101. #define DINO_GMASK 0x800
  102. #define DINO_PAMR 0x804
  103. #define DINO_PAPR 0x808
  104. #define DINO_DAMODE 0x80c
  105. #define DINO_PCICMD 0x810
  106. #define DINO_PCISTS 0x814
  107. #define DINO_MLTIM 0x81c
  108. #define DINO_BRDG_FEAT 0x820
  109. #define DINO_PCIROR 0x824
  110. #define DINO_PCIWOR 0x828
  111. #define DINO_TLTIM 0x830
  112. #define DINO_IRQS 11 /* bits 0-10 are architected */
  113. #define DINO_IRR_MASK 0x5ff /* only 10 bits are implemented */
  114. #define DINO_LOCAL_IRQS (DINO_IRQS+1)
  115. #define DINO_MASK_IRQ(x) (1<<(x))
  116. #define PCIINTA 0x001
  117. #define PCIINTB 0x002
  118. #define PCIINTC 0x004
  119. #define PCIINTD 0x008
  120. #define PCIINTE 0x010
  121. #define PCIINTF 0x020
  122. #define GSCEXTINT 0x040
  123. /* #define xxx 0x080 - bit 7 is "default" */
  124. /* #define xxx 0x100 - bit 8 not used */
  125. /* #define xxx 0x200 - bit 9 not used */
  126. #define RS232INT 0x400
  127. struct dino_device
  128. {
  129. struct pci_hba_data hba; /* 'C' inheritance - must be first */
  130. spinlock_t dinosaur_pen;
  131. u32 imr; /* IRQ's which are enabled */
  132. struct gsc_irq gsc_irq;
  133. int global_irq[DINO_LOCAL_IRQS]; /* map IMR bit to global irq */
  134. #ifdef DINO_DEBUG
  135. unsigned int dino_irr0; /* save most recent IRQ line stat */
  136. #endif
  137. };
  138. static inline struct dino_device *DINO_DEV(struct pci_hba_data *hba)
  139. {
  140. return container_of(hba, struct dino_device, hba);
  141. }
  142. /*
  143. * Dino Configuration Space Accessor Functions
  144. */
  145. #define DINO_CFG_TOK(bus,dfn,pos) ((u32) ((bus)<<16 | (dfn)<<8 | (pos)))
  146. /*
  147. * keep the current highest bus count to assist in allocating busses. This
  148. * tries to keep a global bus count total so that when we discover an
  149. * entirely new bus, it can be given a unique bus number.
  150. */
  151. static int dino_current_bus = 0;
  152. static int dino_cfg_read(struct pci_bus *bus, unsigned int devfn, int where,
  153. int size, u32 *val)
  154. {
  155. struct dino_device *d = DINO_DEV(parisc_walk_tree(bus->bridge));
  156. u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start;
  157. u32 v = DINO_CFG_TOK(local_bus, devfn, where & ~3);
  158. void __iomem *base_addr = d->hba.base_addr;
  159. unsigned long flags;
  160. DBG("%s: %p, %d, %d, %d\n", __func__, base_addr, devfn, where,
  161. size);
  162. spin_lock_irqsave(&d->dinosaur_pen, flags);
  163. /* tell HW which CFG address */
  164. __raw_writel(v, base_addr + DINO_PCI_ADDR);
  165. /* generate cfg read cycle */
  166. if (size == 1) {
  167. *val = readb(base_addr + DINO_CONFIG_DATA + (where & 3));
  168. } else if (size == 2) {
  169. *val = readw(base_addr + DINO_CONFIG_DATA + (where & 2));
  170. } else if (size == 4) {
  171. *val = readl(base_addr + DINO_CONFIG_DATA);
  172. }
  173. spin_unlock_irqrestore(&d->dinosaur_pen, flags);
  174. return 0;
  175. }
  176. /*
  177. * Dino address stepping "feature":
  178. * When address stepping, Dino attempts to drive the bus one cycle too soon
  179. * even though the type of cycle (config vs. MMIO) might be different.
  180. * The read of Ven/Prod ID is harmless and avoids Dino's address stepping.
  181. */
  182. static int dino_cfg_write(struct pci_bus *bus, unsigned int devfn, int where,
  183. int size, u32 val)
  184. {
  185. struct dino_device *d = DINO_DEV(parisc_walk_tree(bus->bridge));
  186. u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start;
  187. u32 v = DINO_CFG_TOK(local_bus, devfn, where & ~3);
  188. void __iomem *base_addr = d->hba.base_addr;
  189. unsigned long flags;
  190. DBG("%s: %p, %d, %d, %d\n", __func__, base_addr, devfn, where,
  191. size);
  192. spin_lock_irqsave(&d->dinosaur_pen, flags);
  193. /* avoid address stepping feature */
  194. __raw_writel(v & 0xffffff00, base_addr + DINO_PCI_ADDR);
  195. __raw_readl(base_addr + DINO_CONFIG_DATA);
  196. /* tell HW which CFG address */
  197. __raw_writel(v, base_addr + DINO_PCI_ADDR);
  198. /* generate cfg read cycle */
  199. if (size == 1) {
  200. writeb(val, base_addr + DINO_CONFIG_DATA + (where & 3));
  201. } else if (size == 2) {
  202. writew(val, base_addr + DINO_CONFIG_DATA + (where & 2));
  203. } else if (size == 4) {
  204. writel(val, base_addr + DINO_CONFIG_DATA);
  205. }
  206. spin_unlock_irqrestore(&d->dinosaur_pen, flags);
  207. return 0;
  208. }
  209. static struct pci_ops dino_cfg_ops = {
  210. .read = dino_cfg_read,
  211. .write = dino_cfg_write,
  212. };
  213. /*
  214. * Dino "I/O Port" Space Accessor Functions
  215. *
  216. * Many PCI devices don't require use of I/O port space (eg Tulip,
  217. * NCR720) since they export the same registers to both MMIO and
  218. * I/O port space. Performance is going to stink if drivers use
  219. * I/O port instead of MMIO.
  220. */
  221. #define DINO_PORT_IN(type, size, mask) \
  222. static u##size dino_in##size (struct pci_hba_data *d, u16 addr) \
  223. { \
  224. u##size v; \
  225. unsigned long flags; \
  226. spin_lock_irqsave(&(DINO_DEV(d)->dinosaur_pen), flags); \
  227. /* tell HW which IO Port address */ \
  228. __raw_writel((u32) addr, d->base_addr + DINO_PCI_ADDR); \
  229. /* generate I/O PORT read cycle */ \
  230. v = read##type(d->base_addr+DINO_IO_DATA+(addr&mask)); \
  231. spin_unlock_irqrestore(&(DINO_DEV(d)->dinosaur_pen), flags); \
  232. return v; \
  233. }
  234. DINO_PORT_IN(b, 8, 3)
  235. DINO_PORT_IN(w, 16, 2)
  236. DINO_PORT_IN(l, 32, 0)
  237. #define DINO_PORT_OUT(type, size, mask) \
  238. static void dino_out##size (struct pci_hba_data *d, u16 addr, u##size val) \
  239. { \
  240. unsigned long flags; \
  241. spin_lock_irqsave(&(DINO_DEV(d)->dinosaur_pen), flags); \
  242. /* tell HW which IO port address */ \
  243. __raw_writel((u32) addr, d->base_addr + DINO_PCI_ADDR); \
  244. /* generate cfg write cycle */ \
  245. write##type(val, d->base_addr+DINO_IO_DATA+(addr&mask)); \
  246. spin_unlock_irqrestore(&(DINO_DEV(d)->dinosaur_pen), flags); \
  247. }
  248. DINO_PORT_OUT(b, 8, 3)
  249. DINO_PORT_OUT(w, 16, 2)
  250. DINO_PORT_OUT(l, 32, 0)
  251. static struct pci_port_ops dino_port_ops = {
  252. .inb = dino_in8,
  253. .inw = dino_in16,
  254. .inl = dino_in32,
  255. .outb = dino_out8,
  256. .outw = dino_out16,
  257. .outl = dino_out32
  258. };
  259. static void dino_mask_irq(struct irq_data *d)
  260. {
  261. struct dino_device *dino_dev = irq_data_get_irq_chip_data(d);
  262. int local_irq = gsc_find_local_irq(d->irq, dino_dev->global_irq, DINO_LOCAL_IRQS);
  263. DBG(KERN_WARNING "%s(0x%px, %d)\n", __func__, dino_dev, d->irq);
  264. /* Clear the matching bit in the IMR register */
  265. dino_dev->imr &= ~(DINO_MASK_IRQ(local_irq));
  266. __raw_writel(dino_dev->imr, dino_dev->hba.base_addr+DINO_IMR);
  267. }
  268. static void dino_unmask_irq(struct irq_data *d)
  269. {
  270. struct dino_device *dino_dev = irq_data_get_irq_chip_data(d);
  271. int local_irq = gsc_find_local_irq(d->irq, dino_dev->global_irq, DINO_LOCAL_IRQS);
  272. u32 tmp;
  273. DBG(KERN_WARNING "%s(0x%px, %d)\n", __func__, dino_dev, d->irq);
  274. /*
  275. ** clear pending IRQ bits
  276. **
  277. ** This does NOT change ILR state!
  278. ** See comment below for ILR usage.
  279. */
  280. __raw_readl(dino_dev->hba.base_addr+DINO_IPR);
  281. /* set the matching bit in the IMR register */
  282. dino_dev->imr |= DINO_MASK_IRQ(local_irq); /* used in dino_isr() */
  283. __raw_writel( dino_dev->imr, dino_dev->hba.base_addr+DINO_IMR);
  284. /* Emulate "Level Triggered" Interrupt
  285. ** Basically, a driver is blowing it if the IRQ line is asserted
  286. ** while the IRQ is disabled. But tulip.c seems to do that....
  287. ** Give 'em a kluge award and a nice round of applause!
  288. **
  289. ** The gsc_write will generate an interrupt which invokes dino_isr().
  290. ** dino_isr() will read IPR and find nothing. But then catch this
  291. ** when it also checks ILR.
  292. */
  293. tmp = __raw_readl(dino_dev->hba.base_addr+DINO_ILR);
  294. if (tmp & DINO_MASK_IRQ(local_irq)) {
  295. DBG(KERN_WARNING "%s(): IRQ asserted! (ILR 0x%x)\n",
  296. __func__, tmp);
  297. gsc_writel(dino_dev->gsc_irq.txn_data, dino_dev->gsc_irq.txn_addr);
  298. }
  299. }
  300. #ifdef CONFIG_SMP
  301. static int dino_set_affinity_irq(struct irq_data *d, const struct cpumask *dest,
  302. bool force)
  303. {
  304. struct dino_device *dino_dev = irq_data_get_irq_chip_data(d);
  305. struct cpumask tmask;
  306. int cpu_irq;
  307. u32 eim;
  308. if (!cpumask_and(&tmask, dest, cpu_online_mask))
  309. return -EINVAL;
  310. cpu_irq = cpu_check_affinity(d, &tmask);
  311. if (cpu_irq < 0)
  312. return cpu_irq;
  313. dino_dev->gsc_irq.txn_addr = txn_affinity_addr(d->irq, cpu_irq);
  314. eim = ((u32) dino_dev->gsc_irq.txn_addr) | dino_dev->gsc_irq.txn_data;
  315. __raw_writel(eim, dino_dev->hba.base_addr+DINO_IAR0);
  316. irq_data_update_effective_affinity(d, &tmask);
  317. return IRQ_SET_MASK_OK;
  318. }
  319. #endif
  320. static struct irq_chip dino_interrupt_type = {
  321. .name = "GSC-PCI",
  322. .irq_unmask = dino_unmask_irq,
  323. .irq_mask = dino_mask_irq,
  324. #ifdef CONFIG_SMP
  325. .irq_set_affinity = dino_set_affinity_irq,
  326. #endif
  327. };
  328. /*
  329. * Handle a Processor interrupt generated by Dino.
  330. *
  331. * ilr_loop counter is a kluge to prevent a "stuck" IRQ line from
  332. * wedging the CPU. Could be removed or made optional at some point.
  333. */
  334. static irqreturn_t dino_isr(int irq, void *intr_dev)
  335. {
  336. struct dino_device *dino_dev = intr_dev;
  337. u32 mask;
  338. int ilr_loop = 100;
  339. /* read and acknowledge pending interrupts */
  340. #ifdef DINO_DEBUG
  341. dino_dev->dino_irr0 =
  342. #endif
  343. mask = __raw_readl(dino_dev->hba.base_addr+DINO_IRR0) & DINO_IRR_MASK;
  344. if (mask == 0)
  345. return IRQ_NONE;
  346. ilr_again:
  347. do {
  348. int local_irq = __ffs(mask);
  349. int irq = dino_dev->global_irq[local_irq];
  350. DBG(KERN_DEBUG "%s(%d, %p) mask 0x%x\n",
  351. __func__, irq, intr_dev, mask);
  352. generic_handle_irq(irq);
  353. mask &= ~DINO_MASK_IRQ(local_irq);
  354. } while (mask);
  355. /* Support for level triggered IRQ lines.
  356. **
  357. ** Dropping this support would make this routine *much* faster.
  358. ** But since PCI requires level triggered IRQ line to share lines...
  359. ** device drivers may assume lines are level triggered (and not
  360. ** edge triggered like EISA/ISA can be).
  361. */
  362. mask = __raw_readl(dino_dev->hba.base_addr+DINO_ILR) & dino_dev->imr;
  363. if (mask) {
  364. if (--ilr_loop > 0)
  365. goto ilr_again;
  366. pr_warn_ratelimited("Dino 0x%px: stuck interrupt %d\n",
  367. dino_dev->hba.base_addr, mask);
  368. }
  369. return IRQ_HANDLED;
  370. }
  371. static void dino_assign_irq(struct dino_device *dino, int local_irq, int *irqp)
  372. {
  373. int irq = gsc_assign_irq(&dino_interrupt_type, dino);
  374. if (irq == NO_IRQ)
  375. return;
  376. *irqp = irq;
  377. dino->global_irq[local_irq] = irq;
  378. }
  379. static void dino_choose_irq(struct parisc_device *dev, void *ctrl)
  380. {
  381. int irq;
  382. struct dino_device *dino = ctrl;
  383. switch (dev->id.sversion) {
  384. case 0x00084: irq = 8; break; /* PS/2 */
  385. case 0x0008c: irq = 10; break; /* RS232 */
  386. case 0x00096: irq = 8; break; /* PS/2 */
  387. default: return; /* Unknown */
  388. }
  389. dino_assign_irq(dino, irq, &dev->irq);
  390. }
  391. /*
  392. * Cirrus 6832 Cardbus reports wrong irq on RDI Tadpole PARISC Laptop ([email protected])
  393. * (the irqs are off-by-one, not sure yet if this is a cirrus, dino-hardware or dino-driver problem...)
  394. */
  395. static void quirk_cirrus_cardbus(struct pci_dev *dev)
  396. {
  397. u8 new_irq = dev->irq - 1;
  398. printk(KERN_INFO "PCI: Cirrus Cardbus IRQ fixup for %s, from %d to %d\n",
  399. pci_name(dev), dev->irq, new_irq);
  400. dev->irq = new_irq;
  401. }
  402. DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6832, quirk_cirrus_cardbus );
  403. #ifdef CONFIG_TULIP
  404. /* Check if PCI device is behind a Card-mode Dino. */
  405. static int pci_dev_is_behind_card_dino(struct pci_dev *dev)
  406. {
  407. struct dino_device *dino_dev;
  408. dino_dev = DINO_DEV(parisc_walk_tree(dev->bus->bridge));
  409. return is_card_dino(&dino_dev->hba.dev->id);
  410. }
  411. static void pci_fixup_tulip(struct pci_dev *dev)
  412. {
  413. if (!pci_dev_is_behind_card_dino(dev))
  414. return;
  415. if (!(pci_resource_flags(dev, 1) & IORESOURCE_MEM))
  416. return;
  417. pr_warn("%s: HP HSC-PCI Cards with card-mode Dino not yet supported.\n",
  418. pci_name(dev));
  419. /* Disable this card by zeroing the PCI resources */
  420. memset(&dev->resource[0], 0, sizeof(dev->resource[0]));
  421. memset(&dev->resource[1], 0, sizeof(dev->resource[1]));
  422. }
  423. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_DEC, PCI_ANY_ID, pci_fixup_tulip);
  424. #endif /* CONFIG_TULIP */
  425. static void __init
  426. dino_bios_init(void)
  427. {
  428. DBG("dino_bios_init\n");
  429. }
  430. /*
  431. * dino_card_setup - Set up the memory space for a Dino in card mode.
  432. * @bus: the bus under this dino
  433. *
  434. * Claim an 8MB chunk of unused IO space and call the generic PCI routines
  435. * to set up the addresses of the devices on this bus.
  436. */
  437. #define _8MB 0x00800000UL
  438. static void __init
  439. dino_card_setup(struct pci_bus *bus, void __iomem *base_addr)
  440. {
  441. int i;
  442. struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge));
  443. struct resource *res;
  444. char name[128];
  445. int size;
  446. res = &dino_dev->hba.lmmio_space;
  447. res->flags = IORESOURCE_MEM;
  448. size = scnprintf(name, sizeof(name), "Dino LMMIO (%s)",
  449. dev_name(bus->bridge));
  450. res->name = kmalloc(size+1, GFP_KERNEL);
  451. if(res->name)
  452. strcpy((char *)res->name, name);
  453. else
  454. res->name = dino_dev->hba.lmmio_space.name;
  455. if (ccio_allocate_resource(dino_dev->hba.dev, res, _8MB,
  456. F_EXTEND(0xf0000000UL) | _8MB,
  457. F_EXTEND(0xffffffffUL) &~ _8MB, _8MB) < 0) {
  458. struct pci_dev *dev, *tmp;
  459. printk(KERN_ERR "Dino: cannot attach bus %s\n",
  460. dev_name(bus->bridge));
  461. /* kill the bus, we can't do anything with it */
  462. list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
  463. list_del(&dev->bus_list);
  464. }
  465. return;
  466. }
  467. bus->resource[1] = res;
  468. bus->resource[0] = &(dino_dev->hba.io_space);
  469. /* Now tell dino what range it has */
  470. for (i = 1; i < 31; i++) {
  471. if (res->start == F_EXTEND(0xf0000000UL | (i * _8MB)))
  472. break;
  473. }
  474. DBG("DINO GSC WRITE i=%d, start=%lx, dino addr = %p\n",
  475. i, res->start, base_addr + DINO_IO_ADDR_EN);
  476. __raw_writel(1 << i, base_addr + DINO_IO_ADDR_EN);
  477. }
  478. static void __init
  479. dino_card_fixup(struct pci_dev *dev)
  480. {
  481. u32 irq_pin;
  482. /*
  483. ** REVISIT: card-mode PCI-PCI expansion chassis do exist.
  484. ** Not sure they were ever productized.
  485. ** Die here since we'll die later in dino_inb() anyway.
  486. */
  487. if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
  488. panic("Card-Mode Dino: PCI-PCI Bridge not supported\n");
  489. }
  490. /*
  491. ** Set Latency Timer to 0xff (not a shared bus)
  492. ** Set CACHELINE_SIZE.
  493. */
  494. dino_cfg_write(dev->bus, dev->devfn,
  495. PCI_CACHE_LINE_SIZE, 2, 0xff00 | L1_CACHE_BYTES/4);
  496. /*
  497. ** Program INT_LINE for card-mode devices.
  498. ** The cards are hardwired according to this algorithm.
  499. ** And it doesn't matter if PPB's are present or not since
  500. ** the IRQ lines bypass the PPB.
  501. **
  502. ** "-1" converts INTA-D (1-4) to PCIINTA-D (0-3) range.
  503. ** The additional "-1" adjusts for skewing the IRQ<->slot.
  504. */
  505. dino_cfg_read(dev->bus, dev->devfn, PCI_INTERRUPT_PIN, 1, &irq_pin);
  506. dev->irq = pci_swizzle_interrupt_pin(dev, irq_pin) - 1;
  507. /* Shouldn't really need to do this but it's in case someone tries
  508. ** to bypass PCI services and look at the card themselves.
  509. */
  510. dino_cfg_write(dev->bus, dev->devfn, PCI_INTERRUPT_LINE, 1, dev->irq);
  511. }
  512. /* The alignment contraints for PCI bridges under dino */
  513. #define DINO_BRIDGE_ALIGN 0x100000
  514. static void __init
  515. dino_fixup_bus(struct pci_bus *bus)
  516. {
  517. struct pci_dev *dev;
  518. struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge));
  519. DBG(KERN_WARNING "%s(0x%px) bus %d platform_data 0x%px\n",
  520. __func__, bus, bus->busn_res.start,
  521. bus->bridge->platform_data);
  522. /* Firmware doesn't set up card-mode dino, so we have to */
  523. if (is_card_dino(&dino_dev->hba.dev->id)) {
  524. dino_card_setup(bus, dino_dev->hba.base_addr);
  525. } else if (bus->parent) {
  526. int i;
  527. pci_read_bridge_bases(bus);
  528. for(i = PCI_BRIDGE_RESOURCES; i < PCI_NUM_RESOURCES; i++) {
  529. if((bus->self->resource[i].flags &
  530. (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
  531. continue;
  532. if(bus->self->resource[i].flags & IORESOURCE_MEM) {
  533. /* There's a quirk to alignment of
  534. * bridge memory resources: the start
  535. * is the alignment and start-end is
  536. * the size. However, firmware will
  537. * have assigned start and end, so we
  538. * need to take this into account */
  539. bus->self->resource[i].end = bus->self->resource[i].end - bus->self->resource[i].start + DINO_BRIDGE_ALIGN;
  540. bus->self->resource[i].start = DINO_BRIDGE_ALIGN;
  541. }
  542. DBG("DEBUG %s assigning %d [%pR]\n",
  543. dev_name(&bus->self->dev), i,
  544. &bus->self->resource[i]);
  545. WARN_ON(pci_assign_resource(bus->self, i));
  546. DBG("DEBUG %s after assign %d [%pR]\n",
  547. dev_name(&bus->self->dev), i,
  548. &bus->self->resource[i]);
  549. }
  550. }
  551. list_for_each_entry(dev, &bus->devices, bus_list) {
  552. if (is_card_dino(&dino_dev->hba.dev->id))
  553. dino_card_fixup(dev);
  554. /*
  555. ** P2PB's only have 2 BARs, no IRQs.
  556. ** I'd like to just ignore them for now.
  557. */
  558. if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
  559. pcibios_init_bridge(dev);
  560. continue;
  561. }
  562. /* null out the ROM resource if there is one (we don't
  563. * care about an expansion rom on parisc, since it
  564. * usually contains (x86) bios code) */
  565. dev->resource[PCI_ROM_RESOURCE].flags = 0;
  566. if(dev->irq == 255) {
  567. #define DINO_FIX_UNASSIGNED_INTERRUPTS
  568. #ifdef DINO_FIX_UNASSIGNED_INTERRUPTS
  569. /* This code tries to assign an unassigned
  570. * interrupt. Leave it disabled unless you
  571. * *really* know what you're doing since the
  572. * pin<->interrupt line mapping varies by bus
  573. * and machine */
  574. u32 irq_pin;
  575. dino_cfg_read(dev->bus, dev->devfn,
  576. PCI_INTERRUPT_PIN, 1, &irq_pin);
  577. irq_pin = pci_swizzle_interrupt_pin(dev, irq_pin) - 1;
  578. printk(KERN_WARNING "Device %s has undefined IRQ, "
  579. "setting to %d\n", pci_name(dev), irq_pin);
  580. dino_cfg_write(dev->bus, dev->devfn,
  581. PCI_INTERRUPT_LINE, 1, irq_pin);
  582. dino_assign_irq(dino_dev, irq_pin, &dev->irq);
  583. #else
  584. dev->irq = 65535;
  585. printk(KERN_WARNING "Device %s has unassigned IRQ\n", pci_name(dev));
  586. #endif
  587. } else {
  588. /* Adjust INT_LINE for that busses region */
  589. dino_assign_irq(dino_dev, dev->irq, &dev->irq);
  590. }
  591. }
  592. }
  593. static struct pci_bios_ops dino_bios_ops = {
  594. .init = dino_bios_init,
  595. .fixup_bus = dino_fixup_bus
  596. };
  597. /*
  598. * Initialise a DINO controller chip
  599. */
  600. static void __init
  601. dino_card_init(struct dino_device *dino_dev)
  602. {
  603. u32 brdg_feat = 0x00784e05;
  604. unsigned long status;
  605. status = __raw_readl(dino_dev->hba.base_addr+DINO_IO_STATUS);
  606. if (status & 0x0000ff80) {
  607. __raw_writel(0x00000005,
  608. dino_dev->hba.base_addr+DINO_IO_COMMAND);
  609. udelay(1);
  610. }
  611. __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_GMASK);
  612. __raw_writel(0x00000001, dino_dev->hba.base_addr+DINO_IO_FBB_EN);
  613. __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_ICR);
  614. #if 1
  615. /* REVISIT - should be a runtime check (eg if (CPU_IS_PCX_L) ...) */
  616. /*
  617. ** PCX-L processors don't support XQL like Dino wants it.
  618. ** PCX-L2 ignore XQL signal and it doesn't matter.
  619. */
  620. brdg_feat &= ~0x4; /* UXQL */
  621. #endif
  622. __raw_writel( brdg_feat, dino_dev->hba.base_addr+DINO_BRDG_FEAT);
  623. /*
  624. ** Don't enable address decoding until we know which I/O range
  625. ** currently is available from the host. Only affects MMIO
  626. ** and not I/O port space.
  627. */
  628. __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_IO_ADDR_EN);
  629. __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_DAMODE);
  630. __raw_writel(0x00222222, dino_dev->hba.base_addr+DINO_PCIROR);
  631. __raw_writel(0x00222222, dino_dev->hba.base_addr+DINO_PCIWOR);
  632. __raw_writel(0x00000040, dino_dev->hba.base_addr+DINO_MLTIM);
  633. __raw_writel(0x00000080, dino_dev->hba.base_addr+DINO_IO_CONTROL);
  634. __raw_writel(0x0000008c, dino_dev->hba.base_addr+DINO_TLTIM);
  635. /* Disable PAMR before writing PAPR */
  636. __raw_writel(0x0000007e, dino_dev->hba.base_addr+DINO_PAMR);
  637. __raw_writel(0x0000007f, dino_dev->hba.base_addr+DINO_PAPR);
  638. __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_PAMR);
  639. /*
  640. ** Dino ERS encourages enabling FBB (0x6f).
  641. ** We can't until we know *all* devices below us can support it.
  642. ** (Something in device configuration header tells us).
  643. */
  644. __raw_writel(0x0000004f, dino_dev->hba.base_addr+DINO_PCICMD);
  645. /* Somewhere, the PCI spec says give devices 1 second
  646. ** to recover from the #RESET being de-asserted.
  647. ** Experience shows most devices only need 10ms.
  648. ** This short-cut speeds up booting significantly.
  649. */
  650. mdelay(pci_post_reset_delay);
  651. }
  652. static int __init
  653. dino_bridge_init(struct dino_device *dino_dev, const char *name)
  654. {
  655. unsigned long io_addr;
  656. int result, i, count=0;
  657. struct resource *res, *prevres = NULL;
  658. /*
  659. * Decoding IO_ADDR_EN only works for Built-in Dino
  660. * since PDC has already initialized this.
  661. */
  662. io_addr = __raw_readl(dino_dev->hba.base_addr + DINO_IO_ADDR_EN);
  663. if (io_addr == 0) {
  664. printk(KERN_WARNING "%s: No PCI devices enabled.\n", name);
  665. return -ENODEV;
  666. }
  667. res = &dino_dev->hba.lmmio_space;
  668. for (i = 0; i < 32; i++) {
  669. unsigned long start, end;
  670. if((io_addr & (1 << i)) == 0)
  671. continue;
  672. start = F_EXTEND(0xf0000000UL) | (i << 23);
  673. end = start + 8 * 1024 * 1024 - 1;
  674. DBG("DINO RANGE %d is at 0x%lx-0x%lx\n", count,
  675. start, end);
  676. if(prevres && prevres->end + 1 == start) {
  677. prevres->end = end;
  678. } else {
  679. if(count >= DINO_MAX_LMMIO_RESOURCES) {
  680. printk(KERN_ERR "%s is out of resource windows for range %d (0x%lx-0x%lx)\n", name, count, start, end);
  681. break;
  682. }
  683. prevres = res;
  684. res->start = start;
  685. res->end = end;
  686. res->flags = IORESOURCE_MEM;
  687. res->name = kmalloc(64, GFP_KERNEL);
  688. if(res->name)
  689. snprintf((char *)res->name, 64, "%s LMMIO %d",
  690. name, count);
  691. res++;
  692. count++;
  693. }
  694. }
  695. res = &dino_dev->hba.lmmio_space;
  696. for(i = 0; i < DINO_MAX_LMMIO_RESOURCES; i++) {
  697. if(res[i].flags == 0)
  698. break;
  699. result = ccio_request_resource(dino_dev->hba.dev, &res[i]);
  700. if (result < 0) {
  701. printk(KERN_ERR "%s: failed to claim PCI Bus address "
  702. "space %d (%pR)!\n", name, i, &res[i]);
  703. return result;
  704. }
  705. }
  706. return 0;
  707. }
  708. static int __init dino_common_init(struct parisc_device *dev,
  709. struct dino_device *dino_dev, const char *name)
  710. {
  711. int status;
  712. u32 eim;
  713. struct resource *res;
  714. pcibios_register_hba(&dino_dev->hba);
  715. pci_bios = &dino_bios_ops; /* used by pci_scan_bus() */
  716. pci_port = &dino_port_ops;
  717. /*
  718. ** Note: SMP systems can make use of IRR1/IAR1 registers
  719. ** But it won't buy much performance except in very
  720. ** specific applications/configurations. Note Dino
  721. ** still only has 11 IRQ input lines - just map some of them
  722. ** to a different processor.
  723. */
  724. dev->irq = gsc_alloc_irq(&dino_dev->gsc_irq);
  725. eim = ((u32) dino_dev->gsc_irq.txn_addr) | dino_dev->gsc_irq.txn_data;
  726. /*
  727. ** Dino needs a PA "IRQ" to get a processor's attention.
  728. ** arch/parisc/kernel/irq.c returns an EIRR bit.
  729. */
  730. if (dev->irq < 0) {
  731. printk(KERN_WARNING "%s: gsc_alloc_irq() failed\n", name);
  732. return 1;
  733. }
  734. status = request_irq(dev->irq, dino_isr, 0, name, dino_dev);
  735. if (status) {
  736. printk(KERN_WARNING "%s: request_irq() failed with %d\n",
  737. name, status);
  738. return 1;
  739. }
  740. /* Support the serial port which is sometimes attached on built-in
  741. * Dino / Cujo chips.
  742. */
  743. gsc_fixup_irqs(dev, dino_dev, dino_choose_irq);
  744. /*
  745. ** This enables DINO to generate interrupts when it sees
  746. ** any of its inputs *change*. Just asserting an IRQ
  747. ** before it's enabled (ie unmasked) isn't good enough.
  748. */
  749. __raw_writel(eim, dino_dev->hba.base_addr+DINO_IAR0);
  750. /*
  751. ** Some platforms don't clear Dino's IRR0 register at boot time.
  752. ** Reading will clear it now.
  753. */
  754. __raw_readl(dino_dev->hba.base_addr+DINO_IRR0);
  755. /* allocate I/O Port resource region */
  756. res = &dino_dev->hba.io_space;
  757. if (!is_cujo(&dev->id)) {
  758. res->name = "Dino I/O Port";
  759. } else {
  760. res->name = "Cujo I/O Port";
  761. }
  762. res->start = HBA_PORT_BASE(dino_dev->hba.hba_num);
  763. res->end = res->start + (HBA_PORT_SPACE_SIZE - 1);
  764. res->flags = IORESOURCE_IO; /* do not mark it busy ! */
  765. if (request_resource(&ioport_resource, res) < 0) {
  766. printk(KERN_ERR "%s: request I/O Port region failed "
  767. "0x%lx/%lx (hpa 0x%px)\n",
  768. name, (unsigned long)res->start, (unsigned long)res->end,
  769. dino_dev->hba.base_addr);
  770. return 1;
  771. }
  772. return 0;
  773. }
  774. #define CUJO_RAVEN_ADDR F_EXTEND(0xf1000000UL)
  775. #define CUJO_FIREHAWK_ADDR F_EXTEND(0xf1604000UL)
  776. #define CUJO_RAVEN_BADPAGE 0x01003000UL
  777. #define CUJO_FIREHAWK_BADPAGE 0x01607000UL
  778. static const char dino_vers[][4] = {
  779. "2.0",
  780. "2.1",
  781. "3.0",
  782. "3.1"
  783. };
  784. static const char cujo_vers[][4] = {
  785. "1.0",
  786. "2.0"
  787. };
  788. void ccio_cujo20_fixup(struct parisc_device *dev, u32 iovp);
  789. /*
  790. ** Determine if dino should claim this chip (return 0) or not (return 1).
  791. ** If so, initialize the chip appropriately (card-mode vs bridge mode).
  792. ** Much of the initialization is common though.
  793. */
  794. static int __init dino_probe(struct parisc_device *dev)
  795. {
  796. struct dino_device *dino_dev; // Dino specific control struct
  797. const char *version = "unknown";
  798. char *name;
  799. int is_cujo = 0;
  800. LIST_HEAD(resources);
  801. struct pci_bus *bus;
  802. unsigned long hpa = dev->hpa.start;
  803. int max;
  804. name = "Dino";
  805. if (is_card_dino(&dev->id)) {
  806. version = "3.x (card mode)";
  807. } else {
  808. if (!is_cujo(&dev->id)) {
  809. if (dev->id.hversion_rev < 4) {
  810. version = dino_vers[dev->id.hversion_rev];
  811. }
  812. } else {
  813. name = "Cujo";
  814. is_cujo = 1;
  815. if (dev->id.hversion_rev < 2) {
  816. version = cujo_vers[dev->id.hversion_rev];
  817. }
  818. }
  819. }
  820. printk("%s version %s found at 0x%lx\n", name, version, hpa);
  821. if (!request_mem_region(hpa, PAGE_SIZE, name)) {
  822. printk(KERN_ERR "DINO: Hey! Someone took my MMIO space (0x%lx)!\n",
  823. hpa);
  824. return 1;
  825. }
  826. /* Check for bugs */
  827. if (is_cujo && dev->id.hversion_rev == 1) {
  828. #ifdef CONFIG_IOMMU_CCIO
  829. printk(KERN_WARNING "Enabling Cujo 2.0 bug workaround\n");
  830. if (hpa == (unsigned long)CUJO_RAVEN_ADDR) {
  831. ccio_cujo20_fixup(dev, CUJO_RAVEN_BADPAGE);
  832. } else if (hpa == (unsigned long)CUJO_FIREHAWK_ADDR) {
  833. ccio_cujo20_fixup(dev, CUJO_FIREHAWK_BADPAGE);
  834. } else {
  835. printk("Don't recognise Cujo at address 0x%lx, not enabling workaround\n", hpa);
  836. }
  837. #endif
  838. } else if (!is_cujo && !is_card_dino(&dev->id) &&
  839. dev->id.hversion_rev < 3) {
  840. printk(KERN_WARNING
  841. "The GSCtoPCI (Dino hrev %d) bus converter found may exhibit\n"
  842. "data corruption. See Service Note Numbers: A4190A-01, A4191A-01.\n"
  843. "Systems shipped after Aug 20, 1997 will not exhibit this problem.\n"
  844. "Models affected: C180, C160, C160L, B160L, and B132L workstations.\n\n",
  845. dev->id.hversion_rev);
  846. /* REVISIT: why are C200/C240 listed in the README table but not
  847. ** "Models affected"? Could be an omission in the original literature.
  848. */
  849. }
  850. dino_dev = kzalloc(sizeof(struct dino_device), GFP_KERNEL);
  851. if (!dino_dev) {
  852. printk("dino_init_chip - couldn't alloc dino_device\n");
  853. return 1;
  854. }
  855. dino_dev->hba.dev = dev;
  856. dino_dev->hba.base_addr = ioremap(hpa, 4096);
  857. dino_dev->hba.lmmio_space_offset = PCI_F_EXTEND;
  858. spin_lock_init(&dino_dev->dinosaur_pen);
  859. dino_dev->hba.iommu = ccio_get_iommu(dev);
  860. if (is_card_dino(&dev->id)) {
  861. dino_card_init(dino_dev);
  862. } else {
  863. dino_bridge_init(dino_dev, name);
  864. }
  865. if (dino_common_init(dev, dino_dev, name))
  866. return 1;
  867. dev->dev.platform_data = dino_dev;
  868. pci_add_resource_offset(&resources, &dino_dev->hba.io_space,
  869. HBA_PORT_BASE(dino_dev->hba.hba_num));
  870. if (dino_dev->hba.lmmio_space.flags)
  871. pci_add_resource_offset(&resources, &dino_dev->hba.lmmio_space,
  872. dino_dev->hba.lmmio_space_offset);
  873. if (dino_dev->hba.elmmio_space.flags)
  874. pci_add_resource_offset(&resources, &dino_dev->hba.elmmio_space,
  875. dino_dev->hba.lmmio_space_offset);
  876. if (dino_dev->hba.gmmio_space.flags)
  877. pci_add_resource(&resources, &dino_dev->hba.gmmio_space);
  878. dino_dev->hba.bus_num.start = dino_current_bus;
  879. dino_dev->hba.bus_num.end = 255;
  880. dino_dev->hba.bus_num.flags = IORESOURCE_BUS;
  881. pci_add_resource(&resources, &dino_dev->hba.bus_num);
  882. /*
  883. ** It's not used to avoid chicken/egg problems
  884. ** with configuration accessor functions.
  885. */
  886. dino_dev->hba.hba_bus = bus = pci_create_root_bus(&dev->dev,
  887. dino_current_bus, &dino_cfg_ops, NULL, &resources);
  888. if (!bus) {
  889. printk(KERN_ERR "ERROR: failed to scan PCI bus on %s (duplicate bus number %d?)\n",
  890. dev_name(&dev->dev), dino_current_bus);
  891. pci_free_resource_list(&resources);
  892. /* increment the bus number in case of duplicates */
  893. dino_current_bus++;
  894. return 0;
  895. }
  896. max = pci_scan_child_bus(bus);
  897. pci_bus_update_busn_res_end(bus, max);
  898. /* This code *depends* on scanning being single threaded
  899. * if it isn't, this global bus number count will fail
  900. */
  901. dino_current_bus = max + 1;
  902. pci_bus_assign_resources(bus);
  903. pci_bus_add_devices(bus);
  904. return 0;
  905. }
  906. /*
  907. * Normally, we would just test sversion. But the Elroy PCI adapter has
  908. * the same sversion as Dino, so we have to check hversion as well.
  909. * Unfortunately, the J2240 PDC reports the wrong hversion for the first
  910. * Dino, so we have to test for Dino, Cujo and Dino-in-a-J2240.
  911. * For card-mode Dino, most machines report an sversion of 9D. But 715
  912. * and 725 firmware misreport it as 0x08080 for no adequately explained
  913. * reason.
  914. */
  915. static const struct parisc_device_id dino_tbl[] __initconst = {
  916. { HPHW_A_DMA, HVERSION_REV_ANY_ID, 0x004, 0x0009D },/* Card-mode Dino */
  917. { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x08080 }, /* XXX */
  918. { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x680, 0xa }, /* Bridge-mode Dino */
  919. { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x682, 0xa }, /* Bridge-mode Cujo */
  920. { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x05d, 0xa }, /* Dino in a J2240 */
  921. { 0, }
  922. };
  923. static struct parisc_driver dino_driver __refdata = {
  924. .name = "dino",
  925. .id_table = dino_tbl,
  926. .probe = dino_probe,
  927. };
  928. /*
  929. * One time initialization to let the world know Dino is here.
  930. * This is the only routine which is NOT static.
  931. * Must be called exactly once before pci_init().
  932. */
  933. int __init dino_init(void)
  934. {
  935. register_parisc_driver(&dino_driver);
  936. return 0;
  937. }