From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729766090; cv=none; d=zohomail.com; s=zohoarc; b=OUycsIH3VLeqjcKemdJ7InpyqJ+jazdnLzTwhAj7yd4caPFRyu75gZAXgTlly2H1HPDbjWPbDYZRVTpq2LtNgbSe+3pHbtd1iQePFeYYQO38avwX/m7iJcjM/C8qhCEA4gv4EkrwdGqKLNDGf1gjiTBlKzjdyoR9K3wvrZL6b1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729766090; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=awe07NOksR1ao1OasiHRde1JNGh5DYeYO6Ef7uq8wQo=; b=JuC3771H/exADvqLXFwiUMi5fA2MjN+6h9TNqKLOmJJ3b18hcckZxFigFhY+MZXouf4waI4LA9wj9TT1kIOUXLPvkI/vK5lvbpsB62dAjeY+QeSFULpWVckqlGFAh1z6cSsK4kfIxLVAigonjEaQB2NeVcVItVdvRFUWycyMpOM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729766090703322.98750503126007; Thu, 24 Oct 2024 03:34:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v54-0000n9-2G; Thu, 24 Oct 2024 06:28:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v51-0000le-BG for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:35 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v4t-00087u-CX for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:35 -0400 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a9acafdb745so153003866b.0 for ; Thu, 24 Oct 2024 03:28:25 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765704; x=1730370504; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=awe07NOksR1ao1OasiHRde1JNGh5DYeYO6Ef7uq8wQo=; b=ZYV8QUT5q08k8i5tRsTYl6HAPszXN+ZSN5Unq32+SbrWmwyayAKBfA0+rnd4KHL57u np5bb4nZY+s2BlFFIhU6y/JH5n/lDwlmjHydt9c6ccqwyAl8nbwrxgD+CmLZdN/P5exS YbQFTDZj+mBagwQo/AqR6bSnJi+IgxB6x11sE4sTU8sQurhHU3hGCuiLLqrUetlU3Rrj OVzqJTDnk4RapWcCG+vyMGXRR0FIUjRvZ6liDHuoHK4sGTuEH6NxQrrDa6IMh9sCO76F 2d0Ebif7Sbt30G54YnfGvcJGW87panKfGFGEeGT/h/i1DiSRXthEhwdXzoFTZk+CnDws lU7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765704; x=1730370504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=awe07NOksR1ao1OasiHRde1JNGh5DYeYO6Ef7uq8wQo=; b=rxLdGCdeFOevfp0IbrhhTVj8nTEMtuMKpPcCuDLfMNPjECOMomK/MyngL//gKYO+XY 2Fg+nSMm17a5k2e9dsE1tvi3wK7v4hU7zD0uCaYZEf5ORrE9vavNQj2SFcy39KUsr7u1 vASvJDe9E50l+fAM2NzTjnT9uJyspeNm6Xu3z750R/8PvaJsIR5e6CXkfspT6VEa+RDw SJtYxBJm/knmyNTcdzbwkKOi/3W4R8cG5aZdrUbC7mAgrAwMS7P3UUvYGORkybP5wDh1 12g7kH2pn/g9VrJm80Le/PtS3F05wvOXw2NDniGI95T+MN4kNegDAqlf/wEWluJ6neWH am+A== X-Gm-Message-State: AOJu0YwCVxQg9LcW4slA+c4ED6HHMVg2m3x+YHzK4u7nHc3ceRpYLyJ8 ZXR46Fzv7OfWUYiE7nPPD+//ZL7L2VwZVRHsOwwuat6aU1rKV8sOO6WBnl5VB+689+T4QVJiTCD e2w== X-Google-Smtp-Source: AGHT+IFnwOlVGXvu5vMdnRrj88KCizIA04RU/tOWWBoYvFgXUz86j957W1cQi3V/VPCBA1bIERXcYA== X-Received: by 2002:a17:907:7211:b0:a9a:ca:4436 with SMTP id a640c23a62f3a-a9ad19a8b5amr159060266b.13.1729765704224; Thu, 24 Oct 2024 03:28:24 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v4 01/15] ui & main loop: Redesign of system-specific main thread event handling Date: Thu, 24 Oct 2024 12:27:59 +0200 Message-Id: <20241024102813.9855-2-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::630; envelope-from=phil@philjordan.eu; helo=mail-ej1-x630.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729766092807116600 Content-Type: text/plain; charset="utf-8" macOS's Cocoa event handling must be done on the initial (main) thread of the process. Furthermore, if library or application code uses libdispatch, the main dispatch queue must be handling events on the main thread as well. So far, this has affected Qemu in both the Cocoa and SDL UIs, although in different ways: the Cocoa UI replaces the default qemu_main function with one that spins Qemu's internal main event loop off onto a background thread. SDL (which uses Cocoa internally) on the other hand uses a polling approach within Qemu's main event loop. Events are polled during the SDL UI's dpy_refresh callback, which happens to run on the main thread by default. As UIs are mutually exclusive, this works OK as long as nothing else needs platform-native event handling. In the next patch, a new device is introduced based on the ParavirtualizedGraphics.framework in macOS. This uses libdispatch internally, and only works when events are being handled on the main runloop. With the current system, it works when using either the Cocoa or the SDL UI. However, it does not when running headless. Moreover, any attempt to install a similar scheme to the Cocoa UI's main thread replacement fails when combined with the SDL UI. This change formalises main thread handling. UI (Display) and OS platform implementations can declare requirements or preferences: * The Cocoa UI specifies that Qemu's main loop must run on a background thread and provides a function to run on the main thread which runs the NSApplication event handling runloop. * The SDL UI specifies that Qemu's main loop must run on the main thread. * For other UIs, or in the absence of UIs, the platform's default behaviour is followed. * The Darwin platform provides a default function to run on the main thread, which runs the main CFRunLoop. * Other OSes do not provide their own default main function and thus fall back to running Qemu's main loop on the main thread, as usual. This means that on macOS, the platform's runloop events are always handled, regardless of chosen UI. The new PV graphics device will thus work in all configurations. Signed-off-by: Phil Dennis-Jordan --- include/qemu-main.h | 3 +-- include/qemu/typedefs.h | 1 + include/sysemu/os-posix.h | 2 ++ include/sysemu/os-win32.h | 2 ++ include/ui/console.h | 12 +++++++++ os-posix.c | 20 ++++++++++++++ system/main.c | 45 +++++++++++++++++++++++++++----- system/vl.c | 2 ++ ui/cocoa.m | 55 +++++++++------------------------------ ui/console.c | 32 +++++++++++++++++++++-- ui/sdl2.c | 2 ++ ui/trace-events | 1 + 12 files changed, 123 insertions(+), 54 deletions(-) diff --git a/include/qemu-main.h b/include/qemu-main.h index 940960a7dbc..4bd0d667edc 100644 --- a/include/qemu-main.h +++ b/include/qemu-main.h @@ -5,7 +5,6 @@ #ifndef QEMU_MAIN_H #define QEMU_MAIN_H =20 -int qemu_default_main(void); -extern int (*qemu_main)(void); +extern qemu_main_fn qemu_main; =20 #endif /* QEMU_MAIN_H */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 3d84efcac47..b02cfe1f328 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -131,5 +131,6 @@ typedef struct IRQState *qemu_irq; * Function types */ typedef void (*qemu_irq_handler)(void *opaque, int n, int level); +typedef int (*qemu_main_fn)(void); =20 #endif /* QEMU_TYPEDEFS_H */ diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h index b881ac6c6f7..51bbb5370e0 100644 --- a/include/sysemu/os-posix.h +++ b/include/sysemu/os-posix.h @@ -26,6 +26,7 @@ #ifndef QEMU_OS_POSIX_H #define QEMU_OS_POSIX_H =20 +#include "qemu/typedefs.h" #include #include #include @@ -54,6 +55,7 @@ void os_set_chroot(const char *path); void os_setup_limits(void); void os_setup_post(void); int os_mlock(void); +qemu_main_fn os_non_loop_main_thread_fn(void); =20 /** * qemu_alloc_stack: diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index b82a5d3ad93..db0daba9a52 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -26,6 +26,7 @@ #ifndef QEMU_OS_WIN32_H #define QEMU_OS_WIN32_H =20 +#include "qemu/typedefs.h" #include #include #include @@ -105,6 +106,7 @@ void os_set_line_buffering(void); void os_setup_early_signal_handling(void); =20 int getpagesize(void); +static inline qemu_main_fn os_non_loop_main_thread_fn(void) { return NULL;= } =20 #if !defined(EPROTONOSUPPORT) # define EPROTONOSUPPORT EINVAL diff --git a/include/ui/console.h b/include/ui/console.h index 5832d52a8a6..4e3dc7da146 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -440,6 +440,18 @@ typedef struct QemuDisplay QemuDisplay; =20 struct QemuDisplay { DisplayType type; + /* + * Some UIs have special requirements, for the qemu_main event loop ru= nning + * on either the process's initial (main) thread ('Off'), or on an + * explicitly created background thread ('On') because of platform-spe= cific + * event handling. + * The default, 'Auto', indicates the display will work with both setu= ps. + * If 'On', either a qemu_main_thread_fn must be supplied, or it must = be + * ensured that all applicable host OS platforms supply a default main. + * (via os_non_loop_main_thread_fn()) + */ + OnOffAuto qemu_main_on_bg_thread; + qemu_main_fn qemu_main_thread_fn; void (*early_init)(DisplayOptions *opts); void (*init)(DisplayState *ds, DisplayOptions *opts); const char *vc; diff --git a/os-posix.c b/os-posix.c index 43f9a43f3fe..a173c026f6c 100644 --- a/os-posix.c +++ b/os-posix.c @@ -37,6 +37,8 @@ =20 #ifdef CONFIG_LINUX #include +#elif defined(CONFIG_DARWIN) +#include #endif =20 =20 @@ -342,3 +344,21 @@ int os_mlock(void) return -ENOSYS; #endif } + +#ifdef CONFIG_DARWIN +static int os_darwin_cfrunloop_main(void) +{ + CFRunLoopRun(); + abort(); +} +#endif + +qemu_main_fn os_non_loop_main_thread_fn(void) +{ +#ifdef CONFIG_DARWIN + /* By default, run the OS's event runloop on the main thread. */ + return os_darwin_cfrunloop_main; +#else + return NULL; +#endif +} diff --git a/system/main.c b/system/main.c index 9b91d21ea8c..358eab281b0 100644 --- a/system/main.c +++ b/system/main.c @@ -24,13 +24,10 @@ =20 #include "qemu/osdep.h" #include "qemu-main.h" +#include "qemu/main-loop.h" #include "sysemu/sysemu.h" =20 -#ifdef CONFIG_SDL -#include -#endif - -int qemu_default_main(void) +static int qemu_default_main(void) { int status; =20 @@ -40,10 +37,44 @@ int qemu_default_main(void) return status; } =20 -int (*qemu_main)(void) =3D qemu_default_main; +/* + * Various macOS system libraries, including the Cocoa UI and anything usi= ng + * libdispatch, such as ParavirtualizedGraphics.framework, requires that t= he + * main runloop, on the main (initial) thread be running or at least regul= arly + * polled for events. A special mode is therefore supported, where the QEMU + * main loop runs on a separate thread and the main thread handles the + * CF/Cocoa runloop. + */ + +static void *call_qemu_default_main(void *opaque) +{ + int status; + + bql_lock(); + status =3D qemu_default_main(); + bql_unlock(); + + exit(status); +} + +static void qemu_run_default_main_on_new_thread(void) +{ + QemuThread thread; + + qemu_thread_create(&thread, "qemu_main", call_qemu_default_main, + NULL, QEMU_THREAD_DETACHED); +} + +qemu_main_fn qemu_main; =20 int main(int argc, char **argv) { qemu_init(argc, argv); - return qemu_main(); + if (qemu_main) { + qemu_run_default_main_on_new_thread(); + bql_unlock(); + return qemu_main(); + } else { + qemu_default_main(); + } } diff --git a/system/vl.c b/system/vl.c index e83b3b2608b..c1db20dbee9 100644 --- a/system/vl.c +++ b/system/vl.c @@ -134,6 +134,7 @@ #include "sysemu/iothread.h" #include "qemu/guest-random.h" #include "qemu/keyval.h" +#include "qemu-main.h" =20 #define MAX_VIRTIO_CONSOLES 1 =20 @@ -3667,6 +3668,7 @@ void qemu_init(int argc, char **argv) trace_init_file(); =20 qemu_init_main_loop(&error_fatal); + qemu_main =3D os_non_loop_main_thread_fn(); cpu_timers_init(); =20 user_register_global_props(); diff --git a/ui/cocoa.m b/ui/cocoa.m index 4c2dd335323..393b3800491 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -73,6 +73,8 @@ int height; } QEMUScreen; =20 +@class QemuCocoaPasteboardTypeOwner; + static void cocoa_update(DisplayChangeListener *dcl, int x, int y, int w, int h); =20 @@ -107,6 +109,7 @@ static void cocoa_switch(DisplayChangeListener *dcl, static NSInteger cbchangecount =3D -1; static QemuClipboardInfo *cbinfo; static QemuEvent cbevent; +static QemuCocoaPasteboardTypeOwner *cbowner; =20 // Utility functions to run specified code block with the BQL held typedef void (^CodeBlock)(void); @@ -1321,8 +1324,10 @@ - (void) dealloc { COCOA_DEBUG("QemuCocoaAppController: dealloc\n"); =20 - if (cocoaView) - [cocoaView release]; + [cocoaView release]; + [cbowner release]; + cbowner =3D nil; + [super dealloc]; } =20 @@ -1938,8 +1943,6 @@ - (void)pasteboard:(NSPasteboard *)sender provideData= ForType:(NSPasteboardType)t =20 @end =20 -static QemuCocoaPasteboardTypeOwner *cbowner; - static void cocoa_clipboard_notify(Notifier *notifier, void *data); static void cocoa_clipboard_request(QemuClipboardInfo *info, QemuClipboardType type); @@ -2002,43 +2005,8 @@ static void cocoa_clipboard_request(QemuClipboardInf= o *info, } } =20 -/* - * The startup process for the OSX/Cocoa UI is complicated, because - * OSX insists that the UI runs on the initial main thread, and so we - * need to start a second thread which runs the qemu_default_main(): - * in main(): - * in cocoa_display_init(): - * assign cocoa_main to qemu_main - * create application, menus, etc - * in cocoa_main(): - * create qemu-main thread - * enter OSX run loop - */ - -static void *call_qemu_main(void *opaque) -{ - int status; - - COCOA_DEBUG("Second thread: calling qemu_default_main()\n"); - bql_lock(); - status =3D qemu_default_main(); - bql_unlock(); - COCOA_DEBUG("Second thread: qemu_default_main() returned, exiting\n"); - [cbowner release]; - exit(status); -} - static int cocoa_main(void) { - QemuThread thread; - - COCOA_DEBUG("Entered %s()\n", __func__); - - bql_unlock(); - qemu_thread_create(&thread, "qemu_main", call_qemu_main, - NULL, QEMU_THREAD_DETACHED); - - // Start the main event loop COCOA_DEBUG("Main thread: entering OSX run loop\n"); [NSApp run]; COCOA_DEBUG("Main thread: left OSX run loop, which should never happen= \n"); @@ -2120,8 +2088,6 @@ static void cocoa_display_init(DisplayState *ds, Disp= layOptions *opts) =20 COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n"); =20 - qemu_main =3D cocoa_main; - // Pull this console process up to being a fully-fledged graphical // app with a menubar and Dock icon ProcessSerialNumber psn =3D { 0, kCurrentProcess }; @@ -2188,8 +2154,11 @@ static void cocoa_display_init(DisplayState *ds, Dis= playOptions *opts) } =20 static QemuDisplay qemu_display_cocoa =3D { - .type =3D DISPLAY_TYPE_COCOA, - .init =3D cocoa_display_init, + .type =3D DISPLAY_TYPE_COCOA, + .init =3D cocoa_display_init, + /* The Cocoa UI will run the NSApplication runloop on the main thread.= */ + .qemu_main_on_bg_thread =3D ON_OFF_AUTO_ON, + .qemu_main_thread_fn =3D cocoa_main, }; =20 static void register_cocoa(void) diff --git a/ui/console.c b/ui/console.c index 5165f171257..1599d8b7095 100644 --- a/ui/console.c +++ b/ui/console.c @@ -33,6 +33,7 @@ #include "qemu/main-loop.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qemu-main.h" #include "chardev/char.h" #include "trace.h" #include "exec/memory.h" @@ -1569,12 +1570,39 @@ void qemu_display_early_init(DisplayOptions *opts) =20 void qemu_display_init(DisplayState *ds, DisplayOptions *opts) { + QemuDisplay *display; + bool bg_main_loop; + assert(opts->type < DISPLAY_TYPE__MAX); if (opts->type =3D=3D DISPLAY_TYPE_NONE) { return; } - assert(dpys[opts->type] !=3D NULL); - dpys[opts->type]->init(ds, opts); + display =3D dpys[opts->type]; + assert(display !=3D NULL); + display->init(ds, opts); + + switch (display->qemu_main_on_bg_thread) { + case ON_OFF_AUTO_OFF: + bg_main_loop =3D false; + qemu_main =3D NULL; + break; + case ON_OFF_AUTO_ON: + bg_main_loop =3D true; + break; + case ON_OFF_AUTO_AUTO: + default: + bg_main_loop =3D qemu_main; + break; + } + + trace_qemu_display_init_main_thread( + DisplayType_str(display->type), display->qemu_main_thread_fn, qemu= _main, + OnOffAuto_lookup.array[display->qemu_main_on_bg_thread], + display->qemu_main_on_bg_thread, bg_main_loop); + if (bg_main_loop && display->qemu_main_thread_fn) { + qemu_main =3D display->qemu_main_thread_fn; + } + assert(!bg_main_loop || qemu_main); } =20 const char *qemu_display_get_vc(DisplayOptions *opts) diff --git a/ui/sdl2.c b/ui/sdl2.c index bd4f5a9da14..35e22785119 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -971,6 +971,8 @@ static QemuDisplay qemu_display_sdl2 =3D { .type =3D DISPLAY_TYPE_SDL, .early_init =3D sdl2_display_early_init, .init =3D sdl2_display_init, + /* SDL must poll for events (via dpy_refresh) on main thread */ + .qemu_main_on_bg_thread =3D ON_OFF_AUTO_OFF, }; =20 static void register_sdl1(void) diff --git a/ui/trace-events b/ui/trace-events index 3da0d5e2800..1e72c967399 100644 --- a/ui/trace-events +++ b/ui/trace-events @@ -16,6 +16,7 @@ displaysurface_free(void *display_surface) "surface=3D%p" displaychangelistener_register(void *dcl, const char *name) "%p [ %s ]" displaychangelistener_unregister(void *dcl, const char *name) "%p [ %s ]" ppm_save(int fd, void *image) "fd=3D%d image=3D%p" +qemu_display_init_main_thread(const char *display_name, bool qemu_display_= sets_main_fn, bool qemu_main_is_set, const char *display_bg_main_loop_prefe= rence, int preference, bool bg_main_loop) "display '%s': sets main thread f= unction: %d, platform provides main function: %d, display background main l= oop preference: %s (%d); main loop will run on background thread: %d" =20 # gtk-egl.c # gtk-gl-area.c --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729766036; cv=none; d=zohomail.com; s=zohoarc; b=MSCNUDV4UYS6kiXtUZw4skumQ1eZgkSAZ8q0znrBEdSQtErZfap7EqFt7ZCh2VLTgQ6wsrqFRHpQqRJwWXEV+lFc6ulU78hPY8lk9mD6TQzYjRIsDtZcSDte4htxkZXLzJewKaJJNfCD5kPcqt9py3DKYFOMLRiFCI0PTg3QN1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729766036; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8mlE45W4fZjmmvi0h+ViiSbucoXF+bM4oc3Tgjqocyg=; b=aLwnCHLyUen5dl6n3X/xpYz8q6IZtgVNkO06tYHpDNrzX+cdm+j2/fy4bFDCg5ICtnZ0lfoyFE26t5L5oirqMUHDaEXWdujEeov1/o/SsRRCUDkybrkTHgmO+jwgUdRsbUGNos+ENXuk3Aj+/Y3DDEJvP6rLq6MoKRoBAEgiFmE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729766036812354.6176856833181; Thu, 24 Oct 2024 03:33:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v54-0000oV-Tq; Thu, 24 Oct 2024 06:28:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v52-0000ma-Rz for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:36 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v4v-00088W-HP for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:36 -0400 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a93c1cc74fdso91007266b.3 for ; Thu, 24 Oct 2024 03:28:28 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765707; x=1730370507; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8mlE45W4fZjmmvi0h+ViiSbucoXF+bM4oc3Tgjqocyg=; b=uVYW5rOt0GNK9B6x1iQUooWT3AMYXkoeDr9vTES66jP3TRCvDnFbbVq6TUlIlf7bCl ZRT2/5M2LR2RcfOWmGY+DoZPfcxz/Cn3e887j7wQXvARZJgwq62FLBQ/hOqx6sH9cz+1 gHJUbdBEU6Lt7t9+Fwf9WY52TED6acr6FQAf80UqrWRGKvf6Vdga4iIvMg0O9B1sdsdV ys4AjB/PkMYms0dJGuLTyBZ3Ls7iAQGkLe3ZTzLSI7/ZArLV71yl2Z9+prLCw3QAm+OY zSjG5o3gfLwTZSqnc+rUCvaOzqoGNBCgv3qAC+IVIEeY4n6ok3xqFOUwTn07uuCcpL9j 1sLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765707; x=1730370507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8mlE45W4fZjmmvi0h+ViiSbucoXF+bM4oc3Tgjqocyg=; b=egv6G7CoZxAx0FWOVa9QK0gK4N7gIcYC+o7KIy2RKwPZ7gWaXhycxaJS+OINZLPD6L xactIbRIf1tPdp65WW/+44vEaFLkE6qe5x/n7Jk/iwtyNJ/NCrN8/SmS5ic5MUYU/lBV oVOVXv3+k/mBl9/80EbfVVOAcoUGjERkV/Qrrha7vJ7O/N+IVNjdySV4oeKiGQXfNZOI l6+uMo1R9RJMhh1e9vRY2VWL4w9GoYDR/rOHUOCpzkZu7GW4fJEluQY10bWzZCVl6RVt 7sK7m4QuDZacitsqfjwwGKJbvKKMlO/fCdnTnLXRSGFDjRvorLnEJD5Xc5uxNUZGrbRu 9wpQ== X-Gm-Message-State: AOJu0Yz1MV+kcLoW0c6GN98mxCUIvnXltq27t49OEOJfR8Aga8wnyjAW sSRF8CztLGYmyhhBINNueGh93PoR+yoxtQXQbO7i5G/eNOU7VFFvNCX8xuOGvbjsxpPLmv2HrC1 HAQ== X-Google-Smtp-Source: AGHT+IEpa38ZXkEyjmxHTcpoOCJKEREMqvtjzimQoDVZFPYTJcfWaf96b7aIcRS99hZYYN/QjqDa2A== X-Received: by 2002:a17:907:7296:b0:a99:46ff:f4e6 with SMTP id a640c23a62f3a-a9abf96f10bmr494498466b.61.1729765706500; Thu, 24 Oct 2024 03:28:26 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, Alexander Graf Subject: [PATCH v4 02/15] hw/display/apple-gfx: Introduce ParavirtualizedGraphics.Framework support Date: Thu, 24 Oct 2024 12:28:00 +0200 Message-Id: <20241024102813.9855-3-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::62d; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62d.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729766038288116600 MacOS provides a framework (library) that allows any vmm to implement a paravirtualized 3d graphics passthrough to the host metal stack called ParavirtualizedGraphics.Framework (PVG). The library abstracts away almost every aspect of the paravirtualized device model and only provides and receives callbacks on MMIO access as well as to share memory address space between the VM and PVG. This patch implements a QEMU device that drives PVG for the VMApple variant of it. Signed-off-by: Alexander Graf Co-authored-by: Alexander Graf Subsequent changes: * Cherry-pick/rebase conflict fixes, API use updates. * Moved from hw/vmapple/ (useful outside that machine type) * Overhaul of threading model, many thread safety improvements. * Asynchronous rendering. * Memory and object lifetime fixes. * Refactoring to split generic and (vmapple) MMIO variant specific code. Signed-off-by: Phil Dennis-Jordan --- v2: * Cherry-pick/rebase conflict fixes * BQL function renaming * Moved from hw/vmapple/ (useful outside that machine type) * Code review comments: Switched to DEFINE_TYPES macro & little endian MMIO. * Removed some dead/superfluous code * Mad set_mode thread & memory safe * Added migration blocker due to lack of (de-)serialisation. * Fixes to ObjC refcounting and autorelease pool usage. * Fixed ObjC new/init misuse * Switched to ObjC category extension for private property. * Simplified task memory mapping and made it thread safe. * Refactoring to split generic and vmapple MMIO variant specific code. * Switched to asynchronous MMIO writes on x86-64 * Rendering and graphics update are now done asynchronously * Fixed cursor handling * Coding convention fixes * Removed software cursor compositing v3: * Rebased on latest upstream, fixed breakages including switching to Reset= table methods. * Squashed patches dealing with dGPUs, MMIO area size, and GPU picking. * Allow re-entrant MMIO; this simplifies the code and solves the divergence between x86-64 and arm64 variants. v4: * Renamed '-vmapple' device variant to '-mmio' * MMIO device type now requires aarch64 host and guest * Complete overhaul of the glue code for making Qemu's and ParavirtualizedGraphics.framework's threading and synchronisation models work together. Calls into PVG are from dispatch queues while the BQL-holding initiating thread processes AIO context events; callbacks fr= om PVG are scheduled as BHs on the BQL/main AIO context, awaiting completion where necessary. * Guest frame rendering state is covered by the BQL, with only the PVG cal= ls outside the lock, and serialised on the named render_queue. * Simplified logic for dropping frames in-flight during mode changes, fixed bug in pending frames logic. * Addressed smaller code review notes such as: function naming, object type declarations, type names/declarations/casts, code formatting, #include order, over-cautious ObjC retain/release, what goes in init vs realize, etc. hw/display/Kconfig | 9 + hw/display/apple-gfx-mmio.m | 284 ++++++++++++++ hw/display/apple-gfx.h | 58 +++ hw/display/apple-gfx.m | 713 ++++++++++++++++++++++++++++++++++++ hw/display/meson.build | 4 + hw/display/trace-events | 26 ++ meson.build | 4 + 7 files changed, 1098 insertions(+) create mode 100644 hw/display/apple-gfx-mmio.m create mode 100644 hw/display/apple-gfx.h create mode 100644 hw/display/apple-gfx.m diff --git a/hw/display/Kconfig b/hw/display/Kconfig index 2250c740078..6a9b7b19ada 100644 --- a/hw/display/Kconfig +++ b/hw/display/Kconfig @@ -140,3 +140,12 @@ config XLNX_DISPLAYPORT =20 config DM163 bool + +config MAC_PVG + bool + default y + +config MAC_PVG_MMIO + bool + depends on MAC_PVG && AARCH64 + diff --git a/hw/display/apple-gfx-mmio.m b/hw/display/apple-gfx-mmio.m new file mode 100644 index 00000000000..06131bc23f1 --- /dev/null +++ b/hw/display/apple-gfx-mmio.m @@ -0,0 +1,284 @@ +/* + * QEMU Apple ParavirtualizedGraphics.framework device, MMIO (arm64) varia= nt + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + * ParavirtualizedGraphics.framework is a set of libraries that macOS prov= ides + * which implements 3d graphics passthrough to the host as well as a + * proprietary guest communication channel to drive it. This device model + * implements support to drive that library from within QEMU as an MMIO-ba= sed + * system device for macOS on arm64 VMs. + */ + +#include "qemu/osdep.h" +#import +#include "apple-gfx.h" +#include "monitor/monitor.h" +#include "hw/sysbus.h" +#include "hw/irq.h" +#include "trace.h" + +OBJECT_DECLARE_SIMPLE_TYPE(AppleGFXMMIOState, APPLE_GFX_MMIO) + +/* + * ParavirtualizedGraphics.Framework only ships header files for the PCI + * variant which does not include IOSFC descriptors and host devices. We a= dd + * their definitions here so that we can also work with the ARM version. + */ +typedef bool(^IOSFCRaiseInterrupt)(uint32_t vector); +typedef bool(^IOSFCUnmapMemory)( + void *, void *, void *, void *, void *, void *); +typedef bool(^IOSFCMapMemory)( + uint64_t phys, uint64_t len, bool ro, void **va, void *, void *); + +@interface PGDeviceDescriptor (IOSurfaceMapper) +@property (readwrite, nonatomic) bool usingIOSurfaceMapper; +@end + +@interface PGIOSurfaceHostDeviceDescriptor : NSObject +-(PGIOSurfaceHostDeviceDescriptor *)init; +@property (readwrite, nonatomic, copy, nullable) IOSFCMapMemory mapMemory; +@property (readwrite, nonatomic, copy, nullable) IOSFCUnmapMemory unmapMem= ory; +@property (readwrite, nonatomic, copy, nullable) IOSFCRaiseInterrupt raise= Interrupt; +@end + +@interface PGIOSurfaceHostDevice : NSObject +-(instancetype)initWithDescriptor:(PGIOSurfaceHostDeviceDescriptor *)desc; +-(uint32_t)mmioReadAtOffset:(size_t)offset; +-(void)mmioWriteAtOffset:(size_t)offset value:(uint32_t)value; +@end + +struct AppleGFXMapSurfaceMemoryJob; +struct AppleGFXMMIOState { + SysBusDevice parent_obj; + + AppleGFXState common; + + qemu_irq irq_gfx; + qemu_irq irq_iosfc; + MemoryRegion iomem_iosfc; + PGIOSurfaceHostDevice *pgiosfc; +}; + +typedef struct AppleGFXMMIOJob { + AppleGFXMMIOState *state; + uint64_t offset; + uint64_t value; + bool completed; +} AppleGFXMMIOJob; + +static void iosfc_do_read(void *opaque) +{ + AppleGFXMMIOJob *job =3D opaque; + job->value =3D [job->state->pgiosfc mmioReadAtOffset:job->offset]; + qatomic_set(&job->completed, true); + aio_wait_kick(); +} + +static uint64_t iosfc_read(void *opaque, hwaddr offset, unsigned size) +{ + AppleGFXMMIOJob job =3D { + .state =3D opaque, + .offset =3D offset, + .completed =3D false, + }; + AioContext *context =3D qemu_get_aio_context(); + dispatch_queue_t queue =3D dispatch_get_global_queue(DISPATCH_QUEUE_PR= IORITY_DEFAULT, 0); + + dispatch_async_f(queue, &job, iosfc_do_read); + AIO_WAIT_WHILE(context, !qatomic_read(&job.completed)); + + trace_apple_gfx_mmio_iosfc_read(offset, job.value); + return job.value; +} + +static void iosfc_do_write(void *opaque) +{ + AppleGFXMMIOJob *job =3D opaque; + [job->state->pgiosfc mmioWriteAtOffset:job->offset value:job->value]; + qatomic_set(&job->completed, true); + aio_wait_kick(); +} + +static void iosfc_write(void *opaque, hwaddr offset, uint64_t val, + unsigned size) +{ + AppleGFXMMIOJob job =3D { + .state =3D opaque, + .offset =3D offset, + .value =3D val, + .completed =3D false, + }; + AioContext *context =3D qemu_get_aio_context(); + dispatch_queue_t queue =3D dispatch_get_global_queue(DISPATCH_QUEUE_PR= IORITY_DEFAULT, 0); + + dispatch_async_f(queue, &job, iosfc_do_write); + AIO_WAIT_WHILE(context, !qatomic_read(&job.completed)); + + trace_apple_gfx_mmio_iosfc_write(offset, val); +} + +static const MemoryRegionOps apple_iosfc_ops =3D { + .read =3D iosfc_read, + .write =3D iosfc_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + }, +}; + +static void raise_iosfc_irq(void *opaque) +{ + AppleGFXMMIOState *s =3D opaque; + + qemu_irq_pulse(s->irq_iosfc); +} + +typedef struct AppleGFXMapSurfaceMemoryJob { + uint64_t guest_physical_address; + uint64_t guest_physical_length; + void *result_mem; + AppleGFXMMIOState *state; + bool read_only; + bool success; + bool done; +} AppleGFXMapSurfaceMemoryJob; + +static void apple_gfx_mmio_map_surface_memory(void *opaque) +{ + AppleGFXMapSurfaceMemoryJob *job =3D opaque; + AppleGFXMMIOState *s =3D job->state; + mach_vm_address_t mem; + + mem =3D apple_gfx_host_address_for_gpa_range(job->guest_physical_addre= ss, + job->guest_physical_length, + job->read_only); + + qemu_mutex_lock(&s->common.job_mutex); + job->result_mem =3D (void*)mem; + job->success =3D mem !=3D 0; + job->done =3D true; + qemu_cond_broadcast(&s->common.job_cond); + qemu_mutex_unlock(&s->common.job_mutex); +} + +static PGIOSurfaceHostDevice *apple_gfx_prepare_iosurface_host_device( + AppleGFXMMIOState *s) +{ + PGIOSurfaceHostDeviceDescriptor *iosfc_desc =3D + [PGIOSurfaceHostDeviceDescriptor new]; + PGIOSurfaceHostDevice *iosfc_host_dev =3D nil; + + iosfc_desc.mapMemory =3D + ^bool(uint64_t phys, uint64_t len, bool ro, void **va, void *e, vo= id *f) { + AppleGFXMapSurfaceMemoryJob job =3D { + .guest_physical_address =3D phys, .guest_physical_length = =3D len, + .read_only =3D ro, .state =3D s, + }; + + aio_bh_schedule_oneshot(qemu_get_aio_context(), + apple_gfx_mmio_map_surface_memory, &jo= b); + apple_gfx_await_bh_job(&s->common, &job.done); + + *va =3D job.result_mem; + + trace_apple_gfx_iosfc_map_memory(phys, len, ro, va, e, f, *va, + job.success); + + return job.success; + }; + + iosfc_desc.unmapMemory =3D + ^bool(void *a, void *b, void *c, void *d, void *e, void *f) { + trace_apple_gfx_iosfc_unmap_memory(a, b, c, d, e, f); + return true; + }; + + iosfc_desc.raiseInterrupt =3D ^bool(uint32_t vector) { + trace_apple_gfx_iosfc_raise_irq(vector); + aio_bh_schedule_oneshot(qemu_get_aio_context(), raise_iosfc_irq, s= ); + return true; + }; + + iosfc_host_dev =3D + [[PGIOSurfaceHostDevice alloc] initWithDescriptor:iosfc_desc]; + [iosfc_desc release]; + return iosfc_host_dev; +} + +static void raise_gfx_irq(void *opaque) +{ + AppleGFXMMIOState *s =3D opaque; + + qemu_irq_pulse(s->irq_gfx); +} + +static void apple_gfx_mmio_realize(DeviceState *dev, Error **errp) +{ + @autoreleasepool { + AppleGFXMMIOState *s =3D APPLE_GFX_MMIO(dev); + PGDeviceDescriptor *desc =3D [PGDeviceDescriptor new]; + + desc.raiseInterrupt =3D ^(uint32_t vector) { + trace_apple_gfx_raise_irq(vector); + aio_bh_schedule_oneshot(qemu_get_aio_context(), raise_gfx_irq,= s); + }; + + desc.usingIOSurfaceMapper =3D true; + s->pgiosfc =3D apple_gfx_prepare_iosurface_host_device(s); + + apple_gfx_common_realize(&s->common, desc, errp); + [desc release]; + desc =3D nil; + } +} + +static void apple_gfx_mmio_init(Object *obj) +{ + AppleGFXMMIOState *s =3D APPLE_GFX_MMIO(obj); + + apple_gfx_common_init(obj, &s->common, TYPE_APPLE_GFX_MMIO); + + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->common.iomem_gfx); + memory_region_init_io(&s->iomem_iosfc, obj, &apple_iosfc_ops, s, + TYPE_APPLE_GFX_MMIO, 0x10000); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem_iosfc); + sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq_gfx); + sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq_iosfc); +} + +static void apple_gfx_mmio_reset(Object *obj, ResetType type) +{ + AppleGFXMMIOState *s =3D APPLE_GFX_MMIO(obj); + [s->common.pgdev reset]; +} + + +static void apple_gfx_mmio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + rc->phases.hold =3D apple_gfx_mmio_reset; + dc->hotpluggable =3D false; + dc->realize =3D apple_gfx_mmio_realize; +} + +static TypeInfo apple_gfx_mmio_types[] =3D { + { + .name =3D TYPE_APPLE_GFX_MMIO, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(AppleGFXMMIOState), + .class_init =3D apple_gfx_mmio_class_init, + .instance_init =3D apple_gfx_mmio_init, + } +}; +DEFINE_TYPES(apple_gfx_mmio_types) diff --git a/hw/display/apple-gfx.h b/hw/display/apple-gfx.h new file mode 100644 index 00000000000..39931fba65a --- /dev/null +++ b/hw/display/apple-gfx.h @@ -0,0 +1,58 @@ +#ifndef QEMU_APPLE_GFX_H +#define QEMU_APPLE_GFX_H + +#define TYPE_APPLE_GFX_MMIO "apple-gfx-mmio" +#define TYPE_APPLE_GFX_PCI "apple-gfx-pci" + +#include "qemu/osdep.h" +#include +#import +#include "qemu/typedefs.h" +#include "exec/memory.h" +#include "ui/surface.h" + +@class PGDeviceDescriptor; +@protocol PGDevice; +@protocol PGDisplay; +@protocol MTLDevice; +@protocol MTLTexture; +@protocol MTLCommandQueue; + +typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; + +struct AppleGFXMapMemoryJob; +typedef struct AppleGFXState { + MemoryRegion iomem_gfx; + id pgdev; + id pgdisp; + PGTaskList tasks; + QemuConsole *con; + id mtl; + id mtl_queue; + bool cursor_show; + QEMUCursor *cursor; + + /* For running PVG memory-mapping requests in the AIO context */ + QemuCond job_cond; + QemuMutex job_mutex; + + dispatch_queue_t render_queue; + /* The following fields should only be accessed from the BQL: */ + bool gfx_update_requested; + bool new_frame_ready; + bool using_managed_texture_storage; + int32_t pending_frames; + void *vram; + DisplaySurface *surface; + id texture; +} AppleGFXState; + +void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_= name); +void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc, + Error **errp); +uintptr_t apple_gfx_host_address_for_gpa_range(uint64_t guest_physical, + uint64_t length, bool read_= only); +void apple_gfx_await_bh_job(AppleGFXState *s, bool *job_done_flag); + +#endif + diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m new file mode 100644 index 00000000000..46be9957f69 --- /dev/null +++ b/hw/display/apple-gfx.m @@ -0,0 +1,713 @@ +/* + * QEMU Apple ParavirtualizedGraphics.framework device + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + * ParavirtualizedGraphics.framework is a set of libraries that macOS prov= ides + * which implements 3d graphics passthrough to the host as well as a + * proprietary guest communication channel to drive it. This device model + * implements support to drive that library from within QEMU. + */ + +#include "qemu/osdep.h" +#import +#include +#include "apple-gfx.h" +#include "trace.h" +#include "qemu-main.h" +#include "exec/address-spaces.h" +#include "migration/blocker.h" +#include "monitor/monitor.h" +#include "qemu/main-loop.h" +#include "qemu/cutils.h" +#include "qemu/log.h" +#include "qapi/visitor.h" +#include "qapi/error.h" +#include "ui/console.h" + +static const PGDisplayCoord_t apple_gfx_modes[] =3D { + { .x =3D 1440, .y =3D 1080 }, + { .x =3D 1280, .y =3D 1024 }, +}; + +/* This implements a type defined in + * which is opaque from the framework's point of view. Typedef PGTask_t al= ready + * exists in the framework headers. */ +struct PGTask_s { + QTAILQ_ENTRY(PGTask_s) node; + mach_vm_address_t address; + uint64_t len; +}; + +static Error *apple_gfx_mig_blocker; + +static void apple_gfx_render_frame_completed(AppleGFXState *s, + uint32_t width, uint32_t heig= ht); + +static inline dispatch_queue_t get_background_queue(void) +{ + return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); +} + +static PGTask_t *apple_gfx_new_task(AppleGFXState *s, uint64_t len) +{ + mach_vm_address_t task_mem; + PGTask_t *task; + kern_return_t r; + + r =3D mach_vm_allocate(mach_task_self(), &task_mem, len, VM_FLAGS_ANYW= HERE); + if (r !=3D KERN_SUCCESS || task_mem =3D=3D 0) { + return NULL; + } + + task =3D g_new0(PGTask_t, 1); + + task->address =3D task_mem; + task->len =3D len; + QTAILQ_INSERT_TAIL(&s->tasks, task, node); + + return task; +} + +typedef struct AppleGFXIOJob { + AppleGFXState *state; + uint64_t offset; + uint64_t value; + bool completed; +} AppleGFXIOJob; + +static void apple_gfx_do_read(void *opaque) +{ + AppleGFXIOJob *job =3D opaque; + job->value =3D [job->state->pgdev mmioReadAtOffset:job->offset]; + qatomic_set(&job->completed, true); + aio_wait_kick(); +} + +static uint64_t apple_gfx_read(void *opaque, hwaddr offset, unsigned size) +{ + AppleGFXIOJob job =3D { + .state =3D opaque, + .offset =3D offset, + .completed =3D false, + }; + AioContext *context =3D qemu_get_aio_context(); + dispatch_queue_t queue =3D get_background_queue(); + + dispatch_async_f(queue, &job, apple_gfx_do_read); + AIO_WAIT_WHILE(context, !qatomic_read(&job.completed)); + + trace_apple_gfx_read(offset, job.value); + return job.value; +} + +static void apple_gfx_do_write(void *opaque) +{ + AppleGFXIOJob *job =3D opaque; + [job->state->pgdev mmioWriteAtOffset:job->offset value:job->value]; + qatomic_set(&job->completed, true); + aio_wait_kick(); +} + +static void apple_gfx_write(void *opaque, hwaddr offset, uint64_t val, + unsigned size) +{ + /* The methods mmioReadAtOffset: and especially mmioWriteAtOffset: can + * trigger and block on operations on other dispatch queues, which in = turn + * may call back out on one or more of the callback blocks. For this r= eason, + * and as we are holding the BQL, we invoke the I/O methods on a pool + * thread and handle AIO tasks while we wait. Any work in the callbacks + * requiring the BQL will in turn schedule BHs which this thread will + * process while waiting. */ + AppleGFXIOJob job =3D { + .state =3D opaque, + .offset =3D offset, + .value =3D val, + .completed =3D false, + }; + AioContext *context =3D qemu_get_current_aio_context(); + dispatch_queue_t queue =3D get_background_queue(); + + dispatch_async_f(queue, &job, apple_gfx_do_write); + AIO_WAIT_WHILE(context, !qatomic_read(&job.completed)); + + trace_apple_gfx_write(offset, val); +} + +static const MemoryRegionOps apple_gfx_ops =3D { + .read =3D apple_gfx_read, + .write =3D apple_gfx_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static void apple_gfx_render_new_frame_bql_unlock(AppleGFXState *s) +{ + BOOL r; + uint32_t width =3D surface_width(s->surface); + uint32_t height =3D surface_height(s->surface); + MTLRegion region =3D MTLRegionMake2D(0, 0, width, height); + id command_buffer =3D [s->mtl_queue commandBuffer]; + id texture =3D s->texture; + + assert(bql_locked()); + [texture retain]; + + bql_unlock(); + + /* This is not safe to call from the BQL due to PVG-internal locks cau= sing + * deadlocks. */ + r =3D [s->pgdisp encodeCurrentFrameToCommandBuffer:command_buffer + texture:texture + region:region]; + if (!r) { + [texture release]; + bql_lock(); + --s->pending_frames; + bql_unlock(); + qemu_log_mask(LOG_GUEST_ERROR, "apple_gfx_render_new_frame_bql_unl= ock: " + "encodeCurrentFrameToCommandBuffer:texture:region: f= ailed\n"); + return; + } + + if (s->using_managed_texture_storage) { + /* "Managed" textures exist in both VRAM and RAM and must be synce= d. */ + id blit =3D [command_buffer blitCommandEnco= der]; + [blit synchronizeResource:texture]; + [blit endEncoding]; + } + [texture release]; + [command_buffer addCompletedHandler: + ^(id cb) + { + dispatch_async(s->render_queue, ^{ + apple_gfx_render_frame_completed(s, width, height); + }); + }]; + [command_buffer commit]; +} + +static void copy_mtl_texture_to_surface_mem(id texture, void *= vram) +{ + /* TODO: Skip this entirely on a pure Metal or headless/guest-only + * rendering path, else use a blit command encoder? Needs careful + * (double?) buffering design. */ + size_t width =3D texture.width, height =3D texture.height; + MTLRegion region =3D MTLRegionMake2D(0, 0, width, height); + [texture getBytes:vram + bytesPerRow:(width * 4) + bytesPerImage:(width * height * 4) + fromRegion:region + mipmapLevel:0 + slice:0]; +} + +static void apple_gfx_render_frame_completed(AppleGFXState *s, + uint32_t width, uint32_t heig= ht) +{ + bql_lock(); + --s->pending_frames; + assert(s->pending_frames >=3D 0); + + /* Only update display if mode hasn't changed since we started renderi= ng. */ + if (width =3D=3D surface_width(s->surface) && + height =3D=3D surface_height(s->surface)) { + copy_mtl_texture_to_surface_mem(s->texture, s->vram); + if (s->gfx_update_requested) { + s->gfx_update_requested =3D false; + dpy_gfx_update_full(s->con); + graphic_hw_update_done(s->con); + s->new_frame_ready =3D false; + } else { + s->new_frame_ready =3D true; + } + } + if (s->pending_frames > 0) { + apple_gfx_render_new_frame_bql_unlock(s); + } else { + bql_unlock(); + } +} + +static void apple_gfx_fb_update_display(void *opaque) +{ + AppleGFXState *s =3D opaque; + + assert(bql_locked()); + if (s->new_frame_ready) { + dpy_gfx_update_full(s->con); + s->new_frame_ready =3D false; + graphic_hw_update_done(s->con); + } else if (s->pending_frames > 0) { + s->gfx_update_requested =3D true; + } else { + graphic_hw_update_done(s->con); + } +} + +static const GraphicHwOps apple_gfx_fb_ops =3D { + .gfx_update =3D apple_gfx_fb_update_display, + .gfx_update_async =3D true, +}; + +static void update_cursor(AppleGFXState *s) +{ + assert(bql_locked()); + dpy_mouse_set(s->con, s->pgdisp.cursorPosition.x, + s->pgdisp.cursorPosition.y, s->cursor_show); +} + +static void set_mode(AppleGFXState *s, uint32_t width, uint32_t height) +{ + MTLTextureDescriptor *textureDescriptor; + + if (s->surface && + width =3D=3D surface_width(s->surface) && + height =3D=3D surface_height(s->surface)) { + return; + } + + g_free(s->vram); + [s->texture release]; + + s->vram =3D g_malloc0_n(width * height, 4); + s->surface =3D qemu_create_displaysurface_from(width, height, PIXMAN_L= E_a8r8g8b8, + width * 4, s->vram); + + @autoreleasepool { + textureDescriptor =3D + [MTLTextureDescriptor + texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm + width:width + height:height + mipmapped:NO]; + textureDescriptor.usage =3D s->pgdisp.minimumTextureUsage; + s->texture =3D [s->mtl newTextureWithDescriptor:textureDescriptor]; + } + + s->using_managed_texture_storage =3D + (s->texture.storageMode =3D=3D MTLStorageModeManaged); + dpy_gfx_replace_surface(s->con, s->surface); +} + +static void create_fb(AppleGFXState *s) +{ + s->con =3D graphic_console_init(NULL, 0, &apple_gfx_fb_ops, s); + set_mode(s, 1440, 1080); + + s->cursor_show =3D true; +} + +static size_t apple_gfx_get_default_mmio_range_size(void) +{ + size_t mmio_range_size; + @autoreleasepool { + PGDeviceDescriptor *desc =3D [PGDeviceDescriptor new]; + mmio_range_size =3D desc.mmioLength; + [desc release]; + } + return mmio_range_size; +} + +void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_= name) +{ + size_t mmio_range_size =3D apple_gfx_get_default_mmio_range_size(); + + trace_apple_gfx_common_init(obj_name, mmio_range_size); + memory_region_init_io(&s->iomem_gfx, obj, &apple_gfx_ops, s, obj_name, + mmio_range_size); + + /* TODO: PVG framework supports serialising device state: integrate it= ! */ +} + +typedef struct AppleGFXMapMemoryJob { + AppleGFXState *state; + PGTask_t *task; + uint64_t virtual_offset; + PGPhysicalMemoryRange_t *ranges; + uint32_t range_count; + bool read_only; + bool success; + bool done; +} AppleGFXMapMemoryJob; + +uintptr_t apple_gfx_host_address_for_gpa_range(uint64_t guest_physical, + uint64_t length, bool read_= only) +{ + MemoryRegion *ram_region; + uintptr_t host_address; + hwaddr ram_region_offset =3D 0; + hwaddr ram_region_length =3D length; + + ram_region =3D address_space_translate(&address_space_memory, + guest_physical, + &ram_region_offset, + &ram_region_length, !read_only, + MEMTXATTRS_UNSPECIFIED); + + if (!ram_region || ram_region_length < length || + !memory_access_is_direct(ram_region, !read_only)) { + return 0; + } + + host_address =3D (mach_vm_address_t)memory_region_get_ram_ptr(ram_regi= on); + if (host_address =3D=3D 0) { + return 0; + } + host_address +=3D ram_region_offset; + + return host_address; +} + +static void apple_gfx_map_memory(void *opaque) +{ + AppleGFXMapMemoryJob *job =3D opaque; + AppleGFXState *s =3D job->state; + PGTask_t *task =3D job->task; + uint32_t range_count =3D job->range_count; + uint64_t virtual_offset =3D job->virtual_offset; + PGPhysicalMemoryRange_t *ranges =3D job->ranges; + bool read_only =3D job->read_only; + kern_return_t r; + mach_vm_address_t target, source; + vm_prot_t cur_protection, max_protection; + bool success =3D true; + + g_assert(bql_locked()); + + trace_apple_gfx_map_memory(task, range_count, virtual_offset, read_onl= y); + for (int i =3D 0; i < range_count; i++) { + PGPhysicalMemoryRange_t *range =3D &ranges[i]; + + target =3D task->address + virtual_offset; + virtual_offset +=3D range->physicalLength; + + trace_apple_gfx_map_memory_range(i, range->physicalAddress, + range->physicalLength); + + source =3D apple_gfx_host_address_for_gpa_range(range->physicalAdd= ress, + range->physicalLengt= h, + read_only); + if (source =3D=3D 0) { + success =3D false; + continue; + } + + MemoryRegion* alt_mr =3D NULL; + mach_vm_address_t alt_source =3D (mach_vm_address_t)gpa2hva(&alt_m= r, range->physicalAddress, range->physicalLength, NULL); + g_assert(alt_source =3D=3D source); + + cur_protection =3D 0; + max_protection =3D 0; + // Map guest RAM at range->physicalAddress into PG task memory ran= ge + r =3D mach_vm_remap(mach_task_self(), + &target, range->physicalLength, vm_page_size - 1, + VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE, + mach_task_self(), + source, false /* shared mapping, no copy */, + &cur_protection, &max_protection, + VM_INHERIT_COPY); + trace_apple_gfx_remap(r, source, target); + g_assert(r =3D=3D KERN_SUCCESS); + } + + qemu_mutex_lock(&s->job_mutex); + job->success =3D success; + job->done =3D true; + qemu_cond_broadcast(&s->job_cond); + qemu_mutex_unlock(&s->job_mutex); +} + +void apple_gfx_await_bh_job(AppleGFXState *s, bool *job_done_flag) +{ + qemu_mutex_lock(&s->job_mutex); + while (!*job_done_flag) { + qemu_cond_wait(&s->job_cond, &s->job_mutex); + } + qemu_mutex_unlock(&s->job_mutex); +} + +typedef struct AppleGFXReadMemoryJob { + AppleGFXState *s; + hwaddr physical_address; + uint64_t length; + void *dst; + bool done; +} AppleGFXReadMemoryJob; + +static void apple_gfx_do_read_memory(void *opaque) +{ + AppleGFXReadMemoryJob *job =3D opaque; + AppleGFXState *s =3D job->s; + + cpu_physical_memory_read(job->physical_address, job->dst, job->length); + + qemu_mutex_lock(&s->job_mutex); + job->done =3D true; + qemu_cond_broadcast(&s->job_cond); + qemu_mutex_unlock(&s->job_mutex); +} + +static void apple_gfx_read_memory(AppleGFXState *s, hwaddr physical_addres= s, + uint64_t length, void *dst) +{ + AppleGFXReadMemoryJob job =3D { + s, physical_address, length, dst + }; + + trace_apple_gfx_read_memory(physical_address, length, dst); + + /* Traversing the memory map requires RCU/BQL, so do it in a BH. */ + aio_bh_schedule_oneshot(qemu_get_aio_context(), apple_gfx_do_read_memo= ry, + &job); + apple_gfx_await_bh_job(s, &job.done); +} + +static void apple_gfx_register_task_mapping_handlers(AppleGFXState *s, + PGDeviceDescriptor *d= esc) +{ + desc.createTask =3D ^(uint64_t vmSize, void * _Nullable * _Nonnull bas= eAddress) { + PGTask_t *task =3D apple_gfx_new_task(s, vmSize); + *baseAddress =3D (void *)task->address; + trace_apple_gfx_create_task(vmSize, *baseAddress); + return task; + }; + + desc.destroyTask =3D ^(PGTask_t * _Nonnull task) { + trace_apple_gfx_destroy_task(task); + QTAILQ_REMOVE(&s->tasks, task, node); + mach_vm_deallocate(mach_task_self(), task->address, task->len); + g_free(task); + }; + + desc.mapMemory =3D ^bool(PGTask_t * _Nonnull task, uint32_t range_coun= t, + uint64_t virtual_offset, bool read_only, + PGPhysicalMemoryRange_t * _Nonnull ranges) { + AppleGFXMapMemoryJob job =3D { + .state =3D s, + .task =3D task, .ranges =3D ranges, .range_count =3D range_cou= nt, + .read_only =3D read_only, .virtual_offset =3D virtual_offset, + .done =3D false, .success =3D true, + }; + if (range_count > 0) { + aio_bh_schedule_oneshot(qemu_get_aio_context(), + apple_gfx_map_memory, &job); + apple_gfx_await_bh_job(s, &job.done); + } + return job.success; + }; + + desc.unmapMemory =3D ^bool(PGTask_t * _Nonnull task, uint64_t virtualO= ffset, + uint64_t length) { + kern_return_t r; + mach_vm_address_t range_address; + + trace_apple_gfx_unmap_memory(task, virtualOffset, length); + + /* Replace task memory range with fresh pages, undoing the mapping + * from guest RAM. */ + range_address =3D task->address + virtualOffset; + r =3D mach_vm_allocate(mach_task_self(), &range_address, length, + VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE); + g_assert(r =3D=3D KERN_SUCCESS); + + return true; + }; + + desc.readMemory =3D ^bool(uint64_t physical_address, uint64_t length, + void * _Nonnull dst) { + apple_gfx_read_memory(s, physical_address, length, dst); + return true; + }; +} + +static PGDisplayDescriptor *apple_gfx_prepare_display_descriptor(AppleGFXS= tate *s) +{ + PGDisplayDescriptor *disp_desc =3D [PGDisplayDescriptor new]; + + disp_desc.name =3D @"QEMU display"; + disp_desc.sizeInMillimeters =3D NSMakeSize(400., 300.); /* A 20" displ= ay */ + disp_desc.queue =3D dispatch_get_main_queue(); + disp_desc.newFrameEventHandler =3D ^(void) { + trace_apple_gfx_new_frame(); + dispatch_async(s->render_queue, ^{ + /* Drop frames if we get too far ahead. */ + bql_lock(); + if (s->pending_frames >=3D 2) { + bql_unlock(); + return; + } + ++s->pending_frames; + if (s->pending_frames > 1) { + bql_unlock(); + return; + } + @autoreleasepool { + apple_gfx_render_new_frame_bql_unlock(s); + } + }); + }; + disp_desc.modeChangeHandler =3D ^(PGDisplayCoord_t sizeInPixels, + OSType pixelFormat) { + trace_apple_gfx_mode_change(sizeInPixels.x, sizeInPixels.y); + + BQL_LOCK_GUARD(); + set_mode(s, sizeInPixels.x, sizeInPixels.y); + }; + disp_desc.cursorGlyphHandler =3D ^(NSBitmapImageRep *glyph, + PGDisplayCoord_t hotSpot) { + [glyph retain]; + dispatch_async(get_background_queue(), ^{ + BQL_LOCK_GUARD(); + uint32_t bpp =3D glyph.bitsPerPixel; + size_t width =3D glyph.pixelsWide; + size_t height =3D glyph.pixelsHigh; + size_t padding_bytes_per_row =3D glyph.bytesPerRow - width * 4; + const uint8_t* px_data =3D glyph.bitmapData; + + trace_apple_gfx_cursor_set(bpp, width, height); + + if (s->cursor) { + cursor_unref(s->cursor); + s->cursor =3D NULL; + } + + if (bpp =3D=3D 32) { /* Shouldn't be anything else, but just t= o be safe...*/ + s->cursor =3D cursor_alloc(width, height); + s->cursor->hot_x =3D hotSpot.x; + s->cursor->hot_y =3D hotSpot.y; + + uint32_t *dest_px =3D s->cursor->data; + + for (size_t y =3D 0; y < height; ++y) { + for (size_t x =3D 0; x < width; ++x) { + /* NSBitmapImageRep's red & blue channels are swap= ped + * compared to QEMUCursor's. */ + *dest_px =3D + (px_data[0] << 16u) | + (px_data[1] << 8u) | + (px_data[2] << 0u) | + (px_data[3] << 24u); + ++dest_px; + px_data +=3D 4; + } + px_data +=3D padding_bytes_per_row; + } + dpy_cursor_define(s->con, s->cursor); + update_cursor(s); + } + [glyph release]; + }); + }; + disp_desc.cursorShowHandler =3D ^(BOOL show) { + dispatch_async(get_background_queue(), ^{ + BQL_LOCK_GUARD(); + trace_apple_gfx_cursor_show(show); + s->cursor_show =3D show; + update_cursor(s); + }); + }; + disp_desc.cursorMoveHandler =3D ^(void) { + dispatch_async(get_background_queue(), ^{ + BQL_LOCK_GUARD(); + trace_apple_gfx_cursor_move(); + update_cursor(s); + }); + }; + + return disp_desc; +} + +static NSArray* apple_gfx_prepare_display_mode_array(void) +{ + PGDisplayMode *modes[ARRAY_SIZE(apple_gfx_modes)]; + NSArray* mode_array =3D nil; + int i; + + for (i =3D 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { + modes[i] =3D + [[PGDisplayMode alloc] initWithSizeInPixels:apple_gfx_modes[i]= refreshRateInHz:60.]; + } + + mode_array =3D [NSArray arrayWithObjects:modes count:ARRAY_SIZE(apple_= gfx_modes)]; + + for (i =3D 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { + [modes[i] release]; + modes[i] =3D nil; + } + + return mode_array; +} + +static id copy_suitable_metal_device(void) +{ + id dev =3D nil; + NSArray> *devs =3D MTLCopyAllDevices(); + + /* Prefer a unified memory GPU. Failing that, pick a non-removable GPU= . */ + for (size_t i =3D 0; i < devs.count; ++i) { + if (devs[i].hasUnifiedMemory) { + dev =3D devs[i]; + break; + } + if (!devs[i].removable) { + dev =3D devs[i]; + } + } + + if (dev !=3D nil) { + [dev retain]; + } else { + dev =3D MTLCreateSystemDefaultDevice(); + } + [devs release]; + + return dev; +} + +void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc, + Error **errp) +{ + PGDisplayDescriptor *disp_desc =3D nil; + + if (apple_gfx_mig_blocker =3D=3D NULL) { + error_setg(&apple_gfx_mig_blocker, + "Migration state blocked by apple-gfx display device"); + if (migrate_add_blocker(&apple_gfx_mig_blocker, errp) < 0) { + return; + } + } + + QTAILQ_INIT(&s->tasks); + s->render_queue =3D dispatch_queue_create("apple-gfx.render", + DISPATCH_QUEUE_SERIAL); + s->mtl =3D copy_suitable_metal_device(); + s->mtl_queue =3D [s->mtl newCommandQueue]; + + desc.device =3D s->mtl; + + apple_gfx_register_task_mapping_handlers(s, desc); + + s->pgdev =3D PGNewDeviceWithDescriptor(desc); + + disp_desc =3D apple_gfx_prepare_display_descriptor(s); + s->pgdisp =3D [s->pgdev newDisplayWithDescriptor:disp_desc + port:0 serialNum:1234]; + [disp_desc release]; + s->pgdisp.modeList =3D apple_gfx_prepare_display_mode_array(); + + create_fb(s); + + qemu_mutex_init(&s->job_mutex); + qemu_cond_init(&s->job_cond); +} diff --git a/hw/display/meson.build b/hw/display/meson.build index 20a94973fa2..619e642905a 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -61,6 +61,10 @@ system_ss.add(when: 'CONFIG_ARTIST', if_true: files('art= ist.c')) =20 system_ss.add(when: 'CONFIG_ATI_VGA', if_true: [files('ati.c', 'ati_2d.c',= 'ati_dbg.c'), pixman]) =20 +system_ss.add(when: 'CONFIG_MAC_PVG', if_true: [files('apple-gfx.m= '), pvg, metal]) +if cpu =3D=3D 'aarch64' + system_ss.add(when: 'CONFIG_MAC_PVG_MMIO', if_true: [files('apple-gfx-m= mio.m'), pvg, metal]) +endif =20 if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss =3D ss.source_set() diff --git a/hw/display/trace-events b/hw/display/trace-events index 781f8a33203..214998312b9 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -191,3 +191,29 @@ dm163_bits_ppi(unsigned dest_width) "dest_width : %u" dm163_leds(int led, uint32_t value) "led %d: 0x%x" dm163_channels(int channel, uint8_t value) "channel %d: 0x%x" dm163_refresh_rate(uint32_t rr) "refresh rate %d" + +# apple-gfx.m +apple_gfx_read(uint64_t offset, uint64_t res) "offset=3D0x%"PRIx64" res=3D= 0x%"PRIx64 +apple_gfx_write(uint64_t offset, uint64_t val) "offset=3D0x%"PRIx64" val= =3D0x%"PRIx64 +apple_gfx_create_task(uint32_t vm_size, void *va) "vm_size=3D0x%x base_add= r=3D%p" +apple_gfx_destroy_task(void *task) "task=3D%p" +apple_gfx_map_memory(void *task, uint32_t range_count, uint64_t virtual_of= fset, uint32_t read_only) "task=3D%p range_count=3D0x%x virtual_offset=3D0x= %"PRIx64" read_only=3D%d" +apple_gfx_map_memory_range(uint32_t i, uint64_t phys_addr, uint64_t phys_l= en) "[%d] phys_addr=3D0x%"PRIx64" phys_len=3D0x%"PRIx64 +apple_gfx_remap(uint64_t retval, uint64_t source, uint64_t target) "retval= =3D%"PRId64" source=3D0x%"PRIx64" target=3D0x%"PRIx64 +apple_gfx_unmap_memory(void *task, uint64_t virtual_offset, uint64_t lengt= h) "task=3D%p virtual_offset=3D0x%"PRIx64" length=3D0x%"PRIx64 +apple_gfx_read_memory(uint64_t phys_address, uint64_t length, void *dst) "= phys_addr=3D0x%"PRIx64" length=3D0x%"PRIx64" dest=3D%p" +apple_gfx_raise_irq(uint32_t vector) "vector=3D0x%x" +apple_gfx_new_frame(void) "" +apple_gfx_mode_change(uint64_t x, uint64_t y) "x=3D%"PRId64" y=3D%"PRId64 +apple_gfx_cursor_set(uint32_t bpp, uint64_t width, uint64_t height) "bpp= =3D%d width=3D%"PRId64" height=3D0x%"PRId64 +apple_gfx_cursor_show(uint32_t show) "show=3D%d" +apple_gfx_cursor_move(void) "" +apple_gfx_common_init(const char *device_name, size_t mmio_size) "device: = %s; MMIO size: %zu bytes" + +# apple-gfx-mmio.m +apple_gfx_mmio_iosfc_read(uint64_t offset, uint64_t res) "offset=3D0x%"PRI= x64" res=3D0x%"PRIx64 +apple_gfx_mmio_iosfc_write(uint64_t offset, uint64_t val) "offset=3D0x%"PR= Ix64" val=3D0x%"PRIx64 +apple_gfx_iosfc_map_memory(uint64_t phys, uint64_t len, uint32_t ro, void = *va, void *e, void *f, void* va_result, int success) "phys=3D0x%"PRIx64" le= n=3D0x%"PRIx64" ro=3D%d va=3D%p e=3D%p f=3D%p -> *va=3D%p, success =3D %d" +apple_gfx_iosfc_unmap_memory(void *a, void *b, void *c, void *d, void *e, = void *f) "a=3D%p b=3D%p c=3D%p d=3D%p e=3D%p f=3D%p" +apple_gfx_iosfc_raise_irq(uint32_t vector) "vector=3D0x%x" + diff --git a/meson.build b/meson.build index d26690ce204..0e124eff13f 100644 --- a/meson.build +++ b/meson.build @@ -761,6 +761,8 @@ socket =3D [] version_res =3D [] coref =3D [] iokit =3D [] +pvg =3D [] +metal =3D [] emulator_link_args =3D [] midl =3D not_found widl =3D not_found @@ -782,6 +784,8 @@ elif host_os =3D=3D 'darwin' coref =3D dependency('appleframeworks', modules: 'CoreFoundation') iokit =3D dependency('appleframeworks', modules: 'IOKit', required: fals= e) host_dsosuf =3D '.dylib' + pvg =3D dependency('appleframeworks', modules: 'ParavirtualizedGraphics') + metal =3D dependency('appleframeworks', modules: 'Metal') elif host_os =3D=3D 'sunos' socket =3D [cc.find_library('socket'), cc.find_library('nsl'), --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729766002; cv=none; d=zohomail.com; s=zohoarc; b=Uit+BHH5M93lv58b3GQ1+0H/zSO8qWBYf8FQoI0aaoCGJ30jdMXHNwk9b7X9soH1HVWaC/QdTZ/8CZc/gIs27TC2QjaYlx6+nWag09Nqq31pEb2KiMdo63njfW25G3jQYzBTZlu7CdXleXXnAXoW9P4maKW/Wek17VKY3EmMZy4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729766002; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rP0D2cZrDnPuW6xhPjmdVsND3O4YQtS5+Pte7yJoqqw=; b=DeOipi+m5VkzC/0xF36CdiR7lwckQuktyBd1C3ywiC/94D9WAHMdCSZnIfxDzHuUJqKCswd2+w2iayp8Id0b+3VUdX2ZIqOvSDrobDVEDAp70J18jnFcnaa/eWJtyHlyw5dmorwcmoEQkuNlbnFKpx6UKxEYmjwzMNA57CavpmM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729766002935673.2888156589893; Thu, 24 Oct 2024 03:33:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v56-0000p7-H5; Thu, 24 Oct 2024 06:28:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v54-0000nk-G1 for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:38 -0400 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v4w-00089O-VP for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:38 -0400 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a9a6acac4c3so104725266b.0 for ; Thu, 24 Oct 2024 03:28:30 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765709; x=1730370509; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rP0D2cZrDnPuW6xhPjmdVsND3O4YQtS5+Pte7yJoqqw=; b=ooQiMfBJYyFz4aDKE3cjGSnK9jDEYQsIbxBAI98x5uh3yK9GsxDNZcfGt9hrEAltL4 qxX5VVYRC1wZ9CeOlnD0noECg/EgpenRIzWoIcJ6RP9yir3IABfKBTGC8FpXgg4eq6La +iQaJ7sq5uVunJdhxixsBgPywgUX5P/Vp/NBqEnY1UUWNXoFNpZXEb95mnqXMFCSr3PT 7Eq5psCDRa0p0TNEQViUOl4oEVwxtimoJdyvLcbUeEgxK1suZHFl7gGi0KAF1/QzToT6 9s8/ttzQY2YdIUWsrsKoUkTj/KWoPkQXLjeDHMbsJKEpoQjGfmiXq7HS/pKp1GlVCnsx YcMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765709; x=1730370509; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rP0D2cZrDnPuW6xhPjmdVsND3O4YQtS5+Pte7yJoqqw=; b=oWXWEFkze6jCdLCVsBmjh8RiYF2AQydm8kaiEMB8dZrfGkEoEtvkm19PRZdBGhJwcm OPXrn1bwt93AAcmNcYIokEcZfOUN67hpUPfgpmJgSH0jZF6S2PfxxSDA0waTYz/AuAJZ 1I52MabGaT4MsGG0s3dRv/1pYagI794zAXQoY48qbukwr0cdI2Z1NnACIb41y5TcS2Fi d7F86B/MIsXRH5PmrK2tHzZImQFWbtsrkUOsjGlUKLaRy09FqcJJ9DamkcSm3BbTgsqL b8iJI/NB553jVk6bPhcSgWD+QoUTS2mq4xRA6lmoQodJE55fVYcnAcmeLEueILn+ysC9 VSpQ== X-Gm-Message-State: AOJu0YwNUKvRHLySBoEekQTeq7XWJcYGDzX3QgpiTxRC4a25fkOcx4QZ E3HaArtALshCZU6uOnaF6xFiV3oGik9PvJzdsqE/JnwascqE6ffT7FCVUVOQsnEHtjFG43+pbEU 8hQ== X-Google-Smtp-Source: AGHT+IF1uPacvKVgzyNaUMYzJRagxS/AwkFequCZAZd6h8apV/QxBYOicL4KCFdXyoaDqUQ90Q+XfQ== X-Received: by 2002:a17:906:7956:b0:a9a:8028:45d8 with SMTP id a640c23a62f3a-a9ad2711860mr127618266b.7.1729765709495; Thu, 24 Oct 2024 03:28:29 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v4 03/15] hw/display/apple-gfx: Adds PCI implementation Date: Thu, 24 Oct 2024 12:28:01 +0200 Message-Id: <20241024102813.9855-4-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::631; envelope-from=phil@philjordan.eu; helo=mail-ej1-x631.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729766004166116600 This change wires up the PCI variant of the paravirtualised graphics device, mainly useful for x86-64 macOS guests, implemented by macOS's ParavirtualizedGraphics.framework. It builds on code shared with the vmapple/mmio variant of the PVG device. Signed-off-by: Phil Dennis-Jordan --- v4: * Threading improvements analogous to those in common apple-gfx code and mmio device variant. * Smaller code review issues addressed. hw/display/Kconfig | 4 + hw/display/apple-gfx-pci.m | 152 +++++++++++++++++++++++++++++++++++++ hw/display/meson.build | 1 + 3 files changed, 157 insertions(+) create mode 100644 hw/display/apple-gfx-pci.m diff --git a/hw/display/Kconfig b/hw/display/Kconfig index 6a9b7b19ada..2b53dfd7d26 100644 --- a/hw/display/Kconfig +++ b/hw/display/Kconfig @@ -149,3 +149,7 @@ config MAC_PVG_MMIO bool depends on MAC_PVG && AARCH64 =20 +config MAC_PVG_PCI + bool + depends on MAC_PVG && PCI + default y if PCI_DEVICES diff --git a/hw/display/apple-gfx-pci.m b/hw/display/apple-gfx-pci.m new file mode 100644 index 00000000000..4ee26dde422 --- /dev/null +++ b/hw/display/apple-gfx-pci.m @@ -0,0 +1,152 @@ +/* + * QEMU Apple ParavirtualizedGraphics.framework device, PCI variant + * + * Copyright =C2=A9 2023-2024 Phil Dennis-Jordan + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * ParavirtualizedGraphics.framework is a set of libraries that macOS prov= ides + * which implements 3d graphics passthrough to the host as well as a + * proprietary guest communication channel to drive it. This device model + * implements support to drive that library from within QEMU as a PCI devi= ce + * aimed primarily at x86-64 macOS VMs. + */ + +#include "apple-gfx.h" +#include "hw/pci/pci_device.h" +#include "hw/pci/msi.h" +#include "qapi/error.h" +#include "trace.h" +#import + +OBJECT_DECLARE_SIMPLE_TYPE(AppleGFXPCIState, APPLE_GFX_PCI) + +struct AppleGFXPCIState { + PCIDevice parent_obj; + + AppleGFXState common; +}; + +static const char* apple_gfx_pci_option_rom_path =3D NULL; + +static void apple_gfx_init_option_rom_path(void) +{ + NSURL *option_rom_url =3D PGCopyOptionROMURL(); + const char *option_rom_path =3D option_rom_url.fileSystemRepresentatio= n; + apple_gfx_pci_option_rom_path =3D g_strdup(option_rom_path); + [option_rom_url release]; +} + +static void apple_gfx_pci_init(Object *obj) +{ + AppleGFXPCIState *s =3D APPLE_GFX_PCI(obj); + + if (!apple_gfx_pci_option_rom_path) { + /* The following is done on device not class init to avoid running + * ObjC code before fork() in -daemonize mode. */ + PCIDeviceClass *pci =3D PCI_DEVICE_CLASS(object_get_class(obj)); + apple_gfx_init_option_rom_path(); + pci->romfile =3D apple_gfx_pci_option_rom_path; + } + + apple_gfx_common_init(obj, &s->common, TYPE_APPLE_GFX_PCI); +} + +typedef struct AppleGFXPCIInterruptJob { + PCIDevice *device; + uint32_t vector; +} AppleGFXPCIInterruptJob; + +static void apple_gfx_pci_raise_interrupt(void *opaque) +{ + AppleGFXPCIInterruptJob *job =3D opaque; + + if (msi_enabled(job->device)) { + msi_notify(job->device, job->vector); + } + g_free(job); +} + +static void apple_gfx_pci_interrupt(PCIDevice *dev, AppleGFXPCIState *s, + uint32_t vector) +{ + AppleGFXPCIInterruptJob *job; + + trace_apple_gfx_raise_irq(vector); + job =3D g_malloc0(sizeof(*job)); + job->device =3D dev; + job->vector =3D vector; + aio_bh_schedule_oneshot(qemu_get_aio_context(), + apple_gfx_pci_raise_interrupt, job); +} + +static void apple_gfx_pci_realize(PCIDevice *dev, Error **errp) +{ + AppleGFXPCIState *s =3D APPLE_GFX_PCI(dev); + Error *err =3D NULL; + int ret; + + pci_register_bar(dev, PG_PCI_BAR_MMIO, + PCI_BASE_ADDRESS_SPACE_MEMORY, &s->common.iomem_gfx); + + ret =3D msi_init(dev, 0x0 /* config offset; 0 =3D find space */, + PG_PCI_MAX_MSI_VECTORS, true /* msi64bit */, + false /*msi_per_vector_mask*/, &err); + if (ret !=3D 0) { + error_propagate(errp, err); + return; + } + + @autoreleasepool { + PGDeviceDescriptor *desc =3D [PGDeviceDescriptor new]; + desc.raiseInterrupt =3D ^(uint32_t vector) { + apple_gfx_pci_interrupt(dev, s, vector); + }; + + apple_gfx_common_realize(&s->common, desc, errp); + [desc release]; + desc =3D nil; + } +} + +static void apple_gfx_pci_reset(Object *obj, ResetType type) +{ + AppleGFXPCIState *s =3D APPLE_GFX_PCI(obj); + [s->common.pgdev reset]; +} + +static void apple_gfx_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + PCIDeviceClass *pci =3D PCI_DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + assert(rc->phases.hold =3D=3D NULL); + rc->phases.hold =3D apple_gfx_pci_reset; + dc->desc =3D "macOS Paravirtualized Graphics PCI Display Controller"; + dc->hotpluggable =3D false; + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); + + pci->vendor_id =3D PG_PCI_VENDOR_ID; + pci->device_id =3D PG_PCI_DEVICE_ID; + pci->class_id =3D PCI_CLASS_DISPLAY_OTHER; + pci->realize =3D apple_gfx_pci_realize; + + // TODO: Property for setting mode list +} + +static TypeInfo apple_gfx_pci_types[] =3D { + { + .name =3D TYPE_APPLE_GFX_PCI, + .parent =3D TYPE_PCI_DEVICE, + .instance_size =3D sizeof(AppleGFXPCIState), + .class_init =3D apple_gfx_pci_class_init, + .instance_init =3D apple_gfx_pci_init, + .interfaces =3D (InterfaceInfo[]) { + { INTERFACE_PCIE_DEVICE }, + { }, + }, + } +}; +DEFINE_TYPES(apple_gfx_pci_types) + diff --git a/hw/display/meson.build b/hw/display/meson.build index 619e642905a..78e1c41ea0a 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -65,6 +65,7 @@ system_ss.add(when: 'CONFIG_MAC_PVG', if_true: [f= iles('apple-gfx.m'), pv if cpu =3D=3D 'aarch64' system_ss.add(when: 'CONFIG_MAC_PVG_MMIO', if_true: [files('apple-gfx-m= mio.m'), pvg, metal]) endif +system_ss.add(when: 'CONFIG_MAC_PVG_PCI', if_true: [files('apple-gfx-p= ci.m'), pvg, metal]) =20 if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss =3D ss.source_set() --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729765976; cv=none; d=zohomail.com; s=zohoarc; b=HQ53DWMsXT/a3ZwM+eMM1peliLYMlaXcc8JgGn7bu9QyzNYY8nUSBqyH5OUIwG+GTSL/8Zl8NvK1OJG9U89Ww24LW8XVTAUmZZgVPZUR01BRNKemk6AmUXwd2uHewpPU0Q3e8hhIwgzb+2O2JGk8XAUtRwXRlfIAGJSWqv7S/lQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729765976; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IeeiN2yn/TS4rJUlED7bKC2li59eUCEaUtMqhMT8sOo=; b=i/a7yTpJTFAdk4kDojQDBnA3EfG2VZ1uIcHbEOE1aBX9tTSkb28vg+YxzeIr/NqoUvhth4aE8LBmcUPYTBxsNJ0SvilxHx7k62z7nalsdhEdXVgZ8tnbvqNeXUEG87sD09UrDlOa/zdkxOCOmldQdvzDSDv+h8uB3znVUnQa8d8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172976597696432.68718658330852; Thu, 24 Oct 2024 03:32:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5A-0000tP-W2; Thu, 24 Oct 2024 06:28:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v57-0000pq-Fd for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:41 -0400 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v51-0008Ad-8X for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:41 -0400 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-539f7606199so942413e87.0 for ; Thu, 24 Oct 2024 03:28:34 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765713; x=1730370513; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IeeiN2yn/TS4rJUlED7bKC2li59eUCEaUtMqhMT8sOo=; b=QZfm7Tj8AcwHXggf5Z/mcyGAACm4ZOlUe2YUKQhM77EUf3A3Ox5CPfohWKR7yFRsvA CH08lATlQRzZDNoBzMCUcs8R+Ju++6wpoY7nXyOZmIHD3//yABPfoO5/xteMDlUvH30x ZlAfWcOvRlCYHJWJNI5zaDDpM8YjrJQws39jyM13S/3fthAUCXpVnGifMqKDvd9K1QBL d1BBMeSpOW1olkuNHKbJdwT6kux0/EEeUSF5yoh82kewOa7DUQYwONhNDc1v/ucXQX+m acRlzT4OuCZXrgk9B/1sBrH2JoCkbsyLN1mAltObKPEU8Lgc4PNbJr5XDU6k/U/PX0vw Beaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765713; x=1730370513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IeeiN2yn/TS4rJUlED7bKC2li59eUCEaUtMqhMT8sOo=; b=SxjvqJ7VrazK/Ntaoeo9SXKs5S4nU4Szg+865stPkBqCJtAEq1wQg8boZNtJGdl89N QuBZMOxBNayXbH2ACdIFxXEyx2YsTp08NvB39ccaTOFZCVSgiFmid2h7E63CCQ8Wkavk jQPr2UPqS73OqBTBN98NpMJbGED8fkkZDarcGink4UKdEJ9eSfDPSyf/X2QBJmFQjGN5 8sE+W1Z1kH4K3+xx1AKKWyyAwu1sfvbOPZoClcC+6SiSoI1E7DFXA4DqN2UEgVisrINY wdsmpkXipP3izPE2+XnbF8IjtufJZonqQt43DS44+feT8AI7O0tA52ldlGt85R+bnU3h pAFg== X-Gm-Message-State: AOJu0YyEVS3F4XcW/3yiPCtJYVoDTtHywVhA5msUXSOSUx/+h1hrmO9i Etaxgqy0rDCfcYz9S7iko/zkPaRQQ1Z/TNfu1pVQxbbVO4XE0fXPin/Ny6+ImZ2aQka9tJEvMFc inA== X-Google-Smtp-Source: AGHT+IFxh4yci0JDwmIDjNzFulP0W6W66ohWPCHFfjtnBs6L+lHNzJAKEi1Cxydt0p1hQZe54xqXWA== X-Received: by 2002:a05:6512:398a:b0:539:f2f6:c70f with SMTP id 2adb3069b0e04-53b1a2fed80mr2917958e87.8.1729765712713; Thu, 24 Oct 2024 03:28:32 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v4 04/15] hw/display/apple-gfx: Adds configurable mode list Date: Thu, 24 Oct 2024 12:28:02 +0200 Message-Id: <20241024102813.9855-5-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::131; envelope-from=phil@philjordan.eu; helo=mail-lf1-x131.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729765978275116600 Content-Type: text/plain; charset="utf-8" This change adds a property 'display_modes' on the graphics device which permits specifying a list of display modes. (screen resolution and refresh rate) The property is an array of a custom type to make the syntax slightly less awkward to use, for example: -device '{"driver":"apple-gfx-pci", "display-modes":["1920x1080@60", "3840x= 2160@60"]}' Signed-off-by: Phil Dennis-Jordan --- v4: * Switched to the native array property type, which recently gained command line support. * The property has also been added to the -mmio variant. * Tidied up the code a little. hw/display/apple-gfx-mmio.m | 8 +++ hw/display/apple-gfx-pci.m | 9 ++- hw/display/apple-gfx.h | 12 ++++ hw/display/apple-gfx.m | 127 ++++++++++++++++++++++++++++++++---- hw/display/trace-events | 2 + 5 files changed, 145 insertions(+), 13 deletions(-) diff --git a/hw/display/apple-gfx-mmio.m b/hw/display/apple-gfx-mmio.m index 06131bc23f1..5d427c7005e 100644 --- a/hw/display/apple-gfx-mmio.m +++ b/hw/display/apple-gfx-mmio.m @@ -261,6 +261,12 @@ static void apple_gfx_mmio_reset(Object *obj, ResetTyp= e type) [s->common.pgdev reset]; } =20 +static Property apple_gfx_mmio_properties[] =3D { + DEFINE_PROP_ARRAY("display-modes", AppleGFXMMIOState, + common.num_display_modes, common.display_modes, + qdev_prop_display_mode, AppleGFXDisplayMode), + DEFINE_PROP_END_OF_LIST(), +}; =20 static void apple_gfx_mmio_class_init(ObjectClass *klass, void *data) { @@ -270,6 +276,8 @@ static void apple_gfx_mmio_class_init(ObjectClass *klas= s, void *data) rc->phases.hold =3D apple_gfx_mmio_reset; dc->hotpluggable =3D false; dc->realize =3D apple_gfx_mmio_realize; + + device_class_set_props(dc, apple_gfx_mmio_properties); } =20 static TypeInfo apple_gfx_mmio_types[] =3D { diff --git a/hw/display/apple-gfx-pci.m b/hw/display/apple-gfx-pci.m index 4ee26dde422..32e81bbef8b 100644 --- a/hw/display/apple-gfx-pci.m +++ b/hw/display/apple-gfx-pci.m @@ -115,6 +115,13 @@ static void apple_gfx_pci_reset(Object *obj, ResetType= type) [s->common.pgdev reset]; } =20 +static Property apple_gfx_pci_properties[] =3D { + DEFINE_PROP_ARRAY("display-modes", AppleGFXPCIState, + common.num_display_modes, common.display_modes, + qdev_prop_display_mode, AppleGFXDisplayMode), + DEFINE_PROP_END_OF_LIST(), +}; + static void apple_gfx_pci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -132,7 +139,7 @@ static void apple_gfx_pci_class_init(ObjectClass *klass= , void *data) pci->class_id =3D PCI_CLASS_DISPLAY_OTHER; pci->realize =3D apple_gfx_pci_realize; =20 - // TODO: Property for setting mode list + device_class_set_props(dc, apple_gfx_pci_properties); } =20 static TypeInfo apple_gfx_pci_types[] =3D { diff --git a/hw/display/apple-gfx.h b/hw/display/apple-gfx.h index 39931fba65a..d2c6a14229a 100644 --- a/hw/display/apple-gfx.h +++ b/hw/display/apple-gfx.h @@ -9,6 +9,7 @@ #import #include "qemu/typedefs.h" #include "exec/memory.h" +#include "hw/qdev-properties.h" #include "ui/surface.h" =20 @class PGDeviceDescriptor; @@ -20,6 +21,7 @@ =20 typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; =20 +struct AppleGFXDisplayMode; struct AppleGFXMapMemoryJob; typedef struct AppleGFXState { MemoryRegion iomem_gfx; @@ -31,6 +33,8 @@ typedef struct AppleGFXState { id mtl_queue; bool cursor_show; QEMUCursor *cursor; + struct AppleGFXDisplayMode *display_modes; + uint32_t num_display_modes; =20 /* For running PVG memory-mapping requests in the AIO context */ QemuCond job_cond; @@ -47,6 +51,12 @@ typedef struct AppleGFXState { id texture; } AppleGFXState; =20 +typedef struct AppleGFXDisplayMode { + uint16_t width_px; + uint16_t height_px; + uint16_t refresh_rate_hz; +} AppleGFXDisplayMode; + void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_= name); void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc, Error **errp); @@ -54,5 +64,7 @@ uintptr_t apple_gfx_host_address_for_gpa_range(uint64_t g= uest_physical, uint64_t length, bool read_= only); void apple_gfx_await_bh_job(AppleGFXState *s, bool *job_done_flag); =20 +extern const PropertyInfo qdev_prop_display_mode; + #endif =20 diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m index 46be9957f69..42b601329fb 100644 --- a/hw/display/apple-gfx.m +++ b/hw/display/apple-gfx.m @@ -28,9 +28,10 @@ #include "qapi/error.h" #include "ui/console.h" =20 -static const PGDisplayCoord_t apple_gfx_modes[] =3D { - { .x =3D 1440, .y =3D 1080 }, - { .x =3D 1280, .y =3D 1024 }, +static const AppleGFXDisplayMode apple_gfx_default_modes[] =3D { + { 1920, 1080, 60 }, + { 1440, 1080, 60 }, + { 1280, 1024, 60 }, }; =20 /* This implements a type defined in @@ -303,7 +304,6 @@ static void set_mode(AppleGFXState *s, uint32_t width, = uint32_t height) static void create_fb(AppleGFXState *s) { s->con =3D graphic_console_init(NULL, 0, &apple_gfx_fb_ops, s); - set_mode(s, 1440, 1080); =20 s->cursor_show =3D true; } @@ -628,20 +628,25 @@ static void apple_gfx_register_task_mapping_handlers(= AppleGFXState *s, return disp_desc; } =20 -static NSArray* apple_gfx_prepare_display_mode_array(void) +static NSArray* apple_gfx_create_display_mode_array( + const AppleGFXDisplayMode display_modes[], uint32_t display_mode_count) { - PGDisplayMode *modes[ARRAY_SIZE(apple_gfx_modes)]; + PGDisplayMode **modes =3D alloca(sizeof(modes[0]) * display_mode_count= ); NSArray* mode_array =3D nil; - int i; + uint32_t i; =20 - for (i =3D 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { + for (i =3D 0; i < display_mode_count; i++) { + const AppleGFXDisplayMode *mode =3D &display_modes[i]; + trace_apple_gfx_display_mode(i, mode->width_px, mode->height_px); + PGDisplayCoord_t mode_size =3D { mode->width_px, mode->height_px }; modes[i] =3D - [[PGDisplayMode alloc] initWithSizeInPixels:apple_gfx_modes[i]= refreshRateInHz:60.]; + [[PGDisplayMode alloc] initWithSizeInPixels:mode_size + refreshRateInHz:mode->refresh_rate= _hz]; } =20 - mode_array =3D [NSArray arrayWithObjects:modes count:ARRAY_SIZE(apple_= gfx_modes)]; + mode_array =3D [NSArray arrayWithObjects:modes count:display_mode_coun= t]; =20 - for (i =3D 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { + for (i =3D 0; i < display_mode_count; i++) { [modes[i] release]; modes[i] =3D nil; } @@ -679,6 +684,8 @@ void apple_gfx_common_realize(AppleGFXState *s, PGDevic= eDescriptor *desc, Error **errp) { PGDisplayDescriptor *disp_desc =3D nil; + const AppleGFXDisplayMode *display_modes =3D apple_gfx_default_modes; + int num_display_modes =3D ARRAY_SIZE(apple_gfx_default_modes); =20 if (apple_gfx_mig_blocker =3D=3D NULL) { error_setg(&apple_gfx_mig_blocker, @@ -704,10 +711,106 @@ void apple_gfx_common_realize(AppleGFXState *s, PGDe= viceDescriptor *desc, s->pgdisp =3D [s->pgdev newDisplayWithDescriptor:disp_desc port:0 serialNum:1234]; [disp_desc release]; - s->pgdisp.modeList =3D apple_gfx_prepare_display_mode_array(); + + if (s->display_modes !=3D NULL && s->num_display_modes > 0) { + trace_apple_gfx_common_realize_modes_property(s->num_display_modes= ); + display_modes =3D s->display_modes; + num_display_modes =3D s->num_display_modes; + } + s->pgdisp.modeList =3D + apple_gfx_create_display_mode_array(display_modes, num_display_mod= es); =20 create_fb(s); =20 qemu_mutex_init(&s->job_mutex); qemu_cond_init(&s->job_cond); } + +static void apple_gfx_get_display_mode(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop =3D opaque; + AppleGFXDisplayMode *mode =3D object_field_prop_ptr(obj, prop); + /* 3 uint16s (max 5 digits) and 2 separator characters + nul. */ + static const size_t buffer_size =3D 5 * 3 + 2 + 1; + + char buffer[buffer_size]; + char *pos =3D buffer; + + int rc =3D snprintf(buffer, buffer_size, + "%"PRIu16"x%"PRIu16"@%"PRIu16, + mode->width_px, mode->height_px, + mode->refresh_rate_hz); + assert(rc < buffer_size); + + visit_type_str(v, name, &pos, errp); +} + +static void apple_gfx_set_display_mode(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop =3D opaque; + AppleGFXDisplayMode *mode =3D object_field_prop_ptr(obj, prop); + Error *local_err =3D NULL; + const char *endptr; + char *str; + int ret; + unsigned int val; + + visit_type_str(v, name, &str, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + endptr =3D str; + + ret =3D qemu_strtoui(endptr, &endptr, 10, &val); + if (ret || val > UINT16_MAX || val =3D=3D 0) { + error_setg(errp, "width in '%s' must be a decimal integer number " + "of pixels in the range 1..65535", name); + goto out; + } + mode->width_px =3D val; + if (*endptr !=3D 'x') { + goto separator_error; + } + + ret =3D qemu_strtoui(endptr + 1, &endptr, 10, &val); + if (ret || val > UINT16_MAX || val =3D=3D 0) { + error_setg(errp, "height in '%s' must be a decimal integer number " + "of pixels in the range 1..65535", name); + goto out; + } + mode->height_px =3D val; + if (*endptr !=3D '@') { + goto separator_error; + } + + ret =3D qemu_strtoui(endptr + 1, &endptr, 10, &val); + if (ret) { + error_setg(errp, "refresh rate in '%s'" + " must be a non-negative decimal integer (Hertz)", name= ); + } + mode->refresh_rate_hz =3D val; + + goto out; + +separator_error: + error_setg(errp, "Each display mode takes the format " + "'x@'"); +out: + g_free(str); + return; +} + +const PropertyInfo qdev_prop_display_mode =3D { + .name =3D "display_mode", + .description =3D + "Display mode in pixels and Hertz, as x@ " + "Example: 3840x2160@60", + .get =3D apple_gfx_get_display_mode, + .set =3D apple_gfx_set_display_mode, +}; diff --git a/hw/display/trace-events b/hw/display/trace-events index 214998312b9..2780239dbde 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -209,6 +209,8 @@ apple_gfx_cursor_set(uint32_t bpp, uint64_t width, uint= 64_t height) "bpp=3D%d widt apple_gfx_cursor_show(uint32_t show) "show=3D%d" apple_gfx_cursor_move(void) "" apple_gfx_common_init(const char *device_name, size_t mmio_size) "device: = %s; MMIO size: %zu bytes" +apple_gfx_common_realize_modes_property(uint32_t num_modes) "using %u mode= s supplied by 'display-modes' device property" +apple_gfx_display_mode(uint32_t mode_idx, uint16_t width_px, uint16_t heig= ht_px) "mode %2"PRIu32": %4"PRIu16"x%4"PRIu16 =20 # apple-gfx-mmio.m apple_gfx_mmio_iosfc_read(uint64_t offset, uint64_t res) "offset=3D0x%"PRI= x64" res=3D0x%"PRIx64 --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729765757; cv=none; d=zohomail.com; s=zohoarc; b=JTtyC3opYOdmJB55H46bIiuiiJc4rtQAdeVZAHNzYJdcLYM7a+auNkHJJVNXocEpDksqE3XGkYKPJgW4kAdcAKITTVK8iODiAT7WowdBeuhaPU5oXFGjEyREiQB0DFl9jPM5BXmKAAR1OYSEwmKPyactUoixW4E5vvJSylS/+kg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729765757; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=43Rqa3rSbEjTn7/M1pMockmjAAn+2b2pe334Yd8EcZ0=; b=iUk2zRtijF/rd9Dsc3gxj1DLL5DbBdXXezObJHZ4jt4KF+lkL3Kx9Yx6GXXCMo0EPG9elyJ+cUs0P4IENP+tNdBBlMAK/W2sErqYOCSeRKQWPl0l5BSq6aOSQdAUhkRV18smKH0tMqtHHYVm/qDwYZ9+3XP8vaD7SLjFDY5NKb4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729765757451209.5601872848257; Thu, 24 Oct 2024 03:29:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v59-0000rV-Ud; Thu, 24 Oct 2024 06:28:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v57-0000pd-8B for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:41 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v52-0008B4-3U for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:40 -0400 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a93c1cc74fdso91020166b.3 for ; Thu, 24 Oct 2024 03:28:35 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765715; x=1730370515; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=43Rqa3rSbEjTn7/M1pMockmjAAn+2b2pe334Yd8EcZ0=; b=W0Mqz4T4S4R6tkeOLRFstQLj0Sy5WUh0poDANHG2wWSQqZkV1Z+6wILSCWUTOFY85Y nOpL1EGjoD0Zsbmph9Yqs3L+lqumRuuK9JzaMNG4t4jECUB97XyfTDsZkiWuN11vTVAo fqrMhWmZIycVMWUGR0C2+TP3qphs/uI5ujn81m+AMQi37EnTbKTMNnraUFgVySNt8fds v7SsHPBBvD0MAeybplS4pFBf7LJ3aOOgmsQEv/4xnMeKLSHZa8yBLB2M8AQsH3TKPeFB P2K5T8pX9eY+GrrM0QxQnnDRc5K4zUgFD7Lm7bEDXzUjuEUIz6HA7bQVkR/pB7PP5SHR dvsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765715; x=1730370515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=43Rqa3rSbEjTn7/M1pMockmjAAn+2b2pe334Yd8EcZ0=; b=K+B4zumo7320k5HT6tDCp50KTiTzWewzhnmNGei0MpPu6wYjUygcgLeJbxEciaJpZt 6WpnG0wUuP63KBBe66nER8SaY4AKeCYEMzWAyU4L1/zFKBcUav3pGZdxVKRiskHL9bas A2aarf85yxZVxSqoMKUVIYsw9Fix5OI83DIlV8sPsIlofxUbCvtwuhynpbGywwBA5WCi O9tFJwLgBi9kCoJsoEsAtUIQ7DA4sfAlTkL9wMwNWinvMydGENvvCbuIEGzxxyNRCaJQ gE9eDkDYH8KYL4ugYkkvPU+APp/uffLu8UD3Y+XqmY4gevmW2SJ/zeGYaalSzlfGK1+7 MiYg== X-Gm-Message-State: AOJu0Yw5MqY7vzzU12ABDfvfp2Lc2e2NXaj/TgF8OyfgVogf2uft5X39 KcyyWve2hkNmJ5fk1dP1X5ERnPhhn7f7JWtX2JYUO52Ip0gP96qh1xl15GQQWFyh2YgT2c3f3CW oHw== X-Google-Smtp-Source: AGHT+IEpYl4Q/8H3+GW9gpPBXgzVnIWs1IvZEfEOnk8FJgaWRP+LahGIuJT7uhMHwtwmXMFE6w9Yyg== X-Received: by 2002:a17:907:7216:b0:a99:3318:e7c3 with SMTP id a640c23a62f3a-a9abf94de69mr532170966b.43.1729765714570; Thu, 24 Oct 2024 03:28:34 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v4 05/15] MAINTAINERS: Add myself as maintainer for apple-gfx, reviewer for HVF Date: Thu, 24 Oct 2024 12:28:03 +0200 Message-Id: <20241024102813.9855-6-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::636; envelope-from=phil@philjordan.eu; helo=mail-ej1-x636.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729765760560116600 I'm happy to take responsibility for the macOS PV graphics code. As HVF patches don't seem to get much attention at the moment, I'm also adding myself as designated reviewer for HVF and x86 HVF to try and improve that. I anticipate that the resulting workload should be covered by the funding I'm receiving for improving Qemu in combination with macOS. As of right now this runs out at the end of 2024; I expect the workload on apple-gfx should be relatively minor and manageable in my spare time beyond that. I may have to remove myself from more general HVF duties once the contract runs out if it's more than I can manage. Signed-off-by: Phil Dennis-Jordan Reviewed-by: Roman Bolshakov --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index c3bfa132fd6..16ea47a5e6d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -505,6 +505,7 @@ F: target/arm/hvf/ X86 HVF CPUs M: Cameron Esfahani M: Roman Bolshakov +R: Phil Dennis-Jordan W: https://wiki.qemu.org/Features/HVF S: Maintained F: target/i386/hvf/ @@ -512,6 +513,7 @@ F: target/i386/hvf/ HVF M: Cameron Esfahani M: Roman Bolshakov +R: Phil Dennis-Jordan W: https://wiki.qemu.org/Features/HVF S: Maintained F: accel/hvf/ @@ -2580,6 +2582,11 @@ F: hw/display/edid* F: include/hw/display/edid.h F: qemu-edid.c =20 +macOS PV Graphics (apple-gfx) +M: Phil Dennis-Jordan +S: Maintained +F: hw/display/apple-gfx* + PIIX4 South Bridge (i82371AB) M: Herv=C3=A9 Poussineau M: Philippe Mathieu-Daud=C3=A9 --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729765782; cv=none; d=zohomail.com; s=zohoarc; b=kpI0Y4JL/WC/k6SiMDkTtFuPHVxkVXMAs3aFlcqTEWL8XAz9aO0SKHPa1OLMPCDCjvUEiVvWx70ugAGuZBtJTn2c7kvLLJWrP4wtsEZjlmd2zk5i7JJmPrlDsPffaCaJqPUJINMNm7VhVUdFuc/EEysCUxUOMLaYfrschLLgQHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729765782; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LJg2jLf8wSXvkoyvWjUaBSgx6aYJG6tUf7XK38zkYt0=; b=n1dyUNZzR9ScK/CtOpYkXFOYYvYVnCa2rS4t6IL3ym0GKThoLyxmyXpEDvJrqEV6/63LB84bTxdVjX9QR3iIdOCMfNuqajOG9iWhzJyeS08fqEQ3hWXUyiWFQISRHP2FSQjL/OSWu3yoSFjNBHf5wmoyVvJEB8qLIIbAYB0Rt2k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729765782227783.2661501709606; Thu, 24 Oct 2024 03:29:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5B-0000tU-33; Thu, 24 Oct 2024 06:28:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v58-0000qx-OM for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:42 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v53-0008Bw-Td for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:42 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a9a850270e2so116221666b.0 for ; Thu, 24 Oct 2024 03:28:37 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765716; x=1730370516; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LJg2jLf8wSXvkoyvWjUaBSgx6aYJG6tUf7XK38zkYt0=; b=phFtpTXE99JNtaCDU1EevdoRUg+f+s8JiwmMbQxbx2a/RFQAv1zdCmM/9ASxgiGYwg JOX4HUIT8oiulyTS9y/w60RsI+y96d+xoPzDH5E9u7/Z6w4n78Z7/BLWXbbtDnxBi7n9 FmLKBQYCPdSVGJQUytV2vMKD4Sl2d098Nak4Hp/UCw5LoRtOjc1u1c5y5GGsu8nR5CEc UYe76BPONExMQxSybGTUqs2See8bNGvC2Xhx2/j61NI5g3xyO+FHI9OwTtwGV0bHS3Py XWzpJZTq9kKEFTH0kp92JzZW9ykgLEXbrVJkPXV3IaP50Ap/JO5ChHUPfuZ1YI/04gA7 zXdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765716; x=1730370516; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LJg2jLf8wSXvkoyvWjUaBSgx6aYJG6tUf7XK38zkYt0=; b=WvWlSN5eTtM6zTv/NVtPPAmWfKw1LjbyRpGn5SezQaMXTodsQFQXZSpKNN4bFju8T1 wzpnw1LLoeA25CR7ArZ+F6XXNLTcxM8asn4FfvXU3R0JXj0b34k3mrOMTUEW7SvluoUV +4Evwb6teVWX1AV5CBRRbbC3HOIi1ggbxeIniVcz0gsCzUKNkSV7y8ZSauEzSyKWlEeY 5n5wAN1MbpxSYyqdXWyemT7KhoKs17V1iw2iHgs72s5SCyPmHRWQ3h8dwf1SPrBneIho N3gL2qcLCWYq2Q2ZqmT+hIxvm7OHibsRzdSdm774GynOCSgS4f0YH4xUIO9plrNT+pLd 71Ng== X-Gm-Message-State: AOJu0Yzsp3097IN8YEIgu7MH7cRKeJ3GVePDMxL0SsiC0EezwGipzmAj ncr0qo+gTq5PlsCLACyCyA0YfMaNeXO2NlUfSC65keGgvKjajftuEzmor0Bru8PXQC4MJnYaWlU Ebw== X-Google-Smtp-Source: AGHT+IGGc8k77KYt7XI/6rjNyUO758rOXTVH9wOOzPTwFSoCNpqO3c2UiusmAhlkg10jB5l0EJkSlQ== X-Received: by 2002:a17:907:3187:b0:a99:f945:8776 with SMTP id a640c23a62f3a-a9abf88a58bmr477218466b.24.1729765716343; Thu, 24 Oct 2024 03:28:36 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, Alexander Graf Subject: [PATCH v4 06/15] hw: Add vmapple subdir Date: Thu, 24 Oct 2024 12:28:04 +0200 Message-Id: <20241024102813.9855-7-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::62a; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729765783264116600 Content-Type: text/plain; charset="utf-8" From: Alexander Graf We will introduce a number of devices that are specific to the vmapple target machine. To keep them all tidily together, let's put them into a single target directory. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki --- MAINTAINERS | 7 +++++++ hw/Kconfig | 1 + hw/meson.build | 1 + hw/vmapple/Kconfig | 1 + hw/vmapple/meson.build | 0 hw/vmapple/trace-events | 2 ++ hw/vmapple/trace.h | 1 + meson.build | 1 + 8 files changed, 14 insertions(+) create mode 100644 hw/vmapple/Kconfig create mode 100644 hw/vmapple/meson.build create mode 100644 hw/vmapple/trace-events create mode 100644 hw/vmapple/trace.h diff --git a/MAINTAINERS b/MAINTAINERS index 16ea47a5e6d..104813ed85f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2733,6 +2733,13 @@ F: hw/hyperv/hv-balloon*.h F: include/hw/hyperv/dynmem-proto.h F: include/hw/hyperv/hv-balloon.h =20 +VMapple +M: Alexander Graf +R: Phil Dennis-Jordan +S: Maintained +F: hw/vmapple/* +F: include/hw/vmapple/* + Subsystems ---------- Overall Audio backends diff --git a/hw/Kconfig b/hw/Kconfig index 1b4e9bb07f7..2871784cfdc 100644 --- a/hw/Kconfig +++ b/hw/Kconfig @@ -41,6 +41,7 @@ source ufs/Kconfig source usb/Kconfig source virtio/Kconfig source vfio/Kconfig +source vmapple/Kconfig source xen/Kconfig source watchdog/Kconfig =20 diff --git a/hw/meson.build b/hw/meson.build index b827c82c5d7..9c4f6d0d636 100644 --- a/hw/meson.build +++ b/hw/meson.build @@ -39,6 +39,7 @@ subdir('ufs') subdir('usb') subdir('vfio') subdir('virtio') +subdir('vmapple') subdir('watchdog') subdir('xen') subdir('xenpv') diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/hw/vmapple/Kconfig @@ -0,0 +1 @@ + diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build new file mode 100644 index 00000000000..e69de29bb2d diff --git a/hw/vmapple/trace-events b/hw/vmapple/trace-events new file mode 100644 index 00000000000..9ccc5790487 --- /dev/null +++ b/hw/vmapple/trace-events @@ -0,0 +1,2 @@ +# See docs/devel/tracing.rst for syntax documentation. + diff --git a/hw/vmapple/trace.h b/hw/vmapple/trace.h new file mode 100644 index 00000000000..572adbefe04 --- /dev/null +++ b/hw/vmapple/trace.h @@ -0,0 +1 @@ +#include "trace/trace-hw_vmapple.h" diff --git a/meson.build b/meson.build index 0e124eff13f..dd07a425f0e 100644 --- a/meson.build +++ b/meson.build @@ -3478,6 +3478,7 @@ if have_system 'hw/usb', 'hw/vfio', 'hw/virtio', + 'hw/vmapple', 'hw/watchdog', 'hw/xen', 'hw/gpio', --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729765985; cv=none; d=zohomail.com; s=zohoarc; b=nsF57XiYmyrHViy7geGOTnBABjpELS4U2VbcMQyBij2OV78pcb1OHZ3T7qg9ZaBL6NIChpj63VJOVa4zzG4Lf6MOHEdpQ82B9xJaPNy2SrXGHpRB/1Z3yq+ZWoiVhGTwzHn4jfIJr/EBG4gax83jz6CsLaKJxxePSPrexJ+QHhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729765985; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3ZB/+Sc9m5mjoqV4Si29Zg65y5ttl3uRlQNwxYZ9Scg=; b=N4kRKkF2PTC/QlAiQsjd0YiehUENClB7e43Fm4WIv9sGX5Z1kjcMLRcdA20ZGQmNLZMJkHeunAro1AoE1j98fWQfrlj7Y98VGdtpoq5PZ20hhNhn2eyniM4IB6z1n12h5j6vSfypSlVcioOMSN4yodnNIS9a9HtGHcOBU7qHbN0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729765985849169.78296793164714; Thu, 24 Oct 2024 03:33:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5D-0000vV-SC; Thu, 24 Oct 2024 06:28:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v5A-0000sM-Dg for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:44 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v56-0008Cq-1c for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:44 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a9a2209bd7fso86920366b.2 for ; Thu, 24 Oct 2024 03:28:39 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765718; x=1730370518; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3ZB/+Sc9m5mjoqV4Si29Zg65y5ttl3uRlQNwxYZ9Scg=; b=B50kEjd5bPoiatm/yiDK1/v9GuVaX4d0vO7nP58kjX88gaqet8kn8uhLAqHhdsJy1f 0OZJXfCA/VOtTgVgqvHUpDkCnuIKqFYMuAmn0HOjpZymimP5EI0W0/bfpgb3dVtiPBJp JZA69f35/1iIPee9fGzL4u9oL1MwTg2IKLM8P/9z6VZqAisIhyf+l0MbvHmkqr5F84nH u31U5i6ltLRTf8jvxqBZyMdieVkxUjS0gltdrwE3hDD0Gl3/ChAvIGIiXozKAET42GSm 2HfFk/kCPbFJTphOhMjZQwzI462eJrqeYvBAdw/XkWoSFkRY8sn5jmAbcpHEPdeqB3p2 cH/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765718; x=1730370518; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3ZB/+Sc9m5mjoqV4Si29Zg65y5ttl3uRlQNwxYZ9Scg=; b=ozijjVwSgD6u2QXs0aZCacUinirLXtsCiwtFskldJcGy9mMkR1tNKFOuxcww15xGSm BOEYuSWoHFKpQK4mIzc7UsqJmnc3GeKigzt44ph35arm0pbSE3RqYGEG0sfAOkcwnK5g 9g2emeV8G2GjmYmtgZsNuYQzkrTEtiOGI/o6X7h+VNp5D7zQk4h36NSkqicKnVn7XjWF GY4Xa07BDB3D+K4TImQW0pI+9Nj95xRww3pQ9plaRkL5hRJK94SMGOUckLcc0tcdDW+D /Xg2EPUmNEHbn7oZPw84wGQ6pICy+w/h55iCQSg7zQ6fXnSImcjRDjLdHJ0ItS/qxIEn cRIA== X-Gm-Message-State: AOJu0YzLbs/exO5XrMoTsMwmG9MrF0+fC+ptJYOkgXDbfZ29P28QoRdb bbmhvJHROxO2J04yd0yQ5YEf44geKxi1iF9Cg42lNKT/1qOrJys1gpWFpM+OyMnyo9eOE+wuIWA Zyw== X-Google-Smtp-Source: AGHT+IH+iI1Lv/Zp5TojNnTWlXfqM1Ibi563uASESdJeRr6tXeDptt83uR87vdeZctHxm+o+seYTYQ== X-Received: by 2002:a17:906:d554:b0:a9a:2afc:e4e4 with SMTP id a640c23a62f3a-a9ad285fd4amr122434666b.59.1729765718508; Thu, 24 Oct 2024 03:28:38 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, Alexander Graf Subject: [PATCH v4 07/15] hw/misc/pvpanic: Add MMIO interface Date: Thu, 24 Oct 2024 12:28:05 +0200 Message-Id: <20241024102813.9855-8-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::62f; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729765988263116600 From: Alexander Graf In addition to the ISA and PCI variants of pvpanic, let's add an MMIO platform device that we can use in embedded arm environments. Signed-off-by: Alexander Graf Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki --- hw/misc/Kconfig | 4 +++ hw/misc/meson.build | 1 + hw/misc/pvpanic-mmio.c | 61 +++++++++++++++++++++++++++++++++++++++ include/hw/misc/pvpanic.h | 1 + 4 files changed, 67 insertions(+) create mode 100644 hw/misc/pvpanic-mmio.c diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 1f1baa5dde9..5a6c1603b60 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -145,6 +145,10 @@ config PVPANIC_ISA depends on ISA_BUS select PVPANIC_COMMON =20 +config PVPANIC_MMIO + bool + select PVPANIC_COMMON + config AUX bool select I2C diff --git a/hw/misc/meson.build b/hw/misc/meson.build index d02d96e403b..4de4db0a600 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -122,6 +122,7 @@ system_ss.add(when: 'CONFIG_ARMSSE_MHU', if_true: files= ('armsse-mhu.c')) =20 system_ss.add(when: 'CONFIG_PVPANIC_ISA', if_true: files('pvpanic-isa.c')) system_ss.add(when: 'CONFIG_PVPANIC_PCI', if_true: files('pvpanic-pci.c')) +system_ss.add(when: 'CONFIG_PVPANIC_MMIO', if_true: files('pvpanic-mmio.c'= )) system_ss.add(when: 'CONFIG_AUX', if_true: files('auxbus.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files( 'aspeed_hace.c', diff --git a/hw/misc/pvpanic-mmio.c b/hw/misc/pvpanic-mmio.c new file mode 100644 index 00000000000..56738efee53 --- /dev/null +++ b/hw/misc/pvpanic-mmio.c @@ -0,0 +1,61 @@ +/* + * QEMU simulated pvpanic device (MMIO frontend) + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +#include "hw/qdev-properties.h" +#include "hw/misc/pvpanic.h" +#include "hw/sysbus.h" +#include "standard-headers/misc/pvpanic.h" + +OBJECT_DECLARE_SIMPLE_TYPE(PVPanicMMIOState, PVPANIC_MMIO_DEVICE) + +#define PVPANIC_MMIO_SIZE 0x2 + +struct PVPanicMMIOState { + SysBusDevice parent_obj; + + PVPanicState pvpanic; +}; + +static void pvpanic_mmio_initfn(Object *obj) +{ + PVPanicMMIOState *s =3D PVPANIC_MMIO_DEVICE(obj); + + pvpanic_setup_io(&s->pvpanic, DEVICE(s), PVPANIC_MMIO_SIZE); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->pvpanic.mr); +} + +static Property pvpanic_mmio_properties[] =3D { + DEFINE_PROP_UINT8("events", PVPanicMMIOState, pvpanic.events, + PVPANIC_PANICKED | PVPANIC_CRASH_LOADED), + DEFINE_PROP_END_OF_LIST(), +}; + +static void pvpanic_mmio_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + device_class_set_props(dc, pvpanic_mmio_properties); + set_bit(DEVICE_CATEGORY_MISC, dc->categories); +} + +static const TypeInfo pvpanic_mmio_info =3D { + .name =3D TYPE_PVPANIC_MMIO_DEVICE, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(PVPanicMMIOState), + .instance_init =3D pvpanic_mmio_initfn, + .class_init =3D pvpanic_mmio_class_init, +}; + +static void pvpanic_register_types(void) +{ + type_register_static(&pvpanic_mmio_info); +} + +type_init(pvpanic_register_types) diff --git a/include/hw/misc/pvpanic.h b/include/hw/misc/pvpanic.h index 9a71a5ad0d7..049a94c1125 100644 --- a/include/hw/misc/pvpanic.h +++ b/include/hw/misc/pvpanic.h @@ -26,6 +26,7 @@ =20 #define TYPE_PVPANIC_ISA_DEVICE "pvpanic" #define TYPE_PVPANIC_PCI_DEVICE "pvpanic-pci" +#define TYPE_PVPANIC_MMIO_DEVICE "pvpanic-mmio" =20 #define PVPANIC_IOPORT_PROP "ioport" =20 --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729765781; cv=none; d=zohomail.com; s=zohoarc; b=A2zrhdny35L8It1+lHg/IUW2sl6X9fdGysJuuxO3osxkslhmxtUgep0LR/O0zCrAUM2X1AH4SUndSxGh9kEFS1MBJLGFjTIeoQLAg5Ogf+dqMhdFH2J1/WDKd2txzit3rvHRtdE6n2OaYVU9ehC9vNH7cyrEQvVzAdS1bcdmuK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729765781; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IOlf/wzEJ+wM7g5BTurCACeEWddAq/2jF0kyAkwof9o=; b=T9TlLnoWI+SaBt9x5ZDkZw9Z3qetFRWZxkvLe8yGNGC45JfikpcAG3Bv+u+gQhvAVAemXTuu4HFPlCoBJ8VSInFYt1+Y1VVz/wEc9CWD8/Opj6g0nxd5Uh9pWT+y2l/prYV86/BNYr3Rl76R8hPityuIxFk4ib541F6n+pwhMD4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17297657814681013.3905905477707; Thu, 24 Oct 2024 03:29:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5F-0000wq-Ca; Thu, 24 Oct 2024 06:28:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v5B-0000u1-Ff for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:45 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v58-0008Dy-Bn for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:45 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a9a850270e2so116231766b.0 for ; Thu, 24 Oct 2024 03:28:42 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765721; x=1730370521; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IOlf/wzEJ+wM7g5BTurCACeEWddAq/2jF0kyAkwof9o=; b=vAA6hRr3XWSmin7ZVcfpnmVNjqHtCHIbbQRY0AtipYtqiGTfjGKnYZcCM/Q16W0x75 kVhRXxwgbMLEya4K/nwiZ2FzbAlGIXUusFTfCC2Eqklhk0PH+N2DHV4lM4bth7d2/Kk2 bemb2UzU7LI6Me4Eg1fXbAj0v7SQxl6ga0ebmMLnMDql3IpXSAeSw746Cl4b4PX6+qne M6Y+0YORPmKwAKeio1+w7ikPvlactifOAlJ1OCcIJ3rvzKZzLoJHG8Jt5EigkmgJ3XLV 7UEiFp+oSQjyPbgIhkPF3uvUHG7pdNb2GxD7+OxG79gbbseKkYbtYnk1VdFeFlKEaFxI 8BPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765721; x=1730370521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IOlf/wzEJ+wM7g5BTurCACeEWddAq/2jF0kyAkwof9o=; b=huZUBAi09c9DsfZQ3XHWADEviZhDrYoKdAjy9hPCZYXUuhlTaSnNeuULwDAAV8D5RG vNmYjCOdsRdOkImeWSzwhYCMBYrx4jXl/GV2Oi0aEo37Sh3s2/3CPT6FdOKf4hWyu3cS R6W8q2fRp/DYMmSwBeJCc1josX7WNLgz4zQ3+sydT2Hzt/GLPM2V+4U6sRnxK/IeHw0m j+Oq+8/zb0ZcLUmK+421Ri56AXeQ9aaXZpHw1j9J83h1HOOS5AqDoMNdoKrATbgm6Z6S Da53dZO/XkHifsMFdp6b0YyvCh5BcZVRcMCBFdPAyzW+evTMh+JNlK1rzx+ljOCKedQw lrqQ== X-Gm-Message-State: AOJu0YyL+5317vJefew4h9TcwJzvrlEsb5o8xs5dWQ8fT2kU3m/XPVsn 0pqSh3p7yokCAbFlXzFuP3f2zYJCCPgx3YhecRiyrrAzRXegFQzBCZp2T1OsHpe7BasRlqhDAsQ 8hg== X-Google-Smtp-Source: AGHT+IEW8XvWl7WjK5L6NTaQiRxCXYwncONlzs/TAiw6pzsr5QrMaAH6KgMxVt0rkKJqjqOk0fXWnQ== X-Received: by 2002:a17:907:7247:b0:a9a:33c:f6e1 with SMTP id a640c23a62f3a-a9abf851e2dmr534891566b.5.1729765720535; Thu, 24 Oct 2024 03:28:40 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, Alexander Graf Subject: [PATCH v4 08/15] hvf: arm: Ignore writes to CNTP_CTL_EL0 Date: Thu, 24 Oct 2024 12:28:06 +0200 Message-Id: <20241024102813.9855-9-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::62e; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62e.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729765783239116600 Content-Type: text/plain; charset="utf-8" From: Alexander Graf MacOS unconditionally disables interrupts of the physical timer on boot and then continues to use the virtual one. We don't really want to support a full physical timer emulation, so let's just ignore those writes. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki --- target/arm/hvf/hvf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index 6cea483d422..b45b764dfd0 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -11,6 +11,7 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/log.h" =20 #include "sysemu/runstate.h" #include "sysemu/hvf.h" @@ -184,6 +185,7 @@ void hvf_arm_init_debug(void) #define SYSREG_OSLSR_EL1 SYSREG(2, 0, 1, 1, 4) #define SYSREG_OSDLR_EL1 SYSREG(2, 0, 1, 3, 4) #define SYSREG_CNTPCT_EL0 SYSREG(3, 3, 14, 0, 1) +#define SYSREG_CNTP_CTL_EL0 SYSREG(3, 3, 14, 2, 1) #define SYSREG_PMCR_EL0 SYSREG(3, 3, 9, 12, 0) #define SYSREG_PMUSERENR_EL0 SYSREG(3, 3, 9, 14, 0) #define SYSREG_PMCNTENSET_EL0 SYSREG(3, 3, 9, 12, 1) @@ -1620,6 +1622,13 @@ static int hvf_sysreg_write(CPUState *cpu, uint32_t = reg, uint64_t val) case SYSREG_OSLAR_EL1: env->cp15.oslsr_el1 =3D val & 1; return 0; + case SYSREG_CNTP_CTL_EL0: + /* + * Guests should not rely on the physical counter, but macOS emits + * disable writes to it. Let it do so, but ignore the requests. + */ + qemu_log_mask(LOG_UNIMP, "Unsupported write to CNTP_CTL_EL0\n"); + return 0; case SYSREG_OSDLR_EL1: /* Dummy register */ return 0; --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729765957; cv=none; d=zohomail.com; s=zohoarc; b=Hi39dDx19cyYPEwGM0GhK7tDA6nyGS5789aHtWfLUC8rWB5Zfeei1e4wOSBpu93EzXCQxkYvSX/dbuN/AAUW0LJ7OsdPqgfUyGplKIaHV6VDrRqC42QXDH+lMv8F6tD9WOl7sLJDlloGO1W4xQlJeHyHNdNGYCI1Y3skbZNSNHk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729765957; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bz/mNzSry4lLD1G1310RMOxW7TAxrgxHRhUSMqGbbHA=; b=ZtYGrzMAadTxesJqdjzkI/HLWu3sLcEFzzD2XLxFrvjcK4v89b7i0LJo+9YkC9Ju1VBtP4a8VR5IW1SOFLiYLpXSHDkq3Zbjtfsb2mgw2zou55u08752aOedIGI97x5yIlbgLSuOkFvZpkTxEuSPcZLLklP8mJOIwh0Nixxvej8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729765957756245.94776436469397; Thu, 24 Oct 2024 03:32:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5G-0000y2-SQ; Thu, 24 Oct 2024 06:28:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v5C-0000vJ-VK for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:47 -0400 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v5A-0008FJ-9A for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:46 -0400 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5cb15b84544so901986a12.2 for ; Thu, 24 Oct 2024 03:28:43 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765723; x=1730370523; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bz/mNzSry4lLD1G1310RMOxW7TAxrgxHRhUSMqGbbHA=; b=TRbGQNs0qupd5El4aVQelvVhL1SsqF2nYPJX1PeoRjaEPYcIwSPj65fZXG3tRgpMPs srm8GlvrRsr7t5Y+iPs2aesl9lF1zxOYfRDMs493NjG70RTKc13uZJr9Ny4Bss/P4JeX 7Ah3SaRXmS2ZYITjiLUj78GCDObOZWjtI+H1q5dlluNca8Vdc2rCTtvMM8FNjTiIgaBS TZTzwr77OMOCFhDlMqbYCTlnkHMGeLQhFN3L9E00MBDrVV9YbBwEpvpLO5ByA8uNTsFQ 57vFffjp0j+DUe2WimetYHWUl+v5ZctzLg6u0/CMUFnbnh/gKDvqZ4gBzWqxZplAprc0 9RdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765723; x=1730370523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bz/mNzSry4lLD1G1310RMOxW7TAxrgxHRhUSMqGbbHA=; b=WJG65mvRyZCyj6D7fRsf7UUascDoZcSi93E0xk4ys/DwvlUJy5DyneWcdE393bs/p+ sBoiFhOoU4gjAXYpzI9FBrvqQfiN5zcF6OLjklwJ+AhcEA0f6E7mlLLYvgXbT0lhbW7A CzPJWTpKm5VG+WY2hElGyI9VvHzVL6bUQlpbibvtJaGvPuhyGcnUs/22mhEkHv9V8p+T wO7CXRuaCvf/1vLAxjihuGSWZVK6FvJCU/abwmO2MQLUap8taP7iOGs7QK3nh0i2uzbG G3hOBF17+ZXqxnpUIeL35X/RxCNHqcnXeauUkt0NPDbHwBsxEGl86ticXMGi6lzgwIuN s81w== X-Gm-Message-State: AOJu0Yy+vsxIvAl42OIr3bgf+XvybULMbLUBxuUPbPd2mE6XvLm1YgKS XWZUJ8lVf1JZMOicmyTQ7DF9ykZCYxI7uKkmuXl4xdljScjYeXdmCGUmwHSTr5ilFH223dL4VnV qOQ== X-Google-Smtp-Source: AGHT+IFTJ3JbC76Lz9f6bCIHNSmAZscoc70vg71xHP5TjAOQPwmP9JkODwDIiQun5SA/Ijq0+2qq3A== X-Received: by 2002:a17:907:1c16:b0:a99:55ab:b666 with SMTP id a640c23a62f3a-a9abf8aa246mr495232566b.34.1729765722581; Thu, 24 Oct 2024 03:28:42 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, Alexander Graf Subject: [PATCH v4 09/15] gpex: Allow more than 4 legacy IRQs Date: Thu, 24 Oct 2024 12:28:07 +0200 Message-Id: <20241024102813.9855-10-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::533; envelope-from=phil@philjordan.eu; helo=mail-ed1-x533.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729765960105116600 Content-Type: text/plain; charset="utf-8" From: Alexander Graf Some boards such as vmapple don't do real legacy PCI IRQ swizzling. Instead, they just keep allocating more board IRQ lines for each new legacy IRQ. Let's support that mode by giving instantiators a new "nr_irqs" property they can use to support more than 4 legacy IRQ lines. In this mode, GPEX will export more IRQ lines, one for each device. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki --- v4: * Turned pair of IRQ arrays into array of structs. * Simplified swizzling logic selection. hw/arm/sbsa-ref.c | 2 +- hw/arm/virt.c | 2 +- hw/i386/microvm.c | 2 +- hw/loongarch/virt.c | 2 +- hw/mips/loongson3_virt.c | 2 +- hw/openrisc/virt.c | 12 +++++------ hw/pci-host/gpex.c | 43 ++++++++++++++++++++++++++++++-------- hw/riscv/virt.c | 12 +++++------ hw/xtensa/virt.c | 2 +- include/hw/pci-host/gpex.h | 7 +++---- 10 files changed, 55 insertions(+), 31 deletions(-) diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c index e3195d54497..7e7322486c2 100644 --- a/hw/arm/sbsa-ref.c +++ b/hw/arm/sbsa-ref.c @@ -673,7 +673,7 @@ static void create_pcie(SBSAMachineState *sms) /* Map IO port space */ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, base_pio); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, qdev_get_gpio_in(sms->gic, irq + i)); gpex_set_irq_num(GPEX_HOST(dev), i, irq + i); diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 8b2b991d978..bd3b17be2ea 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1547,7 +1547,7 @@ static void create_pcie(VirtMachineState *vms) /* Map IO port space */ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, base_pio); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, qdev_get_gpio_in(vms->gic, irq + i)); gpex_set_irq_num(GPEX_HOST(dev), i, irq + i); diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 693099f2256..b3a348bee09 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -139,7 +139,7 @@ static void create_gpex(MicrovmMachineState *mms) mms->gpex.mmio64.base, mmio64_alias); } =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, x86ms->gsi[mms->gpex.irq + i]); } diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index 9a635d1d3d3..50056384994 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -741,7 +741,7 @@ static void virt_devices_init(DeviceState *pch_pic, memory_region_add_subregion(get_system_memory(), VIRT_PCI_IO_BASE, pio_alias); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { sysbus_connect_irq(d, i, qdev_get_gpio_in(pch_pic, 16 + i)); gpex_set_irq_num(GPEX_HOST(gpex_dev), i, 16 + i); diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c index f3b6326cc59..884b5f23a99 100644 --- a/hw/mips/loongson3_virt.c +++ b/hw/mips/loongson3_virt.c @@ -458,7 +458,7 @@ static inline void loongson3_virt_devices_init(MachineS= tate *machine, virt_memmap[VIRT_PCIE_PIO].base, s->pio_al= ias); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, virt_memmap[VIRT_PCIE_PIO].bas= e); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { irq =3D qdev_get_gpio_in(pic, PCIE_IRQ_BASE + i); sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); gpex_set_irq_num(GPEX_HOST(dev), i, PCIE_IRQ_BASE + i); diff --git a/hw/openrisc/virt.c b/hw/openrisc/virt.c index 47d2c9bd3c7..6f053bf48e0 100644 --- a/hw/openrisc/virt.c +++ b/hw/openrisc/virt.c @@ -318,7 +318,7 @@ static void create_pcie_irq_map(void *fdt, char *nodena= me, int irq_base, { int pin, dev; uint32_t irq_map_stride =3D 0; - uint32_t full_irq_map[GPEX_NUM_IRQS * GPEX_NUM_IRQS * 6] =3D {}; + uint32_t full_irq_map[PCI_NUM_PINS * PCI_NUM_PINS * 6] =3D {}; uint32_t *irq_map =3D full_irq_map; =20 /* @@ -330,11 +330,11 @@ static void create_pcie_irq_map(void *fdt, char *node= name, int irq_base, * possible slot) seeing the interrupt-map-mask will allow the table * to wrap to any number of devices. */ - for (dev =3D 0; dev < GPEX_NUM_IRQS; dev++) { + for (dev =3D 0; dev < PCI_NUM_PINS; dev++) { int devfn =3D dev << 3; =20 - for (pin =3D 0; pin < GPEX_NUM_IRQS; pin++) { - int irq_nr =3D irq_base + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_= IRQS); + for (pin =3D 0; pin < PCI_NUM_PINS; pin++) { + int irq_nr =3D irq_base + ((pin + PCI_SLOT(devfn)) % PCI_NUM_P= INS); int i =3D 0; =20 /* Fill PCI address cells */ @@ -357,7 +357,7 @@ static void create_pcie_irq_map(void *fdt, char *nodena= me, int irq_base, } =20 qemu_fdt_setprop(fdt, nodename, "interrupt-map", full_irq_map, - GPEX_NUM_IRQS * GPEX_NUM_IRQS * + PCI_NUM_PINS * PCI_NUM_PINS * irq_map_stride * sizeof(uint32_t)); =20 qemu_fdt_setprop_cells(fdt, nodename, "interrupt-map-mask", @@ -409,7 +409,7 @@ static void openrisc_virt_pcie_init(OR1KVirtState *stat= e, memory_region_add_subregion(get_system_memory(), pio_base, alias); =20 /* Connect IRQ lines. */ - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { pcie_irq =3D get_per_cpu_irq(cpus, num_cpus, irq_base + i); =20 sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pcie_irq); diff --git a/hw/pci-host/gpex.c b/hw/pci-host/gpex.c index e9cf455bf52..cd63aa2d3cf 100644 --- a/hw/pci-host/gpex.c +++ b/hw/pci-host/gpex.c @@ -32,6 +32,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "hw/irq.h" +#include "hw/pci/pci_bus.h" #include "hw/pci-host/gpex.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" @@ -41,20 +42,25 @@ * GPEX host */ =20 +struct GPEXIrq { + qemu_irq irq; + int irq_num; +}; + static void gpex_set_irq(void *opaque, int irq_num, int level) { GPEXHost *s =3D opaque; =20 - qemu_set_irq(s->irq[irq_num], level); + qemu_set_irq(s->irq[irq_num].irq, level); } =20 int gpex_set_irq_num(GPEXHost *s, int index, int gsi) { - if (index >=3D GPEX_NUM_IRQS) { + if (index >=3D s->num_irqs) { return -EINVAL; } =20 - s->irq_num[index] =3D gsi; + s->irq[index].irq_num =3D gsi; return 0; } =20 @@ -62,7 +68,7 @@ static PCIINTxRoute gpex_route_intx_pin_to_irq(void *opaq= ue, int pin) { PCIINTxRoute route; GPEXHost *s =3D opaque; - int gsi =3D s->irq_num[pin]; + int gsi =3D s->irq[pin].irq_num; =20 route.irq =3D gsi; if (gsi < 0) { @@ -74,6 +80,13 @@ static PCIINTxRoute gpex_route_intx_pin_to_irq(void *opa= que, int pin) return route; } =20 +static int gpex_swizzle_map_irq_fn(PCIDevice *pci_dev, int pin) +{ + PCIBus *bus =3D pci_device_root_bus(pci_dev); + + return (PCI_SLOT(pci_dev->devfn) + pin) % bus->nirq; +} + static void gpex_host_realize(DeviceState *dev, Error **errp) { PCIHostState *pci =3D PCI_HOST_BRIDGE(dev); @@ -82,6 +95,8 @@ static void gpex_host_realize(DeviceState *dev, Error **e= rrp) PCIExpressHost *pex =3D PCIE_HOST_BRIDGE(dev); int i; =20 + s->irq =3D g_malloc0_n(s->num_irqs, sizeof(*s->irq)); + pcie_host_mmcfg_init(pex, PCIE_MMCFG_SIZE_MAX); sysbus_init_mmio(sbd, &pex->mmio); =20 @@ -128,19 +143,27 @@ static void gpex_host_realize(DeviceState *dev, Error= **errp) sysbus_init_mmio(sbd, &s->io_ioport); } =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { - sysbus_init_irq(sbd, &s->irq[i]); - s->irq_num[i] =3D -1; + for (i =3D 0; i < s->num_irqs; i++) { + sysbus_init_irq(sbd, &s->irq[i].irq); + s->irq[i].irq_num =3D -1; } =20 pci->bus =3D pci_register_root_bus(dev, "pcie.0", gpex_set_irq, - pci_swizzle_map_irq_fn, s, &s->io_mmi= o, - &s->io_ioport, 0, 4, TYPE_PCIE_BUS); + gpex_swizzle_map_irq_fn, + s, &s->io_mmio, &s->io_ioport, 0, + s->num_irqs, TYPE_PCIE_BUS); =20 pci_bus_set_route_irq_fn(pci->bus, gpex_route_intx_pin_to_irq); qdev_realize(DEVICE(&s->gpex_root), BUS(pci->bus), &error_fatal); } =20 +static void gpex_host_unrealize(DeviceState *dev) +{ + GPEXHost *s =3D GPEX_HOST(dev); + + g_free(s->irq); +} + static const char *gpex_host_root_bus_path(PCIHostState *host_bridge, PCIBus *rootbus) { @@ -166,6 +189,7 @@ static Property gpex_host_properties[] =3D { gpex_cfg.mmio64.base, 0), DEFINE_PROP_SIZE(PCI_HOST_ABOVE_4G_MMIO_SIZE, GPEXHost, gpex_cfg.mmio64.size, 0), + DEFINE_PROP_UINT8("num-irqs", GPEXHost, num_irqs, PCI_NUM_PINS), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -176,6 +200,7 @@ static void gpex_host_class_init(ObjectClass *klass, vo= id *data) =20 hc->root_bus_path =3D gpex_host_root_bus_path; dc->realize =3D gpex_host_realize; + dc->unrealize =3D gpex_host_unrealize; set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); dc->fw_name =3D "pci"; device_class_set_props(dc, gpex_host_properties); diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index ee3129f3b31..08832dc2359 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -167,7 +167,7 @@ static void create_pcie_irq_map(RISCVVirtState *s, void= *fdt, char *nodename, { int pin, dev; uint32_t irq_map_stride =3D 0; - uint32_t full_irq_map[GPEX_NUM_IRQS * GPEX_NUM_IRQS * + uint32_t full_irq_map[PCI_NUM_PINS * PCI_NUM_PINS * FDT_MAX_INT_MAP_WIDTH] =3D {}; uint32_t *irq_map =3D full_irq_map; =20 @@ -179,11 +179,11 @@ static void create_pcie_irq_map(RISCVVirtState *s, vo= id *fdt, char *nodename, * possible slot) seeing the interrupt-map-mask will allow the table * to wrap to any number of devices. */ - for (dev =3D 0; dev < GPEX_NUM_IRQS; dev++) { + for (dev =3D 0; dev < PCI_NUM_PINS; dev++) { int devfn =3D dev * 0x8; =20 - for (pin =3D 0; pin < GPEX_NUM_IRQS; pin++) { - int irq_nr =3D PCIE_IRQ + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_= IRQS); + for (pin =3D 0; pin < PCI_NUM_PINS; pin++) { + int irq_nr =3D PCIE_IRQ + ((pin + PCI_SLOT(devfn)) % PCI_NUM_P= INS); int i =3D 0; =20 /* Fill PCI address cells */ @@ -209,7 +209,7 @@ static void create_pcie_irq_map(RISCVVirtState *s, void= *fdt, char *nodename, } =20 qemu_fdt_setprop(fdt, nodename, "interrupt-map", full_irq_map, - GPEX_NUM_IRQS * GPEX_NUM_IRQS * + PCI_NUM_PINS * PCI_NUM_PINS * irq_map_stride * sizeof(uint32_t)); =20 qemu_fdt_setprop_cells(fdt, nodename, "interrupt-map-mask", @@ -1157,7 +1157,7 @@ static inline DeviceState *gpex_pcie_init(MemoryRegio= n *sys_mem, =20 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, pio_base); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { irq =3D qdev_get_gpio_in(irqchip, PCIE_IRQ + i); =20 sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); diff --git a/hw/xtensa/virt.c b/hw/xtensa/virt.c index 5310a888613..8f5c2009d29 100644 --- a/hw/xtensa/virt.c +++ b/hw/xtensa/virt.c @@ -93,7 +93,7 @@ static void create_pcie(MachineState *ms, CPUXtensaState = *env, int irq_base, /* Connect IRQ lines. */ extints =3D xtensa_get_extints(env); =20 - for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + for (i =3D 0; i < PCI_NUM_PINS; i++) { void *q =3D extints[irq_base + i]; =20 sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, q); diff --git a/include/hw/pci-host/gpex.h b/include/hw/pci-host/gpex.h index dce883573ba..84471533af0 100644 --- a/include/hw/pci-host/gpex.h +++ b/include/hw/pci-host/gpex.h @@ -32,8 +32,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(GPEXHost, GPEX_HOST) #define TYPE_GPEX_ROOT_DEVICE "gpex-root" OBJECT_DECLARE_SIMPLE_TYPE(GPEXRootState, GPEX_ROOT_DEVICE) =20 -#define GPEX_NUM_IRQS 4 - struct GPEXRootState { /*< private >*/ PCIDevice parent_obj; @@ -49,6 +47,7 @@ struct GPEXConfig { PCIBus *bus; }; =20 +typedef struct GPEXIrq GPEXIrq; struct GPEXHost { /*< private >*/ PCIExpressHost parent_obj; @@ -60,8 +59,8 @@ struct GPEXHost { MemoryRegion io_mmio; MemoryRegion io_ioport_window; MemoryRegion io_mmio_window; - qemu_irq irq[GPEX_NUM_IRQS]; - int irq_num[GPEX_NUM_IRQS]; + GPEXIrq *irq; + uint8_t num_irqs; =20 bool allow_unmapped_accesses; =20 --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729765791; cv=none; d=zohomail.com; s=zohoarc; b=lmZyLDq0whEAS9K6sHbuRsM0/RmezqmXB7c9N15sTlgvIaU2YEdvOV8cua0hS5qtfFbSm1ktLTchdOvuKB66XcUiSMt0mbTduYwZSHRHUbRvVq+/aGAVnV5D4mX9CCW/1Zpn6GkKLyTClXqR50J2daBAqWLF2dlFjWOBrSpyuFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729765791; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=srotUHyJbBG14YJnMiXmtjlIkN3kjov0nscN29OW7AI=; b=RB0cY4dGkrOcgYB+hlrV175DLQ3Yo11LJnwAHt9BE7OmFq8WKnOfI2d1Iufxni4jGYuLYGK5v9KEydVnNpb8NKOC/Bks4x1bkvG5H2pRQOqF17G1AoeaqjutIoZJbbche9j/qY/7oIc3o7fUyf/ZfR3xAKcj0lbyq8bFHvziNAA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729765791370466.18810033024226; Thu, 24 Oct 2024 03:29:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5J-0000zn-7Z; Thu, 24 Oct 2024 06:28:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v5G-0000xt-Lj for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:50 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v5D-0008H5-Ov for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:50 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a9a6b4ca29bso77412166b.3 for ; Thu, 24 Oct 2024 03:28:47 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765726; x=1730370526; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=srotUHyJbBG14YJnMiXmtjlIkN3kjov0nscN29OW7AI=; b=DvjPynz+jThEzZCWFU3jQuJF/Ek+k6YaOs2mlvfMzmBqUWGSPjC3yDNqtJf9ZPW497 Q0FXU4QHIyw31/3jOGjx5ThZNICr8ggTNGCfCkLedJePyq168lvmjluXb4x5rG3mJnfI HYqpnvLv45iyYqIQQyBj1yWJeHjWyqpCIWVRH4e4GPZdnn2/ReliuUv6Jr7i4/6e+DYa Vc4oP/9CrRPR7sSvLv7iHsPn987uX9NpQQPoLimIFSrMGrMxjEvYZaf+ti6MhS1Ieyby +EoRx7ryqoOdy3Jomhx3w9ophgufm7itNXdCiq0VagHPnjF3g/rKCagbcAv2gn359LUu 3KZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765726; x=1730370526; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=srotUHyJbBG14YJnMiXmtjlIkN3kjov0nscN29OW7AI=; b=oSKGv/+J0Hq91R9bOsarIx5N0WxnjtRTz72uiZxsqkWplJrGe29B2S55HUea5nb3aT 2BaaBMRLil258uQr0Zffp6gjEKp0LIqhRf0H1nm+JMjO2eRPRSyAUQwj4SNrXT5YBdeH /hg/n8Tkud80Qkh5P694D2IzI4ZZQSVOuaiMdIjxgqrQfT5Gummt/SJCc4ak7TB75gRp A5cHcjgp03hZ4Ex1VlokE14FHlwg+oS87Jk/kwA0Ut8gY/xy7TUKNebo/LCrRwKHkQbx uahfQ5d8mFrFiU1GUmQQVRXPZ6V9xB6lEYlgYRVqF75AFBfZMxzK3Yky3VNs2pBsLBk8 7XLg== X-Gm-Message-State: AOJu0Yyh0j+eP2Ds3rUbjRbDHdeD/qMimDYIsNAMi+1hsuYdtc/IJHNg ZuHzpNIPdl1Q619qClHFoTcjIHLKrUWsqGZNkrB+DuISTfWhcl//HpKyBNQgIZ+N2OzGf14hLWM j4A== X-Google-Smtp-Source: AGHT+IG+xwOJgxIJNc587NrJWxSFXaSN4m5mNRoAAv0dE3NxTtrHvVS9tN5C79/fYwQwg/cA1twqNw== X-Received: by 2002:a17:906:c115:b0:a9a:e6:a031 with SMTP id a640c23a62f3a-a9abf964e1amr533555166b.59.1729765726244; Thu, 24 Oct 2024 03:28:46 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, Alexander Graf Subject: [PATCH v4 10/15] hw/vmapple/aes: Introduce aes engine Date: Thu, 24 Oct 2024 12:28:08 +0200 Message-Id: <20241024102813.9855-11-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::62f; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729765793615116600 From: Alexander Graf VMApple contains an "aes" engine device that it uses to encrypt and decrypt its nvram. It has trivial hard coded keys it uses for that purpose. Add device emulation for this device model. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan --- v3: * Rebased on latest upstream and fixed minor breakages. * Replaced legacy device reset method with Resettable method v4: * Improved logging of unimplemented functions and guest errors. * Better adherence to naming and coding conventions. * Cleaner error handling and recovery, including using g_autoptr hw/vmapple/Kconfig | 2 + hw/vmapple/aes.c | 572 ++++++++++++++++++++++++++++++++++++++++ hw/vmapple/meson.build | 1 + hw/vmapple/trace-events | 16 ++ include/qemu/cutils.h | 15 ++ util/hexdump.c | 14 + 6 files changed, 620 insertions(+) create mode 100644 hw/vmapple/aes.c diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index 8b137891791..a73504d5999 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -1 +1,3 @@ +config VMAPPLE_AES + bool =20 diff --git a/hw/vmapple/aes.c b/hw/vmapple/aes.c new file mode 100644 index 00000000000..59cdcd65f90 --- /dev/null +++ b/hw/vmapple/aes.c @@ -0,0 +1,572 @@ +/* + * QEMU Apple AES device emulation + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "trace.h" +#include "crypto/hash.h" +#include "crypto/aes.h" +#include "crypto/cipher.h" +#include "hw/irq.h" +#include "hw/sysbus.h" +#include "migration/vmstate.h" +#include "qemu/cutils.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "sysemu/dma.h" + +#define TYPE_AES "apple-aes" +OBJECT_DECLARE_SIMPLE_TYPE(AESState, AES) + +#define MAX_FIFO_SIZE 9 + +#define CMD_KEY 0x1 +#define CMD_KEY_CONTEXT_SHIFT 27 +#define CMD_KEY_CONTEXT_MASK (0x1 << CMD_KEY_CONTEXT_SHIFT) +#define CMD_KEY_SELECT_MAX_IDX 0x7 +#define CMD_KEY_SELECT_SHIFT 24 +#define CMD_KEY_SELECT_MASK (CMD_KEY_SELECT_MAX_IDX << CMD_KEY_SELECT= _SHIFT) +#define CMD_KEY_KEY_LEN_NUM 4u +#define CMD_KEY_KEY_LEN_SHIFT 22 +#define CMD_KEY_KEY_LEN_MASK ((CMD_KEY_KEY_LEN_NUM - 1u) << CMD_KEY_KE= Y_LEN_SHIFT) +#define CMD_KEY_ENCRYPT_SHIFT 20 +#define CMD_KEY_ENCRYPT_MASK (0x1 << CMD_KEY_ENCRYPT_SHIFT) +#define CMD_KEY_BLOCK_MODE_SHIFT 16 +#define CMD_KEY_BLOCK_MODE_MASK (0x3 << CMD_KEY_BLOCK_MODE_SHIFT) +#define CMD_IV 0x2 +#define CMD_IV_CONTEXT_SHIFT 26 +#define CMD_IV_CONTEXT_MASK (0x3 << CMD_KEY_CONTEXT_SHIFT) +#define CMD_DSB 0x3 +#define CMD_SKG 0x4 +#define CMD_DATA 0x5 +#define CMD_DATA_KEY_CTX_SHIFT 27 +#define CMD_DATA_KEY_CTX_MASK (0x1 << CMD_DATA_KEY_CTX_SHIFT) +#define CMD_DATA_IV_CTX_SHIFT 25 +#define CMD_DATA_IV_CTX_MASK (0x3 << CMD_DATA_IV_CTX_SHIFT) +#define CMD_DATA_LEN_MASK 0xffffff +#define CMD_STORE_IV 0x6 +#define CMD_STORE_IV_ADDR_MASK 0xffffff +#define CMD_WRITE_REG 0x7 +#define CMD_FLAG 0x8 +#define CMD_FLAG_STOP_MASK BIT(26) +#define CMD_FLAG_RAISE_IRQ_MASK BIT(27) +#define CMD_FLAG_INFO_MASK 0xff +#define CMD_MAX 0x10 + +#define CMD_SHIFT 28 + +#define REG_STATUS 0xc +#define REG_STATUS_DMA_READ_RUNNING BIT(0) +#define REG_STATUS_DMA_READ_PENDING BIT(1) +#define REG_STATUS_DMA_WRITE_RUNNING BIT(2) +#define REG_STATUS_DMA_WRITE_PENDING BIT(3) +#define REG_STATUS_BUSY BIT(4) +#define REG_STATUS_EXECUTING BIT(5) +#define REG_STATUS_READY BIT(6) +#define REG_STATUS_TEXT_DPA_SEEDED BIT(7) +#define REG_STATUS_UNWRAP_DPA_SEEDED BIT(8) + +#define REG_IRQ_STATUS 0x18 +#define REG_IRQ_STATUS_INVALID_CMD BIT(2) +#define REG_IRQ_STATUS_FLAG BIT(5) +#define REG_IRQ_ENABLE 0x1c +#define REG_WATERMARK 0x20 +#define REG_Q_STATUS 0x24 +#define REG_FLAG_INFO 0x30 +#define REG_FIFO 0x200 + +static const uint32_t key_lens[CMD_KEY_KEY_LEN_NUM] =3D { + [0] =3D 16, + [1] =3D 24, + [2] =3D 32, + [3] =3D 64, +}; + +typedef struct Key { + uint32_t key_len; + uint8_t key[32]; +} Key; + +typedef struct IV { + uint32_t iv[4]; +} IV; + +static Key builtin_keys[CMD_KEY_SELECT_MAX_IDX + 1] =3D { + [1] =3D { + .key_len =3D 32, + .key =3D { 0x1 }, + }, + [2] =3D { + .key_len =3D 32, + .key =3D { 0x2 }, + }, + [3] =3D { + .key_len =3D 32, + .key =3D { 0x3 }, + } +}; + +struct AESState { + SysBusDevice parent_obj; + + qemu_irq irq; + MemoryRegion iomem1; + MemoryRegion iomem2; + AddressSpace *as; + + uint32_t status; + uint32_t q_status; + uint32_t irq_status; + uint32_t irq_enable; + uint32_t watermark; + uint32_t flag_info; + uint32_t fifo[MAX_FIFO_SIZE]; + uint32_t fifo_idx; + Key key[2]; + IV iv[4]; + bool is_encrypt; + QCryptoCipherMode block_mode; +}; + +static void aes_update_irq(AESState *s) +{ + qemu_set_irq(s->irq, !!(s->irq_status & s->irq_enable)); +} + +static uint64_t aes1_read(void *opaque, hwaddr offset, unsigned size) +{ + AESState *s =3D opaque; + uint64_t res =3D 0; + + switch (offset) { + case REG_STATUS: + res =3D s->status; + break; + case REG_IRQ_STATUS: + res =3D s->irq_status; + break; + case REG_IRQ_ENABLE: + res =3D s->irq_enable; + break; + case REG_WATERMARK: + res =3D s->watermark; + break; + case REG_Q_STATUS: + res =3D s->q_status; + break; + case REG_FLAG_INFO: + res =3D s->flag_info; + break; + + default: + qemu_log_mask(LOG_UNIMP, "%s: Unknown AES MMIO offset %" PRIx64 "\= n", + __func__, offset); + break; + } + + trace_aes_read(offset, res); + + return res; +} + +static void fifo_append(AESState *s, uint64_t val) +{ + if (s->fifo_idx =3D=3D MAX_FIFO_SIZE) { + /* Exceeded the FIFO. Bail out */ + return; + } + + s->fifo[s->fifo_idx++] =3D val; +} + +static bool has_payload(AESState *s, uint32_t elems) +{ + return s->fifo_idx >=3D (elems + 1); +} + +static bool cmd_key(AESState *s) +{ + uint32_t cmd =3D s->fifo[0]; + uint32_t key_select =3D (cmd & CMD_KEY_SELECT_MASK) >> CMD_KEY_SELECT_= SHIFT; + uint32_t ctxt =3D (cmd & CMD_KEY_CONTEXT_MASK) >> CMD_KEY_CONTEXT_SHIF= T; + uint32_t key_len; + + switch ((cmd & CMD_KEY_BLOCK_MODE_MASK) >> CMD_KEY_BLOCK_MODE_SHIFT) { + case 0: + s->block_mode =3D QCRYPTO_CIPHER_MODE_ECB; + break; + case 1: + s->block_mode =3D QCRYPTO_CIPHER_MODE_CBC; + break; + default: + return false; + } + + s->is_encrypt =3D cmd & CMD_KEY_ENCRYPT_MASK; + key_len =3D key_lens[((cmd & CMD_KEY_KEY_LEN_MASK) >> CMD_KEY_KEY_LEN_= SHIFT)]; + + if (key_select) { + trace_aes_cmd_key_select_builtin(ctxt, key_select, + s->is_encrypt ? "en" : "de", + QCryptoCipherMode_str(s->block_mo= de)); + s->key[ctxt] =3D builtin_keys[key_select]; + } else { + trace_aes_cmd_key_select_new(ctxt, key_len, + s->is_encrypt ? "en" : "de", + QCryptoCipherMode_str(s->block_mode)); + if (key_len > sizeof(s->key[ctxt].key)) { + return false; + } + if (!has_payload(s, key_len / sizeof(uint32_t))) { + /* wait for payload */ + qemu_log_mask(LOG_GUEST_ERROR, "%s: No payload\n", __func__); + return false; + } + memcpy(&s->key[ctxt].key, &s->fifo[1], key_len); + s->key[ctxt].key_len =3D key_len; + } + + return true; +} + +static bool cmd_iv(AESState *s) +{ + uint32_t cmd =3D s->fifo[0]; + uint32_t ctxt =3D (cmd & CMD_IV_CONTEXT_MASK) >> CMD_IV_CONTEXT_SHIFT; + + if (!has_payload(s, 4)) { + /* wait for payload */ + return false; + } + memcpy(&s->iv[ctxt].iv, &s->fifo[1], sizeof(s->iv[ctxt].iv)); + trace_aes_cmd_iv(ctxt, s->fifo[1], s->fifo[2], s->fifo[3], s->fifo[4]); + + return true; +} + +static void dump_data(const char *desc, const void *p, size_t len) +{ + static const size_t MAX_LEN =3D 0x1000; + char hex[MAX_LEN * 2 + 1] =3D ""; + + if (len > MAX_LEN) { + return; + } + + qemu_hexdump_to_buffer(hex, sizeof(hex), p, len); + trace_aes_dump_data(desc, hex); +} + +static bool cmd_data(AESState *s) +{ + uint32_t cmd =3D s->fifo[0]; + uint32_t ctxt_iv =3D 0; + uint32_t ctxt_key =3D (cmd & CMD_DATA_KEY_CTX_MASK) >> CMD_DATA_KEY_CT= X_SHIFT; + uint32_t len =3D cmd & CMD_DATA_LEN_MASK; + uint64_t src_addr =3D s->fifo[2]; + uint64_t dst_addr =3D s->fifo[3]; + QCryptoCipherAlgo alg; + g_autoptr(QCryptoCipher) cipher =3D NULL; + g_autoptr(GByteArray) src =3D NULL; + g_autoptr(GByteArray) dst =3D NULL; + MemTxResult r; + + src_addr |=3D ((uint64_t)s->fifo[1] << 16) & 0xffff00000000ULL; + dst_addr |=3D ((uint64_t)s->fifo[1] << 32) & 0xffff00000000ULL; + + trace_aes_cmd_data(ctxt_key, ctxt_iv, src_addr, dst_addr, len); + + if (!has_payload(s, 3)) { + /* wait for payload */ + qemu_log_mask(LOG_GUEST_ERROR, "%s: No payload\n", __func__); + return false; + } + + if (ctxt_key >=3D ARRAY_SIZE(s->key) || + ctxt_iv >=3D ARRAY_SIZE(s->iv)) { + /* Invalid input */ + qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid key or iv\n", __func__= ); + return false; + } + + src =3D g_byte_array_sized_new(len); + g_byte_array_set_size(src, len); + dst =3D g_byte_array_sized_new(len); + g_byte_array_set_size(dst, len); + + r =3D dma_memory_read(s->as, src_addr, src->data, len, MEMTXATTRS_UNSP= ECIFIED); + if (r !=3D MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: DMA read of %"PRIu32" bytes " + "from 0x%"PRIx64" failed. (r=3D%d)\n", + __func__, len, src_addr, r); + return false; + } + + dump_data("cmd_data(): src_data=3D", src->data, len); + + switch (s->key[ctxt_key].key_len) { + case 128 / 8: + alg =3D QCRYPTO_CIPHER_ALGO_AES_128; + break; + case 192 / 8: + alg =3D QCRYPTO_CIPHER_ALGO_AES_192; + break; + case 256 / 8: + alg =3D QCRYPTO_CIPHER_ALGO_AES_256; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid key length\n", __func_= _); + return false; + } + cipher =3D qcrypto_cipher_new(alg, s->block_mode, + s->key[ctxt_key].key, + s->key[ctxt_key].key_len, NULL); + if (!cipher) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to create cipher object= \n", + __func__); + return false; + } + if (s->block_mode !=3D QCRYPTO_CIPHER_MODE_ECB) { + if (qcrypto_cipher_setiv(cipher, (void *)s->iv[ctxt_iv].iv, + sizeof(s->iv[ctxt_iv].iv), NULL) !=3D 0) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to set IV\n", __fun= c__); + return false; + } + } + if (s->is_encrypt) { + if (qcrypto_cipher_encrypt(cipher, src->data, dst->data, len, NULL= ) !=3D 0) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: Encryption failed\n", __fu= nc__); + return false; + } + } else { + if (qcrypto_cipher_decrypt(cipher, src->data, dst->data, len, NULL= ) !=3D 0) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: Decryption failed\n", __fu= nc__); + return false; + } + } + + dump_data("cmd_data(): dst_data=3D", dst->data, len); + r =3D dma_memory_write(s->as, dst_addr, dst->data, len, MEMTXATTRS_UNS= PECIFIED); + if (r !=3D MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: DMA write of %"PRIu32" bytes " + "to 0x%"PRIx64" failed. (r=3D%d)\n", + __func__, len, src_addr, r); + return false; + } + + return true; +} + +static bool cmd_store_iv(AESState *s) +{ + uint32_t cmd =3D s->fifo[0]; + uint32_t ctxt =3D (cmd & CMD_IV_CONTEXT_MASK) >> CMD_IV_CONTEXT_SHIFT; + uint64_t addr =3D s->fifo[1]; + + if (!has_payload(s, 1)) { + /* wait for payload */ + qemu_log_mask(LOG_GUEST_ERROR, "%s: No payload\n", __func__); + return false; + } + + if (ctxt >=3D ARRAY_SIZE(s->iv)) { + /* Invalid context selected */ + return false; + } + + addr |=3D ((uint64_t)cmd << 32) & 0xff00000000ULL; + cpu_physical_memory_write(addr, &s->iv[ctxt].iv, sizeof(s->iv[ctxt].iv= )); + + trace_aes_cmd_store_iv(ctxt, addr, s->iv[ctxt].iv[0], s->iv[ctxt].iv[1= ], + s->iv[ctxt].iv[2], s->iv[ctxt].iv[3]); + + return true; +} + +static bool cmd_flag(AESState *s) +{ + uint32_t cmd =3D s->fifo[0]; + uint32_t raise_irq =3D cmd & CMD_FLAG_RAISE_IRQ_MASK; + + /* We always process data when it's coming in, so fire an IRQ immediat= ely */ + if (raise_irq) { + s->irq_status |=3D REG_IRQ_STATUS_FLAG; + } + + s->flag_info =3D cmd & CMD_FLAG_INFO_MASK; + + trace_aes_cmd_flag(!!raise_irq, s->flag_info); + + return true; +} + +static void fifo_process(AESState *s) +{ + uint32_t cmd =3D s->fifo[0] >> CMD_SHIFT; + bool success =3D false; + + if (!s->fifo_idx) { + return; + } + + switch (cmd) { + case CMD_KEY: + success =3D cmd_key(s); + break; + case CMD_IV: + success =3D cmd_iv(s); + break; + case CMD_DATA: + success =3D cmd_data(s); + break; + case CMD_STORE_IV: + success =3D cmd_store_iv(s); + break; + case CMD_FLAG: + success =3D cmd_flag(s); + break; + default: + s->irq_status |=3D REG_IRQ_STATUS_INVALID_CMD; + break; + } + + if (success) { + s->fifo_idx =3D 0; + } + + trace_aes_fifo_process(cmd, success ? 1 : 0); +} + +static void aes1_write(void *opaque, hwaddr offset, uint64_t val, unsigned= size) +{ + AESState *s =3D opaque; + + trace_aes_write(offset, val); + + switch (offset) { + case REG_IRQ_STATUS: + s->irq_status &=3D ~val; + break; + case REG_IRQ_ENABLE: + s->irq_enable =3D val; + break; + case REG_FIFO: + fifo_append(s, val); + fifo_process(s); + break; + default: + qemu_log_mask(LOG_UNIMP, + "%s: Unknown AES MMIO offset %"PRIx64", data %"PRIx6= 4"\n", + __func__, offset, val); + return; + } + + aes_update_irq(s); +} + +static const MemoryRegionOps aes1_ops =3D { + .read =3D aes1_read, + .write =3D aes1_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static uint64_t aes2_read(void *opaque, hwaddr offset, unsigned size) +{ + uint64_t res =3D 0; + + switch (offset) { + case 0: + res =3D 0; + break; + default: + trace_aes_2_read_unknown(offset); + break; + } + + trace_aes_2_read(offset, res); + + return res; +} + +static void aes2_write(void *opaque, hwaddr offset, uint64_t val, unsigned= size) +{ + trace_aes_2_write(offset, val); + + switch (offset) { + default: + trace_aes_2_write_unknown(offset); + return; + } +} + +static const MemoryRegionOps aes2_ops =3D { + .read =3D aes2_read, + .write =3D aes2_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static void aes_reset(Object *obj, ResetType type) +{ + AESState *s =3D AES(obj); + + s->status =3D 0x3f80; + s->q_status =3D 2; + s->irq_status =3D 0; + s->irq_enable =3D 0; + s->watermark =3D 0; +} + +static void aes_init(Object *obj) +{ + AESState *s =3D AES(obj); + + memory_region_init_io(&s->iomem1, obj, &aes1_ops, s, TYPE_AES, 0x4000); + memory_region_init_io(&s->iomem2, obj, &aes2_ops, s, TYPE_AES, 0x4000); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem1); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem2); + sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq); + s->as =3D &address_space_memory; +} + +static void aes_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + rc->phases.hold =3D aes_reset; +} + +static const TypeInfo aes_info =3D { + .name =3D TYPE_AES, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(AESState), + .class_init =3D aes_class_init, + .instance_init =3D aes_init, +}; + +static void aes_register_types(void) +{ + type_register_static(&aes_info); +} + +type_init(aes_register_types) diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build index e69de29bb2d..bcd4dcb28d2 100644 --- a/hw/vmapple/meson.build +++ b/hw/vmapple/meson.build @@ -0,0 +1 @@ +system_ss.add(when: 'CONFIG_VMAPPLE_AES', if_true: files('aes.c')) diff --git a/hw/vmapple/trace-events b/hw/vmapple/trace-events index 9ccc5790487..12757bc0852 100644 --- a/hw/vmapple/trace-events +++ b/hw/vmapple/trace-events @@ -1,2 +1,18 @@ # See docs/devel/tracing.rst for syntax documentation. =20 +# aes.c +aes_read(uint64_t offset, uint64_t res) "offset=3D0x%"PRIx64" res=3D0x%"PR= Ix64 +aes_cmd_key_select_builtin(uint32_t ctx, uint32_t key_id, const char *dire= ction, const char *cipher) "[%d] Selecting builtin key %d to %scrypt with %= s" +aes_cmd_key_select_new(uint32_t ctx, uint32_t key_len, const char *directi= on, const char *cipher) "[%d] Selecting new key size=3D%d to %scrypt with %= s" +aes_cmd_iv(uint32_t ctx, uint32_t iv0, uint32_t iv1, uint32_t iv2, uint32_= t iv3) "[%d] 0x%08x 0x%08x 0x%08x 0x%08x" +aes_cmd_data(uint32_t key, uint32_t iv, uint64_t src, uint64_t dst, uint32= _t len) "[key=3D%d iv=3D%d] src=3D0x%"PRIx64" dst=3D0x%"PRIx64" len=3D0x%x" +aes_cmd_store_iv(uint32_t ctx, uint64_t addr, uint32_t iv0, uint32_t iv1, = uint32_t iv2, uint32_t iv3) "[%d] addr=3D0x%"PRIx64"x -> 0x%08x 0x%08x 0x%0= 8x 0x%08x" +aes_cmd_flag(uint32_t raise, uint32_t flag_info) "raise=3D%d flag_info=3D0= x%x" +aes_fifo_process(uint32_t cmd, uint32_t success) "cmd=3D%d success=3D%d" +aes_write(uint64_t offset, uint64_t val) "offset=3D0x%"PRIx64" val=3D0x%"P= RIx64 +aes_2_read_unknown(uint64_t offset) "offset=3D0x%"PRIx64 +aes_2_read(uint64_t offset, uint64_t res) "offset=3D0x%"PRIx64" res=3D0x%"= PRIx64 +aes_2_write_unknown(uint64_t offset) "offset=3D0x%"PRIx64 +aes_2_write(uint64_t offset, uint64_t val) "offset=3D0x%"PRIx64" val=3D0x%= "PRIx64 +aes_dump_data(const char *desc, const char *hex) "%s%s" + diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 34a9b9b2204..36c68ce86c5 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -302,4 +302,19 @@ GString *qemu_hexdump_line(GString *str, const void *b= uf, size_t len, void qemu_hexdump(FILE *fp, const char *prefix, const void *bufptr, size_t size); =20 +/** + * qemu_hexdump_to_buffer: + * @buffer: output string buffer + * @buffer_size: amount of available space in buffer. Must be at least + * data_size*2+1. + * @data: input bytes + * @data_size: number of bytes in data + * + * Converts the @data_size bytes in @data into hex digit pairs, writing th= em to + * @buffer. Finally, a nul terminating character is written; @buffer there= fore + * needs space for (data_size*2+1) chars. + */ +void qemu_hexdump_to_buffer(char *restrict buffer, size_t buffer_size, + const uint8_t *restrict data, size_t data_size= ); + #endif diff --git a/util/hexdump.c b/util/hexdump.c index ae0d4992dcf..86345db20a8 100644 --- a/util/hexdump.c +++ b/util/hexdump.c @@ -97,3 +97,17 @@ void qemu_hexdump(FILE *fp, const char *prefix, } =20 } + +void qemu_hexdump_to_buffer(char *restrict buffer, size_t buffer_size, + const uint8_t *restrict data, size_t data_size) +{ + size_t i; + + assert(buffer_size >=3D data_size * 2 + 1 && buffer_size > data_size); + for (i =3D 0; i < data_size; i++) { + uint8_t val =3D data[i]; + *(buffer++) =3D hexdump_nibble(val >> 4); + *(buffer++) =3D hexdump_nibble(val & 0xf); + } + *buffer =3D '\0'; +} --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729766010; cv=none; d=zohomail.com; s=zohoarc; b=Srgy4flVEIQnWsk7Ohil/INVUvNlp3f4DagsrxSUlxLPrbTl0B9HP1/CnVC48neJ26F+d4jhK02sfYSDsBZnSn1zVZjcHiAsDJRjfLtu+ADBxaMTb1YEw7BJPR4Zp+a6sQIHv90OEzCgtQ3dyYNVS/cuit5hcaSUFFFk75Vb1ME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729766010; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O+oMGpZpk5UqkW6ZNwVEybaQMPICUUS3gQUdIlM43Mo=; b=UdqfI9UlyaVni5QSNQ90aPAvSB3P4sRAfCrnKVEK3Pc6/ZwLURK2dKDB0GOZgc5JUsr2ZhLF0Ul4KcXcH3pGfOvBGGKCaSK6MZUl0nvv2+2NryTw0EtNBLzPisYtN72wrdyONp0bro8ZGV5ShF6QeB8wAwTO8Y8nlwD2G1Ify7U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729766010536700.0297404107333; Thu, 24 Oct 2024 03:33:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5N-00015I-9c; Thu, 24 Oct 2024 06:28:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v5J-000114-Dz for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:54 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v5H-0008I2-Ad for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:53 -0400 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a99ebb390a5so341341366b.1 for ; Thu, 24 Oct 2024 03:28:50 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765730; x=1730370530; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O+oMGpZpk5UqkW6ZNwVEybaQMPICUUS3gQUdIlM43Mo=; b=FkiBHQ9vBA+27nmT10VT/kmqJO7Rd4aB+MXInqEzWQifzF1fnOBszlw+blwDZaeaTR dX6wY+iTFdy/4koNFttKF5IMJP1soBTtyahWpJ2nkw6/YNdh9NL40Fd+xtLC3/FuYT/J wr0cozTxqIHql7/QIxmcyIi4z9smg/EHcVPl+cezP6eYms4OIt6DS86RpveYr86S9RKZ oKrSIgcMdBGXHf00+xEiQuEoZxtJ6z2arbX6bNXWl3ydYaTtaZlWZfZnnpl+fLleG/9s zcd5a/4kCWdDNFC6Du37tqPgW1k+Jr1ERFgfQxODn2ilN7+rFUEYQtVJcLkI1KpWmyR8 KwnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765730; x=1730370530; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O+oMGpZpk5UqkW6ZNwVEybaQMPICUUS3gQUdIlM43Mo=; b=bYesLCSDkTJrXH8kcxDFegzHY7a31vj7UmS5nWqG1MaCL6Bco9u6Tt0boYTfM8uNPL UcW+XVU96ss4Pc1wPyv56nL9q1nekloMoNKhzebNmQIR1l3s0nYyCUgkH8LhdOGKWMSW ByY4WIaGXXSe1YPy2MptfulbByeYwZF6HN8YNpkShvaR+Ju3c9PWWZWj0iVyxhStiLpd mGU0z1+ic2BMySfWh6kOaQ81N/Yid7RWNKc85P2Ds/x3/k4aT/3UIQcBNljHCv6PluDt bB4u2ZjiJam/OoZd3LGkLSM3pI6kozbbmaBR+6D/SdTk+dUxn1KI2YX6dHttagXma7vh MeuA== X-Gm-Message-State: AOJu0Yz1kvih6SLOdKNvthuQCluIfPgPJ5uNI/eUtSRcO53DDvzkGIEW GPVC6W2KxrVAbsO8fOzJZWXFU2u21PrlDv7txsim3hfxm4Cw09uFU8rRwtJEOTId1KDR5x9ubqJ Fvg== X-Google-Smtp-Source: AGHT+IHuo+qwQNvvY53TTgDYQd9UY+9pBSKOkixoI+uOijtLXI2CoF63vhadyaIRMyyiEGtr6SHrtg== X-Received: by 2002:a17:907:3f89:b0:a99:ff33:9ba5 with SMTP id a640c23a62f3a-a9ad1a5eecamr186480266b.24.1729765729830; Thu, 24 Oct 2024 03:28:49 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, Alexander Graf Subject: [PATCH v4 11/15] hw/vmapple/bdif: Introduce vmapple backdoor interface Date: Thu, 24 Oct 2024 12:28:09 +0200 Message-Id: <20241024102813.9855-12-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::632; envelope-from=phil@philjordan.eu; helo=mail-ej1-x632.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729766012258116600 From: Alexander Graf The VMApple machine exposes AUX and ROOT block devices (as well as USB OTG emulation) via virtio-pci as well as a special, simple backdoor platform device. This patch implements this backdoor platform device to the best of my understanding. I left out any USB OTG parts; they're only needed for guest recovery and I don't understand the protocol yet. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan --- v4: * Moved most header code to .c, rest to vmapple.h * Better compliance with coding, naming, and formatting conventions. hw/vmapple/Kconfig | 3 + hw/vmapple/bdif.c | 259 +++++++++++++++++++++++++++++++++++ hw/vmapple/meson.build | 1 + hw/vmapple/trace-events | 5 + include/hw/vmapple/vmapple.h | 15 ++ 5 files changed, 283 insertions(+) create mode 100644 hw/vmapple/bdif.c create mode 100644 include/hw/vmapple/vmapple.h diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index a73504d5999..68f88876eb9 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -1,3 +1,6 @@ config VMAPPLE_AES bool =20 +config VMAPPLE_BDIF + bool + diff --git a/hw/vmapple/bdif.c b/hw/vmapple/bdif.c new file mode 100644 index 00000000000..8a697d759bd --- /dev/null +++ b/hw/vmapple/bdif.c @@ -0,0 +1,259 @@ +/* + * VMApple Backdoor Interface + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "trace.h" +#include "hw/vmapple/vmapple.h" +#include "hw/sysbus.h" +#include "hw/block/block.h" +#include "qapi/error.h" +#include "sysemu/block-backend.h" + +OBJECT_DECLARE_SIMPLE_TYPE(VMAppleBdifState, VMAPPLE_BDIF) + +struct VMAppleBdifState { + SysBusDevice parent_obj; + + BlockBackend *aux; + BlockBackend *root; + MemoryRegion mmio; +}; + +#define VMAPPLE_BDIF_SIZE 0x00200000 + +#define REG_DEVID_MASK 0xffff0000 +#define DEVID_ROOT 0x00000000 +#define DEVID_AUX 0x00010000 +#define DEVID_USB 0x00100000 + +#define REG_STATUS 0x0 +#define REG_STATUS_ACTIVE BIT(0) +#define REG_CFG 0x4 +#define REG_CFG_ACTIVE BIT(1) +#define REG_UNK1 0x8 +#define REG_BUSY 0x10 +#define REG_BUSY_READY BIT(0) +#define REG_UNK2 0x400 +#define REG_CMD 0x408 +#define REG_NEXT_DEVICE 0x420 +#define REG_UNK3 0x434 + +typedef struct VblkSector { + uint32_t pad; + uint32_t pad2; + uint32_t sector; + uint32_t pad3; +} VblkSector; + +typedef struct VblkReqCmd { + uint64_t addr; + uint32_t len; + uint32_t flags; +} VblkReqCmd; + +typedef struct VblkReq { + VblkReqCmd sector; + VblkReqCmd data; + VblkReqCmd retval; +} VblkReq; + +#define VBLK_DATA_FLAGS_READ 0x00030001 +#define VBLK_DATA_FLAGS_WRITE 0x00010001 + +#define VBLK_RET_SUCCESS 0 +#define VBLK_RET_FAILED 1 + +static uint64_t bdif_read(void *opaque, hwaddr offset, unsigned size) +{ + uint64_t ret =3D -1; + uint64_t devid =3D offset & REG_DEVID_MASK; + + switch (offset & ~REG_DEVID_MASK) { + case REG_STATUS: + ret =3D REG_STATUS_ACTIVE; + break; + case REG_CFG: + ret =3D REG_CFG_ACTIVE; + break; + case REG_UNK1: + ret =3D 0x420; + break; + case REG_BUSY: + ret =3D REG_BUSY_READY; + break; + case REG_UNK2: + ret =3D 0x1; + break; + case REG_UNK3: + ret =3D 0x0; + break; + case REG_NEXT_DEVICE: + switch (devid) { + case DEVID_ROOT: + ret =3D 0x8000000; + break; + case DEVID_AUX: + ret =3D 0x10000; + break; + } + break; + } + + trace_bdif_read(offset, size, ret); + return ret; +} + +static void le2cpu_sector(VblkSector *sector) +{ + sector->sector =3D le32_to_cpu(sector->sector); +} + +static void le2cpu_reqcmd(VblkReqCmd *cmd) +{ + cmd->addr =3D le64_to_cpu(cmd->addr); + cmd->len =3D le32_to_cpu(cmd->len); + cmd->flags =3D le32_to_cpu(cmd->flags); +} + +static void le2cpu_req(VblkReq *req) +{ + le2cpu_reqcmd(&req->sector); + le2cpu_reqcmd(&req->data); + le2cpu_reqcmd(&req->retval); +} + +static void vblk_cmd(uint64_t devid, BlockBackend *blk, uint64_t value, + uint64_t static_off) +{ + VblkReq req; + VblkSector sector; + uint64_t off =3D 0; + char *buf =3D NULL; + uint8_t ret =3D VBLK_RET_FAILED; + int r; + + cpu_physical_memory_read(value, &req, sizeof(req)); + le2cpu_req(&req); + + if (req.sector.len !=3D sizeof(sector)) { + ret =3D VBLK_RET_FAILED; + goto out; + } + + /* Read the vblk command */ + cpu_physical_memory_read(req.sector.addr, §or, sizeof(sector)); + le2cpu_sector(§or); + + off =3D sector.sector * 512ULL + static_off; + + /* Sanity check that we're not allocating bogus sizes */ + if (req.data.len > 128 * MiB) { + goto out; + } + + buf =3D g_malloc0(req.data.len); + switch (req.data.flags) { + case VBLK_DATA_FLAGS_READ: + r =3D blk_pread(blk, off, req.data.len, buf, 0); + trace_bdif_vblk_read(devid =3D=3D DEVID_AUX ? "aux" : "root", + req.data.addr, off, req.data.len, r); + if (r < 0) { + goto out; + } + cpu_physical_memory_write(req.data.addr, buf, req.data.len); + ret =3D VBLK_RET_SUCCESS; + break; + case VBLK_DATA_FLAGS_WRITE: + /* Not needed, iBoot only reads */ + break; + default: + break; + } + +out: + g_free(buf); + cpu_physical_memory_write(req.retval.addr, &ret, 1); +} + +static void bdif_write(void *opaque, hwaddr offset, + uint64_t value, unsigned size) +{ + VMAppleBdifState *s =3D opaque; + uint64_t devid =3D (offset & REG_DEVID_MASK); + + trace_bdif_write(offset, size, value); + + switch (offset & ~REG_DEVID_MASK) { + case REG_CMD: + switch (devid) { + case DEVID_ROOT: + vblk_cmd(devid, s->root, value, 0x0); + break; + case DEVID_AUX: + vblk_cmd(devid, s->aux, value, 0x0); + break; + } + break; + } +} + +static const MemoryRegionOps bdif_ops =3D { + .read =3D bdif_read, + .write =3D bdif_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + }, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + }, +}; + +static void bdif_init(Object *obj) +{ + VMAppleBdifState *s =3D VMAPPLE_BDIF(obj); + + memory_region_init_io(&s->mmio, obj, &bdif_ops, obj, + "VMApple Backdoor Interface", VMAPPLE_BDIF_SIZE); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static Property bdif_properties[] =3D { + DEFINE_PROP_DRIVE("aux", VMAppleBdifState, aux), + DEFINE_PROP_DRIVE("root", VMAppleBdifState, root), + DEFINE_PROP_END_OF_LIST(), +}; + +static void bdif_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->desc =3D "VMApple Backdoor Interface"; + device_class_set_props(dc, bdif_properties); +} + +static const TypeInfo bdif_info =3D { + .name =3D TYPE_VMAPPLE_BDIF, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(VMAppleBdifState), + .instance_init =3D bdif_init, + .class_init =3D bdif_class_init, +}; + +static void bdif_register_types(void) +{ + type_register_static(&bdif_info); +} + +type_init(bdif_register_types) diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build index bcd4dcb28d2..d4624713deb 100644 --- a/hw/vmapple/meson.build +++ b/hw/vmapple/meson.build @@ -1 +1,2 @@ system_ss.add(when: 'CONFIG_VMAPPLE_AES', if_true: files('aes.c')) +system_ss.add(when: 'CONFIG_VMAPPLE_BDIF', if_true: files('bdif.c')) diff --git a/hw/vmapple/trace-events b/hw/vmapple/trace-events index 12757bc0852..6c3fdb389a6 100644 --- a/hw/vmapple/trace-events +++ b/hw/vmapple/trace-events @@ -16,3 +16,8 @@ aes_2_write_unknown(uint64_t offset) "offset=3D0x%"PRIx64 aes_2_write(uint64_t offset, uint64_t val) "offset=3D0x%"PRIx64" val=3D0x%= "PRIx64 aes_dump_data(const char *desc, const char *hex) "%s%s" =20 +# bdif.c +bdif_read(uint64_t offset, uint32_t size, uint64_t value) "offset=3D0x%"PR= Ix64" size=3D0x%x value=3D0x%"PRIx64 +bdif_write(uint64_t offset, uint32_t size, uint64_t value) "offset=3D0x%"P= RIx64" size=3D0x%x value=3D0x%"PRIx64 +bdif_vblk_read(const char *dev, uint64_t addr, uint64_t offset, uint32_t l= en, int r) "dev=3D%s addr=3D0x%"PRIx64" off=3D0x%"PRIx64" size=3D0x%x r=3D%= d" + diff --git a/include/hw/vmapple/vmapple.h b/include/hw/vmapple/vmapple.h new file mode 100644 index 00000000000..a4c87b166d5 --- /dev/null +++ b/include/hw/vmapple/vmapple.h @@ -0,0 +1,15 @@ +/* + * Devices specific to the VMApple machine type + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_VMAPPLE_VMAPPLE_H +#define HW_VMAPPLE_VMAPPLE_H + +#define TYPE_VMAPPLE_BDIF "vmapple-bdif" + +#endif /* HW_VMAPPLE_VMAPPLE_H */ --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729766007; cv=none; d=zohomail.com; s=zohoarc; b=N5GNsqbbxphTWEM6Y3AQYc6nicV2QME7SlhWmwHXbPUe9Wb69bD/OGO7u6BQwlurTIkAkX3+WbHvx8rhqgbizO+Zoa2yNI0yiWXKawru+NPeDlqiF45Ln8cbTnEggfyToV8+62TPo9Ma8pAkd/y2lzBIUb3yzb8cEVycLiN+paE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729766007; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0nReO9r9RrbUk1hvaDfJ9iU/fN5yRbIfPdkL/UxhNLg=; b=VFf1UgNrShaIM0YHGPEWVtgXx89ojGXz4tnGhm8Bs8h76Cl5hhmC7fi7w30vGZErxoIm9sEr5ecp1S4hMwLxPzLLIHvOE2OYeMpdMBMLcBhQKO7RsiUyZFvnRPYz5yxI0CPVJ9pPLfjo0pmVEIneI0tVQh6y1ImexBfKEAJqviY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17297660070108.94493744434942; Thu, 24 Oct 2024 03:33:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5O-00017C-DU; Thu, 24 Oct 2024 06:28:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v5L-00012N-C6 for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:55 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v5J-0008IZ-Du for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:55 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a9acafdb745so153083566b.0 for ; Thu, 24 Oct 2024 03:28:52 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765732; x=1730370532; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0nReO9r9RrbUk1hvaDfJ9iU/fN5yRbIfPdkL/UxhNLg=; b=Xlt5OIUrLFQbm13tXIROyivFsqYkH7W4bNZS8Vr3o+bNSBFJC1CKJw0j7G+3eTDMqD WeXgzEM4dpPjXAjyzwmxcI50bDsEhfqO8c6hodaiTCLGU/0qv0EuHzXcebElysEq03LE ANFukznq35YS3cVcu2jUHBiwfxjXeGyIdxabOIkk/+kO3TUXJUf0+jjMTZtVmDzs9Srn U/Wn517umiV4vldFcC1w2H5IY+QeUat3FMy7De+c7V1a2sS/BxzSYUhRh9ufb6SVblst 4HvAQfimFOl0oBVJ3UC7/KKPNEArDAgSyTVUlFJOUXinGPVPsUx2qkOaVqODR8/G8t7p J/aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765732; x=1730370532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0nReO9r9RrbUk1hvaDfJ9iU/fN5yRbIfPdkL/UxhNLg=; b=VwmfBjpKatizWCvWwTDEVigIVzQqgNGibj43bZ6C3p9ug9ZcbQuIb9hv2SxE7y77XK XRJkRNdTHV79POPS9aWUreeZLouH2Iv+LMZNCQNls7SEOChobwJXildhPp/+ike5Sz5Q nI4wBlzlfcI1LuELPoq3lPVAamOqQyb/pwe0Ds8bBdpr0BAhWj6L+lMw9sUavyVRvra7 bFPBQMrAQJXD+G2Hr9zsOx/zm2Z5ce2Pycj8lYELy5waS+mjRFIxaltVtO07Bgg7FiD/ tPrMXKNLeNfIj03GzFt0uSgEqrFJRE4m5mjTREAR6tFYjdWME7UTIbcet7fj8tVWMEkT oh9w== X-Gm-Message-State: AOJu0YzfmxmJAXBvHKaalTx8BMozbEiezPRoqdV+xePq+23Bqz8iZ6q4 7oMg79whniG42m4rUT6ifmV5Gds5Z6WTWvqC0YxBFiJXMXCrJWhe6+9HQmqnVWasuDqBynanPE3 rpg== X-Google-Smtp-Source: AGHT+IGHpK9VgCKrLDKOqmStQzxC8yg4Uc6VdrJTE5SlWfLSJW35I2wQF2EzsXfU7Ev0vNMBJfkytg== X-Received: by 2002:a17:907:7f0e:b0:a9a:cf0:8fd4 with SMTP id a640c23a62f3a-a9ad19d4c3dmr168980766b.18.1729765731784; Thu, 24 Oct 2024 03:28:51 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, Alexander Graf Subject: [PATCH v4 12/15] hw/vmapple/cfg: Introduce vmapple cfg region Date: Thu, 24 Oct 2024 12:28:10 +0200 Message-Id: <20241024102813.9855-13-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::62f; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62f.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729766008221116600 From: Alexander Graf Instead of device tree or other more standardized means, VMApple passes platform configuration to the first stage boot loader in a binary encoded format that resides at a dedicated RAM region in physical address space. This patch models this configuration space as a qdev device which we can then map at the fixed location in the address space. That way, we can influence and annotate all configuration fields easily. Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan --- v3: * Replaced legacy device reset method with Resettable method v4: * Fixed initialisation of default values for properties * Dropped superfluous endianness conversions * Moved most header code to .c, device name #define goes in vmapple.h hw/vmapple/Kconfig | 3 + hw/vmapple/cfg.c | 197 +++++++++++++++++++++++++++++++++++ hw/vmapple/meson.build | 1 + include/hw/vmapple/vmapple.h | 2 + 4 files changed, 203 insertions(+) create mode 100644 hw/vmapple/cfg.c diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index 68f88876eb9..8bbeb9a9237 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -4,3 +4,6 @@ config VMAPPLE_AES config VMAPPLE_BDIF bool =20 +config VMAPPLE_CFG + bool + diff --git a/hw/vmapple/cfg.c b/hw/vmapple/cfg.c new file mode 100644 index 00000000000..aeb76ba363c --- /dev/null +++ b/hw/vmapple/cfg.c @@ -0,0 +1,197 @@ +/* + * VMApple Configuration Region + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/vmapple/vmapple.h" +#include "hw/sysbus.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "net/net.h" + +OBJECT_DECLARE_SIMPLE_TYPE(VMAppleCfgState, VMAPPLE_CFG) + +#define VMAPPLE_CFG_SIZE 0x00010000 + +typedef struct VMAppleCfg { + uint32_t version; /* 0x000 */ + uint32_t nr_cpus; /* 0x004 */ + uint32_t unk1; /* 0x008 */ + uint32_t unk2; /* 0x00c */ + uint32_t unk3; /* 0x010 */ + uint32_t unk4; /* 0x014 */ + uint64_t ecid; /* 0x018 */ + uint64_t ram_size; /* 0x020 */ + uint32_t run_installer1; /* 0x028 */ + uint32_t unk5; /* 0x02c */ + uint32_t unk6; /* 0x030 */ + uint32_t run_installer2; /* 0x034 */ + uint32_t rnd; /* 0x038 */ + uint32_t unk7; /* 0x03c */ + MACAddr mac_en0; /* 0x040 */ + uint8_t pad1[2]; + MACAddr mac_en1; /* 0x048 */ + uint8_t pad2[2]; + MACAddr mac_wifi0; /* 0x050 */ + uint8_t pad3[2]; + MACAddr mac_bt0; /* 0x058 */ + uint8_t pad4[2]; + uint8_t reserved[0xa0]; /* 0x060 */ + uint32_t cpu_ids[0x80]; /* 0x100 */ + uint8_t scratch[0x200]; /* 0x180 */ + char serial[32]; /* 0x380 */ + char unk8[32]; /* 0x3a0 */ + char model[32]; /* 0x3c0 */ + uint8_t unk9[32]; /* 0x3e0 */ + uint32_t unk10; /* 0x400 */ + char soc_name[32]; /* 0x404 */ +} VMAppleCfg; + +struct VMAppleCfgState { + SysBusDevice parent_obj; + VMAppleCfg cfg; + + MemoryRegion mem; + char *serial; + char *model; + char *soc_name; +}; + +static void vmapple_cfg_reset(Object *obj, ResetType type) +{ + VMAppleCfgState *s =3D VMAPPLE_CFG(obj); + VMAppleCfg *cfg; + + cfg =3D memory_region_get_ram_ptr(&s->mem); + memset((void *)cfg, 0, VMAPPLE_CFG_SIZE); + *cfg =3D s->cfg; +} + +static bool strlcpy_set_error(char *restrict dst, const char *restrict src, + size_t dst_size, Error **errp, + const char *parent_func, const char *locatio= n, + const char *buffer_name) +{ + size_t len; + + len =3D g_strlcpy(dst, src, dst_size); + if (len < dst_size) { /* len does not count nul terminator */ + return true; + } + + error_setg(errp, + "strlcpy_set_error: %s (%s): Destination buffer %s too smal= l " + "(need %zu, have %zu)", + parent_func, location, buffer_name, len + 1, dst_size); + return false; +} + +/* + * String copying wrapper that returns and reports a runtime error in + * case of truncation due to insufficient destination buffer space. + */ +#define strlcpy_array_return_error(dst_array, src, errp) \ + do { \ + if (!strlcpy_set_error((dst_array), (src), ARRAY_SIZE(dst_array), = (errp),\ + __func__, stringify(__LINE__), # dst_array)= ) { \ + return; \ + } \ + } while (0) + +static void vmapple_cfg_realize(DeviceState *dev, Error **errp) +{ + VMAppleCfgState *s =3D VMAPPLE_CFG(dev); + uint32_t i; + + if (!s->serial) { + s->serial =3D g_strdup("1234"); + } + if (!s->model) { + s->model =3D g_strdup("VM0001"); + } + if (!s->soc_name) { + s->soc_name =3D g_strdup("Apple M1 (Virtual)"); + } + + strlcpy_array_return_error(s->cfg.serial, s->serial, errp); + strlcpy_array_return_error(s->cfg.model, s->model, errp); + strlcpy_array_return_error(s->cfg.soc_name, s->soc_name, errp); + strlcpy_array_return_error(s->cfg.unk8, "D/A", errp); + s->cfg.version =3D 2; + s->cfg.unk1 =3D 1; + s->cfg.unk2 =3D 1; + s->cfg.unk3 =3D 0x20; + s->cfg.unk4 =3D 0; + s->cfg.unk5 =3D 1; + s->cfg.unk6 =3D 1; + s->cfg.unk7 =3D 0; + s->cfg.unk10 =3D 1; + + if (s->cfg.nr_cpus > ARRAY_SIZE(s->cfg.cpu_ids)) { + error_setg(errp, + "Failed to create %u CPUs, vmapple machine supports %zu= max", + s->cfg.nr_cpus, ARRAY_SIZE(s->cfg.cpu_ids)); + return; + } + for (i =3D 0; i < s->cfg.nr_cpus; i++) { + s->cfg.cpu_ids[i] =3D i; + } +} + +static void vmapple_cfg_init(Object *obj) +{ + VMAppleCfgState *s =3D VMAPPLE_CFG(obj); + + memory_region_init_ram(&s->mem, obj, "VMApple Config", VMAPPLE_CFG_SIZ= E, + &error_fatal); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mem); +} + +static Property vmapple_cfg_properties[] =3D { + DEFINE_PROP_UINT32("nr-cpus", VMAppleCfgState, cfg.nr_cpus, 1), + DEFINE_PROP_UINT64("ecid", VMAppleCfgState, cfg.ecid, 0), + DEFINE_PROP_UINT64("ram-size", VMAppleCfgState, cfg.ram_size, 0), + DEFINE_PROP_UINT32("run_installer1", VMAppleCfgState, cfg.run_installe= r1, 0), + DEFINE_PROP_UINT32("run_installer2", VMAppleCfgState, cfg.run_installe= r2, 0), + DEFINE_PROP_UINT32("rnd", VMAppleCfgState, cfg.rnd, 0), + DEFINE_PROP_MACADDR("mac-en0", VMAppleCfgState, cfg.mac_en0), + DEFINE_PROP_MACADDR("mac-en1", VMAppleCfgState, cfg.mac_en1), + DEFINE_PROP_MACADDR("mac-wifi0", VMAppleCfgState, cfg.mac_wifi0), + DEFINE_PROP_MACADDR("mac-bt0", VMAppleCfgState, cfg.mac_bt0), + DEFINE_PROP_STRING("serial", VMAppleCfgState, serial), + DEFINE_PROP_STRING("model", VMAppleCfgState, model), + DEFINE_PROP_STRING("soc_name", VMAppleCfgState, soc_name), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vmapple_cfg_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + dc->realize =3D vmapple_cfg_realize; + dc->desc =3D "VMApple Configuration Region"; + device_class_set_props(dc, vmapple_cfg_properties); + rc->phases.hold =3D vmapple_cfg_reset; +} + +static const TypeInfo vmapple_cfg_info =3D { + .name =3D TYPE_VMAPPLE_CFG, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(VMAppleCfgState), + .instance_init =3D vmapple_cfg_init, + .class_init =3D vmapple_cfg_class_init, +}; + +static void vmapple_cfg_register_types(void) +{ + type_register_static(&vmapple_cfg_info); +} + +type_init(vmapple_cfg_register_types) diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build index d4624713deb..64b78693a31 100644 --- a/hw/vmapple/meson.build +++ b/hw/vmapple/meson.build @@ -1,2 +1,3 @@ system_ss.add(when: 'CONFIG_VMAPPLE_AES', if_true: files('aes.c')) system_ss.add(when: 'CONFIG_VMAPPLE_BDIF', if_true: files('bdif.c')) +system_ss.add(when: 'CONFIG_VMAPPLE_CFG', if_true: files('cfg.c')) diff --git a/include/hw/vmapple/vmapple.h b/include/hw/vmapple/vmapple.h index a4c87b166d5..984281b6a67 100644 --- a/include/hw/vmapple/vmapple.h +++ b/include/hw/vmapple/vmapple.h @@ -12,4 +12,6 @@ =20 #define TYPE_VMAPPLE_BDIF "vmapple-bdif" =20 +#define TYPE_VMAPPLE_CFG "vmapple-cfg" + #endif /* HW_VMAPPLE_VMAPPLE_H */ --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729765873; cv=none; d=zohomail.com; s=zohoarc; b=a0m8meu7/VZOjh43QzHN32AsmOhe+RXx/uumtcpwjg9DJgFNPLilo+r45Fwnsf0526PAeq0gstFRQonSdmsdo4H9VmQw9f1zG+Hq95M8xtXlmTo6hW+Y3YQjNJ1tvYPjLY6OFVCmaKdfbmzGpjjG+h+RzGvZk1MqAmbJ4j1ZsNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729765873; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ujv8zlJ6TnvpJffDSdKWrcVLbeFkBxDBjcdWqMuqf/Y=; b=ZmkidbPcAxcna0rL1deQhzw/kHNGpGvSdk71u92gzZ+x4Bk1XBKz8Rpc5Jo5B6zZ08IkowlKR91QLgJ7ekGGGC6DHbIjA/4JT3bFlL1gG7mrvvwIwvbfVyc3ucusSogfZ7EsPxvGrjhmlfaFV4aj8RF7ec0/cmslspAsAEAXF5Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729765873743499.6735513369016; Thu, 24 Oct 2024 03:31:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5P-00018C-QX; Thu, 24 Oct 2024 06:29:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v5N-00016T-Vv for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:58 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v5L-0008JV-Ct for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:57 -0400 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5c97c7852e8so943721a12.1 for ; Thu, 24 Oct 2024 03:28:54 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765734; x=1730370534; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ujv8zlJ6TnvpJffDSdKWrcVLbeFkBxDBjcdWqMuqf/Y=; b=1n1QrndNpWvIYOwhhzh5YIJ8LWDrlsU5JCQfwOigvLyy+YndO4+qoxP68xLnYr9BK5 gGOQgdW5Llb0nRYDRv8bxdhnyVxk+sOvIeCtw/9q8lxh2/8BzivGQzQBbcJDf+Mndxgz OWjj0dAfHHSjvdPuRcdyuHpKIlFIGUw8QkV5pk0JcxqurXfIugJZ01tFrRFritioqIsD QNZxhmk0dkiyhjgQg0XCxxKYPubk5IWKto2My0gK6SUETnwsSQnXZPy0eFpJeNVwJ/oN BPpkornhDz8ZJvh6mc528j5IXkV/a6Te3l9FG6dyzdIb9YfT5Danff4LDl+Ts2u0lS1O 7c/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765734; x=1730370534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ujv8zlJ6TnvpJffDSdKWrcVLbeFkBxDBjcdWqMuqf/Y=; b=nwURKq5W16PG8g7E8ckj+0k+E1pq6a2FuCzcmC9xuJOhoanR20tQp04oxJgbMlXol/ ccrCjRBQ9McpB7qQhJp8K0nD0W2xFeKzX7NA3Fspt3ZEzC3E+Ir/EQTw16h+2lI1JsBw 1Z2orWQ2TjtPxy73sUm+uOzLQMoLbWtAuMMyIP0GHXiRv6tRlgo/zHqhAsMKz956PXuh RWuPrzgs+Dg9zX6hSINFql0DmPT6j7BhtBBUrqmazOpKQ8nJY9XfAv2wocN2nQkBDPgf Xc3d8yBky/M0lL2wN5sBdObrZHlmNRmKLm02FTyeJ9W2khfwbTCuFqKCo9N+2DY9Gyts Zu2A== X-Gm-Message-State: AOJu0YxYGDKAB2CvVtzeBhwPuNPb3zFsmwYLzH53WXbd64MWrN2JRoh9 7PKu9ScX55KaS8jtakQjRUs50znv5fLu2GTzVQjirumczz1rObYVh9esoBE3RAVus9W5GIVASCp GFA== X-Google-Smtp-Source: AGHT+IGutW5gH7uqwb9wVAP82ivBz1I2tTvRchyKwX71nIKwBSsN+qbwa+n8WalAsfftj+d736tNVA== X-Received: by 2002:a17:907:7282:b0:a9a:37fe:e7d0 with SMTP id a640c23a62f3a-a9abf99cf5dmr485967266b.64.1729765733793; Thu, 24 Oct 2024 03:28:53 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, Alexander Graf Subject: [PATCH v4 13/15] hw/vmapple/virtio-blk: Add support for apple virtio-blk Date: Thu, 24 Oct 2024 12:28:11 +0200 Message-Id: <20241024102813.9855-14-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::52a; envelope-from=phil@philjordan.eu; helo=mail-ed1-x52a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729765876076116600 From: Alexander Graf Apple has its own virtio-blk PCI device ID where it deviates from the official virtio-pci spec slightly: It puts a new "apple type" field at a static offset in config space and introduces a new barrier command. This patch first creates a mechanism for virtio-blk downstream classes to handle unknown commands. It then creates such a downstream class and a new vmapple-virtio-blk-pci class which support the additional apple type config identifier as well as the barrier command. It then exposes 2 subclasses from that that we can use to expose root and aux virtio-blk devices: "vmapple-virtio-root" and "vmapple-virtio-aux". Signed-off-by: Alexander Graf Signed-off-by: Phil Dennis-Jordan --- v4: * Use recommended object type declaration pattern. * Correctly log unimplemented code paths. * Most header code moved to .c, type name #defines moved to vmapple.h hw/block/virtio-blk.c | 19 ++- hw/vmapple/Kconfig | 3 + hw/vmapple/meson.build | 1 + hw/vmapple/virtio-blk.c | 233 +++++++++++++++++++++++++++++++++ include/hw/pci/pci_ids.h | 1 + include/hw/virtio/virtio-blk.h | 12 +- include/hw/vmapple/vmapple.h | 4 + 7 files changed, 268 insertions(+), 5 deletions(-) create mode 100644 hw/vmapple/virtio-blk.c diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 9166d7974d4..9e8337bb639 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -50,12 +50,12 @@ static void virtio_blk_init_request(VirtIOBlock *s, Vir= tQueue *vq, req->mr_next =3D NULL; } =20 -static void virtio_blk_free_request(VirtIOBlockReq *req) +void virtio_blk_free_request(VirtIOBlockReq *req) { g_free(req); } =20 -static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char sta= tus) +void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status) { VirtIOBlock *s =3D req->dev; VirtIODevice *vdev =3D VIRTIO_DEVICE(s); @@ -966,8 +966,18 @@ static int virtio_blk_handle_request(VirtIOBlockReq *r= eq, MultiReqBuffer *mrb) break; } default: - virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP); - virtio_blk_free_request(req); + { + /* + * Give subclasses a chance to handle unknown requests. This way t= he + * class lookup is not in the hot path. + */ + VirtIOBlkClass *vbk =3D VIRTIO_BLK_GET_CLASS(s); + if (!vbk->handle_unknown_request || + !vbk->handle_unknown_request(req, mrb, type)) { + virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP); + virtio_blk_free_request(req); + } + } } return 0; } @@ -2044,6 +2054,7 @@ static const TypeInfo virtio_blk_info =3D { .instance_size =3D sizeof(VirtIOBlock), .instance_init =3D virtio_blk_instance_init, .class_init =3D virtio_blk_class_init, + .class_size =3D sizeof(VirtIOBlkClass), }; =20 static void virtio_register_types(void) diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index 8bbeb9a9237..bcd1be63e3c 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -7,3 +7,6 @@ config VMAPPLE_BDIF config VMAPPLE_CFG bool =20 +config VMAPPLE_VIRTIO_BLK + bool + diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build index 64b78693a31..bf17cf906c9 100644 --- a/hw/vmapple/meson.build +++ b/hw/vmapple/meson.build @@ -1,3 +1,4 @@ system_ss.add(when: 'CONFIG_VMAPPLE_AES', if_true: files('aes.c')) system_ss.add(when: 'CONFIG_VMAPPLE_BDIF', if_true: files('bdif.c')) system_ss.add(when: 'CONFIG_VMAPPLE_CFG', if_true: files('cfg.c')) +system_ss.add(when: 'CONFIG_VMAPPLE_VIRTIO_BLK', if_true: files('virtio-b= lk.c')) diff --git a/hw/vmapple/virtio-blk.c b/hw/vmapple/virtio-blk.c new file mode 100644 index 00000000000..3a8b47bc55f --- /dev/null +++ b/hw/vmapple/virtio-blk.c @@ -0,0 +1,233 @@ +/* + * VMApple specific VirtIO Block implementation + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + * VMApple uses almost standard VirtIO Block, but with a few key differenc= es: + * + * - Different PCI device/vendor ID + * - An additional "type" identifier to differentiate AUX and Root volumes + * - An additional BARRIER command + */ + +#include "qemu/osdep.h" +#include "hw/vmapple/vmapple.h" +#include "hw/virtio/virtio-blk.h" +#include "hw/virtio/virtio-pci.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" + +OBJECT_DECLARE_TYPE(VMAppleVirtIOBlk, VMAppleVirtIOBlkClass, VMAPPLE_VIRTI= O_BLK) + +typedef struct VMAppleVirtIOBlkClass { + /*< private >*/ + VirtIOBlkClass parent; + /*< public >*/ + void (*get_config)(VirtIODevice *vdev, uint8_t *config); +} VMAppleVirtIOBlkClass; + +typedef struct VMAppleVirtIOBlk { + /* */ + VirtIOBlock parent_obj; + + /* */ + uint32_t apple_type; +} VMAppleVirtIOBlk; + +/* + * vmapple-virtio-blk-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VMAPPLE_VIRTIO_BLK_PCI "vmapple-virtio-blk-pci-base" +OBJECT_DECLARE_SIMPLE_TYPE(VMAppleVirtIOBlkPCI, VMAPPLE_VIRTIO_BLK_PCI) + +#define VIRTIO_BLK_T_APPLE_BARRIER 0x10000 + +#define VIRTIO_APPLE_TYPE_ROOT 1 +#define VIRTIO_APPLE_TYPE_AUX 2 + +static bool vmapple_virtio_blk_handle_unknown_request(VirtIOBlockReq *req, + MultiReqBuffer *mrb, + uint32_t type) +{ + switch (type) { + case VIRTIO_BLK_T_APPLE_BARRIER: + qemu_log_mask(LOG_UNIMP, "%s: Barrier requests are currently no-op= s\n", + __func__); + virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); + virtio_blk_free_request(req); + return true; + default: + return false; + } +} + +/* + * VMApple virtio-blk uses the same config format as normal virtio, with o= ne + * exception: It adds an "apple type" specififer at the same location that + * the spec reserves for max_secure_erase_sectors. Let's hook into the + * get_config code path here, run it as usual and then patch in the apple = type. + */ +static void vmapple_virtio_blk_get_config(VirtIODevice *vdev, uint8_t *con= fig) +{ + VMAppleVirtIOBlk *dev =3D VMAPPLE_VIRTIO_BLK(vdev); + VMAppleVirtIOBlkClass *vvbk =3D VMAPPLE_VIRTIO_BLK_GET_CLASS(dev); + struct virtio_blk_config *blkcfg =3D (struct virtio_blk_config *)confi= g; + + vvbk->get_config(vdev, config); + + g_assert(dev->parent_obj.config_size >=3D endof(struct virtio_blk_conf= ig, zoned)); + + /* Apple abuses the field for max_secure_erase_sectors as type id */ + blkcfg->max_secure_erase_sectors =3D dev->apple_type; +} + +static Property vmapple_virtio_blk_properties[] =3D { + DEFINE_PROP_UINT32("apple-type", VMAppleVirtIOBlk, apple_type, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vmapple_virtio_blk_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtIOBlkClass *vbk =3D VIRTIO_BLK_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + VMAppleVirtIOBlkClass *vvbk =3D VMAPPLE_VIRTIO_BLK_CLASS(klass); + + vbk->handle_unknown_request =3D vmapple_virtio_blk_handle_unknown_requ= est; + vvbk->get_config =3D vdc->get_config; + vdc->get_config =3D vmapple_virtio_blk_get_config; + device_class_set_props(dc, vmapple_virtio_blk_properties); +} + +static const TypeInfo vmapple_virtio_blk_info =3D { + .name =3D TYPE_VMAPPLE_VIRTIO_BLK, + .parent =3D TYPE_VIRTIO_BLK, + .instance_size =3D sizeof(VMAppleVirtIOBlk), + .class_init =3D vmapple_virtio_blk_class_init, +}; + +/* PCI Devices */ + +struct VMAppleVirtIOBlkPCI { + VirtIOPCIProxy parent_obj; + VMAppleVirtIOBlk vdev; + uint32_t apple_type; +}; + + +static Property vmapple_virtio_blk_pci_properties[] =3D { + DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), + DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vmapple_virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error= **errp) +{ + VMAppleVirtIOBlkPCI *dev =3D VMAPPLE_VIRTIO_BLK_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + VirtIOBlkConf *conf =3D &dev->vdev.parent_obj.conf; + + if (conf->num_queues =3D=3D VIRTIO_BLK_AUTO_NUM_QUEUES) { + conf->num_queues =3D virtio_pci_optimal_num_queues(0); + } + + if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors =3D conf->num_queues + 1; + } + + /* + * We don't support zones, but we need the additional config space siz= e. + * Let's just expose the feature so the rest of the virtio-blk logic + * allocates enough space for us. The guest will ignore zones anyway. + */ + virtio_add_feature(&dev->vdev.parent_obj.host_features, VIRTIO_BLK_F_Z= ONED); + /* Propagate the apple type down to the virtio-blk device */ + qdev_prop_set_uint32(DEVICE(&dev->vdev), "apple-type", dev->apple_type= ); + /* and spawn the virtio-blk device */ + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); + + /* + * The virtio-pci machinery adjusts its vendor/device ID based on whet= her + * we support modern or legacy virtio. Let's patch it back to the Apple + * identifiers here. + */ + pci_config_set_vendor_id(vpci_dev->pci_dev.config, PCI_VENDOR_ID_APPLE= ); + pci_config_set_device_id(vpci_dev->pci_dev.config, + PCI_DEVICE_ID_APPLE_VIRTIO_BLK); +} + +static void vmapple_virtio_blk_pci_class_init(ObjectClass *klass, void *da= ta) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + device_class_set_props(dc, vmapple_virtio_blk_pci_properties); + k->realize =3D vmapple_virtio_blk_pci_realize; + pcidev_k->vendor_id =3D PCI_VENDOR_ID_APPLE; + pcidev_k->device_id =3D PCI_DEVICE_ID_APPLE_VIRTIO_BLK; + pcidev_k->revision =3D VIRTIO_PCI_ABI_VERSION; + pcidev_k->class_id =3D PCI_CLASS_STORAGE_SCSI; +} + +static void vmapple_virtio_blk_pci_instance_init(Object *obj) +{ + VMAppleVirtIOBlkPCI *dev =3D VMAPPLE_VIRTIO_BLK_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VMAPPLE_VIRTIO_BLK); +} + +static const VirtioPCIDeviceTypeInfo vmapple_virtio_blk_pci_info =3D { + .base_name =3D TYPE_VMAPPLE_VIRTIO_BLK_PCI, + .generic_name =3D "vmapple-virtio-blk-pci", + .instance_size =3D sizeof(VMAppleVirtIOBlkPCI), + .instance_init =3D vmapple_virtio_blk_pci_instance_init, + .class_init =3D vmapple_virtio_blk_pci_class_init, +}; + +static void vmapple_virtio_root_instance_init(Object *obj) +{ + VMAppleVirtIOBlkPCI *dev =3D VMAPPLE_VIRTIO_BLK_PCI(obj); + + dev->apple_type =3D VIRTIO_APPLE_TYPE_ROOT; +} + +static const TypeInfo vmapple_virtio_root_info =3D { + .name =3D TYPE_VMAPPLE_VIRTIO_ROOT, + .parent =3D "vmapple-virtio-blk-pci", + .instance_size =3D sizeof(VMAppleVirtIOBlkPCI), + .instance_init =3D vmapple_virtio_root_instance_init, +}; + +static void vmapple_virtio_aux_instance_init(Object *obj) +{ + VMAppleVirtIOBlkPCI *dev =3D VMAPPLE_VIRTIO_BLK_PCI(obj); + + dev->apple_type =3D VIRTIO_APPLE_TYPE_AUX; +} + +static const TypeInfo vmapple_virtio_aux_info =3D { + .name =3D TYPE_VMAPPLE_VIRTIO_AUX, + .parent =3D "vmapple-virtio-blk-pci", + .instance_size =3D sizeof(VMAppleVirtIOBlkPCI), + .instance_init =3D vmapple_virtio_aux_instance_init, +}; + +static void vmapple_virtio_blk_register_types(void) +{ + type_register_static(&vmapple_virtio_blk_info); + virtio_pci_types_register(&vmapple_virtio_blk_pci_info); + type_register_static(&vmapple_virtio_root_info); + type_register_static(&vmapple_virtio_aux_info); +} + +type_init(vmapple_virtio_blk_register_types) diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h index f1a53fea8d6..33e2898be95 100644 --- a/include/hw/pci/pci_ids.h +++ b/include/hw/pci/pci_ids.h @@ -191,6 +191,7 @@ #define PCI_DEVICE_ID_APPLE_UNI_N_AGP 0x0020 #define PCI_DEVICE_ID_APPLE_U3_AGP 0x004b #define PCI_DEVICE_ID_APPLE_UNI_N_GMAC 0x0021 +#define PCI_DEVICE_ID_APPLE_VIRTIO_BLK 0x1a00 =20 #define PCI_VENDOR_ID_SUN 0x108e #define PCI_DEVICE_ID_SUN_EBUS 0x1000 diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 5c14110c4b1..28d5046ea6c 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -24,7 +24,7 @@ #include "qapi/qapi-types-virtio.h" =20 #define TYPE_VIRTIO_BLK "virtio-blk-device" -OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBlock, VIRTIO_BLK) +OBJECT_DECLARE_TYPE(VirtIOBlock, VirtIOBlkClass, VIRTIO_BLK) =20 /* This is the last element of the write scatter-gather list */ struct virtio_blk_inhdr @@ -100,6 +100,16 @@ typedef struct MultiReqBuffer { bool is_write; } MultiReqBuffer; =20 +typedef struct VirtIOBlkClass { + /*< private >*/ + VirtioDeviceClass parent; + /*< public >*/ + bool (*handle_unknown_request)(VirtIOBlockReq *req, MultiReqBuffer *mr= b, + uint32_t type); +} VirtIOBlkClass; + void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); +void virtio_blk_free_request(VirtIOBlockReq *req); +void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status); =20 #endif diff --git a/include/hw/vmapple/vmapple.h b/include/hw/vmapple/vmapple.h index 984281b6a67..266dc826d38 100644 --- a/include/hw/vmapple/vmapple.h +++ b/include/hw/vmapple/vmapple.h @@ -14,4 +14,8 @@ =20 #define TYPE_VMAPPLE_CFG "vmapple-cfg" =20 +#define TYPE_VMAPPLE_VIRTIO_BLK "vmapple-virtio-blk" +#define TYPE_VMAPPLE_VIRTIO_ROOT "vmapple-virtio-root" +#define TYPE_VMAPPLE_VIRTIO_AUX "vmapple-virtio-aux" + #endif /* HW_VMAPPLE_VMAPPLE_H */ --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729765993; cv=none; d=zohomail.com; s=zohoarc; b=L7FZP0CQxnuCiB97J1PmIFxgMXRmUAuXh+0uXqcLhX+yP9odv0h8Vi1XfJj/gW7Ffije6jfaa0oueNXhmvXnOEAQUZ2pMxBog93jLKH5KrDu14IH5/zXrkIHBXJRfjEdkYKWPeO+LOHafiXHQ3qvvBxZs++W+GfB9JTkyI6baI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729765993; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vQg8pMZdlj0Iio1vObJ7qVnikTueMhpFssiBJNcinU0=; b=h4Hx17Mn5T99C12o6K4zAQUAMgVLrbOMTIkywfmlsBqA8V+YdSwavVUiwO4Vt0tsrto4ITA+2TzxOrj0bj02m2QDE9mD/zkxWrDSsRzHDoDGH1Se67bjuhuWCKR7eZ3dvrpCNfmin72SyxCnNqPdxEP3JRzaUGku8o2yws7BqCI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729765993359491.95378305968575; Thu, 24 Oct 2024 03:33:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5R-0001Cn-J1; Thu, 24 Oct 2024 06:29:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v5P-00018S-TI for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:29:00 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v5N-0008KQ-JB for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:28:59 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a9a3dc089d8so92355866b.3 for ; Thu, 24 Oct 2024 03:28:57 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765736; x=1730370536; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vQg8pMZdlj0Iio1vObJ7qVnikTueMhpFssiBJNcinU0=; b=Q2PyAYljOwDUn6VuIV9YEsDdNbHm77gmZWbuqXKzIsK2dZGOM9eQR8T4RpnvzAPoQf f64mOGa0TX6my0dDkYEVb4B0mIg2HoHJ0+K9hI6VFqIhqg4xXa4+uS8bI5zvCVlPyP65 uMCYEZoGmoQZAc4NuqxnBQyWrip5X4dlVvH+aqkS1QYfve/RGEMMtk2T558P49g7+q7T Qjaopw7tao2v95kXEckRMVwAIyq7j1NIsAt7/wUooJtecjXxTfHZFcVmNkVCDGLB33lM wpUMmt49HZnHPfg7tGfSC1NnpnTSJPDH/eH1pN5hIy8bM59vZYvSXeDEpU/vq/HlNdrx OyEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765736; x=1730370536; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vQg8pMZdlj0Iio1vObJ7qVnikTueMhpFssiBJNcinU0=; b=evjDy6lQWiEdo+2vNguLabgNZSbHqz744kSNPSEEQXVvW8vd385WMg9uF86ut/gIlq EMdHYTCTQ5I82jPDX//vuWoC/ph+zYKJaK1TAtj1A8oZhOO++6R7d9u/QXH9+gbsZWjG DWN17wJeRgcIk0jN4ZUsRRhuUPReJzOGftcTMzmdTp43Ef6yXh8iAY0KRvsb3oy1U39T fu6DlHTEUFGj0ea3PysKYjbuaiTpHnHBcm1yl7FNwKCqnUZ8junVxwH0cbBlhhZEa/hu Y9LSxl4exitaaJ5nsna6FTqG0Sl/uNDtSFXAWL6E4DBEf6ZaoPSfK+NH8XrVKbfeBOOl eoog== X-Gm-Message-State: AOJu0Yzh5Z+IUyr0ARTZ7jlnIWJnqequiw47Fz3YGi/hywCmCvjxfAFB +AFTODlZNg8tEyhy+P+UfZTdrzqb5iNvaps3fc7ua1BmlTbDA1Z/HowVcdftnZH5JsJTvQM3Hbe rBA== X-Google-Smtp-Source: AGHT+IGVOKMNZ1zvW2X2xl/nggzj9gm43PhCkogIKKi+aBdLQFzj2EpU93TzpAgykA5tXqXyUDsCGA== X-Received: by 2002:a17:907:960b:b0:a99:ef5d:443e with SMTP id a640c23a62f3a-a9abf84c947mr490544766b.13.1729765735934; Thu, 24 Oct 2024 03:28:55 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v4 14/15] hw/block/virtio-blk: Replaces request free function with g_free Date: Thu, 24 Oct 2024 12:28:12 +0200 Message-Id: <20241024102813.9855-15-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::62a; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729765994090116600 Content-Type: text/plain; charset="utf-8" The virtio_blk_free_request() function has been a 1-liner forwarding to g_free() for a while now. We may as well call g_free on the request pointer directly. Signed-off-by: Phil Dennis-Jordan Reviewed-by: Akihiko Odaki --- hw/block/virtio-blk.c | 43 +++++++++++++++------------------- hw/vmapple/virtio-blk.c | 2 +- include/hw/virtio/virtio-blk.h | 1 - 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 9e8337bb639..40d2c9bc591 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -50,11 +50,6 @@ static void virtio_blk_init_request(VirtIOBlock *s, Virt= Queue *vq, req->mr_next =3D NULL; } =20 -void virtio_blk_free_request(VirtIOBlockReq *req) -{ - g_free(req); -} - void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status) { VirtIOBlock *s =3D req->dev; @@ -93,7 +88,7 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req= , int error, if (acct_failed) { block_acct_failed(blk_get_stats(s->blk), &req->acct); } - virtio_blk_free_request(req); + g_free(req); } =20 blk_error_action(s->blk, action, is_read, error); @@ -136,7 +131,7 @@ static void virtio_blk_rw_complete(void *opaque, int re= t) =20 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); block_acct_done(blk_get_stats(s->blk), &req->acct); - virtio_blk_free_request(req); + g_free(req); } } =20 @@ -151,7 +146,7 @@ static void virtio_blk_flush_complete(void *opaque, int= ret) =20 virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); block_acct_done(blk_get_stats(s->blk), &req->acct); - virtio_blk_free_request(req); + g_free(req); } =20 static void virtio_blk_discard_write_zeroes_complete(void *opaque, int ret) @@ -169,7 +164,7 @@ static void virtio_blk_discard_write_zeroes_complete(vo= id *opaque, int ret) if (is_write_zeroes) { block_acct_done(blk_get_stats(s->blk), &req->acct); } - virtio_blk_free_request(req); + g_free(req); } =20 static VirtIOBlockReq *virtio_blk_get_request(VirtIOBlock *s, VirtQueue *v= q) @@ -214,7 +209,7 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req) =20 fail: virtio_blk_req_complete(req, status); - virtio_blk_free_request(req); + g_free(req); } =20 static inline void submit_requests(VirtIOBlock *s, MultiReqBuffer *mrb, @@ -612,7 +607,7 @@ static void virtio_blk_zone_report_complete(void *opaqu= e, int ret) =20 out: virtio_blk_req_complete(req, err_status); - virtio_blk_free_request(req); + g_free(req); g_free(data->zone_report_data.zones); g_free(data); } @@ -661,7 +656,7 @@ static void virtio_blk_handle_zone_report(VirtIOBlockRe= q *req, return; out: virtio_blk_req_complete(req, err_status); - virtio_blk_free_request(req); + g_free(req); } =20 static void virtio_blk_zone_mgmt_complete(void *opaque, int ret) @@ -677,7 +672,7 @@ static void virtio_blk_zone_mgmt_complete(void *opaque,= int ret) } =20 virtio_blk_req_complete(req, err_status); - virtio_blk_free_request(req); + g_free(req); } =20 static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *req, BlockZoneOp op) @@ -719,7 +714,7 @@ static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *= req, BlockZoneOp op) return 0; out: virtio_blk_req_complete(req, err_status); - virtio_blk_free_request(req); + g_free(req); return err_status; } =20 @@ -750,7 +745,7 @@ static void virtio_blk_zone_append_complete(void *opaqu= e, int ret) =20 out: virtio_blk_req_complete(req, err_status); - virtio_blk_free_request(req); + g_free(req); g_free(data); } =20 @@ -788,7 +783,7 @@ static int virtio_blk_handle_zone_append(VirtIOBlockReq= *req, =20 out: virtio_blk_req_complete(req, err_status); - virtio_blk_free_request(req); + g_free(req); return err_status; } =20 @@ -855,7 +850,7 @@ static int virtio_blk_handle_request(VirtIOBlockReq *re= q, MultiReqBuffer *mrb) virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); block_acct_invalid(blk_get_stats(s->blk), is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_RE= AD); - virtio_blk_free_request(req); + g_free(req); return 0; } =20 @@ -911,7 +906,7 @@ static int virtio_blk_handle_request(VirtIOBlockReq *re= q, MultiReqBuffer *mrb) VIRTIO_BLK_ID_BYTES)); iov_from_buf(in_iov, in_num, 0, serial, size); virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); - virtio_blk_free_request(req); + g_free(req); break; } case VIRTIO_BLK_T_ZONE_APPEND & ~VIRTIO_BLK_T_OUT: @@ -943,7 +938,7 @@ static int virtio_blk_handle_request(VirtIOBlockReq *re= q, MultiReqBuffer *mrb) if (unlikely(!(type & VIRTIO_BLK_T_OUT) || out_len > sizeof(dwz_hdr))) { virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP); - virtio_blk_free_request(req); + g_free(req); return 0; } =20 @@ -960,7 +955,7 @@ static int virtio_blk_handle_request(VirtIOBlockReq *re= q, MultiReqBuffer *mrb) is_write_zeroe= s); if (err_status !=3D VIRTIO_BLK_S_OK) { virtio_blk_req_complete(req, err_status); - virtio_blk_free_request(req); + g_free(req); } =20 break; @@ -975,7 +970,7 @@ static int virtio_blk_handle_request(VirtIOBlockReq *re= q, MultiReqBuffer *mrb) if (!vbk->handle_unknown_request || !vbk->handle_unknown_request(req, mrb, type)) { virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP); - virtio_blk_free_request(req); + g_free(req); } } } @@ -998,7 +993,7 @@ void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq) while ((req =3D virtio_blk_get_request(s, vq))) { if (virtio_blk_handle_request(req, &mrb)) { virtqueue_detach_element(req->vq, &req->elem, 0); - virtio_blk_free_request(req); + g_free(req); break; } } @@ -1048,7 +1043,7 @@ static void virtio_blk_dma_restart_bh(void *opaque) while (req) { next =3D req->next; virtqueue_detach_element(req->vq, &req->elem, 0); - virtio_blk_free_request(req); + g_free(req); req =3D next; } break; @@ -1131,7 +1126,7 @@ static void virtio_blk_reset(VirtIODevice *vdev) /* No other threads can access req->vq here */ virtqueue_detach_element(req->vq, &req->elem, 0); =20 - virtio_blk_free_request(req); + g_free(req); } } =20 diff --git a/hw/vmapple/virtio-blk.c b/hw/vmapple/virtio-blk.c index 3a8b47bc55f..9f84c4851f5 100644 --- a/hw/vmapple/virtio-blk.c +++ b/hw/vmapple/virtio-blk.c @@ -58,7 +58,7 @@ static bool vmapple_virtio_blk_handle_unknown_request(Vir= tIOBlockReq *req, qemu_log_mask(LOG_UNIMP, "%s: Barrier requests are currently no-op= s\n", __func__); virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); - virtio_blk_free_request(req); + g_free(req); return true; default: return false; diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 28d5046ea6c..dcb2c89aed5 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -109,7 +109,6 @@ typedef struct VirtIOBlkClass { } VirtIOBlkClass; =20 void virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); -void virtio_blk_free_request(VirtIOBlockReq *req); void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status); =20 #endif --=20 2.39.3 (Apple Git-145) From nobody Sat Nov 23 18:09:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1729765795; cv=none; d=zohomail.com; s=zohoarc; b=Wukgh/KJ0cs05mzLx1Zv8sBBluDPZJr+0aR7knAaGc8cz5djEEfzey7R+SgwueqYnUpxXDoGn/bQ+GjTwOiJNVxsanNB/F9WTAjt8W+s3aj8kfu16SkzRHEX3StxHQzbvTQ8exIhDRikWfhrqHhT0LSNz7aUiCaQ3ZUosu+FnJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729765795; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S6Db/cvMMYo0kjOvyKFTXFs2E1xARh8XKyK0zLYpqeA=; b=Cq64BB7DV+H1pBGU3AO9t+/WVi41y/q7XQ0EA2OwfK3NCn50BTYATGxWmewhmfKtsB7XCscrsfMhMHjsAXAEUqoxWwSMZ8n7DtH4GwpZFfEAYdyAyGeGuLOEiv0uYl769posTBHNh4CxnPO78d5QDjD1aXn5JZSzmA2Ryzq20XU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17297657953271006.5409532107203; Thu, 24 Oct 2024 03:29:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3v5X-0001RK-Pi; Thu, 24 Oct 2024 06:29:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3v5U-0001Md-DL for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:29:04 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t3v5P-0008LM-Lt for qemu-devel@nongnu.org; Thu, 24 Oct 2024 06:29:04 -0400 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a9a3dc089d8so92359866b.3 for ; Thu, 24 Oct 2024 03:28:59 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a913706d3sm601019066b.134.2024.10.24.03.28.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 24 Oct 2024 03:28:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1729765738; x=1730370538; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S6Db/cvMMYo0kjOvyKFTXFs2E1xARh8XKyK0zLYpqeA=; b=qbaEvt39sMcWV17chPLqvAiSP4hDNvAm6zv6GnlifbZHg9VhJFzKAOPmb2LayQ/z21 /uRXkmoTlP3cQ5nVpdUt0oEPpCZsu6fVSTYCKoJ+/f6sCMgoYIqYJYCcWWGbTRN+A3Lm 5OX+T2WqWpAhvFjdOUjDbbRM28LOo4S/Eyg6Ev8dmYqDdn0wbG3beb4Qoq26gVK46uPU Gpgvs9Atw/DzwRvniM7d919CfEq7RVeDLuPjo1jZhIYDmQsfkz8QVs810j5JhPV+/9UQ Sutaz/YhJmS0HCNjfJZJ34jQUaoYqJ0Ge9pa8fLIP9cRM06vJh14AEhmPbru/PxF8bo3 xsXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765738; x=1730370538; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S6Db/cvMMYo0kjOvyKFTXFs2E1xARh8XKyK0zLYpqeA=; b=qxdr0s2SY/kMI6Tdki7K/Z9rbXA1h1DfoZ+P/eYXNorSoaGj01tsPz8NaoP/V7IDNk NCcQC/bPf+YR43KG6a22LBoMCNK0TPwubIgJBDC1+k7iPt4uH5rCxxPJWH9XkS2hTDHX iAwzxBUNJPy8F8j/JBdGFj7exedaZJjSJnnt+XYlrx2aUcXUxMltgv+vFxgKVqMAdRWc BbXPprThdQhsnJEa5SI/klWi1PTRvg7hMo0pUIjZewgpBWH5I25P7VcWeLkSXoFYWvxk GXcI4tEAvCNTjywvBtMLXyXDrsgO90cAdKQYJFbTMHl5LPQBSXKetARessrPFTpghY8u AdrA== X-Gm-Message-State: AOJu0YxibyzjETPIP0fkFOL5KjwhSElrZAWCsvduNlZ3bXtNCzweQwWs P7PcQHqBI2Z5+VWjUh6AE/AkA3LTf/6ZgoJKYFgqbTtXFDQvYbROw2HgPxtM+aFL3KIOv31obeO ONQ== X-Google-Smtp-Source: AGHT+IGv+8qakHOLzAIT08ZVKR6o3fJogwztS56JwtXYRcddcYRFinzlO6Ea7odPJlAW1KK9GQuOOA== X-Received: by 2002:a17:907:9813:b0:a9a:a7fd:d840 with SMTP id a640c23a62f3a-a9abf84d168mr541868966b.1.1729765737800; Thu, 24 Oct 2024 03:28:57 -0700 (PDT) From: Phil Dennis-Jordan To: qemu-devel@nongnu.org Cc: agraf@csgraf.de, phil@philjordan.eu, peter.maydell@linaro.org, pbonzini@redhat.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, stefanha@redhat.com, mst@redhat.com, slp@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, gaosong@loongson.cn, jiaxun.yang@flygoat.com, chenhuacai@kernel.org, kwolf@redhat.com, hreitz@redhat.com, philmd@linaro.org, shorne@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, bmeng.cn@gmail.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, jcmvbkbc@gmail.com, marcandre.lureau@redhat.com, berrange@redhat.com, akihiko.odaki@daynix.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, Alexander Graf Subject: [PATCH v4 15/15] hw/vmapple/vmapple: Add vmapple machine type Date: Thu, 24 Oct 2024 12:28:13 +0200 Message-Id: <20241024102813.9855-16-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241024102813.9855-1-phil@philjordan.eu> References: <20241024102813.9855-1-phil@philjordan.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: neutral client-ip=2a00:1450:4864:20::62c; envelope-from=phil@philjordan.eu; helo=mail-ej1-x62c.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @philjordan-eu.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729765797830116600 From: Alexander Graf Apple defines a new "vmapple" machine type as part of its proprietary macOS Virtualization.Framework vmm. This machine type is similar to the virt one, but with subtle differences in base devices, a few special vmapple device additions and a vastly different boot chain. This patch reimplements this machine type in QEMU. To use it, you have to have a readily installed version of macOS for VMApple, run on macOS with -accel hvf, pass the Virtualization.Framework boot rom (AVPBooter) in via -bios, pass the aux and root volume as pflash and pass aux and root volume as virtio drives. In addition, you also need to find the machine UUID and pass that as -M vmapple,uuid=3D parameter: $ qemu-system-aarch64 -accel hvf -M vmapple,uuid=3D0x1234 -m 4G \ -bios /System/Library/Frameworks/Virtualization.framework/Versions/A/Re= sources/AVPBooter.vmapple2.bin -drive file=3Daux,if=3Dpflash,format=3Draw \ -drive file=3Droot,if=3Dpflash,format=3Draw \ -drive file=3Daux,if=3Dnone,id=3Daux,format=3Draw \ -device vmapple-virtio-aux,drive=3Daux \ -drive file=3Droot,if=3Dnone,id=3Droot,format=3Draw \ -device vmapple-virtio-root,drive=3Droot With all these in place, you should be able to see macOS booting successfully. Known issues: - Keyboard and mouse/tablet input is laggy. The reason for this is either that macOS's XHCI driver is broken when the device/platform does not support MSI/MSI-X, or there's some unfortunate interplay with Qemu's XHCI implementation in this scenario. - Currently only macOS 12 guests are supported. The boot process for 13+ will need further investigation and adjustment. Signed-off-by: Alexander Graf Co-authored-by: Phil Dennis-Jordan Signed-off-by: Phil Dennis-Jordan --- v3: * Rebased on latest upstream, updated affinity and NIC creation API usage * Included Apple-variant virtio-blk in build dependency * Updated API usage for setting 'redist-region-count' array-typed property= on GIC. * Switched from virtio HID devices (for which macOS 12 does not contain dr= ivers) to an XHCI USB controller and USB HID devices. v4: * Fixups for v4 changes to the other patches in the set. * Corrected the assert macro to use * Removed superfluous endian conversions corresponding to cfg's. * Init error handling improvement. * No need to select CPU type on TCG, as only HVF is supported. * Machine type version bumped to 9.2 * #include order improved MAINTAINERS | 1 + docs/system/arm/vmapple.rst | 63 ++++ docs/system/target-arm.rst | 1 + hw/vmapple/Kconfig | 20 ++ hw/vmapple/meson.build | 1 + hw/vmapple/vmapple.c | 652 ++++++++++++++++++++++++++++++++++++ 6 files changed, 738 insertions(+) create mode 100644 docs/system/arm/vmapple.rst create mode 100644 hw/vmapple/vmapple.c diff --git a/MAINTAINERS b/MAINTAINERS index 104813ed85f..f44418b4a95 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2739,6 +2739,7 @@ R: Phil Dennis-Jordan S: Maintained F: hw/vmapple/* F: include/hw/vmapple/* +F: docs/system/arm/vmapple.rst =20 Subsystems ---------- diff --git a/docs/system/arm/vmapple.rst b/docs/system/arm/vmapple.rst new file mode 100644 index 00000000000..acb921ffb35 --- /dev/null +++ b/docs/system/arm/vmapple.rst @@ -0,0 +1,63 @@ +VMApple machine emulation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +VMApple is the device model that the macOS built-in hypervisor called "Vir= tualization.framework" +exposes to Apple Silicon macOS guests. The "vmapple" machine model in QEMU= implements the same +device model, but does not use any code from Virtualization.Framework. + +Prerequisites +------------- + +To run the vmapple machine model, you need to + + * Run on Apple Silicon + * Run on macOS 12.0 or above + * Have an already installed copy of a Virtualization.Framework macOS 12 v= irtual machine. I will + assume that you installed it using the macosvm CLI. + +First, we need to extract the UUID from the virtual machine that you insta= lled. You can do this +by running the following shell script: + +.. code-block:: bash + :caption: uuid.sh script to extract the UUID from a macosvm.json file + + #!/bin/bash + + MID=3D$(cat "$1" | python3 -c 'import json,sys;obj=3Djson.load(sys.stdin= );print(obj["machineId"]);') + echo "$MID" | base64 -d | plutil -extract ECID raw - + +Now we also need to trim the aux partition. It contains metadata that we c= an just discard: + +.. code-block:: bash + :caption: Command to trim the aux file + + $ dd if=3D"aux.img" of=3D"aux.img.trimmed" bs=3D$(( 0x4000 )) skip=3D1 + +How to run +---------- + +Then, we can launch QEMU with the Virtualization.Framework pre-boot enviro= nment and the readily +installed target disk images. I recommend to port forward the VM's ssh and= vnc ports to the host +to get better interactive access into the target system: + +.. code-block:: bash + :caption: Example execution command line + + $ UUID=3D$(uuid.sh macosvm.json) + $ AVPBOOTER=3D/System/Library/Frameworks/Virtualization.framework/Resour= ces/AVPBooter.vmapple2.bin + $ AUX=3Daux.img.trimmed + $ DISK=3Ddisk.img + $ qemu-system-aarch64 \ + -serial mon:stdio \ + -m 4G \ + -accel hvf \ + -M vmapple,uuid=3D$UUID \ + -bios $AVPBOOTER \ + -drive file=3D"$AUX",if=3Dpflash,format=3Draw \ + -drive file=3D"$DISK",if=3Dpflash,format=3Draw \ + -drive file=3D"$AUX",if=3Dnone,id=3Daux,format=3Draw \ + -drive file=3D"$DISK",if=3Dnone,id=3Droot,format=3Draw \ + -device vmapple-virtio-aux,drive=3Daux \ + -device vmapple-virtio-root,drive=3Droot \ + -net user,ipv6=3Doff,hostfwd=3Dtcp::2222-:22,hostfwd=3Dtcp::5901-:5= 900 \ + -net nic,model=3Dvirtio-net-pci \ diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst index 3c0a5848453..f2e0ac99537 100644 --- a/docs/system/target-arm.rst +++ b/docs/system/target-arm.rst @@ -102,6 +102,7 @@ undocumented; you can get a complete list by running arm/stellaris arm/stm32 arm/virt + arm/vmapple arm/xenpvh arm/xlnx-versal-virt arm/xlnx-zynq diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig index bcd1be63e3c..6a4c4a7fa2e 100644 --- a/hw/vmapple/Kconfig +++ b/hw/vmapple/Kconfig @@ -10,3 +10,23 @@ config VMAPPLE_CFG config VMAPPLE_VIRTIO_BLK bool =20 +config VMAPPLE + bool + depends on ARM + depends on HVF + default y if ARM + imply PCI_DEVICES + select ARM_GIC + select PLATFORM_BUS + select PCI_EXPRESS + select PCI_EXPRESS_GENERIC_BRIDGE + select PL011 # UART + select PL031 # RTC + select PL061 # GPIO + select GPIO_PWR + select PVPANIC_MMIO + select VMAPPLE_AES + select VMAPPLE_BDIF + select VMAPPLE_CFG + select MAC_PVG_MMIO + select VMAPPLE_VIRTIO_BLK diff --git a/hw/vmapple/meson.build b/hw/vmapple/meson.build index bf17cf906c9..e572f7d5602 100644 --- a/hw/vmapple/meson.build +++ b/hw/vmapple/meson.build @@ -2,3 +2,4 @@ system_ss.add(when: 'CONFIG_VMAPPLE_AES', if_true: files('= aes.c')) system_ss.add(when: 'CONFIG_VMAPPLE_BDIF', if_true: files('bdif.c')) system_ss.add(when: 'CONFIG_VMAPPLE_CFG', if_true: files('cfg.c')) system_ss.add(when: 'CONFIG_VMAPPLE_VIRTIO_BLK', if_true: files('virtio-b= lk.c')) +specific_ss.add(when: 'CONFIG_VMAPPLE', if_true: files('vmapple.c')) diff --git a/hw/vmapple/vmapple.c b/hw/vmapple/vmapple.c new file mode 100644 index 00000000000..b9454c07eee --- /dev/null +++ b/hw/vmapple/vmapple.c @@ -0,0 +1,652 @@ +/* + * VMApple machine emulation + * + * Copyright =C2=A9 2023 Amazon.com, Inc. or its affiliates. All Rights Re= served. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + * VMApple is the device model that the macOS built-in hypervisor called + * "Virtualization.framework" exposes to Apple Silicon macOS guests. The + * machine model in this file implements the same device model in QEMU, but + * does not use any code from Virtualization.Framework. + */ + +#include "qemu/osdep.h" +#include "qemu/bitops.h" +#include "qemu/datadir.h" +#include "qemu/error-report.h" +#include "qemu/guest-random.h" +#include "qemu/help-texts.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/option.h" +#include "qemu/units.h" +#include "monitor/qdev.h" +#include "hw/boards.h" +#include "hw/irq.h" +#include "hw/loader.h" +#include "hw/qdev-properties.h" +#include "hw/sysbus.h" +#include "hw/usb.h" +#include "hw/arm/boot.h" +#include "hw/arm/primecell.h" +#include "hw/char/pl011.h" +#include "hw/intc/arm_gic.h" +#include "hw/intc/arm_gicv3_common.h" +#include "hw/misc/pvpanic.h" +#include "hw/pci-host/gpex.h" +#include "hw/usb/xhci.h" +#include "hw/virtio/virtio-pci.h" +#include "hw/vmapple/vmapple.h" +#include "net/net.h" +#include "qapi/error.h" +#include "qapi/qmp/qlist.h" +#include "qapi/visitor.h" +#include "qapi/qapi-visit-common.h" +#include "standard-headers/linux/input.h" +#include "sysemu/hvf.h" +#include "sysemu/kvm.h" +#include "sysemu/reset.h" +#include "sysemu/runstate.h" +#include "sysemu/sysemu.h" +#include "target/arm/internals.h" +#include "target/arm/kvm_arm.h" + +struct VMAppleMachineClass { + MachineClass parent; +}; + +struct VMAppleMachineState { + MachineState parent; + + Notifier machine_done; + struct arm_boot_info bootinfo; + MemMapEntry *memmap; + const int *irqmap; + DeviceState *gic; + DeviceState *cfg; + Notifier powerdown_notifier; + PCIBus *bus; + MemoryRegion fw_mr; + uint64_t uuid; +}; + +#define DEFINE_VMAPPLE_MACHINE_LATEST(major, minor, latest) \ + static void vmapple##major##_##minor##_class_init(ObjectClass *oc, \ + void *data) \ + { \ + MachineClass *mc =3D MACHINE_CLASS(oc); \ + vmapple_machine_##major##_##minor##_options(mc); \ + mc->desc =3D "QEMU " # major "." # minor " Apple Virtual Machine";= \ + if (latest) { \ + mc->alias =3D "vmapple"; \ + } \ + } \ + static const TypeInfo machvmapple##major##_##minor##_info =3D { \ + .name =3D MACHINE_TYPE_NAME("vmapple-" # major "." # minor), \ + .parent =3D TYPE_VMAPPLE_MACHINE, \ + .class_init =3D vmapple##major##_##minor##_class_init, \ + }; \ + static void machvmapple_machine_##major##_##minor##_init(void) \ + { \ + type_register_static(&machvmapple##major##_##minor##_info); \ + } \ + type_init(machvmapple_machine_##major##_##minor##_init); + +#define DEFINE_VMAPPLE_MACHINE_AS_LATEST(major, minor) \ + DEFINE_VMAPPLE_MACHINE_LATEST(major, minor, true) +#define DEFINE_VMAPPLE_MACHINE(major, minor) \ + DEFINE_VMAPPLE_MACHINE_LATEST(major, minor, false) + +#define TYPE_VMAPPLE_MACHINE MACHINE_TYPE_NAME("vmapple") +OBJECT_DECLARE_TYPE(VMAppleMachineState, VMAppleMachineClass, VMAPPLE_MACH= INE) + +/* Number of external interrupt lines to configure the GIC with */ +#define NUM_IRQS 256 + +enum { + VMAPPLE_FIRMWARE, + VMAPPLE_CONFIG, + VMAPPLE_MEM, + VMAPPLE_GIC_DIST, + VMAPPLE_GIC_REDIST, + VMAPPLE_UART, + VMAPPLE_RTC, + VMAPPLE_PCIE, + VMAPPLE_PCIE_MMIO, + VMAPPLE_PCIE_ECAM, + VMAPPLE_GPIO, + VMAPPLE_PVPANIC, + VMAPPLE_APV_GFX, + VMAPPLE_APV_IOSFC, + VMAPPLE_AES_1, + VMAPPLE_AES_2, + VMAPPLE_BDOOR, + VMAPPLE_MEMMAP_LAST, +}; + +static MemMapEntry memmap[] =3D { + [VMAPPLE_FIRMWARE] =3D { 0x00100000, 0x00100000 }, + [VMAPPLE_CONFIG] =3D { 0x00400000, 0x00010000 }, + + [VMAPPLE_GIC_DIST] =3D { 0x10000000, 0x00010000 }, + [VMAPPLE_GIC_REDIST] =3D { 0x10010000, 0x00400000 }, + + [VMAPPLE_UART] =3D { 0x20010000, 0x00010000 }, + [VMAPPLE_RTC] =3D { 0x20050000, 0x00001000 }, + [VMAPPLE_GPIO] =3D { 0x20060000, 0x00001000 }, + [VMAPPLE_PVPANIC] =3D { 0x20070000, 0x00000002 }, + [VMAPPLE_BDOOR] =3D { 0x30000000, 0x00200000 }, + [VMAPPLE_APV_GFX] =3D { 0x30200000, 0x00010000 }, + [VMAPPLE_APV_IOSFC] =3D { 0x30210000, 0x00010000 }, + [VMAPPLE_AES_1] =3D { 0x30220000, 0x00004000 }, + [VMAPPLE_AES_2] =3D { 0x30230000, 0x00004000 }, + [VMAPPLE_PCIE_ECAM] =3D { 0x40000000, 0x10000000 }, + [VMAPPLE_PCIE_MMIO] =3D { 0x50000000, 0x1fff0000 }, + + /* Actual RAM size depends on configuration */ + [VMAPPLE_MEM] =3D { 0x70000000ULL, GiB}, +}; + +static const int irqmap[] =3D { + [VMAPPLE_UART] =3D 1, + [VMAPPLE_RTC] =3D 2, + [VMAPPLE_GPIO] =3D 0x5, + [VMAPPLE_APV_IOSFC] =3D 0x10, + [VMAPPLE_APV_GFX] =3D 0x11, + [VMAPPLE_AES_1] =3D 0x12, + [VMAPPLE_PCIE] =3D 0x20, +}; + +#define GPEX_NUM_IRQS 16 + +static void create_bdif(VMAppleMachineState *vms, MemoryRegion *mem) +{ + DeviceState *bdif; + SysBusDevice *bdif_sb; + DriveInfo *di_aux =3D drive_get(IF_PFLASH, 0, 0); + DriveInfo *di_root =3D drive_get(IF_PFLASH, 0, 1); + + if (!di_aux) { + error_report("No AUX device. Please specify one as pflash drive."); + exit(1); + } + + if (!di_root) { + /* Fall back to the first IF_VIRTIO device as root device */ + di_root =3D drive_get(IF_VIRTIO, 0, 0); + } + + if (!di_root) { + error_report("No root device. Please specify one as virtio drive."= ); + exit(1); + } + + /* PV backdoor device */ + bdif =3D qdev_new(TYPE_VMAPPLE_BDIF); + bdif_sb =3D SYS_BUS_DEVICE(bdif); + sysbus_mmio_map(bdif_sb, 0, vms->memmap[VMAPPLE_BDOOR].base); + + qdev_prop_set_drive(DEVICE(bdif), "aux", blk_by_legacy_dinfo(di_aux)); + qdev_prop_set_drive(DEVICE(bdif), "root", blk_by_legacy_dinfo(di_root)= ); + + sysbus_realize_and_unref(bdif_sb, &error_fatal); +} + +static void create_pvpanic(VMAppleMachineState *vms, MemoryRegion *mem) +{ + SysBusDevice *cfg; + + vms->cfg =3D qdev_new(TYPE_PVPANIC_MMIO_DEVICE); + cfg =3D SYS_BUS_DEVICE(vms->cfg); + sysbus_mmio_map(cfg, 0, vms->memmap[VMAPPLE_PVPANIC].base); + + sysbus_realize_and_unref(cfg, &error_fatal); +} + +static void create_cfg(VMAppleMachineState *vms, MemoryRegion *mem) +{ + SysBusDevice *cfg; + MachineState *machine =3D MACHINE(vms); + uint32_t rnd =3D 1; + + vms->cfg =3D qdev_new(TYPE_VMAPPLE_CFG); + cfg =3D SYS_BUS_DEVICE(vms->cfg); + sysbus_mmio_map(cfg, 0, vms->memmap[VMAPPLE_CONFIG].base); + + qemu_guest_getrandom_nofail(&rnd, sizeof(rnd)); + + qdev_prop_set_uint32(vms->cfg, "nr-cpus", machine->smp.cpus); + qdev_prop_set_uint64(vms->cfg, "ecid", vms->uuid); + qdev_prop_set_uint64(vms->cfg, "ram-size", machine->ram_size); + qdev_prop_set_uint32(vms->cfg, "rnd", rnd); + + sysbus_realize_and_unref(cfg, &error_fatal); +} + +static void create_gfx(VMAppleMachineState *vms, MemoryRegion *mem) +{ + int irq_gfx =3D vms->irqmap[VMAPPLE_APV_GFX]; + int irq_iosfc =3D vms->irqmap[VMAPPLE_APV_IOSFC]; + SysBusDevice *aes; + + aes =3D SYS_BUS_DEVICE(qdev_new("apple-gfx-mmio")); + sysbus_mmio_map(aes, 0, vms->memmap[VMAPPLE_APV_GFX].base); + sysbus_mmio_map(aes, 1, vms->memmap[VMAPPLE_APV_IOSFC].base); + sysbus_connect_irq(aes, 0, qdev_get_gpio_in(vms->gic, irq_gfx)); + sysbus_connect_irq(aes, 1, qdev_get_gpio_in(vms->gic, irq_iosfc)); + sysbus_realize_and_unref(aes, &error_fatal); +} + +static void create_aes(VMAppleMachineState *vms, MemoryRegion *mem) +{ + int irq =3D vms->irqmap[VMAPPLE_AES_1]; + SysBusDevice *aes; + + aes =3D SYS_BUS_DEVICE(qdev_new("apple-aes")); + sysbus_mmio_map(aes, 0, vms->memmap[VMAPPLE_AES_1].base); + sysbus_mmio_map(aes, 1, vms->memmap[VMAPPLE_AES_2].base); + sysbus_connect_irq(aes, 0, qdev_get_gpio_in(vms->gic, irq)); + sysbus_realize_and_unref(aes, &error_fatal); +} + +static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index) +{ + return NUM_IRQS + cpu_nr * GIC_INTERNAL + ppi_index; +} + +static void create_gic(VMAppleMachineState *vms, MemoryRegion *mem) +{ + MachineState *ms =3D MACHINE(vms); + /* We create a standalone GIC */ + SysBusDevice *gicbusdev; + QList *redist_region_count; + int i; + unsigned int smp_cpus =3D ms->smp.cpus; + + vms->gic =3D qdev_new(gicv3_class_name()); + qdev_prop_set_uint32(vms->gic, "revision", 3); + qdev_prop_set_uint32(vms->gic, "num-cpu", smp_cpus); + /* + * Note that the num-irq property counts both internal and external + * interrupts; there are always 32 of the former (mandated by GIC spec= ). + */ + qdev_prop_set_uint32(vms->gic, "num-irq", NUM_IRQS + 32); + + uint32_t redist0_capacity =3D + vms->memmap[VMAPPLE_GIC_REDIST].size / GICV3_REDIST_SIZE; + uint32_t redist0_count =3D MIN(smp_cpus, redist0_capacity); + + redist_region_count =3D qlist_new(); + qlist_append_int(redist_region_count, redist0_count); + qdev_prop_set_array(vms->gic, "redist-region-count", redist_region_cou= nt); + + gicbusdev =3D SYS_BUS_DEVICE(vms->gic); + sysbus_realize_and_unref(gicbusdev, &error_fatal); + sysbus_mmio_map(gicbusdev, 0, vms->memmap[VMAPPLE_GIC_DIST].base); + sysbus_mmio_map(gicbusdev, 1, vms->memmap[VMAPPLE_GIC_REDIST].base); + + /* + * Wire the outputs from each CPU's generic timer and the GICv3 + * maintenance interrupt signal to the appropriate GIC PPI inputs, + * and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inpu= ts. + */ + for (i =3D 0; i < smp_cpus; i++) { + DeviceState *cpudev =3D DEVICE(qemu_get_cpu(i)); + + /* Map the virt timer to PPI 27 */ + qdev_connect_gpio_out(cpudev, GTIMER_VIRT, + qdev_get_gpio_in(vms->gic, + arm_gic_ppi_index(i, 27))); + + /* Map the GIC IRQ and FIQ lines to CPU */ + sysbus_connect_irq(gicbusdev, i, qdev_get_gpio_in(cpudev, ARM_CPU_= IRQ)); + sysbus_connect_irq(gicbusdev, i + smp_cpus, + qdev_get_gpio_in(cpudev, ARM_CPU_FIQ)); + } +} + +static void create_uart(const VMAppleMachineState *vms, int uart, + MemoryRegion *mem, Chardev *chr) +{ + hwaddr base =3D vms->memmap[uart].base; + int irq =3D vms->irqmap[uart]; + DeviceState *dev =3D qdev_new(TYPE_PL011); + SysBusDevice *s =3D SYS_BUS_DEVICE(dev); + + qdev_prop_set_chr(dev, "chardev", chr); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + memory_region_add_subregion(mem, base, + sysbus_mmio_get_region(s, 0)); + sysbus_connect_irq(s, 0, qdev_get_gpio_in(vms->gic, irq)); +} + +static void create_rtc(const VMAppleMachineState *vms) +{ + hwaddr base =3D vms->memmap[VMAPPLE_RTC].base; + int irq =3D vms->irqmap[VMAPPLE_RTC]; + + sysbus_create_simple("pl031", base, qdev_get_gpio_in(vms->gic, irq)); +} + +static DeviceState *gpio_key_dev; +static void vmapple_powerdown_req(Notifier *n, void *opaque) +{ + /* use gpio Pin 3 for power button event */ + qemu_set_irq(qdev_get_gpio_in(gpio_key_dev, 0), 1); +} + +static void create_gpio_devices(const VMAppleMachineState *vms, int gpio, + MemoryRegion *mem) +{ + DeviceState *pl061_dev; + hwaddr base =3D vms->memmap[gpio].base; + int irq =3D vms->irqmap[gpio]; + SysBusDevice *s; + + pl061_dev =3D qdev_new("pl061"); + /* Pull lines down to 0 if not driven by the PL061 */ + qdev_prop_set_uint32(pl061_dev, "pullups", 0); + qdev_prop_set_uint32(pl061_dev, "pulldowns", 0xff); + s =3D SYS_BUS_DEVICE(pl061_dev); + sysbus_realize_and_unref(s, &error_fatal); + memory_region_add_subregion(mem, base, sysbus_mmio_get_region(s, 0)); + sysbus_connect_irq(s, 0, qdev_get_gpio_in(vms->gic, irq)); + gpio_key_dev =3D sysbus_create_simple("gpio-key", -1, + qdev_get_gpio_in(pl061_dev, 3)); +} + +static void vmapple_firmware_init(VMAppleMachineState *vms, + MemoryRegion *sysmem) +{ + hwaddr size =3D vms->memmap[VMAPPLE_FIRMWARE].size; + hwaddr base =3D vms->memmap[VMAPPLE_FIRMWARE].base; + const char *bios_name; + int image_size; + char *fname; + + bios_name =3D MACHINE(vms)->firmware; + if (!bios_name) { + error_report("No firmware specified"); + exit(1); + } + + fname =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); + if (!fname) { + error_report("Could not find ROM image '%s'", bios_name); + exit(1); + } + + memory_region_init_ram(&vms->fw_mr, NULL, "firmware", size, &error_fat= al); + image_size =3D load_image_mr(fname, &vms->fw_mr); + + g_free(fname); + if (image_size < 0) { + error_report("Could not load ROM image '%s'", bios_name); + exit(1); + } + + memory_region_add_subregion(get_system_memory(), base, &vms->fw_mr); +} + +static void create_pcie(VMAppleMachineState *vms) +{ + hwaddr base_mmio =3D vms->memmap[VMAPPLE_PCIE_MMIO].base; + hwaddr size_mmio =3D vms->memmap[VMAPPLE_PCIE_MMIO].size; + hwaddr base_ecam =3D vms->memmap[VMAPPLE_PCIE_ECAM].base; + hwaddr size_ecam =3D vms->memmap[VMAPPLE_PCIE_ECAM].size; + int irq =3D vms->irqmap[VMAPPLE_PCIE]; + MemoryRegion *mmio_alias; + MemoryRegion *mmio_reg; + MemoryRegion *ecam_alias; + MemoryRegion *ecam_reg; + DeviceState *dev; + int i; + PCIHostState *pci; + DeviceState *usb_controller; + USBBus *usb_bus; + + dev =3D qdev_new(TYPE_GPEX_HOST); + qdev_prop_set_uint32(dev, "num-irqs", GPEX_NUM_IRQS); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + + /* Map only the first size_ecam bytes of ECAM space */ + ecam_alias =3D g_new0(MemoryRegion, 1); + ecam_reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); + memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam", + ecam_reg, 0, size_ecam); + memory_region_add_subregion(get_system_memory(), base_ecam, ecam_alias= ); + + /* + * Map the MMIO window from [0x50000000-0x7fff0000] in PCI space into + * system address space at [0x50000000-0x7fff0000]. + */ + mmio_alias =3D g_new0(MemoryRegion, 1); + mmio_reg =3D sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); + memory_region_init_alias(mmio_alias, OBJECT(dev), "pcie-mmio", + mmio_reg, base_mmio, size_mmio); + memory_region_add_subregion(get_system_memory(), base_mmio, mmio_alias= ); + + for (i =3D 0; i < GPEX_NUM_IRQS; i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, + qdev_get_gpio_in(vms->gic, irq + i)); + gpex_set_irq_num(GPEX_HOST(dev), i, irq + i); + } + + pci =3D PCI_HOST_BRIDGE(dev); + vms->bus =3D pci->bus; + g_assert(vms->bus); + + while ((dev =3D qemu_create_nic_device("virtio-net-pci", true, NULL)))= { + qdev_realize_and_unref(dev, BUS(vms->bus), &error_fatal); + } + + usb_controller =3D qdev_new(TYPE_QEMU_XHCI); + qdev_realize_and_unref(usb_controller, BUS(pci->bus), &error_fatal); + + usb_bus =3D USB_BUS(object_resolve_type_unambiguous(TYPE_USB_BUS, + &error_fatal)); + usb_create_simple(usb_bus, "usb-kbd"); + usb_create_simple(usb_bus, "usb-tablet"); +} + +static void vmapple_reset(void *opaque) +{ + VMAppleMachineState *vms =3D opaque; + hwaddr base =3D vms->memmap[VMAPPLE_FIRMWARE].base; + + cpu_set_pc(first_cpu, base); +} + +static void mach_vmapple_init(MachineState *machine) +{ + VMAppleMachineState *vms =3D VMAPPLE_MACHINE(machine); + MachineClass *mc =3D MACHINE_GET_CLASS(machine); + const CPUArchIdList *possible_cpus; + MemoryRegion *sysmem =3D get_system_memory(); + int n; + unsigned int smp_cpus =3D machine->smp.cpus; + unsigned int max_cpus =3D machine->smp.max_cpus; + + vms->memmap =3D memmap; + machine->usb =3D true; + + possible_cpus =3D mc->possible_cpu_arch_ids(machine); + assert(possible_cpus->len =3D=3D max_cpus); + for (n =3D 0; n < possible_cpus->len; n++) { + Object *cpu; + CPUState *cs; + + if (n >=3D smp_cpus) { + break; + } + + cpu =3D object_new(possible_cpus->cpus[n].type); + object_property_set_int(cpu, "mp-affinity", + possible_cpus->cpus[n].arch_id, NULL); + + cs =3D CPU(cpu); + cs->cpu_index =3D n; + + numa_cpu_pre_plug(&possible_cpus->cpus[cs->cpu_index], DEVICE(cpu), + &error_fatal); + + object_property_set_bool(cpu, "has_el3", false, NULL); + object_property_set_bool(cpu, "has_el2", false, NULL); + object_property_set_int(cpu, "psci-conduit", QEMU_PSCI_CONDUIT_HVC, + NULL); + + /* Secondary CPUs start in PSCI powered-down state */ + if (n > 0) { + object_property_set_bool(cpu, "start-powered-off", true, NULL); + } + + object_property_set_link(cpu, "memory", OBJECT(sysmem), &error_abo= rt); + qdev_realize(DEVICE(cpu), NULL, &error_fatal); + object_unref(cpu); + } + + memory_region_add_subregion(sysmem, vms->memmap[VMAPPLE_MEM].base, + machine->ram); + + create_gic(vms, sysmem); + create_bdif(vms, sysmem); + create_pvpanic(vms, sysmem); + create_aes(vms, sysmem); + create_gfx(vms, sysmem); + create_uart(vms, VMAPPLE_UART, sysmem, serial_hd(0)); + create_rtc(vms); + create_pcie(vms); + + create_gpio_devices(vms, VMAPPLE_GPIO, sysmem); + + vmapple_firmware_init(vms, sysmem); + create_cfg(vms, sysmem); + + /* connect powerdown request */ + vms->powerdown_notifier.notify =3D vmapple_powerdown_req; + qemu_register_powerdown_notifier(&vms->powerdown_notifier); + + vms->bootinfo.ram_size =3D machine->ram_size; + vms->bootinfo.board_id =3D -1; + vms->bootinfo.loader_start =3D vms->memmap[VMAPPLE_MEM].base; + vms->bootinfo.skip_dtb_autoload =3D true; + vms->bootinfo.firmware_loaded =3D true; + arm_load_kernel(ARM_CPU(first_cpu), machine, &vms->bootinfo); + + qemu_register_reset(vmapple_reset, vms); +} + +static CpuInstanceProperties +vmapple_cpu_index_to_props(MachineState *ms, unsigned cpu_index) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + const CPUArchIdList *possible_cpus =3D mc->possible_cpu_arch_ids(ms); + + assert(cpu_index < possible_cpus->len); + return possible_cpus->cpus[cpu_index].props; +} + + +static int64_t vmapple_get_default_cpu_node_id(const MachineState *ms, int= idx) +{ + return idx % ms->numa_state->num_nodes; +} + +static const CPUArchIdList *vmapple_possible_cpu_arch_ids(MachineState *ms) +{ + int n; + unsigned int max_cpus =3D ms->smp.max_cpus; + + if (ms->possible_cpus) { + assert(ms->possible_cpus->len =3D=3D max_cpus); + return ms->possible_cpus; + } + + ms->possible_cpus =3D g_malloc0(sizeof(CPUArchIdList) + + sizeof(CPUArchId) * max_cpus); + ms->possible_cpus->len =3D max_cpus; + for (n =3D 0; n < ms->possible_cpus->len; n++) { + ms->possible_cpus->cpus[n].type =3D ms->cpu_type; + ms->possible_cpus->cpus[n].arch_id =3D + arm_build_mp_affinity(n, GICV3_TARGETLIST_BITS); + ms->possible_cpus->cpus[n].props.has_thread_id =3D true; + ms->possible_cpus->cpus[n].props.thread_id =3D n; + } + return ms->possible_cpus; +} + +static void vmapple_get_uuid(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VMAppleMachineState *vms =3D VMAPPLE_MACHINE(obj); + + visit_type_uint64(v, name, &vms->uuid, errp); +} + +static void vmapple_set_uuid(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + VMAppleMachineState *vms =3D VMAPPLE_MACHINE(obj); + Error *error =3D NULL; + + visit_type_uint64(v, name, &vms->uuid, &error); + if (error) { + error_propagate(errp, error); + return; + } +} + +static void vmapple_machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->init =3D mach_vmapple_init; + mc->max_cpus =3D 32; + mc->block_default_type =3D IF_VIRTIO; + mc->no_cdrom =3D 1; + mc->pci_allow_0_address =3D true; + mc->minimum_page_bits =3D 12; + mc->possible_cpu_arch_ids =3D vmapple_possible_cpu_arch_ids; + mc->cpu_index_to_instance_props =3D vmapple_cpu_index_to_props; + mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("host"); + mc->get_default_cpu_node_id =3D vmapple_get_default_cpu_node_id; + mc->default_ram_id =3D "mach-vmapple.ram"; + + object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy", + "on", true); + + object_class_property_add(oc, "uuid", "uint64", vmapple_get_uuid, + vmapple_set_uuid, NULL, NULL); + object_class_property_set_description(oc, "uuid", "Machine UUID (SDOM)= "); +} + +static void vmapple_instance_init(Object *obj) +{ + VMAppleMachineState *vms =3D VMAPPLE_MACHINE(obj); + + vms->irqmap =3D irqmap; +} + +static const TypeInfo vmapple_machine_info =3D { + .name =3D TYPE_VMAPPLE_MACHINE, + .parent =3D TYPE_MACHINE, + .abstract =3D true, + .instance_size =3D sizeof(VMAppleMachineState), + .class_size =3D sizeof(VMAppleMachineClass), + .class_init =3D vmapple_machine_class_init, + .instance_init =3D vmapple_instance_init, +}; + +static void machvmapple_machine_init(void) +{ + type_register_static(&vmapple_machine_info); +} +type_init(machvmapple_machine_init); + +static void vmapple_machine_9_2_options(MachineClass *mc) +{ +} +DEFINE_VMAPPLE_MACHINE_AS_LATEST(9, 2) + --=20 2.39.3 (Apple Git-145)