From patchwork Tue Jun 13 03:01:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 107047 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp274079vqr; Mon, 12 Jun 2023 20:15:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6WbfRI3n3m69qS/dBFY2lPVpHRE2ii6l/4Lat9mjbriHhKKfKoBvZhBX5gn+swXIJYFH+d X-Received: by 2002:a17:906:d553:b0:970:c9f:2db6 with SMTP id cr19-20020a170906d55300b009700c9f2db6mr11715229ejc.63.1686626103124; Mon, 12 Jun 2023 20:15:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686626103; cv=none; d=google.com; s=arc-20160816; b=rIWvXooWOYEuH5ny3ZHpHWfJ5tlWPcws4HVPcfZoRMFLYorU6w/Ft4yo7RRGUx0QaK XUlJs5SuzJqxCMETHYTXSruOWIuwj8u2SofT/KoYQQV2Om0La0JBpTJkYnvvMSg0L25k SKf5VbZYlYxIKheNmJJuwtiuZdT5qegDuoTb4spjY5923SqvjPJsB0JzoV2I58ylsPL5 Kejd9M9soY80e6/qahNE0lSpjGbkXLf2prBZoThsgwMQipHUMbbMe6GidPVMWNG7tNEt GrI2jTw1n+O/7QNHgWCjfU0fixzSc9LbfOlXa02na/hnnUK+y2lYkBkiHe0Ugevh3DY6 avvw== 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:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=GIsbNY4Mb47GZOP1sDLnLj7sNU75tuWjGzp78R/rGnQ=; b=sx50UAWj5RIncT0Comr7bnCoY8CdlGjUJXP/qWty3pYJtksPVRtgqLnya0X3IC+5R5 +lXdQmcHsi/SfLGjw8fWzMRROAV3pz20FTj15hkh5zudFoqzDEIZrxxBGpgf+ZgstcnO B6BZOPItnwepoysd1G1sSKUSIK2DtY6nmDvE0MIn6hNH0bixrGcV3GLS12bL/j2yPws1 rB/4r8/jgjex9vARPVYDZTyoAzOT6Mcqt0p/BQ9SUd+H7Qpl07DqSoLy98Ys3QR10biD JotDWMJgaKBQfqnzPFPy58ctLdNu0Slp1BtimgwZtOtVmHelT9aKQDjL1S1RnzPTreS9 RZZQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id si26-20020a170906ceda00b0097488f56babsi5440817ejb.101.2023.06.12.20.14.39; Mon, 12 Jun 2023 20:15:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239417AbjFMDFF (ORCPT + 99 others); Mon, 12 Jun 2023 23:05:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239365AbjFMDEG (ORCPT ); Mon, 12 Jun 2023 23:04:06 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.102]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 232511FFD; Mon, 12 Jun 2023 20:03:04 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:47948.1267835893 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id 07D72100312; Tue, 13 Jun 2023 11:02:10 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-7vx9t with ESMTP id cc3a4c0ad4584704b36637bc3ff8007e for bhelgaas@google.com; Tue, 13 Jun 2023 11:02:13 CST X-Transaction-ID: cc3a4c0ad4584704b36637bc3ff8007e X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Bjorn Helgaas 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 , Thomas Zimmermann , Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , David Airlie , Daniel Vetter , Helge Deller Subject: [PATCH v7 5/8] video/aperture: Add a helper to detect if an aperture contains firmware FB Date: Tue, 13 Jun 2023 11:01:48 +0800 Message-Id: <20230613030151.216625-6-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230613030151.216625-1-15330273260@189.cn> References: <20230613030151.216625-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768555652460053800?= X-GMAIL-MSGID: =?utf-8?q?1768555652460053800?= From: Sui Jingfeng This patch adds the aperture_contain_firmware_fb() function to do the determination. Unfortunately due to the fact that 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 handle this problem by introducing two static variables which 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 resource may get reallocated(the VRAM BAR could be moved) at kernel boot stage. Cc: Thomas Zimmermann Cc: Javier Martinez Canillas Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: David Airlie Cc: Daniel Vetter 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..6e5d8a08683c 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 on if there is a firmware framebuffer belong to 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..5a5422cec669 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 on 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 /**