1 /* 2 * Copyright 2020, Jérôme Duval, jerome.duval@gmail.com. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef WMI_PRIVATE_H 6 #define WMI_PRIVATE_H 7 8 9 #include <ACPI.h> 10 #include <new> 11 #include <stdio.h> 12 #include <string.h> 13 14 #include <lock.h> 15 #include <smbios.h> 16 #include <util/AutoLock.h> 17 #include <util/DoublyLinkedList.h> 18 #include <wmi.h> 19 20 21 //#define WMI_TRACE 22 #ifndef DRIVER_NAME 23 # define DRIVER_NAME "wmi" 24 #endif 25 #ifdef WMI_TRACE 26 # define TRACE(x...) dprintf("\33[33m" DRIVER_NAME ":\33[0m " x) 27 #else 28 # define TRACE(x...) 29 #endif 30 #define TRACE_ALWAYS(x...) dprintf("\33[33m" DRIVER_NAME ":\33[0m " x) 31 #define ERROR(x...) TRACE_ALWAYS(x) 32 #define CALLED() TRACE("CALLED %s\n", __PRETTY_FUNCTION__) 33 34 35 #define WMI_ACPI_DRIVER_NAME "drivers/wmi/acpi/driver_v1" 36 #define WMI_DEVICE_MODULE_NAME "drivers/wmi/device/driver_v1" 37 38 #define WMI_ASUS_DRIVER_NAME "drivers/wmi/asus/driver_v1" 39 40 #define WMI_BUS_COOKIE "wmi/bus/index" 41 42 43 class WMIACPI; 44 class WMIDevice; 45 46 47 extern device_manager_info *gDeviceManager; 48 extern smbios_module_info *gSMBios; 49 extern wmi_device_interface gWMIDeviceModule; 50 extern driver_module_info gWMIAsusDriverModule; 51 52 53 class WMIDevice { 54 public: 55 WMIDevice(device_node* node); 56 ~WMIDevice(); 57 58 status_t InitCheck(); 59 status_t EvaluateMethod(uint8 instance, uint32 methodId, 60 const acpi_data* in, acpi_data* out); 61 status_t InstallEventHandler(const char* guidString, 62 acpi_notify_handler handler, void* context); 63 status_t RemoveEventHandler(const char* guidString); 64 status_t GetEventData(uint32 notify, acpi_data* out); 65 const char* GetUid(); 66 private: 67 68 private: 69 device_node* fNode; 70 WMIACPI* fBus; 71 uint32 fBusCookie; 72 status_t fInitStatus; 73 }; 74 75 76 typedef struct { 77 uint8 guid[16]; 78 union { 79 char oid[2]; 80 struct { 81 uint8 notify_id; 82 }; 83 }; 84 uint8 max_instance; 85 uint8 flags; 86 } guid_info; 87 88 89 struct wmi_info; 90 typedef struct wmi_info : DoublyLinkedListLinkImpl<wmi_info> { 91 guid_info guid; 92 acpi_notify_handler handler; 93 void* handler_context; 94 } wmi_info; 95 typedef DoublyLinkedList<wmi_info> WMIInfoList; 96 97 98 99 class WMIACPI { 100 public: 101 WMIACPI(device_node *node); 102 ~WMIACPI(); 103 104 status_t InitCheck(); 105 106 status_t Scan(); 107 108 status_t GetBlock(uint32 busCookie, 109 uint8 instance, uint32 methodId, 110 acpi_data* out); 111 status_t SetBlock(uint32 busCookie, 112 uint8 instance, uint32 methodId, 113 const acpi_data* in); 114 status_t EvaluateMethod(uint32 busCookie, 115 uint8 instance, uint32 methodId, 116 const acpi_data* in, acpi_data* out); 117 status_t InstallEventHandler(const char* guidString, 118 acpi_notify_handler handler, void* context); 119 status_t RemoveEventHandler(const char* guidString); 120 status_t GetEventData(uint32 notify, acpi_data* out); 121 const char* GetUid(uint32 busCookie); 122 private: 123 status_t _SetEventGeneration(wmi_info* info, 124 bool enabled); 125 status_t _EvaluateMethodSimple(const char* method, 126 uint64 integer); 127 void _Notify(acpi_handle device, uint32 value); 128 static void _NotifyHandler(acpi_handle device, 129 uint32 value, void *context); 130 131 void _GuidToGuidString(uint8 guid[16], 132 char* guidString); 133 private: 134 device_node* fNode; 135 acpi_device_module_info* acpi; 136 acpi_device acpi_cookie; 137 status_t fStatus; 138 WMIInfoList fList; 139 wmi_info* fWMIInfos; 140 uint32 fWMIInfoCount; 141 const char* fUid; 142 }; 143 144 145 #endif // WMI_PRIVATE_H 146