HAP Memory APIs. More...
#include <stdlib.h>
#include "AEEStdDef.h"
#include "AEEStdErr.h"
Go to the source code of this file.
Classes | |
struct | HAP_mem_stats |
Statistics of user heap memory. More... | |
struct | HAP_mem_heap_info_t |
RequestID/Response for HAP_mem_get_heap_info. More... | |
Macros | |
HAP_PROT | |
These macros define the permissions on memory block described by the file descriptor. It is passed as input parameter 'prot' to HAP_mmap(). These can be ORed to set the required permissions. | |
#define | HAP_PROT_NONE 0x00 /* no permissions */ |
Passing HAP_PROT_NONE as input results in setting 'NO' permissions on the buffer. | |
#define | HAP_PROT_READ 0x01 /* pages can be read */ |
Passing HAP_PROT_READ as input results in setting 'Read' permissions on the buffer. | |
#define | HAP_PROT_WRITE 0x02 /* pages can be written */ |
Passing HAP_PROT_WRITE as input results in setting 'Write' permissions on the buffer. | |
#define | HAP_PROT_EXEC 0x04 /* pages can be executed */ |
Passing HAP_PROT_EXEC as input results in setting 'Execute' permissions on the buffer. Currently not supported. | |
HAP_MEM_CACHE | |
These macros define the cache policies for mapping memory pages to DSP MMU. Default cache policy is cache writeback. It is passed as input parameter 'prot', or-ed with page protections to HAP_mmap(). | |
#define | HAP_MEM_CACHE_WRITEBACK (0x10) /* cache write back */ |
Passing HAP_MEM_CACHE_WRITEBACK as input results in mapping memory as cache writeback. | |
#define | HAP_MEM_CACHE_NON_SHARED (0x20) /* normal uncached memory */ |
Passing HAP_MEM_CACHE_NON_SHARED as input results in mapping memory as uncached. | |
#define | HAP_MEM_CACHE_WRITETHROUGH (0x40) /* write through memory */ |
Passing HAP_MEM_CACHE_WRITETHROUGH as input results in mapping memory as cache write through. | |
HAP_MEM_FLAGS | |
These macros define the buffer attribute flags for allocating APPS memory from the DSP. It is passed as input parameter 'flags' to HAP_apps_mem_request(). | |
#define | HAP_MEM_FLAGS_SKIP_DSP_MAP 0 |
Allocate memory on HLOS but skip DSP mapping. | |
#define | HAP_MEM_FLAGS_DSP_MAP 1 |
Allocate memory on HLOS and map on DSP. | |
#define | HAP_MEM_FLAGS_EXTENDED_MAP 2 |
Allocate memory on HLOS and map beyond 4GB virtual address range on DSP. More... | |
#define | HAP_MEM_FLAGS_MAX (HAP_MEM_FLAGS_EXTENDED_MAP + 1) |
Max number of flags supported by HAP_apps_mem_request. | |
Enumerations | |
enum | HAP_mem_stats_request { USAGE_STATS = 1, MAX_USED } |
Enum for reqID for HAP_mem_get_heap_info() | |
Functions | |
static int | HAP_malloc (uint32 bytes, void **pptr) |
static int | HAP_free (void *ptr) |
int | HAP_mem_get_stats (struct HAP_mem_stats *stats) |
int | HAP_mem_get_heap_info (HAP_mem_heap_info_t *payload) |
int | HAP_mem_set_grow_size (uint64 min, uint64 max) |
int | HAP_mem_set_heap_thresholds (unsigned int low_largest_block_size, unsigned int high_largest_block_size) |
void * | HAP_mmap (void *addr, int len, int prot, int flags, int fd, long offset) |
void * | HAP_mmap2 (void *addr, size_t len, int prot, int flags, int fd, long offset) |
int | HAP_munmap (void *addr, int len) |
int | HAP_munmap2 (void *addr, size_t len) |
int | HAP_mmap_get (int fd, void **vaddr, uint64 *paddr) |
int | HAP_mmap_put (int fd) |
uint64 | HAP_mem_available_stack (void) |
int | HAP_apps_mem_request (size_t len, uint32_t flags, int *fd, uint64_t *dsp_va) |
int | HAP_apps_mem_release (int fd) |
HAP Memory APIs.
#define HAP_MEM_FLAGS_EXTENDED_MAP 2 |
Allocate memory on HLOS and map beyond 4GB virtual address range on DSP.
Unsupported currently. Reserved for future use.
int HAP_apps_mem_release | ( | int | fd | ) |
Release previously allocated APPS memory from DSP. Releases memory from HLOS. Also unmaps memory from DSP if HAP_MEM_FLAGS_DSP_MAP was previously passed while requesting memory.
[in] | fd | previously returned file descriptor of buffer |
int HAP_apps_mem_request | ( | size_t | len, |
uint32_t | flags, | ||
int * | fd, | ||
uint64_t * | dsp_va | ||
) |
Allocate and map APPS memory from DSP
Usage of this API over malloc() is recommended when client wants greater control over DSP virtual address space as free() does not necessarily free the allocated memory depending on heap thresholds. HAP_apps_mem_request and HAP_apps_mem_release guarantee freeing of the allocated memory.
[in] | len | size of memory to be allocated |
[in] | flags | Buffer attribute flags HAP_MEM_FLAGS_SKIP_DSP_MAP, HAP_MEM_FLAGS_DSP_MAP or HAP_MEM_FLAGS_EXTENDED_MAP |
[out] | fd | file descriptor of buffer |
[out] | dsp_va | DSP mapped virtual address |
|
inlinestatic |
Free the memory block allocated through HAP_malloc().
[in] | ptr | pointer to the memory block |
|
inlinestatic |
Allocate a block of memory.
[in] | bytes | size of memory block in bytes. |
[out] | pptr | pointer to the memory block |
uint64 HAP_mem_available_stack | ( | void | ) |
Get the stack size (in bytes) available for current thread Supported only on Lahaina and Cedros
int HAP_mem_get_heap_info | ( | HAP_mem_heap_info_t * | payload | ) |
Get the heap info.
payload,pointer | to store the request/response |
int HAP_mem_get_stats | ( | struct HAP_mem_stats * | stats | ) |
Get the current statistics from the heap.
[in,out] | stats | pointer to stats structure |
AEE_SUCCESS |
int HAP_mem_set_grow_size | ( | uint64 | min, |
uint64 | max | ||
) |
Set the minimum and maximum size by which the user heap should grow when it is exhausted and needs to add memory from the HLOS on the Apps processor.
This API allows to configure the minimum and maximum size that should be added to the DSP user heap when an allocation fails and more memory needs to be obtained from the HLOS. Using this API is optional. If not used, the runtime will try to choose reasonable growth sizes based on allocation history.
[in] | min | minimum bytes to grow the heap by when requesting a new segment |
[in] | max | maximum bytes to grow the heap by when requesting a new segment |
AEE_SUCCESS |
int HAP_mem_set_heap_thresholds | ( | unsigned int | low_largest_block_size, |
unsigned int | high_largest_block_size | ||
) |
Set low and high memory thresholds for heap
Thresholds must be tuned according to the memory requirements
Improper thresholds might led to heap failure
[in] | low_largest_block_size | (in bytes) - the heap will grow if size of the largest free block is less than this threshold. Currently, setting this parameter will have no impact on the heap. |
[in] | high_largest_block_size | (in bytes) - the heap manager will release all unused sections if size of the largest free block is greater than this threshold. The recommended value for this, is the size of largest single allocation possible in your application. |
void* HAP_mmap | ( | void * | addr, |
int | len, | ||
int | prot, | ||
int | flags, | ||
int | fd, | ||
long | offset | ||
) |
Map buffer associated with the file descriptor to DSP memory. The reference count gets incremented if the file descriptor is already mapped. This API is limited to buffer size less then 2 GB. Recommendation is to use HAP_mmap2 for buffer of size > 2 power(8*sizeof(size_t))
[in] | addr | mapping at fixed address, not supported currently. This has to be set to NULL |
[in] | len | size of the buffer to be mapped |
[in] | prot | protection flags - supported are only HAP_PROT_READ and HAP_PROT_WRITE. HAP_PROT_EXEC is not supported |
[in] | flags | HAP_MAP_NO_MAP - Increment reference count with no mapping 0 - map the buffer and increment the reference count |
[in] | fd | file descriptor for the buffer |
[in] | offset | offset into the buffer |
mapped | address -1 on failure |
void* HAP_mmap2 | ( | void * | addr, |
size_t | len, | ||
int | prot, | ||
int | flags, | ||
int | fd, | ||
long | offset | ||
) |
Map buffer associated with the file descriptor to DSP memory. The reference count gets incremented if the file descriptor is already mapped.
[in] | addr | mapping at fixed address, not supported currently. This has to be set to NULL |
[in] | len | size of the buffer to be mapped |
[in] | prot | protection flags - supported are only HAP_PROT_READ and HAP_PROT_WRITE. HAP_PROT_EXEC is not supported |
[in] | flags | HAP_MAP_NO_MAP - Increment reference count with no mapping 0 - map the buffer and increment the reference count |
[in] | fd | file descriptor for the buffer |
[in] | offset | offset into the buffer |
mapped | address -1 on failure |
int HAP_mmap_get | ( | int | fd, |
void ** | vaddr, | ||
uint64 * | paddr | ||
) |
Get virtual and physical address associated with the buffer and increments the reference count.
[in] | fd | file descriptor for the buffer |
[out] | vaddr | virtual address associated with the buffer |
[out] | paddr | physical address associated with the buffer |
0 | on success AEE_ENOSUCHMAP if fd is invalid |
int HAP_mmap_put | ( | int | fd | ) |
Decrements the reference count of the file descriptor.
[in] | fd | file descriptor of the buffer |
0 | on success AEE_ENOSUCHMAP if fd is invalid AEE_EBADMAPREFCNT if map refcount is <=0 |
int HAP_munmap | ( | void * | addr, |
int | len | ||
) |
Decrements the reference count and unmaps the buffer from memory if the reference count goes to 0. This API is used for buffer size less then 2 GB. Recommendation is to use HAP_munmap2 for buffer of size > 2 power(8*sizeof(size_t)).
[in] | addr | mapped address |
[in] | len | size of the mapped buffer |
int HAP_munmap2 | ( | void * | addr, |
size_t | len | ||
) |
Decrements the reference count and unmaps the buffer from memory if the reference count goes to 0.
[in] | addr | mapped address |
[in] | len | size of the mapped buffer |