]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/Opal/OpalPassword/OpalHiiCallbacks.c
b07e38c1449d64569a0f5019b5d775028e8eee6d
[mirror_edk2.git] / SecurityPkg / Tcg / Opal / OpalPassword / OpalHiiCallbacks.c
1 /** @file
2 Callbacks required by the HII of the Opal UEFI Driver to help display
3 Opal device information.
4
5 Copyright (c) 2016 - 2018, 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 #include "OpalHii.h"
17
18 /**
19 Get Opal var name.
20 The return Value must be freed by caller if not NULL
21
22 @param OpalDisk The disk.
23 @param Prefix The prefix string.
24
25 @retval The var name string.
26
27 **/
28 CHAR16*
29 OpalDriverGetOpalVarName(
30 OPAL_DISK *OpalDisk,
31 const CHAR16 *Prefix
32 )
33 {
34 OPAL_DRIVER_DEVICE* Dev;
35 UINTN PrefixLen;
36 UINTN NameLen;
37 UINTN VarNameLen;
38 CHAR16* VarName;
39
40 Dev = DRIVER_DEVICE_FROM_OPALDISK(OpalDisk);
41 if (Dev == NULL) {
42 return NULL;
43 }
44
45 PrefixLen = StrLen(Prefix);
46
47 NameLen = 0;
48 if (Dev->Name16 != NULL) {
49 NameLen = StrLen(Dev->Name16);
50 }
51
52 VarNameLen = PrefixLen + NameLen;
53
54 VarName = (CHAR16*)AllocateZeroPool((VarNameLen + 1) * sizeof(CHAR16));
55 if (VarName == NULL) {
56 return NULL;
57 }
58
59 CopyMem(VarName, Prefix, PrefixLen * sizeof(CHAR16));
60 if (Dev->Name16 != NULL) {
61 CopyMem(VarName + PrefixLen, Dev->Name16, NameLen * sizeof(CHAR16));
62 }
63 VarName[VarNameLen] = 0;
64
65 return VarName;
66 }
67
68 /**
69 Get the driver image handle.
70
71 @retval the driver image handle.
72
73 **/
74 EFI_HANDLE
75 HiiGetDriverImageHandleCB(
76 VOID
77 )
78 {
79 return gImageHandle;
80 }
81
82 /**
83 Check whether enable feature or not.
84
85 @retval Return the disk number.
86
87 **/
88 UINT8
89 HiiGetNumConfigRequiredOpalDisksCB(
90 VOID
91 )
92 {
93 UINT8 NumDisks;
94 UINT8 NumLockedOpalDisks;
95 OPAL_DISK *OpalDisk;
96 UINT8 Index;
97
98 NumLockedOpalDisks = 0;
99
100 NumDisks = GetDeviceCount();
101
102 for (Index = 0; Index < NumDisks; Index++) {
103 OpalDisk = HiiGetOpalDiskCB(Index);
104
105 if (OpalDisk != NULL) {
106 if (!OpalFeatureEnabled (&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature)) {
107 DEBUG ((DEBUG_INFO, "Ignoring disk %u because feature is disabled or health has already been inspected\n", Index));
108 } else if (OpalDeviceLocked (&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature)) {
109 NumLockedOpalDisks++;
110 }
111 }
112 }
113
114 return NumLockedOpalDisks;
115 }
116
117
118
119 /**
120 Returns the opaque pointer to a physical disk context.
121
122 @param DiskIndex Input the disk index.
123
124 @retval The device pointer.
125
126 **/
127 VOID *
128 HiiGetDiskContextCB(
129 UINT8 DiskIndex
130 )
131 {
132 OPAL_DRIVER_DEVICE* Dev;
133 UINT8 CurrentDisk;
134
135 Dev = OpalDriverGetDeviceList();
136 CurrentDisk = 0;
137
138 if (DiskIndex >= GetDeviceCount()) {
139 return NULL;
140 }
141
142 while (Dev != NULL) {
143 if (CurrentDisk == DiskIndex) {
144 return Dev;
145 } else {
146 Dev = Dev->Next;
147 CurrentDisk++;
148 }
149 }
150
151 return NULL;
152 }
153
154 /**
155 Returns the opaque pointer to a physical disk context.
156
157 @param DiskIndex Input the disk index.
158
159 @retval The device pointer.
160
161 **/
162 OPAL_DISK*
163 HiiGetOpalDiskCB(
164 UINT8 DiskIndex
165 )
166 {
167 VOID *Ctx;
168 OPAL_DRIVER_DEVICE *Tmp;
169
170 Ctx = HiiGetDiskContextCB (DiskIndex);
171
172 if (Ctx == NULL) {
173 return NULL;
174 }
175
176 Tmp = (OPAL_DRIVER_DEVICE*) Ctx;
177
178 return &Tmp->OpalDisk;
179 }
180
181 /**
182 Returns the disk name.
183
184 @param DiskIndex Input the disk index.
185
186 @retval Returns the disk name.
187
188 **/
189 CHAR8*
190 HiiDiskGetNameCB(
191 UINT8 DiskIndex
192 )
193 {
194 OPAL_DRIVER_DEVICE* Ctx;
195
196 Ctx = (OPAL_DRIVER_DEVICE*) HiiGetDiskContextCB (DiskIndex);
197
198 if (Ctx != NULL) {
199 if (Ctx->NameZ == NULL) {
200 OpalDriverGetDriverDeviceName (Ctx);
201 }
202 return Ctx->NameZ;
203 }
204 return NULL;
205 }
206
207 /**
208 Returns the driver name.
209
210 @retval Returns the driver name.
211
212 **/
213 CHAR16*
214 HiiGetDriverNameCB(
215 VOID
216 )
217 {
218 return (CHAR16*)EFI_DRIVER_NAME_UNICODE;
219 }