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