xref: /qemu/include/exec/target_page.h (revision 6ff5da16000f908140723e164d33a0b51a6c4162)
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_BITS_MIN TARGET_PAGE_BITS
45 # define TARGET_PAGE_SIZE    (1 << TARGET_PAGE_BITS)
46 # define TARGET_PAGE_MASK    ((TARGET_PAGE_TYPE)-1 << TARGET_PAGE_BITS)
47 #endif
48 
49 #define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
50 
51 static inline size_t qemu_target_page_size(void)
52 {
53     return TARGET_PAGE_SIZE;
54 }
55 
56 static inline int qemu_target_page_mask(void)
57 {
58     return TARGET_PAGE_MASK;
59 }
60 
61 static inline int qemu_target_page_bits(void)
62 {
63     return TARGET_PAGE_BITS;
64 }
65 
66 int qemu_target_page_bits_min(void);
67 size_t qemu_target_pages_to_MiB(size_t pages);
68 
69 #endif
70