• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 #ifndef LIBTEEOS_TEE_BITMAP_H
13 #define LIBTEEOS_TEE_BITMAP_H
14 
15 #include <stdint.h>
16 #include <stdio.h>
17 #include <stdbool.h>
18 
19 #define MOVE_BIT    3
20 #define INDEX_MAX   8
21 #define BITMAP_MASK 0xFF
22 
23 int32_t get_valid_bit(const uint8_t *bitmap, uint32_t bit_max);
24 
is_bit_seted(const uint8_t * bitmap,uint32_t bit_max,uint32_t bit)25 static inline bool is_bit_seted(const uint8_t *bitmap, uint32_t bit_max, uint32_t bit)
26 {
27     if ((bitmap == NULL) || (bit >= bit_max))
28         return false;
29 
30     return (((bitmap[bit >> MOVE_BIT]) & (0x1 << (bit % INDEX_MAX))) ? true : false);
31 }
32 
set_bitmap(uint8_t * bitmap,uint32_t bit_max,uint32_t bit)33 static inline void set_bitmap(uint8_t *bitmap, uint32_t bit_max, uint32_t bit)
34 {
35     if ((bitmap == NULL) || (bit >= bit_max))
36         return;
37 
38     bitmap[bit >> MOVE_BIT] = (bitmap[bit >> MOVE_BIT]) | (0x1 << (bit % INDEX_MAX));
39 }
40 
clear_bitmap(uint8_t * bitmap,uint32_t bit_max,uint32_t bit)41 static inline void clear_bitmap(uint8_t *bitmap, uint32_t bit_max, uint32_t bit)
42 {
43     if ((bitmap == NULL) || (bit >= bit_max))
44         return;
45 
46     bitmap[bit >> MOVE_BIT] = (bitmap[bit >> MOVE_BIT]) & (~(uint8_t)(0x1 << (bit % INDEX_MAX)));
47 }
48 #endif
49