summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Universal/PlatformDriverOverride/PlatformDriOverrideDxe/PlatformDriOverride.c
blob: 2a189138ed2e53c7ba65af519304f42a4e24121e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/** @file

Copyright (c) 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution.  The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

Module Name:

    PlatformDriOverride.c

Abstract:


**/


#include "PlatformDriOverride.h"

EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL gPlatformDriverOverride = {
  GetDriver,
  GetDriverPath,
  DriverLoaded
};

STATIC  LIST_ENTRY      mMappingDataBase = INITIALIZE_LIST_HEAD_VARIABLE (mMappingDataBase);
STATIC  BOOLEAN         mEnvironmentVariableRead = FALSE;
STATIC  EFI_HANDLE      mCallerImageHandle;


EFI_STATUS
EFIAPI
PlatformDriverOverrideEntry (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
/*++

Routine Description:
   Platform Driver Override driver entry point, install the Platform Driver Override Protocol

Arguments:
  (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)

Returns:
  EFI_STATUS

--*/
{
  mEnvironmentVariableRead = FALSE;
  mCallerImageHandle = ImageHandle;
  InitializeListHead (&mMappingDataBase);
  return InstallPlatformDriverOverrideProtocol (&gPlatformDriverOverride);
}


/**
  Retrieves the image handle of the platform override driver for a controller in the system.

  @param  This                   A pointer to the
                                 EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL instance.
  @param  ControllerHandle       The device handle of the controller to check if a
                                 driver override exists.
  @param  DriverImageHandle      On input, a pointer to the previous driver image
                                 handle returned by GetDriver().  On output, a
                                 pointer to the next driver image handle. Passing
                                 in a NULL,  will return the first driver image
                                 handle for ControllerHandle.

  @retval EFI_SUCCESS            The driver override for ControllerHandle was
                                 returned in DriverImageHandle.
  @retval EFI_NOT_FOUND          A driver override for ControllerHandle was not
                                 found.
  @retval EFI_INVALID_PARAMETER  The handle specified by ControllerHandle is not a
                                 valid handle. DriverImageHandle is not a handle
                                 that was returned on a previous  call to
                                 GetDriver().

**/
STATIC
EFI_STATUS
EFIAPI
GetDriver (
  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL              * This,
  IN     EFI_HANDLE                                     ControllerHandle,
  IN OUT EFI_HANDLE                                     * DriverImageHandle
  )
{
  EFI_STATUS  Status;
  //
  // Check that ControllerHandle is a valid handle
  //
  if (ControllerHandle == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  //
  // Read the environment variable(s) that contain the override mappings from Controller Device Path to
  // a set of Driver Device Paths, and  initialize in memory database of the overrides that map Controller
  // Device Paths to an ordered set of Driver Device Paths and Driver Handles. This action is only performed
  // once and finished in first call.
  //
  if (!mEnvironmentVariableRead) {
    mEnvironmentVariableRead = TRUE;

    Status = InitOverridesMapping (&mMappingDataBase);
    if (Status == EFI_NOT_FOUND) {
      InitializeListHead (&mMappingDataBase);
      return EFI_NOT_FOUND;
    } else if (Status == EFI_VOLUME_CORRUPTED){
      DEBUG ((DEBUG_ERROR, "Platform Driver Override Variable is corrupt\n"));
      //
      // The environment variable(s) that contain the override mappings from Controller Device Path to
      //  a set of Driver Device Paths is corrupted,  platform code can use LibDeleteOverridesVariables to
      //  delete all orverride variables as a policy. Here can be IBV/OEM customized.
      //

      //LibDeleteOverridesVariables();
      InitializeListHead (&mMappingDataBase);
      return EFI_NOT_FOUND;
    } else if (EFI_ERROR (Status)){
      InitializeListHead (&mMappingDataBase);
      return EFI_NOT_FOUND;
    }
  }
  //
  // if the environment variable does not exist or the variable appears to be corrupt, just return not found
  //
  if (IsListEmpty (&mMappingDataBase)) {
    return EFI_NOT_FOUND;
  }

  return GetDriverFromMapping (
            This,
            ControllerHandle,
            DriverImageHandle,
            &mMappingDataBase,
            mCallerImageHandle
            );

}


/**
  For the use of the ControllerHandle parameter in the GetDriverPath() and DriverLoaded() APIs
  makes those APIs very difficult to use, so not support.



**/
STATIC
EFI_STATUS
EFIAPI
GetDriverPath (
  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL              * This,
  IN     EFI_HANDLE                                     ControllerHandle,
  IN OUT EFI_DEVICE_PATH_PROTOCOL                       **DriverImagePath
  )
{
  return EFI_UNSUPPORTED;
}


/**
  For the use of the ControllerHandle parameter in the GetDriverPath() and DriverLoaded() APIs
  makes those APIs very difficult to use, so not support.



**/
STATIC
EFI_STATUS
EFIAPI
DriverLoaded (
  IN EFI_PLATFORM_DRIVER_OVERRIDE_PROTOCOL          * This,
  IN EFI_HANDLE                                     ControllerHandle,
  IN EFI_DEVICE_PATH_PROTOCOL                       * DriverImagePath,
  IN EFI_HANDLE                                     DriverImageHandle
  )
{
  return EFI_UNSUPPORTED;
}