]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/UfsPciHcDxe/UfsPciHcDxe.h
a2e61d61280460c67ecf3d12dd93b02e89a6b188
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / UfsPciHcDxe / UfsPciHcDxe.h
1 /** @file
2 UfsHcDxe driver is used to provide platform-dependent info, mainly UFS host controller
3 MMIO base, to upper layer UFS drivers.
4
5 Copyright (c) 2014 - 2018, 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.
10
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.
13
14 **/
15
16 #ifndef _EFI_UFS_HOST_CONTROLLER_H_
17 #define _EFI_UFS_HOST_CONTROLLER_H_
18
19 #include <Uefi.h>
20
21 #include <IndustryStandard/Pci.h>
22 #include <IndustryStandard/Acpi.h>
23
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>
31
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>
39
40 extern EFI_DRIVER_BINDING_PROTOCOL gUfsHcDriverBinding;
41 extern EFI_COMPONENT_NAME_PROTOCOL gUfsHcComponentName;
42 extern EFI_COMPONENT_NAME2_PROTOCOL gUfsHcComponentName2;
43
44 //
45 // Unique signature for private data structure.
46 //
47 #define UFS_HC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U','F','S','H')
48
49 typedef struct _UFS_HOST_CONTROLLER_PRIVATE_DATA UFS_HOST_CONTROLLER_PRIVATE_DATA;
50
51 //
52 // Ufs host controller private data structure.
53 //
54 struct _UFS_HOST_CONTROLLER_PRIVATE_DATA {
55 UINT32 Signature;
56
57 EDKII_UFS_HOST_CONTROLLER_PROTOCOL UfsHc;
58 EFI_PCI_IO_PROTOCOL *PciIo;
59 UINT8 BarIndex;
60 UINT64 PciAttributes;
61 };
62
63 #define UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC(a) \
64 CR (a, \
65 UFS_HOST_CONTROLLER_PRIVATE_DATA, \
66 UfsHc, \
67 UFS_HC_PRIVATE_DATA_SIGNATURE \
68 )
69
70 /**
71 Retrieves a Unicode string that is the user readable name of the driver.
72
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.
79
80 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
81 EFI_COMPONENT_NAME_PROTOCOL instance.
82
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.
91
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.
96
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.
100
101 @retval EFI_INVALID_PARAMETER Language is NULL.
102
103 @retval EFI_INVALID_PARAMETER DriverName is NULL.
104
105 @retval EFI_UNSUPPORTED The driver specified by This does not support
106 the language specified by Language.
107
108 **/
109 EFI_STATUS
110 EFIAPI
111 UfsHcComponentNameGetDriverName (
112 IN EFI_COMPONENT_NAME_PROTOCOL *This,
113 IN CHAR8 *Language,
114 OUT CHAR16 **DriverName
115 );
116
117 /**
118 Retrieves a Unicode string that is the user readable name of the controller
119 that is being managed by a driver.
120
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.
129
130 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
131 EFI_COMPONENT_NAME_PROTOCOL instance.
132
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
136 returned.
137
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
145 child controller.
146
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.
155
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
161 specified by This.
162
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
166 DriverName.
167
168 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
169
170 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
171 EFI_HANDLE.
172
173 @retval EFI_INVALID_PARAMETER Language is NULL.
174
175 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
176
177 @retval EFI_UNSUPPORTED The driver specified by This is not currently
178 managing the controller specified by
179 ControllerHandle and ChildHandle.
180
181 @retval EFI_UNSUPPORTED The driver specified by This does not support
182 the language specified by Language.
183
184 **/
185 EFI_STATUS
186 EFIAPI
187 UfsHcComponentNameGetControllerName (
188 IN EFI_COMPONENT_NAME_PROTOCOL *This,
189 IN EFI_HANDLE ControllerHandle,
190 IN EFI_HANDLE ChildHandle OPTIONAL,
191 IN CHAR8 *Language,
192 OUT CHAR16 **ControllerName
193 );
194
195 /**
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.
198
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.
212
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
223 bus driver.
224
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
229 specified by This.
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.
236 **/
237 EFI_STATUS
238 EFIAPI
239 UfsHcDriverBindingSupported (
240 IN EFI_DRIVER_BINDING_PROTOCOL *This,
241 IN EFI_HANDLE Controller,
242 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
243 );
244
245 /**
246 Starts a device controller or a bus controller.
247
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.
257
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
272 driver.
273
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.
278
279 **/
280 EFI_STATUS
281 EFIAPI
282 UfsHcDriverBindingStart (
283 IN EFI_DRIVER_BINDING_PROTOCOL *This,
284 IN EFI_HANDLE Controller,
285 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
286 );
287
288 /**
289 Stops a device controller or a bus controller.
290
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.
301
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.
309
310 @retval EFI_SUCCESS The device was stopped.
311 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
312
313 **/
314 EFI_STATUS
315 EFIAPI
316 UfsHcDriverBindingStop (
317 IN EFI_DRIVER_BINDING_PROTOCOL *This,
318 IN EFI_HANDLE Controller,
319 IN UINTN NumberOfChildren,
320 IN EFI_HANDLE *ChildHandleBuffer
321 );
322
323 /**
324 Get the MMIO base of the UFS host controller.
325
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.
328
329 @retval EFI_SUCCESS The operation succeeds.
330 @retval others The operation fails.
331 **/
332 EFI_STATUS
333 EFIAPI
334 UfsHcGetMmioBar (
335 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
336 OUT UINTN *MmioBar
337 );
338
339 /**
340 Provides the UFS controller-specific addresses needed to access system memory.
341
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
346 that were mapped.
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().
350
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.
356
357 **/
358 EFI_STATUS
359 EFIAPI
360 UfsHcMap (
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,
366 OUT VOID **Mapping
367 );
368
369 /**
370 Completes the Map() operation and releases any corresponding resources.
371
372 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
373 @param Mapping The mapping value returned from Map().
374
375 @retval EFI_SUCCESS The range was unmapped.
376 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
377
378 **/
379 EFI_STATUS
380 EFIAPI
381 UfsHcUnmap (
382 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
383 IN VOID *Mapping
384 );
385
386 /**
387 Allocates pages that are suitable for an EfiUfsHcOperationBusMasterCommonBuffer
388 mapping.
389
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
396 allocated range.
397 @param Attributes The requested bit mask of attributes for the allocated range.
398
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.
404
405 **/
406 EFI_STATUS
407 EFIAPI
408 UfsHcAllocateBuffer (
409 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
410 IN EFI_ALLOCATE_TYPE Type,
411 IN EFI_MEMORY_TYPE MemoryType,
412 IN UINTN Pages,
413 OUT VOID **HostAddress,
414 IN UINT64 Attributes
415 );
416
417 /**
418 Frees memory that was allocated with AllocateBuffer().
419
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.
423
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().
427
428 **/
429 EFI_STATUS
430 EFIAPI
431 UfsHcFreeBuffer (
432 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
433 IN UINTN Pages,
434 IN VOID *HostAddress
435 );
436
437 /**
438 Flushes all posted write transactions from the UFS bus to attached UFS device.
439
440 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
441
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.
446
447 **/
448 EFI_STATUS
449 EFIAPI
450 UfsHcFlush (
451 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This
452 );
453
454 /**
455 Enable a UFS bus driver to access UFS MMIO registers in the UFS Host Controller memory space.
456
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
460 memory operation.
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.
464
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.
470
471 **/
472 EFI_STATUS
473 EFIAPI
474 UfsHcMmioRead (
475 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
476 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL_WIDTH Width,
477 IN UINT64 Offset,
478 IN UINTN Count,
479 IN OUT VOID *Buffer
480 );
481
482 /**
483 Enable a UFS bus driver to access UFS MMIO registers in the UFS Host Controller memory space.
484
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
488 memory operation.
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.
492
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.
498
499 **/
500 EFI_STATUS
501 EFIAPI
502 UfsHcMmioWrite (
503 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
504 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL_WIDTH Width,
505 IN UINT64 Offset,
506 IN UINTN Count,
507 IN OUT VOID *Buffer
508 );
509
510 #endif