LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Multiple Device driver from single device driver???? (http://www.linuxquestions.org/questions/linux-kernel-70/multiple-device-driver-from-single-device-driver-635631/)

rickhg12hs 04-15-2008 09:28 PM

Multiple Device driver from single device driver????
 
Goal:

Use multiple PCI cards in a system when the provided device driver assumes only one card will be present.

Background:

A reference design provides a device driver for a mini-PCI card. This device driver spans several loadable kernel modules (addressing different logical portions of the hardware) and each kernel module has dozens of source files. The device driver was written assuming _only_ one card would be present in the system at a time resulting in hardware/driver "state" variables sprinkled throughout all the source files.

Solution?:

Obviously the device driver could be completely rewritten by aggregating all of the state variables into some sort of structure and then kmalloc'ing a number of them at kernel module load/init time (array or linked list, etc.). This looks to be rather hard (the state variables are everywhere and the chances of missing some are high) and tedious (> 100k LOC).

Is there another option by perhaps wrapping the device driver in a way to allow multiple cards?

Is there a smart _and_ lazy way to accomplish the goal?

shishir 05-14-2008 03:15 PM

You could load multiple instances of the same driver? using modprobe options like -o. you can see how it is done at this location which talks about bonding drivers : http://lwn.net/Articles/258538/

Hope this helped.

rickhg12hs 05-24-2008 10:37 PM

Linux kernel module global variables are all in one namespace, no?
 
Quote:

Originally Posted by shishir (Post 3153273)
You could load multiple instances of the same driver? using modprobe options like -o. you can see how it is done at this location which talks about bonding drivers : http://lwn.net/Articles/258538/

Since Linux has a monolithic kernel, won't all the non-static global variables clash when the second re-named module is loaded/linked?

How can this be prevented easily without a module rewrite?

shishir 05-25-2008 12:11 AM

The way it works is kernel gives each modules its own namespace, as long as you are not exporting symbols from the modules, you should be fine.


All times are GMT -5. The time now is 10:31 PM.