s390_ext.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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 <asm/lowcore.h>
  13. #include <asm/s390_ext.h>
  14. /*
  15.  * Simple hash strategy: index = code & 0xff;
  16.  * ext_int_hash[index] is the start of the list for all external interrupts
  17.  * that hash to this index. With the current set of external interrupts 
  18.  * (0x1202 external call, 0x1004 cpu timer, 0x2401 hwc console, 0x4000
  19.  * iucv and 0x2603 pfault) this is always the first element. 
  20.  */
  21. ext_int_info_t *ext_int_hash[256] = { 0, };
  22. int register_external_interrupt(__u16 code, ext_int_handler_t handler) {
  23.         ext_int_info_t *p;
  24.         int index;
  25. p = (ext_int_info_t *) kmalloc(sizeof(ext_int_info_t), GFP_ATOMIC);
  26.         if (p == NULL)
  27.                 return -ENOMEM;
  28.         p->code = code;
  29.         p->handler = handler;
  30.         index = code & 0xff;
  31.         p->next = ext_int_hash[index];
  32.         ext_int_hash[index] = p;
  33.         return 0;
  34. }
  35. int register_early_external_interrupt(__u16 code, ext_int_handler_t handler,
  36.       ext_int_info_t *p) {
  37.         int index;
  38.         if (p == NULL)
  39.                 return -EINVAL;
  40.         p->code = code;
  41.         p->handler = handler;
  42.         index = code & 0xff;
  43.         p->next = ext_int_hash[index];
  44.         ext_int_hash[index] = p;
  45.         return 0;
  46. }
  47. int unregister_external_interrupt(__u16 code, ext_int_handler_t handler) {
  48.         ext_int_info_t *p, *q;
  49.         int index;
  50.         index = code & 0xff;
  51.         q = NULL;
  52.         p = ext_int_hash[index];
  53.         while (p != NULL) {
  54.                 if (p->code == code && p->handler == handler)
  55.                         break;
  56.                 q = p;
  57.                 p = p->next;
  58.         }
  59.         if (p == NULL)
  60.                 return -ENOENT;
  61.         if (q != NULL)
  62.                 q->next = p->next;
  63.         else
  64.                 ext_int_hash[index] = p->next;
  65. kfree(p);
  66.         return 0;
  67. }
  68. int unregister_early_external_interrupt(__u16 code, ext_int_handler_t handler,
  69. ext_int_info_t *p) {
  70. ext_int_info_t *q;
  71. int index;
  72. if (p == NULL || p->code != code || p->handler != handler)
  73. return -EINVAL;
  74. index = code & 0xff;
  75. q = ext_int_hash[index];
  76. if (p != q) {
  77. while (q != NULL) {
  78. if (q->next == p)
  79. break;
  80. q = q->next;
  81. }
  82. if (q == NULL)
  83. return -ENOENT;
  84. q->next = p->next;
  85. } else
  86. ext_int_hash[index] = p->next;
  87. return 0;
  88. }
  89. EXPORT_SYMBOL(register_external_interrupt);
  90. EXPORT_SYMBOL(unregister_external_interrupt);