1 /* 2 * Copyright 2009, Clemens Zeidler. All rights reserved. 3 * Copyright 2006, Jérôme Duval. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef _ACPI_PRIVATE_H 7 #define _ACPI_PRIVATE_H 8 9 10 #include <sys/cdefs.h> 11 12 #include <device_manager.h> 13 #include <KernelExport.h> 14 #include <ACPI.h> 15 #include <PCI.h> 16 17 // name of ACPI root module 18 #define ACPI_ROOT_MODULE_NAME "bus_managers/acpi/root/driver_v1" 19 20 // name of ACPI device modules 21 #define ACPI_DEVICE_MODULE_NAME "bus_managers/acpi/driver_v1" 22 23 // name of the ACPI namespace device 24 #define ACPI_NS_DUMP_DEVICE_MODULE_NAME "bus_managers/acpi/namespace/device_v1" 25 26 27 __BEGIN_DECLS 28 29 extern device_manager_info* gDeviceManager; 30 extern pci_module_info* gPCIManager; 31 32 // information about one ACPI device 33 typedef struct acpi_device_cookie { 34 char* path; // path 35 acpi_handle handle; 36 uint32 type; // type 37 device_node* node; 38 char name[32]; // name (for fast log) 39 } acpi_device_cookie; 40 41 42 typedef struct acpi_resource acpi_resource; 43 typedef acpi_status (*acpi_walk_resources_callback)(acpi_resource* resource, 44 void* context); 45 46 47 // ACPI root. 48 typedef struct acpi_root_info { 49 driver_module_info info; 50 51 status_t (*get_handle)(acpi_handle parent, const char *pathname, 52 acpi_handle *retHandle); 53 54 /* Global Lock */ 55 56 status_t (*acquire_global_lock)(uint16 timeout, uint32 *handle); 57 status_t (*release_global_lock)(uint32 handle); 58 59 /* Notify Handler */ 60 61 status_t (*install_notify_handler)(acpi_handle device, 62 uint32 handlerType, acpi_notify_handler handler, 63 void *context); 64 status_t (*remove_notify_handler)(acpi_handle device, 65 uint32 handlerType, acpi_notify_handler handler); 66 67 /* GPE Handler */ 68 status_t (*update_all_gpes)(); 69 status_t (*enable_gpe)(acpi_handle handle, uint32 gpeNumber); 70 status_t (*disable_gpe)(acpi_handle handle, uint32 gpeNumber); 71 status_t (*clear_gpe)(acpi_handle handle, uint32 gpeNumber); 72 status_t (*set_gpe)(acpi_handle handle, uint32 gpeNumber, 73 uint8 action); 74 status_t (*finish_gpe)(acpi_handle handle, uint32 gpeNumber); 75 status_t (*install_gpe_handler)(acpi_handle handle, uint32 gpeNumber, 76 uint32 type, acpi_gpe_handler handler, void *data); 77 status_t (*remove_gpe_handler)(acpi_handle handle, uint32 gpeNumber, 78 acpi_gpe_handler address); 79 80 /* Address Space Handler */ 81 82 status_t (*install_address_space_handler)(acpi_handle handle, 83 uint32 spaceId, 84 acpi_adr_space_handler handler, 85 acpi_adr_space_setup setup, void *data); 86 status_t (*remove_address_space_handler)(acpi_handle handle, 87 uint32 spaceId, 88 acpi_adr_space_handler handler); 89 90 /* Fixed Event Management */ 91 92 void (*enable_fixed_event)(uint32 event); 93 void (*disable_fixed_event)(uint32 event); 94 95 uint32 (*fixed_event_status) (uint32 event); 96 /* Returns 1 if event set, 0 otherwise */ 97 void (*reset_fixed_event) (uint32 event); 98 99 status_t (*install_fixed_event_handler)(uint32 event, 100 acpi_event_handler handler, void *data); 101 status_t (*remove_fixed_event_handler)(uint32 event, 102 acpi_event_handler handler); 103 104 /* Namespace Access */ 105 106 status_t (*get_next_entry)(uint32 objectType, const char *base, 107 char *result, size_t length, void **_counter); 108 status_t (*get_device)(const char *hid, uint32 index, char *result, 109 size_t resultLength); 110 111 status_t (*get_device_hid)(const char *path, char *hid, 112 size_t hidLength); 113 uint32 (*get_object_type)(const char *path); 114 status_t (*get_object)(const char *path, 115 acpi_object_type **_returnValue); 116 status_t (*get_object_typed)(const char *path, 117 acpi_object_type **_returnValue, uint32 objectType); 118 status_t (*ns_handle_to_pathname)(acpi_handle targetHandle, 119 acpi_data *buffer); 120 121 /* Control method execution and data acquisition */ 122 123 status_t (*evaluate_object)(acpi_handle handle, const char* object, 124 acpi_objects *args, acpi_object_type *returnValue, 125 size_t bufferLength); 126 status_t (*evaluate_method)(acpi_handle handle, const char *method, 127 acpi_objects *args, acpi_data *returnValue); 128 129 /* Resource info */ 130 131 status_t (*get_irq_routing_table)(acpi_handle busDeviceHandle, 132 acpi_data *retBuffer); 133 status_t (*get_current_resources)(acpi_handle busDeviceHandle, 134 acpi_data *retBuffer); 135 status_t (*get_possible_resources)(acpi_handle busDeviceHandle, 136 acpi_data *retBuffer); 137 status_t (*set_current_resources)(acpi_handle busDeviceHandle, 138 acpi_data *buffer); 139 status_t (*walk_resources)(acpi_handle busDeviceHandle, 140 char *method, acpi_walk_resources_callback callback, 141 void* context); 142 143 /* Power state setting */ 144 145 status_t (*prepare_sleep_state)(uint8 state, void (*wakeFunc)(void), 146 size_t size); 147 status_t (*enter_sleep_state)(uint8 state); 148 status_t (*reboot)(void); 149 150 /* Table Access */ 151 status_t (*get_table)(const char *signature, uint32 instance, 152 void **tableHeader); 153 } acpi_root_info; 154 155 156 extern struct acpi_module_info gACPIModule; 157 158 extern struct device_module_info acpi_ns_dump_module; 159 160 extern struct driver_module_info embedded_controller_driver_module; 161 extern struct device_module_info embedded_controller_device_module; 162 163 extern acpi_device_module_info gACPIDeviceModule; 164 165 166 status_t get_handle(acpi_handle parent, const char* pathname, 167 acpi_handle* retHandle); 168 169 status_t acquire_global_lock(uint16 timeout, uint32* handle); 170 status_t release_global_lock(uint32 handle); 171 172 status_t install_notify_handler(acpi_handle device, uint32 handlerType, 173 acpi_notify_handler handler, void* context); 174 status_t remove_notify_handler(acpi_handle device, uint32 handlerType, 175 acpi_notify_handler handler); 176 177 status_t update_all_gpes(); 178 status_t enable_gpe(acpi_handle handle, uint32 gpeNumber); 179 status_t disable_gpe(acpi_handle handle, uint32 gpeNumber); 180 status_t clear_gpe(acpi_handle handle, uint32 gpeNumber); 181 status_t set_gpe(acpi_handle handle, uint32 gpeNumber, uint8 action); 182 status_t finish_gpe(acpi_handle handle, uint32 gpeNumber); 183 status_t install_gpe_handler(acpi_handle handle, uint32 gpeNumber, uint32 type, 184 acpi_gpe_handler handler, void* data); 185 status_t remove_gpe_handler(acpi_handle handle, uint32 gpeNumber, 186 acpi_gpe_handler address); 187 188 status_t install_address_space_handler(acpi_handle handle, uint32 spaceID, 189 acpi_adr_space_handler handler, acpi_adr_space_setup setup, void* data); 190 status_t remove_address_space_handler(acpi_handle handle, uint32 spaceID, 191 acpi_adr_space_handler handler); 192 193 void enable_fixed_event(uint32 event); 194 void disable_fixed_event(uint32 event); 195 196 uint32 fixed_event_status(uint32 event); 197 void reset_fixed_event(uint32 event); 198 199 status_t install_fixed_event_handler(uint32 event, acpi_event_handler handler, 200 void* data); 201 status_t remove_fixed_event_handler(uint32 event, acpi_event_handler handler); 202 203 status_t get_next_entry(uint32 object_type, const char* base, char* result, 204 size_t length, void** _counter); 205 status_t get_device(const char* hid, uint32 index, char* result, 206 size_t resultLength); 207 208 status_t get_device_hid(const char* path, char* hid, size_t hidLength); 209 uint32 get_object_type(const char* path); 210 status_t get_object(const char* path, acpi_object_type** _returnValue); 211 status_t get_object_typed(const char* path, acpi_object_type** _returnValue, 212 uint32 object_type); 213 status_t ns_handle_to_pathname(acpi_handle targetHandle, acpi_data* buffer); 214 215 status_t evaluate_object(acpi_handle handle, const char* object, 216 acpi_objects* args, acpi_object_type* returnValue, size_t bufferLength); 217 status_t evaluate_method(acpi_handle handle, const char* method, 218 acpi_objects* args, acpi_data* returnValue); 219 220 status_t get_irq_routing_table(acpi_handle busDeviceHandle, 221 acpi_data* returnValue); 222 status_t get_current_resources(acpi_handle busDeviceHandle, 223 acpi_data* returnValue); 224 status_t get_possible_resources(acpi_handle busDeviceHandle, 225 acpi_data* returnValue); 226 status_t set_current_resources(acpi_handle busDeviceHandle, 227 acpi_data* buffer); 228 status_t walk_resources(acpi_handle busDeviceHandle, char* method, 229 acpi_walk_resources_callback callback, void* context); 230 231 status_t prepare_sleep_state(uint8 state, void (*wakeFunc)(void), size_t size); 232 status_t enter_sleep_state(uint8 state); 233 234 status_t reboot(void); 235 236 status_t get_table(const char* signature, uint32 instance, void** tableHeader); 237 238 __END_DECLS 239 240 241 #endif /* _ACPI_PRIVATE_H */ 242