From: Thomas Huth <thuth@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Michael S Tsirkin <mst@redhat.com>,
qemu-devel@nongnu.org, Bernhard Beschow <shentey@gmail.com>,
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"BALATON Zoltan" <balaton@eik.bme.hu>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Eduardo Habkost" <eduardo@habkost.net>
Subject: [PATCH v6 2/4] hw/core/qdev-properties-system: Allow the 'slew' policy only on x86
Date: Tue, 10 Jan 2023 10:53:49 +0100 [thread overview]
Message-ID: <20230110095351.611724-3-thuth@redhat.com> (raw)
In-Reply-To: <20230110095351.611724-1-thuth@redhat.com>
The 'slew' tick policy is currently enforced to be only available on
x86 via some "#ifdef TARGET_I386" statements in mc146818rtc.c. We
want to get rid of those #ifdefs, so we need a different way of
checking whether the policy is allowed or not. Using the setter
function in hw/core/qdev-properties-system.c seems to be a good
place, so let's add a check here.
Suggested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
hw/core/qdev-properties-system.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 54a09fa9ac..d42493f630 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -33,6 +33,7 @@
#include "net/net.h"
#include "hw/pci/pci.h"
#include "hw/pci/pcie.h"
+#include "hw/i386/x86.h"
#include "util/block-helpers.h"
static bool check_prop_still_unset(Object *obj, const char *name,
@@ -558,13 +559,38 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
/* --- lost tick policy --- */
+static void qdev_propinfo_set_losttickpolicy(Object *obj, Visitor *v,
+ const char *name, void *opaque,
+ Error **errp)
+{
+ Property *prop = opaque;
+ int *ptr = object_field_prop_ptr(obj, prop);
+ int value;
+
+ if (!visit_type_enum(v, name, &value, prop->info->enum_table, errp)) {
+ return;
+ }
+
+ if (value == LOST_TICK_POLICY_SLEW) {
+ MachineState *ms = MACHINE(qdev_get_machine());
+
+ if (!object_dynamic_cast(OBJECT(ms), TYPE_X86_MACHINE)) {
+ error_setg(errp,
+ "the 'slew' policy is only available for x86 machines");
+ return;
+ }
+ }
+
+ *ptr = value;
+}
+
QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int));
const PropertyInfo qdev_prop_losttickpolicy = {
.name = "LostTickPolicy",
.enum_table = &LostTickPolicy_lookup,
.get = qdev_propinfo_get_enum,
- .set = qdev_propinfo_set_enum,
+ .set = qdev_propinfo_set_losttickpolicy,
.set_default_value = qdev_propinfo_set_default_value_enum,
};
--
2.31.1
next prev parent reply other threads:[~2023-01-10 10:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-10 9:53 [PATCH v6 0/4] Make the mc146818 RTC device target independent Thomas Huth
2023-01-10 9:53 ` [PATCH v6 1/4] hw/intc: Extract the IRQ counting functions into a separate file Thomas Huth
2023-01-11 22:48 ` Bernhard Beschow
2023-01-10 9:53 ` Thomas Huth [this message]
2023-01-11 22:52 ` [PATCH v6 2/4] hw/core/qdev-properties-system: Allow the 'slew' policy only on x86 Bernhard Beschow
2023-01-10 9:53 ` [PATCH v6 3/4] hw/rtc/mc146818rtc: Make the mc146818 RTC device target independent Thomas Huth
2023-01-10 9:53 ` [PATCH v6 4/4] softmmu/rtc: Emit warning when using driftfix=slew on systems without mc146818 Thomas Huth
2023-01-10 10:21 ` [PATCH v6 0/4] Make the mc146818 RTC device target independent Philippe Mathieu-Daudé
2023-01-10 23:16 ` Mark Cave-Ayland
2023-01-13 8:54 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230110095351.611724-3-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=balaton@eik.bme.hu \
--cc=eduardo@habkost.net \
--cc=marcel.apfelbaum@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=shentey@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).