SCO OpenServer
db_alloc(D3oddi)
db_alloc, db_free --
allocate and free physically contiguous memory
Synopsis
#include <sys/devbuf.h>
int db_alloc(struct devbuf *dv);
int db_free(struct devbuf *dv)
Description
db_alloc allocates physically contiguous memory
necessary for performing DMA transfers.
It was used by tape drives and other devices
tha need large amounts of memory for buffers.
db_free releases the previously allocated memory.
Arguments
dv-
Pointer to a devbuf structure,
defined in the <sys/devbuf.h> header file as:
struct devbuf {
paddr_t bufptr; /* pointer to start of buffer */
paddr_t bufend; /* pointer to end of buffer */
long size; /* size of buffer */
paddr_t head; /* put buffer data here */
paddr_t tail; /* get buffer data here */
}
Except for size
,
all members of the devbuf structure are read-only.
Set the size
member of the devbuf structure
to the block size required before calling db_alloc.
Return values
db_alloc returns zero (0) if no memory is available;
otherwise, 1 is returned.
db_free always returns zero (0).
Usage
Use the
db_read(D3oddi)
and
db_write(D3oddi)
functions to read from and write to
memory areas allocated with
db_alloc(D3oddi).
Context and synchronization
User or blockable
context.
Hardware applicability
All
Version applicability
oddi:
1, 2
Differences between versions
Current drivers should call the
getcpages(D3oddi)
function to allocate DMAable memory.
See
``Memory allocation'' in HDK Technical Reference
for a list of other facilities
that can be used to allocate memory.
SVR5 DDI compatibility
This function is not supported in DDI.
Instead, populate a
physreq(D4)
structure,
call the
physreq_alloc(D3)
and
physreq_prep(D3)
functions to allocate and prepare the physreq structure,
then allocate the memory with
kmem_alloc_phys(D3),
kmem_alloc_physreq(D3),
or
kmem_zalloc_physreq(D3)
function.
See
``Memory allocation'' in HDK Technical Reference
for more information about DDI facilities
for allocating memory.
References
db_read(D3oddi),
db_write(D3oddi)
``Memory allocation'' in HDK Technical Reference
Examples
The following example allocates a single 120K buffer:
struct devbuf dv;
dv.size = (long) (120 * 1024); /* 120K bytes */
if (db_alloc(&dv) == 0) {
cmn_err(CE_NOTE, "db_alloc failed");
return(-1);
}
The following example releases previously allocated memory:
struct devbuf dv;
db_free(&dv);
19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 5 HDK - June 2005