From patchwork Sat Feb 13 00:23:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 582341 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 CE9D6140B0E for ; Sat, 13 Feb 2016 11:24:56 +1100 (AEDT) Received: from localhost ([::1]:37593 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUO18-0000jh-Ua for incoming@patchwork.ozlabs.org; Fri, 12 Feb 2016 19:24:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUNzc-0006C3-Pk for qemu-devel@nongnu.org; Fri, 12 Feb 2016 19:23:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUNzb-000835-S2 for qemu-devel@nongnu.org; Fri, 12 Feb 2016 19:23:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38456) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUNzb-000831-Mi for qemu-devel@nongnu.org; Fri, 12 Feb 2016 19:23:19 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 611BBA84; Sat, 13 Feb 2016 00:23:19 +0000 (UTC) Received: from gimli.home (ovpn-113-102.phx2.redhat.com [10.3.113.102]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1D0NIw7013836; Fri, 12 Feb 2016 19:23:19 -0500 From: Alex Williamson To: seabios@seabios.org Date: Fri, 12 Feb 2016 17:23:18 -0700 Message-ID: <20160213002318.18456.48603.stgit@gimli.home> In-Reply-To: <20160213001835.18456.46422.stgit@gimli.home> References: <20160213001835.18456.46422.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: alex.williamson@redhat.com, allen.m.kay@intel.com, qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [RFC PATCH v3 3/3] fw/pci: Allocate IGD stolen memory 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 Intel IGD makes use of memory allocated and marked reserved by the BIOS as a stolen memory range. For the most part, guest drivers don't make use of this, but our achilles heel is the vBIOS. The vBIOS programs the device to use the host stolen memory range and it's used in the pre-boot environment. Generally the guest won't have access to the host stolen memory area, so these accesses either land in VM memory or unassigned space and generate IOMMU faults. By allocating this range in SeaBIOS and programming it into the device, QEMU (via vfio) can make sure this guest allocated stolen memory range is used instead. Signed-off-by: Alex Williamson --- src/fw/pciinit.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index 92170d5..c1ad5d4 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -260,7 +260,7 @@ static void ich9_smbus_setup(struct pci_device *dev, void *arg) static void intel_igd_opregion_setup(struct pci_device *dev, void *arg) { struct romfile_s *file = romfile_find("etc/igd-opregion"); - void *opregion; + void *opregion, *bdsm; u16 bdf = dev->bdf; if (!file || !file->size) @@ -281,6 +281,17 @@ static void intel_igd_opregion_setup(struct pci_device *dev, void *arg) dprintf(1, "Intel IGD OpRegion enabled on %02x:%02x.%x\n", pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf)); + + bdsm = memalign_high(1024 * 1024, 1024 * 1024); + if (!bdsm) { + warn_noalloc(); + return; + } + + pci_config_writel(bdf, 0x5C, cpu_to_le32((u32)bdsm)); + + dprintf(1, "Allocated 1MB reserved memory for Intel IGD stolen memory at " + "0x%08x\n", (u32)bdsm); } static const struct pci_device_id pci_device_tbl[] = {