]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.h
MdeModulePkg: Apply uncrustify changes
[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 - 2017, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9
10 **/
11
12 #ifndef _EMMC_DXE_H_
13 #define _EMMC_DXE_H_
14
15 #include <Uefi.h>
16 #include <IndustryStandard/Emmc.h>
17
18 #include <Protocol/SdMmcPassThru.h>
19 #include <Protocol/BlockIo.h>
20 #include <Protocol/BlockIo2.h>
21 #include <Protocol/StorageSecurityCommand.h>
22 #include <Protocol/EraseBlock.h>
23 #include <Protocol/DiskInfo.h>
24
25 #include <Protocol/DevicePath.h>
26
27 #include <Library/DebugLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/BaseLib.h>
30 #include <Library/UefiLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/DevicePathLib.h>
35 #include <Library/UefiRuntimeServicesTableLib.h>
36
37 #include "EmmcBlockIo.h"
38 #include "EmmcDiskInfo.h"
39
40 //
41 // Global Variables
42 //
43 extern EFI_DRIVER_BINDING_PROTOCOL gEmmcDxeDriverBinding;
44 extern EFI_COMPONENT_NAME_PROTOCOL gEmmcDxeComponentName;
45 extern EFI_COMPONENT_NAME2_PROTOCOL gEmmcDxeComponentName2;
46
47 #define EMMC_PARTITION_SIGNATURE SIGNATURE_32 ('E', 'm', 'm', 'P')
48
49 #define EMMC_PARTITION_DATA_FROM_BLKIO(a) \
50 CR(a, EMMC_PARTITION, BlockIo, EMMC_PARTITION_SIGNATURE)
51
52 #define EMMC_PARTITION_DATA_FROM_BLKIO2(a) \
53 CR(a, EMMC_PARTITION, BlockIo2, EMMC_PARTITION_SIGNATURE)
54
55 #define EMMC_PARTITION_DATA_FROM_SSP(a) \
56 CR(a, EMMC_PARTITION, StorageSecurity, EMMC_PARTITION_SIGNATURE)
57
58 #define EMMC_PARTITION_DATA_FROM_ERASEBLK(a) \
59 CR(a, EMMC_PARTITION, EraseBlock, EMMC_PARTITION_SIGNATURE)
60
61 #define EMMC_PARTITION_DATA_FROM_DISKINFO(a) \
62 CR(a, EMMC_PARTITION, DiskInfo, EMMC_PARTITION_SIGNATURE)
63
64 //
65 // Take 2.5 seconds as generic time out value, 1 microsecond as unit.
66 //
67 #define EMMC_GENERIC_TIMEOUT 2500 * 1000
68
69 #define EMMC_REQUEST_SIGNATURE SIGNATURE_32 ('E', 'm', 'R', 'e')
70
71 typedef struct _EMMC_DEVICE EMMC_DEVICE;
72 typedef struct _EMMC_DRIVER_PRIVATE_DATA EMMC_DRIVER_PRIVATE_DATA;
73
74 //
75 // Asynchronous I/O request.
76 //
77 typedef struct {
78 UINT32 Signature;
79 LIST_ENTRY Link;
80
81 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
82 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
83 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
84
85 BOOLEAN IsEnd;
86
87 EFI_BLOCK_IO2_TOKEN *Token;
88 EFI_EVENT Event;
89 } EMMC_REQUEST;
90
91 #define EMMC_REQUEST_FROM_LINK(a) \
92 CR(a, EMMC_REQUEST, Link, EMMC_REQUEST_SIGNATURE)
93
94 typedef struct {
95 UINT32 Signature;
96 BOOLEAN Enable;
97 EMMC_PARTITION_TYPE PartitionType;
98 EFI_HANDLE Handle;
99 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
100 EFI_BLOCK_IO_PROTOCOL BlockIo;
101 EFI_BLOCK_IO2_PROTOCOL BlockIo2;
102 EFI_BLOCK_IO_MEDIA BlockMedia;
103 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL StorageSecurity;
104 EFI_ERASE_BLOCK_PROTOCOL EraseBlock;
105 EFI_DISK_INFO_PROTOCOL DiskInfo;
106
107 LIST_ENTRY Queue;
108
109 EMMC_DEVICE *Device;
110 } EMMC_PARTITION;
111
112 //
113 // Up to 6 slots per EMMC PCI host controller
114 //
115 #define EMMC_MAX_DEVICES 6
116 //
117 // Up to 8 partitions per EMMC device.
118 //
119 #define EMMC_MAX_PARTITIONS 8
120 #define EMMC_MODEL_NAME_MAX_LEN 32
121
122 struct _EMMC_DEVICE {
123 EFI_HANDLE Handle;
124 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
125 UINT8 Slot;
126 BOOLEAN SectorAddressing;
127
128 EMMC_PARTITION Partition[EMMC_MAX_PARTITIONS];
129 EMMC_CSD Csd;
130 EMMC_CID Cid;
131 EMMC_EXT_CSD ExtCsd;
132 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
133 //
134 // The model name consists of three fields in CID register
135 // 1) OEM/Application ID (2 bytes)
136 // 2) Product Name (5 bytes)
137 // 3) Product Serial Number (4 bytes)
138 // The delimiters of these fields are whitespace.
139 //
140 CHAR16 ModelName[EMMC_MODEL_NAME_MAX_LEN];
141 EMMC_DRIVER_PRIVATE_DATA *Private;
142 };
143
144 //
145 // EMMC DXE driver private data structure
146 //
147 struct _EMMC_DRIVER_PRIVATE_DATA {
148 EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
149 EFI_HANDLE Controller;
150 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
151 EFI_HANDLE DriverBindingHandle;
152
153 EMMC_DEVICE Device[EMMC_MAX_DEVICES];
154 };
155
156 /**
157 Tests to see if this driver supports a given controller. If a child device is provided,
158 it further tests to see if this driver supports creating a handle for the specified child device.
159
160 This function checks to see if the driver specified by This supports the device specified by
161 ControllerHandle. Drivers will typically use the device path attached to
162 ControllerHandle and/or the services from the bus I/O abstraction attached to
163 ControllerHandle to determine if the driver supports ControllerHandle. This function
164 may be called many times during platform initialization. In order to reduce boot times, the tests
165 performed by this function must be very small, and take as little time as possible to execute. This
166 function must not change the state of any hardware devices, and this function must be aware that the
167 device specified by ControllerHandle may already be managed by the same driver or a
168 different driver. This function must match its calls to AllocatePages() with FreePages(),
169 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
170 Since ControllerHandle may have been previously started by the same driver, if a protocol is
171 already in the opened state, then it must not be closed with CloseProtocol(). This is required
172 to guarantee the state of ControllerHandle is not modified by this function.
173
174 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
175 @param[in] ControllerHandle The handle of the controller to test. This handle
176 must support a protocol interface that supplies
177 an I/O abstraction to the driver.
178 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
179 parameter is ignored by device drivers, and is optional for bus
180 drivers. For bus drivers, if this parameter is not NULL, then
181 the bus driver must determine if the bus controller specified
182 by ControllerHandle and the child controller specified
183 by RemainingDevicePath are both supported by this
184 bus driver.
185
186 @retval EFI_SUCCESS The device specified by ControllerHandle and
187 RemainingDevicePath is supported by the driver specified by This.
188 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
189 RemainingDevicePath is already being managed by the driver
190 specified by This.
191 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
192 RemainingDevicePath is already being managed by a different
193 driver or an application that requires exclusive access.
194 Currently not implemented.
195 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
196 RemainingDevicePath is not supported by the driver specified by This.
197 **/
198 EFI_STATUS
199 EFIAPI
200 EmmcDxeDriverBindingSupported (
201 IN EFI_DRIVER_BINDING_PROTOCOL *This,
202 IN EFI_HANDLE Controller,
203 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
204 );
205
206 /**
207 Starts a device controller or a bus controller.
208
209 The Start() function is designed to be invoked from the EFI boot service ConnectController().
210 As a result, much of the error checking on the parameters to Start() has been moved into this
211 common boot service. It is legal to call Start() from other locations,
212 but the following calling restrictions must be followed or the system behavior will not be deterministic.
213 1. ControllerHandle must be a valid EFI_HANDLE.
214 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
215 EFI_DEVICE_PATH_PROTOCOL.
216 3. Prior to calling Start(), the Supported() function for the driver specified by This must
217 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
218
219 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
220 @param[in] ControllerHandle The handle of the controller to start. This handle
221 must support a protocol interface that supplies
222 an I/O abstraction to the driver.
223 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
224 parameter is ignored by device drivers, and is optional for bus
225 drivers. For a bus driver, if this parameter is NULL, then handles
226 for all the children of Controller are created by this driver.
227 If this parameter is not NULL and the first Device Path Node is
228 not the End of Device Path Node, then only the handle for the
229 child device specified by the first Device Path Node of
230 RemainingDevicePath is created by this driver.
231 If the first Device Path Node of RemainingDevicePath is
232 the End of Device Path Node, no child handle is created by this
233 driver.
234
235 @retval EFI_SUCCESS The device was started.
236 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
237 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
238 @retval Others The driver failed to start the device.
239
240 **/
241 EFI_STATUS
242 EFIAPI
243 EmmcDxeDriverBindingStart (
244 IN EFI_DRIVER_BINDING_PROTOCOL *This,
245 IN EFI_HANDLE Controller,
246 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
247 );
248
249 /**
250 Stops a device controller or a bus controller.
251
252 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
253 As a result, much of the error checking on the parameters to Stop() has been moved
254 into this common boot service. It is legal to call Stop() from other locations,
255 but the following calling restrictions must be followed or the system behavior will not be deterministic.
256 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
257 same driver's Start() function.
258 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
259 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
260 Start() function, and the Start() function must have called OpenProtocol() on
261 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
262
263 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
264 @param[in] ControllerHandle A handle to the device being stopped. The handle must
265 support a bus specific I/O protocol for the driver
266 to use to stop the device.
267 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
268 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
269 if NumberOfChildren is 0.
270
271 @retval EFI_SUCCESS The device was stopped.
272 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
273
274 **/
275 EFI_STATUS
276 EFIAPI
277 EmmcDxeDriverBindingStop (
278 IN EFI_DRIVER_BINDING_PROTOCOL *This,
279 IN EFI_HANDLE Controller,
280 IN UINTN NumberOfChildren,
281 IN EFI_HANDLE *ChildHandleBuffer
282 );
283
284 /**
285 Retrieves a Unicode string that is the user readable name of the driver.
286
287 This function retrieves the user readable name of a driver in the form of a
288 Unicode string. If the driver specified by This has a user readable name in
289 the language specified by Language, then a pointer to the driver name is
290 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
291 by This does not support the language specified by Language,
292 then EFI_UNSUPPORTED is returned.
293
294 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
295 EFI_COMPONENT_NAME_PROTOCOL instance.
296
297 @param Language[in] A pointer to a Null-terminated ASCII string
298 array indicating the language. This is the
299 language of the driver name that the caller is
300 requesting, and it must match one of the
301 languages specified in SupportedLanguages. The
302 number of languages supported by a driver is up
303 to the driver writer. Language is specified
304 in RFC 4646 or ISO 639-2 language code format.
305
306 @param DriverName[out] A pointer to the Unicode string to return.
307 This Unicode string is the name of the
308 driver specified by This in the language
309 specified by Language.
310
311 @retval EFI_SUCCESS The Unicode string for the Driver specified by
312 This and the language specified by Language was
313 returned in DriverName.
314
315 @retval EFI_INVALID_PARAMETER Language is NULL.
316
317 @retval EFI_INVALID_PARAMETER DriverName is NULL.
318
319 @retval EFI_UNSUPPORTED The driver specified by This does not support
320 the language specified by Language.
321
322 **/
323 EFI_STATUS
324 EFIAPI
325 EmmcDxeComponentNameGetDriverName (
326 IN EFI_COMPONENT_NAME_PROTOCOL *This,
327 IN CHAR8 *Language,
328 OUT CHAR16 **DriverName
329 );
330
331 /**
332 Retrieves a Unicode string that is the user readable name of the controller
333 that is being managed by a driver.
334
335 This function retrieves the user readable name of the controller specified by
336 ControllerHandle and ChildHandle in the form of a Unicode string. If the
337 driver specified by This has a user readable name in the language specified by
338 Language, then a pointer to the controller name is returned in ControllerName,
339 and EFI_SUCCESS is returned. If the driver specified by This is not currently
340 managing the controller specified by ControllerHandle and ChildHandle,
341 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
342 support the language specified by Language, then EFI_UNSUPPORTED is returned.
343
344 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
345 EFI_COMPONENT_NAME_PROTOCOL instance.
346
347 @param ControllerHandle[in] The handle of a controller that the driver
348 specified by This is managing. This handle
349 specifies the controller whose name is to be
350 returned.
351
352 @param ChildHandle[in] The handle of the child controller to retrieve
353 the name of. This is an optional parameter that
354 may be NULL. It will be NULL for device
355 drivers. It will also be NULL for a bus drivers
356 that wish to retrieve the name of the bus
357 controller. It will not be NULL for a bus
358 driver that wishes to retrieve the name of a
359 child controller.
360
361 @param Language[in] A pointer to a Null-terminated ASCII string
362 array indicating the language. This is the
363 language of the driver name that the caller is
364 requesting, and it must match one of the
365 languages specified in SupportedLanguages. The
366 number of languages supported by a driver is up
367 to the driver writer. Language is specified in
368 RFC 4646 or ISO 639-2 language code format.
369
370 @param ControllerName[out] A pointer to the Unicode string to return.
371 This Unicode string is the name of the
372 controller specified by ControllerHandle and
373 ChildHandle in the language specified by
374 Language from the point of view of the driver
375 specified by This.
376
377 @retval EFI_SUCCESS The Unicode string for the user readable name in
378 the language specified by Language for the
379 driver specified by This was returned in
380 DriverName.
381
382 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
383
384 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
385 EFI_HANDLE.
386
387 @retval EFI_INVALID_PARAMETER Language is NULL.
388
389 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
390
391 @retval EFI_UNSUPPORTED The driver specified by This is not currently
392 managing the controller specified by
393 ControllerHandle and ChildHandle.
394
395 @retval EFI_UNSUPPORTED The driver specified by This does not support
396 the language specified by Language.
397
398 **/
399 EFI_STATUS
400 EFIAPI
401 EmmcDxeComponentNameGetControllerName (
402 IN EFI_COMPONENT_NAME_PROTOCOL *This,
403 IN EFI_HANDLE ControllerHandle,
404 IN EFI_HANDLE ChildHandle OPTIONAL,
405 IN CHAR8 *Language,
406 OUT CHAR16 **ControllerName
407 );
408
409 /**
410 Send command SELECT to the device to select/deselect the device.
411
412 @param[in] Device A pointer to the EMMC_DEVICE instance.
413 @param[in] Rca The relative device address to use.
414
415 @retval EFI_SUCCESS The request is executed successfully.
416 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
417 @retval Others The request could not be executed successfully.
418
419 **/
420 EFI_STATUS
421 EmmcSelect (
422 IN EMMC_DEVICE *Device,
423 IN UINT16 Rca
424 );
425
426 /**
427 Send command SEND_STATUS to the device to get device status.
428
429 @param[in] Device A pointer to the EMMC_DEVICE instance.
430 @param[in] Rca The relative device address to use.
431 @param[out] DevStatus The buffer to store the device status.
432
433 @retval EFI_SUCCESS The request is executed successfully.
434 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
435 @retval Others The request could not be executed successfully.
436
437 **/
438 EFI_STATUS
439 EmmcSendStatus (
440 IN EMMC_DEVICE *Device,
441 IN UINT16 Rca,
442 OUT UINT32 *DevStatus
443 );
444
445 /**
446 Send command SEND_CSD to the device to get the CSD register data.
447
448 @param[in] Device A pointer to the EMMC_DEVICE instance.
449 @param[in] Rca The relative device address to use.
450 @param[out] Csd The buffer to store the EMMC_CSD register data.
451
452 @retval EFI_SUCCESS The request is executed successfully.
453 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
454 @retval Others The request could not be executed successfully.
455
456 **/
457 EFI_STATUS
458 EmmcGetCsd (
459 IN EMMC_DEVICE *Device,
460 IN UINT16 Rca,
461 OUT EMMC_CSD *Csd
462 );
463
464 /**
465 Send command SEND_CID to the device to get the CID register data.
466
467 @param[in] Device A pointer to the EMMC_DEVICE instance.
468 @param[in] Rca The relative device address to use.
469 @param[out] Cid The buffer to store the EMMC_CID register data.
470
471 @retval EFI_SUCCESS The request is executed successfully.
472 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
473 @retval Others The request could not be executed successfully.
474
475 **/
476 EFI_STATUS
477 EmmcGetCid (
478 IN EMMC_DEVICE *Device,
479 IN UINT16 Rca,
480 OUT EMMC_CID *Cid
481 );
482
483 /**
484 Send command SEND_EXT_CSD to the device to get the EXT_CSD register data.
485
486 @param[in] Device A pointer to the EMMC_DEVICE instance.
487 @param[out] ExtCsd The buffer to store the EXT_CSD register data.
488
489 @retval EFI_SUCCESS The request is executed successfully.
490 @retval EFI_OUT_OF_RESOURCES The request could not be executed due to a lack of resources.
491 @retval Others The request could not be executed successfully.
492
493 **/
494 EFI_STATUS
495 EmmcGetExtCsd (
496 IN EMMC_DEVICE *Device,
497 OUT EMMC_EXT_CSD *ExtCsd
498 );
499
500 #endif