From patchwork Sat Aug 16 15:01:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 35477 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CBCB620523 for ; Sat, 16 Aug 2014 15:02:29 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id et14sf28255692pad.10 for ; Sat, 16 Aug 2014 08:02:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:reply-to:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=hPhXD49xcjvBC1fik4XuOXxkl91I3D6+tcgjz/k2b1U=; b=UX8LDdwfBSwSURNGf5YmbWvaOcBLobINoX7tmZfE/iDFgmicjJKXGW6anxld+o3eSg LuZDQFhQFonP0G21a5lI8inFJ4u9NJ2X4bd96mcdelAoF4RKeDJCIBQcavwWM1WFmNZl gCVXN+iHbw1Y/1E1uTKDN0zuJOBL180hjPiNtM4rbkzTAX6fgwVeP3T+Oxa/YY/ndOh8 R/Ms99oPgAR3ZeLdRfFn6SmBkjNiWcCsCMYs1jR7O+hAHomG4zYv3LwgxxTRTJM+ehhJ 3tWvrw5kAfqB4pANZ7eRyUyHTZ0IZrTBANAhhNLrWNQUg9k0y6IwqTHY19R2jCvyvDui SOwg== X-Gm-Message-State: ALoCoQniZYPtobtbkANv18j6j7Vbmz+HbPLJmV8yRHUoifaZtUjFsY9lttbew5tP7NguoZrTI/s+ X-Received: by 10.66.249.73 with SMTP id ys9mr13035759pac.9.1408201341331; Sat, 16 Aug 2014 08:02:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.92.228 with SMTP id b91ls223871qge.88.gmail; Sat, 16 Aug 2014 08:02:21 -0700 (PDT) X-Received: by 10.52.15.8 with SMTP id t8mr18260876vdc.18.1408201341129; Sat, 16 Aug 2014 08:02:21 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id q6si3832053vey.71.2014.08.16.08.02.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 16 Aug 2014 08:02:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id la4so4077020vcb.5 for ; Sat, 16 Aug 2014 08:02:21 -0700 (PDT) X-Received: by 10.220.114.66 with SMTP id d2mr15888341vcq.27.1408201340963; Sat, 16 Aug 2014 08:02:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp23623vcb; Sat, 16 Aug 2014 08:02:20 -0700 (PDT) X-Received: by 10.50.111.112 with SMTP id ih16mr72476253igb.30.1408201340249; Sat, 16 Aug 2014 08:02:20 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id gj19si16704832icb.4.2014.08.16.08.02.19 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 16 Aug 2014 08:02:20 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XIfUb-00007R-D8; Sat, 16 Aug 2014 15:02:05 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XIfUa-00007J-La for edk2-devel@lists.sourceforge.net; Sat, 16 Aug 2014 15:02:04 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=lersek@redhat.com; helo=mx1.redhat.com; Received: from mx1.redhat.com ([209.132.183.28]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1XIfUY-0003KI-Vn for edk2-devel@lists.sourceforge.net; Sat, 16 Aug 2014 15:02:04 +0000 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 (8.14.4/8.14.4) with ESMTP id s7GF1tPx009104 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 16 Aug 2014 11:01:55 -0400 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7GF1shK011058; Sat, 16 Aug 2014 11:01:54 -0400 From: Laszlo Ersek To: Gerd Hoffmann , edk2-devel@lists.sourceforge.net Date: Sat, 16 Aug 2014 17:01:51 +0200 Message-Id: <1408201311-16898-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Spam-Score: -2.2 (--) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1XIfUY-0003KI-Vn Subject: [edk2] [PATCH] OvmfPkg: QemuVideoDxe: fix querying of QXL's drawable buffer size X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lersek@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 When setting up the list of GOP modes offered on QEMU's stdvga ("VGA") and QXL ("qxl-vga") video devices, QemuVideoBochsModeSetup() filters those modes against the available framebuffer size. (Refer to SVN r15288 / git commit ec88061e.) The current calculation is correct for stdvga, because on stdvga the value returned by VBE_DISPI_INDEX_VIDEO_MEMORY_64K, ie. the full video RAM, is usable for drawing. However, on the QXL card, only an initial portion of the video RAM is suitable for drawing, as compatibility frame buffer. The size of this segment can be read from a register in the QXL ROM bar (bar 2). Beyond this range, the video RAM contains buffers and structures for the QXL guest-host protocol. Without this fix, OVMF offers too large resolutions on the QXL card (up to the full size of the video RAM). If a GOP client selects such a resolution and draws into the video RAM past the compatibility segment, then the guest corrupts its communication structures (which is invalid guest behavior). Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Signed-off-by: Laszlo Ersek --- OvmfPkg/QemuVideoDxe/Qemu.h | 3 ++- OvmfPkg/QemuVideoDxe/Driver.c | 3 ++- OvmfPkg/QemuVideoDxe/Initialize.c | 41 +++++++++++++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/QemuVideoDxe/Qemu.h b/OvmfPkg/QemuVideoDxe/Qemu.h index 4bf51c7..52ee20d 100644 --- a/OvmfPkg/QemuVideoDxe/Qemu.h +++ b/OvmfPkg/QemuVideoDxe/Qemu.h @@ -499,7 +499,8 @@ QemuVideoCirrusModeSetup ( EFI_STATUS QemuVideoBochsModeSetup ( - QEMU_VIDEO_PRIVATE_DATA *Private + QEMU_VIDEO_PRIVATE_DATA *Private, + BOOLEAN IsQxl ); VOID diff --git a/OvmfPkg/QemuVideoDxe/Driver.c b/OvmfPkg/QemuVideoDxe/Driver.c index 2194cbe..abe2c9d 100644 --- a/OvmfPkg/QemuVideoDxe/Driver.c +++ b/OvmfPkg/QemuVideoDxe/Driver.c @@ -354,7 +354,8 @@ QemuVideoControllerDriverStart ( break; case QEMU_VIDEO_BOCHS_MMIO: case QEMU_VIDEO_BOCHS: - Status = QemuVideoBochsModeSetup (Private); + Status = QemuVideoBochsModeSetup (Private, + (BOOLEAN)(Card->Variant == QEMU_VIDEO_BOCHS)); break; default: ASSERT (FALSE); diff --git a/OvmfPkg/QemuVideoDxe/Initialize.c b/OvmfPkg/QemuVideoDxe/Initialize.c index a536d47..6111d06 100644 --- a/OvmfPkg/QemuVideoDxe/Initialize.c +++ b/OvmfPkg/QemuVideoDxe/Initialize.c @@ -253,7 +253,8 @@ QEMU_VIDEO_BOCHS_MODES QemuVideoBochsModes[] = { EFI_STATUS QemuVideoBochsModeSetup ( - QEMU_VIDEO_PRIVATE_DATA *Private + QEMU_VIDEO_PRIVATE_DATA *Private, + BOOLEAN IsQxl ) { UINT32 AvailableFbSize; @@ -262,10 +263,42 @@ QemuVideoBochsModeSetup ( QEMU_VIDEO_BOCHS_MODES *VideoMode; // - // fetch available framebuffer size + // Fetch the available framebuffer size. // - AvailableFbSize = BochsRead (Private, VBE_DISPI_INDEX_VIDEO_MEMORY_64K); - AvailableFbSize *= SIZE_64KB; + // On stdvga, the full memory size returned by the + // VBE_DISPI_INDEX_VIDEO_MEMORY_64K is usable for drawing. + // + // On QXL however, only a leading segment, "surface 0", can be used for + // drawing; the rest of the buffer is used for the QXL guest-host protocol. + // The size of the drawable portion is available from a field in the QXL ROM + // bar. + // + if (IsQxl) { + UINT32 Signature; + UINT32 DrawStart; + + Signature = 0; + DrawStart = 0xFFFFFFFF; + AvailableFbSize = 0; + if (EFI_ERROR ( + Private->PciIo->Mem.Read (Private->PciIo, EfiPciIoWidthUint32, + PCI_BAR_IDX2, 0, 1, &Signature)) || + Signature != SIGNATURE_32 ('Q', 'X', 'R', 'O') || + EFI_ERROR ( + Private->PciIo->Mem.Read (Private->PciIo, EfiPciIoWidthUint32, + PCI_BAR_IDX2, 36, 1, &DrawStart)) || + DrawStart != 0 || + EFI_ERROR ( + Private->PciIo->Mem.Read (Private->PciIo, EfiPciIoWidthUint32, + PCI_BAR_IDX2, 40, 1, &AvailableFbSize))) { + DEBUG ((EFI_D_ERROR, "%a: can't read size of drawable buffer from QXL " + "ROM\n", __FUNCTION__)); + return EFI_NOT_FOUND; + } + } else { + AvailableFbSize = BochsRead (Private, VBE_DISPI_INDEX_VIDEO_MEMORY_64K); + AvailableFbSize *= SIZE_64KB; + } DEBUG ((EFI_D_VERBOSE, "%a: AvailableFbSize=0x%x\n", __FUNCTION__, AvailableFbSize));