ReactOS 0.4.17-dev-683-g0dafdc5
hwhacks.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS i8042 (ps/2 keyboard-mouse controller) driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/input/i8042prt/hwhacks.c
5 * PURPOSE: Mouse specific functions
6 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
7 * REFERENCES: - http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.0.0.pdf
8 * -
9 */
10
11#include "i8042prt.h"
12#include <wmiguid.h>
13#include <wmidata.h>
14#include <wmistr.h>
15#include <dmilib.h>
16#include <intrin.h>
17
18#define NDEBUG
19#include <debug.h>
20
24
25/* Since Windows 11 24H2 the Hyper-V emulated PS/2 mouse reports vertical
26 * movement already in Windows orientation instead of PS/2 orientation,
27 * see CORE-20561. */
28#define HYPERV_WIN_YAXIS_MIN_BUILD 26100
29
30typedef struct _MATCHENTRY
31{
35
36#define MAX_MATCH_ENTRIES 3
37typedef struct _HARDWARE_TABLE
38{
42
44{
45// { {{BOARD_VENDOR, "RIOWORKS"}, {BOARD_NAME, "HDAMB"}, {BOARD_VERSION, "Rev E"}}, FL_NOLOOP },
46// { {{BOARD_VENDOR, "ASUSTeK Computer Inc."}, {BOARD_NAME, "G1S"}, {BOARD_VERSION, "1.0"}}, FL_NOLOOP },
47
48 { {{SYS_VENDOR, "Microsoft Corporation"}, {SYS_PRODUCT, "Virtual Machine"}}, FL_INITHACK | FL_MICROSOFT_VM },
49 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Inspiron 6000 "}}, FL_INITHACK },
50 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D410 "}}, FL_INITHACK },
51 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D430 "}}, FL_INITHACK },
52 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D530 "}}, FL_INITHACK },
53 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D531 "}}, FL_INITHACK },
54 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D600 "}}, FL_INITHACK },
55 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D610 "}}, FL_INITHACK },
56 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D620 "}}, FL_INITHACK },
57 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D630 "}}, FL_INITHACK },
58 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D810 "}}, FL_INITHACK },
59 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D820 "}}, FL_INITHACK },
60 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude E4300 "}}, FL_INITHACK },
61 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude E4310 "}}, FL_INITHACK },
62 { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude E6400 "}}, FL_INITHACK },
63
64};
65
66
67
68static
69VOID
71 _In_reads_bytes_(TableSize) PVOID SMBiosTables,
73{
74 ULONG i, j;
76
77 ParseSMBiosTables(SMBiosTables, TableSize, Strings);
78
79#if 0 // DBG
80 DbgPrint("i8042prt: Dumping DMI data:\n");
81 DbgPrint("BIOS_VENDOR: %s\n", Strings[BIOS_VENDOR]);
82 DbgPrint("BIOS_VERSION: %s\n", Strings[BIOS_VERSION]);
83 DbgPrint("BIOS_DATE: %s\n", Strings[BIOS_DATE]);
84 DbgPrint("SYS_VENDOR: %s\n", Strings[SYS_VENDOR]);
85 DbgPrint("SYS_PRODUCT: %s\n", Strings[SYS_PRODUCT]);
86 DbgPrint("SYS_VERSION: %s\n", Strings[SYS_VERSION]);
87 DbgPrint("SYS_SERIAL: %s\n", Strings[SYS_SERIAL]);
88 DbgPrint("BOARD_VENDOR: %s\n", Strings[BOARD_VENDOR]);
89 DbgPrint("BOARD_NAME: %s\n", Strings[BOARD_NAME]);
90 DbgPrint("BOARD_VERSION: %s\n", Strings[BOARD_VERSION]);
91 DbgPrint("BOARD_SERIAL: %s\n", Strings[BOARD_SERIAL]);
92 DbgPrint("BOARD_ASSET_TAG: %s\n", Strings[BOARD_ASSET_TAG]);
93#endif
94
95 /* Now loop the hardware table to find a match */
96 for (i = 0; i < ARRAYSIZE(i8042HardwareTable); i++)
97 {
98 for (j = 0; j < MAX_MATCH_ENTRIES; j++)
99 {
101
102 if (Type != ID_NONE)
103 {
104 /* Check for a match */
105 if ((Strings[Type] == NULL) ||
106 strcmp(i8042HardwareTable[i].MatchEntries[j].String,
107 Strings[i8042HardwareTable[i].MatchEntries[j].Type]))
108 {
109 /* Does not match, try next entry */
110 break;
111 }
112 }
113 }
114
115 if (j == MAX_MATCH_ENTRIES)
116 {
117 /* All items matched!
118 * Use |= so as not to clobber flags set by other detections. */
120 DPRINT("Found match for hw table index %u\n", i);
121 break;
122 }
123 }
124}
125
126static
127VOID
129 _In_reads_bytes_(TableSize) PVOID SMBiosTables,
131{
132 static UNICODE_STRING mssmbiosKeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services\\mssmbios");
133 static UNICODE_STRING DataName = RTL_CONSTANT_STRING(L"Data");
134 static UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"SMBiosData");
138
139 /* Create registry key */
141 &mssmbiosKeyName,
143 NULL,
144 NULL);
145 Status = ZwCreateKey(&KeyHandle,
146 KEY_WRITE,
148 0,
149 NULL,
151 NULL);
152
153 if (!NT_SUCCESS(Status))
154 {
155 return;
156 }
157
158 /* Create sub key */
160 &DataName,
162 KeyHandle,
163 NULL);
164 Status = ZwCreateKey(&SubKeyHandle,
165 KEY_WRITE,
167 0,
168 NULL,
170 NULL);
171
172 if (!NT_SUCCESS(Status))
173 {
175 return;
176 }
177
178 /* Write value */
179 ZwSetValueKey(SubKeyHandle,
180 &ValueName,
181 0,
183 SMBiosTables,
184 TableSize);
185
188}
189
190#if defined(_M_IX86) || defined(_M_AMD64)
196static
197ULONG
198i8042GetHyperVOSBuild(
199 VOID)
200{
201 INT CpuInfo[4];
202 ULONG MaxHvLeaf;
203
204 /* Check if we are running under a hypervisor */
205 __cpuid(CpuInfo, 1);
206 if (!(CpuInfo[2] & 0x80000000))
207 return 0;
208
209 /* Check for the Hyper-V signature "Microsoft Hv" */
210 __cpuid(CpuInfo, 0x40000000);
211 MaxHvLeaf = (ULONG)CpuInfo[0];
212 DPRINT1("Hypervisor CPUID: max leaf 0x%lx, signature '%.4s%.4s%.4s'\n",
213 MaxHvLeaf, (PCHAR)&CpuInfo[1], (PCHAR)&CpuInfo[2], (PCHAR)&CpuInfo[3]);
214 if (CpuInfo[1] != 0x7263694D || /* "Micr" */
215 CpuInfo[2] != 0x666F736F || /* "osof" */
216 CpuInfo[3] != 0x76482074) /* "t Hv" */
217 return 0;
218
219 if (MaxHvLeaf < 0x40000002)
220 return 0;
221
222 /* Hypervisor system identity: EAX holds the host OS build number */
223 __cpuid(CpuInfo, 0x40000002);
224 DPRINT1("Hyper-V interface reports host build %lu\n", (ULONG)CpuInfo[0]);
225 return (ULONG)CpuInfo[0];
226}
227#endif
228
229VOID
230NTAPI
232 VOID)
233{
235 PVOID DataBlockObject;
236 PWNODE_ALL_DATA AllData;
238
239 /* Open the data block object for the SMBIOS table */
242 &DataBlockObject);
243 if (!NT_SUCCESS(Status))
244 {
245 DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
246 return;
247 }
248
249 /* Query the required buffer size */
250 BufferSize = 0;
251 Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, NULL);
252 if (!NT_SUCCESS(Status))
253 {
254 DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
255 return;
256 }
257
258 AllData = ExAllocatePoolWithTag(PagedPool, BufferSize, 'BTMS');
259 if (AllData == NULL)
260 {
261 DPRINT1("Failed to allocate %lu bytes for SMBIOS tables\n", BufferSize);
262 return;
263 }
264
265 /* Query the buffer data */
266 Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, AllData);
267 if (!NT_SUCCESS(Status))
268 {
269 DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
270 ExFreePoolWithTag(AllData, 'BTMS');
271 return;
272 }
273
274 /* FIXME: This function should be removed once the mssmbios driver is implemented */
275 /* Store SMBios data in registry */
276 i8042StoreSMBiosTables(AllData + 1,
277 AllData->FixedInstanceSize);
278 DPRINT1("SMBiosTables HACK, see CORE-14867\n");
279
280 /* Parse the table */
281 i8042ParseSMBiosTables(AllData + 1,
282 AllData->WnodeHeader.BufferSize);
283
284 /* Free the buffer */
285 ExFreePoolWithTag(AllData, 'BTMS');
286
287#if defined(_M_IX86) || defined(_M_AMD64)
288 /* The Y-axis workaround requires both the Hyper-V SMBIOS identity and
289 * an affected host build number range.
290 * The SMBIOS check keeps other hypervisors that expose the Hyper-V
291 * CPUID interface (e.g. VMware/VirtualBox running on top of the
292 * Windows Hypervisor Platform) unaffected. */
293 if ((i8042HwFlags & FL_MICROSOFT_VM) && i8042GetHyperVOSBuild() >= HYPERV_WIN_YAXIS_MIN_BUILD)
294 {
295 DPRINT1("Hyper-V host reports Windows-oriented PS/2 Y-axis, skipping Y negation\n");
297 }
298#endif
299}
300
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define BufferSize
Definition: mmc.h:75
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
static const WCHAR Strings[]
Definition: reg.c:35
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
VOID ParseSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize, _Inout_updates_(ID_STRINGS_MAX) PCHAR *Strings)
Definition: dmilib.c:41
@ BIOS_VERSION
Definition: dmilib.h:14
@ BOARD_VENDOR
Definition: dmilib.h:22
@ SYS_VERSION
Definition: dmilib.h:18
@ SYS_PRODUCT
Definition: dmilib.h:17
@ ID_STRINGS_MAX
Definition: dmilib.h:28
@ BOARD_ASSET_TAG
Definition: dmilib.h:26
@ BIOS_DATE
Definition: dmilib.h:15
@ SYS_VENDOR
Definition: dmilib.h:16
@ BIOS_VENDOR
Definition: dmilib.h:13
@ BOARD_NAME
Definition: dmilib.h:23
@ BOARD_VERSION
Definition: dmilib.h:24
@ BOARD_SERIAL
Definition: dmilib.h:25
@ ID_NONE
Definition: dmilib.h:12
@ SYS_SERIAL
Definition: dmilib.h:19
#define L(x)
Definition: resources.c:13
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:24
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define DbgPrint
Definition: hal.h:12
#define HYPERV_WIN_YAXIS_MIN_BUILD
Definition: hwhacks.c:28
struct _HARDWARE_TABLE HARDWARE_TABLE
ULONG i8042HwFlags
Definition: hwhacks.c:23
PVOID i8042SMBiosTables
Definition: hwhacks.c:22
const GUID MSSmBios_RawSMBiosTables_GUID
Definition: hwhacks.c:21
const HARDWARE_TABLE i8042HardwareTable[]
Definition: hwhacks.c:43
static VOID i8042StoreSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize)
Definition: hwhacks.c:128
#define MAX_MATCH_ENTRIES
Definition: hwhacks.c:36
static VOID i8042ParseSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize)
Definition: hwhacks.c:70
VOID NTAPI i8042InitializeHwHacks(VOID)
Definition: hwhacks.c:231
struct _MATCHENTRY MATCHENTRY
@ FL_MICROSOFT_VM
Definition: i8042prt.h:455
@ FL_INITHACK
Definition: i8042prt.h:454
@ FL_HYPERV_SKIP_Y_NEGATION
Definition: i8042prt.h:456
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ PNDIS_STRING _Out_ PNDIS_HANDLE SubKeyHandle
Definition: ndis.h:4726
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define _In_reads_bytes_(s)
Definition: no_sal2.h:170
#define _In_
Definition: no_sal2.h:158
#define REG_BINARY
Definition: nt_native.h:1499
#define KEY_WRITE
Definition: nt_native.h:1034
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1063
NTSTATUS NTAPI IoWMIOpenBlock(_In_ LPCGUID DataBlockGuid, _In_ ULONG DesiredAccess, _Out_ PVOID *DataBlockObject)
Definition: wmi.c:140
NTSTATUS NTAPI IoWMIQueryAllData(IN PVOID DataBlockObject, IN OUT ULONG *InOutBufferSize, OUT PVOID OutBuffer)
Definition: wmi.c:169
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define DPRINT
Definition: sndvol32.h:73
ULONG Flags
Definition: hwhacks.c:40
MATCHENTRY MatchEntries[MAX_MATCH_ENTRIES]
Definition: hwhacks.c:39
ULONG Type
Definition: hwhacks.c:32
PCHAR String
Definition: hwhacks.c:33
struct _WNODE_HEADER WnodeHeader
Definition: wmistr.h:112
ULONG FixedInstanceSize
Definition: wmistr.h:118
#define NTAPI
Definition: typedefs.h:36
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
#define SMBIOS_DATA_GUID
Definition: wmiguid.h:30
#define WMIGUID_QUERY
Definition: wmistr.h:159
_Must_inspect_result_ typedef _Out_ PULONG TableSize
Definition: iotypes.h:4330