xref: /qemu/include/exec/target_page.h (revision fc524567087c2537b5103cdfc1d41e4f442892b6)
1 /*
2  * Target page sizes and friends for non target files
3  *
4  * Copyright (c) 2017 Red Hat Inc
5  *
6  * Authors:
7  *  David Alan Gilbert <dgilbert@redhat.com>
8  *  Juan Quintela <quintela@redhat.com>
9  *
10  * This work is licensed under the terms of the GNU GPL, version 2 or later.
11  * See the COPYING file in the top-level directory.
12  */
13 
14 #ifndef EXEC_TARGET_PAGE_H
15 #define EXEC_TARGET_PAGE_H
16 
17 /*
18  * If compiling per-target, get the real values.
19  * For generic code, reuse the mechanism for variable page size.
20  */
21 #ifdef COMPILING_PER_TARGET
22 #include "cpu-param.h"
23 #include "exec/target_long.h"
24 #define TARGET_PAGE_TYPE  target_long
25 #else
26 #define TARGET_PAGE_BITS_VARY
27 #define TARGET_PAGE_TYPE  int
28 #endif
29 
30 #ifdef TARGET_PAGE_BITS_VARY
31 # include "exec/page-vary.h"
32 extern const TargetPageBits target_page;
33 # ifdef CONFIG_DEBUG_TCG
34 #  define TARGET_PAGE_BITS   ({ assert(target_page.decided); \
35                                 target_page.bits; })
36 #  define TARGET_PAGE_MASK   ({ assert(target_page.decided); \
37                                 (TARGET_PAGE_TYPE)target_page.mask; })
38 # else
39 #  define TARGET_PAGE_BITS   target_page.bits
40 #  define TARGET_PAGE_MASK   ((TARGET_PAGE_TYPE)target_page.mask)
41 # endif
42 # define TARGET_PAGE_SIZE    (-(int)TARGET_PAGE_MASK)
43 #else
44 # define TARGET_PAGE_SIZE    (1 << TARGET_PAGE_BITS)
45 # define TARGET_PAGE_MASK    ((TARGET_PAGE_TYPE)-1 << TARGET_PAGE_BITS)
46 #endif
47 
48 #define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
49 
qemu_target_page_size(void)50 static inline size_t qemu_target_page_size(void)
51 {
52     return TARGET_PAGE_SIZE;
53 }
54 
qemu_target_page_mask(void)55 static inline int qemu_target_page_mask(void)
56 {
57     return TARGET_PAGE_MASK;
58 }
59 
qemu_target_page_bits(void)60 static inline int qemu_target_page_bits(void)
61 {
62     return TARGET_PAGE_BITS;
63 }
64 
65 size_t qemu_target_pages_to_MiB(size_t pages);
66 
67 #endif
68