From nobody Sat Nov 23 20:47:37 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=1730235847; cv=none; d=zohomail.com; s=zohoarc; b=iKkCQ7YvLTnF1bznA7gqWf/OEPyDCury8+KZW0BvlLX0/J9Cupt8Vf4dtN8LSkLHICsu6HIVmgh7c8d3OWwGVyJRe0kmHfqgOQ/Pzu97MLZxV4wAHcJskKuRwuvG4e4CyaFe47qEV9U2Admh2/4f3EuX6wTGjvprShjLJEObI2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730235847; 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=eHMN46rJt9QcxyBveWaVh/b2Y4BBk6tAt2nO8pjIz70=; b=efHGOx+2P/wW0Yc7gpbW3w/UfxZuag14t2TVv3zwgMO7vvaDR8KKVepV8hODNsV280WfGYYvZT/F3F9H/Vf0VrrADcYSt86ZjaGl0RllxPrnDP8V/VvVHdaAPefNRj+vywRw+htXuefAceqnVCdKOHsNJTtuq2Nq7az6ZTqvr/4= 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 1730235847813504.85879587461056; Tue, 29 Oct 2024 14:04:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5tIm-0003e4-Vh; Tue, 29 Oct 2024 16:58: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 1t5tIk-0003bF-Pc for qemu-devel@nongnu.org; Tue, 29 Oct 2024 16:58:55 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t5tIe-0005XO-Ny for qemu-devel@nongnu.org; Tue, 29 Oct 2024 16:58:54 -0400 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5c9454f3bfaso7058588a12.2 for ; Tue, 29 Oct 2024 13:58:48 -0700 (PDT) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cbb629d5besm4217341a12.33.2024.10.29.13.58.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 29 Oct 2024 13:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1730235527; x=1730840327; 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=eHMN46rJt9QcxyBveWaVh/b2Y4BBk6tAt2nO8pjIz70=; b=MyG+cP5UkEMFyOHjTzNLkMibFV63+8eOhV+4CzBDhho8EC5QGE5XUhNCTrpzCVfuc5 B7TsAJWPelSya+g9aLqbNH9etbuyFNMUssWByzE8nAsLWC0iyUjVUJ2qsl14gXqPsr07 K1iLDIvYMSbscdB4jrJfkGtw6W+WIv7xZTr+Lq68fWd83Kja+7po8wIaWergS77FlPA6 XzqbngmPQp5AaJcNqngOOLWF0/OsyCAZLcSSSrU2jzRu38mcVHwVwgqin5pTSz6AE6am tpDkGYamD1ITxmBQYc4zrBBFMqkwQXXlJ9evsurmODV5PqM5rpFq1rC4r5RdCuJv+Oqo 62pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730235527; x=1730840327; 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=eHMN46rJt9QcxyBveWaVh/b2Y4BBk6tAt2nO8pjIz70=; b=fVcOdQs+rPZu4vDOtAtpvbzPeZM9V7N3LLjUBBlADKAjcrCa2f1db+lANJtZt3LLSD yBGlkewvf+jKRd/qJlAPOOEl1Fef+p7GtpNPoPRokRUNL800ShOXJub9718Tq1krC+ub cv+N3gmJqcvJ4e0FtJC0XW6DOnkoB1mlLXU7lN99kvx0sWxpDFwEx4RXb1U13puBEABH zhwR36jOD90ZSiPOqv0+2LbvsIu6ah6jQ8XE7rJHjZfnEgnN1tH66BXUjOoo+fOr1qJw FbQLQra/ibso8DyVFXrA1b4R0fZzxLLWSqHXosZCMsvm1E10OO9qw4jo6cN6u4Xyb0DQ yXxg== X-Gm-Message-State: AOJu0YwfMfn1lutGYrnD2sJdLWYvYY7ybJ9v4gLPp57zZHwAdKJdDeGq J4En4zJ48/4rPkQkxG02vMIc1G9AcbiIerC0iXM7jyOO8UmIGWGKFCwVyAbz8CYsUjScAZYu0+v 08Q== X-Google-Smtp-Source: AGHT+IG0c5iaxrQkuxUH/XYReAYUlCoqOEq8E9gLnYtMS85x1xYncJsFBiQ63dUCUeVy7q2jGm8fpw== X-Received: by 2002:a05:6402:51d0:b0:5cb:66c6:d82a with SMTP id 4fb4d7f45d1cf-5cbbf88a35fmr9930969a12.3.1730235527106; Tue, 29 Oct 2024 13:58:47 -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 v5 04/15] hw/display/apple-gfx: Adds configurable mode list Date: Tue, 29 Oct 2024 21:58:08 +0100 Message-Id: <20241029205819.69888-5-phil@philjordan.eu> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20241029205819.69888-1-phil@philjordan.eu> References: <20241029205819.69888-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::535; envelope-from=phil@philjordan.eu; helo=mail-ed1-x535.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: 1730235849090116600 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. v5: * Better error handling and buffer management in property parsing and output. 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 | 121 ++++++++++++++++++++++++++++++++---- hw/display/trace-events | 2 + 5 files changed, 139 insertions(+), 13 deletions(-) diff --git a/hw/display/apple-gfx-mmio.m b/hw/display/apple-gfx-mmio.m index b0c5669a344..a801c5fa722 100644 --- a/hw/display/apple-gfx-mmio.m +++ b/hw/display/apple-gfx-mmio.m @@ -364,6 +364,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) { @@ -373,6 +379,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 870d0c41e66..e2fa2567c99 100644 --- a/hw/display/apple-gfx-pci.m +++ b/hw/display/apple-gfx-pci.m @@ -113,6 +113,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); @@ -129,7 +136,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 ef34e8160c8..e9fef09e37e 100644 --- a/hw/display/apple-gfx.h +++ b/hw/display/apple-gfx.h @@ -16,6 +16,7 @@ #import #include "qemu/typedefs.h" #include "exec/memory.h" +#include "hw/qdev-properties.h" #include "ui/surface.h" =20 @class PGDeviceDescriptor; @@ -27,6 +28,7 @@ =20 typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; =20 +struct AppleGFXDisplayMode; typedef struct AppleGFXState { /* Initialised on init/realize() */ MemoryRegion iomem_gfx; @@ -36,6 +38,8 @@ typedef struct AppleGFXState { id mtl; id mtl_queue; dispatch_queue_t render_queue; + struct AppleGFXDisplayMode *display_modes; + uint32_t num_display_modes; /* * QemuMutex & QemuConds for awaiting completion of PVG memory-mapping= and * reading requests after submitting them to run in the AIO context. @@ -66,6 +70,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); @@ -75,5 +85,7 @@ uintptr_t apple_gfx_host_address_for_gpa_range(uint64_t g= uest_physical, void apple_gfx_await_bh_job(AppleGFXState *s, QemuCond *job_cond, 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 101b38e8a6e..2e264e5561f 100644 --- a/hw/display/apple-gfx.m +++ b/hw/display/apple-gfx.m @@ -31,9 +31,10 @@ #include "sysemu/dma.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 @@ -320,7 +321,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; } @@ -686,20 +686,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; } @@ -737,6 +742,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, @@ -763,7 +770,14 @@ void apple_gfx_common_realize(AppleGFXState *s, PGDevi= ceDescriptor *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 @@ -771,3 +785,86 @@ void apple_gfx_common_realize(AppleGFXState *s, PGDevi= ceDescriptor *desc, qemu_cond_init(&s->task_map_job_cond); qemu_cond_init(&s->mem_read_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) + 2 separator characters + nul. */ + char buffer[5 * 3 + 2 + 1]; + char *pos =3D buffer; + + int rc =3D snprintf(buffer, sizeof(buffer), + "%"PRIu16"x%"PRIu16"@%"PRIu16, + mode->width_px, mode->height_px, + mode->refresh_rate_hz); + assert(rc < sizeof(buffer)); + + 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; + g_autofree char *str =3D NULL; + int ret; + 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_strtoi(endptr, &endptr, 10, &val); + if (ret || val > UINT16_MAX || val <=3D 0) { + error_setg(errp, "width in '%s' must be a decimal integer number " + "of pixels in the range 1..65535", name); + return; + } + mode->width_px =3D val; + if (*endptr !=3D 'x') { + goto separator_error; + } + + ret =3D qemu_strtoi(endptr + 1, &endptr, 10, &val); + if (ret || val > UINT16_MAX || val <=3D 0) { + error_setg(errp, "height in '%s' must be a decimal integer number " + "of pixels in the range 1..65535", name); + return; + } + mode->height_px =3D val; + if (*endptr !=3D '@') { + goto separator_error; + } + + ret =3D qemu_strtoi(endptr + 1, &endptr, 10, &val); + if (ret || val > UINT16_MAX || val <=3D 0) { + error_setg(errp, "refresh rate in '%s'" + " must be a positive decimal integer (Hertz)", name); + } + mode->refresh_rate_hz =3D val; + return; + +separator_error: + error_setg(errp, "Each display mode takes the format " + "'x@'"); +} + +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 d63fba6d094..0e223075375 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)