s390_ext.c 3.4 KB

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