2 UfsHcDxe driver is used to provide platform-dependent info, mainly UFS host controller
3 MMIO base, to upper layer UFS drivers.
5 Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _EFI_UFS_HOST_CONTROLLER_H_
17 #define _EFI_UFS_HOST_CONTROLLER_H_
21 #include <IndustryStandard/Pci.h>
22 #include <IndustryStandard/Acpi.h>
24 #include <Protocol/ComponentName.h>
25 #include <Protocol/ComponentName2.h>
26 #include <Protocol/DriverBinding.h>
27 #include <Protocol/LoadedImage.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/PciIo.h>
30 #include <Protocol/UfsHostController.h>
32 #include <Library/BaseLib.h>
33 #include <Library/DebugLib.h>
34 #include <Library/UefiLib.h>
35 #include <Library/DevicePathLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/UefiDriverEntryPoint.h>
40 extern EFI_DRIVER_BINDING_PROTOCOL gUfsHcDriverBinding
;
41 extern EFI_COMPONENT_NAME_PROTOCOL gUfsHcComponentName
;
42 extern EFI_COMPONENT_NAME2_PROTOCOL gUfsHcComponentName2
;
45 // Unique signature for private data structure.
47 #define UFS_HC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U','F','S','H')
49 typedef struct _UFS_HOST_CONTROLLER_PRIVATE_DATA UFS_HOST_CONTROLLER_PRIVATE_DATA
;
52 // Ufs host controller private data structure.
54 struct _UFS_HOST_CONTROLLER_PRIVATE_DATA
{
57 EDKII_UFS_HOST_CONTROLLER_PROTOCOL UfsHc
;
58 EFI_PCI_IO_PROTOCOL
*PciIo
;
63 #define UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC(a) \
65 UFS_HOST_CONTROLLER_PRIVATE_DATA, \
67 UFS_HC_PRIVATE_DATA_SIGNATURE \
71 Retrieves a Unicode string that is the user readable name of the driver.
73 This function retrieves the user readable name of a driver in the form of a
74 Unicode string. If the driver specified by This has a user readable name in
75 the language specified by Language, then a pointer to the driver name is
76 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
77 by This does not support the language specified by Language,
78 then EFI_UNSUPPORTED is returned.
80 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
81 EFI_COMPONENT_NAME_PROTOCOL instance.
83 @param Language[in] A pointer to a Null-terminated ASCII string
84 array indicating the language. This is the
85 language of the driver name that the caller is
86 requesting, and it must match one of the
87 languages specified in SupportedLanguages. The
88 number of languages supported by a driver is up
89 to the driver writer. Language is specified
90 in RFC 4646 or ISO 639-2 language code format.
92 @param DriverName[out] A pointer to the Unicode string to return.
93 This Unicode string is the name of the
94 driver specified by This in the language
95 specified by Language.
97 @retval EFI_SUCCESS The Unicode string for the Driver specified by
98 This and the language specified by Language was
99 returned in DriverName.
101 @retval EFI_INVALID_PARAMETER Language is NULL.
103 @retval EFI_INVALID_PARAMETER DriverName is NULL.
105 @retval EFI_UNSUPPORTED The driver specified by This does not support
106 the language specified by Language.
111 UfsHcComponentNameGetDriverName (
112 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
114 OUT CHAR16
**DriverName
118 Retrieves a Unicode string that is the user readable name of the controller
119 that is being managed by a driver.
121 This function retrieves the user readable name of the controller specified by
122 ControllerHandle and ChildHandle in the form of a Unicode string. If the
123 driver specified by This has a user readable name in the language specified by
124 Language, then a pointer to the controller name is returned in ControllerName,
125 and EFI_SUCCESS is returned. If the driver specified by This is not currently
126 managing the controller specified by ControllerHandle and ChildHandle,
127 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
128 support the language specified by Language, then EFI_UNSUPPORTED is returned.
130 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
131 EFI_COMPONENT_NAME_PROTOCOL instance.
133 @param ControllerHandle[in] The handle of a controller that the driver
134 specified by This is managing. This handle
135 specifies the controller whose name is to be
138 @param ChildHandle[in] The handle of the child controller to retrieve
139 the name of. This is an optional parameter that
140 may be NULL. It will be NULL for device
141 drivers. It will also be NULL for a bus drivers
142 that wish to retrieve the name of the bus
143 controller. It will not be NULL for a bus
144 driver that wishes to retrieve the name of a
147 @param Language[in] A pointer to a Null-terminated ASCII string
148 array indicating the language. This is the
149 language of the driver name that the caller is
150 requesting, and it must match one of the
151 languages specified in SupportedLanguages. The
152 number of languages supported by a driver is up
153 to the driver writer. Language is specified in
154 RFC 4646 or ISO 639-2 language code format.
156 @param ControllerName[out] A pointer to the Unicode string to return.
157 This Unicode string is the name of the
158 controller specified by ControllerHandle and
159 ChildHandle in the language specified by
160 Language from the point of view of the driver
163 @retval EFI_SUCCESS The Unicode string for the user readable name in
164 the language specified by Language for the
165 driver specified by This was returned in
168 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
170 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
173 @retval EFI_INVALID_PARAMETER Language is NULL.
175 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
177 @retval EFI_UNSUPPORTED The driver specified by This is not currently
178 managing the controller specified by
179 ControllerHandle and ChildHandle.
181 @retval EFI_UNSUPPORTED The driver specified by This does not support
182 the language specified by Language.
187 UfsHcComponentNameGetControllerName (
188 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
189 IN EFI_HANDLE ControllerHandle
,
190 IN EFI_HANDLE ChildHandle OPTIONAL
,
192 OUT CHAR16
**ControllerName
196 Tests to see if this driver supports a given controller. If a child device is provided,
197 it further tests to see if this driver supports creating a handle for the specified child device.
199 This function checks to see if the driver specified by This supports the device specified by
200 ControllerHandle. Drivers will typically use the device path attached to
201 ControllerHandle and/or the services from the bus I/O abstraction attached to
202 ControllerHandle to determine if the driver supports ControllerHandle. This function
203 may be called many times during platform initialization. In order to reduce boot times, the tests
204 performed by this function must be very small, and take as little time as possible to execute. This
205 function must not change the state of any hardware devices, and this function must be aware that the
206 device specified by ControllerHandle may already be managed by the same driver or a
207 different driver. This function must match its calls to AllocatePages() with FreePages(),
208 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
209 Since ControllerHandle may have been previously started by the same driver, if a protocol is
210 already in the opened state, then it must not be closed with CloseProtocol(). This is required
211 to guarantee the state of ControllerHandle is not modified by this function.
213 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
214 @param[in] ControllerHandle The handle of the controller to test. This handle
215 must support a protocol interface that supplies
216 an I/O abstraction to the driver.
217 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
218 parameter is ignored by device drivers, and is optional for bus
219 drivers. For bus drivers, if this parameter is not NULL, then
220 the bus driver must determine if the bus controller specified
221 by ControllerHandle and the child controller specified
222 by RemainingDevicePath are both supported by this
225 @retval EFI_SUCCESS The device specified by ControllerHandle and
226 RemainingDevicePath is supported by the driver specified by This.
227 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
228 RemainingDevicePath is already being managed by the driver
230 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
231 RemainingDevicePath is already being managed by a different
232 driver or an application that requires exclusive access.
233 Currently not implemented.
234 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
235 RemainingDevicePath is not supported by the driver specified by This.
239 UfsHcDriverBindingSupported (
240 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
241 IN EFI_HANDLE Controller
,
242 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
246 Starts a device controller or a bus controller.
248 The Start() function is designed to be invoked from the EFI boot service ConnectController().
249 As a result, much of the error checking on the parameters to Start() has been moved into this
250 common boot service. It is legal to call Start() from other locations,
251 but the following calling restrictions must be followed or the system behavior will not be deterministic.
252 1. ControllerHandle must be a valid EFI_HANDLE.
253 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
254 EFI_DEVICE_PATH_PROTOCOL.
255 3. Prior to calling Start(), the Supported() function for the driver specified by This must
256 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
258 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
259 @param[in] ControllerHandle The handle of the controller to start. This handle
260 must support a protocol interface that supplies
261 an I/O abstraction to the driver.
262 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
263 parameter is ignored by device drivers, and is optional for bus
264 drivers. For a bus driver, if this parameter is NULL, then handles
265 for all the children of Controller are created by this driver.
266 If this parameter is not NULL and the first Device Path Node is
267 not the End of Device Path Node, then only the handle for the
268 child device specified by the first Device Path Node of
269 RemainingDevicePath is created by this driver.
270 If the first Device Path Node of RemainingDevicePath is
271 the End of Device Path Node, no child handle is created by this
274 @retval EFI_SUCCESS The device was started.
275 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
276 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
277 @retval Others The driver failded to start the device.
282 UfsHcDriverBindingStart (
283 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
284 IN EFI_HANDLE Controller
,
285 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
289 Stops a device controller or a bus controller.
291 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
292 As a result, much of the error checking on the parameters to Stop() has been moved
293 into this common boot service. It is legal to call Stop() from other locations,
294 but the following calling restrictions must be followed or the system behavior will not be deterministic.
295 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
296 same driver's Start() function.
297 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
298 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
299 Start() function, and the Start() function must have called OpenProtocol() on
300 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
302 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
303 @param[in] ControllerHandle A handle to the device being stopped. The handle must
304 support a bus specific I/O protocol for the driver
305 to use to stop the device.
306 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
307 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
308 if NumberOfChildren is 0.
310 @retval EFI_SUCCESS The device was stopped.
311 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
316 UfsHcDriverBindingStop (
317 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
318 IN EFI_HANDLE Controller
,
319 IN UINTN NumberOfChildren
,
320 IN EFI_HANDLE
*ChildHandleBuffer
324 Get the MMIO base of the UFS host controller.
326 @param[in] This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
327 @param[out] MmioBar The MMIO base address of UFS host controller.
329 @retval EFI_SUCCESS The operation succeeds.
330 @retval others The operation fails.
335 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
340 Provides the UFS controller-specific addresses needed to access system memory.
342 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
343 @param Operation Indicates if the bus master is going to read or write to system memory.
344 @param HostAddress The system memory address to map to the UFS controller.
345 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
347 @param DeviceAddress The resulting map address for the bus master UFS controller to use to
348 access the hosts HostAddress.
349 @param Mapping A resulting value to pass to Unmap().
351 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
352 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
353 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
354 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
355 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
361 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
362 IN EDKII_UFS_HOST_CONTROLLER_OPERATION Operation
,
363 IN VOID
*HostAddress
,
364 IN OUT UINTN
*NumberOfBytes
,
365 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
370 Completes the Map() operation and releases any corresponding resources.
372 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
373 @param Mapping The mapping value returned from Map().
375 @retval EFI_SUCCESS The range was unmapped.
376 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
382 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
387 Allocates pages that are suitable for an EfiUfsHcOperationBusMasterCommonBuffer
390 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
391 @param Type This parameter is not used and must be ignored.
392 @param MemoryType The type of memory to allocate, EfiBootServicesData or
393 EfiRuntimeServicesData.
394 @param Pages The number of pages to allocate.
395 @param HostAddress A pointer to store the base system memory address of the
397 @param Attributes The requested bit mask of attributes for the allocated range.
399 @retval EFI_SUCCESS The requested memory pages were allocated.
400 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
401 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
402 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
403 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
408 UfsHcAllocateBuffer (
409 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
410 IN EFI_ALLOCATE_TYPE Type
,
411 IN EFI_MEMORY_TYPE MemoryType
,
413 OUT VOID
**HostAddress
,
418 Frees memory that was allocated with AllocateBuffer().
420 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
421 @param Pages The number of pages to free.
422 @param HostAddress The base system memory address of the allocated range.
424 @retval EFI_SUCCESS The requested memory pages were freed.
425 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
426 was not allocated with AllocateBuffer().
432 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
438 Flushes all posted write transactions from the UFS bus to attached UFS device.
440 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
442 @retval EFI_SUCCESS The posted write transactions were flushed from the UFS bus
443 to attached UFS device.
444 @retval EFI_DEVICE_ERROR The posted write transactions were not flushed from the UFS
445 bus to attached UFS device due to a hardware error.
451 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
455 Enable a UFS bus driver to access UFS MMIO registers in the UFS Host Controller memory space.
457 @param This A pointer to the EDKII_UFS_HOST_CONTROLLER_PROTOCOL instance.
458 @param Width Signifies the width of the memory operations.
459 @param Offset The offset within the UFS Host Controller MMIO space to start the
461 @param Count The number of memory operations to perform.
462 @param Buffer For read operations, the destination buffer to store the results.
463 For write operations, the source buffer to write data from.
465 @retval EFI_SUCCESS The data was read from or written to the UFS host controller.
466 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
467 valid for the UFS Host Controller memory space.
468 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
469 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
475 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
476 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL_WIDTH Width
,
483 Enable a UFS bus driver to access UFS MMIO registers in the UFS Host Controller memory space.
485 @param This A pointer to the EDKII_UFS_HOST_CONTROLLER_PROTOCOL instance.
486 @param Width Signifies the width of the memory operations.
487 @param Offset The offset within the UFS Host Controller MMIO space to start the
489 @param Count The number of memory operations to perform.
490 @param Buffer For read operations, the destination buffer to store the results.
491 For write operations, the source buffer to write data from.
493 @retval EFI_SUCCESS The data was read from or written to the UFS host controller.
494 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
495 valid for the UFS Host Controller memory space.
496 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
497 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
503 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
504 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL_WIDTH Width
,