1.\" $NetBSD: powerhook_establish.9,v 1.11 2009/05/15 06:40:15 wiz Exp $ 2.\" 3.\" Copyright (c) 1999 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Lennart Augustsson. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd May 14, 2009 31.Dt POWERHOOK_ESTABLISH 9 32.Os 33.Sh NAME 34.Nm powerhook_establish , 35.Nm powerhook_disestablish 36.Nd add or remove a power change hook 37.Sh SYNOPSIS 38.Ft void * 39.Fn powerhook_establish "const char *name" "void (*fn)(int why, void *a)" \ 40"void *arg" 41.Ft void 42.Fn powerhook_disestablish "void *cookie" 43.Sh DESCRIPTION 44.Em The 45.Nm 46.Em API is deprecated. 47.Pp 48The 49.Fn powerhook_establish 50function adds 51.Fa fn 52of the list of hooks invoked by 53.Xr dopowerhooks 9 54at power change. 55When invoked, the hook function 56.Fa fn 57will be passed the new power state as the first argument and 58.Fa arg 59as its second argument. 60.Pp 61The 62.Fn powerhook_disestablish 63function removes the hook described by the opaque pointer 64.Fa cookie 65from the list of hooks to be invoked at power change. 66If 67.Fa cookie 68is invalid, the result of 69.Fn powerhook_disestablish 70is undefined. 71.Pp 72Power hooks should be used to perform activities 73that must happen when the power situation to the computer changes. 74Because of the environment in which they are run, power hooks cannot 75rely on many system services (including file systems, and timeouts 76and other interrupt-driven services). 77The power hooks are typically executed from an interrupt context. 78.Pp 79The different reasons for calling the power hooks are: suspend, standby, and 80resume. 81The reason is reflected in the 82.Fa why 83argument and the values 84.Dv PWR_SOFTSUSPEND , 85.Dv PWR_SUSPEND , 86.Dv PWR_SOFTSTANDBY , 87.Dv PWR_STANDBY , 88.Dv PWR_SOFTRESUME , 89and 90.Dv PWR_RESUME . 91It calls with PWR_SOFTxxx in the normal priority level while the other 92callings are protected with 93.Xr splhigh 9 . 94At suspend the system is going to lose (almost) all power, standby retains 95some power (e.g., minimal power to USB devices), and at resume power is 96back to normal. 97.Sh RETURN VALUES 98If successful, 99.Fn powerhook_establish 100returns an opaque pointer describing the newly-established 101power hook. 102Otherwise, it returns NULL. 103.Sh SEE ALSO 104.Xr dopowerhooks 9 105