Linux Utils Application Programming Interface (API)  linuxutils-m08
 All Data Structures Files Functions Variables Typedefs Groups Pages
Data Structures | Macros | Typedefs | Functions | Variables
Contiguous Memory Manager

Data Structures

struct  CMEM_AllocParams
 Parameters for CMEM_alloc(), CMEM_alloc2(), CMEM_allocPool(), CMEM_allocPool2(), CMEM_free(). More...
 
struct  CMEM_BlockAttrs
 

Macros

#define CMEM_VERSION   0x04000000U
 
#define MAX_POOLS   32
 
#define CMEM_CMABLOCKID   -1
 
#define CMEM_WB   0x00010000
 
#define CMEM_INV   0x00020000
 
#define CMEM_HEAP   0x00040000
 
#define CMEM_POOL   0x00000000
 
#define CMEM_CACHED   0x00080000
 
#define CMEM_NONCACHED   0x00000000
 
#define CMEM_PHYS   0x00100000
 
#define CMEM_IOCMAGIC   0x0000fe00
 
#define CMEM_IOCALLOC   1
 
#define CMEM_IOCALLOCHEAP   2
 
#define CMEM_IOCFREE   3
 
#define CMEM_IOCGETPHYS   4
 
#define CMEM_IOCGETSIZE   5
 
#define CMEM_IOCGETPOOL   6
 
#define CMEM_IOCCACHE   7
 
#define CMEM_IOCGETVERSION   8
 
#define CMEM_IOCGETBLOCK   9
 
#define CMEM_IOCREGUSER   10
 
#define CMEM_IOCGETNUMBLOCKS   11
 
#define CMEM_IOCCACHEWBINV   CMEM_IOCCACHE | CMEM_WB | CMEM_INV
 
#define CMEM_IOCCACHEWB   CMEM_IOCCACHE | CMEM_WB
 
#define CMEM_IOCCACHEINV   CMEM_IOCCACHE | CMEM_INV
 
#define CMEM_IOCALLOCCACHED   CMEM_IOCALLOC | CMEM_CACHED
 
#define CMEM_IOCALLOCHEAPCACHED   CMEM_IOCALLOCHEAP | CMEM_CACHED
 
#define CMEM_IOCFREEHEAP   CMEM_IOCFREE | CMEM_HEAP
 
#define CMEM_IOCFREEPHYS   CMEM_IOCFREE | CMEM_PHYS
 
#define CMEM_IOCFREEHEAPPHYS   CMEM_IOCFREE | CMEM_HEAP | CMEM_PHYS
 
#define CMEM_IOCCMDMASK   0x000000ff
 

Typedefs

typedef struct CMEM_AllocParams CMEM_AllocParams
 Parameters for CMEM_alloc(), CMEM_alloc2(), CMEM_allocPool(), CMEM_allocPool2(), CMEM_free(). More...
 
typedef struct CMEM_BlockAttrs CMEM_BlockAttrs
 

Functions

int CMEM_init (void)
 Initialize the CMEM module. Must be called before other API calls. More...
 
int CMEM_getPool (size_t size)
 Find the pool that best fits a given buffer size and has a buffer available. More...
 
int CMEM_getPool2 (int blockid, size_t size)
 Find the pool in memory block blockid that best fits a given buffer size and has a buffer available. More...
 
void * CMEM_allocPool (int poolid, CMEM_AllocParams *params)
 Allocate memory from a specified pool. More...
 
void * CMEM_allocPool2 (int blockid, int poolid, CMEM_AllocParams *params)
 Allocate memory from a specified pool in a specified memory block. More...
 
void * CMEM_alloc (size_t size, CMEM_AllocParams *params)
 Allocate memory of a specified size. More...
 
void * CMEM_alloc2 (int blockid, size_t size, CMEM_AllocParams *params)
 Allocate memory of a specified size from a specified memory block. More...
 
off_t CMEM_allocPoolPhys (int poolid, CMEM_AllocParams *params)
 Allocate unmapped memory from a specified pool. More...
 
off_t CMEM_allocPoolPhys2 (int blockid, int poolid, CMEM_AllocParams *params)
 Allocate unmapped memory from a specified pool in a specified memory block. More...
 
off_t CMEM_allocPhys (size_t size, CMEM_AllocParams *params)
 Allocate unmapped memory of a specified size. More...
 
off_t CMEM_allocPhys2 (int blockid, size_t size, CMEM_AllocParams *params)
 Allocate unmapped memory of a specified size from a specified memory block. More...
 
void * CMEM_registerAlloc (off_t physp)
 Register shared usage of an already-allocated buffer. More...
 
int CMEM_free (void *ptr, CMEM_AllocParams *params)
 Free a buffer previously allocated with CMEM_alloc()/CMEM_allocPool(). More...
 
int CMEM_freePhys (off_t physp, CMEM_AllocParams *params)
 Free an unmapped buffer previously allocated with CMEM_allocPhys()/CMEM_allocPoolPhys(). More...
 
int CMEM_unregister (void *ptr, CMEM_AllocParams *params)
 Unregister use of a buffer previously registered with CMEM_registerAlloc(). More...
 
off_t CMEM_getPhys (void *ptr)
 Get the physical address of a contiguous buffer. More...
 
int CMEM_cacheWb (void *ptr, size_t size)
 Do a cache writeback of the block pointed to by ptr/size. More...
 
void * CMEM_map (off_t physp, size_t size)
 Map allocated memory. More...
 
int CMEM_unmap (void *userp, size_t size)
 Unmap allocated memory. More...
 
int CMEM_cacheInv (void *ptr, size_t size)
 Do a cache invalidate of the block pointed to by ptr/size. More...
 
int CMEM_cacheWbInv (void *ptr, size_t size)
 Do a cache writeback/invalidate of the block pointed to by ptr/size. More...
 
int CMEM_getVersion (void)
 Retrieve version from CMEM driver. More...
 
int CMEM_getBlock (off_t *pphys_base, size_t *psize)
 Retrieve memory block bounds from CMEM driver. More...
 
int CMEM_getBlockAttrs (int blockid, CMEM_BlockAttrs *pattrs)
 Retrieve extended memory block attributes from CMEM driver. More...
 
int CMEM_getNumBlocks (int *pnblocks)
 Retrieve number of blocks configured into CMEM driver. More...
 
int CMEM_exit (void)
 Finalize the CMEM module. More...
 

Variables

CMEM_AllocParams CMEM_DEFAULTPARAMS
 

Detailed Description

This is the API for the Contiguous Memory Manager.

Macro Definition Documentation

#define CMEM_VERSION   0x04000000U
#define MAX_POOLS   32
#define CMEM_CMABLOCKID   -1
#define CMEM_WB   0x00010000
#define CMEM_INV   0x00020000
#define CMEM_HEAP   0x00040000

operation applies to heap

#define CMEM_POOL   0x00000000

operation applies to a pool

#define CMEM_CACHED   0x00080000

allocated buffer is cached

#define CMEM_NONCACHED   0x00000000

allocated buffer is not cached

#define CMEM_PHYS   0x00100000
#define CMEM_IOCMAGIC   0x0000fe00
#define CMEM_IOCALLOC   1
#define CMEM_IOCALLOCHEAP   2
#define CMEM_IOCFREE   3
#define CMEM_IOCGETPHYS   4
#define CMEM_IOCGETSIZE   5
#define CMEM_IOCGETPOOL   6
#define CMEM_IOCCACHE   7
#define CMEM_IOCGETVERSION   8
#define CMEM_IOCGETBLOCK   9
#define CMEM_IOCREGUSER   10
#define CMEM_IOCGETNUMBLOCKS   11
#define CMEM_IOCCACHEWBINV   CMEM_IOCCACHE | CMEM_WB | CMEM_INV
#define CMEM_IOCCACHEWB   CMEM_IOCCACHE | CMEM_WB
#define CMEM_IOCCACHEINV   CMEM_IOCCACHE | CMEM_INV
#define CMEM_IOCALLOCCACHED   CMEM_IOCALLOC | CMEM_CACHED
#define CMEM_IOCALLOCHEAPCACHED   CMEM_IOCALLOCHEAP | CMEM_CACHED
#define CMEM_IOCFREEHEAP   CMEM_IOCFREE | CMEM_HEAP
#define CMEM_IOCFREEPHYS   CMEM_IOCFREE | CMEM_PHYS
#define CMEM_IOCFREEHEAPPHYS   CMEM_IOCFREE | CMEM_HEAP | CMEM_PHYS
#define CMEM_IOCCMDMASK   0x000000ff

Typedef Documentation

Function Documentation

int CMEM_init ( void  )

Initialize the CMEM module. Must be called before other API calls.

Returns
0 for success or -1 for failure.
See Also
CMEM_exit
int CMEM_getPool ( size_t  size)

Find the pool that best fits a given buffer size and has a buffer available.

Parameters
sizeThe buffer size for which a pool is needed.
Returns
A poolid that can be passed to CMEM_allocPool(), or -1 for error.
Precondition
Must have called CMEM_init()
See Also
CMEM_allocPool()
CMEM_allocPool2()
CMEM_free()
CMEM_getPool2()
int CMEM_getPool2 ( int  blockid,
size_t  size 
)

Find the pool in memory block blockid that best fits a given buffer size and has a buffer available.

Parameters
blockidBlock number
sizeThe buffer size for which a pool is needed.
Returns
A poolid that can be passed to CMEM_allocPool2(), or -1 for error.
Precondition
Must have called CMEM_init()
See Also
CMEM_allocPool()
CMEM_allocPool2()
CMEM_free()
CMEM_getPool()
void* CMEM_allocPool ( int  poolid,
CMEM_AllocParams params 
)

Allocate memory from a specified pool.

Parameters
poolidThe pool from which to allocate memory.
paramsAllocation parameters.
Remarks
params->type is ignored - a pool will always be used.
params->alignment is unused, since pool buffers are already aligned to specific boundaries.
Returns
A pointer to the allocated buffer, or NULL for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_alloc()
CMEM_alloc2()
CMEM_allocPool2()
CMEM_registerAlloc()
CMEM_unregister()
CMEM_free()
void* CMEM_allocPool2 ( int  blockid,
int  poolid,
CMEM_AllocParams params 
)

Allocate memory from a specified pool in a specified memory block.

Parameters
blockidThe memory block from which to allocate.
poolidThe pool from which to allocate memory.
paramsAllocation parameters.
Remarks
params->type is ignored - a pool will always be used.
params->alignment is unused, since pool buffers are already aligned to specific boundaries.
Returns
A pointer to the allocated buffer, or NULL for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_alloc()
CMEM_alloc2()
CMEM_allocPool()
CMEM_registerAlloc()
CMEM_unregister()
CMEM_free()
void* CMEM_alloc ( size_t  size,
CMEM_AllocParams params 
)

Allocate memory of a specified size.

Parameters
sizeThe size of the buffer to allocate.
paramsAllocation parameters.
Remarks
Used to allocate memory from either a pool, the heap, or the CMA global area. If doing a pool allocation, the pool that best fits the requested size will be selected. Use CMEM_allocPool() to allocate from a specific pool. Allocation will be cached or noncached, as specified by params. params->alignment valid only for heap allocation.
Returns
A pointer to the allocated buffer, or NULL for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_allocPool()
CMEM_allocPool2()
CMEM_alloc2()
CMEM_registerAlloc()
CMEM_unregister()
CMEM_free()
void* CMEM_alloc2 ( int  blockid,
size_t  size,
CMEM_AllocParams params 
)

Allocate memory of a specified size from a specified memory block.

Parameters
blockidThe memory block from which to allocate.
sizeThe size of the buffer to allocate.
paramsAllocation parameters.
Remarks
Used to allocate memory from either a pool, the heap, or the CMA global area. If doing a pool allocation, the pool that best fits the requested size will be selected. Use CMEM_allocPool() to allocate from a specific pool.
Allocation will be cached or noncached, as specified by params. params->alignment valid only for heap allocation.
Returns
A pointer to the allocated buffer, or NULL for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_allocPool()
CMEM_allocPool2()
CMEM_alloc()
CMEM_registerAlloc()
CMEM_unregister()
CMEM_free()
off_t CMEM_allocPoolPhys ( int  poolid,
CMEM_AllocParams params 
)

Allocate unmapped memory from a specified pool.

Parameters
poolidThe pool from which to allocate memory.
paramsAllocation parameters.
Remarks
params->type is ignored - a pool will always be used.
params->alignment is unused, since pool buffers are already aligned to specific boundaries.
Returns
The physical address of the allocated buffer, or NULL for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_allocPhys()
CMEM_allocPhys2()
CMEM_allocPoolPhys2()
CMEM_freePhys()
CMEM_map()
off_t CMEM_allocPoolPhys2 ( int  blockid,
int  poolid,
CMEM_AllocParams params 
)

Allocate unmapped memory from a specified pool in a specified memory block.

Parameters
blockidThe memory block from which to allocate.
poolidThe pool from which to allocate memory.
paramsAllocation parameters.
Remarks
params->type is ignored - a pool will always be used.
params->alignment is unused, since pool buffers are already aligned to specific boundaries.
Returns
The physical address of the allocated buffer, or NULL for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_allocPhys()
CMEM_allocPhys2()
CMEM_allocPoolPhys()
CMEM_freePhys()
CMEM_map()
off_t CMEM_allocPhys ( size_t  size,
CMEM_AllocParams params 
)

Allocate unmapped memory of a specified size.

Parameters
sizeThe size of the buffer to allocate.
paramsAllocation parameters.
Remarks
Used to allocate memory from either a pool, the heap, or the CMA global area. If doing a pool allocation, the pool that best fits the requested size will be selected. Use CMEM_allocPool() to allocate from a specific pool. Allocation will be cached or noncached, as specified by params. params->alignment valid only for heap allocation.
Returns
The physical address of the allocated buffer, or NULL for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_allocPoolPhys()
CMEM_allocPoolPhys2()
CMEM_allocPhys2()
CMEM_freePhys()
CMEM_map()
off_t CMEM_allocPhys2 ( int  blockid,
size_t  size,
CMEM_AllocParams params 
)

Allocate unmapped memory of a specified size from a specified memory block.

Parameters
blockidThe memory block from which to allocate.
sizeThe size of the buffer to allocate.
paramsAllocation parameters.
Remarks
Used to allocate memory from either a pool, the heap, or the CMA global area. If doing a pool allocation, the pool that best fits the requested size will be selected. Use CMEM_allocPool() to allocate from a specific pool.
Allocation will be cached or noncached, as specified by params. params->alignment valid only for heap allocation.
Returns
The physical address of the allocated buffer, or NULL for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_allocPoolPhys()
CMEM_allocPoolPhys2()
CMEM_allocPhys()
CMEM_freePhys()
CMEM_map()
void* CMEM_registerAlloc ( off_t  physp)

Register shared usage of an already-allocated buffer.

Parameters
physpPhysical address of the already-allocated buffer.
Remarks
Used to register the calling process for usage of an already-allocated buffer, for the purpose of shared usage of the buffer.
Allocation properties (such as cached/noncached or heap/pool) are inherited from original allocation call.
Returns
A process-specific pointer to the allocated buffer, or NULL for failure.
Precondition
Must have called some form of CMEM_alloc*()
See Also
CMEM_allocPool()
CMEM_allocPool2()
CMEM_alloc()
CMEM_free()
CMEM_unregister()
int CMEM_free ( void *  ptr,
CMEM_AllocParams params 
)

Free a buffer previously allocated with CMEM_alloc()/CMEM_allocPool().

Parameters
ptrThe pointer to the buffer.
paramsAllocation parameters.
Remarks
Use the same CMEM_AllocParams as was used for the allocation. params->flags is "don't care". params->alignment is "don't care".
Returns
0 for success or -1 for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_alloc()
CMEM_alloc2()
CMEM_allocPool()
CMEM_allocPool2()
CMEM_registerAlloc()
CMEM_unregister()
int CMEM_freePhys ( off_t  physp,
CMEM_AllocParams params 
)

Free an unmapped buffer previously allocated with CMEM_allocPhys()/CMEM_allocPoolPhys().

Parameters
physpThe physical address of the buffer.
paramsAllocation parameters.
Remarks
Use the same CMEM_AllocParams as was used for the allocation. params->flags is "don't care". params->alignment is "don't care".
Returns
0 for success or -1 for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_allocPhys()
CMEM_allocPhys2()
CMEM_allocPoolPhys()
CMEM_allocPoolPhys2()
CMEM_unmap()
int CMEM_unregister ( void *  ptr,
CMEM_AllocParams params 
)

Unregister use of a buffer previously registered with CMEM_registerAlloc().

Parameters
ptrThe pointer to the buffer.
paramsAllocation parameters.
Remarks
Use the same CMEM_AllocParams as was used for the allocation. params->flags is "don't care". params->alignment is "don't care".
Returns
0 for success or -1 for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_alloc()
CMEM_alloc2()
CMEM_allocPool()
CMEM_allocPool2()
CMEM_registerAlloc()
CMEM_free()
off_t CMEM_getPhys ( void *  ptr)

Get the physical address of a contiguous buffer.

Parameters
ptrThe pointer to the buffer.
Returns
The physical address of the buffer or 0 for failure.
Precondition
Must have called CMEM_init()
int CMEM_cacheWb ( void *  ptr,
size_t  size 
)

Do a cache writeback of the block pointed to by ptr/size.

Parameters
ptrPointer to block to writeback
sizeSize in bytes of block to writeback.
Returns
Success/failure boolean value
Precondition
Must have called CMEM_init()
See Also
CMEM_cacheInv()
CMEM_cacheWbInv()
void* CMEM_map ( off_t  physp,
size_t  size 
)

Map allocated memory.

Parameters
physpPhysical address of the already-allocated buffer.
sizeSize in bytes of block to map.
Returns
A pointer to the mapped buffer, or NULL for failure.
Precondition
Must have called CMEM_init()
See Also
CMEM_allocPhys()
CMEM_allocPoolPhys()
CMEM_unmap()
int CMEM_unmap ( void *  userp,
size_t  size 
)

Unmap allocated memory.

Parameters
userpUser virtual address of the mapped buffer.
sizeSize in bytes of block to unmap.
Returns
Success/failure boolean value
Precondition
Must have called CMEM_init()
See Also
CMEM_freePhys()
CMEM_map()
int CMEM_cacheInv ( void *  ptr,
size_t  size 
)

Do a cache invalidate of the block pointed to by ptr/size.

Parameters
ptrPointer to block to invalidate
sizeSize in bytes of block to invalidate
Returns
Success/failure boolean value
Precondition
Must have called CMEM_init()
See Also
CMEM_cacheWb()
CMEM_cacheWbInv()
int CMEM_cacheWbInv ( void *  ptr,
size_t  size 
)

Do a cache writeback/invalidate of the block pointed to by ptr/size.

Parameters
ptrPointer to block to writeback/invalidate
sizeSize in bytes of block to writeback/invalidate
Returns
Success/failure boolean value
Precondition
Must have called CMEM_init()
See Also
CMEM_cacheInv()
CMEM_cacheWb()
int CMEM_getVersion ( void  )

Retrieve version from CMEM driver.

Returns
Installed CMEM driver's version number.
Precondition
Must have called CMEM_init()
int CMEM_getBlock ( off_t *  pphys_base,
size_t *  psize 
)

Retrieve memory block bounds from CMEM driver.

Parameters
pphys_basePointer to storage for base physical address of CMEM's memory block
psizePointer to storage for size of CMEM's memory block
Returns
Success (0) or failure (-1).
Precondition
Must have called CMEM_init()
See Also
CMEM_getBlockAttrs()
CMEM_getNumBlocks()
int CMEM_getBlockAttrs ( int  blockid,
CMEM_BlockAttrs pattrs 
)

Retrieve extended memory block attributes from CMEM driver.

Parameters
blockidBlock number
pattrsPointer to CMEM_BlockAttrs struct
Returns
Success (0) or failure (-1).
Remarks
Currently this API returns the same values as CMEM_getBlock().
Precondition
Must have called CMEM_init()
See Also
CMEM_getBlock()
CMEM_getNumBlocks()
int CMEM_getNumBlocks ( int *  pnblocks)

Retrieve number of blocks configured into CMEM driver.

Parameters
pnblocksPointer to storage for holding number of blocks
Returns
Success (0) or failure (-1).
Remarks
Blocks are configured into CMEM through the Linux 'insmod' command.
Precondition
Must have called CMEM_init()
See Also
CMEM_getBlock()
CMEM_getBlockAttrs()
int CMEM_exit ( void  )

Finalize the CMEM module.

Returns
0 for success or -1 for failure.
Remarks
After this function has been called, no other CMEM function may be called (unless CMEM is reinitialized).
Precondition
Must have called CMEM_init()
See Also
CMEM_init()

Variable Documentation

CMEM_AllocParams CMEM_DEFAULTPARAMS
Copyright 2013, Texas Instruments Incorporated