| 1 | #pragma once |
| 2 | |
| 3 | #include <uacpi/types.h> |
| 4 | #include <uacpi/uacpi.h> |
| 5 | |
| 6 | #ifdef __cplusplus |
| 7 | extern "C" { |
| 8 | #endif |
| 9 | |
| 10 | #ifndef UACPI_BAREBONES_MODE |
| 11 | |
| 12 | typedef enum uacpi_fixed_event { |
| 13 | UACPI_FIXED_EVENT_TIMER_STATUS = 1, |
| 14 | UACPI_FIXED_EVENT_POWER_BUTTON, |
| 15 | UACPI_FIXED_EVENT_SLEEP_BUTTON, |
| 16 | UACPI_FIXED_EVENT_RTC, |
| 17 | UACPI_FIXED_EVENT_MAX = UACPI_FIXED_EVENT_RTC, |
| 18 | } uacpi_fixed_event; |
| 19 | |
| 20 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 21 | uacpi_status uacpi_install_fixed_event_handler( |
| 22 | uacpi_fixed_event event, uacpi_interrupt_handler handler, uacpi_handle user |
| 23 | )) |
| 24 | |
| 25 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 26 | uacpi_status uacpi_uninstall_fixed_event_handler( |
| 27 | uacpi_fixed_event event |
| 28 | )) |
| 29 | |
| 30 | /** |
| 31 | * Enable/disable a fixed event. Note that the event is automatically enabled |
| 32 | * upon installing a handler to it. |
| 33 | */ |
| 34 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 35 | uacpi_status uacpi_enable_fixed_event(uacpi_fixed_event event) |
| 36 | ) |
| 37 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 38 | uacpi_status uacpi_disable_fixed_event(uacpi_fixed_event event) |
| 39 | ) |
| 40 | |
| 41 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 42 | uacpi_status uacpi_clear_fixed_event(uacpi_fixed_event event) |
| 43 | ) |
| 44 | |
| 45 | typedef enum uacpi_event_info { |
| 46 | // Event is enabled in software |
| 47 | UACPI_EVENT_INFO_ENABLED = (1 << 0), |
| 48 | |
| 49 | // Event is enabled in software (only for wake) |
| 50 | UACPI_EVENT_INFO_ENABLED_FOR_WAKE = (1 << 1), |
| 51 | |
| 52 | // Event is masked |
| 53 | UACPI_EVENT_INFO_MASKED = (1 << 2), |
| 54 | |
| 55 | // Event has a handler attached |
| 56 | UACPI_EVENT_INFO_HAS_HANDLER = (1 << 3), |
| 57 | |
| 58 | // Hardware enable bit is set |
| 59 | UACPI_EVENT_INFO_HW_ENABLED = (1 << 4), |
| 60 | |
| 61 | // Hardware status bit is set |
| 62 | UACPI_EVENT_INFO_HW_STATUS = (1 << 5), |
| 63 | } uacpi_event_info; |
| 64 | |
| 65 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 66 | uacpi_status uacpi_fixed_event_info( |
| 67 | uacpi_fixed_event event, uacpi_event_info *out_info |
| 68 | )) |
| 69 | |
| 70 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 71 | uacpi_status uacpi_gpe_info( |
| 72 | uacpi_namespace_node *gpe_device, uacpi_u16 idx, |
| 73 | uacpi_event_info *out_info |
| 74 | )) |
| 75 | |
| 76 | // Set if the handler wishes to reenable the GPE it just handled |
| 77 | #define UACPI_GPE_REENABLE (1 << 7) |
| 78 | |
| 79 | typedef uacpi_interrupt_ret (*uacpi_gpe_handler)( |
| 80 | uacpi_handle ctx, uacpi_namespace_node *gpe_device, uacpi_u16 idx |
| 81 | ); |
| 82 | |
| 83 | typedef enum uacpi_gpe_triggering { |
| 84 | UACPI_GPE_TRIGGERING_LEVEL = 0, |
| 85 | UACPI_GPE_TRIGGERING_EDGE = 1, |
| 86 | UACPI_GPE_TRIGGERING_MAX = UACPI_GPE_TRIGGERING_EDGE, |
| 87 | } uacpi_gpe_triggering; |
| 88 | |
| 89 | const uacpi_char *uacpi_gpe_triggering_to_string( |
| 90 | uacpi_gpe_triggering triggering |
| 91 | ); |
| 92 | |
| 93 | /** |
| 94 | * Installs a handler to the provided GPE at 'idx' controlled by device |
| 95 | * 'gpe_device'. The GPE is automatically disabled & cleared according to the |
| 96 | * configured triggering upon invoking the handler. The event is optionally |
| 97 | * re-enabled (by returning UACPI_GPE_REENABLE from the handler) |
| 98 | * |
| 99 | * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE |
| 100 | */ |
| 101 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 102 | uacpi_status uacpi_install_gpe_handler( |
| 103 | uacpi_namespace_node *gpe_device, uacpi_u16 idx, |
| 104 | uacpi_gpe_triggering triggering, uacpi_gpe_handler handler, uacpi_handle ctx |
| 105 | )) |
| 106 | |
| 107 | /** |
| 108 | * Installs a raw handler to the provided GPE at 'idx' controlled by device |
| 109 | * 'gpe_device'. The handler is dispatched immediately after the event is |
| 110 | * received, status & enable bits are untouched. |
| 111 | * |
| 112 | * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE |
| 113 | */ |
| 114 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 115 | uacpi_status uacpi_install_gpe_handler_raw( |
| 116 | uacpi_namespace_node *gpe_device, uacpi_u16 idx, |
| 117 | uacpi_gpe_triggering triggering, uacpi_gpe_handler handler, uacpi_handle ctx |
| 118 | )) |
| 119 | |
| 120 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 121 | uacpi_status uacpi_uninstall_gpe_handler( |
| 122 | uacpi_namespace_node *gpe_device, uacpi_u16 idx, uacpi_gpe_handler handler |
| 123 | )) |
| 124 | |
| 125 | /** |
| 126 | * Marks the GPE 'idx' managed by 'gpe_device' as wake-capable. 'wake_device' is |
| 127 | * optional and configures the GPE to generate an implicit notification whenever |
| 128 | * an event occurs. |
| 129 | * |
| 130 | * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE |
| 131 | */ |
| 132 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 133 | uacpi_status uacpi_setup_gpe_for_wake( |
| 134 | uacpi_namespace_node *gpe_device, uacpi_u16 idx, |
| 135 | uacpi_namespace_node *wake_device |
| 136 | )) |
| 137 | |
| 138 | /** |
| 139 | * Mark a GPE managed by 'gpe_device' as enabled/disabled for wake. The GPE must |
| 140 | * have previously been marked by calling uacpi_gpe_setup_for_wake. This |
| 141 | * function only affects the GPE enable register state following the call to |
| 142 | * uacpi_gpe_enable_all_for_wake. |
| 143 | * |
| 144 | * NOTE: 'gpe_device' may be null for GPEs managed by \_GPE |
| 145 | */ |
| 146 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 147 | uacpi_status uacpi_enable_gpe_for_wake( |
| 148 | uacpi_namespace_node *gpe_device, uacpi_u16 idx |
| 149 | )) |
| 150 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 151 | uacpi_status uacpi_disable_gpe_for_wake( |
| 152 | uacpi_namespace_node *gpe_device, uacpi_u16 idx |
| 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 | */ |
| 164 | UACPI_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 | */ |
| 177 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 178 | uacpi_status uacpi_enable_gpe( |
| 179 | uacpi_namespace_node *gpe_device, uacpi_u16 idx |
| 180 | )) |
| 181 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 182 | uacpi_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 | */ |
| 191 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 192 | uacpi_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 | */ |
| 204 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 205 | uacpi_status uacpi_suspend_gpe( |
| 206 | uacpi_namespace_node *gpe_device, uacpi_u16 idx |
| 207 | )) |
| 208 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 209 | uacpi_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 | */ |
| 220 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 221 | uacpi_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 | */ |
| 234 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 235 | uacpi_status uacpi_mask_gpe( |
| 236 | uacpi_namespace_node *gpe_device, uacpi_u16 idx |
| 237 | )) |
| 238 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 239 | uacpi_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 | */ |
| 246 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 247 | uacpi_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 | */ |
| 254 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 255 | uacpi_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 | */ |
| 262 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 263 | uacpi_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 | */ |
| 270 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 271 | uacpi_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 | )) |
| 276 | UACPI_ALWAYS_ERROR_FOR_REDUCED_HARDWARE( |
| 277 | uacpi_status uacpi_uninstall_gpe_block( |
| 278 | uacpi_namespace_node *gpe_device |
| 279 | )) |
| 280 | |
| 281 | #endif // !UACPI_BAREBONES_MODE |
| 282 | |
| 283 | #ifdef __cplusplus |
| 284 | } |
| 285 | #endif |
| 286 | |