gsc.c 5.9 KB

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