Specifications

D
evice Driver Programming
11-6
Basic Locks 11
After you have defined a basic lock’s lock information structure by using the
LKINFO_DECL(D5) macro, you must allocate and initialize the lock. This is done by
calling the calling the LOCK_ALLOC(D3) routine.
While the kernel sometimes statically allocates locks, device drivers are strongly encour-
aged to always use LOCK_ALLOC to allocate their locks. Use of LOCK_ALLOC enhances
the portability of the driver.
#include <sys/types.h>
#include <sys/kmem.h>
#include <sys/ksynch.h>
#include <sys/ddi.h>
lock_t *LOCK_ALLOC(hierarchy, min_pl, lkinfo_p, flag)
uchar_t hierarchy;
pl_t min_pl;
lkinfo_t *lkinfo_p;
int flag
;
where:
hierarchy is the hierarchy value that asserts the order in which this lock is acquired
relative to other basic and read/write locks. Acceptable hierarchy values range from
1 to 32 inclusively.
When acquiring a lock using any function other than TRYLOCK(D3), the lock
must have a hierarchy value that is strictly greater than the hierarchy values cur-
rently held by the calling context. For example, if lock B is to be acquired uncondi-
tionally while holding lock A, then the hierarchy value associated with lock B
should be strictly greater than the hierarchy value associated with lock A. The hier-
archy values of multiple locks held at any point in time must form a strict ordering.
Further, if one or more locks are acquired at distinct priority levels, you should
define subranges of hierarchy values for each priority level and pick a value from
these subranges. For example, if M is the hierarchy value defined for any lock that
can be acquired at priority level N, then M+1 should be the minimum hierarchy
value defined for any lock that can be acquired at any priority level greater than N.
min_pl is the minimum priority level argument that asserts the minimum priority
level passed in with any attempt to acquire the lock.
The valid priority level arguments for the basic lock allocation and locking inter-
faces are listed below:
pltimeout Block functions scheduled by
itimeout(D3) and dtimeout(D3)
pldisk Block disk device interrupts
plstr Block STREAMS interrupts
plhi Block all interrupts