LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2009, 02:50 AM   #1
Devika99
LQ Newbie
 
Registered: Aug 2008
Posts: 20

Rep: Reputation: 0
lodable kernel module doubt...


I had written a driver and it was working fine on FC11...

Then i tried that program on FC8 and observed that it hangs/crashes sometime after insertng the module (insmod) OR
at times after removing the module and again trying to insert the module...

Not sure what is wrong...the program or something else...

Can any1 plz help me??
 
Old 12-07-2009, 03:01 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
Why don't u put some code for display ? It may be possible for someone to help u after that !!
 
Old 12-07-2009, 03:10 AM   #3
Devika99
LQ Newbie
 
Registered: Aug 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Here's the program...
// PCI driver

#define OUR_PCI_VENDER_ID 0x10b5
#define OUR_PCI_DEVICE_ID 0x9054

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/stat.h>
#include <linux/slab.h>
#include <asm/system.h>
#include <asm/io.h>
#include <linux/types.h>


Quote:
struct pci_card_driver {
void *mm_addr;
struct pci_dev *ppdev;
};

static struct pci_device_id our_pci_id_tb[] = {
{ OUR_PCI_VENDER_ID, OUR_PCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
},
{ 0, }
};
MODULE_DEVICE_TABLE (pci, our_pci_id_tb);
Quote:
static int init_module_probe(struct pci_dev *pdev, const struct pci_device_id *notused)
{
struct pci_card_driver *pci_ptr;
unsigned long mmio_start, mmio_end, mmio_len, mmio_flags, data, data1, data2, data3, data4, data_out, data5, k1;
int err;
u32 val;

pci_ptr = kmalloc(sizeof(*pci_ptr), GFP_KERNEL);
if (!pci_ptr)
return -ENOMEM;
memset(pci_ptr,0,sizeof(*pci_ptr));
pci_ptr ->ppdev =pdev;

err=pci_enable_device(pdev);
if(err)
{
printk(KERN_ERR "err: Cannot enable the device \n");
goto error;
}

else printk("Device enabled\n");

mmio_start = pci_resource_start(pdev, 2);
mmio_end = pci_resource_end(pdev, 2);
mmio_len = pci_resource_len(pdev, 2);
mmio_flags = pci_resource_flags(pdev, 2);

if(pci_request_regions(pdev, "pci_device"))
{
printk("Could not get PCI region\n");
err= -EBUSY;
goto err_disable;
}

pci_ptr ->mm_addr = NULL;

pci_set_drvdata(pdev,pci_ptr);

pci_ptr ->mm_addr = ioremap(mmio_start, mmio_len);

if(!(pci_ptr->mm_addr))
{
printk("Could not ioremap\n");
err= -EIO;
goto err_release_mem;
}

else
{
printk(" The ioaddr is %x \n", pci_ptr -> mm_addr);
printk(" ioaddress obtained \n");

val= readl(pci_ptr->mm_addr + 0x0000100C);
printk(" My value obtained is %u32 \n ", val);

return 0;

}

err_release_mem:
pci_release_regions(pdev);
pci_set_drvdata(pdev, NULL);
err_disable:
pci_disable_device(pdev);
error:
kfree(pci_ptr);
return err;
}
Quote:
static void __devexit remove_pci(struct pci_dev *pdev)
{
struct pci_card_driver *pci_ptr = pci_get_drvdata(pdev);
if (!pci_ptr)
{
printk("<1> sum BUG error");
BUG();
}
iounmap(pci_ptr->mm_addr);
pci_release_regions(pdev);
pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL);
kfree(pci_ptr);
}
Quote:
static struct pci_driver our_pci_driver = {
.name = "pci_device",
.probe = init_module_probe,
.remove = __devexit_p(remove_pci),
.id_table = our_pci_id_tb,
};
Quote:
static int __init pci_init(void)
{
printk(KERN_INFO "pci device_init\n");
return pci_register_driver(&our_pci_driver);
}


static void __exit pci_cleanup(void)
{
printk(KERN_INFO "pci device_cleanup\n");
pci_unregister_driver(&our_pci_driver);
}

module_init(pci_init);
module_exit(pci_cleanup);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Linux device driver for PCI card");

Last edited by Devika99; 12-07-2009 at 03:20 AM.
 
1 members found this post helpful.
Old 12-07-2009, 03:14 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
Does dmesg say anything special ? and it will be better if u edit u r post and put your code in the CODE tags !

Last edited by Aquarius_Girl; 12-07-2009 at 03:16 AM.
 
Old 12-07-2009, 03:18 AM   #5
Devika99
LQ Newbie
 
Registered: Aug 2008
Posts: 20

Original Poster
Rep: Reputation: 0
nop... nothng...it shows that the device has been initialized after insmod... and if i remove the module ,then it shows that module is exited....but after the thing crashes(hangs), nothing works...only way to get out is to reset the PC...n after that i m back to square 1..
 
Old 12-07-2009, 03:25 AM   #6
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Till u don't get a perfect answer, What u can do is to comment out the code where u have allocated memory with kmalloc and see if that memory allocation was the cause of the hanging ?
 
Old 12-07-2009, 03:31 AM   #7
Devika99
LQ Newbie
 
Registered: Aug 2008
Posts: 20

Original Poster
Rep: Reputation: 0
But kmalloc worked perfectly fine when i used FC11....What can be the probable reason for this...
 
Old 12-07-2009, 03:34 AM   #8
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Is there some big kernel version difference between fedora 8 and fedora 11 ? Ok I agree this is a dumb question, I shall get back to you if I could find something on this !

Last edited by Aquarius_Girl; 12-07-2009 at 03:37 AM.
 
Old 12-07-2009, 03:41 AM   #9
Devika99
LQ Newbie
 
Registered: Aug 2008
Posts: 20

Original Poster
Rep: Reputation: 0
i don't know... for FC8 was 2.6.xx... dont remember about which FC11 i had....
 
Old 12-07-2009, 04:35 AM   #10
Devika99
LQ Newbie
 
Registered: Aug 2008
Posts: 20

Original Poster
Rep: Reputation: 0
alright...thanks...
 
  


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
doubt related to module loading in kernel krap Linux - Kernel 9 07-12-2008 01:33 AM
Unable to insert lodable module pathak_ashish Linux - Newbie 1 01-13-2008 07:19 AM
ndiswrapper module doubt Milosevic Slackware 1 11-03-2007 01:44 PM
Lodable module support in Linux. drminix Linux - Software 2 08-14-2005 09:32 PM
kernel module ignorant newbie looking for any one with kernel module knowledge cpoet Slackware 4 11-24-2003 09:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:43 PM.

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