Writing Device Drivers

SunOS 4.1 to SunOS 5.7 Differences

Table A-1 compares device driver routines on the SunOS 4.1 system versus the SunOS 5.7 system. It is not a table of equivalences. That is, simply changing from the function in column one to the function (or group of functions) in column two is not always sufficient. If the 4.1 driver used a function in column one, read about the function in column two before changing any code.

Table A-1 SunOS 4.1 and SunOS 5.7 Kernel Support Routines

SunOS 4.1.x 

SunOS 5.6 

Description 

ASSERT()

ASSERT()

Expression verification 

CDELAY() 

Conditional busy-wait 

DELAY()

drv_usecwait()

Busy-wait for specified interval 

OTHERQ()

OTHERQ()

Gets pointer to queue's partner queue 

RD()

RD()

Gets pointer to the read queue 

WR()

WR()

Gets pointer to the write queue 

add_intr()

ddi_add_intr()

Adds an interrupt handler 

adjmsg()

adjmsg()

Trims bytes from a message 

allocb()

allocb()

Allocates a message block 

backq()

backq()

Gets pointer to queue behind the current queue 

bcmp()

bcmp()

Compares two byte arrays 

bcopy()

bcopy()

Copies data between address locations in kernel 

biodone() iodone()

biodone()

Indicates I/O is complete 

biowait() iowait()

b iowait()

Wait sfor I/O to complete 

bp_mapin()

bp_mapin()

Allocates virtual address space 

bp_mapout()

bp_mapout()

Deallocates virtual address space 

brelse()

-

Returns buffer to the free list 

btodb() 

Converts bytes to disk sectors 

btop()

btop() ddi_btop()

Converts size in bytes to size in pages (round down) 

btopr()

btopr() ddi_btopr()

Converts size in bytes to size in pages (round up) 

bufcall()

bufcall()

Calls a function when a buffer becomes available 

bzero()

bzero()

Zeros out memory 

canput()

canput()

Tests for room in a message queue 

clrbuf()

clrbuf()

Erases the contents of a buffer 

copyb()

copyb()

Copies a message block 

copyin()

ddi_copyin()

Copies data from a user program to a driver buffer 

copymsg()

copymsg()

Copies a message 

copyout()

ddi_copyout()

Copies data from a driver to a user program 

datamsg()

datamsg()

Tests whether a message is a data message 

delay() 

delay() 

Delays execution for a specified number of clock ticks 

disksort()

disksort()

Single direction elevator seek-sort for buffers 

dupb()

dupb()

Duplicates a message block descriptor 

dupmsg()

dupmsg()

Duplicates a message 

enableok()

enableok()

Reschedules a queue for service 

esballoc()

esballoc()

Allocates a message block using caller-supplied buffer 

esbbcall()

esbbcall()

Call sfunction when buffer is available 

ffs()

ddi_ffs()

Finds first bit set in a long integer 

fls()

ddi_fls()

Finds last bit set in a long integer 

flushq()

flushq()

Removes messages from a queue 

free_pktiopb()

scsi_free_consistent_buf()

Frees a SCSI packet in the iopb map

freeb()

freeb()

Frees a message block 

freemsg()

freemsg()

Frees all message blocks in a message 

get_pktiopb()

scsi_alloc_consistent_buf()

Allocates a SCSI packet in the iopb map

geterror()

geterror()

Gets buffer's error number 

getlongprop()

ddi_getlongprop()

Gets arbitrary size property information 

getprop()

ddi_getprop()

Gets boolean and integer property information 

getproplen()

ddi_getproplen()

Gets property information length 

getq()

getq()

Gets the next message from a queue 

gsignal() 

Sends signal to process group 

hat_getpkfnum()

hat_getkpfnum()

Gets page frame number for kernel address 

index()

strchr()

Returns pointer to first occurrence of character in string 

insq()

insq()

Inserts a message into a queue 

kmem_alloc()

kmem_alloc()

Allocates space from kernel free memory 

kmem_free()

kmem_free()

Frees previously allocated kernel memory 

kmem_zalloc()

kmem_zalloc()

Allocates and clears space from kernel free memory 

linkb()

linkb()

Concatenates two message blocks 

log() 

strlog() 

Logs kernel errors 

machineid() 

Gets host ID from EPROM 

major()

getmajor()

Gets major device number 

makecom_g0()

makecom_g0()

Makes packet for SCSI group 0 commands 

makecom_g0_s()

makecom_g0_s()

Makes packet for SCSI group 0 sequential commands 

makecom_g1()

makecom_g1()

Makes packet for SCSI group 1 commands 

makecom_g5()

makecom_g5()

Makes packet for SCSI group 5 commands 

mapin() map_regs()

ddi_regs_map_setup()

Maps physical-to-virtual space 

mapout() unmap_regs()

ddi_regs_map_free()

Removes physical-to-virtual mappings 

max()

max()

Returns the larger of two integers 

mb_mapalloc()

ddi_dma_buf_bind_handle()

Sets up system DMA resources and retrieves DMA address 

mb_mapfree()

ddi_dma_unbind_handle()

Releases system DMA resources 

mballoc() 

Allocates a main bus buffer 

mbrelse() 

Frees main bus resources 

mbsetup() 

Sets up use of main bus resources 

min()

min()

Returns the lesser of two integers 

minor()

getminor()

Gets minor device number 

minphys()

minphys()

Limits transfer request size to system maximum 

mp_nbmapalloc() 

ddi_dma_addr_bind_handle() 

Sets up system DMA resources and retrieves DMA address 

MBI_ADDR() 

Retrieves DMA address 

msgdsize()

msgdsize()

Returns the number of bytes in a message 

nodev()

nodev()

Error function returning ENXIO 

noenable()

noenable()

Prevents a queue from being scheduled 

nulldev()

nulldev()

Function returning zero 

ovbcopy() 

Copies overlapping byte memory regions 

panic() 

cmn_err() 

Reboots at fatal error 

peek()

ddi_peek16()

Reads a 16-bit value from a location 

peekc()

ddi_peek8()

Reads a 8-bit value from a location 

peekl()

ddi_peek32()

Reads a 32-bit value from a location 

physio()

physio()

Limits transfer request size 

pkt_transport()

scsi_transport()

Request by a SCSI target driver to start a command 

poke()

ddi_poke16()

Writes a 16-bit value to a location 

pokec()

ddi_poke8()

Writes a 8-bit value to a location 

pokel()

ddi_poke32()

Writes a 32-bit value to a location 

printf()

cmn_err()

Displays an error message or panics the system 

pritospl() 

Converts priority level 

psignal()

-

Sends a signal to a process 

ptob()

ptob() ddi_ptob()

Converts size in pages to size in bytes 

pullupmsg()

pullupmsg()

Concatenates bytes in a message 

put()

put()

Calls a STREAMS put procedure 

putbq()

putbq()

Places a message at the head of a queue 

putctl()

putctl()

Sends a control message to a queue 

putctl1()

putctl1()

Sends a control message with one-byte parameter to a queue 

putnext()

putnext()

Sends a message to the next queue 

putq()

putq()

Puts a message on a queue 

qenable()

qenable()

Enables a queue 

qreply()

qreply()

Sends a message on a stream in the reverse direction 

qsize()

qsize()

Finds the number of messages on a queue 

remintr()

ddi_remove_intr()

Removes an interrupt handler 

report_dev()

ddi_report_dev()

Announces a device 

rmalloc()

rmallocmap() rmalloc()

Allocates resource map allocates space from a resource map 

rmalloc(iopbmap)

ddi_dma_mem_alloc()

Allocates consistent memory 

rmfree()

rmfreemap() rmfree()

Frees resource map frees space back into a resource map 

rmfree(iopbmap)

ddi_dma_mem_free()

Free consistent memory 

rmvb()

rmvb()

Removes a message block from a message 

rmvq()

rmvq()

Removes a message from a queue 

scsi_abort()

scsi_abort()

Aborts a SCSI command 

scsi_dmafree()

scsi_dmafree()

Frees DMA resources for SCSI command 

scsi_dmaget()

scsi_init_pkt()

Allocates DMA resources for SCSI command 

scsi_ifgetcap()

scsi_ifgetcap()

Gets SCSI transport capability 

scsi_ifsetcap()

scsi_ifsetcap()

Sets SCSI transport capability 

scsi_pktalloc()

scsi_init_pkt()

Allocates packet resources for SCSI command 

scsi_pktfree()

scsi_destroy_pkt()

Frees packet resources for SCSI command 

scsi_poll()

scsi_poll()

Runs a polled SCSI command 

scsi_resalloc()

scsi_init_pkt()

Prepares a complete SCSI packet 

scsi_reset()

scsi_reset()

Resets a SCSI bus or target 

scsi_resfree()

scsi_destroy_pkt()

Frees an allocated SCSI packet 

scsi_slave()

scsi_probe()

Probes for a SCSI target 

selwakeup()

pollwakeup()

Informs a process that an event has occurred 

slaveslot()

ddi_slaveonly()

Tells if device is installed in a slave-only slot 

sleep()

cv_wait()

Supends calling thread and exit mutex atomically 

spln() 

mutex_enter() 

Sets CPU priority level 

splr() splx() 

mutex_exit() 

Resets priority level 

splstr() 

Sets processor level for STREAMS 

strcmp()

strcmp()

Compares two null-terminated strings 

strcpy()

strcmp()

Copies a string from one location to another 

suser() 

drv_priv() 

Verifies superuser 

swab()

swab()

Swaps bytes in 16-bit halfwords 

testb()

testb()

Checks for an available buffer 

timeout()

timeout()

Executes a function after a specified length of time 

uiomove()

uiomove()

Copies kernel data using uio(9S) structure

unbufcall() 

unbufcall() 

Cancels an outstanding bufcall request

unlinkb()

unlinkb()

Removes a message block from the head of a message 

untimeout()

untimeout()

Cancels previous timeout function call 

uprintf() 

cmn_err() 

Kernel print to controlling terminal 

ureadc()

ureadc()

Adds character to a uio structure

useracc()

useracc()

Verifies whether user has access to memory 

usleep() 

drv_usecwait 

Busy-waits for specified interval 

uwritec()

uwritec()

Removes a character from a uio structure

wakeup()

cv_broadcast()

Signals condition and wakes all blocked threads