dino.c 31 KB

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