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