]>
Commit | Line | Data |
---|---|---|
0591696e FT |
1 | /** @file\r |
2 | UfsHcDxe driver is used to provide platform-dependent info, mainly UFS host controller\r | |
3 | MMIO base, to upper layer UFS drivers.\r | |
4 | \r | |
5 | Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r | |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php.\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "UfsPciHcDxe.h"\r | |
17 | \r | |
18 | //\r | |
19 | // NVM Express Driver Binding Protocol Instance\r | |
20 | //\r | |
21 | EFI_DRIVER_BINDING_PROTOCOL gUfsHcDriverBinding = {\r | |
22 | UfsHcDriverBindingSupported,\r | |
23 | UfsHcDriverBindingStart,\r | |
24 | UfsHcDriverBindingStop,\r | |
25 | 0x10,\r | |
26 | NULL,\r | |
27 | NULL\r | |
28 | };\r | |
29 | \r | |
30 | //\r | |
31 | // Template for Ufs host controller private data.\r | |
32 | //\r | |
33 | UFS_HOST_CONTROLLER_PRIVATE_DATA gUfsHcTemplate = {\r | |
34 | UFS_HC_PRIVATE_DATA_SIGNATURE, // Signature\r | |
35 | NULL, // Handle\r | |
36 | { // UfsHcProtocol\r | |
37 | UfsHcGetMmioBar,\r | |
38 | UfsHcAllocateBuffer,\r | |
39 | UfsHcFreeBuffer,\r | |
40 | UfsHcMap,\r | |
41 | UfsHcUnmap,\r | |
42 | UfsHcFlush\r | |
43 | },\r | |
44 | NULL, // PciIo\r | |
45 | 0 // PciAttributes\r | |
46 | };\r | |
47 | \r | |
48 | /**\r | |
49 | Get the MMIO base of the UFS host controller.\r | |
50 | \r | |
51 | @param[in] This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.\r | |
52 | @param[out] MmioBar The MMIO base address of UFS host controller.\r | |
53 | \r | |
54 | @retval EFI_SUCCESS The operation succeeds.\r | |
55 | @retval others The operation fails.\r | |
56 | **/\r | |
57 | EFI_STATUS\r | |
58 | EFIAPI\r | |
59 | UfsHcGetMmioBar (\r | |
60 | IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,\r | |
61 | OUT UINTN *MmioBar\r | |
62 | )\r | |
63 | {\r | |
64 | UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;\r | |
65 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
66 | EFI_STATUS Status;\r | |
67 | \r | |
68 | if ((This == NULL) || (MmioBar == NULL)) {\r | |
69 | return EFI_INVALID_PARAMETER;\r | |
70 | }\r | |
71 | \r | |
72 | Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);\r | |
73 | PciIo = Private->PciIo;\r | |
74 | \r | |
75 | Status = PciIo->Pci.Read (\r | |
76 | PciIo,\r | |
77 | EfiPciIoWidthUint8,\r | |
78 | PCI_BASE_ADDRESSREG_OFFSET,\r | |
79 | sizeof (UINT32),\r | |
80 | MmioBar\r | |
81 | );\r | |
82 | \r | |
83 | if (!EFI_ERROR (Status)) {\r | |
84 | *MmioBar &= (UINTN)~0xF;\r | |
85 | }\r | |
86 | return Status;\r | |
87 | }\r | |
88 | \r | |
89 | /** \r | |
90 | Provides the UFS controller-specific addresses needed to access system memory.\r | |
91 | \r | |
92 | @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.\r | |
93 | @param Operation Indicates if the bus master is going to read or write to system memory.\r | |
94 | @param HostAddress The system memory address to map to the UFS controller.\r | |
95 | @param NumberOfBytes On input the number of bytes to map. On output the number of bytes\r | |
96 | that were mapped. \r | |
97 | @param DeviceAddress The resulting map address for the bus master UFS controller to use to\r | |
98 | access the hosts HostAddress. \r | |
99 | @param Mapping A resulting value to pass to Unmap().\r | |
100 | \r | |
101 | @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r | |
102 | @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer. \r | |
103 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r | |
104 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
105 | @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r | |
106 | \r | |
107 | **/\r | |
108 | EFI_STATUS\r | |
109 | EFIAPI\r | |
110 | UfsHcMap (\r | |
111 | IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,\r | |
112 | IN EDKII_UFS_HOST_CONTROLLER_OPERATION Operation,\r | |
113 | IN VOID *HostAddress,\r | |
114 | IN OUT UINTN *NumberOfBytes,\r | |
115 | OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r | |
116 | OUT VOID **Mapping\r | |
117 | )\r | |
118 | {\r | |
119 | UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;\r | |
120 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
121 | EFI_STATUS Status;\r | |
122 | \r | |
123 | if ((This == NULL) || (HostAddress == NULL) || (NumberOfBytes == NULL) || (DeviceAddress == NULL) || (Mapping == NULL)) {\r | |
124 | return EFI_INVALID_PARAMETER;\r | |
125 | }\r | |
126 | \r | |
127 | Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);\r | |
128 | PciIo = Private->PciIo;\r | |
129 | \r | |
130 | Status = PciIo->Map (PciIo, Operation, HostAddress, NumberOfBytes, DeviceAddress, Mapping);\r | |
131 | return Status;\r | |
132 | }\r | |
133 | \r | |
134 | /** \r | |
135 | Completes the Map() operation and releases any corresponding resources.\r | |
136 | \r | |
137 | @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance. \r | |
138 | @param Mapping The mapping value returned from Map().\r | |
139 | \r | |
140 | @retval EFI_SUCCESS The range was unmapped.\r | |
141 | @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r | |
142 | \r | |
143 | **/\r | |
144 | EFI_STATUS\r | |
145 | EFIAPI\r | |
146 | UfsHcUnmap (\r | |
147 | IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,\r | |
148 | IN VOID *Mapping\r | |
149 | )\r | |
150 | {\r | |
151 | UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;\r | |
152 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
153 | EFI_STATUS Status;\r | |
154 | \r | |
155 | if ((This == NULL) || (Mapping == NULL)) {\r | |
156 | return EFI_INVALID_PARAMETER;\r | |
157 | }\r | |
158 | \r | |
159 | Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);\r | |
160 | PciIo = Private->PciIo;\r | |
161 | \r | |
162 | Status = PciIo->Unmap (PciIo, Mapping);\r | |
163 | return Status;\r | |
164 | }\r | |
165 | \r | |
166 | /** \r | |
167 | Allocates pages that are suitable for an EfiUfsHcOperationBusMasterCommonBuffer\r | |
168 | mapping. \r | |
169 | \r | |
170 | @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.\r | |
171 | @param Type This parameter is not used and must be ignored.\r | |
172 | @param MemoryType The type of memory to allocate, EfiBootServicesData or\r | |
173 | EfiRuntimeServicesData. \r | |
174 | @param Pages The number of pages to allocate. \r | |
175 | @param HostAddress A pointer to store the base system memory address of the\r | |
176 | allocated range. \r | |
177 | @param Attributes The requested bit mask of attributes for the allocated range.\r | |
178 | \r | |
179 | @retval EFI_SUCCESS The requested memory pages were allocated.\r | |
180 | @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r | |
181 | MEMORY_WRITE_COMBINE and MEMORY_CACHED. \r | |
182 | @retval EFI_INVALID_PARAMETER One or more parameters are invalid.\r | |
183 | @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. \r | |
184 | \r | |
185 | **/\r | |
186 | EFI_STATUS\r | |
187 | EFIAPI\r | |
188 | UfsHcAllocateBuffer (\r | |
189 | IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,\r | |
190 | IN EFI_ALLOCATE_TYPE Type,\r | |
191 | IN EFI_MEMORY_TYPE MemoryType,\r | |
192 | IN UINTN Pages,\r | |
193 | OUT VOID **HostAddress,\r | |
194 | IN UINT64 Attributes\r | |
195 | )\r | |
196 | {\r | |
197 | UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;\r | |
198 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
199 | EFI_STATUS Status;\r | |
200 | \r | |
201 | if ((This == NULL) || (HostAddress == NULL)) {\r | |
202 | return EFI_INVALID_PARAMETER;\r | |
203 | }\r | |
204 | \r | |
205 | Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);\r | |
206 | PciIo = Private->PciIo;\r | |
207 | \r | |
208 | Status = PciIo->AllocateBuffer (PciIo, Type, MemoryType, Pages, HostAddress, Attributes);\r | |
209 | return Status;\r | |
210 | }\r | |
211 | \r | |
212 | /** \r | |
213 | Frees memory that was allocated with AllocateBuffer().\r | |
214 | \r | |
215 | @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance. \r | |
216 | @param Pages The number of pages to free. \r | |
217 | @param HostAddress The base system memory address of the allocated range. \r | |
218 | \r | |
219 | @retval EFI_SUCCESS The requested memory pages were freed.\r | |
220 | @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r | |
221 | was not allocated with AllocateBuffer().\r | |
222 | \r | |
223 | **/\r | |
224 | EFI_STATUS\r | |
225 | EFIAPI\r | |
226 | UfsHcFreeBuffer (\r | |
227 | IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,\r | |
228 | IN UINTN Pages,\r | |
229 | IN VOID *HostAddress\r | |
230 | )\r | |
231 | {\r | |
232 | UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;\r | |
233 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
234 | EFI_STATUS Status;\r | |
235 | \r | |
236 | if ((This == NULL) || (HostAddress == NULL)) {\r | |
237 | return EFI_INVALID_PARAMETER;\r | |
238 | }\r | |
239 | \r | |
240 | Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);\r | |
241 | PciIo = Private->PciIo;\r | |
242 | \r | |
243 | Status = PciIo->FreeBuffer (PciIo, Pages, HostAddress);\r | |
244 | return Status;\r | |
245 | }\r | |
246 | \r | |
247 | /** \r | |
248 | Flushes all posted write transactions from the UFS bus to attached UFS device.\r | |
249 | \r | |
250 | @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance. \r | |
251 | \r | |
252 | @retval EFI_SUCCESS The posted write transactions were flushed from the UFS bus\r | |
253 | to attached UFS device. \r | |
254 | @retval EFI_DEVICE_ERROR The posted write transactions were not flushed from the UFS\r | |
255 | bus to attached UFS device due to a hardware error. \r | |
256 | \r | |
257 | **/\r | |
258 | EFI_STATUS\r | |
259 | EFIAPI\r | |
260 | UfsHcFlush (\r | |
261 | IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This\r | |
262 | )\r | |
263 | {\r | |
264 | UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;\r | |
265 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
266 | EFI_STATUS Status;\r | |
267 | \r | |
268 | Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);\r | |
269 | PciIo = Private->PciIo;\r | |
270 | \r | |
271 | Status = PciIo->Flush (PciIo);\r | |
272 | return Status;\r | |
273 | }\r | |
274 | \r | |
275 | /**\r | |
276 | Tests to see if this driver supports a given controller. If a child device is provided,\r | |
277 | it further tests to see if this driver supports creating a handle for the specified child device.\r | |
278 | \r | |
279 | This function checks to see if the driver specified by This supports the device specified by\r | |
280 | ControllerHandle. Drivers will typically use the device path attached to\r | |
281 | ControllerHandle and/or the services from the bus I/O abstraction attached to\r | |
282 | ControllerHandle to determine if the driver supports ControllerHandle. This function\r | |
283 | may be called many times during platform initialization. In order to reduce boot times, the tests\r | |
284 | performed by this function must be very small, and take as little time as possible to execute. This\r | |
285 | function must not change the state of any hardware devices, and this function must be aware that the\r | |
286 | device specified by ControllerHandle may already be managed by the same driver or a\r | |
287 | different driver. This function must match its calls to AllocatePages() with FreePages(),\r | |
288 | AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r | |
289 | Since ControllerHandle may have been previously started by the same driver, if a protocol is\r | |
290 | already in the opened state, then it must not be closed with CloseProtocol(). This is required\r | |
291 | to guarantee the state of ControllerHandle is not modified by this function.\r | |
292 | \r | |
293 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
294 | @param[in] ControllerHandle The handle of the controller to test. This handle\r | |
295 | must support a protocol interface that supplies\r | |
296 | an I/O abstraction to the driver.\r | |
297 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r | |
298 | parameter is ignored by device drivers, and is optional for bus\r | |
299 | drivers. For bus drivers, if this parameter is not NULL, then\r | |
300 | the bus driver must determine if the bus controller specified\r | |
301 | by ControllerHandle and the child controller specified\r | |
302 | by RemainingDevicePath are both supported by this\r | |
303 | bus driver.\r | |
304 | \r | |
305 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r | |
306 | RemainingDevicePath is supported by the driver specified by This.\r | |
307 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
308 | RemainingDevicePath is already being managed by the driver\r | |
309 | specified by This.\r | |
310 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
311 | RemainingDevicePath is already being managed by a different\r | |
312 | driver or an application that requires exclusive access.\r | |
313 | Currently not implemented.\r | |
314 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
315 | RemainingDevicePath is not supported by the driver specified by This.\r | |
316 | **/\r | |
317 | EFI_STATUS\r | |
318 | EFIAPI\r | |
319 | UfsHcDriverBindingSupported (\r | |
320 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
321 | IN EFI_HANDLE Controller,\r | |
322 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
323 | )\r | |
324 | {\r | |
325 | EFI_STATUS Status;\r | |
326 | BOOLEAN UfsHcFound;\r | |
327 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
328 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
329 | PCI_TYPE00 PciData;\r | |
330 | \r | |
331 | PciIo = NULL;\r | |
332 | ParentDevicePath = NULL;\r | |
333 | UfsHcFound = FALSE;\r | |
334 | \r | |
335 | //\r | |
336 | // UfsHcDxe is a device driver, and should ingore the\r | |
337 | // "RemainingDevicePath" according to EFI spec\r | |
338 | //\r | |
339 | Status = gBS->OpenProtocol (\r | |
340 | Controller,\r | |
341 | &gEfiDevicePathProtocolGuid,\r | |
342 | (VOID *) &ParentDevicePath,\r | |
343 | This->DriverBindingHandle,\r | |
344 | Controller,\r | |
345 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
346 | );\r | |
347 | if (EFI_ERROR (Status)) {\r | |
348 | //\r | |
349 | // EFI_ALREADY_STARTED is also an error\r | |
350 | //\r | |
351 | return Status;\r | |
352 | }\r | |
353 | //\r | |
354 | // Close the protocol because we don't use it here\r | |
355 | //\r | |
356 | gBS->CloseProtocol (\r | |
357 | Controller,\r | |
358 | &gEfiDevicePathProtocolGuid,\r | |
359 | This->DriverBindingHandle,\r | |
360 | Controller\r | |
361 | );\r | |
362 | \r | |
363 | //\r | |
364 | // Now test the EfiPciIoProtocol\r | |
365 | //\r | |
366 | Status = gBS->OpenProtocol (\r | |
367 | Controller,\r | |
368 | &gEfiPciIoProtocolGuid,\r | |
369 | (VOID **) &PciIo,\r | |
370 | This->DriverBindingHandle,\r | |
371 | Controller,\r | |
372 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
373 | );\r | |
374 | if (EFI_ERROR (Status)) {\r | |
375 | return Status;\r | |
376 | }\r | |
377 | //\r | |
378 | // Now further check the PCI header: Base class (offset 0x0B) and\r | |
379 | // Sub Class (offset 0x0A). This controller should be an UFS controller\r | |
380 | //\r | |
381 | Status = PciIo->Pci.Read (\r | |
382 | PciIo,\r | |
383 | EfiPciIoWidthUint8,\r | |
384 | 0,\r | |
385 | sizeof (PciData),\r | |
386 | &PciData\r | |
387 | );\r | |
388 | if (EFI_ERROR (Status)) {\r | |
389 | gBS->CloseProtocol (\r | |
390 | Controller,\r | |
391 | &gEfiPciIoProtocolGuid,\r | |
392 | This->DriverBindingHandle,\r | |
393 | Controller\r | |
394 | );\r | |
395 | return EFI_UNSUPPORTED;\r | |
396 | }\r | |
397 | //\r | |
398 | // Since we already got the PciData, we can close protocol to avoid to carry it on for multiple exit points.\r | |
399 | //\r | |
400 | gBS->CloseProtocol (\r | |
401 | Controller,\r | |
402 | &gEfiPciIoProtocolGuid,\r | |
403 | This->DriverBindingHandle,\r | |
404 | Controller\r | |
405 | );\r | |
406 | \r | |
407 | //\r | |
408 | // Examine UFS Host Controller PCI Configuration table fields\r | |
409 | //\r | |
410 | if (PciData.Hdr.ClassCode[2] == PCI_CLASS_MASS_STORAGE) {\r | |
411 | if (PciData.Hdr.ClassCode[1] == 0x09 ) { //UFS Controller Subclass\r | |
412 | UfsHcFound = TRUE;\r | |
413 | }\r | |
414 | }\r | |
415 | \r | |
416 | if (!UfsHcFound) {\r | |
417 | return EFI_UNSUPPORTED;\r | |
418 | }\r | |
419 | \r | |
420 | return Status;\r | |
421 | }\r | |
422 | \r | |
423 | \r | |
424 | /**\r | |
425 | Starts a device controller or a bus controller.\r | |
426 | \r | |
427 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r | |
428 | As a result, much of the error checking on the parameters to Start() has been moved into this\r | |
429 | common boot service. It is legal to call Start() from other locations,\r | |
430 | but the following calling restrictions must be followed or the system behavior will not be deterministic.\r | |
431 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
432 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
433 | EFI_DEVICE_PATH_PROTOCOL.\r | |
434 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
435 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r | |
436 | \r | |
437 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
438 | @param[in] ControllerHandle The handle of the controller to start. This handle\r | |
439 | must support a protocol interface that supplies\r | |
440 | an I/O abstraction to the driver.\r | |
441 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r | |
442 | parameter is ignored by device drivers, and is optional for bus\r | |
443 | drivers. For a bus driver, if this parameter is NULL, then handles\r | |
444 | for all the children of Controller are created by this driver.\r | |
445 | If this parameter is not NULL and the first Device Path Node is\r | |
446 | not the End of Device Path Node, then only the handle for the\r | |
447 | child device specified by the first Device Path Node of\r | |
448 | RemainingDevicePath is created by this driver.\r | |
449 | If the first Device Path Node of RemainingDevicePath is\r | |
450 | the End of Device Path Node, no child handle is created by this\r | |
451 | driver.\r | |
452 | \r | |
453 | @retval EFI_SUCCESS The device was started.\r | |
454 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
455 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
456 | @retval Others The driver failded to start the device.\r | |
457 | \r | |
458 | **/\r | |
459 | EFI_STATUS\r | |
460 | EFIAPI\r | |
461 | UfsHcDriverBindingStart (\r | |
462 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
463 | IN EFI_HANDLE Controller,\r | |
464 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
465 | )\r | |
466 | {\r | |
467 | EFI_STATUS Status;\r | |
468 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
469 | UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;\r | |
470 | UINT64 Supports;\r | |
471 | \r | |
472 | PciIo = NULL;\r | |
473 | Private = NULL;\r | |
474 | Supports = 0;\r | |
475 | \r | |
476 | //\r | |
477 | // Now test and open the EfiPciIoProtocol\r | |
478 | //\r | |
479 | Status = gBS->OpenProtocol (\r | |
480 | Controller,\r | |
481 | &gEfiPciIoProtocolGuid,\r | |
482 | (VOID **) &PciIo,\r | |
483 | This->DriverBindingHandle,\r | |
484 | Controller,\r | |
485 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
486 | );\r | |
487 | //\r | |
488 | // Status == 0 - A normal execution flow, SUCCESS and the program proceeds.\r | |
489 | // Status == ALREADY_STARTED - A non-zero Status code returned. It indicates\r | |
490 | // that the protocol has been opened and should be treated as a\r | |
491 | // normal condition and the program proceeds. The Protocol will not\r | |
492 | // opened 'again' by this call.\r | |
493 | // Status != ALREADY_STARTED - Error status, terminate program execution\r | |
494 | //\r | |
495 | if (EFI_ERROR (Status)) {\r | |
496 | //\r | |
497 | // EFI_ALREADY_STARTED is also an error\r | |
498 | //\r | |
499 | return Status;\r | |
500 | }\r | |
501 | \r | |
502 | Private = AllocateCopyPool (sizeof (UFS_HOST_CONTROLLER_PRIVATE_DATA), &gUfsHcTemplate);\r | |
503 | if (Private == NULL) {\r | |
504 | Status = EFI_OUT_OF_RESOURCES;\r | |
505 | goto Done;\r | |
506 | }\r | |
507 | \r | |
508 | Private->PciIo = PciIo;\r | |
509 | \r | |
510 | Status = PciIo->Attributes (\r | |
511 | PciIo,\r | |
512 | EfiPciIoAttributeOperationGet,\r | |
513 | 0,\r | |
514 | &Private->PciAttributes\r | |
515 | );\r | |
516 | \r | |
517 | if (EFI_ERROR (Status)) {\r | |
518 | goto Done;\r | |
519 | }\r | |
520 | \r | |
521 | Status = PciIo->Attributes (\r | |
522 | PciIo,\r | |
523 | EfiPciIoAttributeOperationSupported,\r | |
524 | 0,\r | |
525 | &Supports\r | |
526 | );\r | |
527 | \r | |
528 | if (!EFI_ERROR (Status)) {\r | |
529 | Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;\r | |
530 | Status = PciIo->Attributes (\r | |
531 | PciIo,\r | |
532 | EfiPciIoAttributeOperationEnable,\r | |
533 | Supports,\r | |
534 | NULL\r | |
535 | );\r | |
536 | } else {\r | |
537 | goto Done;\r | |
538 | }\r | |
539 | \r | |
540 | ///\r | |
541 | /// Install UFS_HOST_CONTROLLER protocol\r | |
542 | ///\r | |
543 | Status = gBS->InstallProtocolInterface (\r | |
544 | &Controller,\r | |
545 | &gEdkiiUfsHostControllerProtocolGuid,\r | |
546 | EFI_NATIVE_INTERFACE,\r | |
547 | (VOID*)&(Private->UfsHc)\r | |
548 | );\r | |
549 | \r | |
550 | Done:\r | |
551 | if (EFI_ERROR (Status)) {\r | |
552 | if ((Private != NULL) && (Private->PciAttributes != 0)) {\r | |
553 | //\r | |
554 | // Restore original PCI attributes\r | |
555 | //\r | |
556 | Status = PciIo->Attributes (\r | |
557 | PciIo,\r | |
558 | EfiPciIoAttributeOperationSet,\r | |
559 | Private->PciAttributes,\r | |
560 | NULL\r | |
561 | );\r | |
562 | ASSERT_EFI_ERROR (Status);\r | |
563 | }\r | |
564 | gBS->CloseProtocol (\r | |
565 | Controller,\r | |
566 | &gEfiPciIoProtocolGuid,\r | |
567 | This->DriverBindingHandle,\r | |
568 | Controller\r | |
569 | );\r | |
570 | if (Private != NULL) {\r | |
571 | FreePool (Private);\r | |
572 | }\r | |
573 | }\r | |
574 | \r | |
575 | return Status;\r | |
576 | }\r | |
577 | \r | |
578 | \r | |
579 | /**\r | |
580 | Stops a device controller or a bus controller.\r | |
581 | \r | |
582 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r | |
583 | As a result, much of the error checking on the parameters to Stop() has been moved\r | |
584 | into this common boot service. It is legal to call Stop() from other locations,\r | |
585 | but the following calling restrictions must be followed or the system behavior will not be deterministic.\r | |
586 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
587 | same driver's Start() function.\r | |
588 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
589 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
590 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
591 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
592 | \r | |
593 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
594 | @param[in] ControllerHandle A handle to the device being stopped. The handle must\r | |
595 | support a bus specific I/O protocol for the driver\r | |
596 | to use to stop the device.\r | |
597 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
598 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r | |
599 | if NumberOfChildren is 0.\r | |
600 | \r | |
601 | @retval EFI_SUCCESS The device was stopped.\r | |
602 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
603 | \r | |
604 | **/\r | |
605 | EFI_STATUS\r | |
606 | EFIAPI\r | |
607 | UfsHcDriverBindingStop (\r | |
608 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
609 | IN EFI_HANDLE Controller,\r | |
610 | IN UINTN NumberOfChildren,\r | |
611 | IN EFI_HANDLE *ChildHandleBuffer\r | |
612 | )\r | |
613 | {\r | |
614 | EFI_STATUS Status;\r | |
615 | UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;\r | |
616 | EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHc;\r | |
617 | \r | |
618 | ///\r | |
619 | /// Get private data\r | |
620 | ///\r | |
621 | Status = gBS->OpenProtocol (\r | |
622 | Controller,\r | |
623 | &gEdkiiUfsHostControllerProtocolGuid,\r | |
624 | (VOID **) &UfsHc,\r | |
625 | This->DriverBindingHandle,\r | |
626 | Controller,\r | |
627 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
628 | );\r | |
629 | \r | |
630 | if (EFI_ERROR (Status)) {\r | |
631 | return EFI_DEVICE_ERROR;\r | |
632 | }\r | |
633 | \r | |
634 | Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (UfsHc);\r | |
635 | \r | |
636 | Status = gBS->UninstallProtocolInterface (\r | |
637 | Controller,\r | |
638 | &gEdkiiUfsHostControllerProtocolGuid,\r | |
639 | &(Private->UfsHc)\r | |
640 | );\r | |
641 | if (!EFI_ERROR (Status)) {\r | |
642 | //\r | |
643 | // Restore original PCI attributes\r | |
644 | //\r | |
645 | Status = Private->PciIo->Attributes (\r | |
646 | Private->PciIo,\r | |
647 | EfiPciIoAttributeOperationSet,\r | |
648 | Private->PciAttributes,\r | |
649 | NULL\r | |
650 | );\r | |
651 | ASSERT_EFI_ERROR (Status);\r | |
652 | \r | |
653 | //\r | |
654 | // Close protocols opened by UFS host controller driver\r | |
655 | //\r | |
656 | gBS->CloseProtocol (\r | |
657 | Controller,\r | |
658 | &gEfiPciIoProtocolGuid,\r | |
659 | This->DriverBindingHandle,\r | |
660 | Controller\r | |
661 | );\r | |
662 | \r | |
663 | FreePool (Private);\r | |
664 | }\r | |
665 | \r | |
666 | return Status;\r | |
667 | }\r | |
668 | \r | |
669 | /**\r | |
670 | The entry point for UFS host controller driver, used to install this driver on the ImageHandle.\r | |
671 | \r | |
672 | @param[in] ImageHandle The firmware allocated handle for this driver image.\r | |
673 | @param[in] SystemTable Pointer to the EFI system table.\r | |
674 | \r | |
675 | @retval EFI_SUCCESS Driver loaded.\r | |
676 | @retval other Driver not loaded.\r | |
677 | \r | |
678 | **/\r | |
679 | EFI_STATUS\r | |
680 | EFIAPI\r | |
681 | UfsHcDriverEntry (\r | |
682 | IN EFI_HANDLE ImageHandle,\r | |
683 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
684 | )\r | |
685 | {\r | |
686 | EFI_STATUS Status;\r | |
687 | \r | |
688 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
689 | ImageHandle,\r | |
690 | SystemTable,\r | |
691 | &gUfsHcDriverBinding,\r | |
692 | ImageHandle,\r | |
693 | &gUfsHcComponentName,\r | |
694 | &gUfsHcComponentName2\r | |
695 | );\r | |
696 | ASSERT_EFI_ERROR (Status);\r | |
697 | \r | |
698 | return Status;\r | |
699 | }\r |