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
= 0;
941 PartialDescriptor
->u
.Interrupt
.Vector
= 6;
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
= 0;
1426 PartialDescriptor
->u
.Interrupt
.Vector
= Irq
[i
];
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
= 0;
1574 PartialDescriptor
->u
.Interrupt
.Vector
= Irq
[i
];
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 WRITE_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
,
1628 StallExecutionProcessor(10000);
1630 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1631 if ((Status
& 0x01) != 0x01)
1633 /* PC/XT keyboard or no keyboard */
1637 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1638 if (Scancode
!= 0xFA)
1640 /* No ACK received */
1644 StallExecutionProcessor(10000);
1645 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1646 if ((Status
& 0x01) != 0x01)
1648 /* Found AT keyboard */
1652 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1653 if (Scancode
!= 0xAB)
1655 /* No 0xAB received */
1659 StallExecutionProcessor(10000);
1660 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1661 if ((Status
& 0x01) != 0x01)
1663 /* No byte in buffer */
1667 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1668 if (Scancode
!= 0x41)
1670 /* No 0x41 received */
1674 /* Found MF-II keyboard */
1680 DetectKeyboardPeripheral(FRLDRHKEY ControllerKey
)
1682 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
1683 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
1684 PCM_KEYBOARD_DEVICE_DATA KeyboardData
;
1685 FRLDRHKEY PeripheralKey
;
1689 /* HACK: don't call DetectKeyboardDevice() as it fails in Qemu 0.8.2 */
1690 if (TRUE
|| DetectKeyboardDevice())
1692 /* Create controller key */
1693 Error
= RegCreateKey(ControllerKey
,
1694 L
"KeyboardPeripheral\\0",
1696 if (Error
!= ERROR_SUCCESS
)
1698 DbgPrint((DPRINT_HWDETECT
, "Failed to create peripheral key\n"));
1701 DbgPrint((DPRINT_HWDETECT
, "Created key: KeyboardPeripheral\\0\n"));
1703 /* Set 'ComponentInformation' value */
1704 SetComponentInformation(ControllerKey
,
1709 /* Set 'Configuration Data' value */
1710 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) +
1711 sizeof(CM_KEYBOARD_DEVICE_DATA
);
1712 FullResourceDescriptor
= MmAllocateMemory(Size
);
1713 if (FullResourceDescriptor
== NULL
)
1715 DbgPrint((DPRINT_HWDETECT
,
1716 "Failed to allocate resource descriptor\n"));
1720 /* Initialize resource descriptor */
1721 memset(FullResourceDescriptor
, 0, Size
);
1722 FullResourceDescriptor
->InterfaceType
= Isa
;
1723 FullResourceDescriptor
->BusNumber
= 0;
1724 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
1725 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
1726 FullResourceDescriptor
->PartialResourceList
.Count
= 1;
1728 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0];
1729 PartialDescriptor
->Type
= CmResourceTypeDeviceSpecific
;
1730 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
1731 PartialDescriptor
->u
.DeviceSpecificData
.DataSize
= sizeof(CM_KEYBOARD_DEVICE_DATA
);
1733 KeyboardData
= (PCM_KEYBOARD_DEVICE_DATA
)(PartialDescriptor
+ 1);
1734 KeyboardData
->Version
= 1;
1735 KeyboardData
->Revision
= 1;
1736 KeyboardData
->Type
= 4;
1737 KeyboardData
->Subtype
= 0;
1738 KeyboardData
->KeyboardFlags
= 0x20;
1740 /* Set 'Configuration Data' value */
1741 Error
= RegSetValue(PeripheralKey
,
1742 L
"Configuration Data",
1743 REG_FULL_RESOURCE_DESCRIPTOR
,
1744 (PCHAR
)FullResourceDescriptor
,
1746 MmFreeMemory(FullResourceDescriptor
);
1747 if (Error
!= ERROR_SUCCESS
)
1749 DbgPrint((DPRINT_HWDETECT
,
1750 "RegSetValue(Configuration Data) failed (Error %u)\n",
1754 /* Set 'Identifier' value */
1755 Error
= RegSetValue(PeripheralKey
,
1758 (PCHAR
)L
"PCAT_ENHANCED",
1759 14 * sizeof(WCHAR
));
1760 if (Error
!= ERROR_SUCCESS
)
1762 DbgPrint((DPRINT_HWDETECT
,
1763 "RegSetValue() failed (Error %u)\n",
1771 DetectKeyboardController(FRLDRHKEY BusKey
)
1773 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
1774 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
1775 FRLDRHKEY ControllerKey
;
1779 /* Create controller key */
1780 Error
= RegCreateKey(BusKey
,
1781 L
"KeyboardController\\0",
1783 if (Error
!= ERROR_SUCCESS
)
1785 DbgPrint((DPRINT_HWDETECT
, "Failed to create controller key\n"));
1788 DbgPrint((DPRINT_HWDETECT
, "Created key: KeyboardController\\0\n"));
1790 /* Set 'ComponentInformation' value */
1791 SetComponentInformation(ControllerKey
,
1796 /* Set 'Configuration Data' value */
1797 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) +
1798 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
);
1799 FullResourceDescriptor
= MmAllocateMemory(Size
);
1800 if (FullResourceDescriptor
== NULL
)
1802 DbgPrint((DPRINT_HWDETECT
,
1803 "Failed to allocate resource descriptor\n"));
1807 /* Initialize resource descriptor */
1808 memset(FullResourceDescriptor
, 0, Size
);
1809 FullResourceDescriptor
->InterfaceType
= Isa
;
1810 FullResourceDescriptor
->BusNumber
= 0;
1811 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
1812 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
1813 FullResourceDescriptor
->PartialResourceList
.Count
= 3;
1816 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[0];
1817 PartialDescriptor
->Type
= CmResourceTypeInterrupt
;
1818 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
1819 PartialDescriptor
->Flags
= CM_RESOURCE_INTERRUPT_LATCHED
;
1820 PartialDescriptor
->u
.Interrupt
.Level
= 0;
1821 PartialDescriptor
->u
.Interrupt
.Vector
= 1;
1822 PartialDescriptor
->u
.Interrupt
.Affinity
= 0xFFFFFFFF;
1824 /* Set IO Port 0x60 */
1825 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[1];
1826 PartialDescriptor
->Type
= CmResourceTypePort
;
1827 PartialDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1828 PartialDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1829 PartialDescriptor
->u
.Port
.Start
.LowPart
= 0x60;
1830 PartialDescriptor
->u
.Port
.Start
.HighPart
= 0x0;
1831 PartialDescriptor
->u
.Port
.Length
= 1;
1833 /* Set IO Port 0x64 */
1834 PartialDescriptor
= &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[2];
1835 PartialDescriptor
->Type
= CmResourceTypePort
;
1836 PartialDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
1837 PartialDescriptor
->Flags
= CM_RESOURCE_PORT_IO
;
1838 PartialDescriptor
->u
.Port
.Start
.LowPart
= 0x64;
1839 PartialDescriptor
->u
.Port
.Start
.HighPart
= 0x0;
1840 PartialDescriptor
->u
.Port
.Length
= 1;
1842 /* Set 'Configuration Data' value */
1843 Error
= RegSetValue(ControllerKey
,
1844 L
"Configuration Data",
1845 REG_FULL_RESOURCE_DESCRIPTOR
,
1846 (PCHAR
)FullResourceDescriptor
,
1848 MmFreeMemory(FullResourceDescriptor
);
1849 if (Error
!= ERROR_SUCCESS
)
1851 DbgPrint((DPRINT_HWDETECT
,
1852 "RegSetValue(Configuration Data) failed (Error %u)\n",
1857 DetectKeyboardPeripheral(ControllerKey
);
1862 PS2ControllerWait(VOID
)
1867 for (Timeout
= 0; Timeout
< CONTROLLER_TIMEOUT
; Timeout
++)
1869 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1870 if ((Status
& CONTROLLER_STATUS_INPUT_BUFFER_FULL
) == 0)
1873 /* Sleep for one millisecond */
1874 StallExecutionProcessor(1000);
1880 DetectPS2AuxPort(VOID
)
1886 /* Put the value 0x5A in the output buffer using the
1887 * "WriteAuxiliary Device Output Buffer" command (0xD3).
1888 * Poll the Status Register for a while to see if the value really turns up
1889 * in the Data Register. If the KEYBOARD_STATUS_MOUSE_OBF bit is also set
1890 * to 1 in the Status Register, we assume this controller has an
1891 * Auxiliary Port (a.k.a. Mouse Port).
1893 PS2ControllerWait();
1894 WRITE_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_CONTROL
,
1895 CONTROLLER_COMMAND_WRITE_MOUSE_OUTPUT_BUFFER
);
1896 PS2ControllerWait();
1898 /* 0x5A is a random dummy value */
1899 WRITE_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
,
1902 for (Loops
= 0; Loops
< 10; Loops
++)
1904 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1906 if ((Status
& CONTROLLER_STATUS_OUTPUT_BUFFER_FULL
) != 0)
1908 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1909 if ((Status
& CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL
) != 0)
1916 StallExecutionProcessor(10000);
1924 DetectPS2AuxDevice(VOID
)
1929 PS2ControllerWait();
1930 WRITE_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_CONTROL
,
1931 CONTROLLER_COMMAND_WRITE_MOUSE
);
1932 PS2ControllerWait();
1934 /* Identify device */
1935 WRITE_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
,
1938 StallExecutionProcessor(10000);
1940 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1941 if ((Status
& CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL
) == 0)
1946 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1947 if (Scancode
!= 0xFA)
1950 StallExecutionProcessor(10000);
1952 Status
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_STATUS
);
1953 if ((Status
& CONTROLLER_STATUS_MOUSE_OUTPUT_BUFFER_FULL
) == 0)
1958 Scancode
= READ_PORT_UCHAR((PUCHAR
)CONTROLLER_REGISTER_DATA
);
1959 if (Scancode
!= 0x00)
1967 DetectPS2Mouse(FRLDRHKEY BusKey
)
1969 CM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
1970 FRLDRHKEY ControllerKey
;
1971 FRLDRHKEY PeripheralKey
;
1974 if (DetectPS2AuxPort())
1976 DbgPrint((DPRINT_HWDETECT
, "Detected PS2 port\n"));
1978 /* Create controller key */
1979 Error
= RegCreateKey(BusKey
,
1980 L
"PointerController\\0",
1982 if (Error
!= ERROR_SUCCESS
)
1984 DbgPrint((DPRINT_HWDETECT
, "Failed to create controller key\n"));
1987 DbgPrint((DPRINT_HWDETECT
, "Created key: PointerController\\0\n"));
1989 /* Set 'ComponentInformation' value */
1990 SetComponentInformation(ControllerKey
,
1995 memset(&FullResourceDescriptor
, 0, sizeof(CM_FULL_RESOURCE_DESCRIPTOR
));
1997 /* Initialize resource descriptor */
1998 FullResourceDescriptor
.InterfaceType
= Isa
;
1999 FullResourceDescriptor
.BusNumber
= 0;
2000 FullResourceDescriptor
.PartialResourceList
.Version
= 1;
2001 FullResourceDescriptor
.PartialResourceList
.Revision
= 1;
2002 FullResourceDescriptor
.PartialResourceList
.Count
= 1;
2005 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].Type
= CmResourceTypeInterrupt
;
2006 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].ShareDisposition
= CmResourceShareUndetermined
;
2007 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].Flags
= CM_RESOURCE_INTERRUPT_LATCHED
;
2008 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].u
.Interrupt
.Level
= 0;
2009 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].u
.Interrupt
.Vector
= 12;
2010 FullResourceDescriptor
.PartialResourceList
.PartialDescriptors
[0].u
.Interrupt
.Affinity
= 0xFFFFFFFF;
2012 /* Set 'Configuration Data' value */
2013 Error
= RegSetValue(ControllerKey
,
2014 L
"Configuration Data",
2015 REG_FULL_RESOURCE_DESCRIPTOR
,
2016 (PCHAR
)&FullResourceDescriptor
,
2017 sizeof(CM_FULL_RESOURCE_DESCRIPTOR
));
2018 if (Error
!= ERROR_SUCCESS
)
2020 DbgPrint((DPRINT_HWDETECT
,
2021 "RegSetValue(Configuration Data) failed (Error %u)\n",
2027 if (DetectPS2AuxDevice())
2029 DbgPrint((DPRINT_HWDETECT
, "Detected PS2 mouse\n"));
2031 /* Create peripheral key */
2032 Error
= RegCreateKey(ControllerKey
,
2033 L
"PointerPeripheral\\0",
2035 if (Error
!= ERROR_SUCCESS
)
2037 DbgPrint((DPRINT_HWDETECT
, "Failed to create peripheral key\n"));
2040 DbgPrint((DPRINT_HWDETECT
, "Created key: PointerPeripheral\\0\n"));
2042 /* Set 'ComponentInformation' value */
2043 SetComponentInformation(PeripheralKey
,
2048 /* Initialize resource descriptor */
2049 memset(&FullResourceDescriptor
, 0, sizeof(CM_FULL_RESOURCE_DESCRIPTOR
));
2050 FullResourceDescriptor
.InterfaceType
= Isa
;
2051 FullResourceDescriptor
.BusNumber
= 0;
2052 FullResourceDescriptor
.PartialResourceList
.Version
= 1;
2053 FullResourceDescriptor
.PartialResourceList
.Revision
= 1;
2054 FullResourceDescriptor
.PartialResourceList
.Count
= 0;
2056 /* Set 'Configuration Data' value */
2057 Error
= RegSetValue(PeripheralKey
,
2058 L
"Configuration Data",
2059 REG_FULL_RESOURCE_DESCRIPTOR
,
2060 (PCHAR
)&FullResourceDescriptor
,
2061 sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) -
2062 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
));
2063 if (Error
!= ERROR_SUCCESS
)
2065 DbgPrint((DPRINT_HWDETECT
,
2066 "RegSetValue(Configuration Data) failed (Error %u)\n",
2071 /* Set 'Identifier' value */
2072 Error
= RegSetValue(PeripheralKey
,
2075 (PCHAR
)L
"MICROSOFT PS2 MOUSE",
2076 20 * sizeof(WCHAR
));
2077 if (Error
!= ERROR_SUCCESS
)
2079 DbgPrint((DPRINT_HWDETECT
,
2080 "RegSetValue() failed (Error %u)\n",
2090 DetectDisplayController(FRLDRHKEY BusKey
)
2093 FRLDRHKEY ControllerKey
;
2097 Error
= RegCreateKey(BusKey
,
2098 L
"DisplayController\\0",
2100 if (Error
!= ERROR_SUCCESS
)
2102 DbgPrint((DPRINT_HWDETECT
, "Failed to create controller key\n"));
2105 DbgPrint((DPRINT_HWDETECT
, "Created key: PointerController\\0\n"));
2107 /* Set 'ComponentInformation' value */
2108 SetComponentInformation(ControllerKey
,
2113 /* FIXME: Set 'ComponentInformation' value */
2115 VesaVersion
= BiosIsVesaSupported();
2116 if (VesaVersion
!= 0)
2118 DbgPrint((DPRINT_HWDETECT
,
2119 "VESA version %c.%c\n",
2120 (VesaVersion
>> 8) + '0',
2121 (VesaVersion
& 0xFF) + '0'));
2125 DbgPrint((DPRINT_HWDETECT
,
2126 "VESA not supported\n"));
2129 if (VesaVersion
>= 0x0200)
2140 /* Set 'Identifier' value */
2141 Error
= RegSetValue(ControllerKey
,
2145 (wcslen(Buffer
) + 1) * sizeof(WCHAR
));
2146 if (Error
!= ERROR_SUCCESS
)
2148 DbgPrint((DPRINT_HWDETECT
,
2149 "RegSetValue() failed (Error %u)\n",
2154 /* FIXME: Add display peripheral (monitor) data */
2159 DetectIsaBios(FRLDRHKEY SystemKey
, ULONG
*BusNumber
)
2161 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
2167 /* Create new bus key */
2169 L
"MultifunctionAdapter\\%u", *BusNumber
);
2170 Error
= RegCreateKey(SystemKey
,
2173 if (Error
!= ERROR_SUCCESS
)
2175 DbgPrint((DPRINT_HWDETECT
, "RegCreateKey() failed (Error %u)\n", (int)Error
));
2179 /* Set 'Component Information' value similar to my NT4 box */
2180 SetComponentInformation(BusKey
,
2185 /* Increment bus number */
2188 /* Set 'Identifier' value */
2189 Error
= RegSetValue(BusKey
,
2194 if (Error
!= ERROR_SUCCESS
)
2196 DbgPrint((DPRINT_HWDETECT
, "RegSetValue() failed (Error %u)\n", (int)Error
));
2200 /* Set 'Configuration Data' value */
2201 Size
= sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) -
2202 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
);
2203 FullResourceDescriptor
= MmAllocateMemory(Size
);
2204 if (FullResourceDescriptor
== NULL
)
2206 DbgPrint((DPRINT_HWDETECT
,
2207 "Failed to allocate resource descriptor\n"));
2211 /* Initialize resource descriptor */
2212 memset(FullResourceDescriptor
, 0, Size
);
2213 FullResourceDescriptor
->InterfaceType
= Isa
;
2214 FullResourceDescriptor
->BusNumber
= 0;
2215 FullResourceDescriptor
->PartialResourceList
.Version
= 1;
2216 FullResourceDescriptor
->PartialResourceList
.Revision
= 1;
2217 FullResourceDescriptor
->PartialResourceList
.Count
= 0;
2219 /* Set 'Configuration Data' value */
2220 Error
= RegSetValue(BusKey
,
2221 L
"Configuration Data",
2222 REG_FULL_RESOURCE_DESCRIPTOR
,
2223 (PCHAR
) FullResourceDescriptor
,
2225 MmFreeMemory(FullResourceDescriptor
);
2226 if (Error
!= ERROR_SUCCESS
)
2228 DbgPrint((DPRINT_HWDETECT
,
2229 "RegSetValue(Configuration Data) failed (Error %u)\n",
2234 /* Detect ISA/BIOS devices */
2235 DetectBiosDisks(SystemKey
, BusKey
);
2237 DetectBiosFloppyController(SystemKey
, BusKey
);
2239 DetectSerialPorts(BusKey
);
2241 DetectParallelPorts(BusKey
);
2243 DetectKeyboardController(BusKey
);
2245 DetectPS2Mouse(BusKey
);
2247 DetectDisplayController(BusKey
);
2249 /* FIXME: Detect more ISA devices */
2256 FRLDRHKEY SystemKey
;
2257 ULONG BusNumber
= 0;
2260 DbgPrint((DPRINT_HWDETECT
, "DetectHardware()\n"));
2262 /* Create the 'System' key */
2263 Error
= RegCreateKey(NULL
,
2264 L
"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System",
2266 if (Error
!= ERROR_SUCCESS
)
2268 DbgPrint((DPRINT_HWDETECT
, "RegCreateKey() failed (Error %u)\n", (int)Error
));
2275 DetectCPUs(SystemKey
);
2278 DetectPciBios(SystemKey
, &BusNumber
);
2279 DetectApmBios(SystemKey
, &BusNumber
);
2280 DetectPnpBios(SystemKey
, &BusNumber
);
2281 DetectIsaBios(SystemKey
, &BusNumber
);
2282 DetectAcpiBios(SystemKey
, &BusNumber
);
2284 DbgPrint((DPRINT_HWDETECT
, "DetectHardware() Done\n"));
2287 printf("*** System stopped ***\n");