Received: from eggs.gnu.org ([2001:4830:134:3::10]:48835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQdJj-0004f9-Qy for qemu-devel@nongnu.org; Tue, 02 Feb 2016 10:56:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQdJi-0001oz-9T for qemu-devel@nongnu.org; Tue, 02 Feb 2016 10:56:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55635) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQdJi-0001ou-0v for qemu-devel@nongnu.org; Tue, 02 Feb 2016 10:56:34 -0500 Message-ID: <1454428592.10542.27.camel@redhat.com> From: Alex Williamson Date: Tue, 02 Feb 2016 08:56:32 -0700 In-Reply-To: <56B0964C.5000708@redhat.com> References: <20160202041510.32092.58972.stgit@gimli.home> <56B0964C.5000708@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [SeaBIOS] [RFC PATCH] fw/pci: Add support for mapping Intel IGD OpRegion via QEMU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laszlo Ersek , seabios@seabios.org Cc: qemu-devel@nongnu.org, kraxel@redhat.com On Tue, 2016-02-02 at 12:43 +0100, Laszlo Ersek wrote: > On 02/02/16 05:15, Alex Williamson wrote: > > The proposed IGD OpRegion support in QEMU via vfio maps the host > > OpRegion into VM system memory at the address written to the ASL > > Storage register (0xFC).=C2=A0=C2=A0The OpRegion contains a 16-byte s= ignature > > followed by a 4-byte size field.=C2=A0=C2=A0Therefore SeaBIOS can all= ocate a > > buffer of the typical size (8KB), this results in a matching e820 > > reserved entry for the range, then write the buffer address to the AS= L > > Storage register, blinking the OpRegion into the VM address space.=C2= =A0=C2=A0At > > that point SeaBIOS can validate the signature and size and remap if > > necessary.=C2=A0=C2=A0If the OpRegion is larger than 8KB, this would = result in > > any conflicting ranges being temporarily mapped with the OpRegion, > > which probably needs further discussion on what that could break. > > Other options might be to use the same algorithm with an obscenely > > sized initial buffer to make sure we do not overlap, always > > re-allocating the proper sized buffer, or perhaps we could pass the > > OpRegion itself or information about the OpRegion through fw_cfg. > >=C2=A0 > > With the posted kernel series[1] and QEMU series[2] (on top of Gerd's > > IGD patches[3]), this makes the OpRegion available to the VM and > > tracing shows that the guest driver does access it. > >=C2=A0 > > [1] https://lkml.org/lkml/2016/2/1/884 > > [2] https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg00202.ht= ml > > [3] https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg00244.ht= ml > >=C2=A0 > > Signed-off-by: Alex Williamson > > --- > > =C2=A0src/fw/pciinit.c |=C2=A0=C2=A0=C2=A050 ++++++++++++++++++++++++= ++++++++++++++++++++++++++ > > =C2=A01 file changed, 50 insertions(+) > >=C2=A0 > > diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c > > index c31c2fa..4f3251e 100644 > > --- a/src/fw/pciinit.c > > +++ b/src/fw/pciinit.c > > @@ -257,6 +257,52 @@ static void ich9_smbus_setup(struct pci_device *= dev, void *arg) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pci_config_writeb(bdf, ICH9_SMB_HOSTC, = ICH9_SMB_HOSTC_HST_EN); > > =C2=A0} > > =C2=A0 > > +static void intel_igd_opregion_setup(struct pci_device *dev, void *a= rg) > > +{ > > +=C2=A0=C2=A0=C2=A0=C2=A0u16 bdf =3D dev->bdf; > > +=C2=A0=C2=A0=C2=A0=C2=A0u32 orig; > > +=C2=A0=C2=A0=C2=A0=C2=A0void *opregion; > > +=C2=A0=C2=A0=C2=A0=C2=A0int size =3D 8; > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0if (!CONFIG_QEMU) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return; > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0orig =3D pci_config_readl(bdf, 0xFC); > > + > > +realloc: > > +=C2=A0=C2=A0=C2=A0=C2=A0opregion =3D malloc_high(size * 1024); > > +=C2=A0=C2=A0=C2=A0=C2=A0if (!opregion) { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0warn_noalloc(); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return; > > +=C2=A0=C2=A0=C2=A0=C2=A0} > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0/* > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* QEMU maps the OpRegion into system m= emory at the address written here, > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* this overlaps our malloc, which mark= s the range e820 reserved. > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*/ > > +=C2=A0=C2=A0=C2=A0=C2=A0pci_config_writel(bdf, 0xFC, cpu_to_le32((u3= 2)opregion)); > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0if (memcmp(opregion, "IntelGraphicsMem", 16)= ) { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pci_config_writel(bd= f, 0xFC, orig); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0free(opregion); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return; /* the opreg= ion didn't magically appear, not supported */ > > +=C2=A0=C2=A0=C2=A0=C2=A0} > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0if (size =3D=3D le32_to_cpu(*(u32 *)(opregio= n + 16))) { > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0dprintf(1, "Intel IG= D OpRegion enabled on %02x:%02x.%x\n", > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_= bdf_to_fn(bdf)); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0return; /* success! = */ > > +=C2=A0=C2=A0=C2=A0=C2=A0} > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0pci_config_writel(bdf, 0xFC, orig); > > +=C2=A0=C2=A0=C2=A0=C2=A0free(opregion); > > + > > +=C2=A0=C2=A0=C2=A0=C2=A0if (size =3D=3D 8) { /* try once more with a= new size */ > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0size =3D le32_to_cpu= (*(u32 *)(opregion + 16)); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0goto realloc; >=C2=A0 > Is this idiomatic SeaBIOS coding style? >=C2=A0 > How about "for (;;)" -- the code has many instances -- and reworking > this last branch accordingly? >=C2=A0 > (Apologies, not a very important comment.) I did check that I wasn't the only one using a goto in SeaBIOS and I don't see any sort of CodingStyle doc precluding it, but I apologize if there have been previous discussions that I've missed.=C2=A0=C2=A0I don't= have the same aversion to gotos as many people do, but of course the loop can be reworked in any number of ways if there's a preference to avoid them. Thanks, Alex > > +=C2=A0=C2=A0=C2=A0=C2=A0} > > +} > > + > > =C2=A0static const struct pci_device_id pci_device_tbl[] =3D { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0/* PIIX3/PIIX4 PCI to ISA bridge */ > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEV= ICE_ID_INTEL_82371SB_0, > > @@ -290,6 +336,10 @@ static const struct pci_device_id pci_device_tbl= [] =3D { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0PCI_DEVICE_CLASS(PCI_VENDOR_ID_APPLE, 0= x0017, 0xff00, apple_macio_setup), > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0PCI_DEVICE_CLASS(PCI_VENDOR_ID_APPLE, 0= x0022, 0xff00, apple_macio_setup), > > =C2=A0 > > +=C2=A0=C2=A0=C2=A0=C2=A0/* Intel IGD OpRegion setup */ > > +=C2=A0=C2=A0=C2=A0=C2=A0PCI_DEVICE_CLASS(PCI_VENDOR_ID_INTEL, PCI_AN= Y_ID, PCI_CLASS_DISPLAY_VGA, > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0intel_igd_opregi= on_setup), > > + > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0PCI_DEVICE_END, > > =C2=A0}; > > =C2=A0 > >=C2=A0 > >=C2=A0 > > _______________________________________________ > > SeaBIOS mailing list > > SeaBIOS@seabios.org > > http://www.seabios.org/mailman/listinfo/seabios > >=C2=A0 >=C2=A0