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