qemu/include/exec/memory-internal.h
<<
>>
Prefs
   1/*
   2 * Declarations for functions which are internal to the memory subsystem.
   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, memory.c and accel/tcg/cputlb.c ONLY,
  16 * for declarations which are shared between the memory subsystem's
  17 * internals and the TCG TLB code. Do not include it from elsewhere.
  18 */
  19
  20#ifndef MEMORY_INTERNAL_H
  21#define MEMORY_INTERNAL_H
  22
  23#ifndef CONFIG_USER_ONLY
  24static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv)
  25{
  26    return fv->dispatch;
  27}
  28
  29static inline AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as)
  30{
  31    return flatview_to_dispatch(address_space_to_flatview(as));
  32}
  33
  34extern const MemoryRegionOps unassigned_mem_ops;
  35
  36bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr,
  37                                unsigned size, bool is_write);
  38
  39void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section);
  40AddressSpaceDispatch *address_space_dispatch_new(FlatView *fv);
  41void address_space_dispatch_compact(AddressSpaceDispatch *d);
  42void address_space_dispatch_free(AddressSpaceDispatch *d);
  43
  44void mtree_print_dispatch(fprintf_function mon, void *f,
  45                          struct AddressSpaceDispatch *d,
  46                          MemoryRegion *root);
  47
  48/* Opaque struct for passing info from memory_notdirty_write_prepare()
  49 * to memory_notdirty_write_complete(). Callers should treat all fields
  50 * as private, with the exception of @active.
  51 *
  52 * @active is a field which is not touched by either the prepare or
  53 * complete functions, but which the caller can use if it wishes to
  54 * track whether it has called prepare for this struct and so needs
  55 * to later call the complete function.
  56 */
  57typedef struct {
  58    CPUState *cpu;
  59    ram_addr_t ram_addr;
  60    vaddr mem_vaddr;
  61    unsigned size;
  62    bool locked;
  63    bool active;
  64} NotDirtyInfo;
  65
  66/**
  67 * memory_notdirty_write_prepare: call before writing to non-dirty memory
  68 * @ndi: pointer to opaque NotDirtyInfo struct
  69 * @cpu: CPU doing the write
  70 * @mem_vaddr: virtual address of write
  71 * @ram_addr: the ram address of the write
  72 * @size: size of write in bytes
  73 *
  74 * Any code which writes to the host memory corresponding to
  75 * guest RAM which has been marked as NOTDIRTY must wrap those
  76 * writes in calls to memory_notdirty_write_prepare() and
  77 * memory_notdirty_write_complete():
  78 *
  79 *  NotDirtyInfo ndi;
  80 *  memory_notdirty_write_prepare(&ndi, ....);
  81 *  ... perform write here ...
  82 *  memory_notdirty_write_complete(&ndi);
  83 *
  84 * These calls will ensure that we flush any TCG translated code for
  85 * the memory being written, update the dirty bits and (if possible)
  86 * remove the slowpath callback for writing to the memory.
  87 *
  88 * This must only be called if we are using TCG; it will assert otherwise.
  89 *
  90 * We may take a lock in the prepare call, so callers must ensure that
  91 * they don't exit (via longjump or otherwise) without calling complete.
  92 *
  93 * This call must only be made inside an RCU critical section.
  94 * (Note that while we're executing a TCG TB we're always in an
  95 * RCU critical section, which is likely to be the case for callers
  96 * of these functions.)
  97 */
  98void memory_notdirty_write_prepare(NotDirtyInfo *ndi,
  99                                   CPUState *cpu,
 100                                   vaddr mem_vaddr,
 101                                   ram_addr_t ram_addr,
 102                                   unsigned size);
 103/**
 104 * memory_notdirty_write_complete: finish write to non-dirty memory
 105 * @ndi: pointer to the opaque NotDirtyInfo struct which was initialized
 106 * by memory_not_dirty_write_prepare().
 107 */
 108void memory_notdirty_write_complete(NotDirtyInfo *ndi);
 109
 110#endif
 111#endif
 112