xref: /netbsd-src/share/man/man9/pmf.9 (revision da9817918ec7e88db2912a2882967c7570a83f47)
1.\" $NetBSD: pmf.9,v 1.11 2009/05/14 23:05:21 dyoung 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 May 14, 2009
34.Dt PMF 9
35.Os
36.Sh NAME
37.Nm PMF ,
38.Nm pmf_device_register ,
39.Nm pmf_device_register1 ,
40.Nm pmf_device_deregister ,
41.Nm pmf_device_suspend ,
42.Nm pmf_device_resume ,
43.Nm pmf_device_recursive_suspend ,
44.Nm pmf_device_recursive_resume ,
45.Nm pmf_device_resume_subtree ,
46.Nm pmf_class_network_register ,
47.Nm pmf_class_input_register ,
48.Nm pmf_class_display_register ,
49.Nm pmf_system_suspend ,
50.Nm pmf_system_resume ,
51.Nm pmf_system_shutdown ,
52.Nm pmf_event_register ,
53.Nm pmf_event_deregister ,
54.Nm pmf_event_inject ,
55.Nm pmf_set_platform ,
56.Nm pmf_get_platform
57.Nd power management and inter-driver messaging framework
58.Sh SYNOPSIS
59.In sys/device.h
60.Ft bool
61.Fn pmf_device_register "device_t dev" "bool (*suspend)(device_t dev)" "bool (*resume)(device_t dev)"
62.Ft bool
63.Fn pmf_device_register1 "device_t dev" "bool (*suspend)(device_t dev)" "bool (*resume)(device_t dev)" "bool (*shutdown)(device_t dev, int how)"
64.Ft void
65.Fn pmf_device_deregister "device_t dev"
66.Ft bool
67.Fn pmf_device_suspend "device_t dev"
68.Ft bool
69.Fn pmf_device_resume "device_t dev"
70.Ft bool
71.Fn pmf_device_recursive_suspend "device_t dev"
72.Ft bool
73.Fn pmf_device_recursive_resume "device_t dev"
74.Ft bool
75.Fn pmf_device_resume_subtree "device_t dev"
76.Ft void
77.Fn pmf_class_network_register "device_t dev" "struct ifnet *ifp"
78.Ft bool
79.Fn pmf_class_input_register "device_t dev"
80.Ft bool
81.Fn pmf_class_display_register "device_t dev"
82.Ft bool
83.Fn pmf_system_suspend "void"
84.Ft bool
85.Fn pmf_system_resume "void"
86.Ft void
87.Fn pmf_system_shutdown "int"
88.Ft bool
89.Fn pmf_event_register "device_t dev" "pmf_generic_event_t ev" "void (*handler)(device_t dev)" "bool global"
90.Ft void
91.Fn pmf_event_deregister "device_t dev" "pmf_generic_event_t ev" "void (*handler)(device_t dev)" "bool global"
92.Ft bool
93.Fn pmf_event_inject "device_t dev" "pmf_generic_event_t ev"
94.Ft bool
95.Fn pmf_set_platform "const char *key" "const char *value"
96.Ft const char *
97.Fn pmf_get_platform "const char *key"
98.Sh DESCRIPTION
99The machine-independent
100.Nm
101framework provides power management and inter-driver messaging support
102for device drivers.
103.Sh DATA TYPES
104Drivers for devices implementing
105.Nm
106may make use of the following data type:
107.Bl -tag -width compact
108.It Fa pmf_generic_event_t
109A device driver can register as a listener for specific events, or inject
110events into the message queue.
111The following message types are defined:
112.Bl -item -compact -offset indent
113.It
114.Dv PMFE_DISPLAY_ON
115.It
116.Dv PMFE_DISPLAY_REDUCED
117.It
118.Dv PMFE_DISPLAY_STANDBY
119.It
120.Dv PMFE_DISPLAY_SUSPEND
121.It
122.Dv PMFE_DISPLAY_OFF
123.It
124.Dv PMFE_DISPLAY_BRIGHTNESS_UP
125.It
126.Dv PMFE_DISPLAY_BRIGHTNESS_DOWN
127.It
128.Dv PMFE_AUDIO_VOLUME_UP
129.It
130.Dv PMFE_AUDIO_VOLUME_DOWN
131.It
132.Dv PMFE_AUDIO_VOLUME_TOGGLE
133.It
134.Dv PMFE_CHASSIS_LID_CLOSE
135.It
136.Dv PMFE_CHASSIS_LID_OPEN
137.El
138.El
139.Sh FUNCTIONS
140.Bl -tag -width compact
141.It Fn pmf_device_register "dev" "suspend" "resume"
142Register a device with the power management framework.
143.Fa suspend
144and
145.Fa resume
146are passed
147.Fa dev
148and they return
149.Dv true
150on success and
151.Dv false
152on failure.
153If either
154.Fa suspend
155or
156.Fa resume
157is
158.Dv NULL
159then it is assumed that device state does not need to be captured and
160resumed on a power transition.
161Bus and class-level power management will still be performed.
162Returns
163.Dv false
164if there was an error.
165.It Fn pmf_device_register1 "dev" "suspend" "resume" "shutdown"
166Like
167.Fn pmf_device_register ,
168but additionally registers a shutdown handler.
169During system shutdown,
170.Fn pmf_system_shutdown
171calls
172.Fa shutdown
173on
174.Fa dev
175with the
176.Xr reboot 2
177.Dq howto
178in the second argument.
179.Fa shutdown
180should return
181.Dv true
182on success and
183.Dv false
184on failure.
185.It Fn pmf_device_deregister "dev"
186Deregister a device with the power management framework.
187.It Fn pmf_device_suspend "dev"
188Suspend a device by first calling the class suspend handler, followed by
189the driver suspend handler, and finally the bus suspend handler.
190.It Fn pmf_device_resume "dev"
191Resume a device by first calling the bus resume handler, followed by the
192driver resume handler, and finally the class resume handler.
193.It Fn pmf_device_recursive_suspend "dev"
194As
195.Fn pmf_device_suspend ,
196but ensures that all child devices of
197.Fa dev
198are suspended.
199.It Fn pmf_device_recursive_resume "dev"
200As
201.Fn pmf_device_resume ,
202but ensures that all parent devices of
203.Fa dev
204are resumed.
205.It Fn pmf_device_resume_subtree "dev"
206As
207.Fn pmf_device_resume ,
208but ensures that all child devices of
209.Fa dev
210are resumed.
211.It Fn pmf_class_network_register "dev" "ifp"
212Register a device with the power management framework as a network-class
213device.
214.It Fn pmf_class_input_register "dev"
215Register a device with the power management framework as an input-class
216device.
217.It Fn pmf_class_display_register "dev"
218Register a device with the power management framework as a display-class
219device.
220.It Fn pmf_system_suspend "void"
221Suspend all attached devices.
222Devices are suspended by traversing the
223autoconfiguration tree beginning with the leaf nodes.
224This function will fail if any attached drivers do not support the power
225management framework.
226.It Fn pmf_system_resume "void"
227Resume all attached devices.
228Devices are resumed by traversing the
229autoconfiguration tree beginning with devices that do not have a parent.
230This function will fail if any attached drivers do not support the power
231management framework.
232.It Fn pmf_system_shutdown "int"
233Shutdown all attached devices.
234Devices are shut down by traversing the
235autoconfiguration tree beginning with the leaf nodes.
236The integer argument is passed to the driver shutdown functions.
237It should contain the
238.Xr reboot 2
239.Dq howto
240argument.
241This function ignores the presence of attached drivers that do not support the
242power management framework.
243.It Fn pmf_event_register "dev" "ev" "handler" "global"
244Register the callback
245.Fa handler
246to be called whenever an
247.Fa ev
248event is triggered.
249If
250.Fa global
251is
252.Dv true ,
253.Fa handler
254accepts anonymous events from
255.Fn pmf_event_inject .
256.It Fn pmf_event_deregister "dev" "ev" "handler" "global"
257Deregister the callback previously registered with
258.Fn pmf_event_register .
259.It Fn pmf_event_inject "dev" "ev"
260Inject an inter-driver message into the message queue.
261If
262.Fa dev
263is
264.Dv NULL ,
265the event is considered to be anonymous and one or more drivers
266may handle this event, otherwise the event is delivered directly to
267the callback registered by
268.Fa dev .
269.It Fn pmf_set_platform "key" "value"
270Insert a name-value pair into the platform information database.
271.It Fn pmf_get_platform "key"
272Retrieve the value for
273.Fa key
274from the platform information database.
275Returns
276.Dv NULL
277if the key is not present.
278.El
279.Sh CODE REFERENCES
280This section describes places within the
281.Nx
282source tree where actual code implementing or using the power management
283framework can be found.
284All pathnames are relative to
285.Pa /usr/src .
286.Pp
287The power management framework is implemented within the files
288.Pa sys/sys/pmf.h ,
289.Pa sys/sys/device.h ,
290.Pa sys/kern/kern_pmf.c ,
291and
292.Pa sys/kern/subr_autoconf.c .
293.Sh SEE ALSO
294.Xr autoconf 9 ,
295.Xr driver 9
296.Sh HISTORY
297The
298.Nm
299framework appeared in
300.Nx 5.0 .
301.Sh AUTHORS
302.An Jared D. McNeill Aq jmcneill@NetBSD.org
303.An Joerg Sonnenberger Aq joerg@NetBSD.org
304