DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
SVR5

kmem_alloc(D3)


kmem_alloc -- allocate space from kernel free memory

Synopsis

   #include <sys/types.h>
   #include <sys/kmem.h>
   #include <sys/ddi.h>
   

void *kmem_alloc(size_t size, int flag);

Description

kmem_alloc allocates size bytes of kernel memory and returns a pointer to the allocated memory. If flag is set to KM_SLEEP, the caller will sleep if necessary until the specified amount of memory is available. If flag is set to KM_NOSLEEP, the caller will not sleep, but kmem_alloc will return NULL if the specified amount of memory is not immediately available.

Arguments


size
Number of bytes to allocate.

flag
Specifies whether the caller is willing to sleep waiting for memory.

Return values

Upon successful completion, kem_alloc( ) returns a pointer to the allocated memory. If KM_NOSLEEP is specified and sufficient memory is not immediately available, kmem_alloc( ) returns a NULL pointer. If size is set to 0, kmem_alloc returns NULL, regardless of the value of flag.

The address returned by a successful call to kmem_alloc( ) is word-aligned.

Usage

Drivers should not assume that memory allocated by kmem_alloc( ) is usable for DMA operations, nor should drivers assume that the memory has any specific physical properties such as starting address alignment, physical address range, or physical contiguity.

Context and synchronization

If flag is set to KM_NOSLEEP, non-blockable, initialization, or interrupt context.

If flag is set to KM_SLEEP, user context.

Hardware applicability

All

Version applicability

ddi: 1, 2, 3, 4, 5, 5mp, 6, 6mp, 7, 7mp, 7.1, 7.1mp, 8, 8mp

Differences between versions

In DDI versions 1, 2, 3, 4, 5, and 5mp, the memory returned by kmem_alloc( ) is all below 16MB and thus in the range for 24-bit DMA. In other words, it satisfies worst-case DMA-ability requirements on systems with restricted DMA; see phys_dmasize of physreq(D4). In versions 1, 2, 3, and 4, the memory returned is also physically contiguous, which is required for DMA that does not utilize scatter/gather. For other versions, there are no guarantees on the memory properties.

Beginning with DDI version 6, memory with specific physical properties can be obtained through kmem_alloc_physreq(D3), or kmem_zalloc_physreq(D3). In DDI version 5, contiguous memory with specific physical properties can be obtained through kmem_alloc_physcontig(D3).

The DDI 6, 6mp, 7, and 7mp versions do not know about memory greater than 4GB so the memory allocated by all forms of the kmem_alloc( ) function is below 4GB.

SCO OpenServer ODDI compatibility

On SCO OpenServer, memory allocated with kmem_alloc(D3oddi) is always below the 16MB boundary unless the KM_NO_DMA flag is specified. Only memory that will be accessed by ISA DMA devices needs to be below the 16MB boundary, so when porting from SVR5 to SCO OpenServer, you should usually specify the KM_NO_DMA flag to kmem_alloc( ) calls. Memory allocated by the SCO OpenServer kmem_alloc( ) may or may not be contiguous.

References

kmem_alloc_physcontig(D3), kmem_alloc_physreq(D3), kmem_free(D3), kmem_free_physcontig(D3), kmem_zalloc(D3), kmem_zalloc_physreq(D3), ptob(D3), physreq(D4)

``Memory allocation'' in HDK Technical Reference


19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005