From: Jan Kiszka <jan.kis...@siemens.com> We can express the offset of old portio completely via MemoryRegionPortio::offset by splitting up regions of different offsets and adjusting those offsets appropriately.
Signed-off-by: Jan Kiszka <jan.kis...@siemens.com> --- Will write a patch to remove MemoryRegion::offset now. hw/isa-bus.c | 28 ++++++++++------------------ memory.c | 15 +++++++-------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/hw/isa-bus.c b/hw/isa-bus.c index 27c76b4..558312d 100644 --- a/hw/isa-bus.c +++ b/hw/isa-bus.c @@ -107,19 +107,14 @@ static void isa_register_portio_1(ISADevice *dev, MemoryRegion *region; unsigned i; - if (off_low == 0 && pio_init[count].size == 0) { - /* Special case simple adjustments. */ - pio = (MemoryRegionPortio *) pio_init; - } else { - /* Copy the sub-list and null-terminate it. */ - pio = g_new(MemoryRegionPortio, count + 1); - memcpy(pio, pio_init, sizeof(MemoryRegionPortio) * count); - memset(pio + count, 0, sizeof(MemoryRegionPortio)); - - /* Adjust the offsets to all be zero-based for the region. */ - for (i = 0; i < count; ++i) { - pio[i].offset -= off_low; - } + /* Copy the sub-list and null-terminate it. */ + pio = g_new(MemoryRegionPortio, count + 1); + memcpy(pio, pio_init, sizeof(MemoryRegionPortio) * count); + memset(pio + count, 0, sizeof(MemoryRegionPortio)); + + /* Adjust the offsets to be absolute. */ + for (i = 0; i < count; ++i) { + pio[i].offset += start; } ops = g_new0(MemoryRegionOps, 1); @@ -127,7 +122,6 @@ static void isa_register_portio_1(ISADevice *dev, region = g_new(MemoryRegion, 1); memory_region_init_io(region, ops, opaque, name, off_high - off_low); - memory_region_set_offset(region, start + off_low); memory_region_add_subregion(isabus->address_space_io, start + off_low, region); } @@ -154,8 +148,8 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start, assert(pio->offset >= off_last); off_last = pio->offset; - /* If we see a hole, break the region. */ - if (off_last > off_high) { + /* If we see a new offset, break the region. */ + if (off_last > off_low) { isa_register_portio_1(dev, pio_start, count, start, off_low, off_high, opaque, name); /* ... and start collecting anew. */ @@ -163,8 +157,6 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start, off_low = off_last; off_high = off_low + pio->len; count = 0; - } else if (off_last + pio->len > off_high) { - off_high = off_last + pio->len; } } diff --git a/memory.c b/memory.c index aef4702..51f0297 100644 --- a/memory.c +++ b/memory.c @@ -375,8 +375,7 @@ static const MemoryRegionPortio *find_portio(MemoryRegion *mr, uint64_t offset, const MemoryRegionPortio *mrp; for (mrp = mr->ops->old_portio; mrp->size; ++mrp) { - if (offset >= mrp->offset && offset < mrp->offset + mrp->len - && width == mrp->size + if (offset < mrp->len && width == mrp->size && (write ? (bool)mrp->write : (bool)mrp->read)) { return mrp; } @@ -396,12 +395,12 @@ static void memory_region_iorange_read(IORange *iorange, *data = ((uint64_t)1 << (width * 8)) - 1; if (mrp) { - *data = mrp->read(mr->opaque, offset + mr->offset); + *data = mrp->read(mr->opaque, offset + mrp->offset); } else if (width == 2) { mrp = find_portio(mr, offset, 1, false); assert(mrp); - *data = mrp->read(mr->opaque, offset + mr->offset) | - (mrp->read(mr->opaque, offset + mr->offset + 1) << 8); + *data = mrp->read(mr->opaque, offset + mrp->offset) | + (mrp->read(mr->opaque, offset + mrp->offset + 1) << 8); } return; } @@ -423,12 +422,12 @@ static void memory_region_iorange_write(IORange *iorange, const MemoryRegionPortio *mrp = find_portio(mr, offset, width, true); if (mrp) { - mrp->write(mr->opaque, offset + mr->offset, data); + mrp->write(mr->opaque, offset + mrp->offset, data); } else if (width == 2) { mrp = find_portio(mr, offset, 1, false); assert(mrp); - mrp->write(mr->opaque, offset + mr->offset, data & 0xff); - mrp->write(mr->opaque, offset + mr->offset + 1, data >> 8); + mrp->write(mr->opaque, offset + mrp->offset, data & 0xff); + mrp->write(mr->opaque, offset + mrp->offset + 1, data >> 8); } return; } -- 1.7.3.4