17777dab0Sopenharmony_ci/* 27777dab0Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License. 57777dab0Sopenharmony_ci * You may obtain a copy of the License at 67777dab0Sopenharmony_ci * 77777dab0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 87777dab0Sopenharmony_ci * 97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and 137777dab0Sopenharmony_ci * limitations under the License. 147777dab0Sopenharmony_ci */ 157777dab0Sopenharmony_ci 167777dab0Sopenharmony_ci#ifndef TEE_SHAREMEM_OPS_H 177777dab0Sopenharmony_ci#define TEE_SHAREMEM_OPS_H 187777dab0Sopenharmony_ci 197777dab0Sopenharmony_ci/** 207777dab0Sopenharmony_ci * @addtogroup TeeTrusted 217777dab0Sopenharmony_ci * @{ 227777dab0Sopenharmony_ci * 237777dab0Sopenharmony_ci * @brief TEE(Trusted Excution Environment) API. 247777dab0Sopenharmony_ci * Provides security capability APIs such as trusted storage, encryption and decryption, 257777dab0Sopenharmony_ci * and trusted time for trusted application development. 267777dab0Sopenharmony_ci * 277777dab0Sopenharmony_ci * @since 12 287777dab0Sopenharmony_ci */ 297777dab0Sopenharmony_ci 307777dab0Sopenharmony_ci/** 317777dab0Sopenharmony_ci * @file tee_sharemem_ops.h 327777dab0Sopenharmony_ci * 337777dab0Sopenharmony_ci * @brief Provides APIs for developers to apply for shared memory. 347777dab0Sopenharmony_ci * 357777dab0Sopenharmony_ci * @library NA 367777dab0Sopenharmony_ci * @kit TEEKit 377777dab0Sopenharmony_ci * @syscap SystemCapability.Tee.TeeClient 387777dab0Sopenharmony_ci * @since 12 397777dab0Sopenharmony_ci * @version 1.0 407777dab0Sopenharmony_ci */ 417777dab0Sopenharmony_ci 427777dab0Sopenharmony_ci#include <stdint.h> 437777dab0Sopenharmony_ci#include <tee_defines.h> 447777dab0Sopenharmony_ci 457777dab0Sopenharmony_ci#ifdef __cplusplus 467777dab0Sopenharmony_ciextern "C" { 477777dab0Sopenharmony_ci#endif 487777dab0Sopenharmony_ci 497777dab0Sopenharmony_ci/** 507777dab0Sopenharmony_ci * @brief Alloc shared memory in TEE. 517777dab0Sopenharmony_ci * 527777dab0Sopenharmony_ci * @param uuid Indicates the UUID of TA. 537777dab0Sopenharmony_ci * @param size Indicates the size of the requested shared memory. 547777dab0Sopenharmony_ci * 557777dab0Sopenharmony_ci * @return Returns a pointer to the newly allocated space if the operation is successful. 567777dab0Sopenharmony_ci * Returns a <b>NULL</b> pointer if the allocation fails. 577777dab0Sopenharmony_ci * 587777dab0Sopenharmony_ci * @since 12 597777dab0Sopenharmony_ci * @version 1.0 607777dab0Sopenharmony_ci */ 617777dab0Sopenharmony_civoid *tee_alloc_sharemem_aux(const struct tee_uuid *uuid, uint32_t size); 627777dab0Sopenharmony_ci 637777dab0Sopenharmony_ci/** 647777dab0Sopenharmony_ci * @brief Alloc continuous shared memory in TEE. 657777dab0Sopenharmony_ci * 667777dab0Sopenharmony_ci * @param uuid Indicates the UUID of TA. 677777dab0Sopenharmony_ci * @param size Indicates the size of the requested shared memory. 687777dab0Sopenharmony_ci * 697777dab0Sopenharmony_ci * @return Returns a pointer to the newly allocated space if the operation is successful. 707777dab0Sopenharmony_ci * Returns a <b>NULL</b> pointer if the allocation fails. 717777dab0Sopenharmony_ci * 727777dab0Sopenharmony_ci * @since 12 737777dab0Sopenharmony_ci * @version 1.0 747777dab0Sopenharmony_ci */ 757777dab0Sopenharmony_civoid *tee_alloc_coherent_sharemem_aux(const struct tee_uuid *uuid, uint32_t size); 767777dab0Sopenharmony_ci 777777dab0Sopenharmony_ci/** 787777dab0Sopenharmony_ci * @brief Free the shared memory in TEE. 797777dab0Sopenharmony_ci * 807777dab0Sopenharmony_ci * @param addr Indicates the shared memory address that will be freed. 817777dab0Sopenharmony_ci * @param size Indicates the size of the shared memory. 827777dab0Sopenharmony_ci * 837777dab0Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 847777dab0Sopenharmony_ci * Returns others if the operation is failed. 857777dab0Sopenharmony_ci * 867777dab0Sopenharmony_ci * @since 12 877777dab0Sopenharmony_ci * @version 1.0 887777dab0Sopenharmony_ci */ 897777dab0Sopenharmony_ciuint32_t tee_free_sharemem(void *addr, uint32_t size); 907777dab0Sopenharmony_ci 917777dab0Sopenharmony_ci/** 927777dab0Sopenharmony_ci * @brief Copy shared memory from source task. 937777dab0Sopenharmony_ci * 947777dab0Sopenharmony_ci * @param src_task Indicates the pid of the source task. 957777dab0Sopenharmony_ci * @param src Indicates the address of the source buffer. 967777dab0Sopenharmony_ci * @param src_size Indicates the size of the source buffer. 977777dab0Sopenharmony_ci * @param dst Indicates the address of the destination buffer. 987777dab0Sopenharmony_ci * @param dst_size Indicates the size of the destination buffer. 997777dab0Sopenharmony_ci * 1007777dab0Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 1017777dab0Sopenharmony_ci * Returns <b>-1</b> if the operation is failed. 1027777dab0Sopenharmony_ci * 1037777dab0Sopenharmony_ci * @since 12 1047777dab0Sopenharmony_ci * @version 1.0 1057777dab0Sopenharmony_ci */ 1067777dab0Sopenharmony_ciint32_t copy_from_sharemem(uint32_t src_task, uint64_t src, uint32_t src_size, uintptr_t dst, uint32_t dst_size); 1077777dab0Sopenharmony_ci 1087777dab0Sopenharmony_ci/** 1097777dab0Sopenharmony_ci * @brief Copy shared memory to destination task. 1107777dab0Sopenharmony_ci * 1117777dab0Sopenharmony_ci * @param src Indicates the address of the source buffer. 1127777dab0Sopenharmony_ci * @param src_size Indicates the size of the source buffer. 1137777dab0Sopenharmony_ci * @param dst_task Indicates the pid of the destination task. 1147777dab0Sopenharmony_ci * @param dst Indicates the address of the destination buffer. 1157777dab0Sopenharmony_ci * @param dst_size Indicates the size of the destination buffer. 1167777dab0Sopenharmony_ci * 1177777dab0Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful. 1187777dab0Sopenharmony_ci * Returns <b>-1</b> if the operation is failed. 1197777dab0Sopenharmony_ci * 1207777dab0Sopenharmony_ci * @since 12 1217777dab0Sopenharmony_ci * @version 1.0 1227777dab0Sopenharmony_ci */ 1237777dab0Sopenharmony_ciint32_t copy_to_sharemem(uintptr_t src, uint32_t src_size, uint32_t dst_task, uint64_t dst, uint32_t dst_size); 1247777dab0Sopenharmony_ci#ifdef __cplusplus 1257777dab0Sopenharmony_ci} 1267777dab0Sopenharmony_ci#endif 1277777dab0Sopenharmony_ci/** @} */ 1287777dab0Sopenharmony_ci#endif