17.4 GetDriver() Implementation
The example below shows an example implementation of the GetDriver() function of the Bus Specific Driver Override Protocol. The first step is to retrieve the private context structure from the This pointer using the CR() macro defined in Section 17.3 above. If no image handles are registered, EFI_NOT_FOUND. is returned. If DriverImageHandle is a pointer to NULL, the first image handle from HandleBuffer is returned. If DriverImageHandle is not a pointer to NULL, a search is made through HandleBuffer to find a matching handle. If a matching handle is not found, EFI_INVALID_PARAMETER is returned. If a matching handle is found, the next handle in the array is returned. If the matching handle is the last handle in the array, EFI_NOT_FOUND is returned.

Example 167-GetDriver() Function of a Bus Specific Driver Override Protocol

1
#include <Uefi.h>
2
#include <Protocol/BusSpecificDriverOverride.h>
3
4
EFI_STATUS
5
EFIAPI
6
AbcGetDriver (
7
IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,
8
IN OUT EFI_HANDLE *DriverImageHandle
9
)
10
{
11
UINTN Index;
12
ABC_PRIVATE_DATA *Private;
13
14
Private = ABC_PRIVATE_DATA_FROM_BUS_SPECIFIC_DRIVER_OVERRIDE_THIS (This);
15
16
if (Private->NumberOfHandles == 0) {
17
return EFI_NOT_FOUND;
18
}
19
20
if (DriverImageHandle == NULL) {
21
return EFI_INVALID_PARAMETER;
22
}
23
24
if (*DriverImageHandle == NULL) {
25
*DriverImageHandle = Private->HandleBuffer[0];
26
return EFI_SUCCESS;
27
}
28
29
for (Index = 0;
30
Index < Private->NumberOfHandles;
31
Index++) {
32
if (*DriverImageHandle == Private->HandleBuffer[Index]) {
33
Index++;
34
if (Index < Private->NumberOfHandles) {
35
*DriverImageHandle = Private->HandleBuffer[Index];
36
return EFI_SUCCESS;
37
} else {
38
return EFI_NOT_FOUND;
39
}
40
}
41
}
42
43
return EFI_INVALID_PARAMETER;
44
}
Copied!