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