diff mbox series

[16/26] hw/display/apple-gfx: Asynchronous MMIO writes on x86-64

Message ID 20240715210705.32365-17-phil@philjordan.eu (mailing list archive)
State New, archived
Headers show
Series [01/26] hw/vmapple/apple-gfx: Introduce ParavirtualizedGraphics.Framework support | expand

Commit Message

Phil Dennis-Jordan July 15, 2024, 9:06 p.m. UTC
This change ensures that the MMIO write calls into the PVG
framework are performed asynchronously on a background dispatch
queue. Without this, we rapidly run into re-entrant MMIO issues.

This problem only seems to exist on x86-64 hosts. Conversely,
doing it async on arm64/vmapple causes other issues, so we're
left with 2 different implementations.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 hw/display/apple-gfx.m | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m
index 806feb58fa..48463e5a1f 100644
--- a/hw/display/apple-gfx.m
+++ b/hw/display/apple-gfx.m
@@ -67,15 +67,28 @@  static uint64_t apple_gfx_read(void *opaque, hwaddr offset, unsigned size)
     return res;
 }
 
-static void apple_gfx_write(void *opaque, hwaddr offset, uint64_t val, unsigned size)
+static void apple_gfx_write(void *opaque, hwaddr offset, uint64_t val,
+                            unsigned size)
 {
     AppleGFXState *s = opaque;
 
     trace_apple_gfx_write(offset, val);
 
+#ifdef __x86_64__
+    id<PGDevice> dev = s->pgdev;
+    dispatch_queue_t bg_queue = NULL;
+
+    bg_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
+    [dev retain];
+    dispatch_async(bg_queue, ^{
+        [dev mmioWriteAtOffset:offset value:val];
+        [dev release];
+    });
+#else
     bql_unlock();
     [s->pgdev mmioWriteAtOffset:offset value:val];
     bql_lock();
+#endif
 }
 
 static const MemoryRegionOps apple_gfx_ops = {