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