dino.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  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 irq_desc *desc = irq_to_desc(irq);
  264. struct dino_device *dino_dev = desc->chip_data;
  265. int local_irq = gsc_find_local_irq(irq, dino_dev->global_irq, DINO_LOCAL_IRQS);
  266. DBG(KERN_WARNING "%s(0x%p, %d)\n", __func__, dino_dev, irq);
  267. /* Clear the matching bit in the IMR register */
  268. dino_dev->imr &= ~(DINO_MASK_IRQ(local_irq));
  269. __raw_writel(dino_dev->imr, dino_dev->hba.base_addr+DINO_IMR);
  270. }
  271. static void dino_enable_irq(unsigned int irq)
  272. {
  273. struct irq_desc *desc = irq_to_desc(irq);
  274. struct dino_device *dino_dev = desc->chip_data;
  275. int local_irq = gsc_find_local_irq(irq, dino_dev->global_irq, DINO_LOCAL_IRQS);
  276. u32 tmp;
  277. DBG(KERN_WARNING "%s(0x%p, %d)\n", __func__, dino_dev, irq);
  278. /*
  279. ** clear pending IRQ bits
  280. **
  281. ** This does NOT change ILR state!
  282. ** See comment below for ILR usage.
  283. */
  284. __raw_readl(dino_dev->hba.base_addr+DINO_IPR);
  285. /* set the matching bit in the IMR register */
  286. dino_dev->imr |= DINO_MASK_IRQ(local_irq); /* used in dino_isr() */
  287. __raw_writel( dino_dev->imr, dino_dev->hba.base_addr+DINO_IMR);
  288. /* Emulate "Level Triggered" Interrupt
  289. ** Basically, a driver is blowing it if the IRQ line is asserted
  290. ** while the IRQ is disabled. But tulip.c seems to do that....
  291. ** Give 'em a kluge award and a nice round of applause!
  292. **
  293. ** The gsc_write will generate an interrupt which invokes dino_isr().
  294. ** dino_isr() will read IPR and find nothing. But then catch this
  295. ** when it also checks ILR.
  296. */
  297. tmp = __raw_readl(dino_dev->hba.base_addr+DINO_ILR);
  298. if (tmp & DINO_MASK_IRQ(local_irq)) {
  299. DBG(KERN_WARNING "%s(): IRQ asserted! (ILR 0x%x)\n",
  300. __func__, tmp);
  301. gsc_writel(dino_dev->txn_data, dino_dev->txn_addr);
  302. }
  303. }
  304. static unsigned int dino_startup_irq(unsigned int irq)
  305. {
  306. dino_enable_irq(irq);
  307. return 0;
  308. }
  309. static struct irq_chip dino_interrupt_type = {
  310. .typename = "GSC-PCI",
  311. .startup = dino_startup_irq,
  312. .shutdown = dino_disable_irq,
  313. .enable = dino_enable_irq,
  314. .disable = dino_disable_irq,
  315. .ack = no_ack_irq,
  316. .end = no_end_irq,
  317. };
  318. /*
  319. * Handle a Processor interrupt generated by Dino.
  320. *
  321. * ilr_loop counter is a kluge to prevent a "stuck" IRQ line from
  322. * wedging the CPU. Could be removed or made optional at some point.
  323. */
  324. static irqreturn_t dino_isr(int irq, void *intr_dev)
  325. {
  326. struct dino_device *dino_dev = intr_dev;
  327. u32 mask;
  328. int ilr_loop = 100;
  329. /* read and acknowledge pending interrupts */
  330. #ifdef DINO_DEBUG
  331. dino_dev->dino_irr0 =
  332. #endif
  333. mask = __raw_readl(dino_dev->hba.base_addr+DINO_IRR0) & DINO_IRR_MASK;
  334. if (mask == 0)
  335. return IRQ_NONE;
  336. ilr_again:
  337. do {
  338. int local_irq = __ffs(mask);
  339. int irq = dino_dev->global_irq[local_irq];
  340. DBG(KERN_DEBUG "%s(%d, %p) mask 0x%x\n",
  341. __func__, irq, intr_dev, mask);
  342. __do_IRQ(irq);
  343. mask &= ~(1 << local_irq);
  344. } while (mask);
  345. /* Support for level triggered IRQ lines.
  346. **
  347. ** Dropping this support would make this routine *much* faster.
  348. ** But since PCI requires level triggered IRQ line to share lines...
  349. ** device drivers may assume lines are level triggered (and not
  350. ** edge triggered like EISA/ISA can be).
  351. */
  352. mask = __raw_readl(dino_dev->hba.base_addr+DINO_ILR) & dino_dev->imr;
  353. if (mask) {
  354. if (--ilr_loop > 0)
  355. goto ilr_again;
  356. printk(KERN_ERR "Dino 0x%p: stuck interrupt %d\n",
  357. dino_dev->hba.base_addr, mask);
  358. return IRQ_NONE;
  359. }
  360. return IRQ_HANDLED;
  361. }
  362. static void dino_assign_irq(struct dino_device *dino, int local_irq, int *irqp)
  363. {
  364. int irq = gsc_assign_irq(&dino_interrupt_type, dino);
  365. if (irq == NO_IRQ)
  366. return;
  367. *irqp = irq;
  368. dino->global_irq[local_irq] = irq;
  369. }
  370. static void dino_choose_irq(struct parisc_device *dev, void *ctrl)
  371. {
  372. int irq;
  373. struct dino_device *dino = ctrl;
  374. switch (dev->id.sversion) {
  375. case 0x00084: irq = 8; break; /* PS/2 */
  376. case 0x0008c: irq = 10; break; /* RS232 */
  377. case 0x00096: irq = 8; break; /* PS/2 */
  378. default: return; /* Unknown */
  379. }
  380. dino_assign_irq(dino, irq, &dev->irq);
  381. }
  382. /*
  383. * Cirrus 6832 Cardbus reports wrong irq on RDI Tadpole PARISC Laptop (deller@gmx.de)
  384. * (the irqs are off-by-one, not sure yet if this is a cirrus, dino-hardware or dino-driver problem...)
  385. */
  386. static void __devinit quirk_cirrus_cardbus(struct pci_dev *dev)
  387. {
  388. u8 new_irq = dev->irq - 1;
  389. printk(KERN_INFO "PCI: Cirrus Cardbus IRQ fixup for %s, from %d to %d\n",
  390. pci_name(dev), dev->irq, new_irq);
  391. dev->irq = new_irq;
  392. }
  393. DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6832, quirk_cirrus_cardbus );
  394. static void __init
  395. dino_bios_init(void)
  396. {
  397. DBG("dino_bios_init\n");
  398. }
  399. /*
  400. * dino_card_setup - Set up the memory space for a Dino in card mode.
  401. * @bus: the bus under this dino
  402. *
  403. * Claim an 8MB chunk of unused IO space and call the generic PCI routines
  404. * to set up the addresses of the devices on this bus.
  405. */
  406. #define _8MB 0x00800000UL
  407. static void __init
  408. dino_card_setup(struct pci_bus *bus, void __iomem *base_addr)
  409. {
  410. int i;
  411. struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge));
  412. struct resource *res;
  413. char name[128];
  414. int size;
  415. res = &dino_dev->hba.lmmio_space;
  416. res->flags = IORESOURCE_MEM;
  417. size = scnprintf(name, sizeof(name), "Dino LMMIO (%s)",
  418. dev_name(bus->bridge));
  419. res->name = kmalloc(size+1, GFP_KERNEL);
  420. if(res->name)
  421. strcpy((char *)res->name, name);
  422. else
  423. res->name = dino_dev->hba.lmmio_space.name;
  424. if (ccio_allocate_resource(dino_dev->hba.dev, res, _8MB,
  425. F_EXTEND(0xf0000000UL) | _8MB,
  426. F_EXTEND(0xffffffffUL) &~ _8MB, _8MB) < 0) {
  427. struct list_head *ln, *tmp_ln;
  428. printk(KERN_ERR "Dino: cannot attach bus %s\n",
  429. dev_name(bus->bridge));
  430. /* kill the bus, we can't do anything with it */
  431. list_for_each_safe(ln, tmp_ln, &bus->devices) {
  432. struct pci_dev *dev = pci_dev_b(ln);
  433. list_del(&dev->bus_list);
  434. }
  435. return;
  436. }
  437. bus->resource[1] = res;
  438. bus->resource[0] = &(dino_dev->hba.io_space);
  439. /* Now tell dino what range it has */
  440. for (i = 1; i < 31; i++) {
  441. if (res->start == F_EXTEND(0xf0000000UL | (i * _8MB)))
  442. break;
  443. }
  444. DBG("DINO GSC WRITE i=%d, start=%lx, dino addr = %p\n",
  445. i, res->start, base_addr + DINO_IO_ADDR_EN);
  446. __raw_writel(1 << i, base_addr + DINO_IO_ADDR_EN);
  447. }
  448. static void __init
  449. dino_card_fixup(struct pci_dev *dev)
  450. {
  451. u32 irq_pin;
  452. /*
  453. ** REVISIT: card-mode PCI-PCI expansion chassis do exist.
  454. ** Not sure they were ever productized.
  455. ** Die here since we'll die later in dino_inb() anyway.
  456. */
  457. if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
  458. panic("Card-Mode Dino: PCI-PCI Bridge not supported\n");
  459. }
  460. /*
  461. ** Set Latency Timer to 0xff (not a shared bus)
  462. ** Set CACHELINE_SIZE.
  463. */
  464. dino_cfg_write(dev->bus, dev->devfn,
  465. PCI_CACHE_LINE_SIZE, 2, 0xff00 | L1_CACHE_BYTES/4);
  466. /*
  467. ** Program INT_LINE for card-mode devices.
  468. ** The cards are hardwired according to this algorithm.
  469. ** And it doesn't matter if PPB's are present or not since
  470. ** the IRQ lines bypass the PPB.
  471. **
  472. ** "-1" converts INTA-D (1-4) to PCIINTA-D (0-3) range.
  473. ** The additional "-1" adjusts for skewing the IRQ<->slot.
  474. */
  475. dino_cfg_read(dev->bus, dev->devfn, PCI_INTERRUPT_PIN, 1, &irq_pin);
  476. dev->irq = pci_swizzle_interrupt_pin(dev, irq_pin) - 1;
  477. /* Shouldn't really need to do this but it's in case someone tries
  478. ** to bypass PCI services and look at the card themselves.
  479. */
  480. dino_cfg_write(dev->bus, dev->devfn, PCI_INTERRUPT_LINE, 1, dev->irq);
  481. }
  482. /* The alignment contraints for PCI bridges under dino */
  483. #define DINO_BRIDGE_ALIGN 0x100000
  484. static void __init
  485. dino_fixup_bus(struct pci_bus *bus)
  486. {
  487. struct list_head *ln;
  488. struct pci_dev *dev;
  489. struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge));
  490. int port_base = HBA_PORT_BASE(dino_dev->hba.hba_num);
  491. DBG(KERN_WARNING "%s(0x%p) bus %d platform_data 0x%p\n",
  492. __func__, bus, bus->secondary,
  493. bus->bridge->platform_data);
  494. /* Firmware doesn't set up card-mode dino, so we have to */
  495. if (is_card_dino(&dino_dev->hba.dev->id)) {
  496. dino_card_setup(bus, dino_dev->hba.base_addr);
  497. } else if(bus->parent == NULL) {
  498. /* must have a dino above it, reparent the resources
  499. * into the dino window */
  500. int i;
  501. struct resource *res = &dino_dev->hba.lmmio_space;
  502. bus->resource[0] = &(dino_dev->hba.io_space);
  503. for(i = 0; i < DINO_MAX_LMMIO_RESOURCES; i++) {
  504. if(res[i].flags == 0)
  505. break;
  506. bus->resource[i+1] = &res[i];
  507. }
  508. } else if (bus->parent) {
  509. int i;
  510. pci_read_bridge_bases(bus);
  511. for(i = PCI_BRIDGE_RESOURCES; i < PCI_NUM_RESOURCES; i++) {
  512. if((bus->self->resource[i].flags &
  513. (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
  514. continue;
  515. if(bus->self->resource[i].flags & IORESOURCE_MEM) {
  516. /* There's a quirk to alignment of
  517. * bridge memory resources: the start
  518. * is the alignment and start-end is
  519. * the size. However, firmware will
  520. * have assigned start and end, so we
  521. * need to take this into account */
  522. bus->self->resource[i].end = bus->self->resource[i].end - bus->self->resource[i].start + DINO_BRIDGE_ALIGN;
  523. bus->self->resource[i].start = DINO_BRIDGE_ALIGN;
  524. }
  525. DBG("DEBUG %s assigning %d [0x%lx,0x%lx]\n",
  526. dev_name(&bus->self->dev), i,
  527. bus->self->resource[i].start,
  528. bus->self->resource[i].end);
  529. pci_assign_resource(bus->self, i);
  530. DBG("DEBUG %s after assign %d [0x%lx,0x%lx]\n",
  531. dev_name(&bus->self->dev), i,
  532. bus->self->resource[i].start,
  533. bus->self->resource[i].end);
  534. }
  535. }
  536. list_for_each(ln, &bus->devices) {
  537. int i;
  538. dev = pci_dev_b(ln);
  539. if (is_card_dino(&dino_dev->hba.dev->id))
  540. dino_card_fixup(dev);
  541. /*
  542. ** P2PB's only have 2 BARs, no IRQs.
  543. ** I'd like to just ignore them for now.
  544. */
  545. if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)
  546. continue;
  547. /* Adjust the I/O Port space addresses */
  548. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  549. struct resource *res = &dev->resource[i];
  550. if (res->flags & IORESOURCE_IO) {
  551. res->start |= port_base;
  552. res->end |= port_base;
  553. }
  554. #ifdef __LP64__
  555. /* Sign Extend MMIO addresses */
  556. else if (res->flags & IORESOURCE_MEM) {
  557. res->start |= F_EXTEND(0UL);
  558. res->end |= F_EXTEND(0UL);
  559. }
  560. #endif
  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 (0x%lx-0x%lx)!\n", name, i,
  703. (unsigned long)res[i].start, (unsigned long)res[i].end);
  704. return result;
  705. }
  706. }
  707. return 0;
  708. }
  709. static int __init dino_common_init(struct parisc_device *dev,
  710. struct dino_device *dino_dev, const char *name)
  711. {
  712. int status;
  713. u32 eim;
  714. struct gsc_irq gsc_irq;
  715. struct resource *res;
  716. pcibios_register_hba(&dino_dev->hba);
  717. pci_bios = &dino_bios_ops; /* used by pci_scan_bus() */
  718. pci_port = &dino_port_ops;
  719. /*
  720. ** Note: SMP systems can make use of IRR1/IAR1 registers
  721. ** But it won't buy much performance except in very
  722. ** specific applications/configurations. Note Dino
  723. ** still only has 11 IRQ input lines - just map some of them
  724. ** to a different processor.
  725. */
  726. dev->irq = gsc_alloc_irq(&gsc_irq);
  727. dino_dev->txn_addr = gsc_irq.txn_addr;
  728. dino_dev->txn_data = gsc_irq.txn_data;
  729. eim = ((u32) gsc_irq.txn_addr) | gsc_irq.txn_data;
  730. /*
  731. ** Dino needs a PA "IRQ" to get a processor's attention.
  732. ** arch/parisc/kernel/irq.c returns an EIRR bit.
  733. */
  734. if (dev->irq < 0) {
  735. printk(KERN_WARNING "%s: gsc_alloc_irq() failed\n", name);
  736. return 1;
  737. }
  738. status = request_irq(dev->irq, dino_isr, 0, name, dino_dev);
  739. if (status) {
  740. printk(KERN_WARNING "%s: request_irq() failed with %d\n",
  741. name, status);
  742. return 1;
  743. }
  744. /* Support the serial port which is sometimes attached on built-in
  745. * Dino / Cujo chips.
  746. */
  747. gsc_fixup_irqs(dev, dino_dev, dino_choose_irq);
  748. /*
  749. ** This enables DINO to generate interrupts when it sees
  750. ** any of its inputs *change*. Just asserting an IRQ
  751. ** before it's enabled (ie unmasked) isn't good enough.
  752. */
  753. __raw_writel(eim, dino_dev->hba.base_addr+DINO_IAR0);
  754. /*
  755. ** Some platforms don't clear Dino's IRR0 register at boot time.
  756. ** Reading will clear it now.
  757. */
  758. __raw_readl(dino_dev->hba.base_addr+DINO_IRR0);
  759. /* allocate I/O Port resource region */
  760. res = &dino_dev->hba.io_space;
  761. if (!is_cujo(&dev->id)) {
  762. res->name = "Dino I/O Port";
  763. } else {
  764. res->name = "Cujo I/O Port";
  765. }
  766. res->start = HBA_PORT_BASE(dino_dev->hba.hba_num);
  767. res->end = res->start + (HBA_PORT_SPACE_SIZE - 1);
  768. res->flags = IORESOURCE_IO; /* do not mark it busy ! */
  769. if (request_resource(&ioport_resource, res) < 0) {
  770. printk(KERN_ERR "%s: request I/O Port region failed "
  771. "0x%lx/%lx (hpa 0x%p)\n",
  772. name, (unsigned long)res->start, (unsigned long)res->end,
  773. dino_dev->hba.base_addr);
  774. return 1;
  775. }
  776. return 0;
  777. }
  778. #define CUJO_RAVEN_ADDR F_EXTEND(0xf1000000UL)
  779. #define CUJO_FIREHAWK_ADDR F_EXTEND(0xf1604000UL)
  780. #define CUJO_RAVEN_BADPAGE 0x01003000UL
  781. #define CUJO_FIREHAWK_BADPAGE 0x01607000UL
  782. static const char *dino_vers[] = {
  783. "2.0",
  784. "2.1",
  785. "3.0",
  786. "3.1"
  787. };
  788. static const char *cujo_vers[] = {
  789. "1.0",
  790. "2.0"
  791. };
  792. void ccio_cujo20_fixup(struct parisc_device *dev, u32 iovp);
  793. /*
  794. ** Determine if dino should claim this chip (return 0) or not (return 1).
  795. ** If so, initialize the chip appropriately (card-mode vs bridge mode).
  796. ** Much of the initialization is common though.
  797. */
  798. static int __init dino_probe(struct parisc_device *dev)
  799. {
  800. struct dino_device *dino_dev; // Dino specific control struct
  801. const char *version = "unknown";
  802. char *name;
  803. int is_cujo = 0;
  804. struct pci_bus *bus;
  805. unsigned long hpa = dev->hpa.start;
  806. name = "Dino";
  807. if (is_card_dino(&dev->id)) {
  808. version = "3.x (card mode)";
  809. } else {
  810. if (!is_cujo(&dev->id)) {
  811. if (dev->id.hversion_rev < 4) {
  812. version = dino_vers[dev->id.hversion_rev];
  813. }
  814. } else {
  815. name = "Cujo";
  816. is_cujo = 1;
  817. if (dev->id.hversion_rev < 2) {
  818. version = cujo_vers[dev->id.hversion_rev];
  819. }
  820. }
  821. }
  822. printk("%s version %s found at 0x%lx\n", name, version, hpa);
  823. if (!request_mem_region(hpa, PAGE_SIZE, name)) {
  824. printk(KERN_ERR "DINO: Hey! Someone took my MMIO space (0x%ld)!\n",
  825. hpa);
  826. return 1;
  827. }
  828. /* Check for bugs */
  829. if (is_cujo && dev->id.hversion_rev == 1) {
  830. #ifdef CONFIG_IOMMU_CCIO
  831. printk(KERN_WARNING "Enabling Cujo 2.0 bug workaround\n");
  832. if (hpa == (unsigned long)CUJO_RAVEN_ADDR) {
  833. ccio_cujo20_fixup(dev, CUJO_RAVEN_BADPAGE);
  834. } else if (hpa == (unsigned long)CUJO_FIREHAWK_ADDR) {
  835. ccio_cujo20_fixup(dev, CUJO_FIREHAWK_BADPAGE);
  836. } else {
  837. printk("Don't recognise Cujo at address 0x%lx, not enabling workaround\n", hpa);
  838. }
  839. #endif
  840. } else if (!is_cujo && !is_card_dino(&dev->id) &&
  841. dev->id.hversion_rev < 3) {
  842. printk(KERN_WARNING
  843. "The GSCtoPCI (Dino hrev %d) bus converter found may exhibit\n"
  844. "data corruption. See Service Note Numbers: A4190A-01, A4191A-01.\n"
  845. "Systems shipped after Aug 20, 1997 will not exhibit this problem.\n"
  846. "Models affected: C180, C160, C160L, B160L, and B132L workstations.\n\n",
  847. dev->id.hversion_rev);
  848. /* REVISIT: why are C200/C240 listed in the README table but not
  849. ** "Models affected"? Could be an omission in the original literature.
  850. */
  851. }
  852. dino_dev = kzalloc(sizeof(struct dino_device), GFP_KERNEL);
  853. if (!dino_dev) {
  854. printk("dino_init_chip - couldn't alloc dino_device\n");
  855. return 1;
  856. }
  857. dino_dev->hba.dev = dev;
  858. dino_dev->hba.base_addr = ioremap_nocache(hpa, 4096);
  859. dino_dev->hba.lmmio_space_offset = 0; /* CPU addrs == bus addrs */
  860. spin_lock_init(&dino_dev->dinosaur_pen);
  861. dino_dev->hba.iommu = ccio_get_iommu(dev);
  862. if (is_card_dino(&dev->id)) {
  863. dino_card_init(dino_dev);
  864. } else {
  865. dino_bridge_init(dino_dev, name);
  866. }
  867. if (dino_common_init(dev, dino_dev, name))
  868. return 1;
  869. dev->dev.platform_data = dino_dev;
  870. /*
  871. ** It's not used to avoid chicken/egg problems
  872. ** with configuration accessor functions.
  873. */
  874. dino_dev->hba.hba_bus = bus = pci_scan_bus_parented(&dev->dev,
  875. dino_current_bus, &dino_cfg_ops, NULL);
  876. if(bus) {
  877. /* This code *depends* on scanning being single threaded
  878. * if it isn't, this global bus number count will fail
  879. */
  880. dino_current_bus = bus->subordinate + 1;
  881. pci_bus_assign_resources(bus);
  882. pci_bus_add_devices(bus);
  883. } else {
  884. printk(KERN_ERR "ERROR: failed to scan PCI bus on %s (duplicate bus number %d?)\n",
  885. dev_name(&dev->dev), dino_current_bus);
  886. /* increment the bus number in case of duplicates */
  887. dino_current_bus++;
  888. }
  889. return 0;
  890. }
  891. /*
  892. * Normally, we would just test sversion. But the Elroy PCI adapter has
  893. * the same sversion as Dino, so we have to check hversion as well.
  894. * Unfortunately, the J2240 PDC reports the wrong hversion for the first
  895. * Dino, so we have to test for Dino, Cujo and Dino-in-a-J2240.
  896. * For card-mode Dino, most machines report an sversion of 9D. But 715
  897. * and 725 firmware misreport it as 0x08080 for no adequately explained
  898. * reason.
  899. */
  900. static struct parisc_device_id dino_tbl[] = {
  901. { HPHW_A_DMA, HVERSION_REV_ANY_ID, 0x004, 0x0009D },/* Card-mode Dino */
  902. { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x08080 }, /* XXX */
  903. { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x680, 0xa }, /* Bridge-mode Dino */
  904. { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x682, 0xa }, /* Bridge-mode Cujo */
  905. { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x05d, 0xa }, /* Dino in a J2240 */
  906. { 0, }
  907. };
  908. static struct parisc_driver dino_driver = {
  909. .name = "dino",
  910. .id_table = dino_tbl,
  911. .probe = dino_probe,
  912. };
  913. /*
  914. * One time initialization to let the world know Dino is here.
  915. * This is the only routine which is NOT static.
  916. * Must be called exactly once before pci_init().
  917. */
  918. int __init dino_init(void)
  919. {
  920. register_parisc_driver(&dino_driver);
  921. return 0;
  922. }