dino.c 30 KB

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