3 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #ifndef _SD_BLOCK_IO_PEI_H_
15 #define _SD_BLOCK_IO_PEI_H_
19 #include <Ppi/SdMmcHostController.h>
20 #include <Ppi/BlockIo.h>
21 #include <Ppi/BlockIo2.h>
23 #include <Library/DebugLib.h>
24 #include <Library/BaseLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/IoLib.h>
28 #include <Library/TimerLib.h>
29 #include <Library/PeiServicesLib.h>
31 #include <IndustryStandard/Sd.h>
33 typedef struct _SD_PEIM_HC_PRIVATE_DATA SD_PEIM_HC_PRIVATE_DATA
;
34 typedef struct _SD_PEIM_HC_SLOT SD_PEIM_HC_SLOT
;
35 typedef struct _SD_TRB SD_TRB
;
40 #define SD_PEIM_SIG SIGNATURE_32 ('S', 'D', 'C', 'P')
41 #define SD_PEIM_SLOT_SIG SIGNATURE_32 ('S', 'D', 'C', 'S')
43 #define SD_PEIM_MAX_SLOTS 6
45 struct _SD_PEIM_HC_SLOT
{
47 EFI_PEI_BLOCK_IO2_MEDIA Media
;
50 SD_HC_SLOT_CAP Capability
;
52 BOOLEAN SectorAddressing
;
53 SD_PEIM_HC_PRIVATE_DATA
*Private
;
56 struct _SD_PEIM_HC_PRIVATE_DATA
{
58 SD_PEIM_MEM_POOL
*Pool
;
59 EFI_PEI_RECOVERY_BLOCK_IO_PPI BlkIoPpi
;
60 EFI_PEI_RECOVERY_BLOCK_IO2_PPI BlkIo2Ppi
;
61 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList
;
62 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList
;
63 SD_PEIM_HC_SLOT Slot
[SD_PEIM_MAX_SLOTS
];
65 UINT8 TotalBlkIoDevices
;
68 #define SD_TIMEOUT MultU64x32((UINT64)(3), 1000000)
69 #define GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, SD_PEIM_HC_PRIVATE_DATA, BlkIoPpi, SD_PEIM_SIG)
70 #define GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, SD_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, SD_PEIM_SIG)
73 SD_PEIM_HC_SLOT
*Slot
;
76 SD_COMMAND_PACKET
*Packet
;
80 SD_HC_TRANSFER_MODE Mode
;
84 SD_HC_ADMA_DESC_LINE
*AdmaDesc
;
89 Gets the count of block I/O devices that one specific block driver detects.
91 This function is used for getting the count of block I/O devices that one
92 specific block driver detects. To the PEI ATAPI driver, it returns the number
93 of all the detected ATAPI devices it detects during the enumeration process.
94 To the PEI legacy floppy driver, it returns the number of all the legacy
95 devices it finds during its enumeration process. If no device is detected,
96 then the function will return zero.
98 @param[in] PeiServices General-purpose services that are available
100 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI
102 @param[out] NumberBlockDevices The number of block I/O devices discovered.
104 @retval EFI_SUCCESS The operation performed successfully.
109 SdBlockIoPeimGetDeviceNo (
110 IN EFI_PEI_SERVICES
**PeiServices
,
111 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
112 OUT UINTN
*NumberBlockDevices
116 Gets a block device's media information.
118 This function will provide the caller with the specified block device's media
119 information. If the media changes, calling this function will update the media
120 information accordingly.
122 @param[in] PeiServices General-purpose services that are available to every
124 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
125 @param[in] DeviceIndex Specifies the block device to which the function wants
126 to talk. Because the driver that implements Block I/O
127 PPIs will manage multiple block devices, the PPIs that
128 want to talk to a single device must specify the
129 device index that was assigned during the enumeration
130 process. This index is a number from one to
132 @param[out] MediaInfo The media information of the specified block media.
133 The caller is responsible for the ownership of this
137 The MediaInfo structure describes an enumeration of possible block device
138 types. This enumeration exists because no device paths are actually passed
139 across interfaces that describe the type or class of hardware that is publishing
140 the block I/O interface. This enumeration will allow for policy decisions
141 in the Recovery PEIM, such as "Try to recover from legacy floppy first,
142 LS-120 second, CD-ROM third." If there are multiple partitions abstracted
143 by a given device type, they should be reported in ascending order; this
144 order also applies to nested partitions, such as legacy MBR, where the
145 outermost partitions would have precedence in the reporting order. The
146 same logic applies to systems such as IDE that have precedence relationships
147 like "Master/Slave" or "Primary/Secondary". The master device should be
148 reported first, the slave second.
150 @retval EFI_SUCCESS Media information about the specified block device
151 was obtained successfully.
152 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
158 SdBlockIoPeimGetMediaInfo (
159 IN EFI_PEI_SERVICES
**PeiServices
,
160 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
161 IN UINTN DeviceIndex
,
162 OUT EFI_PEI_BLOCK_IO_MEDIA
*MediaInfo
166 Reads the requested number of blocks from the specified block device.
168 The function reads the requested number of blocks from the device. All the
169 blocks are read, or an error is returned. If there is no media in the device,
170 the function returns EFI_NO_MEDIA.
172 @param[in] PeiServices General-purpose services that are available to
174 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
175 @param[in] DeviceIndex Specifies the block device to which the function wants
176 to talk. Because the driver that implements Block I/O
177 PPIs will manage multiple block devices, PPIs that
178 want to talk to a single device must specify the device
179 index that was assigned during the enumeration process.
180 This index is a number from one to NumberBlockDevices.
181 @param[in] StartLBA The starting logical block address (LBA) to read from
183 @param[in] BufferSize The size of the Buffer in bytes. This number must be
184 a multiple of the intrinsic block size of the device.
185 @param[out] Buffer A pointer to the destination buffer for the data.
186 The caller is responsible for the ownership of the
189 @retval EFI_SUCCESS The data was read correctly from the device.
190 @retval EFI_DEVICE_ERROR The device reported an error while attempting
191 to perform the read operation.
192 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
193 valid, or the buffer is not properly aligned.
194 @retval EFI_NO_MEDIA There is no media in the device.
195 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
196 the intrinsic block size of the device.
201 SdBlockIoPeimReadBlocks (
202 IN EFI_PEI_SERVICES
**PeiServices
,
203 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
204 IN UINTN DeviceIndex
,
205 IN EFI_PEI_LBA StartLBA
,
211 Gets the count of block I/O devices that one specific block driver detects.
213 This function is used for getting the count of block I/O devices that one
214 specific block driver detects. To the PEI ATAPI driver, it returns the number
215 of all the detected ATAPI devices it detects during the enumeration process.
216 To the PEI legacy floppy driver, it returns the number of all the legacy
217 devices it finds during its enumeration process. If no device is detected,
218 then the function will return zero.
220 @param[in] PeiServices General-purpose services that are available
222 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI
224 @param[out] NumberBlockDevices The number of block I/O devices discovered.
226 @retval EFI_SUCCESS The operation performed successfully.
231 SdBlockIoPeimGetDeviceNo2 (
232 IN EFI_PEI_SERVICES
**PeiServices
,
233 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
234 OUT UINTN
*NumberBlockDevices
238 Gets a block device's media information.
240 This function will provide the caller with the specified block device's media
241 information. If the media changes, calling this function will update the media
242 information accordingly.
244 @param[in] PeiServices General-purpose services that are available to every
246 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.
247 @param[in] DeviceIndex Specifies the block device to which the function wants
248 to talk. Because the driver that implements Block I/O
249 PPIs will manage multiple block devices, the PPIs that
250 want to talk to a single device must specify the
251 device index that was assigned during the enumeration
252 process. This index is a number from one to
254 @param[out] MediaInfo The media information of the specified block media.
255 The caller is responsible for the ownership of this
259 The MediaInfo structure describes an enumeration of possible block device
260 types. This enumeration exists because no device paths are actually passed
261 across interfaces that describe the type or class of hardware that is publishing
262 the block I/O interface. This enumeration will allow for policy decisions
263 in the Recovery PEIM, such as "Try to recover from legacy floppy first,
264 LS-120 second, CD-ROM third." If there are multiple partitions abstracted
265 by a given device type, they should be reported in ascending order; this
266 order also applies to nested partitions, such as legacy MBR, where the
267 outermost partitions would have precedence in the reporting order. The
268 same logic applies to systems such as IDE that have precedence relationships
269 like "Master/Slave" or "Primary/Secondary". The master device should be
270 reported first, the slave second.
272 @retval EFI_SUCCESS Media information about the specified block device
273 was obtained successfully.
274 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
280 SdBlockIoPeimGetMediaInfo2 (
281 IN EFI_PEI_SERVICES
**PeiServices
,
282 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
283 IN UINTN DeviceIndex
,
284 OUT EFI_PEI_BLOCK_IO2_MEDIA
*MediaInfo
288 Reads the requested number of blocks from the specified block device.
290 The function reads the requested number of blocks from the device. All the
291 blocks are read, or an error is returned. If there is no media in the device,
292 the function returns EFI_NO_MEDIA.
294 @param[in] PeiServices General-purpose services that are available to
296 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.
297 @param[in] DeviceIndex Specifies the block device to which the function wants
298 to talk. Because the driver that implements Block I/O
299 PPIs will manage multiple block devices, PPIs that
300 want to talk to a single device must specify the device
301 index that was assigned during the enumeration process.
302 This index is a number from one to NumberBlockDevices.
303 @param[in] StartLBA The starting logical block address (LBA) to read from
305 @param[in] BufferSize The size of the Buffer in bytes. This number must be
306 a multiple of the intrinsic block size of the device.
307 @param[out] Buffer A pointer to the destination buffer for the data.
308 The caller is responsible for the ownership of the
311 @retval EFI_SUCCESS The data was read correctly from the device.
312 @retval EFI_DEVICE_ERROR The device reported an error while attempting
313 to perform the read operation.
314 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
315 valid, or the buffer is not properly aligned.
316 @retval EFI_NO_MEDIA There is no media in the device.
317 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
318 the intrinsic block size of the device.
323 SdBlockIoPeimReadBlocks2 (
324 IN EFI_PEI_SERVICES
**PeiServices
,
325 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
326 IN UINTN DeviceIndex
,
327 IN EFI_PEI_LBA StartLBA
,
333 Initialize the memory management pool for the host controller.
335 @param Private The Sd Peim driver private data.
337 @retval EFI_SUCCESS The memory pool is initialized.
338 @retval Others Fail to init the memory pool.
343 IN SD_PEIM_HC_PRIVATE_DATA
*Private
347 Allocate some memory from the host controller's memory pool
348 which can be used to communicate with host controller.
350 @param Pool The host controller's memory pool.
351 @param Size Size of the memory to allocate.
353 @return The allocated memory or NULL.
358 IN SD_PEIM_MEM_POOL
*Pool
,
363 Free the allocated memory back to the memory pool.
365 @param Pool The memory pool of the host controller.
366 @param Mem The memory to free.
367 @param Size The size of the memory to free.
372 IN SD_PEIM_MEM_POOL
*Pool
,