Linux Device Driver Q&A
Linux Device Driver Q&A
who calls the Probe function for Driver?
The starting trigger function for the
driver->probe()
callback is themodule_init()
macro called while loading the driver; thismacro
is defined ininclude/linux/module.h
.module_init(my_driver_init)
has the callback tomy_driver_init()
function.my_driver_init()
function should have a call toplatform_driver_register(my_driver)
platform_driver_register(my_driver)
assignsmy_driver -> probe()
handle to genericdrv -> probe()
and calls thedriver_register(my_driver)
function.driver_register(my_driver)
function addsmy_driver
to the platform bus and callsdriver_attach()
function.In the same way, even the
platform_device
needs to attach to the platform bus.Finally, only if the
driver_match_device()
returns success based on the.name
&.id_table
of thedriver
matches in the platform devices list that comes either fromACPI/DTS
, then thedriver_probe_device()
gets called that has thedrv->probe()
callback.
what is segmentation fault:
You cannot access nonexistent memory in your address space. This will cause a segmentation fault.Page Fault:
If you access unmapped memory, the CPU raises a page fault and the OS handles itPgae:
Memory page, virtual page, or simply page are terms you use to refer to a fixed length contiguous block of virtual memory.
Frame:
Frame refers to a fixed-length contiguous block of physical memory on top of which the operating system maps a memory page
- In How Many Ways We Can Allocate Device Number?
- How Can We Allocate Device Number Statically?
int register_chrdev_region(dev_t first, unsigned int count, char *name);
Here;
first is the beginning device number of the range you would like to allocate. The minor number portion of first is often 0.
count is the total number of contiguous device numbers you are requesting.
name is the name of the device that should be associated with this number range. it will appear in /proc/devices and sysfs.
- How Can We Allocate Device Number Dynamically ?
int alloc_chrdev_region(dev_t *dev, unsigned int firstminor, unsigned int count, char *name);
Here:
dev is an output-only parameter that will, on successful completion, hold the first number in your allocated range.
firstminor should be the requested first minor number to use; it is usually 0
count is the total number of contiguous device numbers you are requesting.
- How Can We Free Device Numbers ?
void unregister_chrdev_region(dev_t first, unsigned int count);
- What Is Major Number And It's Usage ?
The major number tells you which driver handles which device file.
- Can We Have Same Major Number For More Than One Device File ?
- What Is Minor Number And It's Usage ?
The minor number is used only by the driver itself to differentiate which device it's operating on, just in case the driver handles more than one device.
(or)
one driver can control more than one device .minor will be used to distinguish the one device from other devices
- What Is Range Of Major And Minor Numbers?
- What Is Use Of Dev_t Type ?
- How To Retrieve Major And Minor Number From Dev_t Type ?
MAJOR(dev_t dev); // to obtain major number
MINOR(dev_t dev); // to obtain minor number
int major=MAJOR(dev_t dev);
int minor =MINOR(dev_t dev);
- How Can I Use My Own Major And Minor Number For A Device File ?
Answer :
register_chrdev_region works well if you know ahead of time exactly which device numbers you want. Often, however, you will not know which major numbers your device will use; there is a constant effort within the Linux kernel development community to move over to the use of dynamically-allocated device numbers.
- How To See Statically Assigned Major Numbers ?
Some major device numbers are statically assigned to the most common devices. A list of those devices can be found in Documentation/devices.txt within the kernel source tree
- What Is The Disadvantage Of Dynamic Device Number Assignment ?
The disadvantage of dynamic assignment is that you can't create the device nodes in advance, because the major number assigned to your module will vary.
- Where Can We Write Allocation And Freeing Of Device Number's Code ?
allocation : init function of a module
freeing : cleanup function of a module
Comments
Post a Comment