From patchwork Mon Jan 7 22:22:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 210253 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 F2D972C0091 for ; Tue, 8 Jan 2013 09:23:07 +1100 (EST) Received: from localhost ([::1]:60876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsL62-0007dX-32 for incoming@patchwork.ozlabs.org; Mon, 07 Jan 2013 17:23:06 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsL5D-0005LO-Sr for qemu-devel@nongnu.org; Mon, 07 Jan 2013 17:22:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsL5C-000134-OD for qemu-devel@nongnu.org; Mon, 07 Jan 2013 17:22:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:64587) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsL5C-00012w-H6 for qemu-devel@nongnu.org; Mon, 07 Jan 2013 17:22:14 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r07MMDZh028446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 7 Jan 2013 17:22:14 -0500 Received: from bling.home ([10.3.113.8]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r07MMDve015694; Mon, 7 Jan 2013 17:22:13 -0500 To: alex.williamson@redhat.com, kvm@vger.kernel.org From: Alex Williamson Date: Mon, 07 Jan 2013 15:22:13 -0700 Message-ID: <20130107222213.9460.44737.stgit@bling.home> In-Reply-To: <20130107221001.9460.85677.stgit@bling.home> References: <20130107221001.9460.85677.stgit@bling.home> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 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 3/3] vfio-pci: [NOT FOR COMMIT] Hack around HD5450 I/O port backdoor 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 This is a hack specific to my system which I haven't even attempted to generalize yet. The ATI/AMD Radeon HD5450 VGA BIOS appears to have a backdoor to determine the physical address of the device. It reads a value matching the top byte of the I/O Port BAR from a register in VGA I/O port space then uses in/out to that address during BIOS execution. On my setup the I/O port BAR is at 0x4000 physically and emulated for the guest at 0xc0000. So I simply look for this access and replace 0x40 with 0xc0. That's enough for it to get through BIOS init, but it's still only partially functional (no VGA text mode). Signed-off-by: Alex Williamson --- hw/vfio_pci.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/vfio_pci.c b/hw/vfio_pci.c index 846e8de..5db076f 100644 --- a/hw/vfio_pci.c +++ b/hw/vfio_pci.c @@ -1041,6 +1041,15 @@ static uint64_t vfio_legacy_read(void *opaque, hwaddr addr, unsigned size) break; } + /* XXX - Complete hardcoded hack, need to figure out how common this is and + * come up with a device quirk and match host phys to guest phys. This is + * only known to be needed for an ATI/AMD Radeon HD5450 which stores the + * upper byte of the I/O port address in this unused VGA I/O port register. + */ + if (io->region_offset == 0x3c0 && addr == 3 && size == 1 && data == 0x40) { + data = 0xc0; + } + DPRINTF("%s(0x%"HWADDR_PRIx", %d) = 0x%"PRIx64"\n", __func__, io->region_offset + addr, size, data);