12EFI_GUID mHddPasswordDeviceInfoGuid = HDD_PASSWORD_DEVICE_INFO_GUID;
33 IN UINT16 PortMultiplierPort,
42 UINT8 Buffer[HDD_PAYLOAD];
44 if ((AtaPassThru ==
NULL) || (Password ==
NULL)) {
45 return EFI_INVALID_PARAMETER;
59 AtaPassThru->Mode->IoAlign
62 return EFI_OUT_OF_RESOURCES;
70 Acb.AtaCommand = ATA_SECURITY_UNLOCK_CMD;
71 Acb.AtaDeviceHead = (UINT8)(PortMultiplierPort == 0xFFFF ? 0 : (PortMultiplierPort << 4));
76 ZeroMem (&Packet,
sizeof (Packet));
77 Packet.
Protocol = EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT;
78 Packet.
Length = EFI_ATA_PASS_THRU_LENGTH_BYTES;
82 ((CHAR16 *)Buffer)[0] = Identifier & BIT0;
83 CopyMem (&((CHAR16 *)Buffer)[1], Password, HDD_PASSWORD_MAX_LENGTH);
89 Status = AtaPassThru->PassThru (
95 if (!EFI_ERROR (Status) &&
99 Status = EFI_DEVICE_ERROR;
104 ZeroMem (Buffer,
sizeof (Buffer));
106 DEBUG ((DEBUG_INFO,
"%a() - %r\n", __func__, Status));
127 IN UINT16 PortMultiplierPort
135 if (AtaPassThru ==
NULL) {
136 return EFI_INVALID_PARAMETER;
150 AtaPassThru->Mode->IoAlign
153 return EFI_OUT_OF_RESOURCES;
161 Acb.AtaCommand = ATA_SECURITY_FREEZE_LOCK_CMD;
162 Acb.AtaDeviceHead = (UINT8)(PortMultiplierPort == 0xFFFF ? 0 : (PortMultiplierPort << 4));
167 ZeroMem (&Packet,
sizeof (Packet));
168 Packet.
Protocol = EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA;
169 Packet.
Length = EFI_ATA_PASS_THRU_LENGTH_NO_DATA_TRANSFER;
174 Status = AtaPassThru->PassThru (
180 if (!EFI_ERROR (Status) &&
184 Status = EFI_DEVICE_ERROR;
189 DEBUG ((DEBUG_INFO,
"%a() - %r\n", __func__, Status));
210 UINT16 PortMultiplierPort;
212 UINTN DevicePathLength;
217 Buffer = (VOID *)&DummyData;
218 Length =
sizeof (DummyData);
219 Status =
RestoreLockBox (&mHddPasswordDeviceInfoGuid, Buffer, &Length);
220 if (Status == EFI_BUFFER_TOO_SMALL) {
222 if (Buffer !=
NULL) {
223 Status =
RestoreLockBox (&mHddPasswordDeviceInfoGuid, Buffer, &Length);
227 if ((Buffer ==
NULL) || (Buffer == (VOID *)&DummyData)) {
229 }
else if (EFI_ERROR (Status)) {
234 Status = AtaPassThruPpi->GetDevicePath (AtaPassThruPpi, &DevicePathLength, &DevicePath);
244 Status = AtaPassThruPpi->GetNextPort (AtaPassThruPpi, &Port);
245 if (EFI_ERROR (Status)) {
252 PortMultiplierPort = 0xFFFF;
254 Status = AtaPassThruPpi->GetNextDevice (AtaPassThruPpi, Port, &PortMultiplierPort);
255 if (EFI_ERROR (Status)) {
267 while ((
UINTN)DevInfo < ((
UINTN)Buffer + Length)) {
271 if ((DevInfo->Device.Port == Port) &&
272 (DevInfo->Device.PortMultiplierPort == PortMultiplierPort) &&
273 (DevInfo->DevicePathLength >= DevicePathLength) &&
283 if (!
IsZeroBuffer (DevInfo->Password, HDD_PASSWORD_MAX_LENGTH)) {
284 UnlockDevice (AtaPassThruPpi, Port, PortMultiplierPort, 0, DevInfo->Password);
324 DEBUG ((DEBUG_INFO,
"%a() - enter at S3 resume\n", __func__));
328 DEBUG ((DEBUG_INFO,
"%a() - exit at S3 resume\n", __func__));
334 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
335 &gEdkiiPeiAtaPassThruPpiGuid,
359 if ((EFI_ERROR (Status)) || (BootMode != BOOT_ON_S3_RESUME)) {
360 return EFI_UNSUPPORTED;
363 DEBUG ((DEBUG_INFO,
"%a: Enters in S3 path.\n", __func__));
#define ATA_ERRREG_ABRT
Aborted Command defined from ATA-1.
#define ATA_STSREG_ERR
Error defined from ATA-1.
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
BOOLEAN EFIAPI IsZeroBuffer(IN CONST VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
VOID EFIAPI FreeAlignedPages(IN VOID *Buffer, IN UINTN Pages)
EFI_STATUS EFIAPI PeiServicesGetBootMode(OUT EFI_BOOT_MODE *BootMode)
EFI_STATUS EFIAPI PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS UnlockDevice(IN EDKII_PEI_ATA_PASS_THRU_PPI *AtaPassThru, IN UINT16 Port, IN UINT16 PortMultiplierPort, IN CHAR8 Identifier, IN CHAR8 *Password)
EFI_STATUS EFIAPI HddPasswordAtaPassThruNotify(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, IN VOID *Ppi)
EFI_STATUS EFIAPI HddPasswordPeiInit(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
VOID UnlockHddPassword(IN EDKII_PEI_ATA_PASS_THRU_PPI *AtaPassThruPpi)
EFI_STATUS FreezeLockDevice(IN EDKII_PEI_ATA_PASS_THRU_PPI *AtaPassThru, IN UINT16 Port, IN UINT16 PortMultiplierPort)
RETURN_STATUS EFIAPI RestoreLockBox(IN GUID *Guid, IN VOID *Buffer OPTIONAL, IN OUT UINTN *Length OPTIONAL)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
VOID * EFI_PEI_FILE_HANDLE
VOID *EFIAPI AllocateAlignedPages(IN UINTN Pages, IN UINTN Alignment)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
VOID EFIAPI Exit(IN EFI_STATUS Status)
#define EFI_SIZE_TO_PAGES(Size)
EFI_ATA_STATUS_BLOCK * Asb
EFI_ATA_PASS_THRU_LENGTH Length
EFI_ATA_PASS_THRU_CMD_PROTOCOL Protocol
EFI_ATA_COMMAND_BLOCK * Acb