1#pragma once
2
3#include <uacpi/types.h>
4#include <uacpi/uacpi.h>
5#include <uacpi/acpi.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11typedef enum uacpi_fixed_event {
12 UACPI_FIXED_EVENT_TIMER_STATUS = 1,
13 UACPI_FIXED_EVENT_POWER_BUTTON,
14 UACPI_FIXED_EVENT_SLEEP_BUTTON,
15 UACPI_FIXED_EVENT_RTC,
16 UACPI_FIXED_EVENT_MAX = UACPI_FIXED_EVENT_RTC,
17} uacpi_fixed_event;
18
19UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
20uacpi_status uacpi_install_fixed_event_handler(
21 uacpi_fixed_event event, uacpi_interrupt_handler handler, uacpi_handle user
22))
23
24UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
25uacpi_status uacpi_uninstall_fixed_event_handler(
26 uacpi_fixed_event event
27))
28
29/*
30 * Enable/disable a fixed event. Note that the event is automatically enabled
31 * upon installing a handler to it.
32 */
33UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
34 uacpi_status uacpi_enable_fixed_event(uacpi_fixed_event event)
35)
36UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
37 uacpi_status uacpi_disable_fixed_event(uacpi_fixed_event event)
38)
39
40UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
41 uacpi_status uacpi_clear_fixed_event(uacpi_fixed_event event)
42)
43
44typedef enum uacpi_event_info {
45 // Event is enabled in software
46 UACPI_EVENT_INFO_ENABLED = (1 << 0),
47
48 // Event is enabled in software (only for wake)
49 UACPI_EVENT_INFO_ENABLED_FOR_WAKE = (1 << 1),
50
51 // Event is masked
52 UACPI_EVENT_INFO_MASKED = (1 << 2),
53
54 // Event has a handler attached
55 UACPI_EVENT_INFO_HAS_HANDLER = (1 << 3),
56
57 // Hardware enable bit is set
58 UACPI_EVENT_INFO_HW_ENABLED = (1 << 4),
59
60 // Hardware status bit is set
61 UACPI_EVENT_INFO_HW_STATUS = (1 << 5),
62} uacpi_event_info;
63
64UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
65uacpi_status uacpi_fixed_event_info(
66 uacpi_fixed_event event, uacpi_event_info *out_info
67))
68
69UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
70uacpi_status uacpi_gpe_info(
71 uacpi_namespace_node *gpe_devicem, uacpi_u16 idx,
72 uacpi_event_info *out_info
73))
74
75// Set if the handler wishes to reenable the GPE it just handled
76#define UACPI_GPE_REENABLE (1 << 7)
77
78typedef uacpi_interrupt_ret (*uacpi_gpe_handler)(
79 uacpi_handle ctx, uacpi_namespace_node *gpe_device, uacpi_u16 idx
80);
81
82typedef enum uacpi_gpe_triggering {
83 UACPI_GPE_TRIGGERING_LEVEL = 0,
84 UACPI_GPE_TRIGGERING_EDGE = 1,
85 UACPI_GPE_TRIGGERING_MAX = UACPI_GPE_TRIGGERING_EDGE,
86} uacpi_gpe_triggering;
87
88const uacpi_char *uacpi_gpe_triggering_to_string(
89 uacpi_gpe_triggering triggering
90);
91
92/*
93 * Installs a handler to the provided GPE at 'idx' controlled by device
94 * 'gpe_device'. The GPE is automatically disabled & cleared according to the
95 * configured triggering upon invoking the handler. The event is optionally
96 * re-enabled (by returning UACPI_GPE_REENABLE from the handler)
97 *
98 * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
99 */
100UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
101uacpi_status uacpi_install_gpe_handler(
102 uacpi_namespace_node *gpe_device, uacpi_u16 idx,
103 uacpi_gpe_triggering triggering, uacpi_gpe_handler handler, uacpi_handle ctx
104))
105
106/*
107 * Installs a raw handler to the provided GPE at 'idx' controlled by device
108 * 'gpe_device'. The handler is dispatched immediately after the event is
109 * received, status & enable bits are untouched.
110 *
111 * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
112 */
113UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
114 uacpi_status uacpi_install_gpe_handler_raw(
115 uacpi_namespace_node *gpe_device, uacpi_u16 idx,
116 uacpi_gpe_triggering triggering, uacpi_gpe_handler handler, uacpi_handle ctx
117))
118
119UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
120uacpi_status uacpi_uninstall_gpe_handler(
121 uacpi_namespace_node *gpe_device, uacpi_u16 idx, uacpi_gpe_handler handler
122))
123
124/*
125 * Marks the GPE 'idx' managed by 'gpe_device' as wake-capable. 'wake_device' is
126 * optional and configures the GPE to generate an implicit notification whenever
127 * an event occurs.
128 *
129 * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
130 */
131UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
132uacpi_status uacpi_gpe_setup_for_wake(
133 uacpi_namespace_node *gpe_device, uacpi_u16 idx,
134 uacpi_namespace_node *wake_device
135))
136
137/*
138 * Mark a GPE managed by 'gpe_device' as enabled/disabled for wake. The GPE must
139 * have previously been marked by calling uacpi_gpe_setup_for_wake. This
140 * function only affects the GPE enable register state following the call to
141 * uacpi_gpe_enable_all_for_wake.
142 *
143 * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
144 */
145UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
146uacpi_status uacpi_gpe_enable_for_wake(
147 uacpi_namespace_node *gpe_device, uacpi_u16 idx
148))
149UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
150uacpi_status uacpi_gpe_disable_for_wake(
151 uacpi_namespace_node *gpe_device, uacpi_u16 idx
152))
153
154
155/*
156 * Finalize GPE initialization by enabling all GPEs not configured for wake and
157 * having a matching AML handler detected.
158 *
159 * This should be called after the kernel power managment subsystem has
160 * enumerated all of the devices, executing their _PRW methods etc., and
161 * marking those it wishes to use for wake by calling uacpi_setup_gpe_for_wake
162 * or uacpi_mark_gpe_for_wake.
163 */
164UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
165 uacpi_status uacpi_finalize_gpe_initialization(void)
166)
167
168/*
169 * Enable/disable a general purpose event managed by 'gpe_device'. Internally
170 * this uses reference counting to make sure a GPE is not disabled until all
171 * possible users of it do so. GPEs not marked for wake are enabled
172 * automatically so this API is only needed for wake events or those that don't
173 * have a corresponding AML handler.
174 *
175 * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
176 */
177UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
178uacpi_status uacpi_enable_gpe(
179 uacpi_namespace_node *gpe_device, uacpi_u16 idx
180))
181UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
182uacpi_status uacpi_disable_gpe(
183 uacpi_namespace_node *gpe_device, uacpi_u16 idx
184))
185
186/*
187 * Clear the status bit of the event 'idx' managed by 'gpe_device'.
188 *
189 * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
190 */
191UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
192uacpi_status uacpi_clear_gpe(
193 uacpi_namespace_node *gpe_device, uacpi_u16 idx
194))
195
196/*
197 * Suspend/resume a general purpose event managed by 'gpe_device'. This bypasses
198 * the reference counting mechanism and unconditionally clears/sets the
199 * corresponding bit in the enable registers. This is used for switching the GPE
200 * to poll mode.
201 *
202 * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
203 */
204UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
205uacpi_status uacpi_suspend_gpe(
206 uacpi_namespace_node *gpe_device, uacpi_u16 idx
207))
208UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
209uacpi_status uacpi_resume_gpe(
210 uacpi_namespace_node *gpe_device, uacpi_u16 idx
211))
212
213/*
214 * Finish handling the GPE managed by 'gpe_device' at 'idx'. This clears the
215 * status registers if it hasn't been cleared yet and re-enables the event if
216 * it was enabled before.
217 *
218 * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
219 */
220UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
221uacpi_status uacpi_finish_handling_gpe(
222 uacpi_namespace_node *gpe_device, uacpi_u16 idx
223))
224
225/*
226 * Hard mask/umask a general purpose event at 'idx' managed by 'gpe_device'.
227 * This is used to permanently silence an event so that further calls to
228 * enable/disable as well as suspend/resume get ignored. This might be necessary
229 * for GPEs that cause an event storm due to the kernel's inability to properly
230 * handle them. The only way to enable a masked event is by a call to unmask.
231 *
232 * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE
233 */
234UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
235uacpi_status uacpi_mask_gpe(
236 uacpi_namespace_node *gpe_device, uacpi_u16 idx
237))
238UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
239uacpi_status uacpi_unmask_gpe(
240 uacpi_namespace_node *gpe_device, uacpi_u16 idx
241))
242
243/*
244 * Disable all GPEs currently set up on the system.
245 */
246UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
247uacpi_status uacpi_disable_all_gpes(void)
248)
249
250/*
251 * Enable all GPEs not marked as wake. This is only needed after the system
252 * wakes from a shallow sleep state and is called automatically by wake code.
253 */
254UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
255uacpi_status uacpi_enable_all_runtime_gpes(void)
256)
257
258/*
259 * Enable all GPEs marked as wake. This is only needed before the system goes
260 * to sleep is called automatically by sleep code.
261 */
262UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
263uacpi_status uacpi_enable_all_wake_gpes(void)
264)
265
266/*
267 * Install/uninstall a new GPE block, usually defined by a device in the
268 * namespace with a _HID of ACPI0006.
269 */
270UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
271uacpi_status uacpi_install_gpe_block(
272 uacpi_namespace_node *gpe_device, uacpi_u64 address,
273 uacpi_address_space address_space, uacpi_u16 num_registers,
274 uacpi_u32 irq
275))
276UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE(
277uacpi_status uacpi_uninstall_gpe_block(
278 uacpi_namespace_node *gpe_device
279))
280
281#ifdef __cplusplus
282}
283#endif
284