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/setup.c
5 * PURPOSE: Create a legacy PDO during ReactOS installation
6 * PROGRAMMERS: Copyright 2006-2007 Hervé Poussineau (hpoussin@reactos.org)
10 * All this file is a big hack and should be removed one day...
13 /* INCLUDES ******************************************************************/
17 /* GLOBALS *******************************************************************/
19 #define KEYBOARD_DATA_PORT 0x60
20 #define KEYBOARD_CONTROL_PORT 0x64
21 #define KEYBOARD_IRQ 1
23 /* FUNCTIONS *****************************************************************/
29 UNICODE_STRING PathU
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\MACHINE\\SYSTEM\\Setup");
30 OBJECT_ATTRIBUTES ObjectAttributes
;
31 HANDLE hSetupKey
= (HANDLE
)NULL
;
35 InitializeObjectAttributes(&ObjectAttributes
, &PathU
, OBJ_KERNEL_HANDLE
| OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
36 Status
= ZwOpenKey(&hSetupKey
, KEY_QUERY_VALUE
, &ObjectAttributes
);
38 if (Status
== STATUS_OBJECT_NAME_NOT_FOUND
)
43 if (hSetupKey
!= (HANDLE
)NULL
)
45 INFO_(I8042PRT
, "IsFirstStageSetup() returns %s\n", ret
? "YES" : "NO");
51 IN PCWSTR PortTypeName
,
52 IN PUNICODE_STRING DeviceName
,
53 IN PCWSTR RegistryPath
)
55 UNICODE_STRING PathU
= RTL_CONSTANT_STRING(L
"\\REGISTRY\\MACHINE\\HARDWARE\\DEVICEMAP");
56 OBJECT_ATTRIBUTES ObjectAttributes
;
57 HANDLE hDeviceMapKey
= (HANDLE
)-1;
58 HANDLE hPortKey
= (HANDLE
)-1;
59 UNICODE_STRING PortTypeNameU
;
62 InitializeObjectAttributes(&ObjectAttributes
, &PathU
, OBJ_KERNEL_HANDLE
| OBJ_CASE_INSENSITIVE
, NULL
, NULL
);
63 Status
= ZwOpenKey(&hDeviceMapKey
, 0, &ObjectAttributes
);
64 if (!NT_SUCCESS(Status
))
66 WARN_(I8042PRT
, "ZwOpenKey() failed with status 0x%08lx\n", Status
);
70 RtlInitUnicodeString(&PortTypeNameU
, PortTypeName
);
71 InitializeObjectAttributes(&ObjectAttributes
, &PortTypeNameU
, OBJ_KERNEL_HANDLE
, hDeviceMapKey
, NULL
);
72 Status
= ZwCreateKey(&hPortKey
, KEY_SET_VALUE
, &ObjectAttributes
, 0, NULL
, REG_OPTION_VOLATILE
, NULL
);
73 if (!NT_SUCCESS(Status
))
75 WARN_(I8042PRT
, "ZwCreateKey() failed with status 0x%08lx\n", Status
);
79 Status
= ZwSetValueKey(hPortKey
, DeviceName
, 0, REG_SZ
, (PVOID
)RegistryPath
, wcslen(RegistryPath
) * sizeof(WCHAR
) + sizeof(UNICODE_NULL
));
80 if (!NT_SUCCESS(Status
))
82 WARN_(I8042PRT
, "ZwSetValueKey() failed with status 0x%08lx\n", Status
);
86 Status
= STATUS_SUCCESS
;
89 if (hDeviceMapKey
!= (HANDLE
)-1)
90 ZwClose(hDeviceMapKey
);
91 if (hPortKey
!= (HANDLE
)-1)
97 i8042AddLegacyKeyboard(
98 IN PDRIVER_OBJECT DriverObject
,
99 IN PUNICODE_STRING RegistryPath
)
101 UNICODE_STRING KeyboardName
= RTL_CONSTANT_STRING(L
"\\Device\\KeyboardPort8042");
102 PI8042_DEVICE_TYPE DeviceExtension
= NULL
;
103 PDEVICE_OBJECT Pdo
= NULL
;
106 TRACE_(I8042PRT
, "i8042AddLegacyKeyboard()\n");
108 /* Create a named PDO */
109 Status
= IoCreateDevice(
111 sizeof(I8042_DEVICE_TYPE
),
113 FILE_DEVICE_8042_PORT
,
114 FILE_DEVICE_SECURE_OPEN
,
117 if (!NT_SUCCESS(Status
))
119 WARN_(I8042PRT
, "IoCreateDevice() failed with status 0x%08lx\n", Status
);
123 /* Initialize device extension */
124 DeviceExtension
= (PI8042_DEVICE_TYPE
)Pdo
->DeviceExtension
;
125 RtlZeroMemory(DeviceExtension
, sizeof(I8042_DEVICE_TYPE
));
126 *DeviceExtension
= PhysicalDeviceObject
;
127 Pdo
->Flags
&= ~DO_DEVICE_INITIALIZING
;
129 /* Add FDO at the top of the PDO */
130 Status
= i8042AddDevice(DriverObject
, Pdo
);
131 if (!NT_SUCCESS(Status
))
133 WARN_(I8042PRT
, "i8042AddDevice() failed with status 0x%08lx\n", Status
);
137 /* We will send the IRP_MN_START_DEVICE later when kbdclass looks for legacy drivers */
138 AddRegistryEntry(L
"KeyboardPort", &KeyboardName
, RegistryPath
->Buffer
);
140 Status
= STATUS_SUCCESS
;
141 /* Yes, completly forget the Pdo pointer, as we will never
142 * have to unload this driver during first stage setup.
146 if (!NT_SUCCESS(Status
))