1.2.5 Controlling Driver Load Order

The first driver to claim a device obtains ownership of that device, either shared or exclusive.

Driver load order is determined by entries in the \Machine\System\CurrentControlSet key in the registry. This key has a Control subkey containing system-wide information and a Services subkey containing driver-specific information.

During system initialization, when a driver is loaded depends on the following characteristics:

·During which phase does it load (Services\DriverName\Start value in the registry)?

·During a given phase, in which group does it reside (\Services\DriverName\Group) and in what order does its group load (\Control\ServiceGroupOrder)?

·Within a given group, in what order does this driver load (\Services\DriverName\Tag and \Control\GroupOrderList)?

·Does the driver require that any prerequisite drivers or services be loaded (\Services\DriverName\DependOnGroup and DependOnService)?

Driver Start Value

A driver can have one of the following values in \Machine\System\CurrentControlSet\Services\DriverName\Start:

Start Value When Started
SERVICE_BOOT_START (0x0) By OS loader (Phase 2)
SERVICE_SYSTEM_START (0x01) During OS initialization (Phase 5)
SERVICE_AUTO_START (0x02) By Service Control Manager during startup (Phase 8)
SERVICE_DEMAND_START (0x03) On demand, by Service Control Manager
SERVICE_DISABLED (0x04) Not started

Driver Load Service Group

Drivers with start values of SERVICE_BOOT_START and SERVICE_SYSTEM_START can be organized into groups to further structure the order in which they are loaded.

\Machine\System\CurrentControlSet\Control\ServiceGroupOrder contains a list of the driver load service groups. The list is scanned twice. First, all drivers with start value SERVICE_BOOT_START are loaded; then all drivers with start value SERVICE_SYSTEM_START are loaded.

The ServiceGroupOrder list looks something like the following:

System Bus Extender

Scsi miniport

port

Primary disk

SCSI class

SCSI CDROM class

filter

boot file system

Base

Pointer Port

Keyboard Port

Pointer Class

Keyboard Class

Video Init

Video

Video Save

file system

Event log

Streams Drivers

PNP_TDI

NDIS

TDI

NetBIOSGroup

SpoolerGroup

NetDDEGroup

Parallel Arbitrator

extended base

RemoteValidation

PCI Configuration

If a driver is a member of a load service group, the group name is listed in the driver's services subkey in the registry (\Machine\Hardware\System\
CurrentControlSet\Services\
DriverName\Group).

After all ServiceGroupOrder groups of a given Start value have been loaded, the system loads all groups not in the list and then all drivers without a group.

Load Order Within a Group

Drivers that are in a load group and have a start value of SERVICE_BOOT_START or SERVICE_SYSTEM_START can use tags to indicate their load order within the group.

The services registry entry for the disk class driver looks something like the following:

\Machine\Hardware\System\CurrentControlSet\Services\Disk

DependOnGroup:REG_MULTI_SZ:SCSI miniport

ErrorControl:REG_DWORD:0 // = SERVICE_ERROR_IGNORE

Group:REG_SZ:SCSI class

Start:REG_DWORD:0 // = SERVICE_BOOT_START

Type:REG_DWORD:0x1 // = SERVICE_KERNEL_DRIVER

Tag:REG_DWORD:0x2

:

The disk class driver is in the SCSI class group and its group tag is 2.

The registry key \Machine\Hardware\System\CurrentControlSet\Control\
GroupOrderList
defines the number of tags in each group and the order in which tagged drivers are loaded within a group. An excerpt of this key including the SCSI class group looks something like the following:

\Machine\Hardware\System\CurrentControlSet\Control\GroupOrderList

:

SCSI CDROM Class:REG_BINARY:02 00 00 00 01 00 00 00 02 00 00 00

SCSI Class:REG_BINARY:03 00 00 00 01 00 00 00 02 00 00 00 03...

SCSI miniport:REG_BINARY:24 00 00 00 00 01 00 00 01 ...

:

Within the SCSI class group, drivers with tag 1 are loaded first, then drivers with tag 2, and then drivers with tag 3. Drivers without a tag are loaded last in their group.

Not every group is included in the GroupOrderList. When a group is not in the GroupOrderList, the order in which the drivers load within the group cannot be guaranteed.

Dependencies

Prerequisite drivers are listed in a driver's services subkey in the DependOnGroup and DependOnService entries. The services subkey for the disk class driver shown above indicates that this driver cannot be loaded until at least one driver from the SCSI miniport group has been loaded.

Defining Driver Load Order for New Drivers

To define the load order for a new driver, assign the driver a start value, a service group (optional), a group tag (optional), and prerequisite drivers (optional).

The start value must be one of the system-defined SERVICE_xxx values.

The service group can be an existing system-defined group or a new group. If you define a new group, add it to \Machine\System\CurrentControlSet
\Control\ServiceGroupOrder
. Note that ServiceGroupOrder is reset during a system upgrade, so drivers that modify this registry key may need to be reinstalled after an upgrade.

Use an existing group tag, or define a new one in \Machine\System
\CurrentControlSet\Control\GroupOrderList
.

List prerequisite drivers in DependOnGroup and DependOnService in the driver's services key.

A driver writer can modify the registry using routines, INF files, or the Windows NT registry editor (regedt32). During driver development it may be convenient to edit the registry manually with the registry editor. When the driver is nearing completion, it is best for the driver to make any necessary registry changes using routines (RtlCreateRegistryKey and RtlWriteRegistryValue) or through the driver's INF file. For more information on runtime library routines, see the Kernel-Mode Driver Reference. For more information on INF files, see Chapter 2.