• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2009-12-22
13  * Description: SC内存算法模块的模块内头文件。
14  */
15 #ifndef PRT_FSCMEM_INTERNAL_H
16 #define PRT_FSCMEM_INTERNAL_H
17 
18 #include "prt_fscmem_external.h"
19 #include "prt_cpu_external.h"
20 #include "prt_lib_external.h"
21 #include "../prt_mem_internal.h"
22 
23 /*
24  * 模块内宏定义
25  */
26 #define OS_FSC_MEM_PREV_USED 0
27 #define OS_FSC_MEM_USED_MAGIC OS_MEM_HEAD_MAGICWORD
28 
29 #define OS_FSC_MEM_SZ2IDX(size) (31 - OsGetLmb1((U32)(size)))
30 #define OS_FSC_MEM_IDX2BIT(idx) (0x80000000UL >> (idx))
31 
32 #define OS_FSC_MEM_SIZE_ALIGN OS_MEM_ADDR_ALIGN
33 #define OS_FSC_MEM_MIN_SIZE (OS_FSC_MEM_SLICE_HEAD_SIZE + OS_FSC_MEM_SIZE_ALIGN)
34 
35 /*
36  * 模块内全局变量声明
37  */
38 
39 /*
40  * 模块内函数声明
41  */
42 extern void *OsFscMemSplit(U8 ptNo, uintptr_t size, uintptr_t align,
43                            struct TagFscMemCtrl *fscFreeListHead, U32 *bitMapPtr);
44 extern U32 OsMemPtParaCheck(uintptr_t addr, uintptr_t size, uintptr_t *ptAddr);
45 
46 /*
47  * 模块内内联函数定义
48  */
OsFscMemDelete(struct TagFscMemCtrl * currBlk)49 OS_SEC_ALW_INLINE INLINE void OsFscMemDelete(struct TagFscMemCtrl *currBlk)
50 {
51     currBlk->next->prev = currBlk->prev;
52     currBlk->prev->next = currBlk->next;
53 }
54 
OsFscMemInsert(struct TagFscMemCtrl * currBlk,struct TagFscMemCtrl * fscFreeList,U32 * bitMapPtr)55 OS_SEC_ALW_INLINE INLINE void OsFscMemInsert(struct TagFscMemCtrl *currBlk,
56                                              struct TagFscMemCtrl *fscFreeList,
57                                              U32 *bitMapPtr)
58 {
59     U32 idx = OS_FSC_MEM_SZ2IDX(currBlk->size);
60     struct TagFscMemCtrl *headBlk = &(fscFreeList[idx]);
61 
62     *bitMapPtr |= OS_FSC_MEM_IDX2BIT(idx);
63 
64     currBlk->prev = headBlk;
65     currBlk->next = headBlk->next;
66     headBlk->next->prev = currBlk;
67     headBlk->next = currBlk;
68 }
69 
OsFscMemBlockInit(struct TagFscMemCtrl * memBlk)70 OS_SEC_ALW_INLINE INLINE void OsFscMemBlockInit(struct TagFscMemCtrl *memBlk)
71 {
72     /* 后续考虑整块内存初始化为随机值,当前仅清零控制头 */
73     memBlk->next = NULL;
74     memBlk->size = 0;
75     memBlk->prevSize = 0;
76     memBlk->prev = NULL;
77 }
78 
79 #endif /* PRT_FSCMEM_INTERNAL_H */
80