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 /** 17 * @addtogroup Ddk 18 * @{ 19 * 20 * @brief Provides Base DDK APIs, including creating the shared memory, mapping the shared memory,\n 21 * unmapping the shared memory, and destroying the shared memory. 22 * 23 * @since 12 24 */ 25 26 /** 27 * @file ddk_api.h 28 * 29 * @brief Declares the Base DDK APIs. 30 * 31 * @library libddk_base.z.so 32 * @kit DriverDevelopmentKit 33 * @syscap SystemCapability.Driver.DDK.Extension 34 * @since 12 35 */ 36 37 #ifndef DDK_API_H 38 #define DDK_API_H 39 40 #include <stdint.h> 41 #include "ddk_types.h" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif /* __cplusplus */ 46 47 /** 48 * @brief Creates shared memory. To prevent resource leakage, destroy the shared memory that is not required by\n 49 * calling <b>OH_DDK_DestroyAshmem</b>. 50 * 51 * @param name Pointer to the shared memory to create. 52 * @param size Size of the buffer corresponding to the shared memory. 53 * @param ashmem Pointer to the shared memory created. 54 * @return {@link DDK_SUCCESS} the operation is successful. 55 * {@link DDK_INVALID_PARAMETER} name is NULL, size is 0 or ashmem is NULL. 56 * {@link DDK_FAILURE} create the shared memory failed or create structure DDK_Ashmem failed. 57 * @since 12 58 */ 59 DDK_RetCode OH_DDK_CreateAshmem(const uint8_t *name, uint32_t size, DDK_Ashmem **ashmem); 60 61 /** 62 * @brief Maps the created shared memory to the user space. Unmap the shared memory that is not required by using\n 63 * <b>OH_DDK_UnmapAshmem</b>. 64 * 65 * @param ashmem Pointer of the shared memory to map. 66 * @param ashmemMapType Protection permission value of the shared memory. 67 * @return {@link DDK_SUCCESS} the operation is successful. 68 * {@link DDK_NULL_PTR} ashmem is NULL. 69 * {@link DDK_FAILURE} the fd of ashmem is invalid. 70 * {@link DDK_INVALID_OPERATION} use function MapAshmem failed. 71 * @since 12 72 */ 73 DDK_RetCode OH_DDK_MapAshmem(DDK_Ashmem *ashmem, const uint8_t ashmemMapType); 74 75 /** 76 * @brief Unmaps shared memory. 77 * 78 * @param ashmem Pointer of the shared memory to unmap. 79 * @return {@link DDK_SUCCESS} the operation is successful. 80 * {@link DDK_NULL_PTR} ashmem is NULL. 81 * {@link DDK_FAILURE} the fd of ashmem is invalid. 82 * @since 12 83 */ 84 DDK_RetCode OH_DDK_UnmapAshmem(DDK_Ashmem *ashmem); 85 86 /** 87 * @brief Destroys shared memory. 88 * 89 * @param ashmem Pointer of the shared memory to destroy. 90 * @return {@link DDK_SUCCESS} the operation is successful. 91 * {@link DDK_NULL_PTR} ashmem is NULL. 92 * {@link DDK_FAILURE} the fd of ashmem is invalid. 93 * @since 12 94 */ 95 DDK_RetCode OH_DDK_DestroyAshmem(DDK_Ashmem *ashmem); 96 #ifdef __cplusplus 97 } 98 /** @} */ 99 #endif /* __cplusplus */ 100 #endif // DDK_APIS_H