memory-internal.h 3.6 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * Declarations for obsolete exec.c functions
 *
 * Copyright 2011 Red Hat, Inc. and/or its affiliates
 *
 * Authors:
 *  Avi Kivity <avi@redhat.com>
 *
9 10
 * This work is licensed under the terms of the GNU GPL, version 2 or
 * later.  See the COPYING file in the top-level directory.
11 12 13 14 15 16 17 18
 *
 */

/*
 * This header is for use by exec.c and memory.c ONLY.  Do not include it.
 * The functions declared here will be removed soon.
 */

A
Avi Kivity 已提交
19 20
#ifndef MEMORY_INTERNAL_H
#define MEMORY_INTERNAL_H
21 22

#ifndef CONFIG_USER_ONLY
P
Paolo Bonzini 已提交
23
#include "hw/xen/xen.h"
24

A
Avi Kivity 已提交
25 26 27 28

typedef struct AddressSpaceDispatch AddressSpaceDispatch;

void address_space_init_dispatch(AddressSpace *as);
A
Avi Kivity 已提交
29
void address_space_destroy_dispatch(AddressSpace *as);
A
Avi Kivity 已提交
30

31 32
extern const MemoryRegionOps unassigned_mem_ops;

33 34 35
bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr,
                                unsigned size, bool is_write);

36
ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
37
                                   MemoryRegion *mr);
38
ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr);
39
void *qemu_get_ram_ptr(ram_addr_t addr);
40 41 42
void qemu_ram_free(ram_addr_t addr);
void qemu_ram_free_from_ptr(ram_addr_t addr);

43 44 45
static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
                                                 ram_addr_t length,
                                                 unsigned client)
46
{
47
    unsigned long end, page, next;
48 49 50

    assert(client < DIRTY_MEMORY_NUM);

51 52 53 54 55
    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
    page = start >> TARGET_PAGE_BITS;
    next = find_next_bit(ram_list.dirty_memory[client], end, page);

    return next < end;
56 57
}

58
static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,
59
                                                      unsigned client)
60
{
61
    return cpu_physical_memory_get_dirty(addr, 1, client);
62 63
}

64
static inline bool cpu_physical_memory_is_clean(ram_addr_t addr)
65
{
66 67
    bool vga = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_VGA);
    bool code = cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_CODE);
68
    bool migration =
69
        cpu_physical_memory_get_dirty_flag(addr, DIRTY_MEMORY_MIGRATION);
70
    return !(vga && code && migration);
71 72
}

73
static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
74
                                                      unsigned client)
75
{
76
    assert(client < DIRTY_MEMORY_NUM);
77
    set_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]);
78 79
}

80
static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
81
                                                       ram_addr_t length)
82
{
83
    unsigned long end, page;
84

85 86 87 88 89 90
    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
    page = start >> TARGET_PAGE_BITS;
    bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION], page, end - page);
    bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_VGA], page, end - page);
    bitmap_set(ram_list.dirty_memory[DIRTY_MEMORY_CODE], page, end - page);
    xen_modified_memory(start, length);
91 92
}

93 94 95
static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start,
                                                         ram_addr_t length,
                                                         unsigned client)
96
{
97
    unsigned long end, page;
98

99
    assert(client < DIRTY_MEMORY_NUM);
100 101 102
    end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS;
    page = start >> TARGET_PAGE_BITS;
    bitmap_clear(ram_list.dirty_memory[client], page, end - page);
103 104 105
}

void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
106
                                     unsigned client);
107

108 109 110
#endif

#endif