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 struct acpi_object_type acpi_object_type; 15 16 #define B_ACPI_MODULE_NAME "bus_managers/acpi/v1" 17 18 typedef addr_t acpi_physical_address; 19 typedef 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 /* Address Space (Operation Region) Types */ 28 29 enum { 30 ACPI_ADR_SPACE_SYSTEM_MEMORY = 0, 31 ACPI_ADR_SPACE_SYSTEM_IO = 1, 32 ACPI_ADR_SPACE_PCI_CONFIG = 2, 33 ACPI_ADR_SPACE_EC = 3, 34 ACPI_ADR_SPACE_SMBUS = 4, 35 ACPI_ADR_SPACE_CMOS = 5, 36 ACPI_ADR_SPACE_PCI_BAR_TARGET = 6, 37 ACPI_ADR_SPACE_DATA_TABLE = 7, 38 ACPI_ADR_SPACE_FIXED_HARDWARE = 127 39 }; 40 41 /* ACPI fixed event types */ 42 43 enum { 44 ACPI_EVENT_PMTIMER = 0, 45 ACPI_EVENT_GLOBAL, 46 ACPI_EVENT_POWER_BUTTON, 47 ACPI_EVENT_SLEEP_BUTTON, 48 ACPI_EVENT_RTC 49 }; 50 51 /* ACPI Object Types */ 52 53 enum { 54 ACPI_TYPE_ANY = 0, 55 ACPI_TYPE_INTEGER, 56 ACPI_TYPE_STRING, 57 ACPI_TYPE_BUFFER, 58 ACPI_TYPE_PACKAGE, 59 ACPI_TYPE_FIELD_UNIT, 60 ACPI_TYPE_DEVICE, 61 ACPI_TYPE_EVENT, 62 ACPI_TYPE_METHOD, 63 ACPI_TYPE_MUTEX, 64 ACPI_TYPE_REGION, 65 ACPI_TYPE_POWER, 66 ACPI_TYPE_PROCESSOR, 67 ACPI_TYPE_THERMAL, 68 ACPI_TYPE_BUFFER_FIELD, 69 ACPI_TYPE_LOCAL_REFERENCE = 0x14 70 }; 71 72 /* ACPI control method arg type */ 73 74 struct acpi_object_type { 75 uint32 object_type; 76 union { 77 uint32 integer; 78 struct { 79 uint32 len; 80 char *string; /* You have to allocate string space yourself */ 81 } string; 82 struct { 83 size_t length; 84 void *buffer; 85 } buffer; 86 struct { 87 uint32 count; 88 acpi_object_type *objects; 89 } package; 90 struct { 91 uint32 actual_type; 92 acpi_handle handle; 93 } reference; 94 struct { 95 uint32 cpu_id; 96 int pblk_address; 97 size_t pblk_length; 98 } processor; 99 struct { 100 uint32 min_power_state; 101 uint32 resource_order; 102 } power_resource; 103 } data; 104 }; 105 106 107 /* 108 * List of objects, used as a parameter list for control method evaluation 109 */ 110 typedef struct acpi_objects { 111 uint32 count; 112 acpi_object_type *pointer; 113 } acpi_objects; 114 115 116 typedef struct acpi_data { 117 acpi_size length; /* Length in bytes of the buffer */ 118 void *pointer; /* pointer to buffer */ 119 } acpi_data; 120 121 122 enum { 123 ACPI_ALLOCATE_BUFFER = -1, 124 }; 125 126 127 #endif // __ACTYPES_H__ 128 129 130 #ifndef __ACRESTYP_H__ 131 132 133 typedef struct acpi_prt 134 { 135 uint32 length; 136 uint32 pin; 137 int address; /* here for 64-bit alignment */ 138 uint32 sourceIndex; 139 char source[4]; /* pad to 64 bits so sizeof() works in 140 all cases */ 141 } acpi_pci_routing_table; 142 143 144 #endif // __ACRESTYP_H__ 145 146 147 typedef uint32 (*acpi_event_handler)(void *Context); 148 149 typedef status_t (*acpi_adr_space_handler)(uint32 function, 150 acpi_physical_address address, uint32 bitWidth, int *value, 151 void *handlerContext, void *regionContext); 152 153 typedef status_t (*acpi_adr_space_setup)(acpi_handle regionHandle, 154 uint32 function, void *handlerContext, void **regionContext); 155 156 typedef void (*acpi_notify_handler)(acpi_handle device, uint32 value, 157 void *context); 158 159 160 struct acpi_module_info { 161 module_info info; 162 163 status_t (*get_handle)(acpi_handle parent, char *pathname, 164 acpi_handle *retHandle); 165 166 /* Global Lock */ 167 168 status_t (*acquire_global_lock)(uint16 timeout, uint32 *handle); 169 status_t (*release_global_lock)(uint32 handle); 170 171 /* Notify Handler */ 172 173 status_t (*install_notify_handler)(acpi_handle device, 174 uint32 handlerType, acpi_notify_handler handler, 175 void *context); 176 status_t (*remove_notify_handler)(acpi_handle device, 177 uint32 handlerType, acpi_notify_handler handler); 178 179 /* GPE Handler */ 180 181 status_t (*enable_gpe)(acpi_handle handle, uint32 gpeNumber, 182 uint32 flags); 183 status_t (*set_gpe_type)(acpi_handle handle, uint32 gpeNumber, 184 uint8 type); 185 status_t (*install_gpe_handler)(acpi_handle handle, uint32 gpeNumber, 186 uint32 type, acpi_event_handler handler, void *data); 187 status_t (*remove_gpe_handler)(acpi_handle handle, uint32 gpeNumber, 188 acpi_event_handler address); 189 190 /* Address Space Handler */ 191 192 status_t (*install_address_space_handler)(acpi_handle handle, 193 uint32 spaceId, 194 acpi_adr_space_handler handler, 195 acpi_adr_space_setup setup, void *data); 196 status_t (*remove_address_space_handler)(acpi_handle handle, 197 uint32 spaceId, 198 acpi_adr_space_handler handler); 199 200 /* Fixed Event Management */ 201 202 void (*enable_fixed_event)(uint32 event); 203 void (*disable_fixed_event)(uint32 event); 204 205 uint32 (*fixed_event_status) (uint32 event); 206 /* Returns 1 if event set, 0 otherwise */ 207 void (*reset_fixed_event) (uint32 event); 208 209 status_t (*install_fixed_event_handler)(uint32 event, 210 interrupt_handler *handler, void *data); 211 status_t (*remove_fixed_event_handler)(uint32 event, 212 interrupt_handler *handler); 213 214 /* Namespace Access */ 215 216 status_t (*get_next_entry)(uint32 objectType, const char *base, 217 char *result, size_t length, void **_counter); 218 status_t (*get_device)(const char *hid, uint32 index, char *result, 219 size_t resultLength); 220 221 status_t (*get_device_hid)(const char *path, char *hid, 222 size_t hidLength); 223 uint32 (*get_object_type)(const char *path); 224 status_t (*get_object)(const char *path, 225 acpi_object_type **_returnValue); 226 status_t (*get_object_typed)(const char *path, 227 acpi_object_type **_returnValue, uint32 objectType); 228 status_t (*ns_handle_to_pathname)(acpi_handle targetHandle, 229 acpi_data *buffer); 230 231 /* Control method execution and data acquisition */ 232 233 status_t (*evaluate_object)(const char* object, 234 acpi_object_type *returnValue, size_t bufferLength); 235 status_t (*evaluate_method)(acpi_handle handle, const char *method, 236 acpi_objects *args, acpi_data *returnValue); 237 238 /* Resource info */ 239 240 status_t (*get_irq_routing_table)(acpi_handle busDeviceHandle, 241 acpi_data *retBuffer); 242 243 /* Power state setting */ 244 245 status_t (*prepare_sleep_state)(uint8 state, void (*wakeFunc)(void), 246 size_t size); 247 status_t (*enter_sleep_state)(uint8 state); 248 status_t (*reboot)(void); 249 }; 250 251 252 /* Sleep states */ 253 254 enum { 255 ACPI_POWER_STATE_ON = 0, 256 ACPI_POWER_STATE_SLEEP_S1, 257 ACPI_POWER_STATE_SLEEP_S2, 258 ACPI_POWER_STATE_SLEEP_S3, 259 ACPI_POWER_STATE_HIBERNATE, 260 ACPI_POWER_STATE_OFF 261 }; 262 263 264 #define ACPI_DEVICE_HID_ITEM "acpi/hid" 265 #define ACPI_DEVICE_PATH_ITEM "acpi/path" 266 #define ACPI_DEVICE_TYPE_ITEM "acpi/type" 267 268 269 typedef struct acpi_device_cookie *acpi_device; 270 271 // Interface to one ACPI device. 272 typedef struct acpi_device_module_info { 273 driver_module_info info; 274 275 /* Notify Handler */ 276 277 status_t (*install_notify_handler)(acpi_device device, 278 uint32 handlerType, acpi_notify_handler handler, 279 void *context); 280 status_t (*remove_notify_handler)(acpi_device device, 281 uint32 handlerType, acpi_notify_handler handler); 282 283 /* Address Space Handler */ 284 status_t (*install_address_space_handler)(acpi_device device, 285 uint32 spaceId, 286 acpi_adr_space_handler handler, 287 acpi_adr_space_setup setup, void *data); 288 status_t (*remove_address_space_handler)(acpi_device device, 289 uint32 spaceId, 290 acpi_adr_space_handler handler); 291 292 /* Namespace Access */ 293 uint32 (*get_object_type)(acpi_device device); 294 status_t (*get_object)(acpi_device device, const char *path, 295 acpi_object_type **_returnValue); 296 297 /* Control method execution and data acquisition */ 298 status_t (*evaluate_method)(acpi_device device, const char *method, 299 acpi_objects *args, acpi_data *returnValue); 300 } acpi_device_module_info; 301 302 303 #endif /* _ACPI_H */ 304