Memory-related changes sneak peek for 1.6
Subsystems (2)
cover Memory-related changes sneak peek for 1.6
Patches 1-10 are small changes, some of them bugfixes for the IOMMU portion of the patches.
Patches 11-13 introduce three new address_space APIs and clean up the dispatch logic a bit by removing memory_region_section_addr.
Patches 14-22 introduce IOMMU memory regions, convert sPAPR to the new API, and finally eliminate DMAContext in favor of AddressSpace.
Patches 24-37 set an owner on all regions owned by hot-unpluggable devices (and several others when that was easy), and add ref/unref calls that keep the regions alive even if the owner is hot-unplugged.
Patches 38-40 make memory_region_find safe for usage outside the BQL.
These patches are also at git://github.com/bonzini/qemu.git, branch iommu.
Please review!
Alexey Kardashevskiy (1):
memory: give name to every AddressSpace
Avi Kivity (5):
memory: fix address space initialization/destruction
memory: limit sections in the radix tree to the actual address space
size
memory: iommu support
vfio: abort if an emulated iommu is used
pci: use memory core for iommu support
Jan Kiszka (3):
memory: Replace open-coded memory_region_is_romd
memory: Rename readable flag to romd_mode
memory: Introduce address_space_lookup_region
Paolo Bonzini (31):
memory: assert that PhysPageEntry's ptr does not overflow
memory: allow memory_region_find() to run on non-root memory regions
memory: do not duplicate memory_region_destructor_none
memory: make memory_global_sync_dirty_bitmap take an AddressSpace
memory: create FlatView for new address spaces
exec: remove obsolete comment
memory: add address_space_valid
memory: add address_space_translate
spapr: convert TCE API to use an opaque type
spapr: make IOMMU translation go through IOMMUTLBEntry
spapr: use memory core for iommu support
dma: eliminate old-style IOMMU support
spapr_vio: take care of creating our own AddressSpace/DMAContext
dma: eliminate DMAContext
memory: add getter/setter for owner
memory: add ref/unref
memory: add ref/unref calls
pci: set owner for BARs
sysbus: set owner for MMIO regions
acpi: add memory_region_set_owner calls
misc: add memory_region_set_owner calls
isa/portio: allow setting an owner
vga: add memory_region_set_owner calls
pci-assign: add memory_region_set_owner calls
vfio: add memory_region_set_owner calls
exec: check MRU in qemu_ram_addr_from_host
memory: return MemoryRegion from qemu_ram_addr_from_host
memory: ref/unref memory across address_space_map/unmap
memory: access FlatView from a local variable
memory: use a new FlatView pointer on every topology update
memory: add reference counting to FlatView
arch_init.c | 2 +- cputlb.c | 20 ++- dma-helpers.c | 180 +------------------ exec.c | 315 ++++++++++++++++++++++----------- hw/acpi/ich9.c | 1 + hw/acpi/piix4.c | 5 + hw/block/pflash_cfi01.c | 6 +- hw/block/pflash_cfi02.c | 2 +- hw/char/serial-pci.c | 1 + hw/core/loader.c | 1 + hw/core/sysbus.c | 2 + hw/display/cirrus_vga.c | 19 ++- hw/display/exynos4210_fimd.c | 6 + hw/display/framebuffer.c | 10 +- hw/display/qxl.c | 5 +- hw/display/vga-isa-mm.c | 2 +- hw/display/vga-isa.c | 4 +- hw/display/vga-pci.c | 5 +- hw/display/vga.c | 19 ++- hw/display/vga_int.h | 9 +- hw/display/vmware_vga.c | 4 +- hw/dma/pl330.c | 8 +- hw/i386/kvm/ioapic.c | 2 + hw/i386/kvm/pci-assign.c | 11 ++ hw/i386/kvmvapic.c | 1 + hw/ide/ahci.c | 18 +- hw/ide/ahci.h | 4 +- hw/ide/ich.c | 2 +- hw/ide/macio.c | 4 +- hw/isa/apm.c | 1 + hw/isa/isa-bus.c | 2 + hw/misc/pc-testdev.c | 7 + hw/misc/vfio.c | 12 ++ hw/pci/pci.c | 53 +++--- hw/ppc/spapr_iommu.c | 108 +++++------- hw/ppc/spapr_pci.c | 18 ++- hw/ppc/spapr_vio.c | 13 +- hw/scsi/megasas.c | 4 +- hw/scsi/virtio-scsi.c | 2 +- hw/scsi/vmw_pvscsi.c | 2 +- hw/sd/sdhci.c | 22 ++-- hw/usb/hcd-ehci-pci.c | 4 +- hw/usb/hcd-ehci-sysbus.c | 2 +- hw/usb/hcd-ehci.c | 12 +- hw/usb/hcd-ehci.h | 2 +- hw/usb/hcd-ohci.c | 30 ++-- hw/usb/libhw.c | 4 +- hw/virtio/dataplane/hostmem.c | 7 + hw/virtio/vhost.c | 2 + hw/virtio/virtio-balloon.c | 1 + hw/xen/xen_pt.c | 4 + include/exec/cpu-common.h | 2 +- include/exec/cputlb.h | 12 +- include/exec/ioport.h | 3 + include/exec/memory.h | 186 +++++++++++++++---- include/hw/pci-host/spapr.h | 2 +- include/hw/pci/pci.h | 24 ++-- include/hw/pci/pci_bus.h | 5 +- include/hw/ppc/spapr.h | 12 +- include/hw/ppc/spapr_vio.h | 36 +++-- include/hw/virtio/dataplane/hostmem.h | 1 + include/sysemu/dma.h | 158 +++++------------ ioport.c | 10 + kvm-all.c | 2 + memory.c | 267 ++++++++++++++++++++++------ target-arm/kvm.c | 2 + target-i386/kvm.c | 4 +- target-sparc/mmu_helper.c | 1 + translate-all.c | 8 +- xen-all.c | 2 + 70 files changed, 983 insertions(+), 734 deletions(-)
Quoted 1 line
From
aec410066128aaca6337754c389f0e7c2d47089cMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 11:30:23 +0200
Subject: [PATCH 01/40] memory: assert that PhysPageEntry's ptr does not overflow
--- exec.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
exec.c +2 -0
@@ -719,6 +719,8 @@ static void destroy_all_mappings(AddressSpaceDispatch *d)static uint16_t phys_section_add (MemoryRegionSection *section) { +assert (phys_sections_nb <TARGET_PAGE_SIZE ); +if (phys_sections_nb == phys_sections_nb_alloc) { phys_sections_nb_alloc =MAX (phys_sections_nb_alloc *2 ,16 ); phys_sections = g_renew(MemoryRegionSection, phys_sections,
Signature · 1 line
1.7.1
Quoted 1 line
From
4434e2f8603954905655a79b73f1b9859e20f227Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 15:48:28 +0200
Subject: [PATCH 02/40] memory: allow memory_region_find() to run on non-root memory regions
memory_region_find() is similar to registering a MemoryListener and checking for the MemoryRegionSections that come from a particular region. There is no reason for this to be limited to a root memory region.
--- include/exec/memory.h | 13 +++++++------ memory.c | 20 +++++++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-)
include/exec/memory.h +7 -6
@@ -725,17 +725,18 @@ void memory_region_set_alias_offset(MemoryRegion *mr,* * Returns a #MemoryRegionSection that describes a contiguous overlap. * It will have the following characteristics: -* .@offset_within_address_space >= @addr -* .@offset_within_address_space + .@size <= @addr + @size * .@size = 0 iff no overlap was found * .@mr is non-%NULL iff an overlap was found * -* @address_space: a top-level (i.e. parentless) region that contains -* the region to be found -* @addr: start of the area within @address_space to be searched +* If @mr is parent-less, +* .@offset_within_address_space >= @addr +* .@offset_within_address_space + .@size <= @addr + @size +* +* @mr: a (possibly indirect) parent that contains the region to be found +* @addr: start of the area within @as to be searched * @size: size of the area to be searched */ -MemoryRegionSection memory_region_find (MemoryRegion *address_space, +MemoryRegionSection memory_region_find (MemoryRegion *mr,hwaddr addr,uint64_t size);/**
memory.c +15 -5
@@ -1451,15 +1451,24 @@ static FlatRange *address_space_lookup(AddressSpace *as, AddrRange addr) sizeof(FlatRange), cmp_flatrange_addr); } -MemoryRegionSection memory_region_find (MemoryRegion *address_space, +MemoryRegionSection memory_region_find (MemoryRegion *mr,hwaddr addr,uint64_t size) { -AddressSpace *as =memory_region_to_address_space (address_space); -AddrRange range =addrrange_make (int128_make64 (addr), -int128_make64 (size)); -FlatRange *fr =address_space_lookup (as, range);MemoryRegionSection ret = { .mr =NULL , .size =0 }; +MemoryRegion *root; +AddressSpace *as; +AddrRange range; +FlatRange *fr; + + addr += mr->addr; +for (root = mr; root->parent; ) { + root = root->parent; + addr += root->addr; + } + as =memory_region_to_address_space (root); + range =addrrange_make (int128_make64 (addr),int128_make64 (size)); + fr =address_space_lookup (as, range);if (!fr) {return ret; }
@@ -1470,6 +1479,7 @@ MemoryRegionSection memory_region_find(MemoryRegion *address_space, } ret.mr = fr->mr; + ret.address_space = as; range =addrrange_intersection (range, fr->addr); ret.offset_within_region = fr->offset_in_region; ret.offset_within_region += int128_get64(int128_sub(range.start,
Signature · 1 line
1.7.1
Quoted 1 line
From
b3e8ad57d21913dd7a8dfee6578c987095ed6831Mon Sep 17 00:00:00 2001
From: Jan Kiszka <[email protected]>
Date: Mon, 6 May 2013 18:07:05 +0200
Subject: [PATCH 03/40] memory: Replace open-coded memory_region_is_romd
Improves readability.
--- translate-all.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
translate-all.c +1 -1
@@ -1359,7 +1359,7 @@ void tb_invalidate_phys_addr(hwaddr addr) section =phys_page_find (address_space_memory.dispatch, addr >>TARGET_PAGE_BITS );if (!(memory_region_is_ram (section->mr) - || (section->mr->rom_device && section->mr->readable))) { + ||memory_region_is_romd (section->mr))) {return ; } ram_addr = (memory_region_get_ram_addr (section->mr) &TARGET_PAGE_MASK )
Signature · 1 line
1.7.1
Quoted 1 line
From
5f2a3cce1385d2abd93a0c8bcbf5e58a02db82c0Mon Sep 17 00:00:00 2001
From: Jan Kiszka <[email protected]>
Date: Mon, 6 May 2013 18:12:06 +0200
Subject: [PATCH 04/40] memory: Rename readable flag to romd_mode
"Readable" is a very unfortunate name for this flag because even a rom_device region will always be readable from the guest POV. What differs is the mapping, just like the comments had to explain already. Also, readable could currently be understood as being a generic region flag, but it only applies to rom_device regions.
So name the flag and the function to modify it after the original term "ROMD" which could also be interpreted as "ROM direct", i.e. ROM mode with direct access. In any case, the scope if the flag is clearer now.
--- hw/block/pflash_cfi01.c | 6 +++--- hw/block/pflash_cfi02.c | 2 +- include/exec/memory.h | 22 +++++++++++----------- memory.c | 30 +++++++++++++++--------------- 4 files changed, 30 insertions(+), 30 deletions(-)
hw/block/pflash_cfi01.c +3 -3
@@ -105,7 +105,7 @@ static void pflash_timer (void *opaque)DPRINTF ("%s: command %02x done\n" , __func__, pfl->cmd);/* Reset flash */ pfl->status ^=0x80 ; -memory_region_rom_device_set_readable (&pfl->mem, true); +memory_region_rom_device_set_romd (&pfl->mem, true); pfl->wcycle =0 ; pfl->cmd =0 ; }
@@ -281,7 +281,7 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,if (!pfl->wcycle) {/* Set the device in I/O access mode */ -memory_region_rom_device_set_readable (&pfl->mem, false); +memory_region_rom_device_set_romd (&pfl->mem, false); }switch (pfl->wcycle) {
@@ -458,7 +458,7 @@ static void pflash_write(pflash_t *pfl, hwaddr offset, "\n", __func__, offset, pfl->wcycle, pfl->cmd, value); reset_flash: -memory_region_rom_device_set_readable (&pfl->mem, true); +memory_region_rom_device_set_romd (&pfl->mem, true); pfl->wcycle =0 ; pfl->cmd =0 ;
hw/block/pflash_cfi02.c +1 -1
@@ -111,7 +111,7 @@ static void pflash_setup_mappings(pflash_t *pfl)static void pflash_register_memory (pflash_t *pfl,int rom_mode) { -memory_region_rom_device_set_readable (&pfl->orig_mem, rom_mode); +memory_region_rom_device_set_romd (&pfl->orig_mem, rom_mode); pfl->rom_mode = rom_mode; }
include/exec/memory.h +11 -11
@@ -126,7 +126,7 @@ struct MemoryRegion {ram_addr_t ram_addr;bool subpage;bool terminates; -bool readable; +bool romd_mode;bool ram;bool readonly;/* For RAM regions */ bool enabled;
@@ -355,16 +355,16 @@ uint64_t memory_region_size(MemoryRegion *mr);bool memory_region_is_ram (MemoryRegion *mr);/** -* memory_region_is_romd: check whether a memory region is ROMD +* memory_region_is_romd: check whether a memory region is in ROMD mode * -* Returns %true is a memory region is ROMD and currently set to allow +* Returns %true is a memory region is a ROM device and currently set to allow * direct reads. * * @mr: the memory region being queried */ static inline bool memory_region_is_romd (MemoryRegion *mr) { -return mr->rom_device && mr->readable; +return mr->rom_device && mr->romd_mode; }/**
@@ -502,18 +502,18 @@ void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,void memory_region_set_readonly (MemoryRegion *mr,bool readonly);/** -* memory_region_rom_device_set_readable: enable/disable ROM readability +* memory_region_rom_device_set_romd: enable/disable ROMD mode * * Allows a ROM device (initialized with memory_region_init_rom_device() to -* to be marked as readable (default) or not readable. When it is readable, -* the device is mapped to guest memory. When not readable, reads are -* forwarded to the #MemoryRegion.read function. +* set to ROMD mode (default) or MMIO mode. When it is in ROMD mode, the +* device is mapped to guest memory and satisfies read access directly. +* When in MMIO mode, reads are forwarded to the #MemoryRegion.read function. +* Writes are always handled by the #MemoryRegion.write function. * * @mr: the memory region to be updated -* @readable: whether reads are satisified directly (%true) or via callbacks -* (%false) +* @romd_mode: whether the region in in ROMD mode or not */ -void memory_region_rom_device_set_readable (MemoryRegion *mr,bool readable); +void memory_region_rom_device_set_romd (MemoryRegion *mr,bool romd_mode);/** * memory_region_set_coalescing: Enable memory coalescing for the region.
memory.c +15 -15
@@ -213,7 +213,7 @@ struct FlatRange {hwaddr offset_in_region;AddrRange addr;uint8_t dirty_log_mask; -bool readable; +bool romd_mode;bool readonly; };
@@ -236,7 +236,7 @@ static bool flatrange_equal(FlatRange *a, FlatRange *b)return a->mr == b->mr &&addrrange_equal (a->addr, b->addr) && a->offset_in_region == b->offset_in_region - && a->readable == b->readable + && a->romd_mode == b->romd_mode && a->readonly == b->readonly; }
@@ -276,7 +276,7 @@ static bool can_merge(FlatRange *r1, FlatRange *r2) r1->addr.size), int128_make64(r2->offset_in_region)) && r1->dirty_log_mask == r2->dirty_log_mask - && r1->readable == r2->readable + && r1->romd_mode == r2->romd_mode && r1->readonly == r2->readonly; }
@@ -532,7 +532,7 @@ static void render_memory_region(FlatView *view, fr.offset_in_region = offset_in_region; fr.addr =addrrange_make (base, now); fr.dirty_log_mask = mr->dirty_log_mask; - fr.readable = mr->readable; + fr.romd_mode = mr->romd_mode; fr.readonly = readonly;flatview_insert (view, i, &fr); ++i;
@@ -552,7 +552,7 @@ static void render_memory_region(FlatView *view, fr.offset_in_region = offset_in_region; fr.addr =addrrange_make (base, remain); fr.dirty_log_mask = mr->dirty_log_mask; - fr.readable = mr->readable; + fr.romd_mode = mr->romd_mode; fr.readonly = readonly;flatview_insert (view, i, &fr); }
@@ -801,7 +801,7 @@ void memory_region_init(MemoryRegion *mr, mr->enabled = true; mr->terminates = false; mr->ram = false; - mr->readable = true; + mr->romd_mode = true; mr->readonly = false; mr->rom_device = false; mr->destructor = memory_region_destructor_none;
@@ -1121,11 +1121,11 @@ void memory_region_set_readonly(MemoryRegion *mr, bool readonly) } } -void memory_region_rom_device_set_readable (MemoryRegion *mr,bool readable) +void memory_region_rom_device_set_romd (MemoryRegion *mr,bool romd_mode) { -if (mr->readable != readable) { +if (mr->romd_mode != romd_mode) {memory_region_transaction_begin (); - mr->readable = readable; + mr->romd_mode = romd_mode; memory_region_update_pending |= mr->enabled;memory_region_transaction_commit (); }
@@ -1659,9 +1659,9 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f, base + mr->addr + (hwaddr )int128_get64 (mr->size) -1 , mr->priority, - mr->readable ?'R' :'-' , - !mr->readonly && !(mr->rom_device && mr->readable) ?'W' - :'-' , + mr->romd_mode ?'R' :'-' , + !mr->readonly && !(mr->rom_device && mr->romd_mode) ?'W' + :'-' , mr->name, mr->alias->name, mr->alias_offset,
@@ -1674,9 +1674,9 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f, base + mr->addr + (hwaddr )int128_get64 (mr->size) -1 , mr->priority, - mr->readable ?'R' :'-' , - !mr->readonly && !(mr->rom_device && mr->readable) ?'W' - :'-' , + mr->romd_mode ?'R' :'-' , + !mr->readonly && !(mr->rom_device && mr->romd_mode) ?'W' + :'-' , mr->name); }
Signature · 1 line
1.7.1
Quoted 1 line
From
98f505210d420ea66a2c9566657527c2c61e1a38Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Fri, 3 May 2013 17:18:36 +0200
Subject: [PATCH 05/40] memory: do not duplicate memory_region_destructor_none
--- memory.c | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-)
memory.c +1 -5
@@ -768,10 +768,6 @@ static void memory_region_destructor_ram_from_ptr(MemoryRegion *mr)qemu_ram_free_from_ptr (mr->ram_addr); } -static void memory_region_destructor_iomem (MemoryRegion *mr) -{ -} -static void memory_region_destructor_rom_device (MemoryRegion *mr) {qemu_ram_free (mr->ram_addr &TARGET_PAGE_MASK );
@@ -929,7 +925,7 @@ void memory_region_init_io(MemoryRegion *mr, mr->ops = ops; mr->opaque = opaque; mr->terminates = true; - mr->destructor = memory_region_destructor_iomem; + mr->destructor = memory_region_destructor_none; mr->ram_addr = ~(ram_addr_t )0 ; }
Signature · 1 line
1.7.1
Quoted 1 line
From
0f9f5c1fc24b61563cd4ba7af812ace0a6cb1152Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Wed, 24 Apr 2013 10:46:55 +0200
Subject: [PATCH 06/40] memory: make memory_global_sync_dirty_bitmap take an AddressSpace
--- arch_init.c | 2 +- include/exec/memory.h | 7 +++---- memory.c | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-)
arch_init.c +1 -1
@@ -386,7 +386,7 @@ static void migration_bitmap_sync(void) }trace_migration_bitmap_sync_start (); -memory_global_sync_dirty_bitmap (get_system_memory ()); +address_space_sync_dirty_bitmap (&address_space_memory); QTAILQ_FOREACH(block, &ram_list.blocks, next) {for (addr =0 ; addr < block->length; addr +=TARGET_PAGE_SIZE ) {
include/exec/memory.h +3 -4
@@ -757,13 +757,12 @@ memory_region_section_addr(MemoryRegionSection *section, }/** -* memory_global_sync_dirty_bitmap: synchronize the dirty log for all memory +* address_space_sync_dirty_bitmap: synchronize the dirty log for all memory * * Synchronizes the dirty page log for an entire address space. -* @address_space: a top-level (i.e. parentless) region that contains the -* memory being synchronized +* @as: the address space that contains the memory being synchronized */ -void memory_global_sync_dirty_bitmap (MemoryRegion *address_space); +void address_space_sync_dirty_bitmap (AddressSpace *as);/** * memory_region_transaction_begin: Start a transaction.
memory.c +1 -2
@@ -1486,9 +1486,8 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,return ret; } -void memory_global_sync_dirty_bitmap (MemoryRegion *address_space) +void address_space_sync_dirty_bitmap (AddressSpace *as) { -AddressSpace *as =memory_region_to_address_space (address_space);FlatRange *fr; FOR_EACH_FLAT_RANGE(fr, as->current_map) {
Signature · 1 line
1.7.1
Quoted 1 line
From
4f30f3aaad45954884d49aec8989b93899e65afdMon Sep 17 00:00:00 2001
From: Avi Kivity <[email protected]>
Date: Tue, 30 Oct 2012 13:47:44 +0200
Subject: [PATCH 07/40] memory: fix address space initialization/destruction
A couple of fields were left uninitialized. This was not observed earlier because all address spaces were statically allocated. Also free allocation for those fields.
--- memory.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
memory.c +3 -0
@@ -1573,6 +1573,8 @@ void address_space_init(AddressSpace *as, MemoryRegion *root) as->root = root; as->current_map =g_new (FlatView,1 );flatview_init (as->current_map); + as->ioeventfd_nb =0 ; + as->ioeventfds =NULL ;QTAILQ_INSERT_TAIL (&address_spaces, as, address_spaces_link); as->name =NULL ;memory_region_transaction_commit ();
@@ -1589,6 +1591,7 @@ void address_space_destroy(AddressSpace *as)address_space_destroy_dispatch (as);flatview_destroy (as->current_map);g_free (as->current_map); +g_free (as->ioeventfds); }uint64_t io_mem_read (MemoryRegion *mr,hwaddr addr,unsigned size)
Signature · 1 line
1.7.1
Quoted 1 line
From
dead812ca6dc44d97024ccda1a9d9217946aa742Mon Sep 17 00:00:00 2001
From: Avi Kivity <[email protected]>
Date: Tue, 30 Oct 2012 13:47:45 +0200
Subject: [PATCH 08/40] memory: limit sections in the radix tree to the actual address space size
The radix tree is statically sized to fit TARGET_PHYS_ADDR_SPACE_BITS. If a larger memory region is registered, it will overflow.
Fix by limiting any section in the radix tree to the supported size.
This problem was not observed earlier since artificial regions (containers and aliases) are eliminated by the memory core, leaving only device regions which have reasonable sizes. An IOMMU however cannot be eliminated by the memory core, and may have an artificial size.
--- exec.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-)
exec.c +14 -1
@@ -777,10 +777,23 @@ static void register_multipage(AddressSpaceDispatch *d, MemoryRegionSection *sec section_index); } +static MemoryRegionSection limit (MemoryRegionSection section) +{ +unsigned practical_as_bits =MIN (TARGET_PHYS_ADDR_SPACE_BITS ,62 ); +hwaddr as_limit; + + as_limit = (hwaddr )1 << practical_as_bits; + + section.size =MIN (section.offset_within_address_space + section.size, as_limit) + - section.offset_within_address_space; + +return section; +} +static void mem_add (MemoryListener *listener,MemoryRegionSection *section) {AddressSpaceDispatch *d =container_of (listener, AddressSpaceDispatch, listener); -MemoryRegionSection now = *section, remain = *section; +MemoryRegionSection now =limit (*section), remain =limit (*section);if ((now.offset_within_address_space & ~TARGET_PAGE_MASK ) || (now.size <TARGET_PAGE_SIZE )) {
Signature · 1 line
1.7.1
Quoted 1 line
From
11c523170b4dc49c5010ede5ddaaded64b0ef1faMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 16 Apr 2013 15:39:51 +0200
Subject: [PATCH 09/40] memory: create FlatView for new address spaces
A new address space has an empty FlatView. In order to create it, we must (a) call memory_region_transaction_commit after the address space is inserted into the list; (b) force memory_region_transaction_commit to do something.
This bug was latent so far because all address spaces started empty, including the PCI address space where the bus master region is initially disabled. However, the target address space of an IOMMU is usually rooted at get_system_memory(), which might not be empty at the time the IOMMU is created.
--- memory.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
memory.c +2 -1
@@ -1577,8 +1577,9 @@ void address_space_init(AddressSpace *as, MemoryRegion *root) as->ioeventfds =NULL ;QTAILQ_INSERT_TAIL (&address_spaces, as, address_spaces_link); as->name =NULL ; -memory_region_transaction_commit ();address_space_init_dispatch (as); + memory_region_update_pending |= root->enabled; +memory_region_transaction_commit (); }void address_space_destroy (AddressSpace *as)
Signature · 1 line
1.7.1
Quoted 1 line
From
714a2bab77e6e5df064071c05d079de0b059434cMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Thu, 11 Apr 2013 15:33:16 +0200
Subject: [PATCH 10/40] exec: remove obsolete comment
See how we call memory_region_section_addr two lines below to convert a physical address to a base address in the region.
--- exec.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
exec.c +0 -6
@@ -639,12 +639,6 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env, iotlb |= phys_section_rom; } }else { -/* IO handlers are currently passed a physical address. -It would be nice to pass an offset from the base address -of that region. This would avoid having to special case RAM, -and avoid full address decoding in every device. -We can't use the high bits of pd for this because -IO_MEM_ROMD uses these as a ram address. */ iotlb = section - phys_sections; iotlb +=memory_region_section_addr (section, paddr); }
Signature · 1 line
1.7.1
Quoted 1 line
From
6ac25708f0c7a7c725c1c202d771954310ebfbc1Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Thu, 11 Apr 2013 15:40:59 +0200
Subject: [PATCH 11/40] memory: add address_space_valid
Checking whether an address space is possible in the old-style IOMMU implementation, but there is no equivalent in the memory API. Implement it with a lookup of the dispatch tree.
--- dma-helpers.c | 5 +++++ exec.c | 24 ++++++++++++++++++++++++ include/exec/memory.h | 12 ++++++++++++ include/sysemu/dma.h | 3 ++- 4 files changed, 43 insertions(+), 1 deletions(-)
dma-helpers.c +5 -0
@@ -298,6 +298,11 @@ bool iommu_dma_memory_valid(DMAContext *dma, dma_addr_t addr, dma_addr_t len, plen = len; } +if (!address_space_valid (dma->as, paddr, len, + dir ==DMA_DIRECTION_FROM_DEVICE )) { +return false; + } + len -= plen; addr += plen; }
exec.c +24 -0
@@ -2093,6 +2093,30 @@ static void cpu_notify_map_clients(void) } } +bool address_space_valid (AddressSpace *as,hwaddr addr,int len,bool is_write) +{ +AddressSpaceDispatch *d = as->dispatch; +MemoryRegionSection *section; +int l; +hwaddr page; + +while (len >0 ) { + page = addr &TARGET_PAGE_MASK ; + l = (page +TARGET_PAGE_SIZE ) - addr; +if (l > len) { + l = len; + } + section =phys_page_find (d, addr >>TARGET_PAGE_BITS ); +if (section->mr == &io_mem_unassigned) { +return false; + } + + len -= l; + addr += l; + } +return true; +} +/* Map a physical memory region into a host virtual address. * May map a subset of the requested range, given by and returned in *plen. * May return NULL if resources needed to perform the mapping are exhausted.
include/exec/memory.h +12 -0
@@ -857,6 +857,18 @@ void address_space_write(AddressSpace *as, hwaddr addr,*/ void address_space_read (AddressSpace *as,hwaddr addr,uint8_t *buf,int len); +/* address_space_valid: check for validity of an address space range +* +* Check whether access to the given address space range is permitted by +* any IOMMU regions that are active for the address space. +* +* @as: #AddressSpace to be accessed +* @addr: address within that address space +* @len: pointer to length +* @is_write: indicates the transfer direction +*/ +bool address_space_valid (AddressSpace *as,hwaddr addr,int len,bool is_write); +/* address_space_map: map a physical memory region into a host virtual address * * May map a subset of the requested range, given by and returned in @plen.
include/sysemu/dma.h +2 -1
@@ -113,7 +113,8 @@ static inline bool dma_memory_valid(DMAContext *dma, DMADirection dir) {if (!dma_has_iommu (dma)) { -return true; +return address_space_valid (dma->as, addr, len, + dir ==DMA_DIRECTION_FROM_DEVICE ); }else {return iommu_dma_memory_valid (dma, addr, len, dir); }
Signature · 1 line
1.7.1
Quoted 1 line
From
709e90cb3f1e1995f93c95ba5353c96dd8a530b2Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Thu, 11 Apr 2013 13:21:06 +0200
Subject: [PATCH 12/40] memory: add address_space_translate
Using phys_page_find to translate an AddressSpace to a MemoryRegionSection is unwieldy. It requires to pass the page index rather than the address, and later memory_region_section_addr has to be called. Replace memory_region_section_addr with a function that does all of it: call phys_page_find, compute the offset within the region, and check how big the current mapping is. This way, a large flat region can be written with a single lookup rather than a page at a time.
address_space_translate will also provide a single point where IOMMU forwarding is implemented.
--- cputlb.c | 20 +++--- exec.c | 184 ++++++++++++++++++++++++++---------------------- include/exec/cputlb.h | 12 ++-- include/exec/memory.h | 31 ++++----- translate-all.c | 6 +- 5 files changed, 133 insertions(+), 120 deletions(-)
cputlb.c +11 -9
@@ -248,13 +248,18 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr,target_ulong code_address;uintptr_t addend;CPUTLBEntry *te; -hwaddr iotlb; +hwaddr iotlb, xlat, sz;assert (size >=TARGET_PAGE_SIZE );if (size !=TARGET_PAGE_SIZE ) {tlb_add_large_page (env, vaddr, size); } - section =phys_page_find (address_space_memory.dispatch, paddr >>TARGET_PAGE_BITS ); + + sz = size; + section =address_space_translate (&address_space_memory, paddr, &xlat, &sz, + false); +assert (sz >=TARGET_PAGE_SIZE ); +#if defined(DEBUG_TLB ) printf("tlb_set_page: vaddr=" TARGET_FMT_lx " paddr=0x" TARGET_FMT_plx " prot=%x idx=%d pd=0x%08lx\n",
@@ -269,15 +274,14 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr, }if (memory_region_is_ram (section->mr) ||memory_region_is_romd (section->mr)) { - addend = (uintptr_t )memory_region_get_ram_ptr (section->mr) - +memory_region_section_addr (section, paddr); + addend = (uintptr_t )memory_region_get_ram_ptr (section->mr) + xlat; }else { addend =0 ; } code_address = address; - iotlb =memory_region_section_get_iotlb (env, section, vaddr, paddr, prot, - &address); + iotlb =memory_region_section_get_iotlb (env, section, vaddr, paddr, xlat, + prot, &address); index = (vaddr >>TARGET_PAGE_BITS ) & (CPU_TLB_SIZE -1 ); env->iotlb[mmu_idx][index] = iotlb - vaddr;
@@ -300,9 +304,7 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr,/* Write access calls the I/O callback. */ te->addr_write = address |TLB_MMIO ; }else if (memory_region_is_ram (section->mr) - && !cpu_physical_memory_is_dirty ( - section->mr->ram_addr - +memory_region_section_addr (section, paddr))) { + && !cpu_physical_memory_is_dirty (section->mr->ram_addr + xlat)) { te->addr_write = address |TLB_NOTDIRTY ; }else { te->addr_write = address;
exec.c +100 -84
415 lines not on this page · raw message
include/exec/cputlb.h +5 -7
@@ -26,8 +26,6 @@ void tlb_unprotect_code_phys(CPUArchState *env, ram_addr_t ram_addr, target_ulong vaddr);void tlb_reset_dirty_range (CPUTLBEntry *tlb_entry,uintptr_t start,uintptr_t length); -MemoryRegionSection *phys_page_find (struct AddressSpaceDispatch *d, -hwaddr index);void cpu_tlb_reset_dirty_all (ram_addr_t start1,ram_addr_t length);void tlb_set_dirty (CPUArchState *env,target_ulong vaddr);extern int tlb_flush_count;
@@ -35,11 +33,11 @@ extern int tlb_flush_count;/* exec.c */ void tb_flush_jmp_cache (CPUArchState *env,target_ulong addr);hwaddr memory_region_section_get_iotlb (CPUArchState *env, -MemoryRegionSection *section, -target_ulong vaddr, -hwaddr paddr, -int prot, -target_ulong *address); +MemoryRegionSection *section, +target_ulong vaddr, +hwaddr paddr,hwaddr xlat, +int prot, +target_ulong *address);bool memory_region_is_unassigned (MemoryRegion *mr);#endif
include/exec/memory.h +14 -17
@@ -740,23 +740,6 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr, hwaddr addr, uint64_t size);/** -* memory_region_section_addr: get offset within MemoryRegionSection -* -* Returns offset within MemoryRegionSection -* -* @section: the memory region section being queried -* @addr: address in address space -*/ -static inline hwaddr -memory_region_section_addr (MemoryRegionSection *section, -hwaddr addr) -{ - addr -= section->offset_within_address_space; - addr += section->offset_within_region; -return addr; -} - -/** * address_space_sync_dirty_bitmap: synchronize the dirty log for all memory * * Synchronizes the dirty page log for an entire address space.
@@ -857,6 +840,20 @@ void address_space_write(AddressSpace *as, hwaddr addr,*/ void address_space_read (AddressSpace *as,hwaddr addr,uint8_t *buf,int len); +/* address_space_translate: translate an address range into an address space +* into a MemoryRegionSection and an address range into that section +* +* @as: #AddressSpace to be accessed +* @addr: address within that address space +* @xlat: pointer to address within the returned memory region section's +* #MemoryRegion. +* @len: pointer to length +* @is_write: indicates the transfer direction +*/ +MemoryRegionSection *address_space_translate (AddressSpace *as,hwaddr addr, +hwaddr *xlat,hwaddr *len, +bool is_write); +/* address_space_valid: check for validity of an address space range * * Check whether access to the given address space range is permitted by
translate-all.c +3 -3
@@ -1355,15 +1355,15 @@ void tb_invalidate_phys_addr(hwaddr addr) {ram_addr_t ram_addr;MemoryRegionSection *section; +hwaddr l =1 ; - section =phys_page_find (address_space_memory.dispatch, - addr >>TARGET_PAGE_BITS ); + section =address_space_translate (&address_space_memory, addr, &addr, &l, false);if (!(memory_region_is_ram (section->mr) ||memory_region_is_romd (section->mr))) {return ; } ram_addr = (memory_region_get_ram_addr (section->mr) &TARGET_PAGE_MASK ) - +memory_region_section_addr (section, addr); + + addr;tb_invalidate_phys_page_range (ram_addr, ram_addr +1 ,0 ); }#endif /* TARGET_HAS_ICE && !defined(CONFIG_USER_ONLY) */
Signature · 1 line
1.7.1
Quoted 1 line
From
56c78924db451f1a3288c9321f198b16b845333dMon Sep 17 00:00:00 2001
From: Jan Kiszka <[email protected]>
Date: Mon, 6 May 2013 16:48:02 +0200
Subject: [PATCH 13/40] memory: Introduce address_space_lookup_region
This introduces a wrapper for phys_page_find (before we complicate address_space_translate with IOMMU translation). This function will also encapsulate locking and reference counting when we introduce BQL-free dispatching.
--- exec.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
exec.c +7 -1
@@ -198,13 +198,19 @@ static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr indexreturn &phys_sections[lp.ptr]; } +static MemoryRegionSection *address_space_lookup_region (AddressSpace *as, +hwaddr addr) +{ +return phys_page_find (as->dispatch, addr >>TARGET_PAGE_BITS ); +} +MemoryRegionSection *address_space_translate (AddressSpace *as,hwaddr addr,hwaddr *xlat,hwaddr *plen,bool is_write) {MemoryRegionSection *section; - section =phys_page_find (as->dispatch, addr >>TARGET_PAGE_BITS ); + section =address_space_lookup_region (as, addr);/* Compute offset with MemoryRegionSection */ addr -= section->offset_within_address_space; *plen =MIN (section->size - addr, *plen);
Signature · 1 line
1.7.1
Quoted 1 line
From
09c14c1d787d5319ce0d4dbceb9366937031f51bMon Sep 17 00:00:00 2001
From: Avi Kivity <[email protected]>
Date: Tue, 30 Oct 2012 13:47:46 +0200
Subject: [PATCH 14/40] memory: iommu support
Add a new memory region type that translates addresses it is given, then forwards them to a target address space. This is similar to an alias, except that the mapping is more flexible than a linear translation and trucation, and also less efficient since the translation happens at runtime.
The implementation uses an AddressSpace mapping the target region to avoid hierarchical dispatch all the way to the resolved region; only iommu regions are looked up dynamically.
--- exec.c | 35 +++++++++++++++++++++++++++++------ include/exec/memory.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ memory.c | 21 +++++++++++++++++++++ 3 files changed, 94 insertions(+), 6 deletions(-)
exec.c +29 -6
@@ -208,15 +208,38 @@ MemoryRegionSection *address_space_translate(AddressSpace *as, hwaddr addr, hwaddr *xlat, hwaddr *plen, bool is_write) { +IOMMUTLBEntry iotlb;MemoryRegionSection *section; +hwaddr len = *plen; - section =address_space_lookup_region (as, addr); -/* Compute offset with MemoryRegionSection */ - addr -= section->offset_within_address_space; - *plen =MIN (section->size - addr, *plen); +for (;;) { + section =address_space_lookup_region (as, addr); + +/* Compute offset with MemoryRegionSection */ + addr -= section->offset_within_address_space; + len =MIN (section->size - addr, len); + +/* Compute offset with MemoryRegion */ + addr += section->offset_within_region; + +if (!section->mr->iommu_ops) { +break ; + } + + iotlb = section->mr->iommu_ops->translate (section->mr, addr); + addr = ((iotlb.translated_addr & ~iotlb.addr_mask) + | (addr & iotlb.addr_mask)); + len =MIN (len, (addr | iotlb.addr_mask) - addr +1 ); +if (!iotlb.perm[is_write]) { + section = &phys_sections[phys_section_unassigned]; +break ; + } + + as = section->mr->iommu_target_as; + } -/* Compute offset with MemoryRegion */ - *xlat = addr + section->offset_within_region; + *plen = len; + *xlat = addr;return section; }
include/exec/memory.h +44 -0
74 lines not on this page · raw message
memory.c +21 -0
@@ -787,6 +787,7 @@ void memory_region_init(MemoryRegion *mr, uint64_t size) { mr->ops =NULL ; + mr->iommu_ops =NULL ; mr->parent =NULL ; mr->size =int128_make64 (size);if (size ==UINT64_MAX ) {
@@ -978,6 +979,21 @@ void memory_region_init_rom_device(MemoryRegion *mr, mr->ram_addr =qemu_ram_alloc (size, mr); } +void memory_region_init_iommu (MemoryRegion *mr, +MemoryRegionIOMMUOps *ops, +AddressSpace *target_as, +const char *name, +uint64_t size) +{ +memory_region_init (mr, name, size); + mr->ops =NULL ; + mr->iommu_ops = ops, + mr->opaque = mr; + mr->terminates = true;/* then re-forwards */ + mr->destructor = memory_region_destructor_none; + mr->iommu_target_as = target_as; +} +static uint64_t invalid_read (void *opaque,hwaddr addr,unsigned size) {
@@ -1052,6 +1068,11 @@ bool memory_region_is_rom(MemoryRegion *mr)return mr->ram && mr->readonly; } +bool memory_region_is_iommu (MemoryRegion *mr) +{ +return mr->iommu_ops; +} +void memory_region_set_log (MemoryRegion *mr,bool log,unsigned client) {uint8_t mask =1 << client;
Signature · 1 line
1.7.1
Quoted 1 line
From
10f19efd55a416806850b6074f26ed4712069f65Mon Sep 17 00:00:00 2001
From: Avi Kivity <[email protected]>
Date: Tue, 30 Oct 2012 13:47:49 +0200
Subject: [PATCH 15/40] vfio: abort if an emulated iommu is used
vfio doesn't support guest iommus yet, indicate it to the user by gently depositing a core on their disk.
--- hw/misc/vfio.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
hw/misc/vfio.c +2 -0
@@ -1939,6 +1939,8 @@ static void vfio_listener_region_add(MemoryListener *listener,void *vaddr;int ret; +assert (!memory_region_is_iommu (section->mr)); +if (vfio_listener_skipped_section (section)) { DPRINTF("SKIPPING region_add %"HWADDR_PRIx" - %"PRIx64"\n", section->offset_within_address_space,
Signature · 1 line
1.7.1
Quoted 1 line
From
78c5a629090ef01292e32d74cd2b711c0c6af6baMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Wed, 10 Apr 2013 17:30:48 +0200
Subject: [PATCH 16/40] spapr: convert TCE API to use an opaque type
The TCE table is currently returned as a DMAContext, and non-type-safe APIs are called later passing back the DMAContext. Since we want to move away from DMAContext, use an opaque type instead, and add an accessor to retrieve the DMAContext from it.
--- hw/ppc/spapr_iommu.c | 54 +++++++++++++++++------------------------- hw/ppc/spapr_pci.c | 8 +++--- hw/ppc/spapr_vio.c | 13 +++++---- include/hw/pci-host/spapr.h | 2 +- include/hw/ppc/spapr.h | 12 +++++---- include/hw/ppc/spapr_vio.h | 1 + 6 files changed, 42 insertions(+), 48 deletions(-)
hw/ppc/spapr_iommu.c +22 -32
97 lines not on this page · raw message
hw/ppc/spapr_pci.c +4 -4
@@ -511,7 +511,7 @@ static DMAContext *spapr_pci_dma_context_fn(PCIBus *bus, void *opaque, {sPAPRPHBState *phb = opaque; -return phb->dma; +return spapr_tce_get_dma (phb->tcet); }static int spapr_phb_init (SysBusDevice *s)
@@ -646,8 +646,8 @@ static int spapr_phb_init(SysBusDevice *s) sphb->dma_window_start =0 ; sphb->dma_window_size =0x40000000 ; - sphb->dma =spapr_tce_new_dma_context (sphb->dma_liobn, sphb->dma_window_size); -if (!sphb->dma) { + sphb->tcet =spapr_tce_new_table (sphb->dma_liobn, sphb->dma_window_size); +if (!sphb->tcet) {fprintf (stderr,"Unable to create TCE table for %s\n" , sphb->dtbusname);return -1 ; }
@@ -676,7 +676,7 @@ static void spapr_phb_reset(DeviceState *qdev)sPAPRPHBState *sphb =SPAPR_PCI_HOST_BRIDGE (s);/* Reset the IOMMU state */ -spapr_tce_reset (sphb->dma); +spapr_tce_reset (sphb->tcet); }static Property spapr_phb_properties[] = {
hw/ppc/spapr_vio.c +7 -6
@@ -145,7 +145,7 @@ static int vio_make_devnode(VIOsPAPRDevice *dev, } } - ret =spapr_tcet_dma_dt (fdt, node_off,"ibm,my-dma-window" , dev->dma); + ret =spapr_tcet_dma_dt (fdt, node_off,"ibm,my-dma-window" , dev->tcet);if (ret <0 ) {return ret; }
@@ -319,8 +319,8 @@ int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq)static void spapr_vio_quiesce_one (VIOsPAPRDevice *dev) { -if (dev->dma) { -spapr_tce_reset (dev->dma); +if (dev->tcet) { +spapr_tce_reset (dev->tcet); }free_crq (dev); }
@@ -345,12 +345,12 @@ static void rtas_set_tce_bypass(sPAPREnvironment *spapr, uint32_t token,return ; } -if (!dev->dma) { +if (!dev->tcet) {rtas_st (rets,0 ,-3 );return ; } -spapr_tce_set_bypass (dev->dma, !!enable); +spapr_tce_set_bypass (dev->tcet, !!enable);rtas_st (rets,0 ,0 ); }
@@ -457,7 +457,8 @@ static int spapr_vio_busdev_init(DeviceState *qdev)if (pc->rtce_window_size) {uint32_t liobn =SPAPR_VIO_BASE_LIOBN | dev->reg; - dev->dma =spapr_tce_new_dma_context (liobn, pc->rtce_window_size); + dev->tcet =spapr_tce_new_table (liobn, pc->rtce_window_size); + dev->dma =spapr_tce_get_dma (dev->tcet); }return pc->init (dev);
include/hw/pci-host/spapr.h +1 -1
@@ -49,7 +49,7 @@ typedef struct sPAPRPHBState {uint32_t dma_liobn;uint64_t dma_window_start;uint64_t dma_window_size; -DMAContext *dma; +sPAPRTCETable *tcet;struct {uint32_t irq;
include/hw/ppc/spapr.h +7 -5
@@ -342,17 +342,19 @@ typedef struct sPAPRTCE {#define RTAS_ERROR_LOG_MAX 2048 +typedef struct sPAPRTCETable sPAPRTCETable ;void spapr_iommu_init (void );void spapr_events_init (sPAPREnvironment *spapr);void spapr_events_fdt_skel (void *fdt,uint32_t epow_irq); -DMAContext *spapr_tce_new_dma_context (uint32_t liobn,size_t window_size); -void spapr_tce_free (DMAContext *dma); -void spapr_tce_reset (DMAContext *dma); -void spapr_tce_set_bypass (DMAContext *dma,bool bypass); +sPAPRTCETable *spapr_tce_new_table (uint32_t liobn,size_t window_size); +DMAContext *spapr_tce_get_dma (sPAPRTCETable *tcet); +void spapr_tce_free (sPAPRTCETable *tcet); +void spapr_tce_reset (sPAPRTCETable *tcet); +void spapr_tce_set_bypass (sPAPRTCETable *tcet,bool bypass);int spapr_dma_dt (void *fdt,int node_off,const char *propname,uint32_t liobn,uint64_t window,uint32_t size);int spapr_tcet_dma_dt (void *fdt,int node_off,const char *propname, -DMAContext *dma); +sPAPRTCETable *tcet);#endif /* !defined (__HW_SPAPR_H__) */
include/hw/ppc/spapr_vio.h +1 -0
@@ -63,6 +63,7 @@ struct VIOsPAPRDevice {uint32_t irq;target_ulong signal_state;VIOsPAPR_CRQ crq; +sPAPRTCETable *tcet;DMAContext *dma; };
Signature · 1 line
1.7.1
Quoted 1 line
From
ce608ec7588a33519c626b95f713579fe7e44a29Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 16 Apr 2013 15:05:06 +0200
Subject: [PATCH 17/40] spapr: make IOMMU translation go through IOMMUTLBEntry
The next step is to introduce the translation code that will be used for IOMMU MemoryRegions, but still do the actual translation in a DMAContext.
--- hw/ppc/spapr_iommu.c | 57 ++++++++++++++++++++++++++++---------------------- 1 files changed, 32 insertions(+), 25 deletions(-)
hw/ppc/spapr_iommu.c +32 -25
84 lines not on this page · raw message
Signature · 1 line
1.7.1
Quoted 1 line
From
7e23ad2c1a26221ba927e92f97ef2e56308ec0d6Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Thu, 11 Apr 2013 12:35:33 +0200
Subject: [PATCH 18/40] spapr: use memory core for iommu support
Now we can stop using a "translating" DMAContext, but we do not yet modify the sPAPRTCETable users to get an AddressSpace; they keep using the table via a DMAContext.
--- hw/ppc/spapr_iommu.c | 42 ++++++++++++++++++++---------------------- include/hw/ppc/spapr.h | 1 + 2 files changed, 21 insertions(+), 22 deletions(-)
hw/ppc/spapr_iommu.c +20 -22
85 lines not on this page · raw message
include/hw/ppc/spapr.h +1 -0
@@ -349,6 +349,7 @@ void spapr_events_init(sPAPREnvironment *spapr);void spapr_events_fdt_skel (void *fdt,uint32_t epow_irq);sPAPRTCETable *spapr_tce_new_table (uint32_t liobn,size_t window_size);DMAContext *spapr_tce_get_dma (sPAPRTCETable *tcet); +MemoryRegion *spapr_tce_get_iommu (sPAPRTCETable *tcet);void spapr_tce_free (sPAPRTCETable *tcet);void spapr_tce_reset (sPAPRTCETable *tcet);void spapr_tce_set_bypass (sPAPRTCETable *tcet,bool bypass);
Signature · 1 line
1.7.1
Quoted 1 line
From
c537f2332d33fffff67af2d7f48af9727adac659Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Wed, 10 Apr 2013 17:49:04 +0200
Subject: [PATCH 19/40] dma: eliminate old-style IOMMU support
The translate function in the DMAContext is now always NULL. Remove every reference to it.
--- dma-helpers.c | 173 ++------------------------------------------------ exec.c | 3 +- hw/pci/pci.c | 3 +- hw/ppc/spapr_iommu.c | 2 +- include/sysemu/dma.h | 118 +++++++++------------------------- 5 files changed, 42 insertions(+), 257 deletions(-)
dma-helpers.c +7 -166
194 lines not on this page · raw message
exec.c +1 -2
@@ -1870,8 +1870,7 @@ static void memory_map_init(void)memory_listener_register (&io_memory_listener, &address_space_io);memory_listener_register (&tcg_memory_listener, &address_space_memory); -dma_context_init (&dma_context_memory, &address_space_memory, -NULL ,NULL ,NULL ); +dma_context_init (&dma_context_memory, &address_space_memory); }MemoryRegion *get_system_memory (void )
hw/pci/pci.c +2 -1
@@ -814,8 +814,9 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,memory_region_set_enabled (&pci_dev->bus_master_enable_region, false);address_space_init (&pci_dev->bus_master_as, &pci_dev->bus_master_enable_region); pci_dev->dma =g_new (DMAContext,1 ); -dma_context_init (pci_dev->dma, &pci_dev->bus_master_as,NULL ,NULL ,NULL ); +dma_context_init (pci_dev->dma, &pci_dev->bus_master_as); } + pci_dev->devfn = devfn;pstrcpy (pci_dev->name,sizeof (pci_dev->name), name); pci_dev->irq_state =0 ;
hw/ppc/spapr_iommu.c +1 -1
@@ -155,7 +155,7 @@ sPAPRTCETable *spapr_tce_new_table(uint32_t liobn, size_t window_size) &address_space_memory, "iommu-spapr", INT64_MAX);address_space_init (&tcet->as, &tcet->iommu); -dma_context_init (&tcet->dma, &tcet->as,NULL ,NULL ,NULL ); +dma_context_init (&tcet->dma, &tcet->as);QLIST_INSERT_HEAD (&spapr_tce_tables, tcet, list);
include/sysemu/dma.h +31 -87
180 lines not on this page · raw message
Signature · 1 line
1.7.1
Quoted 1 line
From
792356993c94cf713d0d6335a9056e9c9937ba2bMon Sep 17 00:00:00 2001
From: Avi Kivity <[email protected]>
Date: Tue, 30 Oct 2012 13:47:48 +0200
Subject: [PATCH 20/40] pci: use memory core for iommu support
Use the new iommu support in the memory core for iommu support. The only user, spapr, is also converted, but it still provides a DMAContext interface until the non-PCI bits switch to AddressSpace.
--- hw/pci/pci.c | 53 ++++++++++++++++++++++++++-------------------- hw/ppc/spapr_pci.c | 12 +++++++--- include/hw/pci/pci.h | 7 ++++- include/hw/pci/pci_bus.h | 5 ++- 4 files changed, 46 insertions(+), 31 deletions(-)
hw/pci/pci.c +30 -23
85 lines not on this page · raw message
hw/ppc/spapr_pci.c +3 -4
@@ -506,12 +506,11 @@ static const MemoryRegionOps spapr_msi_ops = {/* * PHB PCI device */ -static DMAContext *spapr_pci_dma_context_fn (PCIBus *bus,void *opaque, -int devfn) +static MemoryRegion *spapr_pci_dma_iommu (PCIBus *bus,void *opaque,int devfn) {sPAPRPHBState *phb = opaque; -return spapr_tce_get_dma (phb->tcet); +return spapr_tce_get_iommu (phb->tcet); }static int spapr_phb_init (SysBusDevice *s)
@@ -651,7 +655,7 @@ static int spapr_phb_init(SysBusDevice *s)fprintf (stderr,"Unable to create TCE table for %s\n" , sphb->dtbusname);return -1 ; } -pci_setup_iommu (bus, spapr_pci_dma_context_fn, sphb); +pci_setup_iommu (bus, spapr_pci_dma_iommu,NULL , sphb);QLIST_INSERT_HEAD (&spapr->phbs, sphb, list);
include/hw/pci/pci.h +5 -2
@@ -242,6 +242,7 @@ struct PCIDevice {PCIIORegion io_regions[PCI_NUM_REGIONS ];AddressSpace bus_master_as;MemoryRegion bus_master_enable_region; +MemoryRegion *iommu;DMAContext *dma;/* do not access the following fields */
@@ -401,9 +402,11 @@ int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,void pci_device_deassert_intx (PCIDevice *dev); -typedef DMAContext *(*PCIDMAContextFunc )(PCIBus *,void *,int ); +typedef MemoryRegion *(*PCIIOMMUFunc )(PCIBus *,void *,int ); +typedef void (*PCIIOMMUDestructorFunc )(MemoryRegion *mr); -void pci_setup_iommu (PCIBus *bus,PCIDMAContextFunc fn,void *opaque); +void pci_setup_iommu (PCIBus *bus,PCIIOMMUFunc fn,PCIIOMMUDestructorFunc dtor, +void *opaque);static inline void pci_set_byte (uint8_t *config,uint8_t val)
include/hw/pci/pci_bus.h +3 -2
@@ -10,8 +10,9 @@struct PCIBus {BusState qbus; -PCIDMAContextFunc dma_context_fn; -void *dma_context_opaque; +PCIIOMMUFunc iommu_fn; +PCIIOMMUDestructorFunc iommu_dtor_fn; +void *iommu_opaque;uint8_t devfn_min;pci_set_irq_fn set_irq;pci_map_irq_fn map_irq;
Signature · 1 line
1.7.1
Quoted 1 line
From
bcc2d6705279feb9b3acb3ecd74d288f99b7a280Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Thu, 11 Apr 2013 12:38:50 +0200
Subject: [PATCH 21/40] spapr_vio: take care of creating our own AddressSpace/DMAContext
Fetch the root region from the sPAPRTCETable, and use it to build an AddressSpace and DMAContext.
Now, everywhere we have a DMAContext we also have access to the corresponding AddressSpace (either because we create it just before the DMAContext, or because dma_context_memory's AddressSpace is trivially address_space_memory).
--- hw/ppc/spapr_iommu.c | 11 ----------- hw/ppc/spapr_vio.c | 3 ++- include/hw/ppc/spapr.h | 1 - include/hw/ppc/spapr_vio.h | 36 +++++++++++++++++++++++------------- 4 files changed, 25 insertions(+), 26 deletions(-)
hw/ppc/spapr_iommu.c +0 -11
@@ -37,10 +37,6 @@ enum sPAPRTCEAccess { };struct sPAPRTCETable { -/* temporary until everyone has its own AddressSpace */ -DMAContext dma; -AddressSpace as; -uint32_t liobn;uint32_t window_size;sPAPRTCE *table;
@@ -154,8 +150,6 @@ sPAPRTCETable *spapr_tce_new_table(uint32_t liobn, size_t window_size)memory_region_init_iommu (&tcet->iommu, &spapr_iommu_ops, &address_space_memory,"iommu-spapr" ,INT64_MAX ); -address_space_init (&tcet->as, &tcet->iommu); -dma_context_init (&tcet->dma, &tcet->as);QLIST_INSERT_HEAD (&spapr_tce_tables, tcet, list);
@@ -175,11 +169,6 @@ void spapr_tce_free(sPAPRTCETable *tcet)g_free (tcet); } -DMAContext *spapr_tce_get_dma (sPAPRTCETable *tcet) -{ -return &tcet->dma; -} -MemoryRegion *spapr_tce_get_iommu (sPAPRTCETable *tcet) {return &tcet->iommu;
hw/ppc/spapr_vio.c +2 -1
@@ -458,7 +458,8 @@ static int spapr_vio_busdev_init(DeviceState *qdev)if (pc->rtce_window_size) {uint32_t liobn =SPAPR_VIO_BASE_LIOBN | dev->reg; dev->tcet =spapr_tce_new_table (liobn, pc->rtce_window_size); - dev->dma =spapr_tce_get_dma (dev->tcet); +address_space_init (&dev->as,spapr_tce_get_iommu (dev->tcet)); +dma_context_init (&dev->dma, &dev->as); }return pc->init (dev);
include/hw/ppc/spapr.h +0 -1
@@ -348,7 +348,6 @@ void spapr_iommu_init(void);void spapr_events_init (sPAPREnvironment *spapr);void spapr_events_fdt_skel (void *fdt,uint32_t epow_irq);sPAPRTCETable *spapr_tce_new_table (uint32_t liobn,size_t window_size); -DMAContext *spapr_tce_get_dma (sPAPRTCETable *tcet);MemoryRegion *spapr_tce_get_iommu (sPAPRTCETable *tcet);void spapr_tce_free (sPAPRTCETable *tcet);void spapr_tce_reset (sPAPRTCETable *tcet);
include/hw/ppc/spapr_vio.h +23 -13
@@ -63,8 +63,9 @@ struct VIOsPAPRDevice {uint32_t irq;target_ulong signal_state;VIOsPAPR_CRQ crq; +AddressSpace as; +DMAContext dma;sPAPRTCETable *tcet; -DMAContext *dma; };#define DEFINE_SPAPR_PROPERTIES (type, field) \
@@ -92,35 +93,44 @@ static inline qemu_irq spapr_vio_qirq(VIOsPAPRDevice *dev)static inline bool spapr_vio_dma_valid (VIOsPAPRDevice *dev,uint64_t taddr,uint32_t size,DMADirection dir) { -return dma_memory_valid (dev->dma, taddr, size, dir); +return dma_memory_valid (&dev->dma, taddr, size, dir); }static inline int spapr_vio_dma_read (VIOsPAPRDevice *dev,uint64_t taddr,void *buf,uint32_t size) { -return (dma_memory_read (dev->dma, taddr, buf, size) !=0 ) ? -H_DEST_PARM :H_SUCCESS ; +if (!dma_memory_valid (&dev->dma, taddr, size,DMA_DIRECTION_TO_DEVICE )) { +return H_DEST_PARM ; + } +dma_memory_read (&dev->dma, taddr, buf, size); +return H_SUCCESS ; }static inline int spapr_vio_dma_write (VIOsPAPRDevice *dev,uint64_t taddr,const void *buf,uint32_t size) { -return (dma_memory_write (dev->dma, taddr, buf, size) !=0 ) ? -H_DEST_PARM :H_SUCCESS ; +if (!dma_memory_valid (&dev->dma, taddr, size,DMA_DIRECTION_FROM_DEVICE )) { +return H_DEST_PARM ; + } +dma_memory_write (&dev->dma, taddr, buf, size); +return H_SUCCESS ; }static inline int spapr_vio_dma_set (VIOsPAPRDevice *dev,uint64_t taddr,uint8_t c,uint32_t size) { -return (dma_memory_set (dev->dma, taddr, c, size) !=0 ) ? -H_DEST_PARM :H_SUCCESS ; +if (!dma_memory_valid (&dev->dma, taddr, size,DMA_DIRECTION_FROM_DEVICE )) { +return H_DEST_PARM ; + } +dma_memory_set (&dev->dma, taddr, c, size); +return H_SUCCESS ; } -#define vio_stb (_dev, _addr, _val) (stb_dma((_dev)->dma, (_addr), (_val))) -#define vio_sth (_dev, _addr, _val) (stw_be_dma((_dev)->dma, (_addr), (_val))) -#define vio_stl (_dev, _addr, _val) (stl_be_dma((_dev)->dma, (_addr), (_val))) -#define vio_stq (_dev, _addr, _val) (stq_be_dma((_dev)->dma, (_addr), (_val))) -#define vio_ldq (_dev, _addr) (ldq_be_dma((_dev)->dma, (_addr))) +#define vio_stb (_dev, _addr, _val) (stb_dma(&(_dev)->dma, (_addr), (_val))) +#define vio_sth (_dev, _addr, _val) (stw_be_dma(&(_dev)->dma, (_addr), (_val))) +#define vio_stl (_dev, _addr, _val) (stl_be_dma(&(_dev)->dma, (_addr), (_val))) +#define vio_stq (_dev, _addr, _val) (stq_be_dma(&(_dev)->dma, (_addr), (_val))) +#define vio_ldq (_dev, _addr) (ldq_be_dma(&(_dev)->dma, (_addr)))int spapr_vio_send_crq (VIOsPAPRDevice *dev,uint8_t *crq);
Signature · 1 line
1.7.1
Quoted 1 line
From
b87464e18f334cb100999f47ce0f98657bf8ddfbMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Wed, 10 Apr 2013 18:15:49 +0200
Subject: [PATCH 22/40] dma: eliminate DMAContext
The DMAContext is a simple pointer to an AddressSpace that is now always already available. Make everyone hold the address space directly, and clean up the DMA API to use the AddressSpace directly.
--- dma-helpers.c | 24 ++++---------- exec.c | 3 -- hw/dma/pl330.c | 8 ++-- hw/ide/ahci.c | 18 +++++----- hw/ide/ahci.h | 4 +- hw/ide/ich.c | 2 +- hw/ide/macio.c | 4 +- hw/pci/pci.c | 4 -- hw/ppc/spapr_vio.c | 1 - hw/scsi/megasas.c | 4 +- hw/scsi/virtio-scsi.c | 2 +- hw/scsi/vmw_pvscsi.c | 2 +- hw/sd/sdhci.c | 22 ++++++------ hw/usb/hcd-ehci-pci.c | 4 +- hw/usb/hcd-ehci-sysbus.c | 2 +- hw/usb/hcd-ehci.c | 12 +++--- hw/usb/hcd-ehci.h | 2 +- hw/usb/hcd-ohci.c | 30 +++++++++--------- hw/usb/libhw.c | 4 +- include/hw/pci/pci.h | 17 +++++----- include/hw/ppc/spapr_vio.h | 25 +++++++------- include/sysemu/dma.h | 75 +++++++++++++++++++------------------------- 22 files changed, 119 insertions(+), 150 deletions(-)
dma-helpers.c +7 -17
@@ -14,11 +14,9 @@/* #define DEBUG_IOMMU */ -int dma_memory_set (DMAContext *dma,dma_addr_t addr,uint8_t c,dma_addr_t len) +int dma_memory_set (AddressSpace *as,dma_addr_t addr,uint8_t c,dma_addr_t len) { -AddressSpace *as = dma->as; - -dma_barrier (dma,DMA_DIRECTION_FROM_DEVICE ); +dma_barrier (as,DMA_DIRECTION_FROM_DEVICE );#define FILLBUF_SIZE 512uint8_t fillbuf[FILLBUF_SIZE ];
@@ -35,13 +33,13 @@ int dma_memory_set(DMAContext *dma, dma_addr_t addr, uint8_t c, dma_addr_t len)return 0 ; } -void qemu_sglist_init (QEMUSGList *qsg,int alloc_hint,DMAContext *dma) +void qemu_sglist_init (QEMUSGList *qsg,int alloc_hint,AddressSpace *as) { qsg->sg =g_malloc (alloc_hint *sizeof (ScatterGatherEntry)); qsg->nsg =0 ; qsg->nalloc = alloc_hint; qsg->size =0 ; - qsg->dma = dma; + qsg->as = as; }void qemu_sglist_add (QEMUSGList *qsg,dma_addr_t base,dma_addr_t len)
@@ -101,7 +99,7 @@ static void dma_bdrv_unmap(DMAAIOCB *dbs)int i;for (i =0 ; i < dbs->iov.niov; ++i) { -dma_memory_unmap (dbs->sg->dma, dbs->iov.iov[i].iov_base, +dma_memory_unmap (dbs->sg->as, dbs->iov.iov[i].iov_base, dbs->iov.iov[i].iov_len, dbs->dir, dbs->iov.iov[i].iov_len); }
@@ -149,7 +147,7 @@ static void dma_bdrv_cb(void *opaque, int ret)while (dbs->sg_cur_index < dbs->sg->nsg) { cur_addr = dbs->sg->sg[dbs->sg_cur_index].base + dbs->sg_cur_byte; cur_len = dbs->sg->sg[dbs->sg_cur_index].len - dbs->sg_cur_byte; - mem =dma_memory_map (dbs->sg->dma, cur_addr, &cur_len, dbs->dir); + mem =dma_memory_map (dbs->sg->as, cur_addr, &cur_len, dbs->dir);if (!mem)break ;qemu_iovec_add (&dbs->iov, mem, cur_len);
@@ -246,7 +244,7 @@ static uint64_t dma_buf_rw(uint8_t *ptr, int32_t len, QEMUSGList *sg,while (len >0 ) {ScatterGatherEntry entry = sg->sg[sg_cur_index++];int32_t xfer =MIN (len, entry.len); -dma_memory_rw (sg->dma, entry.base, ptr, xfer, dir); +dma_memory_rw (sg->as, entry.base, ptr, xfer, dir); ptr += xfer; len -= xfer; resid -= xfer;
@@ -270,11 +268,3 @@ void dma_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie, {bdrv_acct_start (bs, cookie, sg->size, type); } - -void dma_context_init (DMAContext *dma,AddressSpace *as) -{ -#ifdef DEBUG_IOMMU -fprintf (stderr,"dma_context_init(%p -> %p)\n" , dma, as); -#endif - dma->as = as; -}
exec.c +0 -3
@@ -64,7 +64,6 @@ static MemoryRegion *system_io;AddressSpace address_space_io;AddressSpace address_space_memory; -DMAContext dma_context_memory;MemoryRegion io_mem_ram, io_mem_rom, io_mem_unassigned, io_mem_notdirty;static MemoryRegion io_mem_subpage_ram;
@@ -1869,8 +1868,6 @@ static void memory_map_init(void)memory_listener_register (&core_memory_listener, &address_space_memory);memory_listener_register (&io_memory_listener, &address_space_io);memory_listener_register (&tcg_memory_listener, &address_space_memory); - -dma_context_init (&dma_context_memory, &address_space_memory); }MemoryRegion *get_system_memory (void )
hw/dma/pl330.c +4 -4
@@ -1074,7 +1074,7 @@ static inline const PL330InsnDesc *pl330_fetch_insn(PL330Chan *ch)uint8_t opcode;int i; -dma_memory_read (&dma_context_memory, ch->pc, &opcode,1 ); +dma_memory_read (&address_space_memory, ch->pc, &opcode,1 );for (i =0 ; insn_desc[i].size; i++) {if ((opcode & insn_desc[i].opmask) == insn_desc[i].opcode) {return &insn_desc[i];
@@ -1088,7 +1088,7 @@ static inline void pl330_exec_insn(PL330Chan *ch, const PL330InsnDesc *insn)uint8_t buf[PL330_INSN_MAXSIZE ];assert (insn->size <=PL330_INSN_MAXSIZE ); -dma_memory_read (&dma_context_memory, ch->pc, buf, insn->size); +dma_memory_read (&address_space_memory, ch->pc, buf, insn->size); insn->exec (ch, buf[0 ], &buf[1 ], insn->size -1 ); }
@@ -1153,7 +1153,7 @@ static int pl330_exec_cycle(PL330Chan *channel)if (q !=NULL && q->len <=pl330_fifo_num_free (&s->fifo)) {int len = q->len - (q->addr & (q->len -1 )); -dma_memory_read (&dma_context_memory, q->addr, buf, len); +dma_memory_read (&address_space_memory, q->addr, buf, len);if (PL330_ERR_DEBUG >1 ) {DB_PRINT ("PL330 read from memory @%08x (size = %08x):\n" , q->addr, len);
@@ -1185,7 +1185,7 @@ static int pl330_exec_cycle(PL330Chan *channel) fifo_res =pl330_fifo_get (&s->fifo, buf, len, q->tag); }if (fifo_res ==PL330_FIFO_OK || q->z) { -dma_memory_write (&dma_context_memory, q->addr, buf, len); +dma_memory_write (&address_space_memory, q->addr, buf, len);if (PL330_ERR_DEBUG >1 ) {DB_PRINT ("PL330 read from memory @%08x (size = %08x):\n" , q->addr, len);
hw/ide/ahci.c +9 -9
@@ -597,7 +597,7 @@ static void ahci_write_fis_d2h(AHCIDevice *ad, uint8_t *cmd_fis)if (!cmd_fis) {/* map cmd_fis */ uint64_t tbl_addr =le64_to_cpu (ad->cur_cmd->tbl_addr); - cmd_fis =dma_memory_map (ad->hba->dma, tbl_addr, &cmd_len, + cmd_fis =dma_memory_map (ad->hba->as, tbl_addr, &cmd_len,DMA_DIRECTION_TO_DEVICE ); cmd_mapped =1 ; }
@@ -630,7 +630,7 @@ static void ahci_write_fis_d2h(AHCIDevice *ad, uint8_t *cmd_fis)ahci_trigger_irq (ad->hba, ad,PORT_IRQ_D2H_REG_FIS );if (cmd_mapped) { -dma_memory_unmap (ad->hba->dma, cmd_fis, cmd_len, +dma_memory_unmap (ad->hba->as, cmd_fis, cmd_len,DMA_DIRECTION_TO_DEVICE , cmd_len); } }
@@ -657,7 +657,7 @@ static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist, int offset) }/* map PRDT */ -if (!(prdt =dma_memory_map (ad->hba->dma, prdt_addr, &prdt_len, +if (!(prdt =dma_memory_map (ad->hba->as, prdt_addr, &prdt_len,DMA_DIRECTION_TO_DEVICE ))){DPRINTF (ad->port_no,"map failed\n" );return -1 ;
@@ -691,7 +691,7 @@ static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist, int offset) goto out; } -qemu_sglist_init (sglist, (sglist_alloc_hint - off_idx), ad->hba->dma); +qemu_sglist_init (sglist, (sglist_alloc_hint - off_idx), ad->hba->as);qemu_sglist_add (sglist,le64_to_cpu (tbl[off_idx].addr + off_pos),le32_to_cpu (tbl[off_idx].flags_size) +1 - off_pos);
@@ -703,7 +703,7 @@ static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist, int offset) } out: -dma_memory_unmap (ad->hba->dma, prdt, prdt_len, +dma_memory_unmap (ad->hba->as, prdt, prdt_len,DMA_DIRECTION_TO_DEVICE , prdt_len);return r; }
@@ -836,7 +836,7 @@ static int handle_cmd(AHCIState *s, int port, int slot) tbl_addr =le64_to_cpu (cmd->tbl_addr); cmd_len =0x80 ; - cmd_fis =dma_memory_map (s->dma, tbl_addr, &cmd_len, + cmd_fis =dma_memory_map (s->as, tbl_addr, &cmd_len,DMA_DIRECTION_FROM_DEVICE );if (!cmd_fis) {
@@ -963,7 +963,7 @@ static int handle_cmd(AHCIState *s, int port, int slot) } out: -dma_memory_unmap (s->dma, cmd_fis, cmd_len,DMA_DIRECTION_FROM_DEVICE , +dma_memory_unmap (s->as, cmd_fis, cmd_len,DMA_DIRECTION_FROM_DEVICE , cmd_len);if (s->dev[port].port.ifs[0 ].status & (BUSY_STAT |DRQ_STAT )) {
@@ -1145,12 +1145,12 @@ static const IDEDMAOps ahci_dma_ops = { .reset = ahci_dma_reset, }; -void ahci_init (AHCIState *s,DeviceState *qdev,DMAContext *dma,int ports) +void ahci_init (AHCIState *s,DeviceState *qdev,AddressSpace *as,int ports) {qemu_irq *irqs;int i; - s->dma = dma; + s->as = as; s->ports = ports; s->dev =g_malloc0 (sizeof (AHCIDevice) * ports);ahci_reg_init (s);
hw/ide/ahci.h +2 -2
@@ -297,7 +297,7 @@ typedef struct AHCIState {uint32_t idp_index;/* Current IDP index */ int32_t ports;qemu_irq irq; -DMAContext *dma; +AddressSpace *as; } AHCIState; typedef struct AHCIPCIState {
@@ -338,7 +338,7 @@ typedef struct NCQFrame {uint8_t reserved10; }QEMU_PACKED NCQFrame; -void ahci_init (AHCIState *s,DeviceState *qdev,DMAContext *dma,int ports); +void ahci_init (AHCIState *s,DeviceState *qdev,AddressSpace *as,int ports);void ahci_uninit (AHCIState *s);void ahci_reset (AHCIState *s);
hw/ide/ich.c +1 -1
@@ -104,7 +104,7 @@ static int pci_ich9_ahci_init(PCIDevice *dev)uint8_t *sata_cap; d = DO_UPCAST(struct AHCIPCIState, card, dev); -ahci_init (&d->ahci, &dev->qdev,pci_dma_context (dev),6 ); +ahci_init (&d->ahci, &dev->qdev,pci_get_address_space (dev),6 );pci_config_set_prog_interface (d->card.config,AHCI_PROGMODE_MAJOR_REV_1 );
hw/ide/macio.c +2 -2
@@ -71,7 +71,7 @@ static void pmac_ide_atapi_transfer_cb(void *opaque, int ret) s->io_buffer_size = io->len;qemu_sglist_init (&s->sg, io->len /MACIO_PAGE_SIZE +1 , - &dma_context_memory); + &address_space_memory);qemu_sglist_add (&s->sg, io->addr, io->len); io->addr += io->len; io->len =0 ;
@@ -128,7 +128,7 @@ static void pmac_ide_transfer_cb(void *opaque, int ret) s->io_buffer_size = io->len;qemu_sglist_init (&s->sg, io->len /MACIO_PAGE_SIZE +1 , - &dma_context_memory); + &address_space_memory);qemu_sglist_add (&s->sg, io->addr, io->len); io->addr += io->len; io->len =0 ;
hw/pci/pci.c +0 -4
@@ -819,8 +819,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, pci_dev->iommu, 0, memory_region_size(pci_dev->iommu));memory_region_set_enabled (&pci_dev->bus_master_enable_region, false);address_space_init (&pci_dev->bus_master_as, &pci_dev->bus_master_enable_region); - pci_dev->dma =g_new (DMAContext,1 ); -dma_context_init (pci_dev->dma, &pci_dev->bus_master_as); pci_dev->devfn = devfn;pstrcpy (pci_dev->name,sizeof (pci_dev->name), name);
@@ -879,8 +877,6 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)memory_region_del_subregion (&pci_dev->bus_master_enable_region, pci_dev->iommu); pci_dev->bus->iommu_dtor_fn (pci_dev->iommu);memory_region_destroy (&pci_dev->bus_master_enable_region); -g_free (pci_dev->dma); - pci_dev->dma =NULL ; }static void pci_unregister_io_regions (PCIDevice *pci_dev)
hw/ppc/spapr_vio.c +0 -1
@@ -459,7 +459,6 @@ static int spapr_vio_busdev_init(DeviceState *qdev)uint32_t liobn =SPAPR_VIO_BASE_LIOBN | dev->reg; dev->tcet =spapr_tce_new_table (liobn, pc->rtce_window_size);address_space_init (&dev->as,spapr_tce_get_iommu (dev->tcet)); -dma_context_init (&dev->dma, &dev->as); }return pc->init (dev);
hw/scsi/megasas.c +2 -2
@@ -232,7 +232,7 @@ static int megasas_map_sgl(MegasasState *s, MegasasCmd *cmd, union mfi_sgl *sgl) MEGASAS_MAX_SGE);return iov_count; } -qemu_sglist_init (&cmd->qsg, iov_count,pci_dma_context (&s->dev)); +qemu_sglist_init (&cmd->qsg, iov_count,pci_get_address_space (&s->dev));for (i =0 ; i < iov_count; i++) {dma_addr_t iov_pa, iov_size_p;
@@ -628,7 +628,7 @@ static int megasas_map_dcmd(MegasasState *s, MegasasCmd *cmd) } iov_pa =megasas_sgl_get_addr (cmd, &cmd->frame->dcmd.sgl); iov_size =megasas_sgl_get_len (cmd, &cmd->frame->dcmd.sgl); -qemu_sglist_init (&cmd->qsg,1 ,pci_dma_context (&s->dev)); +qemu_sglist_init (&cmd->qsg,1 ,pci_get_address_space (&s->dev));qemu_sglist_add (&cmd->qsg, iov_pa, iov_size); cmd->iov_size = iov_size;return cmd->iov_size;
hw/scsi/virtio-scsi.c +1 -1
@@ -80,7 +80,7 @@ static void virtio_scsi_bad_req(void)static void qemu_sgl_init_external (QEMUSGList *qsgl,struct iovec *sg,hwaddr *addr,int num) { -qemu_sglist_init (qsgl, num, &dma_context_memory); +qemu_sglist_init (qsgl, num, &address_space_memory);while (num--) {qemu_sglist_add (qsgl, *(addr++), (sg++)->iov_len); }
hw/scsi/vmw_pvscsi.c +1 -1
@@ -617,7 +617,7 @@ pvscsi_build_sglist(PVSCSIState *s, PVSCSIRequest *r) {PCIDevice *d =PCI_DEVICE (s); -qemu_sglist_init (&r->sgl,1 ,pci_dma_context (d)); +pci_dma_sglist_init (&r->sgl, d,1 );if (r->req.flags &PVSCSI_FLAG_CMD_WITH_SG_LIST ) {pvscsi_convert_sglist (r); }else {
hw/sd/sdhci.c +11 -11
@@ -496,7 +496,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s) s->blkcnt--; } } -dma_memory_write (&dma_context_memory, s->sdmasysad, +dma_memory_write (&address_space_memory, s->sdmasysad, &s->fifo_buffer[begin], s->data_count - begin); s->sdmasysad += s->data_count - begin;if (s->data_count == block_size) {
@@ -518,7 +518,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s) s->data_count = block_size; boundary_count -= block_size - begin; } -dma_memory_read (&dma_context_memory, s->sdmasysad, +dma_memory_read (&address_space_memory, s->sdmasysad, &s->fifo_buffer[begin], s->data_count); s->sdmasysad += s->data_count - begin;if (s->data_count == block_size) {
@@ -557,10 +557,10 @@ static void sdhci_sdma_transfer_single_block(SDHCIState *s)for (n =0 ; n < datacnt; n++) { s->fifo_buffer[n] =sd_read_data (s->card); } -dma_memory_write (&dma_context_memory, s->sdmasysad, s->fifo_buffer, +dma_memory_write (&address_space_memory, s->sdmasysad, s->fifo_buffer, datacnt); }else { -dma_memory_read (&dma_context_memory, s->sdmasysad, s->fifo_buffer, +dma_memory_read (&address_space_memory, s->sdmasysad, s->fifo_buffer, datacnt);for (n =0 ; n < datacnt; n++) {sd_write_data (s->card, s->fifo_buffer[n]);
@@ -588,7 +588,7 @@ static void get_adma_description(SDHCIState *s, ADMADescr *dscr)hwaddr entry_addr = (hwaddr )s->admasysaddr;switch (SDHC_DMA_TYPE (s->hostctl)) {case SDHC_CTRL_ADMA2_32 : -dma_memory_read (&dma_context_memory, entry_addr, (uint8_t *)&adma2, +dma_memory_read (&address_space_memory, entry_addr, (uint8_t *)&adma2,sizeof (adma2)); adma2 =le64_to_cpu (adma2);/* The spec does not specify endianness of descriptor table.
@@ -600,7 +600,7 @@ static void get_adma_description(SDHCIState *s, ADMADescr *dscr) dscr->incr =8 ;break ;case SDHC_CTRL_ADMA1_32 : -dma_memory_read (&dma_context_memory, entry_addr, (uint8_t *)&adma1, +dma_memory_read (&address_space_memory, entry_addr, (uint8_t *)&adma1,sizeof (adma1)); adma1 =le32_to_cpu (adma1); dscr->addr = (hwaddr)(adma1 &0xFFFFF000 );
@@ -613,12 +613,12 @@ static void get_adma_description(SDHCIState *s, ADMADescr *dscr) }break ;case SDHC_CTRL_ADMA2_64 : -dma_memory_read (&dma_context_memory, entry_addr, +dma_memory_read (&address_space_memory, entry_addr, (uint8_t *)(&dscr->attr),1 ); -dma_memory_read (&dma_context_memory, entry_addr +2 , +dma_memory_read (&address_space_memory, entry_addr +2 , (uint8_t *)(&dscr->length),2 ); dscr->length =le16_to_cpu (dscr->length); -dma_memory_read (&dma_context_memory, entry_addr +4 , +dma_memory_read (&address_space_memory, entry_addr +4 , (uint8_t *)(&dscr->addr),8 ); dscr->attr =le64_to_cpu (dscr->attr); dscr->attr &=0xfffffff8 ;
@@ -678,7 +678,7 @@ static void sdhci_do_adma(SDHCIState *s) s->data_count = block_size; length -= block_size - begin; } -dma_memory_write (&dma_context_memory, dscr.addr, +dma_memory_write (&address_space_memory, dscr.addr, &s->fifo_buffer[begin], s->data_count - begin); dscr.addr += s->data_count - begin;
@@ -702,7 +702,7 @@ static void sdhci_do_adma(SDHCIState *s) s->data_count = block_size; length -= block_size - begin; } -dma_memory_read (&dma_context_memory, dscr.addr, +dma_memory_read (&address_space_memory, dscr.addr, &s->fifo_buffer[begin], s->data_count); dscr.addr += s->data_count - begin;if (s->data_count == block_size) {
hw/usb/hcd-ehci-pci.c +2 -2
@@ -63,7 +63,7 @@ static int usb_ehci_pci_initfn(PCIDevice *dev) s->caps[0x09 ] =0x68 ;/* EECP */ s->irq = dev->irq[3 ]; - s->dma =pci_dma_context (dev); + s->as =pci_get_address_space (dev); s->capsbase =0x00 ; s->opregbase =0x20 ;
@@ -86,7 +86,7 @@ static void usb_ehci_pci_write_config(PCIDevice *dev, uint32_t addr,return ; } busmaster =pci_get_word (dev->config +PCI_COMMAND ) &PCI_COMMAND_MASTER ; - i->ehci.dma = busmaster ?pci_dma_context (dev) :NULL ; + i->ehci.as = busmaster ?pci_get_address_space (dev) : &address_space_memory; }static Property ehci_pci_properties[] = {
hw/usb/hcd-ehci-sysbus.c +1 -1
@@ -40,7 +40,7 @@ static int usb_ehci_sysbus_initfn(SysBusDevice *dev) s->capsbase = sec->capsbase; s->opregbase = sec->opregbase; - s->dma = &dma_context_memory; + s->as = &address_space_memory;usb_ehci_initfn (s,DEVICE (dev));sysbus_init_irq (dev, &s->irq);
hw/usb/hcd-ehci.c +6 -6
@@ -446,7 +446,7 @@ static inline int get_dwords(EHCIState *ehci, uint32_t addr, {int i; -if (!ehci->dma) { +if (!ehci->as) {ehci_raise_irq (ehci,USBSTS_HSE ); ehci->usbcmd &= ~USBCMD_RUNSTOP ;trace_usb_ehci_dma_error ();
@@ -454,7 +454,7 @@ static inline int get_dwords(EHCIState *ehci, uint32_t addr, }for (i =0 ; i < num; i++, buf++, addr +=sizeof (*buf)) { -dma_memory_read (ehci->dma, addr, buf,sizeof (*buf)); +dma_memory_read (ehci->as, addr, buf,sizeof (*buf)); *buf =le32_to_cpu (*buf); }
@@ -467,7 +467,7 @@ static inline int put_dwords(EHCIState *ehci, uint32_t addr, {int i; -if (!ehci->dma) { +if (!ehci->as) {ehci_raise_irq (ehci,USBSTS_HSE ); ehci->usbcmd &= ~USBCMD_RUNSTOP ;trace_usb_ehci_dma_error ();
@@ -476,7 +476,7 @@ static inline int put_dwords(EHCIState *ehci, uint32_t addr,for (i =0 ; i < num; i++, buf++, addr +=sizeof (*buf)) {uint32_t tmp =cpu_to_le32 (*buf); -dma_memory_write (ehci->dma, addr, &tmp,sizeof (tmp)); +dma_memory_write (ehci->as, addr, &tmp,sizeof (tmp)); }return num;
@@ -1245,7 +1245,7 @@ static int ehci_init_transfer(EHCIPacket *p) cpage =get_field (p->qtd.token,QTD_TOKEN_CPAGE ); bytes =get_field (p->qtd.token,QTD_TOKEN_TBYTES ); offset = p->qtd.bufptr[0 ] & ~QTD_BUFPTR_MASK ; -qemu_sglist_init (&p->sgl,5 , p->queue->ehci->dma); +qemu_sglist_init (&p->sgl,5 , p->queue->ehci->as);while (bytes >0 ) {if (cpage >4 ) {
@@ -1484,7 +1484,7 @@ static int ehci_process_itd(EHCIState *ehci,return -1 ; } -qemu_sglist_init (&ehci->isgl,2 , ehci->dma); +qemu_sglist_init (&ehci->isgl,2 , ehci->as);if (off + len >4096 ) {/* transfer crosses page border */ uint32_t len2 = off + len -4096 ;
hw/usb/hcd-ehci.h +1 -1
@@ -261,7 +261,7 @@ struct EHCIState {USBBus bus;qemu_irq irq;MemoryRegion mem; -DMAContext *dma; +AddressSpace *as;MemoryRegion mem_caps;MemoryRegion mem_opreg;MemoryRegion mem_ports;
hw/usb/hcd-ohci.c +15 -15
@@ -62,7 +62,7 @@ typedef struct {USBBus bus;qemu_irq irq;MemoryRegion mem; -DMAContext *dma; +AddressSpace *as;int num_ports;const char *name;
@@ -508,7 +508,7 @@ static inline int get_dwords(OHCIState *ohci, addr += ohci->localmem_base;for (i =0 ; i < num; i++, buf++, addr +=sizeof (*buf)) { -dma_memory_read (ohci->dma, addr, buf,sizeof (*buf)); +dma_memory_read (ohci->as, addr, buf,sizeof (*buf)); *buf =le32_to_cpu (*buf); }
@@ -525,7 +525,7 @@ static inline int put_dwords(OHCIState *ohci,for (i =0 ; i < num; i++, buf++, addr +=sizeof (*buf)) {uint32_t tmp =cpu_to_le32 (*buf); -dma_memory_write (ohci->dma, addr, &tmp,sizeof (tmp)); +dma_memory_write (ohci->as, addr, &tmp,sizeof (tmp)); }return 1 ;
@@ -540,7 +540,7 @@ static inline int get_words(OHCIState *ohci, addr += ohci->localmem_base;for (i =0 ; i < num; i++, buf++, addr +=sizeof (*buf)) { -dma_memory_read (ohci->dma, addr, buf,sizeof (*buf)); +dma_memory_read (ohci->as, addr, buf,sizeof (*buf)); *buf =le16_to_cpu (*buf); }
@@ -557,7 +557,7 @@ static inline int put_words(OHCIState *ohci,for (i =0 ; i < num; i++, buf++, addr +=sizeof (*buf)) {uint16_t tmp =cpu_to_le16 (*buf); -dma_memory_write (ohci->dma, addr, &tmp,sizeof (tmp)); +dma_memory_write (ohci->as, addr, &tmp,sizeof (tmp)); }return 1 ;
@@ -585,7 +585,7 @@ static inline int ohci_read_iso_td(OHCIState *ohci,static inline int ohci_read_hcca (OHCIState *ohci,dma_addr_t addr,struct ohci_hcca *hcca) { -dma_memory_read (ohci->dma, addr + ohci->localmem_base, hcca,sizeof (*hcca)); +dma_memory_read (ohci->as, addr + ohci->localmem_base, hcca,sizeof (*hcca));return 1 ; }
@@ -617,7 +617,7 @@ static inline int ohci_put_iso_td(OHCIState *ohci,static inline int ohci_put_hcca (OHCIState *ohci,dma_addr_t addr,struct ohci_hcca *hcca) { -dma_memory_write (ohci->dma, +dma_memory_write (ohci->as, addr + ohci->localmem_base +HCCA_WRITEBACK_OFFSET , (char *)hcca +HCCA_WRITEBACK_OFFSET ,HCCA_WRITEBACK_SIZE );
@@ -634,12 +634,12 @@ static void ohci_copy_td(OHCIState *ohci, struct ohci_td *td, n =0x1000 - (ptr &0xfff );if (n > len) n = len; -dma_memory_rw (ohci->dma, ptr + ohci->localmem_base, buf, n, dir); +dma_memory_rw (ohci->as, ptr + ohci->localmem_base, buf, n, dir);if (n == len)return ; ptr = td->be & ~0xfffu ; buf += n; -dma_memory_rw (ohci->dma, ptr + ohci->localmem_base, buf, len - n, dir); +dma_memory_rw (ohci->as, ptr + ohci->localmem_base, buf, len - n, dir); }/* Read/Write the contents of an ISO TD from/to main memory. */
@@ -653,12 +653,12 @@ static void ohci_copy_iso_td(OHCIState *ohci, n =0x1000 - (ptr &0xfff );if (n > len) n = len; -dma_memory_rw (ohci->dma, ptr + ohci->localmem_base, buf, n, dir); +dma_memory_rw (ohci->as, ptr + ohci->localmem_base, buf, n, dir);if (n == len)return ; ptr = end_addr & ~0xfffu ; buf += n; -dma_memory_rw (ohci->dma, ptr + ohci->localmem_base, buf, len - n, dir); +dma_memory_rw (ohci->as, ptr + ohci->localmem_base, buf, len - n, dir); }static void ohci_process_lists (OHCIState *ohci,int completion);
@@ -1788,11 +1788,11 @@ static USBBusOps ohci_bus_ops = {static int usb_ohci_init (OHCIState *ohci,DeviceState *dev,int num_ports,dma_addr_t localmem_base,char *masterbus,uint32_t firstport, -DMAContext *dma) +AddressSpace *as) {int i; - ohci->dma = dma; + ohci->as = as;if (usb_frame_time ==0 ) {#ifdef OHCI_TIME_WARP
@@ -1859,7 +1859,7 @@ static int usb_ohci_initfn_pci(struct PCIDevice *dev)if (usb_ohci_init (&ohci->state, &dev->qdev, ohci->num_ports,0 , ohci->masterbus, ohci->firstport, -pci_dma_context (dev)) !=0 ) { +pci_get_address_space (dev)) !=0 ) {return -1 ; } ohci->state.irq = ohci->pci_dev.irq[0 ];
@@ -1882,7 +1882,7 @@ static int ohci_init_pxa(SysBusDevice *dev)/* Cannot fail as we pass NULL for masterbus */ usb_ohci_init (&s->ohci, &dev->qdev, s->num_ports, s->dma_offset,NULL ,0 , - &dma_context_memory); + &address_space_memory);sysbus_init_irq (dev, &s->ohci.irq);sysbus_init_mmio (dev, &s->ohci.mem);
hw/usb/libhw.c +2 -2
@@ -37,7 +37,7 @@ int usb_packet_map(USBPacket *p, QEMUSGList *sgl)while (len) {dma_addr_t xlen = len; - mem =dma_memory_map (sgl->dma, base, &xlen, dir); + mem =dma_memory_map (sgl->as, base, &xlen, dir);if (!mem) { goto err; }
@@ -63,7 +63,7 @@ void usb_packet_unmap(USBPacket *p, QEMUSGList *sgl)int i;for (i =0 ; i < p->iov.niov; i++) { -dma_memory_unmap (sgl->dma, p->iov.iov[i].iov_base, +dma_memory_unmap (sgl->as, p->iov.iov[i].iov_base, p->iov.iov[i].iov_len, dir, p->iov.iov[i].iov_len); }
include/hw/pci/pci.h +8 -9
@@ -243,7 +243,6 @@ struct PCIDevice {AddressSpace bus_master_as;MemoryRegion bus_master_enable_region;MemoryRegion *iommu; -DMAContext *dma;/* do not access the following fields */ PCIConfigReadFunc *config_read;
@@ -642,15 +641,15 @@ static inline uint32_t pci_config_size(const PCIDevice *d) }/* DMA access functions */ -static inline DMAContext *pci_dma_context (PCIDevice *dev) +static inline AddressSpace *pci_get_address_space (PCIDevice *dev) { -return dev->dma; +return &dev->bus_master_as; }static inline int pci_dma_rw (PCIDevice *dev,dma_addr_t addr,void *buf,dma_addr_t len,DMADirection dir) { -dma_memory_rw (pci_dma_context (dev), addr, buf, len, dir); +dma_memory_rw (pci_get_address_space (dev), addr, buf, len, dir);return 0 ; }
@@ -670,12 +669,12 @@ static inline int pci_dma_write(PCIDevice *dev, dma_addr_t addr, static inline uint##_bits##_t ld##_l##_pci_dma(PCIDevice *dev, \dma_addr_t addr) \ { \ - return ld##_l##_dma(pci_dma_context(dev), addr); \ + return ld##_l##_dma(pci_get_address_space(dev), addr); \ } \ static inline void st##_s##_pci_dma(PCIDevice *dev, \ dma_addr_t addr, uint##_bits##_t val) \ { \ - st##_s##_dma(pci_dma_context(dev), addr, val); \ + st##_s##_dma(pci_get_address_space(dev), addr, val); \ }PCI_DMA_DEFINE_LDST (ub, b,8 );
@@ -693,20 +692,20 @@ static inline void *pci_dma_map(PCIDevice *dev, dma_addr_t addr, {void *buf; - buf =dma_memory_map (pci_dma_context (dev), addr, plen, dir); + buf =dma_memory_map (pci_get_address_space (dev), addr, plen, dir);return buf; }static inline void pci_dma_unmap (PCIDevice *dev,void *buffer,dma_addr_t len,DMADirection dir,dma_addr_t access_len) { -dma_memory_unmap (pci_dma_context (dev), buffer, len, dir, access_len); +dma_memory_unmap (pci_get_address_space (dev), buffer, len, dir, access_len); }static inline void pci_dma_sglist_init (QEMUSGList *qsg,PCIDevice *dev,int alloc_hint) { -qemu_sglist_init (qsg, alloc_hint,pci_dma_context (dev)); +qemu_sglist_init (qsg, alloc_hint,pci_get_address_space (dev)); }extern const VMStateDescription vmstate_pci_device;
include/hw/ppc/spapr_vio.h +12 -13
@@ -64,7 +64,6 @@ struct VIOsPAPRDevice {target_ulong signal_state;VIOsPAPR_CRQ crq;AddressSpace as; -DMAContext dma;sPAPRTCETable *tcet; };
@@ -93,44 +92,44 @@ static inline qemu_irq spapr_vio_qirq(VIOsPAPRDevice *dev)static inline bool spapr_vio_dma_valid (VIOsPAPRDevice *dev,uint64_t taddr,uint32_t size,DMADirection dir) { -return dma_memory_valid (&dev->dma, taddr, size, dir); +return dma_memory_valid (&dev->as, taddr, size, dir); }static inline int spapr_vio_dma_read (VIOsPAPRDevice *dev,uint64_t taddr,void *buf,uint32_t size) { -if (!dma_memory_valid (&dev->dma, taddr, size,DMA_DIRECTION_TO_DEVICE )) { +if (!dma_memory_valid (&dev->as, taddr, size,DMA_DIRECTION_TO_DEVICE )) {return H_DEST_PARM ; } -dma_memory_read (&dev->dma, taddr, buf, size); +dma_memory_read (&dev->as, taddr, buf, size);return H_SUCCESS ; }static inline int spapr_vio_dma_write (VIOsPAPRDevice *dev,uint64_t taddr,const void *buf,uint32_t size) { -if (!dma_memory_valid (&dev->dma, taddr, size,DMA_DIRECTION_FROM_DEVICE )) { +if (!dma_memory_valid (&dev->as, taddr, size,DMA_DIRECTION_FROM_DEVICE )) {return H_DEST_PARM ; } -dma_memory_write (&dev->dma, taddr, buf, size); +dma_memory_write (&dev->as, taddr, buf, size);return H_SUCCESS ; }static inline int spapr_vio_dma_set (VIOsPAPRDevice *dev,uint64_t taddr,uint8_t c,uint32_t size) { -if (!dma_memory_valid (&dev->dma, taddr, size,DMA_DIRECTION_FROM_DEVICE )) { +if (!dma_memory_valid (&dev->as, taddr, size,DMA_DIRECTION_FROM_DEVICE )) {return H_DEST_PARM ; } -dma_memory_set (&dev->dma, taddr, c, size); +dma_memory_set (&dev->as, taddr, c, size);return H_SUCCESS ; } -#define vio_stb (_dev, _addr, _val) (stb_dma(&(_dev)->dma, (_addr), (_val))) -#define vio_sth (_dev, _addr, _val) (stw_be_dma(&(_dev)->dma, (_addr), (_val))) -#define vio_stl (_dev, _addr, _val) (stl_be_dma(&(_dev)->dma, (_addr), (_val))) -#define vio_stq (_dev, _addr, _val) (stq_be_dma(&(_dev)->dma, (_addr), (_val))) -#define vio_ldq (_dev, _addr) (ldq_be_dma(&(_dev)->dma, (_addr))) +#define vio_stb (_dev, _addr, _val) (stb_dma(&(_dev)->as, (_addr), (_val))) +#define vio_sth (_dev, _addr, _val) (stw_be_dma(&(_dev)->as, (_addr), (_val))) +#define vio_stl (_dev, _addr, _val) (stl_be_dma(&(_dev)->as, (_addr), (_val))) +#define vio_stq (_dev, _addr, _val) (stq_be_dma(&(_dev)->as, (_addr), (_val))) +#define vio_ldq (_dev, _addr) (ldq_be_dma(&(_dev)->as, (_addr)))int spapr_vio_send_crq (VIOsPAPRDevice *dev,uint8_t *crq);
include/sysemu/dma.h +32 -43
127 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
d5f91f32b2275e9193dfea002b91a0d0dc78ea27Mon Sep 17 00:00:00 2001
From: Alexey Kardashevskiy <[email protected]>
Date: Mon, 29 Apr 2013 16:25:51 +0000
Subject: [PATCH 23/40] memory: give name to every AddressSpace
The "info mtree" command in QEMU console prints only "memory" and "I/O" address spaces while there are actually a lot more other AddressSpace structs created by PCI and VIO devices. Those devices do not normally have names and therefore not present in "info mtree" output.
The patch fixes this.
--- exec.c | 6 ++---- hw/pci/pci.c | 3 ++- hw/ppc/spapr_vio.c | 2 +- include/exec/memory.h | 5 +++-- memory.c | 8 +++----- 5 files changed, 11 insertions(+), 13 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
97d7ec17467e17da33c8f5ebb7debfb3f8b508ceMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 06:59:09 +0200
Subject: [PATCH 24/40] memory: add getter/setter for owner
Whenever memory regions are accessed outside the BQL, they need to be preserved against hot-unplug. MemoryRegions actually do not have their own reference count; they piggyback on a QOM object, their "owner". Add two functions to retrieve and specify the owner.
The setter function will affect the owner recursively on a whole tree of contained regions, but without crossing (a) aliases (b) regions that are already owned by another device. This is so that a device can create a complex tree of regions and a single call to memory_region_set_owner (perhaps even within a bus-specific function, e.g. pci_register_bar) will affect the entire tree.
--- include/exec/memory.h | 18 ++++++++++++++++++ memory.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 0 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
6779775be21f7ae52fd5def34d6cab8e840e0ff6Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 09:06:00 +0200
Subject: [PATCH 25/40] memory: add ref/unref
--- include/exec/memory.h | 34 ++++++++++++++++++++++++++++++++++ memory.c | 14 ++++++++++++++ 2 files changed, 48 insertions(+), 0 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
124a7d065a876ebd2d2dd6dddb5c9b044806a36aMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Mon, 6 May 2013 10:46:11 +0200
Subject: [PATCH 26/40] memory: add ref/unref calls
Add ref/unref calls at the following places:
- places where memory regions are stashed by a listener and used outside the BQL (including in Xen or KVM).
- memory_region_find callsites
--- exec.c | 6 +++++- hw/core/loader.c | 1 + hw/display/exynos4210_fimd.c | 6 ++++++ hw/display/framebuffer.c | 10 ++++++---- hw/i386/kvm/ioapic.c | 2 ++ hw/i386/kvmvapic.c | 1 + hw/misc/vfio.c | 2 ++ hw/virtio/dataplane/hostmem.c | 7 +++++++ hw/virtio/vhost.c | 2 ++ hw/virtio/virtio-balloon.c | 1 + hw/xen/xen_pt.c | 4 ++++ include/hw/virtio/dataplane/hostmem.h | 1 + kvm-all.c | 2 ++ memory.c | 16 ++++++++++++++++ target-arm/kvm.c | 2 ++ target-sparc/mmu_helper.c | 1 + xen-all.c | 2 ++ 17 files changed, 61 insertions(+), 5 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
6154dafb504ac657c5514d388743b02bb7c4b26aMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 06:59:52 +0200
Subject: [PATCH 27/40] pci: set owner for BARs
--- hw/pci/pci.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
c15017492a7d8c3af69338e04961e8db218d1564Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 07:26:41 +0200
Subject: [PATCH 28/40] sysbus: set owner for MMIO regions
--- hw/core/sysbus.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
18d459f8c3ce069878e94fcc2ac979c618d6124dMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 08:56:13 +0200
Subject: [PATCH 29/40] acpi: add memory_region_set_owner calls
ACPI regions are added directly to the I/O address space, without going through BARs. Thus they need the owner to be set directly.
--- hw/acpi/ich9.c | 1 + hw/acpi/piix4.c | 5 +++++ hw/isa/apm.c | 1 + 3 files changed, 7 insertions(+), 0 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
66ff6cd04763424cf883d3a262bd883bbf3213b9Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 08:57:58 +0200
Subject: [PATCH 30/40] misc: add memory_region_set_owner calls
--- hw/char/serial-pci.c | 1 + hw/misc/pc-testdev.c | 7 +++++++ 2 files changed, 8 insertions(+), 0 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
5a9cbbf27c157f5857e477281ec7daa4ae09f049Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 08:32:40 +0200
Subject: [PATCH 31/40] isa/portio: allow setting an owner
--- hw/isa/isa-bus.c | 2 ++ include/exec/ioport.h | 3 +++ ioport.c | 10 ++++++++++ 3 files changed, 15 insertions(+), 0 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
440e242741c891464ddc8354772303018ece636dMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 08:58:25 +0200
Subject: [PATCH 32/40] vga: add memory_region_set_owner calls
--- hw/display/cirrus_vga.c | 19 ++++++++++++++----- hw/display/qxl.c | 5 +++-- hw/display/vga-isa-mm.c | 2 +- hw/display/vga-isa.c | 4 ++-- hw/display/vga-pci.c | 5 +++-- hw/display/vga.c | 19 ++++++++++++++----- hw/display/vga_int.h | 9 +++++---- hw/display/vmware_vga.c | 4 ++-- 8 files changed, 44 insertions(+), 23 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
ad7acb4678bba543423637c8ac0179b4cc14679cMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 08:59:02 +0200
Subject: [PATCH 33/40] pci-assign: add memory_region_set_owner calls
--- hw/i386/kvm/pci-assign.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
2c3d6858c7095704384fd5aadbf8280c64049601Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 08:59:11 +0200
Subject: [PATCH 34/40] vfio: add memory_region_set_owner calls
--- hw/misc/vfio.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
06f4696fd1c7978d51c809959fd4ce8877f9b448Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Mon, 6 May 2013 14:28:39 +0200
Subject: [PATCH 35/40] exec: check MRU in qemu_ram_addr_from_host
This function is not used outside the iothread mutex, so it can use ram_list.mru_block.
--- exec.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
8510b1a668c1d2620fc6e3311099585e46a140ebMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Mon, 6 May 2013 14:36:15 +0200
Subject: [PATCH 36/40] memory: return MemoryRegion from qemu_ram_addr_from_host
It will be needed in the next patch.
--- exec.c | 35 +++++++++++++++++++++-------------- include/exec/cpu-common.h | 2 +- target-i386/kvm.c | 4 ++-- 3 files changed, 24 insertions(+), 17 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
4e00d11fa293223d3f25e3fca51dda536bbea84dMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Mon, 6 May 2013 14:37:15 +0200
Subject: [PATCH 37/40] memory: ref/unref memory across address_space_map/unmap
The iothread mutex might be released between map and unmap, so the mapped region might disappear.
--- exec.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
22d38d6913e8cbc3c08574c8b71aa6ec7e547ea7Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Mon, 6 May 2013 10:26:13 +0200
Subject: [PATCH 38/40] memory: access FlatView from a local variable
We will soon require accesses to as->current_map to be placed under a lock (with reference counting so as to keep the critical section small). To simplify this change, always fetch as->current_map into a local variable and access it through that variable.
--- memory.c | 31 +++++++++++++++++++++---------- 1 files changed, 21 insertions(+), 10 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
eee8881b980d7cc49675611ce5ec90564543f845Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Mon, 6 May 2013 10:29:07 +0200
Subject: [PATCH 39/40] memory: use a new FlatView pointer on every topology update
This is the first step towards converting as->current_map to RCU-style updates, where the FlatView updates run concurrently with uses of an old FlatView.
--- memory.c | 34 ++++++++++++++++++---------------- 1 files changed, 18 insertions(+), 16 deletions(-)
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Quoted 1 line
From
752269a023f2e2f7591158ca069b5af7aa822223Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Mon, 6 May 2013 11:57:21 +0200
Subject: [PATCH 40/40] memory: add reference counting to FlatView
With this change, a FlatView can be used even after a concurrent update has replaced it. Because we do not have RCU, we use a mutex to protect the small critical sections that read/write the as->current_map pointer. Accesses to the FlatView can be done outside the mutex.
If a MemoryRegion will be used after the FlatView is unref-ed (or after a MemoryListener callback is returned), a reference has to be added to that MemoryRegion. For example, memory_region_find adds a reference to the MemoryRegion that it returns.
--- memory.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 67 insertions(+), 8 deletions(-)
memory.c +67 -8
75 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Part of the diff is not shown here. View the raw message.
Quoted 2 lines · Paolo Bonzini
These patches are also at
git://github.com/bonzini/qemu.git, branch iommu.
A number of the patches in this series have checkpatch issues, mostly but not exclusively over-long lines.
exec.c
Quoted 12 lines
From
aec410066128aaca6337754c389f0e7c2d47089cMon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 7 May 2013 11:30:23 +0200
Subject: [PATCH 01/40] memory: assert that PhysPageEntry's ptr does not overflowSigned-off-by Paolo Bonzini <[email protected]>--- exec.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)exec.c +0
-0
...why is there all this junk at the bottom of your cover letter?
thanks
-- PMM
Il 07/05/2013 16:46, Peter Maydell ha scritto:
Quoted 6 lines · Paolo Bonzini
Quoted 2 lines
These patches are also at
git://github.com/bonzini/qemu.git, branch iommu.A number of the patches in this series have checkpatch issues, mostly but not exclusively over-long lines.
ERROR: space prohibited before open square bracket '[' #2157: FILE: hw/ppc/spapr_iommu.c:106:
+ .perm = { [0] = tce & SPAPR_TCE_RO, [1] = tce & SPAPR_TCE_WO },
False positive.
ERROR: do not use assignment in if condition
#3313: FILE: hw/ide/ahci.c:660:
+ if (!(prdt = dma_memory_map(ad->hba->as, prdt_addr, &prdt_len,
Pre-existing, in a large mechanical patch. Will not fix.
ERROR: spaces required around that '?' (ctx:VxV)
#4298: FILE: memory.c:1600:
+ as->name = g_strdup(name?name:"anonymous");
^ERROR: spaces required around that ':' (ctx:VxV)
#4298: FILE: memory.c:1600:
+ as->name = g_strdup(name?name:"anonymous");
^Will fix.
ERROR: need consistent spacing around '*' (ctx:WxV) #4399: FILE: memory.c:1044:
+Object *memory_region_owner(MemoryRegion *mr)
^
False positive.
ERROR: "foo * bar" should be "foo *bar"
#5224: FILE: hw/display/cirrus_vga.c:2809:
+static void cirrus_init_common(CirrusVGAState * s, int device_id,
Will fix.
Paolo
Quoted 6 lines · Paolo Bonzini
Patches 1-10 are small changes, some of them bugfixes for the IOMMU portion of the patches.
Patches 11-13 introduce three new
address_spaceAPIs and clean up the dispatch logic a bit by removingmemory_region_section_addr.
Quoted 8 lines
Patches 14-22 introduce IOMMU memory regions, convert sPAPR to the new API, and finally eliminate DMAContext in favor of AddressSpace.
Patches 24-37 set an owner on all regions owned by hot-unpluggable devices (and several others when that was easy), and add ref/unref calls that keep the regions alive even if the owner is hot-unplugged.
Patches 38-40 make
memory_region_findsafe for usage outside the BQL.
I assume you're not going to try to get these all committed in one lump, by the way? I stopped reviewing after patch 22, since the BQL related stuff seems to still be under discussion.
thanks
-- PMM
Il 07/05/2013 20:51, Peter Maydell ha scritto:
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines
Patches 1-10 are small changes, some of them bugfixes for the IOMMU portion of the patches.
Patches 11-13 introduce three new
address_spaceAPIs and clean up the dispatch logic a bit by removingmemory_region_section_addr.Patches 14-22 introduce IOMMU memory regions, convert sPAPR to the new API, and finally eliminate DMAContext in favor of AddressSpace.
Quoted 8 lines
Quoted 5 lines
Patches 24-37 set an owner on all regions owned by hot-unpluggable devices (and several others when that was easy), and add ref/unref calls that keep the regions alive even if the owner is hot-unplugged.
Patches 38-40 make
memory_region_findsafe for usage outside the BQL.I assume you're not going to try to get these all committed in one lump, by the way?
In as big a lump as possible, but not necessarily in one lump.
Quoted 3 lines
I stopped reviewing after patch 22,
since the BQL related stuff seems to still be under discussion.
Note that patch 37 is a fix for an existing bug (disk I/O to a device-owned RAM area can corrupt QEMU if you unplug the device in parallel), and it needs all the 13 previous patches unfortunately.
Only the last 3 are strictly for out-of-BQL operation.
Paolo