/* Refer to SD Host Controller Simplified spec 3.0 Section 3.1 for details. */
EFI_STATUS EmmcPeimHcCardDetect(IN UINTN Bar)
/* Refer to SD Host Controller Simplified spec 3.0 Section 3.1 for details. */
EFI_STATUS EmmcPeimHcCardDetect(IN UINTN Bar)
{
  EFI_STATUS  Status;
  UINT16      Data;
  UINT32      PresentState;
  Status = EmmcPeimHcRwMmio (Bar + EMMC_HC_NOR_INT_STS, TRUE, sizeof (Data), &Data);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  if ((Data & (BIT6 | BIT7)) != 0) {
    Data  &= BIT6 | BIT7;
    Status = EmmcPeimHcRwMmio (Bar + EMMC_HC_NOR_INT_STS, FALSE, sizeof (Data), &Data);
    if (EFI_ERROR (Status)) {
      return Status;
    }
  }
  Status = EmmcPeimHcRwMmio (Bar + EMMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  if ((PresentState & BIT16) != 0) {
    return EFI_SUCCESS;
  } else {
    return EFI_NO_MEDIA;
  }
}