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