numa: add -numa node,memdev= option
[qemu.git] / include / exec / ram_addr.h
1 /*
2 * Declarations for cpu physical memory functions
3 *
4 * Copyright 2011 Red Hat, Inc. and/or its affiliates
5 *
6 * Authors:
7 * Avi Kivity <avi@redhat.com>
8 *
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.
11 *
12 */
13
14 /*
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.
17 */
18
19 #ifndef RAM_ADDR_H
20 #define RAM_ADDR_H
21
22 #ifndef CONFIG_USER_ONLY
23 #include "hw/xen/xen.h"
24
25 ram_addr_t qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
26 const char *mem_path);
27 ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
28 MemoryRegion *mr);
29 ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr);
30 void *qemu_get_ram_ptr(ram_addr_t addr);
31 void qemu_ram_free(ram_addr_t addr);
32 void qemu_ram_free_from_ptr(ram_addr_t addr);
33
34 static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
35 ram_addr_t length,
36 unsigned client)
37 {
38 unsigned long end, page, next;
39
40 assert(client < DIRTY_MEMORY_NUM);
41
42 end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
43 page = start >> TARGET_PAGE_BITS;
44 next = find_next_bit(ram_list.dirty_memory[client], end, page);
45
46 return next < end;
47 }
48
49 static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,
50 unsigned client)
51 {
52 return cpu_physical_memory_get_dirty(addr, 1, client);
53 }
54
55 static inline bool cpu_physical_memory_is_clean(ram_addr_t addr)
56 {
57 bool vga = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_VGA);
58 bool code = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_CODE);
59 bool migration =
60 cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_MIGRATION);
61 return !(vga && code && migration);
62 }
63
64 static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
65 unsigned client)
66 {
67 assert(client < DIRTY_MEMORY_NUM);
68 set_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]);
69 }
70
71 static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
72 ram_addr_t length)
73 {
74 unsigned long end, page;
75
76 end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
77 page = start >> TARGET_PAGE_BITS;
78 bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION], page, end - page);
79 bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_VGA], page, end - page);
80 bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_CODE], page, end - page);
81 xen_modified_memory(start, length);
82 }
83
84 #if !defined(_WIN32)
85 static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
86 ram_addr_t start,
87 ram_addr_t pages)
88 {
89 unsigned long i, j;
90 unsigned long page_number, c;
91 hwaddr addr;
92 ram_addr_t ram_addr;
93 unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
94 unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
95 unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
96
97 /* start address is aligned at the start of a word? */
98 if ((((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) &&
99 (hpratio == 1)) {
100 long k;
101 long nr = BITS_TO_LONGS(pages);
102
103 for (k = 0; k < nr; k++) {
104 if (bitmap[k]) {
105 unsigned long temp = leul_to_cpu(bitmap[k]);
106
107 ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION][page + k] |= temp;
108 ram_list.dirty_memory[DIRTY_MEMORY_VGA][page + k] |= temp;
109 ram_list.dirty_memory[DIRTY_MEMORY_CODE][page + k] |= temp;
110 }
111 }
112 xen_modified_memory(start, pages);
113 } else {
114 /*
115 * bitmap-traveling is faster than memory-traveling (for addr...)
116 * especially when most of the memory is not dirty.
117 */
118 for (i = 0; i < len; i++) {
119 if (bitmap[i] != 0) {
120 c = leul_to_cpu(bitmap[i]);
121 do {
122 j = ctzl(c);
123 c &= ~(1ul << j);
124 page_number = (i * HOST_LONG_BITS + j) * hpratio;
125 addr = page_number * TARGET_PAGE_SIZE;
126 ram_addr = start + addr;
127 cpu_physical_memory_set_dirty_range(ram_addr,
128 TARGET_PAGE_SIZE * hpratio);
129 } while (c != 0);
130 }
131 }
132 }
133 }
134 #endif /* not _WIN32 */
135
136 static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
137 ram_addr_t length,
138 unsigned client)
139 {
140 unsigned long end, page;
141
142 assert(client < DIRTY_MEMORY_NUM);
143 end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
144 page = start >> TARGET_PAGE_BITS;
145 bitmap_clear(ram_list.dirty_memory[client], page, end - page);
146 }
147
148 void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t length,
149 unsigned client);
150
151 #endif
152 #endif