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, 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>
29 #include <Protocol/DevicePath.h>
31 #include <Library/DebugLib.h>
32 #include <Library/UefiDriverEntryPoint.h>
33 #include <Library/BaseLib.h>
34 #include <Library/UefiLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/DevicePathLib.h>
39 #include <Library/UefiRuntimeServicesTableLib.h>
41 #include "EmmcBlockIo.h"
45 extern EFI_DRIVER_BINDING_PROTOCOL gEmmcDxeDriverBinding
;
46 extern EFI_COMPONENT_NAME_PROTOCOL gEmmcDxeComponentName
;
47 extern EFI_COMPONENT_NAME2_PROTOCOL gEmmcDxeComponentName2
;
49 #define EMMC_PARTITION_SIGNATURE SIGNATURE_32 ('E', 'm', 'm', 'P')
51 #define EMMC_PARTITION_DATA_FROM_BLKIO(a) \
52 CR(a, EMMC_PARTITION, BlockIo, EMMC_PARTITION_SIGNATURE)
54 #define EMMC_PARTITION_DATA_FROM_BLKIO2(a) \
55 CR(a, EMMC_PARTITION, BlockIo2, EMMC_PARTITION_SIGNATURE)
57 #define EMMC_PARTITION_DATA_FROM_SSP(a) \
58 CR(a, EMMC_PARTITION, StorageSecurity, EMMC_PARTITION_SIGNATURE)
61 // Take 2.5 seconds as generic time out value, 1 microsecond as unit.
63 #define EMMC_GENERIC_TIMEOUT 2500 * 1000
65 #define EMMC_REQUEST_SIGNATURE SIGNATURE_32 ('E', 'm', 'R', 'e')
67 typedef struct _EMMC_DEVICE EMMC_DEVICE
;
68 typedef struct _EMMC_DRIVER_PRIVATE_DATA EMMC_DRIVER_PRIVATE_DATA
;
71 // Asynchronous I/O request.
77 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
78 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
79 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
83 EFI_BLOCK_IO2_TOKEN
*Token
;
87 #define EMMC_REQUEST_FROM_LINK(a) \
88 CR(a, EMMC_REQUEST, Link, EMMC_REQUEST_SIGNATURE)
93 EMMC_PARTITION_TYPE PartitionType
;
95 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
96 EFI_BLOCK_IO_PROTOCOL BlockIo
;
97 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
98 EFI_BLOCK_IO_MEDIA BlockMedia
;
99 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL StorageSecurity
;
107 // Up to 6 slots per EMMC PCI host controller
109 #define EMMC_MAX_DEVICES 6
111 // Up to 8 partitions per EMMC device.
113 #define EMMC_MAX_PARTITIONS 8
114 #define EMMC_MODEL_NAME_MAX_LEN 32
116 struct _EMMC_DEVICE
{
118 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
120 BOOLEAN SectorAddressing
;
122 EMMC_PARTITION Partition
[EMMC_MAX_PARTITIONS
];
126 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
128 // The model name consists of three fields in CID register
129 // 1) OEM/Application ID (2 bytes)
130 // 2) Product Name (5 bytes)
131 // 3) Product Serial Number (4 bytes)
132 // The delimiters of these fields are whitespace.
134 CHAR16 ModelName
[EMMC_MODEL_NAME_MAX_LEN
];
135 EMMC_DRIVER_PRIVATE_DATA
*Private
;
139 // EMMC DXE driver private data structure
141 struct _EMMC_DRIVER_PRIVATE_DATA
{
142 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
143 EFI_HANDLE Controller
;
144 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
145 EFI_HANDLE DriverBindingHandle
;
147 EMMC_DEVICE Device
[EMMC_MAX_DEVICES
];
151 Tests to see if this driver supports a given controller. If a child device is provided,
152 it further tests to see if this driver supports creating a handle for the specified child device.
154 This function checks to see if the driver specified by This supports the device specified by
155 ControllerHandle. Drivers will typically use the device path attached to
156 ControllerHandle and/or the services from the bus I/O abstraction attached to
157 ControllerHandle to determine if the driver supports ControllerHandle. This function
158 may be called many times during platform initialization. In order to reduce boot times, the tests
159 performed by this function must be very small, and take as little time as possible to execute. This
160 function must not change the state of any hardware devices, and this function must be aware that the
161 device specified by ControllerHandle may already be managed by the same driver or a
162 different driver. This function must match its calls to AllocatePages() with FreePages(),
163 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
164 Since ControllerHandle may have been previously started by the same driver, if a protocol is
165 already in the opened state, then it must not be closed with CloseProtocol(). This is required
166 to guarantee the state of ControllerHandle is not modified by this function.
168 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
169 @param[in] ControllerHandle The handle of the controller to test. This handle
170 must support a protocol interface that supplies
171 an I/O abstraction to the driver.
172 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
173 parameter is ignored by device drivers, and is optional for bus
174 drivers. For bus drivers, if this parameter is not NULL, then
175 the bus driver must determine if the bus controller specified
176 by ControllerHandle and the child controller specified
177 by RemainingDevicePath are both supported by this
180 @retval EFI_SUCCESS The device specified by ControllerHandle and
181 RemainingDevicePath is supported by the driver specified by This.
182 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
183 RemainingDevicePath is already being managed by the driver
185 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
186 RemainingDevicePath is already being managed by a different
187 driver or an application that requires exclusive access.
188 Currently not implemented.
189 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
190 RemainingDevicePath is not supported by the driver specified by This.
194 EmmcDxeDriverBindingSupported (
195 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
196 IN EFI_HANDLE Controller
,
197 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
201 Starts a device controller or a bus controller.
203 The Start() function is designed to be invoked from the EFI boot service ConnectController().
204 As a result, much of the error checking on the parameters to Start() has been moved into this
205 common boot service. It is legal to call Start() from other locations,
206 but the following calling restrictions must be followed or the system behavior will not be deterministic.
207 1. ControllerHandle must be a valid EFI_HANDLE.
208 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
209 EFI_DEVICE_PATH_PROTOCOL.
210 3. Prior to calling Start(), the Supported() function for the driver specified by This must
211 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
213 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
214 @param[in] ControllerHandle The handle of the controller to start. This handle
215 must support a protocol interface that supplies
216 an I/O abstraction to the driver.
217 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
218 parameter is ignored by device drivers, and is optional for bus
219 drivers. For a bus driver, if this parameter is NULL, then handles
220 for all the children of Controller are created by this driver.
221 If this parameter is not NULL and the first Device Path Node is
222 not the End of Device Path Node, then only the handle for the
223 child device specified by the first Device Path Node of
224 RemainingDevicePath is created by this driver.
225 If the first Device Path Node of RemainingDevicePath is
226 the End of Device Path Node, no child handle is created by this
229 @retval EFI_SUCCESS The device was started.
230 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
231 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
232 @retval Others The driver failded to start the device.
237 EmmcDxeDriverBindingStart (
238 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
239 IN EFI_HANDLE Controller
,
240 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
244 Stops a device controller or a bus controller.
246 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
247 As a result, much of the error checking on the parameters to Stop() has been moved
248 into this common boot service. It is legal to call Stop() from other locations,
249 but the following calling restrictions must be followed or the system behavior will not be deterministic.
250 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
251 same driver's Start() function.
252 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
253 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
254 Start() function, and the Start() function must have called OpenProtocol() on
255 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
257 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
258 @param[in] ControllerHandle A handle to the device being stopped. The handle must
259 support a bus specific I/O protocol for the driver
260 to use to stop the device.
261 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
262 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
263 if NumberOfChildren is 0.
265 @retval EFI_SUCCESS The device was stopped.
266 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
271 EmmcDxeDriverBindingStop (
272 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
273 IN EFI_HANDLE Controller
,
274 IN UINTN NumberOfChildren
,
275 IN EFI_HANDLE
*ChildHandleBuffer
279 Retrieves a Unicode string that is the user readable name of the driver.
281 This function retrieves the user readable name of a driver in the form of a
282 Unicode string. If the driver specified by This has a user readable name in
283 the language specified by Language, then a pointer to the driver name is
284 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
285 by This does not support the language specified by Language,
286 then EFI_UNSUPPORTED is returned.
288 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
289 EFI_COMPONENT_NAME_PROTOCOL instance.
291 @param Language[in] A pointer to a Null-terminated ASCII string
292 array indicating the language. This is the
293 language of the driver name that the caller is
294 requesting, and it must match one of the
295 languages specified in SupportedLanguages. The
296 number of languages supported by a driver is up
297 to the driver writer. Language is specified
298 in RFC 4646 or ISO 639-2 language code format.
300 @param DriverName[out] A pointer to the Unicode string to return.
301 This Unicode string is the name of the
302 driver specified by This in the language
303 specified by Language.
305 @retval EFI_SUCCESS The Unicode string for the Driver specified by
306 This and the language specified by Language was
307 returned in DriverName.
309 @retval EFI_INVALID_PARAMETER Language is NULL.
311 @retval EFI_INVALID_PARAMETER DriverName is NULL.
313 @retval EFI_UNSUPPORTED The driver specified by This does not support
314 the language specified by Language.
319 EmmcDxeComponentNameGetDriverName (
320 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
322 OUT CHAR16
**DriverName
326 Retrieves a Unicode string that is the user readable name of the controller
327 that is being managed by a driver.
329 This function retrieves the user readable name of the controller specified by
330 ControllerHandle and ChildHandle in the form of a Unicode string. If the
331 driver specified by This has a user readable name in the language specified by
332 Language, then a pointer to the controller name is returned in ControllerName,
333 and EFI_SUCCESS is returned. If the driver specified by This is not currently
334 managing the controller specified by ControllerHandle and ChildHandle,
335 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
336 support the language specified by Language, then EFI_UNSUPPORTED is returned.
338 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
339 EFI_COMPONENT_NAME_PROTOCOL instance.
341 @param ControllerHandle[in] The handle of a controller that the driver
342 specified by This is managing. This handle
343 specifies the controller whose name is to be
346 @param ChildHandle[in] The handle of the child controller to retrieve
347 the name of. This is an optional parameter that
348 may be NULL. It will be NULL for device
349 drivers. It will also be NULL for a bus drivers
350 that wish to retrieve the name of the bus
351 controller. It will not be NULL for a bus
352 driver that wishes to retrieve the name of a
355 @param Language[in] A pointer to a Null-terminated ASCII string
356 array indicating the language. This is the
357 language of the driver name that the caller is
358 requesting, and it must match one of the
359 languages specified in SupportedLanguages. The
360 number of languages supported by a driver is up
361 to the driver writer. Language is specified in
362 RFC 4646 or ISO 639-2 language code format.
364 @param ControllerName[out] A pointer to the Unicode string to return.
365 This Unicode string is the name of the
366 controller specified by ControllerHandle and
367 ChildHandle in the language specified by
368 Language from the point of view of the driver
371 @retval EFI_SUCCESS The Unicode string for the user readable name in
372 the language specified by Language for the
373 driver specified by This was returned in
376 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
378 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
381 @retval EFI_INVALID_PARAMETER Language is NULL.
383 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
385 @retval EFI_UNSUPPORTED The driver specified by This is not currently
386 managing the controller specified by
387 ControllerHandle and ChildHandle.
389 @retval EFI_UNSUPPORTED The driver specified by This does not support
390 the language specified by Language.
395 EmmcDxeComponentNameGetControllerName (
396 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
397 IN EFI_HANDLE ControllerHandle
,
398 IN EFI_HANDLE ChildHandle OPTIONAL
,
400 OUT CHAR16
**ControllerName
404 Send command SELECT to the device to select/deselect the device.
406 @param[in] Device A pointer to the EMMC_DEVICE instance.
407 @param[in] Rca The relative device address to use.
409 @retval EFI_SUCCESS The request is executed successfully.
410 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
411 @retval Others The request could not be executed successfully.
416 IN EMMC_DEVICE
*Device
,
421 Send command SEND_STATUS to the device to get device status.
423 @param[in] Device A pointer to the EMMC_DEVICE instance.
424 @param[in] Rca The relative device address to use.
425 @param[out] DevStatus The buffer to store the device status.
427 @retval EFI_SUCCESS The request is executed successfully.
428 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
429 @retval Others The request could not be executed successfully.
434 IN EMMC_DEVICE
*Device
,
436 OUT UINT32
*DevStatus
440 Send command SEND_CSD to the device to get the CSD register data.
442 @param[in] Device A pointer to the EMMC_DEVICE instance.
443 @param[in] Rca The relative device address to use.
444 @param[out] Csd The buffer to store the EMMC_CSD register data.
446 @retval EFI_SUCCESS The request is executed successfully.
447 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
448 @retval Others The request could not be executed successfully.
453 IN EMMC_DEVICE
*Device
,
459 Send command SEND_CID to the device to get the CID register data.
461 @param[in] Device A pointer to the EMMC_DEVICE instance.
462 @param[in] Rca The relative device address to use.
463 @param[out] Csd The buffer to store the EMMC_CSD register data.
465 @retval EFI_SUCCESS The request is executed successfully.
466 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
467 @retval Others The request could not be executed successfully.
472 IN EMMC_DEVICE
*Device
,
478 Send command SEND_EXT_CSD to the device to get the EXT_CSD register data.
480 @param[in] Device A pointer to the EMMC_DEVICE instance.
481 @param[out] ExtCsd The buffer to store the EXT_CSD register data.
483 @retval EFI_SUCCESS The request is executed successfully.
484 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
485 @retval Others The request could not be executed successfully.
490 IN EMMC_DEVICE
*Device
,
491 OUT EMMC_EXT_CSD
*ExtCsd