s390_ext.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:3k
源码类别:

嵌入式Linux

开发平台:

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. ext_int_info_t ext_int_info_timer;
  23. ext_int_info_t ext_int_info_hwc;
  24. ext_int_info_t ext_int_pfault;
  25. int register_external_interrupt(__u16 code, ext_int_handler_t handler) {
  26.         ext_int_info_t *p;
  27.         int index;
  28.         index = code & 0xff;
  29.         p = ext_int_hash[index];
  30.         while (p != NULL) {
  31.                 if (p->code == code)
  32.                         return -EBUSY;
  33.                 p = p->next;
  34.         }
  35.         if (code == 0x1004) /* time_init is done before kmalloc works :-/ */
  36.                 p = &ext_int_info_timer;
  37.         else if (code == 0x2401) /* hwc_init is done too early too */
  38.                 p = &ext_int_info_hwc;
  39.         else if (code == 0x2603) /* pfault_init is done too early too */
  40. p = &ext_int_pfault;
  41. else
  42.                 p = (ext_int_info_t *)
  43.                           kmalloc(sizeof(ext_int_info_t), GFP_ATOMIC);
  44.         if (p == NULL)
  45.                 return -ENOMEM;
  46.         p->code = code;
  47.         p->handler = handler;
  48.         p->next = ext_int_hash[index];
  49.         ext_int_hash[index] = p;
  50.         return 0;
  51. }
  52. int unregister_external_interrupt(__u16 code, ext_int_handler_t handler) {
  53.         ext_int_info_t *p, *q;
  54.         int index;
  55.         index = code & 0xff;
  56.         q = NULL;
  57.         p = ext_int_hash[index];
  58.         while (p != NULL) {
  59.                 if (p->code == code && p->handler == handler)
  60.                         break;
  61.                 q = p;
  62.                 p = p->next;
  63.         }
  64.         if (p == NULL)
  65.                 return -ENOENT;
  66.         if (q != NULL)
  67.                 q->next = p->next;
  68.         else
  69.                 ext_int_hash[index] = p->next;
  70.         if (code != 0x1004 && code != 0x2401 && code != 0x2603)
  71.                 kfree(p);
  72.         return 0;
  73. }
  74. EXPORT_SYMBOL(register_external_interrupt);
  75. EXPORT_SYMBOL(unregister_external_interrupt);