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