]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.h
MdeModulePkg/SdMmc: Add EDKII SD/MMC stack
[mirror_edk2.git] / MdeModulePkg / Bus / Sd / EmmcDxe / EmmcDxe.h
1 /** @file
2 Header file for EmmcDxe 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 _EMMC_DXE_H_
19 #define _EMMC_DXE_H_
20
21 #include <Uefi.h>
22 #include <IndustryStandard/Emmc.h>
23
24 #include <Protocol/SdMmcPassThru.h>
25 #include <Protocol/BlockIo.h>
26 #include <Protocol/BlockIo2.h>
27 #include <Protocol/StorageSecurityCommand.h>
28
29 #include <Protocol/DevicePath.h>
30
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>
40
41 #include "EmmcBlockIo.h"
42 //
43 // Global Variables
44 //
45 extern EFI_DRIVER_BINDING_PROTOCOL gEmmcDxeDriverBinding;
46 extern EFI_COMPONENT_NAME_PROTOCOL gEmmcDxeComponentName;
47 extern EFI_COMPONENT_NAME2_PROTOCOL gEmmcDxeComponentName2;
48
49 #define EMMC_PARTITION_SIGNATURE SIGNATURE_32 ('E', 'm', 'm', 'P')
50
51 #define EMMC_PARTITION_DATA_FROM_BLKIO(a) \
52 CR(a, EMMC_PARTITION, BlockIo, EMMC_PARTITION_SIGNATURE)
53
54 #define EMMC_PARTITION_DATA_FROM_BLKIO2(a) \
55 CR(a, EMMC_PARTITION, BlockIo2, EMMC_PARTITION_SIGNATURE)
56
57 #define EMMC_PARTITION_DATA_FROM_SSP(a) \
58 CR(a, EMMC_PARTITION, StorageSecurity, EMMC_PARTITION_SIGNATURE)
59
60 //
61 // Take 2.5 seconds as generic time out value, 1 microsecond as unit.
62 //
63 #define EMMC_GENERIC_TIMEOUT 2500 * 1000
64
65 #define EMMC_REQUEST_SIGNATURE SIGNATURE_32 ('E', 'm', 'R', 'e')
66
67 typedef struct _EMMC_DEVICE EMMC_DEVICE;
68 typedef struct _EMMC_DRIVER_PRIVATE_DATA EMMC_DRIVER_PRIVATE_DATA;
69
70 //
71 // Asynchronous I/O request.
72 //
73 typedef struct {
74 UINT32 Signature;
75 LIST_ENTRY Link;
76
77 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
78 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
79 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
80
81 BOOLEAN IsEnd;
82
83 EFI_BLOCK_IO2_TOKEN *Token;
84 EFI_EVENT Event;
85 } EMMC_REQUEST;
86
87 #define EMMC_REQUEST_FROM_LINK(a) \
88 CR(a, EMMC_REQUEST, Link, EMMC_REQUEST_SIGNATURE)
89
90 typedef struct {
91 UINT32 Signature;
92 BOOLEAN Enable;
93 EMMC_PARTITION_TYPE PartitionType;
94 EFI_HANDLE Handle;
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;
100
101 LIST_ENTRY Queue;
102
103 EMMC_DEVICE *Device;
104 } EMMC_PARTITION;
105
106 //
107 // Up to 6 slots per EMMC PCI host controller
108 //
109 #define EMMC_MAX_DEVICES 6
110 //
111 // Up to 8 partitions per EMMC device.
112 //
113 #define EMMC_MAX_PARTITIONS 8
114 #define EMMC_MODEL_NAME_MAX_LEN 32
115
116 struct _EMMC_DEVICE {
117 EFI_HANDLE Handle;
118 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
119 UINT8 Slot;
120 BOOLEAN SectorAddressing;
121
122 EMMC_PARTITION Partition[EMMC_MAX_PARTITIONS];
123 EMMC_CSD Csd;
124 EMMC_CID Cid;
125 EMMC_EXT_CSD ExtCsd;
126 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
127 //
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.
133 //
134 CHAR16 ModelName[EMMC_MODEL_NAME_MAX_LEN];
135 EMMC_DRIVER_PRIVATE_DATA *Private;
136 } ;
137
138 //
139 // EMMC DXE driver private data structure
140 //
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;
146
147 EMMC_DEVICE Device[EMMC_MAX_DEVICES];
148 } ;
149
150 /**
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.
153
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.
167
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
178 bus driver.
179
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
184 specified by This.
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.
191 **/
192 EFI_STATUS
193 EFIAPI
194 EmmcDxeDriverBindingSupported (
195 IN EFI_DRIVER_BINDING_PROTOCOL *This,
196 IN EFI_HANDLE Controller,
197 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
198 );
199
200 /**
201 Starts a device controller or a bus controller.
202
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.
212
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
227 driver.
228
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.
233
234 **/
235 EFI_STATUS
236 EFIAPI
237 EmmcDxeDriverBindingStart (
238 IN EFI_DRIVER_BINDING_PROTOCOL *This,
239 IN EFI_HANDLE Controller,
240 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
241 );
242
243 /**
244 Stops a device controller or a bus controller.
245
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.
256
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.
264
265 @retval EFI_SUCCESS The device was stopped.
266 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
267
268 **/
269 EFI_STATUS
270 EFIAPI
271 EmmcDxeDriverBindingStop (
272 IN EFI_DRIVER_BINDING_PROTOCOL *This,
273 IN EFI_HANDLE Controller,
274 IN UINTN NumberOfChildren,
275 IN EFI_HANDLE *ChildHandleBuffer
276 );
277
278 /**
279 Retrieves a Unicode string that is the user readable name of the driver.
280
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.
287
288 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
289 EFI_COMPONENT_NAME_PROTOCOL instance.
290
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.
299
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.
304
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.
308
309 @retval EFI_INVALID_PARAMETER Language is NULL.
310
311 @retval EFI_INVALID_PARAMETER DriverName is NULL.
312
313 @retval EFI_UNSUPPORTED The driver specified by This does not support
314 the language specified by Language.
315
316 **/
317 EFI_STATUS
318 EFIAPI
319 EmmcDxeComponentNameGetDriverName (
320 IN EFI_COMPONENT_NAME_PROTOCOL *This,
321 IN CHAR8 *Language,
322 OUT CHAR16 **DriverName
323 );
324
325 /**
326 Retrieves a Unicode string that is the user readable name of the controller
327 that is being managed by a driver.
328
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.
337
338 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
339 EFI_COMPONENT_NAME_PROTOCOL instance.
340
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
344 returned.
345
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
353 child controller.
354
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.
363
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
369 specified by This.
370
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
374 DriverName.
375
376 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
377
378 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
379 EFI_HANDLE.
380
381 @retval EFI_INVALID_PARAMETER Language is NULL.
382
383 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
384
385 @retval EFI_UNSUPPORTED The driver specified by This is not currently
386 managing the controller specified by
387 ControllerHandle and ChildHandle.
388
389 @retval EFI_UNSUPPORTED The driver specified by This does not support
390 the language specified by Language.
391
392 **/
393 EFI_STATUS
394 EFIAPI
395 EmmcDxeComponentNameGetControllerName (
396 IN EFI_COMPONENT_NAME_PROTOCOL *This,
397 IN EFI_HANDLE ControllerHandle,
398 IN EFI_HANDLE ChildHandle OPTIONAL,
399 IN CHAR8 *Language,
400 OUT CHAR16 **ControllerName
401 );
402
403 /**
404 Send command SELECT to the device to select/deselect the device.
405
406 @param[in] Device A pointer to the EMMC_DEVICE instance.
407 @param[in] Rca The relative device address to use.
408
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.
412
413 **/
414 EFI_STATUS
415 EmmcSelect (
416 IN EMMC_DEVICE *Device,
417 IN UINT16 Rca
418 );
419
420 /**
421 Send command SEND_STATUS to the device to get device status.
422
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.
426
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.
430
431 **/
432 EFI_STATUS
433 EmmcSendStatus (
434 IN EMMC_DEVICE *Device,
435 IN UINT16 Rca,
436 OUT UINT32 *DevStatus
437 );
438
439 /**
440 Send command SEND_CSD to the device to get the CSD register data.
441
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.
445
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.
449
450 **/
451 EFI_STATUS
452 EmmcGetCsd (
453 IN EMMC_DEVICE *Device,
454 IN UINT16 Rca,
455 OUT EMMC_CSD *Csd
456 );
457
458 /**
459 Send command SEND_CID to the device to get the CID register data.
460
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.
464
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.
468
469 **/
470 EFI_STATUS
471 EmmcGetCid (
472 IN EMMC_DEVICE *Device,
473 IN UINT16 Rca,
474 OUT EMMC_CID *Cid
475 );
476
477 /**
478 Send command SEND_EXT_CSD to the device to get the EXT_CSD register data.
479
480 @param[in] Device A pointer to the EMMC_DEVICE instance.
481 @param[out] ExtCsd The buffer to store the EXT_CSD register data.
482
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.
486
487 **/
488 EFI_STATUS
489 EmmcGetExtCsd (
490 IN EMMC_DEVICE *Device,
491 OUT EMMC_EXT_CSD *ExtCsd
492 );
493
494 #endif
495