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