From patchwork Wed Jan 20 09:10:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 8070131 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BCE179F440 for ; Wed, 20 Jan 2016 09:13:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EA4EE203AC for ; Wed, 20 Jan 2016 09:13:01 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1381B201B9 for ; Wed, 20 Jan 2016 09:13:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aLomQ-00018Q-V2; Wed, 20 Jan 2016 09:10:18 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aLomO-00018K-TY for xen-devel@lists.xensource.com; Wed, 20 Jan 2016 09:10:17 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id BE/B8-13905-8FE4F965; Wed, 20 Jan 2016 09:10:16 +0000 X-Env-Sender: kraxel@redhat.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1453281013!16951172!1 X-Originating-IP: [209.132.183.28] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMjA5LjEzMi4xODMuMjggPT4gNTQwNjQ=\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10204 invoked from network); 20 Jan 2016 09:10:15 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by server-9.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Jan 2016 09:10:15 -0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 581648DFE8; Wed, 20 Jan 2016 09:10:13 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-40.ams2.redhat.com [10.36.116.40]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0K9AB46024712; Wed, 20 Jan 2016 04:10:12 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 1ED66806C1; Wed, 20 Jan 2016 10:10:11 +0100 (CET) Message-ID: <1453281011.11804.40.camel@redhat.com> From: Gerd Hoffmann To: Eduardo Habkost Date: Wed, 20 Jan 2016 10:10:11 +0100 In-Reply-To: <20160119151302.GB3869@thinpad.lan.raisama.net> References: <1451994098-6972-1-git-send-email-kraxel@redhat.com> <1451994098-6972-6-git-send-email-kraxel@redhat.com> <1452095101.6096.55.camel@redhat.com> <20160119151302.GB3869@thinpad.lan.raisama.net> Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 Cc: igvt-g@ml01.01.org, xen-devel@lists.xensource.com, Stefano Stabellini , qemu-devel@nongnu.org, Cao jin , vfio-users@redhat.com Subject: Re: [Xen-devel] [PATCH v3 05/11] igd: TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE: call parent realize X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, > > > > + i440fx_realize = k->realize; > > > > k->realize = igd_pt_i440fx_realize; > > > > ... because we are overriding it right here. > > Many device classes have a parent_realize field so they can keep > a pointer to the original realize function. It's better than a > static variable. How does the attached patch (incremental fix, not tested yet) look like? cheers, Gerd Reviewed-by: Eduardo Habkost From 3d110e297b5182107e055db3ab69092affdef5bb Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 20 Jan 2016 10:08:19 +0100 Subject: [PATCH] [fixup] TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE realize_parent --- hw/pci-host/igd.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/hw/pci-host/igd.c b/hw/pci-host/igd.c index 160828f..2d51745 100644 --- a/hw/pci-host/igd.c +++ b/hw/pci-host/igd.c @@ -49,12 +49,24 @@ out_free: g_free(path); } -static void (*i440fx_realize)(PCIDevice *pci_dev, Error **errp); +#define IGD_PT_I440FX_CLASS(class) \ + OBJECT_CLASS_CHECK(IGDPtI440fxClass, (class), \ + TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE) +#define IGD_PT_I440FX_GET_CLASS(obj) \ + OBJECT_GET_CLASS(IGDPtI440fxClass, (obj), \ + TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE) + +typedef struct IGDPtI440fxClass { + PCIDeviceClass parent_class; + void (*parent_realize)(PCIDevice *dev, Error **errp); +} IGDPtI440fxClass; + static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp) { + IGDPtI440fxClass *k = IGD_PT_I440FX_GET_CLASS(pci_dev); Error *err = NULL; - i440fx_realize(pci_dev, &err); + k->parent_realize(pci_dev, &err); if (err != NULL) { error_propagate(errp, err); return; @@ -72,11 +84,12 @@ static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp) static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data) { + IGDPtI440fxClass *k = IGD_PT_I440FX_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); - PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass); - i440fx_realize = k->realize; - k->realize = igd_pt_i440fx_realize; + k->parent_realize = pc->realize; + pc->realize = igd_pt_i440fx_realize; dc->desc = "IGD Passthrough Host bridge (i440fx)"; } @@ -84,6 +97,7 @@ static const TypeInfo igd_passthrough_i440fx_info = { .name = TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE, .parent = TYPE_I440FX_PCI_DEVICE, .class_init = igd_passthrough_i440fx_class_init, + .class_size = sizeof(IGDPtI440fxClass), }; static void (*q35_realize)(PCIDevice *pci_dev, Error **errp); -- 1.8.3.1