diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 3b95c69ba411176db2fa6a6314cef5a07136e69d..10fc92501fb094fa8c21c856badf22acff16ba2e 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 82f8ea62640d69d634a9762ae3fddc3190f22b6b..f704c420f773639907a336f5e3b34890c82d5954 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 d2466a7a971fe950ec409142ab2b9f56b706cf6e..c8d0bf445dbf1b2e60bbf60e8d92d8969ebd3a9b 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -836,6 +836,18 @@ void memory_region_set_address(MemoryRegion *mr, hwaddr addr); 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 e04d5196b0da9b11ee6809a31639620cd6a8381b..24027c507755b81dc789ef03c0a6ab33a831b225 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) {