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, 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>
23 #include <Protocol/ComponentName.h>
24 #include <Protocol/ComponentName2.h>
25 #include <Protocol/DriverBinding.h>
26 #include <Protocol/LoadedImage.h>
27 #include <Protocol/DevicePath.h>
28 #include <Protocol/PciIo.h>
29 #include <Protocol/UfsHostController.h>
31 #include <Library/BaseLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/DevicePathLib.h>
35 #include <Library/MemoryAllocationLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/UefiDriverEntryPoint.h>
39 extern EFI_DRIVER_BINDING_PROTOCOL gUfsHcDriverBinding
;
40 extern EFI_COMPONENT_NAME_PROTOCOL gUfsHcComponentName
;
41 extern EFI_COMPONENT_NAME2_PROTOCOL gUfsHcComponentName2
;
44 // Unique signature for private data structure.
46 #define UFS_HC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U','F','S','H')
48 typedef struct _UFS_HOST_CONTROLLER_PRIVATE_DATA UFS_HOST_CONTROLLER_PRIVATE_DATA
;
51 // Nvme private data structure.
53 struct _UFS_HOST_CONTROLLER_PRIVATE_DATA
{
57 EDKII_UFS_HOST_CONTROLLER_PROTOCOL UfsHc
;
58 EFI_PCI_IO_PROTOCOL
*PciIo
;
62 #define UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC(a) \
64 UFS_HOST_CONTROLLER_PRIVATE_DATA, \
66 UFS_HC_PRIVATE_DATA_SIGNATURE \
70 Retrieves a Unicode string that is the user readable name of the driver.
72 This function retrieves the user readable name of a driver in the form of a
73 Unicode string. If the driver specified by This has a user readable name in
74 the language specified by Language, then a pointer to the driver name is
75 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
76 by This does not support the language specified by Language,
77 then EFI_UNSUPPORTED is returned.
79 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
80 EFI_COMPONENT_NAME_PROTOCOL instance.
82 @param Language[in] A pointer to a Null-terminated ASCII string
83 array indicating the language. This is the
84 language of the driver name that the caller is
85 requesting, and it must match one of the
86 languages specified in SupportedLanguages. The
87 number of languages supported by a driver is up
88 to the driver writer. Language is specified
89 in RFC 4646 or ISO 639-2 language code format.
91 @param DriverName[out] A pointer to the Unicode string to return.
92 This Unicode string is the name of the
93 driver specified by This in the language
94 specified by Language.
96 @retval EFI_SUCCESS The Unicode string for the Driver specified by
97 This and the language specified by Language was
98 returned in DriverName.
100 @retval EFI_INVALID_PARAMETER Language is NULL.
102 @retval EFI_INVALID_PARAMETER DriverName is NULL.
104 @retval EFI_UNSUPPORTED The driver specified by This does not support
105 the language specified by Language.
110 UfsHcComponentNameGetDriverName (
111 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
113 OUT CHAR16
**DriverName
117 Retrieves a Unicode string that is the user readable name of the controller
118 that is being managed by a driver.
120 This function retrieves the user readable name of the controller specified by
121 ControllerHandle and ChildHandle in the form of a Unicode string. If the
122 driver specified by This has a user readable name in the language specified by
123 Language, then a pointer to the controller name is returned in ControllerName,
124 and EFI_SUCCESS is returned. If the driver specified by This is not currently
125 managing the controller specified by ControllerHandle and ChildHandle,
126 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
127 support the language specified by Language, then EFI_UNSUPPORTED is returned.
129 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
130 EFI_COMPONENT_NAME_PROTOCOL instance.
132 @param ControllerHandle[in] The handle of a controller that the driver
133 specified by This is managing. This handle
134 specifies the controller whose name is to be
137 @param ChildHandle[in] The handle of the child controller to retrieve
138 the name of. This is an optional parameter that
139 may be NULL. It will be NULL for device
140 drivers. It will also be NULL for a bus drivers
141 that wish to retrieve the name of the bus
142 controller. It will not be NULL for a bus
143 driver that wishes to retrieve the name of a
146 @param Language[in] A pointer to a Null-terminated ASCII string
147 array indicating the language. This is the
148 language of the driver name that the caller is
149 requesting, and it must match one of the
150 languages specified in SupportedLanguages. The
151 number of languages supported by a driver is up
152 to the driver writer. Language is specified in
153 RFC 4646 or ISO 639-2 language code format.
155 @param ControllerName[out] A pointer to the Unicode string to return.
156 This Unicode string is the name of the
157 controller specified by ControllerHandle and
158 ChildHandle in the language specified by
159 Language from the point of view of the driver
162 @retval EFI_SUCCESS The Unicode string for the user readable name in
163 the language specified by Language for the
164 driver specified by This was returned in
167 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
169 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
172 @retval EFI_INVALID_PARAMETER Language is NULL.
174 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
176 @retval EFI_UNSUPPORTED The driver specified by This is not currently
177 managing the controller specified by
178 ControllerHandle and ChildHandle.
180 @retval EFI_UNSUPPORTED The driver specified by This does not support
181 the language specified by Language.
186 UfsHcComponentNameGetControllerName (
187 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
188 IN EFI_HANDLE ControllerHandle
,
189 IN EFI_HANDLE ChildHandle OPTIONAL
,
191 OUT CHAR16
**ControllerName
195 Tests to see if this driver supports a given controller. If a child device is provided,
196 it further tests to see if this driver supports creating a handle for the specified child device.
198 This function checks to see if the driver specified by This supports the device specified by
199 ControllerHandle. Drivers will typically use the device path attached to
200 ControllerHandle and/or the services from the bus I/O abstraction attached to
201 ControllerHandle to determine if the driver supports ControllerHandle. This function
202 may be called many times during platform initialization. In order to reduce boot times, the tests
203 performed by this function must be very small, and take as little time as possible to execute. This
204 function must not change the state of any hardware devices, and this function must be aware that the
205 device specified by ControllerHandle may already be managed by the same driver or a
206 different driver. This function must match its calls to AllocatePages() with FreePages(),
207 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
208 Since ControllerHandle may have been previously started by the same driver, if a protocol is
209 already in the opened state, then it must not be closed with CloseProtocol(). This is required
210 to guarantee the state of ControllerHandle is not modified by this function.
212 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
213 @param[in] ControllerHandle The handle of the controller to test. This handle
214 must support a protocol interface that supplies
215 an I/O abstraction to the driver.
216 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
217 parameter is ignored by device drivers, and is optional for bus
218 drivers. For bus drivers, if this parameter is not NULL, then
219 the bus driver must determine if the bus controller specified
220 by ControllerHandle and the child controller specified
221 by RemainingDevicePath are both supported by this
224 @retval EFI_SUCCESS The device specified by ControllerHandle and
225 RemainingDevicePath is supported by the driver specified by This.
226 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
227 RemainingDevicePath is already being managed by the driver
229 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
230 RemainingDevicePath is already being managed by a different
231 driver or an application that requires exclusive access.
232 Currently not implemented.
233 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
234 RemainingDevicePath is not supported by the driver specified by This.
238 UfsHcDriverBindingSupported (
239 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
240 IN EFI_HANDLE Controller
,
241 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
245 Starts a device controller or a bus controller.
247 The Start() function is designed to be invoked from the EFI boot service ConnectController().
248 As a result, much of the error checking on the parameters to Start() has been moved into this
249 common boot service. It is legal to call Start() from other locations,
250 but the following calling restrictions must be followed or the system behavior will not be deterministic.
251 1. ControllerHandle must be a valid EFI_HANDLE.
252 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
253 EFI_DEVICE_PATH_PROTOCOL.
254 3. Prior to calling Start(), the Supported() function for the driver specified by This must
255 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
257 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
258 @param[in] ControllerHandle The handle of the controller to start. This handle
259 must support a protocol interface that supplies
260 an I/O abstraction to the driver.
261 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
262 parameter is ignored by device drivers, and is optional for bus
263 drivers. For a bus driver, if this parameter is NULL, then handles
264 for all the children of Controller are created by this driver.
265 If this parameter is not NULL and the first Device Path Node is
266 not the End of Device Path Node, then only the handle for the
267 child device specified by the first Device Path Node of
268 RemainingDevicePath is created by this driver.
269 If the first Device Path Node of RemainingDevicePath is
270 the End of Device Path Node, no child handle is created by this
273 @retval EFI_SUCCESS The device was started.
274 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
275 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
276 @retval Others The driver failded to start the device.
281 UfsHcDriverBindingStart (
282 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
283 IN EFI_HANDLE Controller
,
284 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
288 Stops a device controller or a bus controller.
290 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
291 As a result, much of the error checking on the parameters to Stop() has been moved
292 into this common boot service. It is legal to call Stop() from other locations,
293 but the following calling restrictions must be followed or the system behavior will not be deterministic.
294 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
295 same driver's Start() function.
296 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
297 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
298 Start() function, and the Start() function must have called OpenProtocol() on
299 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
301 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
302 @param[in] ControllerHandle A handle to the device being stopped. The handle must
303 support a bus specific I/O protocol for the driver
304 to use to stop the device.
305 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
306 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
307 if NumberOfChildren is 0.
309 @retval EFI_SUCCESS The device was stopped.
310 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
315 UfsHcDriverBindingStop (
316 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
317 IN EFI_HANDLE Controller
,
318 IN UINTN NumberOfChildren
,
319 IN EFI_HANDLE
*ChildHandleBuffer
323 Get the MMIO base of the UFS host controller.
325 @param[in] This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
326 @param[out] MmioBar The MMIO base address of UFS host controller.
328 @retval EFI_SUCCESS The operation succeeds.
329 @retval others The operation fails.
334 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
339 Provides the UFS controller-specific addresses needed to access system memory.
341 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
342 @param Operation Indicates if the bus master is going to read or write to system memory.
343 @param HostAddress The system memory address to map to the UFS controller.
344 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
346 @param DeviceAddress The resulting map address for the bus master UFS controller to use to
347 access the hosts HostAddress.
348 @param Mapping A resulting value to pass to Unmap().
350 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
351 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
352 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
353 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
354 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
360 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
361 IN EDKII_UFS_HOST_CONTROLLER_OPERATION Operation
,
362 IN VOID
*HostAddress
,
363 IN OUT UINTN
*NumberOfBytes
,
364 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
369 Completes the Map() operation and releases any corresponding resources.
371 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
372 @param Mapping The mapping value returned from Map().
374 @retval EFI_SUCCESS The range was unmapped.
375 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
381 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
386 Allocates pages that are suitable for an EfiUfsHcOperationBusMasterCommonBuffer
389 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
390 @param Type This parameter is not used and must be ignored.
391 @param MemoryType The type of memory to allocate, EfiBootServicesData or
392 EfiRuntimeServicesData.
393 @param Pages The number of pages to allocate.
394 @param HostAddress A pointer to store the base system memory address of the
396 @param Attributes The requested bit mask of attributes for the allocated range.
398 @retval EFI_SUCCESS The requested memory pages were allocated.
399 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
400 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
401 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
402 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
407 UfsHcAllocateBuffer (
408 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
409 IN EFI_ALLOCATE_TYPE Type
,
410 IN EFI_MEMORY_TYPE MemoryType
,
412 OUT VOID
**HostAddress
,
417 Frees memory that was allocated with AllocateBuffer().
419 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
420 @param Pages The number of pages to free.
421 @param HostAddress The base system memory address of the allocated range.
423 @retval EFI_SUCCESS The requested memory pages were freed.
424 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
425 was not allocated with AllocateBuffer().
431 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This
,
437 Flushes all posted write transactions from the UFS bus to attached UFS device.
439 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
441 @retval EFI_SUCCESS The posted write transactions were flushed from the UFS bus
442 to attached UFS device.
443 @retval EFI_DEVICE_ERROR The posted write transactions were not flushed from the UFS
444 bus to attached UFS device due to a hardware error.
450 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL
*This