summaryrefslogtreecommitdiff
path: root/Core/EM/Nvme/NvmeInt13
diff options
context:
space:
mode:
authorraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
committerraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
commitb7c51c9cf4864df6aabb99a1ae843becd577237c (patch)
treeeebe9b0d0ca03062955223097e57da84dd618b9a /Core/EM/Nvme/NvmeInt13
downloadzprj-master.tar.xz
init. 1AQQW051HEADmaster
Diffstat (limited to 'Core/EM/Nvme/NvmeInt13')
-rw-r--r--Core/EM/Nvme/NvmeInt13/NvmeInt13.c474
-rw-r--r--Core/EM/Nvme/NvmeInt13/NvmeInt13.cif16
-rw-r--r--Core/EM/Nvme/NvmeInt13/NvmeInt13.dxs71
-rw-r--r--Core/EM/Nvme/NvmeInt13/NvmeInt13.h161
-rw-r--r--Core/EM/Nvme/NvmeInt13/NvmeInt13.inf5
-rw-r--r--Core/EM/Nvme/NvmeInt13/NvmeInt13.mak84
-rw-r--r--Core/EM/Nvme/NvmeInt13/NvmeInt13.sdl48
7 files changed, 859 insertions, 0 deletions
diff --git a/Core/EM/Nvme/NvmeInt13/NvmeInt13.c b/Core/EM/Nvme/NvmeInt13/NvmeInt13.c
new file mode 100644
index 0000000..b58c1f0
--- /dev/null
+++ b/Core/EM/Nvme/NvmeInt13/NvmeInt13.c
@@ -0,0 +1,474 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2014, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/NVMe/NvmeInt13/NvmeInt13.c 2 2/02/16 1:31a Karthikar $
+//
+// $Revision: 2 $
+//
+// $Date: 2/02/16 1:31a $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/NVMe/NvmeInt13/NvmeInt13.c $
+//
+// 2 2/02/16 1:31a Karthikar
+// [TAG] EIP254245
+// [Category] Bug Fix
+// [Symptom] Static code analysis issues found in Aptio4 Nvme module
+// [RootCause] In for loop comma operator is used instead of && for
+// mutiple test conditions.
+// [Solution] Replaced comma operator with &&.
+// [Files] NvmeInt13.c
+//
+// 1 9/04/14 7:56a Anandakrishnanl
+// [TAG] EIP180861
+// [Category] Improvement
+// [Description] Legacy Boot support in Aptio 4.x Nvme driver
+// [Files] NvmeInt13.cif
+// NvmeInt13.c
+// NvmeInt13.h
+// NvmeInt13.sdl
+// NvmeInt13.mak
+// NvmeInt13.inf
+// NvmeInt13.dxs
+//
+//**********************************************************************
+//**********************************************************************
+//<AMI_FHDR_START>
+//
+// Name: NvmeInt13.c
+//
+// Description: Nvme Driver for Legacy Mode. It installs the Int13
+// support for the Nvme devices
+//
+//<AMI_FHDR_END>
+//**********************************************************************
+
+#include "Token.h"
+#include "AmiDxeLib.h"
+#include "NvmeInt13.h"
+#include <Protocol/ComponentName.h>
+#include <Protocol/LegacyBiosExt.h>
+#include <Protocol/LegacyBios.h>
+#include <Protocol/PciIo.h>
+#include <Protocol/BlockIo.h>
+
+EFI_LEGACY_BIOS_EXT_PROTOCOL *gBiosExtensions = NULL;
+NVME_INT13_DATA *gNvmeInt13BinData = NULL;
+AMI_NVME_LEGACY_PROTOCOL gNvmeLegacyProtocol;
+
+static EFI_GUID gAmiNvmeLegacyProtocolGuid = AMI_NVME_LEGACY_PROTOCOL_GUID;
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: NvmeInt13EntryPoint
+//
+// Description: NVMe INT13 driver entry point. Installs call back
+// notification on gAmiNvmeLegacyProtocolGuid installation.
+//
+// Input:
+// IN EFI_HANDLE ImageHandle,
+// IN EFI_SYSTEM_TABLE *SystemTable
+//
+// Output:
+// EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes: None
+//
+//
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+NvmeInt13EntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+)
+{
+ EFI_STATUS Status;
+ EFI_HANDLE NvmeInt13Handle=NULL;
+
+ InitAmiLib(ImageHandle, SystemTable);
+
+ Status = InitInt13RuntimeImage();
+ if (EFI_ERROR(Status)) {
+ return Status;
+ }
+
+ gNvmeLegacyProtocol.AddNvmeLegacyDevice = NvmeInstallLegacyDevice;
+
+ Status = pBS->InstallProtocolInterface (
+ &NvmeInt13Handle,
+ &gAmiNvmeLegacyProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &gNvmeLegacyProtocol
+ );
+
+ return Status;
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: InitInt13RuntimeImage
+//
+// Description: Initialization of data structures and placement of runtime
+//
+// Input:
+// NONE
+//
+// Output:
+// EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes: None
+//
+//
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+InitInt13RuntimeImage()
+{
+ EFI_STATUS Status;
+ VOID *Image;
+ UINTN ImageSize = 0;
+
+
+ //
+ // Get the NVMe INT13 runtime image
+ //
+ Status = pBS->LocateProtocol(
+ &gEfiLegacyBiosExtProtocolGuid, NULL, &gBiosExtensions);
+ if (EFI_ERROR(Status)) return Status;
+
+ Status = gBiosExtensions->GetEmbeddedRom(
+ CSM16_MODULEID, CSM16_VENDORID, CSM16_NVME_RT_DID, &Image, &ImageSize);
+ if (EFI_ERROR(Status)) return Status;
+
+ //
+ // Do the necessary RT data initialization here using Image before it is shadowed
+ //..............................
+ {
+#pragma pack(push, 1)
+ // Update NVMe SMI information
+ typedef struct _NVME_SMM_RTS {
+ UINT8 MiscInfo;
+ UINT16 SmmAttr;
+ UINT32 SmmPort;
+ UINT32 SmmData;
+ } NVME_SMM_RTS;
+
+ static NVME_SMM_RTS NvmeSmmRt = {1, 0, SW_SMI_IO_ADDRESS, NVME_SWSMI};
+
+ *(NVME_SMM_RTS*)((UINTN)Image + ((NVME_INT13_DATA*)Image)->NvmeSmmDataOffset) = NvmeSmmRt;
+#pragma pack(pop)
+ }
+
+ // Copy image to shadow E000/F000 area
+ (UINTN)gNvmeInt13BinData = gBiosExtensions->CopyLegacyTable(Image, (UINT16)ImageSize, 0x10, 2);
+
+ TRACE((-1, "gNvmeInt13BinData : %lX\n", gNvmeInt13BinData));
+
+ return EFI_SUCCESS;
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: CreateDeviceName
+//
+// Description: This function retrieves NVMe device name, copies it into
+// lower memory and returns a pointer to the string
+//
+// Input:
+// UINT8 DevIndex,
+// UINT8 *DevNameStringSrc,
+// UINT16 *StringDestinationSegment,
+// UINT16 *StringDestinationOffset,
+// UINT16 *MfgStringDestinationSegment,
+// UINT16 *MfgStringDestinationOffset
+//
+// Output:
+// EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes: None
+//
+//
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+CreateDeviceName (
+ UINT8 DevIndex,
+ UINT8 *DevNameStringSrc,
+ UINT16 *StringDestinationSegment,
+ UINT16 *StringDestinationOffset,
+ UINT16 *MfgStringDestinationSegment,
+ UINT16 *MfgStringDestinationOffset
+)
+{
+ UINT8 *DevName = (gNvmeInt13BinData->NvmeMassI13Dev)[DevIndex].DeviceNameString;
+ UINT8 i;
+
+ //
+ // Copy the string, compact it on the way (no more that one ' ' in a row)
+ //
+ for (i=0; i<31 && *DevNameStringSrc != 0; i++, DevNameStringSrc++)
+ {
+ if ((*DevNameStringSrc == 0x20) && (*(DevNameStringSrc-1) == 0x20)) continue;
+ *DevName++ = *DevNameStringSrc; // DevNameStringSrc incremented unconditionally
+ }
+ *DevName = 0; // string terminator
+
+ DevName = (gNvmeInt13BinData->NvmeMassI13Dev)[DevIndex].DeviceNameString;
+
+ *StringDestinationSegment = (UINT16)(((UINTN)DevName & 0xf0000) >> 4);
+ *StringDestinationOffset = (UINT16)((UINTN)DevName & 0xffff);
+
+ *MfgStringDestinationSegment = (UINT16)(((UINTN)gNvmeInt13BinData->MfgGenericName & 0xf0000) >> 4);
+ *MfgStringDestinationOffset = (UINT16)((UINTN)gNvmeInt13BinData->MfgGenericName & 0xffff);
+
+ return EFI_SUCCESS;
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: CreateBbsEntry
+//
+// Description: This function takes the device index within NVMEMASS_INT13_DEV
+// list and prepares BBS entry for this device
+//
+// Input:
+// UINT8 DevIndex,
+// IN NVME_LEGACY_MASS_DEVICE *NvmeLegacyMassDevice,
+// OUT BBS_TABLE *BbsEntry
+//
+// Output:
+// EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes: None
+//
+//
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+CreateBbsEntry (
+ UINT8 DevIndex,
+ IN NVME_LEGACY_MASS_DEVICE *NvmeLegacyMassDevice,
+ OUT BBS_TABLE *BbsEntry
+)
+{
+ EFI_STATUS Status;
+ UINT8 Handle;
+ UINT8 DevAndSysType;
+ UINT8 BaidDeviceType;
+ BBS_STATUS_FLAGS StatusFlags;
+
+ ASSERT(DevIndex < NVMEDEVS_MAX_ENTRIES);
+
+ if (gBiosExtensions == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ pBS->SetMem(BbsEntry, sizeof(BBS_TABLE), 0);
+
+ //
+ // Get the HC PCI location
+ //
+ BbsEntry->Bus = (UINT32)(NvmeLegacyMassDevice->PciBDF >> 8);
+ BbsEntry->Device = (UINT32)((NvmeLegacyMassDevice->PciBDF & 0xFF) >> 3);
+ BbsEntry->Function = (UINT32)(NvmeLegacyMassDevice->PciBDF & 7);
+
+ //
+ // Update class/subclass information
+ //
+ BbsEntry->Class = PCI_CLASS_MASS_STORAGE;
+ BbsEntry->SubClass = PCI_CLASS_MASS_STORAGE_SOLID_STATE;
+
+ StatusFlags.Enabled = 1; StatusFlags.MediaPresent = 1;
+ BbsEntry->StatusFlags = StatusFlags; // Enabled, Unknown media
+
+ //
+ // Copy the device name string into low memory at gLegacyMemoryAddress, and
+ // update the string pointer in BBS table entry
+ //
+ Status = CreateDeviceName(
+ DevIndex,
+ NvmeLegacyMassDevice->DevString,
+ &BbsEntry->DescStringSegment,
+ &BbsEntry->DescStringOffset,
+ &BbsEntry->MfgStringSegment,
+ &BbsEntry->MfgStringOffset
+ );
+ ASSERT_EFI_ERROR(Status);
+ if (EFI_ERROR(Status)) return Status;
+
+ DevAndSysType = (SYSTYPE_ATA << 4)+DEVTYPE_SYS;
+ Handle = (UINT8)NvmeLegacyMassDevice->LogicalAddress;
+
+ switch (NvmeLegacyMassDevice->StorageType) {
+
+ case NVME_MASS_DEV_HDD:
+ BbsEntry->DeviceType = BBS_HARDDISK;
+ BaidDeviceType = BAID_TYPE_HDD;
+ Handle |= 0x80;
+ BbsEntry->BootHandlerSegment = (UINT16)((UINTN)gNvmeInt13BinData >> 4);
+ BbsEntry->BootHandlerOffset = gNvmeInt13BinData->BcvOffset + DevIndex*4;
+ break;
+
+ default:
+ BbsEntry->DeviceType = BBS_UNKNOWN;
+ }
+
+ BbsEntry->InitPerReserved = ((UINT32)BaidDeviceType<<24)
+ +((UINT32)Handle<<8)
+ +(UINT32)DevAndSysType;
+
+ *(UINTN*)(&BbsEntry->IBV1) = (UINTN)NvmeLegacyMassDevice->Handle;
+
+ return EFI_SUCCESS;
+}
+
+//**********************************************************************
+//<AMI_PHDR_START>
+//
+// Procedure: NvmeInstallLegacyDevice
+//
+// Description: This API is called by NVMe bus driver. The device is added into CSM16
+// data area for legacy boot
+//
+// Input:
+// NVME_LEGACY_MASS_DEVICE *NvmeLegacyMassDevice
+//
+// Output:
+// EFI_STATUS
+//
+// Modified:
+//
+// Referrals:
+//
+// Notes: None
+//
+//
+//<AMI_PHDR_END>
+//**********************************************************************
+EFI_STATUS
+NvmeInstallLegacyDevice (
+ NVME_LEGACY_MASS_DEVICE *NvmeLegacyMassDevice
+)
+{
+ BBS_TABLE BbsEntry;
+ EFI_STATUS Status;
+ UINT8 EntryNumber = 0xff;
+ UINT8 Index;
+ NVME_MASS_DEV_INFO *Device;
+ NVME_DEV_PCI_LOCATION *NvmePciDataOffset;
+
+ TRACE((-1, "Installing NVMe INT13 device %lx\n", NvmeLegacyMassDevice));
+
+ //
+ // See if device is already in the list, if yes - return error.
+ //
+ for (Index = 0; Index < NVMEDEVS_MAX_ENTRIES; Index++) {
+ if ((gNvmeInt13BinData->NvmeMassI13Dev)[Index].Handle == (UINT8)NvmeLegacyMassDevice->LogicalAddress) {
+ ASSERT(FALSE); // ERROR: Device already exists
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+ //
+ // Look for an empty slot in BcvLookupTable
+ //
+ for (Index=0; Index<NVMEDEVS_MAX_ENTRIES; Index++) {
+ if ((gNvmeInt13BinData->NvmeMassI13Dev)[Index].Handle == 0) {
+ break;
+ }
+ }
+
+ ASSERT(Index<NVMEDEVS_MAX_ENTRIES);
+
+ if (Index==NVMEDEVS_MAX_ENTRIES) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = gBiosExtensions->UnlockShadow(0, 0, 0, 0);
+ ASSERT_EFI_ERROR(Status);
+
+ Status = CreateBbsEntry(Index, NvmeLegacyMassDevice, &BbsEntry);
+ ASSERT_EFI_ERROR(Status);
+
+ Status = gBiosExtensions->InsertBbsEntryAt(gBiosExtensions,
+ &BbsEntry,
+ &EntryNumber);
+ ASSERT_EFI_ERROR(Status);
+
+ //
+ // Entry has been successfully added, update the lookup table
+ //
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].Handle = (UINT8)NvmeLegacyMassDevice->LogicalAddress;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].BbsEntryNo = EntryNumber;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].DevBaidType = (UINT8)(BbsEntry.InitPerReserved>>24);
+
+ //
+ // Update device geometry related information
+ //
+ Device = (NVME_MASS_DEV_INFO*)NvmeLegacyMassDevice->DevInfo;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].NumHeads = Device->bNonLBAHeads;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].LBANumHeads = Device->bHeads;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].NumCylinders = Device->wNonLBACylinders;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].LBANumCyls = Device->wCylinders;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].NumSectors = Device->bNonLBASectors;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].LBANumSectors = Device->bSectors;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].BytesPerSector = Device->wBlockSize;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].LastLBA = Device->dMaxLba;
+ (gNvmeInt13BinData->NvmeMassI13Dev)[Index].BpbMediaDesc = 0;
+
+ // Update PCI Bus#
+ NvmePciDataOffset = (NVME_DEV_PCI_LOCATION *)((UINTN)gNvmeInt13BinData + gNvmeInt13BinData->NvmePciDataOffset);
+ NvmePciDataOffset[Index].Handle = (UINT8)NvmeLegacyMassDevice->LogicalAddress;
+ NvmePciDataOffset[Index].PciBDF = NvmeLegacyMassDevice->PciBDF;
+
+ Status = gBiosExtensions->LockShadow(0, 0);
+ ASSERT_EFI_ERROR(Status);
+
+ return EFI_SUCCESS;
+}
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2014, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/Nvme/NvmeInt13/NvmeInt13.cif b/Core/EM/Nvme/NvmeInt13/NvmeInt13.cif
new file mode 100644
index 0000000..e2c2bb6
--- /dev/null
+++ b/Core/EM/Nvme/NvmeInt13/NvmeInt13.cif
@@ -0,0 +1,16 @@
+<component>
+ name = "Nvme Int13"
+ category = ModulePart
+ LocalRoot = "Core\EM\Nvme\NvmeInt13\"
+ RefName = "NVMEINT13"
+
+[files]
+"NvmeInt13.c"
+"NvmeInt13.h"
+"NvmeInt13.sdl"
+"NvmeInt13.mak"
+"NvmeInt13.inf"
+"NvmeInt13.dxs"
+[parts]
+"NVME_I13_BINARY"
+<endComponent>
diff --git a/Core/EM/Nvme/NvmeInt13/NvmeInt13.dxs b/Core/EM/Nvme/NvmeInt13/NvmeInt13.dxs
new file mode 100644
index 0000000..ae03d50
--- /dev/null
+++ b/Core/EM/Nvme/NvmeInt13/NvmeInt13.dxs
@@ -0,0 +1,71 @@
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2014, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/NVMe/NvmeInt13/NvmeInt13.dxs 1 9/04/14 7:56a Anandakrishnanl $
+//
+// $Revision: 1 $
+//
+// $Date: 9/04/14 7:56a $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/NVMe/NvmeInt13/NvmeInt13.dxs $
+//
+// 1 9/04/14 7:56a Anandakrishnanl
+// [TAG] EIP180861
+// [Category] Improvement
+// [Description] Legacy Boot support in Aptio 4.x Nvme driver
+// [Files] NvmeInt13.cif
+// NvmeInt13.c
+// NvmeInt13.h
+// NvmeInt13.sdl
+// NvmeInt13.mak
+// NvmeInt13.inf
+// NvmeInt13.dxs
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//
+// Name: NvmeInt13.dxs
+//
+// Description: This file is the dependency file for the NvmeInt13 driver
+//
+//<AMI_FHDR_END>
+//**********************************************************************
+#include "token.h"
+#ifdef CSM_SUPPORT
+#include <Protocol\LegacyBiosExt.h>
+#include <Protocol/LegacyBios.h>
+#endif
+
+DEPENDENCY_START
+#if CSM_SUPPORT
+ EFI_LEGACY_BIOS_EXT_PROTOCOL_GUID AND
+ EFI_LEGACY_BIOS_PROTOCOL_GUID
+#endif
+DEPENDENCY_END
+
+//****************************************************************************
+//****************************************************************************
+//** **
+//** (C)Copyright 1985-2011, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Pkwy, Norcross, GA 30093 **
+//** **
+//** Phone (770)-246-8600 **
+//** **
+//****************************************************************************
+//****************************************************************************
diff --git a/Core/EM/Nvme/NvmeInt13/NvmeInt13.h b/Core/EM/Nvme/NvmeInt13/NvmeInt13.h
new file mode 100644
index 0000000..c8d48a0
--- /dev/null
+++ b/Core/EM/Nvme/NvmeInt13/NvmeInt13.h
@@ -0,0 +1,161 @@
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2014, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/NVMe/NvmeInt13/NvmeInt13.h 1 9/04/14 7:56a Anandakrishnanl $
+//
+// $Revision: 1 $
+//
+// $Date: 9/04/14 7:56a $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/NVMe/NvmeInt13/NvmeInt13.h $
+//
+// 1 9/04/14 7:56a Anandakrishnanl
+// [TAG] EIP180861
+// [Category] Improvement
+// [Description] Legacy Boot support in Aptio 4.x Nvme driver
+// [Files] NvmeInt13.cif
+// NvmeInt13.c
+// NvmeInt13.h
+// NvmeInt13.sdl
+// NvmeInt13.mak
+// NvmeInt13.inf
+// NvmeInt13.dxs
+//
+//**********************************************************************
+//**********************************************************************
+//<AMI_FHDR_START>
+//
+// Name: NvmeInt13.h
+//
+// Description: Definitions and structures for NVMe INT13
+//
+//<AMI_FHDR_END>
+//**********************************************************************
+
+#ifndef __NVMEI13_H__
+#define __NVMEI13_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <Efi.h>
+#include <Protocol/AmiNvmeLegacy.h>
+#include "NvmeBus.h"
+
+#define BAID_TYPE_HDD 1
+#define BAID_TYPE_RMD_HDD 2
+#define BAID_TYPE_CDROM 3
+#define BAID_TYPE_RMD_FDD 4
+#define BAID_TYPE_FDD 5
+
+#define CSM16_NVME_RT_DID 5
+
+#define SYSTYPE_ATA 0
+#define DEVTYPE_SYS 1
+
+// Values for Mass Storage Device type
+//-------------------------------------
+#define NVME_MASS_DEV_HDD 1
+#define MAX_NVME_DEVICES 16
+#define NVMEDEVS_MAX_ENTRIES 8
+
+#pragma pack(1)
+
+typedef struct _NVME_MASS_DEV_INFO{
+ UINT16 wBlockSize;
+ UINT64 dMaxLba;
+ UINT8 bHeads;
+ UINT8 bSectors;
+ UINT16 wCylinders;
+ UINT8 bNonLBAHeads;
+ UINT8 bNonLBASectors;
+ UINT16 wNonLBACylinders;
+} NVME_MASS_DEV_INFO;
+
+struct _NVME_LEGACY_MASS_DEVICE {
+ VOID *DevInfo;
+ UINT16 LogicalAddress;
+ EFI_HANDLE Handle;
+ UINT16 PciBDF;
+ UINT8 *DevString;
+ UINT8 StorageType;
+};
+
+typedef struct {
+ UINT8 Handle;
+ UINT16 PciBDF;
+} NVME_DEV_PCI_LOCATION;
+
+
+typedef struct {
+ UINT8 Handle;
+ UINT8 BbsEntryNo;
+ UINT8 DevBaidType;
+ UINT8 NumHeads;
+ UINT8 LBANumHeads;
+ UINT16 NumCylinders;
+ UINT16 LBANumCyls;
+ UINT8 NumSectors;
+ UINT8 LBANumSectors;
+ UINT16 BytesPerSector;
+ UINT8 MediaType;
+ UINT64 LastLBA;
+ UINT8 BpbMediaDesc;
+ UINT8 DeviceNameString[32];
+} NVMEMASS_INT13_DEV;
+
+//
+// The following data structure is located in NvmeI13.BIN
+//
+typedef struct {
+ NVMEMASS_INT13_DEV NvmeMassI13Dev[NVMEDEVS_MAX_ENTRIES];
+ UINT8 MfgGenericName[13]; // "NVME Storage", 0
+ UINT16 BcvOffset;
+ UINT16 NvmeSmmDataOffset;
+ UINT16 NvmePciDataOffset;
+} NVME_INT13_DATA;
+
+#pragma pack()
+
+EFI_STATUS
+NvmeInstallLegacyDevice (
+ NVME_LEGACY_MASS_DEVICE *NvmeLegacyMassDevice
+);
+
+EFI_STATUS
+InitInt13RuntimeImage();
+
+/****** DO NOT WRITE BELOW THIS LINE *******/
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+//**********************************************************************
+//**********************************************************************
+//** **
+//** (C)Copyright 1985-2014, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//**********************************************************************
+//**********************************************************************
diff --git a/Core/EM/Nvme/NvmeInt13/NvmeInt13.inf b/Core/EM/Nvme/NvmeInt13/NvmeInt13.inf
new file mode 100644
index 0000000..3a75d3d
--- /dev/null
+++ b/Core/EM/Nvme/NvmeInt13/NvmeInt13.inf
@@ -0,0 +1,5 @@
+[MODULE]
+ModuleID = 1
+VendorID = 0
+DeviceID = 5
+File = Addon\NvmeI13.BIN
diff --git a/Core/EM/Nvme/NvmeInt13/NvmeInt13.mak b/Core/EM/Nvme/NvmeInt13/NvmeInt13.mak
new file mode 100644
index 0000000..54c9372
--- /dev/null
+++ b/Core/EM/Nvme/NvmeInt13/NvmeInt13.mak
@@ -0,0 +1,84 @@
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2014, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
+#**********************************************************************
+# $Header: /Alaska/SOURCE/Modules/NVMe/NvmeInt13/NvmeInt13.mak 1 9/04/14 7:56a Anandakrishnanl $
+#
+# $Revision: 1 $
+#
+# $Date: 9/04/14 7:56a $
+#**********************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/NVMe/NvmeInt13/NvmeInt13.mak $
+#
+# 1 9/04/14 7:56a Anandakrishnanl
+# [TAG] EIP180861
+# [Category] Improvement
+# [Description] Legacy Boot support in Aptio 4.x Nvme driver
+# [Files] NvmeInt13.cif
+# NvmeInt13.c
+# NvmeInt13.h
+# NvmeInt13.sdl
+# NvmeInt13.mak
+# NvmeInt13.inf
+# NvmeInt13.dxs
+#
+#**********************************************************************
+#**********************************************************************
+#<AMI_FHDR_START>
+#
+# Name: NvmeInt13.mak
+#
+# Description: Make file for NvmeInt13
+#
+#<AMI_FHDR_END>
+#**********************************************************************
+
+all: NVMEINT13
+
+$(BUILD_DIR)\NvmeInt13.mak: $(NVME_INT13_DIR)\NvmeInt13.cif $(NVME_INT13_DIR)\$(@B).mak $(BUILD_RULES)
+ $(CIF2MAK) $(CIF2MAK_DEFAULTS) $(NVME_INT13_DIR)\NvmeInt13.cif
+
+NVMEINT13: $(BUILD_DIR)\NvmeInt13.mak NVMEINT13BIN
+
+NVME_INT13_INCLUDES=\
+ /I$(NVME_DIR)\
+
+NVME_OBJECTS = \
+$(BUILD_DIR)\$(NVME_INT13_DIR)\NvmeInt13.obj \
+
+NVMEINT13BIN: $(AMIDXELIB)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\NvmeInt13.mak all\
+ GUID=C9A6DE36-FDFF-4FAF-8343-85D9E3470F43\
+ "OBJECTS=$(NVME_OBJECTS)"\
+ "MY_INCLUDES=$(NVME_INT13_INCLUDES)"\
+ ENTRY_POINT=NvmeInt13EntryPoint\
+ TYPE=BS_DRIVER\
+ COMPRESS=1\
+ DEPEX1=$(NVME_INT13_DIR)\NvmeInt13.dxs \
+
+#**********************************************************************
+#**********************************************************************
+#** **
+#** (C)Copyright 1985-2014, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#**********************************************************************
+#**********************************************************************
diff --git a/Core/EM/Nvme/NvmeInt13/NvmeInt13.sdl b/Core/EM/Nvme/NvmeInt13/NvmeInt13.sdl
new file mode 100644
index 0000000..b4c6cb1
--- /dev/null
+++ b/Core/EM/Nvme/NvmeInt13/NvmeInt13.sdl
@@ -0,0 +1,48 @@
+TOKEN
+ Name = "NVMEINT13_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable Sdio Int13 support in the project."
+ TokenType = Boolean
+ TargetMAK = Yes
+ TargetH = Yes
+ Master = Yes
+ Token = "CSM_SUPPORT" "=" "1"
+End
+
+PATH
+ Name = "NVME_INT13_DIR"
+ Path = "Core\EM\Nvme\NvmeInt13"
+End
+
+MODULE
+ Help = "Includes NvmeInt13.mak"
+ File = "NvmeInt13.mak"
+End
+
+TOKEN
+ Name = "NVME_SWSMI"
+ Value = "0x42"
+ Help = "Data to be written to SW SMI port to invoke NVME SW SMI handler."
+ TokenType = Integer
+ TargetH = Yes
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\NvmeInt13.ffs"
+ Parent = "FV_MAIN"
+ InvokeOrder = AfterParent
+End
+
+
+TOKEN
+ Name = "NVMEI13_BIN"
+ Value = "addon\NvmeI13.bin"
+ TokenType = Expression
+ TargetMAK = Yes
+End
+
+ELINK
+ Name = "$(NVME_INT13_DIR)\NvmeInt13.inf"
+ Parent = "CSM_CUSTOM_INFS"
+ InvokeOrder = AfterParent
+End