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