1 /** @file
2   Ihe internal heder file includes the required Protocol/Guid/Library
3   and the shared function APIs.
4 
5 Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution.  The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10 
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #ifndef _INTERNAL_PLATFORM_DRIVER_OVERRIDE_H_
17 #define _INTERNAL_PLATFORM_DRIVER_OVERRIDE_H_
18 
19 #include <PiDxe.h>
20 
21 #include <Protocol/HiiConfigAccess.h>
22 #include <Protocol/HiiConfigRouting.h>
23 #include <Protocol/HiiDatabase.h>
24 #include <Protocol/FormBrowser2.h>
25 #include <Protocol/LoadedImage.h>
26 #include <Protocol/FirmwareVolume2.h>
27 #include <Protocol/PciIo.h>
28 #include <Protocol/BusSpecificDriverOverride.h>
29 #include <Protocol/ComponentName2.h>
30 #include <Protocol/ComponentName.h>
31 #include <Protocol/DriverBinding.h>
32 #include <Protocol/DevicePath.h>
33 #include <Protocol/PlatformDriverOverride.h>
34 #include <Guid/MdeModuleHii.h>
35 #include <Guid/VariableFormat.h>
36 
37 #include <Library/BaseLib.h>
38 #include <Library/DebugLib.h>
39 #include <Library/UefiLib.h>
40 #include <Library/PrintLib.h>
41 #include <Library/UefiDriverEntryPoint.h>
42 #include <Library/UefiBootServicesTableLib.h>
43 #include <Library/UefiRuntimeServicesTableLib.h>
44 #include <Library/BaseMemoryLib.h>
45 #include <Library/MemoryAllocationLib.h>
46 #include <Library/DevicePathLib.h>
47 #include <Library/DxeServicesTableLib.h>
48 #include <Library/HiiLib.h>
49 
50 /**
51   Free all the mapping database memory resource and initialize the mapping list entry.
52 
53   @param  MappingDataBase          Mapping database list entry pointer
54 
55   @retval EFI_INVALID_PARAMETER    mapping database list entry is NULL
56   @retval EFI_SUCCESS              Free success
57 
58 **/
59 EFI_STATUS
60 EFIAPI
61 FreeMappingDatabase (
62   IN  OUT  LIST_ENTRY            *MappingDataBase
63   )
64 ;
65 
66 /**
67   Read the NV environment variable(s) that contain the override mappings from Controller Device Path to
68   a set of Driver Device Paths, and create the mapping database in memory to contain these variable info.
69 
70   @param  MappingDataBase          Mapping database list entry pointer
71 
72   @retval EFI_INVALID_PARAMETER    MappingDataBase pointer is null
73   @retval EFI_NOT_FOUND            Cannot find the 'PlatDriOver' NV variable
74   @retval EFI_VOLUME_CORRUPTED     The found NV variable is corrupted
75   @retval EFI_SUCCESS              Create the mapping database in memory successfully
76 
77 **/
78 EFI_STATUS
79 EFIAPI
80 InitOverridesMapping (
81   OUT  LIST_ENTRY            *MappingDataBase
82   )
83 ;
84 
85 /**
86   Save the memory mapping database into NV environment variable(s).
87   If MappingDataBase list is empty, then delete all platform override NV variables.
88 
89   @param  MappingDataBase          Mapping database list entry pointer
90 
91   @retval EFI_INVALID_PARAMETER    MappingDataBase pointer is null
92   @retval EFI_SUCCESS              Save memory mapping database successfully
93 
94 **/
95 EFI_STATUS
96 EFIAPI
97 SaveOverridesMapping (
98   IN  LIST_ENTRY              *MappingDataBase
99   )
100 ;
101 
102 /**
103   Retrieves the image handle of the platform override driver for a controller in the system from the memory mapping database.
104 
105   @param  ControllerHandle         The device handle of the controller to check if
106                                    a driver override exists.
107   @param  DriverImageHandle        On output, a pointer to the next driver handle.
108                                    Passing in a pointer to NULL, will return the
109                                    first driver handle for ControllerHandle.
110   @param  MappingDataBase          MappingDataBase - Mapping database list entry
111                                    pointer
112   @param  CallerImageHandle        The caller driver's image handle, for
113                                    UpdateFvFileDevicePath use.
114 
115   @retval EFI_INVALID_PARAMETER    The handle specified by ControllerHandle is not
116                                    a valid handle.  Or DriverImagePath is not a
117                                    device path that was returned on a previous call
118                                    to GetDriverPath().
119   @retval EFI_NOT_FOUND            A driver override for ControllerHandle was not
120                                    found.
121   @retval EFI_UNSUPPORTED          The operation is not supported.
122   @retval EFI_SUCCESS              The driver override for ControllerHandle was
123                                    returned in DriverImagePath.
124 
125 **/
126 EFI_STATUS
127 EFIAPI
128 GetDriverFromMapping (
129   IN     EFI_HANDLE                                     ControllerHandle,
130   IN OUT EFI_HANDLE                                     *DriverImageHandle,
131   IN     LIST_ENTRY                                     *MappingDataBase,
132   IN     EFI_HANDLE                                     CallerImageHandle
133   )
134 ;
135 
136 /**
137   Check mapping database whether already has the mapping info which
138   records the input Controller to input DriverImage.
139 
140   @param  ControllerDevicePath     The controller device path is to be check.
141   @param  DriverImageDevicePath    The driver image device path is to be check.
142   @param  MappingDataBase          Mapping database list entry pointer
143   @param  DriverInfoNum            the controller's total override driver number
144   @param  DriverImageNO            The driver order number for the input DriverImage.
145                                    If the DriverImageDevicePath is NULL, DriverImageNO is not set.
146 
147   @retval EFI_INVALID_PARAMETER    ControllerDevicePath or MappingDataBase is NULL.
148   @retval EFI_NOT_FOUND            ControllerDevicePath is not found in MappingDataBase or
149                                    DriverImageDevicePath is not found in the found DriverImage Info list.
150   @retval EFI_SUCCESS              The controller's total override driver number and
151                                    input DriverImage's order number is correctly return.
152 **/
153 EFI_STATUS
154 EFIAPI
155 CheckMapping (
156   IN     EFI_DEVICE_PATH_PROTOCOL                       *ControllerDevicePath,
157   IN     EFI_DEVICE_PATH_PROTOCOL                       *DriverImageDevicePath  OPTIONAL,
158   IN     LIST_ENTRY                                     *MappingDataBase,
159   OUT    UINT32                                         *DriverInfoNum  OPTIONAL,
160   OUT    UINT32                                         *DriverImageNO  OPTIONAL
161   )
162 ;
163 
164 /**
165   Insert a driver image as a controller's override driver into the mapping database.
166   The driver image's order number is indicated by DriverImageNO.
167 
168   @param  ControllerDevicePath     The controller device path need to add a
169                                    override driver image item
170   @param  DriverImageDevicePath    The driver image device path need to be insert
171   @param  MappingDataBase          Mapping database list entry pointer
172   @param  DriverImageNO            The inserted order number. If this number is taken,
173                                    the larger available number will be used.
174 
175   @retval EFI_INVALID_PARAMETER    ControllerDevicePath is NULL, or DriverImageDevicePath is NULL
176                                    or MappingDataBase is NULL
177   @retval EFI_ALREADY_STARTED      The input Controller to input DriverImage has been
178                                    recorded into the mapping database.
179   @retval EFI_SUCCESS              The Controller and DriverImage are inserted into
180                                    the mapping database successfully.
181 
182 **/
183 EFI_STATUS
184 EFIAPI
185 InsertDriverImage (
186   IN     EFI_DEVICE_PATH_PROTOCOL                       *ControllerDevicePath,
187   IN     EFI_DEVICE_PATH_PROTOCOL                       *DriverImageDevicePath,
188   IN     LIST_ENTRY                                     *MappingDataBase,
189   IN     UINT32                                         DriverImageNO
190   )
191 ;
192 
193 /**
194   Delete a controller's override driver from the mapping database.
195 
196   @param  ControllerDevicePath     The controller device path will be deleted
197                                    when all drivers images on it are removed.
198   @param  DriverImageDevicePath    The driver image device path will be delete.
199                                    If NULL, all driver image will be delete.
200   @param  MappingDataBase          Mapping database list entry pointer
201 
202   @retval EFI_INVALID_PARAMETER    ControllerDevicePath is NULL, or MappingDataBase is NULL
203   @retval EFI_NOT_FOUND            ControllerDevicePath is not found in MappingDataBase or
204                                    DriverImageDevicePath is not found in the found DriverImage Info list.
205   @retval EFI_SUCCESS              Delete the specified driver successfully.
206 
207 **/
208 EFI_STATUS
209 EFIAPI
210 DeleteDriverImage (
211   IN     EFI_DEVICE_PATH_PROTOCOL                       *ControllerDevicePath,
212   IN     EFI_DEVICE_PATH_PROTOCOL                       *DriverImageDevicePath,
213   IN     LIST_ENTRY                                     *MappingDataBase
214   )
215 ;
216 
217 #endif
218