2 Header file for EmmcDxe Driver.
4 This file defines common data structures, macro definitions and some module
5 internal function header files.
7 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <IndustryStandard/Emmc.h>
24 #include <Protocol/SdMmcPassThru.h>
25 #include <Protocol/BlockIo.h>
26 #include <Protocol/BlockIo2.h>
27 #include <Protocol/StorageSecurityCommand.h>
28 #include <Protocol/EraseBlock.h>
29 #include <Protocol/DiskInfo.h>
31 #include <Protocol/DevicePath.h>
33 #include <Library/DebugLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/BaseLib.h>
36 #include <Library/UefiLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/MemoryAllocationLib.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/DevicePathLib.h>
41 #include <Library/UefiRuntimeServicesTableLib.h>
43 #include "EmmcBlockIo.h"
44 #include "EmmcDiskInfo.h"
49 extern EFI_DRIVER_BINDING_PROTOCOL gEmmcDxeDriverBinding
;
50 extern EFI_COMPONENT_NAME_PROTOCOL gEmmcDxeComponentName
;
51 extern EFI_COMPONENT_NAME2_PROTOCOL gEmmcDxeComponentName2
;
53 #define EMMC_PARTITION_SIGNATURE SIGNATURE_32 ('E', 'm', 'm', 'P')
55 #define EMMC_PARTITION_DATA_FROM_BLKIO(a) \
56 CR(a, EMMC_PARTITION, BlockIo, EMMC_PARTITION_SIGNATURE)
58 #define EMMC_PARTITION_DATA_FROM_BLKIO2(a) \
59 CR(a, EMMC_PARTITION, BlockIo2, EMMC_PARTITION_SIGNATURE)
61 #define EMMC_PARTITION_DATA_FROM_SSP(a) \
62 CR(a, EMMC_PARTITION, StorageSecurity, EMMC_PARTITION_SIGNATURE)
64 #define EMMC_PARTITION_DATA_FROM_ERASEBLK(a) \
65 CR(a, EMMC_PARTITION, EraseBlock, EMMC_PARTITION_SIGNATURE)
67 #define EMMC_PARTITION_DATA_FROM_DISKINFO(a) \
68 CR(a, EMMC_PARTITION, DiskInfo, EMMC_PARTITION_SIGNATURE)
71 // Take 2.5 seconds as generic time out value, 1 microsecond as unit.
73 #define EMMC_GENERIC_TIMEOUT 2500 * 1000
75 #define EMMC_REQUEST_SIGNATURE SIGNATURE_32 ('E', 'm', 'R', 'e')
77 typedef struct _EMMC_DEVICE EMMC_DEVICE
;
78 typedef struct _EMMC_DRIVER_PRIVATE_DATA EMMC_DRIVER_PRIVATE_DATA
;
81 // Asynchronous I/O request.
87 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
88 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
89 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
93 EFI_BLOCK_IO2_TOKEN
*Token
;
97 #define EMMC_REQUEST_FROM_LINK(a) \
98 CR(a, EMMC_REQUEST, Link, EMMC_REQUEST_SIGNATURE)
103 EMMC_PARTITION_TYPE PartitionType
;
105 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
106 EFI_BLOCK_IO_PROTOCOL BlockIo
;
107 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
108 EFI_BLOCK_IO_MEDIA BlockMedia
;
109 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL StorageSecurity
;
110 EFI_ERASE_BLOCK_PROTOCOL EraseBlock
;
111 EFI_DISK_INFO_PROTOCOL DiskInfo
;
119 // Up to 6 slots per EMMC PCI host controller
121 #define EMMC_MAX_DEVICES 6
123 // Up to 8 partitions per EMMC device.
125 #define EMMC_MAX_PARTITIONS 8
126 #define EMMC_MODEL_NAME_MAX_LEN 32
128 struct _EMMC_DEVICE
{
130 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
132 BOOLEAN SectorAddressing
;
134 EMMC_PARTITION Partition
[EMMC_MAX_PARTITIONS
];
138 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
140 // The model name consists of three fields in CID register
141 // 1) OEM/Application ID (2 bytes)
142 // 2) Product Name (5 bytes)
143 // 3) Product Serial Number (4 bytes)
144 // The delimiters of these fields are whitespace.
146 CHAR16 ModelName
[EMMC_MODEL_NAME_MAX_LEN
];
147 EMMC_DRIVER_PRIVATE_DATA
*Private
;
151 // EMMC DXE driver private data structure
153 struct _EMMC_DRIVER_PRIVATE_DATA
{
154 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
155 EFI_HANDLE Controller
;
156 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
157 EFI_HANDLE DriverBindingHandle
;
159 EMMC_DEVICE Device
[EMMC_MAX_DEVICES
];
163 Tests to see if this driver supports a given controller. If a child device is provided,
164 it further tests to see if this driver supports creating a handle for the specified child device.
166 This function checks to see if the driver specified by This supports the device specified by
167 ControllerHandle. Drivers will typically use the device path attached to
168 ControllerHandle and/or the services from the bus I/O abstraction attached to
169 ControllerHandle to determine if the driver supports ControllerHandle. This function
170 may be called many times during platform initialization. In order to reduce boot times, the tests
171 performed by this function must be very small, and take as little time as possible to execute. This
172 function must not change the state of any hardware devices, and this function must be aware that the
173 device specified by ControllerHandle may already be managed by the same driver or a
174 different driver. This function must match its calls to AllocatePages() with FreePages(),
175 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
176 Since ControllerHandle may have been previously started by the same driver, if a protocol is
177 already in the opened state, then it must not be closed with CloseProtocol(). This is required
178 to guarantee the state of ControllerHandle is not modified by this function.
180 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
181 @param[in] ControllerHandle The handle of the controller to test. This handle
182 must support a protocol interface that supplies
183 an I/O abstraction to the driver.
184 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
185 parameter is ignored by device drivers, and is optional for bus
186 drivers. For bus drivers, if this parameter is not NULL, then
187 the bus driver must determine if the bus controller specified
188 by ControllerHandle and the child controller specified
189 by RemainingDevicePath are both supported by this
192 @retval EFI_SUCCESS The device specified by ControllerHandle and
193 RemainingDevicePath is supported by the driver specified by This.
194 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
195 RemainingDevicePath is already being managed by the driver
197 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
198 RemainingDevicePath is already being managed by a different
199 driver or an application that requires exclusive access.
200 Currently not implemented.
201 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
202 RemainingDevicePath is not supported by the driver specified by This.
206 EmmcDxeDriverBindingSupported (
207 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
208 IN EFI_HANDLE Controller
,
209 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
213 Starts a device controller or a bus controller.
215 The Start() function is designed to be invoked from the EFI boot service ConnectController().
216 As a result, much of the error checking on the parameters to Start() has been moved into this
217 common boot service. It is legal to call Start() from other locations,
218 but the following calling restrictions must be followed or the system behavior will not be deterministic.
219 1. ControllerHandle must be a valid EFI_HANDLE.
220 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
221 EFI_DEVICE_PATH_PROTOCOL.
222 3. Prior to calling Start(), the Supported() function for the driver specified by This must
223 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
225 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
226 @param[in] ControllerHandle The handle of the controller to start. This handle
227 must support a protocol interface that supplies
228 an I/O abstraction to the driver.
229 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
230 parameter is ignored by device drivers, and is optional for bus
231 drivers. For a bus driver, if this parameter is NULL, then handles
232 for all the children of Controller are created by this driver.
233 If this parameter is not NULL and the first Device Path Node is
234 not the End of Device Path Node, then only the handle for the
235 child device specified by the first Device Path Node of
236 RemainingDevicePath is created by this driver.
237 If the first Device Path Node of RemainingDevicePath is
238 the End of Device Path Node, no child handle is created by this
241 @retval EFI_SUCCESS The device was started.
242 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
243 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
244 @retval Others The driver failded to start the device.
249 EmmcDxeDriverBindingStart (
250 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
251 IN EFI_HANDLE Controller
,
252 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
256 Stops a device controller or a bus controller.
258 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
259 As a result, much of the error checking on the parameters to Stop() has been moved
260 into this common boot service. It is legal to call Stop() from other locations,
261 but the following calling restrictions must be followed or the system behavior will not be deterministic.
262 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
263 same driver's Start() function.
264 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
265 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
266 Start() function, and the Start() function must have called OpenProtocol() on
267 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
269 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
270 @param[in] ControllerHandle A handle to the device being stopped. The handle must
271 support a bus specific I/O protocol for the driver
272 to use to stop the device.
273 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
274 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
275 if NumberOfChildren is 0.
277 @retval EFI_SUCCESS The device was stopped.
278 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
283 EmmcDxeDriverBindingStop (
284 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
285 IN EFI_HANDLE Controller
,
286 IN UINTN NumberOfChildren
,
287 IN EFI_HANDLE
*ChildHandleBuffer
291 Retrieves a Unicode string that is the user readable name of the driver.
293 This function retrieves the user readable name of a driver in the form of a
294 Unicode string. If the driver specified by This has a user readable name in
295 the language specified by Language, then a pointer to the driver name is
296 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
297 by This does not support the language specified by Language,
298 then EFI_UNSUPPORTED is returned.
300 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
301 EFI_COMPONENT_NAME_PROTOCOL instance.
303 @param Language[in] A pointer to a Null-terminated ASCII string
304 array indicating the language. This is the
305 language of the driver name that the caller is
306 requesting, and it must match one of the
307 languages specified in SupportedLanguages. The
308 number of languages supported by a driver is up
309 to the driver writer. Language is specified
310 in RFC 4646 or ISO 639-2 language code format.
312 @param DriverName[out] A pointer to the Unicode string to return.
313 This Unicode string is the name of the
314 driver specified by This in the language
315 specified by Language.
317 @retval EFI_SUCCESS The Unicode string for the Driver specified by
318 This and the language specified by Language was
319 returned in DriverName.
321 @retval EFI_INVALID_PARAMETER Language is NULL.
323 @retval EFI_INVALID_PARAMETER DriverName is NULL.
325 @retval EFI_UNSUPPORTED The driver specified by This does not support
326 the language specified by Language.
331 EmmcDxeComponentNameGetDriverName (
332 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
334 OUT CHAR16
**DriverName
338 Retrieves a Unicode string that is the user readable name of the controller
339 that is being managed by a driver.
341 This function retrieves the user readable name of the controller specified by
342 ControllerHandle and ChildHandle in the form of a Unicode string. If the
343 driver specified by This has a user readable name in the language specified by
344 Language, then a pointer to the controller name is returned in ControllerName,
345 and EFI_SUCCESS is returned. If the driver specified by This is not currently
346 managing the controller specified by ControllerHandle and ChildHandle,
347 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
348 support the language specified by Language, then EFI_UNSUPPORTED is returned.
350 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
351 EFI_COMPONENT_NAME_PROTOCOL instance.
353 @param ControllerHandle[in] The handle of a controller that the driver
354 specified by This is managing. This handle
355 specifies the controller whose name is to be
358 @param ChildHandle[in] The handle of the child controller to retrieve
359 the name of. This is an optional parameter that
360 may be NULL. It will be NULL for device
361 drivers. It will also be NULL for a bus drivers
362 that wish to retrieve the name of the bus
363 controller. It will not be NULL for a bus
364 driver that wishes to retrieve the name of a
367 @param Language[in] A pointer to a Null-terminated ASCII string
368 array indicating the language. This is the
369 language of the driver name that the caller is
370 requesting, and it must match one of the
371 languages specified in SupportedLanguages. The
372 number of languages supported by a driver is up
373 to the driver writer. Language is specified in
374 RFC 4646 or ISO 639-2 language code format.
376 @param ControllerName[out] A pointer to the Unicode string to return.
377 This Unicode string is the name of the
378 controller specified by ControllerHandle and
379 ChildHandle in the language specified by
380 Language from the point of view of the driver
383 @retval EFI_SUCCESS The Unicode string for the user readable name in
384 the language specified by Language for the
385 driver specified by This was returned in
388 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
390 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
393 @retval EFI_INVALID_PARAMETER Language is NULL.
395 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
397 @retval EFI_UNSUPPORTED The driver specified by This is not currently
398 managing the controller specified by
399 ControllerHandle and ChildHandle.
401 @retval EFI_UNSUPPORTED The driver specified by This does not support
402 the language specified by Language.
407 EmmcDxeComponentNameGetControllerName (
408 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
409 IN EFI_HANDLE ControllerHandle
,
410 IN EFI_HANDLE ChildHandle OPTIONAL
,
412 OUT CHAR16
**ControllerName
416 Send command SELECT to the device to select/deselect the device.
418 @param[in] Device A pointer to the EMMC_DEVICE instance.
419 @param[in] Rca The relative device address to use.
421 @retval EFI_SUCCESS The request is executed successfully.
422 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
423 @retval Others The request could not be executed successfully.
428 IN EMMC_DEVICE
*Device
,
433 Send command SEND_STATUS to the device to get device status.
435 @param[in] Device A pointer to the EMMC_DEVICE instance.
436 @param[in] Rca The relative device address to use.
437 @param[out] DevStatus The buffer to store the device status.
439 @retval EFI_SUCCESS The request is executed successfully.
440 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
441 @retval Others The request could not be executed successfully.
446 IN EMMC_DEVICE
*Device
,
448 OUT UINT32
*DevStatus
452 Send command SEND_CSD to the device to get the CSD register data.
454 @param[in] Device A pointer to the EMMC_DEVICE instance.
455 @param[in] Rca The relative device address to use.
456 @param[out] Csd The buffer to store the EMMC_CSD register data.
458 @retval EFI_SUCCESS The request is executed successfully.
459 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
460 @retval Others The request could not be executed successfully.
465 IN EMMC_DEVICE
*Device
,
471 Send command SEND_CID to the device to get the CID register data.
473 @param[in] Device A pointer to the EMMC_DEVICE instance.
474 @param[in] Rca The relative device address to use.
475 @param[out] Cid The buffer to store the EMMC_CID register data.
477 @retval EFI_SUCCESS The request is executed successfully.
478 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
479 @retval Others The request could not be executed successfully.
484 IN EMMC_DEVICE
*Device
,
490 Send command SEND_EXT_CSD to the device to get the EXT_CSD register data.
492 @param[in] Device A pointer to the EMMC_DEVICE instance.
493 @param[out] ExtCsd The buffer to store the EXT_CSD register data.
495 @retval EFI_SUCCESS The request is executed successfully.
496 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
497 @retval Others The request could not be executed successfully.
502 IN EMMC_DEVICE
*Device
,
503 OUT EMMC_EXT_CSD
*ExtCsd