From patchwork Mon Oct 30 14:39:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1857147 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=AL6U92Ku; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SJwvD2xC9z1yQW for ; Tue, 31 Oct 2023 01:41:28 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxTRH-0001ON-O8; Mon, 30 Oct 2023 10:40:24 -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 1qxTRF-0001O2-Rb for qemu-ppc@nongnu.org; Mon, 30 Oct 2023 10:40:21 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxTR9-0001mc-C3 for qemu-ppc@nongnu.org; Mon, 30 Oct 2023 10:40:21 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40790b0a224so33366525e9.0 for ; Mon, 30 Oct 2023 07:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698676808; x=1699281608; 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=k6siaLDPN7rSUcCidjmSdujoZ1Clu6ak+uuvWhAfvmw=; b=AL6U92Kutol4J+wa3wAIFluDUGyz6apXLR542dFacd/PZZJOOixnspwIBfGo2AjB5V PurkAjC4HIFtigzycQz0QslPyOEZKzXorsvn4kWq8bRH14mXrcTqe0KURmLFI14/oPsP hFGkRR6ukWPRDAxVsEzx62G8pdlsB2liDsDa15yUTriCVbH7zHtsL/xPczZAJSGJ5waO CCIojWqsozvSm8XS+q3feDDJUcVq9eSdTT7kAdOERmQ3PxTjLttpRHhC4ltxi1TaTl2h jESlYgVl47RrVrjRh3R+ZSm5Fzpj1FU6nXxyhe9a9MGYsQU6zOi8KTYmN6q1fr1ro6fZ sCaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698676808; x=1699281608; 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=k6siaLDPN7rSUcCidjmSdujoZ1Clu6ak+uuvWhAfvmw=; b=J8PFYYkl2rrp95VGuu38ahvOO9KV0hP52kIGqVCA8WTi09LY7XpWqPR29M4mIGU4UZ ky3f60xU2lHFxIkpeXaIFuMIqsUDRRrN+OWtTCGUv7NQBcvKafCmB1jvVhGWLt5IxX2A g9GaacN4iNN1v7N7v3hb8VKJSQaA6aMHrrZj1jX7Pf+DZ+2lGgD3eeU5gMYcAHIy8oN9 3ojHir3CKBMBLAr6VFsv+3U0+AAM2PBbdBBdDMfGry4sI5v2A4ERpt4jE7fo/kmnxWAQ Koqh4bUPfFlfkUCQzPlCNa0OIrM4QwQZ1LdKPxNdPgLIJV9//Vzo0LpbG1xJHER4vlwj oP2A== X-Gm-Message-State: AOJu0YzkzByv4IFgUkaICanV/AAkQfr8qI9WxDWjFOF+leKKnHNFK+qx 4KC7sGuM56TAr0CNY2D5thYVwg== X-Google-Smtp-Source: AGHT+IEN1tC7QqL+vvg0htfcj01AzEW/xTlNdfksFtZAlrrQUX0XcOeSfEcP/xGD7BuUuisxF7KARw== X-Received: by 2002:a05:600c:3b20:b0:407:612b:91fb with SMTP id m32-20020a05600c3b2000b00407612b91fbmr8013575wms.30.1698676808504; Mon, 30 Oct 2023 07:40:08 -0700 (PDT) Received: from m1x-phil.lan ([176.170.212.50]) by smtp.gmail.com with ESMTPSA id bg9-20020a05600c3c8900b004063cd8105csm13009491wmb.22.2023.10.30.07.40.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Oct 2023 07:40:08 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Peter Maydell , Markus Armbruster Cc: Luc Michel , Daniel Henrique Barboza , Alistair Francis , Paolo Bonzini , Eduardo Habkost , Mark Cave-Ayland , Bernhard Beschow , qemu-ppc@nongnu.org, "Edgar E . Iglesias" , "Daniel P . Berrange" , Thomas Huth , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 1/5] qdev: Add qdev_prop_set_array() Date: Mon, 30 Oct 2023 15:39:52 +0100 Message-ID: <20231030143957.82988-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231030143957.82988-1-philmd@linaro.org> References: <20231030143957.82988-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=philmd@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-ppc@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-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kevin Wolf Instead of exposing the ugly hack of how we represent arrays in qdev (a static "foo-len" property and after it is set, dynamically created "foo[i]" properties) to boards, add an interface that allows setting the whole array at once. Once all internal users of devices with array properties have been converted to use this function, we can change the implementation to move away from this hack. Signed-off-by: Kevin Wolf Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Peter Maydell Tested-by: Philippe Mathieu-Daudé Message-ID: <20231030114802.3671871-4-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé --- include/hw/qdev-properties.h | 3 +++ hw/core/qdev-properties.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index e1df08876c..7fa2fdb7c9 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -206,6 +206,9 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name, const uint8_t *value); void qdev_prop_set_enum(DeviceState *dev, const char *name, int value); +/* Takes ownership of @values */ +void qdev_prop_set_array(DeviceState *dev, const char *name, QList *values); + void *object_field_prop_ptr(Object *obj, Property *prop); void qdev_prop_register_global(GlobalProperty *prop); diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 357b8761b5..950ef48e01 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -3,12 +3,14 @@ #include "qapi/error.h" #include "qapi/qapi-types-misc.h" #include "qapi/qmp/qerror.h" +#include "qapi/qmp/qlist.h" #include "qemu/ctype.h" #include "qemu/error-report.h" #include "qapi/visitor.h" #include "qemu/units.h" #include "qemu/cutils.h" #include "qdev-prop-internal.h" +#include "qom/qom-qobject.h" void qdev_prop_set_after_realize(DeviceState *dev, const char *name, Error **errp) @@ -739,6 +741,25 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value) &error_abort); } +void qdev_prop_set_array(DeviceState *dev, const char *name, QList *values) +{ + const QListEntry *entry; + g_autofree char *prop_len = g_strdup_printf("len-%s", name); + uint32_t i = 0; + + object_property_set_int(OBJECT(dev), prop_len, qlist_size(values), + &error_abort); + + QLIST_FOREACH_ENTRY(values, entry) { + g_autofree char *prop_idx = g_strdup_printf("%s[%u]", name, i); + object_property_set_qobject(OBJECT(dev), prop_idx, entry->value, + &error_abort); + i++; + } + + qobject_unref(values); +} + static GPtrArray *global_props(void) { static GPtrArray *gp;