Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MdeModulePkg: Added PPI support in UFS PEI driver. #6340

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 100 additions & 21 deletions MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,13 +1082,17 @@ InitializeUfsBlockIoPeim (
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
UFS_PEIM_HC_PRIVATE_DATA *Private;
EDKII_UFS_HOST_CONTROLLER_PPI *UfsHcPpi;
UINT32 Index;
UINTN MmioBase;
UINT8 Controller;
UFS_UNIT_DESC UnitDescriptor;
EFI_STATUS Status;
UFS_PEIM_HC_PRIVATE_DATA *Private;
EDKII_UFS_HOST_CONTROLLER_PPI *UfsHcPpi;
UINT32 Index;
UINTN MmioBase;
UINT8 Controller;
UFS_UNIT_DESC UnitDescriptor;
EDKII_UFS_HC_PLATFORM_PPI *UfsHcPlatformPpi = NULL;
UFS_DEV_DESC DeviceDescriptor;
UINT8 RefClkAttr;
EDKII_UFS_CARD_REF_CLK_FREQ_ATTRIBUTE Attributes;

//
// Shadow this PEIM to run from memory
Expand All @@ -1110,6 +1114,19 @@ InitializeUfsBlockIoPeim (
return EFI_DEVICE_ERROR;
}

//
// Locate ufs host controller platform PPI
//
Status = PeiServicesLocatePpi (
&gEdkiiUfsHcPlatformPpiGuid,
0,
NULL,
(VOID **)&UfsHcPlatformPpi
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "LocatePpi gEdkiiUfsHcPlatformPpiGuid Status :%r\n", Status));
}

IoMmuInit ();

Controller = 0;
Expand Down Expand Up @@ -1145,7 +1162,7 @@ InitializeUfsBlockIoPeim (
//
// Initialize UFS Host Controller H/W.
//
Status = UfsControllerInit (Private);
Status = UfsControllerInit (UfsHcPlatformPpi, Private);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "UfsDevicePei: Host Controller Initialization Error, Status = %r\n", Status));
Controller++;
Expand Down Expand Up @@ -1174,25 +1191,87 @@ InitializeUfsBlockIoPeim (
continue;
}

//
// Check if 8 common luns are active and set corresponding bit mask.
//
for (Index = 0; Index < UFS_PEIM_MAX_LUNS; Index++) {
Status = UfsRwDeviceDesc (Private, TRUE, UfsUnitDesc, (UINT8)Index, 0, &UnitDescriptor, sizeof (UFS_UNIT_DESC));
if ((UfsHcPlatformPpi != NULL) &&
((UfsHcPlatformPpi->RefClkFreq == EdkiiUfsCardRefClkFreq19p2Mhz) ||
(UfsHcPlatformPpi->RefClkFreq == EdkiiUfsCardRefClkFreq26Mhz) ||
(UfsHcPlatformPpi->RefClkFreq == EdkiiUfsCardRefClkFreq38p4Mhz)))
{
RefClkAttr = UfsAttrRefClkFreq;
Attributes = EdkiiUfsCardRefClkFreqObsolete;

Status = UfsRwAttributes (Private, TRUE, RefClkAttr, 0, 0, (UINT32 *)&Attributes);
DEBUG ((DEBUG_INFO, "UfsRwAttributes #1 Status = %r \n", Status));
if (!EFI_ERROR (Status)) {
if (Attributes != UfsHcPlatformPpi->RefClkFreq) {
Attributes = UfsHcPlatformPpi->RefClkFreq;
DEBUG (
(DEBUG_INFO,
"Setting bRefClkFreq attribute(%x) to %x\n 0 -> 19.2 Mhz\n 1 -> 26 Mhz\n 2 -> 38.4 Mhz\n 3 -> Obsolete\n",
RefClkAttr,
Attributes)
);
Status = UfsRwAttributes (Private, FALSE, RefClkAttr, 0, 0, (UINT32 *)&Attributes);
DEBUG ((DEBUG_INFO, "UfsRwAttributes #2 Status = %r \n", Status));
if (EFI_ERROR (Status)) {
DEBUG (
(DEBUG_ERROR,
"Failed to Change Reference Clock Attribute to, Status = %r \n",
Status)
);
}
}
} else {
DEBUG (
(DEBUG_ERROR,
"Failed to Read Reference Clock Attribute, Status = %r \n",
Status)
);
}
}

if ((UfsHcPlatformPpi != NULL) && (UfsHcPlatformPpi->Callback != NULL)) {
Status = UfsHcPlatformPpi->Callback (&Private->UfsHcBase, EdkiiUfsHcPostLinkStartup);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Fail to read UFS Unit Descriptor, Index = %X, Status = %r\n", Index, Status));
DEBUG ((DEBUG_ERROR, "Failure from platform driver during EdkiiUfsHcPostLinkStartup, Status = %r\n", Status));
Controller++;
continue;
}

if (UnitDescriptor.LunEn == 0x1) {
DEBUG ((DEBUG_INFO, "Ufs %d Lun %d is enabled\n", Controller, Index));
Private->Luns.BitMask |= (BIT0 << Index);
//
// Check if 8 common luns are active and set corresponding bit mask.
//
for (Index = 0; Index < UFS_PEIM_MAX_LUNS; Index++) {
Status = UfsRwDeviceDesc (Private, TRUE, UfsUnitDesc, (UINT8)Index, 0, &UnitDescriptor, sizeof (UFS_UNIT_DESC));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Fail to read UFS Unit Descriptor, Index = %X, Status = %r\n", Index, Status));
continue;
}

if (UnitDescriptor.LunEn == 0x1) {
DEBUG ((DEBUG_INFO, "Ufs %d Lun %d is enabled\n", Controller, Index));
Private->Luns.BitMask |= (BIT0 << Index);
}
}
}

PeiServicesInstallPpi (&Private->BlkIoPpiList);
PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList);
Controller++;
//
// Get Ufs Device's Lun Info by reading Configuration Descriptor
//
Status = UfsRwDeviceDesc (Private, TRUE, UfsConfigDesc, 0, 0, &DeviceDescriptor, sizeof (UFS_DEV_DESC));
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Ufs Get Configuration Descriptor Error, Status = %r\n", Status));
Controller++;
continue;
}

if (DeviceDescriptor.SecurityLun == 0x1) {
DEBUG ((DEBUG_INFO, "UFS WLUN RPMB is supported\n"));
Private->Luns.BitMask |= BIT11;
}

PeiServicesInstallPpi (&Private->BlkIoPpiList);
PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList);
Controller++;
}
}

return EFI_SUCCESS;
Expand Down
31 changes: 30 additions & 1 deletion MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <PiPei.h>

#include <Ppi/UfsHostController.h>
#include <Ppi/UfsHostControllerPlatformPpi.h>
#include <Ppi/BlockIo.h>
#include <Ppi/BlockIo2.h>
#include <Ppi/IoMmu.h>
Expand Down Expand Up @@ -156,6 +157,33 @@ typedef struct _UFS_DEVICE_MANAGEMENT_REQUEST_PACKET {
UINT8 Ocs;
} UFS_DEVICE_MANAGEMENT_REQUEST_PACKET;

/**
Read or write specified attribute of a UFS device.

@param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.
@param[in] Read The boolean variable to show r/w direction.
@param[in] AttrId The ID of Attribute.
@param[in] Index The Index of Attribute.
@param[in] Selector The Selector of Attribute.
@param[in, out] Attributes The value of Attribute to be read or written.

@retval EFI_SUCCESS The Attribute was read/written successfully.
@retval EFI_INVALID_PARAMETER AttrId, Index and Selector are invalid combination to point to a
type of UFS device descriptor.
@retval EFI_DEVICE_ERROR A device error occurred while attempting to r/w the Attribute.
@retval EFI_TIMEOUT A timeout occurred while waiting for the completion of r/w the Attribute.

**/
EFI_STATUS
UfsRwAttributes (
IN UFS_PEIM_HC_PRIVATE_DATA *Private,
IN BOOLEAN Read,
IN UINT8 AttrId,
IN UINT8 Index,
IN UINT8 Selector,
IN OUT UINT32 *Attributes
);

/**
Sends a UFS-supported SCSI Request Packet to a UFS device that is attached to the UFS host controller.

Expand Down Expand Up @@ -193,7 +221,8 @@ UfsExecScsiCmds (
**/
EFI_STATUS
UfsControllerInit (
IN UFS_PEIM_HC_PRIVATE_DATA *Private
IN EDKII_UFS_HC_PLATFORM_PPI *UfsHcPlatformPpi,
IN UFS_PEIM_HC_PRIVATE_DATA *Private
);

/**
Expand Down
1 change: 1 addition & 0 deletions MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsBlockIoPei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
gEdkiiPeiUfsHostControllerPpiGuid ## CONSUMES
gEdkiiIoMmuPpiGuid ## CONSUMES
gEfiEndOfPeiSignalPpiGuid ## CONSUMES
gEdkiiUfsHcPlatformPpiGuid ## SOMETIMES CONSUMES

[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdUfsInitialCompletionTimeout ## CONSUMES
Expand Down
Loading
Loading