1.\" $NetBSD: pmf.9,v 1.3 2007/12/13 15:37:33 xtraeme Exp $ 2.\" 3.\" Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by Jared D. McNeill. 17.\" 4. Neither the name of The NetBSD Foundation nor the names of its 18.\" contributors may be used to endorse or promote products derived 19.\" from this software without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31.\" POSSIBILITY OF SUCH DAMAGE. 32.\" 33.Dd December 13, 2007 34.Dt PMF 9 35.Os 36.Sh NAME 37.Nm PMF , 38.Nm pmf_device_register , 39.Nm pmf_device_deregister , 40.Nm pmf_device_suspend , 41.Nm pmf_device_resume , 42.Nm pmf_device_recursive_suspend , 43.Nm pmf_device_recursive_resume , 44.Nm pmf_device_resume_subtree , 45.Nm pmf_class_network_register , 46.Nm pmf_class_input_register , 47.Nm pmf_class_display_register , 48.Nm pmf_system_suspend , 49.Nm pmf_system_resume , 50.Nm pmf_system_shutdown , 51.Nm pmf_event_register , 52.Nm pmf_event_deregister , 53.Nm pmf_event_inject , 54.Nm pmf_set_platform , 55.Nm pmf_get_platform 56.Nd power management and inter-driver messaging framework 57.Sh SYNOPSIS 58.In sys/device.h 59.Ft bool 60.Fn pmf_device_register "device_t dev" "bool (*suspend)(device_t dev)" "bool (*resume)(device_t dev)" 61.Ft void 62.Fn pmf_device_deregister "device_t dev" 63.Ft bool 64.Fn pmf_device_suspend "device_t dev" 65.Ft bool 66.Fn pmf_device_resume "device_t dev" 67.Ft bool 68.Fn pmf_device_recursive_suspend "device_t dev" 69.Ft bool 70.Fn pmf_device_recursive_resume "device_t dev" 71.Ft bool 72.Fn pmf_device_resume_subtree "device_t dev" 73.Ft void 74.Fn pmf_class_network_register "device_t dev" "struct ifnet *ifp" 75.Ft bool 76.Fn pmf_class_input_register "device_t dev" 77.Ft bool 78.Fn pmf_class_display_register "device_t dev" 79.Ft bool 80.Fn pmf_system_suspend "void" 81.Ft bool 82.Fn pmf_system_resume "void" 83.Ft void 84.Fn pmf_system_shutdown "void" 85.Ft bool 86.Fn pmf_event_register "device_t dev" "pmf_generic_event_t ev" "void (*handler)(device_t dev)" "bool global" 87.Ft void 88.Fn pmf_event_deregister "device_t dev" "pmf_generic_event_t ev" "void (*handler)(device_t dev)" "bool global" 89.Ft bool 90.Fn pmf_event_inject "device_t dev" "pmf_generic_event_t ev" 91.Ft bool 92.Fn pmf_set_platform "const char *key" "const char *value" 93.Ft const char * 94.Fn pmf_get_platform "const char *key" 95.Sh DESCRIPTION 96The machine-independent 97.Nm 98framework provides power management and inter-driver messaging support 99for device drivers. 100.Sh DATA TYPES 101Drivers for devices implementing 102.Nm 103may make use of the following data type: 104.Bl -tag -width compact 105.It Fa pmf_generic_event_t 106A device driver can register as a listener for specific events, or inject 107events into the message queue. 108The following message types are defined: 109.Bd -literal 110 PMFE_DISPLAY_ON 111 PMFE_DISPLAY_REDUCED 112 PMFE_DISPLAY_STANDBY 113 PMFE_DISPLAY_SUSPEND 114 PMFE_DISPLAY_OFF 115 PMFE_DISPLAY_BRIGHTNESS_UP 116 PMFE_DISPLAY_BRIGHTNESS_DOWN 117 PMFE_AUDIO_VOLUME_DOWN 118 PMFE_AUDIO_VOLUME_TOGGLE 119 PMFE_CHASSIS_LID_CLOSE 120 PMFE_CHASSIS_LID_OPEN 121.Ed 122.El 123.Sh FUNCTIONS 124.Bl -tag -width compact 125.It Fn pmf_device_register "dev" "suspend" "resume" 126Register a device with the power management framework. If either 127.Fa suspend 128or 129.Fa resume 130is 131.Dv NULL 132then it is assumed that device state does not need to be captured and 133resumed on a power transition. Bus and class-level power management 134will still be performed. Returns true if there was an error. 135.It Fn pmf_device_deregister "dev" 136Deregister a device with the power management framework. 137.It Fn pmf_device_suspend "dev" 138Suspend a device by first calling the class suspend handler, followed by 139the driver suspend handler, and finally the bus suspend handler. 140.It Fn pmf_device_resume "dev" 141Resume a device by first calling the bus resume handler, followed by the 142driver resume handler, and finally the class resume handler. 143.It Fn pmf_device_recursive_suspend "dev" 144As 145.Fn pmf_device_suspend , 146but ensures that all child devices of 147.Fa dev 148are suspended. 149.It Fn pmf_device_recursive_resume "dev" 150As 151.Fn pmf_device_resume , 152but ensures that all parent devices of 153.Fa dev 154are resumed. 155.It Fn pmf_device_resume_subtree "dev" 156As 157.Fn pmf_device_resume , 158but ensures that all child devices of 159.Fa dev 160are resumed. 161.It Fn pmf_class_network_register "dev" "ifp" 162Register a device with the power management framework as a network-class 163device. 164.It Fn pmf_class_input_register "dev" 165Register a device with the power management framework as an input-class 166device. 167.It Fn pmf_class_display_register "dev" 168Register a device with the power management framework as a display-class 169device. 170.It Fn pmf_system_suspend "void" 171Suspend all attached devices. Devices are suspended by traversing the 172autoconfiguration tree beginning with the leaf nodes. 173This function will fail if any attached drivers do not support the power 174management framework. 175.It Fn pmf_system_resume "void" 176Resume all attached devices. Devices are resumed by traversing the 177autoconfiguration tree beginning with devices that do not have a parent. 178This function will fail if any attached drivers do not support the power 179management framework. 180.It Fn pmf_system_shutdown "void" 181As 182.Fn pmf_system_suspend , 183but ignores the presence of attached drivers that do not support the 184power management framework. 185.It Fn pmf_event_register "dev" "ev" "handler" "global" 186Register the callback 187.Fa handler 188to be called whenever an 189.Fa ev 190event is triggered. If 191.Fa global 192is 193.Dv true , 194.Fa handler 195accepts anonymous events from 196.Fn pmf_event_inject . 197.It Fn pmf_event_deregister "dev" "ev" "handler" "global" 198Deregister the callback previously registered with 199.Fn pmf_event_register . 200.It Fn pmf_event_inject "dev" "ev" 201Inject an inter-driver message into the message queue. If 202.Fa dev 203is 204.Dv NULL , 205the event is considered to be anonymous and one or more drivers 206may handle this event, otherwise the event is delivered directly to 207the callback registered by 208.Fa dev . 209.It Fn pmf_set_platform "key" "value" 210Insert a name-value pair into the platform information database. 211.It Fn pmf_get_platform "key" 212Retrieve the value for 213.Fa key 214from the platform information database. Returns 215.Dv NULL 216if the key is not present. 217.El 218.Sh CODE REFERENCES 219This section describes places within the 220.Nx 221source tree where actual code implementing or using the power management 222framework can be found. 223All pathnames are relative to 224.Pa /usr/src . 225.Pp 226The power management framework is implemented within the files 227.Pa sys/pmf.h , 228.Pa sys/device.h , 229.Pa sys/kern/kern_pmf.c , 230and 231.Pa sys/kern/subr_autoconf.c . 232.Sh SEE ALSO 233.Xr autoconf 9 , 234.Xr driver 9 235.Sh HISTORY 236The 237.Nm 238framework appeared in 239.Nx 5.0 . 240.Sh AUTHORS 241.An Jared D. McNeill Aq jmcneill@NetBSD.org 242.An Joerg Sonnenberger Aq joerg@NetBSD.org 243