PATH 
ADC Home > Documentation > Hardware > Device Managers and Drivers > PCI Card Services > Designing PCI Cards and Drivers for Power Macintosh Computers


  

Matching Drivers With Devices

Mac OS matches drivers to devices by using the following algorithm:

Note

Each device node should have just one compatible property, containing one or more C-formatted name strings as its value. The strings must be packed in sequence with no unused bytes between them and should be arranged with the more compatible names first.

The DLL routines GetDriverForDevice, InstallDriverForDevice, and FindDriversForDevice use the following algorithm to match or install the "best" driver for a device:

  1. Find all candidate drivers for the device. A driver is a candidate if its nameInfoStr value matches either the device's name or one of the names found in the device's compatible property.
  2. Sort this list based on whether the driver matched using the device's name or a compatible name. Those matched with the device name are put at the head of the list. Ties are broken using the driver's version number (See HigherDriverVersion.) Pseudo code for file-based driver sorting is shown in Listing 7-1. The code returns 0 if two drivers are equally compatible, a negative number if driver1 is less compatible than driver2, and a positive number if driver1 is more compatible than driver2.
  3. If not installing the driver, return the driver at the head of the candidate list and discard any remaining candidates.

If you still have candidates with which to attempt an installation, do the following:

  1. Load and install the driver located at the head of the list.
  2. The driver should probe the device, using DSL services, to verify the match. If the driver did not successfully initialize itself, discard it and return to step 1.
  3. Discard any remaining candidates.

The routines that use this algorithm are described in detail in the sections that start with Loading and Unloading.

Listing 7-1 File-based driver sorting

SInt16 CandidateCompareRoutine
            (FileBasedDriverInfoPtr             Driver1,
             FileBasedDriverInfoPtr             Driver2,
             StringPtr                          CompatibleNames,
             ItemCount                          nCompatibleNames)

{
    SInt16          matchResults = 0;

    if ( Driver1 and Driver2 matched using same property (name or compatible))
    {

        if ( both drivers matched using compatible property )
        {

            if ( drivers not matched with identical compatible name )
            {

                /* Which compatible name (by number) did driver1/driver2 match? */
                Driver1CompatibleName = WhichCompatibleName(Driver1,...);
                Driver2CompatibleName = WhichCompatibleName(Driver2,...);

                if ( Driver1CompatibleName != Driver2CompatibleName )
                {
                    if ( Driver1CompatibleName < Driver2CompatibleName )
                        return 1;      /* driver1 is "more compatible" */
                    else
                        return -1;      /* driver2 is "more compatible" */
                }
            }
        }

    /* Break tie with version numbers, if possible. */
    matchResults = HigherDriverVersion  (&Driver1 ->
    info.theType.version, &Driver2 -> info.theType.version);

    /* Same version number too? */
    if ( matchResults == 0 )

        {
        /* Final tie breaker is their filenames */
        /* Reverse the compare with RelString */
        matchResults = RelString    (Driver2 -> info.theSpec.name,
                                    Driver1 -> info.theSpec.name, true, true );
        }

    return matchResults;
    }
    /* Matched using different property */
    if ( Driver1 matched using compatible property )
    return -1;                                  /* driver 2 is higher */
    return 1;                                   /* else driver 1 is higher */
}

© 1999 Apple Computer, Inc. – (Last Updated 26 March 99)