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 
172 
174 
178 typedef enum _tivx_memory_type_e {
182 
188 typedef struct _tivx_shared_mem_ptr_t {
189 
191  volatile uint32_t mem_heap_region;
192 
196  volatile int32_t dma_buf_fd;
197 
202  volatile uint64_t shared_ptr;
203 
208  volatile uint64_t host_ptr;
209 
213  volatile uint32_t dma_buf_fd_offset;
214 
215  /* Padding to align to 64 bytes */
216  volatile uint32_t rsv[1];
217 
219 
225 typedef struct _tivx_mem_stats_t {
226 
231 
236 
238 
249 vx_status tivxMemBufferAlloc(tivx_shared_mem_ptr_t *mem_ptr, uint32_t size, vx_enum mem_heap_region);
250 
259 vx_status tivxMemBufferFree(tivx_shared_mem_ptr_t *mem_ptr, uint32_t size);
260 
275 vx_status tivxMemBufferMap(void *host_ptr, uint32_t size, vx_enum mem_type, vx_enum maptype);
276 
293 vx_status tivxMemBufferUnmap(void *host_ptr, uint32_t size, vx_enum mem_type, vx_enum maptype);
294 
305 uint64_t tivxMemHost2SharedPtr(uint64_t host_ptr, vx_enum mem_heap_region);
306 
316 void* tivxMemShared2TargetPtr(const tivx_shared_mem_ptr_t *shared_ptr);
317 
329 uint64_t tivxMemShared2PhysPtr(uint64_t shared_ptr, vx_enum mem_heap_region);
330 
342 void *tivxMemAlloc(vx_uint32 size, vx_enum mem_heap_region);
343 
353 vx_status tivxMemFree(void *ptr, vx_uint32 size, vx_enum mem_heap_region);
354 
363 void tivxMemStats(tivx_mem_stats *stats, vx_enum mem_type);
364 
374 int32_t tivxMemResetScratchHeap(vx_enum mem_heap_region);
375 
394 vx_status tivxMemTranslateVirtAddr(const void *virtAddr, uint64_t *fd, void **phyAddr);
395 
410 vx_bool tivxMemCompareFd(uint64_t dmaBufFd1, uint64_t dmaBufFd2, uint32_t size1, uint32_t size2);
411 
432 vx_status tivxMemTranslateFd(uint64_t dmaBufFd, uint32_t size, void **virtAddr, void **phyAddr);
433 
442 void tivxEnableL1DandL2CacheWb(void);
443 
444 #ifdef __cplusplus
445 }
446 #endif
447 
448 #endif
vx_bool
External cacheable memory with write through policy.
Definition: tivx_mem.h:171
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:178
vx_status tivxMemFree(void *ptr, vx_uint32 size, vx_enum mem_heap_region)
Frees already allocated memory.
int32_t tivxMemResetScratchHeap(vx_enum mem_heap_region)
Reset scratch memory.
int32_t vx_enum
vx_status tivxMemTranslateFd(uint64_t dmaBufFd, uint32_t size, void **virtAddr, void **phyAddr)
Translates a given file descriptor to a virtual and physical address. The following conditions regard...
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:230
VX_ID_TI
vx_enum vx_status
#define VX_ENUM_BASE(vendor, id)
External persistent non cacheable 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 in the shared memory carveout region used by OpenVX data buffers...
External scratch non cacheable memory.
Definition: tivx_mem.h:163
External memory.
Definition: tivx_mem.h:93
External scratch memory.
Definition: tivx_mem.h:148
vx_bool tivxMemCompareFd(uint64_t dmaBufFd1, uint64_t dmaBufFd2, uint32_t size1, uint32_t size2)
Compares two given FD&#39;s and returns a boolean based on whether they are the same or not...
Memory type when a DMA will access the memory rather than the HOST.
Definition: tivx_mem.h:180
Internal memory at L2 level.
Definition: tivx_mem.h:120
Structure describing a memory stats pointer.
Definition: tivx_mem.h:225
volatile uint32_t dma_buf_fd_offset
Offset of dmaBufFd, This will be used by host/Linux CPU.
Definition: tivx_mem.h:213
Structure describing a shared memory pointer.
Definition: tivx_mem.h:188
volatile uint32_t mem_heap_region
Memory region to which this pointer belongs, see tivx_mem_heap_region_e.
Definition: tivx_mem.h:191
vx_uint32 free_size
Max free block in memory heap segment Set to 0 when free size cannot be determined.
Definition: tivx_mem.h:235
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:208
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:202
vx_status tivxMemBufferAlloc(tivx_shared_mem_ptr_t *mem_ptr, uint32_t size, vx_enum mem_heap_region)
Allocates memory of given size in the shared memory carveout region used by OpenVX data buffers...
volatile int32_t dma_buf_fd
Value of dmaBufFd corresponds to the host_ptr, This will be used by host/Linux CPU.
Definition: tivx_mem.h:196