From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MjKBw-0000FG-P0 for qemu-devel@nongnu.org; Thu, 03 Sep 2009 17:50:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MjKBs-0000Do-99 for qemu-devel@nongnu.org; Thu, 03 Sep 2009 17:50:04 -0400 Received: from [199.232.76.173] (port=38371 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MjKBr-0000Di-WF for qemu-devel@nongnu.org; Thu, 03 Sep 2009 17:50:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33469) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MjKBq-0003W1-VA for qemu-devel@nongnu.org; Thu, 03 Sep 2009 17:49:59 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n83LnqId021290 for ; Thu, 3 Sep 2009 17:49:52 -0400 Received: from pike.pond.sub.org (vpn-10-13.str.redhat.com [10.32.10.13]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n83Lnpf0008144 for ; Thu, 3 Sep 2009 17:49:52 -0400 From: Markus Armbruster Date: Thu, 03 Sep 2009 23:49:50 +0200 Message-ID: <873a73d7gh.fsf@pike.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] Defaults for qdev properties inherited from bus List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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?