112636162Sopenharmony_ci/*
212636162Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
312636162Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
412636162Sopenharmony_ci * you may not use this file except in compliance with the License.
512636162Sopenharmony_ci * You may obtain a copy of the License at
612636162Sopenharmony_ci *
712636162Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
812636162Sopenharmony_ci *
912636162Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1012636162Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1112636162Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212636162Sopenharmony_ci * See the License for the specific language governing permissions and
1312636162Sopenharmony_ci * limitations under the License.
1412636162Sopenharmony_ci */
1512636162Sopenharmony_ci#ifndef DDK_API_H
1612636162Sopenharmony_ci#define DDK_API_H
1712636162Sopenharmony_ci
1812636162Sopenharmony_ci/**
1912636162Sopenharmony_ci * @addtogroup Ddk
2012636162Sopenharmony_ci * @{
2112636162Sopenharmony_ci *
2212636162Sopenharmony_ci * @brief Provides Base DDK APIs, including creating the shared memory, mapping the shared memory,\n
2312636162Sopenharmony_ci * unmapping the shared memory, and destroying the shared memory.
2412636162Sopenharmony_ci *
2512636162Sopenharmony_ci * @since 12
2612636162Sopenharmony_ci */
2712636162Sopenharmony_ci
2812636162Sopenharmony_ci/**
2912636162Sopenharmony_ci * @file ddk_api.h
3012636162Sopenharmony_ci *
3112636162Sopenharmony_ci * @brief Declares the Base DDK APIs.
3212636162Sopenharmony_ci *
3312636162Sopenharmony_ci * @syscap SystemCapability.Driver.DDK.Extension
3412636162Sopenharmony_ci * @since 12
3512636162Sopenharmony_ci */
3612636162Sopenharmony_ci
3712636162Sopenharmony_ci#include <stdint.h>
3812636162Sopenharmony_ci#include "ddk_types.h"
3912636162Sopenharmony_ci
4012636162Sopenharmony_ci#ifdef __cplusplus
4112636162Sopenharmony_ciextern "C" {
4212636162Sopenharmony_ci#endif /* __cplusplus */
4312636162Sopenharmony_ci
4412636162Sopenharmony_ci/**
4512636162Sopenharmony_ci * @brief Creates shared memory. To prevent resource leakage, destroy the shared memory that is not required by\n
4612636162Sopenharmony_ci * calling <b>OH_DDK_DestroyAshmem</b>.
4712636162Sopenharmony_ci *
4812636162Sopenharmony_ci * @param name Pointer to the shared memory to create.
4912636162Sopenharmony_ci * @param size Size of the buffer corresponding to the shared memory.
5012636162Sopenharmony_ci * @param ashmem Pointer to the shared memory created.
5112636162Sopenharmony_ci * @return Returns <b>DDK_SUCCESS</b> if the operation is successful; returns a negative value otherwise.
5212636162Sopenharmony_ci * @since 12
5312636162Sopenharmony_ci */
5412636162Sopenharmony_ciDDK_RetCode OH_DDK_CreateAshmem(const uint8_t *name, uint32_t size, DDK_Ashmem **ashmem);
5512636162Sopenharmony_ci
5612636162Sopenharmony_ci/**
5712636162Sopenharmony_ci * @brief Maps the created shared memory to the user space. Unmap the shared memory that is not required by using\n
5812636162Sopenharmony_ci * <b>OH_DDK_UnmapAshmem</b>.
5912636162Sopenharmony_ci *
6012636162Sopenharmony_ci * @param ashmem Pointer of the shared memory to map.
6112636162Sopenharmony_ci * @param ashmemMapType Protection permission value of the shared memory.
6212636162Sopenharmony_ci * @return Returns <b>DDK_SUCCESS</b> if the operation is successful; returns a negative value otherwise.
6312636162Sopenharmony_ci * @since 12
6412636162Sopenharmony_ci */
6512636162Sopenharmony_ciDDK_RetCode OH_DDK_MapAshmem(DDK_Ashmem *ashmem, const uint8_t ashmemMapType);
6612636162Sopenharmony_ci
6712636162Sopenharmony_ci/**
6812636162Sopenharmony_ci * @brief Unmaps shared memory.
6912636162Sopenharmony_ci *
7012636162Sopenharmony_ci * @param ashmem Pointer of the shared memory to unmap.
7112636162Sopenharmony_ci * @return Returns <b>DDK_SUCCESS</b> if the operation is successful; returns a negative value otherwise.
7212636162Sopenharmony_ci * @since 12
7312636162Sopenharmony_ci */
7412636162Sopenharmony_ciDDK_RetCode OH_DDK_UnmapAshmem(DDK_Ashmem *ashmem);
7512636162Sopenharmony_ci
7612636162Sopenharmony_ci/**
7712636162Sopenharmony_ci * @brief Destroys shared memory.
7812636162Sopenharmony_ci *
7912636162Sopenharmony_ci * @param ashmem Pointer of the shared memory to destroy.
8012636162Sopenharmony_ci * @return Returns <b>DDK_SUCCESS</b> if the operation is successful; returns a negative value otherwise.
8112636162Sopenharmony_ci * @since 12
8212636162Sopenharmony_ci */
8312636162Sopenharmony_ciDDK_RetCode OH_DDK_DestroyAshmem(DDK_Ashmem *ashmem);
8412636162Sopenharmony_ci#ifdef __cplusplus
8512636162Sopenharmony_ci}
8612636162Sopenharmony_ci/** @} */
8712636162Sopenharmony_ci#endif /* __cplusplus */
8812636162Sopenharmony_ci#endif // DDK_APIS_H