LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 10-20-2011, 05:17 AM   #1
humph
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Rep: Reputation: Disabled
Module Issue


Hi guys. I'm currently trying to test the interrupt line on a PowerPC device. To do this I am creating a module that does a simple printk when the Interrupt is triggered. It cross-compiles without any errors or warnings but the problem I'm encountering is that when I try to do an insmod on the target device there is an error that prevents the module from being loaded. The code for the module is:

Code:
//int_test.c

#include <linux/kernel.h>               
#include <linux/module.h>
#include <linux/irq.h>
#include <linux/interrupt.h>




//static irqreturn_t irq_handler(int irq, void *dev_id)
irqreturn_t irq_handler(int irq, void *dev_id)
{
   printk("IRQ5 triggered\n");
   return IRQ_HANDLED;
}


int init_module()
{
	
	printk("testing\n");	
   return request_irq(5,   
              irq_handler,  
              IRQF_SHARED, 
              "tst_interrupt",NULL);
	printk("Set up IRQ5\n");
}

/* Cleanup */
void cleanup_module()
{
	free_irq(5, NULL);
}
The Makefile is simply:

Code:
obj-m  :=  int_test.o
When I run it I get the error:
Code:
[root@p1021mds /root]# insmod int_test.ko                                       
int_test: module license 'unspecified' taints kernel.                           
Disabling lock debugging due to kernel taint                                    
testing                                                                         
insmod: error inserting 'int_test.ko': -1 Invalid parameters
dmesg gives:

Code:
PHY: mdio@ffe24000:02 - Link is Up - 1000/Full                                  
testing                                                                         
int_test: module license 'unspecified' taints kernel.                           
Disabling lock debugging due to kernel taint                                    
testing
If anyone has come across this before or thinks they know what the cause might be I'd greatly appreciate the help. If I've left any information out just ask.

Thanks a lot.

EDIT: Forgot to mention that the kernel version is "3.0.4+ #14 SMP" on the target board.

Last edited by humph; 10-20-2011 at 05:22 AM.
 
Old 10-21-2011, 12:12 AM   #2
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Is the code getting compiled without any errors?
Quote:
Originally Posted by humph View Post
The Makefile is simply:
Code:
obj-m  :=  int_test.o
The Makefile of a kernel module usually contains:
Code:
obj-m += hello.o

all:
......make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
......make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Makefile is TAB sensitive. The red dots above need to be replaced
by a TAB.

For getting rid of the Kernel taint message, you need to add the following
to your code.
Code:
MODULE_LICENSE ("GPL");

Last edited by Aquarius_Girl; 10-21-2011 at 12:20 AM.
 
Old 10-21-2011, 04:04 AM   #3
humph
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thanks for the reply. The code is getting compiled error free and with regards to the make file I've omitted that and just enter the Linux directory in the terminal. Found that the reason insmod was not loading the module was due to request_irq() returning an error value and not 0. Apparently one of the parameters is invalid so I'm not trying to hunt down the source code for request_irq() to work out exactly what is going on.
 
Old 10-21-2011, 04:10 AM   #4
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by humph View Post
Found that the reason insmod was not loading the module was due to request_irq() returning an error value and not 0.
How did you find that request_irq is not returning 0?
AFAIK, for "executing" a kernel module, one has to "insmod" it.
Am I missing a point here?
 
Old 10-21-2011, 07:14 AM   #5
humph
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
I changed the hi.c code to:

Quote:
static int hi(void)
{
/*printk(KERN_INFO "Hello from hi module.\n");
printk(KERN_INFO "The user space process is '%s'\n", current->comm);
printk(KERN_INFO "The user space PID is %i\n", current->pid);
return 0; // to show a successful load*/
printk("Setting up IRQ5\n");
int error;


struct device dev;


error = request_irq(5,
irq_handl,
0,
"Int Test",&dev);

if(error == 0){
printk("0 error returned\n");
return 0;
}
else{
printk("%d\n",error);
return 0;
}
}

static void bye(void)
{
printk(KERN_INFO "Goodbye from hi module.\n");
}

module_init(hi);
module_exit(bye);

MODULE_AUTHOR("Robert P. J. Day");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_VERSION("2:1.0") ;
MODULE_DESCRIPTION("You have to start somewhere.");
So now I can actually see what it is returning. The error number it returns is 22, or an invalid parameter. I am trying to track down where in the Kernel is actually returning this error. So far I know it goes to interrupt.h (http://lxr.free-electrons.com/source...a=powerpc#L129) as I inserted a printk at that point in the code. However I'm still unsuccessful in tracking where it goes after that.
 
Old 10-22-2011, 09:45 AM   #6
rulingminds
LQ Newbie
 
Registered: Sep 2011
Posts: 9

Rep: Reputation: Disabled
Problem is with the irq number. In case of Powerpc, the irq number should be mapped to a virtual irq and that will be passed to the request_irq(). Generally irq will be specified in the device tree and the function of_irq_to_resource() is called to get the virq for the irq that is taken from the device tree.
 
Old 10-24-2011, 04:40 AM   #7
humph
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thanks for the reply. That sounds pretty promising so I'll give it a go.
 
Old 10-25-2011, 08:46 AM   #8
humph
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hi everyone. I had a look through the kernel looking for some examples of virtual IRQs and from that edited my code to the following:
Code:
//IRQF_SHARED
#include <linux/module.h>       // for all modules
#include <linux/init.h>         // for entry/exit macros
#include <linux/kernel.h>       // for printk priority macros
#include <asm/current.h>        // process information, just for fun
#include <linux/sched.h>        // for "struct task_struct"
#include <linux/interrupt.h>
#include <linux/device.h>









static irqreturn_t irq_handl(int irq, void *dev_id)
{	
   printk("IRQ5 triggered\n");
   return IRQ_HANDLED;
}
 



static int hi(void)
{
        /*printk(KERN_INFO "Hello from hi module.\n");
        printk(KERN_INFO "The user space process is '%s'\n", current->comm);
        printk(KERN_INFO "The user space PID is  %i\n", current->pid);
        return 0;       // to show a successful load*/
	 printk("Setting up IRQ5\n");
	 int error;   
	
	struct device dev;
	int virq;
	unsigned long mapIRQ;
	
	mapIRQ = 5;
	
	virq = irq_create_mapping(NULL,mapIRQ);
 
	 
	      error = request_irq(virq,   
              irq_handl,  
              0, 
              "Int Test",&dev);

	if(error == 0){
		printk("0 error returned\n");		
		return 0;
	}
	else{
		printk("%d\n",error);
		return 0;
	}	
}

static void bye(void)
{
        printk(KERN_INFO "Goodbye from hi module.\n");
}

module_init(hi);
module_exit(bye);

MODULE_AUTHOR("Robert P. J. Day");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_VERSION("2:1.0") ;
MODULE_DESCRIPTION("You have to start somewhere.");
So it now compiles and returns what I'm expecting after performing an insmod:
Code:
Setting up IRQ5                                                                 
This is before calling the request threaded IRQ                                 
0 error returned
I verified that it had been registered by Linux through /proc/interrupts:
Code:
[root@p1021mds /root]# cat /proc/interrupts                                     
           CPU0       CPU1                                                      
 18:          8          0   OpenPIC   Level     phy_interrupt                  
 19:          0          0   OpenPIC   Level     fsl-lbc                        
 22:          0         30   OpenPIC   Level     eth1_g0_rx                     
 23:          0          0   OpenPIC   Edge      Int Test                       
 25:          0         28   OpenPIC   Level     eth1_g1_tx                     
 26:          0          0   OpenPIC   Level     eth1_g1_rx                     
 27:          0          0   OpenPIC   Level     eth1_g1_er                     
 28:         27          0   OpenPIC   Level     ehci_hcd:usb1                  
 31:          1          0   OpenPIC   Level     eth1_g0_tx                     
 33:          0          0   OpenPIC   Level     eth1_g0_er                     
 42:       1066          0   OpenPIC   Level     serial                         
 43:          0          0   OpenPIC   Level     i2c-mpc, i2c-mpc               
 45:          0          0   OpenPIC   Level     talitos                        
 72:          0          0   OpenPIC   Level     mmc0                           
251:          0          0   OpenPIC   Edge      ipi call function              
252:       1568       1887   OpenPIC   Edge      ipi reschedule                 
253:         28         14   OpenPIC   Edge      ipi call function single       
LOC:       2179       4191   Local timer interrupts                             
SPU:          1          0   Spurious interrupts                                
CNT:          0          0   Performance monitoring interrupts                  
MCE:          0          0   Machine check exceptions
However, when I'm testing the pin (by putting a pull-up button combination that asserts a low with a button press) I am not getting the "IRQ5 triggered" message. I was just wondering if anyone could verify that what I've done in my code is correct or, more than likely, wrong. Thanks a lot.
 
Old 10-26-2011, 07:53 AM   #9
humph
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
It turned out to be a problem in hardware and it's working now. Thanks for the help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] baffling perl module issue allied air Slackware 4 05-22-2011 07:28 PM
kernel module compilation issue daff_vadi Linux - Kernel 4 07-15-2010 05:52 AM
fglrx module issue zpr Linux - Laptop and Netbook 1 04-14-2009 11:54 PM
Iptables Module Issue aaf Linux - Security 4 01-04-2007 10:04 AM
e1000 module issue on kernel 2.6.10 blizzardtweaker Slackware 23 01-05-2005 06:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 04:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration