sdp.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All rights reserved.
  3. Module Name:
  4. sdp.h
  5. Abstract:
  6. This header contains internal definitions for the SD library. This file
  7. should only be included by the library itself, not by external consumers of
  8. the library.
  9. Author:
  10. Evan Green 27-Feb-2014
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include <dev/sd.h>
  16. //
  17. // --------------------------------------------------------------------- Macros
  18. //
  19. //
  20. // This macro determines if the given card is an SD card. It returns non-zero
  21. // if it is an SD card, or 0 if it is an MMC card.
  22. //
  23. #define SD_IS_CARD_SD(_Controller) \
  24. ((_Controller)->Version < SdVersionMaximum)
  25. //
  26. // ---------------------------------------------------------------- Definitions
  27. //
  28. //
  29. // Define the amount of time to wait in microseconds for the controller to
  30. // respond.
  31. //
  32. #define EFI_SD_CONTROLLER_TIMEOUT 1000000
  33. //
  34. // Define the amount of time to wait in seconds for the status to go green.
  35. //
  36. #define EFI_SD_CONTROLLER_STATUS_TIMEOUT 60000000
  37. //
  38. // Define the amount of time to wait for the card to initialize, in
  39. // microseconds.
  40. //
  41. #define SD_CARD_DELAY 1000
  42. #define SD_POST_RESET_DELAY 2000
  43. //
  44. // Define the number of attempts to try certain commands.
  45. //
  46. #define SD_CARD_INITIALIZE_RETRY_COUNT 3
  47. #define SD_CARD_OPERATING_CONDITION_RETRY_COUNT 1000
  48. #define SD_CONFIGURATION_REGISTER_RETRY_COUNT 3
  49. #define SD_SWITCH_RETRY_COUNT 4
  50. #define SD_INTERFACE_CONDITION_RETRY_COUNT 10
  51. #define SD_SET_BLOCK_LENGTH_RETRY_COUNT 10
  52. //
  53. // Define the block sized used by the SD library.
  54. //
  55. #define SD_BLOCK_SIZE 512
  56. #define SD_MMC_MAX_BLOCK_SIZE 512
  57. //
  58. // Define the maximum number of blocks that can be sent in a single command.
  59. //
  60. #define SD_MAX_BLOCK_COUNT 0xFFFF
  61. //
  62. // Define the maximum number of times to retry I/O.
  63. //
  64. #define EFI_SD_IO_RETRIES 5
  65. //
  66. // ------------------------------------------------------ Data Type Definitions
  67. //
  68. /*++
  69. Structure Description:
  70. This structure defines the context for an SD/MMC controller instance.
  71. Members:
  72. ControllerBase - Stores a pointer to the base address of the host
  73. controller registers.
  74. ConsumerContext - Stores a context pointer passed to the function pointers
  75. contained in this structure.
  76. FunctionTable - Stores the table of functions used to perform SD operations
  77. that require accessing registers. This is either filled with the
  78. standard host controller routines or override routines supplied during
  79. initialization.
  80. GetCardDetectStatus - Stores an optional pointer to a function used to
  81. determine if there is a card in the slot.
  82. GetWriteProtectStatus - Stores an optional pointer to a function used to
  83. determine the state of the physical write protect switch on the card.
  84. Voltages - Stores a bitmask of supported voltages.
  85. Version - Stores the specification revision of the card.
  86. HighCapacity - Stores a boolean indicating if the card is high capacity or
  87. not.
  88. CardAddress - Stores the card address.
  89. BusWidth - Stores the width of the bus. Valid values are 1, 4 and 8.
  90. ClockSpeed - Stores the bus clock speed. This must start at the lowest
  91. setting (400kHz) until it's known how fast the card can go.
  92. FundamentalClock - Stores the fundamental clock speed in Hertz.
  93. ReadBlockLength - Stores the block length when reading blocks from the
  94. card.
  95. WriteBlockLength - Stores the block length when writing blocks to the
  96. card.
  97. UserCapacity - Stores the primary capacity of the controller, in bytes.
  98. BootCapacity - Stores the capacity of the boot partition, in bytes.
  99. RpmbCapacity - Stores the capacity of the Replay Protected Memory Block, in
  100. bytes.
  101. GeneralPartitionCapacity - Stores the capacity of the general partitions,
  102. in bytes.
  103. EraseGroupSize - Stores the erase group size of the card, in blocks.
  104. CardSpecificData - Stores the card specific data.
  105. PartitionConfiguration - Stores the partition configuration of this device.
  106. HostCapabilities - Stores the host controller capability bits.
  107. CardCapabilities - Stores the card capability bits.
  108. MaxBlocksPerTransfer - Stores the maximum number of blocks that can occur
  109. in a single transfer. The default is SD_MAX_BLOCK_COUNT.
  110. --*/
  111. struct _EFI_SD_CONTROLLER {
  112. VOID *ControllerBase;
  113. VOID *ConsumerContext;
  114. SD_FUNCTION_TABLE FunctionTable;
  115. PSD_GET_CARD_DETECT_STATUS GetCardDetectStatus;
  116. PSD_GET_WRITE_PROTECT_STATUS GetWriteProtectStatus;
  117. UINT32 Voltages;
  118. SD_VERSION Version;
  119. BOOLEAN HighCapacity;
  120. UINT16 CardAddress;
  121. UINT16 BusWidth;
  122. SD_CLOCK_SPEED ClockSpeed;
  123. UINT32 FundamentalClock;
  124. UINT32 ReadBlockLength;
  125. UINT32 WriteBlockLength;
  126. UINT64 UserCapacity;
  127. UINT64 BootCapacity;
  128. UINT64 RpmbCapacity;
  129. UINT64 GeneralPartitionCapacity[SD_MMC_GENERAL_PARTITION_COUNT];
  130. UINT32 EraseGroupSize;
  131. UINT32 CardSpecificData[4];
  132. UINT32 PartitionConfiguration;
  133. UINT32 HostCapabilities;
  134. UINT32 CardCapabilities;
  135. UINT32 MaxBlocksPerTransfer;
  136. };
  137. //
  138. // -------------------------------------------------------------------- Globals
  139. //
  140. //
  141. // Stores the standard SD host controller function table.
  142. //
  143. extern SD_FUNCTION_TABLE EfiSdStdFunctionTable;
  144. //
  145. // -------------------------------------------------------- Function Prototypes
  146. //