1#ifndef RAMLIST_H
2#define RAMLIST_H
3
4#include "qemu/queue.h"
5#include "qemu/thread.h"
6#include "qemu/rcu.h"
7#include "qemu/rcu_queue.h"
8
9typedef struct RAMBlockNotifier RAMBlockNotifier;
10
11#define DIRTY_MEMORY_VGA 0
12#define DIRTY_MEMORY_CODE 1
13#define DIRTY_MEMORY_MIGRATION 2
14#define DIRTY_MEMORY_NUM 3
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#define DIRTY_MEMORY_BLOCK_SIZE ((ram_addr_t)256 * 1024 * 8)
42typedef struct {
43 struct rcu_head rcu;
44 unsigned long *blocks[];
45} DirtyMemoryBlocks;
46
47typedef struct RAMList {
48 QemuMutex mutex;
49 RAMBlock *mru_block;
50
51 QLIST_HEAD(, RAMBlock) blocks;
52 DirtyMemoryBlocks *dirty_memory[DIRTY_MEMORY_NUM];
53 uint32_t version;
54 QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers;
55} RAMList;
56extern RAMList ram_list;
57
58
59#define INTERNAL_RAMBLOCK_FOREACH(block) \
60 QLIST_FOREACH_RCU(block, &ram_list.blocks, next)
61
62#define RAMBLOCK_FOREACH(block) INTERNAL_RAMBLOCK_FOREACH(block)
63
64void qemu_mutex_lock_ramlist(void);
65void qemu_mutex_unlock_ramlist(void);
66
67struct RAMBlockNotifier {
68 void (*ram_block_added)(RAMBlockNotifier *n, void *host, size_t size,
69 size_t max_size);
70 void (*ram_block_removed)(RAMBlockNotifier *n, void *host, size_t size,
71 size_t max_size);
72 void (*ram_block_resized)(RAMBlockNotifier *n, void *host, size_t old_size,
73 size_t new_size);
74 QLIST_ENTRY(RAMBlockNotifier) next;
75};
76
77void ram_block_notifier_add(RAMBlockNotifier *n);
78void ram_block_notifier_remove(RAMBlockNotifier *n);
79void ram_block_notify_add(void *host, size_t size, size_t max_size);
80void ram_block_notify_remove(void *host, size_t size, size_t max_size);
81void ram_block_notify_resize(void *host, size_t old_size, size_t new_size);
82
83GString *ram_block_format(void);
84
85#endif
86