Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17787773rwd; Tue, 27 Jun 2023 07:35:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7r0cMQ9Zxl0HnU9dkZEJTbjrqFDZBrBmRjQHjhOwPApwKU9II9saxbsQV9BpBbugKRIEq2 X-Received: by 2002:a17:90a:199b:b0:260:de07:c656 with SMTP id 27-20020a17090a199b00b00260de07c656mr20816696pji.25.1687876522918; Tue, 27 Jun 2023 07:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687876522; cv=none; d=google.com; s=arc-20160816; b=cuYqIKD8GCAWSDbA095gni33wFK2Pe+J4BsrInAbpxTAKa30LVNo7uGEAOkryCEc/7 VvrsYG60mALXxz53HRcwUt6qKAiEgKeXWi8/Q2W5d8dE7p0aXJYDdyV0DGQbJ4GtqKe5 7On/VLM7bjVaPaQ4o46ZjNczmyNx9H+IEaWfGmxbJqq1HW1otIh9TkZRLG0rAMeydlVh uUbV21ofYc7PSQvKRTxEK9JtpzRFI2b8dq6wN+0ND5tvTnjhM8tOmUgAlr2pdWXRtg2w 9XfkABwyRZKp8w6UbmpEEI7iU1yfNupnS0cqjYu/Rn1h47avsGxt2y3OzYENRBwAkS28 x+zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id; bh=wATeBbX0Srbm729lPDPFsg/BHyVN3pr7M6bTvFF64YA=; fh=70Kk3tRoiECXOg0gNkjV+Y7cG3TJJg7Oxkl6NWIRot8=; b=WRFRHg7ikVZV+WBYbog653vSLvxWHiG2p0MAE31vJrstL+g2orkLKLhUP8SipefIO+ aiEgopst/5AJ5r6dZb9PtjGaJtzbfNc37v8sBlHubLcorNd4q6WaFyx2K5Km0Hbp+T74 JfmL47JMLSq07eAoG2TE9HZfm+N+h6Vp8K5yXqD47eYg1NYQhrx6L6ZWaWl0VwYgiCPr +/WLP/qIz+ds++8/XoAw1Cldjdqh05bDz3tLGlzwpTAidPmuNuzT5kuHxYJDpP9hR89i yq0AQXsQUyFZHNcDmW65HjWQk9w3BHqFkH9fxgdYR9kdzLqYcGefV5qbzvvt3yYRbKtd JNyg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q27-20020a63f95b000000b0053ef08b29bbsi7461573pgk.564.2023.06.27.07.35.11; Tue, 27 Jun 2023 07:35:22 -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 S231425AbjF0OVX (ORCPT + 99 others); Tue, 27 Jun 2023 10:21:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbjF0OVV (ORCPT ); Tue, 27 Jun 2023 10:21:21 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6A2D3AB; Tue, 27 Jun 2023 07:21:17 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8CxKsZb8Jpk0iYDAA--.4924S3; Tue, 27 Jun 2023 22:21:15 +0800 (CST) Received: from [10.20.42.43] (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxB81Z8JpkJlkMAA--.41429S3; Tue, 27 Jun 2023 22:21:13 +0800 (CST) Message-ID: <8da62fff-5402-db70-eae5-9174e6753fc7@loongson.cn> Date: Tue, 27 Jun 2023 22:21:13 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v7 5/8] video/aperture: Add a helper to detect if an aperture contains firmware FB Content-Language: en-US To: Sui Jingfeng <15330273260@189.cn>, 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, Thomas Zimmermann , Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , David Airlie , Daniel Vetter , Helge Deller , Jani Nikula References: <20230613030151.216625-1-15330273260@189.cn> <20230613030151.216625-6-15330273260@189.cn> From: Sui Jingfeng Organization: Loongson In-Reply-To: <20230613030151.216625-6-15330273260@189.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8BxB81Z8JpkJlkMAA--.41429S3 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj93XoWxuw1UtrW3tryktry5GFyUArc_yoW7tr1UpF sxAFZ8Gr4UKF1Fyay3CrWI9r4rXa1SqFWrW39xA3s3AF17AFykJr17ZFyDJrZxJrZrAa4a grZxtryrCa1DAFXCm3ZEXasCq-sJn29KB7ZKAUJUUUUk529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUPvb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUtVW8ZwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU tVWrXwAv7VC2z280aVAFwI0_Cr0_Gr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvEwI xGrwCYjI0SjxkI62AI1cAE67vIY487MxkF7I0En4kS14v26r1q6r43MxAIw28IcxkI7VAK I48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1q6r43MI8I3I0E5I8CrV AFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCI c40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267 AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Cr0_ Gr1UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUxO zsDUUUU X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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  PING ? On 2023/6/13 11:01, Sui Jingfeng wrote: > 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 > > /** -- Jingfeng