All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PULL 3/9] qxl: factor out qxl_get_check_slot_offset
Date: Wed,  6 Jul 2016 12:04:36 +0200	[thread overview]
Message-ID: <1467799482-26420-4-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1467799482-26420-1-git-send-email-kraxel@redhat.com>

New helper function which translates a qxl physical address into
memory slot and offset.  Also applies sanity checks.  Factored out
from qxl_phys2virt.  No functional change.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 1466597244-5938-1-git-send-email-kraxel@redhat.com
---
 hw/display/qxl.c | 59 ++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 38 insertions(+), 21 deletions(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index 47cc6f4..2ea4e3b 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -1338,36 +1338,53 @@ static void qxl_reset_surfaces(PCIQXLDevice *d)
 }
 
 /* can be also called from spice server thread context */
-void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id)
+static bool qxl_get_check_slot_offset(PCIQXLDevice *qxl, QXLPHYSICAL pqxl,
+                                      uint32_t *s, uint64_t *o)
 {
     uint64_t phys   = le64_to_cpu(pqxl);
     uint32_t slot   = (phys >> (64 -  8)) & 0xff;
     uint64_t offset = phys & 0xffffffffffff;
 
-    switch (group_id) {
-    case MEMSLOT_GROUP_HOST:
-        return (void *)(intptr_t)offset;
-    case MEMSLOT_GROUP_GUEST:
-        if (slot >= NUM_MEMSLOTS) {
-            qxl_set_guest_bug(qxl, "slot too large %d >= %d", slot,
-                              NUM_MEMSLOTS);
-            return NULL;
-        }
-        if (!qxl->guest_slots[slot].active) {
-            qxl_set_guest_bug(qxl, "inactive slot %d\n", slot);
-            return NULL;
-        }
-        if (offset < qxl->guest_slots[slot].delta) {
-            qxl_set_guest_bug(qxl,
+    if (slot >= NUM_MEMSLOTS) {
+        qxl_set_guest_bug(qxl, "slot too large %d >= %d", slot,
+                          NUM_MEMSLOTS);
+        return false;
+    }
+    if (!qxl->guest_slots[slot].active) {
+        qxl_set_guest_bug(qxl, "inactive slot %d\n", slot);
+        return false;
+    }
+    if (offset < qxl->guest_slots[slot].delta) {
+        qxl_set_guest_bug(qxl,
                           "slot %d offset %"PRIu64" < delta %"PRIu64"\n",
                           slot, offset, qxl->guest_slots[slot].delta);
-            return NULL;
-        }
-        offset -= qxl->guest_slots[slot].delta;
-        if (offset > qxl->guest_slots[slot].size) {
-            qxl_set_guest_bug(qxl,
+        return false;
+    }
+    offset -= qxl->guest_slots[slot].delta;
+    if (offset > qxl->guest_slots[slot].size) {
+        qxl_set_guest_bug(qxl,
                           "slot %d offset %"PRIu64" > size %"PRIu64"\n",
                           slot, offset, qxl->guest_slots[slot].size);
+        return false;
+    }
+
+    *s = slot;
+    *o = offset;
+    return true;
+}
+
+/* can be also called from spice server thread context */
+void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id)
+{
+    uint64_t offset;
+    uint32_t slot;
+
+    switch (group_id) {
+    case MEMSLOT_GROUP_HOST:
+        offset = le64_to_cpu(pqxl) & 0xffffffffffff;
+        return (void *)(intptr_t)offset;
+    case MEMSLOT_GROUP_GUEST:
+        if (!qxl_get_check_slot_offset(qxl, pqxl, &slot, &offset)) {
             return NULL;
         }
         return qxl->guest_slots[slot].ptr + offset;
-- 
1.8.3.1

  parent reply	other threads:[~2016-07-06 10:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-06 10:04 [Qemu-devel] [PULL 0/9] spice and qxl bugfixes Gerd Hoffmann
2016-07-06 10:04 ` [Qemu-devel] [PULL 1/9] qxl: use uint64_t for vram size Gerd Hoffmann
2016-07-06 10:04 ` [Qemu-devel] [PULL 2/9] qxl: handle no updates in interface_update_area_complete Gerd Hoffmann
2016-07-06 10:04 ` Gerd Hoffmann [this message]
2016-07-06 10:04 ` [Qemu-devel] [PULL 4/9] qxl: store memory region and offset instead of pointer for guest slots Gerd Hoffmann
2016-07-06 10:04 ` [Qemu-devel] [PULL 5/9] qxl: fix surface migration Gerd Hoffmann
2016-07-06 10:04 ` [Qemu-devel] [PULL 6/9] spice: avoid .set_mm_time on >= 0.12.6 Gerd Hoffmann
2016-07-06 10:04 ` [Qemu-devel] [PULL 7/9] virgl: count the calls to gl_block Gerd Hoffmann
2016-07-06 10:04 ` [Qemu-devel] [PULL 8/9] spice: use the right head for multi-monitor Gerd Hoffmann
2016-07-06 10:04 ` [Qemu-devel] [PULL 9/9] virgl: pass whole GL scanout dimensions Gerd Hoffmann
2016-07-06 13:07 ` [Qemu-devel] [PULL 0/9] spice and qxl bugfixes Peter Maydell

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=1467799482-26420-4-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.