master
1/* $NetBSD: pmf.h,v 1.25 2020/09/12 18:08:38 macallan Exp $ */
2
3/*-
4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef _SYS_PMF_H
30#define _SYS_PMF_H
31
32#if defined(_KERNEL) || defined(_KMEMUSER)
33
34#include <sys/types.h>
35#include <sys/device_if.h>
36
37typedef enum {
38 PMFE_DISPLAY_ON,
39 PMFE_DISPLAY_REDUCED,
40 PMFE_DISPLAY_STANDBY,
41 PMFE_DISPLAY_SUSPEND,
42 PMFE_DISPLAY_OFF,
43 PMFE_DISPLAY_BRIGHTNESS_UP,
44 PMFE_DISPLAY_BRIGHTNESS_DOWN,
45 PMFE_AUDIO_VOLUME_UP,
46 PMFE_AUDIO_VOLUME_DOWN,
47 PMFE_AUDIO_VOLUME_TOGGLE,
48 PMFE_CHASSIS_LID_CLOSE,
49 PMFE_CHASSIS_LID_OPEN,
50 PMFE_RADIO_ON,
51 PMFE_RADIO_OFF,
52 PMFE_RADIO_TOGGLE,
53 PMFE_POWER_CHANGED,
54 PMFE_SPEED_CHANGED,
55 PMFE_THROTTLE_ENABLE,
56 PMFE_THROTTLE_DISABLE,
57 PMFE_KEYBOARD_BRIGHTNESS_UP,
58 PMFE_KEYBOARD_BRIGHTNESS_DOWN,
59 PMFE_KEYBOARD_BRIGHTNESS_TOGGLE
60} pmf_generic_event_t;
61
62struct pmf_qual {
63 const device_suspensor_t *pq_suspensor;
64 devact_level_t pq_actlvl;
65};
66
67typedef struct pmf_qual pmf_qual_t;
68#endif
69
70#if defined(_KERNEL)
71extern const pmf_qual_t * const PMF_Q_NONE;
72extern const pmf_qual_t * const PMF_Q_SELF;
73extern const pmf_qual_t * const PMF_Q_DRVCTL;
74
75extern const device_suspensor_t
76 * const device_suspensor_self,
77 * const device_suspensor_system,
78 * const device_suspensor_drvctl;
79
80void pmf_init(void);
81
82bool pmf_event_inject(device_t, pmf_generic_event_t);
83bool pmf_event_register(device_t, pmf_generic_event_t,
84 void (*)(device_t), bool);
85void pmf_event_deregister(device_t, pmf_generic_event_t,
86 void (*)(device_t), bool);
87
88bool pmf_set_platform(const char *, const char *);
89const char *pmf_get_platform(const char *);
90
91bool pmf_system_resume(const pmf_qual_t *);
92bool pmf_system_bus_resume(const pmf_qual_t *);
93bool pmf_system_suspend(const pmf_qual_t *);
94void pmf_system_shutdown(int);
95
96bool pmf_device_register1(device_t,
97 bool (*)(device_t, const pmf_qual_t *),
98 bool (*)(device_t, const pmf_qual_t *),
99 bool (*)(device_t, int));
100/* compatibility */
101#define pmf_device_register(__d, __s, __r) \
102 pmf_device_register1((__d), (__s), (__r), NULL)
103
104void pmf_device_deregister(device_t);
105bool pmf_device_suspend(device_t, const pmf_qual_t *);
106bool pmf_device_resume(device_t, const pmf_qual_t *);
107
108bool pmf_device_recursive_suspend(device_t, const pmf_qual_t *);
109bool pmf_device_recursive_resume(device_t, const pmf_qual_t *);
110bool pmf_device_descendants_resume(device_t, const pmf_qual_t *);
111bool pmf_device_subtree_resume(device_t, const pmf_qual_t *);
112
113bool pmf_device_descendants_release(device_t, const pmf_qual_t *);
114bool pmf_device_subtree_release(device_t, const pmf_qual_t *);
115
116struct ifnet;
117void pmf_class_network_register(device_t, struct ifnet *);
118
119bool pmf_class_input_register(device_t);
120bool pmf_class_display_register(device_t);
121
122void pmf_qual_recursive_copy(pmf_qual_t *, const pmf_qual_t *);
123void pmf_self_suspensor_init(device_t, device_suspensor_t *,
124 pmf_qual_t *);
125
126static __inline const device_suspensor_t *
127pmf_qual_suspension(const pmf_qual_t *pq)
128{
129 return pq->pq_suspensor;
130}
131
132static __inline devact_level_t
133pmf_qual_depth(const pmf_qual_t *pq)
134{
135 return pq->pq_actlvl;
136}
137
138static __inline bool
139pmf_qual_descend_ok(const pmf_qual_t *pq)
140{
141 return pq->pq_actlvl == DEVACT_LEVEL_FULL;
142}
143
144#endif /* !_KERNEL */
145
146#endif /* !_SYS_PMF_H */