Writing Device Drivers

Utility Functions

These interfaces are miscellaneous utilities that the driver may use.

void ASSERT(EX);

The ASSERT(9F) macro does nothing if EX evaluates to nonzero. If EX evaluates to zero, ASSERT(9F) panics the system. ASSERT(9F) is useful in debugging a driver, since it can be used to stop the system when an unexpected situation is encountered, such as an erroneously NULL pointer.

ASSERT(9F) exhibits this behavior only when the DEBUG preprocessor symbol is defined.

int bcmp(const void *s1, const void *s2, size_t len);

bcmp(9F) compares len bytes of the byte arrays starting at s1 and s2. If these bytes are identical, bcmp(9F) returns zero. Otherwise, bcmp(9F) returns a nonzero value.

unsigned long btop(unsigned long numbytes);

btop(9F) converts a size n expressed in bytes to a size expressed in terms of the main system MMU page size, rounded down to the nearest page.

unsigned long btopr(unsigned long numbytes);

btopr(9F) converts a size n expressed in bytes to a size expressed in terms of the main system MMU page size, rounded up to the nearest page.

void bzero(void *addr, size_t bytes);

bzero(9F) zeroes bytes starting at addr.

unsigned long ddi_btop(dev_info_t *dip, unsigned long bytes);

ddi_btop(9F) converts a size expressed in bytes to a size expressed in terms of the parent bus nexus page size, rounded down to the nearest page.

unsigned long ddi_btopr(dev_info_t *dip, unsigned long bytes);

ddi_btopr(9F) converts a size expressed in bytes to a size expressed in terms of the parent bus nexus page size, rounded up to the nearest page.

unsigned long ddi_ptob(dev_info_t *dip, unsigned long pages);

ddi_ptob(9F) converts a size expressed in terms of the parent bus nexus page size to a size expressed in bytes.

int ddi_ffs(long mask);

ddi_ffs(9F) returns the number of the first (least-significant) bit set in mask.

int ddi_fls(long mask);

ddi_ffs(9F) returns the number of the last (most-significant) bit set in mask.

caddr_t ddi_get_driver_private(dev_info_t *dip);

ddi_get_driver_private(9F) returns a pointer to the data stored in the driver-private area of the dev_info node identified by dip.

void ddi_set_driver_private(dev_info_t *dip, caddr_t data);

ddi_set_driver_private(9F) sets the driver-private data of the dev_info node identified by dip to the value data.

int ddi_peek8(dev_info_t *dip, int8_t *addr, int8_t *valuep);

ddi_peek8(9F) reads 8-bit from the address addr to the location pointed to by valuep.

int ddi_peek16(dev_info_t *dip, int16_t *addr, int16_t *valuep);

ddi_peek16(9F) reads 16-bit from the address addr to the location pointed to by valuep.

int ddi_peek32(dev_info_t *dip, int32_t *addr, int32_t *valuep);

ddi_peek32(9F) reads 32-bit from the address addr to the location pointed to by valuep.

int ddi_peek64(dev_info_t *dip, int64_t *addr, int64_t *valuep);

ddi_peek64(9F) reads 64-bit from the address addr to the location pointed to by valuep.

int ddi_poke8(dev_info_t *dip, int8_t *addr, int8_t value);

ddi_poke8(9F) writes the data in value to the address addr.

int ddi_poke16(dev_info_t *dip, int16_t *addr, int16_t value);

ddi_poke16(9F) writes the data in value to the address addr.

int ddi_poke32(dev_info_t *dip, int32_t *addr, int32_t value);

ddi_poke32(9F) writes the data in value to the address addr.

int ddi_poke64(dev_info_t *dip, int64_t *addr, int64_t value);

ddi_poke64(9F) writes the data in value to the address addr.

major_t getmajor(dev_t dev);

getmajor(9F) decodes the major device number from dev and returns it.

minor_t getminor(dev_t dev);

getminor(9F) decodes the minor device number from dev and returns it.

dev_t makedevice(major_t majnum, minor_t minnum);

makedevice(9F) constructs and returns a device number of type dev_t from the major device number majnum and the minor device number minnum.

int max(int int1, int int2);

max(9F) returns the larger of the integers int1 and int2.

int min(int int1, int int2);

min(9F) returns the lesser of the integers int1 and int2.

int nodev();

nodev(9F) returns an error. Use nodev(9F) as the entry in the cb_ops(9S) structure for any entry point for which the driver must always fail.

int nulldev();

nulldev(9F) always returns zero, a return which for many entry points implies success. See the manual pages in Section 9 of the Solaris 7 Reference Manual Collection to learn about entry point return semantics.

unsigned long ptob(unsigned long numpages);

ptob(9F) converts a size expressed in terms of the main system memory management unit (MMU) page size to a size expressed in bytes.