From patchwork Wed Oct 15 09:05:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 399830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7A160140119 for ; Wed, 15 Oct 2014 20:10:07 +1100 (EST) Received: from localhost ([::1]:42919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeKar-0003ET-Ha for incoming@patchwork.ozlabs.org; Wed, 15 Oct 2014 05:10:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeKXm-0006TT-Fj for qemu-devel@nongnu.org; Wed, 15 Oct 2014 05:07:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeKXd-00071m-Sr for qemu-devel@nongnu.org; Wed, 15 Oct 2014 05:06:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13634) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeKXd-00071V-LC for qemu-devel@nongnu.org; Wed, 15 Oct 2014 05:06:45 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9F96dHL015394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 15 Oct 2014 05:06:39 -0400 Received: from nilsson.home.kraxel.org (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9F96bPD004627; Wed, 15 Oct 2014 05:06:37 -0400 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id E9FF9814DC; Wed, 15 Oct 2014 11:06:35 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 15 Oct 2014 11:05:44 +0200 Message-Id: <1413363967-2489-12-git-send-email-kraxel@redhat.com> In-Reply-To: <1413363967-2489-1-git-send-email-kraxel@redhat.com> References: <1413363967-2489-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gonglei , Gerd Hoffmann Subject: [Qemu-devel] [PULL 11/34] ne2000: add bootindex to qom property X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gonglei Add a qom property with the same name 'bootindex', when we remove it form qdev property, things will continue to work just fine, and we can use qom features which are not supported by qdev property. At present, isa_ne2000 device does not support to boot os, so we register two seprate qom getter/setter functions. Signed-off-by: Gonglei Reviewed-by: Gerd Hoffmann Signed-off-by: Gerd Hoffmann --- hw/net/ne2000-isa.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/net/ne2000.c | 12 ++++++++++++ 2 files changed, 56 insertions(+) diff --git a/hw/net/ne2000-isa.c b/hw/net/ne2000-isa.c index 6eb1dac..82e2ba1 100644 --- a/hw/net/ne2000-isa.c +++ b/hw/net/ne2000-isa.c @@ -28,6 +28,7 @@ #include "net/net.h" #include "ne2000.h" #include "exec/address-spaces.h" +#include "qapi/visitor.h" #define TYPE_ISA_NE2000 "ne2k_isa" #define ISA_NE2000(obj) OBJECT_CHECK(ISANE2000State, (obj), TYPE_ISA_NE2000) @@ -101,11 +102,54 @@ static void isa_ne2000_class_initfn(ObjectClass *klass, void *data) set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); } +static void isa_ne2000_get_bootindex(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + ISANE2000State *isa = ISA_NE2000(obj); + NE2000State *s = &isa->ne2000; + + visit_type_int32(v, &s->c.bootindex, name, errp); +} + +static void isa_ne2000_set_bootindex(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + ISANE2000State *isa = ISA_NE2000(obj); + NE2000State *s = &isa->ne2000; + int32_t boot_index; + Error *local_err = NULL; + + visit_type_int32(v, &boot_index, name, &local_err); + if (local_err) { + goto out; + } + /* check whether bootindex is present in fw_boot_order list */ + check_boot_index(boot_index, &local_err); + if (local_err) { + goto out; + } + /* change bootindex to a new one */ + s->c.bootindex = boot_index; + +out: + if (local_err) { + error_propagate(errp, local_err); + } +} + +static void isa_ne2000_instance_init(Object *obj) +{ + object_property_add(obj, "bootindex", "int32", + isa_ne2000_get_bootindex, + isa_ne2000_set_bootindex, NULL, NULL, NULL); + object_property_set_int(obj, -1, "bootindex", NULL); +} static const TypeInfo ne2000_isa_info = { .name = TYPE_ISA_NE2000, .parent = TYPE_ISA_DEVICE, .instance_size = sizeof(ISANE2000State), .class_init = isa_ne2000_class_initfn, + .instance_init = isa_ne2000_instance_init, }; static void ne2000_isa_register_types(void) diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c index a62d12d..62b86af 100644 --- a/hw/net/ne2000.c +++ b/hw/net/ne2000.c @@ -752,6 +752,17 @@ static void pci_ne2000_exit(PCIDevice *pci_dev) qemu_free_irq(s->irq); } +static void ne2000_instance_init(Object *obj) +{ + PCIDevice *pci_dev = PCI_DEVICE(obj); + PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev); + NE2000State *s = &d->ne2000; + + device_add_bootindex_property(obj, &s->c.bootindex, + "bootindex", "/ethernet-phy@0", + &pci_dev->qdev, NULL); +} + static Property ne2000_properties[] = { DEFINE_NIC_PROPERTIES(PCINE2000State, ne2000.c), DEFINE_PROP_END_OF_LIST(), @@ -778,6 +789,7 @@ static const TypeInfo ne2000_info = { .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCINE2000State), .class_init = ne2000_class_init, + .instance_init = ne2000_instance_init, }; static void ne2000_register_types(void)