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