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