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