s390_ext.c 3.4 KB

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