From patchwork Tue Jul 11 16:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 118658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp625708vqm; Tue, 11 Jul 2023 10:04:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlHYqscwIKg45UpdBsV5nRuUQern2CoSQPfD1QfktKhqqIA/lvTFgau6V/2+ZWZhu1slNL0h X-Received: by 2002:a05:6a20:258a:b0:11f:6391:3add with SMTP id k10-20020a056a20258a00b0011f63913addmr15803833pzd.15.1689095073494; Tue, 11 Jul 2023 10:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689095073; cv=none; d=google.com; s=arc-20160816; b=XIv30bMM6G57/DF2wFSGY/Wvh8OsSFSNpAFTh+sZSmpO4Gd2TaG5HkbjBpqa9AVM64 1viIb/tV57yKaHNBqQkzIaMMrz9BwWd07sSJgQzRC7B5E6lRx+tbte+L7hMlonMD/Pdy eUQFKyuFA7wHnPdOrlurtGVIDhP9r+ccOiAwxdm9Qux+40hyn1mKAKUB+1eEyks+DTqB VB7xk96Ha0dg9N0WtQ9e2BrsjIwcfyzVdiZep30Z/Kb2i7BPcNYZxBpe0hHWEh0fHpLS sBXoEJHTx7sf6Z+ncQN8ecAsFU3PtN8rtJN/rT98RoLdoVQbpbv4hXZfYTESTTJ6M4ou 79Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=s3RR0NYHlYchGZfrgsz7DmY+bKmfwkFHz2pu3a35dQQ=; fh=XlWA3Y+MFaMsv8l7a0bPbKiHO/DSgPSssRLTDW9iA0I=; b=h9scZtMZqBvOGGxerfCi1XGbBFoKvwLcpnIGgPkvWWxbIO2vhfW7HpRLOqa32zDBpd qzqv18MAVUHGfuRnL2uNOSUwJ0w/dLAGSbA7fCaYVEYZgO7/hy9l3nZzwKe8aX/4BVBV UHz9X2Xmg57le3Q/A+a+i8RKL+No7diYa7LVqQyc8VvhzYFQFDtJMrYw6raNSWg0lnH4 WssSSRx0R9M7AxZzBpu5U+Ni3RR0QDEEzYyGF99FDglRUPVvMsrc2a0psO2mkTZhjdZd mdcVmtQzxV1jST2aRNEFmHGZYjd4u2OAUEy0YKv6SopUq3HKWozkct+pI/HgZ3U+bHAk WB/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=WozqtjMV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l1-20020a056a0016c100b006724753efd3si1810286pfc.195.2023.07.11.10.04.19; Tue, 11 Jul 2023 10:04:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=WozqtjMV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232686AbjGKQcf (ORCPT + 99 others); Tue, 11 Jul 2023 12:32:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232486AbjGKQc0 (ORCPT ); Tue, 11 Jul 2023 12:32:26 -0400 Received: from out-28.mta0.migadu.com (out-28.mta0.migadu.com [91.218.175.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 490D010C4 for ; Tue, 11 Jul 2023 09:32:20 -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=1689093138; 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=s3RR0NYHlYchGZfrgsz7DmY+bKmfwkFHz2pu3a35dQQ=; b=WozqtjMVmgFuC4Asnp2YwVthzxT8OwpiQ0LadMHgEQxaZrlUFJ72re4kuVfXCgPLjOFZ3i 6mJ090nchTsgXH9ZfBOZZhJ23oa0knENxqlBzpwcIF7ZLqLaRQbw4oMg7dJq8mcHK4Bl8k GuWrnM9EO7Y8unOLvVKV3YVb4cK7Jro= From: Sui Jingfeng To: Alex Deucher , Christian Koenig , David Airlie , Daniel Vetter , Dave Airlie , Thomas Zimmermann , Jocelyn Falempe , Javier Martinez Canillas , Maxime Ripard , Jani Nikula , Joonas Lahtinen , Ben Skeggs , Lyude Paul , Bjorn Helgaas , Helge Deller , Mario Limonciello Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-fbdev@vger.kernel.org, Sui Jingfeng Subject: [PATCH v3 1/9] video/aperture: Add a helper to detect if an aperture contains firmware FB Date: Wed, 12 Jul 2023 00:31:47 +0800 Message-Id: <20230711163155.791522-2-sui.jingfeng@linux.dev> In-Reply-To: <20230711163155.791522-1-sui.jingfeng@linux.dev> References: <20230711163155.791522-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771144555654976391 X-GMAIL-MSGID: 1771144555654976391 From: Sui Jingfeng This patch adds the aperture_contain_firmware_fb() function to do the determination. Unfortunately, due to the fact that the apertures list will be freed dynamically, the location and size information of the firmware FB will be lost after dedicated drivers call aperture_remove_conflicting_devices(), aperture_remove_conflicting_pci_devices() or aperture_remove_all_conflicting_devices() functions      We solve this problem by introducing two static variables that record the firmware framebuffer's start addrness and end addrness. It assumes that the system has only one active firmware framebuffer driver at a time. We don't use the global structure screen_info here, because PCI resources may get reallocated (the VRAM BAR could be moved) during the kernel boot stage. Cc: Thomas Zimmermann Cc: Javier Martinez Canillas Cc: Bjorn Helgaas Cc: Helge Deller Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/drm_aperture.c | 16 ++++++++++++++++ drivers/video/aperture.c | 29 +++++++++++++++++++++++++++++ include/drm/drm_aperture.h | 2 ++ include/linux/aperture.h | 7 +++++++ 4 files changed, 54 insertions(+) diff --git a/drivers/gpu/drm/drm_aperture.c b/drivers/gpu/drm/drm_aperture.c index 5729f3bb4398..f9c957aa5874 100644 --- a/drivers/gpu/drm/drm_aperture.c +++ b/drivers/gpu/drm/drm_aperture.c @@ -190,3 +190,19 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, return aperture_remove_conflicting_pci_devices(pdev, req_driver->name); } EXPORT_SYMBOL(drm_aperture_remove_conflicting_pci_framebuffers); + +/** + * drm_aperture_contain_firmware_fb - Determine if a aperture contains firmware framebuffer + * + * @base: the aperture's base address in physical memory + * @size: aperture size in bytes + * + * Returns: + * true if there exist a firmware framebuffer inside of the aperture passed in, + * or false otherwise. + */ +bool drm_aperture_contain_firmware_fb(resource_size_t base, resource_size_t size) +{ + return aperture_contain_firmware_fb(base, base + size); +} +EXPORT_SYMBOL(drm_aperture_contain_firmware_fb); diff --git a/drivers/video/aperture.c b/drivers/video/aperture.c index 561be8feca96..34eb962cfae8 100644 --- a/drivers/video/aperture.c +++ b/drivers/video/aperture.c @@ -141,6 +141,9 @@ struct aperture_range { static LIST_HEAD(apertures); static DEFINE_MUTEX(apertures_lock); +static resource_size_t firm_fb_start; +static resource_size_t firm_fb_end; + static bool overlap(resource_size_t base1, resource_size_t end1, resource_size_t base2, resource_size_t end2) { @@ -170,6 +173,9 @@ static int devm_aperture_acquire(struct device *dev, mutex_lock(&apertures_lock); + firm_fb_start = base; + firm_fb_end = end; + list_for_each(pos, &apertures) { ap = container_of(pos, struct aperture_range, lh); if (overlap(base, end, ap->base, ap->base + ap->size)) { @@ -377,3 +383,26 @@ int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, const char *na } EXPORT_SYMBOL(aperture_remove_conflicting_pci_devices); + +/** + * aperture_contain_firmware_fb - Detect if the firmware framebuffer belong to + * a aperture. + * @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(resource_size_t ap_start, resource_size_t ap_end) +{ + /* No firmware framebuffer support */ + if (!firm_fb_start || !firm_fb_end) + return false; + + if (firm_fb_start >= ap_start && firm_fb_end <= ap_end) + return true; + + return false; +} +EXPORT_SYMBOL(aperture_contain_firmware_fb); diff --git a/include/drm/drm_aperture.h b/include/drm/drm_aperture.h index cbe33b49fd5d..6a0b9bacb081 100644 --- a/include/drm/drm_aperture.h +++ b/include/drm/drm_aperture.h @@ -35,4 +35,6 @@ drm_aperture_remove_framebuffers(const struct drm_driver *req_driver) req_driver); } +bool drm_aperture_contain_firmware_fb(resource_size_t base, resource_size_t size); + #endif diff --git a/include/linux/aperture.h b/include/linux/aperture.h index 1a9a88b11584..d4dc5917c49b 100644 --- a/include/linux/aperture.h +++ b/include/linux/aperture.h @@ -19,6 +19,8 @@ int aperture_remove_conflicting_devices(resource_size_t base, resource_size_t si 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); #else static inline int devm_aperture_acquire_for_platform_device(struct platform_device *pdev, resource_size_t base, @@ -42,6 +44,11 @@ static inline int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, { return 0; } + +static inline bool aperture_contain_firmware_fb(resource_size_t ap_start, resource_size_t ap_end) +{ + return false; +} #endif /**