QuarkSocPkg: Add new package for Quark SoC X1000

Changes for V4
==============
1) Remove Unicode character from C source file
2) Move delete of QuarkSocPkg\QuarkNorthCluster\Binary\QuarkMicrocode
   from QuarkPlatformPkg commit to QuarkSocPkg commit

Changes for V2
==============
1) Sync with new APIs in SmmCpuFeaturesLib class
2) Use new generic PCI serial driver PciSioSerialDxe in MdeModulePkg
3) Remove PCI serial driver from QuarkSocPkg
4) Apply optimizations to MtrrLib from MtrrLib in UefiCpuPkg
5) Convert all UNI files to utf-8
6) Replace tabs with spaces and remove trailing spaces
7) Add License.txt

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
Acked-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19286 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Michael Kinney
2015-12-15 19:22:23 +00:00
committed by mdkinney
parent 46ff196fde
commit 9b6bbcdbfd
176 changed files with 54761 additions and 0 deletions

View File

@@ -0,0 +1,233 @@
/** @file
UEFI Component Name(2) protocol implementation for SD controller driver.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "SDController.h"
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gSDControllerName = {
SDControllerGetDriverName,
SDControllerGetControllerName,
"eng"
};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gSDControllerName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) SDControllerGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) SDControllerGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mSDControllerDriverNameTable[] = {
{ "eng;en", L"EFI SD Host Controller Driver" },
{ NULL, NULL }
};
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 3066 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
SDControllerGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mSDControllerDriverNameTable,
DriverName,
(BOOLEAN)(This == &gSDControllerName)
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 3066 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
SDControllerGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
SDHOST_DATA *SDHostData;
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Make sure this driver is currently managing ControllerHandle
//
Status = EfiTestManagedDevice (
ControllerHandle,
gSDControllerDriverBinding.DriverBindingHandle,
&gEfiPciIoProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get the device context
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSDHostIoProtocolGuid,
(VOID **) &SDHostIo,
gSDControllerDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
SDHostData = SDHOST_DATA_FROM_THIS(SDHostIo);
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
SDHostData->ControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gSDControllerName)
);
}

View File

@@ -0,0 +1,147 @@
/** @file
This file contains the delarations for componet name routines.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _COMPONENT_NAME_H_
#define _COMPONENT_NAME_H_
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 3066 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
SDControllerGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 3066 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
SDControllerGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,322 @@
/** @file
The definition for SD host controller driver model and HC protocol routines.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _SD_CONTROLLER_H_
#define _SD_CONTROLLER_H_
#include <Uefi.h>
#include <Protocol/PciIo.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <IndustryStandard/Pci22.h>
#include "ComponentName.h"
#include "SDHostIo.h"
extern EFI_DRIVER_BINDING_PROTOCOL gSDControllerDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gSDControllerName;
extern EFI_COMPONENT_NAME2_PROTOCOL gSDControllerName2;
#define SDHOST_DATA_SIGNATURE SIGNATURE_32 ('s', 'd', 'h', 's')
#define BLOCK_SIZE 0x200
#define TIME_OUT_1S 1000
#pragma pack(1)
//
// PCI Class Code structure
//
typedef struct {
UINT8 PI;
UINT8 SubClassCode;
UINT8 BaseCode;
} PCI_CLASSC;
#pragma pack()
typedef struct {
UINTN Signature;
EFI_SD_HOST_IO_PROTOCOL SDHostIo;
EFI_PCI_IO_PROTOCOL *PciIo;
BOOLEAN IsAutoStopCmd;
UINT32 BaseClockInMHz;
UINT32 CurrentClockInKHz;
UINT32 BlockLength;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
}SDHOST_DATA;
#define SDHOST_DATA_FROM_THIS(a) \
CR(a, SDHOST_DATA, SDHostIo, SDHOST_DATA_SIGNATURE)
/**
Test to see if this driver supports ControllerHandle. Any
ControllerHandle that has SDHostIoProtocol installed will be supported.
@param This Protocol instance pointer.
@param Controller Handle of device to test.
@param RemainingDevicePath Not used.
@return EFI_SUCCESS This driver supports this device.
@return EFI_UNSUPPORTED This driver does not support this device.
**/
EFI_STATUS
EFIAPI
SDControllerSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
/**
Starting the SD Host Controller Driver.
@param This Protocol instance pointer.
@param Controller Handle of device to test.
@param RemainingDevicePath Not used.
@retval EFI_SUCCESS This driver supports this device.
@retval EFI_UNSUPPORTED This driver does not support this device.
@retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
**/
EFI_STATUS
EFIAPI
SDControllerStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
/**
Stop this driver on ControllerHandle. Support stoping any child handles
created by this driver.
@param This Protocol instance pointer.
@param Controller Handle of device to stop driver on.
@param NumberOfChildren Number of Children in the ChildHandleBuffer.
@param ChildHandleBuffer List of handles for the children we need to stop.
@return EFI_SUCCESS
@return others
**/
EFI_STATUS
EFIAPI
SDControllerStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
/**
The main function used to send the command to the card inserted into the SD host slot.
It will assemble the arguments to set the command register and wait for the command
and transfer completed until timeout. Then it will read the response register to fill
the ResponseData.
@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_OUT_OF_RESOURCES
@retval EFI_TIMEOUT
@retval EFI_DEVICE_ERROR
**/
EFI_STATUS
EFIAPI
SendCommand (
IN EFI_SD_HOST_IO_PROTOCOL *This,
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 OPTIONAL
);
/**
Set max clock frequency of the host, the actual frequency may not be the same as MaxFrequency.
It depends on the max frequency the host can support, divider, and host speed mode.
@param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
@param MaxFrequency Max frequency in HZ.
@retval EFI_SUCCESS
@retval EFI_TIMEOUT
**/
EFI_STATUS
EFIAPI
SetClockFrequency (
IN EFI_SD_HOST_IO_PROTOCOL *This,
IN UINT32 MaxFrequencyInKHz
);
/**
Set bus width of the host controller
@param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
@param BusWidth Bus width in 1, 4, 8 bits.
@retval EFI_SUCCESS
@retval EFI_INVALID_PARAMETER
**/
EFI_STATUS
EFIAPI
SetBusWidth (
IN EFI_SD_HOST_IO_PROTOCOL *This,
IN UINT32 BusWidth
);
/**
Set voltage which could supported by the host controller.
Support 0(Power off the host), 1.8V, 3.0V, 3.3V
@param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
@param Voltage Units in 0.1 V.
@retval EFI_SUCCESS
@retval EFI_INVALID_PARAMETER
**/
EFI_STATUS
EFIAPI
SetHostVoltage (
IN EFI_SD_HOST_IO_PROTOCOL *This,
IN UINT32 Voltage
);
/**
Reset the host controller.
@param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
@param ResetAll TRUE to reset all.
@retval EFI_SUCCESS
@retval EFI_TIMEOUT
**/
EFI_STATUS
EFIAPI
ResetSDHost (
IN EFI_SD_HOST_IO_PROTOCOL *This,
IN RESET_TYPE ResetType
);
/**
Enable auto stop on the host controller.
@param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
@param Enable TRUE to enable, FALSE to disable.
@retval EFI_SUCCESS
@retval EFI_TIMEOUT
**/
EFI_STATUS
EFIAPI
EnableAutoStopCmd (
IN EFI_SD_HOST_IO_PROTOCOL *This,
IN BOOLEAN Enable
);
/**
Find whether these is a card inserted into the slot. If so init the host.
If not, return EFI_NOT_FOUND.
@param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
@retval EFI_SUCCESS
@retval EFI_NOT_FOUND
**/
EFI_STATUS
EFIAPI
DetectCardAndInitHost (
IN EFI_SD_HOST_IO_PROTOCOL *This
);
/**
Set the Block length on the host controller.
@param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
@param BlockLength card supportes block length.
@retval EFI_SUCCESS
@retval EFI_TIMEOUT
**/
EFI_STATUS
EFIAPI
SetBlockLength (
IN EFI_SD_HOST_IO_PROTOCOL *This,
IN UINT32 BlockLength
);
/**
Enable/Disable High Speed transfer mode
@param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
@param Enable TRUE to Enable, FALSE to Disable
@return EFI_SUCCESS
**/
EFI_STATUS
EFIAPI
SetHighSpeedMode (
IN EFI_SD_HOST_IO_PROTOCOL *This,
IN BOOLEAN Enable
);
EFI_STATUS
EFIAPI
SetDDRMode (
IN EFI_SD_HOST_IO_PROTOCOL *This,
IN BOOLEAN Enable
);
#endif

View File

@@ -0,0 +1,62 @@
## @file
#
# Component Description File For SDControllerDxe Module.
#
# Copyright (c) 2013-2015 Intel Corporation.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = SDController
FILE_GUID = 90A330BD-6F89-4900-933A-C25EB4356348
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = InitializeSDController
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
# DRIVER_BINDING = gSDControllerDriverBinding
# COMPONENT_NAME = gSDControllerName
# COMPONENT_NAME2 = gSDControllerName2
#
[Sources]
SDController.c
SDController.h
ComponentName.c
ComponentName.h
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
QuarkSocPkg/QuarkSocPkg.dec
[LibraryClasses]
MemoryAllocationLib
BaseLib
UefiLib
UefiBootServicesTableLib
UefiDriverEntryPoint
BaseMemoryLib
DebugLib
PcdLib
[Protocols]
gEfiPciIoProtocolGuid ## TO_START
gEfiSDHostIoProtocolGuid ## BY_START
[FeaturePcd]
gEfiQuarkSCSocIdTokenSpaceGuid.PcdSdHciQuirkNoHiSpd

View File

@@ -0,0 +1,656 @@
/** @file
CEATA specific functions implementation
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "SDMediaDevice.h"
/**
Send RW_MULTIPLE_REGISTER command
@param CardData Pointer to CARD_DATA.
@param Address Register address.
@param ByteCount Buffer size.
@param Write TRUE means write, FALSE means read.
@param Buffer Buffer pointer.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
ReadWriteMultipleRegister (
IN CARD_DATA *CardData,
IN UINT16 Address,
IN UINT8 ByteCount,
IN BOOLEAN Write,
IN UINT8 *Buffer
)
{
EFI_STATUS Status;
UINT32 Argument;
Status = EFI_SUCCESS;
if ((Address % 4 != 0) || (ByteCount % 4 != 0)) {
Status = EFI_INVALID_PARAMETER;
goto Exit;
}
Argument = (Address << 16) | ByteCount;
if (Write) {
Argument |= BIT31;
}
if (Write) {
CopyMem (CardData->AlignedBuffer, Buffer, ByteCount);
Status = SendCommand (
CardData,
RW_MULTIPLE_REGISTER,
Argument,
OutData,
CardData->AlignedBuffer,
ByteCount,
ResponseR1b,
TIMEOUT_DATA,
(UINT32*)&(CardData->CardStatus)
);
} else {
Status = SendCommand (
CardData,
RW_MULTIPLE_REGISTER,
Argument,
InData,
CardData->AlignedBuffer,
ByteCount,
ResponseR1,
TIMEOUT_DATA,
(UINT32*)&(CardData->CardStatus)
);
if (!EFI_ERROR (Status)) {
CopyMem (Buffer, CardData->AlignedBuffer, ByteCount);
}
}
Exit:
return Status;
}
/**
Send ReadWriteMultipleBlock command with RW_MULTIPLE_REGISTER command
@param CardData Pointer to CARD_DATA.
@param DataUnitCount Buffer size in 512 bytes unit.
@param Write TRUE means write, FALSE means read.
@param Buffer Buffer pointer.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
ReadWriteMultipleBlock (
IN CARD_DATA *CardData,
IN UINT16 DataUnitCount,
IN BOOLEAN Write,
IN UINT8 *Buffer
)
{
EFI_STATUS Status;
EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
UINT32 TransferLength;
Status = EFI_SUCCESS;
SDHostIo = CardData->SDHostIo;
TransferLength = DataUnitCount * DATA_UNIT_SIZE;
if (TransferLength > SDHostIo->HostCapability.BoundarySize) {
return EFI_INVALID_PARAMETER;
}
if (Write) {
CopyMem (CardData->AlignedBuffer, Buffer, TransferLength);
Status = SendCommand (
CardData,
RW_MULTIPLE_BLOCK,
(DataUnitCount | BIT31),
OutData,
CardData->AlignedBuffer,
TransferLength,
ResponseR1b,
TIMEOUT_DATA,
(UINT32*)&(CardData->CardStatus)
);
} else {
Status = SendCommand (
CardData,
RW_MULTIPLE_BLOCK,
DataUnitCount,
InData,
CardData->AlignedBuffer,
TransferLength,
ResponseR1,
TIMEOUT_DATA,
(UINT32*)&(CardData->CardStatus)
);
if (!EFI_ERROR (Status)) {
CopyMem (Buffer, CardData->AlignedBuffer, TransferLength);
}
}
return Status;
}
/**
Send software reset
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
SoftwareReset (
IN CARD_DATA *CardData
)
{
EFI_STATUS Status;
UINT8 Data;
UINT32 TimeOut;
Data = BIT2;
Status = FastIO (CardData, Reg_Control, &Data, TRUE);
if (EFI_ERROR (Status)) {
goto Exit;
}
TimeOut = 5 * 1000;
do {
gBS->Stall (1 * 1000);
Status = FastIO (CardData, Reg_Control, &Data, FALSE);
if (EFI_ERROR (Status)) {
goto Exit;
}
if ((Data & BIT2) == BIT2) {
break;
}
TimeOut--;
} while (TimeOut > 0);
if (TimeOut == 0) {
Status = EFI_TIMEOUT;
goto Exit;
}
Data &= ~BIT2;
Status = FastIO (CardData, Reg_Control, &Data, TRUE);
TimeOut = 5 * 1000;
do {
gBS->Stall (1 * 1000);
Status = FastIO (CardData, Reg_Control, &Data, FALSE);
if (EFI_ERROR (Status)) {
goto Exit;
}
if ((Data & BIT2) != BIT2) {
break;
}
TimeOut--;
} while (TimeOut > 0);
if (TimeOut == 0) {
Status = EFI_TIMEOUT;
goto Exit;
}
Exit:
return Status;
}
/**
SendATACommand specificed in Taskfile
@param CardData Pointer to CARD_DATA.
@param TaskFile Pointer to TASK_FILE.
@param Write TRUE means write, FALSE means read.
@param Buffer If NULL, means no data transfer, neither read nor write.
@param SectorCount Buffer size in 512 bytes unit.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
SendATACommand (
IN CARD_DATA *CardData,
IN TASK_FILE *TaskFile,
IN BOOLEAN Write,
IN UINT8 *Buffer,
IN UINT16 SectorCount
)
{
EFI_STATUS Status;
EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
UINT8 Data;
UINT32 TimeOut;
SDHostIo = CardData->SDHostIo;
//
//Write register
//
Status = ReadWriteMultipleRegister (
CardData,
0,
sizeof (TASK_FILE),
TRUE,
(UINT8*)TaskFile
);
if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "ReadWriteMultipleRegister 0x%x\n", Status));
goto Exit;
}
TimeOut = 5000;
do {
gBS->Stall (1 * 1000);
Data = 0;
Status = FastIO (
CardData,
Reg_Command_Status,
&Data,
FALSE
);
if (EFI_ERROR (Status)) {
return Status;
}
if (((Data & BIT7) == 0) && ((Data & BIT6) == BIT6)) {
break;
}
TimeOut --;
} while (TimeOut > 0);
if (TimeOut == 0) {
DEBUG((EFI_D_ERROR, "ReadWriteMultipleRegister FastIO EFI_TIMEOUT 0x%x\n", Data));
Status = EFI_TIMEOUT;
goto Exit;
}
if (Buffer != NULL) {
Status = ReadWriteMultipleBlock (
CardData,
SectorCount,
Write,
(UINT8*)Buffer
);
if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "ReadWriteMultipleBlock EFI_TIMEOUT 0x%x\n", Status));
goto Exit;
}
TimeOut = 5 * 1000;
do {
gBS->Stall (1 * 1000);
Data = 0;
Status = FastIO (
CardData,
Reg_Command_Status,
&Data,
FALSE
);
if (EFI_ERROR (Status)) {
return Status;
}
if (((Data & BIT7) == 0) && ((Data & BIT3) == 0)) {
break;
}
TimeOut --;
} while (TimeOut > 0);
if (TimeOut == 0) {
DEBUG((EFI_D_ERROR, "ReadWriteMultipleBlock FastIO EFI_TIMEOUT 0x%x\n", Data));
Status = EFI_TIMEOUT;
goto Exit;
}
if (((Data & BIT6) == BIT6) && (Data & BIT0) == 0) {
Status = EFI_SUCCESS;
} else {
Status = EFI_DEVICE_ERROR;
}
}
Exit:
if (EFI_ERROR (Status)) {
SoftwareReset (CardData);
}
return Status;
}
/**
IDENTIFY_DEVICE command
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
IndentifyDevice (
IN CARD_DATA *CardData
)
{
EFI_STATUS Status;
ZeroMem (&CardData->TaskFile, sizeof (TASK_FILE));
//
//The host only supports nIEN = 0
//
CardData->TaskFile.Command_Status = IDENTIFY_DEVICE;
Status = SendATACommand (
CardData,
&CardData->TaskFile,
FALSE,
(UINT8*)&(CardData->IndentifyDeviceData),
1
);
return Status;
}
/**
FLUSH_CACHE_EXT command
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
FlushCache (
IN CARD_DATA *CardData
)
{
//
//Hitachi CE-ATA will always make the busy high after
//receving this command
//
/*
EFI_STATUS Status;
ZeroMem (&CardData->TaskFile, sizeof (TASK_FILE));
//
//The host only supports nIEN = 0
//
CardData->TaskFile.Command_Status = FLUSH_CACHE_EXT;
Status = SendATACommand (
CardData,
&CardData->TaskFile,
FALSE,
NULL,
0
);
*/
return EFI_SUCCESS;
}
/**
STANDBY_IMMEDIATE command
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
StandByImmediate (
IN CARD_DATA *CardData
)
{
EFI_STATUS Status;
ZeroMem (&CardData->TaskFile, sizeof (TASK_FILE));
//
//The host only supports nIEN = 0
//
CardData->TaskFile.Command_Status = STANDBY_IMMEDIATE;
Status = SendATACommand (
CardData,
&CardData->TaskFile,
FALSE,
NULL,
0
);
return Status;
}
/**
READ_DMA_EXT command
@param CardData Pointer to CARD_DATA.
@param LBA The starting logical block address to read from on the device.
@param Buffer A pointer to the destination buffer for the data. The caller
is responsible for either having implicit or explicit ownership
of the buffer.
@param SectorCount Size in 512 bytes unit.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
ReadDMAExt (
IN CARD_DATA *CardData,
IN EFI_LBA LBA,
IN UINT8 *Buffer,
IN UINT16 SectorCount
)
{
EFI_STATUS Status;
ZeroMem (&CardData->TaskFile, sizeof (TASK_FILE));
//
//The host only supports nIEN = 0
//
CardData->TaskFile.Command_Status = READ_DMA_EXT;
CardData->TaskFile.SectorCount = (UINT8)SectorCount;
CardData->TaskFile.SectorCount_Exp = (UINT8)(SectorCount >> 8);
CardData->TaskFile.LBALow = (UINT8)LBA;
CardData->TaskFile.LBAMid = (UINT8)RShiftU64(LBA, 8);
CardData->TaskFile.LBAHigh = (UINT8)RShiftU64(LBA, 16);
CardData->TaskFile.LBALow_Exp = (UINT8)RShiftU64(LBA, 24);
CardData->TaskFile.LBAMid_Exp = (UINT8)RShiftU64(LBA, 32);
CardData->TaskFile.LBAHigh_Exp = (UINT8)RShiftU64(LBA, 40);
Status = SendATACommand (
CardData,
&CardData->TaskFile,
FALSE,
Buffer,
SectorCount
);
return Status;
}
/**
WRITE_DMA_EXT command
@param CardData Pointer to CARD_DATA.
@param LBA The starting logical block address to read from on the device.
@param Buffer A pointer to the destination buffer for the data. The caller
is responsible for either having implicit or explicit ownership
of the buffer.
@param SectorCount Size in 512 bytes unit.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
WriteDMAExt (
IN CARD_DATA *CardData,
IN EFI_LBA LBA,
IN UINT8 *Buffer,
IN UINT16 SectorCount
)
{
EFI_STATUS Status;
ZeroMem (&CardData->TaskFile, sizeof (TASK_FILE));
//
//The host only supports nIEN = 0
//
CardData->TaskFile.Command_Status = WRITE_DMA_EXT;
CardData->TaskFile.SectorCount = (UINT8)SectorCount;
CardData->TaskFile.SectorCount_Exp = (UINT8)(SectorCount >> 8);
CardData->TaskFile.LBALow = (UINT8)LBA;
CardData->TaskFile.LBAMid = (UINT8)RShiftU64(LBA, 8);
CardData->TaskFile.LBAHigh = (UINT8)RShiftU64(LBA, 16);
CardData->TaskFile.LBALow_Exp = (UINT8)RShiftU64(LBA, 24);
CardData->TaskFile.LBAMid_Exp = (UINT8)RShiftU64(LBA, 32);
CardData->TaskFile.LBAHigh_Exp = (UINT8)RShiftU64(LBA, 40);
Status = SendATACommand (
CardData,
&CardData->TaskFile,
TRUE,
Buffer,
SectorCount
);
return Status;
}
/**
Judge whether it is CE-ATA device or not.
@param CardData Pointer to CARD_DATA.
@retval TRUE
@retval FALSE
**/
BOOLEAN
IsCEATADevice (
IN CARD_DATA *CardData
)
{
EFI_STATUS Status;
Status = ReadWriteMultipleRegister (
CardData,
0,
sizeof (TASK_FILE),
FALSE,
(UINT8*)&CardData->TaskFile
);
if (EFI_ERROR (Status)) {
//
//To bring back the normal MMC card to work
//
CardData->SDHostIo->ResetSDHost (CardData->SDHostIo, Reset_DAT_CMD);
return FALSE;
}
if (CardData->TaskFile.LBAMid == CE_ATA_SIG_CE &&
CardData->TaskFile.LBAHigh == CE_ATA_SIG_AA
) {
//
//Disable Auto CMD for CE-ATA
//
CardData->SDHostIo->EnableAutoStopCmd (CardData->SDHostIo, FALSE);
return TRUE;
}
return FALSE;
}

View File

@@ -0,0 +1,396 @@
/** @file
Block I/O protocol for CE-ATA device
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "SDMediaDevice.h"
/**
Implements EFI_BLOCK_IO_PROTOCOL.Reset() function.
@param This The EFI_BLOCK_IO_PROTOCOL instance.
@param ExtendedVerification Indicates that the driver may perform a more exhaustive.
verification operation of the device during reset.
(This parameter is ingored in this driver.)
@retval EFI_SUCCESS Success
**/
EFI_STATUS
EFIAPI
CEATABlockReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
EFI_STATUS Status;
CARD_DATA *CardData;
EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
CardData = CARD_DATA_FROM_THIS(This);
SDHostIo = CardData->SDHostIo;
if (!ExtendedVerification) {
Status = SoftwareReset (CardData);
} else {
Status = SDHostIo->ResetSDHost (SDHostIo, Reset_DAT_CMD);
if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "CEATABlockReset: Fail to ResetSDHost\n" ));
return Status;
}
Status = MMCSDCardInit (CardData);
}
return Status;
}
/**
Implements EFI_BLOCK_IO_PROTOCOL.ReadBlocks() function.
@param This The EFI_BLOCK_IO_PROTOCOL instance.
@param MediaId The media id that the write request is for.
@param LBA The starting logical block address to read from on the device.
The caller is responsible for writing to only legitimate locations.
@param BufferSize The size of the Buffer in bytes. This must be a multiple of the
intrinsic block size of the device.
@param Buffer A pointer to the destination buffer for the data. The caller
is responsible for either having implicit or explicit ownership
of the buffer.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
EFIAPI
CEATABlockReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
EFI_STATUS Status;
CARD_DATA *CardData;
UINT32 TransferSize;
UINT8 *pBuf;
UINT32 Index;
UINT64 Address;
UINT32 Remainder;
UINT64 CEATALBA;
UINT32 BoundarySize;
Status = EFI_SUCCESS;
CardData = CARD_DATA_FROM_THIS(This);
pBuf = Buffer;
Index = 0;
Address = MultU64x32(LBA, CardData->BlockIoMedia.BlockSize);
BoundarySize = CardData->SDHostIo->HostCapability.BoundarySize;
if (!Buffer) {
Status = EFI_INVALID_PARAMETER;
DEBUG((EFI_D_ERROR, "CEATABlockReadBlocks:Invalid parameter\n" ));
goto Exit;
}
if (MediaId != CardData->BlockIoMedia.MediaId) {
Status = EFI_MEDIA_CHANGED;
DEBUG((EFI_D_ERROR, "CEATABlockReadBlocks:Media changed\n" ));
goto Exit;
}
if ((BufferSize % CardData->BlockIoMedia.BlockSize) != 0) {
Status = EFI_BAD_BUFFER_SIZE;
DEBUG((EFI_D_ERROR, "CEATABlockReadBlocks:Bad buffer size\n" ));
goto Exit;
}
if (BufferSize == 0) {
Status = EFI_SUCCESS;
goto Exit;
}
if ((Address + BufferSize) > MultU64x32 (CardData->BlockIoMedia.LastBlock + 1, CardData->BlockIoMedia.BlockSize)) {
Status = EFI_INVALID_PARAMETER;
DEBUG((EFI_D_ERROR, "CEATABlockReadBlocks:Invalid parameter\n" ));
goto Exit;
}
do {
if (BufferSize < BoundarySize) {
TransferSize = (UINT32)BufferSize;
} else {
TransferSize = BoundarySize;
}
Address += Index * TransferSize;
CEATALBA = DivU64x32Remainder (Address, DATA_UNIT_SIZE, &Remainder);
ASSERT(Remainder == 0);
Status = ReadDMAExt (
CardData,
CEATALBA,
pBuf,
(UINT16)(TransferSize / DATA_UNIT_SIZE)
);
if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "Read Failed at 0x%x, Index %d, Size 0x%x\n", Address, Index, TransferSize));
This->Reset (This, TRUE);
goto Exit;
}
BufferSize -= TransferSize;
pBuf += TransferSize;
Index ++;
} while (BufferSize != 0);
Exit:
return Status;
}
/**
Implements EFI_BLOCK_IO_PROTOCOL.WriteBlocks() function.
@param This The EFI_BLOCK_IO_PROTOCOL instance.
@param MediaId The media id that the write request is for.
@param LBA The starting logical block address to read from on the device.
The caller is responsible for writing to only legitimate locations.
@param BufferSize The size of the Buffer in bytes. This must be a multiple of the
intrinsic block size of the device.
@param Buffer A pointer to the destination buffer for the data. The caller
is responsible for either having implicit or explicit ownership
of the buffer.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
EFIAPI
CEATABlockWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
EFI_STATUS Status;
CARD_DATA *CardData;
UINT32 TransferSize;
UINT8 *pBuf;
UINT32 Index;
UINT64 Address;
UINT32 Remainder;
UINT64 CEATALBA;
UINT32 BoundarySize;
Status = EFI_SUCCESS;
CardData = CARD_DATA_FROM_THIS(This);
pBuf = Buffer;
Index = 0;
Address = MultU64x32(LBA, CardData->BlockIoMedia.BlockSize);
BoundarySize = CardData->SDHostIo->HostCapability.BoundarySize;
if (!Buffer) {
Status = EFI_INVALID_PARAMETER;
goto Exit;
}
if (MediaId != CardData->BlockIoMedia.MediaId) {
Status = EFI_MEDIA_CHANGED;
goto Exit;
}
if ((BufferSize % CardData->BlockIoMedia.BlockSize) != 0) {
Status = EFI_BAD_BUFFER_SIZE;
goto Exit;
}
if (BufferSize == 0) {
Status = EFI_SUCCESS;
goto Exit;
}
if (CardData->BlockIoMedia.ReadOnly) {
Status = EFI_WRITE_PROTECTED;
goto Exit;
}
if ((Address + BufferSize) > MultU64x32 (CardData->BlockIoMedia.LastBlock + 1, CardData->BlockIoMedia.BlockSize)) {
Status = EFI_INVALID_PARAMETER;
goto Exit;
}
CardData->NeedFlush = TRUE;
do {
if (BufferSize < BoundarySize) {
TransferSize = (UINT32)BufferSize;
} else {
TransferSize = BoundarySize;
}
Address += Index * TransferSize;
CEATALBA = DivU64x32Remainder (Address, DATA_UNIT_SIZE, &Remainder);
ASSERT(Remainder == 0);
Status = WriteDMAExt (
CardData,
CEATALBA,
pBuf,
(UINT16)(TransferSize / DATA_UNIT_SIZE)
);
if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "Write Failed at 0x%x, Index %d, Size 0x%x\n", Address, Index, TransferSize));
This->Reset (This, TRUE);
goto Exit;
}
BufferSize -= TransferSize;
pBuf += TransferSize;
Index ++;
} while (BufferSize != 0);
Exit:
return Status;
}
/**
Implements EFI_BLOCK_IO_PROTOCOL.FlushBlocks() function.
(In this driver, this function just returns EFI_SUCCESS.)
@param This The EFI_BLOCK_IO_PROTOCOL instance.
@retval EFI_SUCCESS
@retval Others
**/
EFI_STATUS
EFIAPI
CEATABlockFlushBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This
)
{
EFI_STATUS Status;
CARD_DATA *CardData;
CardData = CARD_DATA_FROM_THIS(This);
if (CardData->NeedFlush) {
CardData->NeedFlush = FALSE;
Status = FlushCache (CardData);
}
return EFI_SUCCESS;
}
/**
CEATA card BlockIo init function.
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS
@retval Others
**/
EFI_STATUS
CEATABlockIoInit (
IN CARD_DATA *CardData
)
/*++
Routine Description:
CEATA card BlockIo init function
Arguments:
CardData - Pointer to CARD_DATA
Returns:
EFI_SUCCESS - Success
--*/
{
EFI_STATUS Status;
UINT64 MaxSize;
UINT32 Remainder;
//
//BlockIO protocol
//
CardData->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION;
CardData->BlockIo.Media = &(CardData->BlockIoMedia);
CardData->BlockIo.Reset = CEATABlockReset;
CardData->BlockIo.ReadBlocks = CEATABlockReadBlocks ;
CardData->BlockIo.WriteBlocks = CEATABlockWriteBlocks;
CardData->BlockIo.FlushBlocks = CEATABlockFlushBlocks;
CardData->BlockIoMedia.MediaId = 0;
CardData->BlockIoMedia.RemovableMedia = FALSE;
CardData->BlockIoMedia.MediaPresent = TRUE;
CardData->BlockIoMedia.LogicalPartition = FALSE;
if (CardData->CSDRegister.PERM_WRITE_PROTECT | CardData->CSDRegister.TMP_WRITE_PROTECT) {
CardData->BlockIoMedia.ReadOnly = TRUE;
} else {
CardData->BlockIoMedia.ReadOnly = FALSE;
}
CardData->BlockIoMedia.WriteCaching = FALSE;
CardData->BlockIoMedia.IoAlign = 1;
Status = IndentifyDevice (CardData);
if (EFI_ERROR (Status)) {
goto Exit;
}
//
//Some device does not support this feature
//
if (CardData->IndentifyDeviceData.MaxWritesPerAddress == 0) {
CardData->BlockIoMedia.ReadOnly = TRUE;
}
CardData->BlockIoMedia.BlockSize = (1 << CardData->IndentifyDeviceData.Sectorsize);
ASSERT(CardData->BlockIoMedia.BlockSize >= 12);
MaxSize = *(UINT64*)(CardData->IndentifyDeviceData.MaximumLBA);
MaxSize = MultU64x32 (MaxSize, 512);
Remainder = 0;
CardData->BlockNumber = DivU64x32Remainder (MaxSize, CardData->BlockIoMedia.BlockSize, &Remainder);
ASSERT(Remainder == 0);
CardData->BlockIoMedia.LastBlock = (EFI_LBA)(CardData->BlockNumber - 1);
Exit:
return Status;
}

View File

@@ -0,0 +1,221 @@
/** @file
UEFI Component Name(2) protocol implementation for SD media device driver.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "SDMediaDevice.h"
//
// EFI Component Name Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gSDMediaDeviceName = {
SDMediaDeviceGetDriverName,
SDMediaDeviceGetControllerName,
"eng"
};
//
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gSDMediaDeviceName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) SDMediaDeviceGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) SDMediaDeviceGetControllerName,
"en"
};
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mSDMediaDeviceDriverNameTable[] = {
{ "eng;en", L"UEFI MMC/SD Media Device Driver" },
{ NULL, NULL }
};
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 3066 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
SDMediaDeviceGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mSDMediaDeviceDriverNameTable,
DriverName,
(BOOLEAN)(This == &gSDMediaDeviceName)
);
}
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 3066 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
SDMediaDeviceGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
CARD_DATA *CardData;
//
// This is a device driver, so ChildHandle must be NULL.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
//
// Get the device context
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiBlockIoProtocolGuid,
(VOID **) &BlockIo,
gSDMediaDeviceDriverBinding.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
CardData = CARD_DATA_FROM_THIS (BlockIo);
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
CardData->ControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gSDMediaDeviceName)
);
}

View File

@@ -0,0 +1,145 @@
/** @file
This file contains the delarations for componet name routines.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _COMPONENT_NAME_H_
#define _COMPONENT_NAME_H_
/**
Retrieves a Unicode string that is the user readable name of the driver.
This function retrieves the user readable name of a driver in the form of a
Unicode string. If the driver specified by This has a user readable name in
the language specified by Language, then a pointer to the driver name is
returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
by This does not support the language specified by Language,
then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified
in RFC 3066 or ISO 639-2 language code format.
@param DriverName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
driver specified by This in the language
specified by Language.
@retval EFI_SUCCESS The Unicode string for the Driver specified by
This and the language specified by Language was
returned in DriverName.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER DriverName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
SDMediaDeviceGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
This function retrieves the user readable name of the controller specified by
ControllerHandle and ChildHandle in the form of a Unicode string. If the
driver specified by This has a user readable name in the language specified by
Language, then a pointer to the controller name is returned in ControllerName,
and EFI_SUCCESS is returned. If the driver specified by This is not currently
managing the controller specified by ControllerHandle and ChildHandle,
then EFI_UNSUPPORTED is returned. If the driver specified by This does not
support the language specified by Language, then EFI_UNSUPPORTED is returned.
@param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
EFI_COMPONENT_NAME_PROTOCOL instance.
@param ControllerHandle[in] The handle of a controller that the driver
specified by This is managing. This handle
specifies the controller whose name is to be
returned.
@param ChildHandle[in] The handle of the child controller to retrieve
the name of. This is an optional parameter that
may be NULL. It will be NULL for device
drivers. It will also be NULL for a bus drivers
that wish to retrieve the name of the bus
controller. It will not be NULL for a bus
driver that wishes to retrieve the name of a
child controller.
@param Language[in] A pointer to a Null-terminated ASCII string
array indicating the language. This is the
language of the driver name that the caller is
requesting, and it must match one of the
languages specified in SupportedLanguages. The
number of languages supported by a driver is up
to the driver writer. Language is specified in
RFC 3066 or ISO 639-2 language code format.
@param ControllerName[out] A pointer to the Unicode string to return.
This Unicode string is the name of the
controller specified by ControllerHandle and
ChildHandle in the language specified by
Language from the point of view of the driver
specified by This.
@retval EFI_SUCCESS The Unicode string for the user readable name in
the language specified by Language for the
driver specified by This was returned in
DriverName.
@retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
@retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
EFI_HANDLE.
@retval EFI_INVALID_PARAMETER Language is NULL.
@retval EFI_INVALID_PARAMETER ControllerName is NULL.
@retval EFI_UNSUPPORTED The driver specified by This is not currently
managing the controller specified by
ControllerHandle and ChildHandle.
@retval EFI_UNSUPPORTED The driver specified by This does not support
the language specified by Language.
**/
EFI_STATUS
EFIAPI
SDMediaDeviceGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
#endif

View File

@@ -0,0 +1,544 @@
/** @file
Block I/O protocol for MMC/SD device
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "SDMediaDevice.h"
/**
Implements EFI_BLOCK_IO_PROTOCOL.Reset() function.
@param This The EFI_BLOCK_IO_PROTOCOL instance.
@param ExtendedVerification Indicates that the driver may perform a more exhaustive.
verification operation of the device during reset.
(This parameter is ingored in this driver.)
@retval EFI_SUCCESS Success
**/
EFI_STATUS
EFIAPI
MMCSDBlockReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
CARD_DATA *CardData;
EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
CardData = CARD_DATA_FROM_THIS(This);
SDHostIo = CardData->SDHostIo;
return SDHostIo->ResetSDHost (SDHostIo, Reset_DAT_CMD);
}
/**
Implements EFI_BLOCK_IO_PROTOCOL.ReadBlocks() function.
@param This The EFI_BLOCK_IO_PROTOCOL instance.
@param MediaId The media id that the write request is for.
@param LBA The starting logical block address to read from on the device.
The caller is responsible for writing to only legitimate locations.
@param BufferSize The size of the Buffer in bytes. This must be a multiple of the
intrinsic block size of the device.
@param Buffer A pointer to the destination buffer for the data. The caller
is responsible for either having implicit or explicit ownership
of the buffer.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
EFIAPI
MMCSDBlockReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
EFI_STATUS Status;
UINT32 Address;
CARD_DATA *CardData;
EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
UINT32 RemainingLength;
UINT32 TransferLength;
UINT8 *BufferPointer;
BOOLEAN SectorAddressing;
UINTN TotalBlock;
DEBUG((EFI_D_INFO, "Read(LBA=%08lx, Buffer=%08x, Size=%08x)\n", LBA, Buffer, BufferSize));
Status = EFI_SUCCESS;
CardData = CARD_DATA_FROM_THIS(This);
SDHostIo = CardData->SDHostIo;
if (MediaId != CardData->BlockIoMedia.MediaId) {
return EFI_MEDIA_CHANGED;
}
if (ModU64x32 (BufferSize,CardData->BlockIoMedia.BlockSize) != 0) {
return EFI_BAD_BUFFER_SIZE;
}
if ((CardData->CardType == SDMemoryCard2High) || (CardData->CardType == MMCCardHighCap)) {
SectorAddressing = TRUE;
} else {
SectorAddressing = FALSE;
}
if (SectorAddressing) {
//
//Block Address
//
Address = (UINT32)DivU64x32 (MultU64x32 (LBA, CardData->BlockIoMedia.BlockSize), 512);
} else {
//
//Byte Address
//
Address = (UINT32)MultU64x32 (LBA, CardData->BlockIoMedia.BlockSize);
}
TotalBlock = (UINTN) DivU64x32 (BufferSize, CardData->BlockIoMedia.BlockSize);
if (LBA + TotalBlock > CardData->BlockIoMedia.LastBlock + 1) {
return EFI_INVALID_PARAMETER;
}
if (!Buffer) {
Status = EFI_INVALID_PARAMETER;
DEBUG ((EFI_D_ERROR, "MMCSDBlockReadBlocks:Invalid parameter \r\n"));
goto Done;
}
if ((BufferSize % CardData->BlockIoMedia.BlockSize) != 0) {
Status = EFI_BAD_BUFFER_SIZE;
DEBUG ((EFI_D_ERROR, "MMCSDBlockReadBlocks: Bad buffer size \r\n"));
goto Done;
}
if (BufferSize == 0) {
Status = EFI_SUCCESS;
goto Done;
}
BufferPointer = Buffer;
RemainingLength = (UINT32)BufferSize;
while (RemainingLength > 0) {
if ((BufferSize > CardData->BlockIoMedia.BlockSize)) {
if (RemainingLength > SDHostIo->HostCapability.BoundarySize) {
TransferLength = SDHostIo->HostCapability.BoundarySize;
} else {
TransferLength = RemainingLength;
}
if (CardData->CardType == MMCCard || CardData->CardType == MMCCardHighCap) {
if (!(CardData->ExtCSDRegister.CARD_TYPE & (BIT2 | BIT3))) {
Status = SendCommand (
CardData,
SET_BLOCKLEN,
CardData->BlockIoMedia.BlockSize,
NoData,
NULL,
0,
ResponseR1,
TIMEOUT_COMMAND,
(UINT32*)&(CardData->CardStatus)
);
if (EFI_ERROR (Status)) {
break;
}
}
Status = SendCommand (
CardData,
SET_BLOCK_COUNT,
TransferLength / CardData->BlockIoMedia.BlockSize,
NoData,
NULL,
0,
ResponseR1,
TIMEOUT_COMMAND,
(UINT32*)&(CardData->CardStatus)
);
if (EFI_ERROR (Status)) {
break;
}
}
Status = SendCommand (
CardData,
READ_MULTIPLE_BLOCK,
Address,
InData,
CardData->AlignedBuffer,
TransferLength,
ResponseR1,
TIMEOUT_DATA,
(UINT32*)&(CardData->CardStatus)
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "MMCSDBlockReadBlocks: READ_MULTIPLE_BLOCK -> Fail\n"));
break;
}
} else {
if (RemainingLength > CardData->BlockIoMedia.BlockSize) {
TransferLength = CardData->BlockIoMedia.BlockSize;
} else {
TransferLength = RemainingLength;
}
Status = SendCommand (
CardData,
READ_SINGLE_BLOCK,
Address,
InData,
CardData->AlignedBuffer,
(UINT32)TransferLength,
ResponseR1,
TIMEOUT_DATA,
(UINT32*)&(CardData->CardStatus)
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "MMCSDBlockReadBlocks: READ_SINGLE_BLOCK -> Fail\n"));
break;
}
}
CopyMem (BufferPointer, CardData->AlignedBuffer, TransferLength);
if (SectorAddressing) {
//
//Block Address
//
Address += TransferLength / 512;
} else {
//
//Byte Address
//
Address += TransferLength;
}
BufferPointer += TransferLength;
RemainingLength -= TransferLength;
}
if (EFI_ERROR (Status)) {
if ((CardData->CardType == SDMemoryCard) ||
(CardData->CardType == SDMemoryCard2)||
(CardData->CardType == SDMemoryCard2High)) {
SendCommand (
CardData,
STOP_TRANSMISSION,
0,
NoData,
NULL,
0,
ResponseR1b,
TIMEOUT_COMMAND,
(UINT32*)&(CardData->CardStatus)
);
} else {
SendCommand (
CardData,
STOP_TRANSMISSION,
0,
NoData,
NULL,
0,
ResponseR1,
TIMEOUT_COMMAND,
(UINT32*)&(CardData->CardStatus)
);
}
}
Done:
DEBUG((EFI_D_INFO, "MMCSDBlockReadBlocks: Status = %r\n", Status));
return Status;
}
/**
Implements EFI_BLOCK_IO_PROTOCOL.WriteBlocks() function.
@param This The EFI_BLOCK_IO_PROTOCOL instance.
@param MediaId The media id that the write request is for.
@param LBA The starting logical block address to read from on the device.
The caller is responsible for writing to only legitimate locations.
@param BufferSize The size of the Buffer in bytes. This must be a multiple of the
intrinsic block size of the device.
@param Buffer A pointer to the destination buffer for the data. The caller
is responsible for either having implicit or explicit ownership
of the buffer.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
EFIAPI
MMCSDBlockWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA LBA,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
EFI_STATUS Status;
UINT32 Address;
CARD_DATA *CardData;
EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
UINT32 RemainingLength;
UINT32 TransferLength;
UINT8 *BufferPointer;
BOOLEAN SectorAddressing;
DEBUG((EFI_D_INFO, "Write(LBA=%08lx, Buffer=%08x, Size=%08x)\n", LBA, Buffer, BufferSize));
Status = EFI_SUCCESS;
CardData = CARD_DATA_FROM_THIS(This);
SDHostIo = CardData->SDHostIo;
if ((CardData->CardType == SDMemoryCard2High) || (CardData->CardType == MMCCardHighCap)) {
SectorAddressing = TRUE;
} else {
SectorAddressing = FALSE;
}
if (SectorAddressing) {
//
//Block Address
//
Address = (UINT32)DivU64x32 (MultU64x32 (LBA, CardData->BlockIoMedia.BlockSize), 512);
} else {
//
//Byte Address
//
Address = (UINT32)MultU64x32 (LBA, CardData->BlockIoMedia.BlockSize);
}
if (!Buffer) {
Status = EFI_INVALID_PARAMETER;
DEBUG ((EFI_D_ERROR, "MMCSDBlockWriteBlocks: Invalid parameter \r\n"));
goto Done;
}
if ((BufferSize % CardData->BlockIoMedia.BlockSize) != 0) {
Status = EFI_BAD_BUFFER_SIZE;
DEBUG ((EFI_D_ERROR, "MMCSDBlockWriteBlocks: Bad buffer size \r\n"));
goto Done;
}
if (BufferSize == 0) {
Status = EFI_SUCCESS;
goto Done;
}
if (This->Media->ReadOnly == TRUE) {
Status = EFI_WRITE_PROTECTED;
DEBUG ((EFI_D_ERROR, "MMCSDBlockWriteBlocks: Write protected \r\n"));
goto Done;
}
BufferPointer = Buffer;
RemainingLength = (UINT32)BufferSize;
while (RemainingLength > 0) {
if ((BufferSize > CardData->BlockIoMedia.BlockSize) ) {
if (RemainingLength > SDHostIo->HostCapability.BoundarySize) {
TransferLength = SDHostIo->HostCapability.BoundarySize;
} else {
TransferLength = RemainingLength;
}
if (CardData->CardType == MMCCard || CardData->CardType == MMCCardHighCap) {
if (!(CardData->ExtCSDRegister.CARD_TYPE & (BIT2 | BIT3))) {
Status = SendCommand (
CardData,
SET_BLOCKLEN,
CardData->BlockIoMedia.BlockSize,
NoData,
NULL,
0,
ResponseR1,
TIMEOUT_COMMAND,
(UINT32*)&(CardData->CardStatus)
);
if (EFI_ERROR (Status)) {
break;
}
}
Status = SendCommand (
CardData,
SET_BLOCK_COUNT,
TransferLength / CardData->BlockIoMedia.BlockSize,
NoData,
NULL,
0,
ResponseR1,
TIMEOUT_COMMAND,
(UINT32*)&(CardData->CardStatus)
);
if (EFI_ERROR (Status)) {
break;
}
}
CopyMem (CardData->AlignedBuffer, BufferPointer, TransferLength);
Status = SendCommand (
CardData,
WRITE_MULTIPLE_BLOCK,
Address,
OutData,
CardData->AlignedBuffer,
(UINT32)TransferLength,
ResponseR1,
TIMEOUT_DATA,
(UINT32*)&(CardData->CardStatus)
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "MMCSDBlockWriteBlocks: WRITE_MULTIPLE_BLOCK -> Fail\n"));
break;
}
} else {
if (RemainingLength > CardData->BlockIoMedia.BlockSize) {
TransferLength = CardData->BlockIoMedia.BlockSize;
} else {
TransferLength = RemainingLength;
}
CopyMem (CardData->AlignedBuffer, BufferPointer, TransferLength);
Status = SendCommand (
CardData,
WRITE_BLOCK,
Address,
OutData,
CardData->AlignedBuffer,
(UINT32)TransferLength,
ResponseR1,
TIMEOUT_DATA,
(UINT32*)&(CardData->CardStatus)
);
}
if (SectorAddressing) {
//
//Block Address
//
Address += TransferLength / 512;
} else {
//
//Byte Address
//
Address += TransferLength;
}
BufferPointer += TransferLength;
RemainingLength -= TransferLength;
}
if (EFI_ERROR (Status)) {
SendCommand (
CardData,
STOP_TRANSMISSION,
0,
NoData,
NULL,
0,
ResponseR1b,
TIMEOUT_COMMAND,
(UINT32*)&(CardData->CardStatus)
);
}
Done:
return EFI_SUCCESS;
}
/**
Implements EFI_BLOCK_IO_PROTOCOL.FlushBlocks() function.
(In this driver, this function just returns EFI_SUCCESS.)
@param This The EFI_BLOCK_IO_PROTOCOL instance.
@retval EFI_SUCCESS
@retval Others
**/
EFI_STATUS
EFIAPI
MMCSDBlockFlushBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This
)
{
return EFI_SUCCESS;
}
/**
MMC/SD card BlockIo init function.
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS
@retval Others
**/
EFI_STATUS
MMCSDBlockIoInit (
IN CARD_DATA *CardData
)
{
//
//BlockIO protocol
//
CardData->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION;
CardData->BlockIo.Media = &(CardData->BlockIoMedia);
CardData->BlockIo.Reset = MMCSDBlockReset;
CardData->BlockIo.ReadBlocks = MMCSDBlockReadBlocks ;
CardData->BlockIo.WriteBlocks = MMCSDBlockWriteBlocks;
CardData->BlockIo.FlushBlocks = MMCSDBlockFlushBlocks;
CardData->BlockIoMedia.MediaId = 0;
CardData->BlockIoMedia.RemovableMedia = FALSE;
CardData->BlockIoMedia.MediaPresent = TRUE;
CardData->BlockIoMedia.LogicalPartition = FALSE;
if (CardData->CSDRegister.PERM_WRITE_PROTECT || CardData->CSDRegister.TMP_WRITE_PROTECT) {
CardData->BlockIoMedia.ReadOnly = TRUE;
} else {
CardData->BlockIoMedia.ReadOnly = FALSE;
}
CardData->BlockIoMedia.WriteCaching = FALSE;
CardData->BlockIoMedia.BlockSize = CardData->BlockLen;
CardData->BlockIoMedia.IoAlign = 1;
CardData->BlockIoMedia.LastBlock = (EFI_LBA)(CardData->BlockNumber - 1);
return EFI_SUCCESS;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,323 @@
/** @file
The definition for SD media device driver model and blkio protocol routines.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "SDMediaDevice.h"
EFI_DRIVER_BINDING_PROTOCOL gSDMediaDeviceDriverBinding = {
SDMediaDeviceSupported,
SDMediaDeviceStart,
SDMediaDeviceStop,
0x20,
NULL,
NULL
};
/**
Entry point for EFI drivers.
@param ImageHandle EFI_HANDLE.
@param SystemTable EFI_SYSTEM_TABLE.
@retval EFI_SUCCESS Driver is successfully loaded.
@return Others Failed.
**/
EFI_STATUS
EFIAPI
InitializeSDMediaDevice (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
&gSDMediaDeviceDriverBinding,
ImageHandle,
&gSDMediaDeviceName,
&gSDMediaDeviceName2
);
}
/**
Test to see if this driver supports ControllerHandle. Any
ControllerHandle that has BlockIoProtocol installed will be supported.
@param This Protocol instance pointer.
@param Controller Handle of device to test.
@param RemainingDevicePath Not used.
@return EFI_SUCCESS This driver supports this device.
@return EFI_UNSUPPORTED This driver does not support this device.
**/
EFI_STATUS
EFIAPI
SDMediaDeviceSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
//
// Test whether there is PCI IO Protocol attached on the controller handle.
//
Status = gBS->OpenProtocol (
Controller,
&gEfiSDHostIoProtocolGuid,
(VOID **)&SDHostIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
goto Exit;
}
gBS->CloseProtocol (
Controller,
&gEfiSDHostIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
Exit:
return Status;
}
/**
Starting the SD Media Device Driver.
@param This Protocol instance pointer.
@param Controller Handle of device to test.
@param RemainingDevicePath Not used.
@retval EFI_SUCCESS This driver supports this device.
@retval EFI_UNSUPPORTED This driver does not support this device.
@retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
**/
EFI_STATUS
EFIAPI
SDMediaDeviceStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
CARD_DATA *CardData;
CardData = NULL;
//
// Open PCI I/O Protocol and save pointer to open protocol
// in private data area.
//
Status = gBS->OpenProtocol (
Controller,
&gEfiSDHostIoProtocolGuid,
(VOID **) &SDHostIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "SDMediaDeviceStart: Fail to open gEfiSDHostIoProtocolGuid \r\n"));
goto Exit;
}
Status = SDHostIo->DetectCardAndInitHost (SDHostIo);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_INFO, "SDMediaDeviceStart: Fail to DetectCardAndInitHost \r\n"));
goto Exit;
}
CardData = (CARD_DATA*)AllocateZeroPool(sizeof (CARD_DATA));
if (CardData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
DEBUG ((EFI_D_ERROR, "SDMediaDeviceStart: Fail to AllocateZeroPool(CARD_DATA) \r\n"));
goto Exit;
}
ASSERT (SDHostIo->HostCapability.BoundarySize >= 4 * 1024);
CardData->RawBufferPointer = (UINT8*)((UINTN)DMA_MEMORY_TOP);
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiBootServicesData,
EFI_SIZE_TO_PAGES (2 * SDHostIo->HostCapability.BoundarySize),
(EFI_PHYSICAL_ADDRESS *)(&CardData->RawBufferPointer)
);
if (CardData->RawBufferPointer == NULL) {
DEBUG ((EFI_D_ERROR, "SDMediaDeviceStart: Fail to AllocateZeroPool(2*x) \r\n"));
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
CardData->AlignedBuffer = CardData->RawBufferPointer - ((UINTN)(CardData->RawBufferPointer) & (SDHostIo->HostCapability.BoundarySize - 1)) + SDHostIo->HostCapability.BoundarySize;
CardData->Signature = CARD_DATA_SIGNATURE;
CardData->SDHostIo = SDHostIo;
Status = MMCSDCardInit (CardData);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "SDMediaDeviceStart: Fail to MMCSDCardInit \r\n"));
goto Exit;
}
DEBUG ((EFI_D_INFO, "SDMediaDeviceStart: MMCSDCardInit SuccessFul\n"));
if (CardData->CardType == CEATACard) {
Status = CEATABlockIoInit (CardData);
} else {
Status = MMCSDBlockIoInit (CardData);
}
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "SDMediaDeviceStart: Fail to BlockIoInit \r\n"));
goto Exit;
}
DEBUG ((EFI_D_INFO, "SDMediaDeviceStart: BlockIo is successfully installed\n"));
Status = gBS->InstallProtocolInterface (
&Controller,
&gEfiBlockIoProtocolGuid,
EFI_NATIVE_INTERFACE,
&CardData->BlockIo
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "SDMediaDeviceStart: Fail to install gEfiBlockIoProtocolGuid \r\n"));
goto Exit;
}
//
// Install the component name protocol
//
CardData->ControllerNameTable = NULL;
AddUnicodeString2 (
"eng",
gSDMediaDeviceName.SupportedLanguages,
&CardData->ControllerNameTable,
L"MMC/SD Media Device",
TRUE
);
AddUnicodeString2 (
"en",
gSDMediaDeviceName2.SupportedLanguages,
&CardData->ControllerNameTable,
L"MMC/SD Media Device",
FALSE
);
Exit:
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_INFO, "SDMediaDeviceStart: End with failure\r\n"));
if (CardData != NULL) {
if (CardData->RawBufferPointer != NULL) {
gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) CardData->RawBufferPointer, EFI_SIZE_TO_PAGES (2 * SDHostIo->HostCapability.BoundarySize));
}
FreePool (CardData);
}
}
return Status;
}
/**
Stop this driver on ControllerHandle. Support stoping any child handles
created by this driver.
@param This Protocol instance pointer.
@param Controller Handle of device to stop driver on.
@param NumberOfChildren Number of Children in the ChildHandleBuffer.
@param ChildHandleBuffer List of handles for the children we need to stop.
@return EFI_SUCCESS
@return others
**/
EFI_STATUS
EFIAPI
SDMediaDeviceStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
CARD_DATA *CardData;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
//
// First find BlockIo Protocol
//
Status = gBS->OpenProtocol (
Controller,
&gEfiBlockIoProtocolGuid,
(VOID **)&BlockIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
CardData = CARD_DATA_FROM_THIS(BlockIo);
//
// Uninstall Block I/O protocol from the device handle
//
Status = gBS->UninstallProtocolInterface (
Controller,
&gEfiBlockIoProtocolGuid,
BlockIo
);
if (EFI_ERROR (Status)) {
return Status;
}
if (CardData != NULL) {
if (CardData->RawBufferPointer != NULL) {
gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) CardData->RawBufferPointer, EFI_SIZE_TO_PAGES (2 * CardData->SDHostIo->HostCapability.BoundarySize));
}
FreeUnicodeStringTable (CardData->ControllerNameTable);
FreePool (CardData);
}
gBS->CloseProtocol (
Controller,
&gEfiSDHostIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,468 @@
/** @file
The definition for SD media device driver model and blkio protocol routines.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _SD_MEDIA_DEVICE_H_
#define _SD_MEDIA_DEVICE_H_
#include <Uefi.h>
#include <Protocol/PciIo.h>
#include <Protocol/BlockIo.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <IndustryStandard/Pci22.h>
#include "ComponentName.h"
#include "SDHostIo.h"
extern EFI_DRIVER_BINDING_PROTOCOL gSDMediaDeviceDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gSDMediaDeviceName;
extern EFI_COMPONENT_NAME2_PROTOCOL gSDMediaDeviceName2;
//
// Define the region of memory used for DMA memory
//
#define DMA_MEMORY_TOP 0x0000000001FFFFFFULL
#define CARD_DATA_SIGNATURE SIGNATURE_32 ('c', 'a', 'r', 'd')
//
// Command timeout will be max 100 ms
//
#define TIMEOUT_COMMAND 100
#define TIMEOUT_DATA 5000
typedef enum{
UnknownCard = 0,
MMCCard, // MMC card
MMCCardHighCap, // MMC Card High Capacity
CEATACard, // CE-ATA device
SDMemoryCard, // SD 1.1 card
SDMemoryCard2, // SD 2.0 or above standard card
SDMemoryCard2High // SD 2.0 or above high capacity card
}CARD_TYPE;
typedef struct {
//
//BlockIO
//
UINTN Signature;
EFI_BLOCK_IO_PROTOCOL BlockIo;
EFI_BLOCK_IO_MEDIA BlockIoMedia;
EFI_SD_HOST_IO_PROTOCOL *SDHostIo;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
CARD_TYPE CardType;
UINT8 CurrentBusWidth;
BOOLEAN DualVoltage;
BOOLEAN NeedFlush;
UINT8 Reserved[3];
UINT16 Address;
UINT32 BlockLen;
UINT32 MaxFrequency;
UINT64 BlockNumber;
//
//Common used
//
CARD_STATUS CardStatus;
OCR OCRRegister;
CID CIDRegister;
CSD CSDRegister;
EXT_CSD ExtCSDRegister;
UINT8 *RawBufferPointer;
UINT8 *AlignedBuffer;
//
//CE-ATA specific
//
TASK_FILE TaskFile;
IDENTIFY_DEVICE_DATA IndentifyDeviceData;
//
//SD specific
//
SCR SCRRegister;
SD_STATUS_REG SDSattus;
SWITCH_STATUS SwitchStatus;
}CARD_DATA;
#define CARD_DATA_FROM_THIS(a) \
CR(a, CARD_DATA, BlockIo, CARD_DATA_SIGNATURE)
/**
Test to see if this driver supports ControllerHandle. Any
ControllerHandle that has BlockIoProtocol installed will be supported.
@param This Protocol instance pointer.
@param Controller Handle of device to test.
@param RemainingDevicePath Not used.
@return EFI_SUCCESS This driver supports this device.
@return EFI_UNSUPPORTED This driver does not support this device.
**/
EFI_STATUS
EFIAPI
SDMediaDeviceSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
/**
Starting the SD Media Device Driver.
@param This Protocol instance pointer.
@param Controller Handle of device to test.
@param RemainingDevicePath Not used.
@retval EFI_SUCCESS This driver supports this device.
@retval EFI_UNSUPPORTED This driver does not support this device.
@retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
**/
EFI_STATUS
EFIAPI
SDMediaDeviceStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
/**
Stop this driver on ControllerHandle. Support stoping any child handles
created by this driver.
@param This Protocol instance pointer.
@param Controller Handle of device to stop driver on.
@param NumberOfChildren Number of Children in the ChildHandleBuffer.
@param ChildHandleBuffer List of handles for the children we need to stop.
@return EFI_SUCCESS
@return others
**/
EFI_STATUS
EFIAPI
SDMediaDeviceStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
/**
MMC/SD card init function
@param CardData Pointer to CARD_DATA.
@return EFI_SUCCESS
@return others
**/
EFI_STATUS
MMCSDCardInit (
IN CARD_DATA *CardData
);
/**
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
);
/**
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
);
/**
Send the card FAST_IO command
@param CardData Pointer to CARD_DATA.
@param RegisterAddress Register Address.
@param RegisterData Pointer to register Data.
@param Write TRUE for write, FALSE for read.
@retval EFI_SUCCESS
@retval EFI_UNSUPPORTED
@retval EFI_INVALID_PARAMETER
@retval EFI_DEVICE_ERROR
**/
EFI_STATUS
FastIO (
IN CARD_DATA *CardData,
IN UINT8 RegisterAddress,
IN OUT UINT8 *RegisterData,
IN BOOLEAN Write
);
/**
Judge whether it is CE-ATA device or not.
@param CardData Pointer to CARD_DATA.
@retval TRUE
@retval FALSE
**/
BOOLEAN
IsCEATADevice (
IN CARD_DATA *CardData
);
/**
Send software reset
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
SoftwareReset (
IN CARD_DATA *CardData
);
/**
SendATACommand specificed in Taskfile
@param CardData Pointer to CARD_DATA.
@param TaskFile Pointer to TASK_FILE.
@param Write TRUE means write, FALSE means read.
@param Buffer If NULL, means no data transfer, neither read nor write.
@param SectorCount Buffer size in 512 bytes unit.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
SendATACommand (
IN CARD_DATA *CardData,
IN TASK_FILE *TaskFile,
IN BOOLEAN Write,
IN UINT8 *Buffer,
IN UINT16 SectorCount
);
/**
IDENTIFY_DEVICE command
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
IndentifyDevice (
IN CARD_DATA *CardData
);
/**
FLUSH_CACHE_EXT command
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
FlushCache (
IN CARD_DATA *CardData
);
/**
STANDBY_IMMEDIATE command
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
StandByImmediate (
IN CARD_DATA *CardData
);
/**
READ_DMA_EXT command
@param CardData Pointer to CARD_DATA.
@param LBA The starting logical block address to read from on the device.
@param Buffer A pointer to the destination buffer for the data. The caller
is responsible for either having implicit or explicit ownership
of the buffer.
@param SectorCount Size in 512 bytes unit.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
ReadDMAExt (
IN CARD_DATA *CardData,
IN EFI_LBA LBA,
IN UINT8 *Buffer,
IN UINT16 SectorCount
);
/**
WRITE_DMA_EXT command
@param CardData Pointer to CARD_DATA.
@param LBA The starting logical block address to read from on the device.
@param Buffer A pointer to the destination buffer for the data. The caller
is responsible for either having implicit or explicit ownership
of the buffer.
@param SectorCount Size in 512 bytes unit.
@retval EFI_SUCCESS Success
@retval EFI_DEVICE_ERROR Hardware Error
@retval EFI_INVALID_PARAMETER Parameter is error
@retval EFI_NO_MEDIA No media
@retval EFI_MEDIA_CHANGED Media Change
@retval EFI_BAD_BUFFER_SIZE Buffer size is bad
**/
EFI_STATUS
WriteDMAExt (
IN CARD_DATA *CardData,
IN EFI_LBA LBA,
IN UINT8 *Buffer,
IN UINT16 SectorCount
);
/**
CEATA card BlockIo init function.
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS
@retval Others
**/
EFI_STATUS
CEATABlockIoInit (
IN CARD_DATA *CardData
);
/**
MMC/SD card BlockIo init function.
@param CardData Pointer to CARD_DATA.
@retval EFI_SUCCESS
@retval Others
**/
EFI_STATUS
MMCSDBlockIoInit (
IN CARD_DATA *CardData
);
#endif

View File

@@ -0,0 +1,66 @@
## @file
#
# Component Description File For SDMediaDeviceDxe Module.
#
# Copyright (c) 2013-2015 Intel Corporation.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = SDMediaDevice
FILE_GUID = 80897901-91F6-4efe-9579-3353A0C02DAB
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = InitializeSDMediaDevice
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
# DRIVER_BINDING = gSDMediaDeviceDriverBinding
# COMPONENT_NAME = gSDMediaDeviceName
# COMPONENT_NAME2 = gSDMediaDeviceName2
#
[Sources]
SDMediaDevice.c
SDMediaDevice.h
MMCSDTransfer.c
CEATA.c
CEATABlockIo.c
MMCSDBlockIo.c
ComponentName.c
ComponentName.h
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
QuarkSocPkg/QuarkSocPkg.dec
[LibraryClasses]
MemoryAllocationLib
BaseLib
UefiLib
UefiBootServicesTableLib
UefiDriverEntryPoint
BaseMemoryLib
DebugLib
PcdLib
[Protocols]
gEfiPciIoProtocolGuid ## TO_START
gEfiSDHostIoProtocolGuid ## TO_START
gEfiBlockIoProtocolGuid ## BY_START
[Pcd.common]