Commit eccd9e25 authored by Patrick Mochel's avatar Patrick Mochel

Driver model: doc updates.

From Geert Uytterhoeven
parent 693ccaab
...@@ -11,11 +11,11 @@ structures, most of the binding can take place using common code. ...@@ -11,11 +11,11 @@ structures, most of the binding can take place using common code.
Bus Bus
~~~ ~~~
The bus type structure contains a list of all devices that on that bus The bus type structure contains a list of all devices that are on that bus
type in the system. When device_register is called for a device, it is type in the system. When device_register is called for a device, it is
inserted into the end of this list. The bus object also contains a inserted into the end of this list. The bus object also contains a
list of all drivers of that bus type. When driver_register is called list of all drivers of that bus type. When driver_register is called
for a driver, it is inserted into the end of this list. These are the for a driver, it is inserted at the end of this list. These are the
two events which trigger driver binding. two events which trigger driver binding.
...@@ -42,7 +42,7 @@ Device Class ...@@ -42,7 +42,7 @@ Device Class
~~~~~~~~~~~~ ~~~~~~~~~~~~
Upon the successful completion of probe, the device is registered with Upon the successful completion of probe, the device is registered with
the class to which it belongs. Device drivers belong to one and only the class to which it belongs. Device drivers belong to one and only one
class, and that is set in the driver's devclass field. class, and that is set in the driver's devclass field.
devclass_add_device is called to enumerate the device within the class devclass_add_device is called to enumerate the device within the class
and actually register it with the class, which happens with the and actually register it with the class, which happens with the
...@@ -61,7 +61,7 @@ driver's list of devices. ...@@ -61,7 +61,7 @@ driver's list of devices.
sysfs sysfs
~~~~~~~~ ~~~~~
A symlink is created in the bus's 'devices' directory that points to A symlink is created in the bus's 'devices' directory that points to
the device's directory in the physical hierarchy. the device's directory in the physical hierarchy.
......
...@@ -58,7 +58,7 @@ match(): Attaching Drivers to Devices ...@@ -58,7 +58,7 @@ match(): Attaching Drivers to Devices
The format of device ID structures and the semantics for comparing The format of device ID structures and the semantics for comparing
them are inherently bus-specific. Drivers typically declare an array them are inherently bus-specific. Drivers typically declare an array
of device IDs of device they support that reside in a bus-specific of device IDs of devices they support that reside in a bus-specific
driver structure. driver structure.
The purpose of the match callback is provide the bus an opportunity to The purpose of the match callback is provide the bus an opportunity to
...@@ -153,7 +153,7 @@ directory: ...@@ -153,7 +153,7 @@ directory:
|-- agpgart |-- agpgart
`-- e100 `-- e100
Each device that is discovered a bus of that type gets a symlink in Each device that is discovered on a bus of that type gets a symlink in
the bus's devices directory to the device's directory in the physical the bus's devices directory to the device's directory in the physical
hierarchy: hierarchy:
......
...@@ -105,7 +105,7 @@ default subdirectories: ...@@ -105,7 +105,7 @@ default subdirectories:
Drivers registered with the class get a symlink in the drivers/ directory Drivers registered with the class get a symlink in the drivers/ directory
that points the driver's directory (under its bus directory): that points to the driver's directory (under its bus directory):
class/ class/
`-- input `-- input
......
...@@ -47,11 +47,13 @@ intf_list: List of intf_data. There is one structure allocated for ...@@ -47,11 +47,13 @@ intf_list: List of intf_data. There is one structure allocated for
children: List of child devices. children: List of child devices.
parent: *** FIXME ***
name: ASCII description of device. name: ASCII description of device.
Example: " 3Com Corporation 3c905 100BaseTX [Boomerang]" Example: " 3Com Corporation 3c905 100BaseTX [Boomerang]"
bus_id: ASCII representation of device's bus position. This bus_id: ASCII representation of device's bus position. This
field should a name unique across all devices on the field should be a name unique across all devices on the
bus type the device belongs to. bus type the device belongs to.
Example: PCI bus_ids are in the form of Example: PCI bus_ids are in the form of
...@@ -66,12 +68,12 @@ bus: Pointer to struct bus_type that device belongs to. ...@@ -66,12 +68,12 @@ bus: Pointer to struct bus_type that device belongs to.
dir: Device's sysfs directory. dir: Device's sysfs directory.
class_num: Class-enumerated value of the device.
driver: Pointer to struct device_driver that controls the device. driver: Pointer to struct device_driver that controls the device.
driver_data: Driver-specific data. driver_data: Driver-specific data.
class_num: Class-enumerated value of the device.
platform_data: Platform data specific to the device. platform_data: Platform data specific to the device.
current_state: Current power state of the device. current_state: Current power state of the device.
...@@ -108,7 +110,7 @@ get_device() will return a pointer to the struct device passed to it ...@@ -108,7 +110,7 @@ get_device() will return a pointer to the struct device passed to it
if the reference is not already 0 (if it's in the process of being if the reference is not already 0 (if it's in the process of being
removed already). removed already).
A driver can take use the lock in the device structure using: A driver can access the lock in the device structure using:
void lock_device(struct device * dev); void lock_device(struct device * dev);
void unlock_device(struct device * dev); void unlock_device(struct device * dev);
......
...@@ -63,9 +63,9 @@ Most drivers will not be able to be converted completely to the new ...@@ -63,9 +63,9 @@ Most drivers will not be able to be converted completely to the new
model because the bus they belong to has a bus-specific structure with model because the bus they belong to has a bus-specific structure with
bus-specific fields that cannot be generalized. bus-specific fields that cannot be generalized.
The most common example this are device ID structures. A driver The most common example of this are device ID structures. A driver
typically defines an array of device IDs that it supports. The format typically defines an array of device IDs that it supports. The format
of this structure and the semantics for comparing device IDs is of these structures and the semantics for comparing device IDs are
completely bus-specific. Defining them as bus-specific entities would completely bus-specific. Defining them as bus-specific entities would
sacrifice type-safety, so we keep bus-specific structures around. sacrifice type-safety, so we keep bus-specific structures around.
...@@ -77,8 +77,8 @@ struct pci_driver { ...@@ -77,8 +77,8 @@ struct pci_driver {
struct device_driver driver; struct device_driver driver;
}; };
A definition that included bus-specific fields would look something A definition that included bus-specific fields would look like
like (using the eepro100 driver again): (using the eepro100 driver again):
static struct pci_driver eepro100_driver = { static struct pci_driver eepro100_driver = {
.id_table = eepro100_pci_tbl, .id_table = eepro100_pci_tbl,
...@@ -109,7 +109,7 @@ struct device_driver object. ...@@ -109,7 +109,7 @@ struct device_driver object.
Most drivers, however, will have a bus-specific structure and will Most drivers, however, will have a bus-specific structure and will
need to register with the bus using something like pci_driver_register. need to register with the bus using something like pci_driver_register.
It is important that drivers register their drivers as early as It is important that drivers register their driver structure as early as
possible. Registration with the core initializes several fields in the possible. Registration with the core initializes several fields in the
struct device_driver object, including the reference count and the struct device_driver object, including the reference count and the
lock. These fields are assumed to be valid at all times and may be lock. These fields are assumed to be valid at all times and may be
...@@ -148,7 +148,7 @@ accesses it. ...@@ -148,7 +148,7 @@ accesses it.
sysfs sysfs
~~~~~~~~ ~~~~~
When a driver is registered, a sysfs directory is created in its When a driver is registered, a sysfs directory is created in its
bus's directory. In this directory, the driver can export an interface bus's directory. In this directory, the driver can export an interface
...@@ -205,7 +205,7 @@ management based on the requirements of the system and the ...@@ -205,7 +205,7 @@ management based on the requirements of the system and the
user-defined policy. user-defined policy.
SUSPEND_NOTIFY notifies the device that a suspend transition is about SUSPEND_NOTIFY notifies the device that a suspend transition is about
to happen. This happens on system power state transition to verify to happen. This happens on system power state transitions to verify
that all devices can successfully suspend. that all devices can successfully suspend.
A driver may choose to fail on this call, which should cause the A driver may choose to fail on this call, which should cause the
......
...@@ -82,7 +82,7 @@ Devices are enumerated within the interface. This happens in interface_add_data( ...@@ -82,7 +82,7 @@ Devices are enumerated within the interface. This happens in interface_add_data(
and the enumerated value is stored in the struct intf_data for that device. and the enumerated value is stored in the struct intf_data for that device.
sysfs sysfs
~~~~~~~~ ~~~~~
Each interface is given a directory in the directory of the device Each interface is given a directory in the directory of the device
class it belongs to: class it belongs to:
...@@ -120,10 +120,10 @@ device interface. ...@@ -120,10 +120,10 @@ device interface.
Many interfaces have a major number associated with them and each Many interfaces have a major number associated with them and each
device gets a minor number. Or, multiple interfaces might share one device gets a minor number. Or, multiple interfaces might share one
major number, and each get receive a range of minor numbers (like in major number, and each will receive a range of minor numbers (like in
the case of input devices). the case of input devices).
These major and minor numbers could be stored in the interface These major and minor numbers could be stored in the interface
structure. Major and minor allocation could happen when the interface structure. Major and minor allocations could happen when the interface
is registered with the class, or via a helper function. is registered with the class, or via a helper function.
...@@ -9,7 +9,7 @@ Overview ...@@ -9,7 +9,7 @@ Overview
~~~~~~~~ ~~~~~~~~
This driver model is a unification of all the current, disparate driver models This driver model is a unification of all the current, disparate driver models
that are currently in the kernel. It is intended is to augment the that are currently in the kernel. It is intended to augment the
bus-specific drivers for bridges and devices by consolidating a set of data bus-specific drivers for bridges and devices by consolidating a set of data
and operations into globally accessible data structures. and operations into globally accessible data structures.
...@@ -23,7 +23,7 @@ tree as well as its local tree. In fact, the local tree becomes just a subset ...@@ -23,7 +23,7 @@ tree as well as its local tree. In fact, the local tree becomes just a subset
of the global tree. of the global tree.
Common data fields can also be moved out of the local bus models into the Common data fields can also be moved out of the local bus models into the
global model. Some of the manipulation of these fields can also be global model. Some of the manipulations of these fields can also be
consolidated. Most likely, manipulation functions will become a set consolidated. Most likely, manipulation functions will become a set
of helper functions, which the bus drivers wrap around to include any of helper functions, which the bus drivers wrap around to include any
bus-specific items. bus-specific items.
...@@ -71,7 +71,7 @@ fields of struct device unless there is a strong compelling reason to do so. ...@@ -71,7 +71,7 @@ fields of struct device unless there is a strong compelling reason to do so.
This abstraction is prevention of unnecessary pain during transitional phases. This abstraction is prevention of unnecessary pain during transitional phases.
If the name of the field changes or is removed, then every downstream driver If the name of the field changes or is removed, then every downstream driver
will break. On the other hand, if only the bus layer (and not the device will break. On the other hand, if only the bus layer (and not the device
layer) accesses struct device, it is only those that need to change. layer) accesses struct device, it is only that layer that needs to change.
User Interface User Interface
...@@ -96,9 +96,9 @@ Whenever a device is inserted into the tree, a directory is created for it. ...@@ -96,9 +96,9 @@ Whenever a device is inserted into the tree, a directory is created for it.
This directory may be populated at each layer of discovery - the global layer, This directory may be populated at each layer of discovery - the global layer,
the bus layer, or the device layer. the bus layer, or the device layer.
The global layer currently creates two files - name and 'power'. The The global layer currently creates two files - 'name' and 'power'. The
former only reports the name of the device. The latter reports the former only reports the name of the device. The latter reports the
current power state of the device. It also be used to set the current current power state of the device. It will also be used to set the current
power state. power state.
The bus layer may also create files for the devices it finds while probing the The bus layer may also create files for the devices it finds while probing the
......
...@@ -10,9 +10,9 @@ host bridges to peripheral buses. ...@@ -10,9 +10,9 @@ host bridges to peripheral buses.
Platform drivers Platform drivers
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
Drivers for platform devices have typically very simple and Drivers for platform devices are typically very simple and
unstructured. Either the device was present at a particular I/O port unstructured. Either the device was present at a particular I/O port
and the driver was loaded, or there was not. There was no possibility and the driver was loaded, or it was not. There was no possibility
of hotplugging or alternative discovery besides probing at a specific of hotplugging or alternative discovery besides probing at a specific
I/O address and expecting a specific response. I/O address and expecting a specific response.
...@@ -49,7 +49,7 @@ devices that it discovers via the bus's add() callback: ...@@ -49,7 +49,7 @@ devices that it discovers via the bus's add() callback:
Bus IDs Bus IDs
~~~~~~~ ~~~~~~~
Bus IDs are the canonical name for the device. There is no globally Bus IDs are the canonical names for the devices. There is no globally
standard addressing mechanism for legacy devices. In the IA-32 world, standard addressing mechanism for legacy devices. In the IA-32 world,
we have Pnp IDs to use, as well as the legacy I/O ports. However, we have Pnp IDs to use, as well as the legacy I/O ports. However,
neither tell what the device really is or have any meaning on other neither tell what the device really is or have any meaning on other
...@@ -62,7 +62,7 @@ within the scope of the kernel). ...@@ -62,7 +62,7 @@ within the scope of the kernel).
For example, a serial driver might find a device at I/O 0x3f8. The For example, a serial driver might find a device at I/O 0x3f8. The
ACPI firmware might also discover a device with PnP ID (_HID) ACPI firmware might also discover a device with PnP ID (_HID)
PNP0501. Both correspond to the same device should be mapped to the PNP0501. Both correspond to the same device and should be mapped to the
canonical name 'serial'. canonical name 'serial'.
The bus_id field should be a concatenation of the canonical name and The bus_id field should be a concatenation of the canonical name and
...@@ -88,7 +88,7 @@ Driver Binding ...@@ -88,7 +88,7 @@ Driver Binding
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
Legacy drivers assume they are bound to the device once they start up Legacy drivers assume they are bound to the device once they start up
and probe an I/O port. Divorcing them from this will be a difficult and probe an I/O port. Divorcing them from this will be a difficult
process. However, that shouldn't prevent us from impelementing process. However, that shouldn't prevent us from implementing
firmware-based enumeration. firmware-based enumeration.
The firmware should notify the platform bus about devices before the The firmware should notify the platform bus about devices before the
......
...@@ -128,7 +128,7 @@ static inline struct pci_dev * to_pci_dev(struct kobject * kobj) ...@@ -128,7 +128,7 @@ static inline struct pci_dev * to_pci_dev(struct kobject * kobj)
The bus_id is an ASCII string that contains the device's address on The bus_id is an ASCII string that contains the device's address on
the bus. The format of this string is bus-specific. This is the bus. The format of this string is bus-specific. This is
necessary for representing device in sysfs. necessary for representing devices in sysfs.
parent is the physical parent of the device. It is important that parent is the physical parent of the device. It is important that
the bus driver sets this field correctly. the bus driver sets this field correctly.
...@@ -286,7 +286,7 @@ parameters. ...@@ -286,7 +286,7 @@ parameters.
It would be difficult and tedious to force every driver on a bus to It would be difficult and tedious to force every driver on a bus to
simultaneously convert their drivers to generic format. Instead, the simultaneously convert their drivers to generic format. Instead, the
bus driver should define single instances of the generic methods that bus driver should define single instances of the generic methods that
forward calls to the bus-specific drivers. For instance: forward call to the bus-specific drivers. For instance:
static int pci_device_remove(struct device * dev) static int pci_device_remove(struct device * dev)
...@@ -330,8 +330,8 @@ registered with the bus at any time. When registration happens, ...@@ -330,8 +330,8 @@ registered with the bus at any time. When registration happens,
devices must be bound to a driver, or drivers must be bound to all devices must be bound to a driver, or drivers must be bound to all
devices that it supports. devices that it supports.
Drivers typically contain a list of device IDs that it supports. The A driver typically contains a list of device IDs that it supports. The
bus driver compares this ID to the ID of devices registered with it. bus driver compares these IDs to the IDs of devices registered with it.
The format of the device IDs, and the semantics for comparing them are The format of the device IDs, and the semantics for comparing them are
bus-specific, so the generic model does attempt to generalize them. bus-specific, so the generic model does attempt to generalize them.
...@@ -396,7 +396,7 @@ This is called immediately before /sbin/hotplug is executed. ...@@ -396,7 +396,7 @@ This is called immediately before /sbin/hotplug is executed.
Step 7: Cleaning up the bus driver. Step 7: Cleaning up the bus driver.
The generic bus, device, and driver structures provide several fields The generic bus, device, and driver structures provide several fields
that can replace those define privately to the bus driver. that can replace those defined privately to the bus driver.
- Device list. - Device list.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment