1 /* $NetBSD: pmf.h,v 1.21 2013/08/06 06:10:57 matt 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 #ifdef _KERNEL
33
34 #include <sys/types.h>
35 #include <sys/device_if.h>
36
37 typedef 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 } pmf_generic_event_t;
56
57 struct pmf_qual {
58 const device_suspensor_t *pq_suspensor;
59 devact_level_t pq_actlvl;
60 };
61
62 typedef struct pmf_qual pmf_qual_t;
63 extern const pmf_qual_t * const PMF_Q_NONE;
64 extern const pmf_qual_t * const PMF_Q_SELF;
65 extern const pmf_qual_t * const PMF_Q_DRVCTL;
66
67 extern const device_suspensor_t
68 * const device_suspensor_self,
69 * const device_suspensor_system,
70 * const device_suspensor_drvctl;
71
72 void pmf_init(void);
73
74 bool pmf_event_inject(device_t, pmf_generic_event_t);
75 bool pmf_event_register(device_t, pmf_generic_event_t,
76 void (*)(device_t), bool);
77 void pmf_event_deregister(device_t, pmf_generic_event_t,
78 void (*)(device_t), bool);
79
80 bool pmf_set_platform(const char *, const char *);
81 const char *pmf_get_platform(const char *);
82
83 bool pmf_system_resume(const pmf_qual_t *);
84 bool pmf_system_bus_resume(const pmf_qual_t *);
85 bool pmf_system_suspend(const pmf_qual_t *);
86 void pmf_system_shutdown(int);
87
88 bool pmf_device_register1(device_t,
89 bool (*)(device_t, const pmf_qual_t *),
90 bool (*)(device_t, const pmf_qual_t *),
91 bool (*)(device_t, int));
92 /* compatibility */
93 #define pmf_device_register(__d, __s, __r) \
94 pmf_device_register1((__d), (__s), (__r), NULL)
95
96 void pmf_device_deregister(device_t);
97 bool pmf_device_suspend(device_t, const pmf_qual_t *);
98 bool pmf_device_resume(device_t, const pmf_qual_t *);
99
100 bool pmf_device_recursive_suspend(device_t, const pmf_qual_t *);
101 bool pmf_device_recursive_resume(device_t, const pmf_qual_t *);
102 bool pmf_device_descendants_resume(device_t, const pmf_qual_t *);
103 bool pmf_device_subtree_resume(device_t, const pmf_qual_t *);
104
105 bool pmf_device_descendants_release(device_t, const pmf_qual_t *);
106 bool pmf_device_subtree_release(device_t, const pmf_qual_t *);
107
108 struct ifnet;
109 void pmf_class_network_register(device_t, struct ifnet *);
110
111 bool pmf_class_input_register(device_t);
112 bool pmf_class_display_register(device_t);
113
114 void pmf_qual_recursive_copy(pmf_qual_t *, const pmf_qual_t *);
115 void pmf_self_suspensor_init(device_t, device_suspensor_t *,
116 pmf_qual_t *);
117
118 static inline const device_suspensor_t *
pmf_qual_suspension(const pmf_qual_t * pq)119 pmf_qual_suspension(const pmf_qual_t *pq)
120 {
121 return pq->pq_suspensor;
122 }
123
124 static inline devact_level_t
pmf_qual_depth(const pmf_qual_t * pq)125 pmf_qual_depth(const pmf_qual_t *pq)
126 {
127 return pq->pq_actlvl;
128 }
129
130 static inline bool
pmf_qual_descend_ok(const pmf_qual_t * pq)131 pmf_qual_descend_ok(const pmf_qual_t *pq)
132 {
133 return pq->pq_actlvl == DEVACT_LEVEL_FULL;
134 }
135
136 #endif /* !_KERNEL */
137
138 #endif /* !_SYS_PMF_H */
139