1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *    http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef TEE_SHAREMEM_OPS_H
17#define TEE_SHAREMEM_OPS_H
18
19/**
20 * @addtogroup TeeTrusted
21 * @{
22 *
23 * @brief TEE(Trusted Excution Environment) API.
24 * Provides security capability APIs such as trusted storage, encryption and decryption,
25 * and trusted time for trusted application development.
26 *
27 * @since 12
28 */
29
30/**
31 * @file tee_sharemem_ops.h
32 *
33 * @brief Provides  APIs for developers to apply for shared memory.
34 *
35 * @library NA
36 * @kit TEEKit
37 * @syscap SystemCapability.Tee.TeeClient
38 * @since 12
39 * @version 1.0
40 */
41
42#include <stdint.h>
43#include <tee_defines.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
50 * @brief Alloc shared memory in TEE.
51 *
52 * @param uuid Indicates the UUID of TA.
53 * @param size Indicates the size of the requested shared memory.
54 *
55 * @return Returns a pointer to the newly allocated space if the operation is successful.
56 *         Returns a <b>NULL</b> pointer if the allocation fails.
57 *
58 * @since 12
59 * @version 1.0
60 */
61void *tee_alloc_sharemem_aux(const struct tee_uuid *uuid, uint32_t size);
62
63/**
64 * @brief Alloc continuous shared memory in TEE.
65 *
66 * @param uuid Indicates the UUID of TA.
67 * @param size Indicates the size of the requested shared memory.
68 *
69 * @return Returns a pointer to the newly allocated space if the operation is successful.
70 *         Returns a <b>NULL</b> pointer if the allocation fails.
71 *
72 * @since 12
73 * @version 1.0
74 */
75void *tee_alloc_coherent_sharemem_aux(const struct tee_uuid *uuid, uint32_t size);
76
77/**
78 * @brief Free the shared memory in TEE.
79 *
80 * @param addr Indicates the shared memory address that will be freed.
81 * @param size Indicates the size of the shared memory.
82 *
83 * @return Returns <b>0</b> if the operation is successful.
84 *         Returns others if the operation is failed.
85 *
86 * @since 12
87 * @version 1.0
88 */
89uint32_t tee_free_sharemem(void *addr, uint32_t size);
90
91/**
92 * @brief Copy shared memory from source task.
93 *
94 * @param src_task Indicates the pid of the source task.
95 * @param src Indicates the address of the source buffer.
96 * @param src_size Indicates the size of the source buffer.
97 * @param dst Indicates the address of the destination buffer.
98 * @param dst_size Indicates the size of the destination buffer.
99 *
100 * @return Returns <b>0</b> if the operation is successful.
101 *         Returns <b>-1</b> if the operation is failed.
102 *
103 * @since 12
104 * @version 1.0
105 */
106int32_t copy_from_sharemem(uint32_t src_task, uint64_t src, uint32_t src_size, uintptr_t dst, uint32_t dst_size);
107
108/**
109 * @brief Copy shared memory to destination task.
110 *
111 * @param src Indicates the address of the source buffer.
112 * @param src_size Indicates the size of the source buffer.
113 * @param dst_task Indicates the pid of the destination task.
114 * @param dst Indicates the address of the destination buffer.
115 * @param dst_size Indicates the size of the destination buffer.
116 *
117 * @return Returns <b>0</b> if the operation is successful.
118 *         Returns <b>-1</b> if the operation is failed.
119 *
120 * @since 12
121 * @version 1.0
122 */
123int32_t copy_to_sharemem(uintptr_t src, uint32_t src_size, uint32_t dst_task, uint64_t dst, uint32_t dst_size);
124#ifdef __cplusplus
125}
126#endif
127/** @} */
128#endif