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