TianoCore EDK2 master
Loading...
Searching...
No Matches
SdBlockIo.c File Reference
#include "SdDxe.h"

Go to the source code of this file.

Functions

VOID EFIAPI AsyncIoCallback (IN EFI_EVENT Event, IN VOID *Context)
 
EFI_STATUS SdSetRca (IN SD_DEVICE *Device, OUT UINT16 *Rca)
 
EFI_STATUS SdSelect (IN SD_DEVICE *Device, IN UINT16 Rca)
 
EFI_STATUS SdSendStatus (IN SD_DEVICE *Device, IN UINT16 Rca, OUT UINT32 *DevStatus)
 
EFI_STATUS SdGetCsd (IN SD_DEVICE *Device, IN UINT16 Rca, OUT SD_CSD *Csd)
 
EFI_STATUS SdGetCid (IN SD_DEVICE *Device, IN UINT16 Rca, OUT SD_CID *Cid)
 
EFI_STATUS SdRwSingleBlock (IN SD_DEVICE *Device, IN EFI_LBA Lba, IN VOID *Buffer, IN UINTN BufferSize, IN BOOLEAN IsRead, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
 
EFI_STATUS SdRwMultiBlocks (IN SD_DEVICE *Device, IN EFI_LBA Lba, IN VOID *Buffer, IN UINTN BufferSize, IN BOOLEAN IsRead, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
 
EFI_STATUS SdReadWrite (IN SD_DEVICE *Device, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT VOID *Buffer, IN UINTN BufferSize, IN BOOLEAN IsRead, IN OUT EFI_BLOCK_IO2_TOKEN *Token)
 
EFI_STATUS EFIAPI SdReset (IN EFI_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
 
EFI_STATUS EFIAPI SdReadBlocks (IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, OUT VOID *Buffer)
 
EFI_STATUS EFIAPI SdWriteBlocks (IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, IN VOID *Buffer)
 
EFI_STATUS EFIAPI SdFlushBlocks (IN EFI_BLOCK_IO_PROTOCOL *This)
 
EFI_STATUS EFIAPI SdResetEx (IN EFI_BLOCK_IO2_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
 
EFI_STATUS EFIAPI SdReadBlocksEx (IN EFI_BLOCK_IO2_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, OUT VOID *Buffer)
 
EFI_STATUS EFIAPI SdWriteBlocksEx (IN EFI_BLOCK_IO2_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, IN VOID *Buffer)
 
EFI_STATUS EFIAPI SdFlushBlocksEx (IN EFI_BLOCK_IO2_PROTOCOL *This, IN OUT EFI_BLOCK_IO2_TOKEN *Token)
 
EFI_STATUS SdEraseBlockStart (IN SD_DEVICE *Device, IN EFI_LBA StartLba, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
 
EFI_STATUS SdEraseBlockEnd (IN SD_DEVICE *Device, IN EFI_LBA EndLba, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
 
EFI_STATUS SdEraseBlock (IN SD_DEVICE *Device, IN EFI_BLOCK_IO2_TOKEN *Token, IN BOOLEAN IsEnd)
 
EFI_STATUS EFIAPI SdEraseBlocks (IN EFI_ERASE_BLOCK_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_ERASE_BLOCK_TOKEN *Token, IN UINTN Size)
 

Detailed Description

The helper functions for BlockIo and BlockIo2 protocol.

Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file SdBlockIo.c.

Function Documentation

◆ AsyncIoCallback()

VOID EFIAPI AsyncIoCallback ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Nonblocking I/O callback function when the event is signaled.

Parameters
[in]EventThe Event this notify function registered to.
[in]ContextPointer to the context data registered to the Event.

Definition at line 21 of file SdBlockIo.c.

◆ SdEraseBlock()

EFI_STATUS SdEraseBlock ( IN SD_DEVICE Device,
IN EFI_BLOCK_IO2_TOKEN Token,
IN BOOLEAN  IsEnd 
)

Erase specified blocks through sync or async I/O request.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[in]TokenA pointer to the token associated with the transaction.
[in]IsEndA boolean to show whether it's the last cmd in a series of cmds. This parameter is only meaningful in async I/O request.
Return values
EFI_SUCCESSThe request is executed successfully.
EFI_OUT_OF_RESOURCESThe request could not be executed due to a lack of resources.
OthersThe request could not be executed successfully.

Definition at line 1219 of file SdBlockIo.c.

◆ SdEraseBlockEnd()

EFI_STATUS SdEraseBlockEnd ( IN SD_DEVICE Device,
IN EFI_LBA  EndLba,
IN EFI_BLOCK_IO2_TOKEN Token,
IN BOOLEAN  IsEnd 
)

Set the erase end address through sync or async I/O request.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[in]EndLbaThe ending logical block address to be erased.
[in]TokenA pointer to the token associated with the transaction.
[in]IsEndA boolean to show whether it's the last cmd in a series of cmds. This parameter is only meaningful in async I/O request.
Return values
EFI_SUCCESSThe request is executed successfully.
EFI_OUT_OF_RESOURCESThe request could not be executed due to a lack of resources.
OthersThe request could not be executed successfully.

Definition at line 1115 of file SdBlockIo.c.

◆ SdEraseBlocks()

EFI_STATUS EFIAPI SdEraseBlocks ( IN EFI_ERASE_BLOCK_PROTOCOL This,
IN UINT32  MediaId,
IN EFI_LBA  Lba,
IN OUT EFI_ERASE_BLOCK_TOKEN Token,
IN UINTN  Size 
)

Erase a specified number of device blocks.

Parameters
[in]ThisIndicates a pointer to the calling context.
[in]MediaIdThe media ID that the erase request is for.
[in]LbaThe starting logical block address to be erased. The caller is responsible for erasing only legitimate locations.
[in,out]TokenA pointer to the token associated with the transaction.
[in]SizeThe size in bytes to be erased. This must be a multiple of the physical block size of the device.
Return values
EFI_SUCCESSThe erase request was queued if Event is not NULL. The data was erased correctly to the device if the Event is NULL.to the device.
EFI_WRITE_PROTECTEDThe device cannot be erased due to write protection.
EFI_DEVICE_ERRORThe device reported an error while attempting to perform the erase operation.
EFI_INVALID_PARAMETERThe erase request contains LBAs that are not valid.
EFI_NO_MEDIAThere is no media in the device.
EFI_MEDIA_CHANGEDThe MediaId is not for the current media.

Definition at line 1331 of file SdBlockIo.c.

◆ SdEraseBlockStart()

EFI_STATUS SdEraseBlockStart ( IN SD_DEVICE Device,
IN EFI_LBA  StartLba,
IN EFI_BLOCK_IO2_TOKEN Token,
IN BOOLEAN  IsEnd 
)

Set the erase start address through sync or async I/O request.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[in]StartLbaThe starting logical block address to be erased.
[in]TokenA pointer to the token associated with the transaction.
[in]IsEndA boolean to show whether it's the last cmd in a series of cmds. This parameter is only meaningful in async I/O request.
Return values
EFI_SUCCESSThe request is executed successfully.
EFI_OUT_OF_RESOURCESThe request could not be executed due to a lack of resources.
OthersThe request could not be executed successfully.

Definition at line 1010 of file SdBlockIo.c.

◆ SdFlushBlocks()

EFI_STATUS EFIAPI SdFlushBlocks ( IN EFI_BLOCK_IO_PROTOCOL This)

Flush the Block Device.

Parameters
ThisIndicates a pointer to the calling context.
Return values
EFI_SUCCESSAll outstanding data was written to the device
EFI_DEVICE_ERRORThe device reported an error while writing back the data
EFI_NO_MEDIAThere is no media in the device.

Definition at line 817 of file SdBlockIo.c.

◆ SdFlushBlocksEx()

EFI_STATUS EFIAPI SdFlushBlocksEx ( IN EFI_BLOCK_IO2_PROTOCOL This,
IN OUT EFI_BLOCK_IO2_TOKEN Token 
)

Flush the Block Device.

Parameters
[in]ThisIndicates a pointer to the calling context.
[in,out]TokenA pointer to the token associated with the transaction.
Return values
EFI_SUCCESSAll outstanding data was written to the device
EFI_DEVICE_ERRORThe device reported an error while writing back the data
EFI_NO_MEDIAThere is no media in the device.

Definition at line 979 of file SdBlockIo.c.

◆ SdGetCid()

EFI_STATUS SdGetCid ( IN SD_DEVICE Device,
IN UINT16  Rca,
OUT SD_CID Cid 
)

Send command SEND_CID to the device to get the CID register data.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[in]RcaThe relative device address to use.
[out]CidThe buffer to store the SD_CID register data.
Return values
EFI_SUCCESSThe request is executed successfully.
EFI_OUT_OF_RESOURCESThe request could not be executed due to a lack of resources.
OthersThe request could not be executed successfully.

Definition at line 258 of file SdBlockIo.c.

◆ SdGetCsd()

EFI_STATUS SdGetCsd ( IN SD_DEVICE Device,
IN UINT16  Rca,
OUT SD_CSD Csd 
)

Send command SEND_CSD to the device to get the CSD register data.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[in]RcaThe relative device address to use.
[out]CsdThe buffer to store the SD_CSD register data.
Return values
EFI_SUCCESSThe request is executed successfully.
EFI_OUT_OF_RESOURCESThe request could not be executed due to a lack of resources.
OthersThe request could not be executed successfully.

Definition at line 205 of file SdBlockIo.c.

◆ SdReadBlocks()

EFI_STATUS EFIAPI SdReadBlocks ( IN EFI_BLOCK_IO_PROTOCOL This,
IN UINT32  MediaId,
IN EFI_LBA  Lba,
IN UINTN  BufferSize,
OUT VOID *  Buffer 
)

Read BufferSize bytes from Lba into Buffer.

Parameters
ThisIndicates a pointer to the calling context.
MediaIdId of the media, changes every time the media is replaced.
LbaThe starting Logical Block Address to read from
BufferSizeSize of Buffer, must be a multiple of device block size.
BufferA pointer to the destination buffer for the data. The caller is responsible for either having implicit or explicit ownership of the buffer.
Return values
EFI_SUCCESSThe data was read correctly from the device.
EFI_DEVICE_ERRORThe device reported an error while performing the read.
EFI_NO_MEDIAThere is no media in the device.
EFI_MEDIA_CHANGEDThe MediaId does not match the current device.
EFI_BAD_BUFFER_SIZEThe Buffer was not a multiple of the block size of the device.
EFI_INVALID_PARAMETERThe read request contains LBAs that are not valid, or the buffer is not on proper alignment.

Definition at line 749 of file SdBlockIo.c.

◆ SdReadBlocksEx()

EFI_STATUS EFIAPI SdReadBlocksEx ( IN EFI_BLOCK_IO2_PROTOCOL This,
IN UINT32  MediaId,
IN EFI_LBA  Lba,
IN OUT EFI_BLOCK_IO2_TOKEN Token,
IN UINTN  BufferSize,
OUT VOID *  Buffer 
)

Read BufferSize bytes from Lba into Buffer.

Parameters
[in]ThisIndicates a pointer to the calling context.
[in]MediaIdId of the media, changes every time the media is replaced.
[in]LbaThe starting Logical Block Address to read from.
[in,out]TokenA pointer to the token associated with the transaction.
[in]BufferSizeSize of Buffer, must be a multiple of device block size.
[out]BufferA pointer to the destination buffer for the data. The caller is responsible for either having implicit or explicit ownership of the buffer.
Return values
EFI_SUCCESSThe read request was queued if Event is not NULL. The data was read correctly from the device if the Event is NULL.
EFI_DEVICE_ERRORThe device reported an error while performing the read.
EFI_NO_MEDIAThere is no media in the device.
EFI_MEDIA_CHANGEDThe MediaId is not for the current media.
EFI_BAD_BUFFER_SIZEThe BufferSize parameter is not a multiple of the intrinsic block size of the device.
EFI_INVALID_PARAMETERThe read request contains LBAs that are not valid, or the buffer is not on proper alignment.
EFI_OUT_OF_RESOURCESThe request could not be completed due to a lack of resources.

Definition at line 906 of file SdBlockIo.c.

◆ SdReadWrite()

EFI_STATUS SdReadWrite ( IN SD_DEVICE Device,
IN UINT32  MediaId,
IN EFI_LBA  Lba,
IN OUT VOID *  Buffer,
IN UINTN  BufferSize,
IN BOOLEAN  IsRead,
IN OUT EFI_BLOCK_IO2_TOKEN Token 
)

This function transfers data from/to the sd memory card device.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[in]MediaIdThe media ID that the read/write request is for.
[in]LbaThe starting logical block address to be read/written. The caller is responsible for reading/writing to only legitimate locations.
[in,out]BufferA pointer to the destination/source buffer for the data.
[in]BufferSizeSize of Buffer, must be a multiple of device block size.
[in]IsReadIndicates it is a read or write operation.
[in,out]TokenA pointer to the token associated with the transaction.
Return values
EFI_SUCCESSThe data was read/written correctly to the device.
EFI_WRITE_PROTECTEDThe device can not be read/written to.
EFI_DEVICE_ERRORThe device reported an error while performing the read/write.
EFI_NO_MEDIAThere is no media in the device.
EFI_MEDIA_CHANGEDThe MediaId does not match the current device.
EFI_BAD_BUFFER_SIZEThe Buffer was not a multiple of the block size of the device.
EFI_INVALID_PARAMETERThe read/write request contains LBAs that are not valid, or the buffer is not on proper alignment.

Definition at line 587 of file SdBlockIo.c.

◆ SdReset()

EFI_STATUS EFIAPI SdReset ( IN EFI_BLOCK_IO_PROTOCOL This,
IN BOOLEAN  ExtendedVerification 
)

Reset the Block Device.

Parameters
ThisIndicates a pointer to the calling context.
ExtendedVerificationDriver may perform diagnostics on reset.
Return values
EFI_SUCCESSThe device was reset.
EFI_DEVICE_ERRORThe device is not functioning properly and could not be reset.

Definition at line 708 of file SdBlockIo.c.

◆ SdResetEx()

EFI_STATUS EFIAPI SdResetEx ( IN EFI_BLOCK_IO2_PROTOCOL This,
IN BOOLEAN  ExtendedVerification 
)

Reset the Block Device.

Parameters
[in]ThisIndicates a pointer to the calling context.
[in]ExtendedVerificationDriver may perform diagnostics on reset.
Return values
EFI_SUCCESSThe device was reset.
EFI_DEVICE_ERRORThe device is not functioning properly and could not be reset.

Definition at line 840 of file SdBlockIo.c.

◆ SdRwMultiBlocks()

EFI_STATUS SdRwMultiBlocks ( IN SD_DEVICE Device,
IN EFI_LBA  Lba,
IN VOID *  Buffer,
IN UINTN  BufferSize,
IN BOOLEAN  IsRead,
IN EFI_BLOCK_IO2_TOKEN Token,
IN BOOLEAN  IsEnd 
)

Read/write multiple blocks through sync or async I/O request.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[in]LbaThe starting logical block address to be read/written. The caller is responsible for reading/writing to only legitimate locations.
[in]BufferA pointer to the destination/source buffer for the data.
[in]BufferSizeSize of Buffer, must be a multiple of device block size.
[in]IsReadIndicates it is a read or write operation.
[in]TokenA pointer to the token associated with the transaction.
[in]IsEndA boolean to show whether it's the last cmd in a series of cmds. This parameter is only meaningful in async I/O request.
Return values
EFI_SUCCESSThe request is executed successfully.
EFI_OUT_OF_RESOURCESThe request could not be executed due to a lack of resources.
OthersThe request could not be executed successfully.

Definition at line 450 of file SdBlockIo.c.

◆ SdRwSingleBlock()

EFI_STATUS SdRwSingleBlock ( IN SD_DEVICE Device,
IN EFI_LBA  Lba,
IN VOID *  Buffer,
IN UINTN  BufferSize,
IN BOOLEAN  IsRead,
IN EFI_BLOCK_IO2_TOKEN Token,
IN BOOLEAN  IsEnd 
)

Read/write single block through sync or async I/O request.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[in]LbaThe starting logical block address to be read/written. The caller is responsible for reading/writing to only legitimate locations.
[in]BufferA pointer to the destination/source buffer for the data.
[in]BufferSizeSize of Buffer, must be a multiple of device block size.
[in]IsReadIndicates it is a read or write operation.
[in]TokenA pointer to the token associated with the transaction.
[in]IsEndA boolean to show whether it's the last cmd in a series of cmds. This parameter is only meaningful in async I/O request.
Return values
EFI_SUCCESSThe request is executed successfully.
EFI_OUT_OF_RESOURCESThe request could not be executed due to a lack of resources.
OthersThe request could not be executed successfully.

Definition at line 318 of file SdBlockIo.c.

◆ SdSelect()

EFI_STATUS SdSelect ( IN SD_DEVICE Device,
IN UINT16  Rca 
)

Send command SELECT to the device to select/deselect the device.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[in]RcaThe relative device address to use.
Return values
EFI_SUCCESSThe request is executed successfully.
EFI_OUT_OF_RESOURCESThe request could not be executed due to a lack of resources.
OthersThe request could not be executed successfully.

Definition at line 112 of file SdBlockIo.c.

◆ SdSendStatus()

EFI_STATUS SdSendStatus ( IN SD_DEVICE Device,
IN UINT16  Rca,
OUT UINT32 *  DevStatus 
)

Send command SEND_STATUS to the device to get device status.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[in]RcaThe relative device address to use.
[out]DevStatusThe buffer to store the device status.
Return values
EFI_SUCCESSThe request is executed successfully.
EFI_OUT_OF_RESOURCESThe request could not be executed due to a lack of resources.
OthersThe request could not be executed successfully.

Definition at line 158 of file SdBlockIo.c.

◆ SdSetRca()

EFI_STATUS SdSetRca ( IN SD_DEVICE Device,
OUT UINT16 *  Rca 
)

Send command SET_RELATIVE_ADDRESS to the device to set the device address.

Parameters
[in]DeviceA pointer to the SD_DEVICE instance.
[out]RcaThe relative device address to assign.
Return values
EFI_SUCCESSThe request is executed successfully.
EFI_OUT_OF_RESOURCESThe request could not be executed due to a lack of resources.
OthersThe request could not be executed successfully.

Definition at line 67 of file SdBlockIo.c.

◆ SdWriteBlocks()

EFI_STATUS EFIAPI SdWriteBlocks ( IN EFI_BLOCK_IO_PROTOCOL This,
IN UINT32  MediaId,
IN EFI_LBA  Lba,
IN UINTN  BufferSize,
IN VOID *  Buffer 
)

Write BufferSize bytes from Lba into Buffer.

Parameters
ThisIndicates a pointer to the calling context.
MediaIdThe media ID that the write request is for.
LbaThe starting logical block address to be written. The caller is responsible for writing to only legitimate locations.
BufferSizeSize of Buffer, must be a multiple of device block size.
BufferA pointer to the source buffer for the data.
Return values
EFI_SUCCESSThe data was written correctly to the device.
EFI_WRITE_PROTECTEDThe device can not be written to.
EFI_DEVICE_ERRORThe device reported an error while performing the write.
EFI_NO_MEDIAThere is no media in the device.
EFI_MEDIA_CHANGEDThe MediaId does not match the current device.
EFI_BAD_BUFFER_SIZEThe Buffer was not a multiple of the block size of the device.
EFI_INVALID_PARAMETERThe write request contains LBAs that are not valid, or the buffer is not on proper alignment.

Definition at line 788 of file SdBlockIo.c.

◆ SdWriteBlocksEx()

EFI_STATUS EFIAPI SdWriteBlocksEx ( IN EFI_BLOCK_IO2_PROTOCOL This,
IN UINT32  MediaId,
IN EFI_LBA  Lba,
IN OUT EFI_BLOCK_IO2_TOKEN Token,
IN UINTN  BufferSize,
IN VOID *  Buffer 
)

Write BufferSize bytes from Lba into Buffer.

Parameters
[in]ThisIndicates a pointer to the calling context.
[in]MediaIdThe media ID that the write request is for.
[in]LbaThe starting logical block address to be written. The caller is responsible for writing to only legitimate locations.
[in,out]TokenA pointer to the token associated with the transaction.
[in]BufferSizeSize of Buffer, must be a multiple of device block size.
[in]BufferA pointer to the source buffer for the data.
Return values
EFI_SUCCESSThe data was written correctly to the device.
EFI_WRITE_PROTECTEDThe device can not be written to.
EFI_DEVICE_ERRORThe device reported an error while performing the write.
EFI_NO_MEDIAThere is no media in the device.
EFI_MEDIA_CHANGEDThe MediaId does not match the current device.
EFI_BAD_BUFFER_SIZEThe Buffer was not a multiple of the block size of the device.
EFI_INVALID_PARAMETERThe write request contains LBAs that are not valid, or the buffer is not on proper alignment.

Definition at line 948 of file SdBlockIo.c.