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