]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHiiCallbacks.c
SecurityPkg OpalPassword: Add solution without SMM device code
[mirror_edk2.git] / SecurityPkg / Tcg / Opal / OpalPasswordDxe / OpalHiiCallbacks.c
CommitLineData
a06875e1
ED
1/** @file\r
2 Callbacks required by the HII of the Opal UEFI Driver to help display\r
3 Opal device information and to send password to SMM handler.\r
4\r
5Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "OpalHii.h"\r
17#include "OpalDriver.h"\r
18#include "OpalDriverPrivate.h"\r
19\r
20/**\r
21 Get Opal var name.\r
22 The return Value must be freed by caller if not NULL\r
23\r
24 @param OpalDisk The disk.\r
25 @param Prefix The prefix string.\r
26\r
27 @retval The var name string.\r
28\r
29**/\r
30CHAR16*\r
31OpalDriverGetOpalVarName(\r
32 OPAL_DISK *OpalDisk,\r
33 const CHAR16 *Prefix\r
34 )\r
35{\r
36 OPAL_DRIVER_DEVICE* Dev;\r
37 UINTN PrefixLen;\r
38 UINTN NameLen;\r
39 UINTN VarNameLen;\r
40 CHAR16* VarName;\r
41\r
42 Dev = DRIVER_DEVICE_FROM_OPALDISK(OpalDisk);\r
43 if (Dev == NULL) {\r
44 return NULL;\r
45 }\r
46\r
47 PrefixLen = StrLen(Prefix);\r
48\r
49 NameLen = 0;\r
50 if (Dev->Name16 != NULL) {\r
51 NameLen = StrLen(Dev->Name16);\r
52 }\r
53\r
54 VarNameLen = PrefixLen + NameLen;\r
55\r
56 VarName = (CHAR16*)AllocateZeroPool((VarNameLen + 1) * sizeof(CHAR16));\r
57 if (VarName == NULL) {\r
58 return NULL;\r
59 }\r
60\r
61 CopyMem(VarName, Prefix, PrefixLen * sizeof(CHAR16));\r
62 if (Dev->Name16 != NULL) {\r
63 CopyMem(VarName + PrefixLen, Dev->Name16, NameLen * sizeof(CHAR16));\r
64 }\r
65 VarName[VarNameLen] = 0;\r
66\r
67 return VarName;\r
68}\r
69\r
70/**\r
71 Get the driver image handle.\r
72\r
73 @retval the driver image handle.\r
74\r
75**/\r
76EFI_HANDLE\r
77HiiGetDriverImageHandleCB(\r
78 VOID\r
79 )\r
80{\r
81 return gImageHandle;\r
82}\r
83\r
84/**\r
85 Check whether enable feature or not.\r
86\r
87 @retval Return the disk number.\r
88\r
89**/\r
90UINT8\r
91HiiGetNumConfigRequiredOpalDisksCB(\r
92 VOID\r
93 )\r
94{\r
95 UINT8 NumDisks;\r
96 UINT8 NumLockedOpalDisks;\r
97 OPAL_DISK *OpalDisk;\r
98 UINT8 Index;\r
99\r
100 NumLockedOpalDisks = 0;\r
101\r
102 NumDisks = GetDeviceCount();\r
103\r
104 for (Index = 0; Index < NumDisks; Index++) {\r
105 OpalDisk = HiiGetOpalDiskCB(Index);\r
106\r
107 if (OpalDisk != NULL) {\r
108 if (!OpalFeatureEnabled (&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature)) {\r
109 DEBUG ((DEBUG_INFO, "Ignoring disk %u because feature is disabled or health has already been inspected\n", Index));\r
110 } else if (OpalDeviceLocked (&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature)) {\r
111 NumLockedOpalDisks++;\r
112 }\r
113 }\r
114 }\r
115\r
116 return NumLockedOpalDisks;\r
117}\r
118\r
119\r
120\r
121/**\r
122 Returns the opaque pointer to a physical disk context.\r
123\r
124 @param DiskIndex Input the disk index.\r
125\r
126 @retval The device pointer.\r
127\r
128**/\r
129VOID *\r
130HiiGetDiskContextCB(\r
131 UINT8 DiskIndex\r
132 )\r
133{\r
134 OPAL_DRIVER_DEVICE* Dev;\r
135 UINT8 CurrentDisk;\r
136\r
137 Dev = OpalDriverGetDeviceList();\r
138 CurrentDisk = 0;\r
139\r
140 if (DiskIndex >= GetDeviceCount()) {\r
141 return NULL;\r
142 }\r
143\r
144 while (Dev != NULL) {\r
145 if (CurrentDisk == DiskIndex) {\r
146 return Dev;\r
147 } else {\r
148 Dev = Dev->Next;\r
149 CurrentDisk++;\r
150 }\r
151 }\r
152\r
153 return NULL;\r
154}\r
155\r
156/**\r
157 Returns the opaque pointer to a physical disk context.\r
158\r
159 @param DiskIndex Input the disk index.\r
160\r
161 @retval The device pointer.\r
162\r
163**/\r
164OPAL_DISK*\r
165HiiGetOpalDiskCB(\r
166 UINT8 DiskIndex\r
167 )\r
168{\r
169 VOID *Ctx;\r
170 OPAL_DRIVER_DEVICE *Tmp;\r
171\r
172 Ctx = HiiGetDiskContextCB (DiskIndex);\r
173\r
174 if (Ctx == NULL) {\r
175 return NULL;\r
176 }\r
177\r
178 Tmp = (OPAL_DRIVER_DEVICE*) Ctx;\r
179\r
180 return &Tmp->OpalDisk;\r
181}\r
182\r
183/**\r
184 Returns the disk name.\r
185\r
186 @param DiskIndex Input the disk index.\r
187\r
188 @retval Returns the disk name.\r
189\r
190**/\r
191CHAR8*\r
192HiiDiskGetNameCB(\r
193 UINT8 DiskIndex\r
194 )\r
195{\r
196 OPAL_DRIVER_DEVICE* Ctx;\r
197\r
198 Ctx = (OPAL_DRIVER_DEVICE*) HiiGetDiskContextCB (DiskIndex);\r
199\r
200 if (Ctx != NULL) {\r
201 if (Ctx->NameZ == NULL) {\r
202 OpalDriverGetDriverDeviceName (Ctx);\r
203 }\r
204 return Ctx->NameZ;\r
205 }\r
206 return NULL;\r
207}\r
208\r
209/**\r
210 Returns the driver name.\r
211\r
212 @retval Returns the driver name.\r
213\r
214**/\r
215CHAR16*\r
216HiiGetDriverNameCB(\r
217 VOID\r
218 )\r
219{\r
220 return (CHAR16*)EFI_DRIVER_NAME_UNICODE;\r
221}\r