qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Defaults for qdev properties inherited from bus
Date: Thu, 03 Sep 2009 23:49:50 +0200	[thread overview]
Message-ID: <873a73d7gh.fsf@pike.pond.sub.org> (raw)

Devices inherit some properties from their bus.  For instance, ISA
devices inherit iobase, iobase2, and PCI devices inherit addr.

Properties have a default value.  For inherited properties, the same
default value has to do for all devices on the same kind of bus, because
the default value is inherited from the bus along with the property.

This isn't always a problem.  For instance, PCI addr defaulting to "pick
one" is exactly right for most devices.  Not so for the ISA iobases:
devices have different default I/O addresses.

Note that isa_create_simple() mask this problem: it takes iobases as
arguments, and the property default value is not used.  The problem
becomes visible when devices are created with -device.

One way to deal with this is to code the true default values in the
device's init() callback: check whether the value is still the
inherited, unwanted default, and if yes, set it to the true default.
Like this:

    if (dev->iobase[0] == -1)
        dev->iobase[0] = 0x441;
    if (dev->iobase[1] == -1)
        dev->iobase[1] = 0x443;

Workable, if not exactly elegant.

A related problem is validation of property vales.  Devices may accept
only a subset of the values the property inherited from the bus accepts.
For instance, ISA devices can typically use only to a fixed set of I/O
addresses.  The bus's PropertyInfo doesn't know them, so this doesn't
get checked.

One way to deal with this is to validate in the device's init()
callback: fail it when the values aren't acceptable.  Like this:

    if (dev->iobase[0] != 0x441 || dev->iobase[1] != 0x443)
        return -1;

Detects bad configuration relatively late.  Is this okay?

             reply	other threads:[~2009-09-03 21:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-03 21:49 Markus Armbruster [this message]
2009-09-04  8:14 ` [Qemu-devel] Defaults for qdev properties inherited from bus Gerd Hoffmann
2009-09-04 17:39   ` Markus Armbruster
2009-09-07 11:02     ` Gerd Hoffmann

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=873a73d7gh.fsf@pike.pond.sub.org \
    --to=armbru@redhat.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).