Kernel Functions for Drivers ddidmabufbindhandle(9F)
NAME
ddidmabufbindhandle - binds a system buffer to a DMA
handle
SYNOPSIS
#include
#include
int ddidmabufbindhandle(ddidmahandlet handle, struct buf *bp,
uintt flags, int (*callback)(caddrt), caddrt
arg, ddidmacookiet *cookiep, uintt *ccountp);
INTERFACE LEVEL
Solaris DI specific (Solaris DI).
PARAMETERS
handle The DMA handle previously allocated by a call to
ddidmaallochandle(9F).
bp A pointer to a system buffer structure (see
buf(9S)).
flags Valid flags include:
DIDMAWRITE Transfer direction is from
memory to I/O
DIDMAREAD Transfer direction is from
I/O to memory
DIDMARDWR Both read and write
DIDMAREDZONE Establish an MU redzone
at end of the object.
DIDMAPARTIAL Partial resource alloca-
tion
DIDMACONSISTENT Nonsequential, random, and
small block transfers.
SunOS 5.11 Last change: 27 Jul 1996 1
Kernel Functions for Drivers ddidmabufbindhandle(9F)
DIDMASTREAMING Sequential, unidirec-
tional, block-sized, and
block-aligned transfers.
callback The address of a function to call back later if
resources are not available now. The following
special function addresses may also be used.
DIDMASLEP Wait until resources are
available.
DIDMADONTWAIT Do not wait until resources
are available and do not
schedule a callback.
arg Argument to be passed to the callback function,
callback, if such a function is specified.
cookiep A pointer to the first ddidmacookie(9S) struc-
ture.
ccountp Upon a successful return, ccountp points to a
value representing the number of cookies for
this DMA object.
DESCRIPTION
ddidmabufbindhandle() allocates DMA resources for a sys-
tem buffer such that a device can perform DMA to or from the
buffer. DMA resources are allocated considering the device's
DMA attributes as expressed by ddidmaattr(9S) (see
ddidmaallochandle(9F)).
ddidmabufbindhandle() fills in the first DMA cookie
pointed to by cookiep with the appropriate address, length,
and bus type. *ccountp is set to the number of DMA cookies
representing this DMA object. Subsequent DMA cookies must be
retrieved by calling ddidmanextcookie(9F) *countp-1 times.
When a DMA transfer completes, the driver should free up
system DMA resources by calling ddidmaunbindhandle(9F).
SunOS 5.11 Last change: 27 Jul 1996 2
Kernel Functions for Drivers ddidmabufbindhandle(9F)
The flags argument contains information for mapping rou-
tines.
DIDMAWRITE, DIDMAREAD, DIDMARDWR
These flags describe the intended direction of the DMA
transfer.
DIDMASTREAMING
This flag should be set if the device is doing sequen-
tial, unidirectional, block-sized, and block-aligned
transfers to or from memory. The alignment and padding
constraints specified by the minxfer and burstsizes
fields in the DMA attribute structure, ddidmaattr(9S)
(see ddidmaallochandle(9F)) is used to allocate the
most effective hardware support for large transfers.
DIDMACONSISTENT
This flag should be set if the device accesses memory
randomly, or if synchronization steps using
ddidmasync(9F) need to be as efficient as possible.
I/O parameter blocks used for communication between a
device and a driver should be allocated using
DIDMACONSISTENT.
DIDMAREDZONE
If this flag is set, the system attempts to establish a
protected red zone after the object. The DMA resource
allocation functions do not guarantee the success of
this request as some implementations may not have the
hardware ability to support a red zone.
DIDMAPARTIAL
Setting this flag indicates the caller can accept
resources for part of the object. That is, if the size
of the object exceeds the resources available, only
resources for a portion of the object are allocated. The
system indicates this condition returning status
DIDMAPARTIALMAP. At a later point, the caller can
use ddidmagetwin(9F) to change the valid portion of
the object for which resources are allocated. If
resources were allocated for only part of the object,
ddidmaaddrbindhandle() returns resources for the
first DMA window. Even when DIDMAPARTIAL is set, the
SunOS 5.11 Last change: 27 Jul 1996 3
Kernel Functions for Drivers ddidmabufbindhandle(9F)
system may decide to allocate resources for the entire
object (less overhead) in which case DIDMAMAPED is
returned.
The callback function, callback, indicates how a caller
wants to handle the possibility of resources not being
available. If callback is set to DIDMADONTWAIT, the
caller does not care if the allocation fails, and can handle
an allocation failure appropriately. If callback is set to
DIDMASLEP, the caller wishes to have the allocation rou-
tines wait for resources to become available. If any other
value is set, and a DMA resource allocation fails, this
value is assumed to be the address of a function to call at
a later time when resources may become available. When the
specified function is called, it is passed arg as an argu-
ment. The specified callback function must return either
DIDMACALBACKRUNOUT or DIDMACALBACKDONE.
DIDMACALBACKRUNOUT indicates that the callback function
attempted to allocate DMA resources but failed to do so. In
this case the callback function is put back on a list to be
called again later. DIDMACALBACKDONE indicates either a
successful allocation of DMA resources or that the driver no
longer wishes to retry.
The callback function is called in interrupt context. There-
fore, only system functions accessible from interrupt con-
text are be available. The callback function must take what-
ever steps necessary to protect its critical resources, data
structures, queues, etc.
RETURN VALUES
ddidmabufbindhandle() returns:
DIDMAMAPED Successfully allocated resources for
the entire object.
DIDMAPARTIALMAP Successfully allocated resources for
a part of the object. This is accept-
able when partial transfers are per-
mitted by setting the DIDMAPARTIAL
flag in flags.
DIDMAINUSE Another I/O transaction is using the
DMA handle.
SunOS 5.11 Last change: 27 Jul 1996 4
Kernel Functions for Drivers ddidmabufbindhandle(9F)
DIDMANORESOURCES No resources are available at the
present time.
DIDMANOMAPING The object cannot be reached by the
device requesting the resources.
DIDMATOBIG The object is too big. A request of
this size can never be satisfied on
this particular system. The maximum
size varies depending on machine and
configuration.
CONTEXT
ddidmabufbindhandle() can be called from user, kernel,
or interrupt context, except when callback is set to
DIDMASLEP, in which case it can be called from user or
kernel context only.
SEE ALSO
ddidmaaddrbindhandle(9F), ddidmaallochandle(9F),
ddidmafreehandle(9F), ddidmagetwin(9F),
ddidmanextcookie(9F), ddidmasync(9F),
ddidmaunbindhandle(9F), buf(9S), ddidmaattr(9S),
ddidmacookie(9S)
Writing Device Drivers
NOTES
If the driver permits partial mapping with the
DIDMAPARTIAL flag, the number of cookies in each window
may exceed the size of the device's scatter/gather list as
specified in the dmaattrsgllen field in the
ddidmaattr(9S) structure. In this case, each set of cook-
ies comprising a DMA window will satisfy the DMA attributes
as described in the ddidmaattr(9S) structure in all
aspects. The driver should set up its DMA engine and perform
one transfer for each set of cookies sufficient for its
scatter/gather list, up to the number of cookies for this
window, before advancing to the next window using
ddidmagetwin(9F).
SunOS 5.11 Last change: 27 Jul 1996 5
|