| Samsung Internal API reference 2.0

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

Typedefs | Enumerations | Functions
Contiguous memory API
Samsung Internal API

## Typedefs
typedef struct __TEES_ContiguousMemoryHandle * | TEES_ContiguousMemoryHandle

## Enumerations
enum | TEES_ContiguousAllocateFlags { TEES_CONTIGUOUS_FLAG_ZERO_ON_FREE = (1U << 0), TEES_CONTIGUOUS_FLAG_ZERO_ON_ALLOC = (1U << 1) }
| Determines the desired allocated memory handle properties. More...
enum | TEES_ContiguousMapFlags { TEES_CONTIGUOUS_MAP_READ = (1U << 0), TEES_CONTIGUOUS_MAP_WRITE = (1U << 1), TEES_CONTIGUOUS_MAP_NON_CACHEABLE = (1U << 2), TEES_CONTIGUOUS_MAP_FIXED = (1U << 3), TEES_CONTIGUOUS_MAP_POPULATE = (1U << 4) }
| Determines the desired mapping properties. More...

## Functions
TEE_Result | TEES_AllocateContiguousMemory (const char *region, size_t size, size_t align, uint32_t flags, TEES_ContiguousMemoryHandle *memory)
| Allocates physically contiguous memory buffer handle of the specified region type. More...
void | TEES_ReleaseContiguousMemory (TEES_ContiguousMemoryHandle memory)
| Releases physically contiguous memory buffer that was previously allocated by TEES_AllocateContiguousMemory. More...
TEE_Result | TEES_MapContiguousMemory (TEES_ContiguousMemoryHandle memory, void **addr, uint32_t flags)
| Maps physically contiguous memory buffer previously allocated by TEES_AllocateContiguousMemory into the address space of current process. More...
void | TEES_UnmapContiguousMemory (void *addr)
| Unmaps physically contiguous memory buffer that was previously mapped by TEES_MapContiguousMemory. More...
TEE_Result | TEES_GetContiguousMemoryPhysaddr (TEES_ContiguousMemoryHandle memory, uint64_t *physaddr)
| Retrieves physical address of physically contiguous memory buffer that was previously allocated by TEES_AllocateContiguousMemory. More...

## Detailed Description

Provides set of functions to manipulate secure contiguous memory allocator.

## Typedef Documentation

TEES_ContiguousMemoryHandle

`#include <scma.h>`

SCMA handle abstraction

## Enumeration Type Documentation

enum TEES_ContiguousAllocateFlags

`#include <scma.h>`

Determines the desired allocated memory handle properties.

Enumerator
TEES_CONTIGUOUS_FLAG_ZERO_ON_FREE | Allocated memory will be zeroed on free.
TEES_CONTIGUOUS_FLAG_ZERO_ON_ALLOC | Allocated memory will be zeroed on allocate.

enum TEES_ContiguousMapFlags

`#include <scma.h>`

Determines the desired mapping properties.

Enumerator
TEES_CONTIGUOUS_MAP_READ | Map memory with read permission.
TEES_CONTIGUOUS_MAP_WRITE | Map memory with write permission.
TEES_CONTIGUOUS_MAP_NON_CACHEABLE | Map memory as non-cacheable.
TEES_CONTIGUOUS_MAP_FIXED | Don't interpret addr as a hint: place the mapping at exactly that address. addr must be a multiple of alignment (maximum of alignment specified in region properties and allocate function). If addr is not aligned or addr + size (specifiead on alloc) overlaps existing mapping function fails. If this flag is passed and addr is NULL function fails.
TEES_CONTIGUOUS_MAP_POPULATE | Do not use lazy mapping.

## Function Documentation

TEE_Result TEES_AllocateContiguousMemory | ( | const char * | region,
|  | size_t | size,
|  | size_t | align,
|  | uint32_t | flags,
|  | TEES_ContiguousMemoryHandle * | memory
| ) |  |

`#include <scma.h>`

Allocates physically contiguous memory buffer handle of the specified region type.

Parameters

  [in] | region | A pointer to the zero-terminated string containing region type name of the contiguous memory region to allocate buffer from.
  [in] | size | The size in bytes of the buffer to be allocated.
  [in] | align | The minimal alignment requirement of starting address and size in bytes. Must be the power of 2.
  [in] | flags | Determines the desired allocated memory handle properties. Containing zero or more bitwise ORed flags from the following list: TEES_CONTIGUOUS_FLAG_ZERO_ON_FREE: allocated memory will be zeroed on free. TEES_CONTIGUOUS_FLAG_ZERO_ON_ALLOC: allocated memory will be zeroed on allocate.
  [out] | memory | Filled with a handle on the allocated memory.

Return values

  TEE_SUCCESS | in case of success
  TEE_ERROR_ACCESS_DENIED | If this API is prohibited for use by current TA.
  TEE_ERROR_ITEM_NOT_FOUND | If the region is not found or access to that region is denied for this TA.
  TEE_ERROR_OUT_OF_MEMORY | If there are not enough contiguous memory of the requested region type.
  TEE_ERROR_ACCESS_CONFLICT | If requested flags are incompatible with flags specified in region configuration.
  TEE_ERROR_BAD_PARAMETERS | If requested size is not Page-aligned, if align is not power of 2 or if called with unknown flags.

Example:

static TEES_ContiguousMemoryHandle handle;
static int test_allocate_contiguous_memory(void)
{
TEE_Result ret;
const size_t size = 1024 * 1024;
const size_t align = 0x1000;
const uint32_t flags = TEES_CONTIGUOUS_FLAG_ZERO_ON_ALLOC;
ret = TEES_AllocateContiguousMemory("region_name", size, align, flags, &handle);
if (ret != TEE_SUCCESS) {
return -1;
}
return 0;
}

TEE_Result TEES_GetContiguousMemoryPhysaddr | ( | TEES_ContiguousMemoryHandle | memory,
|  | uint64_t * | physaddr
| ) |  |

`#include <scma.h>`

Retrieves physical address of physically contiguous memory buffer that was previously allocated by TEES_AllocateContiguousMemory.

Parameters

  [in] | memory | A handle on the previously allocated memory.
  [out] | physaddr | Filled with the physical address of the allocated memory assigned to handle.

Return values

  TEE_SUCCESS | in case of success
  TEE_ERROR_ACCESS_DENIED | If this API is prohibited for use by current TA.

Example:

static TEES_ContiguousMemoryHandle handle;
static uint64_t physaddr;
static int test_get_contiguous_memory_physaddr(void)
{
TEE_Result ret;
ret = TEES_GetContiguousMemoryPhysaddr(memory, &physaddr);
if (ret != TEE_SUCCESS) {
return -1;
}
return 0;
}

TEE_Result TEES_MapContiguousMemory | ( | TEES_ContiguousMemoryHandle | memory,
|  | void ** | addr,
|  | uint32_t | flags
| ) |  |

`#include <scma.h>`

Maps physically contiguous memory buffer previously allocated by TEES_AllocateContiguousMemory into the address space of current process.

Parameters

  [in] | memory | A handle on the previously allocated memory.
  [in,out] | addr | On input filled with a hint address at which memory is to be mapped. If filled by NULL address is chosen automatically. If function success on output contains address of the mapped area.
  [in] | flags | Determines the desired mapping properties. Containing at least TEES_CONTIGUOUS_MAP_READ or TEES_CONTIGUOUS_MAP_WRITE and the bitwise OR of zero or more of the following flags: TEES_CONTIGUOUS_MAP_NON_CACHEABLE: map memory as non-cacheable. TEES_CONTIGUOUS_MAP_READ: map memory with read permission. TEES_CONTIGUOUS_MAP_WRITE: map memory with write permission. TEES_CONTIGUOUS_MAP_FIXED: Don't interpret addr as a hint: place the mapping at exactly that address. addr must be a multiple of alignment (maximum of alignment specified in region properties and allocate function). If addr is not aligned or addr + size (specifiead on alloc) overlaps existing mapping function fails. If this flag is passed and addr is NULL function fails. TEES_CONTIGUOUS_MAP_POPULATE: do not use lazy mapping.

Return values

  TEE_SUCCESS | in case of success
  TEE_ERROR_OUT_OF_MEMORY | If there are not enough virtual memory to make mapping or it can't be mapped at fixed hint.
  TEE_ERROR_ACCESS_CONFLICT | If requested flags are incompatible with flags specified in region configuration or during alloc.
  TEE_ERROR_BAD_PARAMETERS | If requested flags don’t have TEES_CONTIGUOUS_MAP_READ or TEES_CONTIGUOUS_MAP_WRITE or contains unknown bits set.

Example:

static TEES_ContiguousMemoryHandle handle;
static void *addr;
static int test_map_contiguous_memory(void)
{
TEE_Result ret;
const uint32_t flags = TEES_CONTIGUOUS_MAP_READ;
ret = TEES_MapContiguousMemory(handle, &addr, flags);
if (ret != TEE_SUCCESS) {
return -1;
}
return 0;
}

void TEES_ReleaseContiguousMemory | ( | TEES_ContiguousMemoryHandle | memory | ) |

`#include <scma.h>`

Releases physically contiguous memory buffer that was previously allocated by TEES_AllocateContiguousMemory.

Parameters

  [in] | memory | Handle of the allocated memory to release.

Example:

static TEES_ContiguousMemoryHandle handle;
static void test_release_contiguous_memory(void)
{
TEES_ReleaseContiguousMemory(handle);
}

void TEES_UnmapContiguousMemory | ( | void * | addr | ) |

`#include <scma.h>`

Unmaps physically contiguous memory buffer that was previously mapped by TEES_MapContiguousMemory.

Parameters

  [in] | addr | Address at which contiguous memory buffer was mapped.

Example:

static void *addr;
static void test_unmap_contiguous_memory(void)
{
TEES_UnmapContiguousMemory(addr);
}