• 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 LIBTEEMEM_MEM_PAGE_OPS_H
13 #define LIBTEEMEM_MEM_PAGE_OPS_H
14 
15 #include <sre_typedef.h>
16 
17 #ifndef ALIGN_UP
18 #define ALIGN_UP(x, align) (((x) + ((align)-1)) & ~((align)-1))
19 #endif
20 
21 #ifndef ALIGN_DOWN
22 #define ALIGN_DOWN(x, align) ((x) & ~((align)-1))
23 #endif
24 
25 /* Physical address in the system */
26 #ifndef PADDR_T_DEFINED
27 typedef uint64_t paddr_t;
28 #define PADDR_T_DEFINED
29 #endif
30 
31 #ifndef PAGE_SHIFT
32 #define PAGE_SHIFT 12
33 #endif
34 
35 #ifndef PAGE_SIZE
36 #define PAGE_SIZE (1u << PAGE_SHIFT)
37 #endif
38 
39 #ifndef PAGE_MASK
40 #define PAGE_MASK (~(PAGE_SIZE - 1)) /* 0xFFFFF000 */
41 #endif
42 
43 #ifndef PAGE_MASK_64BIT
44 #define PAGE_MASK_64BIT 0xFFFFFFF000
45 #endif
46 
47 #ifndef PAGE_OFFSET_MASK
48 #define PAGE_OFFSET_MASK (PAGE_SIZE - 1) /* 0xFFF */
49 #endif
50 
51 #ifndef PAGE_ALIGN_UP
52 #define PAGE_ALIGN_UP(x) ALIGN_UP((x), PAGE_SIZE)
53 #endif
54 #ifndef PAGE_ALIGN_DOWN
55 #define PAGE_ALIGN_DOWN(x) ALIGN_DOWN((x), PAGE_SIZE)
56 #endif
57 
58 #ifndef IS_PAGE_ALIGNED
59 #define IS_PAGE_ALIGNED(addr) (((addr) & PAGE_OFFSET_MASK) == 0)
60 #endif
61 
62 #endif /* LIBTEEMEM_MEM_PAGE_OPS_H */
63