]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/UfsPciHcDxe/UfsPciHcDxe.h
MdeModulePkg: Add UFS (Universal Flash Storage) Stack
[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, 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
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>
30
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>
38
39 extern EFI_DRIVER_BINDING_PROTOCOL gUfsHcDriverBinding;
40 extern EFI_COMPONENT_NAME_PROTOCOL gUfsHcComponentName;
41 extern EFI_COMPONENT_NAME2_PROTOCOL gUfsHcComponentName2;
42
43 //
44 // Unique signature for private data structure.
45 //
46 #define UFS_HC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('U','F','S','H')
47
48 typedef struct _UFS_HOST_CONTROLLER_PRIVATE_DATA UFS_HOST_CONTROLLER_PRIVATE_DATA;
49
50 //
51 // Nvme private data structure.
52 //
53 struct _UFS_HOST_CONTROLLER_PRIVATE_DATA {
54 UINT32 Signature;
55 EFI_HANDLE Handle;
56
57 EDKII_UFS_HOST_CONTROLLER_PROTOCOL UfsHc;
58 EFI_PCI_IO_PROTOCOL *PciIo;
59 UINT64 PciAttributes;
60 };
61
62 #define UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC(a) \
63 CR (a, \
64 UFS_HOST_CONTROLLER_PRIVATE_DATA, \
65 UfsHc, \
66 UFS_HC_PRIVATE_DATA_SIGNATURE \
67 )
68
69 /**
70 Retrieves a Unicode string that is the user readable name of the driver.
71
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.
78
79 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
80 EFI_COMPONENT_NAME_PROTOCOL instance.
81
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.
90
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.
95
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.
99
100 @retval EFI_INVALID_PARAMETER Language is NULL.
101
102 @retval EFI_INVALID_PARAMETER DriverName is NULL.
103
104 @retval EFI_UNSUPPORTED The driver specified by This does not support
105 the language specified by Language.
106
107 **/
108 EFI_STATUS
109 EFIAPI
110 UfsHcComponentNameGetDriverName (
111 IN EFI_COMPONENT_NAME_PROTOCOL *This,
112 IN CHAR8 *Language,
113 OUT CHAR16 **DriverName
114 );
115
116 /**
117 Retrieves a Unicode string that is the user readable name of the controller
118 that is being managed by a driver.
119
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.
128
129 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
130 EFI_COMPONENT_NAME_PROTOCOL instance.
131
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
135 returned.
136
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
144 child controller.
145
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.
154
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
160 specified by This.
161
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
165 DriverName.
166
167 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
168
169 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
170 EFI_HANDLE.
171
172 @retval EFI_INVALID_PARAMETER Language is NULL.
173
174 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
175
176 @retval EFI_UNSUPPORTED The driver specified by This is not currently
177 managing the controller specified by
178 ControllerHandle and ChildHandle.
179
180 @retval EFI_UNSUPPORTED The driver specified by This does not support
181 the language specified by Language.
182
183 **/
184 EFI_STATUS
185 EFIAPI
186 UfsHcComponentNameGetControllerName (
187 IN EFI_COMPONENT_NAME_PROTOCOL *This,
188 IN EFI_HANDLE ControllerHandle,
189 IN EFI_HANDLE ChildHandle OPTIONAL,
190 IN CHAR8 *Language,
191 OUT CHAR16 **ControllerName
192 );
193
194 /**
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.
197
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.
211
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
222 bus driver.
223
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
228 specified by This.
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.
235 **/
236 EFI_STATUS
237 EFIAPI
238 UfsHcDriverBindingSupported (
239 IN EFI_DRIVER_BINDING_PROTOCOL *This,
240 IN EFI_HANDLE Controller,
241 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
242 );
243
244 /**
245 Starts a device controller or a bus controller.
246
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.
256
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
271 driver.
272
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.
277
278 **/
279 EFI_STATUS
280 EFIAPI
281 UfsHcDriverBindingStart (
282 IN EFI_DRIVER_BINDING_PROTOCOL *This,
283 IN EFI_HANDLE Controller,
284 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
285 );
286
287 /**
288 Stops a device controller or a bus controller.
289
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.
300
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.
308
309 @retval EFI_SUCCESS The device was stopped.
310 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
311
312 **/
313 EFI_STATUS
314 EFIAPI
315 UfsHcDriverBindingStop (
316 IN EFI_DRIVER_BINDING_PROTOCOL *This,
317 IN EFI_HANDLE Controller,
318 IN UINTN NumberOfChildren,
319 IN EFI_HANDLE *ChildHandleBuffer
320 );
321
322 /**
323 Get the MMIO base of the UFS host controller.
324
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.
327
328 @retval EFI_SUCCESS The operation succeeds.
329 @retval others The operation fails.
330 **/
331 EFI_STATUS
332 EFIAPI
333 UfsHcGetMmioBar (
334 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
335 OUT UINTN *MmioBar
336 );
337
338 /**
339 Provides the UFS controller-specific addresses needed to access system memory.
340
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
345 that were mapped.
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().
349
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.
355
356 **/
357 EFI_STATUS
358 EFIAPI
359 UfsHcMap (
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,
365 OUT VOID **Mapping
366 );
367
368 /**
369 Completes the Map() operation and releases any corresponding resources.
370
371 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
372 @param Mapping The mapping value returned from Map().
373
374 @retval EFI_SUCCESS The range was unmapped.
375 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
376
377 **/
378 EFI_STATUS
379 EFIAPI
380 UfsHcUnmap (
381 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
382 IN VOID *Mapping
383 );
384
385 /**
386 Allocates pages that are suitable for an EfiUfsHcOperationBusMasterCommonBuffer
387 mapping.
388
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
395 allocated range.
396 @param Attributes The requested bit mask of attributes for the allocated range.
397
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.
403
404 **/
405 EFI_STATUS
406 EFIAPI
407 UfsHcAllocateBuffer (
408 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
409 IN EFI_ALLOCATE_TYPE Type,
410 IN EFI_MEMORY_TYPE MemoryType,
411 IN UINTN Pages,
412 OUT VOID **HostAddress,
413 IN UINT64 Attributes
414 );
415
416 /**
417 Frees memory that was allocated with AllocateBuffer().
418
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.
422
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().
426
427 **/
428 EFI_STATUS
429 EFIAPI
430 UfsHcFreeBuffer (
431 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
432 IN UINTN Pages,
433 IN VOID *HostAddress
434 );
435
436 /**
437 Flushes all posted write transactions from the UFS bus to attached UFS device.
438
439 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
440
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.
445
446 **/
447 EFI_STATUS
448 EFIAPI
449 UfsHcFlush (
450 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This
451 );
452
453 #endif