1c2c66affSColin Finck /*
2c2c66affSColin Finck * PROJECT: ReactOS i8042 (ps/2 keyboard-mouse controller) driver
3c2c66affSColin Finck * LICENSE: GPL - See COPYING in the top level directory
4c2c66affSColin Finck * FILE: drivers/input/i8042prt/hwhacks.c
5c2c66affSColin Finck * PURPOSE: Mouse specific functions
6c2c66affSColin Finck * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
7c2c66affSColin Finck * REFERENCES: - http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.0.0.pdf
8c2c66affSColin Finck * -
9c2c66affSColin Finck */
10c2c66affSColin Finck
11c2c66affSColin Finck #include "i8042prt.h"
12c2c66affSColin Finck #include <wmiguid.h>
13c2c66affSColin Finck #include <wmidata.h>
14c2c66affSColin Finck #include <wmistr.h>
150854c69aSStanislav Motylkov #include <dmilib.h>
16c2c66affSColin Finck
17c2c66affSColin Finck #define NDEBUG
18c2c66affSColin Finck #include <debug.h>
19c2c66affSColin Finck
20c2c66affSColin Finck const GUID MSSmBios_RawSMBiosTables_GUID = SMBIOS_DATA_GUID;
21c2c66affSColin Finck PVOID i8042SMBiosTables;
22c2c66affSColin Finck ULONG i8042HwFlags;
23c2c66affSColin Finck
24c2c66affSColin Finck typedef struct _MATCHENTRY
25c2c66affSColin Finck {
26c2c66affSColin Finck ULONG Type;
27c2c66affSColin Finck PCHAR String;
28c2c66affSColin Finck } MATCHENTRY;
29c2c66affSColin Finck
30c2c66affSColin Finck #define MAX_MATCH_ENTRIES 3
31c2c66affSColin Finck typedef struct _HARDWARE_TABLE
32c2c66affSColin Finck {
33c2c66affSColin Finck MATCHENTRY MatchEntries[MAX_MATCH_ENTRIES];
34c2c66affSColin Finck ULONG Flags;
35c2c66affSColin Finck } HARDWARE_TABLE;
36c2c66affSColin Finck
37c2c66affSColin Finck const HARDWARE_TABLE i8042HardwareTable[] =
38c2c66affSColin Finck {
39c2c66affSColin Finck // { {{BOARD_VENDOR, "RIOWORKS"}, {BOARD_NAME, "HDAMB"}, {BOARD_VERSION, "Rev E"}}, FL_NOLOOP },
40c2c66affSColin Finck // { {{BOARD_VENDOR, "ASUSTeK Computer Inc."}, {BOARD_NAME, "G1S"}, {BOARD_VERSION, "1.0"}}, FL_NOLOOP },
41c2c66affSColin Finck
42c2c66affSColin Finck { {{SYS_VENDOR, "Microsoft Corporation"}, {SYS_PRODUCT, "Virtual Machine"}}, FL_INITHACK },
43c2c66affSColin Finck { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Inspiron 6000 "}}, FL_INITHACK },
44*058726a2SVincent Franchomme { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D410 "}}, FL_INITHACK },
45c2c66affSColin Finck { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D430 "}}, FL_INITHACK },
46c2c66affSColin Finck { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D530 "}}, FL_INITHACK },
47c2c66affSColin Finck { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D531 "}}, FL_INITHACK },
48c2c66affSColin Finck { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D600 "}}, FL_INITHACK },
498ea42001SDoug Lyons { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D610 "}}, FL_INITHACK },
50c2c66affSColin Finck { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D620 "}}, FL_INITHACK },
51c2c66affSColin Finck { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D630 "}}, FL_INITHACK },
52c2c66affSColin Finck { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D810 "}}, FL_INITHACK },
5399a6d037SScott Maday { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D820 "}}, FL_INITHACK },
54c2c66affSColin Finck { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude E4300 "}}, FL_INITHACK },
55c2c66affSColin Finck { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude E4310 "}}, FL_INITHACK },
56939b25a1SBenjamin Aerni { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude E6400 "}}, FL_INITHACK },
57c2c66affSColin Finck
58c2c66affSColin Finck };
59c2c66affSColin Finck
60c2c66affSColin Finck
61c2c66affSColin Finck
62c2c66affSColin Finck static
63c2c66affSColin Finck VOID
i8042ParseSMBiosTables(_In_reads_bytes_ (TableSize)PVOID SMBiosTables,_In_ ULONG TableSize)64c2c66affSColin Finck i8042ParseSMBiosTables(
65c2c66affSColin Finck _In_reads_bytes_(TableSize) PVOID SMBiosTables,
66c2c66affSColin Finck _In_ ULONG TableSize)
67c2c66affSColin Finck {
680854c69aSStanislav Motylkov ULONG i, j;
69c2c66affSColin Finck PCHAR Strings[ID_STRINGS_MAX] = { 0 };
70c2c66affSColin Finck
710854c69aSStanislav Motylkov ParseSMBiosTables(SMBiosTables, TableSize, Strings);
72c2c66affSColin Finck
73c2c66affSColin Finck #if 0 // DBG
74c2c66affSColin Finck DbgPrint("i8042prt: Dumping DMI data:\n");
75c2c66affSColin Finck DbgPrint("BIOS_VENDOR: %s\n", Strings[BIOS_VENDOR]);
76c2c66affSColin Finck DbgPrint("BIOS_VERSION: %s\n", Strings[BIOS_VERSION]);
77c2c66affSColin Finck DbgPrint("BIOS_DATE: %s\n", Strings[BIOS_DATE]);
78c2c66affSColin Finck DbgPrint("SYS_VENDOR: %s\n", Strings[SYS_VENDOR]);
79c2c66affSColin Finck DbgPrint("SYS_PRODUCT: %s\n", Strings[SYS_PRODUCT]);
80c2c66affSColin Finck DbgPrint("SYS_VERSION: %s\n", Strings[SYS_VERSION]);
81c2c66affSColin Finck DbgPrint("SYS_SERIAL: %s\n", Strings[SYS_SERIAL]);
82c2c66affSColin Finck DbgPrint("BOARD_VENDOR: %s\n", Strings[BOARD_VENDOR]);
83c2c66affSColin Finck DbgPrint("BOARD_NAME: %s\n", Strings[BOARD_NAME]);
84c2c66affSColin Finck DbgPrint("BOARD_VERSION: %s\n", Strings[BOARD_VERSION]);
85c2c66affSColin Finck DbgPrint("BOARD_SERIAL: %s\n", Strings[BOARD_SERIAL]);
86c2c66affSColin Finck DbgPrint("BOARD_ASSET_TAG: %s\n", Strings[BOARD_ASSET_TAG]);
87c2c66affSColin Finck #endif
88c2c66affSColin Finck
89c2c66affSColin Finck /* Now loop the hardware table to find a match */
90c2c66affSColin Finck for (i = 0; i < ARRAYSIZE(i8042HardwareTable); i++)
91c2c66affSColin Finck {
92c2c66affSColin Finck for (j = 0; j < MAX_MATCH_ENTRIES; j++)
93c2c66affSColin Finck {
94c2c66affSColin Finck ULONG Type = i8042HardwareTable[i].MatchEntries[j].Type;
95c2c66affSColin Finck
96c2c66affSColin Finck if (Type != ID_NONE)
97c2c66affSColin Finck {
98c2c66affSColin Finck /* Check for a match */
99c2c66affSColin Finck if ((Strings[Type] == NULL) ||
100c2c66affSColin Finck strcmp(i8042HardwareTable[i].MatchEntries[j].String,
101c2c66affSColin Finck Strings[i8042HardwareTable[i].MatchEntries[j].Type]))
102c2c66affSColin Finck {
103c2c66affSColin Finck /* Does not match, try next entry */
104c2c66affSColin Finck break;
105c2c66affSColin Finck }
106c2c66affSColin Finck }
107c2c66affSColin Finck }
108c2c66affSColin Finck
109c2c66affSColin Finck if (j == MAX_MATCH_ENTRIES)
110c2c66affSColin Finck {
111c2c66affSColin Finck /* All items matched! */
112c2c66affSColin Finck i8042HwFlags = i8042HardwareTable[i].Flags;
113c2c66affSColin Finck DPRINT("Found match for hw table index %u\n", i);
114c2c66affSColin Finck break;
115c2c66affSColin Finck }
116c2c66affSColin Finck }
117c2c66affSColin Finck }
118c2c66affSColin Finck
119a9f20984SStanislav Motylkov static
120a9f20984SStanislav Motylkov VOID
i8042StoreSMBiosTables(_In_reads_bytes_ (TableSize)PVOID SMBiosTables,_In_ ULONG TableSize)121a9f20984SStanislav Motylkov i8042StoreSMBiosTables(
122a9f20984SStanislav Motylkov _In_reads_bytes_(TableSize) PVOID SMBiosTables,
123a9f20984SStanislav Motylkov _In_ ULONG TableSize)
124a9f20984SStanislav Motylkov {
125a9f20984SStanislav Motylkov static UNICODE_STRING mssmbiosKeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services\\mssmbios");
126a9f20984SStanislav Motylkov static UNICODE_STRING DataName = RTL_CONSTANT_STRING(L"Data");
127a9f20984SStanislav Motylkov static UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"SMBiosData");
128a9f20984SStanislav Motylkov OBJECT_ATTRIBUTES ObjectAttributes;
129a9f20984SStanislav Motylkov HANDLE KeyHandle = NULL, SubKeyHandle = NULL;
130a9f20984SStanislav Motylkov NTSTATUS Status;
131a9f20984SStanislav Motylkov
132a9f20984SStanislav Motylkov /* Create registry key */
133a9f20984SStanislav Motylkov InitializeObjectAttributes(&ObjectAttributes,
134a9f20984SStanislav Motylkov &mssmbiosKeyName,
135a9f20984SStanislav Motylkov OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
136a9f20984SStanislav Motylkov NULL,
137a9f20984SStanislav Motylkov NULL);
138a9f20984SStanislav Motylkov Status = ZwCreateKey(&KeyHandle,
139a9f20984SStanislav Motylkov KEY_WRITE,
140a9f20984SStanislav Motylkov &ObjectAttributes,
141a9f20984SStanislav Motylkov 0,
142a9f20984SStanislav Motylkov NULL,
143a9f20984SStanislav Motylkov REG_OPTION_VOLATILE,
144a9f20984SStanislav Motylkov NULL);
145a9f20984SStanislav Motylkov
146a9f20984SStanislav Motylkov if (!NT_SUCCESS(Status))
147a9f20984SStanislav Motylkov {
148a9f20984SStanislav Motylkov return;
149a9f20984SStanislav Motylkov }
150a9f20984SStanislav Motylkov
151a9f20984SStanislav Motylkov /* Create sub key */
152a9f20984SStanislav Motylkov InitializeObjectAttributes(&ObjectAttributes,
153a9f20984SStanislav Motylkov &DataName,
154a9f20984SStanislav Motylkov OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
155a9f20984SStanislav Motylkov KeyHandle,
156a9f20984SStanislav Motylkov NULL);
157a9f20984SStanislav Motylkov Status = ZwCreateKey(&SubKeyHandle,
158a9f20984SStanislav Motylkov KEY_WRITE,
159a9f20984SStanislav Motylkov &ObjectAttributes,
160a9f20984SStanislav Motylkov 0,
161a9f20984SStanislav Motylkov NULL,
162a9f20984SStanislav Motylkov REG_OPTION_VOLATILE,
163a9f20984SStanislav Motylkov NULL);
164a9f20984SStanislav Motylkov
165a9f20984SStanislav Motylkov if (!NT_SUCCESS(Status))
166a9f20984SStanislav Motylkov {
167a9f20984SStanislav Motylkov ZwClose(KeyHandle);
168a9f20984SStanislav Motylkov return;
169a9f20984SStanislav Motylkov }
170a9f20984SStanislav Motylkov
171a9f20984SStanislav Motylkov /* Write value */
172a9f20984SStanislav Motylkov ZwSetValueKey(SubKeyHandle,
173a9f20984SStanislav Motylkov &ValueName,
174a9f20984SStanislav Motylkov 0,
175a9f20984SStanislav Motylkov REG_BINARY,
176a9f20984SStanislav Motylkov SMBiosTables,
177a9f20984SStanislav Motylkov TableSize);
178a9f20984SStanislav Motylkov
179a9f20984SStanislav Motylkov ZwClose(SubKeyHandle);
180a9f20984SStanislav Motylkov ZwClose(KeyHandle);
181a9f20984SStanislav Motylkov }
182a9f20984SStanislav Motylkov
183c2c66affSColin Finck VOID
184c2c66affSColin Finck NTAPI
i8042InitializeHwHacks(VOID)185c2c66affSColin Finck i8042InitializeHwHacks(
186c2c66affSColin Finck VOID)
187c2c66affSColin Finck {
188c2c66affSColin Finck NTSTATUS Status;
189c2c66affSColin Finck PVOID DataBlockObject;
190c2c66affSColin Finck PWNODE_ALL_DATA AllData;
191c2c66affSColin Finck ULONG BufferSize;
192c2c66affSColin Finck
193c2c66affSColin Finck /* Open the data block object for the SMBIOS table */
194c2c66affSColin Finck Status = IoWMIOpenBlock(&MSSmBios_RawSMBiosTables_GUID,
195c2c66affSColin Finck WMIGUID_QUERY,
196c2c66affSColin Finck &DataBlockObject);
197c2c66affSColin Finck if (!NT_SUCCESS(Status))
198c2c66affSColin Finck {
199c2c66affSColin Finck DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
200c2c66affSColin Finck return;
201c2c66affSColin Finck }
202c2c66affSColin Finck
203c2c66affSColin Finck /* Query the required buffer size */
204c2c66affSColin Finck BufferSize = 0;
205c2c66affSColin Finck Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, NULL);
206c2c66affSColin Finck if (!NT_SUCCESS(Status))
207c2c66affSColin Finck {
208c2c66affSColin Finck DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
209c2c66affSColin Finck return;
210c2c66affSColin Finck }
211c2c66affSColin Finck
212c2c66affSColin Finck AllData = ExAllocatePoolWithTag(PagedPool, BufferSize, 'BTMS');
213c2c66affSColin Finck if (AllData == NULL)
214c2c66affSColin Finck {
215c2c66affSColin Finck DPRINT1("Failed to allocate %lu bytes for SMBIOS tables\n", BufferSize);
216c2c66affSColin Finck return;
217c2c66affSColin Finck }
218c2c66affSColin Finck
219c2c66affSColin Finck /* Query the buffer data */
220c2c66affSColin Finck Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, AllData);
221c2c66affSColin Finck if (!NT_SUCCESS(Status))
222c2c66affSColin Finck {
223c2c66affSColin Finck DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
224c2c66affSColin Finck ExFreePoolWithTag(AllData, 'BTMS');
225c2c66affSColin Finck return;
226c2c66affSColin Finck }
227c2c66affSColin Finck
228a9f20984SStanislav Motylkov /* FIXME: This function should be removed once the mssmbios driver is implemented */
229a9f20984SStanislav Motylkov /* Store SMBios data in registry */
230a9f20984SStanislav Motylkov i8042StoreSMBiosTables(AllData + 1,
231a9f20984SStanislav Motylkov AllData->FixedInstanceSize);
232a9f20984SStanislav Motylkov DPRINT1("SMBiosTables HACK, see CORE-14867\n");
233a9f20984SStanislav Motylkov
234c2c66affSColin Finck /* Parse the table */
235c2c66affSColin Finck i8042ParseSMBiosTables(AllData + 1,
236c2c66affSColin Finck AllData->WnodeHeader.BufferSize);
237c2c66affSColin Finck
238c2c66affSColin Finck /* Free the buffer */
239c2c66affSColin Finck ExFreePoolWithTag(AllData, 'BTMS');
240c2c66affSColin Finck }
241c2c66affSColin Finck
242