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.web12.9273.1642413556991670168 for ; Mon, 17 Jan 2022 01:59:17 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UWBClIQ+; 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=1642413555; 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=3RlJvSaTj/2X+cMrXQM3PLqOvTiJgOhtHm1qP3BRk9c=; b=UWBClIQ+xL1D8FwQgNMXlm6Q1SHvUuVg4Tw5f6NvODZ5LjmtMxTBoOc3Y36Kvups5jgAiq 2jR2cg9AuxC0/MFor+oTyzRzAACOqCmQv/6lW/TD+5q3IWAIsvtG+7PfTGCHhJ9mW9jq3Z NsNaHPlSaFbXWQsEVgO8t2NEz9HIVi0= 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-633-sr_lX7oIOgi9MX5RYtd-VA-1; Mon, 17 Jan 2022 04:59:11 -0500 X-MC-Unique: sr_lX7oIOgi9MX5RYtd-VA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2FBB218C8C01; Mon, 17 Jan 2022 09:59:06 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F2A2870D26; Mon, 17 Jan 2022 09:58:53 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 3C2FF1800620; Mon, 17 Jan 2022 10:58:17 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Jordan Justen , Min Xu , Jiewen Yao , Julien Grall , Tom Lendacky , Brijesh Singh , James Bottomley , Erdem Aktas , Pawel Polawski , Anthony Perard , Ard Biesheuvel Subject: [PATCH v2 4/5] OvmfPkg/QemuVideoDxe: factor out QemuVideoBochsAddMode Date: Mon, 17 Jan 2022 10:58:16 +0100 Message-Id: <20220117095817.1964424-5-kraxel@redhat.com> In-Reply-To: <20220117095817.1964424-1-kraxel@redhat.com> References: <20220117095817.1964424-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.34.1