From patchwork Tue Jan 2 16:04:51 2024 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: 759371 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp6113612wrw; Tue, 2 Jan 2024 08:07:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyt0dMTopjdCbOtqMmNJrIJUMu72bJ2oiI3PlTMU6LGTf9qnIGLuO23tKTeBBrpxZ6Eqkt X-Received: by 2002:ac8:774f:0:b0:428:23f2:401d with SMTP id g15-20020ac8774f000000b0042823f2401dmr3159459qtu.60.1704211638846; Tue, 02 Jan 2024 08:07:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704211638; cv=none; d=google.com; s=arc-20160816; b=AuRNZ9gEBeI6yP/uFlPqvGUf8zwjrzYcWZ5BbGaSNXWYpxm9/RO6Cs+64qnaB7fncz SesDlQk+T3URS3kMDYCI25qXTX9oyWQU1uud6+HTUUnCYx7FWavDAtFQ2C4efnq8BvzI 24idOrWoWNAoEPcZTRtmNVMJFSY/gwotnR6SAi60NTTotbpfur/K7xvS75HTTaX/Xdgl EJuVt6Wzb+tHM390HRffKcGPwvd1FCrTL2tcgNRRtXGhrQZ8PR6aLexn3veBVI1bI5YR gTPlP9VKVyoMDpb5TZyUZH3VzDWO1uMGL5PVj6FH59wC9rMkATAufo3k0fI2py1FZqgb AWqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ufonMTH/Sl8kmFdoBgYSf3okj9N+8Wa+NSxI0KCId+c=; fh=Fbl4rt7vNadFyu+mhE5sPZ2m5GJmVL0UTbP+h3uuTlY=; b=Tb/ZSruLlfGvBHlMN2uj4Iboyr3Hzc+Q2r1UPWViCAGr5wcs4yRInbhWy2anESoI8H 0bcOFnCEp2SVElrdmWTssLqk0lmKdisQBIPKPrmfI/mHhqmxIbUzIgTSrQk9v9IIL11y ucAd5IL8P+r7F44i2D06MDLtqW9e7xq12stV37AIiJ1Xcy49xY5e4QQYVOEoFYwKV3cX sQwGpw3En4u/cDa7ppv6Kh9qzhZhT/kaBwUYvrUyzNATsADHyhUgDa8Gur6gRtOI0E0q +rqPbC3WjKOFnCBEwR+rIyTPIn+ZK3aXYOSuV9YBKWnwPQoQjdk5uCI6U7PKFvkZT/6o l/1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D1llJWyG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id cc5-20020a05622a410500b0042588d183b4si27112269qtb.753.2024.01.02.08.07.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jan 2024 08:07:18 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D1llJWyG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rKhGj-0006K2-Qz; Tue, 02 Jan 2024 11:05:29 -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 1rKhGY-0006Gg-1g for qemu-devel@nongnu.org; Tue, 02 Jan 2024 11:05:18 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rKhGS-0002cW-Th for qemu-devel@nongnu.org; Tue, 02 Jan 2024 11:05:17 -0500 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40d5b89e2bfso56729165e9.0 for ; Tue, 02 Jan 2024 08:05:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704211511; x=1704816311; 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=ufonMTH/Sl8kmFdoBgYSf3okj9N+8Wa+NSxI0KCId+c=; b=D1llJWyGhZgFxn3O2fUJEH05tVzdAkpeFyOfCxiUWfIyhoaJ6XD+ovIJKi+cSAc/na oCEwjCsJjOVzfue1dERqMHkBmP0ZeU47qtZf40eJb8ChQxGqpp0614Zd1NuuiPNhh+dL XGPvzbiCu9G/Dsopzsm+e85Es7B0fCJh2zAc1JOBxxIHZVqin1YtoulBbVUlvzEbu3Mv 3vAif3PBo/OjNhH0Gs1g3gaX6bol55Z45uuNAspe6Br2h+pbCqQymOrzfr1Wk6Ka/lWY t/kXvLBIE0j9CdTiHEAaPmizxBFphCdTubarCDlYhAZMjbWnnw6rM8EpMDMMmMQrxOkq LMQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704211511; x=1704816311; 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=ufonMTH/Sl8kmFdoBgYSf3okj9N+8Wa+NSxI0KCId+c=; b=rwbyIZUQEYBHh43jeEMoQSzKv5NqVKYemgtvDObc1eU3ekjkj+yO7EhxMnCFsWu0en NborIQSxVgivfwA/PdaPjTlGd5Sa4SgAnhD+M11lPo9MH41y+5mt58wHzwpmljrS3i67 Qw4WhUdo3zJydDUpyPew0EfmnWpOA15WYUWS5GZk+BX9prJy5GGTVlnsKXEbuDFs2rhY r1ruZ71ayVeZudwo/1+Qr9xZmejr1GTlqrNp3uqPkjE3pZbv0MAkrugapzRWONmhZB4M uVk1Aiz4VuyE8SsFeNSlXubttr7WWRZZVjUhHEOWU8bKEObjM/fS7CudvHSSIvEiw4hp LoyQ== X-Gm-Message-State: AOJu0Yyzgv7CSkv/+2fbZ5pjA6J7LeBvgG/LXD6ij8Zm/BR8C/prySQ7 +qKYrsII4rK17R7FH53BTlaHZPnsOPc2TEvJVX33YGoOHXQ= X-Received: by 2002:a05:600c:520c:b0:40d:8a04:a134 with SMTP id fb12-20020a05600c520c00b0040d8a04a134mr934490wmb.79.1704211511039; Tue, 02 Jan 2024 08:05:11 -0800 (PST) Received: from m1x-phil.lan (sal63-h02-176-184-16-71.dsl.sta.abo.bbox.fr. [176.184.16.71]) by smtp.gmail.com with ESMTPSA id bg29-20020a05600c3c9d00b0040d6d755c90sm19136952wmb.42.2024.01.02.08.05.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jan 2024 08:05:10 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Blake , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , qemu-arm@nongnu.org, Luc Michel , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Mark Cave-Ayland , Eduardo Habkost , Frederic Konrad , Markus Armbruster , Paolo Bonzini , Kevin Wolf , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [RFC PATCH 2/5] qdev-properties: Add OptionalBool QAPI type Date: Tue, 2 Jan 2024 17:04:51 +0100 Message-ID: <20240102160455.68612-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240102160455.68612-1-philmd@linaro.org> References: <20240102160455.68612-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=philmd@linaro.org; helo=mail-wm1-x329.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org To be able to distinct whether a boolean qdev property has been set or not, add the DEFINE_PROP_BOOL_NODEFAULT() qdev macro based on the tri-state OptionalBool QAPI type. Signed-off-by: Philippe Mathieu-Daudé --- qapi/common.json | 16 ++++++++++++++++ include/hw/qdev-properties.h | 5 +++++ hw/core/qdev-properties.c | 10 ++++++++++ 3 files changed, 31 insertions(+) diff --git a/qapi/common.json b/qapi/common.json index 6fed9cde1a..884c143e2a 100644 --- a/qapi/common.json +++ b/qapi/common.json @@ -207,3 +207,19 @@ ## { 'struct': 'HumanReadableText', 'data': { 'human-readable-text': 'str' } } + +## +# @OptionalBool: +# +# An enumeration of three options: true, false, and unset +# +# @unset: Unset (default) +# +# @false: False +# +# @true: True +# +# Since: 9.0 +## +{ 'enum': 'OptionalBool', + 'data': [ 'false', 'true', 'unset' ] } diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 0e1930177e..8cf95da2c3 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -49,6 +49,7 @@ struct PropertyInfo { extern const PropertyInfo qdev_prop_bit; extern const PropertyInfo qdev_prop_bit64; extern const PropertyInfo qdev_prop_bool; +extern const PropertyInfo qdev_prop_bool_unset; extern const PropertyInfo qdev_prop_enum; extern const PropertyInfo qdev_prop_uint8; extern const PropertyInfo qdev_prop_uint16; @@ -105,6 +106,10 @@ extern const PropertyInfo qdev_prop_link; .set_default = true, \ .defval.u = (bool)_defval) +#define DEFINE_PROP_BOOL_NODEFAULT(_name, _state, _field) \ + DEFINE_PROP_SIGNED(_name, _state, _field, OPTIONAL_BOOL_UNSET, \ + qdev_prop_bool_unset, OptionalBool) + /** * The DEFINE_PROP_UINT64_CHECKMASK macro checks a user-supplied value * against corresponding bitmask, rejects the value if it violates. diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 0c17a5de82..1bec8ee679 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -260,6 +260,16 @@ const PropertyInfo qdev_prop_bool = { .set_default_value = set_default_value_bool, }; +/* --- optional bool --- */ + +const PropertyInfo qdev_prop_bool_unset = { + .name = "OptionalBool", + .enum_table = &OptionalBool_lookup, + .get = qdev_propinfo_get_enum, + .set = qdev_propinfo_set_enum, + .set_default_value = qdev_propinfo_set_default_value_enum, +}; + /* --- 8bit integer --- */ static void get_uint8(Object *obj, Visitor *v, const char *name, void *opaque,