]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/UfsPciHcDxe/UfsPciHcDxe.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _EFI_UFS_HOST_CONTROLLER_H_
11 #define _EFI_UFS_HOST_CONTROLLER_H_
12
13 #include <Uefi.h>
14
15 #include <IndustryStandard/Pci.h>
16 #include <IndustryStandard/Acpi.h>
17
18 #include <Protocol/ComponentName.h>
19 #include <Protocol/ComponentName2.h>
20 #include <Protocol/DriverBinding.h>
21 #include <Protocol/LoadedImage.h>
22 #include <Protocol/DevicePath.h>
23 #include <Protocol/PciIo.h>
24 #include <Protocol/UfsHostController.h>
25
26 #include <Library/BaseLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/UefiLib.h>
29 #include <Library/MemoryAllocationLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiDriverEntryPoint.h>
32
33 extern EFI_DRIVER_BINDING_PROTOCOL gUfsHcDriverBinding;
34 extern EFI_COMPONENT_NAME_PROTOCOL gUfsHcComponentName;
35 extern EFI_COMPONENT_NAME2_PROTOCOL gUfsHcComponentName2;
36
37 //
38 // Unique signature for private data structure.
39 //
40 #define UFS_HC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U','F','S','H')
41
42 typedef struct _UFS_HOST_CONTROLLER_PRIVATE_DATA UFS_HOST_CONTROLLER_PRIVATE_DATA;
43
44 //
45 // Ufs host controller private data structure.
46 //
47 struct _UFS_HOST_CONTROLLER_PRIVATE_DATA {
48 UINT32 Signature;
49
50 EDKII_UFS_HOST_CONTROLLER_PROTOCOL UfsHc;
51 EFI_PCI_IO_PROTOCOL *PciIo;
52 UINT8 BarIndex;
53 UINT64 PciAttributes;
54 };
55
56 #define UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC(a) \
57 CR (a, \
58 UFS_HOST_CONTROLLER_PRIVATE_DATA, \
59 UfsHc, \
60 UFS_HC_PRIVATE_DATA_SIGNATURE \
61 )
62
63 /**
64 Retrieves a Unicode string that is the user readable name of the driver.
65
66 This function retrieves the user readable name of a driver in the form of a
67 Unicode string. If the driver specified by This has a user readable name in
68 the language specified by Language, then a pointer to the driver name is
69 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
70 by This does not support the language specified by Language,
71 then EFI_UNSUPPORTED is returned.
72
73 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
74 EFI_COMPONENT_NAME_PROTOCOL instance.
75
76 @param Language[in] A pointer to a Null-terminated ASCII string
77 array indicating the language. This is the
78 language of the driver name that the caller is
79 requesting, and it must match one of the
80 languages specified in SupportedLanguages. The
81 number of languages supported by a driver is up
82 to the driver writer. Language is specified
83 in RFC 4646 or ISO 639-2 language code format.
84
85 @param DriverName[out] A pointer to the Unicode string to return.
86 This Unicode string is the name of the
87 driver specified by This in the language
88 specified by Language.
89
90 @retval EFI_SUCCESS The Unicode string for the Driver specified by
91 This and the language specified by Language was
92 returned in DriverName.
93
94 @retval EFI_INVALID_PARAMETER Language is NULL.
95
96 @retval EFI_INVALID_PARAMETER DriverName is NULL.
97
98 @retval EFI_UNSUPPORTED The driver specified by This does not support
99 the language specified by Language.
100
101 **/
102 EFI_STATUS
103 EFIAPI
104 UfsHcComponentNameGetDriverName (
105 IN EFI_COMPONENT_NAME_PROTOCOL *This,
106 IN CHAR8 *Language,
107 OUT CHAR16 **DriverName
108 );
109
110 /**
111 Retrieves a Unicode string that is the user readable name of the controller
112 that is being managed by a driver.
113
114 This function retrieves the user readable name of the controller specified by
115 ControllerHandle and ChildHandle in the form of a Unicode string. If the
116 driver specified by This has a user readable name in the language specified by
117 Language, then a pointer to the controller name is returned in ControllerName,
118 and EFI_SUCCESS is returned. If the driver specified by This is not currently
119 managing the controller specified by ControllerHandle and ChildHandle,
120 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
121 support the language specified by Language, then EFI_UNSUPPORTED is returned.
122
123 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
124 EFI_COMPONENT_NAME_PROTOCOL instance.
125
126 @param ControllerHandle[in] The handle of a controller that the driver
127 specified by This is managing. This handle
128 specifies the controller whose name is to be
129 returned.
130
131 @param ChildHandle[in] The handle of the child controller to retrieve
132 the name of. This is an optional parameter that
133 may be NULL. It will be NULL for device
134 drivers. It will also be NULL for a bus drivers
135 that wish to retrieve the name of the bus
136 controller. It will not be NULL for a bus
137 driver that wishes to retrieve the name of a
138 child controller.
139
140 @param Language[in] A pointer to a Null-terminated ASCII string
141 array indicating the language. This is the
142 language of the driver name that the caller is
143 requesting, and it must match one of the
144 languages specified in SupportedLanguages. The
145 number of languages supported by a driver is up
146 to the driver writer. Language is specified in
147 RFC 4646 or ISO 639-2 language code format.
148
149 @param ControllerName[out] A pointer to the Unicode string to return.
150 This Unicode string is the name of the
151 controller specified by ControllerHandle and
152 ChildHandle in the language specified by
153 Language from the point of view of the driver
154 specified by This.
155
156 @retval EFI_SUCCESS The Unicode string for the user readable name in
157 the language specified by Language for the
158 driver specified by This was returned in
159 DriverName.
160
161 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
162
163 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
164 EFI_HANDLE.
165
166 @retval EFI_INVALID_PARAMETER Language is NULL.
167
168 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
169
170 @retval EFI_UNSUPPORTED The driver specified by This is not currently
171 managing the controller specified by
172 ControllerHandle and ChildHandle.
173
174 @retval EFI_UNSUPPORTED The driver specified by This does not support
175 the language specified by Language.
176
177 **/
178 EFI_STATUS
179 EFIAPI
180 UfsHcComponentNameGetControllerName (
181 IN EFI_COMPONENT_NAME_PROTOCOL *This,
182 IN EFI_HANDLE ControllerHandle,
183 IN EFI_HANDLE ChildHandle OPTIONAL,
184 IN CHAR8 *Language,
185 OUT CHAR16 **ControllerName
186 );
187
188 /**
189 Tests to see if this driver supports a given controller. If a child device is provided,
190 it further tests to see if this driver supports creating a handle for the specified child device.
191
192 This function checks to see if the driver specified by This supports the device specified by
193 ControllerHandle. Drivers will typically use the device path attached to
194 ControllerHandle and/or the services from the bus I/O abstraction attached to
195 ControllerHandle to determine if the driver supports ControllerHandle. This function
196 may be called many times during platform initialization. In order to reduce boot times, the tests
197 performed by this function must be very small, and take as little time as possible to execute. This
198 function must not change the state of any hardware devices, and this function must be aware that the
199 device specified by ControllerHandle may already be managed by the same driver or a
200 different driver. This function must match its calls to AllocatePages() with FreePages(),
201 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
202 Since ControllerHandle may have been previously started by the same driver, if a protocol is
203 already in the opened state, then it must not be closed with CloseProtocol(). This is required
204 to guarantee the state of ControllerHandle is not modified by this function.
205
206 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
207 @param[in] ControllerHandle The handle of the controller to test. This handle
208 must support a protocol interface that supplies
209 an I/O abstraction to the driver.
210 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
211 parameter is ignored by device drivers, and is optional for bus
212 drivers. For bus drivers, if this parameter is not NULL, then
213 the bus driver must determine if the bus controller specified
214 by ControllerHandle and the child controller specified
215 by RemainingDevicePath are both supported by this
216 bus driver.
217
218 @retval EFI_SUCCESS The device specified by ControllerHandle and
219 RemainingDevicePath is supported by the driver specified by This.
220 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
221 RemainingDevicePath is already being managed by the driver
222 specified by This.
223 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
224 RemainingDevicePath is already being managed by a different
225 driver or an application that requires exclusive access.
226 Currently not implemented.
227 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
228 RemainingDevicePath is not supported by the driver specified by This.
229 **/
230 EFI_STATUS
231 EFIAPI
232 UfsHcDriverBindingSupported (
233 IN EFI_DRIVER_BINDING_PROTOCOL *This,
234 IN EFI_HANDLE Controller,
235 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
236 );
237
238 /**
239 Starts a device controller or a bus controller.
240
241 The Start() function is designed to be invoked from the EFI boot service ConnectController().
242 As a result, much of the error checking on the parameters to Start() has been moved into this
243 common boot service. It is legal to call Start() from other locations,
244 but the following calling restrictions must be followed or the system behavior will not be deterministic.
245 1. ControllerHandle must be a valid EFI_HANDLE.
246 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
247 EFI_DEVICE_PATH_PROTOCOL.
248 3. Prior to calling Start(), the Supported() function for the driver specified by This must
249 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
250
251 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
252 @param[in] ControllerHandle The handle of the controller to start. This handle
253 must support a protocol interface that supplies
254 an I/O abstraction to the driver.
255 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
256 parameter is ignored by device drivers, and is optional for bus
257 drivers. For a bus driver, if this parameter is NULL, then handles
258 for all the children of Controller are created by this driver.
259 If this parameter is not NULL and the first Device Path Node is
260 not the End of Device Path Node, then only the handle for the
261 child device specified by the first Device Path Node of
262 RemainingDevicePath is created by this driver.
263 If the first Device Path Node of RemainingDevicePath is
264 the End of Device Path Node, no child handle is created by this
265 driver.
266
267 @retval EFI_SUCCESS The device was started.
268 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
269 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
270 @retval Others The driver failded to start the device.
271
272 **/
273 EFI_STATUS
274 EFIAPI
275 UfsHcDriverBindingStart (
276 IN EFI_DRIVER_BINDING_PROTOCOL *This,
277 IN EFI_HANDLE Controller,
278 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
279 );
280
281 /**
282 Stops a device controller or a bus controller.
283
284 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
285 As a result, much of the error checking on the parameters to Stop() has been moved
286 into this common boot service. It is legal to call Stop() from other locations,
287 but the following calling restrictions must be followed or the system behavior will not be deterministic.
288 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
289 same driver's Start() function.
290 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
291 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
292 Start() function, and the Start() function must have called OpenProtocol() on
293 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
294
295 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
296 @param[in] ControllerHandle A handle to the device being stopped. The handle must
297 support a bus specific I/O protocol for the driver
298 to use to stop the device.
299 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
300 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
301 if NumberOfChildren is 0.
302
303 @retval EFI_SUCCESS The device was stopped.
304 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
305
306 **/
307 EFI_STATUS
308 EFIAPI
309 UfsHcDriverBindingStop (
310 IN EFI_DRIVER_BINDING_PROTOCOL *This,
311 IN EFI_HANDLE Controller,
312 IN UINTN NumberOfChildren,
313 IN EFI_HANDLE *ChildHandleBuffer
314 );
315
316 /**
317 Get the MMIO base of the UFS host controller.
318
319 @param[in] This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
320 @param[out] MmioBar The MMIO base address of UFS host controller.
321
322 @retval EFI_SUCCESS The operation succeeds.
323 @retval others The operation fails.
324 **/
325 EFI_STATUS
326 EFIAPI
327 UfsHcGetMmioBar (
328 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
329 OUT UINTN *MmioBar
330 );
331
332 /**
333 Provides the UFS controller-specific addresses needed to access system memory.
334
335 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
336 @param Operation Indicates if the bus master is going to read or write to system memory.
337 @param HostAddress The system memory address to map to the UFS controller.
338 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
339 that were mapped.
340 @param DeviceAddress The resulting map address for the bus master UFS controller to use to
341 access the hosts HostAddress.
342 @param Mapping A resulting value to pass to Unmap().
343
344 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
345 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
346 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
347 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
348 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
349
350 **/
351 EFI_STATUS
352 EFIAPI
353 UfsHcMap (
354 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
355 IN EDKII_UFS_HOST_CONTROLLER_OPERATION Operation,
356 IN VOID *HostAddress,
357 IN OUT UINTN *NumberOfBytes,
358 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
359 OUT VOID **Mapping
360 );
361
362 /**
363 Completes the Map() operation and releases any corresponding resources.
364
365 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
366 @param Mapping The mapping value returned from Map().
367
368 @retval EFI_SUCCESS The range was unmapped.
369 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
370
371 **/
372 EFI_STATUS
373 EFIAPI
374 UfsHcUnmap (
375 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
376 IN VOID *Mapping
377 );
378
379 /**
380 Allocates pages that are suitable for an EfiUfsHcOperationBusMasterCommonBuffer
381 mapping.
382
383 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
384 @param Type This parameter is not used and must be ignored.
385 @param MemoryType The type of memory to allocate, EfiBootServicesData or
386 EfiRuntimeServicesData.
387 @param Pages The number of pages to allocate.
388 @param HostAddress A pointer to store the base system memory address of the
389 allocated range.
390 @param Attributes The requested bit mask of attributes for the allocated range.
391
392 @retval EFI_SUCCESS The requested memory pages were allocated.
393 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
394 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
395 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
396 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
397
398 **/
399 EFI_STATUS
400 EFIAPI
401 UfsHcAllocateBuffer (
402 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
403 IN EFI_ALLOCATE_TYPE Type,
404 IN EFI_MEMORY_TYPE MemoryType,
405 IN UINTN Pages,
406 OUT VOID **HostAddress,
407 IN UINT64 Attributes
408 );
409
410 /**
411 Frees memory that was allocated with AllocateBuffer().
412
413 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
414 @param Pages The number of pages to free.
415 @param HostAddress The base system memory address of the allocated range.
416
417 @retval EFI_SUCCESS The requested memory pages were freed.
418 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
419 was not allocated with AllocateBuffer().
420
421 **/
422 EFI_STATUS
423 EFIAPI
424 UfsHcFreeBuffer (
425 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
426 IN UINTN Pages,
427 IN VOID *HostAddress
428 );
429
430 /**
431 Flushes all posted write transactions from the UFS bus to attached UFS device.
432
433 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
434
435 @retval EFI_SUCCESS The posted write transactions were flushed from the UFS bus
436 to attached UFS device.
437 @retval EFI_DEVICE_ERROR The posted write transactions were not flushed from the UFS
438 bus to attached UFS device due to a hardware error.
439
440 **/
441 EFI_STATUS
442 EFIAPI
443 UfsHcFlush (
444 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This
445 );
446
447 /**
448 Enable a UFS bus driver to access UFS MMIO registers in the UFS Host Controller memory space.
449
450 @param This A pointer to the EDKII_UFS_HOST_CONTROLLER_PROTOCOL instance.
451 @param Width Signifies the width of the memory operations.
452 @param Offset The offset within the UFS Host Controller MMIO space to start the
453 memory operation.
454 @param Count The number of memory operations to perform.
455 @param Buffer For read operations, the destination buffer to store the results.
456 For write operations, the source buffer to write data from.
457
458 @retval EFI_SUCCESS The data was read from or written to the UFS host controller.
459 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
460 valid for the UFS Host Controller memory space.
461 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
462 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
463
464 **/
465 EFI_STATUS
466 EFIAPI
467 UfsHcMmioRead (
468 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
469 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL_WIDTH Width,
470 IN UINT64 Offset,
471 IN UINTN Count,
472 IN OUT VOID *Buffer
473 );
474
475 /**
476 Enable a UFS bus driver to access UFS MMIO registers in the UFS Host Controller memory space.
477
478 @param This A pointer to the EDKII_UFS_HOST_CONTROLLER_PROTOCOL instance.
479 @param Width Signifies the width of the memory operations.
480 @param Offset The offset within the UFS Host Controller MMIO space to start the
481 memory operation.
482 @param Count The number of memory operations to perform.
483 @param Buffer For read operations, the destination buffer to store the results.
484 For write operations, the source buffer to write data from.
485
486 @retval EFI_SUCCESS The data was read from or written to the UFS host controller.
487 @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not
488 valid for the UFS Host Controller memory space.
489 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
490 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
491
492 **/
493 EFI_STATUS
494 EFIAPI
495 UfsHcMmioWrite (
496 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
497 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL_WIDTH Width,
498 IN UINT64 Offset,
499 IN UINTN Count,
500 IN OUT VOID *Buffer
501 );
502
503 #endif