1 /*
2 * Copyright (c) 2012-2022 Huawei Technologies Co., Ltd.
3 * Description: dynamic ion memory function declaration.
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15 #ifndef DYNAMIC_MMEM_H
16 #define DYNAMIC_MMEM_H
17
18 #include <linux/version.h>
19 #include <securec.h>
20 #include "teek_ns_client.h"
21
22 #ifdef CONFIG_DYNAMIC_ION
23 #ifdef CONFIG_DMABUF_MM
24 #include <linux/dmabuf/mm_dma_heap.h>
25 #else
26 #include <linux/ion/mm_ion.h>
27 #endif
28 #endif
29
30 struct sg_memory {
31 int dyn_shared_fd;
32 struct sg_table *dyn_sg_table;
33 struct dma_buf *dyn_dma_buf;
34 phys_addr_t ion_phys_addr;
35 size_t len;
36 void *ion_virt_addr;
37 };
38
39 struct dynamic_mem_item {
40 struct list_head head;
41 uint32_t configid;
42 uint32_t size;
43 struct sg_memory memory;
44 uint32_t cafd;
45 struct tc_uuid uuid;
46 uint32_t ddr_sec_region;
47 };
48
49 struct dynamic_mem_config {
50 struct tc_uuid uuid;
51 uint32_t ddr_sec_region;
52 };
53
54 #define MAX_ION_NENTS 1024
55 typedef struct ion_page_info {
56 phys_addr_t phys_addr;
57 uint32_t npages;
58 }tz_page_info;
59
60 typedef struct sglist {
61 uint64_t sglist_size;
62 uint64_t ion_size;
63 uint64_t ion_id;
64 uint64_t info_length;
65 struct ion_page_info page_info[0];
66 }tz_sg_list;
67
68 #ifdef CONFIG_DYNAMIC_ION
69
70 bool is_ion_param(uint32_t param_type);
71 int init_dynamic_mem(void);
72 int load_app_use_configid(uint32_t configid, uint32_t cafd,
73 const struct tc_uuid *uuid, uint32_t size, int32_t *ret_origin);
74 void kill_ion_by_cafd(unsigned int cafd);
75 void kill_ion_by_uuid(const struct tc_uuid *uuid);
76 int load_image_for_ion(const struct load_img_params *params, int32_t *ret_origin);
77 int alloc_for_ion_sglist(const struct tc_call_params *call_params,
78 struct tc_op_params *op_params, uint8_t kernel_params,
79 uint32_t param_type, unsigned int index);
80 int alloc_for_ion(const struct tc_call_params *call_params,
81 struct tc_op_params *op_params, uint8_t kernel_params,
82 uint32_t param_type, unsigned int index);
83 #else
is_ion_param(uint32_t param_type)84 static inline bool is_ion_param(uint32_t param_type)
85 {
86 (void)param_type;
87 return false;
88 }
89
load_image_for_ion(const struct load_img_params *params, int32_t *ret_origin)90 static inline int load_image_for_ion(const struct load_img_params *params, int32_t *ret_origin)
91 {
92 (void)params;
93 (void)ret_origin;
94 return 0;
95 }
96
init_dynamic_mem(void)97 static inline int init_dynamic_mem(void)
98 {
99 return 0;
100 }
101
load_app_use_configid(uint32_t configid, uint32_t cafd, const struct tc_uuid *uuid, uint32_t size)102 static inline int load_app_use_configid(uint32_t configid, uint32_t cafd,
103 const struct tc_uuid *uuid, uint32_t size)
104 {
105 (void)configid;
106 (void)cafd;
107 (void)uuid;
108 (void)size;
109 return 0;
110 }
111
kill_ion_by_cafd(unsigned int cafd)112 static inline void kill_ion_by_cafd(unsigned int cafd)
113 {
114 (void)cafd;
115 return;
116 }
117
kill_ion_by_uuid(const struct tc_uuid *uuid)118 static inline void kill_ion_by_uuid(const struct tc_uuid *uuid)
119 {
120 (void)uuid;
121 return;
122 }
123
alloc_for_ion_sglist(const struct tc_call_params *call_params, struct tc_op_params *op_params, uint8_t kernel_params, uint32_t param_type, unsigned int index)124 static inline int alloc_for_ion_sglist(const struct tc_call_params *call_params,
125 struct tc_op_params *op_params, uint8_t kernel_params,
126 uint32_t param_type, unsigned int index)
127 {
128 (void)call_params;
129 (void)op_params;
130 (void)kernel_params;
131 (void)param_type;
132 (void)index;
133 tloge("not support seg and related feature!\n");
134 return -1;
135 }
136
alloc_for_ion(const struct tc_call_params *call_params, struct tc_op_params *op_params, uint8_t kernel_params, uint32_t param_type, unsigned int index)137 static inline int alloc_for_ion(const struct tc_call_params *call_params,
138 struct tc_op_params *op_params, uint8_t kernel_params,
139 uint32_t param_type, unsigned int index)
140 {
141 (void)call_params;
142 (void)op_params;
143 (void)kernel_params;
144 (void)param_type;
145 (void)index;
146 tloge("not support ion and related feature!\n");
147 return -1;
148 }
149 #endif
150 #endif