dino.c 30 KB

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