From patchwork Tue Jul 11 16:43:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 702067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6C2DEB64DD for ; Tue, 11 Jul 2023 16:53:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232056AbjGKQxg (ORCPT ); Tue, 11 Jul 2023 12:53:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231555AbjGKQxd (ORCPT ); Tue, 11 Jul 2023 12:53:33 -0400 Received: from out-10.mta1.migadu.com (out-10.mta1.migadu.com [95.215.58.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0BFF10D8 for ; Tue, 11 Jul 2023 09:53:31 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1689093809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GBy5pJ1hlnJ55l3+0FoW8CoU4fx5kPQd0O17NeAPNiY=; b=VLnHpbhmCbj+VytfP2De0A90dTbIOm7DbFncSWPFk5st0NBQu1Rgdl8iXr4M//w7gMNkg6 k82DFVKmL0UkqsJrG275lNVeqSYnUy+KXU/qz2KFRRtukDcsipHPOqzM3498Fm16a4DX4L 10mrRoZDA7Sbop614INjogTPQZG6Ouw= From: Sui Jingfeng To: David Airlie Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, kvm@vger.kernel.org, linux-fbdev@vger.kernel.org, Sui Jingfeng , Thomas Zimmermann , Javier Martinez Canillas , Helge Deller Subject: [PATCH v3 2/9] video/aperture: Add a helper for determining if an unmoved aperture contain FB Date: Wed, 12 Jul 2023 00:43:03 +0800 Message-Id: <20230711164310.791756-3-sui.jingfeng@linux.dev> In-Reply-To: <20230711164310.791756-1-sui.jingfeng@linux.dev> References: <20230711164310.791756-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org From: Sui Jingfeng This patch is intended to form a uniform approach to determining if an unmoved aperture contains the firmware FB. I believe that the global screen_info is more about video-specific things. Putting it in video/aperture.c helps form a uniform approach. Cc: Thomas Zimmermann Cc: Javier Martinez Canillas Cc: Helge Deller Signed-off-by: Sui Jingfeng --- drivers/video/aperture.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/aperture.h | 7 +++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/video/aperture.c b/drivers/video/aperture.c index 34eb962cfae8..f03dfcabc303 100644 --- a/drivers/video/aperture.c +++ b/drivers/video/aperture.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -406,3 +407,38 @@ bool aperture_contain_firmware_fb(resource_size_t ap_start, resource_size_t ap_e return false; } EXPORT_SYMBOL(aperture_contain_firmware_fb); + +/** + * aperture_contain_firmware_fb_nonreloc - Detect if the firmware framebuffer + * belong to a non-relocatable aperture, such as the aperture of platform + * device. Note that this function relay on the global screen info. + * @ap_start: the aperture's start address in physical memory + * @ap_end: the aperture's end address in physical memory + * + * Returns: + * true if there is a firmware framebuffer belong to the aperture passed in, + * or false otherwise. + */ +bool aperture_contain_firmware_fb_nonreloc(resource_size_t ap_start, resource_size_t ap_end) +{ + u64 fb_start; + u64 fb_end; + + if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) { + fb_start = (u64)screen_info.ext_lfb_base << 32 | screen_info.lfb_base; + fb_end = fb_start + screen_info.lfb_size; + } else { + fb_start = screen_info.lfb_base; + fb_end = fb_start + screen_info.lfb_size; + } + + /* No firmware framebuffer support */ + if (!fb_start || !fb_end) + return false; + + if (fb_start >= ap_start && fb_end <= ap_end) + return true; + + return false; +} +EXPORT_SYMBOL(aperture_contain_firmware_fb_nonreloc); diff --git a/include/linux/aperture.h b/include/linux/aperture.h index d4dc5917c49b..906d23532b56 100644 --- a/include/linux/aperture.h +++ b/include/linux/aperture.h @@ -21,6 +21,8 @@ int __aperture_remove_legacy_vga_devices(struct pci_dev *pdev); int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, const char *name); bool aperture_contain_firmware_fb(resource_size_t ap_start, resource_size_t ap_end); + +bool aperture_contain_firmware_fb_nonreloc(resource_size_t ap_start, resource_size_t ap_end); #else static inline int devm_aperture_acquire_for_platform_device(struct platform_device *pdev, resource_size_t base, @@ -49,6 +51,11 @@ static inline bool aperture_contain_firmware_fb(resource_size_t ap_start, resour { return false; } + +static bool aperture_contain_firmware_fb_nonreloc(resource_size_t ap_start, resource_size_t ap_end) +{ + return false; +} #endif /**