xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: peter.maydell@linaro.org, xen-devel@lists.xensource.com,
	allen.m.kay@intel.com, weidong.han@intel.com,
	qemu-devel@nongnu.org, yang.z.zhang@intel.com,
	Anthony Liguori <anthony@codemonkey.ws>,
	anthony.perard@citrix.com
Subject: Re: [PATCH 4/5] xen, gfx passthrough: support Intel IGD passthrough with VT-D
Date: Thu, 27 Mar 2014 21:10:54 +0200	[thread overview]
Message-ID: <20140327191054.GA4114@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1403271818200.20764@kaball.uk.xensource.com>

On Thu, Mar 27, 2014 at 06:21:08PM +0000, Stefano Stabellini wrote:
> CC'ing Michael.
> 
> On Fri, 21 Feb 2014, Yang Zhang wrote:
> > From: Yang Zhang <yang.z.zhang@Intel.com>
> > 
> > Some registers of Intel IGD are mapped in host bridge, so it needs to
> > passthrough these registers of physical host bridge to guest because
> > emulated host bridge in guest doesn't have these mappings.
> > 
> > The original patch is from Weidong Han < weidong.han @ intel.com >
> > 
> > Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com>
> > Cc:Weidong Han <weidong.han@intel.com>
> > ---
> >  hw/pci-host/piix.c       |   15 ++++++
> >  hw/pci/pci.c             |   13 +++++
> >  hw/xen/xen_pt.h          |    5 ++
> >  hw/xen/xen_pt_graphics.c |  127 ++++++++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 160 insertions(+), 0 deletions(-)
> > 
> > diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
> > index ffdc853..68cf756 100644
> > --- a/hw/pci-host/piix.c
> > +++ b/hw/pci-host/piix.c
> > @@ -34,6 +34,9 @@
> >  #include "sysemu/sysemu.h"
> >  #include "hw/i386/ioapic.h"
> >  #include "qapi/visitor.h"
> > +#if defined(CONFIG_XEN_PCI_PASSTHROUGH)
> > +#include "hw/xen/xen_pt.h"
> > +#endif
> >  
> >  /*
> >   * I440FX chipset data sheet.
> > @@ -389,6 +392,18 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
> >  
> >      i440fx_update_memory_mappings(f);
> >  
> > +#if defined(CONFIG_XEN_PCI_PASSTHROUGH)
> > +    /*
> > +     * Some registers of Intel IGD are mapped in host bridge, so it needs to
> > +     * passthrough these registers of physical host bridge to guest because
> > +     * emulated host bridge in guest doesn't have these mappings.
> > +     */
> > +    if (intel_pch_init(b) == 0) {
> > +        d->config_read = igd_pci_read;
> > +        d->config_write = igd_pci_write;
> > +    }
> > +#endif
> 
> I can't see the other QEMU maintainers being happy with these changes.
> Michael, do you have a suggestion on how to do this in a better way?

Implement your own pci host bridge, inherit the standard one.


> 
> >      return b;
> >  }
> >  
> > diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> > index e81816e..7016b71 100644
> > --- a/hw/pci/pci.c
> > +++ b/hw/pci/pci.c
> > @@ -36,6 +36,9 @@
> >  #include "hw/pci/msix.h"
> >  #include "exec/address-spaces.h"
> >  #include "hw/hotplug.h"
> > +#if defined(CONFIG_XEN_PCI_PASSTHROUGH)
> > +#include "hw/xen/xen_pt.h"
> > +#endif
> >  
> >  //#define DEBUG_PCI
> >  #ifdef DEBUG_PCI
> > @@ -805,6 +808,16 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
> >      PCIConfigWriteFunc *config_write = pc->config_write;
> >      AddressSpace *dma_as;
> >  
> > +#if defined(CONFIG_XEN_PCI_PASSTHROUGH)
> > +    /*
> > +     * Some video bioses and gfx drivers will assume the bdf of IGD is 00:02.0.
> > +     * So user need to set it to 00:02.0 in Xen configure file explicitly,
> > +     * otherwise IGD will fail to work.
> > +     */
> > +    if (gfx_passthru && devfn == 0x10)
> > +        igd_passthru = 1;
> > +    else
> > +#endif
> >      if (devfn < 0) {
> >          for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices);
> >              devfn += PCI_FUNC_MAX) {
> 
> Same here
> 

So just set the address property to 00:02.0.


> > diff --git a/hw/xen/xen_pt.h b/hw/xen/xen_pt.h
> > index c04bbfd..92e4d51 100644
> > --- a/hw/xen/xen_pt.h
> > +++ b/hw/xen/xen_pt.h
> > @@ -299,8 +299,13 @@ static inline bool xen_pt_has_msix_mapping(XenPCIPassthroughState *s, int bar)
> >  }
> >  
> >  extern int gfx_passthru;
> > +extern int igd_passthru;
> >  int register_vga_regions(XenHostPCIDevice *dev);
> >  int unregister_vga_regions(XenHostPCIDevice *dev);
> >  int setup_vga_pt(XenHostPCIDevice *dev);
> > +int intel_pch_init(PCIBus *bus);
> > +void igd_pci_write(PCIDevice *pci_dev, uint32_t config_addr,
> > +                   uint32_t val, int len);
> > +uint32_t igd_pci_read(PCIDevice *pci_dev, uint32_t config_addr, int len);
> >  
> >  #endif /* !XEN_PT_H */
> > diff --git a/hw/xen/xen_pt_graphics.c b/hw/xen/xen_pt_graphics.c
> > index 54f16cf..2a01406 100644
> > --- a/hw/xen/xen_pt_graphics.c
> > +++ b/hw/xen/xen_pt_graphics.c
> > @@ -5,6 +5,8 @@
> >  #include "xen-host-pci-device.h"
> >  #include "hw/xen/xen_backend.h"
> >  
> > +int igd_passthru;
> > +
> >  /*
> >   * register VGA resources for the domain with assigned gfx
> >   */
> > @@ -233,3 +235,128 @@ static int create_pch_isa_bridge(PCIBus *bus, XenHostPCIDevice *hdev)
> >      XEN_PT_LOG(dev, "Intel PCH ISA bridge is created.\n");
> >      return 0;
> >  }
> > +
> > +int intel_pch_init(PCIBus *bus)
> > +{
> > +    XenHostPCIDevice hdev;
> > +    int r = 0;
> > +
> > +    if (!gfx_passthru) {
> > +        return -1;
> > +    }
> > +
> > +    r = xen_host_pci_device_get(&hdev, 0, 0, 0x1f, 0);
> > +    if (r) {
> > +        XEN_PT_ERR(NULL, "Fail to find intel PCH in host\n");
> > +        goto err;
> > +    }
> > +
> > +    if (hdev.vendor_id == PCI_VENDOR_ID_INTEL) {
> > +        r = create_pch_isa_bridge(bus, &hdev);
> > +        if (r) {
> > +            XEN_PT_ERR(NULL, "Fail to create PCH ISA bridge.\n");
> > +            goto err;
> > +        }
> > +    }
> > +
> > +    xen_host_pci_device_put(&hdev);
> > +
> > +    return  r;
> > +
> > +err:
> > +    return r;
> > +}
> > +
> > +void igd_pci_write(PCIDevice *pci_dev, uint32_t config_addr,
> > +                   uint32_t val, int len)
> > +{
> > +    XenHostPCIDevice dev;
> > +    int r;
> > +
> > +    assert(pci_dev->devfn == 0x00);
> > +
> > +    if (!igd_passthru) {
> > +        goto write_default;
> > +    }
> > +
> > +    switch (config_addr) {
> > +    case 0x58:      /* PAVPC Offset */
> > +        break;
> > +    default:
> > +        goto write_default;
> > +    }
> > +
> > +    /* Host write */
> > +    r = xen_host_pci_device_get(&dev, 0, 0, 0, 0);
> > +    if (r) {
> > +        XEN_PT_ERR(pci_dev, "Can't get pci_dev_host_bridge\n");
> > +        abort();
> > +    }
> > +
> > +    r = xen_host_pci_set_block(&dev, config_addr, (uint8_t *)&val, len);
> > +    if (r) {
> > +        XEN_PT_ERR(pci_dev, "Can't get pci_dev_host_bridge\n");
> > +        abort();
> > +    }
> > +
> > +    xen_host_pci_device_put(&dev);
> > +
> > +    return;
> > +
> > +write_default:
> > +    pci_default_write_config(pci_dev, config_addr, val, len);
> > +}
> > +
> > +uint32_t igd_pci_read(PCIDevice *pci_dev, uint32_t config_addr, int len)
> > +{
> > +    XenHostPCIDevice dev;
> > +    uint32_t val;
> > +    int r;
> > +
> > +    assert(pci_dev->devfn == 0x00);
> > +
> > +    if (!igd_passthru) {
> > +        goto read_default;
> > +    }
> > +
> > +    switch (config_addr) {
> > +    case 0x00:        /* vendor id */
> > +    case 0x02:        /* device id */
> > +    case 0x08:        /* revision id */
> > +    case 0x2c:        /* sybsystem vendor id */
> > +    case 0x2e:        /* sybsystem id */
> > +    case 0x50:        /* SNB: processor graphics control register */
> > +    case 0x52:        /* processor graphics control register */
> > +    case 0xa0:        /* top of memory */
> > +    case 0xb0:        /* ILK: BSM: should read from dev 2 offset 0x5c */
> > +    case 0x58:        /* SNB: PAVPC Offset */
> > +    case 0xa4:        /* SNB: graphics base of stolen memory */
> > +    case 0xa8:        /* SNB: base of GTT stolen memory */
> > +        break;
> > +    default:
> > +        goto read_default;
> > +    }
> > +
> > +    /* Host read */
> > +    r = xen_host_pci_device_get(&dev, 0, 0, 0, 0);
> > +    if (r) {
> > +        goto err_out;
> > +    }
> > +
> > +    r = xen_host_pci_get_block(&dev, config_addr, (uint8_t *)&val, len);
> > +    if (r) {
> > +        goto err_out;
> > +    }
> > +
> > +    xen_host_pci_device_put(&dev);
> > +
> > +    return val;
> > +
> > +read_default:
> > +    return pci_default_read_config(pci_dev, config_addr, len);
> > +
> > +err_out:
> > +    XEN_PT_ERR(pci_dev, "Can't get pci_dev_host_bridge\n");
> > +    return -1;
> > +}
> 
> The Xen specific part is OK.

  reply	other threads:[~2014-03-27 19:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-21  6:44 [PATCH 0/5] xen: add Intel IGD passthrough support Yang Zhang
2014-02-21  6:44 ` [PATCH 1/5] xen, gfx passthrough: basic graphics " Yang Zhang
2014-03-21 16:24   ` Anthony PERARD
2014-05-09  7:27     ` Zhang, Yang Z
2014-04-02 15:19   ` Zytaruk, Kelly
2014-02-21  6:44 ` [PATCH 2/5] xen, gfx passthrough: reserve 00:02.0 for INTEL IGD Yang Zhang
2014-03-21 17:26   ` Anthony PERARD
2014-02-21  6:44 ` [PATCH 3/5] xen, gfx passthrough: create intel isa bridge Yang Zhang
2014-02-21  6:44 ` [PATCH 4/5] xen, gfx passthrough: support Intel IGD passthrough with VT-D Yang Zhang
2014-03-27 18:21   ` Stefano Stabellini
2014-03-27 19:10     ` Michael S. Tsirkin [this message]
2014-02-21  6:44 ` [PATCH 5/5] xen, gfx passthrough: add opregion mapping Yang Zhang
2014-02-27  5:38 ` [PATCH 0/5] xen: add Intel IGD passthrough support Zhang, Yang Z
2014-02-27 12:47   ` Stefano Stabellini
2014-04-04 22:46 ` Kevin O'Connor
2014-04-07  8:36   ` [Xen-devel] " Ian Campbell

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=20140327191054.GA4114@redhat.com \
    --to=mst@redhat.com \
    --cc=allen.m.kay@intel.com \
    --cc=anthony.perard@citrix.com \
    --cc=anthony@codemonkey.ws \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=weidong.han@intel.com \
    --cc=xen-devel@lists.xensource.com \
    --cc=yang.z.zhang@intel.com \
    /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).