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 struct acpi_module_info { 19 module_info info; 20 21 /* Fixed Event Management */ 22 23 void (*enable_fixed_event)(uint32 event); 24 void (*disable_fixed_event)(uint32 event); 25 26 uint32 (*fixed_event_status) (uint32 event); 27 /* Returns 1 if event set, 0 otherwise */ 28 void (*reset_fixed_event) (uint32 event); 29 30 status_t (*install_fixed_event_handler)(uint32 event, 31 interrupt_handler *handler, void *data); 32 status_t (*remove_fixed_event_handler)(uint32 event, 33 interrupt_handler *handler); 34 35 /* Namespace Access */ 36 37 status_t (*get_next_entry)(uint32 objectType, const char *base, 38 char *result, size_t length, void **_counter); 39 status_t (*get_device)(const char *hid, uint32 index, char *result, 40 size_t resultLength); 41 42 status_t (*get_device_hid)(const char *path, char *hid); 43 uint32 (*get_object_type)(const char *path); 44 status_t (*get_object)(const char *path, 45 acpi_object_type **_returnValue); 46 status_t (*get_object_typed)(const char *path, 47 acpi_object_type **_returnValue, uint32 objectType); 48 49 /* Control method execution and data acquisition */ 50 51 status_t (*evaluate_object)(const char *object, 52 acpi_object_type *returnValue, size_t bufferLength); 53 status_t (*evaluate_method)(const char *object, const char *method, 54 acpi_object_type *returnValue, size_t bufferLength, 55 acpi_object_type *args, int numArgs); 56 57 /* Power state setting */ 58 59 status_t (*prepare_sleep_state)(uint8 state, void (*wakeFunc)(void), 60 size_t size); 61 status_t (*enter_sleep_state)(uint8 state); 62 }; 63 64 65 #ifndef __ACTYPES_H__ 66 67 /* ACPI fixed event types */ 68 69 enum { 70 ACPI_EVENT_PMTIMER = 0, 71 ACPI_EVENT_GLOBAL, 72 ACPI_EVENT_POWER_BUTTON, 73 ACPI_EVENT_SLEEP_BUTTON, 74 ACPI_EVENT_RTC 75 }; 76 77 /* ACPI Object Types */ 78 79 enum { 80 ACPI_TYPE_ANY = 0, 81 ACPI_TYPE_INTEGER, 82 ACPI_TYPE_STRING, 83 ACPI_TYPE_BUFFER, 84 ACPI_TYPE_PACKAGE, 85 ACPI_TYPE_FIELD_UNIT, 86 ACPI_TYPE_DEVICE, 87 ACPI_TYPE_EVENT, 88 ACPI_TYPE_METHOD, 89 ACPI_TYPE_MUTEX, 90 ACPI_TYPE_REGION, 91 ACPI_TYPE_POWER, 92 ACPI_TYPE_PROCESSOR, 93 ACPI_TYPE_THERMAL, 94 ACPI_TYPE_BUFFER_FIELD 95 }; 96 97 /* ACPI control method arg type */ 98 99 struct acpi_object_type { 100 uint32 object_type; 101 union { 102 uint32 integer; 103 struct { 104 uint32 len; 105 char *string; /* You have to allocate string space yourself */ 106 } string; 107 struct { 108 size_t length; 109 void *buffer; 110 } buffer; 111 struct { 112 uint32 count; 113 acpi_object_type *objects; 114 } package; 115 struct { 116 uint32 cpu_id; 117 118 int pblk_address; 119 size_t pblk_length; 120 } processor; 121 struct { 122 uint32 min_power_state; 123 uint32 resource_order; 124 } power_resource; 125 } data; 126 }; 127 128 #endif // __ACTYPES_H__ 129 130 /* Sleep states */ 131 132 enum { 133 ACPI_POWER_STATE_ON = 0, 134 ACPI_POWER_STATE_SLEEP_S1, 135 ACPI_POWER_STATE_SLEEP_S2, 136 ACPI_POWER_STATE_SLEEP_S3, 137 ACPI_POWER_STATE_HIBERNATE, 138 ACPI_POWER_STATE_OFF 139 }; 140 141 142 #define ACPI_DEVICE_HID_ITEM "acpi/hid" 143 #define ACPI_DEVICE_PATH_ITEM "acpi/path" 144 #define ACPI_DEVICE_TYPE_ITEM "acpi/type" 145 146 147 typedef struct acpi_device_info *acpi_device; 148 149 // Interface to one ACPI device. 150 typedef struct acpi_device_module_info { 151 driver_module_info info; 152 153 /* Namespace Access */ 154 uint32 (*get_object_type)(acpi_device device); 155 status_t (*get_object)(acpi_device device, const char *path, 156 acpi_object_type **_returnValue); 157 158 /* Control method execution and data acquisition */ 159 status_t (*evaluate_method)(acpi_device device, const char *method, 160 acpi_object_type *returnValue, size_t bufferLength, 161 acpi_object_type *args, int numArgs); 162 } acpi_device_module_info; 163 164 165 #endif /* _ACPI_H */ 166