Re: Associating driver to the existing device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2005-05-30 at 14:20 +0530, Vishal Linux wrote:
> Hi all, 
> 
> 
> I am trying to associate a driver to the '/dev/mem' device (the major
> no. and minor no. of device is 1,1.)
> 
> [vishal@vishalsoni ~]$ ll /dev/mem
> crw-r----- 1 root kmem 1, 1 May 30 2005 /dev/mem
> 
> so that any read/write/mmap happening to this device.. gives control
> to my driver.
> I am able to Successfully register the device ( dmesg tells this) &
> below is the code for kernel 1.6 driver.
> 
> [vishal@vishalsoni ~]$ uname -a
> Linux vishalsoni 2.6.9-1.667 #1 Tue Nov 2 14:41:25 EST 2004 i686 i686
> i386 GNU/Linux
> 
> int LinuxTestMemDevice_init(void)
> {
> int rv = -1;
> int devno = MKDEV(1,1);
> struct cdev my_cdev;
> printk("Skelton Driver, version %s\n", DRIVER_VERSION);
> my_cdev.owner=THIS_MODULE;
> my_cdev.ops =&my_fops;
> rv = cdev_add(&my_cdev,devno,1);
> if(rv) {
> printk(" Error in registering the char device\n");
> return -1;
> }
> else {
> printk(" :------------- Succesfully registered the device -----------
> \n");
> printk(" : Major no. of device is :: %d\n",MAJOR(devno));
> printk(" : Minor no. of device is :: %d\n",MINOR(devno));
> }
> 
> return 0;
> }
> 
> Registration is successful.......
> Now when i try to do [vishal@vishalsoni ~]$ cat /dev/mem
> my implementation of open does not get called. 
> 
> As a test.. i have written, just one line code.
> 
> static int my_open(struct inode *imem, struct file *fmem)
> {
> printk(" INSIDE my_open ..................\n");
> return 1;
> }
> 
> Where am i going wrong !!!!!! Your inputs would be greatly appreciated

I think the "open" system call is going to the existing driver
loaded for this device. In order to get the kernel to call your
open method you can either unload the existing module...or if
it's built-in, then recompile the kernel without the existing
driver.

HTH,
-mandeep

> 
> 
> Thank you,
> Regards,
> Vishal.
> 
> 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux