Finding Resources
The PHDIo driver is told which resources to use in the filename passed with the Create IRP. However, most NT style drivers do not have this luxury. Instead, they must use one of the following techniques to find out what resources to use.
• Ask what resources the kernel has detected.
• Interrogate configurable buses.
• Save the resource requirements in the driver's registry key when it is installed.
• Poke around in memory to see if you can find your devices.
Calling
NT and Windows 2000 attempt to identify all the hardware devices attached to the system when they boot. A driver can look for suitable devices using the
The automatic detection process finds all the buses on the system, all recognized controllers on each bus, and. if possible, each peripheral attached to a controller. It starts by locating any standard serial and parallel ports and finds any attached mice or printers. Along the way, it finds any disk drivers, network cards, etc. The detected information is put in the registry in the HKLM HARDWAREDESCRIPTION key.
Table 18.2 shows the parameters for
The possible bus, controller, and peripheral types are found in the INTERFACE_TYPE and CONFIGURATION_TYPE enumerations in NTDDK.H.
Table 18.2 IoQueryDeviceDescription function
NTSTATUS IoQueryDeviceDescription | (IRQL==PASSIVE_LEVEL) |
---|---|
Parameter | Description |
IN PINTERFACE_TYPE BusType | Bus type |
IN PULONG BusNumber | Bus number, zero-based |
IN PCONFIGURATION_TYPE ControllerType | Controller type |
IN PULONG ControllerNumber | Controller number, zero-based |
IN PCONFIGURATION_TYPE PeripheralType | Peripheral type |
IN PULONG PeripheralNumber | Peripheral number, zero-based |
IN PIO_QUERY_DEVICE_ROUTINE CalloutRoutine | Configuration callback routine name |
IN PVOID Context | Context for configuration callback |
Returns | STATUS_OBJECT_NAME_NOT_FOUND if no match found, or status returned by callback |
Listing 18.7 shows some code that finds any parallel ports that have been detected (i.e., where the ControllerType is ParallelController). The code can be found in the book software file PHDIo autodetect.cpp. Note carefully that the code will find parallel ports that are on all the available buses, not just the ISA bus. At the moment, this code just prints out the basic raw resource details using
The
Listing 18.7 Finding any autodetected parallel ports
NTSTATUS FindParallelPort() {
NTSTATUS status;
for (int BusType=0; BusType<MaximumInterfaceType; BusType++) {
INTERFACE_TYPE iBusType = (INTERFACE_TYPE)BusType;
CONFIGURATION_TYPE CtrlType = ParallelController;
ULONG BusNumber =0;
while (true) {
// See if this bus instance exists
status = IoGueryDeviceDescription(&iBusType, &BusNumber, NULL, NULL, NULL, NULL, AbcConfigCallback, NULL);
if (!NT_SUCCESS(status)) {
if (status != STATUS_OBJECT_NAME_NOT_FOUND) return status;
break;
}
// See what printers exist on this bus instance
status = IoQueryDeviceDescription(&iBusType, &BusNumber, &CtrlrType, NULL, NULL, NULL, AbcConfigCallback, NULL);
if (!NT_SUCCESS(status) && (status != STATUS_OBJECT_NAME_NOT_FOUND)) return status;
BusNumber++;