From nobody Sun Dec 29 02:03:39 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1720933932; cv=none; d=zohomail.com; s=zohoarc; b=IL99QUC6y9r+gzYxqB+OuMbSekHZNZek4V6ldB66yIum/7TGyPzB06elMfazxG9dJz9+GPioH9/xLQUDT5igqriddl2CDZJZVkqVsKvwbIxb+lSRddb83I+QlH5PZKJPS5Sxw6x5IeBeNf1OkHykYw2Ta/m73txMeKbS+yvIc5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720933932; 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=gsn8jpde5vwnK4glFB3pIQsd6ePaO9NWMI60GGv1GCU=; b=HTKrO5B62Mjmap7UifnMTmEmUV2cODE5poAU2VywsmxXR+A8Il30UpkDDGC2ocDiO0rZuYfwEehAsRa4kbO32nU2RcRSu9Dp+m55oeQko2AcEeo447OP3bsIDXKGZ6QTamrGSIkaHlN4IrNW/SFvauxNDNsj0UTMWlIMkswWQi0= 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+importer2=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 1720933932620841.7854178427523; Sat, 13 Jul 2024 22:12:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSrWE-0007LL-FA; Sun, 14 Jul 2024 01:11:31 -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 1sSrW4-0007JH-5M for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:21 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0: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 1sSrW1-00051y-Fn for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:18 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1fb4a807708so29271285ad.2 for ; Sat, 13 Jul 2024 22:11:17 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fc0bc44f5fsm17760665ad.238.2024.07.13.22.11.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Jul 2024 22:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720933876; x=1721538676; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gsn8jpde5vwnK4glFB3pIQsd6ePaO9NWMI60GGv1GCU=; b=dnJ0gOhgISgSswEWWuTQHQu1Wp6/OW9RVxe5TsoJ/Vccq0et6ut19+cDI551ffKKS+ FgOGBb1thZ0rFM+flvR+Lcvjo7IlWSwzgdV76Od5cq7wlM4ek51LXSZKAaAPqM3e57/1 AaJeaVwK24gkgKtur3meyPn/0koVq2R2mZCJuMn0ugUV+eT1As/65O7qHii6lzIe50qL Hj/ycNXVZMCSGeZy4d6vwc8zFHMk3TZ8Ewlhucgwn6YsN3qTexeWbS/3KKO7qvZtvM3/ irnHmxGCQbk1/eNUT/ZkAG64r40/UoyhVsEGVO62qtTiYu5YPYsrja7kGQbIAjFh/nDJ 3plg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720933876; x=1721538676; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gsn8jpde5vwnK4glFB3pIQsd6ePaO9NWMI60GGv1GCU=; b=jrfpYKmilqsa8o1ioRllugqAeXcpQ7sNOLQpG1oW+wZNPGiUDL9LIZdVO1Bo9vmVNP F5YY/k/PCIcQxWljYCl21BaHJ+nEpjBmY/4M/EQe16SrwrMezts8fXkH5BYlOdf3j6Cy nDpO5ASqjdYu+nhX0/1kSCcF2saijWGQVwjjKgKOhI+lNwJrx7zMHP1g32ecyjYu4pYc Hhq2R0IG95wjhmhvFGodge2BQXADWvu5ZGUparQotf5iI6fM33NWUitWeGNMfvCF6ypp oOIaZAI9zkQkItriVj0tph6Z7y3eEb3LeJtnBdwdSXDBC33eRMqnVVblRwfNSXaCYtk5 SnBw== X-Gm-Message-State: AOJu0YxTstl3vq0GGaZGcEV5ZZbzqB/BZ5ULx8A90Jh2585lVE4Wn2JU hlrk3jrD7B7/24SsQ4mhAlY4ekF8piAlLHLrkoRvJewrSNNeaMjI5gTMdlol+i8= X-Google-Smtp-Source: AGHT+IH3EBrhk+JbKV6OPWC33Q5kJgU369sgVZV7MCI845M7gR8y5gKhkWctiuVldR06nk+OsWsSqQ== X-Received: by 2002:a17:902:d48d:b0:1fb:4fa4:d20 with SMTP id d9443c01a7336-1fbb6d59ed0mr169541645ad.38.1720933876122; Sat, 13 Jul 2024 22:11:16 -0700 (PDT) From: Akihiko Odaki Date: Sun, 14 Jul 2024 14:11:02 +0900 Subject: [PATCH v3 2/5] qdev-properties: Add DEFINE_PROP_ON_OFF_AUTO_BIT64() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240714-auto-v3-2-e27401aabab3@daynix.com> References: <20240714-auto-v3-0-e27401aabab3@daynix.com> In-Reply-To: <20240714-auto-v3-0-e27401aabab3@daynix.com> To: Jason Wang , Dmitry Fleytman , Sriram Yagnaraman , "Michael S. Tsirkin" , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Andrew Melnychenko , Yuri Benditovich , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::630; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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_NONE=0.001 autolearn=ham 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1720933934693116300 DEFINE_PROP_ON_OFF_AUTO_BIT64() corresponds to DEFINE_PROP_ON_OFF_AUTO() as DEFINE_PROP_BIT64() corresponds to DEFINE_PROP_BOOL(). The difference is that DEFINE_PROP_ON_OFF_AUTO_BIT64() exposes OnOffAuto instead of bool. Signed-off-by: Akihiko Odaki --- include/hw/qdev-properties.h | 18 ++++++++++++ hw/core/qdev-properties.c | 66 ++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 09aa04ca1e27..afec53a48470 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -43,11 +43,22 @@ struct PropertyInfo { ObjectPropertyRelease *release; }; =20 +/** + * struct OnOffAutoBit64 - OnOffAuto storage with 64 elements. + * @on_bits: Bitmap of elements with "on". + * @auto_bits: Bitmap of elements with "auto". + */ +typedef struct OnOffAutoBit64 { + uint64_t on_bits; + uint64_t auto_bits; +} OnOffAutoBit64; + =20 /*** qdev-properties.c ***/ =20 extern const PropertyInfo qdev_prop_bit; extern const PropertyInfo qdev_prop_bit64; +extern const PropertyInfo qdev_prop_on_off_auto_bit64; extern const PropertyInfo qdev_prop_bool; extern const PropertyInfo qdev_prop_enum; extern const PropertyInfo qdev_prop_uint8; @@ -100,6 +111,13 @@ extern const PropertyInfo qdev_prop_link; .set_default =3D true, \ .defval.u =3D (bool)_defval) =20 +#define DEFINE_PROP_ON_OFF_AUTO_BIT64(_name, _state, _field, _bit, _defval= ) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_on_off_auto_bit64, = \ + OnOffAutoBit64, = \ + .bitnr =3D (_bit), = \ + .set_default =3D true, = \ + .defval.i =3D (OnOffAuto)_defval) + #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \ DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \ .set_default =3D true, \ diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index f0a270bb4f61..cc76ff0dfae6 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -187,7 +187,8 @@ const PropertyInfo qdev_prop_bit =3D { =20 static uint64_t qdev_get_prop_mask64(Property *prop) { - assert(prop->info =3D=3D &qdev_prop_bit64); + assert(prop->info =3D=3D &qdev_prop_bit64 || + prop->info =3D=3D &qdev_prop_on_off_auto_bit64); return 0x1ull << prop->bitnr; } =20 @@ -232,6 +233,69 @@ const PropertyInfo qdev_prop_bit64 =3D { .set_default_value =3D set_default_value_bool, }; =20 +static void prop_get_on_off_auto_bit64(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop =3D opaque; + OnOffAutoBit64 *p =3D object_field_prop_ptr(obj, prop); + int value; + uint64_t mask =3D qdev_get_prop_mask64(prop); + + if (p->auto_bits & mask) { + value =3D ON_OFF_AUTO_AUTO; + } else if (p->on_bits & mask) { + value =3D ON_OFF_AUTO_ON; + } else { + value =3D ON_OFF_AUTO_OFF; + } + + visit_type_enum(v, name, &value, &OnOffAuto_lookup, errp); +} + +static void prop_set_on_off_auto_bit64(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop =3D opaque; + OnOffAutoBit64 *p =3D object_field_prop_ptr(obj, prop); + bool bool_value; + int value; + uint64_t mask =3D qdev_get_prop_mask64(prop); + + if (visit_type_bool(v, name, &bool_value, NULL)) { + value =3D bool_value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; + } else if (!visit_type_enum(v, name, &value, &OnOffAuto_lookup, errp))= { + return; + } + + switch (value) { + case ON_OFF_AUTO_AUTO: + p->on_bits &=3D ~mask; + p->auto_bits |=3D mask; + break; + + case ON_OFF_AUTO_ON: + p->on_bits |=3D mask; + p->auto_bits &=3D ~mask; + break; + + case ON_OFF_AUTO_OFF: + p->on_bits &=3D ~mask; + p->auto_bits &=3D ~mask; + break; + } +} + +const PropertyInfo qdev_prop_on_off_auto_bit64 =3D { + .name =3D "OnOffAuto", + .description =3D "on/off/auto", + .enum_table =3D &OnOffAuto_lookup, + .get =3D prop_get_on_off_auto_bit64, + .set =3D prop_set_on_off_auto_bit64, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + /* --- bool --- */ =20 static void get_bool(Object *obj, Visitor *v, const char *name, void *opaq= ue, --=20 2.45.2