s390_ext.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * arch/s390/kernel/s390_ext.c
  3. *
  4. * S390 version
  5. * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Holger Smolinski (Holger.Smolinski@de.ibm.com),
  7. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  8. */
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/slab.h>
  12. #include <linux/errno.h>
  13. #include <linux/kernel_stat.h>
  14. #include <linux/interrupt.h>
  15. #include <asm/cpu.h>
  16. #include <asm/lowcore.h>
  17. #include <asm/s390_ext.h>
  18. #include <asm/irq_regs.h>
  19. #include <asm/irq.h>
  20. #include "entry.h"
  21. /*
  22. * ext_int_hash[index] is the start of the list for all external interrupts
  23. * that hash to this index. With the current set of external interrupts
  24. * (0x1202 external call, 0x1004 cpu timer, 0x2401 hwc console, 0x4000
  25. * iucv and 0x2603 pfault) this is always the first element.
  26. */
  27. ext_int_info_t *ext_int_hash[256] = { NULL, };
  28. static inline int ext_hash(__u16 code)
  29. {
  30. return (code + (code >> 9)) & 0xff;
  31. }
  32. int register_external_interrupt(__u16 code, ext_int_handler_t handler)
  33. {
  34. ext_int_info_t *p;
  35. int index;
  36. p = kmalloc(sizeof(ext_int_info_t), GFP_ATOMIC);
  37. if (p == NULL)
  38. return -ENOMEM;
  39. p->code = code;
  40. p->handler = handler;
  41. index = ext_hash(code);
  42. p->next = ext_int_hash[index];
  43. ext_int_hash[index] = p;
  44. return 0;
  45. }
  46. int register_early_external_interrupt(__u16 code, ext_int_handler_t handler,
  47. ext_int_info_t *p)
  48. {
  49. int index;
  50. if (p == NULL)
  51. return -EINVAL;
  52. p->code = code;
  53. p->handler = handler;
  54. index = ext_hash(code);
  55. p->next = ext_int_hash[index];
  56. ext_int_hash[index] = p;
  57. return 0;
  58. }
  59. int unregister_external_interrupt(__u16 code, ext_int_handler_t handler)
  60. {
  61. ext_int_info_t *p, *q;
  62. int index;
  63. index = ext_hash(code);
  64. q = NULL;
  65. p = ext_int_hash[index];
  66. while (p != NULL) {
  67. if (p->code == code && p->handler == handler)
  68. break;
  69. q = p;
  70. p = p->next;
  71. }
  72. if (p == NULL)
  73. return -ENOENT;
  74. if (q != NULL)
  75. q->next = p->next;
  76. else
  77. ext_int_hash[index] = p->next;
  78. kfree(p);
  79. return 0;
  80. }
  81. int unregister_early_external_interrupt(__u16 code, ext_int_handler_t handler,
  82. ext_int_info_t *p)
  83. {
  84. ext_int_info_t *q;
  85. int index;
  86. if (p == NULL || p->code != code || p->handler != handler)
  87. return -EINVAL;
  88. index = ext_hash(code);
  89. q = ext_int_hash[index];
  90. if (p != q) {
  91. while (q != NULL) {
  92. if (q->next == p)
  93. break;
  94. q = q->next;
  95. }
  96. if (q == NULL)
  97. return -ENOENT;
  98. q->next = p->next;
  99. } else
  100. ext_int_hash[index] = p->next;
  101. return 0;
  102. }
  103. void do_extint(struct pt_regs *regs, unsigned short code)
  104. {
  105. ext_int_info_t *p;
  106. int index;
  107. struct pt_regs *old_regs;
  108. old_regs = set_irq_regs(regs);
  109. s390_idle_check();
  110. irq_enter();
  111. if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
  112. /* Serve timer interrupts first. */
  113. clock_comparator_work();
  114. kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++;
  115. index = ext_hash(code);
  116. for (p = ext_int_hash[index]; p; p = p->next) {
  117. if (likely(p->code == code))
  118. p->handler(code);
  119. }
  120. irq_exit();
  121. set_irq_regs(old_regs);
  122. }
  123. EXPORT_SYMBOL(register_external_interrupt);
  124. EXPORT_SYMBOL(unregister_external_interrupt);