dino.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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. int port_base = HBA_PORT_BASE(dino_dev->hba.hba_num);
  480. DBG(KERN_WARNING "%s(0x%p) bus %d platform_data 0x%p\n",
  481. __func__, bus, bus->secondary,
  482. bus->bridge->platform_data);
  483. /* Firmware doesn't set up card-mode dino, so we have to */
  484. if (is_card_dino(&dino_dev->hba.dev->id)) {
  485. dino_card_setup(bus, dino_dev->hba.base_addr);
  486. } else if (bus->parent) {
  487. int i;
  488. pci_read_bridge_bases(bus);
  489. for(i = PCI_BRIDGE_RESOURCES; i < PCI_NUM_RESOURCES; i++) {
  490. if((bus->self->resource[i].flags &
  491. (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
  492. continue;
  493. if(bus->self->resource[i].flags & IORESOURCE_MEM) {
  494. /* There's a quirk to alignment of
  495. * bridge memory resources: the start
  496. * is the alignment and start-end is
  497. * the size. However, firmware will
  498. * have assigned start and end, so we
  499. * need to take this into account */
  500. bus->self->resource[i].end = bus->self->resource[i].end - bus->self->resource[i].start + DINO_BRIDGE_ALIGN;
  501. bus->self->resource[i].start = DINO_BRIDGE_ALIGN;
  502. }
  503. DBG("DEBUG %s assigning %d [0x%lx,0x%lx]\n",
  504. dev_name(&bus->self->dev), i,
  505. bus->self->resource[i].start,
  506. bus->self->resource[i].end);
  507. WARN_ON(pci_assign_resource(bus->self, i));
  508. DBG("DEBUG %s after assign %d [0x%lx,0x%lx]\n",
  509. dev_name(&bus->self->dev), i,
  510. bus->self->resource[i].start,
  511. bus->self->resource[i].end);
  512. }
  513. }
  514. list_for_each(ln, &bus->devices) {
  515. int i;
  516. dev = pci_dev_b(ln);
  517. if (is_card_dino(&dino_dev->hba.dev->id))
  518. dino_card_fixup(dev);
  519. /*
  520. ** P2PB's only have 2 BARs, no IRQs.
  521. ** I'd like to just ignore them for now.
  522. */
  523. if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)
  524. continue;
  525. /* Adjust the I/O Port space addresses */
  526. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  527. struct resource *res = &dev->resource[i];
  528. if (res->flags & IORESOURCE_IO) {
  529. res->start |= port_base;
  530. res->end |= port_base;
  531. }
  532. #ifdef __LP64__
  533. /* Sign Extend MMIO addresses */
  534. else if (res->flags & IORESOURCE_MEM) {
  535. res->start |= F_EXTEND(0UL);
  536. res->end |= F_EXTEND(0UL);
  537. }
  538. #endif
  539. }
  540. /* null out the ROM resource if there is one (we don't
  541. * care about an expansion rom on parisc, since it
  542. * usually contains (x86) bios code) */
  543. dev->resource[PCI_ROM_RESOURCE].flags = 0;
  544. if(dev->irq == 255) {
  545. #define DINO_FIX_UNASSIGNED_INTERRUPTS
  546. #ifdef DINO_FIX_UNASSIGNED_INTERRUPTS
  547. /* This code tries to assign an unassigned
  548. * interrupt. Leave it disabled unless you
  549. * *really* know what you're doing since the
  550. * pin<->interrupt line mapping varies by bus
  551. * and machine */
  552. u32 irq_pin;
  553. dino_cfg_read(dev->bus, dev->devfn,
  554. PCI_INTERRUPT_PIN, 1, &irq_pin);
  555. irq_pin = pci_swizzle_interrupt_pin(dev, irq_pin) - 1;
  556. printk(KERN_WARNING "Device %s has undefined IRQ, "
  557. "setting to %d\n", pci_name(dev), irq_pin);
  558. dino_cfg_write(dev->bus, dev->devfn,
  559. PCI_INTERRUPT_LINE, 1, irq_pin);
  560. dino_assign_irq(dino_dev, irq_pin, &dev->irq);
  561. #else
  562. dev->irq = 65535;
  563. printk(KERN_WARNING "Device %s has unassigned IRQ\n", pci_name(dev));
  564. #endif
  565. } else {
  566. /* Adjust INT_LINE for that busses region */
  567. dino_assign_irq(dino_dev, dev->irq, &dev->irq);
  568. }
  569. }
  570. }
  571. static struct pci_bios_ops dino_bios_ops = {
  572. .init = dino_bios_init,
  573. .fixup_bus = dino_fixup_bus
  574. };
  575. /*
  576. * Initialise a DINO controller chip
  577. */
  578. static void __init
  579. dino_card_init(struct dino_device *dino_dev)
  580. {
  581. u32 brdg_feat = 0x00784e05;
  582. unsigned long status;
  583. status = __raw_readl(dino_dev->hba.base_addr+DINO_IO_STATUS);
  584. if (status & 0x0000ff80) {
  585. __raw_writel(0x00000005,
  586. dino_dev->hba.base_addr+DINO_IO_COMMAND);
  587. udelay(1);
  588. }
  589. __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_GMASK);
  590. __raw_writel(0x00000001, dino_dev->hba.base_addr+DINO_IO_FBB_EN);
  591. __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_ICR);
  592. #if 1
  593. /* REVISIT - should be a runtime check (eg if (CPU_IS_PCX_L) ...) */
  594. /*
  595. ** PCX-L processors don't support XQL like Dino wants it.
  596. ** PCX-L2 ignore XQL signal and it doesn't matter.
  597. */
  598. brdg_feat &= ~0x4; /* UXQL */
  599. #endif
  600. __raw_writel( brdg_feat, dino_dev->hba.base_addr+DINO_BRDG_FEAT);
  601. /*
  602. ** Don't enable address decoding until we know which I/O range
  603. ** currently is available from the host. Only affects MMIO
  604. ** and not I/O port space.
  605. */
  606. __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_IO_ADDR_EN);
  607. __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_DAMODE);
  608. __raw_writel(0x00222222, dino_dev->hba.base_addr+DINO_PCIROR);
  609. __raw_writel(0x00222222, dino_dev->hba.base_addr+DINO_PCIWOR);
  610. __raw_writel(0x00000040, dino_dev->hba.base_addr+DINO_MLTIM);
  611. __raw_writel(0x00000080, dino_dev->hba.base_addr+DINO_IO_CONTROL);
  612. __raw_writel(0x0000008c, dino_dev->hba.base_addr+DINO_TLTIM);
  613. /* Disable PAMR before writing PAPR */
  614. __raw_writel(0x0000007e, dino_dev->hba.base_addr+DINO_PAMR);
  615. __raw_writel(0x0000007f, dino_dev->hba.base_addr+DINO_PAPR);
  616. __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_PAMR);
  617. /*
  618. ** Dino ERS encourages enabling FBB (0x6f).
  619. ** We can't until we know *all* devices below us can support it.
  620. ** (Something in device configuration header tells us).
  621. */
  622. __raw_writel(0x0000004f, dino_dev->hba.base_addr+DINO_PCICMD);
  623. /* Somewhere, the PCI spec says give devices 1 second
  624. ** to recover from the #RESET being de-asserted.
  625. ** Experience shows most devices only need 10ms.
  626. ** This short-cut speeds up booting significantly.
  627. */
  628. mdelay(pci_post_reset_delay);
  629. }
  630. static int __init
  631. dino_bridge_init(struct dino_device *dino_dev, const char *name)
  632. {
  633. unsigned long io_addr;
  634. int result, i, count=0;
  635. struct resource *res, *prevres = NULL;
  636. /*
  637. * Decoding IO_ADDR_EN only works for Built-in Dino
  638. * since PDC has already initialized this.
  639. */
  640. io_addr = __raw_readl(dino_dev->hba.base_addr + DINO_IO_ADDR_EN);
  641. if (io_addr == 0) {
  642. printk(KERN_WARNING "%s: No PCI devices enabled.\n", name);
  643. return -ENODEV;
  644. }
  645. res = &dino_dev->hba.lmmio_space;
  646. for (i = 0; i < 32; i++) {
  647. unsigned long start, end;
  648. if((io_addr & (1 << i)) == 0)
  649. continue;
  650. start = F_EXTEND(0xf0000000UL) | (i << 23);
  651. end = start + 8 * 1024 * 1024 - 1;
  652. DBG("DINO RANGE %d is at 0x%lx-0x%lx\n", count,
  653. start, end);
  654. if(prevres && prevres->end + 1 == start) {
  655. prevres->end = end;
  656. } else {
  657. if(count >= DINO_MAX_LMMIO_RESOURCES) {
  658. printk(KERN_ERR "%s is out of resource windows for range %d (0x%lx-0x%lx)\n", name, count, start, end);
  659. break;
  660. }
  661. prevres = res;
  662. res->start = start;
  663. res->end = end;
  664. res->flags = IORESOURCE_MEM;
  665. res->name = kmalloc(64, GFP_KERNEL);
  666. if(res->name)
  667. snprintf((char *)res->name, 64, "%s LMMIO %d",
  668. name, count);
  669. res++;
  670. count++;
  671. }
  672. }
  673. res = &dino_dev->hba.lmmio_space;
  674. for(i = 0; i < DINO_MAX_LMMIO_RESOURCES; i++) {
  675. if(res[i].flags == 0)
  676. break;
  677. result = ccio_request_resource(dino_dev->hba.dev, &res[i]);
  678. if (result < 0) {
  679. printk(KERN_ERR "%s: failed to claim PCI Bus address "
  680. "space %d (0x%lx-0x%lx)!\n", name, i,
  681. (unsigned long)res[i].start, (unsigned long)res[i].end);
  682. return result;
  683. }
  684. }
  685. return 0;
  686. }
  687. static int __init dino_common_init(struct parisc_device *dev,
  688. struct dino_device *dino_dev, const char *name)
  689. {
  690. int status;
  691. u32 eim;
  692. struct gsc_irq gsc_irq;
  693. struct resource *res;
  694. pcibios_register_hba(&dino_dev->hba);
  695. pci_bios = &dino_bios_ops; /* used by pci_scan_bus() */
  696. pci_port = &dino_port_ops;
  697. /*
  698. ** Note: SMP systems can make use of IRR1/IAR1 registers
  699. ** But it won't buy much performance except in very
  700. ** specific applications/configurations. Note Dino
  701. ** still only has 11 IRQ input lines - just map some of them
  702. ** to a different processor.
  703. */
  704. dev->irq = gsc_alloc_irq(&gsc_irq);
  705. dino_dev->txn_addr = gsc_irq.txn_addr;
  706. dino_dev->txn_data = gsc_irq.txn_data;
  707. eim = ((u32) gsc_irq.txn_addr) | gsc_irq.txn_data;
  708. /*
  709. ** Dino needs a PA "IRQ" to get a processor's attention.
  710. ** arch/parisc/kernel/irq.c returns an EIRR bit.
  711. */
  712. if (dev->irq < 0) {
  713. printk(KERN_WARNING "%s: gsc_alloc_irq() failed\n", name);
  714. return 1;
  715. }
  716. status = request_irq(dev->irq, dino_isr, 0, name, dino_dev);
  717. if (status) {
  718. printk(KERN_WARNING "%s: request_irq() failed with %d\n",
  719. name, status);
  720. return 1;
  721. }
  722. /* Support the serial port which is sometimes attached on built-in
  723. * Dino / Cujo chips.
  724. */
  725. gsc_fixup_irqs(dev, dino_dev, dino_choose_irq);
  726. /*
  727. ** This enables DINO to generate interrupts when it sees
  728. ** any of its inputs *change*. Just asserting an IRQ
  729. ** before it's enabled (ie unmasked) isn't good enough.
  730. */
  731. __raw_writel(eim, dino_dev->hba.base_addr+DINO_IAR0);
  732. /*
  733. ** Some platforms don't clear Dino's IRR0 register at boot time.
  734. ** Reading will clear it now.
  735. */
  736. __raw_readl(dino_dev->hba.base_addr+DINO_IRR0);
  737. /* allocate I/O Port resource region */
  738. res = &dino_dev->hba.io_space;
  739. if (!is_cujo(&dev->id)) {
  740. res->name = "Dino I/O Port";
  741. } else {
  742. res->name = "Cujo I/O Port";
  743. }
  744. res->start = HBA_PORT_BASE(dino_dev->hba.hba_num);
  745. res->end = res->start + (HBA_PORT_SPACE_SIZE - 1);
  746. res->flags = IORESOURCE_IO; /* do not mark it busy ! */
  747. if (request_resource(&ioport_resource, res) < 0) {
  748. printk(KERN_ERR "%s: request I/O Port region failed "
  749. "0x%lx/%lx (hpa 0x%p)\n",
  750. name, (unsigned long)res->start, (unsigned long)res->end,
  751. dino_dev->hba.base_addr);
  752. return 1;
  753. }
  754. return 0;
  755. }
  756. #define CUJO_RAVEN_ADDR F_EXTEND(0xf1000000UL)
  757. #define CUJO_FIREHAWK_ADDR F_EXTEND(0xf1604000UL)
  758. #define CUJO_RAVEN_BADPAGE 0x01003000UL
  759. #define CUJO_FIREHAWK_BADPAGE 0x01607000UL
  760. static const char *dino_vers[] = {
  761. "2.0",
  762. "2.1",
  763. "3.0",
  764. "3.1"
  765. };
  766. static const char *cujo_vers[] = {
  767. "1.0",
  768. "2.0"
  769. };
  770. void ccio_cujo20_fixup(struct parisc_device *dev, u32 iovp);
  771. /*
  772. ** Determine if dino should claim this chip (return 0) or not (return 1).
  773. ** If so, initialize the chip appropriately (card-mode vs bridge mode).
  774. ** Much of the initialization is common though.
  775. */
  776. static int __init dino_probe(struct parisc_device *dev)
  777. {
  778. struct dino_device *dino_dev; // Dino specific control struct
  779. const char *version = "unknown";
  780. char *name;
  781. int is_cujo = 0;
  782. LIST_HEAD(resources);
  783. struct pci_bus *bus;
  784. unsigned long hpa = dev->hpa.start;
  785. name = "Dino";
  786. if (is_card_dino(&dev->id)) {
  787. version = "3.x (card mode)";
  788. } else {
  789. if (!is_cujo(&dev->id)) {
  790. if (dev->id.hversion_rev < 4) {
  791. version = dino_vers[dev->id.hversion_rev];
  792. }
  793. } else {
  794. name = "Cujo";
  795. is_cujo = 1;
  796. if (dev->id.hversion_rev < 2) {
  797. version = cujo_vers[dev->id.hversion_rev];
  798. }
  799. }
  800. }
  801. printk("%s version %s found at 0x%lx\n", name, version, hpa);
  802. if (!request_mem_region(hpa, PAGE_SIZE, name)) {
  803. printk(KERN_ERR "DINO: Hey! Someone took my MMIO space (0x%ld)!\n",
  804. hpa);
  805. return 1;
  806. }
  807. /* Check for bugs */
  808. if (is_cujo && dev->id.hversion_rev == 1) {
  809. #ifdef CONFIG_IOMMU_CCIO
  810. printk(KERN_WARNING "Enabling Cujo 2.0 bug workaround\n");
  811. if (hpa == (unsigned long)CUJO_RAVEN_ADDR) {
  812. ccio_cujo20_fixup(dev, CUJO_RAVEN_BADPAGE);
  813. } else if (hpa == (unsigned long)CUJO_FIREHAWK_ADDR) {
  814. ccio_cujo20_fixup(dev, CUJO_FIREHAWK_BADPAGE);
  815. } else {
  816. printk("Don't recognise Cujo at address 0x%lx, not enabling workaround\n", hpa);
  817. }
  818. #endif
  819. } else if (!is_cujo && !is_card_dino(&dev->id) &&
  820. dev->id.hversion_rev < 3) {
  821. printk(KERN_WARNING
  822. "The GSCtoPCI (Dino hrev %d) bus converter found may exhibit\n"
  823. "data corruption. See Service Note Numbers: A4190A-01, A4191A-01.\n"
  824. "Systems shipped after Aug 20, 1997 will not exhibit this problem.\n"
  825. "Models affected: C180, C160, C160L, B160L, and B132L workstations.\n\n",
  826. dev->id.hversion_rev);
  827. /* REVISIT: why are C200/C240 listed in the README table but not
  828. ** "Models affected"? Could be an omission in the original literature.
  829. */
  830. }
  831. dino_dev = kzalloc(sizeof(struct dino_device), GFP_KERNEL);
  832. if (!dino_dev) {
  833. printk("dino_init_chip - couldn't alloc dino_device\n");
  834. return 1;
  835. }
  836. dino_dev->hba.dev = dev;
  837. dino_dev->hba.base_addr = ioremap_nocache(hpa, 4096);
  838. dino_dev->hba.lmmio_space_offset = 0; /* CPU addrs == bus addrs */
  839. spin_lock_init(&dino_dev->dinosaur_pen);
  840. dino_dev->hba.iommu = ccio_get_iommu(dev);
  841. if (is_card_dino(&dev->id)) {
  842. dino_card_init(dino_dev);
  843. } else {
  844. dino_bridge_init(dino_dev, name);
  845. }
  846. if (dino_common_init(dev, dino_dev, name))
  847. return 1;
  848. dev->dev.platform_data = dino_dev;
  849. pci_add_resource(&resources, &dino_dev->hba.io_space);
  850. if (dino_dev->hba.lmmio_space.flags)
  851. pci_add_resource(&resources, &dino_dev->hba.lmmio_space);
  852. if (dino_dev->hba.elmmio_space.flags)
  853. pci_add_resource(&resources, &dino_dev->hba.elmmio_space);
  854. if (dino_dev->hba.gmmio_space.flags)
  855. pci_add_resource(&resources, &dino_dev->hba.gmmio_space);
  856. /*
  857. ** It's not used to avoid chicken/egg problems
  858. ** with configuration accessor functions.
  859. */
  860. dino_dev->hba.hba_bus = bus = pci_create_root_bus(&dev->dev,
  861. dino_current_bus, &dino_cfg_ops, NULL, &resources);
  862. if (!bus) {
  863. printk(KERN_ERR "ERROR: failed to scan PCI bus on %s (duplicate bus number %d?)\n",
  864. dev_name(&dev->dev), dino_current_bus);
  865. pci_free_resource_list(&resources);
  866. /* increment the bus number in case of duplicates */
  867. dino_current_bus++;
  868. return 0;
  869. }
  870. bus->subordinate = pci_scan_child_bus(bus);
  871. /* This code *depends* on scanning being single threaded
  872. * if it isn't, this global bus number count will fail
  873. */
  874. dino_current_bus = bus->subordinate + 1;
  875. pci_bus_assign_resources(bus);
  876. pci_bus_add_devices(bus);
  877. return 0;
  878. }
  879. /*
  880. * Normally, we would just test sversion. But the Elroy PCI adapter has
  881. * the same sversion as Dino, so we have to check hversion as well.
  882. * Unfortunately, the J2240 PDC reports the wrong hversion for the first
  883. * Dino, so we have to test for Dino, Cujo and Dino-in-a-J2240.
  884. * For card-mode Dino, most machines report an sversion of 9D. But 715
  885. * and 725 firmware misreport it as 0x08080 for no adequately explained
  886. * reason.
  887. */
  888. static struct parisc_device_id dino_tbl[] = {
  889. { HPHW_A_DMA, HVERSION_REV_ANY_ID, 0x004, 0x0009D },/* Card-mode Dino */
  890. { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x08080 }, /* XXX */
  891. { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x680, 0xa }, /* Bridge-mode Dino */
  892. { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x682, 0xa }, /* Bridge-mode Cujo */
  893. { HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x05d, 0xa }, /* Dino in a J2240 */
  894. { 0, }
  895. };
  896. static struct parisc_driver dino_driver = {
  897. .name = "dino",
  898. .id_table = dino_tbl,
  899. .probe = dino_probe,
  900. };
  901. /*
  902. * One time initialization to let the world know Dino is here.
  903. * This is the only routine which is NOT static.
  904. * Must be called exactly once before pci_init().
  905. */
  906. int __init dino_init(void)
  907. {
  908. register_parisc_driver(&dino_driver);
  909. return 0;
  910. }