From patchwork Tue Oct 7 05:28:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 397053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3A657140082 for ; Tue, 7 Oct 2014 16:41:08 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752965AbaJGFlE (ORCPT ); Tue, 7 Oct 2014 01:41:04 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:40749 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753602AbaJGFaL (ORCPT ); Tue, 7 Oct 2014 01:30:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=08yvG6RUxyn5keR1ylHDkoqXg0J27xNC2kdG+fz9fJk=; b=mvKogzSxyL8keg/lZ3dCT2R058KLzzoOVpIzOU94Cc6hoBQc8BVkt190bTfQFathTJLnF6vHvC2KdhyJFFMZ5+4Q4vMS/+kuZH2FJubY8oUX0qeM3GLogisdFKhaeGu9q/p1L8QjXjXJtW/4mdkdZ2XaoJSNaR2K9l0yiWGzGAc=; Received: from mailnull by bh-25.webhostbox.net with sa-checked (Exim 4.82) (envelope-from ) id 1XbNLe-002e6U-Ij for linux-tegra@vger.kernel.org; Tue, 07 Oct 2014 05:30:10 +0000 Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:32914 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.82) (envelope-from ) id 1XbNLA-002bVt-Uq; Tue, 07 Oct 2014 05:29:41 +0000 From: Guenter Roeck To: linux-kernel@vger.kernel.org Cc: adi-buildroot-devel@lists.sourceforge.net, devel@driverdev.osuosl.org, devicetree@vger.kernel.org, lguest@lists.ozlabs.org, linux-acpi@vger.kernel.org, linux-alpha@vger.kernel.org, linux-am33-list@redhat.com, linux-cris-kernel@axis.com, linux-efi@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-m32r-ja@ml.linux-m32r.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-tegra@vger.kernel.org, linux-xtensa@linux-xtensa.org, openipmi-developer@lists.sourceforge.net, user-mode-linux-devel@lists.sourceforge.net, linux-arm-kernel@lists.infradead.org, linux-c6x-dev@linux-c6x.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-metag@vger.kernel.org, linux-mips@linux-mips.org, linux-parisc@vger.kernel.org, linux-pm@vger.kernel.org, linux-sh@vger.kernel.org, xen-devel@lists.xenproject.org, Guenter Roeck , Corey Minyard Subject: [PATCH 19/44] ipmi: Register with kernel poweroff handler Date: Mon, 6 Oct 2014 22:28:21 -0700 Message-Id: <1412659726-29957-20-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412659726-29957-1-git-send-email-linux@roeck-us.net> References: <1412659726-29957-1-git-send-email-linux@roeck-us.net> X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=2.8 X-Spam-Checker-Version: spamc_ctasd client on localost X-Spam-Level: X-Spam-Status: No, score=0.0 required=50.0 tests=SpamClass_Unknown, VirusClass_Unknown autolearn=disabled version=1.0.0 X-CTCH-PVer: 0000001 X-CTCH-Spam: Unknown X-CTCH-VOD: Unknown X-CTCH-Flags: 0 X-CTCH-RefID: str=0001.0A020208.54337A62.0104, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-Score: 0.000 X-CTCH-ScoreCust: 0.000 X-CTCH-Rules: X-CTCH-SenderID: linux@roeck-us.net X-CTCH-SenderID-Flags: 0 X-CTCH-SenderID-TotalMessages: 454 X-CTCH-SenderID-TotalSpam: 0 X-CTCH-SenderID-TotalSuspected: 0 X-CTCH-SenderID-TotalConfirmed: 0 X-CTCH-SenderID-TotalBulk: 0 X-CTCH-SenderID-TotalVirus: 0 X-CTCH-SenderID-TotalRecipients: 0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: mailgid no entry from get_relayhosts_entry X-Source: X-Source-Args: X-Source-Dir: Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Register with kernel poweroff handler instead of setting pm_power_off directly. Register with a high priority value of 192 to reflect that the original code overwrites pm_power_off unconditionally. Register poweroff handler after the ipmi system is ready, and unregister it prior to cleanup. This avoids having to check for the ready variable in the poweroff callback. Cc: Corey Minyard Signed-off-by: Guenter Roeck --- drivers/char/ipmi/ipmi_poweroff.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c index 9f2e3be..a942a41 100644 --- a/drivers/char/ipmi/ipmi_poweroff.c +++ b/drivers/char/ipmi/ipmi_poweroff.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -63,9 +64,6 @@ static ipmi_user_t ipmi_user; static int ipmi_ifnum; static void (*specific_poweroff_func)(ipmi_user_t user); -/* Holds the old poweroff function so we can restore it on removal. */ -static void (*old_poweroff_func)(void); - static int set_param_ifnum(const char *val, struct kernel_param *kp) { int rv = param_set_int(val, kp); @@ -544,15 +542,20 @@ static struct poweroff_function poweroff_functions[] = { /* Called on a powerdown request. */ -static void ipmi_poweroff_function(void) +static int ipmi_poweroff_function(struct notifier_block *this, + unsigned long unused1, void *unused2) { - if (!ready) - return; - /* Use run-to-completion mode, since interrupts may be off. */ specific_poweroff_func(ipmi_user); + + return NOTIFY_DONE; } +static struct notifier_block ipmi_poweroff_nb = { + .notifier_call = ipmi_poweroff_function, + .priority = 192, +}; + /* Wait for an IPMI interface to be installed, the first one installed will be grabbed by this code and used to perform the powerdown. */ static void ipmi_po_new_smi(int if_num, struct device *device) @@ -631,9 +634,12 @@ static void ipmi_po_new_smi(int if_num, struct device *device) printk(KERN_INFO PFX "Found a %s style poweroff function\n", poweroff_functions[i].platform_type); specific_poweroff_func = poweroff_functions[i].poweroff_func; - old_poweroff_func = pm_power_off; - pm_power_off = ipmi_poweroff_function; + ready = 1; + + rv = register_poweroff_handler(&ipmi_poweroff_nb); + if (rv) + pr_err(PFX "failed to register poweroff handler\n"); } static void ipmi_po_smi_gone(int if_num) @@ -644,9 +650,10 @@ static void ipmi_po_smi_gone(int if_num) if (ipmi_ifnum != if_num) return; + unregister_poweroff_handler(&ipmi_poweroff_nb); + ready = 0; ipmi_destroy_user(ipmi_user); - pm_power_off = old_poweroff_func; } static struct ipmi_smi_watcher smi_watcher = { @@ -732,12 +739,13 @@ static void __exit ipmi_poweroff_cleanup(void) ipmi_smi_watcher_unregister(&smi_watcher); + unregister_poweroff_handler(&ipmi_poweroff_nb); + if (ready) { rv = ipmi_destroy_user(ipmi_user); if (rv) printk(KERN_ERR PFX "could not cleanup the IPMI" " user: 0x%x\n", rv); - pm_power_off = old_poweroff_func; } } module_exit(ipmi_poweroff_cleanup);