4 * Copyright (C) 2003, 2004 Eric Kohl
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #define CLOCK_TICK_RATE (1193182)
31 #define LATCH (CLOCK_TICK_RATE / HZ)
35 #define MOUSE_TYPE_NONE 0
36 /* Microsoft Mouse with 2 buttons */
37 #define MOUSE_TYPE_MICROSOFT 1
38 /* Logitech Mouse with 3 buttons */
39 #define MOUSE_TYPE_LOGITECH 2
40 /* Microsoft Wheel Mouse (aka Z Mouse) */
41 #define MOUSE_TYPE_WHEELZ 3
42 /* Mouse Systems Mouse */
43 #define MOUSE_TYPE_MOUSESYSTEMS 4
48 /* Controller registers. */
49 #define CONTROLLER_REGISTER_STATUS 0x64
50 #define CONTROLLER_REGISTER_CONTROL 0x64
51 #define CONTROLLER_REGISTER_DATA 0x60
53 /* Controller commands. */
54 #define CONTROLLER_COMMAND_READ_MODE 0x20
55 #define CONTROLLER_COMMAND_WRITE_MODE 0x60
56 #define CONTROLLER_COMMAND_GET_VERSION 0xA1
57 #define CONTROLLER_COMMAND_MOUSE_DISABLE 0xA7
58 #define CONTROLLER_COMMAND_MOUSE_ENABLE 0xA8
59 #define CONTROLLER_COMMAND_TEST_MOUSE 0xA9
60 #define CONTROLLER_COMMAND_SELF_TEST 0xAA
61 #define CONTROLLER_COMMAND_KEYBOARD_TEST 0xAB
62 #define CONTROLLER_COMMAND_KEYBOARD_DISABLE 0xAD
63 #define CONTROLLER_COMMAND_KEYBOARD_ENABLE 0xAE
64 #define CONTROLLER_COMMAND_WRITE_MOUSE_OUTPUT_BUFFER 0xD3
65 #define CONTROLLER_COMMAND_WRITE_MOUSE 0xD4
67 /* Controller status */
68 #define CONTROLLER_STATUS_OUTPUT_BUFFER_FULL 0x01
69 #define CONTROLLER_STATUS_INPUT_BUFFER_FULL 0x02
70 #define CONTROLLER_STATUS_SELF_TEST 0x04
71 #define CONTROLLER_STATUS_COMMAND 0x08
72 #define CONTROLLER_STATUS_UNLOCKED 0x10
73 #define CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL 0x20
74 #define CONTROLLER_STATUS_GENERAL_TIMEOUT 0x40
75 #define CONTROLLER_STATUS_PARITY_ERROR 0x80
76 #define AUX_STATUS_OUTPUT_BUFFER_FULL (CONTROLLER_STATUS_OUTPUT_BUFFER_FULL | \
77 CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL)
79 /* Timeout in ms for sending to keyboard controller. */
80 #define CONTROLLER_TIMEOUT 250
83 typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA
86 ULONG NumberOfCylinders
;
87 ULONG SectorsPerTrack
;
89 } CM_DISK_GEOMETRY_DEVICE_DATA
, *PCM_DISK_GEOMETRY_DEVICE_DATA
;
92 typedef struct _CM_PNP_BIOS_DEVICE_NODE
98 USHORT DeviceAttributes
;
99 } __attribute__((packed
)) CM_PNP_BIOS_DEVICE_NODE
, *PCM_PNP_BIOS_DEVICE_NODE
;
102 typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK
109 ULONG EventFlagAddress
;
110 USHORT RealModeEntryOffset
;
111 USHORT RealModeEntrySegment
;
112 USHORT ProtectedModeEntryOffset
;
113 ULONG ProtectedModeCodeBaseAddress
;
115 USHORT RealModeDataBaseAddress
;
116 ULONG ProtectedModeDataBaseAddress
;
117 } __attribute__((packed
)) CM_PNP_BIOS_INSTALLATION_CHECK
, *PCM_PNP_BIOS_INSTALLATION_CHECK
;
120 static WCHAR Hex
[] = L
"0123456789ABCDEF";
121 static unsigned int delay_count
= 1;
123 extern ULONG reactos_disk_count
;
124 extern ARC_DISK_SIGNATURE reactos_arc_disk_info
[];
125 extern char reactos_arc_strings
[32][256];
127 /* FUNCTIONS ****************************************************************/
131 __StallExecutionProcessor(ULONG Loops
)
133 volatile register unsigned int i
;
134 for (i
= 0; i
< Loops
; i
++);
138 VOID
StallExecutionProcessor(ULONG Microseconds
)
140 ULONGLONG LoopCount
= ((ULONGLONG
)delay_count
* (ULONGLONG
)Microseconds
) / 1000ULL;
141 __StallExecutionProcessor((ULONG
)LoopCount
);
150 WRITE_PORT_UCHAR((PUCHAR
)0x43, 0x00);
151 Count
= READ_PORT_UCHAR((PUCHAR
)0x40);
152 Count
|= READ_PORT_UCHAR((PUCHAR
)0x40) << 8;
159 WaitFor8254Wraparound(VOID
)
162 ULONG PrevCount
= ~0;
165 CurCount
= Read8254Timer();
169 PrevCount
= CurCount
;
170 CurCount
= Read8254Timer();
171 Delta
= CurCount
- PrevCount
;
174 * This limit for delta seems arbitrary, but it isn't, it's
175 * slightly above the level of error a buggy Mercury/Neptune
176 * chipset timer can cause.
184 HalpCalibrateStallExecution(VOID
)
190 /* Initialise timer interrupt with MILLISECOND ms interval */
191 WRITE_PORT_UCHAR((PUCHAR
)0x43, 0x34); /* binary, mode 2, LSB/MSB, ch 0 */
192 WRITE_PORT_UCHAR((PUCHAR
)0x40, LATCH
& 0xff); /* LSB */
193 WRITE_PORT_UCHAR((PUCHAR
)0x40, LATCH
>> 8); /* MSB */
195 /* Stage 1: Coarse calibration */
197 WaitFor8254Wraparound();
202 delay_count
<<= 1; /* Next delay count to try */
204 WaitFor8254Wraparound();
206 __StallExecutionProcessor(delay_count
); /* Do the delay */
208 CurCount
= Read8254Timer();
209 } while (CurCount
> LATCH
/ 2);
211 delay_count
>>= 1; /* Get bottom value for delay */
213 /* Stage 2: Fine calibration */
215 calib_bit
= delay_count
; /* Which bit are we going to test */
217 for(i
=0;i
<PRECISION
;i
++) {
218 calib_bit
>>= 1; /* Next bit to calibrate */
219 if(!calib_bit
) break; /* If we have done all bits, stop */
221 delay_count
|= calib_bit
; /* Set the bit in delay_count */
223 WaitFor8254Wraparound();
225 __StallExecutionProcessor(delay_count
); /* Do the delay */
227 CurCount
= Read8254Timer();
228 if (CurCount
<= LATCH
/ 2) /* If a tick has passed, turn the */
229 delay_count
&= ~calib_bit
; /* calibrated bit back off */
232 /* We're finished: Do the finishing touches */
233 delay_count
/= (MILLISEC
/ 2); /* Calculate delay_count for 1ms */
238 SetComponentInformation(FRLDRHKEY ComponentKey
,
243 CM_COMPONENT_INFORMATION CompInfo
;
246 CompInfo
.Flags
= Flags
;
247 CompInfo
.Version
= 0;
249 CompInfo
.Affinity
= Affinity
;
251 /* Set 'Component Information' value */
252 Error
= RegSetValue(ComponentKey
,
253 L
"Component Information",
256 sizeof(CM_COMPONENT_INFORMATION
));
257 if (Error
!= ERROR_SUCCESS
)
259 DbgPrint((DPRINT_HWDETECT
, "RegSetValue() failed (Error %u)\n", (int)Error
));
265 DetectPnpBios(FRLDRHKEY SystemKey
, ULONG
*BusNumber
)
267 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
268 PCM_PNP_BIOS_DEVICE_NODE DeviceNode
;
269 PCM_PNP_BIOS_INSTALLATION_CHECK InstData
;
276 ULONG FoundNodeCount
;
283 InstData
= (PCM_PNP_BIOS_INSTALLATION_CHECK
)PnpBiosSupported();
284 if (InstData
== NULL
|| strncmp((CHAR
*)InstData
->Signature
, "$PnP", 4))
286 DbgPrint((DPRINT_HWDETECT
, "PnP-BIOS not supported\n"));
289 DbgPrint((DPRINT_HWDETECT
, "Signature '%c%c%c%c'\n",
290 InstData
->Signature
[0], InstData
->Signature
[1],
291 InstData
->Signature
[2], InstData
->Signature
[3]));
294 x
= PnpBiosGetDeviceNodeCount(&NodeSize
, &NodeCount
);
295 NodeCount
&= 0xFF; // needed since some fscked up BIOSes return
296 // wrong info (e.g. Mac Virtual PC)
297 // e.g. look: http://my.execpc.com/~geezer/osd/pnp/pnp16.c
298 if (x
!= 0 || NodeSize
== 0 || NodeCount
== 0)
300 DbgPrint((DPRINT_HWDETECT
, "PnP-BIOS failed to enumerate device nodes\n"));
303 DbgPrint((DPRINT_HWDETECT
, "PnP-BIOS supported\n"));
304 DbgPrint((DPRINT_HWDETECT
, "MaxNodeSize %u NodeCount %u\n", NodeSize
, NodeCount
));
305 DbgPrint((DPRINT_HWDETECT
, "Estimated buffer size %u\n", NodeSize
* NodeCount
));
307 /* Create new bus key */
309 L
"MultifunctionAdapter\\%u", *BusNumber
);
310 Error
= RegCreateKey(SystemKey
,
313 if (Error
!= ERROR_SUCCESS
)
315 DbgPrint((DPRINT_HWDETECT
, "RegCreateKey() failed (Error %u)\n", (int)Error
));
319 /* Increment bus number */
322 /* Set 'Component Information' value similar to my NT4 box */
323 SetComponentInformation(BusKey
,
328 /* Set 'Identifier' value */
329 Error
= RegSetValue(BusKey
,
334 if (Error
!= ERROR_SUCCESS
)
336 DbgPrint((DPRINT_HWDETECT
, "RegSetValue() failed (Error %u)\n", (int)Error
));
340 /* Set 'Configuration Data' value */
341 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) + (NodeSize
* NodeCount
);
342 FullResourceDescriptor
= MmAllocateMemory(Size
);
343 if (FullResourceDescriptor
== NULL
)
345 DbgPrint((DPRINT_HWDETECT
,
346 "Failed to allocate resource descriptor\n"));
349 memset(FullResourceDescriptor
, 0, Size
);
351 /* Initialize resource descriptor */
352 FullResourceDescriptor
->InterfaceType
= Internal
;
353 FullResourceDescriptor
->BusNumber
= 0;
354 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
355 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
356 FullResourceDescriptor
->PartialResourceList
.Count
= 1;
357 FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0].Type
=
358 CmResourceTypeDeviceSpecific
;
359 FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0].ShareDisposition
=
360 CmResourceShareUndetermined
;
362 Ptr
= (char *)(((ULONG_PTR
)&FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0]) +
363 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
));
365 /* Set instalation check data */
366 memcpy (Ptr
, InstData
, sizeof(CM_PNP_BIOS_INSTALLATION_CHECK
));
367 Ptr
+= sizeof(CM_PNP_BIOS_INSTALLATION_CHECK
);
369 /* Copy device nodes */
371 PnpBufferSize
= sizeof(CM_PNP_BIOS_INSTALLATION_CHECK
);
372 for (i
= 0; i
< 0xFF; i
++)
374 NodeNumber
= (UCHAR
)i
;
376 x
= PnpBiosGetDeviceNode(&NodeNumber
, (PVOID
)DISKREADBUFFER
);
379 DeviceNode
= (PCM_PNP_BIOS_DEVICE_NODE
)DISKREADBUFFER
;
381 DbgPrint((DPRINT_HWDETECT
,
382 "Node: %u Size %u (0x%x)\n",
391 Ptr
+= DeviceNode
->Size
;
392 PnpBufferSize
+= DeviceNode
->Size
;
395 if (FoundNodeCount
>= NodeCount
)
400 /* Set real data size */
401 FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0].u
.DeviceSpecificData
.DataSize
=
403 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) + PnpBufferSize
;
405 DbgPrint((DPRINT_HWDETECT
, "Real buffer size: %u\n", PnpBufferSize
));
406 DbgPrint((DPRINT_HWDETECT
, "Resource size: %u\n", Size
));
408 /* Set 'Configuration Data' value */
409 Error
= RegSetValue(BusKey
,
410 L
"Configuration Data",
411 REG_FULL_RESOURCE_DESCRIPTOR
,
412 (PCHAR
) FullResourceDescriptor
,
414 MmFreeMemory(FullResourceDescriptor
);
415 if (Error
!= ERROR_SUCCESS
)
417 DbgPrint((DPRINT_HWDETECT
,
418 "RegSetValue(Configuration Data) failed (Error %u)\n",
426 SetHarddiskConfigurationData(FRLDRHKEY DiskKey
,
429 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
430 PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
;
431 EXTENDED_GEOMETRY ExtGeometry
;
436 /* Set 'Configuration Data' value */
437 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) +
438 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA
);
439 FullResourceDescriptor
= MmAllocateMemory(Size
);
440 if (FullResourceDescriptor
== NULL
)
442 DbgPrint((DPRINT_HWDETECT
,
443 "Failed to allocate a full resource descriptor\n"));
447 memset(FullResourceDescriptor
, 0, Size
);
448 FullResourceDescriptor
->InterfaceType
= InterfaceTypeUndefined
;
449 FullResourceDescriptor
->BusNumber
= 0;
450 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
451 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
452 FullResourceDescriptor
->PartialResourceList
.Count
= 1;
453 FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0].Type
=
454 CmResourceTypeDeviceSpecific
;
455 // FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].ShareDisposition =
456 // FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].Flags =
457 FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0].u
.DeviceSpecificData
.DataSize
=
458 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA
);
460 /* Get pointer to geometry data */
461 DiskGeometry
= (PVOID
)(((ULONG_PTR
)FullResourceDescriptor
) + sizeof(CM_FULL_RESOURCE_DESCRIPTOR
));
463 /* Get the disk geometry */
464 ExtGeometry
.Size
= sizeof(EXTENDED_GEOMETRY
);
465 if (DiskGetExtendedDriveParameters(DriveNumber
, &ExtGeometry
, ExtGeometry
.Size
))
467 DiskGeometry
->BytesPerSector
= ExtGeometry
.BytesPerSector
;
468 DiskGeometry
->NumberOfCylinders
= ExtGeometry
.Cylinders
;
469 DiskGeometry
->SectorsPerTrack
= ExtGeometry
.SectorsPerTrack
;
470 DiskGeometry
->NumberOfHeads
= ExtGeometry
.Heads
;
472 else if(MachDiskGetDriveGeometry(DriveNumber
, &Geometry
))
474 DiskGeometry
->BytesPerSector
= Geometry
.BytesPerSector
;
475 DiskGeometry
->NumberOfCylinders
= Geometry
.Cylinders
;
476 DiskGeometry
->SectorsPerTrack
= Geometry
.Sectors
;
477 DiskGeometry
->NumberOfHeads
= Geometry
.Heads
;
481 DbgPrint((DPRINT_HWDETECT
, "Reading disk geometry failed\n"));
482 MmFreeMemory(FullResourceDescriptor
);
485 DbgPrint((DPRINT_HWDETECT
,
486 "Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
488 DiskGeometry
->NumberOfCylinders
,
489 DiskGeometry
->NumberOfHeads
,
490 DiskGeometry
->SectorsPerTrack
,
491 DiskGeometry
->BytesPerSector
));
493 Error
= RegSetValue(DiskKey
,
494 L
"Configuration Data",
495 REG_FULL_RESOURCE_DESCRIPTOR
,
496 (PCHAR
) FullResourceDescriptor
,
498 MmFreeMemory(FullResourceDescriptor
);
499 if (Error
!= ERROR_SUCCESS
)
501 DbgPrint((DPRINT_HWDETECT
,
502 "RegSetValue(Configuration Data) failed (Error %u)\n",
509 SetHarddiskIdentifier(FRLDRHKEY DiskKey
,
512 PMASTER_BOOT_RECORD Mbr
;
517 WCHAR Identifier
[20];
522 if (!MachDiskReadLogicalSectors(DriveNumber
, 0ULL, 1, (PVOID
)DISKREADBUFFER
))
524 DbgPrint((DPRINT_HWDETECT
, "Reading MBR failed\n"));
528 Buffer
= (ULONG
*)DISKREADBUFFER
;
529 Mbr
= (PMASTER_BOOT_RECORD
)DISKREADBUFFER
;
531 Signature
= Mbr
->Signature
;
532 DbgPrint((DPRINT_HWDETECT
, "Signature: %x\n", Signature
));
534 /* Calculate the MBR checksum */
536 for (i
= 0; i
< 128; i
++)
538 Checksum
+= Buffer
[i
];
540 Checksum
= ~Checksum
+ 1;
541 DbgPrint((DPRINT_HWDETECT
, "Checksum: %x\n", Checksum
));
543 /* Fill out the ARC disk block */
544 reactos_arc_disk_info
[reactos_disk_count
].Signature
= Signature
;
545 reactos_arc_disk_info
[reactos_disk_count
].CheckSum
= Checksum
;
546 sprintf(ArcName
, "multi(0)disk(0)rdisk(%lu)", reactos_disk_count
);
547 strcpy(reactos_arc_strings
[reactos_disk_count
], ArcName
);
548 reactos_arc_disk_info
[reactos_disk_count
].ArcName
=
549 reactos_arc_strings
[reactos_disk_count
];
550 reactos_disk_count
++;
552 /* Convert checksum and signature to identifier string */
553 Identifier
[0] = Hex
[(Checksum
>> 28) & 0x0F];
554 Identifier
[1] = Hex
[(Checksum
>> 24) & 0x0F];
555 Identifier
[2] = Hex
[(Checksum
>> 20) & 0x0F];
556 Identifier
[3] = Hex
[(Checksum
>> 16) & 0x0F];
557 Identifier
[4] = Hex
[(Checksum
>> 12) & 0x0F];
558 Identifier
[5] = Hex
[(Checksum
>> 8) & 0x0F];
559 Identifier
[6] = Hex
[(Checksum
>> 4) & 0x0F];
560 Identifier
[7] = Hex
[Checksum
& 0x0F];
561 Identifier
[8] = L
'-';
562 Identifier
[9] = Hex
[(Signature
>> 28) & 0x0F];
563 Identifier
[10] = Hex
[(Signature
>> 24) & 0x0F];
564 Identifier
[11] = Hex
[(Signature
>> 20) & 0x0F];
565 Identifier
[12] = Hex
[(Signature
>> 16) & 0x0F];
566 Identifier
[13] = Hex
[(Signature
>> 12) & 0x0F];
567 Identifier
[14] = Hex
[(Signature
>> 8) & 0x0F];
568 Identifier
[15] = Hex
[(Signature
>> 4) & 0x0F];
569 Identifier
[16] = Hex
[Signature
& 0x0F];
570 Identifier
[17] = L
'-';
571 Identifier
[18] = L
'A';
573 DbgPrint((DPRINT_HWDETECT
, "Identifier: %S\n", Identifier
));
576 Error
= RegSetValue(DiskKey
,
581 if (Error
!= ERROR_SUCCESS
)
583 DbgPrint((DPRINT_HWDETECT
,
584 "RegSetValue(Identifier) failed (Error %u)\n",
591 DetectBiosDisks(FRLDRHKEY SystemKey
,
594 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
595 PCM_INT13_DRIVE_PARAMETER Int13Drives
;
605 /* Count the number of visible drives */
606 DiskReportError(FALSE
);
609 /* There are some really broken BIOSes out there. There are even BIOSes
610 * that happily report success when you ask them to read from non-existent
611 * harddisks. So, we set the buffer to known contents first, then try to
612 * read. If the BIOS reports success but the buffer contents haven't
613 * changed then we fail anyway */
614 memset((PVOID
) DISKREADBUFFER
, 0xcd, 512);
615 while (MachDiskReadLogicalSectors(0x80 + DiskCount
, 0ULL, 1, (PVOID
)DISKREADBUFFER
))
618 for (i
= 0; ! Changed
&& i
< 512; i
++)
620 Changed
= ((PUCHAR
)DISKREADBUFFER
)[i
] != 0xcd;
624 DbgPrint((DPRINT_HWDETECT
, "BIOS reports success for disk %d but data didn't change\n",
629 memset((PVOID
) DISKREADBUFFER
, 0xcd, 512);
631 DiskReportError(TRUE
);
632 DbgPrint((DPRINT_HWDETECT
, "BIOS reports %d harddisk%s\n",
633 (int)DiskCount
, (DiskCount
== 1) ? "": "s"));
635 /* Allocate resource descriptor */
636 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) +
637 sizeof(CM_INT13_DRIVE_PARAMETER
) * DiskCount
;
638 FullResourceDescriptor
= MmAllocateMemory(Size
);
639 if (FullResourceDescriptor
== NULL
)
641 DbgPrint((DPRINT_HWDETECT
,
642 "Failed to allocate resource descriptor\n"));
646 /* Initialize resource descriptor */
647 memset(FullResourceDescriptor
, 0, Size
);
648 FullResourceDescriptor
->InterfaceType
= InterfaceTypeUndefined
;
649 FullResourceDescriptor
->BusNumber
= -1;
650 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
651 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
652 FullResourceDescriptor
->PartialResourceList
.Count
= 1;
653 FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0].Type
=
654 CmResourceTypeDeviceSpecific
;
655 // FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].ShareDisposition =
656 // FullResourceDescriptor->PartialResourceList.PartialDescriptors[0].Flags =
657 FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0].u
.DeviceSpecificData
.DataSize
=
658 sizeof(CM_INT13_DRIVE_PARAMETER
) * DiskCount
;
660 /* Get harddisk Int13 geometry data */
661 Int13Drives
= (PVOID
)(((ULONG_PTR
)FullResourceDescriptor
) + sizeof(CM_FULL_RESOURCE_DESCRIPTOR
));
662 for (i
= 0; i
< DiskCount
; i
++)
664 if (MachDiskGetDriveGeometry(0x80 + i
, &Geometry
))
666 Int13Drives
[i
].DriveSelect
= 0x80 + i
;
667 Int13Drives
[i
].MaxCylinders
= Geometry
.Cylinders
- 1;
668 Int13Drives
[i
].SectorsPerTrack
= Geometry
.Sectors
;
669 Int13Drives
[i
].MaxHeads
= Geometry
.Heads
- 1;
670 Int13Drives
[i
].NumberDrives
= DiskCount
;
672 DbgPrint((DPRINT_HWDETECT
,
673 "Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
675 Geometry
.Cylinders
- 1,
678 Geometry
.BytesPerSector
));
682 /* Set 'Configuration Data' value */
683 Error
= RegSetValue(SystemKey
,
684 L
"Configuration Data",
685 REG_FULL_RESOURCE_DESCRIPTOR
,
686 (PCHAR
) FullResourceDescriptor
,
688 MmFreeMemory(FullResourceDescriptor
);
689 if (Error
!= ERROR_SUCCESS
)
691 DbgPrint((DPRINT_HWDETECT
,
692 "RegSetValue(Configuration Data) failed (Error %u)\n",
697 /* Create and fill subkey for each harddisk */
698 for (i
= 0; i
< DiskCount
; i
++)
700 /* Create disk key */
702 L
"DiskController\\0\\DiskPeripheral\\%u",
705 Error
= RegCreateKey(BusKey
,
708 if (Error
!= ERROR_SUCCESS
)
710 DbgPrint((DPRINT_HWDETECT
, "Failed to create drive key\n"));
713 DbgPrint((DPRINT_HWDETECT
, "Created key: %S\n", Buffer
));
715 /* Set disk values */
716 SetHarddiskConfigurationData(DiskKey
, 0x80 + i
);
717 SetHarddiskIdentifier(DiskKey
, 0x80 + i
);
727 WRITE_PORT_UCHAR((PUCHAR
)0x70, 0x10);
728 Data
= READ_PORT_UCHAR((PUCHAR
)0x71);
730 return ((Data
& 0xF0) ? 1 : 0) + ((Data
& 0x0F) ? 1 : 0);
735 GetFloppyType(UCHAR DriveNumber
)
739 WRITE_PORT_UCHAR((PUCHAR
)0x70, 0x10);
740 Data
= READ_PORT_UCHAR((PUCHAR
)0x71);
742 if (DriveNumber
== 0)
744 else if (DriveNumber
== 1)
754 PUSHORT SegPtr
= (PUSHORT
)0x7A;
755 PUSHORT OfsPtr
= (PUSHORT
)0x78;
757 return (PVOID
)((ULONG_PTR
)(((ULONG
)(*SegPtr
)) << 4) + (ULONG
)(*OfsPtr
));
762 DetectBiosFloppyPeripheral(FRLDRHKEY ControllerKey
)
764 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
765 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
766 PCM_FLOPPY_DEVICE_DATA FloppyData
;
768 WCHAR Identifier
[20];
769 FRLDRHKEY PeripheralKey
;
774 ULONG MaxDensity
[6] = {0, 360, 1200, 720, 1440, 2880};
777 for (FloppyNumber
= 0; FloppyNumber
< 2; FloppyNumber
++)
779 FloppyType
= GetFloppyType(FloppyNumber
);
781 if ((FloppyType
> 5) || (FloppyType
== 0))
784 DiskResetController(FloppyNumber
);
786 Ptr
= GetInt1eTable();
788 swprintf(KeyName
, L
"FloppyDiskPeripheral\\%u", FloppyNumber
);
790 Error
= RegCreateKey(ControllerKey
,
793 if (Error
!= ERROR_SUCCESS
)
795 DbgPrint((DPRINT_HWDETECT
, "Failed to create peripheral key\n"));
799 DbgPrint((DPRINT_HWDETECT
, "Created key: %S\n", KeyName
));
801 /* Set 'ComponentInformation' value */
802 SetComponentInformation(PeripheralKey
,
807 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) +
808 sizeof(CM_FLOPPY_DEVICE_DATA
);
809 FullResourceDescriptor
= MmAllocateMemory(Size
);
810 if (FullResourceDescriptor
== NULL
)
812 DbgPrint((DPRINT_HWDETECT
,
813 "Failed to allocate resource descriptor\n"));
817 memset(FullResourceDescriptor
, 0, Size
);
818 FullResourceDescriptor
->InterfaceType
= Isa
;
819 FullResourceDescriptor
->BusNumber
= 0;
820 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
821 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
822 FullResourceDescriptor
->PartialResourceList
.Count
= 1;
824 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0];
825 PartialDescriptor
->Type
= CmResourceTypeDeviceSpecific
;
826 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
827 PartialDescriptor
->u
.DeviceSpecificData
.DataSize
= sizeof(CM_FLOPPY_DEVICE_DATA
);
829 FloppyData
= (PVOID
)(((ULONG_PTR
)FullResourceDescriptor
) + sizeof(CM_FULL_RESOURCE_DESCRIPTOR
));
830 FloppyData
->Version
= 2;
831 FloppyData
->Revision
= 0;
832 FloppyData
->MaxDensity
= MaxDensity
[FloppyType
];
833 FloppyData
->MountDensity
= 0;
834 RtlCopyMemory(&FloppyData
->StepRateHeadUnloadTime
,
837 FloppyData
->MaximumTrackValue
= (FloppyType
== 1) ? 39 : 79;
838 FloppyData
->DataTransferRate
= 0;
840 /* Set 'Configuration Data' value */
841 Error
= RegSetValue(PeripheralKey
,
842 L
"Configuration Data",
843 REG_FULL_RESOURCE_DESCRIPTOR
,
844 (PCHAR
) FullResourceDescriptor
,
846 MmFreeMemory(FullResourceDescriptor
);
847 if (Error
!= ERROR_SUCCESS
)
849 DbgPrint((DPRINT_HWDETECT
,
850 "RegSetValue(Configuration Data) failed (Error %u)\n",
855 /* Set 'Identifier' value */
856 swprintf(Identifier
, L
"FLOPPY%u", FloppyNumber
+ 1);
857 Error
= RegSetValue(PeripheralKey
,
861 (wcslen(Identifier
) + 1) * sizeof(WCHAR
));
862 if (Error
!= ERROR_SUCCESS
)
864 DbgPrint((DPRINT_HWDETECT
,
865 "RegSetValue() failed (Error %u)\n",
873 DetectBiosFloppyController(FRLDRHKEY SystemKey
,
876 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
877 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
878 FRLDRHKEY ControllerKey
;
883 FloppyCount
= GetFloppyCount();
884 DbgPrint((DPRINT_HWDETECT
,
885 "Floppy count: %u\n",
888 if (FloppyCount
== 0)
891 Error
= RegCreateKey(BusKey
,
892 L
"DiskController\\0",
894 if (Error
!= ERROR_SUCCESS
)
896 DbgPrint((DPRINT_HWDETECT
, "Failed to create controller key\n"));
900 DbgPrint((DPRINT_HWDETECT
, "Created key: DiskController\\0\n"));
902 /* Set 'ComponentInformation' value */
903 SetComponentInformation(ControllerKey
,
908 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) +
909 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
);
910 FullResourceDescriptor
= MmAllocateMemory(Size
);
911 if (FullResourceDescriptor
== NULL
)
913 DbgPrint((DPRINT_HWDETECT
,
914 "Failed to allocate resource descriptor\n"));
917 memset(FullResourceDescriptor
, 0, Size
);
919 /* Initialize resource descriptor */
920 FullResourceDescriptor
->InterfaceType
= Isa
;
921 FullResourceDescriptor
->BusNumber
= 0;
922 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
923 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
924 FullResourceDescriptor
->PartialResourceList
.Count
= 3;
927 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0];
928 PartialDescriptor
->Type
= CmResourceTypePort
;
929 PartialDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
930 PartialDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
931 PartialDescriptor
->u
.Port
.Start
.LowPart
= 0x03F0;
932 PartialDescriptor
->u
.Port
.Start
.HighPart
= 0x0;
933 PartialDescriptor
->u
.Port
.Length
= 8;
936 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[1];
937 PartialDescriptor
->Type
= CmResourceTypeInterrupt
;
938 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
939 PartialDescriptor
->Flags
= CM_RESOURCE_INTERRUPT_LATCHED
;
940 PartialDescriptor
->u
.Interrupt
.Level
= 6;
941 PartialDescriptor
->u
.Interrupt
.Vector
= 0;
942 PartialDescriptor
->u
.Interrupt
.Affinity
= 0xFFFFFFFF;
944 /* Set DMA channel */
945 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[2];
946 PartialDescriptor
->Type
= CmResourceTypeDma
;
947 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
948 PartialDescriptor
->Flags
= 0;
949 PartialDescriptor
->u
.Dma
.Channel
= 2;
950 PartialDescriptor
->u
.Dma
.Port
= 0;
952 /* Set 'Configuration Data' value */
953 Error
= RegSetValue(ControllerKey
,
954 L
"Configuration Data",
955 REG_FULL_RESOURCE_DESCRIPTOR
,
956 (PCHAR
) FullResourceDescriptor
,
958 MmFreeMemory(FullResourceDescriptor
);
959 if (Error
!= ERROR_SUCCESS
)
961 DbgPrint((DPRINT_HWDETECT
,
962 "RegSetValue(Configuration Data) failed (Error %u)\n",
967 DetectBiosFloppyPeripheral(ControllerKey
);
972 InitializeSerialPort(ULONG Port
,
975 WRITE_PORT_UCHAR((PUCHAR
)Port
+ 3, 0x80); /* set DLAB on */
976 WRITE_PORT_UCHAR((PUCHAR
)Port
, 0x60); /* speed LO byte */
977 WRITE_PORT_UCHAR((PUCHAR
)Port
+ 1, 0); /* speed HI byte */
978 WRITE_PORT_UCHAR((PUCHAR
)Port
+ 3, LineControl
);
979 WRITE_PORT_UCHAR((PUCHAR
)Port
+ 1, 0); /* set comm and DLAB to 0 */
980 WRITE_PORT_UCHAR((PUCHAR
)Port
+ 4, 0x09); /* DR int enable */
981 READ_PORT_UCHAR((PUCHAR
)Port
+ 5); /* clear error bits */
986 DetectSerialMouse(ULONG Port
)
993 /* Shutdown mouse or something like that */
994 LineControl
= READ_PORT_UCHAR((PUCHAR
)Port
+ 4);
995 WRITE_PORT_UCHAR((PUCHAR
)Port
+ 4, (LineControl
& ~0x02) | 0x01);
996 StallExecutionProcessor(100000);
1000 * Maybe there is no serial port although BIOS reported one (this
1001 * is the case on Apple hardware), or the serial port is misbehaving,
1002 * therefore we must give up after some time.
1005 while (READ_PORT_UCHAR((PUCHAR
)Port
+ 5) & 0x01)
1008 return MOUSE_TYPE_NONE
;
1009 READ_PORT_UCHAR((PUCHAR
)Port
);
1013 * Send modem control with 'Data Terminal Ready', 'Request To Send' and
1014 * 'Output Line 2' message. This enables mouse to identify.
1016 WRITE_PORT_UCHAR((PUCHAR
)Port
+ 4, 0x0b);
1018 /* Wait 10 milliseconds for the mouse getting ready */
1019 StallExecutionProcessor(10000);
1021 /* Read first four bytes, which contains Microsoft Mouse signs */
1023 for (i
= 0; i
< 4; i
++)
1025 while (((READ_PORT_UCHAR((PUCHAR
)Port
+ 5) & 1) == 0) && (TimeOut
> 0))
1027 StallExecutionProcessor(1000);
1030 return MOUSE_TYPE_NONE
;
1032 Buffer
[i
] = READ_PORT_UCHAR((PUCHAR
)Port
);
1035 DbgPrint((DPRINT_HWDETECT
,
1036 "Mouse data: %x %x %x %x\n",
1037 Buffer
[0],Buffer
[1],Buffer
[2],Buffer
[3]));
1039 /* Check that four bytes for signs */
1040 for (i
= 0; i
< 4; ++i
)
1042 if (Buffer
[i
] == 'B')
1044 /* Sign for Microsoft Ballpoint */
1045 // DbgPrint("Microsoft Ballpoint device detected\n");
1046 // DbgPrint("THIS DEVICE IS NOT SUPPORTED, YET\n");
1047 return MOUSE_TYPE_NONE
;
1049 else if (Buffer
[i
] == 'M')
1051 /* Sign for Microsoft Mouse protocol followed by button specifier */
1054 /* Overflow Error */
1055 return MOUSE_TYPE_NONE
;
1058 switch (Buffer
[i
+ 1])
1061 DbgPrint((DPRINT_HWDETECT
,
1062 "Microsoft Mouse with 3-buttons detected\n"));
1063 return MOUSE_TYPE_LOGITECH
;
1066 DbgPrint((DPRINT_HWDETECT
,
1067 "Microsoft Wheel Mouse detected\n"));
1068 return MOUSE_TYPE_WHEELZ
;
1072 DbgPrint((DPRINT_HWDETECT
,
1073 "Microsoft Mouse with 2-buttons detected\n"));
1074 return MOUSE_TYPE_MICROSOFT
;
1079 return MOUSE_TYPE_NONE
;
1084 GetSerialMousePnpId(ULONG Port
, char *Buffer
)
1091 WRITE_PORT_UCHAR((PUCHAR
)Port
+ 4, 0x09);
1093 /* Wait 10 milliseconds for the mouse getting ready */
1094 StallExecutionProcessor(10000);
1096 WRITE_PORT_UCHAR((PUCHAR
)Port
+ 4, 0x0b);
1098 StallExecutionProcessor(10000);
1103 while (((READ_PORT_UCHAR((PUCHAR
)Port
+ 5) & 1) == 0) && (TimeOut
> 0))
1105 StallExecutionProcessor(1000);
1113 c
= READ_PORT_UCHAR((PUCHAR
)Port
);
1114 if (c
== 0x08 || c
== 0x28)
1124 while (((READ_PORT_UCHAR((PUCHAR
)Port
+ 5) & 1) == 0) && (TimeOut
> 0))
1126 StallExecutionProcessor(1000);
1131 c
= READ_PORT_UCHAR((PUCHAR
)Port
);
1144 DetectSerialPointerPeripheral(FRLDRHKEY ControllerKey
,
1147 CM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
1149 WCHAR Identifier
[256];
1150 FRLDRHKEY PeripheralKey
;
1158 DbgPrint((DPRINT_HWDETECT
,
1159 "DetectSerialPointerPeripheral()\n"));
1163 InitializeSerialPort(Base
, 2);
1164 MouseType
= DetectSerialMouse(Base
);
1166 if (MouseType
!= MOUSE_TYPE_NONE
)
1168 Length
= GetSerialMousePnpId(Base
, Buffer
);
1169 DbgPrint((DPRINT_HWDETECT
,
1170 "PnP ID length: %u\n",
1175 /* Convert PnP sting to ASCII */
1176 if (Buffer
[0] == 0x08)
1178 for (i
= 0; i
< Length
; i
++)
1183 DbgPrint((DPRINT_HWDETECT
,
1184 "PnP ID string: %s\n",
1187 /* Copy PnpId string */
1188 for (i
= 0; i
< 7; i
++)
1190 Identifier
[i
] = Buffer
[3+i
];
1192 memcpy(&Identifier
[7],
1196 /* Skip device serial number */
1198 if (Buffer
[i
] == '\\')
1200 for (j
= ++i
; i
< Length
; ++i
)
1202 if (Buffer
[i
] == '\\')
1209 /* Skip PnP class */
1210 if (Buffer
[i
] == '\\')
1212 for (j
= ++i
; i
< Length
; ++i
)
1214 if (Buffer
[i
] == '\\')
1222 /* Skip compatible PnP Id */
1223 if (Buffer
[i
] == '\\')
1225 for (j
= ++i
; i
< Length
; ++i
)
1227 if (Buffer
[i
] == '\\')
1230 if (Buffer
[j
] == '*')
1236 /* Get product description */
1237 if (Buffer
[i
] == '\\')
1239 for (j
= ++i
; i
< Length
; ++i
)
1241 if (Buffer
[i
] == ';')
1248 for (k
= 0; k
< i
- j
; k
++)
1250 Identifier
[k
+ 10] = Buffer
[k
+ j
];
1252 Identifier
[10 + (i
-j
)] = 0;
1256 DbgPrint((DPRINT_HWDETECT
,
1257 "Identifier string: %S\n",
1261 if (Length
== 0 || wcslen(Identifier
) < 11)
1265 case MOUSE_TYPE_LOGITECH
:
1267 L
"LOGITECH SERIAL MOUSE");
1270 case MOUSE_TYPE_WHEELZ
:
1272 L
"MICROSOFT SERIAL MOUSE WITH WHEEL");
1275 case MOUSE_TYPE_MICROSOFT
:
1278 L
"MICROSOFT SERIAL MOUSE");
1283 /* Create 'PointerPeripheral' key */
1284 Error
= RegCreateKey(ControllerKey
,
1285 L
"PointerPeripheral\\0",
1287 if (Error
!= ERROR_SUCCESS
)
1289 DbgPrint((DPRINT_HWDETECT
,
1290 "Failed to create peripheral key\n"));
1293 DbgPrint((DPRINT_HWDETECT
,
1294 "Created key: PointerPeripheral\\0\n"));
1296 /* Set 'ComponentInformation' value */
1297 SetComponentInformation(PeripheralKey
,
1302 /* Set 'Configuration Data' value */
1303 memset(&FullResourceDescriptor
, 0, sizeof(CM_FULL_RESOURCE_DESCRIPTOR
));
1304 FullResourceDescriptor
.InterfaceType
= Isa
;
1305 FullResourceDescriptor
.BusNumber
= 0;
1306 FullResourceDescriptor
.PartialResourceList
.Version
= 1;
1307 FullResourceDescriptor
.PartialResourceList
.Revision
= 1;
1308 FullResourceDescriptor
.PartialResourceList
.Count
= 0;
1310 Error
= RegSetValue(PeripheralKey
,
1311 L
"Configuration Data",
1312 REG_FULL_RESOURCE_DESCRIPTOR
,
1313 (PCHAR
)&FullResourceDescriptor
,
1314 sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) -
1315 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
));
1316 if (Error
!= ERROR_SUCCESS
)
1318 DbgPrint((DPRINT_HWDETECT
,
1319 "RegSetValue(Configuration Data) failed (Error %u)\n",
1323 /* Set 'Identifier' value */
1324 Error
= RegSetValue(PeripheralKey
,
1328 (wcslen(Identifier
) + 1) * sizeof(WCHAR
));
1329 if (Error
!= ERROR_SUCCESS
)
1331 DbgPrint((DPRINT_HWDETECT
,
1332 "RegSetValue() failed (Error %u)\n",
1340 DetectSerialPorts(FRLDRHKEY BusKey
)
1342 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
1343 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
1344 PCM_SERIAL_DEVICE_DATA SerialDeviceData
;
1345 ULONG Irq
[4] = {4, 3, 4, 3};
1349 ULONG ControllerNumber
= 0;
1350 FRLDRHKEY ControllerKey
;
1355 DbgPrint((DPRINT_HWDETECT
, "DetectSerialPorts()\n"));
1357 ControllerNumber
= 0;
1358 BasePtr
= (PUSHORT
)0x400;
1359 for (i
= 0; i
< 4; i
++, BasePtr
++)
1361 Base
= (ULONG
)*BasePtr
;
1365 DbgPrint((DPRINT_HWDETECT
,
1366 "Found COM%u port at 0x%x\n",
1370 /* Create controller key */
1372 L
"SerialController\\%u",
1375 Error
= RegCreateKey(BusKey
,
1378 if (Error
!= ERROR_SUCCESS
)
1380 DbgPrint((DPRINT_HWDETECT
, "Failed to create controller key\n"));
1383 DbgPrint((DPRINT_HWDETECT
, "Created key: %S\n", Buffer
));
1385 /* Set 'ComponentInformation' value */
1386 SetComponentInformation(ControllerKey
,
1391 /* Build full device descriptor */
1392 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) +
1393 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
) +
1394 sizeof(CM_SERIAL_DEVICE_DATA
);
1395 FullResourceDescriptor
= MmAllocateMemory(Size
);
1396 if (FullResourceDescriptor
== NULL
)
1398 DbgPrint((DPRINT_HWDETECT
,
1399 "Failed to allocate resource descriptor\n"));
1402 memset(FullResourceDescriptor
, 0, Size
);
1404 /* Initialize resource descriptor */
1405 FullResourceDescriptor
->InterfaceType
= Isa
;
1406 FullResourceDescriptor
->BusNumber
= 0;
1407 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
1408 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
1409 FullResourceDescriptor
->PartialResourceList
.Count
= 3;
1412 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0];
1413 PartialDescriptor
->Type
= CmResourceTypePort
;
1414 PartialDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1415 PartialDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1416 PartialDescriptor
->u
.Port
.Start
.LowPart
= Base
;
1417 PartialDescriptor
->u
.Port
.Start
.HighPart
= 0x0;
1418 PartialDescriptor
->u
.Port
.Length
= 7;
1421 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[1];
1422 PartialDescriptor
->Type
= CmResourceTypeInterrupt
;
1423 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
1424 PartialDescriptor
->Flags
= CM_RESOURCE_INTERRUPT_LATCHED
;
1425 PartialDescriptor
->u
.Interrupt
.Level
= Irq
[i
];
1426 PartialDescriptor
->u
.Interrupt
.Vector
= 0;
1427 PartialDescriptor
->u
.Interrupt
.Affinity
= 0xFFFFFFFF;
1429 /* Set serial data (device specific) */
1430 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[2];
1431 PartialDescriptor
->Type
= CmResourceTypeDeviceSpecific
;
1432 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
1433 PartialDescriptor
->Flags
= 0;
1434 PartialDescriptor
->u
.DeviceSpecificData
.DataSize
= sizeof(CM_SERIAL_DEVICE_DATA
);
1437 (PCM_SERIAL_DEVICE_DATA
)&FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[3];
1438 SerialDeviceData
->BaudClock
= 1843200; /* UART Clock frequency (Hertz) */
1440 /* Set 'Configuration Data' value */
1441 Error
= RegSetValue(ControllerKey
,
1442 L
"Configuration Data",
1443 REG_FULL_RESOURCE_DESCRIPTOR
,
1444 (PCHAR
) FullResourceDescriptor
,
1446 MmFreeMemory(FullResourceDescriptor
);
1447 if (Error
!= ERROR_SUCCESS
)
1449 DbgPrint((DPRINT_HWDETECT
,
1450 "RegSetValue(Configuration Data) failed (Error %u)\n",
1454 /* Set 'Identifier' value */
1458 Error
= RegSetValue(ControllerKey
,
1462 (wcslen(Buffer
) + 1) * sizeof(WCHAR
));
1463 if (Error
!= ERROR_SUCCESS
)
1465 DbgPrint((DPRINT_HWDETECT
,
1466 "RegSetValue() failed (Error %u)\n",
1470 DbgPrint((DPRINT_HWDETECT
,
1471 "Created value: Identifier %s\n",
1474 if (!Rs232PortInUse(Base
))
1476 /* Detect serial mouse */
1477 DetectSerialPointerPeripheral(ControllerKey
, Base
);
1486 DetectParallelPorts(FRLDRHKEY BusKey
)
1488 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
1489 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
1490 ULONG Irq
[3] = {7, 5, (ULONG
)-1};
1492 FRLDRHKEY ControllerKey
;
1495 ULONG ControllerNumber
;
1500 DbgPrint((DPRINT_HWDETECT
, "DetectParallelPorts() called\n"));
1502 ControllerNumber
= 0;
1503 BasePtr
= (PUSHORT
)0x408;
1504 for (i
= 0; i
< 3; i
++, BasePtr
++)
1506 Base
= (ULONG
)*BasePtr
;
1510 DbgPrint((DPRINT_HWDETECT
,
1511 "Parallel port %u: %x\n",
1515 /* Create controller key */
1517 L
"ParallelController\\%u",
1520 Error
= RegCreateKey(BusKey
,
1523 if (Error
!= ERROR_SUCCESS
)
1525 DbgPrint((DPRINT_HWDETECT
, "Failed to create controller key\n"));
1528 DbgPrint((DPRINT_HWDETECT
, "Created key: %S\n", Buffer
));
1530 /* Set 'ComponentInformation' value */
1531 SetComponentInformation(ControllerKey
,
1536 /* Build full device descriptor */
1537 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
);
1538 if (Irq
[i
] != (ULONG
)-1)
1539 Size
+= sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
);
1541 FullResourceDescriptor
= MmAllocateMemory(Size
);
1542 if (FullResourceDescriptor
== NULL
)
1544 DbgPrint((DPRINT_HWDETECT
,
1545 "Failed to allocate resource descriptor\n"));
1548 memset(FullResourceDescriptor
, 0, Size
);
1550 /* Initialize resource descriptor */
1551 FullResourceDescriptor
->InterfaceType
= Isa
;
1552 FullResourceDescriptor
->BusNumber
= 0;
1553 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
1554 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
1555 FullResourceDescriptor
->PartialResourceList
.Count
= (Irq
[i
] != (ULONG
)-1) ? 2 : 1;
1558 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0];
1559 PartialDescriptor
->Type
= CmResourceTypePort
;
1560 PartialDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1561 PartialDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1562 PartialDescriptor
->u
.Port
.Start
.LowPart
= Base
;
1563 PartialDescriptor
->u
.Port
.Start
.HighPart
= 0x0;
1564 PartialDescriptor
->u
.Port
.Length
= 3;
1567 if (Irq
[i
] != (ULONG
)-1)
1569 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[1];
1570 PartialDescriptor
->Type
= CmResourceTypeInterrupt
;
1571 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
1572 PartialDescriptor
->Flags
= CM_RESOURCE_INTERRUPT_LATCHED
;
1573 PartialDescriptor
->u
.Interrupt
.Level
= Irq
[i
];
1574 PartialDescriptor
->u
.Interrupt
.Vector
= 0;
1575 PartialDescriptor
->u
.Interrupt
.Affinity
= 0xFFFFFFFF;
1578 /* Set 'Configuration Data' value */
1579 Error
= RegSetValue(ControllerKey
,
1580 L
"Configuration Data",
1581 REG_FULL_RESOURCE_DESCRIPTOR
,
1582 (PCHAR
) FullResourceDescriptor
,
1584 MmFreeMemory(FullResourceDescriptor
);
1585 if (Error
!= ERROR_SUCCESS
)
1587 DbgPrint((DPRINT_HWDETECT
,
1588 "RegSetValue(Configuration Data) failed (Error %u)\n",
1592 /* Set 'Identifier' value */
1596 Error
= RegSetValue(ControllerKey
,
1600 (wcslen(Buffer
) + 1) * sizeof(WCHAR
));
1601 if (Error
!= ERROR_SUCCESS
)
1603 DbgPrint((DPRINT_HWDETECT
,
1604 "RegSetValue() failed (Error %u)\n",
1608 DbgPrint((DPRINT_HWDETECT
,
1609 "Created value: Identifier %s\n",
1615 DbgPrint((DPRINT_HWDETECT
, "DetectParallelPorts() done\n"));
1620 DetectKeyboardDevice(VOID
)
1625 BOOLEAN Result
= TRUE
;
1627 /* Identify device */
1628 WRITE_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
,
1631 /* Wait for reply */
1632 for (Loops
= 0; Loops
< 100; Loops
++)
1634 StallExecutionProcessor(10000);
1635 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1636 if ((Status
& CONTROLLER_STATUS_OUTPUT_BUFFER_FULL
) != 0)
1640 if ((Status
& CONTROLLER_STATUS_OUTPUT_BUFFER_FULL
) == 0)
1642 /* PC/XT keyboard or no keyboard */
1646 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1647 if (Scancode
!= 0xFA)
1649 /* No ACK received */
1653 StallExecutionProcessor(10000);
1655 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1656 if ((Status
& CONTROLLER_STATUS_OUTPUT_BUFFER_FULL
) == 0)
1658 /* Found AT keyboard */
1662 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1663 if (Scancode
!= 0xAB)
1665 /* No 0xAB received */
1669 StallExecutionProcessor(10000);
1671 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1672 if ((Status
& CONTROLLER_STATUS_OUTPUT_BUFFER_FULL
) == 0)
1674 /* No byte in buffer */
1678 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1679 if (Scancode
!= 0x41)
1681 /* No 0x41 received */
1685 /* Found MF-II keyboard */
1691 DetectKeyboardPeripheral(FRLDRHKEY ControllerKey
)
1693 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
1694 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
1695 PCM_KEYBOARD_DEVICE_DATA KeyboardData
;
1696 FRLDRHKEY PeripheralKey
;
1700 /* HACK: don't call DetectKeyboardDevice() as it fails in Qemu 0.8.2 */
1701 if (TRUE
|| DetectKeyboardDevice())
1703 /* Create controller key */
1704 Error
= RegCreateKey(ControllerKey
,
1705 L
"KeyboardPeripheral\\0",
1707 if (Error
!= ERROR_SUCCESS
)
1709 DbgPrint((DPRINT_HWDETECT
, "Failed to create peripheral key\n"));
1712 DbgPrint((DPRINT_HWDETECT
, "Created key: KeyboardPeripheral\\0\n"));
1714 /* Set 'ComponentInformation' value */
1715 SetComponentInformation(ControllerKey
,
1720 /* Set 'Configuration Data' value */
1721 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) +
1722 sizeof(CM_KEYBOARD_DEVICE_DATA
);
1723 FullResourceDescriptor
= MmAllocateMemory(Size
);
1724 if (FullResourceDescriptor
== NULL
)
1726 DbgPrint((DPRINT_HWDETECT
,
1727 "Failed to allocate resource descriptor\n"));
1731 /* Initialize resource descriptor */
1732 memset(FullResourceDescriptor
, 0, Size
);
1733 FullResourceDescriptor
->InterfaceType
= Isa
;
1734 FullResourceDescriptor
->BusNumber
= 0;
1735 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
1736 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
1737 FullResourceDescriptor
->PartialResourceList
.Count
= 1;
1739 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0];
1740 PartialDescriptor
->Type
= CmResourceTypeDeviceSpecific
;
1741 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
1742 PartialDescriptor
->u
.DeviceSpecificData
.DataSize
= sizeof(CM_KEYBOARD_DEVICE_DATA
);
1744 KeyboardData
= (PCM_KEYBOARD_DEVICE_DATA
)(PartialDescriptor
+ 1);
1745 KeyboardData
->Version
= 1;
1746 KeyboardData
->Revision
= 1;
1747 KeyboardData
->Type
= 4;
1748 KeyboardData
->Subtype
= 0;
1749 KeyboardData
->KeyboardFlags
= 0x20;
1751 /* Set 'Configuration Data' value */
1752 Error
= RegSetValue(PeripheralKey
,
1753 L
"Configuration Data",
1754 REG_FULL_RESOURCE_DESCRIPTOR
,
1755 (PCHAR
)FullResourceDescriptor
,
1757 MmFreeMemory(FullResourceDescriptor
);
1758 if (Error
!= ERROR_SUCCESS
)
1760 DbgPrint((DPRINT_HWDETECT
,
1761 "RegSetValue(Configuration Data) failed (Error %u)\n",
1765 /* Set 'Identifier' value */
1766 Error
= RegSetValue(PeripheralKey
,
1769 (PCHAR
)L
"PCAT_ENHANCED",
1770 14 * sizeof(WCHAR
));
1771 if (Error
!= ERROR_SUCCESS
)
1773 DbgPrint((DPRINT_HWDETECT
,
1774 "RegSetValue() failed (Error %u)\n",
1782 DetectKeyboardController(FRLDRHKEY BusKey
)
1784 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
1785 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
1786 FRLDRHKEY ControllerKey
;
1790 /* Create controller key */
1791 Error
= RegCreateKey(BusKey
,
1792 L
"KeyboardController\\0",
1794 if (Error
!= ERROR_SUCCESS
)
1796 DbgPrint((DPRINT_HWDETECT
, "Failed to create controller key\n"));
1799 DbgPrint((DPRINT_HWDETECT
, "Created key: KeyboardController\\0\n"));
1801 /* Set 'ComponentInformation' value */
1802 SetComponentInformation(ControllerKey
,
1807 /* Set 'Configuration Data' value */
1808 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) +
1809 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
);
1810 FullResourceDescriptor
= MmAllocateMemory(Size
);
1811 if (FullResourceDescriptor
== NULL
)
1813 DbgPrint((DPRINT_HWDETECT
,
1814 "Failed to allocate resource descriptor\n"));
1818 /* Initialize resource descriptor */
1819 memset(FullResourceDescriptor
, 0, Size
);
1820 FullResourceDescriptor
->InterfaceType
= Isa
;
1821 FullResourceDescriptor
->BusNumber
= 0;
1822 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
1823 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
1824 FullResourceDescriptor
->PartialResourceList
.Count
= 3;
1827 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0];
1828 PartialDescriptor
->Type
= CmResourceTypeInterrupt
;
1829 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
1830 PartialDescriptor
->Flags
= CM_RESOURCE_INTERRUPT_LATCHED
;
1831 PartialDescriptor
->u
.Interrupt
.Level
= 1;
1832 PartialDescriptor
->u
.Interrupt
.Vector
= 0;
1833 PartialDescriptor
->u
.Interrupt
.Affinity
= 0xFFFFFFFF;
1835 /* Set IO Port 0x60 */
1836 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[1];
1837 PartialDescriptor
->Type
= CmResourceTypePort
;
1838 PartialDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1839 PartialDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1840 PartialDescriptor
->u
.Port
.Start
.LowPart
= 0x60;
1841 PartialDescriptor
->u
.Port
.Start
.HighPart
= 0x0;
1842 PartialDescriptor
->u
.Port
.Length
= 1;
1844 /* Set IO Port 0x64 */
1845 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[2];
1846 PartialDescriptor
->Type
= CmResourceTypePort
;
1847 PartialDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1848 PartialDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1849 PartialDescriptor
->u
.Port
.Start
.LowPart
= 0x64;
1850 PartialDescriptor
->u
.Port
.Start
.HighPart
= 0x0;
1851 PartialDescriptor
->u
.Port
.Length
= 1;
1853 /* Set 'Configuration Data' value */
1854 Error
= RegSetValue(ControllerKey
,
1855 L
"Configuration Data",
1856 REG_FULL_RESOURCE_DESCRIPTOR
,
1857 (PCHAR
)FullResourceDescriptor
,
1859 MmFreeMemory(FullResourceDescriptor
);
1860 if (Error
!= ERROR_SUCCESS
)
1862 DbgPrint((DPRINT_HWDETECT
,
1863 "RegSetValue(Configuration Data) failed (Error %u)\n",
1868 DetectKeyboardPeripheral(ControllerKey
);
1873 PS2ControllerWait(VOID
)
1878 for (Timeout
= 0; Timeout
< CONTROLLER_TIMEOUT
; Timeout
++)
1880 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1881 if ((Status
& CONTROLLER_STATUS_INPUT_BUFFER_FULL
) == 0)
1884 /* Sleep for one millisecond */
1885 StallExecutionProcessor(1000);
1891 DetectPS2AuxPort(VOID
)
1894 /* Current detection is too unreliable. Just do as if
1895 * the PS/2 aux port is always present
1902 /* Put the value 0x5A in the output buffer using the
1903 * "WriteAuxiliary Device Output Buffer" command (0xD3).
1904 * Poll the Status Register for a while to see if the value really turns up
1905 * in the Data Register. If the KEYBOARD_STATUS_MOUSE_OBF bit is also set
1906 * to 1 in the Status Register, we assume this controller has an
1907 * Auxiliary Port (a.k.a. Mouse Port).
1909 PS2ControllerWait();
1910 WRITE_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_CONTROL
,
1911 CONTROLLER_COMMAND_WRITE_MOUSE_OUTPUT_BUFFER
);
1912 PS2ControllerWait();
1914 /* 0x5A is a random dummy value */
1915 WRITE_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
,
1918 for (Loops
= 0; Loops
< 10; Loops
++)
1920 StallExecutionProcessor(10000);
1921 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1922 if ((Status
& CONTROLLER_STATUS_OUTPUT_BUFFER_FULL
) != 0)
1926 READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1928 return (Status
& CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL
);
1934 DetectPS2AuxDevice(VOID
)
1939 BOOLEAN Result
= TRUE
;
1941 PS2ControllerWait();
1942 WRITE_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_CONTROL
,
1943 CONTROLLER_COMMAND_WRITE_MOUSE
);
1944 PS2ControllerWait();
1946 /* Identify device */
1947 WRITE_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
,
1950 /* Wait for reply */
1951 for (Loops
= 0; Loops
< 100; Loops
++)
1953 StallExecutionProcessor(10000);
1954 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1955 if ((Status
& CONTROLLER_STATUS_OUTPUT_BUFFER_FULL
) != 0)
1959 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1960 if ((Status
& CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL
) == 0)
1963 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1964 if (Scancode
!= 0xFA)
1967 StallExecutionProcessor(10000);
1969 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1970 if ((Status
& CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL
) == 0)
1973 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1974 if (Scancode
!= 0x00)
1982 DetectPS2Mouse(FRLDRHKEY BusKey
)
1984 CM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
1985 FRLDRHKEY ControllerKey
;
1986 FRLDRHKEY PeripheralKey
;
1989 if (DetectPS2AuxPort())
1991 DbgPrint((DPRINT_HWDETECT
, "Detected PS2 port\n"));
1993 /* Create controller key */
1994 Error
= RegCreateKey(BusKey
,
1995 L
"PointerController\\0",
1997 if (Error
!= ERROR_SUCCESS
)
1999 DbgPrint((DPRINT_HWDETECT
, "Failed to create controller key\n"));
2002 DbgPrint((DPRINT_HWDETECT
, "Created key: PointerController\\0\n"));
2004 /* Set 'ComponentInformation' value */
2005 SetComponentInformation(ControllerKey
,
2010 memset(&FullResourceDescriptor
, 0, sizeof(CM_FULL_RESOURCE_DESCRIPTOR
));
2012 /* Initialize resource descriptor */
2013 FullResourceDescriptor
.InterfaceType
= Isa
;
2014 FullResourceDescriptor
.BusNumber
= 0;
2015 FullResourceDescriptor
.PartialResourceList
.Version
= 1;
2016 FullResourceDescriptor
.PartialResourceList
.Revision
= 1;
2017 FullResourceDescriptor
.PartialResourceList
.Count
= 1;
2020 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].Type
= CmResourceTypeInterrupt
;
2021 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].ShareDisposition
= CmResourceShareUndetermined
;
2022 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].Flags
= CM_RESOURCE_INTERRUPT_LATCHED
;
2023 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].u
.Interrupt
.Level
= 12;
2024 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].u
.Interrupt
.Vector
= 0;
2025 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].u
.Interrupt
.Affinity
= 0xFFFFFFFF;
2027 /* Set 'Configuration Data' value */
2028 Error
= RegSetValue(ControllerKey
,
2029 L
"Configuration Data",
2030 REG_FULL_RESOURCE_DESCRIPTOR
,
2031 (PCHAR
)&FullResourceDescriptor
,
2032 sizeof(CM_FULL_RESOURCE_DESCRIPTOR
));
2033 if (Error
!= ERROR_SUCCESS
)
2035 DbgPrint((DPRINT_HWDETECT
,
2036 "RegSetValue(Configuration Data) failed (Error %u)\n",
2042 if (DetectPS2AuxDevice())
2044 DbgPrint((DPRINT_HWDETECT
, "Detected PS2 mouse\n"));
2046 /* Create peripheral key */
2047 Error
= RegCreateKey(ControllerKey
,
2048 L
"PointerPeripheral\\0",
2050 if (Error
!= ERROR_SUCCESS
)
2052 DbgPrint((DPRINT_HWDETECT
, "Failed to create peripheral key\n"));
2055 DbgPrint((DPRINT_HWDETECT
, "Created key: PointerPeripheral\\0\n"));
2057 /* Set 'ComponentInformation' value */
2058 SetComponentInformation(PeripheralKey
,
2063 /* Initialize resource descriptor */
2064 memset(&FullResourceDescriptor
, 0, sizeof(CM_FULL_RESOURCE_DESCRIPTOR
));
2065 FullResourceDescriptor
.InterfaceType
= Isa
;
2066 FullResourceDescriptor
.BusNumber
= 0;
2067 FullResourceDescriptor
.PartialResourceList
.Version
= 1;
2068 FullResourceDescriptor
.PartialResourceList
.Revision
= 1;
2069 FullResourceDescriptor
.PartialResourceList
.Count
= 0;
2071 /* Set 'Configuration Data' value */
2072 Error
= RegSetValue(PeripheralKey
,
2073 L
"Configuration Data",
2074 REG_FULL_RESOURCE_DESCRIPTOR
,
2075 (PCHAR
)&FullResourceDescriptor
,
2076 sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) -
2077 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
));
2078 if (Error
!= ERROR_SUCCESS
)
2080 DbgPrint((DPRINT_HWDETECT
,
2081 "RegSetValue(Configuration Data) failed (Error %u)\n",
2086 /* Set 'Identifier' value */
2087 Error
= RegSetValue(PeripheralKey
,
2090 (PCHAR
)L
"MICROSOFT PS2 MOUSE",
2091 20 * sizeof(WCHAR
));
2092 if (Error
!= ERROR_SUCCESS
)
2094 DbgPrint((DPRINT_HWDETECT
,
2095 "RegSetValue() failed (Error %u)\n",
2105 DetectDisplayController(FRLDRHKEY BusKey
)
2108 FRLDRHKEY ControllerKey
;
2112 Error
= RegCreateKey(BusKey
,
2113 L
"DisplayController\\0",
2115 if (Error
!= ERROR_SUCCESS
)
2117 DbgPrint((DPRINT_HWDETECT
, "Failed to create controller key\n"));
2120 DbgPrint((DPRINT_HWDETECT
, "Created key: DisplayController\\0\n"));
2122 /* Set 'ComponentInformation' value */
2123 SetComponentInformation(ControllerKey
,
2128 /* FIXME: Set 'ComponentInformation' value */
2130 VesaVersion
= BiosIsVesaSupported();
2131 if (VesaVersion
!= 0)
2133 DbgPrint((DPRINT_HWDETECT
,
2134 "VESA version %c.%c\n",
2135 (VesaVersion
>> 8) + '0',
2136 (VesaVersion
& 0xFF) + '0'));
2140 DbgPrint((DPRINT_HWDETECT
,
2141 "VESA not supported\n"));
2144 if (VesaVersion
>= 0x0200)
2155 /* Set 'Identifier' value */
2156 Error
= RegSetValue(ControllerKey
,
2160 (wcslen(Buffer
) + 1) * sizeof(WCHAR
));
2161 if (Error
!= ERROR_SUCCESS
)
2163 DbgPrint((DPRINT_HWDETECT
,
2164 "RegSetValue() failed (Error %u)\n",
2169 /* FIXME: Add display peripheral (monitor) data */
2174 DetectIsaBios(FRLDRHKEY SystemKey
, ULONG
*BusNumber
)
2176 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
2182 /* Create new bus key */
2184 L
"MultifunctionAdapter\\%u", *BusNumber
);
2185 Error
= RegCreateKey(SystemKey
,
2188 if (Error
!= ERROR_SUCCESS
)
2190 DbgPrint((DPRINT_HWDETECT
, "RegCreateKey() failed (Error %u)\n", (int)Error
));
2194 /* Set 'Component Information' value similar to my NT4 box */
2195 SetComponentInformation(BusKey
,
2200 /* Increment bus number */
2203 /* Set 'Identifier' value */
2204 Error
= RegSetValue(BusKey
,
2209 if (Error
!= ERROR_SUCCESS
)
2211 DbgPrint((DPRINT_HWDETECT
, "RegSetValue() failed (Error %u)\n", (int)Error
));
2215 /* Set 'Configuration Data' value */
2216 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) -
2217 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
);
2218 FullResourceDescriptor
= MmAllocateMemory(Size
);
2219 if (FullResourceDescriptor
== NULL
)
2221 DbgPrint((DPRINT_HWDETECT
,
2222 "Failed to allocate resource descriptor\n"));
2226 /* Initialize resource descriptor */
2227 memset(FullResourceDescriptor
, 0, Size
);
2228 FullResourceDescriptor
->InterfaceType
= Isa
;
2229 FullResourceDescriptor
->BusNumber
= 0;
2230 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
2231 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
2232 FullResourceDescriptor
->PartialResourceList
.Count
= 0;
2234 /* Set 'Configuration Data' value */
2235 Error
= RegSetValue(BusKey
,
2236 L
"Configuration Data",
2237 REG_FULL_RESOURCE_DESCRIPTOR
,
2238 (PCHAR
) FullResourceDescriptor
,
2240 MmFreeMemory(FullResourceDescriptor
);
2241 if (Error
!= ERROR_SUCCESS
)
2243 DbgPrint((DPRINT_HWDETECT
,
2244 "RegSetValue(Configuration Data) failed (Error %u)\n",
2249 /* Detect ISA/BIOS devices */
2250 DetectBiosDisks(SystemKey
, BusKey
);
2252 DetectBiosFloppyController(SystemKey
, BusKey
);
2254 DetectSerialPorts(BusKey
);
2256 DetectParallelPorts(BusKey
);
2258 DetectKeyboardController(BusKey
);
2260 DetectPS2Mouse(BusKey
);
2262 DetectDisplayController(BusKey
);
2264 /* FIXME: Detect more ISA devices */
2271 FRLDRHKEY SystemKey
;
2272 ULONG BusNumber
= 0;
2275 DbgPrint((DPRINT_HWDETECT
, "DetectHardware()\n"));
2277 /* Create the 'System' key */
2278 Error
= RegCreateKey(NULL
,
2279 L
"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System",
2281 if (Error
!= ERROR_SUCCESS
)
2283 DbgPrint((DPRINT_HWDETECT
, "RegCreateKey() failed (Error %u)\n", (int)Error
));
2288 DetectPciBios(SystemKey
, &BusNumber
);
2289 DetectApmBios(SystemKey
, &BusNumber
);
2290 DetectPnpBios(SystemKey
, &BusNumber
);
2291 DetectIsaBios(SystemKey
, &BusNumber
);
2292 DetectAcpiBios(SystemKey
, &BusNumber
);
2294 DbgPrint((DPRINT_HWDETECT
, "DetectHardware() Done\n"));
2297 printf("*** System stopped ***\n");