Writing Device Drivers

Check Changed Arguments of DDI Functions

Some DDI function argument data types have been changed. These routines are listed below.

getrbuf() Argument Changes

struct buf *getrbuf(int sleepflag);

In previous releases, sleepflag was defined as a type long.

drv_getparm() Argument Changes

int drv_getparm(unsigned int parm, void *value_p);

In previous releases, value_p was defined as type unsigned long.

In the 64-bit kernel, drv_getparm(9F) can be used to fetch both 32-bit and 64-bit quantities, yet the interface does not define the data types of these quantities, which encourages simple programming errors.

The following new routines offer a safer alternative:

clock_t           ddi_get_lbolt(void);
time_t            ddi_get_time(void);
cred_t            *ddi_get_cred(void);
pid_t             ddi_get_pid(void);

Driver writers are strongly urged to use these routines instead of drv_getparm(9F).

delay() and timeout () Argument Changes

void delay(clock_t ticks);
timeout_id_t timeout(void (*func)(void *), void *arg, clock_t ticks);

The ticks argument to the delay(9F) and timeout(9F) routines has been changed from long to clock_t.

rmallocmap() and rmallocmap_wait() Argument Changes

struct map *rmallocmap(size_t mapsize);
struct map *rmallocmap_wait(size_t mapsize);

The mapsize argument to thermallocmap(9F) and rmallocmap_wait(9F) routines has been changed from ulong_t to size_t.

scsi_alloc_consistent_buf() Argument Changes

struct buf *scsi_alloc_consistent_buf(struct scsi_address *ap,
        struct buf *bp, size_t datalen, uint_t bflags,
        int (*callback )(caddr_t), caddr_t arg);

In previous releases, datalen was defined as an int and bflags was defined as a ulong.

uiomove() Argument Changes

int uiomove(caddr_t address, size_t nbytes,
        enum uio_rw rwflag, uio_t *uio_p);

The nbytes argument was defined as a type long, but because it represents a size in bytes, size_t is more appropriate.

cv_timedwait() and cv_timedwait_sig() Argument Changes

int cv_timedwait(kcondvar_t *cvp, kmutex_t *mp, clock_t timeout);
int cv_timedwait_sig(kcondvar_t *cvp, kmutex_t *mp,    clock_t timeout);

In previous releases, the timeout argument to the cv_timedwait(9F) and cv_timedwait_sig(9F) routines was defined to be of type long. Because they represent time in ticks, clock_t is more appropriate.

ddi_device_copy() Argument Changes

int ddi_device_copy(ddi_acc_handle_t src_handle,
        caddr_t src_addr, ssize_t src_advcnt,
        ddi_acc_handle_t dest_handle, caddr_t dest_addr,
        ssize_t dest_advcnt, size_t bytecount, uint_t dev_datasz);

The src_advcnt, dest_advcnt, dev_datasz arguments have changed type. These were previously defined as long, long, and ulong_t respectively.

ddi_device_zero() Argument Changes

int ddi_device_zero(ddi_acc_handle_t handle,
        caddr_t dev_addr, size_t bytecount, ssize_t dev_advcnt,
        uint_t dev_datasz):

In previous releases, dev_advcnt was defined as a type long and dev_datasz as a ulong_t.

ddi_dma_mem_alloc() Argument Changes

int ddi_dma_mem_alloc(ddi_dma_handle_t handle,
        size_t length, ddi_device_acc_attr_t *accattrp,
        uint_t flags, int (*waitfp)(caddr_t), caddr_t arg,
        caddr_t *kaddrp, size_t *real_length,
        ddi_acc_handle_t *handlep);

In previous releases, length, flags, and real_length were defined with types uint_t, ulong_t, and uint_t *.