2 Header file for SdDxe 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/Sd.h>
24 #include <Protocol/SdMmcPassThru.h>
25 #include <Protocol/BlockIo.h>
26 #include <Protocol/BlockIo2.h>
28 #include <Protocol/DevicePath.h>
30 #include <Library/DebugLib.h>
31 #include <Library/UefiDriverEntryPoint.h>
32 #include <Library/BaseLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/MemoryAllocationLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/DevicePathLib.h>
38 #include <Library/UefiRuntimeServicesTableLib.h>
40 #include "SdBlockIo.h"
44 extern EFI_DRIVER_BINDING_PROTOCOL gSdDxeDriverBinding
;
45 extern EFI_COMPONENT_NAME_PROTOCOL gSdDxeComponentName
;
46 extern EFI_COMPONENT_NAME2_PROTOCOL gSdDxeComponentName2
;
48 #define SD_DEVICE_SIGNATURE SIGNATURE_32 ('S', 'D', 't', 'f')
50 #define SD_DEVICE_DATA_FROM_BLKIO(a) \
51 CR(a, SD_DEVICE, BlockIo, SD_DEVICE_SIGNATURE)
53 #define SD_DEVICE_DATA_FROM_BLKIO2(a) \
54 CR(a, SD_DEVICE, BlockIo2, SD_DEVICE_SIGNATURE)
57 // Take 2.5 seconds as generic time out value, 1 microsecond as unit.
59 #define SD_GENERIC_TIMEOUT 2500 * 1000
61 #define SD_REQUEST_SIGNATURE SIGNATURE_32 ('S', 'D', 'R', 'E')
63 #define SD_MODEL_NAME_MAX_LEN 32
65 typedef struct _SD_DEVICE SD_DEVICE
;
66 typedef struct _SD_DRIVER_PRIVATE_DATA SD_DRIVER_PRIVATE_DATA
;
69 // Asynchronous I/O request.
75 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
76 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
77 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
81 EFI_BLOCK_IO2_TOKEN
*Token
;
86 #define SD_REQUEST_FROM_LINK(a) \
87 CR(a, SD_REQUEST, Link, SD_REQUEST_SIGNATURE)
92 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
94 BOOLEAN SectorAddressing
;
95 EFI_BLOCK_IO_PROTOCOL BlockIo
;
96 EFI_BLOCK_IO2_PROTOCOL BlockIo2
;
97 EFI_BLOCK_IO_MEDIA BlockMedia
;
103 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
105 // The model name consists of three fields in CID register
106 // 1) OEM/Application ID (2 bytes)
107 // 2) Product Name (5 bytes)
108 // 3) Product Serial Number (4 bytes)
109 // The delimiters of these fields are whitespace.
111 CHAR16 ModelName
[SD_MODEL_NAME_MAX_LEN
];
112 SD_DRIVER_PRIVATE_DATA
*Private
;
116 // SD DXE driver private data structure
118 struct _SD_DRIVER_PRIVATE_DATA
{
119 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
120 EFI_HANDLE Controller
;
121 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
122 EFI_HANDLE DriverBindingHandle
;
126 Tests to see if this driver supports a given controller. If a child device is provided,
127 it further tests to see if this driver supports creating a handle for the specified child device.
129 This function checks to see if the driver specified by This supports the device specified by
130 ControllerHandle. Drivers will typically use the device path attached to
131 ControllerHandle and/or the services from the bus I/O abstraction attached to
132 ControllerHandle to determine if the driver supports ControllerHandle. This function
133 may be called many times during platform initialization. In order to reduce boot times, the tests
134 performed by this function must be very small, and take as little time as possible to execute. This
135 function must not change the state of any hardware devices, and this function must be aware that the
136 device specified by ControllerHandle may already be managed by the same driver or a
137 different driver. This function must match its calls to AllocatePages() with FreePages(),
138 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
139 Since ControllerHandle may have been previously started by the same driver, if a protocol is
140 already in the opened state, then it must not be closed with CloseProtocol(). This is required
141 to guarantee the state of ControllerHandle is not modified by this function.
143 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
144 @param[in] ControllerHandle The handle of the controller to test. This handle
145 must support a protocol interface that supplies
146 an I/O abstraction to the driver.
147 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
148 parameter is ignored by device drivers, and is optional for bus
149 drivers. For bus drivers, if this parameter is not NULL, then
150 the bus driver must determine if the bus controller specified
151 by ControllerHandle and the child controller specified
152 by RemainingDevicePath are both supported by this
155 @retval EFI_SUCCESS The device specified by ControllerHandle and
156 RemainingDevicePath is supported by the driver specified by This.
157 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
158 RemainingDevicePath is already being managed by the driver
160 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
161 RemainingDevicePath is already being managed by a different
162 driver or an application that requires exclusive access.
163 Currently not implemented.
164 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
165 RemainingDevicePath is not supported by the driver specified by This.
169 SdDxeDriverBindingSupported (
170 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
171 IN EFI_HANDLE Controller
,
172 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
176 Starts a device controller or a bus controller.
178 The Start() function is designed to be invoked from the EFI boot service ConnectController().
179 As a result, much of the error checking on the parameters to Start() has been moved into this
180 common boot service. It is legal to call Start() from other locations,
181 but the following calling restrictions must be followed or the system behavior will not be deterministic.
182 1. ControllerHandle must be a valid EFI_HANDLE.
183 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
184 EFI_DEVICE_PATH_PROTOCOL.
185 3. Prior to calling Start(), the Supported() function for the driver specified by This must
186 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
188 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
189 @param[in] ControllerHandle The handle of the controller to start. This handle
190 must support a protocol interface that supplies
191 an I/O abstraction to the driver.
192 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
193 parameter is ignored by device drivers, and is optional for bus
194 drivers. For a bus driver, if this parameter is NULL, then handles
195 for all the children of Controller are created by this driver.
196 If this parameter is not NULL and the first Device Path Node is
197 not the End of Device Path Node, then only the handle for the
198 child device specified by the first Device Path Node of
199 RemainingDevicePath is created by this driver.
200 If the first Device Path Node of RemainingDevicePath is
201 the End of Device Path Node, no child handle is created by this
204 @retval EFI_SUCCESS The device was started.
205 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
206 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
207 @retval Others The driver failded to start the device.
212 SdDxeDriverBindingStart (
213 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
214 IN EFI_HANDLE Controller
,
215 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
219 Stops a device controller or a bus controller.
221 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
222 As a result, much of the error checking on the parameters to Stop() has been moved
223 into this common boot service. It is legal to call Stop() from other locations,
224 but the following calling restrictions must be followed or the system behavior will not be deterministic.
225 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
226 same driver's Start() function.
227 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
228 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
229 Start() function, and the Start() function must have called OpenProtocol() on
230 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
232 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
233 @param[in] ControllerHandle A handle to the device being stopped. The handle must
234 support a bus specific I/O protocol for the driver
235 to use to stop the device.
236 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
237 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
238 if NumberOfChildren is 0.
240 @retval EFI_SUCCESS The device was stopped.
241 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
246 SdDxeDriverBindingStop (
247 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
248 IN EFI_HANDLE Controller
,
249 IN UINTN NumberOfChildren
,
250 IN EFI_HANDLE
*ChildHandleBuffer
254 Retrieves a Unicode string that is the user readable name of the driver.
256 This function retrieves the user readable name of a driver in the form of a
257 Unicode string. If the driver specified by This has a user readable name in
258 the language specified by Language, then a pointer to the driver name is
259 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
260 by This does not support the language specified by Language,
261 then EFI_UNSUPPORTED is returned.
263 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
264 EFI_COMPONENT_NAME_PROTOCOL instance.
266 @param Language[in] A pointer to a Null-terminated ASCII string
267 array indicating the language. This is the
268 language of the driver name that the caller is
269 requesting, and it must match one of the
270 languages specified in SupportedLanguages. The
271 number of languages supported by a driver is up
272 to the driver writer. Language is specified
273 in RFC 4646 or ISO 639-2 language code format.
275 @param DriverName[out] A pointer to the Unicode string to return.
276 This Unicode string is the name of the
277 driver specified by This in the language
278 specified by Language.
280 @retval EFI_SUCCESS The Unicode string for the Driver specified by
281 This and the language specified by Language was
282 returned in DriverName.
284 @retval EFI_INVALID_PARAMETER Language is NULL.
286 @retval EFI_INVALID_PARAMETER DriverName is NULL.
288 @retval EFI_UNSUPPORTED The driver specified by This does not support
289 the language specified by Language.
294 SdDxeComponentNameGetDriverName (
295 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
297 OUT CHAR16
**DriverName
301 Retrieves a Unicode string that is the user readable name of the controller
302 that is being managed by a driver.
304 This function retrieves the user readable name of the controller specified by
305 ControllerHandle and ChildHandle in the form of a Unicode string. If the
306 driver specified by This has a user readable name in the language specified by
307 Language, then a pointer to the controller name is returned in ControllerName,
308 and EFI_SUCCESS is returned. If the driver specified by This is not currently
309 managing the controller specified by ControllerHandle and ChildHandle,
310 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
311 support the language specified by Language, then EFI_UNSUPPORTED is returned.
313 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
314 EFI_COMPONENT_NAME_PROTOCOL instance.
316 @param ControllerHandle[in] The handle of a controller that the driver
317 specified by This is managing. This handle
318 specifies the controller whose name is to be
321 @param ChildHandle[in] The handle of the child controller to retrieve
322 the name of. This is an optional parameter that
323 may be NULL. It will be NULL for device
324 drivers. It will also be NULL for a bus drivers
325 that wish to retrieve the name of the bus
326 controller. It will not be NULL for a bus
327 driver that wishes to retrieve the name of a
330 @param Language[in] A pointer to a Null-terminated ASCII string
331 array indicating the language. This is the
332 language of the driver name that the caller is
333 requesting, and it must match one of the
334 languages specified in SupportedLanguages. The
335 number of languages supported by a driver is up
336 to the driver writer. Language is specified in
337 RFC 4646 or ISO 639-2 language code format.
339 @param ControllerName[out] A pointer to the Unicode string to return.
340 This Unicode string is the name of the
341 controller specified by ControllerHandle and
342 ChildHandle in the language specified by
343 Language from the point of view of the driver
346 @retval EFI_SUCCESS The Unicode string for the user readable name in
347 the language specified by Language for the
348 driver specified by This was returned in
351 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
353 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
356 @retval EFI_INVALID_PARAMETER Language is NULL.
358 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
360 @retval EFI_UNSUPPORTED The driver specified by This is not currently
361 managing the controller specified by
362 ControllerHandle and ChildHandle.
364 @retval EFI_UNSUPPORTED The driver specified by This does not support
365 the language specified by Language.
370 SdDxeComponentNameGetControllerName (
371 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
372 IN EFI_HANDLE ControllerHandle
,
373 IN EFI_HANDLE ChildHandle OPTIONAL
,
375 OUT CHAR16
**ControllerName
379 Send command SET_RELATIVE_ADDRESS to the device to set the device address.
381 @param[in] Device A pointer to the SD_DEVICE instance.
382 @param[out] Rca The relative device address to assign.
384 @retval EFI_SUCCESS The request is executed successfully.
385 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
386 @retval Others The request could not be executed successfully.
391 IN SD_DEVICE
*Device
,
396 Send command SELECT to the device to select/deselect the device.
398 @param[in] Device A pointer to the SD_DEVICE instance.
399 @param[in] Rca The relative device address to use.
401 @retval EFI_SUCCESS The request is executed successfully.
402 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
403 @retval Others The request could not be executed successfully.
408 IN SD_DEVICE
*Device
,
413 Send command SEND_STATUS to the device to get device status.
415 @param[in] Device A pointer to the SD_DEVICE instance.
416 @param[in] Rca The relative device address to use.
417 @param[out] DevStatus The buffer to store the device status.
418 @retval EFI_SUCCESS The request is executed successfully.
419 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
420 @retval Others The request could not be executed successfully.
425 IN SD_DEVICE
*Device
,
427 OUT UINT32
*DevStatus
431 Send command SEND_CSD to the device to get the CSD register data.
433 @param[in] Device A pointer to the SD_DEVICE instance.
434 @param[in] Rca The relative device address to use.
435 @param[out] Csd The buffer to store the SD_CSD register data.
437 @retval EFI_SUCCESS The request is executed successfully.
438 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
439 @retval Others The request could not be executed successfully.
444 IN SD_DEVICE
*Device
,
450 Send command SEND_CID to the device to get the CID register data.
452 @param[in] Device A pointer to the SD_DEVICE instance.
453 @param[in] Rca The relative device address to use.
454 @param[out] Cid The buffer to store the SD_CID register data.
456 @retval EFI_SUCCESS The request is executed successfully.
457 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
458 @retval Others The request could not be executed successfully.
463 IN SD_DEVICE
*Device
,