1 /** @file
2   Legacy boot maintainence Ui definition.
3 
4 Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 
16 #ifndef _EFI_LEGACY_BOOT_OPTION_H_
17 #define _EFI_LEGACY_BOOT_OPTION_H_
18 
19 #include <PiDxe.h>
20 
21 
22 #include <Guid/GlobalVariable.h>
23 #include <Guid/LegacyDevOrder.h>
24 #include <Guid/MdeModuleHii.h>
25 
26 #include <Protocol/HiiConfigAccess.h>
27 #include <Protocol/HiiConfigRouting.h>
28 
29 #include <Protocol/HiiDatabase.h>
30 #include <Protocol/LegacyBios.h>
31 
32 #include <Library/UefiDriverEntryPoint.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/UefiRuntimeServicesTableLib.h>
35 #include <Library/BaseLib.h>
36 #include <Library/DevicePathLib.h>
37 #include <Library/DebugLib.h>
38 #include <Library/HiiLib.h>
39 #include <Library/UefiBootManagerLib.h>
40 #include <Library/MemoryAllocationLib.h>
41 #include <Library/UefiLib.h>
42 #include <Library/PrintLib.h>
43 #include <Library/BaseMemoryLib.h>
44 
45 #include "LegacyBootMaintUiVfr.h"
46 
47 #define CONFIG_OPTION_OFFSET    0x1200
48 
49 //
50 // VarOffset that will be used to create question
51 // all these values are computed from the structure
52 // defined below
53 //
54 #define VAR_OFFSET(Field)              ((UINT16) ((UINTN) &(((LEGACY_BOOT_NV_DATA *) 0)->Field)))
55 
56 //
57 // Question Id of Zero is invalid, so add an offset to it
58 //
59 #define QUESTION_ID(Field)             (VAR_OFFSET (Field) + CONFIG_OPTION_OFFSET)
60 
61 
62 #define LEGACY_FD_QUESTION_ID           QUESTION_ID (LegacyFD)
63 #define LEGACY_HD_QUESTION_ID           QUESTION_ID (LegacyHD)
64 #define LEGACY_CD_QUESTION_ID           QUESTION_ID (LegacyCD)
65 #define LEGACY_NET_QUESTION_ID          QUESTION_ID (LegacyNET)
66 #define LEGACY_BEV_QUESTION_ID          QUESTION_ID (LegacyBEV)
67 
68 
69 //
70 // String Contant
71 //
72 #define STR_FLOPPY          L"Floppy Drive #%02x"
73 #define STR_HARDDISK        L"HardDisk Drive #%02x"
74 #define STR_CDROM           L"ATAPI CDROM Drive #%02x"
75 #define STR_NET             L"NET Drive #%02x"
76 #define STR_BEV             L"BEV Drive #%02x"
77 
78 #define STR_FLOPPY_HELP     L"Select Floppy Drive #%02x"
79 #define STR_HARDDISK_HELP   L"Select HardDisk Drive #%02x"
80 #define STR_CDROM_HELP      L"Select ATAPI CDROM Drive #%02x"
81 #define STR_NET_HELP        L"NET Drive #%02x"
82 #define STR_BEV_HELP        L"BEV Drive #%02x"
83 
84 #define STR_FLOPPY_TITLE    L"Set Legacy Floppy Drive Order"
85 #define STR_HARDDISK_TITLE  L"Set Legacy HardDisk Drive Order"
86 #define STR_CDROM_TITLE     L"Set Legacy CDROM Drive Order"
87 #define STR_NET_TITLE       L"Set Legacy NET Drive Order"
88 #define STR_BEV_TITLE       L"Set Legacy BEV Drive Order"
89 
90 //
91 // These are the VFR compiler generated data representing our VFR data.
92 //
93 extern UINT8 LegacyBootMaintUiVfrBin[];
94 
95 #pragma pack(1)
96 
97 ///
98 /// HII specific Vendor Device Path definition.
99 ///
100 typedef struct {
101   VENDOR_DEVICE_PATH             VendorDevicePath;
102   EFI_DEVICE_PATH_PROTOCOL       End;
103 } HII_VENDOR_DEVICE_PATH;
104 
105 
106 
107 //
108 // Variable created with this flag will be "Efi:...."
109 //
110 #define VAR_FLAG  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE
111 
112 
113 #define LEGACY_BOOT_OPTION_CALLBACK_DATA_SIGNATURE  SIGNATURE_32 ('L', 'G', 'C', 'B')
114 
115 typedef struct {
116   UINTN                            Signature;
117 
118   //
119   // HII relative handles
120   //
121   EFI_HII_HANDLE                   HiiHandle;
122   EFI_HANDLE                       DriverHandle;
123 
124   //
125   // Produced protocols
126   //
127   EFI_HII_CONFIG_ACCESS_PROTOCOL   ConfigAccess;
128 
129   //
130   // Maintain the data.
131   //
132   LEGACY_BOOT_MAINTAIN_DATA        *MaintainMapData;
133 } LEGACY_BOOT_OPTION_CALLBACK_DATA;
134 
135 //
136 // All of the signatures that will be used in list structure
137 //
138 #define LEGACY_MENU_OPTION_SIGNATURE      SIGNATURE_32 ('m', 'e', 'n', 'u')
139 #define LEGACY_MENU_ENTRY_SIGNATURE       SIGNATURE_32 ('e', 'n', 't', 'r')
140 
141 #define LEGACY_LEGACY_DEV_CONTEXT_SELECT  0x9
142 
143 typedef struct {
144   UINTN           Signature;
145   LIST_ENTRY      Head;
146   UINTN           MenuNumber;
147 } LEGACY_MENU_OPTION;
148 
149 typedef struct {
150   UINT16    BbsIndex;
151   CHAR16    *Description;
152 } LEGACY_DEVICE_CONTEXT;
153 
154 typedef struct {
155   UINTN           Signature;
156   LIST_ENTRY      Link;
157   UINTN           OptionNumber;
158   UINT16          *DisplayString;
159   UINT16          *HelpString;
160   EFI_STRING_ID   DisplayStringToken;
161   EFI_STRING_ID   HelpStringToken;
162   VOID            *VariableContext;
163 } LEGACY_MENU_ENTRY;
164 
165 typedef struct {
166   UINT16     BbsIndex;
167 } LEGACY_BOOT_OPTION_BBS_DATA;
168 
169 #pragma pack()
170 
171 /**
172   This call back function is registered with Boot Manager formset.
173   When user selects a boot option, this call back function will
174   be triggered. The boot option is saved for later processing.
175 
176 
177   @param This            Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
178   @param Action          Specifies the type of action taken by the browser.
179   @param QuestionId      A unique value which is sent to the original exporting driver
180                          so that it can identify the type of data to expect.
181   @param Type            The type of value for the question.
182   @param Value           A pointer to the data being sent to the original exporting driver.
183   @param ActionRequest   On return, points to the action requested by the callback function.
184 
185   @retval  EFI_SUCCESS           The callback successfully handled the action.
186   @retval  EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.
187 
188 **/
189 EFI_STATUS
190 EFIAPI
191 LegacyBootOptionCallback (
192   IN  CONST EFI_HII_CONFIG_ACCESS_PROTOCOL   *This,
193   IN  EFI_BROWSER_ACTION                     Action,
194   IN  EFI_QUESTION_ID                        QuestionId,
195   IN  UINT8                                  Type,
196   IN  EFI_IFR_TYPE_VALUE                     *Value,
197   OUT EFI_BROWSER_ACTION_REQUEST             *ActionRequest
198   );
199 
200 /**
201   This function allows a caller to extract the current configuration for one
202   or more named elements from the target driver.
203 
204 
205   @param This            - Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
206   @param Request         - A null-terminated Unicode string in <ConfigRequest> format.
207   @param Progress        - On return, points to a character in the Request string.
208                          Points to the string's null terminator if request was successful.
209                          Points to the most recent '&' before the first failing name/value
210                          pair (or the beginning of the string if the failure is in the
211                          first name/value pair) if the request was not successful.
212   @param Results         - A null-terminated Unicode string in <ConfigAltResp> format which
213                          has all values filled in for the names in the Request string.
214                          String to be allocated by the called function.
215 
216   @retval  EFI_SUCCESS            The Results is filled with the requested values.
217   @retval  EFI_OUT_OF_RESOURCES   Not enough memory to store the results.
218   @retval  EFI_INVALID_PARAMETER  Request is NULL, illegal syntax, or unknown name.
219   @retval  EFI_NOT_FOUND          Routing data doesn't match any storage in this driver.
220 
221 **/
222 EFI_STATUS
223 EFIAPI
224 LegacyBootOptionExtractConfig (
225   IN  CONST EFI_HII_CONFIG_ACCESS_PROTOCOL   *This,
226   IN  CONST EFI_STRING                       Request,
227   OUT EFI_STRING                             *Progress,
228   OUT EFI_STRING                             *Results
229   );
230 
231 /**
232   This function processes the results of changes in configuration.
233 
234 
235   @param This            - Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
236   @param Configuration   - A null-terminated Unicode string in <ConfigResp> format.
237   @param Progress        - A pointer to a string filled in with the offset of the most
238                          recent '&' before the first failing name/value pair (or the
239                          beginning of the string if the failure is in the first
240                          name/value pair) or the terminating NULL if all was successful.
241 
242   @retval  EFI_SUCCESS            The Results is processed successfully.
243   @retval  EFI_INVALID_PARAMETER  Configuration is NULL.
244   @retval  EFI_NOT_FOUND          Routing data doesn't match any storage in this driver.
245 
246 **/
247 EFI_STATUS
248 EFIAPI
249 LegacyBootOptionRouteConfig (
250   IN  CONST EFI_HII_CONFIG_ACCESS_PROTOCOL   *This,
251   IN  CONST EFI_STRING                       Configuration,
252   OUT EFI_STRING                             *Progress
253   );
254 
255 #endif
256