Workflow of the driver module

Source: Internet
Author: User
Driver module workflow-general Linux technology-Linux programming and kernel information, the following is a detailed description. The workflow of the driver module is divided into four parts:

1. insmod module
2. initialize the driver module (after initialization, it enters the "Latent" State until there is a system call)
3. When a device is operated, that is, when a system call is made, various service functions provided by the driver module are called.
4. rmmod module

I. Driver Loading
The Linux driver can be directly compiled into the kernel, compiled into a module, and loaded manually when the driver module is required.

When using insmod to load a module, you can also provide module parameters, such:
Static char * whom = "world ";
Static int howmany = 10;
Module_param (howmany, int, S_IRUGO );
Module_param (whom, charp, S_IRUGO );

In this way, when the driver is loaded using commands such as insmod scull. ko whom = "string" howmany = 20, the values of whom and howmay will be passed into the scull driver module.

Ii. initialization of the driver module
The scull_init_module function mainly performs the following tasks:

A) Allocate and register the Primary and Secondary device numbers.

Int register_chrdev_region (dev_t first, unsigned int count, char * name)
Int alloc_chrdev_region (dev_t * dev, unsigned int firstminor, unsigned int count, char * name)

B) initialize the struct representing the device: scull_dev

C) initialize the mutex init_MUTEX.

D) initialize the cdev struct of the device in the kernel. It is mainly used to associate the device with the file_operations struct. In the Linux kernel, The cdev struct represents a device. Before the kernel calls open and read operations on devices, it is necessary to allocate and register one or more cdev structures.

Iii. device operations
Involves open, close ioclt, release, and other functions.

Iv. Uninstall
Scull_cleanup_module
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.