diff mbox

[v3,05/11] igd: TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE: call parent realize

Message ID 1451994098-6972-6-git-send-email-kraxel@redhat.com
State New
Headers show

Commit Message

Gerd Hoffmann Jan. 5, 2016, 11:41 a.m. UTC
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/pci-host/igd.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Stefano Stabellini Jan. 6, 2016, 2:41 p.m. UTC | #1
On Tue, 5 Jan 2016, Gerd Hoffmann wrote:
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/pci-host/igd.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/hw/pci-host/igd.c b/hw/pci-host/igd.c
> index d1eeafb..6f52ab1 100644
> --- a/hw/pci-host/igd.c
> +++ b/hw/pci-host/igd.c
> @@ -53,12 +53,20 @@ out:
>      return ret;
>  }
>  
> +static void (*i440fx_realize)(PCIDevice *pci_dev, Error **errp);
>  static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp)
>  {
> +    Error *err = NULL;
>      uint32_t val = 0;
>      int rc, i, num;
>      int pos, len;

Can't we get the parent PCIDeviceClass realize function from pci_dev? So
that we don't have to introduce i440fx_realize?


> +    i440fx_realize(pci_dev, &err);
> +    if (err != NULL) {
> +        error_propagate(errp, err);
> +        return;
> +    }
> +
>      num = ARRAY_SIZE(igd_host_bridge_infos);
>      for (i = 0; i < num; i++) {
>          pos = igd_host_bridge_infos[i].offset;
> @@ -77,6 +85,7 @@ static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
>  
> +    i440fx_realize = k->realize;
>      k->realize = igd_pt_i440fx_realize;
>      dc->desc = "IGD Passthrough Host bridge";
>  }
> -- 
> 1.8.3.1
>
Gerd Hoffmann Jan. 6, 2016, 3:45 p.m. UTC | #2
> >  
> > +static void (*i440fx_realize)(PCIDevice *pci_dev, Error **errp);
> >  static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp)
> >  {
> > +    Error *err = NULL;
> >      uint32_t val = 0;
> >      int rc, i, num;
> >      int pos, len;
> 
> Can't we get the parent PCIDeviceClass realize function from pci_dev? So
> that we don't have to introduce i440fx_realize?

I don't think so ...

> >  
> > +    i440fx_realize = k->realize;
> >      k->realize = igd_pt_i440fx_realize;

... because we are overriding it right here.

cheers,
  Gerd
Eduardo Habkost Jan. 19, 2016, 3:13 p.m. UTC | #3
On Wed, Jan 06, 2016 at 04:45:01PM +0100, Gerd Hoffmann wrote:
> > >  
> > > +static void (*i440fx_realize)(PCIDevice *pci_dev, Error **errp);
> > >  static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp)
> > >  {
> > > +    Error *err = NULL;
> > >      uint32_t val = 0;
> > >      int rc, i, num;
> > >      int pos, len;
> > 
> > Can't we get the parent PCIDeviceClass realize function from pci_dev? So
> > that we don't have to introduce i440fx_realize?
> 
> I don't think so ...
> 
> > >  
> > > +    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.
diff mbox

Patch

diff --git a/hw/pci-host/igd.c b/hw/pci-host/igd.c
index d1eeafb..6f52ab1 100644
--- a/hw/pci-host/igd.c
+++ b/hw/pci-host/igd.c
@@ -53,12 +53,20 @@  out:
     return ret;
 }
 
+static void (*i440fx_realize)(PCIDevice *pci_dev, Error **errp);
 static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp)
 {
+    Error *err = NULL;
     uint32_t val = 0;
     int rc, i, num;
     int pos, len;
 
+    i440fx_realize(pci_dev, &err);
+    if (err != NULL) {
+        error_propagate(errp, err);
+        return;
+    }
+
     num = ARRAY_SIZE(igd_host_bridge_infos);
     for (i = 0; i < num; i++) {
         pos = igd_host_bridge_infos[i].offset;
@@ -77,6 +85,7 @@  static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
+    i440fx_realize = k->realize;
     k->realize = igd_pt_i440fx_realize;
     dc->desc = "IGD Passthrough Host bridge";
 }