gsc.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Interrupt management for most GSC and related devices.
  3. *
  4. * (c) Copyright 1999 Alex deVries for The Puffin Group
  5. * (c) Copyright 1999 Grant Grundler for Hewlett-Packard
  6. * (c) Copyright 1999 Matthew Wilcox
  7. * (c) Copyright 2000 Helge Deller
  8. * (c) Copyright 2001 Matthew Wilcox for Hewlett-Packard
  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. #include <linux/bitops.h>
  16. #include <linux/errno.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/ioport.h>
  20. #include <linux/module.h>
  21. #include <linux/slab.h>
  22. #include <linux/types.h>
  23. #include <asm/hardware.h>
  24. #include <asm/io.h>
  25. #include "gsc.h"
  26. #undef DEBUG
  27. #ifdef DEBUG
  28. #define DEBPRINTK printk
  29. #else
  30. #define DEBPRINTK(x,...)
  31. #endif
  32. int gsc_alloc_irq(struct gsc_irq *i)
  33. {
  34. int irq = txn_alloc_irq(GSC_EIM_WIDTH);
  35. if (irq < 0) {
  36. printk("cannot get irq\n");
  37. return irq;
  38. }
  39. i->txn_addr = txn_alloc_addr(irq);
  40. i->txn_data = txn_alloc_data(irq);
  41. i->irq = irq;
  42. return irq;
  43. }
  44. int gsc_claim_irq(struct gsc_irq *i, int irq)
  45. {
  46. int c = irq;
  47. irq += CPU_IRQ_BASE; /* virtualize the IRQ first */
  48. irq = txn_claim_irq(irq);
  49. if (irq < 0) {
  50. printk("cannot claim irq %d\n", c);
  51. return irq;
  52. }
  53. i->txn_addr = txn_alloc_addr(irq);
  54. i->txn_data = txn_alloc_data(irq);
  55. i->irq = irq;
  56. return irq;
  57. }
  58. EXPORT_SYMBOL(gsc_alloc_irq);
  59. EXPORT_SYMBOL(gsc_claim_irq);
  60. /* Common interrupt demultiplexer used by Asp, Lasi & Wax. */
  61. irqreturn_t gsc_asic_intr(int gsc_asic_irq, void *dev)
  62. {
  63. unsigned long irr;
  64. struct gsc_asic *gsc_asic = dev;
  65. irr = gsc_readl(gsc_asic->hpa + OFFSET_IRR);
  66. if (irr == 0)
  67. return IRQ_NONE;
  68. DEBPRINTK("%s intr, mask=0x%x\n", gsc_asic->name, irr);
  69. do {
  70. int local_irq = __ffs(irr);
  71. unsigned int irq = gsc_asic->global_irq[local_irq];
  72. __do_IRQ(irq);
  73. irr &= ~(1 << local_irq);
  74. } while (irr);
  75. return IRQ_HANDLED;
  76. }
  77. int gsc_find_local_irq(unsigned int irq, int *global_irqs, int limit)
  78. {
  79. int local_irq;
  80. for (local_irq = 0; local_irq < limit; local_irq++) {
  81. if (global_irqs[local_irq] == irq)
  82. return local_irq;
  83. }
  84. return NO_IRQ;
  85. }
  86. static void gsc_asic_disable_irq(unsigned int irq)
  87. {
  88. struct irq_desc *desc = irq_to_desc(irq);
  89. struct gsc_asic *irq_dev = desc->chip_data;
  90. int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
  91. u32 imr;
  92. DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
  93. irq_dev->name, imr);
  94. /* Disable the IRQ line by clearing the bit in the IMR */
  95. imr = gsc_readl(irq_dev->hpa + OFFSET_IMR);
  96. imr &= ~(1 << local_irq);
  97. gsc_writel(imr, irq_dev->hpa + OFFSET_IMR);
  98. }
  99. static void gsc_asic_enable_irq(unsigned int irq)
  100. {
  101. struct irq_desc *desc = irq_to_desc(irq);
  102. struct gsc_asic *irq_dev = desc->chip_data;
  103. int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
  104. u32 imr;
  105. DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
  106. irq_dev->name, imr);
  107. /* Enable the IRQ line by setting the bit in the IMR */
  108. imr = gsc_readl(irq_dev->hpa + OFFSET_IMR);
  109. imr |= 1 << local_irq;
  110. gsc_writel(imr, irq_dev->hpa + OFFSET_IMR);
  111. /*
  112. * FIXME: read IPR to make sure the IRQ isn't already pending.
  113. * If so, we need to read IRR and manually call do_irq().
  114. */
  115. }
  116. static unsigned int gsc_asic_startup_irq(unsigned int irq)
  117. {
  118. gsc_asic_enable_irq(irq);
  119. return 0;
  120. }
  121. static struct hw_interrupt_type gsc_asic_interrupt_type = {
  122. .typename = "GSC-ASIC",
  123. .startup = gsc_asic_startup_irq,
  124. .shutdown = gsc_asic_disable_irq,
  125. .enable = gsc_asic_enable_irq,
  126. .disable = gsc_asic_disable_irq,
  127. .ack = no_ack_irq,
  128. .end = no_end_irq,
  129. };
  130. int gsc_assign_irq(struct hw_interrupt_type *type, void *data)
  131. {
  132. static int irq = GSC_IRQ_BASE;
  133. struct irq_desc *desc;
  134. if (irq > GSC_IRQ_MAX)
  135. return NO_IRQ;
  136. desc = irq_to_desc(irq);
  137. desc->chip = type;
  138. desc->chip_data = data;
  139. return irq++;
  140. }
  141. void gsc_asic_assign_irq(struct gsc_asic *asic, int local_irq, int *irqp)
  142. {
  143. int irq = asic->global_irq[local_irq];
  144. if (irq <= 0) {
  145. irq = gsc_assign_irq(&gsc_asic_interrupt_type, asic);
  146. if (irq == NO_IRQ)
  147. return;
  148. asic->global_irq[local_irq] = irq;
  149. }
  150. *irqp = irq;
  151. }
  152. static struct device *next_device(struct klist_iter *i)
  153. {
  154. struct klist_node * n = klist_next(i);
  155. return n ? container_of(n, struct device, knode_parent) : NULL;
  156. }
  157. void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
  158. void (*choose_irq)(struct parisc_device *, void *))
  159. {
  160. struct device *dev;
  161. struct klist_iter i;
  162. klist_iter_init(&parent->dev.klist_children, &i);
  163. while ((dev = next_device(&i))) {
  164. struct parisc_device *padev = to_parisc_device(dev);
  165. /* work-around for 715/64 and others which have parent
  166. at path [5] and children at path [5/0/x] */
  167. if (padev->id.hw_type == HPHW_FAULTY)
  168. return gsc_fixup_irqs(padev, ctrl, choose_irq);
  169. choose_irq(padev, ctrl);
  170. }
  171. klist_iter_exit(&i);
  172. }
  173. int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic)
  174. {
  175. struct resource *res;
  176. int i;
  177. gsc_asic->gsc = parent;
  178. /* Initialise local irq -> global irq mapping */
  179. for (i = 0; i < 32; i++) {
  180. gsc_asic->global_irq[i] = NO_IRQ;
  181. }
  182. /* allocate resource region */
  183. res = request_mem_region(gsc_asic->hpa, 0x100000, gsc_asic->name);
  184. if (res) {
  185. res->flags = IORESOURCE_MEM; /* do not mark it busy ! */
  186. }
  187. #if 0
  188. printk(KERN_WARNING "%s IRQ %d EIM 0x%x", gsc_asic->name,
  189. parent->irq, gsc_asic->eim);
  190. if (gsc_readl(gsc_asic->hpa + OFFSET_IMR))
  191. printk(" IMR is non-zero! (0x%x)",
  192. gsc_readl(gsc_asic->hpa + OFFSET_IMR));
  193. printk("\n");
  194. #endif
  195. return 0;
  196. }
  197. extern struct parisc_driver lasi_driver;
  198. extern struct parisc_driver asp_driver;
  199. extern struct parisc_driver wax_driver;
  200. void __init gsc_init(void)
  201. {
  202. #ifdef CONFIG_GSC_LASI
  203. register_parisc_driver(&lasi_driver);
  204. register_parisc_driver(&asp_driver);
  205. #endif
  206. #ifdef CONFIG_GSC_WAX
  207. register_parisc_driver(&wax_driver);
  208. #endif
  209. }