qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Avi Kivity <avi@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>, Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH] isa: Avoid using obsolete memory_region_set_offset for old portio
Date: Sun, 18 Sep 2011 14:54:32 +0200	[thread overview]
Message-ID: <4E75EA08.4090809@web.de> (raw)

From: Jan Kiszka <jan.kiszka@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.kiszka@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

             reply	other threads:[~2011-09-18 12:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-18 12:54 Jan Kiszka [this message]
2011-09-18 13:09 ` [Qemu-devel] [PATCH] memory: Eliminate region offset Jan Kiszka
2011-09-18 15:57 ` [Qemu-devel] [PATCH] isa: Avoid using obsolete memory_region_set_offset for old portio Avi Kivity
2011-09-18 16:29   ` Jan Kiszka
2011-09-18 16:46     ` Avi Kivity
2011-09-18 19:04       ` Jan Kiszka
2011-09-19 12:14         ` Avi Kivity
2011-09-19 12:29           ` Jan Kiszka
2011-09-19 12:37             ` Avi Kivity
2011-09-19 12:48               ` Jan Kiszka
2011-09-19 12:59                 ` Avi Kivity
2011-09-18 16:49 ` Richard Henderson
2011-09-18 19:16   ` Jan Kiszka
2011-09-19 12:15     ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E75EA08.4090809@web.de \
    --to=jan.kiszka@web.de \
    --cc=avi@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).