Advertisement
Guest User

irq_test

a guest
Mar 30th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.40 KB | None | 0 0
  1. #include <linux/init.h>
  2. #include <linux/kernel.h>
  3. #include <linux/module.h>
  4. #include <linux/version.h>
  5. #include <linux/kallsyms.h>
  6.  
  7. #include <linux/interrupt.h>
  8.  
  9. MODULE_LICENSE( "GPL" );
  10.  
  11. static irqreturn_t
  12. dummy_irq_handler( int irq, void *dev_id )
  13. {
  14.    return IRQ_HANDLED;
  15. }
  16.  
  17. static int
  18. check_name( void *data, const char *namebuf, struct module *stub, unsigned long addr )
  19. {
  20.    if ( !strcmp( ( char *) data, namebuf ) ) {
  21.       return addr;
  22.    }
  23.    return 0;
  24. }
  25.  
  26. #if LINUX_VERSION_CODE < KERNEL_VERSION( 2, 6, 36 )
  27. static void noop( uint irq )
  28. {
  29. }
  30.  
  31. static uint noop_ret( uint irq )
  32. {
  33.    return 0;
  34. }
  35.  
  36. struct irq_chip tst_irq_chip = {
  37.    .name         = "tst_dummy",
  38.    .startup      = noop_ret,
  39.    .shutdown      = noop,
  40.    .enable         = noop,
  41.    .disable      = noop,
  42.    
  43.    .ack         = noop,
  44.    .mask         = noop,
  45.    .mask_ack      = noop,
  46.    .unmask         = noop,
  47.    .eoi         = noop,
  48.    
  49.    .end         = noop,
  50.    //.set_affinity   = noop,
  51.    //.retrigger      = noop,
  52.    //.set_type       = noop,
  53.    //.set_wake       = noop,
  54. };
  55. #else
  56. static void noop( struct irq_data *data )
  57. {
  58. }
  59.  
  60. static uint noop_ret( struct irq_data *data )
  61. {
  62.    return 0;
  63. }
  64.  
  65. struct irq_chip tst_irq_chip = {
  66.    .name         = "tst_dummy",
  67.    .irq_startup      = noop_ret,
  68.    .irq_shutdown      = noop,
  69.    .irq_enable         = noop,
  70.    .irq_disable      = noop,
  71.    
  72.    .irq_ack         = noop,
  73.    .irq_mask         = noop,
  74.    .irq_unmask         = noop,
  75.    
  76.    //.irq_end         = noop,
  77.    //.set_affinity   = noop,
  78.    //.retrigger      = noop,
  79.    //.set_type       = noop,
  80.    //.set_wake       = noop,
  81. };
  82.  
  83. #define set_irq_chip irq_set_chip
  84.  
  85. #endif
  86.  
  87.  
  88. static int __init
  89. mod_init( void )
  90. {
  91.    int irq;
  92.    int r = 0;
  93.    int (*test_can_request_irq)( unsigned int irq, unsigned long irqflags );
  94.    
  95.    test_can_request_irq = ( void * ) kallsyms_on_each_symbol( check_name, "can_request_irq" );
  96.    if ( !test_can_request_irq ) {
  97.       pr_err( "Can't get access to function can_request_irq.\n" );
  98.       for_each_irq_nr( irq ) {
  99.          r = request_irq( irq, dummy_irq_handler, 0, NULL, NULL );
  100.          if ( -ENOSYS == r ) {
  101.             set_irq_chip( irq, &tst_irq_chip );
  102.             r = request_irq( irq, dummy_irq_handler, 0, 0, 0 );
  103.          }
  104.          if ( r ) {
  105.             const char *reason = NULL;
  106.            
  107.             switch ( r ) {
  108.                case -EBUSY:
  109.                   reason = "EBUSY";
  110.                   break;
  111.                case -ENOSYS:
  112.                   reason = "ENOSYS";
  113.                   break;
  114.                case -EINVAL:
  115.                   reason = "EINVAL";
  116.                   break;
  117.                default:
  118.                   reason = "UNKNOWN";
  119.                   break;
  120.             }
  121.             pr_info( "IRQ_TEST: IRQ:%d FAIL CODE:%d REASON:%s\n", irq, r, reason );
  122.          } else {
  123.             pr_info( "IRQ_TEST: IRQ:%d SUCCESS\n", irq );
  124.             set_irq_chip( irq, NULL );
  125.             free_irq( irq, NULL );
  126.          }
  127.       }
  128.    } else {
  129.       for_each_irq_nr( irq ) {
  130.          r = test_can_request_irq( irq, 0 );
  131.          if ( r ) {
  132.             pr_info( "IRQ_TEST: IRQ:%d SUCCESS\n", irq );
  133.          } else {
  134.             pr_info( "IRQ_TEST: IRQ:%d FAIL\n", irq );
  135.          }
  136.       }
  137.    }
  138.    
  139.    return 0;
  140. }
  141.  
  142. static void __exit
  143. mod_exit( void )
  144. {
  145. }
  146.  
  147. module_init( mod_init );
  148. module_exit( mod_exit );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement