RE: Device driver registration problem

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

 



Title: RE: Device driver registration problem

try using alloc_chrdev_region,,

-Vamsi



-----Original Message-----
From: kernelnewbies-bounce@xxxxxxxxxxxx on behalf of Ivan Korzakow
Sent: Mon 4/3/2006 2:40 PM
To: kernelnewbies@xxxxxxxxxxxx
Subject: Device driver registration problem

Hi,

I've been unable to solve this problem, so if anyone has an idea, I'll
be really happy to have some hints ! Here is the issue :

I'm writing a device driver which is made of two layers : the
"generic" part containing all the file operations and other
initialization stuff, and a "specific" part (depending on the
hardware) which is a module that register into the generic layer at
init time. Here is a part of that registration function (you can
register several devices at a time) :

int register(struct params *some_params)
{
        int i, result = 0;
        struct device_descr *my_device;

        /* allocate minor numbers for the device */
        result = register_chrdev_region(MKDEV(MY_MAJOR,some_params->from),
                                        some_params->number, "my_driver");
        if (result) {
                printk(KERN_ERR \
                       "Device number registration failed\n");
                goto out;
        }

        /* Create and initialize the device structures */
        for(i = some_params->from ; i <=  some_params->to; i++) {
                my_device = (struct device_descr *) \
                    kzalloc(sizeof(struct device_descr), GFP_KERNEL);
                if (!my_device) {
                        result = -ENOMEM;
                        goto out;
                }
                /* Initialize the devices */
                [...]

                init_device(my_device);
        }
out:
        return resutl;
}

and in the init_device function, I'm doing :

static void init_device(struct device_descr *dev)
{
        int err = 0;
        dev_t devno = MKDEV(MY_MAJOR, dev->devnum);

        /* Register cdev */
        cdev_init(&dev->my_cdev, &my_fops);
        err = kobject_set_name(&dev->my_cdev.kobj, dev->name);
        if (err)
                goto err;

        dev->my_cdev.owner = THIS_MODULE;
        dev->my_cdev.ops = &sci_fops;
        err = cdev_add(&dev->myi_cdev, devno, 1);
        if (err)
                goto err;
        else
                return;
       
 err:
        printk(KERN_ERR "Error %d while adding %s", err, dev->name);
}

After this (long) introduction, my problem : when i am registering
several devices, only device 0 is working, that is to say, when
opening /dev/my_device0, the open function of my driver is called. But
for all the other device numbers, I get the error "No such device or
address".

I really don't see where the problem comes from. I checked with the
debugger that the initialization is ok for each device.
Is it problematic that I call register_chrdev_region and cdev_add not
during module_init but after ?

Thanks in advance for any idea,

Ivan

--
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