Kernel Functions for Drivers ddicopyin(9F)
NAME
ddicopyin - copy data to a driver buffer
SYNOPSIS
#include
#include
#include
int ddicopyin(const void *buf, void *driverbuf, sizet cn, int flags);
INTERFACE LEVEL
Solaris DI specific (Solaris DI).
PARAMETERS
buf Source address from which data is transferred.
driverbuf Driver destination address to which data is
transferred.
cn Number of bytes transferred.
flags Set of flag bits that provide address space
information about buf.
DESCRIPTION
This routine is designed for use in driver ioctl(9E) rou-
tines for drivers that support layered ioctls. ddicopyin()
copies data from a source address to a driver buffer. The
driver developer must ensure that adequate space is allo-
cated for the destination address.
The flags argument determines the address space information
about buf. If the FKIOCTL flag is set, this indicates that
buf is a kernel address, and ddicopyin() behaves like
bcopy(9F). Otherwise, buf is interpreted as a user buffer
address, and ddicopyin() behaves like copyin(9F).
Addresses that are word-aligned are moved most efficiently.
However, the driver developer is not obliged to ensure
alignment. This function automatically finds the most effi-
cient move according to address alignment.
SunOS 5.11 Last change: 19 Apr 2000 1
Kernel Functions for Drivers ddicopyin(9F)
RETURN VALUES
ddicopyin() returns 0, indicating a successful copy. It
returns -1 if one of the following occurs:
o Paging fault; the driver tried to access a page of
memory for which it did not have read or write
access.
o Invalid user address, such as a user area or stack
area.
o Invalid address that would have resulted in data
being copied into the user block.
o Hardware fault; a hardware error prevented access
to the specified user memory. For example, an
uncorrectable parity or EC error occurred.
If -1 is returned to the caller, driver entry point routines
should return EFAULT.
CONTEXT
ddicopyin() can be called from user or kernel context only.
EXAMPLES
Example 1 ddicopyin() example
A driver ioctl(9E) routine (line 12) can be used to get or
set device attributes or registers. For the XSETREGS con-
dition (line 25), the driver copies the user data in arg to
the device registers. If the specified argument contains an
invalid address, an error code is returned.
1 struct device { /* layout of physical device registers */
2 int control; /* physical device control word */
3 int status; /* physical device status word */
4 short recvchar; /* receive character from device */
5 short xmitchar /* transmit character to device */
6 };
7 struct devicestate {
8 volatile struct device *regsp; /* pointer to device registers */
9 kmutext regmutex; /* protect device registers */
. . .
10 };
11 static void *statep; /* for soft state routines */
12 xxioctl(devt dev, int cmd, int arg, int mode,
13 credt *credp, int *rvalp)
SunOS 5.11 Last change: 19 Apr 2000 2
Kernel Functions for Drivers ddicopyin(9F)
14 {
15 struct devicestate *sp;
16 volatile struct device *rp;
17 struct device regbuf; /* temporary buffer for registers */
18 int instance;
19 instance = getminor(dev);
20 sp = ddigetsoftstate(statep, instance);
21 if (sp == NUL)
22 return (ENXIO);
23 rp = sp->regsp;
. . .
24 switch (cmd) {
25 case XGETREGS: /* copy data to temp. regs. buf */
26 if (ddicopyin(arg, ®buf,
27 sizeof (struct device), mode) != 0) {
28 return (EFAULT);
29 }
30 mutexenter(&sp->regmutex);
31 /*
32 * Copy data from temporary device register
33 * buffer to device registers.
34 * e.g. rp->control = regbuf.control;
35 */
36 mutexexit(&sp->regmutex);
37 break;
38 }
39 }
SEE ALSO
ioctl(9E), bcopy(9F), copyin(9F), copyout(9F),
ddicopyout(9F), uiomove(9F)
Writing Device Drivers
NOTES
The value of the flags argument to ddicopyin() should be
passed through directly from the mode argument of ioctl()
untranslated.
Driver defined locks should not be held across calls to this
function.
ddicopyin() should not be used from a streams driver. See
MCOPYIN and MCOPYOUT in STREAMS Programming Guide.
SunOS 5.11 Last change: 19 Apr 2000 3
|