]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Sd/SdDxe/SdDxe.h
MdeModulePkg/SdMmc: Add EDKII SD/MMC stack
[mirror_edk2.git] / MdeModulePkg / Bus / Sd / SdDxe / SdDxe.h
1 /** @file
2 Header file for SdDxe Driver.
3
4 This file defines common data structures, macro definitions and some module
5 internal function header files.
6
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
12
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.
15
16 **/
17
18 #ifndef _SD_DXE_H_
19 #define _SD_DXE_H_
20
21 #include <Uefi.h>
22 #include <IndustryStandard/Sd.h>
23
24 #include <Protocol/SdMmcPassThru.h>
25 #include <Protocol/BlockIo.h>
26 #include <Protocol/BlockIo2.h>
27
28 #include <Protocol/DevicePath.h>
29
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>
39
40 #include "SdBlockIo.h"
41 //
42 // Global Variables
43 //
44 extern EFI_DRIVER_BINDING_PROTOCOL gSdDxeDriverBinding;
45 extern EFI_COMPONENT_NAME_PROTOCOL gSdDxeComponentName;
46 extern EFI_COMPONENT_NAME2_PROTOCOL gSdDxeComponentName2;
47
48 #define SD_DEVICE_SIGNATURE SIGNATURE_32 ('S', 'D', 't', 'f')
49
50 #define SD_DEVICE_DATA_FROM_BLKIO(a) \
51 CR(a, SD_DEVICE, BlockIo, SD_DEVICE_SIGNATURE)
52
53 #define SD_DEVICE_DATA_FROM_BLKIO2(a) \
54 CR(a, SD_DEVICE, BlockIo2, SD_DEVICE_SIGNATURE)
55
56 //
57 // Take 2.5 seconds as generic time out value, 1 microsecond as unit.
58 //
59 #define SD_GENERIC_TIMEOUT 2500 * 1000
60
61 #define SD_REQUEST_SIGNATURE SIGNATURE_32 ('S', 'D', 'R', 'E')
62
63 #define SD_MODEL_NAME_MAX_LEN 32
64
65 typedef struct _SD_DEVICE SD_DEVICE;
66 typedef struct _SD_DRIVER_PRIVATE_DATA SD_DRIVER_PRIVATE_DATA;
67
68 //
69 // Asynchronous I/O request.
70 //
71 typedef struct {
72 UINT32 Signature;
73 LIST_ENTRY Link;
74
75 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
76 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
77 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
78
79 BOOLEAN IsEnd;
80
81 EFI_BLOCK_IO2_TOKEN *Token;
82
83 EFI_EVENT Event;
84 } SD_REQUEST;
85
86 #define SD_REQUEST_FROM_LINK(a) \
87 CR(a, SD_REQUEST, Link, SD_REQUEST_SIGNATURE)
88
89 struct _SD_DEVICE {
90 UINT32 Signature;
91 EFI_HANDLE Handle;
92 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
93 UINT8 Slot;
94 BOOLEAN SectorAddressing;
95 EFI_BLOCK_IO_PROTOCOL BlockIo;
96 EFI_BLOCK_IO2_PROTOCOL BlockIo2;
97 EFI_BLOCK_IO_MEDIA BlockMedia;
98
99 LIST_ENTRY Queue;
100
101 SD_CSD Csd;
102 SD_CID Cid;
103 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
104 //
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.
110 //
111 CHAR16 ModelName[SD_MODEL_NAME_MAX_LEN];
112 SD_DRIVER_PRIVATE_DATA *Private;
113 } ;
114
115 //
116 // SD DXE driver private data structure
117 //
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;
123 } ;
124
125 /**
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.
128
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.
142
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
153 bus driver.
154
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
159 specified by This.
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.
166 **/
167 EFI_STATUS
168 EFIAPI
169 SdDxeDriverBindingSupported (
170 IN EFI_DRIVER_BINDING_PROTOCOL *This,
171 IN EFI_HANDLE Controller,
172 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
173 );
174
175 /**
176 Starts a device controller or a bus controller.
177
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.
187
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
202 driver.
203
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.
208
209 **/
210 EFI_STATUS
211 EFIAPI
212 SdDxeDriverBindingStart (
213 IN EFI_DRIVER_BINDING_PROTOCOL *This,
214 IN EFI_HANDLE Controller,
215 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
216 );
217
218 /**
219 Stops a device controller or a bus controller.
220
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.
231
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.
239
240 @retval EFI_SUCCESS The device was stopped.
241 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
242
243 **/
244 EFI_STATUS
245 EFIAPI
246 SdDxeDriverBindingStop (
247 IN EFI_DRIVER_BINDING_PROTOCOL *This,
248 IN EFI_HANDLE Controller,
249 IN UINTN NumberOfChildren,
250 IN EFI_HANDLE *ChildHandleBuffer
251 );
252
253 /**
254 Retrieves a Unicode string that is the user readable name of the driver.
255
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.
262
263 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
264 EFI_COMPONENT_NAME_PROTOCOL instance.
265
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.
274
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.
279
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.
283
284 @retval EFI_INVALID_PARAMETER Language is NULL.
285
286 @retval EFI_INVALID_PARAMETER DriverName is NULL.
287
288 @retval EFI_UNSUPPORTED The driver specified by This does not support
289 the language specified by Language.
290
291 **/
292 EFI_STATUS
293 EFIAPI
294 SdDxeComponentNameGetDriverName (
295 IN EFI_COMPONENT_NAME_PROTOCOL *This,
296 IN CHAR8 *Language,
297 OUT CHAR16 **DriverName
298 );
299
300 /**
301 Retrieves a Unicode string that is the user readable name of the controller
302 that is being managed by a driver.
303
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.
312
313 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
314 EFI_COMPONENT_NAME_PROTOCOL instance.
315
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
319 returned.
320
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
328 child controller.
329
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.
338
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
344 specified by This.
345
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
349 DriverName.
350
351 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
352
353 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
354 EFI_HANDLE.
355
356 @retval EFI_INVALID_PARAMETER Language is NULL.
357
358 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
359
360 @retval EFI_UNSUPPORTED The driver specified by This is not currently
361 managing the controller specified by
362 ControllerHandle and ChildHandle.
363
364 @retval EFI_UNSUPPORTED The driver specified by This does not support
365 the language specified by Language.
366
367 **/
368 EFI_STATUS
369 EFIAPI
370 SdDxeComponentNameGetControllerName (
371 IN EFI_COMPONENT_NAME_PROTOCOL *This,
372 IN EFI_HANDLE ControllerHandle,
373 IN EFI_HANDLE ChildHandle OPTIONAL,
374 IN CHAR8 *Language,
375 OUT CHAR16 **ControllerName
376 );
377
378 /**
379 Send command SET_RELATIVE_ADDRESS to the device to set the device address.
380
381 @param[in] Device A pointer to the SD_DEVICE instance.
382 @param[out] Rca The relative device address to assign.
383
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.
387
388 **/
389 EFI_STATUS
390 SdSetRca (
391 IN SD_DEVICE *Device,
392 OUT UINT16 *Rca
393 );
394
395 /**
396 Send command SELECT to the device to select/deselect the device.
397
398 @param[in] Device A pointer to the SD_DEVICE instance.
399 @param[in] Rca The relative device address to use.
400
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.
404
405 **/
406 EFI_STATUS
407 SdSelect (
408 IN SD_DEVICE *Device,
409 IN UINT16 Rca
410 );
411
412 /**
413 Send command SEND_STATUS to the device to get device status.
414
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.
421
422 **/
423 EFI_STATUS
424 SdSendStatus (
425 IN SD_DEVICE *Device,
426 IN UINT16 Rca,
427 OUT UINT32 *DevStatus
428 );
429
430 /**
431 Send command SEND_CSD to the device to get the CSD register data.
432
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.
436
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.
440
441 **/
442 EFI_STATUS
443 SdGetCsd (
444 IN SD_DEVICE *Device,
445 IN UINT16 Rca,
446 OUT SD_CSD *Csd
447 );
448
449 /**
450 Send command SEND_CID to the device to get the CID register data.
451
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.
455
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.
459
460 **/
461 EFI_STATUS
462 SdGetCid (
463 IN SD_DEVICE *Device,
464 IN UINT16 Rca,
465 OUT SD_CID *Cid
466 );
467
468 #endif
469