s390_ext.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. * Simple hash strategy: index = code & 0xff;
  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] = { 0, };
  26. int register_external_interrupt(__u16 code, ext_int_handler_t handler)
  27. {
  28. ext_int_info_t *p;
  29. int index;
  30. p = (ext_int_info_t *) kmalloc(sizeof(ext_int_info_t), GFP_ATOMIC);
  31. if (p == NULL)
  32. return -ENOMEM;
  33. p->code = code;
  34. p->handler = handler;
  35. index = code & 0xff;
  36. p->next = ext_int_hash[index];
  37. ext_int_hash[index] = p;
  38. return 0;
  39. }
  40. int register_early_external_interrupt(__u16 code, ext_int_handler_t handler,
  41. ext_int_info_t *p)
  42. {
  43. int index;
  44. if (p == NULL)
  45. return -EINVAL;
  46. p->code = code;
  47. p->handler = handler;
  48. index = code & 0xff;
  49. p->next = ext_int_hash[index];
  50. ext_int_hash[index] = p;
  51. return 0;
  52. }
  53. int unregister_external_interrupt(__u16 code, ext_int_handler_t handler)
  54. {
  55. ext_int_info_t *p, *q;
  56. int index;
  57. index = code & 0xff;
  58. q = NULL;
  59. p = ext_int_hash[index];
  60. while (p != NULL) {
  61. if (p->code == code && p->handler == handler)
  62. break;
  63. q = p;
  64. p = p->next;
  65. }
  66. if (p == NULL)
  67. return -ENOENT;
  68. if (q != NULL)
  69. q->next = p->next;
  70. else
  71. ext_int_hash[index] = p->next;
  72. kfree(p);
  73. return 0;
  74. }
  75. int unregister_early_external_interrupt(__u16 code, ext_int_handler_t handler,
  76. ext_int_info_t *p)
  77. {
  78. ext_int_info_t *q;
  79. int index;
  80. if (p == NULL || p->code != code || p->handler != handler)
  81. return -EINVAL;
  82. index = code & 0xff;
  83. q = ext_int_hash[index];
  84. if (p != q) {
  85. while (q != NULL) {
  86. if (q->next == p)
  87. break;
  88. q = q->next;
  89. }
  90. if (q == NULL)
  91. return -ENOENT;
  92. q->next = p->next;
  93. } else
  94. ext_int_hash[index] = p->next;
  95. return 0;
  96. }
  97. void do_extint(struct pt_regs *regs, unsigned short code)
  98. {
  99. ext_int_info_t *p;
  100. int index;
  101. irq_enter();
  102. asm volatile ("mc 0,0");
  103. if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
  104. /**
  105. * Make sure that the i/o interrupt did not "overtake"
  106. * the last HZ timer interrupt.
  107. */
  108. account_ticks(regs);
  109. kstat_cpu(smp_processor_id()).irqs[EXTERNAL_INTERRUPT]++;
  110. index = code & 0xff;
  111. for (p = ext_int_hash[index]; p; p = p->next) {
  112. if (likely(p->code == code)) {
  113. if (likely(p->handler))
  114. p->handler(regs, code);
  115. }
  116. }
  117. irq_exit();
  118. }
  119. EXPORT_SYMBOL(register_external_interrupt);
  120. EXPORT_SYMBOL(unregister_external_interrupt);