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