From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.11190.1639665016190094019 for ; Thu, 16 Dec 2021 06:30:16 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VVz6rfp9; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639665015; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ukhmAH0XlNh4cd/Ao8c5yaXgKA/qsiFUOtRbnGdHY/U=; b=VVz6rfp9kPOnLRBs/wzKEtqSKBe92j46m1oiIHaNmXvKkE3P3lSryiEadPuO0E6AZouJYg BYYvqTkKV9YeDMcgrBnUTl9jZJzK1Dw8MFwubkEC5oFxMkbdyakFYHFJ1XpbB93RYKvINx Z0UU4v8cnlhNiL9ppbbclXC9TF/lFdo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-353-cKl7njl1Mr6kELSSkgM0fg-1; Thu, 16 Dec 2021 09:30:12 -0500 X-MC-Unique: cKl7njl1Mr6kELSSkgM0fg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 49166760D2; Thu, 16 Dec 2021 14:30:09 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C94D77A223; Thu, 16 Dec 2021 14:30:08 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 4729318003B8; Thu, 16 Dec 2021 15:29:59 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Erdem Aktas , Julien Grall , Brijesh Singh , Pawel Polawski , Min Xu , Jiewen Yao , Tom Lendacky , Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , James Bottomley , Anthony Perard , Gerd Hoffmann Subject: [PATCH 4/5] OvmfPkg/QemuVideoDxe: factor out QemuVideoBochsAddMode Date: Thu, 16 Dec 2021 15:29:58 +0100 Message-Id: <20211216142959.1998191-5-kraxel@redhat.com> In-Reply-To: <20211216142959.1998191-1-kraxel@redhat.com> References: <20211216142959.1998191-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Add helper function to add a video mode to the list of modes. Move code. Minor debug logging tweaks, no other functional change. Signed-off-by: Gerd Hoffmann --- OvmfPkg/QemuVideoDxe/Initialize.c | 77 +++++++++++++++++++------------ 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/OvmfPkg/QemuVideoDxe/Initialize.c b/OvmfPkg/QemuVideoDxe/Initialize.c index 2b174d13faf2..8c5c9176ad21 100644 --- a/OvmfPkg/QemuVideoDxe/Initialize.c +++ b/OvmfPkg/QemuVideoDxe/Initialize.c @@ -245,16 +245,53 @@ STATIC QEMU_VIDEO_BOCHS_MODES QemuVideoBochsModes[] = { #define QEMU_VIDEO_BOCHS_MODE_COUNT \ (ARRAY_SIZE (QemuVideoBochsModes)) +STATIC +VOID +QemuVideoBochsAddMode ( + QEMU_VIDEO_PRIVATE_DATA *Private, + UINT32 AvailableFbSize, + UINT32 Width, + UINT32 Height + ) +{ + QEMU_VIDEO_MODE_DATA *ModeData = Private->ModeData + Private->MaxMode; + UINTN RequiredFbSize; + + RequiredFbSize = (UINTN)Width * Height * 4; + if (RequiredFbSize > AvailableFbSize) { + DEBUG (( + DEBUG_INFO, + "Skipping Bochs Mode %dx%d, 32-bit (not enough vram)\n", + Width, + Height + )); + return; + } + + ModeData->InternalModeIndex = (UINT32)Private->MaxMode; + ModeData->HorizontalResolution = Width; + ModeData->VerticalResolution = Height; + ModeData->ColorDepth = 32; + DEBUG (( + DEBUG_INFO, + "Adding Bochs Internal Mode %d: %dx%d, %d-bit\n", + ModeData->InternalModeIndex, + ModeData->HorizontalResolution, + ModeData->VerticalResolution, + ModeData->ColorDepth + )); + + Private->MaxMode++; +} + EFI_STATUS QemuVideoBochsModeSetup ( QEMU_VIDEO_PRIVATE_DATA *Private, BOOLEAN IsQxl ) { - UINT32 AvailableFbSize; - UINT32 Index; - QEMU_VIDEO_MODE_DATA *ModeData; - QEMU_VIDEO_BOCHS_MODES *VideoMode; + UINT32 AvailableFbSize; + UINT32 Index; // // Fetch the available framebuffer size. @@ -343,34 +380,14 @@ QemuVideoBochsModeSetup ( return EFI_OUT_OF_RESOURCES; } - ModeData = Private->ModeData; - VideoMode = &QemuVideoBochsModes[0]; for (Index = 0; Index < QEMU_VIDEO_BOCHS_MODE_COUNT; Index++) { - UINTN RequiredFbSize; - - RequiredFbSize = (UINTN)VideoMode->Width * VideoMode->Height * 4; - if (RequiredFbSize <= AvailableFbSize) { - ModeData->InternalModeIndex = Index; - ModeData->HorizontalResolution = VideoMode->Width; - ModeData->VerticalResolution = VideoMode->Height; - ModeData->ColorDepth = 32; - DEBUG (( - DEBUG_INFO, - "Adding Mode %d as Bochs Internal Mode %d: %dx%d, %d-bit\n", - (INT32)(ModeData - Private->ModeData), - ModeData->InternalModeIndex, - ModeData->HorizontalResolution, - ModeData->VerticalResolution, - ModeData->ColorDepth - )); - - ModeData++; - } - - VideoMode++; + QemuVideoBochsAddMode ( + Private, + AvailableFbSize, + QemuVideoBochsModes[Index].Width, + QemuVideoBochsModes[Index].Height + ); } - Private->MaxMode = ModeData - Private->ModeData; - return EFI_SUCCESS; } -- 2.33.1