From nobody Sat Dec 28 22:43:51 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=1734992362; cv=none; d=zohomail.com; s=zohoarc; b=Lh/tzK+ZoVcCPLJmynlmcps7FJvNZxa0sp3ayDdqH1mCAviI0B+B7+jelb4jfhf4/bTq+7ebv+YO+QHSKhkYvq/UlrZhxGRccM5ioS+gkzZfkeBA/rbik54Yh1aFWoCzl4mkcVViVWIqXxab6bVwKhlRI7zUcVk1wWYcEDSWQxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734992362; 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=8Hjp2iqfeOlT6Qi6/ngAmISPWXw5OFMz+erfcsZzsrI=; b=Yzl8jxQ5EXGyw12bk0jLxXUuhVbq2SsE8wn8N+llQhy+Go38tG6Deuvq+9B9dd9+9EVVg6LOdCzLkPQ/OGte09ePlZIiEmgXPOkULj/kr38NMhvwn7EVr5a1g50sbne5iMfH1VU2gt4tQhVitxn9esRJmemLN1PNhodlPWf8MV4= 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 1734992362693833.4461671568988; Mon, 23 Dec 2024 14:19:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tPqjr-00023w-9Y; Mon, 23 Dec 2024 17:17:23 -0500 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 1tPqjb-0001zV-M3 for qemu-devel@nongnu.org; Mon, 23 Dec 2024 17:17:07 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tPqjZ-0006vi-34 for qemu-devel@nongnu.org; Mon, 23 Dec 2024 17:17:07 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-43622267b2eso48545405e9.0 for ; Mon, 23 Dec 2024 14:17:03 -0800 (PST) Received: from localhost.localdomain (h082218084190.host.wavenet.at. [82.218.84.190]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436611fc161sm147561075e9.10.2024.12.23.14.16.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Dec 2024 14:17:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20230601.gappssmtp.com; s=20230601; t=1734992222; x=1735597022; 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=8Hjp2iqfeOlT6Qi6/ngAmISPWXw5OFMz+erfcsZzsrI=; b=bjr0D81WkeihqgF288FU3n3vBXIJUIfNj1BNsPOstYMJS0VPIfpFQJl0NhU6K/vnfT mn5f5Hmg+Bn/Ex+sUGWKYv7ksU8foxrytibdHkc4Fwj+FURwU2LtqJGFNKrNPbNrqR/Z oYHuC0heRNWrJWODTcDmXpGv8L9RXt3UYBxWUw7NAWcZyv8Bd0RZJUbfA038YLpbNNDg Z80gA9aqGR7EVYC4wWQPU/zMcfUkfb/l6r9j2aYJjEsIAEHNySzRNyn4fJbVEL28gzLI LFBHED69Gs92HY+JDuoz5aRIwEYEWMq5ed/JJoXUPQ5N005UsGGGnRv5LTu/Ga2N/kLB PlTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734992222; x=1735597022; 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=8Hjp2iqfeOlT6Qi6/ngAmISPWXw5OFMz+erfcsZzsrI=; b=XBvb2Ps7mLk63g/3ZZtwok0AM1G3hGDY8n1yfNtmAFloM0N/ttNMM+FnZHjfY8gCqn MNRRNZOJVtj3aGcDHJdvWNtAy+QK5NWyu3Ox1aSN53dV6zlAsPxqozUxiY049V0iCPzb 6M05OTRU4fvYuwxnSaya85foYh9PD5BfdrMAx8dQjyzmYf+yojV8XhForZamL1Hi/N53 H3vk9ARyvtCp0qyxuepkqoE5OHtHQS5Rn5hIgtNG76M3rSX4JurHCzKh16kpdRIbbMxT 6d9/4gjHw3ieDQ8qj4HP19+ukj9JmJ4NCm7eSD26OkD59Sf3z8UVBRfqFlKAtkOktVka yg/A== X-Gm-Message-State: AOJu0Yzp90EDuv4zTEoOwSokvSELteVsCWxX8y9Qy0Wqv3nFRNxgUT3j wl6lf/Bc0u4vjHiNjJEHHp7ba98QdUp9oP9sLJXDPzwEOBZ40eF40vXXl7zYoJF0+VWlr0NJHAr TCA== X-Gm-Gg: ASbGncu+v/4geW2wtojzzYfFj6CV99jjUuhgnpnUktznLn/kVKuh6zRBsFB5owBfWtv A3jOj+V5rx/L4ZNHOYWN1ZaFH9rBJWAdK+hYs4IwLPOM5YbeaE4lmY8T9BV5K9TXXPADk4I/jgi EL0tRaIglnaOXm/xXFtYNPicPbqTzhxPNQS4NfxjlWSVCHMdpEBQv+b0QiMBhh2raNauSlhmofq ryX7n+Iy22JPPRZfb+Ks5JK8dtoZp80EDd9yiuviMIcvLr69BYCQGcPmh/gWVi2p8Qxiottd3mX PX0hZN5LmX9Go6MWAAoc1GbO9d6oZmdq X-Google-Smtp-Source: AGHT+IGx/Wa1uOLoZe45xcXp15SaP7rA4638SeKF0J9ccay7tEp0QKtXv4WgKLLG/mOB9EamiBrHDA== X-Received: by 2002:a05:6000:461e:b0:388:e377:8a1b with SMTP id ffacd0b85a97d-38a221f38b4mr11517056f8f.28.1734992222083; Mon, 23 Dec 2024 14:17:02 -0800 (PST) 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, 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, balaton@eik.bme.hu Subject: [PATCH v16 04/14] hw/display/apple-gfx: Adds configurable mode list Date: Mon, 23 Dec 2024 23:16:35 +0100 Message-Id: <20241223221645.29911-5-phil@philjordan.eu> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241223221645.29911-1-phil@philjordan.eu> References: <20241223221645.29911-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::335; envelope-from=phil@philjordan.eu; helo=mail-wm1-x335.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: 1734992364670116600 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 Reviewed-by: Akihiko Odaki Tested-by: Akihiko Odaki --- 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. v6: * Switched to using NSMutableArray for the mode list to avoid need for allocating a temporary array - previously done with alloca. v7: * Simplified error handling in property parsing v8: * More consistent integer variable types. v9: * Re-ordered type definitions so we can drop a 'struct' keyword. v15: * Constified the property table. v16: * Removed the DEFINE_PROP_END_OF_LIST markers to match recent upstream changes. hw/display/apple-gfx-mmio.m | 7 ++ hw/display/apple-gfx-pci.m | 8 ++- hw/display/apple-gfx.h | 11 +++ hw/display/apple-gfx.m | 135 +++++++++++++++++++++++++++++++----- hw/display/trace-events | 2 + 5 files changed, 143 insertions(+), 20 deletions(-) diff --git a/hw/display/apple-gfx-mmio.m b/hw/display/apple-gfx-mmio.m index 1a46ff48b7..60580a373d 100644 --- a/hw/display/apple-gfx-mmio.m +++ b/hw/display/apple-gfx-mmio.m @@ -258,6 +258,11 @@ static void apple_gfx_mmio_reset(Object *obj, ResetTyp= e type) [s->common.pgdev reset]; } =20 +static const Property apple_gfx_mmio_properties[] =3D { + DEFINE_PROP_ARRAY("display-modes", AppleGFXMMIOState, + common.num_display_modes, common.display_modes, + qdev_prop_display_mode, AppleGFXDisplayMode), +}; =20 static void apple_gfx_mmio_class_init(ObjectClass *klass, void *data) { @@ -267,6 +272,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 5ff6a487cf..4cfc01fc72 100644 --- a/hw/display/apple-gfx-pci.m +++ b/hw/display/apple-gfx-pci.m @@ -114,6 +114,12 @@ static void apple_gfx_pci_reset(Object *obj, ResetType= type) [s->common.pgdev reset]; } =20 +static const Property apple_gfx_pci_properties[] =3D { + DEFINE_PROP_ARRAY("display-modes", AppleGFXPCIState, + common.num_display_modes, common.display_modes, + qdev_prop_display_mode, AppleGFXDisplayMode), +}; + static void apple_gfx_pci_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -130,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 ef2455e3bd..a1160bf661 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,12 @@ =20 typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; =20 +typedef struct AppleGFXDisplayMode { + uint16_t width_px; + uint16_t height_px; + uint16_t refresh_rate_hz; +} AppleGFXDisplayMode; + typedef struct AppleGFXState { /* Initialised on init/realize() */ MemoryRegion iomem_gfx; @@ -35,6 +42,8 @@ typedef struct AppleGFXState { QemuConsole *con; id mtl; id mtl_queue; + AppleGFXDisplayMode *display_modes; + uint32_t num_display_modes; =20 /* List `tasks` is protected by task_mutex */ QemuMutex task_mutex; @@ -62,5 +71,7 @@ void *apple_gfx_host_ptr_for_gpa_range(uint64_t guest_phy= sical, uint64_t length, bool read_only, MemoryRegion **mapping_in_region); =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 f334ee66fd..b00c72fc4d 100644 --- a/hw/display/apple-gfx.m +++ b/hw/display/apple-gfx.m @@ -31,9 +31,10 @@ #include "system/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 static Error *apple_gfx_mig_blocker; @@ -690,22 +691,24 @@ static void new_frame_handler_bh(void *opaque) 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)]; - NSArray* mode_array; - 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; + uint32_t i; + PGDisplayMode *mode_obj; + NSMutableArray *mode_array =3D + [[NSMutableArray alloc] initWithCapacity:display_mode_count]; + + 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 }; + + mode_obj =3D + [[PGDisplayMode alloc] initWithSizeInPixels:mode_size + refreshRateInHz:mode->refresh_rate= _hz]; + [mode_array addObject:mode_obj]; + [mode_obj release]; } =20 return mode_array; @@ -741,6 +744,9 @@ bool apple_gfx_common_realize(AppleGFXState *s, DeviceS= tate *dev, PGDeviceDescriptor *desc, Error **errp) { PGDisplayDescriptor *disp_desc; + const AppleGFXDisplayMode *display_modes =3D apple_gfx_default_modes; + uint32_t num_display_modes =3D ARRAY_SIZE(apple_gfx_default_modes); + NSArray *mode_array; =20 if (apple_gfx_mig_blocker =3D=3D NULL) { error_setg(&apple_gfx_mig_blocker, @@ -776,8 +782,99 @@ bool apple_gfx_common_realize(AppleGFXState *s, Device= State *dev, port:0 serialNum:next_pgdisplay_serial_n= um++]; [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 mode_array =3D + apple_gfx_create_display_mode_array(display_modes, num_display_mod= es); + [mode_array release]; =20 s->con =3D graphic_console_init(dev, 0, &apple_gfx_fb_ops, s); return true; } + +/* ------ Display mode list device property ------ */ + +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); + const char *endptr; + g_autofree char *str =3D NULL; + int ret; + int val; + + if (!visit_type_str(v, name, &str, errp)) { + 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); + return; + } + 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 a50e4eea0c..52786e6e18 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -212,6 +212,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.5 (Apple Git-154)