[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 23/66] memory: introduce memory_region_present
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 23/66] memory: introduce memory_region_present |
Date: |
Thu, 4 Jul 2013 17:13:19 +0200 |
This new API will avoid having too many memory_region_ref/unref
in paths that currently use memory_region_find.
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/acpi/piix4.c | 6 +++---
hw/isa/lpc_ich9.c | 8 ++++----
include/exec/memory.h | 12 ++++++++++++
memory.c | 9 +++++++++
4 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 3b95c69..10fc925 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -388,10 +388,10 @@ static void piix4_pm_machine_ready(Notifier *n, void
*opaque)
pci_conf = s->dev.config;
pci_conf[0x5f] = 0x10 |
- (memory_region_find(io_as, 0x378, 1).mr ? 0x80 : 0);
+ (memory_region_present(io_as, 0x378) ? 0x80 : 0);
pci_conf[0x63] = 0x60;
- pci_conf[0x67] = (memory_region_find(io_as, 0x3f8, 1).mr ? 0x08 : 0) |
- (memory_region_find(io_as, 0x2f8, 1).mr ? 0x90 : 0);
+ pci_conf[0x67] = (memory_region_present(io_as, 0x3f8) ? 0x08 : 0) |
+ (memory_region_present(io_as, 0x2f8) ? 0x90 : 0);
}
static int piix4_pm_initfn(PCIDevice *dev)
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 82f8ea6..f704c42 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -481,19 +481,19 @@ static void ich9_lpc_machine_ready(Notifier *n, void
*opaque)
uint8_t *pci_conf;
pci_conf = s->d.config;
- if (memory_region_find(io_as, 0x3f8, 1).mr) {
+ if (memory_region_present(io_as, 0x3f8)) {
/* com1 */
pci_conf[0x82] |= 0x01;
}
- if (memory_region_find(io_as, 0x2f8, 1).mr) {
+ if (memory_region_present(io_as, 0x2f8)) {
/* com2 */
pci_conf[0x82] |= 0x02;
}
- if (memory_region_find(io_as, 0x378, 1).mr) {
+ if (memory_region_present(io_as, 0x378)) {
/* lpt */
pci_conf[0x82] |= 0x04;
}
- if (memory_region_find(io_as, 0x3f0, 1).mr) {
+ if (memory_region_present(io_as, 0x3f0)) {
/* floppy */
pci_conf[0x82] |= 0x08;
}
diff --git a/include/exec/memory.h b/include/exec/memory.h
index d2466a7..c8d0bf4 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -837,6 +837,18 @@ void memory_region_set_alias_offset(MemoryRegion *mr,
hwaddr offset);
/**
+ * memory_region_present: translate an address/size relative to a
+ * MemoryRegion into a #MemoryRegionSection.
+ *
+ * Answer whether a #MemoryRegion within @parent covers the address
+ * @addr.
+ *
+ * @parent: a MemoryRegion within which @addr is a relative address
+ * @addr: the area within @parent to be searched
+ */
+bool memory_region_present(MemoryRegion *parent, hwaddr addr);
+
+/**
* memory_region_find: translate an address/size relative to a
* MemoryRegion into a #MemoryRegionSection.
*
diff --git a/memory.c b/memory.c
index e04d519..24027c5 100644
--- a/memory.c
+++ b/memory.c
@@ -1478,6 +1478,15 @@ static FlatRange *address_space_lookup(AddressSpace *as,
AddrRange addr)
sizeof(FlatRange), cmp_flatrange_addr);
}
+bool memory_region_present(MemoryRegion *parent, hwaddr addr)
+{
+ MemoryRegion *mr = memory_region_find(parent, addr, 1).mr;
+ if (!mr) {
+ return false;
+ }
+ return true;
+}
+
MemoryRegionSection memory_region_find(MemoryRegion *mr,
hwaddr addr, uint64_t size)
{
--
1.8.1.4
- [Qemu-devel] [PATCH 12/66] vmware-vga: Accept unaligned I/O accesses, (continued)
- [Qemu-devel] [PATCH 12/66] vmware-vga: Accept unaligned I/O accesses, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 13/66] xen: Mark fixed platform I/O as unaligned, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 14/66] ioport: Switch dispatching to memory core layer, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 16/66] vmport: Disentangle read handler type from portio, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 15/66] ioport: Remove unused old dispatching services, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 17/66] ioport: Move portio types to ioport.h, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 19/66] memory: destroy phys_sections one by one, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 20/66] exec: simplify destruction of the phys map, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 21/66] memory: add getter for owner, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 22/66] memory: add ref/unref, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 23/66] memory: introduce memory_region_present,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 24/66] memory: add ref/unref calls, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 25/66] exec: check MRU in qemu_ram_addr_from_host, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 26/66] exec: move qemu_ram_addr_from_host_nofail to cputlb.c, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 27/66] memory: return MemoryRegion from qemu_ram_addr_from_host, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 28/66] exec: reorganize address_space_map, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 29/66] memory: ref/unref memory across address_space_map/unmap, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 30/66] escc: rename struct to ESCCState, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 31/66] vga: pass owner to vga_init, Paolo Bonzini, 2013/07/04
- [Qemu-devel] [PATCH 32/66] vga: pass owner to vga_common_init, Paolo Bonzini, 2013/07/04