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