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