From nobody Sun Jun 14 21:06:47 2026 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 B56D1C433F5 for ; Wed, 11 May 2022 11:26:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242023AbiEKL0K (ORCPT ); Wed, 11 May 2022 07:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241383AbiEKLZD (ORCPT ); Wed, 11 May 2022 07:25:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02C8E237242 for ; Wed, 11 May 2022 04:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652268298; 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=B9SntuE95Z9lS2Zx81mCZFUkNBpVjW+b+N3eCCbF1gA=; b=Zp+p5FcGfO+WgwRQPJPqawGMxeIPMJL1BIVHXxkW+2hqpBy6BiTgjXcwrgpmAjKW7Icpr3 kq+M71qu1KvTBWIkjjvjgolIBYNXiGBRP+7iU6jy7m6q5z4P2AJ4CBDuUO+djgRgo5Kr6V 9pz5PdZcGPkoQ7Om57A4bqq6V9CgOFY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-639-RwZaKct1MlSPxE3amZWXQA-1; Wed, 11 May 2022 07:24:56 -0400 X-MC-Unique: RwZaKct1MlSPxE3amZWXQA-1 Received: by mail-wr1-f69.google.com with SMTP id t17-20020adfa2d1000000b0020ac519c222so729050wra.4 for ; Wed, 11 May 2022 04:24:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B9SntuE95Z9lS2Zx81mCZFUkNBpVjW+b+N3eCCbF1gA=; b=wX07pUKc43uCcr/FCW8HlHLCWxwaB37KPDdSCUWiAA+f0iIlAiQRrCsj52LvKSLDL0 WvJBa/13/mJakHjfmrK0uJ41vpBLERHz5qogs9vt4ZHQw1yNymlhKwp3/Fdt/5of0QHT NkifzLg8ZlbOMxBFgYa4SwQNhUFd9mysgWR6WbNSAJ+5ChuosjXLKg5qYy7L/eHKxUbi hRO/oeOYKQYy1kwiLMDGgQLI3FfMPKEVCWQBNLIT2wguAAhqX5SEVkuHc9QMA5X1R6P5 +JzY+bbuY4P/kuRFtIUtxtfHFVtU6eOrAE2nLBs4tpJdjWy5/txy31uO80OtUH/KACQf IXHg== X-Gm-Message-State: AOAM530TWV1ZlWbRs874RaObQwDXbslDDYlW2oQzZK7vzJaukeKeqy9A NjrwjbJLjfr3p2wABYO8qJrAurHmB2/zMkysEMBW7a1PwHLpuAgsD7fv8XVhLEpKQ5Bob+Ws9h+ lIesYpm0M0C1xh4dt2KcYjY08/5N36jnTqNGjni48YWwrj+K2fXb4TGR5AjjCV6/1xXhgsxIggv o= X-Received: by 2002:a7b:c310:0:b0:38c:f07a:e10d with SMTP id k16-20020a7bc310000000b0038cf07ae10dmr4381308wmj.110.1652268295562; Wed, 11 May 2022 04:24:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLj2CSI9aVxKNa4g6AjcxfP1g4hpdYDGGtiwl+UPUrJBEfHDnhXd+VQuLlXkDmk+7WrCcTxA== X-Received: by 2002:a7b:c310:0:b0:38c:f07a:e10d with SMTP id k16-20020a7bc310000000b0038cf07ae10dmr4381276wmj.110.1652268295247; Wed, 11 May 2022 04:24:55 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id j1-20020a5d4481000000b0020c5253d8d3sm1429174wrq.31.2022.05.11.04.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 04:24:54 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Daniel Vetter , Greg Kroah-Hartman , Thomas Zimmermann , dri-devel@lists.freedesktop.org, Javier Martinez Canillas Subject: [PATCH v5 1/7] firmware: sysfb: Make sysfb_create_simplefb() return a pdev pointer Date: Wed, 11 May 2022 13:24:32 +0200 Message-Id: <20220511112438.1251024-2-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511112438.1251024-1-javierm@redhat.com> References: <20220511112438.1251024-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This function just returned 0 on success or an errno code on error, but it could be useful for sysfb_init() callers to have a pointer to the device. Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Vetter Reviewed-by: Thomas Zimmermann --- (no changes since v3) Changes in v3: - Add Thomas Zimmermann's Reviewed-by tag to patch #1. Changes in v2: - Rebase on top of latest drm-misc-next and fix conflicts (Daniel Vetter). drivers/firmware/sysfb.c | 4 ++-- drivers/firmware/sysfb_simplefb.c | 16 ++++++++-------- include/linux/sysfb.h | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/firmware/sysfb.c b/drivers/firmware/sysfb.c index 2bfbb05f7d89..b032f40a92de 100644 --- a/drivers/firmware/sysfb.c +++ b/drivers/firmware/sysfb.c @@ -46,8 +46,8 @@ static __init int sysfb_init(void) /* try to create a simple-framebuffer device */ compatible =3D sysfb_parse_mode(si, &mode); if (compatible) { - ret =3D sysfb_create_simplefb(si, &mode); - if (!ret) + pd =3D sysfb_create_simplefb(si, &mode); + if (!IS_ERR(pd)) return 0; } =20 diff --git a/drivers/firmware/sysfb_simplefb.c b/drivers/firmware/sysfb_sim= plefb.c index bda8712bfd8c..a353e27f83f5 100644 --- a/drivers/firmware/sysfb_simplefb.c +++ b/drivers/firmware/sysfb_simplefb.c @@ -57,8 +57,8 @@ __init bool sysfb_parse_mode(const struct screen_info *si, return false; } =20 -__init int sysfb_create_simplefb(const struct screen_info *si, - const struct simplefb_platform_data *mode) +__init struct platform_device *sysfb_create_simplefb(const struct screen_i= nfo *si, + const struct simplefb_platform_data *mode) { struct platform_device *pd; struct resource res; @@ -76,7 +76,7 @@ __init int sysfb_create_simplefb(const struct screen_info= *si, base |=3D (u64)si->ext_lfb_base << 32; if (!base || (u64)(resource_size_t)base !=3D base) { printk(KERN_DEBUG "sysfb: inaccessible VRAM base\n"); - return -EINVAL; + return ERR_PTR(-EINVAL); } =20 /* @@ -93,7 +93,7 @@ __init int sysfb_create_simplefb(const struct screen_info= *si, length =3D mode->height * mode->stride; if (length > size) { printk(KERN_WARNING "sysfb: VRAM smaller than advertised\n"); - return -EINVAL; + return ERR_PTR(-EINVAL); } length =3D PAGE_ALIGN(length); =20 @@ -104,11 +104,11 @@ __init int sysfb_create_simplefb(const struct screen_= info *si, res.start =3D base; res.end =3D res.start + length - 1; if (res.end <=3D res.start) - return -EINVAL; + return ERR_PTR(-EINVAL); =20 pd =3D platform_device_alloc("simple-framebuffer", 0); if (!pd) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 sysfb_apply_efi_quirks(pd); =20 @@ -124,10 +124,10 @@ __init int sysfb_create_simplefb(const struct screen_= info *si, if (ret) goto err_put_device; =20 - return 0; + return pd; =20 err_put_device: platform_device_put(pd); =20 - return ret; + return ERR_PTR(ret); } diff --git a/include/linux/sysfb.h b/include/linux/sysfb.h index b0dcfa26d07b..708152e9037b 100644 --- a/include/linux/sysfb.h +++ b/include/linux/sysfb.h @@ -72,8 +72,8 @@ static inline void sysfb_apply_efi_quirks(struct platform= _device *pd) =20 bool sysfb_parse_mode(const struct screen_info *si, struct simplefb_platform_data *mode); -int sysfb_create_simplefb(const struct screen_info *si, - const struct simplefb_platform_data *mode); +struct platform_device *sysfb_create_simplefb(const struct screen_info *si, + const struct simplefb_platform_data *mode); =20 #else /* CONFIG_SYSFB_SIMPLE */ =20 @@ -83,10 +83,10 @@ static inline bool sysfb_parse_mode(const struct screen= _info *si, return false; } =20 -static inline int sysfb_create_simplefb(const struct screen_info *si, - const struct simplefb_platform_data *mode) +static inline struct platform_device *sysfb_create_simplefb(const struct s= creen_info *si, + const struct simplefb_platform_data *mode) { - return -EINVAL; + return ERR_PTR(-EINVAL); } =20 #endif /* CONFIG_SYSFB_SIMPLE */ --=20 2.35.1 From nobody Sun Jun 14 21:06:47 2026 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 DB5F5C433FE for ; Wed, 11 May 2022 11:26:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242830AbiEKL00 (ORCPT ); Wed, 11 May 2022 07:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241336AbiEKLZD (ORCPT ); Wed, 11 May 2022 07:25:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 39383237BBF for ; Wed, 11 May 2022 04:25:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652268299; 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=xhuIDxij1dFQK1woz+U0GSNcD8pO0M2OCBta2I1W2Qw=; b=ORBnxkDHB3xfQBM956IWxyKKhkWgmM/vAIHqush/esJWAq/OALFIa8Kmp7JSdaQ/6NQKCU pE5fFBt3AO253X16kc1Fq+1MbssSJCuCJhIJxemwfSDY6WwIniEl5M1CBaeTpKlRNpuM8h xbr1z71X/mUqBswsECj3Z2ivG2dB3oE= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-625-lXwsggiIOsuKnIQzTRd7bA-1; Wed, 11 May 2022 07:24:58 -0400 X-MC-Unique: lXwsggiIOsuKnIQzTRd7bA-1 Received: by mail-wm1-f70.google.com with SMTP id i18-20020a1c5412000000b0039491a8298cso610434wmb.5 for ; Wed, 11 May 2022 04:24:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xhuIDxij1dFQK1woz+U0GSNcD8pO0M2OCBta2I1W2Qw=; b=2q4gTW4KFcn0F6p2NNr8StxJWW5aI+H7tU/qrm2oMrQJtyJmnL/LIbIblcfpzlk1qG Dmyz46PtBi/NBQ1H0C57AocMcPP9oFvV8sFh9QSLpRetFvQOWt+MlrC6Zw8+/2ZgAwbb tfD6aNib6S0DZ9HmZ71rNv+JcBAcLtfDfuHCXDYmGwevesUx/aWu2isxza/giQNoT4DL whlbCc9d8NgDaWX6qunQaJGFKr9L4bSTq/rOwdHJcyTlKqC1S9Fxs1oHukuU/nIwdAVK YLiHOcgoKbGUOx6mDpgtzbGuzN++tI68hVP8V8BjA8GsfPcqr/0Er0ZwYSCLBnlgUYh4 YL6Q== X-Gm-Message-State: AOAM532UDaYKsDntnTu4vFfEodq7GebfVav7H21vuOmZOxmSStcy3CjP /hzN0bpCJ4W9sUweIyMVwlYrvU8kCmsRq1g5WHvduKaa5bGy1pQjwlpVinMPqjplPsHPY9jeK9Y e/4LCJ2x7G3c9umlj0OUYydKGhIMo4ALg4Qrw7PvH0uh3LQPWrlKnWSdUCPjKxi/XfwpkgiXMq6 Q= X-Received: by 2002:a7b:cc93:0:b0:394:2622:fcd9 with SMTP id p19-20020a7bcc93000000b003942622fcd9mr4514984wma.20.1652268296569; Wed, 11 May 2022 04:24:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRIFQcq1jQPPfql9v29OqbDwMo6HCFe2d4EHkjhfoYsd8KlDrK7oJBh/f5bYM9M/IMttgafQ== X-Received: by 2002:a7b:cc93:0:b0:394:2622:fcd9 with SMTP id p19-20020a7bcc93000000b003942622fcd9mr4514945wma.20.1652268296167; Wed, 11 May 2022 04:24:56 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id j1-20020a5d4481000000b0020c5253d8d3sm1429174wrq.31.2022.05.11.04.24.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 04:24:55 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Daniel Vetter , Greg Kroah-Hartman , Thomas Zimmermann , dri-devel@lists.freedesktop.org, Javier Martinez Canillas , Jonathan Corbet , linux-doc@vger.kernel.org Subject: [PATCH v5 2/7] firmware: sysfb: Add helpers to unregister a pdev and disable registration Date: Wed, 11 May 2022 13:24:33 +0200 Message-Id: <20220511112438.1251024-3-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511112438.1251024-1-javierm@redhat.com> References: <20220511112438.1251024-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" These can be used by subsystems to unregister a platform device registered by sysfb and also to disable future platform device registration in sysfb. Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Vetter --- (no changes since v4) Changes in v4: - Make sysfb_disable() to also attempt to unregister a device. Changes in v2: - Add kernel-doc comments and include in other_interfaces.rst (Daniel Vette= r). .../driver-api/firmware/other_interfaces.rst | 6 ++ drivers/firmware/sysfb.c | 87 +++++++++++++++++-- include/linux/sysfb.h | 19 ++++ 3 files changed, 106 insertions(+), 6 deletions(-) diff --git a/Documentation/driver-api/firmware/other_interfaces.rst b/Docum= entation/driver-api/firmware/other_interfaces.rst index b81794e0cfbb..06ac89adaafb 100644 --- a/Documentation/driver-api/firmware/other_interfaces.rst +++ b/Documentation/driver-api/firmware/other_interfaces.rst @@ -13,6 +13,12 @@ EDD Interfaces .. kernel-doc:: drivers/firmware/edd.c :internal: =20 +Generic System Framebuffers Interface +------------------------------------- + +.. kernel-doc:: drivers/firmware/sysfb.c + :export: + Intel Stratix10 SoC Service Layer --------------------------------- Some features of the Intel Stratix10 SoC require a level of privilege diff --git a/drivers/firmware/sysfb.c b/drivers/firmware/sysfb.c index b032f40a92de..6768968949e6 100644 --- a/drivers/firmware/sysfb.c +++ b/drivers/firmware/sysfb.c @@ -34,21 +34,92 @@ #include #include =20 +static struct platform_device *pd; +static DEFINE_MUTEX(disable_lock); +static bool disabled; + +static bool sysfb_unregister(void) +{ + if (IS_ERR_OR_NULL(pd)) + return false; + + platform_device_unregister(pd); + pd =3D NULL; + + return true; +} + +/** + * sysfb_disable() - disable the Generic System Framebuffers support + * + * This disables the registration of system framebuffer devices that match= the + * generic drivers that make use of the system framebuffer set up by firmw= are. + * + * It also unregisters a device if this was already registered by sysfb_in= it(). + * + * Context: The function can sleep. A @disable_lock mutex is acquired to s= erialize + * against sysfb_init(), that registers a system framebuffer devi= ce and + * sysfb_try_unregister(), that tries to unregister a framebuffer= device. + */ +void sysfb_disable(void) +{ + mutex_lock(&disable_lock); + sysfb_unregister(); + disabled =3D true; + mutex_unlock(&disable_lock); +} +EXPORT_SYMBOL_GPL(sysfb_disable); + +/** + * sysfb_try_unregister() - attempt to unregister a system framebuffer dev= ice + * @dev: device to unregister + * + * This tries to unregister a system framebuffer device if this was regist= ered + * by the Generic System Framebuffers. The device will only be unregistere= d if + * it was registered by sysfb_init(), otherwise it will not be unregistere= d. + * + * Context: The function can sleep. a @load_lock mutex is acquired to seri= alize + * against sysfb_init(), that registers a simple framebuffer devi= ce and + * sysfb_disable(), that disables the Generic System Framebuffers= support. + * + * Return: + * * true - the device was unregistered successfully + * * false - the device was not unregistered + */ +bool sysfb_try_unregister(struct device *dev) +{ + bool ret =3D false; + + mutex_lock(&disable_lock); + if (IS_ERR_OR_NULL(pd) || pd !=3D to_platform_device(dev)) + goto unlock_mutex; + + ret =3D sysfb_unregister(); + +unlock_mutex: + mutex_unlock(&disable_lock); + return ret; +} +EXPORT_SYMBOL_GPL(sysfb_try_unregister); + static __init int sysfb_init(void) { struct screen_info *si =3D &screen_info; struct simplefb_platform_data mode; - struct platform_device *pd; const char *name; bool compatible; - int ret; + int ret =3D 0; + + mutex_lock(&disable_lock); + if (disabled) + goto unlock_mutex; =20 /* try to create a simple-framebuffer device */ compatible =3D sysfb_parse_mode(si, &mode); if (compatible) { pd =3D sysfb_create_simplefb(si, &mode); if (!IS_ERR(pd)) - return 0; + goto unlock_mutex; } =20 /* if the FB is incompatible, create a legacy framebuffer device */ @@ -60,8 +131,10 @@ static __init int sysfb_init(void) name =3D "platform-framebuffer"; =20 pd =3D platform_device_alloc(name, 0); - if (!pd) - return -ENOMEM; + if (!pd) { + ret =3D -ENOMEM; + goto unlock_mutex; + } =20 sysfb_apply_efi_quirks(pd); =20 @@ -73,9 +146,11 @@ static __init int sysfb_init(void) if (ret) goto err; =20 - return 0; + goto unlock_mutex; err: platform_device_put(pd); +unlock_mutex: + mutex_unlock(&disable_lock); return ret; } =20 diff --git a/include/linux/sysfb.h b/include/linux/sysfb.h index 708152e9037b..e8c0313fac8f 100644 --- a/include/linux/sysfb.h +++ b/include/linux/sysfb.h @@ -55,6 +55,25 @@ struct efifb_dmi_info { int flags; }; =20 +#ifdef CONFIG_SYSFB + +void sysfb_disable(void); +bool sysfb_try_unregister(struct device *dev); + +#else /* CONFIG_SYSFB */ + +static inline void sysfb_disable(void) +{ + +} + +static inline bool sysfb_try_unregister(struct device *dev) +{ + return false; +} + +#endif /* CONFIG_SYSFB */ + #ifdef CONFIG_EFI =20 extern struct efifb_dmi_info efifb_dmi_list[]; --=20 2.35.1 From nobody Sun Jun 14 21:06:47 2026 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 484A7C433F5 for ; Wed, 11 May 2022 11:31:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239240AbiEKLbb (ORCPT ); Wed, 11 May 2022 07:31:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239563AbiEKLa5 (ORCPT ); Wed, 11 May 2022 07:30:57 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 804771DA44 for ; Wed, 11 May 2022 04:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652268655; 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=bKBAcv9/i+j+NmGeneztCrY9Hfc9zc/TOb5Jz8UH/dw=; b=anNttK3x9fdg73xyi/P2jnkHt8EfP84bb+mtIi8eGAR+Zj9LwtfNcIi5NRfAxlA9jYKjiq DZRmaSgunDVpLDP8L0gsE21//FdXSQNJKyaGZ1rdOWPP+Q6lf5X7jc6MnyN7wtuckQXEr+ uuEKlH4JeAX4JFg/7PY0JXGZUxxbJZ0= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-316-nyoCIZJeNeiFeYH5AR2l9Q-1; Wed, 11 May 2022 07:30:54 -0400 X-MC-Unique: nyoCIZJeNeiFeYH5AR2l9Q-1 Received: by mail-wr1-f70.google.com with SMTP id o18-20020adfcf12000000b0020cdc76ea11so740340wrj.3 for ; Wed, 11 May 2022 04:30:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bKBAcv9/i+j+NmGeneztCrY9Hfc9zc/TOb5Jz8UH/dw=; b=gM2cvfpJSbZycoa1bpjY8yhNEsWORmSnC3clb7Ig1aaN0SjJ3wXsOHWJeQRVaVe865 l1X+tqOaUspuk7IX/PpuD+MEvQKFDno5ntmQK+30wl0u1W42rw/w9k2rum8IyQ1vFQvN MjHFtTaS36OUAYJ0998dSXu6o8sgfjhEnSpn53DjFeyGTW9xmKLAsHyQsMJT4T9xeGlJ lhovnuCTDthx6tHL04V9aH5N6U3FkotGphwRJSVtsN9VjHt3rtDzj7JBAFhcUHxJIA/G 5C/Ia4IWJ40V+mXys5xLDwEMgZwMpv2q7AidF+K4XzvegJO3UeBfF4fG750LqQu+90e0 Ka8g== X-Gm-Message-State: AOAM533TouVUku3QatJ/D1eD9cme3fdvQXTKY4KVnvVEzFlqGw4hbyWJ sJKupUrho4GOw35+mLGxZs5xGkI7KVmD1yVHe+r3eDnNCpnP94Gsx8jJjRuj7gHiqLMPCU0xGoy i45rwbF+bLLy7JV8xhh04/0bXOKTk52VQgA33JW5bbdBHIOIMmrJeUswxx+41EE3IePDsH6AQhD o= X-Received: by 2002:adf:9dcc:0:b0:20a:ed44:fd48 with SMTP id q12-20020adf9dcc000000b0020aed44fd48mr22330195wre.120.1652268653208; Wed, 11 May 2022 04:30:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIJjtshhhNaPS9SyMj2B6z8Yib37iNGrRjx/XQ5eyK5wW8o/9hh+eocyK9ixZaPPybN81Bxg== X-Received: by 2002:adf:9dcc:0:b0:20a:ed44:fd48 with SMTP id q12-20020adf9dcc000000b0020aed44fd48mr22330167wre.120.1652268652888; Wed, 11 May 2022 04:30:52 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id w9-20020a5d4049000000b0020c5253d8cfsm1722625wrp.27.2022.05.11.04.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 04:30:52 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Daniel Vetter , Javier Martinez Canillas , Helge Deller , Thomas Zimmermann , Greg Kroah-Hartman Subject: [PATCH v5 3/7] fbdev: Restart conflicting fb removal loop when unregistering devices Date: Wed, 11 May 2022 13:30:39 +0200 Message-Id: <20220511113039.1252432-1-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511112438.1251024-1-javierm@redhat.com> References: <20220511112438.1251024-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Drivers that want to remove registered conflicting framebuffers prior to register their own framebuffer, calls remove_conflicting_framebuffers(). This function takes the registration_lock mutex, to prevent a races when drivers register framebuffer devices. But if a conflicting framebuffer device is found, the underlaying platform device is unregistered and this will lead to the platform driver .remove callback to be called, which in turn will call to the unregister_framebuffer() that takes the same lock. To prevent this, a struct fb_info.forced_out field was used as indication to unregister_framebuffer() whether the mutex has to be grabbed or not. A cleaner solution is to drop the lock before platform_device_unregister() so unregister_framebuffer() can take it when called from the fbdev driver, and just grab the lock again after the device has been registered and do a removal loop restart. Since the framebuffer devices will already be removed, the loop would just finish when no more conflicting framebuffers are found. Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Vetter --- (no changes since v1) drivers/video/fbdev/core/fbmem.c | 22 +++++++++++++++------- include/linux/fb.h | 1 - 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fb= mem.c index b445a7a00def..2fda5917c212 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1555,6 +1555,7 @@ static void do_remove_conflicting_framebuffers(struct= apertures_struct *a, { int i; =20 +restart_removal: /* check all firmware fbs and kick off if the base addr overlaps */ for_each_registered_fb(i) { struct apertures_struct *gen_aper; @@ -1587,12 +1588,23 @@ static void do_remove_conflicting_framebuffers(stru= ct apertures_struct *a, pr_warn("fb%d: no device set\n", i); do_unregister_framebuffer(registered_fb[i]); } else if (dev_is_platform(device)) { - registered_fb[i]->forced_out =3D true; + /* + * Drop the lock because if the device is unregistered, its + * driver will call to unregister_framebuffer(), that takes + * this lock. + */ + mutex_unlock(®istration_lock); platform_device_unregister(to_platform_device(device)); + mutex_lock(®istration_lock); } else { pr_warn("fb%d: cannot remove device\n", i); do_unregister_framebuffer(registered_fb[i]); } + /* + * Restart the removal loop now that the device has been + * unregistered and its associated framebuffer gone. + */ + goto restart_removal; } } } @@ -1899,13 +1911,9 @@ EXPORT_SYMBOL(register_framebuffer); void unregister_framebuffer(struct fb_info *fb_info) { - bool forced_out =3D fb_info->forced_out; - - if (!forced_out) - mutex_lock(®istration_lock); + mutex_lock(®istration_lock); do_unregister_framebuffer(fb_info); - if (!forced_out) - mutex_unlock(®istration_lock); + mutex_unlock(®istration_lock); } EXPORT_SYMBOL(unregister_framebuffer); =20 diff --git a/include/linux/fb.h b/include/linux/fb.h index 69c67c70fa78..bbe1e4571899 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -511,7 +511,6 @@ struct fb_info { } *apertures; =20 bool skip_vt_switch; /* no VT switch on suspend/resume required */ - bool forced_out; /* set when being removed by another driver */ }; =20 static inline struct apertures_struct *alloc_apertures(unsigned int max_nu= m) { --=20 2.35.1 From nobody Sun Jun 14 21:06:47 2026 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 0D223C433FE for ; Wed, 11 May 2022 11:31:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237514AbiEKLbr (ORCPT ); Wed, 11 May 2022 07:31:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239732AbiEKLbo (ORCPT ); Wed, 11 May 2022 07:31:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6BBFD87A25 for ; Wed, 11 May 2022 04:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652268697; 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=SX2bFHVDV/mv6k7vv6fW/ROIxkWSEMHBP8/xN2gTDGs=; b=S2oB44iSzFnrntHz0OOc1hUhexDPJKsKfIXS+3pM1idgR0jkIbO1RwKBM9+M36hw+xPm2m JQo5mtWqYw3MiMddXxHPIJVBV4NXyVyZ95I5vP55so/FRsEOe3iK6JZsss8Z0E4S1e49JE FucXcy1UDbeEXkisWOUMZ3k1Aq5lQcw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653-D3gOa_WpPGOpPSFkFLOObQ-1; Wed, 11 May 2022 07:31:36 -0400 X-MC-Unique: D3gOa_WpPGOpPSFkFLOObQ-1 Received: by mail-wm1-f71.google.com with SMTP id m124-20020a1c2682000000b00393fcd2722dso613753wmm.4 for ; Wed, 11 May 2022 04:31:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SX2bFHVDV/mv6k7vv6fW/ROIxkWSEMHBP8/xN2gTDGs=; b=qXQoEbW+BPK5yv4gxTSvGyl4f4itW2SmfqoIJ6RXDa1mcqc/7h1lHE5fC/MNQpzA9T /J8BMINe0mEmQU0l1eobvaRc+7cVgwuUthyk9iqkqVGWBynJtVjTHjTJzT9Fei4hSL7Q +22hRKteX5FMbpTDAovvJFpLYbZLcNBhVSW8H+V3KfjhKTCzk8E8UAuQxnG0H9bifyx5 xBxD9T8RYcjkhI2gd4ILZ9rHUxiLlorC4OBXsGQwunsd3H2Svs3YRG2UmgUsgmu24g/E qy1wUdnRYdPhrxNVB3lOHFT/OKWPzPn0L6poo++B0SGCBDiEZFZxjUz+sz0WNMx1bZbJ wLKQ== X-Gm-Message-State: AOAM5327HHHwsUQG+WppwHMJV8FoeZfXrEWvYGxo7NGOqEhFoeSDiYth uWDg5U0oNtNQhpCQRi+p6GOm0Tg7r1gobXgEa5Dy5k4CDDjMhyW6/UJjDhVRXpcEWWHFSRMWoQI 95whzpdV5M+cIh8/Qvgkw7RhGS1D7THkNqrfIJwbPe7zwU1tleCoDkVUaHEcGWWLt80f5Qvi1yo U= X-Received: by 2002:adf:f152:0:b0:20a:cb56:c20d with SMTP id y18-20020adff152000000b0020acb56c20dmr22007086wro.699.1652268694911; Wed, 11 May 2022 04:31:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0z1zDlwGIzZgJwvaUaNGzfZllclBP5T5A4FWJ6skTVqjs02PfSApxo9GnfjeSuNrfEEz42w== X-Received: by 2002:adf:f152:0:b0:20a:cb56:c20d with SMTP id y18-20020adff152000000b0020acb56c20dmr22007059wro.699.1652268694617; Wed, 11 May 2022 04:31:34 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id be5-20020a05600c1e8500b003942a244f54sm5611293wmb.45.2022.05.11.04.31.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 04:31:34 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Daniel Vetter , Javier Martinez Canillas , Helge Deller , Thomas Zimmermann , Greg Kroah-Hartman Subject: [PATCH v5 4/7] fbdev: Make sysfb to unregister its own registered devices Date: Wed, 11 May 2022 13:31:25 +0200 Message-Id: <20220511113125.1252660-1-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511112438.1251024-1-javierm@redhat.com> References: <20220511112438.1251024-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The platform devices registered in sysfb match with a firmware-based fbdev or DRM driver, that are used to have early graphics using framebuffers set up by the system firmware. Real DRM drivers later are probed and remove all conflicting framebuffers, leading to these platform devices for generic drivers to be unregistered. But the current solution has the problem that sysfb doesn't know when the device that registered is unregistered. This means that is not able to do any cleanup if needed since the device pointer may not be valid anymore. Not all platforms use sysfb to register the simple framebuffer devices, so an unregistration has to be forced by fbmem if sysfb_try_unregister() does not succeed at unregister the device. Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Vetter --- (no changes since v4) Changes in v4: - Drop call to sysfb_disable() in fbmem since is done in other places now. Changes in v2: - Explain in the commit message that fbmem has to unregister the device as fallback if a driver registered the device itself (Daniel Vetter). - Also explain that fallback in a comment in the code (Daniel Vetter). - Don't encode in fbmem the assumption that sysfb will always register platform devices (Daniel Vetter). - Add a FIXME comment about drivers registering devices (Daniel Vetter). drivers/video/fbdev/core/fbmem.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fb= mem.c index 2fda5917c212..9b035ef4d552 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1587,18 +1588,35 @@ static void do_remove_conflicting_framebuffers(stru= ct apertures_struct *a, if (!device) { pr_warn("fb%d: no device set\n", i); do_unregister_framebuffer(registered_fb[i]); - } else if (dev_is_platform(device)) { + } else { /* * Drop the lock because if the device is unregistered, its * driver will call to unregister_framebuffer(), that takes * this lock. */ mutex_unlock(®istration_lock); - platform_device_unregister(to_platform_device(device)); + /* + * First attempt the device to be unregistered by sysfb. + */ + if (!sysfb_try_unregister(device)) { + if (dev_is_platform(device)) { + /* + * FIXME: sysfb didn't register this device, the platform + * device was registered in other platform code. + */ + platform_device_unregister(to_platform_device(device)); + } else { + /* + * If is not a platform device, at least print a warning. A + * fix would add to make the code that registered the device + * to also unregister it. + */ + pr_warn("fb%d: cannot remove device\n", i); + /* call unregister_framebuffer() since the lock was dropped */ + unregister_framebuffer(registered_fb[i]); + } + } mutex_lock(®istration_lock); - } else { - pr_warn("fb%d: cannot remove device\n", i); - do_unregister_framebuffer(registered_fb[i]); } /* * Restart the removal loop now that the device has been --=20 2.35.1 From nobody Sun Jun 14 21:06:47 2026 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 A6444C433EF for ; Wed, 11 May 2022 11:32:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238377AbiEKLcG (ORCPT ); Wed, 11 May 2022 07:32:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238231AbiEKLcC (ORCPT ); Wed, 11 May 2022 07:32:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 281EF532DF for ; Wed, 11 May 2022 04:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652268719; 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=R2kp5jYCNfGNB7HC1VHLTEN7JTAmf+2Dpd6yPG+mBtE=; b=Ecdsr7AeyDSTqFCvjXiC0AN5cMo3nw00K/ohBrxurtf7PB9IV1UVKK9FYVXCtWvSWRbWD6 CvfsugkuU4dh/uqXECOywz3+bKFPi5qosrEsGqhQoqvXzEX6zS8NfRPyBGy5jYyEN8tyUE TVr54hEfKvG/3y4fG9eCykNhPj8W4vU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-325-keFY4OJCN66s44MnPOK7OQ-1; Wed, 11 May 2022 07:31:50 -0400 X-MC-Unique: keFY4OJCN66s44MnPOK7OQ-1 Received: by mail-wm1-f70.google.com with SMTP id 205-20020a1c02d6000000b003928cd3853aso2694355wmc.9 for ; Wed, 11 May 2022 04:31:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R2kp5jYCNfGNB7HC1VHLTEN7JTAmf+2Dpd6yPG+mBtE=; b=Z3M/ApB8aTBFhLftPDBdewOWAWMBhsRj6zVU5D99ZSw0IdsowUGD8b7gGGQVRriC+S VT7VjXEZApsSmGum3T72c3Azs4W+78eZpRQNJxe0tP4o/TFDCtkUbK3z8KnsNR3hm5u7 yFHT3AhPV6/jwXZe1iLHK0sXzXbXU5MAh0HH+x07tKU0XlZ1PORJAsowqvtDd/kdrXlL t7em4AAxUAk9FiC/n6HWJAEhljPceWpPu382bleIBN9hEN+vnBeZ/ZiSdbmNfQrLbbrY I76rofaZ20R0GeOvTdcDYQSDqBz9owZ4D/5lett2f8fmyydY9F28+A///WIF5oBKsTow co5A== X-Gm-Message-State: AOAM532vkAhMzkKMoBbidbVbxUapNvNV/QXnAJxYDdB7pxZAGxhtkaFC MRt/dmVAQdUe8FAdpxr8THWj1/UNmdrzumi+ZviJcx86GSJPkA/gxIVjwC51BsZsQ0yrVOaxs3Z fcMUb7wisZsU3hn5r6+C1qHhnGEnkw0T4yoz1aT1tfQHEoe18QBruH/YLkhM3jqkosH7pXmTMDh s= X-Received: by 2002:a1c:4d10:0:b0:394:788a:24d7 with SMTP id o16-20020a1c4d10000000b00394788a24d7mr4323377wmh.113.1652268709343; Wed, 11 May 2022 04:31:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVdOZ6jj+GkTcslb2h+9g+NLK3aby//uMM8giiBszt74nPvf6lrNJh9rn58+o3dxXtHD+dwg== X-Received: by 2002:a1c:4d10:0:b0:394:788a:24d7 with SMTP id o16-20020a1c4d10000000b00394788a24d7mr4323344wmh.113.1652268709014; Wed, 11 May 2022 04:31:49 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id e8-20020a5d5308000000b0020c5253d8c2sm1450213wrv.14.2022.05.11.04.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 04:31:48 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Daniel Vetter , Javier Martinez Canillas , Helge Deller , Thomas Zimmermann , Greg Kroah-Hartman Subject: [PATCH v5 5/7] fbdev: Disable sysfb device registration when removing conflicting FBs Date: Wed, 11 May 2022 13:31:44 +0200 Message-Id: <20220511113144.1252729-1-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511112438.1251024-1-javierm@redhat.com> References: <20220511112438.1251024-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The platform devices registered by sysfb match with firmware-based DRM or fbdev drivers, that are used to have early graphics using a framebuffer provided by the system firmware. DRM or fbdev drivers later are probed and remove all conflicting framebuffe= rs, leading to these platform devices for generic drivers to be unregistered. But the current solution has a race, since the sysfb_init() function could be called after a DRM or fbdev driver is probed and request to unregister the devices for drivers with conflicting framebuffes. To prevent this, disable any future sysfb platform device registration by calling sysfb_disable(), if a driver requests to remove the conflicting framebuffers. Suggested-by: Daniel Vetter Signed-off-by: Javier Martinez Canillas Reviewed-by: Daniel Vetter --- Changes in v5: - Move the sysfb_disable() call at conflicting framebuffers again to avoid the need of a DRIVER_FIRMWARE capability flag. - Add Daniel Vetter's Reviewed-by tag again since reverted to the old patch that he already reviewed in v2. Changes in v3: - Call sysfb_disable() when a DRM dev and a fbdev are registered rather than when conflicting framebuffers are removed (Thomas Zimmermann). - Call sysfb_disable() when a fbdev framebuffer is registered rather than when conflicting framebuffers are removed (Thomas Zimmermann). - Drop Daniel Vetter's Reviewed-by tag since patch changed a lot. Changes in v2: - Explain in the commit message that fbmem has to unregister the device as fallback if a driver registered the device itself (Daniel Vetter). - Also explain that fallback in a comment in the code (Daniel Vetter). - Don't encode in fbmem the assumption that sysfb will always register platform devices (Daniel Vetter). - Add a FIXME comment about drivers registering devices (Daniel Vetter). drivers/video/fbdev/core/fbmem.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fb= mem.c index 9b035ef4d552..265efa189bcc 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1789,6 +1789,17 @@ int remove_conflicting_framebuffers(struct apertures= _struct *a, if (do_free) kfree(a); =20 + /* + * If a driver asked to unregister a platform device registered by + * sysfb, then can be assumed that this is a driver for a display + * that is set up by the system firmware and has a generic driver. + * + * Drivers for devices that don't have a generic driver will never + * ask for this, so let's assume that a real driver for the display + * was already probed and prevent sysfb to register devices later. + */ + sysfb_disable(); + return 0; } EXPORT_SYMBOL(remove_conflicting_framebuffers); --=20 2.35.1 From nobody Sun Jun 14 21:06:47 2026 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 E423BC433EF for ; Wed, 11 May 2022 11:32:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239144AbiEKLci (ORCPT ); Wed, 11 May 2022 07:32:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240799AbiEKLc3 (ORCPT ); Wed, 11 May 2022 07:32:29 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 923F323E295 for ; Wed, 11 May 2022 04:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652268743; 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=UDplaZMb5YseJ+Hq/qs3ip7VsbbgryHldJFcbzukwP8=; b=hoDQq/OPlPA1jIbWxLpQn1eaMCxeQk0RSlIkcJZiZ0i1/bLzwG8WTGnBA/CABRbdFhK/gN I60tCXvY26uk2UjfG/gnDuGI27/SRafC2SVLITBo7+M2GVBt3xZcqB/aRY9wuflFTBOk7r 8T3xUgLXEozVJLsbmvoQHQNjjSTgdCU= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-325-4TGt3YBBPj2bBo33graGqg-1; Wed, 11 May 2022 07:32:22 -0400 X-MC-Unique: 4TGt3YBBPj2bBo33graGqg-1 Received: by mail-wr1-f72.google.com with SMTP id u17-20020a056000161100b0020cda98f292so718247wrb.21 for ; Wed, 11 May 2022 04:32:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UDplaZMb5YseJ+Hq/qs3ip7VsbbgryHldJFcbzukwP8=; b=CizHwYKrVS2P32kImrfk/P3/mJ1/otfEOu4wr8ljMeM2QxXahqBDlgB5u4AU65SlZ6 1+YhEclIBpxAfUcXBWxHee7jrUNggLW5FANGDzqBr/KCMDDh4d+ek6+RURtgDsHl13mC LLSevL84apK65sid6i4MV3TFCIzJGyZU8+0CkGfE7WdsSj2ZNwL0cY8dvAdp9wqchSal u7k8YCOrKWxL4eG2VU6Nk3Wei1P5rincSQjW9GmvlJEe8B8FtV49GqPtnE7/qLtcv0z/ mKCa9glPQ3XWVqEuqz1darQHXVQZP1fyR5+jAjtDHqWsqKZkE2VEigEdUvZ/NVPkIDH7 YF1Q== X-Gm-Message-State: AOAM531AxWD7g6jmLcaozrKwmQsFhUi7ZyrUP5rIRaw/ldkvcBfZmdrh YFz6Sw6A8ILoZmLI8m6W/fIGV0/dvvaA14s7pWvXoBY6D3PAPTKWTmwLuc/B9/uf4crgjjbJJGL UFW40tfLDwhDkose6J8wRuBfqJKwa+mv8EXyN7yTTUPfw54r51ONneWhUDZTY1eqF2wX8b5WYdk 0= X-Received: by 2002:a05:6000:1d8b:b0:20c:54e6:1659 with SMTP id bk11-20020a0560001d8b00b0020c54e61659mr22002291wrb.169.1652268741265; Wed, 11 May 2022 04:32:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8DOa4eVy/j4OxWjmKfDXFScY2hy71AEkR7bJehfJjo+JROKXYZWV1lJqXARoz2/Z0HXw3aQ== X-Received: by 2002:a05:6000:1d8b:b0:20c:54e6:1659 with SMTP id bk11-20020a0560001d8b00b0020c54e61659mr22002251wrb.169.1652268740906; Wed, 11 May 2022 04:32:20 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id w12-20020adfde8c000000b0020c5253d8dfsm1476857wrl.43.2022.05.11.04.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 04:32:20 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Daniel Vetter , Javier Martinez Canillas , Helge Deller , Thomas Zimmermann , Greg Kroah-Hartman , Zack Rusin , Hans de Goede , Ilya Trukhanov , Daniel Vetter , Peter Jones Subject: [PATCH v5 6/7] Revert "fbdev: Prevent probing generic drivers if a FB is already registered" Date: Wed, 11 May 2022 13:32:04 +0200 Message-Id: <20220511113204.1252828-1-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511112438.1251024-1-javierm@redhat.com> References: <20220511112438.1251024-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Daniel Vetter This reverts commit fb561bf9abde49f7e00fdbf9ed2ccf2d86cac8ee. With commit 27599aacbaefcbf2af7b06b0029459bbf682000d Author: Thomas Zimmermann Date: Tue Jan 25 10:12:18 2022 +0100 fbdev: Hot-unplug firmware fb devices on forced removal this should be fixed properly and we can remove this somewhat hackish check here (e.g. this won't catch drm drivers if fbdev emulation isn't enabled). Cc: Thomas Zimmermann Cc: Zack Rusin Cc: Javier Martinez Canillas Cc: Zack Rusin Cc: Hans de Goede Cc: Ilya Trukhanov Signed-off-by: Daniel Vetter Signed-off-by: Daniel Vetter Reviewed-by: Javier Martinez Canillas Cc: Peter Jones Cc: linux-fbdev@vger.kernel.org Signed-off-by: Javier Martinez Canillas --- (no changes since v1) drivers/video/fbdev/efifb.c | 11 ----------- drivers/video/fbdev/simplefb.c | 11 ----------- 2 files changed, 22 deletions(-) diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c index ea42ba6445b2..edca3703b964 100644 --- a/drivers/video/fbdev/efifb.c +++ b/drivers/video/fbdev/efifb.c @@ -351,17 +351,6 @@ static int efifb_probe(struct platform_device *dev) char *option =3D NULL; efi_memory_desc_t md; =20 - /* - * Generic drivers must not be registered if a framebuffer exists. - * If a native driver was probed, the display hardware was already - * taken and attempting to use the system framebuffer is dangerous. - */ - if (num_registered_fb > 0) { - dev_err(&dev->dev, - "efifb: a framebuffer is already registered\n"); - return -EINVAL; - } - if (screen_info.orig_video_isVGA !=3D VIDEO_TYPE_EFI || pci_dev_disabled) return -ENODEV; =20 diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c index 94fc9c6d0411..0ef41173325a 100644 --- a/drivers/video/fbdev/simplefb.c +++ b/drivers/video/fbdev/simplefb.c @@ -413,17 +413,6 @@ static int simplefb_probe(struct platform_device *pdev) struct simplefb_par *par; struct resource *res, *mem; =20 - /* - * Generic drivers must not be registered if a framebuffer exists. - * If a native driver was probed, the display hardware was already - * taken and attempting to use the system framebuffer is dangerous. - */ - if (num_registered_fb > 0) { - dev_err(&pdev->dev, - "simplefb: a framebuffer is already registered\n"); - return -EINVAL; - } - if (fb_get_options("simplefb", NULL)) return -ENODEV; =20 --=20 2.35.1 From nobody Sun Jun 14 21:06:47 2026 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 E816CC433F5 for ; Wed, 11 May 2022 11:32:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239896AbiEKLcv (ORCPT ); Wed, 11 May 2022 07:32:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239318AbiEKLck (ORCPT ); Wed, 11 May 2022 07:32:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0442A41322 for ; Wed, 11 May 2022 04:32:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652268758; 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=j9CH2v0YXJ3HjUK6dIstavUpY+IdJA0p7lKZyzF8giE=; b=QljuTuDGkoTfJn2Q/jAgjWR9qIs1l0rRUGFoDuz9tjiWtcjjOHSq1Rs/syy3L6hX9k7ygA xUDxJAjb1LVjz3oxU68YKeOH6C2ahPiSuPu5xFHxSqP3O3xZeB3p/Euv+wLB0qC9tCWCoj EPtk06Z7PG85X4DhGb9RsTwlGZtZUuQ= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-563-RqNKb-q0NVuw6I6LvF1tfA-1; Wed, 11 May 2022 07:32:37 -0400 X-MC-Unique: RqNKb-q0NVuw6I6LvF1tfA-1 Received: by mail-wm1-f69.google.com with SMTP id n26-20020a1c721a000000b003941ea1ced7so609740wmc.7 for ; Wed, 11 May 2022 04:32:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j9CH2v0YXJ3HjUK6dIstavUpY+IdJA0p7lKZyzF8giE=; b=l7l+TEIqUWfLmGypAfPCksKbuisVr2to6aq2CBtrx+hwixqAHPNiviw6jm391xov1q APcISlzNRDk5SbQ1/qrPIIVPh1IiHBddmoDe6SgCILWgmXAb4m8Brx9EmRJMPl0QSqGw 4Y1FmMnwVwvUEdAi1TQ5MMSCnuZhoaeAVezMLOQ8o20tauHw3lhaC26mSKXvlNVla8d0 ppEayOh+dQnuQu3bAgzRscAIoYZxSzyoAhx5GUD+jlgfFssRpfOwLnkG7DTy9tIb4WwY 6+8gr4vkRrtdylhNY0xHl665Tzbtq7Qf3xPjCQiyMdXOcVdt3Jv4F56scnHTZytpZI6K kRPw== X-Gm-Message-State: AOAM533DYyNpHEfuWv+5woe4hbzGj8RMQhtGyMJGhJ9PIzMFHkrFaiW2 MwrKNIIzqHeW6hTpaHhESIyQ2ky0D4dPvb5MOyqT/3nrg6/qzcM9A/qp0qbXaERXfmh1/Qq5cWk iYgtuCan7wvJm5z45yXJHnRMrzfYImcA+AQpL00H0hjwB3E87tQ8dMFtd604oRXGx2eR1Xgz3k/ c= X-Received: by 2002:adf:f747:0:b0:20a:d30a:5f08 with SMTP id z7-20020adff747000000b0020ad30a5f08mr22334028wrp.278.1652268755838; Wed, 11 May 2022 04:32:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgrtdXH49XbKTYGY6jvwa/LsalnhjTRPZOQcdgbrMeYtoBsK3sJMoM3gRNyeWCwdLsXBrWuA== X-Received: by 2002:adf:f747:0:b0:20a:d30a:5f08 with SMTP id z7-20020adff747000000b0020ad30a5f08mr22333989wrp.278.1652268755534; Wed, 11 May 2022 04:32:35 -0700 (PDT) Received: from minerva.home (205.pool92-176-231.dynamic.orange.es. [92.176.231.205]) by smtp.gmail.com with ESMTPSA id bd6-20020a05600c1f0600b00394615cf468sm4928533wmb.28.2022.05.11.04.32.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 04:32:35 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Daniel Vetter , Javier Martinez Canillas , Helge Deller , Thomas Zimmermann , Greg Kroah-Hartman , kernel test robot , Jens Frederich , Jon Nettleton , linux-staging@lists.linux.dev, Daniel Vetter , Daniel Vetter , Matthew Wilcox , Sam Ravnborg , Tetsuo Handa , Zhen Lei , Alex Deucher , Xiyu Yang , Zheyu Ma , Guenter Roeck Subject: [PATCH v5 7/7] fbdev: Make registered_fb[] private to fbmem.c Date: Wed, 11 May 2022 13:32:30 +0200 Message-Id: <20220511113230.1252910-1-javierm@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511112438.1251024-1-javierm@redhat.com> References: <20220511112438.1251024-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Daniel Vetter Well except when the olpc dcon fbdev driver is enabled, that thing digs around in there in rather unfixable ways. Cc oldc_dcon maintainers as fyi. v2: I typoed the config name (0day) Cc: kernel test robot Cc: Jens Frederich Cc: Jon Nettleton Cc: Greg Kroah-Hartman Cc: linux-staging@lists.linux.dev Signed-off-by: Daniel Vetter Signed-off-by: Daniel Vetter Reviewed-by: Javier Martinez Canillas Cc: Daniel Vetter Cc: Helge Deller Cc: Matthew Wilcox Cc: Sam Ravnborg Cc: Tetsuo Handa Cc: Zhen Lei Cc: Alex Deucher Cc: Xiyu Yang Cc: linux-fbdev@vger.kernel.org Cc: Zheyu Ma Cc: Guenter Roeck Signed-off-by: Javier Martinez Canillas --- (no changes since v1) drivers/video/fbdev/core/fbmem.c | 8 ++++++-- include/linux/fb.h | 7 +++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fb= mem.c index 265efa189bcc..6cab5f4c1fb3 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -50,10 +50,14 @@ static DEFINE_MUTEX(registration_lock); =20 struct fb_info *registered_fb[FB_MAX] __read_mostly; -EXPORT_SYMBOL(registered_fb); - int num_registered_fb __read_mostly; +#if IS_ENABLED(CONFIG_FB_OLPC_DCON) +EXPORT_SYMBOL(registered_fb); EXPORT_SYMBOL(num_registered_fb); +#endif +#define for_each_registered_fb(i) \ + for (i =3D 0; i < FB_MAX; i++) \ + if (!registered_fb[i]) {} else =20 bool fb_center_logo __read_mostly; =20 diff --git a/include/linux/fb.h b/include/linux/fb.h index bbe1e4571899..c563e24b6293 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -632,16 +632,15 @@ extern int fb_get_color_depth(struct fb_var_screeninf= o *var, extern int fb_get_options(const char *name, char **option); extern int fb_new_modelist(struct fb_info *info); =20 +#if IS_ENABLED(CONFIG_FB_OLPC_DCON) extern struct fb_info *registered_fb[FB_MAX]; + extern int num_registered_fb; +#endif extern bool fb_center_logo; extern int fb_logo_count; extern struct class *fb_class; =20 -#define for_each_registered_fb(i) \ - for (i =3D 0; i < FB_MAX; i++) \ - if (!registered_fb[i]) {} else - static inline void lock_fb_info(struct fb_info *info) { mutex_lock(&info->lock); --=20 2.35.1