1 /* 2 * Copyright 2005-2008, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License 4 */ 5 #ifndef _ACPI_H 6 #define _ACPI_H 7 8 9 #include <device_manager.h> 10 #include <KernelExport.h> 11 12 13 typedef struct acpi_module_info acpi_module_info; 14 typedef union acpi_object_type acpi_object_type; 15 16 #define B_ACPI_MODULE_NAME "bus_managers/acpi/v1" 17 18 typedef phys_addr_t acpi_physical_address; 19 typedef phys_addr_t acpi_io_address; 20 typedef size_t acpi_size; 21 22 /* Actually a ptr to a NS Node */ 23 typedef void * acpi_handle; 24 25 #ifndef __ACTYPES_H__ 26 27 /* Notify types */ 28 29 #define ACPI_SYSTEM_NOTIFY 0x1 30 #define ACPI_DEVICE_NOTIFY 0x2 31 #define ACPI_ALL_NOTIFY (ACPI_SYSTEM_NOTIFY | ACPI_DEVICE_NOTIFY) 32 #define ACPI_MAX_NOTIFY_HANDLER_TYPE 0x3 33 34 #define ACPI_MAX_SYS_NOTIFY 0x7F 35 36 /* Address Space (Operation Region) Types */ 37 38 enum { 39 ACPI_ADR_SPACE_SYSTEM_MEMORY = 0, 40 ACPI_ADR_SPACE_SYSTEM_IO = 1, 41 ACPI_ADR_SPACE_PCI_CONFIG = 2, 42 ACPI_ADR_SPACE_EC = 3, 43 ACPI_ADR_SPACE_SMBUS = 4, 44 ACPI_ADR_SPACE_CMOS = 5, 45 ACPI_ADR_SPACE_PCI_BAR_TARGET = 6, 46 ACPI_ADR_SPACE_IPMI = 7, 47 ACPI_ADR_SPACE_DATA_TABLE = 8, 48 ACPI_ADR_SPACE_FIXED_HARDWARE = 127 49 }; 50 51 /* ACPI fixed event types */ 52 53 enum { 54 ACPI_EVENT_PMTIMER = 0, 55 ACPI_EVENT_GLOBAL, 56 ACPI_EVENT_POWER_BUTTON, 57 ACPI_EVENT_SLEEP_BUTTON, 58 ACPI_EVENT_RTC 59 }; 60 61 /* ACPI Object Types */ 62 63 enum { 64 ACPI_TYPE_ANY = 0, 65 ACPI_TYPE_INTEGER, 66 ACPI_TYPE_STRING, 67 ACPI_TYPE_BUFFER, 68 ACPI_TYPE_PACKAGE, 69 ACPI_TYPE_FIELD_UNIT, 70 ACPI_TYPE_DEVICE, 71 ACPI_TYPE_EVENT, 72 ACPI_TYPE_METHOD, 73 ACPI_TYPE_MUTEX, 74 ACPI_TYPE_REGION, 75 ACPI_TYPE_POWER, 76 ACPI_TYPE_PROCESSOR, 77 ACPI_TYPE_THERMAL, 78 ACPI_TYPE_BUFFER_FIELD, 79 ACPI_TYPE_DDB_HANDLE, 80 ACPI_TYPE_DEBUG_OBJECT, 81 ACPI_TYPE_LOCAL_REFERENCE = 0x14 82 }; 83 84 /* ACPI control method arg type */ 85 86 union acpi_object_type { 87 uint32 object_type; 88 struct { 89 uint32 object_type; 90 uint64 integer; 91 } integer; 92 struct { 93 uint32 object_type; 94 uint32 len; 95 char *string; /* You have to allocate string space yourself */ 96 } string; 97 struct { 98 uint32 object_type; 99 uint32 length; 100 void *buffer; 101 } buffer; 102 struct { 103 uint32 object_type; 104 uint32 count; 105 acpi_object_type *objects; 106 } package; 107 struct { 108 uint32 object_type; 109 uint32 actual_type; 110 acpi_handle handle; 111 } reference; 112 struct { 113 uint32 object_type; 114 uint32 cpu_id; 115 acpi_io_address pblk_address; 116 uint32 pblk_length; 117 } processor; 118 struct { 119 uint32 object_type; 120 uint32 min_power_state; 121 uint32 resource_order; 122 } power_resource; 123 }; 124 125 126 /* 127 * List of objects, used as a parameter list for control method evaluation 128 */ 129 typedef struct acpi_objects { 130 uint32 count; 131 acpi_object_type *pointer; 132 } acpi_objects; 133 134 135 typedef struct acpi_data { 136 acpi_size length; /* Length in bytes of the buffer */ 137 void *pointer; /* pointer to buffer */ 138 } acpi_data; 139 140 141 enum { 142 ACPI_ALLOCATE_BUFFER = (acpi_size)-1, 143 ACPI_ALLOCATE_LOCAL_BUFFER = (acpi_size)-2, 144 }; 145 146 147 /* 148 * acpi_status should return ACPI specific error codes, not BeOS ones. 149 */ 150 typedef uint32 acpi_status; 151 152 typedef struct acpi_resource acpi_resource; 153 154 #define ACPI_REENABLE_GPE 0x80 155 156 157 #endif // __ACTYPES_H__ 158 159 160 typedef uint32 (*acpi_event_handler)(void *context); 161 typedef uint32 (*acpi_gpe_handler) (acpi_handle GpeDevice, uint32 GpeNumber, 162 void *context); 163 164 typedef acpi_status (*acpi_adr_space_handler)(uint32 function, 165 acpi_physical_address address, uint32 bitWidth, int *value, 166 void *handlerContext, void *regionContext); 167 168 typedef acpi_status (*acpi_adr_space_setup)(acpi_handle regionHandle, 169 uint32 function, void *handlerContext, void **regionContext); 170 171 typedef void (*acpi_notify_handler)(acpi_handle device, uint32 value, 172 void *context); 173 174 typedef acpi_status (*acpi_walk_resources_callback)(acpi_resource* resource, 175 void* context); 176 177 typedef acpi_status (*acpi_walk_callback) (acpi_handle object, uint32 nestingLevel, 178 void *context, void** returnValue); 179 180 181 struct acpi_module_info { 182 module_info info; 183 184 status_t (*get_handle)(acpi_handle parent, const char *pathname, 185 acpi_handle *retHandle); 186 status_t (*get_name)(acpi_handle handle, uint32 nameType, 187 char* returnedName, size_t bufferLength); 188 189 /* Global Lock */ 190 191 status_t (*acquire_global_lock)(uint16 timeout, uint32 *handle); 192 status_t (*release_global_lock)(uint32 handle); 193 194 /* Notify Handler */ 195 196 status_t (*install_notify_handler)(acpi_handle device, 197 uint32 handlerType, acpi_notify_handler handler, 198 void *context); 199 status_t (*remove_notify_handler)(acpi_handle device, 200 uint32 handlerType, acpi_notify_handler handler); 201 202 /* GPE Handler */ 203 204 status_t (*update_all_gpes)(); 205 status_t (*enable_gpe)(acpi_handle handle, uint32 gpeNumber); 206 status_t (*disable_gpe)(acpi_handle handle, uint32 gpeNumber); 207 status_t (*clear_gpe)(acpi_handle handle, uint32 gpeNumber); 208 status_t (*set_gpe)(acpi_handle handle, uint32 gpeNumber, 209 uint8 action); 210 status_t (*finish_gpe)(acpi_handle handle, uint32 gpeNumber); 211 status_t (*install_gpe_handler)(acpi_handle handle, uint32 gpeNumber, 212 uint32 type, acpi_gpe_handler handler, void *data); 213 status_t (*remove_gpe_handler)(acpi_handle handle, uint32 gpeNumber, 214 acpi_gpe_handler address); 215 216 /* Address Space Handler */ 217 218 status_t (*install_address_space_handler)(acpi_handle handle, 219 uint32 spaceId, 220 acpi_adr_space_handler handler, 221 acpi_adr_space_setup setup, void *data); 222 status_t (*remove_address_space_handler)(acpi_handle handle, 223 uint32 spaceId, 224 acpi_adr_space_handler handler); 225 226 /* Fixed Event Management */ 227 228 void (*enable_fixed_event)(uint32 event); 229 void (*disable_fixed_event)(uint32 event); 230 231 uint32 (*fixed_event_status) (uint32 event); 232 /* Returns 1 if event set, 0 otherwise */ 233 void (*reset_fixed_event) (uint32 event); 234 235 status_t (*install_fixed_event_handler)(uint32 event, 236 acpi_event_handler handler, void *data); 237 status_t (*remove_fixed_event_handler)(uint32 event, 238 acpi_event_handler handler); 239 240 /* Namespace Access */ 241 242 status_t (*get_next_entry)(uint32 objectType, const char *base, 243 char *result, size_t length, void **_counter); 244 status_t (*get_next_object)(uint32 objectType, acpi_handle parent, 245 acpi_handle* currentChild); 246 status_t (*walk_namespace)(acpi_handle busDeviceHandle, 247 uint32 objectType, uint32 maxDepth, 248 acpi_walk_callback descendingCallback, 249 acpi_walk_callback ascendingCallback, void* context, 250 void** returnValue); 251 252 status_t (*get_device)(const char *hid, uint32 index, char *result, 253 size_t resultLength); 254 255 status_t (*get_device_info)(const char *path, char** hid, 256 char** cidList, size_t cidListLength, char** uid, char** cls); 257 uint32 (*get_object_type)(const char *path); 258 status_t (*get_object)(const char *path, 259 acpi_object_type **_returnValue); 260 status_t (*get_object_typed)(const char *path, 261 acpi_object_type **_returnValue, uint32 objectType); 262 status_t (*ns_handle_to_pathname)(acpi_handle targetHandle, 263 acpi_data *buffer); 264 265 /* Control method execution and data acquisition */ 266 267 status_t (*evaluate_object)(acpi_handle handle, const char* object, 268 acpi_objects *args, acpi_object_type *returnValue, size_t bufferLength); 269 status_t (*evaluate_method)(acpi_handle handle, const char *method, 270 acpi_objects *args, acpi_data *returnValue); 271 272 /* Resource Management */ 273 274 status_t (*get_irq_routing_table)(acpi_handle busDeviceHandle, 275 acpi_data *retBuffer); 276 status_t (*get_current_resources)(acpi_handle busDeviceHandle, 277 acpi_data *retBuffer); 278 status_t (*get_possible_resources)(acpi_handle busDeviceHandle, 279 acpi_data *retBuffer); 280 status_t (*set_current_resources)(acpi_handle busDeviceHandle, 281 acpi_data *buffer); 282 status_t (*walk_resources)(acpi_handle busDeviceHandle, 283 char *method, acpi_walk_resources_callback callback, 284 void* context); 285 286 /* Power state setting */ 287 288 status_t (*prepare_sleep_state)(uint8 state, void (*wakeFunc)(void), 289 size_t size); 290 status_t (*enter_sleep_state)(uint8 state); 291 status_t (*reboot)(void); 292 293 /* Table Access */ 294 status_t (*get_table)(const char *signature, uint32 instance, 295 void **tableHeader); 296 297 /* Register Access */ 298 status_t (*read_bit_register)(uint32 regid, uint32 *val); 299 status_t (*write_bit_register)(uint32 regid, uint32 val); 300 }; 301 302 303 /* Sleep states */ 304 305 enum { 306 ACPI_POWER_STATE_ON = 0, 307 ACPI_POWER_STATE_SLEEP_S1, 308 ACPI_POWER_STATE_SLEEP_S2, 309 ACPI_POWER_STATE_SLEEP_S3, 310 ACPI_POWER_STATE_HIBERNATE, 311 ACPI_POWER_STATE_OFF 312 }; 313 314 315 #define ACPI_DEVICE_ADDR_ITEM "acpi/addr" 316 #define ACPI_DEVICE_CID_ITEM "acpi/cid" 317 #define ACPI_DEVICE_HANDLE_ITEM "acpi/handle" 318 #define ACPI_DEVICE_HID_ITEM "acpi/hid" 319 #define ACPI_DEVICE_PATH_ITEM "acpi/path" 320 #define ACPI_DEVICE_TYPE_ITEM "acpi/type" 321 #define ACPI_DEVICE_UID_ITEM "acpi/uid" 322 323 324 typedef struct acpi_device_cookie *acpi_device; 325 326 // Interface to one ACPI device. 327 typedef struct acpi_device_module_info { 328 driver_module_info info; 329 330 /* Notify Handler */ 331 332 status_t (*install_notify_handler)(acpi_device device, 333 uint32 handlerType, acpi_notify_handler handler, 334 void *context); 335 status_t (*remove_notify_handler)(acpi_device device, 336 uint32 handlerType, acpi_notify_handler handler); 337 338 /* Address Space Handler */ 339 status_t (*install_address_space_handler)(acpi_device device, 340 uint32 spaceId, 341 acpi_adr_space_handler handler, 342 acpi_adr_space_setup setup, void *data); 343 status_t (*remove_address_space_handler)(acpi_device device, 344 uint32 spaceId, 345 acpi_adr_space_handler handler); 346 347 /* Namespace Access */ 348 uint32 (*get_object_type)(acpi_device device); 349 status_t (*get_object)(acpi_device device, const char *path, 350 acpi_object_type **_returnValue); 351 status_t (*walk_namespace)(acpi_device device, 352 uint32 objectType, uint32 maxDepth, 353 acpi_walk_callback descendingCallback, 354 acpi_walk_callback ascendingCallback, 355 void* context, void** returnValue); 356 357 /* Control method execution and data acquisition */ 358 status_t (*evaluate_method)(acpi_device device, const char *method, 359 acpi_objects *args, acpi_data *returnValue); 360 361 /* Resource Management */ 362 status_t (*walk_resources)(acpi_device device, char *method, 363 acpi_walk_resources_callback callback, void* context); 364 } acpi_device_module_info; 365 366 367 #endif /* _ACPI_H */ 368