10.3. device_t Pointer
Prev | Chapter 10. ISA Device Drivers | Next

## 10.3. device_t Pointer

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`.

Prev | Up | Next
10.2. Basic Information | Home | 10.4. Configuration File and the Order of Identifying and Probing During Auto-Configuration

This, and other documents, can be downloaded from http://ftp.FreeBSD.org/pub/FreeBSD/doc/

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.