Re: [PATCH v7 04/20] kernel: Add combined power-off+restart handler call chain API
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: "Rafael J. Wysocki" <rafael@xxxxxxxxxx>
- Subject: Re: [PATCH v7 04/20] kernel: Add combined power-off+restart handler call chain API
- From: Dmitry Osipenko <dmitry.osipenko@xxxxxxxxxxxxx>
- Date: Fri, 6 May 2022 18:28:49 +0300
- Cc: Thierry Reding <thierry.reding@xxxxxxxxx>, Jonathan Hunter <jonathanh@xxxxxxxxxx>, Russell King <linux@xxxxxxxxxxxxxxx>, Catalin Marinas <catalin.marinas@xxxxxxx>, Will Deacon <will@xxxxxxxxxx>, Guo Ren <guoren@xxxxxxxxxx>, Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>, Greg Ungerer <gerg@xxxxxxxxxxxxxx>, Joshua Thompson <funaho@xxxxxxxxx>, Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>, Sebastian Reichel <sre@xxxxxxxxxx>, Linus Walleij <linus.walleij@xxxxxxxxxx>, Philipp Zabel <p.zabel@xxxxxxxxxxxxxx>, Greentime Hu <green.hu@xxxxxxxxx>, Vincent Chen <deanbo422@xxxxxxxxx>, "James E.J. Bottomley" <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx>, Helge Deller <deller@xxxxxx>, Michael Ellerman <mpe@xxxxxxxxxxxxxx>, Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>, Paul Mackerras <paulus@xxxxxxxxx>, Paul Walmsley <paul.walmsley@xxxxxxxxxx>, Palmer Dabbelt <palmer@xxxxxxxxxxx>, Albert Ou <aou@xxxxxxxxxxxxxxxxx>, Yoshinori Sato <ysato@xxxxxxxxxxxxx>, Rich Felker <dalias@xxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, the arch/x86 maintainers <x86@xxxxxxxxxx>, "H. Peter Anvin" <hpa@xxxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Len Brown <lenb@xxxxxxxxxx>, Santosh Shilimkar <ssantosh@xxxxxxxxxx>, Krzysztof Kozlowski <krzk@xxxxxxxxxx>, Liam Girdwood <lgirdwood@xxxxxxxxx>, Mark Brown <broonie@xxxxxxxxxx>, Pavel Machek <pavel@xxxxxx>, Lee Jones <lee.jones@xxxxxxxxxx>, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Guenter Roeck <linux@xxxxxxxxxxxx>, Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>, Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>, Ulf Hansson <ulf.hansson@xxxxxxxxxx>, Michał Mirosław <mirq-linux@xxxxxxxxxxxx>, Linux Kernel Mailing List <linux-kernel@xxxxxxxxxxxxxxx>, linux-csky@xxxxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-m68k@xxxxxxxxxxxxxxx, "open list:BROADCOM NVRAM DRIVER" <linux-mips@xxxxxxxxxxxxxxx>, linux-parisc@xxxxxxxxxxxxxxx, linux-riscv@xxxxxxxxxxxxxxxxxxx, Linux-sh list <linux-sh@xxxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, ACPI Devel Maling List <linux-acpi@xxxxxxxxxxxxxxx>, Linux PM <linux-pm@xxxxxxxxxxxxxxx>, linux-tegra <linux-tegra@xxxxxxxxxxxxxxx>
- In-reply-to: <CAJZ5v0jxXtwot0qpib4UG8Tz8Hd1dEbgo58tEdPFboU8xwKHNw@mail.gmail.com>
- References: <20220411233832.391817-1-dmitry.osipenko@collabora.com> <20220411233832.391817-5-dmitry.osipenko@collabora.com> <CAJZ5v0gnTSoeNP+QXwrZ45FQY4howVkJMuCjM=j+_-2BngJdQg@mail.gmail.com> <990621e7-9f8a-8b4a-02ec-fd6c1e1f48ff@collabora.com> <CAJZ5v0jxXtwot0qpib4UG8Tz8Hd1dEbgo58tEdPFboU8xwKHNw@mail.gmail.com>
- User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0
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
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]