嵌入式linux中文站在线图书

Previous Page
Next Page

8.1. When a Device Is Registered

The registration of a network device takes place in the following situations:


Loading an NIC's device driver

An NIC's device driver is initialized at boot time if it is built into the kernel, and at runtime if it is loaded as a module. Whenever initialization occurs, all the NICs controlled by that driver are registered.


Inserting a hot-pluggable network device

When a user inserts a hot-pluggable NIC, the kernel notifies its driver, which then registers the device. (For the sake of simplicity, we'll assume the device driver is already loaded.)

In the first situation, the registration model that applies is described in the later section "Skeleton of NIC Registration and Unregistration." It applies to all bus types, and is the same whether the registration routine ends up being called by the bus infrastructure or by the module initialization code. For example, we saw in Chapter 6 how loading a PCI device driver leads to the execution of the pci_driver->probe routine, usually named something like xxx_probe, which is provided by the driver and which takes care of device registration. In this chapter, we will look at how those probe routines are implemented.

The registration of devices using other bus types (USB, PCMCIA, etc.) shares the same skeleton. We will not look at how the infrastructure of those buses ends up calling their probe counterpart, as we saw for PCI in Chapter 6. Older buses may not be able to automatically detect the presence of devices and may require the device drivers to do it by manually probing specific memory addresses, using default parameters or boot-time parameters provided by the user.[*] We will not look at this case either.

[*] See, for example, net_olddevs_init in drivers/net/Space.c. This function, which is tagged with the device_initcall macro introduced in Chapter 7, is executed at boot time. The same function takes care of the registration of the loopback device.


Previous Page
Next Page