exec: Exclude non portable function for MinGW
[qemu/ar7.git] / include / exec / ram_addr.h
blob481a4474174fd51a8580905dcf7c231a373da360
1 /*
2 * Declarations for cpu physical memory functions
4 * Copyright 2011 Red Hat, Inc. and/or its affiliates
6 * Authors:
7 * Avi Kivity <avi@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or
10 * later. See the COPYING file in the top-level directory.
15 * This header is for use by exec.c and memory.c ONLY. Do not include it.
16 * The functions declared here will be removed soon.
19 #ifndef RAM_ADDR_H
20 #define RAM_ADDR_H
22 #ifndef CONFIG_USER_ONLY
23 #include "hw/xen/xen.h"
25 ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
26 MemoryRegion *mr);
27 ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr);
28 void *qemu_get_ram_ptr(ram_addr_t addr);
29 void qemu_ram_free(ram_addr_t addr);
30 void qemu_ram_free_from_ptr(ram_addr_t addr);
32 static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
33 ram_addr_t length,
34 unsigned client)
36 unsigned long end, page, next;
38 assert(client < DIRTY_MEMORY_NUM);
40 end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
41 page = start >> TARGET_PAGE_BITS;
42 next = find_next_bit(ram_list.dirty_memory[client], end, page);
44 return next < end;
47 static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,
48 unsigned client)
50 return cpu_physical_memory_get_dirty(addr, 1, client);
53 static inline bool cpu_physical_memory_is_clean(ram_addr_t addr)
55 bool vga = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_VGA);
56 bool code = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_CODE);
57 bool migration =
58 cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_MIGRATION);
59 return !(vga && code && migration);
62 static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
63 unsigned client)
65 assert(client < DIRTY_MEMORY_NUM);
66 set_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]);
69 static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
70 ram_addr_t length)
72 unsigned long end, page;
74 end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
75 page = start >> TARGET_PAGE_BITS;
76 bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION], page, end - page);
77 bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_VGA], page, end - page);
78 bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_CODE], page, end - page);
79 xen_modified_memory(start, length);
82 #if !defined(_WIN32)
83 static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
84 ram_addr_t start,
85 ram_addr_t pages)
87 unsigned long i, j;
88 unsigned long page_number, c;
89 hwaddr addr;
90 ram_addr_t ram_addr;
91 unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
92 unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
93 unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
95 /* start address is aligned at the start of a word? */
96 if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) {
97 long k;
98 long nr = BITS_TO_LONGS(pages);
100 for (k = 0; k < nr; k++) {
101 if (bitmap[k]) {
102 unsigned long temp = leul_to_cpu(bitmap[k]);
104 ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION][page + k] |= temp;
105 ram_list.dirty_memory[DIRTY_MEMORY_VGA][page + k] |= temp;
106 ram_list.dirty_memory[DIRTY_MEMORY_CODE][page + k] |= temp;
109 xen_modified_memory(start, pages);
110 } else {
112 * bitmap-traveling is faster than memory-traveling (for addr...)
113 * especially when most of the memory is not dirty.
115 for (i = 0; i < len; i++) {
116 if (bitmap[i] != 0) {
117 c = leul_to_cpu(bitmap[i]);
118 do {
119 j = ffsl(c) - 1;
120 c &= ~(1ul << j);
121 page_number = (i * HOST_LONG_BITS + j) * hpratio;
122 addr = page_number * TARGET_PAGE_SIZE;
123 ram_addr = start + addr;
124 cpu_physical_memory_set_dirty_range(ram_addr,
125 TARGET_PAGE_SIZE * hpratio);
126 } while (c != 0);
131 #endif /* not _WIN32 */
133 static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
134 ram_addr_t length,
135 unsigned client)
137 unsigned long end, page;
139 assert(client < DIRTY_MEMORY_NUM);
140 end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
141 page = start >> TARGET_PAGE_BITS;
142 bitmap_clear(ram_list.dirty_memory[client], page, end - page);
145 void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t length,
146 unsigned client);
148 #endif
149 #endif