diff options
author | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
---|---|---|
committer | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
commit | b7c51c9cf4864df6aabb99a1ae843becd577237c (patch) | |
tree | eebe9b0d0ca03062955223097e57da84dd618b9a /Board/EM/MeWrapper/AmtWrapper/AmtPetAlert | |
download | zprj-b7c51c9cf4864df6aabb99a1ae843becd577237c.tar.xz |
Diffstat (limited to 'Board/EM/MeWrapper/AmtWrapper/AmtPetAlert')
8 files changed, 2398 insertions, 0 deletions
diff --git a/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.c b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.c new file mode 100644 index 0000000..774d8f9 --- /dev/null +++ b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.c @@ -0,0 +1,863 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/AmtPetAlert.c 8 6/18/14 3:16a Larryliu $ +// +// $Revision: 8 $ +// +// $Date: 6/18/14 3:16a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/AmtPetAlert.c $ +// +// 8 6/18/14 3:16a Larryliu +// [TAG] EIP173999 +// [Category] Improvement +// [Description] [HWR]Remove useless comments from Intel ME +// component.(except RC) +// [Files] AmtPetAlert.c +// +// 6 5/14/14 9:38p Tristinchou +// [TAG] EIP160730 +// [Category] Improvement +// [Description] Remove the variable runtime attribute and keep original +// attributes. +// +// 5 12/25/12 12:56a Klzhan +// Fix AMT_TC007 fail. +// +// 4 11/07/12 8:45a Klzhan +// Improvement : Set Booted HDD as expected Boot device +// +// 3 9/19/12 6:58a Klzhan +// Correct PET Alert behavior. +// +// 2 6/05/12 2:33a Klzhan +// [TAG] EIP90325 +// [Category] Improvement +// [Description] To pass Win8 SCT test. +// +// 1 2/08/12 1:10a Klzhan +// Initial Check in +// +// 2 6/30/11 5:49a Klzhan +// Fix AMT TC007 fail with Fixed bootorder. +// +// 1 2/25/11 1:45a Klzhan +// Initial Check-in +// +// 1 12/03/10 5:11a Klzhan +// Initial Check-in. +// +//********************************************************************** + +//<AMI_FHDR_START> +//--------------------------------------------------------------------------- +// Name: AmtPetAlert.c +// +// Description: AMT Pet Alert Functions. +// +//--------------------------------------------------------------------------- +//<AMI_FHDR_END> +#include "AmtPetAlert.h" +#include <ReferenceCode\ME\Protocol\AlertStandardFormat\AlertStandardFormat.h> + +EFI_GUID gEfiAmtWrapperProtocolGuid = EFI_AMT_WRAPPER_PROTOCOL_GUID; +EFI_GUID gEfiSetupGuid = SETUP_GUID; +EFI_GUID gEfiGlobalVariableGuid = EFI_GLOBAL_VARIABLE_GUID; +EFI_GUID gEfiLegacyBiosProtocolGuid = EFI_LEGACY_BIOS_PROTOCOL_GUID; +EFI_GUID gEfiEventReadyToBootGuid = EFI_EVENT_GROUP_READY_TO_BOOT; +EFI_GUID gEfiDiskInfoProtocolGuid = EFI_DISK_INFO_PROTOCOL_GUID; +EFI_GUID gEfiDevicePathProtocolGuid = EFI_DEVICE_PATH_PROTOCOL_GUID; +EFI_GUID gEfiHeciProtocolGuid = HECI_PROTOCOL_GUID; +EFI_GUID gEfiBlockIoProtocolGuid = EFI_BLOCK_IO_PROTOCOL_GUID; +EFI_GUID gEfiSimpleFileSystemProtocolGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; + +VOID +InitializeAmtPetAlert ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable +) +{ + EFI_STATUS Status; + EFI_EVENT ReadyToBootEvent; + EFI_EVENT LegacyBootEvent; + + EfiInitializeDriverLib (ImageHandle, SystemTable); + + // + // Register Ready to Boot Event for AMT Wrapper + // + Status = EfiCreateEventReadyToBoot( + EFI_TPL_CALLBACK, + AmtPetAlertReadyToBoot, + (VOID *)&ImageHandle, + &ReadyToBootEvent + ); + + Status = EfiCreateEventLegacyBoot( + EFI_TPL_CALLBACK, + AmtPetAlertLegacyBoot, + NULL, + &LegacyBootEvent + ); + + return; +} + +VOID SwapEntries ( + IN CHAR8 *Data, + IN UINT16 Size +) +{ + UINT16 Index; + CHAR8 Temp8; + + for (Index = 0; (Index+1) < Size; Index+=2) { + Temp8 = Data[Index]; + Data[Index] = Data[Index + 1]; + Data[Index + 1] = Temp8; + } +} + +CHAR8 * +ConvertChar16ToChar8 ( + IN CHAR16 *Src +) +{ + UINTN l; + CHAR8 *Output; + CHAR8 *Dest; + EFI_STATUS Status; + + l = EfiStrLen(Src) + 1; + Status = gBS->AllocatePool( + EfiBootServicesData, + l, + &Output + ); + ASSERT_EFI_ERROR(Status); + + Dest = Output; + while (*Src) { + *Dest++ = (UINT8) (*Src++); + } + *Dest = 0; + + return Output; +} + +// Example 1: 16 10 0F 6F 02 68 08 FF FF 00 00 40 13 XX XX XX +// Example 2: 15 10 0F 6F 02 68 10 FF FF 22 00 AA 13 03 03 02 +BOOT_AUDIT_ENTRY PetAlertWithoutChange = { + 0x15, 0x10, 0x0F, 0x6F, 0x02, 0x68, 0x08, 0xFF, 0xFF, 0x22, 0x00, 0x40, 0x13, 0x00, 0x00, 0x00 +}; + +BOOT_AUDIT_ENTRY PetAlertWithChange = { + 0x15, 0x10, 0x0F, 0x6F, 0x02, 0x68, 0x10, 0xFF, 0xFF, 0x22, 0x00, 0xAA, 0x13, 0x03, 0x03, 0x02 +}; + +EFI_STATUS +SendBaeMessage( + BOOT_AUDIT_ENTRY *Buffer +) +{ + EFI_HECI_PROTOCOL *Heci; + UINT32 HeciLength; + BOOT_AUDIT_ENTRY_PACK Pack; + UINT32 MeStatus; + EFI_STATUS TempStatus; + EFI_STATUS Status; + + gBS->CopyMem(&Pack.Data, Buffer, sizeof(BOOT_AUDIT_ENTRY)); + Pack.Command = EFI_ASF_MESSAGE_COMMAND_MESSAGE; // 0x04 + Pack.ByteCount = sizeof(BOOT_AUDIT_ENTRY); + HeciLength = sizeof(BOOT_AUDIT_ENTRY_PACK); // length include Command & ByteCount + + Status = gBS->LocateProtocol ( + &gEfiHeciProtocolGuid, + NULL, + &Heci + ); + if (!EFI_ERROR(Status)) { + TempStatus = Heci->GetMeStatus(&MeStatus); + ASSERT_EFI_ERROR(TempStatus); + + // + // Only send ASF Push Progress code when ME is ready. Ignore FW Init Status. + // + if (ME_STATUS_ME_STATE_ONLY(MeStatus) == ME_READY) { + Status = Heci->SendMsg( + (UINT32*)&Pack, + HeciLength, + BIOS_ASF_HOST_ADDR, + HECI_ASF_MESSAGE_ADDR + ); + if (EFI_ERROR(Status)) { + + } + } else { + + } + } else { + + } + + return Status; +} + +EFI_STATUS +PetAlert( + UINT8 DeviceType, + CHAR8 *HarddriveTag +) +{ + PET_ALERT_CFG PetAlertCfg[4]; + UINTN VarSize; + UINT32 VarAttr; + BOOLEAN BootChange = FALSE; + EFI_STATUS Status; + UINT8 BootHDD = 0, i; + + VarSize = sizeof(PetAlertCfg); + Status = gRT->GetVariable ( + L"PetAlertCfg", + &gEfiAmtWrapperProtocolGuid, + &VarAttr, + &VarSize, + &PetAlertCfg + ); + if (EFI_ERROR (Status)) { + VarAttr = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS; + + PetAlertCfg[0].BootQueue = DeviceType; + PetAlertCfg[1].BootQueue = DeviceType; + PetAlertCfg[2].BootQueue = DeviceType; + PetAlertCfg[3].BootQueue = DeviceType; + + if(DeviceType == BBS_TYPE_HARDDRIVE) + EfiAsciiStrCpy(PetAlertCfg[0].BootHarddriveTag, HarddriveTag); + else + EfiAsciiStrCpy(PetAlertCfg[0].BootHarddriveTag, ""); + EfiAsciiStrCpy(PetAlertCfg[1].BootHarddriveTag, ""); + EfiAsciiStrCpy(PetAlertCfg[2].BootHarddriveTag, ""); + EfiAsciiStrCpy(PetAlertCfg[3].BootHarddriveTag, ""); + BootChange = TRUE; + }else + { + if(DeviceType != BBS_HARDDISK) + BootChange = TRUE; + else + // If Boot HDD, check ModelSerialNumber + { + // last boot is not HD boot + if(PetAlertCfg[0].BootQueue != DeviceType) + { + BootChange = TRUE; + }else + { + // If this HDD is "excepted" or not + for(i = 0 ; i < 4 ; i++) + { + if((!EfiAsciiStrCmp(HarddriveTag,PetAlertCfg[i].BootHarddriveTag))) + BootHDD++; + } + // Not "Excepted", Set BootChanged + if(BootHDD == 0) + BootChange = TRUE; + } + } + if((DeviceType == BBS_HARDDISK) && BootChange) + PetAlertWithChange.EventData3 = 0x02; + // Not Frist Boot, update PET BAE variable. + PetAlertCfg[3].BootQueue = PetAlertCfg[2].BootQueue; + PetAlertCfg[2].BootQueue = PetAlertCfg[1].BootQueue; + PetAlertCfg[1].BootQueue = PetAlertCfg[0].BootQueue; + PetAlertCfg[0].BootQueue = DeviceType; + + // Update for HDD string + EfiAsciiStrCpy(PetAlertCfg[3].BootHarddriveTag, PetAlertCfg[2].BootHarddriveTag); + EfiAsciiStrCpy(PetAlertCfg[2].BootHarddriveTag, PetAlertCfg[1].BootHarddriveTag); + EfiAsciiStrCpy(PetAlertCfg[1].BootHarddriveTag, PetAlertCfg[0].BootHarddriveTag); + EfiAsciiStrCpy(PetAlertCfg[0].BootHarddriveTag, HarddriveTag); + } + + if (BootChange) + SendBaeMessage(&PetAlertWithChange); + else + SendBaeMessage(&PetAlertWithoutChange); + + VarSize = sizeof(PetAlertCfg); + Status = gRT->SetVariable ( + L"PetAlertCfg", + &gEfiAmtWrapperProtocolGuid, + VarAttr, + VarSize, + PetAlertCfg + ); + + return Status; +} + +BOOLEAN +ComparePathNode( + IN EFI_DEVICE_PATH_PROTOCOL *PathNode1, + IN EFI_DEVICE_PATH_PROTOCOL *PathNode2 +) +{ + BOOLEAN st = FALSE; + UINTN Size1, Size2; + UINT8 *p1, *p2; + + if (PathNode1 == PathNode2) { + st = TRUE; + } else if (PathNode1 == NULL) { + } else if (PathNode2 == NULL) { + } else { + Size1 = DevicePathNodeLength(PathNode1); + Size2 = DevicePathNodeLength(PathNode2); + p1 = (UINT8 *)PathNode1; + p2 = (UINT8 *)PathNode2; + if ((Size1 == Size2) + && (DevicePathType(PathNode1) == DevicePathType(PathNode2)) + && (EfiCompareMem(p1+1, p2+1, Size1-1) == 0)) { + st = TRUE; + } + } + + return st; +} + +UINT8 +GetDeviceType( + IN EFI_DEVICE_PATH_PROTOCOL *DevPath + ) +{ + UINT8 DeviceType = 0; + EFI_DEVICE_PATH_PROTOCOL *DevPathNode; + + // + // Find HDD Node in BootDevPath + // + DevPathNode = BdsLibUnpackDevicePath(DevPath); + ASSERT (DevPathNode); + + while (!IsDevicePathEnd(DevPathNode)) { + if (DevicePathType(DevPathNode) == MEDIA_DEVICE_PATH) { + if (DevicePathSubType(DevPathNode) == MEDIA_HARDDRIVE_DP) { + DeviceType = BBS_TYPE_HARDDRIVE; // 2 + break; + } else if (DevicePathSubType(DevPathNode) == MEDIA_CDROM_DP) { + DeviceType = BBS_TYPE_CDROM; // 3 + break; + } else if (DevicePathSubType(DevPathNode) == MEDIA_FILEPATH_DP) { + DeviceType = BBS_TYPE_FLOPPY; // 1 + break; + } + } + // + // Next device path node + // + DevPathNode = NextDevicePathNode(DevPathNode); + } + + return DeviceType; +} + +EFI_DEVICE_PATH_PROTOCOL * +GetMediaPathNode ( + IN EFI_DEVICE_PATH_PROTOCOL *DevPath +) +{ + EFI_DEVICE_PATH_PROTOCOL *DevPathNode; + EFI_DEVICE_PATH_PROTOCOL *MediaPathNode = NULL; + + // + // Find HDD Node in BootDevPath + // + DevPathNode = BdsLibUnpackDevicePath(DevPath); + ASSERT (DevPathNode); + + while (!IsDevicePathEnd(DevPathNode)) { + if (DevicePathType(DevPathNode) == MEDIA_FILEPATH_DP) { + MediaPathNode = DevPathNode; + break; + } + // + // Next device path node + // + DevPathNode = NextDevicePathNode(DevPathNode); + } + + return MediaPathNode; +} + +BOOLEAN +CompareMediaPathNode( + IN EFI_DEVICE_PATH_PROTOCOL *DevPath1, + IN EFI_DEVICE_PATH_PROTOCOL *DevPath2 +) +{ + EFI_DEVICE_PATH_PROTOCOL *PathNode1; + EFI_DEVICE_PATH_PROTOCOL *PathNode2; + BOOLEAN st = FALSE; + + PathNode1 = GetMediaPathNode(DevPath1); + PathNode2 = GetMediaPathNode(DevPath2); + st = ComparePathNode(PathNode1, PathNode2); + + return st; +} + +VOID +Trim( + CHAR8 *sDesc, + CHAR8 *sSrc +) +{ + UINTN p1 ,p2; + CHAR8 ch; + UINTN i,l; + + p1 = 0xFF; + p2 = 0xFF; + i = 0; + for(;;) { + ch = *(sSrc+i); + if (ch == 0) { + break; + } else if (ch != 0x20) { + p2 = i; + if (p1 == 0xFF) { + p1 = i; + } + } + i++; + } + + l = (p2 - p1) + 1; + gBS->CopyMem(sDesc, sSrc+p1, l); + *(sDesc+l) = 0; +} + +EFI_STATUS +GetModelSerialNumber( + IN EFI_HANDLE Handle, + OUT CHAR8 *ModelSerialNumber +) +{ + EFI_STATUS Status = EFI_NOT_FOUND; + EFI_DISK_INFO_PROTOCOL *DiskInfo; + IDENTIFY_DATA *IdentifyDriveInfo = NULL; + UINT32 BufferSize; + CHAR8 ModelNumber[42]; + CHAR8 SerialNumber[22]; + EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL; + + EfiAsciiStrCpy(ModelSerialNumber, ""); + + for(;;) { + Status = gBS->HandleProtocol( + Handle, + &gEfiDevicePathProtocolGuid, + &DevicePath); + if (EFI_ERROR(Status)) + break; + + Status = gBS->LocateDevicePath ( + &gEfiDiskInfoProtocolGuid, + &DevicePath, + &Handle + ); + if (EFI_ERROR (Status)) { + break; + } + + Status = gBS->HandleProtocol ( + Handle, + &gEfiDiskInfoProtocolGuid, + &DiskInfo + ); + if (EFI_ERROR(Status)) + break; + + Status = gBS->AllocatePool( + EfiBootServicesData, + sizeof (IDENTIFY_DATA), + &IdentifyDriveInfo + ); + if (EFI_ERROR(Status)) + break; + + gBS->SetMem(IdentifyDriveInfo, sizeof (IDENTIFY_DATA), 0); + BufferSize = sizeof (IDENTIFY_DATA); + Status = DiskInfo->Identify ( + DiskInfo, + IdentifyDriveInfo, + &BufferSize + ); + if (EFI_ERROR(Status)) + break; + + gBS->CopyMem(SerialNumber, IdentifyDriveInfo->Serial_Number_10, 20); + SwapEntries (SerialNumber, 20); + SerialNumber[20] = '\0'; + Trim(SerialNumber, SerialNumber); + + gBS->CopyMem(ModelNumber, IdentifyDriveInfo->Model_Number_27, 40); + SwapEntries (ModelNumber, 40); + ModelNumber[40] = '\0'; + Trim(ModelNumber, ModelNumber); + + EfiAsciiStrCpy(ModelSerialNumber, ModelNumber); + EfiAsciiStrCat(ModelSerialNumber, "_"); + EfiAsciiStrCat(ModelSerialNumber, SerialNumber); + + Status = EFI_SUCCESS; + break; + } + + if (IdentifyDriveInfo != NULL) + gBS->FreePool(IdentifyDriveInfo); + + return Status; +} + +EFI_DEVICE_PATH_PROTOCOL * +GetDevicePathFromBBS( + UINT8 DeviceType, + CHAR8 *ModelSerialNumber + +) +{ + EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; + UINT16 HddCount = 0; + HDD_INFO *LocalHddInfo = NULL; + UINT16 BbsCount = 0; + BBS_TABLE *BbsTable; + EFI_STATUS Status; + BBS_TABLE *BbsEntry; + EFI_DEVICE_PATH_PROTOCOL *DevicePath = NULL; + UINTN i; + EFI_HANDLE Handle; + UINTN DeviceIndex; + UINTN DevicePriority; + + Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, &LegacyBios); + if (!EFI_ERROR (Status)) { + Status = LegacyBios->GetBbsInfo ( + LegacyBios, + &HddCount, + &LocalHddInfo, + &BbsCount, + &BbsTable + ); + if (!EFI_ERROR (Status)) { + // + // Find match index by prioridy + // + DeviceIndex = (UINTN)-1; + DevicePriority = (UINTN)-1; + for (i = 0; i < BbsCount; i++) { + BbsEntry = BbsTable+i; + if (BbsEntry->BootPriority == BBS_IGNORE_ENTRY) + continue; + if (BbsEntry->DeviceType == DeviceType) { + if (DevicePriority > BbsEntry->BootPriority) { + DevicePriority = BbsEntry->BootPriority; + DeviceIndex = i; + } + } + } + + // + // Get model and serial number + // + if (DeviceIndex != (UINTN)-1) { + BbsEntry = BbsTable + DeviceIndex; + Handle = *(VOID**)(&BbsEntry->IBV1); + GetModelSerialNumber(Handle, ModelSerialNumber); + } + } + } + + return DevicePath; +} + +EFI_STATUS +NotifyPetAlert( + EFI_EVENT Event, + VOID *ParentImageHandle +) +{ + EFI_STATUS Status = EFI_SUCCESS; + UINTN i; + UINT16 BootCurrent; + UINTN VarSize; + CHAR16 BootXXXX[16]; + EFI_LOAD_OPTION *BootOption = NULL; + UINT8 *pDP; + BBS_BBS_DEVICE_PATH *bDP; // DP for BBS + UINTN LegacyBoot = 1; + EFI_DEVICE_PATH_PROTOCOL *BootDevicePath = NULL; + UINT8 DeviceType; + CHAR8 ModelSerialNumber[64]; + EFI_ASF_BOOT_OPTIONS *mAsfBootOptions; + EFI_ALERT_STANDARD_FORMAT_PROTOCOL *Asf; + EFI_GUID gEfiAlertStandardFormatProtocolGuid = EFI_ALERT_STANDARD_FORMAT_PROTOCOL_GUID; + + Status = gBS->LocateProtocol ( + &gEfiAlertStandardFormatProtocolGuid, + NULL, + &Asf + ); + + if (EFI_ERROR (Status)) return Status; + Status = Asf->GetBootOptions (Asf, &mAsfBootOptions); + if (EFI_ERROR (Status)) mAsfBootOptions = NULL; + + EfiAsciiStrCpy(ModelSerialNumber, ""); + + // + // BootCurrent + // + VarSize = sizeof (UINT16); + Status = gRT->GetVariable ( + L"BootCurrent", + &gEfiGlobalVariableGuid, + NULL, + &VarSize, + &BootCurrent + ); + if (!EFI_ERROR (Status)) { + } else { + BootCurrent = 0; + } + + SPrint(BootXXXX, sizeof(BootXXXX), L"Boot%04x", BootCurrent); + + VarSize = 0; + Status = gRT->GetVariable ( + BootXXXX, + &gEfiGlobalVariableGuid, + NULL, + &VarSize, + NULL + ); + if (Status != EFI_BUFFER_TOO_SMALL) { + return Status; + } + + // + // Allocate Memory for BootXXXX + // + Status = gBS->AllocatePool( + EfiBootServicesData, + VarSize, + &BootOption + ); + ASSERT_EFI_ERROR(Status); + + Status = gRT->GetVariable ( + BootXXXX, + &gEfiGlobalVariableGuid, + NULL, + &VarSize, + BootOption + ); + if (!EFI_ERROR (Status)) { + pDP = (UINT8*)(BootOption+1); + pDP += (EfiStrLen((CHAR16*)pDP) + 1) * sizeof(CHAR16); + + BootDevicePath = EfiDuplicateDevicePath((EFI_DEVICE_PATH_PROTOCOL *)pDP); + + // + // Free Memory for BootXXXX + // + if (BootOption != NULL) { + gBS->FreePool(BootOption); + BootOption = NULL; + } + } + + if (BootDevicePath != NULL) { + bDP = (BBS_BBS_DEVICE_PATH *)BootDevicePath; + if (bDP->Header.Type == BBS_DEVICE_PATH && bDP->Header.SubType == BBS_BBS_DP) { + LegacyBoot = 1; + } else { + LegacyBoot = 0; + } + } + + //------------------------------------------------------------------------- + // EFI Boot + //------------------------------------------------------------------------- + if (LegacyBoot == 0) { + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + EFI_HANDLE Handle; + EFI_DEVICE_PATH_PROTOCOL *DPath; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_DEVICE_PATH_PROTOCOL *BootDeviceHandle; + + if (BootDevicePath == NULL) { + // + // Boot to EFI Shell + // + //Need Save "BootXXXX" in setup when launch entry after add boot option without Save + } + else { + DevicePath = EfiDuplicateDevicePath(BootDevicePath); + Status = gBS->LocateDevicePath ( + &gEfiSimpleFileSystemProtocolGuid, + &DevicePath, + &BootDeviceHandle + ); + if (EFI_ERROR (Status)) { + BootDeviceHandle = NULL; + } + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiSimpleFileSystemProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (i = 0; i < HandleCount; i ++) { + BOOLEAN st; + + Handle = HandleBuffer[i]; + Status = gBS->HandleProtocol ( + Handle, + &gEfiDevicePathProtocolGuid, + &DPath + ); + if (!EFI_ERROR (Status)) { + // + // !!! CompareMedia only work with HDD & CD-ROM !!! + // + st = CompareMediaPathNode(BootDevicePath, DPath); + if (st == FALSE) { + // + // for USB MassStorage + // + if (Handle == BootDeviceHandle) { + st = TRUE; + } + } + + if (st) { + DeviceType = GetDeviceType(BootDevicePath); + + if (DeviceType == BBS_TYPE_HARDDRIVE) { + GetModelSerialNumber(Handle, ModelSerialNumber); + } else { + EfiAsciiStrCpy(ModelSerialNumber, ""); + } + PetAlert(DeviceType, ModelSerialNumber); + } + } + } + if (HandleBuffer != NULL) { + gBS->FreePool (HandleBuffer); + } + } + } + } + //------------------------------------------------------------------------- + // Legacy Boot + //------------------------------------------------------------------------- + else { + if (BootDevicePath != NULL) { + bDP = (BBS_BBS_DEVICE_PATH *)BootDevicePath; + DeviceType = (UINT8) bDP->DeviceType; + } else { + DeviceType = BBS_TYPE_HARDDRIVE; + } + if ((mAsfBootOptions != NULL) && (mAsfBootOptions->SubCommand == 0x16)) { + switch (mAsfBootOptions->SpecialCommand ) { + case 1: DeviceType = BBS_TYPE_EMBEDDED_NETWORK; + break; + case 2: + case 3: DeviceType = BBS_TYPE_HARDDRIVE; + break; + case 5: DeviceType = BBS_TYPE_CDROM; + break; + } + } + + switch (DeviceType) { + case BBS_TYPE_EMBEDDED_NETWORK: + case BBS_TYPE_FLOPPY: + case BBS_TYPE_CDROM: + PetAlert(DeviceType, NULL); + break; + + case BBS_TYPE_HARDDRIVE: + GetDevicePathFromBBS(BBS_TYPE_HARDDRIVE, ModelSerialNumber); + PetAlert(DeviceType, ModelSerialNumber); + break; + + default: + // + // Add code for process if run here + // + PetAlert(DeviceType, NULL); + break; + } + } + + return Status; +} + +EFI_STATUS +AmtPetAlertReadyToBoot( + EFI_EVENT Event, + VOID *ParentImageHandle +) +{ + EFI_STATUS Status = EFI_SUCCESS; + + Status = NotifyPetAlert(Event, ParentImageHandle); + + return Status; +} + +EFI_STATUS +AmtPetAlertLegacyBoot( + EFI_EVENT Event, + VOID *ParentImageHandle +) +{ + EFI_STATUS Status = EFI_SUCCESS; + + return Status; +} +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* diff --git a/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.cif b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.cif new file mode 100644 index 0000000..d346ae9 --- /dev/null +++ b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.cif @@ -0,0 +1,14 @@ +<component> + name = "AmtPetAlert" + category = ModulePart + LocalRoot = "Board\EM\MeWrapper\AmtWrapper\AmtPetAlert\" + RefName = "AmtPetAlert" +[files] +"AmtPetAlert.sdl" +"AmtPetAlert.mak" +"AmtPetAlert.c" +"AmtPetAlert.h" +"AmtPetAlert.dxs" +"DevicePath.h" +"DevicePath.c" +<endComponent> diff --git a/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.dxs b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.dxs new file mode 100644 index 0000000..29ac1c9 --- /dev/null +++ b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.dxs @@ -0,0 +1,68 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/AmtPetAlert.dxs 1 2/08/12 1:10a Klzhan $ +// +// $Revision: 1 $ +// +// $Date: 2/08/12 1:10a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/AmtPetAlert.dxs $ +// +// 1 2/08/12 1:10a Klzhan +// Initial Check in +// +// 1 2/25/11 1:45a Klzhan +// Initial Check-in +// +// 1 12/03/10 5:11a Klzhan +// Initial Check-in. +// +//********************************************************************** + +//<AMI_FHDR_START> +//--------------------------------------------------------------------------- +// Name: AmtPeiAlert.dxs +// +// Description: This file is the dependency file for AmtPetAlert driver. +// +//--------------------------------------------------------------------------- +//<AMI_FHDR_END> +#include <Protocol\Variable.h> + +#include EFI_PROTOCOL_DEFINITION (ActiveManagement) +#include EFI_PROTOCOL_DEFINITION (Heci) + +DEPENDENCY_START + EFI_HECI_PROTOCOL_GUID AND + EFI_ACTIVE_MANAGEMENT_PROTOCOL_GUID AND + EFI_VARIABLE_ARCH_PROTOCOL_GUID AND + EFI_VARIABLE_WRITE_ARCH_PROTOCOL_GUID +DEPENDENCY_END + +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* diff --git a/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.h b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.h new file mode 100644 index 0000000..de37961 --- /dev/null +++ b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.h @@ -0,0 +1,205 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* + +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/AmtPetAlert.h 1 2/08/12 1:10a Klzhan $ +// +// $Revision: 1 $ +// +// $Date: 2/08/12 1:10a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/AmtPetAlert.h $ +// +// 1 2/08/12 1:10a Klzhan +// Initial Check in +// +// 1 2/25/11 1:45a Klzhan +// Initial Check-in +// +// 1 12/03/10 5:11a Klzhan +// Initial Check-in. +// +//********************************************************************** + +//<AMI_FHDR_START> +//--------------------------------------------------------------------------- +// Name: AmtPetAlert.h +// +// Description: Header file of AmtPetAlert module. +// +//--------------------------------------------------------------------------- +//<AMI_FHDR_END> +#ifndef __AMT_PET_ALERT_H__ +#define __AMT_PET_ALERT_H__ + +#include "Tiano.h" +#include "EfiDriverLib.h" +#include "EfiPrintLib.h" +#include "EfiCommonLib.h" +#include "Amt.h" +#include "EfiScriptLib.h" +#include "AmtLib.h" +#include "MeLib.h" +#include "Include\Protocol\PDiskInfo.h" +#include "DevicePath.h" +#include "HeciRegs.h" + +#include EFI_PROTOCOL_CONSUMER (AmtPlatformPolicy) +#include EFI_PROTOCOL_CONSUMER (AmtWrapper) +#include EFI_PROTOCOL_CONSUMER (DiskInfo) +#include EFI_PROTOCOL_CONSUMER (Heci) +#include EFI_PROTOCOL_CONSUMER (BlockIo) +#include EFI_PROTOCOL_CONSUMER (SimpleFileSystem) +#include EFI_PROTOCOL_DEFINITION (LegacyBios) +#include EFI_GUID_DEFINITION (GlobalVariable) + +#define SETUP_GUID { 0xEC87D643, 0xEBA4, 0x4BB5, 0xA1, 0xE5, 0x3F, 0x3E, 0x36, 0xB2, 0x0D, 0xA9 } +//#define EFI_GLOBAL_VARIABLE_GUID { 0x8BE4DF61, 0x93CA, 0x11D2, 0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C } + +// Based on ATA/ATAPI-6 +typedef struct _IDENTIFY_DATA{ + + UINT16 General_Config_0; + UINT16 Reserved_1; + UINT16 Special_Config_2; + UINT16 Reserved_3; + UINT16 Reserved_4; + UINT16 Reserved_5; + UINT16 Reserved_6; + UINT16 Reserved_7; + UINT16 Reserved_8; + UINT16 Reserved_9; + UINT8 Serial_Number_10[20]; + UINT16 Reserved_20; + UINT16 Reserved_21; + UINT16 Reserved_22; + UINT8 Firmware_Revision_23[8]; + UINT8 Model_Number_27[40]; + UINT16 Maximum_Sector_Multiple_Command_47; + UINT16 Reserved_48; + UINT16 Capabilities_49; + UINT16 Capabilities_50; + UINT16 PIO_Mode_51; + UINT16 Reserved_52; + UINT16 Valid_Bits_53; + UINT16 Reserved_54_58[5]; + UINT16 Valid_Bits_59; + UINT32 Addressable_Sector_60; + UINT16 SingleWord_DMA_62; + UINT16 MultiWord_DMA_63; + UINT16 PIO_Mode_64; + UINT16 Min_Multiword_DMA_timing_65; + UINT16 Manuf_Multiword_DMA_timing_66; + UINT16 Min_PIO_Mode_timing_67; + UINT16 Min_PIO_Mode_timing_68; + UINT16 Reserved_69_74[6]; + UINT16 Queue_Depth_75; + UINT16 Reserved_76_79[4]; + UINT16 Major_Revision_80; + UINT16 Minor_Revision_81; + UINT16 Command_Set_Supported_82; + UINT16 Command_Set_Supported_83; + UINT16 Command_Set_Supported_84; + UINT16 Command_Set_Enabled_85; + UINT16 Command_Set_Enabled_86; + UINT16 Command_Set_Enabled_87; + UINT16 UDMA_Mode_88; + UINT16 Time_security_Earse_89; + UINT16 Time_Esecurity_Earse_90; + UINT16 Current_Power_Level_91; + UINT16 Master_Password_Rev_92; + UINT16 Hard_Reset_Value_93; + UINT16 Acoustic_Level_94; + UINT16 Reserved_95_99[5]; + UINT64 LBA_48; + UINT16 Reserved_104_126[23]; + UINT16 Status_Notification_127; + UINT16 Security_Status_128; + UINT16 Reserved_129_159[31]; + UINT16 CFA_Power_Mode_160; + UINT16 Reserved_161_175[15]; + UINT16 Media_Serial_Number_176_205[30]; + UINT16 Reserved_206_254[49]; + UINT16 Checksum_255; +} IDENTIFY_DATA; + +#pragma pack(push,1) +typedef struct { + UINT32 Attributes; + UINT16 FilePathListLength; +} EFI_LOAD_OPTION; + +// Example 1: 16 10 0F 6F 02 68 08 FF FF 00 00 40 13 XX XX XX +// Example 2: 15 10 0F 6F 02 68 10 FF FF 22 00 AA 13 03 03 02 + +typedef struct { + UINT8 SubCommand; // 0x00 + UINT8 VersionNumber; // 0x01 + UINT8 EventSensorType; // 0x02 + UINT8 EventType; // 0x03 + UINT8 EventOffset; // 0x04 + UINT8 EventSourceType; // 0x05 + UINT8 EventSeverity; // 0x06 + UINT8 SensorDevice; // 0x07 + UINT8 Sensornumber; // 0x08 + UINT8 Entity; // 0x09 + UINT8 EntityInstance; // 0x0A + UINT8 EventData1; // 0x0B + UINT8 EventData2; // 0x0C + UINT8 EventData3; // 0x0D + UINT8 EventData4; // 0x0E + UINT8 EventData5; // 0x0F +} BOOT_AUDIT_ENTRY; + +typedef struct { + UINT8 Command; + UINT8 ByteCount; + BOOT_AUDIT_ENTRY Data; +} BOOT_AUDIT_ENTRY_PACK; + +typedef struct { + UINT8 BootQueue; + UINT8 BootHarddriveTag[64]; +} PET_ALERT_CFG; + +#pragma pack(pop) + +EFI_STATUS +AmtPetAlertReadyToBoot( + EFI_EVENT Event, + VOID *ParentImageHandle +); + +EFI_STATUS +AmtPetAlertLegacyBoot( + EFI_EVENT Event, + VOID *ParentImageHandle +); + +#endif +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//*************************************************************************
\ No newline at end of file diff --git a/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.mak b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.mak new file mode 100644 index 0000000..cf5d5a4 --- /dev/null +++ b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.mak @@ -0,0 +1,82 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2010, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/AmtPetAlert.mak 1 2/08/12 1:10a Klzhan $ +# +# $Revision: 1 $ +# +# $Date: 2/08/12 1:10a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/AmtPetAlert.mak $ +# +# 1 2/08/12 1:10a Klzhan +# Initial Check in +# +# 1 2/25/11 1:45a Klzhan +# Initial Check-in +# +# 1 12/03/10 5:11a Klzhan +# Initial Check-in. +# +#********************************************************************** +# +#<AMI_FHDR_START> +#--------------------------------------------------------------------------- +# Name: AmtPetAlert.mak +# +# Description: Makefile for AMT Pet Alert Module. +# +#--------------------------------------------------------------------------- +#<AMI_FHDR_END> +#--------------------------------------------------------------------------- +# Create AMT PET Alert Screens +#--------------------------------------------------------------------------- +All : AmtPetAlert + +AmtPetAlert : $(BUILD_DIR)\AmtPetAlert.mak AmtPetAlertBin + +$(BUILD_DIR)\AmtPetAlert.mak : $(AMT_PET_ALERT_DIR)\$(@B).cif $(AMT_PET_ALERT_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(AMT_PET_ALERT_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +AmtPetAlert_INCLUDES= \ + $(EDK_INCLUDES) \ + $(MISCFRAMEWORK_INCLUDES) \ + $(ME_INCLUDES) \ + $(IndustryStandard_INCLUDES)\ + +AmtPetAlertBin : $(EFIDRIVERLIB) $(EDKFRAMEWORKPROTOCOLLIB) $(PRINTLIB) $(EFICOMMONLIB) + $(MAKE) /$(MAKEFLAGS) $(EDK_DEFAULTS)\ + /f $(BUILD_DIR)\AmtPetAlert.mak all \ + "MY_INCLUDES=$(AmtPetAlert_INCLUDES)"\ + GUID=290EA249-6E88-423c-B0DA-75CDDE7920CC \ + TYPE=BS_DRIVER \ + ENTRY_POINT=InitializeAmtPetAlert \ + DEPEX1=$(AMT_PET_ALERT_DIR)\AmtPetAlert.dxs \ + DEPEX1_TYPE=EFI_SECTION_DXE_DEPEX \ + COMPRESS=1 +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2010, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#*************************************************************************
\ No newline at end of file diff --git a/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.sdl b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.sdl new file mode 100644 index 0000000..36ac23b --- /dev/null +++ b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/AmtPetAlert.sdl @@ -0,0 +1,24 @@ +TOKEN + Name = "AmtPetAlert_SUPPORT" + Value = "1" + Help = "Main switch to enable AMT PET Alert support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +PATH + Name = "AMT_PET_ALERT_DIR" +End + +MODULE + Help = "Includes AmtPetAlert.mak to Project" + File = "AmtPetAlert.mak" +End + +ELINK + Name = "$(BUILD_DIR)\AmtPetAlert.ffs" + Parent = "FV_MAIN" + InvokeOrder = AfterParent +End
\ No newline at end of file diff --git a/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/DevicePath.c b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/DevicePath.c new file mode 100644 index 0000000..0aec0b3 --- /dev/null +++ b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/DevicePath.c @@ -0,0 +1,1049 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/DevicePath.c 1 2/08/12 1:10a Klzhan $ +// +// $Revision: 1 $ +// +// $Date: 2/08/12 1:10a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/DevicePath.c $ +// +// 1 2/08/12 1:10a Klzhan +// Initial Check in +// +// 1 2/25/11 1:45a Klzhan +// Initial Check-in +// +// 1 12/03/10 5:11a Klzhan +// Initial Check-in. +// +//********************************************************************** +// +//<AMI_FHDR_START> +//--------------------------------------------------------------------------- +// Name: DevicePath.c +// +// Description: DevicePath functions for AMT Pet Alert. +// +//--------------------------------------------------------------------------- +//<AMI_FHDR_END> +#include "DevicePath.h" + +EFI_GUID UnknownDeviceGuid = UNKNOWN_DEVICE_GUID; + +EFI_GUID mEfiMsgPcAnsiGuid = DEVICE_PATH_MESSAGING_PC_ANSI; +EFI_GUID mEfiMsgVt100Guid = DEVICE_PATH_MESSAGING_VT_100; +EFI_GUID mEfiMsgVt100PlusGuid = DEVICE_PATH_MESSAGING_VT_100_PLUS; +EFI_GUID mEfiMsgVt100Utf8Guid = DEVICE_PATH_MESSAGING_VT_UTF8; + +VOID * +ReallocatePool ( + IN VOID *OldPool, + IN UINTN OldSize, + IN UINTN NewSize +) +/*++ + +Routine Description: + + Adjusts the size of a previously allocated buffer. + +Arguments: + + OldPool - A pointer to the buffer whose size is being adjusted. + + OldSize - The size of the current buffer. + + NewSize - The size of the new buffer. + +Returns: + + EFI_SUCEESS - The requested number of bytes were allocated. + + EFI_OUT_OF_RESOURCES - The pool requested could not be allocated. + + EFI_INVALID_PARAMETER - The buffer was invalid. + +--*/ +{ + VOID *NewPool; + + NewPool = NULL; + if (NewSize) + { + NewPool = EfiLibAllocateZeroPool (NewSize); + } + + if (OldPool) + { + if (NewPool) + { + EfiCopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize); + } + + gBS->FreePool (OldPool); + } + + return NewPool; +} + +CHAR16 * +CatPrint ( + IN OUT POOL_PRINT *Str, + IN CHAR16 *fmt, + ... +) +/*++ + +Routine Description: + + Concatenates a formatted unicode string to allocated pool. + The caller must free the resulting buffer. + +Arguments: + + Str - Tracks the allocated pool, size in use, and + amount of pool allocated. + + fmt - The format string + +Returns: + + Allocated buffer with the formatted string printed in it. + The caller must free the allocated buffer. The buffer + allocation is not packed. + +--*/ +{ + UINT16 *AppendStr; + VA_LIST args; + UINTN strsize; + + AppendStr = EfiLibAllocateZeroPool (0x1000); + if (AppendStr == NULL) + { + return Str->str; + } + + VA_START (args, fmt); + VSPrint (AppendStr, 0x1000, fmt, args); + VA_END (args); + if (NULL == Str->str) + { + strsize = EfiStrSize (AppendStr); + Str->str = EfiLibAllocateZeroPool (strsize); + ASSERT (Str->str != NULL); + } + else + { + strsize = EfiStrSize (AppendStr) + EfiStrSize (Str->str) - sizeof (UINT16); + Str->str = ReallocatePool ( + Str->str, + EfiStrSize (Str->str), + strsize + ); + ASSERT (Str->str != NULL); + } + + Str->maxlen = MAX_CHAR * sizeof (UINT16); + if (strsize < Str->maxlen) + { + EfiStrCat (Str->str, AppendStr); + Str->len = strsize - sizeof (UINT16); + } + + gBS->FreePool (AppendStr); + return Str->str; +} + +EFI_DEVICE_PATH_PROTOCOL * +BdsLibUnpackDevicePath ( + IN EFI_DEVICE_PATH_PROTOCOL *DevPath +) +/*++ + +Routine Description: + + Function unpacks a device path data structure so that all the nodes + of a device path are naturally aligned. + +Arguments: + + DevPath - A pointer to a device path data structure + +Returns: + + If the memory for the device path is successfully allocated, then a + pointer to the new device path is returned. Otherwise, NULL is returned. + +--*/ +{ + EFI_DEVICE_PATH_PROTOCOL *Src; + EFI_DEVICE_PATH_PROTOCOL *Dest; + EFI_DEVICE_PATH_PROTOCOL *NewPath; + UINTN Size; + + // + // Walk device path and round sizes to valid boundries + // + Src = DevPath; + Size = 0; + for (;;) + { + Size += DevicePathNodeLength (Src); + Size += ALIGN_SIZE (Size); + + if (IsDevicePathEnd (Src)) + { + break; + } + + Src = NextDevicePathNode (Src); + } + // + // Allocate space for the unpacked path + // + NewPath = EfiLibAllocateZeroPool (Size); + if (NewPath) + { + + ASSERT (((UINTN) NewPath) % MIN_ALIGNMENT_SIZE == 0); + + // + // Copy each node + // + Src = DevPath; + Dest = NewPath; + for (;;) + { + Size = DevicePathNodeLength (Src); + EfiCopyMem (Dest, Src, Size); + Size += ALIGN_SIZE (Size); + SetDevicePathNodeLength (Dest, Size); + Dest->Type |= EFI_DP_TYPE_UNPACKED; + Dest = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) Dest) + Size); + + if (IsDevicePathEnd (Src)) + { + break; + } + + Src = NextDevicePathNode (Src); + } + } + + return NewPath; +} + +VOID +DevPathPci ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + PCI_DEVICE_PATH *Pci; + + Pci = DevPath; + CatPrint (Str, L"Pci(%x|%x)", Pci->Device, Pci->Function); +} + +VOID +DevPathPccard ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + PCCARD_DEVICE_PATH *Pccard; + + Pccard = DevPath; + CatPrint (Str, L"Pcmcia(Function%x)", Pccard->FunctionNumber); +} + +VOID +DevPathMemMap ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + MEMMAP_DEVICE_PATH *MemMap; + + MemMap = DevPath; + CatPrint ( + Str, + L"MemMap(%d:%.lx-%.lx)", + MemMap->MemoryType, + MemMap->StartingAddress, + MemMap->EndingAddress + ); +} + +VOID +DevPathController ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + CONTROLLER_DEVICE_PATH *Controller; + + Controller = DevPath; + CatPrint (Str, L"Ctrl(%d)", Controller->Controller); +} + +VOID +DevPathVendor ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +/*++ + +Routine Description: + + Convert Vendor device path to device name + +Arguments: + + Str - The buffer store device name + DevPath - Pointer to vendor device path + +Returns: + + When it return, the device name have been stored in *Str. + +--*/ +{ + VENDOR_DEVICE_PATH *Vendor; + CHAR16 *Type; + INT32 *Temp; + + Vendor = DevPath; + Temp = (INT32 *) (&Vendor->Guid); + + switch (DevicePathType (&Vendor->Header)) + { + case HARDWARE_DEVICE_PATH: + // + // If the device is a winntbus device, we will give it a readable device name. + // + Type = L"Hw"; + break; + + case MESSAGING_DEVICE_PATH: + // + // If the device is a winntbus device, we will give it a readable device name. + // + if (EfiCompareGuid (&Vendor->Guid, &mEfiMsgPcAnsiGuid)) + { + CatPrint (Str, L"%s", L"PC-ANSI"); + return ; + } + else if (EfiCompareGuid (&Vendor->Guid, &mEfiMsgVt100Guid)) + { + CatPrint (Str, L"%s", L"VT100"); + return ; + } + else if (EfiCompareGuid (&Vendor->Guid, &mEfiMsgVt100PlusGuid)) + { + CatPrint (Str, L"%s", L"VT100+"); + return ; + } + else if (EfiCompareGuid (&Vendor->Guid, &mEfiMsgVt100Utf8Guid)) + { + CatPrint (Str, L"%s", L"VT100-UTF8"); + return ; + } + else + { + Type = L"Msg"; + break; + } + + case MEDIA_DEVICE_PATH: + Type = L"Media"; + break; + + default: + Type = L"?"; + break; + } + + CatPrint (Str, L"Ven%s(%g)", Type, &Vendor->Guid); +} + +VOID +DevPathAcpi ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + ACPI_HID_DEVICE_PATH *Acpi; + + Acpi = DevPath; + if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) + { + CatPrint (Str, L"Acpi(PNP%04x,%x)", EISA_ID_TO_NUM (Acpi->HID), Acpi->UID); + } + else + { + CatPrint (Str, L"Acpi(%08x,%x)", Acpi->HID, Acpi->UID); + } +} + +VOID +DevPathAtapi ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + ATAPI_DEVICE_PATH *Atapi; + + Atapi = DevPath; + CatPrint ( + Str, + L"Ata(%s,%s)", + Atapi->PrimarySecondary ? L"Secondary" : L"Primary", + Atapi->SlaveMaster ? L"Slave" : L"Master" + ); +} + +VOID +DevPathScsi ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + SCSI_DEVICE_PATH *Scsi; + + Scsi = DevPath; + CatPrint (Str, L"Scsi(Pun%x,Lun%x)", Scsi->Pun, Scsi->Lun); +} + +VOID +DevPathFibre ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + FIBRECHANNEL_DEVICE_PATH *Fibre; + + Fibre = DevPath; + CatPrint (Str, L"Fibre(Wwn%lx,Lun%x)", Fibre->WWN, Fibre->Lun); +} + +VOID +DevPath1394 ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + F1394_DEVICE_PATH *F1394; + + F1394 = DevPath; + CatPrint (Str, L"1394(%g)", &F1394->Guid); +} + +VOID +DevPathUsb ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + USB_DEVICE_PATH *Usb; + + Usb = DevPath; + CatPrint (Str, L"Usb(%x, %x)", Usb->ParentPortNumber, Usb->InterfaceNumber); +} + +VOID +DevPathUsbClass ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + USB_CLASS_DEVICE_PATH *UsbClass; + + UsbClass = DevPath; + CatPrint ( + Str, + L"Usb Class(%x, %x, %x, %x, %x)", + UsbClass->VendorId, + UsbClass->ProductId, + UsbClass->DeviceClass, + UsbClass->DeviceSubClass, + UsbClass->DeviceProtocol + ); +} + +VOID +DevPathI2O ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + I2O_DEVICE_PATH *I2O; + + I2O = DevPath; + CatPrint (Str, L"I2O(%x)", I2O->Tid); +} + +VOID +DevPathMacAddr ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + MAC_ADDR_DEVICE_PATH *MAC; + UINTN HwAddressSize; + UINTN Index; + + MAC = DevPath; + + HwAddressSize = sizeof (EFI_MAC_ADDRESS); + if (MAC->IfType == 0x01 || MAC->IfType == 0x00) + { + HwAddressSize = 6; + } + + CatPrint (Str, L"Mac("); + + for (Index = 0; Index < HwAddressSize; Index++) + { + CatPrint (Str, L"%02x", MAC->MacAddress.Addr[Index]); + } + + CatPrint (Str, L")"); +} + +VOID +DevPathIPv4 ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + IPv4_DEVICE_PATH *IP; + + IP = DevPath; + CatPrint ( + Str, + L"IPv4(%d.%d.%d.%d:%d)", + IP->RemoteIpAddress.Addr[0], + IP->RemoteIpAddress.Addr[1], + IP->RemoteIpAddress.Addr[2], + IP->RemoteIpAddress.Addr[3], + IP->RemotePort + ); +} + +VOID +DevPathIPv6 ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + IPv6_DEVICE_PATH *IP; + + IP = DevPath; + CatPrint (Str, L"IP-v6(not-done)"); +} + +VOID +DevPathInfiniBand ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + INFINIBAND_DEVICE_PATH *InfiniBand; + + InfiniBand = DevPath; + CatPrint (Str, L"InfiniBand(not-done)"); +} + +VOID +DevPathUart ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + UART_DEVICE_PATH *Uart; + CHAR8 Parity; + + Uart = DevPath; + switch (Uart->Parity) + { + case 0: + Parity = 'D'; + break; + + case 1: + Parity = 'N'; + break; + + case 2: + Parity = 'E'; + break; + + case 3: + Parity = 'O'; + break; + + case 4: + Parity = 'M'; + break; + + case 5: + Parity = 'S'; + break; + + default: + Parity = 'x'; + break; + } + + if (Uart->BaudRate == 0) + { + CatPrint (Str, L"Uart(DEFAULT %c", Parity); + } + else + { + CatPrint (Str, L"Uart(%d %c", Uart->BaudRate, Parity); + } + + if (Uart->DataBits == 0) + { + CatPrint (Str, L"D"); + } + else + { + CatPrint (Str, L"%d", Uart->DataBits); + } + + switch (Uart->StopBits) + { + case 0: + CatPrint (Str, L"D)"); + break; + + case 1: + CatPrint (Str, L"1)"); + break; + + case 2: + CatPrint (Str, L"1.5)"); + break; + + case 3: + CatPrint (Str, L"2)"); + break; + + default: + CatPrint (Str, L"x)"); + break; + } +} + +VOID +DevPathHardDrive ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + HARDDRIVE_DEVICE_PATH *Hd; + + Hd = DevPath; + switch (Hd->SignatureType) + { + case SIGNATURE_TYPE_MBR: + CatPrint ( + Str, + L"HD(Part%d,Sig%08x)", + Hd->PartitionNumber, + *((UINT32 *) (&(Hd->Signature[0]))) + ); + break; + + case SIGNATURE_TYPE_GUID: + CatPrint ( + Str, + L"HD(Part%d,Sig%g)", + Hd->PartitionNumber, + (EFI_GUID *) &(Hd->Signature[0]) + ); + break; + + default: + CatPrint ( + Str, + L"HD(Part%d,MBRType=%02x,SigType=%02x)", + Hd->PartitionNumber, + Hd->MBRType, + Hd->SignatureType + ); + break; + } +} + +VOID +DevPathCDROM ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + CDROM_DEVICE_PATH *Cd; + + Cd = DevPath; + CatPrint (Str, L"CDROM(Entry%x)", Cd->BootEntry); +} + +VOID +DevPathFilePath ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + FILEPATH_DEVICE_PATH *Fp; + + Fp = DevPath; + CatPrint (Str, L"%s", Fp->PathName); +} + +VOID +DevPathMediaProtocol ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + MEDIA_PROTOCOL_DEVICE_PATH *MediaProt; + + MediaProt = DevPath; + CatPrint (Str, L"%g", &MediaProt->Protocol); +} + +VOID +DevPathFvFilePath ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath; + + FvFilePath = DevPath; + CatPrint (Str, L"%g", &FvFilePath->NameGuid); +} + +VOID +DevPathBssBss ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + BBS_BBS_DEVICE_PATH *Bbs; + CHAR16 *Type; + + Bbs = DevPath; + switch (Bbs->DeviceType) + { + case BBS_TYPE_FLOPPY: + Type = L"Floppy"; + break; + + case BBS_TYPE_HARDDRIVE: + Type = L"Harddrive"; + break; + + case BBS_TYPE_CDROM: + Type = L"CDROM"; + break; + + case BBS_TYPE_PCMCIA: + Type = L"PCMCIA"; + break; + + case BBS_TYPE_USB: + Type = L"Usb"; + break; + + case BBS_TYPE_EMBEDDED_NETWORK: + Type = L"Net"; + break; + + default: + Type = L"?"; + break; + } + // + // Since current Print function hasn't implemented %a (for ansi string) + // we will only print Unicode strings. + // + CatPrint (Str, L"Legacy-%s", Type); +} + +VOID +DevPathEndInstance ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + CatPrint (Str, L","); +} + +VOID +DevPathNodeUnknown ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath +) +{ + CatPrint (Str, L"?"); +} + +DEVICE_PATH_STRING_TABLE DevPathTable[] = { + HARDWARE_DEVICE_PATH, + HW_PCI_DP, + DevPathPci, + HARDWARE_DEVICE_PATH, + HW_PCCARD_DP, + DevPathPccard, + HARDWARE_DEVICE_PATH, + HW_MEMMAP_DP, + DevPathMemMap, + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + DevPathVendor, + HARDWARE_DEVICE_PATH, + HW_CONTROLLER_DP, + DevPathController, + ACPI_DEVICE_PATH, + ACPI_DP, + DevPathAcpi, + MESSAGING_DEVICE_PATH, + MSG_ATAPI_DP, + DevPathAtapi, + MESSAGING_DEVICE_PATH, + MSG_SCSI_DP, + DevPathScsi, + MESSAGING_DEVICE_PATH, + MSG_FIBRECHANNEL_DP, + DevPathFibre, + MESSAGING_DEVICE_PATH, + MSG_1394_DP, + DevPath1394, + MESSAGING_DEVICE_PATH, + MSG_USB_DP, + DevPathUsb, + MESSAGING_DEVICE_PATH, + MSG_USB_CLASS_DP, + DevPathUsbClass, + MESSAGING_DEVICE_PATH, + MSG_I2O_DP, + DevPathI2O, + MESSAGING_DEVICE_PATH, + MSG_MAC_ADDR_DP, + DevPathMacAddr, + MESSAGING_DEVICE_PATH, + MSG_IPv4_DP, + DevPathIPv4, + MESSAGING_DEVICE_PATH, + MSG_IPv6_DP, + DevPathIPv6, + MESSAGING_DEVICE_PATH, + MSG_INFINIBAND_DP, + DevPathInfiniBand, + MESSAGING_DEVICE_PATH, + MSG_UART_DP, + DevPathUart, + MESSAGING_DEVICE_PATH, + MSG_VENDOR_DP, + DevPathVendor, + MEDIA_DEVICE_PATH, + MEDIA_HARDDRIVE_DP, + DevPathHardDrive, + MEDIA_DEVICE_PATH, + MEDIA_CDROM_DP, + DevPathCDROM, + MEDIA_DEVICE_PATH, + MEDIA_VENDOR_DP, + DevPathVendor, + MEDIA_DEVICE_PATH, + MEDIA_FILEPATH_DP, + DevPathFilePath, + MEDIA_DEVICE_PATH, + MEDIA_PROTOCOL_DP, + DevPathMediaProtocol, + MEDIA_DEVICE_PATH, + MEDIA_FV_FILEPATH_DP, + DevPathFvFilePath, + BBS_DEVICE_PATH, + BBS_BBS_DP, + DevPathBssBss, + END_DEVICE_PATH_TYPE, + END_INSTANCE_DEVICE_PATH_SUBTYPE, + DevPathEndInstance, + 0, + 0, + NULL + }; + +CHAR16 * +DevicePathToStr ( + IN EFI_DEVICE_PATH_PROTOCOL *DevPath +) +/*++ + + Turns the Device Path into a printable string. Allcoates + the string from pool. The caller must SafeFreePool the returned + string. + +--*/ +{ + POOL_PRINT Str; + EFI_DEVICE_PATH_PROTOCOL *DevPathNode; + VOID (*DumpNode) (POOL_PRINT *, VOID *); + + UINTN Index; + UINTN NewSize; + + EfiZeroMem (&Str, sizeof (Str)); + + if (DevPath == NULL) + { + goto Done; + } + // + // Unpacked the device path + // + DevPath = BdsLibUnpackDevicePath (DevPath); + ASSERT (DevPath); + + // + // Process each device path node + // + DevPathNode = DevPath; + while (!IsDevicePathEnd (DevPathNode)) + { + // + // Find the handler to dump this device path node + // + DumpNode = NULL; + for (Index = 0; DevPathTable[Index].Function; Index += 1) + { + + if (DevicePathType (DevPathNode) == DevPathTable[Index].Type && + DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType + ) + { + DumpNode = DevPathTable[Index].Function; + break; + } + } + // + // If not found, use a generic function + // + if (!DumpNode) + { + DumpNode = DevPathNodeUnknown; + } + // + // Put a path seperator in if needed + // + if (Str.len && DumpNode != DevPathEndInstance) + { + CatPrint (&Str, L"/"); + } + // + // Print this node of the device path + // + DumpNode (&Str, DevPathNode); + + // + // Next device path node + // + DevPathNode = NextDevicePathNode (DevPathNode); + } + // + // Shrink pool used for string allocation + // + gBS->FreePool (DevPath); + +Done: + NewSize = (Str.len + 1) * sizeof (CHAR16); + Str.str = ReallocatePool (Str.str, NewSize, NewSize); + ASSERT (Str.str != NULL); + Str.str[Str.len] = 0; + return Str.str; +} + +EFI_DEVICE_PATH_PROTOCOL * +LibDuplicateDevicePathInstance ( + IN EFI_DEVICE_PATH_PROTOCOL *DevPath +) +/*++ + +Routine Description: + + Function creates a device path data structure that identically matches the + device path passed in. + +Arguments: + + DevPath - A pointer to a device path data structure. + +Returns: + + The new copy of DevPath is created to identically match the input. + Otherwise, NULL is returned. + +--*/ +{ + EFI_DEVICE_PATH_PROTOCOL *NewDevPath; + EFI_DEVICE_PATH_PROTOCOL *DevicePathInst; + EFI_DEVICE_PATH_PROTOCOL *Temp; + UINTN Size; + + // + // get the size of an instance from the input + // + Temp = DevPath; + DevicePathInst = EfiDevicePathInstance (&Temp, &Size); + + // + // Make a copy + // + NewDevPath = NULL; + if (Size) + { + NewDevPath = EfiLibAllocateZeroPool (Size); + ASSERT (NewDevPath != NULL); + } + + if (NewDevPath) + { + EfiCopyMem (NewDevPath, DevicePathInst, Size); + } + + return NewDevPath; +} +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//*************************************************************************
\ No newline at end of file diff --git a/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/DevicePath.h b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/DevicePath.h new file mode 100644 index 0000000..1f73827 --- /dev/null +++ b/Board/EM/MeWrapper/AmtWrapper/AmtPetAlert/DevicePath.h @@ -0,0 +1,93 @@ +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//************************************************************************* +//********************************************************************** +// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/DevicePath.h 1 2/08/12 1:10a Klzhan $ +// +// $Revision: 1 $ +// +// $Date: 2/08/12 1:10a $ +//********************************************************************** +// Revision History +// ---------------- +// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/ME/AmtWrapper/AmtPetAlert/DevicePath.h $ +// +// 1 2/08/12 1:10a Klzhan +// Initial Check in +// +// 1 2/25/11 1:45a Klzhan +// Initial Check-in +// +// 1 12/03/10 5:11a Klzhan +// Initial Check-in. +// +//********************************************************************** +// +//<AMI_FHDR_START> +//--------------------------------------------------------------------------- +// Name: DevicePath.c +// +// Description: DevicePath functions for AMT Pet Alert. +// +//--------------------------------------------------------------------------- +//<AMI_FHDR_END> +#include "Tiano.h" +#include "EfiPrintLib.h" +#include "EfiDriverLib.h" + +// +// Internal definitions +// +typedef struct { + CHAR16 *str; + UINTN len; + UINTN maxlen; +} POOL_PRINT; + +typedef struct { + UINT8 Type; + UINT8 SubType; + VOID (*Function) (POOL_PRINT *, VOID *); +} DEVICE_PATH_STRING_TABLE; + +// +// Define Maxmim characters that will be accepted +// +#define MAX_CHAR 480 +#define MAX_CHAR_SIZE (MAX_CHAR * 2) + +#define MIN_ALIGNMENT_SIZE 4 +#define ALIGN_SIZE(a) ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0) + +CHAR16 * +DevicePathToStr ( + EFI_DEVICE_PATH_PROTOCOL *DevPath +); + +EFI_DEVICE_PATH_PROTOCOL * +BdsLibUnpackDevicePath ( + IN EFI_DEVICE_PATH_PROTOCOL *DevPath +); +//************************************************************************* +//************************************************************************* +//** ** +//** (C)Copyright 1985-2010, American Megatrends, Inc. ** +//** ** +//** All Rights Reserved. ** +//** ** +//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +//** ** +//** Phone: (770)-246-8600 ** +//** ** +//************************************************************************* +//*************************************************************************
\ No newline at end of file |