1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
.\" $NetBSD: pmf.9,v 1.23 2024/03/09 05:22:05 riastradh Exp $
.\"
.\" Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd March 9, 2024
.Dt PMF 9
.Os
.Sh NAME
.Nm PMF ,
.Nm pmf_device_register ,
.Nm pmf_device_register1 ,
.Nm pmf_device_deregister ,
.Nm pmf_device_suspend ,
.Nm pmf_device_resume ,
.Nm pmf_device_recursive_suspend ,
.Nm pmf_device_recursive_resume ,
.Nm pmf_device_resume_subtree ,
.Nm pmf_class_network_register ,
.Nm pmf_class_input_register ,
.Nm pmf_class_display_register ,
.Nm pmf_system_suspend ,
.Nm pmf_system_resume ,
.Nm pmf_system_shutdown ,
.Nm pmf_event_register ,
.Nm pmf_event_deregister ,
.Nm pmf_event_inject ,
.Nm pmf_set_platform ,
.Nm pmf_get_platform
.Nd power management and inter-driver messaging framework
.Sh SYNOPSIS
.In sys/device.h
.Ft bool
.Fn pmf_device_register "device_t dev" "bool (*suspend)(device_t dev, const pmf_qual_t *qual)" "bool (*resume)(device_t dev, const pmf_qual_t *qual)"
.Ft bool
.Fn pmf_device_register1 "device_t dev" "bool (*suspend)(device_t dev, const pmf_qual_t *qual)" "bool (*resume)(device_t dev, const pmf_qual_t *qual)" "bool (*shutdown)(device_t dev, int how)"
.Ft void
.Fn pmf_device_deregister "device_t dev"
.Ft bool
.Fn pmf_device_suspend "device_t dev" "const pmf_qual_t *qual"
.Ft bool
.Fn pmf_device_resume "device_t dev" "const pmf_qual_t *qual"
.Ft bool
.Fn pmf_device_recursive_suspend "device_t dev" "const pmf_qual_t *qual"
.Ft bool
.Fn pmf_device_recursive_resume "device_t dev" "const pmf_qual_t *qual"
.Ft bool
.Fn pmf_device_subtree_resume "device_t dev" "const pmf_qual_t *qual"
.Ft void
.Fn pmf_class_network_register "device_t dev" "struct ifnet *ifp"
.Ft bool
.Fn pmf_class_input_register "device_t dev"
.Ft bool
.Fn pmf_class_display_register "device_t dev"
.Ft bool
.Fn pmf_system_suspend "const pmf_qual_t *qual"
.Ft bool
.Fn pmf_system_resume "const pmf_qual_t *qual"
.Ft void
.Fn pmf_system_shutdown "int"
.Ft bool
.Fn pmf_event_register "device_t dev" "pmf_generic_event_t ev" "void (*handler)(device_t dev)" "bool global"
.Ft void
.Fn pmf_event_deregister "device_t dev" "pmf_generic_event_t ev" "void (*handler)(device_t dev)" "bool global"
.Ft bool
.Fn pmf_event_inject "device_t dev" "pmf_generic_event_t ev"
.Ft bool
.Fn pmf_set_platform "const char *key" "const char *value"
.Ft const char *
.Fn pmf_get_platform "const char *key"
.Sh DESCRIPTION
The machine-independent
.Nm
framework provides power management and inter-driver messaging support
for device drivers.
.Sh DATA TYPES
Drivers for devices implementing
.Nm
may make use of the following data type:
.Bl -tag -width compact
.It Fa pmf_qual_t
An opaque aggregate of qualifications on a
.Nm
suspend or resume call.
.It Fa pmf_generic_event_t
A device driver can register as a listener for specific events, or inject
events into the message queue.
The following message types are defined:
.Bl -item -compact -offset indent
.It
.Dv PMFE_DISPLAY_ON
.It
.Dv PMFE_DISPLAY_REDUCED
.It
.Dv PMFE_DISPLAY_STANDBY
.It
.Dv PMFE_DISPLAY_SUSPEND
.It
.Dv PMFE_DISPLAY_OFF
.It
.Dv PMFE_DISPLAY_BRIGHTNESS_UP
.It
.Dv PMFE_DISPLAY_BRIGHTNESS_DOWN
.It
.Dv PMFE_AUDIO_VOLUME_UP
.It
.Dv PMFE_AUDIO_VOLUME_DOWN
.It
.Dv PMFE_AUDIO_VOLUME_TOGGLE
.It
.Dv PMFE_CHASSIS_LID_CLOSE
.It
.Dv PMFE_CHASSIS_LID_OPEN
.El
.El
.Sh FUNCTIONS
.Bl -tag -width compact
.It Fn pmf_device_register "dev" "suspend" "resume"
Register a device with the power management framework.
The
.Fa suspend
and
.Fa resume
functions are passed
.Fa dev
and a
.Fa pmf_qual_t ,
and will be called when the system state changes;
they should return
.Dv true
on success and
.Dv false
on failure.
If either
.Fa suspend
or
.Fa resume
is
.Dv NULL
then it is assumed that device state does not need to be captured and
resumed on a power transition.
Bus and class-level power management will still be performed.
.Pp
.Fn pmf_device_register
always returns true.
Callers should ignore the return value.
.It Fn pmf_device_register1 "dev" "suspend" "resume" "shutdown"
Like
.Fn pmf_device_register ,
but additionally registers a shutdown handler.
During system shutdown,
.Fn pmf_system_shutdown
calls
.Fa shutdown
on
.Fa dev
with the
.Xr reboot 2
.Dq howto
in the second argument.
.Fa shutdown
should return
.Dv true
on success and
.Dv false
on failure.
.Pp
.Fn pmf_device_register1
always returns true.
Callers should ignore the return value.
.It Fn pmf_device_deregister "dev"
Deregister a device with the power management framework.
.It Fn pmf_device_suspend "dev" "qual"
Suspend a device by first calling the class suspend handler, followed by
the driver suspend handler, and finally the bus suspend handler.
.It Fn pmf_device_resume "dev" "qual"
Resume a device by first calling the bus resume handler, followed by the
driver resume handler, and finally the class resume handler.
.It Fn pmf_device_recursive_suspend "dev" "qual"
As
.Fn pmf_device_suspend ,
but ensures that all child devices of
.Fa dev
are suspended.
.It Fn pmf_device_recursive_resume "dev" "qual"
As
.Fn pmf_device_resume ,
but ensures that all parent devices of
.Fa dev
are resumed.
.It Fn pmf_device_subtree_resume "dev" "qual"
As
.Fn pmf_device_resume ,
but ensures that all child devices of
.Fa dev
are resumed.
.It Fn pmf_class_network_register "dev" "ifp"
Register a device with the power management framework as a network-class
device.
.It Fn pmf_class_input_register "dev"
Register a device with the power management framework as an input-class
device.
.It Fn pmf_class_display_register "dev"
Register a device with the power management framework as a display-class
device.
.It Fn pmf_system_suspend "qual"
Suspend all attached devices.
Devices are suspended by traversing the autoconfiguration tree
beginning with the leaf nodes.
This function will fail if any attached drivers do not support the power
management framework.
.It Fn pmf_system_resume "qual"
Resume all attached devices.
Devices are resumed by traversing the
autoconfiguration tree beginning with devices that do not have a parent.
This function will fail if any attached drivers do not support the power
management framework.
.It Fn pmf_system_shutdown "int"
Shutdown all attached devices.
Devices are shut down by traversing the
autoconfiguration tree beginning with the leaf nodes.
The integer argument is passed to the driver shutdown functions.
It should contain the
.Xr reboot 2
.Dq howto
argument.
This function ignores the presence of attached drivers that do not support the
power management framework.
.It Fn pmf_event_register "dev" "ev" "handler" "global"
Register the callback
.Fa handler
to be called whenever an
.Fa ev
event is triggered.
If
.Fa global
is
.Dv true ,
.Fa handler
accepts anonymous events from
.Fn pmf_event_inject .
.It Fn pmf_event_deregister "dev" "ev" "handler" "global"
Deregister the callback previously registered with
.Fn pmf_event_register .
.It Fn pmf_event_inject "dev" "ev"
Inject an inter-driver message into the message queue.
If
.Fa dev
is
.Dv NULL ,
the event is considered to be anonymous and one or more drivers
may handle this event, otherwise the event is delivered directly to
the callback registered by
.Fa dev .
.It Fn pmf_set_platform "key" "value"
Insert a name-value pair into the platform information database.
.It Fn pmf_get_platform "key"
Retrieve the value for
.Fa key
from the platform information database.
Returns
.Dv NULL
if the key is not present.
.El
.Sh CODE REFERENCES
The power management framework is implemented within the files
.Pa sys/sys/pmf.h ,
.Pa sys/sys/device.h ,
.Pa sys/kern/kern_pmf.c ,
and
.Pa sys/kern/subr_autoconf.c .
.Sh SEE ALSO
.Xr autoconf 9 ,
.Xr driver 9
.Sh HISTORY
The
.Nm
framework appeared in
.Nx 5.0 .
.Sh AUTHORS
.An Jared D. McNeill Aq Mt jmcneill@NetBSD.org
.An Joerg Sonnenberger Aq Mt joerg@NetBSD.org
.Sh BUGS
.Fn pmf_device_register
and
.Fn pmf_device_register1
never fail and should return void, but until all callers are updated to
ignore the return value, they must continue to return bool:
.Lk "https://gnats.NetBSD.org/57575" "PR kern/57575"
|