device_t
is the pointer type for
the device structure. Here we consider only the methods
interesting from the device driver writer's standpoint. The
methods to manipulate values in the device structure
are:
device_t
device_get_parent(dev)
Get the parent bus of a
device.
driver_t
device_get_driver(dev)
Get pointer to its driver
structure.
char
*device_get_name(dev)
Get the driver name, such
as "xxx"
for our example.
int device_get_unit(dev)
Get the unit number (units are numbered from 0 for the
devices associated with each driver).
char
*device_get_nameunit(dev)
Get the device name
including the unit number, such as “xxx0”, “xxx1” and so
on.
char
*device_get_desc(dev)
Get the device
description. Normally it describes the exact model of device
in human-readable form.
device_set_desc(dev,
desc)
Set the description. This makes the device
description point to the string desc which may not be
deallocated or changed after that.
device_set_desc_copy(dev,
desc)
Set the description. The description is
copied into an internal dynamically allocated buffer, so the
string desc may be changed afterwards without adverse
effects.
void
*device_get_softc(dev)
Get pointer to the device
descriptor (struct xxx_softc
)
associated with this device.
u_int32_t
device_get_flags(dev)
Get the flags specified for
the device in the configuration file.
A convenience function device_printf(dev, fmt,
...)
may be used to print the messages from the
device driver. It automatically prepends the unitname and
colon to the message.
The device_t methods are implemented in the file
kern/bus_subr.c
.
All FreeBSD documents are available for download at https://download.freebsd.org/ftp/doc/
Questions that are not answered by the
documentation may be
sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.