/** Send command by using Host IO protocol @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. @param CommandIndex The command index to set the command index field of command register. @param Argument Command argument to set the argument field of command register. @param DataType TRANSFER_TYPE, indicates no data, data in or data out. @param Buffer Contains the data read from / write to the device. @param BufferSize The size of the buffer. @param ResponseType RESPONSE_TYPE. @param TimeOut Time out value in 1 ms unit. @param ResponseData Depending on the ResponseType, such as CSD or card status. @retval EFI_SUCCESS @retval EFI_INVALID_PARAMETER @retval EFI_UNSUPPORTED @retval EFI_DEVICE_ERROR **/ EFI_STATUS SendCommand ( IN CARD_DATA *CardData, IN UINT16 CommandIndex, IN UINT32 Argument, IN TRANSFER_TYPE DataType, IN UINT8 *Buffer, OPTIONAL IN UINT32 BufferSize, IN RESPONSE_TYPE ResponseType, IN UINT32 TimeOut, OUT UINT32 *ResponseData ) { EFI_STATUS Status; EFI_SD_HOST_IO_PROTOCOL *SDHostIo; SDHostIo = CardData->SDHostIo; if (CardData->CardType != MMCCard && CardData->CardType != MMCCardHighCap) { CommandIndex |= AUTO_CMD12_ENABLE; } Status = SDHostIo->SendCommand ( SDHostIo, CommandIndex, Argument, DataType, Buffer, BufferSize, ResponseType, TimeOut, ResponseData ); if (!EFI_ERROR (Status)) { if (ResponseType == ResponseR1 || ResponseType == ResponseR1b) { ASSERT(ResponseData != NULL); Status = CheckCardStatus (*ResponseData); } } else { SDHostIo->ResetSDHost (SDHostIo, Reset_DAT_CMD); } return Status; }
/** Send the card APP_CMD command with the following command indicated by CommandIndex @param CardData Pointer to CARD_DATA. @param CommandIndex The command index to set the command index field of command register. @param Argument Command argument to set the argument field of command register. @param DataType TRANSFER_TYPE, indicates no data, data in or data out. @param Buffer Contains the data read from / write to the device. @param BufferSize The size of the buffer. @param ResponseType RESPONSE_TYPE. @param TimeOut Time out value in 1 ms unit. @param ResponseData Depending on the ResponseType, such as CSD or card status. @retval EFI_SUCCESS @retval EFI_INVALID_PARAMETER @retval EFI_UNSUPPORTED @retval EFI_DEVICE_ERROR **/ EFI_STATUS SendAppCommand ( IN CARD_DATA *CardData, IN UINT16 CommandIndex, IN UINT32 Argument, IN TRANSFER_TYPE DataType, IN UINT8 *Buffer, OPTIONAL IN UINT32 BufferSize, IN RESPONSE_TYPE ResponseType, IN UINT32 TimeOut, OUT UINT32 *ResponseData ) { EFI_STATUS Status; EFI_SD_HOST_IO_PROTOCOL *SDHostIo; UINT8 Index; SDHostIo = CardData->SDHostIo; Status = EFI_SUCCESS; for (Index = 0; Index < 2; Index++) { Status = SDHostIo->SendCommand ( SDHostIo, APP_CMD, (CardData->Address << 16), NoData, NULL, 0, ResponseR1, TIMEOUT_COMMAND, (UINT32*)&(CardData->CardStatus) ); if (!EFI_ERROR (Status)) { Status = CheckCardStatus (*(UINT32*)&(CardData->CardStatus)); if (CardData->CardStatus.SAPP_CMD != 1) { Status = EFI_DEVICE_ERROR; } if (!EFI_ERROR (Status)) { break; } } else { SDHostIo->ResetSDHost (SDHostIo, Reset_Auto); } } if (EFI_ERROR (Status)) { return Status; } if (CardData->CardType != MMCCard && CardData->CardType != MMCCardHighCap) { CommandIndex |= AUTO_CMD12_ENABLE; } Status = SDHostIo->SendCommand ( SDHostIo, CommandIndex, Argument, DataType, Buffer, BufferSize, ResponseType, TimeOut, ResponseData ); if (!EFI_ERROR (Status)) { if (ResponseType == ResponseR1 || ResponseType == ResponseR1b) { ASSERT(ResponseData != NULL); Status = CheckCardStatus (*ResponseData); } } else { SDHostIo->ResetSDHost (SDHostIo, Reset_Auto); } return Status; }