Linux misc devices and character devices

Source: Internet
Author: User

Tag: member function by character command height file nod avoid member

.1 introduction of miscellaneous device drivers

A character device is a device that must be sequentially accessed in serial order, without a system-fast buffer, to understand the framework and composition of the drive in the Linux kernel, as well as the steps to be written. However, when we write more drivers, we will find that: some of the hardware does not conform to the category of pre-defined character devices, and the ordinary character device's main device number, whether static or dynamic allocation, will consume a master device number (currently a system can only have up to 255 character devices), Compare wasted master device number resources. As a result, miscellaneous device drivers are introduced.

The miscellaneous device is a typical character device (like the input subsystem to be introduced next, hehe), with the main device number fixed at 10. Its internal implementation is implemented by calling Register_chrdev () with the main device number 10来, and internally calls Class_create () and Device_create () to create a device node for each miscellaneous device. This avoids the hassle of creating a device node with the Mknod command or by invoking the two function itself.

From this point on, miscellaneous devices are re-encapsulation of the drivers we normally write character devices, reducing the difficulty of writing character device drivers while saving the main device number resources.

.3 Miscellaneous device and character device implementation comparison

In the process of developing character device drivers, our implementation steps are as follows:

Request a character device number: You can specify it, or the system can be automatically assigned;

Constructs a file_operations structure, which contains all the operations on the hardware;

Implement the member functions in the file_operations structure;

Registering the character device into the system: Register_chrdev ();

Create device class and device node: Class_create (), device_create ();

Tell the kernel entry and exit functions: Module_init (), Module_exit ();

Miscellaneous device drivers are also character device drivers, so the process of registering with the character device driver, it must also go through the above steps, but the miscellaneous device driver in the application of the character device number, registration character device to system, create device class and device node is encapsulated, we only need to complete the following steps to develop:

Constructs a file_operations structure, which contains all the operations on the hardware;

Implement the member functions in the file_operations structure;

Constructs a miscellaneous device-driven (struct-miscdevice) entity and assigns values to the File_operations entities previously defined;

Call Misc_register () at the entry function to register miscellaneous devices with the system;

Call Misc_deregister () at the Exit function to unregister the miscellaneous device from the system;

Tell the kernel entry and exit functions: Module_init (), Module_exit ();

It is also possible to draw a conclusion: no matter how well the Linux kernel is designed to drive the framework, how much code the kernel implements, the code that is relevant to the hardware needs to be implemented.

Linux misc devices and character devices

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.