Linux kernel-driven registration how to talk

Source: Internet
Author: User

There are several ways to register Linux drivers, usually in the form of a kernel-provided characterization data structure encapsulated by the interface functions provided by the kernel subsystem, and some are more complex to maintain in a linked list. The following are several ways to register the driver registration:

First, the subsystem has a special driver registration function:

For example, the RTC subsystem provides RTC_DEVICE_REGISTER registration interface functions.

For example:

Rtc_device_register (Client->name,&client->dev, &rx8025_rtc_ops, this_module);

static struct Rtc_class_ops rx8025_rtc_ops= {

. Read_time= Rx8025_get_time,

. Set_time= Rx8025_set_time,

. read_alarm= Rx8025_read_alarm,

. set_alarm= Rx8025_set_alarm,

. alarm_irq_enable= Rx8025_alarm_irq_enable,

};

The main implementation of Rtc_class_ops. Using the RTC interface Rtc_device_register, registered to the RTC subsystem, controlled by the RTC subsystem, including device creation, proc and sys file system attribute creation. You can use the functions in the RTC Subsystem interface file INTERFACE.C.

In addition the network port type driver also has a specialized interface:

Register_netdev (Ndev);

After registering the network port is managed by the kernel.

Second, there is no special driver registration function

This type of driver registration is straightforward and follows the generic character-driven function. such as the watchdog class driver. Registered with the Misc type driver.

For example:

Misc_register (&rc32434_wdt_miscdev);

static const struct FILE_OPERATIONSRC32434_WDT_FOPS = {

. Owner = This_module,

. Llseek = No_llseek,

. write = Rc32434_wdt_write,

. Unlocked_ioctl = Rc32434_wdt_ioctl,

. open = Rc32434_wdt_open,

. Release = Rc32434_wdt_release,

};

Implement a watchdog-owned interface.

Three, complex drive

This type of driver has a special option in the kernel configuration, once this option is selected, the relevant system module initialization is performed after the kernel boots, maintaining a linked list, and the specific driver is to add members to the list, and the system module will detect the new member join and complete join to the subsystem processing work.

For example, PCI:

The PCI subsystem starts the BIOS at the time of registration:

Subsys_initcall (Pcibios_init);

Where Subsys_initcall is called when the kernel is initialized.

About Subsys_initcall Definitions:

#define Pure_initcall (FN) __define_initcall ("0", fn,0)

#define Core_initcall (FN) __define_initcall ("1", fn,1)

#define CORE_INITCALL_SYNC (FN) __define_initcall ("1s", fn,1s)

#define Postcore_initcall (FN) __define_initcall ("2", fn,2)

#definepostcore_initcall_sync (FN) __define_initcall ("2s", fn,2s)

#define Arch_initcall (FN) __define_initcall ("3", fn,3)

#define ARCH_INITCALL_SYNC (FN) __define_initcall ("3s", fn,3s)

#define Subsys_initcall (FN) __define_initcall ("4", fn,4)

#define SUBSYS_INITCALL_SYNC (FN) __define_initcall ("4s", fn,4s)

#define Fs_initcall (FN) __define_initcall ("5", fn,5)

#define FS_INITCALL_SYNC (FN) __define_initcall ("5s", fn,5s)

#define Rootfs_initcall (FN) __define_initcall ("Rootfs", Fn,rootfs)

#define Device_initcall (FN) __define_initcall ("6", fn,6)

#define DEVICE_INITCALL_SYNC (FN) __define_initcall ("6s", fn,6s)

#define Late_initcall (FN) __define_initcall ("7", fn,7)

#define LATE_INITCALL_SYNC (FN) __define_initcall ("7s", fn,7s)

There is a paragraph in the link script vmlinux.lds:


The location of each segment in the kernel file:


When the kernel is configured to select the PCI bus subsystem, Subsys_initcall (pcibios_init) is executed when the kernel is booted;

The module maintains a global variable hose_list. and managed in a chain-list management way, once the list has new members added, it is processed using the PCI subsystem, including scanning, probing, and so on.

The main task of this approach is to add members to the Hose_list list and then use the PCI subsystem. In PowerPC, for example, the PCI process is as follows:


The CPU initializes the arch important module after the kernel is booted, where a PCI bridge is added, the bridge resolves the PCI controller resource for the PowerPC and assigns a controller director, and then adds it to the Hose_list list. Complete the registration process.

While the pci_32.c file is for the management of Bois, which manages the hose_list linked list, manages the addition of members. When a member is registered, it is processed using the PCI subsystem.

Similar to the Rapdiio drive:

The RapidIO system is also a PCI-like approach, and the system will start the RapidIO subsystem when the kernel is configured with RapidIO selected.

In the RIO.C:

int __devinit rio_init_mports (void)

{

struct Rio_mport *port;

List_for_each_entry (port,&rio_mports, node) {

if (Port->host_deviceid >= 0)

Rio_enum_mport (port);

Else

Rio_disc_mport (port);

}

Rio_init ();

return 0;

}

Device_initcall_sync (Rio_init_mports);

Where Device_initcall_sync is the initialization section mentioned above.

#define DEVICE_INITCALL_SYNC (FN) __define_initcall ("6s", fn,6s)

The condition for performing this initialization of the RapidIO subsystem is that the kernel has the relevant configuration.

Take PowerPC as an example, the following is the process of adding to the RapidIO subsystem:


Among them, RIO.C maintains the rio-mports linked list, detects whether a new member is registered in, once a new member is registered to be added to the RapidIO subsystem for processing.

And the fsl_rio.c file has subsys_initcall initialization, complete the Rapdidio driver registration, this part of the work is also the kernel configuration can be completed. After registration, the resources on PowerPC are parsed and added mport to the rio-mports linked list. Complete the registration.

The registration process for RapidIO is of the same type as the PCI registration process. is the kernel in the configuration when the relevant support startup subsystem is selected, the subsystem initiates the work of a chain list detection. The specific driver needs to add members to the list.


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.