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 _EMMC_BLOCK_IO_PEI_H_
15 #define _EMMC_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/Emmc.h>
35 typedef struct _EMMC_PEIM_HC_PRIVATE_DATA EMMC_PEIM_HC_PRIVATE_DATA
;
36 typedef struct _EMMC_PEIM_HC_SLOT EMMC_PEIM_HC_SLOT
;
37 typedef struct _EMMC_TRB EMMC_TRB
;
40 #include "EmmcHcMem.h"
42 #define EMMC_PEIM_SIG SIGNATURE_32 ('E', 'M', 'C', 'P')
43 #define EMMC_PEIM_SLOT_SIG SIGNATURE_32 ('E', 'M', 'C', 'S')
45 #define EMMC_PEIM_MAX_SLOTS 6
46 #define EMMC_PEIM_MAX_PARTITIONS 8
48 struct _EMMC_PEIM_HC_SLOT
{
50 EFI_PEI_BLOCK_IO2_MEDIA Media
[EMMC_PEIM_MAX_PARTITIONS
];
52 EMMC_PARTITION_TYPE PartitionType
[EMMC_PEIM_MAX_PARTITIONS
];
55 EMMC_HC_SLOT_CAP Capability
;
58 BOOLEAN SectorAddressing
;
59 EMMC_PEIM_HC_PRIVATE_DATA
*Private
;
62 struct _EMMC_PEIM_HC_PRIVATE_DATA
{
64 EMMC_PEIM_MEM_POOL
*Pool
;
65 EFI_PEI_RECOVERY_BLOCK_IO_PPI BlkIoPpi
;
66 EFI_PEI_RECOVERY_BLOCK_IO2_PPI BlkIo2Ppi
;
67 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList
;
68 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList
;
71 // EndOfPei callback is used to do the cleanups before exit of PEI phase.
73 EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList
;
75 EMMC_PEIM_HC_SLOT Slot
[EMMC_PEIM_MAX_SLOTS
];
77 UINT8 TotalBlkIoDevices
;
80 #define EMMC_TIMEOUT MultU64x32((UINT64)(3), 1000000)
81 #define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIoPpi, EMMC_PEIM_SIG)
82 #define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, EMMC_PEIM_SIG)
83 #define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, EndOfPeiNotifyList, EMMC_PEIM_SIG)
86 EMMC_PEIM_HC_SLOT
*Slot
;
89 EMMC_COMMAND_PACKET
*Packet
;
93 EFI_PHYSICAL_ADDRESS DataPhy
;
95 EMMC_HC_TRANSFER_MODE Mode
;
99 EMMC_HC_ADMA_DESC_LINE
*AdmaDesc
;
104 Gets the count of block I/O devices that one specific block driver detects.
106 This function is used for getting the count of block I/O devices that one
107 specific block driver detects. To the PEI ATAPI driver, it returns the number
108 of all the detected ATAPI devices it detects during the enumeration process.
109 To the PEI legacy floppy driver, it returns the number of all the legacy
110 devices it finds during its enumeration process. If no device is detected,
111 then the function will return zero.
113 @param[in] PeiServices General-purpose services that are available
115 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI
117 @param[out] NumberBlockDevices The number of block I/O devices discovered.
119 @retval EFI_SUCCESS The operation performed successfully.
124 EmmcBlockIoPeimGetDeviceNo (
125 IN EFI_PEI_SERVICES
**PeiServices
,
126 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
127 OUT UINTN
*NumberBlockDevices
131 Gets a block device's media information.
133 This function will provide the caller with the specified block device's media
134 information. If the media changes, calling this function will update the media
135 information accordingly.
137 @param[in] PeiServices General-purpose services that are available to every
139 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
140 @param[in] DeviceIndex Specifies the block device to which the function wants
141 to talk. Because the driver that implements Block I/O
142 PPIs will manage multiple block devices, the PPIs that
143 want to talk to a single device must specify the
144 device index that was assigned during the enumeration
145 process. This index is a number from one to
147 @param[out] MediaInfo The media information of the specified block media.
148 The caller is responsible for the ownership of this
152 The MediaInfo structure describes an enumeration of possible block device
153 types. This enumeration exists because no device paths are actually passed
154 across interfaces that describe the type or class of hardware that is publishing
155 the block I/O interface. This enumeration will allow for policy decisions
156 in the Recovery PEIM, such as "Try to recover from legacy floppy first,
157 LS-120 second, CD-ROM third." If there are multiple partitions abstracted
158 by a given device type, they should be reported in ascending order; this
159 order also applies to nested partitions, such as legacy MBR, where the
160 outermost partitions would have precedence in the reporting order. The
161 same logic applies to systems such as IDE that have precedence relationships
162 like "Master/Slave" or "Primary/Secondary". The master device should be
163 reported first, the slave second.
165 @retval EFI_SUCCESS Media information about the specified block device
166 was obtained successfully.
167 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
173 EmmcBlockIoPeimGetMediaInfo (
174 IN EFI_PEI_SERVICES
**PeiServices
,
175 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
176 IN UINTN DeviceIndex
,
177 OUT EFI_PEI_BLOCK_IO_MEDIA
*MediaInfo
181 Reads the requested number of blocks from the specified block device.
183 The function reads the requested number of blocks from the device. All the
184 blocks are read, or an error is returned. If there is no media in the device,
185 the function returns EFI_NO_MEDIA.
187 @param[in] PeiServices General-purpose services that are available to
189 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
190 @param[in] DeviceIndex Specifies the block device to which the function wants
191 to talk. Because the driver that implements Block I/O
192 PPIs will manage multiple block devices, PPIs that
193 want to talk to a single device must specify the device
194 index that was assigned during the enumeration process.
195 This index is a number from one to NumberBlockDevices.
196 @param[in] StartLBA The starting logical block address (LBA) to read from
198 @param[in] BufferSize The size of the Buffer in bytes. This number must be
199 a multiple of the intrinsic block size of the device.
200 @param[out] Buffer A pointer to the destination buffer for the data.
201 The caller is responsible for the ownership of the
204 @retval EFI_SUCCESS The data was read correctly from the device.
205 @retval EFI_DEVICE_ERROR The device reported an error while attempting
206 to perform the read operation.
207 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
208 valid, or the buffer is not properly aligned.
209 @retval EFI_NO_MEDIA There is no media in the device.
210 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
211 the intrinsic block size of the device.
216 EmmcBlockIoPeimReadBlocks (
217 IN EFI_PEI_SERVICES
**PeiServices
,
218 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
219 IN UINTN DeviceIndex
,
220 IN EFI_PEI_LBA StartLBA
,
226 Gets the count of block I/O devices that one specific block driver detects.
228 This function is used for getting the count of block I/O devices that one
229 specific block driver detects. To the PEI ATAPI driver, it returns the number
230 of all the detected ATAPI devices it detects during the enumeration process.
231 To the PEI legacy floppy driver, it returns the number of all the legacy
232 devices it finds during its enumeration process. If no device is detected,
233 then the function will return zero.
235 @param[in] PeiServices General-purpose services that are available
237 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI
239 @param[out] NumberBlockDevices The number of block I/O devices discovered.
241 @retval EFI_SUCCESS The operation performed successfully.
246 EmmcBlockIoPeimGetDeviceNo2 (
247 IN EFI_PEI_SERVICES
**PeiServices
,
248 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
249 OUT UINTN
*NumberBlockDevices
253 Gets a block device's media information.
255 This function will provide the caller with the specified block device's media
256 information. If the media changes, calling this function will update the media
257 information accordingly.
259 @param[in] PeiServices General-purpose services that are available to every
261 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.
262 @param[in] DeviceIndex Specifies the block device to which the function wants
263 to talk. Because the driver that implements Block I/O
264 PPIs will manage multiple block devices, the PPIs that
265 want to talk to a single device must specify the
266 device index that was assigned during the enumeration
267 process. This index is a number from one to
269 @param[out] MediaInfo The media information of the specified block media.
270 The caller is responsible for the ownership of this
274 The MediaInfo structure describes an enumeration of possible block device
275 types. This enumeration exists because no device paths are actually passed
276 across interfaces that describe the type or class of hardware that is publishing
277 the block I/O interface. This enumeration will allow for policy decisions
278 in the Recovery PEIM, such as "Try to recover from legacy floppy first,
279 LS-120 second, CD-ROM third." If there are multiple partitions abstracted
280 by a given device type, they should be reported in ascending order; this
281 order also applies to nested partitions, such as legacy MBR, where the
282 outermost partitions would have precedence in the reporting order. The
283 same logic applies to systems such as IDE that have precedence relationships
284 like "Master/Slave" or "Primary/Secondary". The master device should be
285 reported first, the slave second.
287 @retval EFI_SUCCESS Media information about the specified block device
288 was obtained successfully.
289 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
295 EmmcBlockIoPeimGetMediaInfo2 (
296 IN EFI_PEI_SERVICES
**PeiServices
,
297 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
298 IN UINTN DeviceIndex
,
299 OUT EFI_PEI_BLOCK_IO2_MEDIA
*MediaInfo
303 Reads the requested number of blocks from the specified block device.
305 The function reads the requested number of blocks from the device. All the
306 blocks are read, or an error is returned. If there is no media in the device,
307 the function returns EFI_NO_MEDIA.
309 @param[in] PeiServices General-purpose services that are available to
311 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.
312 @param[in] DeviceIndex Specifies the block device to which the function wants
313 to talk. Because the driver that implements Block I/O
314 PPIs will manage multiple block devices, PPIs that
315 want to talk to a single device must specify the device
316 index that was assigned during the enumeration process.
317 This index is a number from one to NumberBlockDevices.
318 @param[in] StartLBA The starting logical block address (LBA) to read from
320 @param[in] BufferSize The size of the Buffer in bytes. This number must be
321 a multiple of the intrinsic block size of the device.
322 @param[out] Buffer A pointer to the destination buffer for the data.
323 The caller is responsible for the ownership of the
326 @retval EFI_SUCCESS The data was read correctly from the device.
327 @retval EFI_DEVICE_ERROR The device reported an error while attempting
328 to perform the read operation.
329 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
330 valid, or the buffer is not properly aligned.
331 @retval EFI_NO_MEDIA There is no media in the device.
332 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
333 the intrinsic block size of the device.
338 EmmcBlockIoPeimReadBlocks2 (
339 IN EFI_PEI_SERVICES
**PeiServices
,
340 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
341 IN UINTN DeviceIndex
,
342 IN EFI_PEI_LBA StartLBA
,
348 Initialize the memory management pool for the host controller.
350 @param Private The Emmc Peim driver private data.
352 @retval EFI_SUCCESS The memory pool is initialized.
353 @retval Others Fail to init the memory pool.
357 EmmcPeimInitMemPool (
358 IN EMMC_PEIM_HC_PRIVATE_DATA
*Private
362 Release the memory management pool.
364 @param Pool The memory pool to free.
366 @retval EFI_DEVICE_ERROR Fail to free the memory pool.
367 @retval EFI_SUCCESS The memory pool is freed.
371 EmmcPeimFreeMemPool (
372 IN EMMC_PEIM_MEM_POOL
*Pool
376 Allocate some memory from the host controller's memory pool
377 which can be used to communicate with host controller.
379 @param Pool The host controller's memory pool.
380 @param Size Size of the memory to allocate.
382 @return The allocated memory or NULL.
386 EmmcPeimAllocateMem (
387 IN EMMC_PEIM_MEM_POOL
*Pool
,
392 Free the allocated memory back to the memory pool.
394 @param Pool The memory pool of the host controller.
395 @param Mem The memory to free.
396 @param Size The size of the memory to free.
401 IN EMMC_PEIM_MEM_POOL
*Pool
,
415 Provides the controller-specific addresses required to access system memory from a
418 @param Operation Indicates if the bus master is going to read or write to system memory.
419 @param HostAddress The system memory address to map to the PCI controller.
420 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
422 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
423 access the hosts HostAddress.
424 @param Mapping A resulting value to pass to Unmap().
426 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
427 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
428 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
429 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
430 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
435 IN EDKII_IOMMU_OPERATION Operation
,
436 IN VOID
*HostAddress
,
437 IN OUT UINTN
*NumberOfBytes
,
438 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
443 Completes the Map() operation and releases any corresponding resources.
445 @param Mapping The mapping value returned from Map().
447 @retval EFI_SUCCESS The range was unmapped.
448 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
449 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
457 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
458 OperationBusMasterCommonBuffer64 mapping.
460 @param Pages The number of pages to allocate.
461 @param HostAddress A pointer to store the base system memory address of the
463 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
464 access the hosts HostAddress.
465 @param Mapping A resulting value to pass to Unmap().
467 @retval EFI_SUCCESS The requested memory pages were allocated.
468 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
469 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
470 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
471 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
475 IoMmuAllocateBuffer (
477 OUT VOID
**HostAddress
,
478 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
483 Frees memory that was allocated with AllocateBuffer().
485 @param Pages The number of pages to free.
486 @param HostAddress The base system memory address of the allocated range.
487 @param Mapping The mapping value returned from Map().
489 @retval EFI_SUCCESS The requested memory pages were freed.
490 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
491 was not allocated with AllocateBuffer().
497 IN VOID
*HostAddress
,
502 One notified function to cleanup the allocated DMA buffers at the end of PEI.
504 @param[in] PeiServices Pointer to PEI Services Table.
505 @param[in] NotifyDescriptor Pointer to the descriptor for the Notification
506 event that caused this function to execute.
507 @param[in] Ppi Pointer to the PPI data associated with this function.
509 @retval EFI_SUCCESS The function completes successfully
514 EmmcBlockIoPeimEndOfPei (
515 IN EFI_PEI_SERVICES
**PeiServices
,
516 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,