Commit Graph

51 Commits

Author SHA1 Message Date
Avi Kivity 86e775c654 memory: replace cpu_physical_sync_dirty_bitmap() with a memory API
The function is still used as the implementation.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-20 14:14:07 +02:00
Avi Kivity e2177955a8 memory: introduce memory_region_find()
Given an address space (represented by the top-level memory region),
returns the memory region that maps a given range.  Useful for implementing
DMA.

The implementation is a simplistic binary search.  Once we have a tree
representation this can be optimized.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-20 14:14:07 +02:00
Avi Kivity 55043ba37e memory: add memory_region_is_logging()
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-20 14:14:06 +02:00
Avi Kivity ce7923da4d memory: add memory_region_is_rom()
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-20 14:14:06 +02:00
Avi Kivity 8ea9252abe memory: add memory_region_is_ram()
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-20 14:14:06 +02:00
Anthony Liguori f76d27b67c Merge remote-tracking branch 'qemu-kvm/memory/exec-obsolete' into staging 2011-12-19 09:45:17 -06:00
Anthony Liguori 4a1cc6800a Merge remote-tracking branch 'qemu-kvm/memory/xen' into staging 2011-12-19 09:45:12 -06:00
Avi Kivity 67d95c153b memory: move obsolete exec.c functions to a private header
This will help avoid accidental usage.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-19 17:28:54 +02:00
Avi Kivity fce537d4a7 memory, xen: pass MemoryRegion to xen_ram_alloc()
Currently xen_ram_alloc() relies on ram_addr, which is going away.
Give it something else to use as a cookie.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-19 17:23:24 +02:00
Avi Kivity e87c099f1c memory: optimize empty transactions due to mutators
The mutating memory APIs can easily cause empty transactions,
where the mutators don't actually change anything, or perhaps
only modify disabled regions.  Detect these conditions and
avoid regenerating the memory topology.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-05 12:04:09 +02:00
Avi Kivity 4703359e0e memory: introduce memory_region_set_alias_offset()
Add an API to update an alias offset of an active alias.  This can be
used to simplify implementation of dynamic memory banks.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-05 12:04:05 +02:00
Avi Kivity 2282e1af40 memory: introduce memory_region_set_address()
Allow changing the address of a memory region while it is
in the memory hierarchy.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-04 19:19:39 +02:00
Avi Kivity 6bba19ba4e memory: introduce memory_region_set_enabled()
This allows users to disable a memory region without removing
it from the hierarchy, simplifying the implementation of
memory routers.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-12-04 19:00:33 +02:00
Avi Kivity 897fa7cff2 memory: add MemoryRegionOps::valid.accepts
MemoryRegionOps::valid tries to declaratively specify which transactions
are accepted by the device/bus, however it is not completely generic.  Add
a callback for special cases.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-11-24 18:32:00 +02:00
Avi Kivity 88365e47dd memory: fix 'info mtree' segfaults
'info mtree' accesses invalid memory in two cases, both due to incorrect
(and unsafe) usage of QTAILQ_FOREACH_SAFE().

Reported-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-11-13 12:00:55 +02:00
Avi Kivity 08dafab4bd memory: use 128-bit integers for sizes and intermediates
Since the memory API supports 64-bit buses, it needs a larger type to represent
intermediate results.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-10-16 13:19:17 +02:00
Jan Kiszka 03808f58e4 memory: Fix old portio word accesses
As we register old portio regions via ioport_register, we are also
responsible for providing the word access wrapper.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-10-11 15:57:09 +02:00
Avi Kivity 6bf9fd43cf Introduce PortioList
Add a type and methods for manipulating a list of disjoint I/O ports,
used in some older hardware devices.

Based on original patch by Richard Henderson.

Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-10-11 15:57:07 +02:00
Jan Kiszka 9479c57a8c memory: Print regions in ascending order
Makes reading the output more user friendly.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-10-02 16:27:14 +02:00
Jan Kiszka 066318109f memory: Do not print empty PIO root
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-10-02 16:27:14 +02:00
Jan Kiszka 4b474ba7a1 memory: Print region priority
Useful to discover eclipses.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-10-02 16:27:14 +02:00
Blue Swirl 314e298735 memory: simple memory tree printer
Add a monitor command 'info mtree' to show the memory hierarchy
much like /proc/iomem in Linux.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-10-02 16:27:13 +02:00
Avi Kivity fb1cd6f998 memory: implement memory_region_set_readonly()
The property is inheritable, but only if set to true.  This is so
that memory routers can mark sections of RAM as read-only via aliases.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-09-25 14:48:47 +03:00
Michael Walle 860329b251 memory: fix subregion collision warning
Instead of the offset property use the proper addr property to calculate
the offsets.

Additionally, be a little more verbose on the warning and print the
subregion name.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-09-18 14:55:16 +03:00
David Gibson d2963631dd Fix subtle integer overflow bug in memory API
It is quite common to have a MemoryRegion with size of INT64_MAX.
When processing alias regions in render_memory_region() it's quite
easy to find a case where it will construct a temporary AddrRange with
a non-zero start, and size still of INT64_MAX.  When means attempting
to compute the end of such a range as start + size will result in
signed integer overflow.

This integer overflow means that addrrange_intersects() can
incorrectly report regions as not intersecting when they do.  For
example consider the case of address ranges {0x10000000000,
0x7fffffffffffffff} and {0x10010000000, 0x10000000} where the second
is in fact included completely in the first.

This patch rearranges addrrange_intersects() to avoid the integer
overflow, correcting this behaviour.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-09-14 11:21:58 +03:00
Jan Kiszka 021d26d161 memory: Fix memory_region_get_ram_ptr for ROM devices
Mask out the sub-page bits that are used by ROM device for storing the
io-index and the IO_MEM_ROMD flag.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-08-30 11:20:18 +03:00
Avi Kivity b5fe14cc7e memory: fix rom_device I/O mode
When adding a rom_device in I/O mode, we incorrectly masked off the low
bits, resulting in a pure RAM map.  Fix my masking off the high bits and
IO_MEM_ROMD, yielding a pure I/O map.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-08-29 11:52:09 +03:00
Avi Kivity 75f5941cb5 memory: add opaque parameter to memory_region_init_rom_device()
The MemoryRegionOps callbacks expect it.

Signed-off-by: Avi Kivity <avi@redhat.com>
2011-08-26 00:35:15 +03:00
Avi Kivity 7bc2b9cd4d memory: fix memory_region_init_rom_device() not initializing ->ops
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-08-25 14:56:14 +03:00
Richard Henderson 563ea48903 memory: Fix old_portio vs non-zero offset
The legacy functions that we're wrapping expect that offset
to be included in the register.  Indeed, they generally
expect the absolute address and then mask off the "high" bits.

The FDC is the first converted device with a non-zero offset.

Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
2011-08-22 19:29:04 +03:00
Anthony Liguori a5e1cbc80e memory: temporarily suppress the subregion collision warning
After 312b4234, the APIC and PCI devices are colliding with each other.  This
is harmless in practice because the APIC accesses are special cased and never
make there way onto the bus.

Avi is working on a proper fix, but until that's ready, avoid printing the
warning.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-22 11:14:56 -05:00
Avi Kivity 3a130f4ef0 memory: crack wide ioport accesses into smaller ones when needed
The memory API supports cracking wide accesses into narrower ones
when needed; but this was no implemented for the pio address space,
causing lsi53c895a's IO BAR to malfunction.

Fix by correctly cracking wide accesses when needed.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-21 18:27:33 -05:00
Avi Kivity 164a4dcd8d memory: abstract cracking of write access ops into a function
The memory API automatically cracks large reads and writes into smaller
ones when needed.  Factor out this mechanism, which is now duplicated between
memory reads and memory writes, into a function.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-21 18:27:33 -05:00
Anthony Liguori 7267c0947d Use glib memory allocation and free functions
qemu_malloc/qemu_free no longer exist after this commit.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-20 23:01:08 -05:00
Avi Kivity d0a9b5bc0a memory: add API for creating ROM/device regions
ROM/device regions act as mapped RAM for reads, can I/O memory for
writes.  This allow emulation of flash devices.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-12 08:31:30 -05:00
Avi Kivity 545e92e06a memory: reclaim resources when a memory region is destroyed for good
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-12 08:31:29 -05:00
Avi Kivity 8417cebfda memory: use signed arithmetic
When trying to map an alias of a ram region, where the alias starts at
address A and we map it into address B, and A > B, we had an arithmetic
underflow.  Because we use unsigned arithmetic, the underflow converted
into a large number which failed addrrange_intersects() tests.

The concrete example which triggered this was cirrus vga mapping
the framebuffer at offsets 0xc0000-0xc7fff (relative to the start of
the framebuffer) into offsets 0xa0000 (relative to system addres space
start).

With our favorite analogy of a windowing system, this is equivalent to
dragging a subwindow off the left edge of the screen, and failing to clip
it into its parent window which is on screen.

Fix by switching to signed arithmetic.

Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-05 10:57:36 -05:00
Avi Kivity 39b796f28c memory: synchronize dirty bitmap before unmapping a range
When a range is being unmapped, ask accelerators (e.g. kvm) to synchronize the
dirty bitmap to avoid losing information forever.

Fixes grub2 screen update.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-05 10:57:36 -05:00
Avi Kivity 4ef4db8603 memory: transaction API
Allow changes to the memory hierarchy to be accumulated and
made visible all at once.  This reduces computational effort,
especially when an accelerator (e.g. kvm) is involved.

Useful when a single register update causes multiple changes
to an address space.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:43 -05:00
Avi Kivity b8af1afbfb memory: separate building the final memory map into two steps
Instead of adding and deleting regions in one pass, do a delete
pass followed by an add pass.  This fixes the following case:

from:
  0x0000-0x0fff ram  (a1)
  0x1000-0x1fff mmio (a2)
  0x2000-0x2fff ram  (a3)

to:
  0x0000-0x2fff ram  (b1)

The single pass algorithm removed a1, added b2, then removed a2 and a3,
which caused the wrong memory map to be built.  The two pass algorithm
removes a1, a2, and a3, then adds b1.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:43 -05:00
Avi Kivity 3e9d69e737 memory: add ioeventfd support
As with the rest of the memory API, the caller associates an eventfd
with an address, and the memory API takes care of registering or
unregistering when the address is made visible or invisible to the
guest.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:43 -05:00
Avi Kivity 74901c3bd0 memory: add backward compatibility for old mmio registration
This eases the transition to the new API.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:43 -05:00
Avi Kivity 627a0e90dc memory: add backward compatibility for old portio registration
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:43 -05:00
Avi Kivity 658b222401 memory: I/O address space support
Allow registering I/O ports via the same mechanism as mmio ranges.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:43 -05:00
Avi Kivity 16ef61c9e5 memory: late initialization of ram_addr
For non-RAM memory regions, we cannot tell whether this is an I/O region
or an MMIO region.  Since the qemu backing registration is different for
the two, we have to defer initialization until we know which address
space we are in.

These shenanigans will be removed once the backing registration is unified
with the memory API.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:43 -05:00
Avi Kivity 14a3c10ac8 memory: rename MemoryRegion::has_ram_addr to ::terminates
I/O regions will not have ram_addrs, so this is a better name.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:43 -05:00
Avi Kivity cc31e6e7b3 memory: abstract address space operations
Prepare for multiple address space support by abstracting away the details
of registering a memory range with qemu's flat representation into an
AddressSpace object.

Note operations which are memory specific are not abstracted, since they will
never be called on I/O address spaces anyway.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:42 -05:00
Avi Kivity 1c0ffa58af Internal interfaces for memory API
get_system_memory() provides the root of the memory hierarchy.

This interface is intended to be private between memory.c and exec.c.
If this file is included elsewhere, it should be regarded as a bug (or
TODO item).  However, it will be temporarily needed for the conversion
to hierarchical memory routing.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:42 -05:00
Avi Kivity 3d8e6bf977 memory: merge adjacent segments of a single memory region
Simple implementations of memory routers, for example the Cirrus VGA memory banks
or the 440FX PAM registers can generate adjacent memory regions which are contiguous.
Detect these and merge them; this saves kvm memory slots and shortens lookup times.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:42 -05:00
Avi Kivity 5a58334769 memory: implement dirty tracking
Currently dirty tracking is implemented by passing through
all calls to the underlying cpu_physical_memory_*() calls.

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-29 08:25:42 -05:00