~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to include/exec/memory.h

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <stdbool.h>
21
21
#include "qemu-common.h"
22
22
#include "exec/cpu-common.h"
 
23
#ifndef CONFIG_USER_ONLY
23
24
#include "exec/hwaddr.h"
 
25
#endif
24
26
#include "qemu/queue.h"
25
 
#include "exec/iorange.h"
26
 
#include "exec/ioport.h"
27
27
#include "qemu/int128.h"
 
28
#include "qemu/notify.h"
 
29
 
 
30
#define MAX_PHYS_ADDR_SPACE_BITS 62
 
31
#define MAX_PHYS_ADDR            (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
28
32
 
29
33
typedef struct MemoryRegionOps MemoryRegionOps;
30
 
typedef struct MemoryRegionPortio MemoryRegionPortio;
31
34
typedef struct MemoryRegionMmio MemoryRegionMmio;
32
35
 
33
36
/* Must match *_DIRTY_FLAGS in cpu-all.h.  To be replaced with dynamic
42
45
    CPUWriteMemoryFunc *write[3];
43
46
};
44
47
 
45
 
/* Internal use; thunks between old-style IORange and MemoryRegions. */
46
 
typedef struct MemoryRegionIORange MemoryRegionIORange;
47
 
struct MemoryRegionIORange {
48
 
    IORange iorange;
49
 
    MemoryRegion *mr;
50
 
    hwaddr offset;
 
48
typedef struct IOMMUTLBEntry IOMMUTLBEntry;
 
49
 
 
50
/* See address_space_translate: bit 0 is read, bit 1 is write.  */
 
51
typedef enum {
 
52
    IOMMU_NONE = 0,
 
53
    IOMMU_RO   = 1,
 
54
    IOMMU_WO   = 2,
 
55
    IOMMU_RW   = 3,
 
56
} IOMMUAccessFlags;
 
57
 
 
58
struct IOMMUTLBEntry {
 
59
    AddressSpace    *target_as;
 
60
    hwaddr           iova;
 
61
    hwaddr           translated_addr;
 
62
    hwaddr           addr_mask;  /* 0xfff = 4k translation */
 
63
    IOMMUAccessFlags perm;
51
64
};
52
65
 
53
66
/*
102
115
         bool unaligned;
103
116
    } impl;
104
117
 
105
 
    /* If .read and .write are not present, old_portio may be used for
106
 
     * backwards compatibility with old portio registration
107
 
     */
108
 
    const MemoryRegionPortio *old_portio;
109
118
    /* If .read and .write are not present, old_mmio may be used for
110
119
     * backwards compatibility with old mmio registration
111
120
     */
112
121
    const MemoryRegionMmio old_mmio;
113
122
};
114
123
 
 
124
typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps;
 
125
 
 
126
struct MemoryRegionIOMMUOps {
 
127
    /* Return a TLB entry that contains a given address. */
 
128
    IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr);
 
129
};
 
130
 
115
131
typedef struct CoalescedMemoryRange CoalescedMemoryRange;
116
132
typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd;
117
133
 
118
134
struct MemoryRegion {
119
135
    /* All fields are private - violators will be prosecuted */
120
136
    const MemoryRegionOps *ops;
 
137
    const MemoryRegionIOMMUOps *iommu_ops;
121
138
    void *opaque;
 
139
    struct Object *owner;
122
140
    MemoryRegion *parent;
123
141
    Int128 size;
124
142
    hwaddr addr;
126
144
    ram_addr_t ram_addr;
127
145
    bool subpage;
128
146
    bool terminates;
129
 
    bool readable;
 
147
    bool romd_mode;
130
148
    bool ram;
131
149
    bool readonly; /* For RAM regions */
132
150
    bool enabled;
144
162
    uint8_t dirty_log_mask;
145
163
    unsigned ioeventfd_nb;
146
164
    MemoryRegionIoeventfd *ioeventfds;
147
 
};
148
 
 
149
 
struct MemoryRegionPortio {
150
 
    uint32_t offset;
151
 
    uint32_t len;
152
 
    unsigned size;
153
 
    IOPortReadFunc *read;
154
 
    IOPortWriteFunc *write;
155
 
};
156
 
 
157
 
#define PORTIO_END_OF_LIST() { }
 
165
    NotifierList iommu_notify;
 
166
};
 
167
 
 
168
typedef struct MemoryListener MemoryListener;
 
169
 
 
170
/**
 
171
 * MemoryListener: callbacks structure for updates to the physical memory map
 
172
 *
 
173
 * Allows a component to adjust to changes in the guest-visible memory map.
 
174
 * Use with memory_listener_register() and memory_listener_unregister().
 
175
 */
 
176
struct MemoryListener {
 
177
    void (*begin)(MemoryListener *listener);
 
178
    void (*commit)(MemoryListener *listener);
 
179
    void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
 
180
    void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
 
181
    void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
 
182
    void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
 
183
    void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
 
184
    void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
 
185
    void (*log_global_start)(MemoryListener *listener);
 
186
    void (*log_global_stop)(MemoryListener *listener);
 
187
    void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
 
188
                        bool match_data, uint64_t data, EventNotifier *e);
 
189
    void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section,
 
190
                        bool match_data, uint64_t data, EventNotifier *e);
 
191
    void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section,
 
192
                               hwaddr addr, hwaddr len);
 
193
    void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
 
194
                               hwaddr addr, hwaddr len);
 
195
    /* Lower = earlier (during add), later (during del) */
 
196
    unsigned priority;
 
197
    AddressSpace *address_space_filter;
 
198
    QTAILQ_ENTRY(MemoryListener) link;
 
199
};
158
200
 
159
201
/**
160
202
 * AddressSpace: describes a mapping of addresses to #MemoryRegion objects
161
203
 */
162
204
struct AddressSpace {
163
205
    /* All fields are private. */
164
 
    const char *name;
 
206
    char *name;
165
207
    MemoryRegion *root;
166
208
    struct FlatView *current_map;
167
209
    int ioeventfd_nb;
168
210
    struct MemoryRegionIoeventfd *ioeventfds;
169
211
    struct AddressSpaceDispatch *dispatch;
 
212
    struct AddressSpaceDispatch *next_dispatch;
 
213
    MemoryListener dispatch_listener;
 
214
 
170
215
    QTAILQ_ENTRY(AddressSpace) address_spaces_link;
171
216
};
172
217
 
185
230
    MemoryRegion *mr;
186
231
    AddressSpace *address_space;
187
232
    hwaddr offset_within_region;
188
 
    uint64_t size;
 
233
    Int128 size;
189
234
    hwaddr offset_within_address_space;
190
235
    bool readonly;
191
236
};
192
237
 
193
 
typedef struct MemoryListener MemoryListener;
194
 
 
195
 
/**
196
 
 * MemoryListener: callbacks structure for updates to the physical memory map
197
 
 *
198
 
 * Allows a component to adjust to changes in the guest-visible memory map.
199
 
 * Use with memory_listener_register() and memory_listener_unregister().
200
 
 */
201
 
struct MemoryListener {
202
 
    void (*begin)(MemoryListener *listener);
203
 
    void (*commit)(MemoryListener *listener);
204
 
    void (*region_add)(MemoryListener *listener, MemoryRegionSection *section);
205
 
    void (*region_del)(MemoryListener *listener, MemoryRegionSection *section);
206
 
    void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section);
207
 
    void (*log_start)(MemoryListener *listener, MemoryRegionSection *section);
208
 
    void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section);
209
 
    void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section);
210
 
    void (*log_global_start)(MemoryListener *listener);
211
 
    void (*log_global_stop)(MemoryListener *listener);
212
 
    void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
213
 
                        bool match_data, uint64_t data, EventNotifier *e);
214
 
    void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section,
215
 
                        bool match_data, uint64_t data, EventNotifier *e);
216
 
    void (*coalesced_mmio_add)(MemoryListener *listener, MemoryRegionSection *section,
217
 
                               hwaddr addr, hwaddr len);
218
 
    void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection *section,
219
 
                               hwaddr addr, hwaddr len);
220
 
    /* Lower = earlier (during add), later (during del) */
221
 
    unsigned priority;
222
 
    AddressSpace *address_space_filter;
223
 
    QTAILQ_ENTRY(MemoryListener) link;
224
 
};
225
 
 
226
238
/**
227
239
 * memory_region_init: Initialize a memory region
228
240
 *
230
242
 * memory_region_add_subregion() to add subregions.
231
243
 *
232
244
 * @mr: the #MemoryRegion to be initialized
 
245
 * @owner: the object that tracks the region's reference count
233
246
 * @name: used for debugging; not visible to the user or ABI
234
247
 * @size: size of the region; any subregions beyond this size will be clipped
235
248
 */
236
249
void memory_region_init(MemoryRegion *mr,
 
250
                        struct Object *owner,
237
251
                        const char *name,
238
252
                        uint64_t size);
 
253
 
 
254
/**
 
255
 * memory_region_ref: Add 1 to a memory region's reference count
 
256
 *
 
257
 * Whenever memory regions are accessed outside the BQL, they need to be
 
258
 * preserved against hot-unplug.  MemoryRegions actually do not have their
 
259
 * own reference count; they piggyback on a QOM object, their "owner".
 
260
 * This function adds a reference to the owner.
 
261
 *
 
262
 * All MemoryRegions must have an owner if they can disappear, even if the
 
263
 * device they belong to operates exclusively under the BQL.  This is because
 
264
 * the region could be returned at any time by memory_region_find, and this
 
265
 * is usually under guest control.
 
266
 *
 
267
 * @mr: the #MemoryRegion
 
268
 */
 
269
void memory_region_ref(MemoryRegion *mr);
 
270
 
 
271
/**
 
272
 * memory_region_unref: Remove 1 to a memory region's reference count
 
273
 *
 
274
 * Whenever memory regions are accessed outside the BQL, they need to be
 
275
 * preserved against hot-unplug.  MemoryRegions actually do not have their
 
276
 * own reference count; they piggyback on a QOM object, their "owner".
 
277
 * This function removes a reference to the owner and possibly destroys it.
 
278
 *
 
279
 * @mr: the #MemoryRegion
 
280
 */
 
281
void memory_region_unref(MemoryRegion *mr);
 
282
 
239
283
/**
240
284
 * memory_region_init_io: Initialize an I/O memory region.
241
285
 *
243
287
 * if @size is nonzero, subregions will be clipped to @size.
244
288
 *
245
289
 * @mr: the #MemoryRegion to be initialized.
 
290
 * @owner: the object that tracks the region's reference count
246
291
 * @ops: a structure containing read and write callbacks to be used when
247
292
 *       I/O is performed on the region.
248
293
 * @opaque: passed to to the read and write callbacks of the @ops structure.
250
295
 * @size: size of the region.
251
296
 */
252
297
void memory_region_init_io(MemoryRegion *mr,
 
298
                           struct Object *owner,
253
299
                           const MemoryRegionOps *ops,
254
300
                           void *opaque,
255
301
                           const char *name,
260
306
 *                          region will modify memory directly.
261
307
 *
262
308
 * @mr: the #MemoryRegion to be initialized.
 
309
 * @owner: the object that tracks the region's reference count
263
310
 * @name: the name of the region.
264
311
 * @size: size of the region.
265
312
 */
266
313
void memory_region_init_ram(MemoryRegion *mr,
 
314
                            struct Object *owner,
267
315
                            const char *name,
268
316
                            uint64_t size);
269
317
 
273
321
 *                              region will modify memory directly.
274
322
 *
275
323
 * @mr: the #MemoryRegion to be initialized.
 
324
 * @owner: the object that tracks the region's reference count
276
325
 * @name: the name of the region.
277
326
 * @size: size of the region.
278
327
 * @ptr: memory to be mapped; must contain at least @size bytes.
279
328
 */
280
329
void memory_region_init_ram_ptr(MemoryRegion *mr,
 
330
                                struct Object *owner,
281
331
                                const char *name,
282
332
                                uint64_t size,
283
333
                                void *ptr);
287
337
 *                           part of another memory region.
288
338
 *
289
339
 * @mr: the #MemoryRegion to be initialized.
 
340
 * @owner: the object that tracks the region's reference count
290
341
 * @name: used for debugging; not visible to the user or ABI
291
342
 * @orig: the region to be referenced; @mr will be equivalent to
292
343
 *        @orig between @offset and @offset + @size - 1.
294
345
 * @size: size of the region.
295
346
 */
296
347
void memory_region_init_alias(MemoryRegion *mr,
 
348
                              struct Object *owner,
297
349
                              const char *name,
298
350
                              MemoryRegion *orig,
299
351
                              hwaddr offset,
304
356
 *                                 handled via callbacks.
305
357
 *
306
358
 * @mr: the #MemoryRegion to be initialized.
 
359
 * @owner: the object that tracks the region's reference count
307
360
 * @ops: callbacks for write access handling.
308
361
 * @name: the name of the region.
309
362
 * @size: size of the region.
310
363
 */
311
364
void memory_region_init_rom_device(MemoryRegion *mr,
 
365
                                   struct Object *owner,
312
366
                                   const MemoryRegionOps *ops,
313
367
                                   void *opaque,
314
368
                                   const char *name,
323
377
 * the memory API will cause an abort().
324
378
 *
325
379
 * @mr: the #MemoryRegion to be initialized
 
380
 * @owner: the object that tracks the region's reference count
326
381
 * @name: used for debugging; not visible to the user or ABI
327
382
 * @size: size of the region.
328
383
 */
329
384
void memory_region_init_reservation(MemoryRegion *mr,
 
385
                                    struct Object *owner,
330
386
                                    const char *name,
331
387
                                    uint64_t size);
 
388
 
 
389
/**
 
390
 * memory_region_init_iommu: Initialize a memory region that translates
 
391
 * addresses
 
392
 *
 
393
 * An IOMMU region translates addresses and forwards accesses to a target
 
394
 * memory region.
 
395
 *
 
396
 * @mr: the #MemoryRegion to be initialized
 
397
 * @owner: the object that tracks the region's reference count
 
398
 * @ops: a function that translates addresses into the @target region
 
399
 * @name: used for debugging; not visible to the user or ABI
 
400
 * @size: size of the region.
 
401
 */
 
402
void memory_region_init_iommu(MemoryRegion *mr,
 
403
                              struct Object *owner,
 
404
                              const MemoryRegionIOMMUOps *ops,
 
405
                              const char *name,
 
406
                              uint64_t size);
 
407
 
332
408
/**
333
409
 * memory_region_destroy: Destroy a memory region and reclaim all resources.
334
410
 *
339
415
void memory_region_destroy(MemoryRegion *mr);
340
416
 
341
417
/**
 
418
 * memory_region_owner: get a memory region's owner.
 
419
 *
 
420
 * @mr: the memory region being queried.
 
421
 */
 
422
struct Object *memory_region_owner(MemoryRegion *mr);
 
423
 
 
424
/**
342
425
 * memory_region_size: get a memory region's size.
343
426
 *
344
427
 * @mr: the memory region being queried.
355
438
bool memory_region_is_ram(MemoryRegion *mr);
356
439
 
357
440
/**
358
 
 * memory_region_is_romd: check whether a memory region is ROMD
 
441
 * memory_region_is_romd: check whether a memory region is in ROMD mode
359
442
 *
360
 
 * Returns %true is a memory region is ROMD and currently set to allow
 
443
 * Returns %true if a memory region is a ROM device and currently set to allow
361
444
 * direct reads.
362
445
 *
363
446
 * @mr: the memory region being queried
364
447
 */
365
448
static inline bool memory_region_is_romd(MemoryRegion *mr)
366
449
{
367
 
    return mr->rom_device && mr->readable;
 
450
    return mr->rom_device && mr->romd_mode;
368
451
}
369
452
 
370
453
/**
 
454
 * memory_region_is_iommu: check whether a memory region is an iommu
 
455
 *
 
456
 * Returns %true is a memory region is an iommu.
 
457
 *
 
458
 * @mr: the memory region being queried
 
459
 */
 
460
bool memory_region_is_iommu(MemoryRegion *mr);
 
461
 
 
462
/**
 
463
 * memory_region_notify_iommu: notify a change in an IOMMU translation entry.
 
464
 *
 
465
 * @mr: the memory region that was changed
 
466
 * @entry: the new entry in the IOMMU translation table.  The entry
 
467
 *         replaces all old entries for the same virtual I/O address range.
 
468
 *         Deleted entries have .@perm == 0.
 
469
 */
 
470
void memory_region_notify_iommu(MemoryRegion *mr,
 
471
                                IOMMUTLBEntry entry);
 
472
 
 
473
/**
 
474
 * memory_region_register_iommu_notifier: register a notifier for changes to
 
475
 * IOMMU translation entries.
 
476
 *
 
477
 * @mr: the memory region to observe
 
478
 * @n: the notifier to be added; the notifier receives a pointer to an
 
479
 *     #IOMMUTLBEntry as the opaque value; the pointer ceases to be
 
480
 *     valid on exit from the notifier.
 
481
 */
 
482
void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n);
 
483
 
 
484
/**
 
485
 * memory_region_unregister_iommu_notifier: unregister a notifier for
 
486
 * changes to IOMMU translation entries.
 
487
 *
 
488
 * @n: the notifier to be removed.
 
489
 */
 
490
void memory_region_unregister_iommu_notifier(Notifier *n);
 
491
 
 
492
/**
371
493
 * memory_region_name: get a memory region's name
372
494
 *
373
495
 * Returns the string that was used to initialize the memory region.
502
624
void memory_region_set_readonly(MemoryRegion *mr, bool readonly);
503
625
 
504
626
/**
505
 
 * memory_region_rom_device_set_readable: enable/disable ROM readability
 
627
 * memory_region_rom_device_set_romd: enable/disable ROMD mode
506
628
 *
507
629
 * Allows a ROM device (initialized with memory_region_init_rom_device() to
508
 
 * to be marked as readable (default) or not readable.  When it is readable,
509
 
 * the device is mapped to guest memory.  When not readable, reads are
510
 
 * forwarded to the #MemoryRegion.read function.
 
630
 * set to ROMD mode (default) or MMIO mode.  When it is in ROMD mode, the
 
631
 * device is mapped to guest memory and satisfies read access directly.
 
632
 * When in MMIO mode, reads are forwarded to the #MemoryRegion.read function.
 
633
 * Writes are always handled by the #MemoryRegion.write function.
511
634
 *
512
635
 * @mr: the memory region to be updated
513
 
 * @readable: whether reads are satisified directly (%true) or via callbacks
514
 
 *            (%false)
 
636
 * @romd_mode: %true to put the region into ROMD mode
515
637
 */
516
 
void memory_region_rom_device_set_readable(MemoryRegion *mr, bool readable);
 
638
void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode);
517
639
 
518
640
/**
519
641
 * memory_region_set_coalescing: Enable memory coalescing for the region.
718
840
                                    hwaddr offset);
719
841
 
720
842
/**
721
 
 * memory_region_find: locate a MemoryRegion in an address space
722
 
 *
723
 
 * Locates the first #MemoryRegion within an address space given by
724
 
 * @address_space that overlaps the range given by @addr and @size.
 
843
 * memory_region_present: translate an address/size relative to a
 
844
 * MemoryRegion into a #MemoryRegionSection.
 
845
 *
 
846
 * Answer whether a #MemoryRegion within @parent covers the address
 
847
 * @addr.
 
848
 *
 
849
 * @parent: a MemoryRegion within which @addr is a relative address
 
850
 * @addr: the area within @parent to be searched
 
851
 */
 
852
bool memory_region_present(MemoryRegion *parent, hwaddr addr);
 
853
 
 
854
/**
 
855
 * memory_region_find: translate an address/size relative to a
 
856
 * MemoryRegion into a #MemoryRegionSection.
 
857
 *
 
858
 * Locates the first #MemoryRegion within @mr that overlaps the range
 
859
 * given by @addr and @size.
725
860
 *
726
861
 * Returns a #MemoryRegionSection that describes a contiguous overlap.
727
862
 * It will have the following characteristics:
 
863
 *    .@size = 0 iff no overlap was found
 
864
 *    .@mr is non-%NULL iff an overlap was found
 
865
 *
 
866
 * Remember that in the return value the @offset_within_region is
 
867
 * relative to the returned region (in the .@mr field), not to the
 
868
 * @mr argument.
 
869
 *
 
870
 * Similarly, the .@offset_within_address_space is relative to the
 
871
 * address space that contains both regions, the passed and the
 
872
 * returned one.  However, in the special case where the @mr argument
 
873
 * has no parent (and thus is the root of the address space), the
 
874
 * following will hold:
728
875
 *    .@offset_within_address_space >= @addr
729
876
 *    .@offset_within_address_space + .@size <= @addr + @size
730
 
 *    .@size = 0 iff no overlap was found
731
 
 *    .@mr is non-%NULL iff an overlap was found
732
877
 *
733
 
 * @address_space: a top-level (i.e. parentless) region that contains
734
 
 *       the region to be found
735
 
 * @addr: start of the area within @address_space to be searched
 
878
 * @mr: a MemoryRegion within which @addr is a relative address
 
879
 * @addr: start of the area within @as to be searched
736
880
 * @size: size of the area to be searched
737
881
 */
738
 
MemoryRegionSection memory_region_find(MemoryRegion *address_space,
 
882
MemoryRegionSection memory_region_find(MemoryRegion *mr,
739
883
                                       hwaddr addr, uint64_t size);
740
884
 
741
885
/**
742
 
 * memory_region_section_addr: get offset within MemoryRegionSection
743
 
 *
744
 
 * Returns offset within MemoryRegionSection
745
 
 *
746
 
 * @section: the memory region section being queried
747
 
 * @addr: address in address space
748
 
 */
749
 
static inline hwaddr
750
 
memory_region_section_addr(MemoryRegionSection *section,
751
 
                           hwaddr addr)
752
 
{
753
 
    addr -= section->offset_within_address_space;
754
 
    addr += section->offset_within_region;
755
 
    return addr;
756
 
}
757
 
 
758
 
/**
759
 
 * memory_global_sync_dirty_bitmap: synchronize the dirty log for all memory
 
886
 * address_space_sync_dirty_bitmap: synchronize the dirty log for all memory
760
887
 *
761
888
 * Synchronizes the dirty page log for an entire address space.
762
 
 * @address_space: a top-level (i.e. parentless) region that contains the
763
 
 *       memory being synchronized
 
889
 * @as: the address space that contains the memory being synchronized
764
890
 */
765
 
void memory_global_sync_dirty_bitmap(MemoryRegion *address_space);
 
891
void address_space_sync_dirty_bitmap(AddressSpace *as);
766
892
 
767
893
/**
768
894
 * memory_region_transaction_begin: Start a transaction.
812
938
 *
813
939
 * @as: an uninitialized #AddressSpace
814
940
 * @root: a #MemoryRegion that routes addesses for the address space
 
941
 * @name: an address space name.  The name is only used for debugging
 
942
 *        output.
815
943
 */
816
 
void address_space_init(AddressSpace *as, MemoryRegion *root);
 
944
void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name);
817
945
 
818
946
 
819
947
/**
830
958
/**
831
959
 * address_space_rw: read from or write to an address space.
832
960
 *
 
961
 * Return true if the operation hit any unassigned memory or encountered an
 
962
 * IOMMU fault.
 
963
 *
833
964
 * @as: #AddressSpace to be accessed
834
965
 * @addr: address within that address space
835
966
 * @buf: buffer with the data transferred
836
967
 * @is_write: indicates the transfer direction
837
968
 */
838
 
void address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
 
969
bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
839
970
                      int len, bool is_write);
840
971
 
841
972
/**
842
973
 * address_space_write: write to address space.
843
974
 *
 
975
 * Return true if the operation hit any unassigned memory or encountered an
 
976
 * IOMMU fault.
 
977
 *
844
978
 * @as: #AddressSpace to be accessed
845
979
 * @addr: address within that address space
846
980
 * @buf: buffer with the data transferred
847
981
 */
848
 
void address_space_write(AddressSpace *as, hwaddr addr,
 
982
bool address_space_write(AddressSpace *as, hwaddr addr,
849
983
                         const uint8_t *buf, int len);
850
984
 
851
985
/**
852
986
 * address_space_read: read from an address space.
853
987
 *
 
988
 * Return true if the operation hit any unassigned memory or encountered an
 
989
 * IOMMU fault.
 
990
 *
854
991
 * @as: #AddressSpace to be accessed
855
992
 * @addr: address within that address space
856
993
 * @buf: buffer with the data transferred
857
994
 */
858
 
void address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len);
 
995
bool address_space_read(AddressSpace *as, hwaddr addr, uint8_t *buf, int len);
 
996
 
 
997
/* address_space_translate: translate an address range into an address space
 
998
 * into a MemoryRegion and an address range into that section
 
999
 *
 
1000
 * @as: #AddressSpace to be accessed
 
1001
 * @addr: address within that address space
 
1002
 * @xlat: pointer to address within the returned memory region section's
 
1003
 * #MemoryRegion.
 
1004
 * @len: pointer to length
 
1005
 * @is_write: indicates the transfer direction
 
1006
 */
 
1007
MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
 
1008
                                      hwaddr *xlat, hwaddr *len,
 
1009
                                      bool is_write);
 
1010
 
 
1011
/* address_space_access_valid: check for validity of accessing an address
 
1012
 * space range
 
1013
 *
 
1014
 * Check whether memory is assigned to the given address space range, and
 
1015
 * access is permitted by any IOMMU regions that are active for the address
 
1016
 * space.
 
1017
 *
 
1018
 * For now, addr and len should be aligned to a page size.  This limitation
 
1019
 * will be lifted in the future.
 
1020
 *
 
1021
 * @as: #AddressSpace to be accessed
 
1022
 * @addr: address within that address space
 
1023
 * @len: length of the area to be checked
 
1024
 * @is_write: indicates the transfer direction
 
1025
 */
 
1026
bool address_space_access_valid(AddressSpace *as, hwaddr addr, int len, bool is_write);
859
1027
 
860
1028
/* address_space_map: map a physical memory region into a host virtual address
861
1029
 *