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