5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 static CHAR Hex
[] = "0123456789ABCDEF";
26 //static unsigned int delay_count = 1;
28 extern ULONG reactos_disk_count
;
29 extern ARC_DISK_SIGNATURE reactos_arc_disk_info
[];
30 extern char reactos_arc_strings
[32][256];
33 SetHarddiskConfigurationData(PCONFIGURATION_COMPONENT_DATA DiskKey
,
36 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
37 PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
;
38 EXTENDED_GEOMETRY ExtGeometry
;
42 /* Set 'Configuration Data' value */
43 Size
= sizeof(CM_PARTIAL_RESOURCE_LIST
) +
44 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA
);
45 PartialResourceList
= MmHeapAlloc(Size
);
46 if (PartialResourceList
== NULL
)
48 DbgPrint((DPRINT_HWDETECT
,
49 "Failed to allocate a full resource descriptor\n"));
53 memset(PartialResourceList
, 0, Size
);
54 PartialResourceList
->Version
= 1;
55 PartialResourceList
->Revision
= 1;
56 PartialResourceList
->Count
= 1;
57 PartialResourceList
->PartialDescriptors
[0].Type
=
58 CmResourceTypeDeviceSpecific
;
59 // PartialResourceList->PartialDescriptors[0].ShareDisposition =
60 // PartialResourceList->PartialDescriptors[0].Flags =
61 PartialResourceList
->PartialDescriptors
[0].u
.DeviceSpecificData
.DataSize
=
62 sizeof(CM_DISK_GEOMETRY_DEVICE_DATA
);
64 /* Get pointer to geometry data */
65 DiskGeometry
= (PVOID
)(((ULONG_PTR
)PartialResourceList
) + sizeof(CM_PARTIAL_RESOURCE_LIST
));
67 /* Get the disk geometry */
68 ExtGeometry
.Size
= sizeof(EXTENDED_GEOMETRY
);
70 if(MachDiskGetDriveGeometry(DriveNumber
, &Geometry
))
72 DiskGeometry
->BytesPerSector
= Geometry
.BytesPerSector
;
73 DiskGeometry
->NumberOfCylinders
= Geometry
.Cylinders
;
74 DiskGeometry
->SectorsPerTrack
= Geometry
.Sectors
;
75 DiskGeometry
->NumberOfHeads
= Geometry
.Heads
;
79 DbgPrint((DPRINT_HWDETECT
, "Reading disk geometry failed\n"));
80 MmHeapFree(PartialResourceList
);
83 DbgPrint((DPRINT_HWDETECT
,
84 "Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
86 DiskGeometry
->NumberOfCylinders
,
87 DiskGeometry
->NumberOfHeads
,
88 DiskGeometry
->SectorsPerTrack
,
89 DiskGeometry
->BytesPerSector
));
91 FldrSetConfigurationData(DiskKey
, PartialResourceList
, Size
);
92 MmHeapFree(PartialResourceList
);
97 SetHarddiskIdentifier(PCONFIGURATION_COMPONENT_DATA DiskKey
,
100 PMASTER_BOOT_RECORD Mbr
;
109 if (!MachDiskReadLogicalSectors(DriveNumber
, 0ULL, 1, (PVOID
)DISKREADBUFFER
))
111 DbgPrint((DPRINT_HWDETECT
, "Reading MBR failed\n"));
115 Buffer
= (ULONG
*)DISKREADBUFFER
;
116 Mbr
= (PMASTER_BOOT_RECORD
)DISKREADBUFFER
;
118 Signature
= Mbr
->Signature
;
119 DbgPrint((DPRINT_HWDETECT
, "Signature: %x\n", Signature
));
121 /* Calculate the MBR checksum */
123 for (i
= 0; i
< 128; i
++)
125 Checksum
+= Buffer
[i
];
127 Checksum
= ~Checksum
+ 1;
128 DbgPrint((DPRINT_HWDETECT
, "Checksum: %x\n", Checksum
));
130 /* Fill out the ARC disk block */
131 reactos_arc_disk_info
[reactos_disk_count
].Signature
= Signature
;
132 reactos_arc_disk_info
[reactos_disk_count
].CheckSum
= Checksum
;
133 sprintf(ArcName
, "multi(0)disk(0)rdisk(%lu)", reactos_disk_count
);
134 strcpy(reactos_arc_strings
[reactos_disk_count
], ArcName
);
135 reactos_arc_disk_info
[reactos_disk_count
].ArcName
=
136 reactos_arc_strings
[reactos_disk_count
];
137 reactos_disk_count
++;
139 /* Convert checksum and signature to identifier string */
140 Identifier
[0] = Hex
[(Checksum
>> 28) & 0x0F];
141 Identifier
[1] = Hex
[(Checksum
>> 24) & 0x0F];
142 Identifier
[2] = Hex
[(Checksum
>> 20) & 0x0F];
143 Identifier
[3] = Hex
[(Checksum
>> 16) & 0x0F];
144 Identifier
[4] = Hex
[(Checksum
>> 12) & 0x0F];
145 Identifier
[5] = Hex
[(Checksum
>> 8) & 0x0F];
146 Identifier
[6] = Hex
[(Checksum
>> 4) & 0x0F];
147 Identifier
[7] = Hex
[Checksum
& 0x0F];
149 Identifier
[9] = Hex
[(Signature
>> 28) & 0x0F];
150 Identifier
[10] = Hex
[(Signature
>> 24) & 0x0F];
151 Identifier
[11] = Hex
[(Signature
>> 20) & 0x0F];
152 Identifier
[12] = Hex
[(Signature
>> 16) & 0x0F];
153 Identifier
[13] = Hex
[(Signature
>> 12) & 0x0F];
154 Identifier
[14] = Hex
[(Signature
>> 8) & 0x0F];
155 Identifier
[15] = Hex
[(Signature
>> 4) & 0x0F];
156 Identifier
[16] = Hex
[Signature
& 0x0F];
157 Identifier
[17] = '-';
158 Identifier
[18] = 'A';
160 DbgPrint((DPRINT_HWDETECT
, "Identifier: %s\n", Identifier
));
163 FldrSetIdentifier(DiskKey
, Identifier
);
167 DetectBiosDisks(PCONFIGURATION_COMPONENT_DATA SystemKey
,
168 PCONFIGURATION_COMPONENT_DATA BusKey
)
170 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
171 PCM_INT13_DRIVE_PARAMETER Int13Drives
;
173 PCONFIGURATION_COMPONENT_DATA DiskKey
, ControllerKey
;
179 /* Count the number of visible drives */
180 DiskReportError(FALSE
);
183 /* There are some really broken BIOSes out there. There are even BIOSes
184 * that happily report success when you ask them to read from non-existent
185 * harddisks. So, we set the buffer to known contents first, then try to
186 * read. If the BIOS reports success but the buffer contents haven't
187 * changed then we fail anyway */
188 memset((PVOID
) DISKREADBUFFER
, 0xcd, 512);
189 while (MachDiskReadLogicalSectors(0x80 + DiskCount
, 0ULL, 1, (PVOID
)DISKREADBUFFER
))
192 for (i
= 0; ! Changed
&& i
< 512; i
++)
194 Changed
= ((PUCHAR
)DISKREADBUFFER
)[i
] != 0xcd;
198 DbgPrint((DPRINT_HWDETECT
, "BIOS reports success for disk %d but data didn't change\n",
203 memset((PVOID
) DISKREADBUFFER
, 0xcd, 512);
205 DiskReportError(TRUE
);
206 DbgPrint((DPRINT_HWDETECT
, "BIOS reports %d harddisk%s\n",
207 (int)DiskCount
, (DiskCount
== 1) ? "": "s"));
209 FldrCreateComponentKey(BusKey
,
215 DbgPrint((DPRINT_HWDETECT
, "Created key: DiskController\\0\n"));
217 /* Set 'ComponentInformation' value */
218 FldrSetComponentInformation(ControllerKey
,
219 Output
| Input
| Removable
,
223 //DetectBiosFloppyController(BusKey, ControllerKey);
225 /* Allocate resource descriptor */
226 Size
= sizeof(CM_PARTIAL_RESOURCE_LIST
) +
227 sizeof(CM_INT13_DRIVE_PARAMETER
) * DiskCount
;
228 PartialResourceList
= MmHeapAlloc(Size
);
229 if (PartialResourceList
== NULL
)
231 DbgPrint((DPRINT_HWDETECT
,
232 "Failed to allocate resource descriptor\n"));
236 /* Initialize resource descriptor */
237 memset(PartialResourceList
, 0, Size
);
238 PartialResourceList
->Version
= 1;
239 PartialResourceList
->Revision
= 1;
240 PartialResourceList
->Count
= 1;
241 PartialResourceList
->PartialDescriptors
[0].Type
= CmResourceTypeDeviceSpecific
;
242 PartialResourceList
->PartialDescriptors
[0].ShareDisposition
= 0;
243 PartialResourceList
->PartialDescriptors
[0].Flags
= 0;
244 PartialResourceList
->PartialDescriptors
[0].u
.DeviceSpecificData
.DataSize
=
245 sizeof(CM_INT13_DRIVE_PARAMETER
) * DiskCount
;
247 /* Get harddisk Int13 geometry data */
248 Int13Drives
= (PVOID
)(((ULONG_PTR
)PartialResourceList
) + sizeof(CM_PARTIAL_RESOURCE_LIST
));
249 for (i
= 0; i
< DiskCount
; i
++)
251 if (MachDiskGetDriveGeometry(0x80 + i
, &Geometry
))
253 Int13Drives
[i
].DriveSelect
= 0x80 + i
;
254 Int13Drives
[i
].MaxCylinders
= Geometry
.Cylinders
- 1;
255 Int13Drives
[i
].SectorsPerTrack
= Geometry
.Sectors
;
256 Int13Drives
[i
].MaxHeads
= Geometry
.Heads
- 1;
257 Int13Drives
[i
].NumberDrives
= DiskCount
;
259 DbgPrint((DPRINT_HWDETECT
,
260 "Disk %x: %u Cylinders %u Heads %u Sectors %u Bytes\n",
262 Geometry
.Cylinders
- 1,
265 Geometry
.BytesPerSector
));
269 /* Set 'Configuration Data' value */
270 FldrSetConfigurationData(SystemKey
, PartialResourceList
, Size
);
271 MmHeapFree(PartialResourceList
);
273 /* Create and fill subkey for each harddisk */
274 for (i
= 0; i
< DiskCount
; i
++)
276 /* Create disk key */
277 FldrCreateComponentKey(ControllerKey
,
284 /* Set 'ComponentInformation' value */
285 FldrSetComponentInformation(DiskKey
,
290 /* Set disk values */
291 SetHarddiskConfigurationData(DiskKey
, 0x80 + i
);
292 SetHarddiskIdentifier(DiskKey
, 0x80 + i
);
297 DetectIsaBios(PCONFIGURATION_COMPONENT_DATA SystemKey
, ULONG
*BusNumber
)
299 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
300 PCONFIGURATION_COMPONENT_DATA BusKey
;
303 /* Create new bus key */
304 FldrCreateComponentKey(SystemKey
,
305 L
"MultifunctionAdapter",
308 MultiFunctionAdapter
,
311 /* Set 'Component Information' value similar to my NT4 box */
312 FldrSetComponentInformation(BusKey
,
317 /* Increment bus number */
320 /* Set 'Identifier' value */
321 FldrSetIdentifier(BusKey
, "ISA");
323 /* Set 'Configuration Data' value */
324 Size
= sizeof(CM_PARTIAL_RESOURCE_LIST
) -
325 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
);
326 PartialResourceList
= MmHeapAlloc(Size
);
327 if (PartialResourceList
== NULL
)
329 DbgPrint((DPRINT_HWDETECT
,
330 "Failed to allocate resource descriptor\n"));
334 /* Initialize resource descriptor */
335 memset(PartialResourceList
, 0, Size
);
336 PartialResourceList
->Version
= 1;
337 PartialResourceList
->Revision
= 1;
338 PartialResourceList
->Count
= 0;
340 /* Set 'Configuration Data' value */
341 FldrSetConfigurationData(BusKey
, PartialResourceList
, Size
);
342 MmHeapFree(PartialResourceList
);
345 /* Detect ISA/BIOS devices */
346 DetectBiosDisks(SystemKey
, BusKey
);
349 /* FIXME: Detect more ISA devices */
352 PCONFIGURATION_COMPONENT_DATA
355 PCONFIGURATION_COMPONENT_DATA SystemKey
;
358 DbgPrint((DPRINT_HWDETECT
, "DetectHardware()\n"));
360 /* Create the 'System' key */
361 FldrCreateSystemKey(&SystemKey
);
363 /* Set empty component information */
364 FldrSetComponentInformation(SystemKey
,
369 /* TODO: Build actual xbox's hardware configuration tree */
370 DetectIsaBios(SystemKey
, &BusNumber
);
372 DbgPrint((DPRINT_HWDETECT
, "DetectHardware() Done\n"));