3 Copyright (c) 2015 - 2017, 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>
22 #include <Ppi/IoMmu.h>
23 #include <Ppi/EndOfPeiPhase.h>
25 #include <Library/DebugLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/IoLib.h>
30 #include <Library/TimerLib.h>
31 #include <Library/PeiServicesLib.h>
33 #include <IndustryStandard/Sd.h>
35 typedef struct _SD_PEIM_HC_PRIVATE_DATA SD_PEIM_HC_PRIVATE_DATA
;
36 typedef struct _SD_PEIM_HC_SLOT SD_PEIM_HC_SLOT
;
37 typedef struct _SD_TRB SD_TRB
;
42 #define SD_PEIM_SIG SIGNATURE_32 ('S', 'D', 'C', 'P')
43 #define SD_PEIM_SLOT_SIG SIGNATURE_32 ('S', 'D', 'C', 'S')
45 #define SD_PEIM_MAX_SLOTS 6
47 struct _SD_PEIM_HC_SLOT
{
49 EFI_PEI_BLOCK_IO2_MEDIA Media
;
52 SD_HC_SLOT_CAP Capability
;
54 BOOLEAN SectorAddressing
;
55 SD_PEIM_HC_PRIVATE_DATA
*Private
;
58 struct _SD_PEIM_HC_PRIVATE_DATA
{
60 SD_PEIM_MEM_POOL
*Pool
;
61 EFI_PEI_RECOVERY_BLOCK_IO_PPI BlkIoPpi
;
62 EFI_PEI_RECOVERY_BLOCK_IO2_PPI BlkIo2Ppi
;
63 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList
;
64 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList
;
67 // EndOfPei callback is used to do the cleanups before exit of PEI phase.
69 EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList
;
71 SD_PEIM_HC_SLOT Slot
[SD_PEIM_MAX_SLOTS
];
73 UINT8 TotalBlkIoDevices
;
76 #define SD_TIMEOUT MultU64x32((UINT64)(3), 1000000)
77 #define GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, SD_PEIM_HC_PRIVATE_DATA, BlkIoPpi, SD_PEIM_SIG)
78 #define GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, SD_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, SD_PEIM_SIG)
79 #define GET_SD_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) CR (a, SD_PEIM_HC_PRIVATE_DATA, EndOfPeiNotifyList, SD_PEIM_SIG)
82 SD_PEIM_HC_SLOT
*Slot
;
85 SD_COMMAND_PACKET
*Packet
;
89 EFI_PHYSICAL_ADDRESS DataPhy
;
91 SD_HC_TRANSFER_MODE Mode
;
95 SD_HC_ADMA_DESC_LINE
*AdmaDesc
;
100 Gets the count of block I/O devices that one specific block driver detects.
102 This function is used for getting the count of block I/O devices that one
103 specific block driver detects. To the PEI ATAPI driver, it returns the number
104 of all the detected ATAPI devices it detects during the enumeration process.
105 To the PEI legacy floppy driver, it returns the number of all the legacy
106 devices it finds during its enumeration process. If no device is detected,
107 then the function will return zero.
109 @param[in] PeiServices General-purpose services that are available
111 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI
113 @param[out] NumberBlockDevices The number of block I/O devices discovered.
115 @retval EFI_SUCCESS The operation performed successfully.
120 SdBlockIoPeimGetDeviceNo (
121 IN EFI_PEI_SERVICES
**PeiServices
,
122 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
123 OUT UINTN
*NumberBlockDevices
127 Gets a block device's media information.
129 This function will provide the caller with the specified block device's media
130 information. If the media changes, calling this function will update the media
131 information accordingly.
133 @param[in] PeiServices General-purpose services that are available to every
135 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
136 @param[in] DeviceIndex Specifies the block device to which the function wants
137 to talk. Because the driver that implements Block I/O
138 PPIs will manage multiple block devices, the PPIs that
139 want to talk to a single device must specify the
140 device index that was assigned during the enumeration
141 process. This index is a number from one to
143 @param[out] MediaInfo The media information of the specified block media.
144 The caller is responsible for the ownership of this
148 The MediaInfo structure describes an enumeration of possible block device
149 types. This enumeration exists because no device paths are actually passed
150 across interfaces that describe the type or class of hardware that is publishing
151 the block I/O interface. This enumeration will allow for policy decisions
152 in the Recovery PEIM, such as "Try to recover from legacy floppy first,
153 LS-120 second, CD-ROM third." If there are multiple partitions abstracted
154 by a given device type, they should be reported in ascending order; this
155 order also applies to nested partitions, such as legacy MBR, where the
156 outermost partitions would have precedence in the reporting order. The
157 same logic applies to systems such as IDE that have precedence relationships
158 like "Master/Slave" or "Primary/Secondary". The master device should be
159 reported first, the slave second.
161 @retval EFI_SUCCESS Media information about the specified block device
162 was obtained successfully.
163 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
169 SdBlockIoPeimGetMediaInfo (
170 IN EFI_PEI_SERVICES
**PeiServices
,
171 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
172 IN UINTN DeviceIndex
,
173 OUT EFI_PEI_BLOCK_IO_MEDIA
*MediaInfo
177 Reads the requested number of blocks from the specified block device.
179 The function reads the requested number of blocks from the device. All the
180 blocks are read, or an error is returned. If there is no media in the device,
181 the function returns EFI_NO_MEDIA.
183 @param[in] PeiServices General-purpose services that are available to
185 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
186 @param[in] DeviceIndex Specifies the block device to which the function wants
187 to talk. Because the driver that implements Block I/O
188 PPIs will manage multiple block devices, PPIs that
189 want to talk to a single device must specify the device
190 index that was assigned during the enumeration process.
191 This index is a number from one to NumberBlockDevices.
192 @param[in] StartLBA The starting logical block address (LBA) to read from
194 @param[in] BufferSize The size of the Buffer in bytes. This number must be
195 a multiple of the intrinsic block size of the device.
196 @param[out] Buffer A pointer to the destination buffer for the data.
197 The caller is responsible for the ownership of the
200 @retval EFI_SUCCESS The data was read correctly from the device.
201 @retval EFI_DEVICE_ERROR The device reported an error while attempting
202 to perform the read operation.
203 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
204 valid, or the buffer is not properly aligned.
205 @retval EFI_NO_MEDIA There is no media in the device.
206 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
207 the intrinsic block size of the device.
212 SdBlockIoPeimReadBlocks (
213 IN EFI_PEI_SERVICES
**PeiServices
,
214 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
215 IN UINTN DeviceIndex
,
216 IN EFI_PEI_LBA StartLBA
,
222 Gets the count of block I/O devices that one specific block driver detects.
224 This function is used for getting the count of block I/O devices that one
225 specific block driver detects. To the PEI ATAPI driver, it returns the number
226 of all the detected ATAPI devices it detects during the enumeration process.
227 To the PEI legacy floppy driver, it returns the number of all the legacy
228 devices it finds during its enumeration process. If no device is detected,
229 then the function will return zero.
231 @param[in] PeiServices General-purpose services that are available
233 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI
235 @param[out] NumberBlockDevices The number of block I/O devices discovered.
237 @retval EFI_SUCCESS The operation performed successfully.
242 SdBlockIoPeimGetDeviceNo2 (
243 IN EFI_PEI_SERVICES
**PeiServices
,
244 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
245 OUT UINTN
*NumberBlockDevices
249 Gets a block device's media information.
251 This function will provide the caller with the specified block device's media
252 information. If the media changes, calling this function will update the media
253 information accordingly.
255 @param[in] PeiServices General-purpose services that are available to every
257 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.
258 @param[in] DeviceIndex Specifies the block device to which the function wants
259 to talk. Because the driver that implements Block I/O
260 PPIs will manage multiple block devices, the PPIs that
261 want to talk to a single device must specify the
262 device index that was assigned during the enumeration
263 process. This index is a number from one to
265 @param[out] MediaInfo The media information of the specified block media.
266 The caller is responsible for the ownership of this
270 The MediaInfo structure describes an enumeration of possible block device
271 types. This enumeration exists because no device paths are actually passed
272 across interfaces that describe the type or class of hardware that is publishing
273 the block I/O interface. This enumeration will allow for policy decisions
274 in the Recovery PEIM, such as "Try to recover from legacy floppy first,
275 LS-120 second, CD-ROM third." If there are multiple partitions abstracted
276 by a given device type, they should be reported in ascending order; this
277 order also applies to nested partitions, such as legacy MBR, where the
278 outermost partitions would have precedence in the reporting order. The
279 same logic applies to systems such as IDE that have precedence relationships
280 like "Master/Slave" or "Primary/Secondary". The master device should be
281 reported first, the slave second.
283 @retval EFI_SUCCESS Media information about the specified block device
284 was obtained successfully.
285 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
291 SdBlockIoPeimGetMediaInfo2 (
292 IN EFI_PEI_SERVICES
**PeiServices
,
293 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
294 IN UINTN DeviceIndex
,
295 OUT EFI_PEI_BLOCK_IO2_MEDIA
*MediaInfo
299 Reads the requested number of blocks from the specified block device.
301 The function reads the requested number of blocks from the device. All the
302 blocks are read, or an error is returned. If there is no media in the device,
303 the function returns EFI_NO_MEDIA.
305 @param[in] PeiServices General-purpose services that are available to
307 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.
308 @param[in] DeviceIndex Specifies the block device to which the function wants
309 to talk. Because the driver that implements Block I/O
310 PPIs will manage multiple block devices, PPIs that
311 want to talk to a single device must specify the device
312 index that was assigned during the enumeration process.
313 This index is a number from one to NumberBlockDevices.
314 @param[in] StartLBA The starting logical block address (LBA) to read from
316 @param[in] BufferSize The size of the Buffer in bytes. This number must be
317 a multiple of the intrinsic block size of the device.
318 @param[out] Buffer A pointer to the destination buffer for the data.
319 The caller is responsible for the ownership of the
322 @retval EFI_SUCCESS The data was read correctly from the device.
323 @retval EFI_DEVICE_ERROR The device reported an error while attempting
324 to perform the read operation.
325 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
326 valid, or the buffer is not properly aligned.
327 @retval EFI_NO_MEDIA There is no media in the device.
328 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
329 the intrinsic block size of the device.
334 SdBlockIoPeimReadBlocks2 (
335 IN EFI_PEI_SERVICES
**PeiServices
,
336 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
337 IN UINTN DeviceIndex
,
338 IN EFI_PEI_LBA StartLBA
,
344 Initialize the memory management pool for the host controller.
346 @param Private The Sd Peim driver private data.
348 @retval EFI_SUCCESS The memory pool is initialized.
349 @retval Others Fail to init the memory pool.
354 IN SD_PEIM_HC_PRIVATE_DATA
*Private
358 Release the memory management pool.
360 @param Pool The memory pool to free.
362 @retval EFI_DEVICE_ERROR Fail to free the memory pool.
363 @retval EFI_SUCCESS The memory pool is freed.
368 IN SD_PEIM_MEM_POOL
*Pool
372 Allocate some memory from the host controller's memory pool
373 which can be used to communicate with host controller.
375 @param Pool The host controller's memory pool.
376 @param Size Size of the memory to allocate.
378 @return The allocated memory or NULL.
383 IN SD_PEIM_MEM_POOL
*Pool
,
388 Free the allocated memory back to the memory pool.
390 @param Pool The memory pool of the host controller.
391 @param Mem The memory to free.
392 @param Size The size of the memory to free.
397 IN SD_PEIM_MEM_POOL
*Pool
,
411 Provides the controller-specific addresses required to access system memory from a
414 @param Operation Indicates if the bus master is going to read or write to system memory.
415 @param HostAddress The system memory address to map to the PCI controller.
416 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
418 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
419 access the hosts HostAddress.
420 @param Mapping A resulting value to pass to Unmap().
422 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
423 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
424 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
425 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
426 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
431 IN EDKII_IOMMU_OPERATION Operation
,
432 IN VOID
*HostAddress
,
433 IN OUT UINTN
*NumberOfBytes
,
434 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
439 Completes the Map() operation and releases any corresponding resources.
441 @param Mapping The mapping value returned from Map().
443 @retval EFI_SUCCESS The range was unmapped.
444 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
445 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
453 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
454 OperationBusMasterCommonBuffer64 mapping.
456 @param Pages The number of pages to allocate.
457 @param HostAddress A pointer to store the base system memory address of the
459 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
460 access the hosts HostAddress.
461 @param Mapping A resulting value to pass to Unmap().
463 @retval EFI_SUCCESS The requested memory pages were allocated.
464 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
465 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
466 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
467 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
471 IoMmuAllocateBuffer (
473 OUT VOID
**HostAddress
,
474 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
479 Frees memory that was allocated with AllocateBuffer().
481 @param Pages The number of pages to free.
482 @param HostAddress The base system memory address of the allocated range.
483 @param Mapping The mapping value returned from Map().
485 @retval EFI_SUCCESS The requested memory pages were freed.
486 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
487 was not allocated with AllocateBuffer().
493 IN VOID
*HostAddress
,
498 One notified function to cleanup the allocated DMA buffers at the end of PEI.
500 @param[in] PeiServices Pointer to PEI Services Table.
501 @param[in] NotifyDescriptor Pointer to the descriptor for the Notification
502 event that caused this function to execute.
503 @param[in] Ppi Pointer to the PPI data associated with this function.
505 @retval EFI_SUCCESS The function completes successfully
510 SdBlockIoPeimEndOfPei (
511 IN EFI_PEI_SERVICES
**PeiServices
,
512 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,