TIOVX User Guide
tivx_mem.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright (c) 2017-2019 Texas Instruments Incorporated
4 *
5 * All rights reserved not granted herein.
6 *
7 * Limited License.
8 *
9 * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
10 * license under copyrights and patents it now or hereafter owns or controls to make,
11 * have made, use, import, offer to sell and sell ("Utilize") this software subject to the
12 * terms herein. With respect to the foregoing patent license, such license is granted
13 * solely to the extent that any such patent is necessary to Utilize the software alone.
14 * The patent license shall not apply to any combinations which include this software,
15 * other than combinations with devices manufactured by or for TI ("TI Devices").
16 * No hardware patent is licensed hereunder.
17 *
18 * Redistributions must preserve existing copyright notices and reproduce this license
19 * (including the above copyright notice and the disclaimer and (if applicable) source
20 * code license limitations below) in the documentation and/or other materials provided
21 * with the distribution
22 *
23 * Redistribution and use in binary form, without modification, are permitted provided
24 * that the following conditions are met:
25 *
26 * * No reverse engineering, decompilation, or disassembly of this software is
27 * permitted with respect to any software provided in binary form.
28 *
29 * * any redistribution and use are licensed by TI for use only with TI Devices.
30 *
31 * * Nothing shall obligate TI to provide you with source code for the software
32 * licensed and provided to you in object code.
33 *
34 * If software source code is provided to you, modification and redistribution of the
35 * source code are permitted provided that the following conditions are met:
36 *
37 * * any redistribution and use of the source code, including any resulting derivative
38 * works, are licensed by TI for use only with TI Devices.
39 *
40 * * any redistribution and use of any object code compiled from the source code
41 * and any resulting derivative works, are licensed by TI for use only with TI Devices.
42 *
43 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers
44 *
45 * may be used to endorse or promote products derived from this software without
46 * specific prior written permission.
47 *
48 * DISCLAIMER.
49 *
50 * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
51 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53 * IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
55 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
57 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
58 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
59 * OF THE POSSIBILITY OF SUCH DAMAGE.
60 *
61 */
62 
63 
64 
65 
66 #ifndef TIVX_MEM_H_
67 #define TIVX_MEM_H_
68 
69 #include <VX/vx.h>
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
86 typedef enum _tivx_mem_heap_region_e
87 {
94 
101 
121 
141 
149 
164 
166 
170 typedef enum _tivx_memory_type_e {
174 
180 typedef struct _tivx_shared_mem_ptr_t {
181 
183  volatile uint32_t mem_heap_region;
184 
188  volatile int32_t dma_buf_fd;
189 
194  volatile uint64_t shared_ptr;
195 
200  volatile uint64_t host_ptr;
201 
205  volatile uint32_t dma_buf_fd_offset;
206 
207  /* Padding to align to 64 bytes */
208  volatile uint32_t rsv[1];
209 
211 
217 typedef struct _tivx_mem_stats_t {
218 
223 
228 
230 
240 vx_status tivxMemBufferAlloc(tivx_shared_mem_ptr_t *mem_ptr, uint32_t size, vx_enum mem_heap_region);
241 
250 vx_status tivxMemBufferFree(tivx_shared_mem_ptr_t *mem_ptr, uint32_t size);
251 
266 vx_status tivxMemBufferMap(void *host_ptr, uint32_t size, vx_enum mem_type, vx_enum maptype);
267 
284 vx_status tivxMemBufferUnmap(void *host_ptr, uint32_t size, vx_enum mem_type, vx_enum maptype);
285 
296 uint64_t tivxMemHost2SharedPtr(uint64_t host_ptr, vx_enum mem_heap_region);
297 
307 void* tivxMemShared2TargetPtr(const tivx_shared_mem_ptr_t *shared_ptr);
308 
320 uint64_t tivxMemShared2PhysPtr(uint64_t shared_ptr, vx_enum mem_heap_region);
321 
332 void *tivxMemAlloc(vx_uint32 size, vx_enum mem_heap_region);
333 
343 void tivxMemFree(void *ptr, vx_uint32 size, vx_enum mem_heap_region);
344 
353 void tivxMemStats(tivx_mem_stats *stats, vx_enum mem_type);
354 
364 int32_t tivxMemResetScratchHeap(vx_enum mem_heap_region);
365 
384 vx_status tivxMemTranslateVirtAddr(const void *virtAddr, uint64_t *fd, void **phyAddr);
385 
406 vx_status tivxMemTranslateFd(uint64_t dmaBufFd, uint32_t size, void **virtAddr, void **phyAddr);
407 
416 void tivxEnableL1DandL2CacheWb(void);
417 
418 #ifdef __cplusplus
419 }
420 #endif
421 
422 #endif
tivx_mem_heap_region_e
Enum that list all possible memory regions from which allocations are possible.
Definition: tivx_mem.h:86
tivx_memory_type_e
An enumeration of TI extension memory import types.
Definition: tivx_mem.h:170
int32_t tivxMemResetScratchHeap(vx_enum mem_heap_region)
Reset scratch memory.
int32_t vx_enum
void tivxMemFree(void *ptr, vx_uint32 size, vx_enum mem_heap_region)
Frees already allocated memory.
vx_status tivxMemTranslateFd(uint64_t dmaBufFd, uint32_t size, void **virtAddr, void **phyAddr)
Translates a given file descriptor to a virtual and physical addresss. The following conditions regar...
vx_status tivxMemTranslateVirtAddr(const void *virtAddr, uint64_t *fd, void **phyAddr)
Translates a given virtual address to a file descriptor and a physical address. The following conditi...
vx_uint32 mem_size
Total size of memory segment Set to 0 when memory segment size cannot be determined.
Definition: tivx_mem.h:222
VX_ID_TI
vx_enum vx_status
#define VX_ENUM_BASE(vendor, id)
External persistent non cachable memory.
Definition: tivx_mem.h:156
void tivxEnableL1DandL2CacheWb(void)
For J784S4, the C7X cache coherency model is different than other Jacinto SoC&#39;s. While other SoC&#39;s C7...
void * tivxMemAlloc(vx_uint32 size, vx_enum mem_heap_region)
Allocates memory of given size.
External scratch non cachable memory.
Definition: tivx_mem.h:163
External memory.
Definition: tivx_mem.h:93
External scratch memory.
Definition: tivx_mem.h:148
Memory type when a DMA will access the memory rather than the HOST.
Definition: tivx_mem.h:172
Internal memory at L2 level.
Definition: tivx_mem.h:120
Structure describing a memory stats pointer.
Definition: tivx_mem.h:217
volatile uint32_t dma_buf_fd_offset
Offset of dmaBufFd, This will be used by host/Linux CPU.
Definition: tivx_mem.h:205
Structure describing a shared memory pointer.
Definition: tivx_mem.h:180
volatile uint32_t mem_heap_region
Memory region to which this pointer belongs, see tivx_mem_heap_region_e.
Definition: tivx_mem.h:183
vx_uint32 free_size
Max free block in memoru heap segment Set to 0 when free size cannot be determined.
Definition: tivx_mem.h:227
Internal memory at L3 level.
Definition: tivx_mem.h:100
volatile uint64_t host_ptr
Value of pointer as seen as by host CPU Host CPU will have method to convert to/from shared memory po...
Definition: tivx_mem.h:200
Internal memory at L1 level.
Definition: tivx_mem.h:140
uint32_t vx_uint32
vx_status tivxMemBufferMap(void *host_ptr, uint32_t size, vx_enum mem_type, vx_enum maptype)
Map an allocated buffer address.
VX_ENUM_MEMORY_TYPE
void * tivxMemShared2TargetPtr(const tivx_shared_mem_ptr_t *shared_ptr)
Convert shared pointer to target pointer.
uint64_t tivxMemShared2PhysPtr(uint64_t shared_ptr, vx_enum mem_heap_region)
Convert shared pointer to system physical memory location This is mainly used for configuring physica...
void tivxMemStats(tivx_mem_stats *stats, vx_enum mem_type)
Get memory segment information.
uint64_t tivxMemHost2SharedPtr(uint64_t host_ptr, vx_enum mem_heap_region)
Convert Host pointer to shared pointer.
vx_status tivxMemBufferFree(tivx_shared_mem_ptr_t *mem_ptr, uint32_t size)
Free buffer from shared memory.
vx_status tivxMemBufferUnmap(void *host_ptr, uint32_t size, vx_enum mem_type, vx_enum maptype)
UnMap a buffer address.
volatile uint64_t shared_ptr
Value of pointer as seen in shared memory All CPUs will have method to convert from shared memory poi...
Definition: tivx_mem.h:194
vx_status tivxMemBufferAlloc(tivx_shared_mem_ptr_t *mem_ptr, uint32_t size, vx_enum mem_heap_region)
Alloc buffer from shared memory.
volatile int32_t dma_buf_fd
Value of dmaBufFd correspods to the host_ptr, This will be used by host/Linux CPU.
Definition: tivx_mem.h:188