From patchwork Sat Sep 1 14:08:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 10584787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E07E016B1 for ; Sat, 1 Sep 2018 14:10:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3C4A2A218 for ; Sat, 1 Sep 2018 14:10:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7C892A223; Sat, 1 Sep 2018 14:10:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.1 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6197C2A218 for ; Sat, 1 Sep 2018 14:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:MIME-Version:Subject:From:References :In-Reply-To:Message-Id:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IS2ZpjRteHSUanf/V0fq71rsqi/wlF/IJFxzNKYKXA8=; b=Evg3uTnWFEWFpC U2k6oIZseTIYwA2HKIisa482gXk4TkDeE2l6JkFWENxq7VNzYqr7Y6G/V6kzjFpKlpjC5gsbXjdLM ddeWmL2W+gWR5qSWRYlcskGu2MiPxx3yPsG6+lZFY/iHkCz7Y3n6rQJmBtGi4ZEEpBdAD2b+mQvVB Je+tgldh4WwhQmjWA4MlqkgYZjlB2q229Wd7GN4P3o4LcETGVlZZB3vPaIPAbMwmN7zC7XA2aJhi4 kI6oXF3zt8ZBjipAztPCWIy9WxIoW4r0aUniRBxglVD8aVcnPA3O7RYiMux7L2L6KbKUpKk0/zv40 GUI1RVaoyf4SGSaBZYsw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fw6bW-0001uW-7j; Sat, 01 Sep 2018 14:10:22 +0000 Received: from rere.qmqm.pl ([91.227.64.183]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fw6a7-0000et-TY for linux-arm-kernel@lists.infradead.org; Sat, 01 Sep 2018 14:08:59 +0000 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 422dNl58hQzdC; Sat, 1 Sep 2018 16:08:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1535810887; bh=chMZQiuJkZVb/oGMhUJ0Y2jWN0e8uTlU+J2Rh2hB2+U=; h=Date:In-Reply-To:References:From:Subject:To:Cc:Cc:From; b=WkxRhtYMtLQZu8QvljKL584ecjIb7Ghy7eTxPbfA6ZyoqkWZnCP+0sJ+3nnuGBY6I HSA9D//XUC/VzAMa9aK43YARMQvnD/quQOEZpIHNNUABXg0hwHop86nfv0+Bjs7pSR rKjWvuzceipaJ8mQbDhn3BVSnlKFYV5hSQ/RLui3osD+9G6Hg6vBNmu80z2Aoxn4Ou LC7xD5Cs3Jx2i/8HTefQvPkaS7kPfxk8PxWOGNaFzC3waCDTSDu0/eC8gKSG/HXtvc er0LxAkDHamlr+YP9YHwETROXIi42xRqoTlqObcjViV1WaigK3kMIri3aqH+pVZBVY 9za6md3gvcCDg== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.100.0 at mail Date: Sat, 01 Sep 2018 16:08:45 +0200 Message-Id: <7db1c278276de420eb45a1b71d06b5eb6bbd49ef.1535810304.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 04/13] fbdev: add remove_conflicting_pci_framebuffers() MIME-Version: 1.0 To: dri-devel@lists.freedesktop.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180901_070856_308871_1B30FF48 X-CRM114-Status: GOOD ( 10.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, linux-tegra@vger.kernel.org, Bartlomiej Zolnierkiewicz , David Airlie , amd-gfx@lists.freedesktop.org, Jonathan Hunter , Eric Anholt , Thierry Reding , Gerd Hoffmann , Alex Deucher , Dave Airlie , Maxime Ripard , virtualization@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Almost all PCI drivers using remove_conflicting_framebuffers() wrap it with the same code. --- v2: add kerneldoc for DRM helper v3: propagate remove_conflicting_framebuffers() return value + move kerneldoc to where function is implemented Signed-off-by: Michał Mirosław --- drivers/video/fbdev/core/fbmem.c | 35 ++++++++++++++++++++++++++++++++ include/drm/drm_fb_helper.h | 12 +++++++++++ include/linux/fb.h | 2 ++ 3 files changed, 49 insertions(+) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 2de93b5014e3..cd96b1c62bbe 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -1812,6 +1813,40 @@ int remove_conflicting_framebuffers(struct apertures_struct *a, } EXPORT_SYMBOL(remove_conflicting_framebuffers); +/** + * remove_conflicting_pci_framebuffers - remove firmware-configured framebuffers for PCI devices + * @pdev: PCI device + * @resource_id: index of PCI BAR configuring framebuffer memory + * @name: requesting driver name + * + * This function removes framebuffer devices (eg. initialized by firmware) + * using memory range configured for @pdev's BAR @resource_id. + * + * The function assumes that PCI device with shadowed ROM drives a primary + * display and so kicks out vga16fb. + */ +int remove_conflicting_pci_framebuffers(struct pci_dev *pdev, int res_id, const char *name) +{ + struct apertures_struct *ap; + bool primary = false; + int err; + + ap = alloc_apertures(1); + if (!ap) + return -ENOMEM; + + ap->ranges[0].base = pci_resource_start(pdev, res_id); + ap->ranges[0].size = pci_resource_len(pdev, res_id); +#ifdef CONFIG_X86 + primary = pdev->resource[PCI_ROM_RESOURCE].flags & + IORESOURCE_ROM_SHADOW; +#endif + err = remove_conflicting_framebuffers(ap, name, primary); + kfree(ap); + return err; +} +EXPORT_SYMBOL(remove_conflicting_pci_framebuffers); + /** * register_framebuffer - registers a frame buffer device * @fb_info: frame buffer info structure diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h index b069433e7fc1..20ea856db900 100644 --- a/include/drm/drm_fb_helper.h +++ b/include/drm/drm_fb_helper.h @@ -577,4 +577,16 @@ drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a, #endif } +static inline int +drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, + int resource_id, + const char *name) +{ +#if IS_REACHABLE(CONFIG_FB) + return remove_conflicting_pci_framebuffers(pdev, resource_id, name); +#else + return 0; +#endif +} + #endif diff --git a/include/linux/fb.h b/include/linux/fb.h index aa74a228bb92..abeffd55b66a 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -632,6 +632,8 @@ extern ssize_t fb_sys_write(struct fb_info *info, const char __user *buf, extern int register_framebuffer(struct fb_info *fb_info); extern int unregister_framebuffer(struct fb_info *fb_info); extern int unlink_framebuffer(struct fb_info *fb_info); +extern int remove_conflicting_pci_framebuffers(struct pci_dev *pdev, int res_id, + const char *name); extern int remove_conflicting_framebuffers(struct apertures_struct *a, const char *name, bool primary); extern int fb_prepare_logo(struct fb_info *fb_info, int rotate);