dino.c 31 KB

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