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