Writing Device Drivers

Device Information Library Interfaces

The LDI includes libdevinfo(3LIB) interfaces that report a snapshot of device layering information. Device layering occurs when one device in the system is a consumer of another device in the system. Device layering information is reported only if both the consumer and the target are bound to a device node that is contained within the snapshot.

Device layering information is reported by the libdevinfo(3LIB) interfaces as a directed graph. An lnode is an abstraction that represents a vertex in the graph and is bound to a device node. You can use libdevinfo(3LIB) interfaces to access properties of an lnode, such as the name and device number of the node.

The edges in the graph are represented by a link. A link has a source lnode that represents the device consumer. A link also has a target lnode that represents the target device.

The following describes the libdevinfo(3LIB) device layering information interfaces:

DINFOLYR

Snapshot flag that enables you to capture device layering information.

di_link_t

A directed link between two endpoints. Each endpoint is a di_lnode_t. An opaque structure.

di_lnode_t

The endpoint of a link. An opaque structure. A di_lnode_t is bound to a di_node_t.

di_node_t

Represents a device node. An opaque structure. A di_node_t is not necessarily bound to a di_lnode_t.

di_walk_link(3DEVINFO)

Walk all links in the snapshot.

di_walk_lnode(3DEVINFO)

Walk all lnodes in the snapshot.

di_link_next_by_node(3DEVINFO)

Get a handle to the next link where the specified di_node_t node is either the source or the target.

di_link_next_by_lnode(3DEVINFO)

Get a handle to the next link where the specified di_lnode_t lnode is either the source or the target.

di_link_to_lnode(3DEVINFO)

Get the lnode that corresponds to the specified endpoint of a di_link_t link.

di_link_spectype(3DEVINFO)

Get the link spectype. The spectype indicates how the target device is being accessed. The target device is represented by the target lnode.

di_lnode_next(3DEVINFO)

Get a handle to the next occurrence of the specified di_lnode_t lnode associated with the specified di_node_t device node.

di_lnode_name(3DEVINFO)

Get the name that is associated with the specified lnode.

di_lnode_devinfo(3DEVINFO)

Get a handle to the device node that is associated with the specified lnode.

di_lnode_devt(3DEVINFO)

Get the device number of the device node that is associated with the specified lnode.

The device layering information returned by the LDI can be quite complex. Therefore, the LDI provides interfaces to help you traverse the device tree and the device usage graph. These interfaces enable the consumer of a device tree snapshot to associate custom data pointers with different structures within the snapshot. For example, as an application traverses lnodes, the application can update the custom pointer associated with each lnode to mark which lnodes already have been seen.

The following describes the libdevinfo(3LIB) node and link marking interfaces:

di_lnode_private_set(3DEVINFO)

Associate the specified data with the specified lnode. This association enables you to traverse lnodes in the snapshot.

di_lnode_private_get(3DEVINFO)

Retrieve a pointer to data that was associated with an lnode through a call to di_lnode_private_set(3DEVINFO).

di_link_private_set(3DEVINFO)

Associate the specified data with the specified link. This association enables you to traverse links in the snapshot.

di_link_private_get(3DEVINFO)

Retrieve a pointer to data that was associated with a link through a call to di_link_private_set(3DEVINFO).