gsc.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 gsc_asic *irq_dev = irq_desc[irq].chip_data;
  89. int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
  90. u32 imr;
  91. DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __FUNCTION__, irq,
  92. irq_dev->name, imr);
  93. /* Disable the IRQ line by clearing the bit in the IMR */
  94. imr = gsc_readl(irq_dev->hpa + OFFSET_IMR);
  95. imr &= ~(1 << local_irq);
  96. gsc_writel(imr, irq_dev->hpa + OFFSET_IMR);
  97. }
  98. static void gsc_asic_enable_irq(unsigned int irq)
  99. {
  100. struct gsc_asic *irq_dev = irq_desc[irq].chip_data;
  101. int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
  102. u32 imr;
  103. DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __FUNCTION__, irq,
  104. irq_dev->name, imr);
  105. /* Enable the IRQ line by setting the bit in the IMR */
  106. imr = gsc_readl(irq_dev->hpa + OFFSET_IMR);
  107. imr |= 1 << local_irq;
  108. gsc_writel(imr, irq_dev->hpa + OFFSET_IMR);
  109. /*
  110. * FIXME: read IPR to make sure the IRQ isn't already pending.
  111. * If so, we need to read IRR and manually call do_irq().
  112. */
  113. }
  114. static unsigned int gsc_asic_startup_irq(unsigned int irq)
  115. {
  116. gsc_asic_enable_irq(irq);
  117. return 0;
  118. }
  119. static struct hw_interrupt_type gsc_asic_interrupt_type = {
  120. .typename = "GSC-ASIC",
  121. .startup = gsc_asic_startup_irq,
  122. .shutdown = gsc_asic_disable_irq,
  123. .enable = gsc_asic_enable_irq,
  124. .disable = gsc_asic_disable_irq,
  125. .ack = no_ack_irq,
  126. .end = no_end_irq,
  127. };
  128. int gsc_assign_irq(struct hw_interrupt_type *type, void *data)
  129. {
  130. static int irq = GSC_IRQ_BASE;
  131. if (irq > GSC_IRQ_MAX)
  132. return NO_IRQ;
  133. irq_desc[irq].chip = type;
  134. irq_desc[irq].chip_data = data;
  135. return irq++;
  136. }
  137. void gsc_asic_assign_irq(struct gsc_asic *asic, int local_irq, int *irqp)
  138. {
  139. int irq = asic->global_irq[local_irq];
  140. if (irq <= 0) {
  141. irq = gsc_assign_irq(&gsc_asic_interrupt_type, asic);
  142. if (irq == NO_IRQ)
  143. return;
  144. asic->global_irq[local_irq] = irq;
  145. }
  146. *irqp = irq;
  147. }
  148. static struct device *next_device(struct klist_iter *i)
  149. {
  150. struct klist_node * n = klist_next(i);
  151. return n ? container_of(n, struct device, knode_parent) : NULL;
  152. }
  153. void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
  154. void (*choose_irq)(struct parisc_device *, void *))
  155. {
  156. struct device *dev;
  157. struct klist_iter i;
  158. klist_iter_init(&parent->dev.klist_children, &i);
  159. while ((dev = next_device(&i))) {
  160. struct parisc_device *padev = to_parisc_device(dev);
  161. /* work-around for 715/64 and others which have parent
  162. at path [5] and children at path [5/0/x] */
  163. if (padev->id.hw_type == HPHW_FAULTY)
  164. return gsc_fixup_irqs(padev, ctrl, choose_irq);
  165. choose_irq(padev, ctrl);
  166. }
  167. klist_iter_exit(&i);
  168. }
  169. int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic)
  170. {
  171. struct resource *res;
  172. int i;
  173. gsc_asic->gsc = parent;
  174. /* Initialise local irq -> global irq mapping */
  175. for (i = 0; i < 32; i++) {
  176. gsc_asic->global_irq[i] = NO_IRQ;
  177. }
  178. /* allocate resource region */
  179. res = request_mem_region(gsc_asic->hpa, 0x100000, gsc_asic->name);
  180. if (res) {
  181. res->flags = IORESOURCE_MEM; /* do not mark it busy ! */
  182. }
  183. #if 0
  184. printk(KERN_WARNING "%s IRQ %d EIM 0x%x", gsc_asic->name,
  185. parent->irq, gsc_asic->eim);
  186. if (gsc_readl(gsc_asic->hpa + OFFSET_IMR))
  187. printk(" IMR is non-zero! (0x%x)",
  188. gsc_readl(gsc_asic->hpa + OFFSET_IMR));
  189. printk("\n");
  190. #endif
  191. return 0;
  192. }
  193. extern struct parisc_driver lasi_driver;
  194. extern struct parisc_driver asp_driver;
  195. extern struct parisc_driver wax_driver;
  196. void __init gsc_init(void)
  197. {
  198. #ifdef CONFIG_GSC_LASI
  199. register_parisc_driver(&lasi_driver);
  200. register_parisc_driver(&asp_driver);
  201. #endif
  202. #ifdef CONFIG_GSC_WAX
  203. register_parisc_driver(&wax_driver);
  204. #endif
  205. }