From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com
Subject: [Qemu-devel] [PATCH 6/9] qdev: accept both strings and integers for PCI addresses
Date: Thu, 9 Feb 2012 15:31:55 +0100 [thread overview]
Message-ID: <1328797918-1316-7-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1328797918-1316-1-git-send-email-pbonzini@redhat.com>
Visitors allow a limited form of polymorphism. Exploit it to support
setting the non-legacy PCI address property both as a DD.F string
and as an 8-bit integer.
The 8-bit integer form is just too clumsy, it is unlikely that we will
ever drop it.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/qdev-properties.c | 36 +++++++++++++++++++++++++-----------
1 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index b6d6fcf..9a838b0 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -943,25 +943,40 @@ PropertyInfo qdev_prop_losttickpolicy = {
/*
* bus-local address, i.e. "$slot" or "$slot.$fn"
*/
-static int parse_pci_devfn(DeviceState *dev, Property *prop, const char *str)
+static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
+ const char *name, Error **errp)
{
+ DeviceState *dev = DEVICE(obj);
+ Property *prop = opaque;
uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
unsigned int slot, fn, n;
+ Error *local_err = NULL;
+ char *str = (char *)"";
+
+ if (dev->state != DEV_STATE_CREATED) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ visit_type_str(v, &str, name, &local_err);
+ if (local_err) {
+ return set_int32(obj, v, opaque, name, errp);
+ }
if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) {
fn = 0;
if (sscanf(str, "%x%n", &slot, &n) != 1) {
- return -EINVAL;
+ goto invalid;
}
}
- if (str[n] != '\0')
- return -EINVAL;
- if (fn > 7)
- return -EINVAL;
- if (slot > 31)
- return -EINVAL;
+ if (str[n] != '\0' || fn > 7 || slot > 31) {
+ goto invalid;
+ }
*ptr = slot << 3 | fn;
- return 0;
+ return;
+
+invalid:
+ error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
}
static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t len)
@@ -978,10 +993,9 @@ static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t
PropertyInfo qdev_prop_pci_devfn = {
.name = "int32",
.legacy_name = "pci-devfn",
- .parse = parse_pci_devfn,
.print = print_pci_devfn,
.get = get_int32,
- .set = set_int32,
+ .set = set_pci_devfn,
/* FIXME: this should be -1...255, but the address is stored
* into an uint32_t rather than int32_t.
*/
--
1.7.7.6
next prev parent reply other threads:[~2012-02-09 14:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-09 14:31 [Qemu-devel] [PATCH 0/9] qdev deconstruction, command-line episode Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 1/9] qapi: allow sharing enum implementation across visitors Paolo Bonzini
2012-02-21 20:31 ` Andreas Färber
2012-02-22 7:30 ` Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 2/9] qapi: drop qmp_input_end_optional Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 3/9] qapi: add string-based visitors Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 4/9] qapi: add tests for " Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 5/9] qom: add generic string parsing/printing Paolo Bonzini
2012-02-21 20:47 ` Andreas Färber
2012-02-22 7:31 ` Paolo Bonzini
2012-02-09 14:31 ` Paolo Bonzini [this message]
2012-02-09 14:31 ` [Qemu-devel] [PATCH 7/9] qdev: accept hex properties only if prefixed by 0x Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 8/9] qdev: use built-in QOM string parser Paolo Bonzini
2012-02-09 14:31 ` [Qemu-devel] [PATCH 9/9] qdev: drop unnecessary parse/print methods Paolo Bonzini
2012-02-21 17:13 ` [Qemu-devel] [PULL v2 0/9] qdev deconstruction, command-line episode Paolo Bonzini
2012-02-22 14:44 ` Anthony Liguori
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=1328797918-1316-7-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
/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).