Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4650909iob; Sun, 8 May 2022 20:37:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSVNpcmvnvGqVTbyzVgXKeg4WOwB+2aPocFYXGfSdiMBhq8jbIBbrs7PLT8ObslE+tEnit X-Received: by 2002:a17:902:e54b:b0:15e:c88e:b8b with SMTP id n11-20020a170902e54b00b0015ec88e0b8bmr14493831plf.123.1652067439820; Sun, 08 May 2022 20:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652067439; cv=none; d=google.com; s=arc-20160816; b=OmHP/TtURyusgwNo9e5uDJe7/E/1dV6g4/mI2QdEQJRBPckDfk4+h7GydZi4X24sEH mzlLOjedcfXJJk6mCwiK7bwmusQA5LyQfVP18UvEA6aWR+SDmk5iJwHM9uYJXYLylYVh KQ5MC1fQc7uMZLHY/JicrDFNRo9NAb+vft67O6vlpXReGOUVDB2ECowX6vH00gb/JoLr IDH5WdNa9gfexVhHP2IoA11WtrZqR8V4wiWZV7+eINX0qb1SU7jLRmJQUtreol/iG98/ 0aNeCnMYh+27AkCfsVpSRRjJn6QJ4lxBkIzLtQhKLeqKrL7Ioq64xSePA8bul2s7jmJM BDng== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=+/G6ZNFnePPGvWMUDzG2GW5fKXkJFmu80NjhJfCI3Eo=; b=uczXssHCBGmObS+ReQQRQerJis1LkZKJHrFcgOMnVHdyHND3cJYkPl6zNYaa3Kk6iI Cl4s/Jes04ritkABWgNDQYykGK3PrCQ8v2KQSCr1311KrLVeDi+rodN8gv6SxsClZuDd hWz9IdeWlZnfKaQn/JGyvd3EDpAeFXlpPjOzwuci+pa3Q+dtH/Wb/4JPKpBW059CR9KB pXA+TJUN23+C2NbObUbJMVK6pgd41NQkpAaY9KV8r0wCGrGBKuveuzjsEzGdCehiArET esf25ocO/2rFwfdBhlMuaGmroQlmhtdMfSjyZ6TfBPnCUnb+8cCrOQjEc5AUkgX4Y6gA b+WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=j4PWvQ+K; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y4-20020a170902864400b00153b2d164e0si9792478plt.232.2022.05.08.20.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 20:37:19 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=j4PWvQ+K; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B2122887B8; Sun, 8 May 2022 20:35:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442864AbiEFPdP (ORCPT + 99 others); Fri, 6 May 2022 11:33:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442857AbiEFPcm (ORCPT ); Fri, 6 May 2022 11:32:42 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FBED6D1BE; Fri, 6 May 2022 08:28:58 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id A73061F46AFF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1651850936; bh=36GvcdSB/pf30ZP9RtiH75vOy9s3MxY1/p1dsQRCX00=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=j4PWvQ+KBo4etBUy0FbW/p7HgcgQKy32GPpN6vjoThFzS1+RGmcEmteL2lFd/bVBT AknDobZqw5O4tK0BEn0jni1jZ1Y8w81F2B2OWV3FF7FrvJT7Y7bQUJJnPaIFMtFHn0 reKyy4wB8Xbrn+puiesHuayZefx8p/F1dSlMuhF2rKVyTgZW8aR+4U0aGftdyXJz/m 3XXXthcoiK77QOv1j4fPfZKN7nj7ru6E9U9WMrpUGrEUEDI35YvC+Jqrddc9aKOX41 7IjiAmfXml1CMKMBOqZ8jj6SNKFVNBjY8WGAT41UAfMzpF3zkqjQi1yQ9WbfUjIX3x 36sMhgh0cdItw== Message-ID: <296e6f6f-e96d-2db1-77b9-288dc47d1b98@collabora.com> Date: Fri, 6 May 2022 18:28:49 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v7 04/20] kernel: Add combined power-off+restart handler call chain API Content-Language: en-US To: "Rafael J. Wysocki" Cc: Thierry Reding , Jonathan Hunter , Russell King , Catalin Marinas , Will Deacon , Guo Ren , Geert Uytterhoeven , Greg Ungerer , Joshua Thompson , Thomas Bogendoerfer , Sebastian Reichel , Linus Walleij , Philipp Zabel , Greentime Hu , Vincent Chen , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , Yoshinori Sato , Rich Felker , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , the arch/x86 maintainers , "H. Peter Anvin" , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Len Brown , Santosh Shilimkar , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Pavel Machek , Lee Jones , Andrew Morton , Guenter Roeck , Daniel Lezcano , Andy Shevchenko , Ulf Hansson , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Linux Kernel Mailing List , linux-csky@vger.kernel.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, "open list:BROADCOM NVRAM DRIVER" , linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, Linux-sh list , xen-devel@lists.xenproject.org, ACPI Devel Maling List , Linux PM , linux-tegra References: <20220411233832.391817-1-dmitry.osipenko@collabora.com> <20220411233832.391817-5-dmitry.osipenko@collabora.com> <990621e7-9f8a-8b4a-02ec-fd6c1e1f48ff@collabora.com> From: Dmitry Osipenko In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=unavailable 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 On 4/20/22 21:47, Rafael J. Wysocki wrote: >>>> + spin_unlock(&platform_power_off_lock); >>>> + >>>> + if (ret) >>>> + return ret; >>>> + >>>> + ret = register_power_off_handler(&priv->power_off_nb); >>>> + if (ret) >>>> + priv->platform_power_off_cb = NULL; >>>> + >>>> + return ret; >>>> +} >>>> +EXPORT_SYMBOL_GPL(register_platform_power_off); >>>> + >>>> +/** >>>> + * unregister_platform_power_off - Unregister platform-level power-off callback >>>> + * @power_off: Power-off callback >>>> + * >>>> + * Unregisters previously registered platform power-off callback. >>>> + * >>>> + * Returns zero on success, or error code on failure. >>>> + */ >>>> +int unregister_platform_power_off(void (*power_off)(void)) >>>> +{ >>>> + struct sys_off_handler_private_data *priv; >>>> + int ret; >>>> + >>>> + priv = sys_off_handler_private_data(&platform_power_off_handler); >>>> + >>>> + if (priv->platform_power_off_cb != power_off) >>>> + return -EINVAL; >>>> + >>>> + ret = unregister_power_off_handler(&priv->power_off_nb); >>>> + priv->platform_power_off_cb = NULL; >>>> + >>>> + return ret; >>>> +} >>>> +EXPORT_SYMBOL_GPL(unregister_platform_power_off); >>>> + >>>> +/** >>>> + * do_kernel_power_off - Execute kernel power-off handler call chain >>>> + * >>>> + * Calls functions registered with register_power_off_handler. >>>> + * >>>> + * Expected to be called as last step of the power-off sequence. >>>> + * >>>> + * Powers off the system immediately if a power-off handler function has >>>> + * been registered. Otherwise does nothing. >>>> + */ >>>> +void do_kernel_power_off(void) >>>> +{ >>>> + /* legacy pm_power_off() is unchained and has highest priority */ >>>> + if (pm_power_off && pm_power_off != dummy_pm_power_off) >>>> + return pm_power_off(); >>>> + >>>> + blocking_notifier_call_chain(&power_off_handler_list, POWEROFF_NORMAL, >>>> + NULL); >>>> +} >>>> + >>>> +static void do_kernel_power_off_prepare(void) >>>> +{ >>>> + /* legacy pm_power_off_prepare() is unchained and has highest priority */ >>>> + if (pm_power_off_prepare) >>>> + return pm_power_off_prepare(); >>>> + >>>> + blocking_notifier_call_chain(&power_off_handler_list, POWEROFF_PREPARE, >>>> + NULL); >>>> +} >>>> + >>>> /** >>>> * kernel_power_off - power_off the system >>>> * >>>> @@ -304,8 +893,7 @@ EXPORT_SYMBOL_GPL(kernel_halt); >>>> void kernel_power_off(void) >>>> { >>>> kernel_shutdown_prepare(SYSTEM_POWER_OFF); >>>> - if (pm_power_off_prepare) >>>> - pm_power_off_prepare(); >>>> + do_kernel_power_off_prepare(); >>>> migrate_to_reboot_cpu(); >>>> syscore_shutdown(); >>>> pr_emerg("Power down\n"); >>>> @@ -314,6 +902,16 @@ void kernel_power_off(void) >>>> } >>>> EXPORT_SYMBOL_GPL(kernel_power_off); >>>> >>>> +bool kernel_can_power_off(void) >>>> +{ >>>> + if (!pm_power_off && >>>> + blocking_notifier_call_chain_is_empty(&power_off_handler_list)) >>>> + return false; >>>> + >>>> + return true; >>> return pm_power_off || >>> blocking_notifier_call_chain_is_empty(&power_off_handler_list); >> Thank you for the thorough review! > You're very welcome! Thanks again for taking a look at the patches. I don't have strong preferences about the names and etc, so I'll update it all in v8 like you suggested. -- Best regards, Dmitry