gsc.c 5.6 KB

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