memory-internal.h 4.1 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
23
#include "hw/xen.h"
24

A
Avi Kivity 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
typedef struct PhysPageEntry PhysPageEntry;

struct PhysPageEntry {
    uint16_t is_leaf : 1;
     /* index into phys_sections (is_leaf) or phys_map_nodes (!is_leaf) */
    uint16_t ptr : 15;
};

typedef struct AddressSpaceDispatch AddressSpaceDispatch;

struct AddressSpaceDispatch {
    /* This is a multi-level map on the physical address space.
     * The bottom level has pointers to MemoryRegionSections.
     */
    PhysPageEntry phys_map;
    MemoryListener listener;
};

void address_space_init_dispatch(AddressSpace *as);
A
Avi Kivity 已提交
44
void address_space_destroy_dispatch(AddressSpace *as);
A
Avi Kivity 已提交
45

46
ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
47
                                   MemoryRegion *mr);
48
ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr);
49 50 51
void qemu_ram_free(ram_addr_t addr);
void qemu_ram_free_from_ptr(ram_addr_t addr);

52
struct MemoryRegion;
53
struct MemoryRegionSection;
54

A
Avi Kivity 已提交
55 56
void qemu_register_coalesced_mmio(hwaddr addr, ram_addr_t size);
void qemu_unregister_coalesced_mmio(hwaddr addr, ram_addr_t size);
57

58 59 60 61
#define VGA_DIRTY_FLAG       0x01
#define CODE_DIRTY_FLAG      0x02
#define MIGRATION_DIRTY_FLAG 0x08

J
Juan Quintela 已提交
62
static inline int cpu_physical_memory_get_dirty_flags(ram_addr_t addr)
63
{
J
Juan Quintela 已提交
64
    return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS];
65 66
}

J
Juan Quintela 已提交
67 68
/* read dirty bit (return 0 or 1) */
static inline int cpu_physical_memory_is_dirty(ram_addr_t addr)
69
{
J
Juan Quintela 已提交
70
    return cpu_physical_memory_get_dirty_flags(addr) == 0xff;
71 72
}

73 74
static inline int cpu_physical_memory_get_dirty(ram_addr_t start,
                                                ram_addr_t length,
75 76
                                                int dirty_flags)
{
77 78 79 80 81 82
    int ret = 0;
    ram_addr_t addr, end;

    end = TARGET_PAGE_ALIGN(start + length);
    start &= TARGET_PAGE_MASK;
    for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
J
Juan Quintela 已提交
83
        ret |= cpu_physical_memory_get_dirty_flags(addr) & dirty_flags;
84 85
    }
    return ret;
86 87
}

J
Juan Quintela 已提交
88 89 90 91 92 93
static inline int cpu_physical_memory_set_dirty_flags(ram_addr_t addr,
                                                      int dirty_flags)
{
    return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] |= dirty_flags;
}

94 95
static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
{
J
Juan Quintela 已提交
96
    cpu_physical_memory_set_dirty_flags(addr, 0xff);
97 98
}

J
Juan Quintela 已提交
99 100
static inline int cpu_physical_memory_clear_dirty_flags(ram_addr_t addr,
                                                        int dirty_flags)
101
{
J
Juan Quintela 已提交
102 103 104
    int mask = ~dirty_flags;

    return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] &= mask;
105 106
}

107 108 109 110 111 112
static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
                                                       ram_addr_t length,
                                                       int dirty_flags)
{
    ram_addr_t addr, end;

113 114 115
    end = TARGET_PAGE_ALIGN(start + length);
    start &= TARGET_PAGE_MASK;
    for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
J
Juan Quintela 已提交
116
        cpu_physical_memory_set_dirty_flags(addr, dirty_flags);
117
    }
118
    xen_modified_memory(addr, length);
119 120
}

121
static inline void cpu_physical_memory_mask_dirty_range(ram_addr_t start,
122
                                                        ram_addr_t length,
123 124
                                                        int dirty_flags)
{
125
    ram_addr_t addr, end;
126

127 128 129
    end = TARGET_PAGE_ALIGN(start + length);
    start &= TARGET_PAGE_MASK;
    for (addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
J
Juan Quintela 已提交
130
        cpu_physical_memory_clear_dirty_flags(addr, dirty_flags);
131 132 133 134 135
    }
}

void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
                                     int dirty_flags);
136 137 138

extern const IORangeOps memory_region_iorange_ops;

139 140 141
#endif

#endif