From patchwork Tue Mar 5 16:04:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 225070 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6DB8F2C0333 for ; Wed, 6 Mar 2013 03:05:44 +1100 (EST) Received: from localhost ([::1]:56163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCuN4-0007Xp-Jy for incoming@patchwork.ozlabs.org; Tue, 05 Mar 2013 11:05:42 -0500 Received: from eggs.gnu.org ([208.118.235.92]:38903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCuMG-0006ry-Hu for qemu-devel@nongnu.org; Tue, 05 Mar 2013 11:04:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCuME-0003E0-Ph for qemu-devel@nongnu.org; Tue, 05 Mar 2013 11:04:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:27302) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCuME-0003CL-BY for qemu-devel@nongnu.org; Tue, 05 Mar 2013 11:04:50 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r25G4mQf030204 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 5 Mar 2013 11:04:49 -0500 Received: from bling.home (ovpn-113-45.phx2.redhat.com [10.3.113.45]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r25G4mS0023152; Tue, 5 Mar 2013 11:04:48 -0500 To: kevin@koconnor.net, seabios@seabios.org From: Alex Williamson Date: Tue, 05 Mar 2013 09:04:47 -0700 Message-ID: <20130305160406.22844.21669.stgit@bling.home> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH v2] pciinit: Enable default VGA device 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 As QEMU gains PCI bridge and PCIe root port support, we won't always find the VGA device on the root bus. We therefore need to add support to find and enable a VGA device and the path to it through the VGA Enable support in the PCI bridge control register. Signed-off-by: Alex Williamson --- src/optionroms.c | 2 +- src/pciinit.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 1 + 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/optionroms.c b/src/optionroms.c index caa2151..ac92613 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -213,7 +213,7 @@ run_file_roms(const char *prefix, int isvga, u64 *sources) ****************************************************************/ // Verify device is a vga device with legacy address decoding enabled. -static int +int is_pci_vga(struct pci_device *pci) { if (pci->class != PCI_CLASS_DISPLAY_VGA) diff --git a/src/pciinit.c b/src/pciinit.c index ce0a4cc..eb49a76 100644 --- a/src/pciinit.c +++ b/src/pciinit.c @@ -316,6 +316,49 @@ static void pci_bios_init_devices(void) } } +static void pci_enable_default_vga(void) +{ + struct pci_device *pci; + + foreachpci(pci) { + if (is_pci_vga(pci)) { + dprintf(1, "PCI: Using %02x:%02x.%x for primary VGA\n", + pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), + pci_bdf_to_fn(pci->bdf)); + return; + } + } + + pci = pci_find_class(PCI_CLASS_DISPLAY_VGA); + if (!pci) { + dprintf(1, "PCI: No VGA devices found\n"); + return; + } + + dprintf(1, "PCI: Enabling %02x:%02x.%x for primary VGA\n", + pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), + pci_bdf_to_fn(pci->bdf)); + + u16 cmd = pci_config_readw(pci->bdf, PCI_COMMAND); + cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY; + pci_config_writew(pci->bdf, PCI_COMMAND, cmd); + + while (pci->parent) { + pci = pci->parent; + + dprintf(1, "PCI: Setting VGA enable on bridge %02x:%02x.%x\n", + pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), + pci_bdf_to_fn(pci->bdf)); + + u8 ctrl = pci_config_readb(pci->bdf, PCI_BRIDGE_CONTROL); + ctrl |= PCI_BRIDGE_CTL_VGA; + pci_config_writeb(pci->bdf, PCI_BRIDGE_CONTROL, ctrl); + + u16 cmd = pci_config_readw(pci->bdf, PCI_COMMAND); + cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY; + pci_config_writew(pci->bdf, PCI_COMMAND, cmd); + } +} /**************************************************************** * Platform device initialization @@ -804,4 +847,6 @@ pci_setup(void) pci_bios_init_devices(); free(busses); + + pci_enable_default_vga(); } diff --git a/src/util.h b/src/util.h index 306a8bf..e1df295 100644 --- a/src/util.h +++ b/src/util.h @@ -343,6 +343,7 @@ void vgahook_setup(struct pci_device *pci); // optionroms.c void call_bcv(u16 seg, u16 ip); +int is_pci_vga(struct pci_device *pci); void optionrom_setup(void); void vgarom_setup(void); void s3_resume_vga(void);