xref: /reactos/drivers/input/i8042prt/registry.c (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * PROJECT:     ReactOS i8042 (ps/2 keyboard-mouse controller) driver
3*c2c66affSColin Finck  * LICENSE:     GPL - See COPYING in the top level directory
4*c2c66affSColin Finck  * FILE:        drivers/input/i8042prt/i8042prt.c
5*c2c66affSColin Finck  * PURPOSE:     Reading the registry
6*c2c66affSColin Finck  * PROGRAMMERS: Copyright Victor Kirhenshtein (sauros@iname.com)
7*c2c66affSColin Finck                 Copyright Jason Filby (jasonfilby@yahoo.com)
8*c2c66affSColin Finck                 Copyright Martijn Vernooij (o112w8r02@sneakemail.com)
9*c2c66affSColin Finck                 Copyright 2006-2007 Herv� Poussineau (hpoussin@reactos.org)
10*c2c66affSColin Finck  */
11*c2c66affSColin Finck 
12*c2c66affSColin Finck /* INCLUDES ******************************************************************/
13*c2c66affSColin Finck 
14*c2c66affSColin Finck #include "i8042prt.h"
15*c2c66affSColin Finck 
16*c2c66affSColin Finck #include <debug.h>
17*c2c66affSColin Finck 
18*c2c66affSColin Finck /* FUNCTIONS *****************************************************************/
19*c2c66affSColin Finck 
20*c2c66affSColin Finck NTSTATUS
ReadRegistryEntries(IN PUNICODE_STRING RegistryPath,OUT PI8042_SETTINGS Settings)21*c2c66affSColin Finck ReadRegistryEntries(
22*c2c66affSColin Finck 	IN PUNICODE_STRING RegistryPath,
23*c2c66affSColin Finck 	OUT PI8042_SETTINGS Settings)
24*c2c66affSColin Finck {
25*c2c66affSColin Finck 	RTL_QUERY_REGISTRY_TABLE Parameters[17];
26*c2c66affSColin Finck 	NTSTATUS Status;
27*c2c66affSColin Finck 
28*c2c66affSColin Finck 	ULONG DefaultKeyboardDataQueueSize = 0x64;
29*c2c66affSColin Finck 	PCWSTR DefaultKeyboardDeviceBaseName = L"KeyboardPort";
30*c2c66affSColin Finck 	ULONG DefaultMouseDataQueueSize = 0x64;
31*c2c66affSColin Finck 	ULONG DefaultMouseResolution = 3;
32*c2c66affSColin Finck 	ULONG DefaultMouseSynchIn100ns = 20000000;
33*c2c66affSColin Finck 	ULONG DefaultNumberOfButtons = 2;
34*c2c66affSColin Finck 	PCWSTR DefaultPointerDeviceBaseName = L"PointerPort";
35*c2c66affSColin Finck 	ULONG DefaultPollStatusIterations = 1;
36*c2c66affSColin Finck 	ULONG DefaultOverrideKeyboardType = 4;
37*c2c66affSColin Finck 	ULONG DefaultOverrideKeyboardSubtype = 0;
38*c2c66affSColin Finck 	ULONG DefaultPollingIterations = 12000;
39*c2c66affSColin Finck 	ULONG DefaultPollingIterationsMaximum = 12000;
40*c2c66affSColin Finck 	ULONG DefaultResendIterations = 0x3;
41*c2c66affSColin Finck 	ULONG DefaultSampleRate = 60;
42*c2c66affSColin Finck 	ULONG DefaultCrashOnCtrlScroll;
43*c2c66affSColin Finck 
44*c2c66affSColin Finck 	/* Default value for CrashOnCtrlScroll depends if we're
45*c2c66affSColin Finck 	 * running a debug build or a normal build.
46*c2c66affSColin Finck 	 */
47*c2c66affSColin Finck #if DBG
48*c2c66affSColin Finck 	DefaultCrashOnCtrlScroll = 1;
49*c2c66affSColin Finck #else
50*c2c66affSColin Finck 	DefaultCrashOnCtrlScroll = 0;
51*c2c66affSColin Finck #endif
52*c2c66affSColin Finck 
53*c2c66affSColin Finck 	RtlZeroMemory(Parameters, sizeof(Parameters));
54*c2c66affSColin Finck 
55*c2c66affSColin Finck 	Parameters[0].Flags = RTL_QUERY_REGISTRY_SUBKEY;
56*c2c66affSColin Finck 	Parameters[0].Name = L"Parameters";
57*c2c66affSColin Finck 
58*c2c66affSColin Finck 	Parameters[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
59*c2c66affSColin Finck 	Parameters[1].Name = L"KeyboardDataQueueSize";
60*c2c66affSColin Finck 	Parameters[1].EntryContext = &Settings->KeyboardDataQueueSize;
61*c2c66affSColin Finck 	Parameters[1].DefaultType = REG_DWORD;
62*c2c66affSColin Finck 	Parameters[1].DefaultData = &DefaultKeyboardDataQueueSize;
63*c2c66affSColin Finck 	Parameters[1].DefaultLength = sizeof(ULONG);
64*c2c66affSColin Finck 
65*c2c66affSColin Finck 	Parameters[2].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
66*c2c66affSColin Finck 	Parameters[2].Name = L"KeyboardDeviceBaseName";
67*c2c66affSColin Finck 	Parameters[2].EntryContext = &Settings->KeyboardDeviceBaseName;
68*c2c66affSColin Finck 	Parameters[2].DefaultType = REG_SZ;
69*c2c66affSColin Finck 	Parameters[2].DefaultData = (PVOID)DefaultKeyboardDeviceBaseName;
70*c2c66affSColin Finck 	Parameters[2].DefaultLength = 0;
71*c2c66affSColin Finck 
72*c2c66affSColin Finck 	Parameters[3].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
73*c2c66affSColin Finck 	Parameters[3].Name = L"MouseDataQueueSize";
74*c2c66affSColin Finck 	Parameters[3].EntryContext = &Settings->MouseDataQueueSize;
75*c2c66affSColin Finck 	Parameters[3].DefaultType = REG_DWORD;
76*c2c66affSColin Finck 	Parameters[3].DefaultData = &DefaultMouseDataQueueSize;
77*c2c66affSColin Finck 	Parameters[3].DefaultLength = sizeof(ULONG);
78*c2c66affSColin Finck 
79*c2c66affSColin Finck 	Parameters[4].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
80*c2c66affSColin Finck 	Parameters[4].Name = L"MouseResolution";
81*c2c66affSColin Finck 	Parameters[4].EntryContext = &Settings->MouseResolution;
82*c2c66affSColin Finck 	Parameters[4].DefaultType = REG_DWORD;
83*c2c66affSColin Finck 	Parameters[4].DefaultData = &DefaultMouseResolution;
84*c2c66affSColin Finck 	Parameters[4].DefaultLength = sizeof(ULONG);
85*c2c66affSColin Finck 
86*c2c66affSColin Finck 	Parameters[5].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
87*c2c66affSColin Finck 	Parameters[5].Name = L"MouseSynchIn100ns";
88*c2c66affSColin Finck 	Parameters[5].EntryContext = &Settings->MouseSynchIn100ns;
89*c2c66affSColin Finck 	Parameters[5].DefaultType = REG_DWORD;
90*c2c66affSColin Finck 	Parameters[5].DefaultData = &DefaultMouseSynchIn100ns;
91*c2c66affSColin Finck 	Parameters[5].DefaultLength = sizeof(ULONG);
92*c2c66affSColin Finck 
93*c2c66affSColin Finck 	Parameters[6].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
94*c2c66affSColin Finck 	Parameters[6].Name = L"NumberOfButtons";
95*c2c66affSColin Finck 	Parameters[6].EntryContext = &Settings->NumberOfButtons;
96*c2c66affSColin Finck 	Parameters[6].DefaultType = REG_DWORD;
97*c2c66affSColin Finck 	Parameters[6].DefaultData = &DefaultNumberOfButtons;
98*c2c66affSColin Finck 	Parameters[6].DefaultLength = sizeof(ULONG);
99*c2c66affSColin Finck 
100*c2c66affSColin Finck 	Parameters[7].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
101*c2c66affSColin Finck 	Parameters[7].Name = L"PointerDeviceBaseName";
102*c2c66affSColin Finck 	Parameters[7].EntryContext = &Settings->PointerDeviceBaseName;
103*c2c66affSColin Finck 	Parameters[7].DefaultType = REG_SZ;
104*c2c66affSColin Finck 	Parameters[7].DefaultData = (PVOID)DefaultPointerDeviceBaseName;
105*c2c66affSColin Finck 	Parameters[7].DefaultLength = 0;
106*c2c66affSColin Finck 
107*c2c66affSColin Finck 	Parameters[8].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
108*c2c66affSColin Finck 	Parameters[8].Name = L"PollStatusIterations";
109*c2c66affSColin Finck 	Parameters[8].EntryContext = &Settings->PollStatusIterations;
110*c2c66affSColin Finck 	Parameters[8].DefaultType = REG_DWORD;
111*c2c66affSColin Finck 	Parameters[8].DefaultData = &DefaultPollStatusIterations;
112*c2c66affSColin Finck 	Parameters[8].DefaultLength = sizeof(ULONG);
113*c2c66affSColin Finck 
114*c2c66affSColin Finck 	Parameters[9].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
115*c2c66affSColin Finck 	Parameters[9].Name = L"OverrideKeyboardType";
116*c2c66affSColin Finck 	Parameters[9].EntryContext = &Settings->OverrideKeyboardType;
117*c2c66affSColin Finck 	Parameters[9].DefaultType = REG_DWORD;
118*c2c66affSColin Finck 	Parameters[9].DefaultData = &DefaultOverrideKeyboardType;
119*c2c66affSColin Finck 	Parameters[9].DefaultLength = sizeof(ULONG);
120*c2c66affSColin Finck 
121*c2c66affSColin Finck 	Parameters[10].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
122*c2c66affSColin Finck 	Parameters[10].Name = L"OverrideKeyboardSubtype";
123*c2c66affSColin Finck 	Parameters[10].EntryContext = &Settings->OverrideKeyboardSubtype;
124*c2c66affSColin Finck 	Parameters[10].DefaultType = REG_DWORD;
125*c2c66affSColin Finck 	Parameters[10].DefaultData = &DefaultOverrideKeyboardSubtype;
126*c2c66affSColin Finck 	Parameters[10].DefaultLength = sizeof(ULONG);
127*c2c66affSColin Finck 
128*c2c66affSColin Finck 	Parameters[11].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
129*c2c66affSColin Finck 	Parameters[11].Name = L"PollingIterations";
130*c2c66affSColin Finck 	Parameters[11].EntryContext = &Settings->PollingIterations;
131*c2c66affSColin Finck 	Parameters[11].DefaultType = REG_DWORD;
132*c2c66affSColin Finck 	Parameters[11].DefaultData = &DefaultPollingIterations;
133*c2c66affSColin Finck 	Parameters[11].DefaultLength = sizeof(ULONG);
134*c2c66affSColin Finck 
135*c2c66affSColin Finck 	Parameters[12].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
136*c2c66affSColin Finck 	Parameters[12].Name = L"PollingIterationsMaximum";
137*c2c66affSColin Finck 	Parameters[12].EntryContext = &Settings->PollingIterationsMaximum;
138*c2c66affSColin Finck 	Parameters[12].DefaultType = REG_DWORD;
139*c2c66affSColin Finck 	Parameters[12].DefaultData = &DefaultPollingIterationsMaximum;
140*c2c66affSColin Finck 	Parameters[12].DefaultLength = sizeof(ULONG);
141*c2c66affSColin Finck 
142*c2c66affSColin Finck 	Parameters[13].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
143*c2c66affSColin Finck 	Parameters[13].Name = L"ResendIterations";
144*c2c66affSColin Finck 	Parameters[13].EntryContext = &Settings->ResendIterations;
145*c2c66affSColin Finck 	Parameters[13].DefaultType = REG_DWORD;
146*c2c66affSColin Finck 	Parameters[13].DefaultData = &DefaultResendIterations;
147*c2c66affSColin Finck 	Parameters[13].DefaultLength = sizeof(ULONG);
148*c2c66affSColin Finck 
149*c2c66affSColin Finck 	Parameters[14].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
150*c2c66affSColin Finck 	Parameters[14].Name = L"SampleRate";
151*c2c66affSColin Finck 	Parameters[14].EntryContext = &Settings->SampleRate;
152*c2c66affSColin Finck 	Parameters[14].DefaultType = REG_DWORD;
153*c2c66affSColin Finck 	Parameters[14].DefaultData = &DefaultSampleRate;
154*c2c66affSColin Finck 	Parameters[14].DefaultLength = sizeof(ULONG);
155*c2c66affSColin Finck 
156*c2c66affSColin Finck 	Parameters[15].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
157*c2c66affSColin Finck 	Parameters[15].Name = L"CrashOnCtrlScroll";
158*c2c66affSColin Finck 	Parameters[15].EntryContext = &Settings->CrashOnCtrlScroll;
159*c2c66affSColin Finck 	Parameters[15].DefaultType = REG_DWORD;
160*c2c66affSColin Finck 	Parameters[15].DefaultData = &DefaultCrashOnCtrlScroll;
161*c2c66affSColin Finck 	Parameters[15].DefaultLength = sizeof(ULONG);
162*c2c66affSColin Finck 
163*c2c66affSColin Finck 	Status = RtlQueryRegistryValues(
164*c2c66affSColin Finck 		RTL_REGISTRY_ABSOLUTE,
165*c2c66affSColin Finck 		RegistryPath->Buffer,
166*c2c66affSColin Finck 		Parameters,
167*c2c66affSColin Finck 		NULL,
168*c2c66affSColin Finck 		NULL);
169*c2c66affSColin Finck 
170*c2c66affSColin Finck 	if (NT_SUCCESS(Status))
171*c2c66affSColin Finck 	{
172*c2c66affSColin Finck 		/* Check values */
173*c2c66affSColin Finck 		if (Settings->KeyboardDataQueueSize < 1)
174*c2c66affSColin Finck 			Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize;
175*c2c66affSColin Finck 		if (Settings->MouseDataQueueSize < 1)
176*c2c66affSColin Finck 			Settings->MouseDataQueueSize = DefaultMouseDataQueueSize;
177*c2c66affSColin Finck 		if (Settings->NumberOfButtons < 1)
178*c2c66affSColin Finck 			Settings->NumberOfButtons = DefaultNumberOfButtons;
179*c2c66affSColin Finck 		if (Settings->PollingIterations < 0x400)
180*c2c66affSColin Finck 			Settings->PollingIterations = DefaultPollingIterations;
181*c2c66affSColin Finck 		if (Settings->PollingIterationsMaximum < 0x400)
182*c2c66affSColin Finck 			Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum;
183*c2c66affSColin Finck 		if (Settings->ResendIterations < 1)
184*c2c66affSColin Finck 			Settings->ResendIterations = DefaultResendIterations;
185*c2c66affSColin Finck 	}
186*c2c66affSColin Finck 	else if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
187*c2c66affSColin Finck 	{
188*c2c66affSColin Finck 		/* Registry path doesn't exist. Set defaults */
189*c2c66affSColin Finck 		Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize;
190*c2c66affSColin Finck 		Settings->MouseDataQueueSize = DefaultMouseDataQueueSize;
191*c2c66affSColin Finck 		Settings->MouseResolution = DefaultMouseResolution;
192*c2c66affSColin Finck 		Settings->MouseSynchIn100ns = DefaultMouseSynchIn100ns;
193*c2c66affSColin Finck 		Settings->NumberOfButtons = DefaultNumberOfButtons;
194*c2c66affSColin Finck 		Settings->PollStatusIterations = DefaultPollStatusIterations;
195*c2c66affSColin Finck 		Settings->OverrideKeyboardType = DefaultOverrideKeyboardType;
196*c2c66affSColin Finck 		Settings->OverrideKeyboardSubtype = DefaultOverrideKeyboardSubtype;
197*c2c66affSColin Finck 		Settings->PollingIterations = DefaultPollingIterations;
198*c2c66affSColin Finck 		Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum;
199*c2c66affSColin Finck 		Settings->ResendIterations = DefaultResendIterations;
200*c2c66affSColin Finck 		Settings->SampleRate = DefaultSampleRate;
201*c2c66affSColin Finck 		Settings->CrashOnCtrlScroll = DefaultCrashOnCtrlScroll;
202*c2c66affSColin Finck 		if (!RtlCreateUnicodeString(&Settings->KeyboardDeviceBaseName, DefaultKeyboardDeviceBaseName)
203*c2c66affSColin Finck 		 || !RtlCreateUnicodeString(&Settings->PointerDeviceBaseName, DefaultPointerDeviceBaseName))
204*c2c66affSColin Finck 		{
205*c2c66affSColin Finck 			WARN_(I8042PRT, "RtlCreateUnicodeString() failed\n");
206*c2c66affSColin Finck 			Status = STATUS_NO_MEMORY;
207*c2c66affSColin Finck 		}
208*c2c66affSColin Finck 		else
209*c2c66affSColin Finck 		{
210*c2c66affSColin Finck 			Status = STATUS_SUCCESS;
211*c2c66affSColin Finck 		}
212*c2c66affSColin Finck 	}
213*c2c66affSColin Finck 
214*c2c66affSColin Finck 	if (NT_SUCCESS(Status))
215*c2c66affSColin Finck 	{
216*c2c66affSColin Finck 		INFO_(I8042PRT, "KeyboardDataQueueSize : 0x%lx\n", Settings->KeyboardDataQueueSize);
217*c2c66affSColin Finck 		INFO_(I8042PRT, "KeyboardDeviceBaseName : %wZ\n", &Settings->KeyboardDeviceBaseName);
218*c2c66affSColin Finck 		INFO_(I8042PRT, "MouseDataQueueSize : 0x%lx\n", Settings->MouseDataQueueSize);
219*c2c66affSColin Finck 		INFO_(I8042PRT, "MouseResolution : 0x%lx\n", Settings->MouseResolution);
220*c2c66affSColin Finck 		INFO_(I8042PRT, "MouseSynchIn100ns : %lu\n", Settings->MouseSynchIn100ns);
221*c2c66affSColin Finck 		INFO_(I8042PRT, "NumberOfButtons : 0x%lx\n", Settings->NumberOfButtons);
222*c2c66affSColin Finck 		INFO_(I8042PRT, "PointerDeviceBaseName : %wZ\n", &Settings->PointerDeviceBaseName);
223*c2c66affSColin Finck 		INFO_(I8042PRT, "PollStatusIterations : 0x%lx\n", Settings->PollStatusIterations);
224*c2c66affSColin Finck 		INFO_(I8042PRT, "OverrideKeyboardType : 0x%lx\n", Settings->OverrideKeyboardType);
225*c2c66affSColin Finck 		INFO_(I8042PRT, "OverrideKeyboardSubtype : 0x%lx\n", Settings->OverrideKeyboardSubtype);
226*c2c66affSColin Finck 		INFO_(I8042PRT, "PollingIterations : 0x%lx\n", Settings->PollingIterations);
227*c2c66affSColin Finck 		INFO_(I8042PRT, "PollingIterationsMaximum : %lu\n", Settings->PollingIterationsMaximum);
228*c2c66affSColin Finck 		INFO_(I8042PRT, "ResendIterations : 0x%lx\n", Settings->ResendIterations);
229*c2c66affSColin Finck 		INFO_(I8042PRT, "SampleRate : %lu\n", Settings->SampleRate);
230*c2c66affSColin Finck 	}
231*c2c66affSColin Finck 
232*c2c66affSColin Finck 	return Status;
233*c2c66affSColin Finck }
234