154568cb3Sopenharmony_ci/*
254568cb3Sopenharmony_ci * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
354568cb3Sopenharmony_ci *
454568cb3Sopenharmony_ci * UniProton is licensed under Mulan PSL v2.
554568cb3Sopenharmony_ci * You can use this software according to the terms and conditions of the Mulan PSL v2.
654568cb3Sopenharmony_ci * You may obtain a copy of Mulan PSL v2 at:
754568cb3Sopenharmony_ci *          http://license.coscl.org.cn/MulanPSL2
854568cb3Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
954568cb3Sopenharmony_ci * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
1054568cb3Sopenharmony_ci * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
1154568cb3Sopenharmony_ci * See the Mulan PSL v2 for more details.
1254568cb3Sopenharmony_ci * Create: 2009-12-22
1354568cb3Sopenharmony_ci * Description: SC内存算法模块的模块内头文件。
1454568cb3Sopenharmony_ci */
1554568cb3Sopenharmony_ci#ifndef PRT_FSCMEM_INTERNAL_H
1654568cb3Sopenharmony_ci#define PRT_FSCMEM_INTERNAL_H
1754568cb3Sopenharmony_ci
1854568cb3Sopenharmony_ci#include "prt_fscmem_external.h"
1954568cb3Sopenharmony_ci#include "prt_cpu_external.h"
2054568cb3Sopenharmony_ci#include "prt_lib_external.h"
2154568cb3Sopenharmony_ci#include "../prt_mem_internal.h"
2254568cb3Sopenharmony_ci
2354568cb3Sopenharmony_ci/*
2454568cb3Sopenharmony_ci * 模块内宏定义
2554568cb3Sopenharmony_ci */
2654568cb3Sopenharmony_ci#define OS_FSC_MEM_PREV_USED 0
2754568cb3Sopenharmony_ci#define OS_FSC_MEM_USED_MAGIC OS_MEM_HEAD_MAGICWORD
2854568cb3Sopenharmony_ci
2954568cb3Sopenharmony_ci#define OS_FSC_MEM_SZ2IDX(size) (31 - OsGetLmb1((U32)(size)))
3054568cb3Sopenharmony_ci#define OS_FSC_MEM_IDX2BIT(idx) (0x80000000UL >> (idx))
3154568cb3Sopenharmony_ci
3254568cb3Sopenharmony_ci#define OS_FSC_MEM_SIZE_ALIGN OS_MEM_ADDR_ALIGN
3354568cb3Sopenharmony_ci#define OS_FSC_MEM_MIN_SIZE (OS_FSC_MEM_SLICE_HEAD_SIZE + OS_FSC_MEM_SIZE_ALIGN)
3454568cb3Sopenharmony_ci
3554568cb3Sopenharmony_ci/*
3654568cb3Sopenharmony_ci * 模块内全局变量声明
3754568cb3Sopenharmony_ci */
3854568cb3Sopenharmony_ci
3954568cb3Sopenharmony_ci/*
4054568cb3Sopenharmony_ci * 模块内函数声明
4154568cb3Sopenharmony_ci */
4254568cb3Sopenharmony_ciextern void *OsFscMemSplit(U8 ptNo, uintptr_t size, uintptr_t align,
4354568cb3Sopenharmony_ci                           struct TagFscMemCtrl *fscFreeListHead, U32 *bitMapPtr);
4454568cb3Sopenharmony_ciextern U32 OsMemPtParaCheck(uintptr_t addr, uintptr_t size, uintptr_t *ptAddr);
4554568cb3Sopenharmony_ci
4654568cb3Sopenharmony_ci/*
4754568cb3Sopenharmony_ci * 模块内内联函数定义
4854568cb3Sopenharmony_ci */
4954568cb3Sopenharmony_ciOS_SEC_ALW_INLINE INLINE void OsFscMemDelete(struct TagFscMemCtrl *currBlk)
5054568cb3Sopenharmony_ci{
5154568cb3Sopenharmony_ci    currBlk->next->prev = currBlk->prev;
5254568cb3Sopenharmony_ci    currBlk->prev->next = currBlk->next;
5354568cb3Sopenharmony_ci}
5454568cb3Sopenharmony_ci
5554568cb3Sopenharmony_ciOS_SEC_ALW_INLINE INLINE void OsFscMemInsert(struct TagFscMemCtrl *currBlk,
5654568cb3Sopenharmony_ci                                             struct TagFscMemCtrl *fscFreeList,
5754568cb3Sopenharmony_ci                                             U32 *bitMapPtr)
5854568cb3Sopenharmony_ci{
5954568cb3Sopenharmony_ci    U32 idx = OS_FSC_MEM_SZ2IDX(currBlk->size);
6054568cb3Sopenharmony_ci    struct TagFscMemCtrl *headBlk = &(fscFreeList[idx]);
6154568cb3Sopenharmony_ci
6254568cb3Sopenharmony_ci    *bitMapPtr |= OS_FSC_MEM_IDX2BIT(idx);
6354568cb3Sopenharmony_ci
6454568cb3Sopenharmony_ci    currBlk->prev = headBlk;
6554568cb3Sopenharmony_ci    currBlk->next = headBlk->next;
6654568cb3Sopenharmony_ci    headBlk->next->prev = currBlk;
6754568cb3Sopenharmony_ci    headBlk->next = currBlk;
6854568cb3Sopenharmony_ci}
6954568cb3Sopenharmony_ci
7054568cb3Sopenharmony_ciOS_SEC_ALW_INLINE INLINE void OsFscMemBlockInit(struct TagFscMemCtrl *memBlk)
7154568cb3Sopenharmony_ci{
7254568cb3Sopenharmony_ci    /* 后续考虑整块内存初始化为随机值,当前仅清零控制头 */
7354568cb3Sopenharmony_ci    memBlk->next = NULL;
7454568cb3Sopenharmony_ci    memBlk->size = 0;
7554568cb3Sopenharmony_ci    memBlk->prevSize = 0;
7654568cb3Sopenharmony_ci    memBlk->prev = NULL;
7754568cb3Sopenharmony_ci}
7854568cb3Sopenharmony_ci
7954568cb3Sopenharmony_ci#endif /* PRT_FSCMEM_INTERNAL_H */
80