]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/I2c/I2cDxe/I2cHost.c
MdePkg, MdeModulePkg: Remove EFI_ABORTED from I2C protocols per PI spec 1.4.
[mirror_edk2.git] / MdeModulePkg / Bus / I2c / I2cDxe / I2cHost.c
CommitLineData
43e543bc
EL
1/** @file\r
2 This file implements I2C Host Protocol which provides callers with the ability to \r
3 do I/O transactions to all of the devices on the I2C bus.\r
4\r
01331951 5 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>\r
1d956501 6 Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>\r
43e543bc
EL
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "I2cDxe.h"\r
18\r
19EFI_DRIVER_BINDING_PROTOCOL gI2cHostDriverBinding = {\r
20 I2cHostDriverSupported,\r
21 I2cHostDriverStart,\r
22 I2cHostDriverStop,\r
23 0x10,\r
24 NULL,\r
25 NULL\r
26};\r
27\r
28//\r
29// Driver name table \r
30//\r
31GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mI2cHostDriverNameTable[] = {\r
32 { "eng;en", L"I2c Host Driver" },\r
33 { NULL , NULL }\r
34};\r
35\r
36//\r
37// EFI Component Name Protocol\r
38//\r
39GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gI2cHostComponentName = {\r
40 (EFI_COMPONENT_NAME_GET_DRIVER_NAME) I2cHostComponentNameGetDriverName,\r
41 (EFI_COMPONENT_NAME_GET_CONTROLLER_NAME) I2cHostComponentNameGetControllerName,\r
42 "eng"\r
43};\r
44\r
45//\r
46// EFI Component Name 2 Protocol\r
47//\r
48GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gI2cHostComponentName2 = {\r
49 I2cHostComponentNameGetDriverName,\r
50 I2cHostComponentNameGetControllerName,\r
51 "en"\r
52};\r
53\r
54/**\r
55 Retrieves a Unicode string that is the user readable name of the driver.\r
56\r
57 This function retrieves the user readable name of a driver in the form of a\r
58 Unicode string. If the driver specified by This has a user readable name in\r
59 the language specified by Language, then a pointer to the driver name is\r
60 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
61 by This does not support the language specified by Language,\r
62 then EFI_UNSUPPORTED is returned.\r
63\r
64 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
65 EFI_COMPONENT_NAME_PROTOCOL instance.\r
66\r
67 @param Language[in] A pointer to a Null-terminated ASCII string\r
68 array indicating the language. This is the\r
69 language of the driver name that the caller is\r
70 requesting, and it must match one of the\r
71 languages specified in SupportedLanguages. The\r
72 number of languages supported by a driver is up\r
73 to the driver writer. Language is specified\r
74 in RFC 4646 or ISO 639-2 language code format.\r
75\r
76 @param DriverName[out] A pointer to the Unicode string to return.\r
77 This Unicode string is the name of the\r
78 driver specified by This in the language\r
79 specified by Language.\r
80\r
81 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
82 This and the language specified by Language was\r
83 returned in DriverName.\r
84\r
85 @retval EFI_INVALID_PARAMETER Language is NULL.\r
86\r
87 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
88\r
89 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
90 the language specified by Language.\r
91\r
92**/\r
93EFI_STATUS\r
94EFIAPI\r
95I2cHostComponentNameGetDriverName (\r
96 IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
97 IN CHAR8 *Language,\r
98 OUT CHAR16 **DriverName\r
99 )\r
100{\r
101 return LookupUnicodeString2 (\r
102 Language,\r
103 This->SupportedLanguages,\r
104 mI2cHostDriverNameTable,\r
105 DriverName,\r
106 (BOOLEAN)(This != &gI2cHostComponentName2)\r
107 );\r
108}\r
109\r
110/**\r
111 Retrieves a Unicode string that is the user readable name of the controller\r
112 that is being managed by a driver.\r
113\r
114 This function retrieves the user readable name of the controller specified by\r
115 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
116 driver specified by This has a user readable name in the language specified by\r
117 Language, then a pointer to the controller name is returned in ControllerName,\r
118 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
119 managing the controller specified by ControllerHandle and ChildHandle,\r
120 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
121 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
122\r
123 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
124 EFI_COMPONENT_NAME_PROTOCOL instance.\r
125\r
126 @param ControllerHandle[in] The handle of a controller that the driver\r
127 specified by This is managing. This handle\r
128 specifies the controller whose name is to be\r
129 returned.\r
130\r
131 @param ChildHandle[in] The handle of the child controller to retrieve\r
132 the name of. This is an optional parameter that\r
133 may be NULL. It will be NULL for device\r
134 drivers. It will also be NULL for a bus drivers\r
135 that wish to retrieve the name of the bus\r
136 controller. It will not be NULL for a bus\r
137 driver that wishes to retrieve the name of a\r
138 child controller.\r
139\r
140 @param Language[in] A pointer to a Null-terminated ASCII string\r
141 array indicating the language. This is the\r
142 language of the driver name that the caller is\r
143 requesting, and it must match one of the\r
144 languages specified in SupportedLanguages. The\r
145 number of languages supported by a driver is up\r
146 to the driver writer. Language is specified in\r
147 RFC 4646 or ISO 639-2 language code format.\r
148\r
149 @param ControllerName[out] A pointer to the Unicode string to return.\r
150 This Unicode string is the name of the\r
151 controller specified by ControllerHandle and\r
152 ChildHandle in the language specified by\r
153 Language from the point of view of the driver\r
154 specified by This.\r
155\r
156 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
157 the language specified by Language for the\r
158 driver specified by This was returned in\r
159 DriverName.\r
160\r
161 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
162\r
163 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
164 EFI_HANDLE.\r
165\r
166 @retval EFI_INVALID_PARAMETER Language is NULL.\r
167\r
168 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
169\r
170 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
171 managing the controller specified by\r
172 ControllerHandle and ChildHandle.\r
173\r
174 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
175 the language specified by Language.\r
176\r
177**/\r
178EFI_STATUS\r
179EFIAPI\r
180I2cHostComponentNameGetControllerName (\r
181 IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
182 IN EFI_HANDLE ControllerHandle,\r
183 IN EFI_HANDLE ChildHandle OPTIONAL,\r
184 IN CHAR8 *Language,\r
185 OUT CHAR16 **ControllerName\r
186 )\r
187{\r
188 return EFI_UNSUPPORTED;\r
189}\r
190\r
191/**\r
192 Tests to see if this driver supports a given controller. If a child device is provided,\r
193 it further tests to see if this driver supports creating a handle for the specified child device.\r
194\r
195 This function checks to see if the driver specified by This supports the device specified by\r
196 ControllerHandle. Drivers will typically use the device path attached to\r
197 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
198 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
199 may be called many times during platform initialization. In order to reduce boot times, the tests\r
200 performed by this function must be very small, and take as little time as possible to execute. This\r
201 function must not change the state of any hardware devices, and this function must be aware that the\r
202 device specified by ControllerHandle may already be managed by the same driver or a\r
203 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
204 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
205 Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
206 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
207 to guarantee the state of ControllerHandle is not modified by this function.\r
208\r
209 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
210 @param[in] ControllerHandle The handle of the controller to test. This handle\r
211 must support a protocol interface that supplies\r
212 an I/O abstraction to the driver.\r
213 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
214 parameter is ignored by device drivers, and is optional for bus\r
215 drivers. For bus drivers, if this parameter is not NULL, then\r
216 the bus driver must determine if the bus controller specified\r
217 by ControllerHandle and the child controller specified\r
218 by RemainingDevicePath are both supported by this\r
219 bus driver.\r
220\r
221 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
222 RemainingDevicePath is supported by the driver specified by This.\r
223 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
224 RemainingDevicePath is already being managed by the driver\r
225 specified by This.\r
226 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
227 RemainingDevicePath is already being managed by a different\r
228 driver or an application that requires exclusive access.\r
229 Currently not implemented.\r
230 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
231 RemainingDevicePath is not supported by the driver specified by This.\r
232**/\r
233EFI_STATUS\r
234EFIAPI\r
235I2cHostDriverSupported (\r
236 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
237 IN EFI_HANDLE Controller,\r
238 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
239 )\r
240{\r
241 EFI_I2C_MASTER_PROTOCOL *I2cMaster;\r
242 EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL *I2cBusConfigurationManagement;\r
243 EFI_STATUS Status;\r
244\r
245 //\r
246 // Locate I2C Bus Configuration Management Protocol\r
247 //\r
248 Status = gBS->OpenProtocol (\r
249 Controller,\r
250 &gEfiI2cBusConfigurationManagementProtocolGuid,\r
251 (VOID **)&I2cBusConfigurationManagement,\r
252 This->DriverBindingHandle,\r
253 Controller,\r
254 EFI_OPEN_PROTOCOL_BY_DRIVER\r
255 );\r
256 if (EFI_ERROR (Status)) {\r
257 return Status;\r
258 }\r
259\r
260 //\r
261 // Close the protocol because we don't use it here\r
262 //\r
263 gBS->CloseProtocol (\r
264 Controller,\r
265 &gEfiI2cBusConfigurationManagementProtocolGuid,\r
266 This->DriverBindingHandle,\r
267 Controller\r
268 );\r
269\r
270 //\r
271 // Locate I2C Master Protocol\r
272 //\r
273 Status = gBS->OpenProtocol (\r
274 Controller,\r
275 &gEfiI2cMasterProtocolGuid,\r
276 (VOID **)&I2cMaster,\r
277 This->DriverBindingHandle,\r
278 Controller,\r
279 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
280 );\r
281 if (EFI_ERROR (Status)) {\r
282 return Status;\r
283 }\r
284\r
285 return EFI_SUCCESS;\r
286}\r
287\r
288/**\r
289 Starts a device controller or a bus controller.\r
290\r
291 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
292 As a result, much of the error checking on the parameters to Start() has been moved into this\r
293 common boot service. It is legal to call Start() from other locations,\r
294 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
295 1. ControllerHandle must be a valid EFI_HANDLE.\r
296 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
297 EFI_DEVICE_PATH_PROTOCOL.\r
298 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
299 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
300\r
301 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
302 @param[in] ControllerHandle The handle of the controller to start. This handle\r
303 must support a protocol interface that supplies\r
304 an I/O abstraction to the driver.\r
305 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
306 parameter is ignored by device drivers, and is optional for bus\r
307 drivers. For a bus driver, if this parameter is NULL, then handles\r
308 for all the children of Controller are created by this driver.\r
309 If this parameter is not NULL and the first Device Path Node is\r
310 not the End of Device Path Node, then only the handle for the\r
311 child device specified by the first Device Path Node of\r
312 RemainingDevicePath is created by this driver.\r
313 If the first Device Path Node of RemainingDevicePath is\r
314 the End of Device Path Node, no child handle is created by this\r
315 driver.\r
316\r
317 @retval EFI_SUCCESS The device was started.\r
318 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
319 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
320 @retval Others The driver failded to start the device.\r
321\r
322**/\r
323EFI_STATUS\r
324EFIAPI\r
325I2cHostDriverStart (\r
326 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
327 IN EFI_HANDLE Controller,\r
328 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
329 )\r
330{\r
331 EFI_STATUS Status;\r
332 EFI_I2C_MASTER_PROTOCOL *I2cMaster;\r
333 EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL *I2cBusConfigurationManagement;\r
334 I2C_HOST_CONTEXT *I2cHostContext;\r
335\r
336 I2cMaster = NULL;\r
337 I2cHostContext = NULL;\r
338 I2cBusConfigurationManagement = NULL;\r
339\r
340 //\r
341 // Locate I2C Bus Configuration Management Protocol\r
342 //\r
343 Status = gBS->OpenProtocol (\r
344 Controller,\r
345 &gEfiI2cBusConfigurationManagementProtocolGuid,\r
346 (VOID **)&I2cBusConfigurationManagement,\r
347 This->DriverBindingHandle,\r
348 Controller,\r
349 EFI_OPEN_PROTOCOL_BY_DRIVER\r
350 );\r
351 if (EFI_ERROR (Status)) {\r
352 DEBUG ((EFI_D_ERROR, "I2cHost: Open I2C bus configuration error, Status = %r\n", Status));\r
353 return Status;\r
354 }\r
355\r
356 //\r
357 // Locate I2C Master Protocol\r
358 //\r
359 Status = gBS->OpenProtocol ( \r
360 Controller,\r
361 &gEfiI2cMasterProtocolGuid,\r
362 (VOID **)&I2cMaster,\r
363 This->DriverBindingHandle,\r
364 Controller,\r
365 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
366 );\r
367 if (EFI_ERROR (Status)) {\r
368 DEBUG ((EFI_D_ERROR, "I2cHost: Open I2C master error, Status = %r\n", Status));\r
369 goto Exit;\r
370 }\r
371\r
372 //\r
373 // Allocate the I2C Host Context structure\r
374 //\r
375 I2cHostContext = AllocateZeroPool (sizeof (I2C_HOST_CONTEXT));\r
376 if (I2cHostContext == NULL) {\r
377 DEBUG ((EFI_D_ERROR, "I2cHost: there is no enough memory to allocate.\n"));\r
378 Status = EFI_OUT_OF_RESOURCES;\r
379 goto Exit;\r
380 }\r
381\r
382 //\r
383 // Initialize the context structure for the current I2C Controller\r
384 //\r
385 I2cHostContext->Signature = I2C_HOST_SIGNATURE;\r
386 I2cHostContext->I2cMaster = I2cMaster;\r
387 I2cHostContext->I2cBusConfigurationManagement = I2cBusConfigurationManagement;\r
388 I2cHostContext->I2cBusConfiguration = (UINTN) -1;\r
389 InitializeListHead(&I2cHostContext->RequestList);\r
390\r
391 //\r
392 // Reset the controller\r
393 //\r
394 Status = I2cMaster->Reset (I2cMaster);\r
395 if (EFI_ERROR (Status)) {\r
396 DEBUG ((EFI_D_ERROR, "I2cHost: I2C controller reset failed!\n"));\r
397 goto Exit;\r
398 }\r
399\r
400 //\r
401 // Create the I2C transaction complete event\r
402 //\r
403 Status = gBS->CreateEvent (\r
404 EVT_NOTIFY_SIGNAL,\r
405 TPL_I2C_SYNC,\r
406 I2cHostRequestCompleteEvent,\r
407 I2cHostContext,\r
408 &I2cHostContext->I2cEvent\r
409 );\r
410 if (EFI_ERROR (Status)) {\r
411 DEBUG ((EFI_D_ERROR, "I2cHost: create complete event error, Status = %r\n", Status));\r
412 goto Exit;\r
413 }\r
414\r
415 //\r
416 // Get the bus management event\r
417 //\r
418 Status = gBS->CreateEvent (\r
419 EVT_NOTIFY_SIGNAL,\r
420 TPL_I2C_SYNC,\r
421 I2cHostI2cBusConfigurationAvailable,\r
422 I2cHostContext,\r
423 &I2cHostContext->I2cBusConfigurationEvent\r
424 );\r
425 if (EFI_ERROR (Status)) {\r
426 DEBUG ((EFI_D_ERROR, "I2cHost: create bus available event error, Status = %r\n", Status));\r
427 goto Exit;\r
428 } \r
429\r
430 //\r
431 // Build the I2C host protocol for the current I2C controller\r
432 //\r
433 I2cHostContext->I2cHost.QueueRequest = I2cHostQueueRequest;\r
434 I2cHostContext->I2cHost.I2cControllerCapabilities = I2cMaster->I2cControllerCapabilities;\r
435\r
436 //\r
437 // Install the driver protocol\r
438 //\r
439 Status = gBS->InstallMultipleProtocolInterfaces (\r
440 &Controller,\r
441 &gEfiI2cHostProtocolGuid,\r
442 &I2cHostContext->I2cHost,\r
443 NULL\r
444 );\r
445Exit:\r
446 if (EFI_ERROR (Status)) {\r
447 DEBUG ((EFI_D_ERROR, "I2cHost: Start() function failed, Status = %r\n", Status));\r
448 if (I2cBusConfigurationManagement != NULL) {\r
449 gBS->CloseProtocol (\r
450 Controller,\r
451 &gEfiI2cBusConfigurationManagementProtocolGuid,\r
452 This->DriverBindingHandle,\r
453 Controller\r
454 ); \r
455 }\r
456 \r
457 if ((I2cHostContext != NULL) && (I2cHostContext->I2cEvent != NULL)) {\r
458 gBS->CloseEvent (I2cHostContext->I2cEvent);\r
459 I2cHostContext->I2cEvent = NULL;\r
460 }\r
461\r
462 if ((I2cHostContext != NULL) && (I2cHostContext->I2cBusConfigurationEvent != NULL)) {\r
463 gBS->CloseEvent (I2cHostContext->I2cBusConfigurationEvent);\r
464 I2cHostContext->I2cBusConfigurationEvent = NULL;\r
465 }\r
466\r
467 //\r
468 // Release the context structure upon failure\r
469 //\r
470 if (I2cHostContext != NULL) {\r
471 FreePool (I2cHostContext);\r
472 }\r
473 }\r
474\r
475 //\r
476 // Return the operation status.\r
477 //\r
478 return Status;\r
479}\r
480\r
481/**\r
482 Stops a device controller or a bus controller.\r
483\r
484 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
485 As a result, much of the error checking on the parameters to Stop() has been moved\r
486 into this common boot service. It is legal to call Stop() from other locations,\r
487 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
488 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
489 same driver's Start() function.\r
490 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
491 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
492 Start() function, and the Start() function must have called OpenProtocol() on\r
493 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
494\r
495 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
496 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
497 support a bus specific I/O protocol for the driver\r
498 to use to stop the device.\r
499 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
500 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
501 if NumberOfChildren is 0.\r
502\r
503 @retval EFI_SUCCESS The device was stopped.\r
504 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
505\r
506**/\r
507EFI_STATUS\r
508EFIAPI\r
509I2cHostDriverStop (\r
510 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
511 IN EFI_HANDLE Controller,\r
512 IN UINTN NumberOfChildren,\r
513 IN EFI_HANDLE *ChildHandleBuffer\r
514 )\r
515{\r
516 EFI_STATUS Status; \r
517 I2C_HOST_CONTEXT *I2cHostContext;\r
518 EFI_I2C_HOST_PROTOCOL *I2cHost;\r
519 EFI_TPL TplPrevious;\r
520\r
521 TplPrevious = EfiGetCurrentTpl ();\r
522 if (TplPrevious > TPL_I2C_SYNC) {\r
523 DEBUG ((EFI_D_ERROR, "I2cHost: TPL %d is too high in Stop.\n", TplPrevious));\r
524 return EFI_DEVICE_ERROR;\r
525 }\r
526\r
527 Status = gBS->OpenProtocol (\r
528 Controller,\r
529 &gEfiI2cHostProtocolGuid,\r
530 (VOID **) &I2cHost,\r
531 This->DriverBindingHandle,\r
532 Controller,\r
533 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
534 );\r
535\r
536 if (EFI_ERROR (Status)) {\r
537 return EFI_DEVICE_ERROR;\r
538 }\r
539\r
540 I2cHostContext = I2C_HOST_CONTEXT_FROM_PROTOCOL (I2cHost);\r
541\r
542 //\r
543 // Raise TPL for critical section\r
544 //\r
545 TplPrevious = gBS->RaiseTPL (TPL_I2C_SYNC);\r
546 \r
547 //\r
548 // If there is pending request or pending bus configuration, do not stop\r
549 //\r
550 Status = EFI_DEVICE_ERROR;\r
551 if (( !I2cHostContext->I2cBusConfigurationManagementPending )\r
552 && IsListEmpty (&I2cHostContext->RequestList)) {\r
553 \r
554 //\r
555 // Remove the I2C host protocol\r
556 //\r
557 Status = gBS->UninstallMultipleProtocolInterfaces (\r
558 Controller,\r
559 &gEfiI2cHostProtocolGuid,\r
560 I2cHost,\r
561 NULL\r
562 );\r
563 }\r
564 \r
565 //\r
566 // Leave critical section\r
567 //\r
568 gBS->RestoreTPL (TplPrevious);\r
569 if (!EFI_ERROR (Status)) {\r
570 gBS->CloseProtocol (\r
571 Controller,\r
572 &gEfiI2cBusConfigurationManagementProtocolGuid,\r
573 This->DriverBindingHandle,\r
574 Controller\r
575 );\r
576\r
577 //\r
578 // Release I2c Host resources\r
579 //\r
580 if (I2cHostContext->I2cBusConfigurationEvent != NULL) {\r
581 gBS->CloseEvent (I2cHostContext->I2cBusConfigurationEvent);\r
582 I2cHostContext->I2cBusConfigurationEvent = NULL;\r
583 }\r
584 \r
585 if (I2cHostContext->I2cEvent != NULL) {\r
586 gBS->CloseEvent (I2cHostContext->I2cEvent);\r
587 I2cHostContext->I2cEvent = NULL;\r
588 }\r
589 \r
590 FreePool (I2cHostContext);\r
591 }\r
592\r
593 //\r
594 // Return the stop status\r
595 //\r
596 return Status;\r
597}\r
598\r
599/**\r
600 Handle the I2C bus configuration available event\r
601\r
602 This routine is called at TPL_I2C_SYNC.\r
603\r
604 @param[in] Event Address of an EFI_EVENT handle\r
605 @param[in] Context Address of an I2C_HOST_CONTEXT structure\r
606\r
607**/\r
608VOID\r
609EFIAPI\r
610I2cHostI2cBusConfigurationAvailable (\r
611 IN EFI_EVENT Event,\r
612 IN VOID *Context\r
613 )\r
614{\r
615 I2C_HOST_CONTEXT *I2cHostContext;\r
616 EFI_I2C_MASTER_PROTOCOL *I2cMaster;\r
617 I2C_REQUEST *I2cRequest;\r
618 LIST_ENTRY *EntryHeader;\r
619 LIST_ENTRY *Entry;\r
620 EFI_STATUS Status;\r
621\r
622 //\r
623 // Mark this I2C bus configuration management operation as complete\r
624 //\r
625 I2cHostContext = (I2C_HOST_CONTEXT *)Context;\r
626 I2cMaster = I2cHostContext->I2cMaster;\r
627 ASSERT (I2cMaster != NULL);\r
628 //\r
629 // Clear flag to indicate I2C bus configuration is finished\r
630 //\r
631 I2cHostContext->I2cBusConfigurationManagementPending = FALSE;\r
632\r
633 //\r
634 // Validate the completion status\r
635 //\r
636 if (EFI_ERROR (I2cHostContext->Status)) {\r
637 //\r
638 // Setting I2C bus configuration failed before\r
639 //\r
640 I2cHostRequestComplete (I2cHostContext, I2cHostContext->Status);\r
641\r
642 //\r
643 // Unknown I2C bus configuration\r
644 // Force next operation to enable the I2C bus configuration\r
645 //\r
646 I2cHostContext->I2cBusConfiguration = (UINTN) -1;\r
647 \r
648 //\r
649 // Do not continue current I2C request\r
650 //\r
651 return;\r
652 }\r
653\r
654 //\r
655 // Get the first request in the link with FIFO order\r
656 //\r
657 EntryHeader = &I2cHostContext->RequestList;\r
658 Entry = GetFirstNode (EntryHeader);\r
659 I2cRequest = I2C_REQUEST_FROM_ENTRY (Entry);\r
660\r
661 //\r
662 // Update the I2C bus configuration of the current I2C request\r
663 //\r
664 I2cHostContext->I2cBusConfiguration = I2cRequest->I2cBusConfiguration;\r
665\r
666 //\r
667 // Start an I2C operation on the host, the status is returned by I2cHostContext->Status\r
668 //\r
669 Status = I2cMaster->StartRequest ( \r
670 I2cMaster,\r
671 I2cRequest->SlaveAddress,\r
672 I2cRequest->RequestPacket,\r
673 I2cHostContext->I2cEvent,\r
674 &I2cHostContext->Status\r
675 );\r
01331951
SEHM
676\r
677 if (EFI_ERROR (Status)) {\r
678 DEBUG((DEBUG_ERROR, "I2cHostI2cBusConfigurationAvailable: Error starting I2C operation, %r\n", Status));\r
679 }\r
43e543bc
EL
680}\r
681\r
682/**\r
683 Complete the current request\r
684\r
685 This routine is called at TPL_I2C_SYNC.\r
686\r
687 @param[in] I2cHostContext Address of an I2C_HOST_CONTEXT structure.\r
688 @param[in] Status Status of the I2C operation.\r
689\r
690 @return This routine returns the input status value.\r
691\r
692**/\r
693EFI_STATUS\r
694I2cHostRequestComplete (\r
695 I2C_HOST_CONTEXT *I2cHostContext,\r
696 EFI_STATUS Status\r
697 )\r
698{\r
699 I2C_REQUEST *I2cRequest;\r
700 LIST_ENTRY *EntryHeader;\r
701 LIST_ENTRY *Entry;\r
702\r
703 //\r
704 // Remove the current I2C request from the list\r
705 //\r
706 EntryHeader = &I2cHostContext->RequestList;\r
707 Entry = GetFirstNode (EntryHeader);\r
708 I2cRequest = I2C_REQUEST_FROM_ENTRY (Entry);\r
709\r
710 //\r
711 // Save the status for QueueRequest\r
712 //\r
713 if ( NULL != I2cRequest->Status ) {\r
714 *I2cRequest->Status = Status;\r
715 }\r
716\r
717 //\r
718 // Notify the user of the I2C request completion\r
719 //\r
720 if ( NULL != I2cRequest->Event ) {\r
721 gBS->SignalEvent (I2cRequest->Event);\r
722 }\r
723\r
724 //\r
725 // Done with this request, remove the current request from list\r
726 //\r
727 RemoveEntryList (&I2cRequest->Link);\r
728 FreePool (I2cRequest->RequestPacket);\r
729 FreePool (I2cRequest);\r
730\r
731 //\r
732 // If there is more I2C request, start next one\r
733 //\r
734 if(!IsListEmpty (EntryHeader)) {\r
735 I2cHostRequestEnable (I2cHostContext);\r
736 }\r
737 \r
738 return Status;\r
739}\r
740\r
741/**\r
742 Handle the bus available event\r
743\r
744 This routine is called at TPL_I2C_SYNC.\r
745\r
746 @param[in] Event Address of an EFI_EVENT handle\r
747 @param[in] Context Address of an I2C_HOST_CONTEXT structure\r
748\r
749**/\r
750VOID\r
751EFIAPI\r
752I2cHostRequestCompleteEvent (\r
753 IN EFI_EVENT Event,\r
754 IN VOID *Context\r
755 )\r
756{\r
757 I2C_HOST_CONTEXT *I2cHostContext;\r
758\r
759 //\r
760 // Handle the completion event\r
761 //\r
762 I2cHostContext = (I2C_HOST_CONTEXT *)Context;\r
763 I2cHostRequestComplete (I2cHostContext, I2cHostContext->Status);\r
764}\r
765\r
766/**\r
767 Enable access to the I2C bus configuration\r
768\r
769 @param[in] I2cHostContext Address of an I2C_HOST_CONTEXT structure\r
770\r
771 @retval EFI_SUCCESS The operation completed successfully.\r
772 @retval EFI_ABORTED The request did not complete because the driver\r
773 was shutdown.\r
774 @retval EFI_BAD_BUFFER_SIZE The WriteBytes or ReadBytes buffer size is too large.\r
775 @retval EFI_DEVICE_ERROR There was an I2C error (NACK) during the operation.\r
776 This could indicate the slave device is not present.\r
777 @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
778 @retval EFI_NO_MAPPING Invalid I2cBusConfiguration value\r
779 @retval EFI_NO_RESPONSE The I2C device is not responding to the\r
780 slave address. EFI_DEVICE_ERROR may also be\r
781 returned if the controller can not distinguish\r
782 when the NACK occurred.\r
783 @retval EFI_NOT_FOUND I2C slave address exceeds maximum address\r
784 @retval EFI_NOT_READY I2C bus is busy or operation pending, wait for\r
785 the event and then read status.\r
786 @retval EFI_OUT_OF_RESOURCES Insufficient memory for I2C operation\r
787 @retval EFI_TIMEOUT The transaction did not complete within an internally\r
788 specified timeout period.\r
789\r
790**/\r
791EFI_STATUS\r
792I2cHostRequestEnable (\r
793 I2C_HOST_CONTEXT *I2cHostContext\r
794 )\r
795{\r
796 UINTN I2cBusConfiguration;\r
797 CONST EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL *I2cBusConfigurationManagement;\r
798 I2C_REQUEST *I2cRequest;\r
799 EFI_STATUS Status;\r
800 EFI_TPL TplPrevious;\r
801 LIST_ENTRY *EntryHeader;\r
802 LIST_ENTRY *Entry;\r
803\r
804 //\r
805 // Assume pending request\r
806 //\r
807 Status = EFI_NOT_READY;\r
808\r
809 I2cBusConfigurationManagement = I2cHostContext->I2cBusConfigurationManagement;\r
810\r
811 //\r
812 // Validate the I2c bus configuration\r
813 //\r
814 EntryHeader = &I2cHostContext->RequestList;\r
815 Entry = GetFirstNode (EntryHeader);\r
816 I2cRequest = I2C_REQUEST_FROM_ENTRY (Entry);\r
817\r
818 I2cBusConfiguration = I2cRequest->I2cBusConfiguration;\r
819\r
820 if (I2cHostContext->I2cBusConfiguration != I2cBusConfiguration ) {\r
821 //\r
822 // Set flag to indicate I2C bus configuration is in progress\r
823 //\r
824 I2cHostContext->I2cBusConfigurationManagementPending = TRUE;\r
825 //\r
826 // Update bus configuration for this device's requesting bus configuration\r
827 //\r
828 Status = I2cBusConfigurationManagement->EnableI2cBusConfiguration (\r
829 I2cBusConfigurationManagement,\r
830 I2cBusConfiguration,\r
831 I2cHostContext->I2cBusConfigurationEvent,\r
832 &I2cHostContext->Status\r
833 );\r
834 } else {\r
835 //\r
836 // I2C bus configuration is same, no need change configuration and start I2c transaction directly\r
837 //\r
838 TplPrevious = gBS->RaiseTPL ( TPL_I2C_SYNC );\r
839\r
840 //\r
841 // Same I2C bus configuration\r
842 //\r
843 I2cHostContext->Status = EFI_SUCCESS;\r
844 I2cHostI2cBusConfigurationAvailable (I2cHostContext->I2cBusConfigurationEvent, I2cHostContext);\r
845\r
846 //\r
847 // Release the thread synchronization\r
848 //\r
849 gBS->RestoreTPL ( TplPrevious );\r
850 }\r
851 return Status;\r
852}\r
853\r
854/**\r
855 Queue an I2C operation for execution on the I2C controller.\r
856\r
857 This routine must be called at or below TPL_NOTIFY. For synchronous\r
858 requests this routine must be called at or below TPL_CALLBACK.\r
859\r
860 N.B. The typical consumers of this API are the I2C bus driver and\r
861 on rare occasions the I2C test application. Extreme care must be\r
862 taken by other consumers of this API to prevent confusing the\r
863 third party I2C drivers due to a state change at the I2C device\r
864 which the third party I2C drivers did not initiate. I2C platform\r
865 drivers may use this API within these guidelines.\r
866\r
867 This layer uses the concept of I2C bus configurations to describe\r
868 the I2C bus. An I2C bus configuration is defined as a unique\r
869 setting of the multiplexers and switches in the I2C bus which\r
870 enable access to one or more I2C devices. When using a switch\r
871 to divide a bus, due to speed differences, the I2C platform layer\r
872 would define an I2C bus configuration for the I2C devices on each\r
873 side of the switch. When using a multiplexer, the I2C platform\r
874 layer defines an I2C bus configuration for each of the selector\r
875 values required to control the multiplexer. See Figure 1 in the\r
876 <a href="http://www.nxp.com/documents/user_manual/UM10204.pdf">I<sup>2</sup>C\r
877 Specification</a> for a complex I2C bus configuration.\r
878\r
879 The I2C host driver processes all operations in FIFO order. Prior to\r
880 performing the operation, the I2C host driver calls the I2C platform\r
881 driver to reconfigure the switches and multiplexers in the I2C bus\r
882 enabling access to the specified I2C device. The I2C platform driver\r
883 also selects the maximum bus speed for the device. After the I2C bus\r
884 is configured, the I2C host driver calls the I2C port driver to\r
885 initialize the I2C controller and start the I2C operation.\r
886\r
887 @param[in] This Address of an EFI_I2C_HOST_PROTOCOL instance.\r
888 @param[in] I2cBusConfiguration I2C bus configuration to access the I2C\r
889 device.\r
890 @param[in] SlaveAddress Address of the device on the I2C bus.\r
891 @param[in] Event Event to set for asynchronous operations,\r
892 NULL for synchronous operations\r
893 @param[in] RequestPacket Address of an EFI_I2C_REQUEST_PACKET\r
894 structure describing the I2C operation\r
895 @param[out] I2cStatus Optional buffer to receive the I2C operation\r
896 completion status\r
897\r
898 @retval EFI_SUCCESS The operation completed successfully.\r
43e543bc
EL
899 @retval EFI_BAD_BUFFER_SIZE The WriteBytes or ReadBytes buffer size is too large.\r
900 @retval EFI_DEVICE_ERROR There was an I2C error (NACK) during the operation.\r
901 This could indicate the slave device is not present.\r
902 @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
903 @retval EFI_INVALID_PARAMETER TPL is too high\r
904 @retval EFI_NO_MAPPING Invalid I2cBusConfiguration value\r
905 @retval EFI_NO_RESPONSE The I2C device is not responding to the\r
906 slave address. EFI_DEVICE_ERROR may also be\r
907 returned if the controller can not distinguish\r
908 when the NACK occurred.\r
909 @retval EFI_NOT_FOUND I2C slave address exceeds maximum address\r
910 @retval EFI_NOT_READY I2C bus is busy or operation pending, wait for\r
911 the event and then read status pointed to by\r
912 the request packet.\r
913 @retval EFI_OUT_OF_RESOURCES Insufficient memory for I2C operation\r
914 @retval EFI_TIMEOUT The transaction did not complete within an internally\r
915 specified timeout period.\r
916\r
917**/\r
918EFI_STATUS\r
919EFIAPI\r
920I2cHostQueueRequest (\r
921 IN CONST EFI_I2C_HOST_PROTOCOL *This,\r
922 IN UINTN I2cBusConfiguration,\r
923 IN UINTN SlaveAddress,\r
924 IN EFI_EVENT Event OPTIONAL,\r
925 IN EFI_I2C_REQUEST_PACKET *RequestPacket,\r
926 OUT EFI_STATUS *I2cStatus OPTIONAL\r
927 )\r
928{\r
929 EFI_STATUS Status;\r
930 EFI_EVENT SyncEvent;\r
931 EFI_TPL TplPrevious;\r
932 I2C_REQUEST *I2cRequest;\r
933 I2C_HOST_CONTEXT *I2cHostContext;\r
934 BOOLEAN FirstRequest;\r
935 UINTN RequestPacketSize;\r
62eeb52a 936 UINTN StartBit;\r
43e543bc
EL
937\r
938 SyncEvent = NULL;\r
939 FirstRequest = FALSE;\r
940 Status = EFI_SUCCESS;\r
941\r
942 if (RequestPacket == NULL) {\r
943 return EFI_INVALID_PARAMETER;\r
944 }\r
62eeb52a
EL
945 \r
946 if ((SlaveAddress & I2C_ADDRESSING_10_BIT) != 0) {\r
947 //\r
948 // 10-bit address, bits 0-9 are used for 10-bit I2C slave addresses,\r
949 // bits 10-30 are reserved bits and must be zero\r
950 //\r
951 StartBit = 10;\r
952 } else {\r
953 //\r
954 // 7-bit address, Bits 0-6 are used for 7-bit I2C slave addresses,\r
955 // bits 7-30 are reserved bits and must be zero\r
956 //\r
957 StartBit = 7;\r
958 }\r
959\r
960 if (BitFieldRead32 ((UINT32)SlaveAddress, StartBit, 30) != 0) {\r
961 //\r
962 // Reserved bit set in the SlaveAddress parameter\r
963 //\r
964 return EFI_NOT_FOUND;\r
965 }\r
43e543bc
EL
966\r
967 I2cHostContext = I2C_HOST_CONTEXT_FROM_PROTOCOL (This);\r
968\r
969 if (Event == NULL) {\r
970 //\r
971 // For synchronous transaction, register an event used to wait for finishing synchronous transaction\r
972 //\r
973 Status = gBS->CreateEvent ( \r
974 0,\r
975 TPL_I2C_SYNC,\r
976 NULL,\r
977 NULL,\r
978 &SyncEvent\r
979 );\r
980 if (EFI_ERROR (Status)) {\r
981 return Status;\r
982 }\r
983 }\r
984 \r
985 //\r
986 // TPL should be at or below TPL_NOTIFY.\r
987 // For synchronous requests this routine must be called at or below TPL_CALLBACK.\r
988 //\r
989 TplPrevious = EfiGetCurrentTpl ();\r
990 if ((TplPrevious > TPL_I2C_SYNC) || ((Event == NULL) && (TplPrevious > TPL_CALLBACK))) {\r
991 DEBUG ((EFI_D_ERROR, "ERROR - TPL %d is too high!\n", TplPrevious));\r
992 return EFI_INVALID_PARAMETER;\r
993 }\r
994\r
995 //\r
996 // Allocate the request structure\r
997 //\r
998 I2cRequest = AllocateZeroPool (sizeof (I2C_REQUEST));\r
999 if (I2cRequest == NULL) {\r
1000 DEBUG ((EFI_D_ERROR, "WARNING - Failed to allocate I2C_REQUEST!\n"));\r
1001 return EFI_OUT_OF_RESOURCES;\r
1002 }\r
1003\r
1004 //\r
1005 // Initialize the request\r
1006 //\r
1007 I2cRequest->Signature = I2C_REQUEST_SIGNATURE;\r
1008 I2cRequest->I2cBusConfiguration = I2cBusConfiguration;\r
1009 I2cRequest->SlaveAddress = SlaveAddress;\r
1010 I2cRequest->Event = (Event == NULL) ? SyncEvent : Event;\r
1011 I2cRequest->Status = I2cStatus;\r
1012\r
1013 //\r
1014 // Copy request packet into private buffer, as RequestPacket may be freed during asynchronous transaction\r
1015 //\r
1016 RequestPacketSize = sizeof (UINTN) + RequestPacket->OperationCount * sizeof (EFI_I2C_OPERATION);\r
1017 I2cRequest->RequestPacket = AllocateZeroPool (RequestPacketSize);\r
4c7e997e 1018 ASSERT (I2cRequest->RequestPacket != NULL);\r
43e543bc
EL
1019 CopyMem (I2cRequest->RequestPacket, RequestPacket, RequestPacketSize);\r
1020\r
1021 //\r
1022 // Synchronize with the other threads\r
1023 //\r
1024 gBS->RaiseTPL ( TPL_I2C_SYNC );\r
1025 \r
1026 FirstRequest = IsListEmpty (&I2cHostContext->RequestList);\r
1027 \r
1028 //\r
1029 // Insert new I2C request in the list\r
1030 //\r
1031 InsertTailList (&I2cHostContext->RequestList, &I2cRequest->Link);\r
1032\r
1033 //\r
1034 // Release the thread synchronization\r
1035 //\r
1036 gBS->RestoreTPL (TplPrevious);\r
1037 \r
1038 if (FirstRequest) {\r
1039 //\r
1040 // Start the first I2C request, then the subsequent of I2C request will continue\r
1041 //\r
1042 Status = I2cHostRequestEnable (I2cHostContext);\r
1043 }\r
1044\r
1045 if (Event != NULL) {\r
1046 //\r
1047 // For asynchronous, return EFI_SUCCESS indicating that the asynchronously I2C transaction was queued.\r
1048 // No real I2C operation status in I2cStatus\r
1049 //\r
1050 return EFI_SUCCESS;\r
1051 }\r
1052\r
1053 //\r
1054 // For synchronous transaction, wait for the operation completion\r
1055 //\r
1056 do {\r
1057 Status = gBS->CheckEvent (SyncEvent);\r
1058 } while (Status == EFI_NOT_READY);\r
1059\r
1060 //\r
1061 // Get the I2C operation status\r
1062 //\r
1063 Status = I2cHostContext->Status;\r
1064\r
1065 //\r
1066 // Return the I2C operation status\r
1067 //\r
1068 if (I2cStatus != NULL) {\r
1069 *I2cStatus = Status;\r
1070 }\r
1071\r
1072 //\r
1073 // Close the event if necessary\r
1074 //\r
1075 if (SyncEvent != NULL) {\r
1076 gBS->CloseEvent (SyncEvent);\r
1077 }\r
1078\r
1079 return Status;\r
1080}\r
1081\r
1082/**\r
1083 The user Entry Point for I2C host module. The user code starts with this function.\r
1084\r
1085 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
1086 @param[in] SystemTable A pointer to the EFI System Table.\r
1087\r
1088 @retval EFI_SUCCESS The entry point is executed successfully.\r
1089 @retval other Some error occurs when executing this entry point.\r
1090\r
1091**/\r
1092EFI_STATUS\r
1093EFIAPI\r
1094InitializeI2cHost(\r
1095 IN EFI_HANDLE ImageHandle,\r
1096 IN EFI_SYSTEM_TABLE *SystemTable\r
1097 )\r
1098{\r
1099 EFI_STATUS Status;\r
1100\r
1101 //\r
1102 // Install driver model protocol(s).\r
1103 //\r
1104 Status = EfiLibInstallDriverBindingComponentName2 (\r
1105 ImageHandle,\r
1106 SystemTable,\r
1107 &gI2cHostDriverBinding,\r
1108 ImageHandle,\r
1109 &gI2cHostComponentName,\r
1110 &gI2cHostComponentName2\r
1111 );\r
1112 ASSERT_EFI_ERROR (Status);\r
1113 return Status;\r
1114}\r
1115\r
1116/**\r
1117 This is the unload handle for I2C host module.\r
1118\r
1119 Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r
1120 Uninstall all the protocols installed in the driver entry point.\r
1121\r
1122 @param[in] ImageHandle The drivers' driver image.\r
1123\r
1124 @retval EFI_SUCCESS The image is unloaded.\r
1125 @retval Others Failed to unload the image.\r
1126\r
1127**/\r
1128EFI_STATUS\r
1129EFIAPI\r
1130I2cHostUnload (\r
1131 IN EFI_HANDLE ImageHandle\r
1132 )\r
1133{\r
1134 EFI_STATUS Status;\r
1135 EFI_HANDLE *DeviceHandleBuffer;\r
1136 UINTN DeviceHandleCount;\r
1137 UINTN Index;\r
6f497f8f
EL
1138 EFI_COMPONENT_NAME_PROTOCOL *ComponentName;\r
1139 EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;\r
43e543bc
EL
1140\r
1141 //\r
1142 // Get the list of all I2C Controller handles in the handle database.\r
1143 // If there is an error getting the list, then the unload\r
1144 // operation fails.\r
1145 //\r
1146 Status = gBS->LocateHandleBuffer (\r
1147 ByProtocol,\r
1148 &gEfiI2cHostProtocolGuid,\r
1149 NULL,\r
1150 &DeviceHandleCount,\r
1151 &DeviceHandleBuffer\r
1152 );\r
1153\r
2fa77862
EL
1154 if (!EFI_ERROR (Status)) {\r
1155 //\r
1156 // Disconnect the driver specified by ImageHandle from all\r
1157 // the devices in the handle database.\r
1158 //\r
1159 for (Index = 0; Index < DeviceHandleCount; Index++) {\r
1160 Status = gBS->DisconnectController (\r
1161 DeviceHandleBuffer[Index],\r
1162 ImageHandle,\r
1163 NULL\r
1164 );\r
1165 if (EFI_ERROR (Status)) {\r
1166 goto Done;\r
1167 }\r
43e543bc
EL
1168 }\r
1169 }\r
1170\r
1171 //\r
1172 // Uninstall all the protocols installed in the driver entry point\r
1173 //\r
1174 Status = gBS->UninstallMultipleProtocolInterfaces (\r
1175 gI2cHostDriverBinding.DriverBindingHandle,\r
1176 &gEfiDriverBindingProtocolGuid,\r
1177 &gI2cHostDriverBinding,\r
43e543bc
EL
1178 NULL\r
1179 );\r
1180 ASSERT_EFI_ERROR (Status);\r
1181\r
6f497f8f
EL
1182 //\r
1183 // Note we have to one by one uninstall the following protocols.\r
1184 // It's because some of them are optionally installed based on\r
1185 // the following PCD settings.\r
1186 // gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable\r
1187 // gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable\r
1188 // gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable\r
1189 // gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable\r
1190 //\r
1191 Status = gBS->HandleProtocol (\r
1192 gI2cHostDriverBinding.DriverBindingHandle,\r
1193 &gEfiComponentNameProtocolGuid,\r
1194 (VOID **) &ComponentName\r
1195 );\r
1196 if (!EFI_ERROR (Status)) {\r
1197 gBS->UninstallProtocolInterface (\r
1198 gI2cHostDriverBinding.DriverBindingHandle,\r
1199 &gEfiComponentNameProtocolGuid,\r
1200 ComponentName\r
1201 );\r
1202 }\r
1203\r
1204 Status = gBS->HandleProtocol (\r
1205 gI2cHostDriverBinding.DriverBindingHandle,\r
1206 &gEfiComponentName2ProtocolGuid,\r
1207 (VOID **) &ComponentName2\r
1208 );\r
1209 if (!EFI_ERROR (Status)) {\r
1210 gBS->UninstallProtocolInterface (\r
1211 gI2cHostDriverBinding.DriverBindingHandle,\r
1212 &gEfiComponentName2ProtocolGuid,\r
1213 ComponentName2\r
1214 );\r
1215 }\r
1216\r
1217 Status = EFI_SUCCESS;\r
1218\r
43e543bc
EL
1219Done:\r
1220 //\r
1221 // Free the buffer containing the list of handles from the handle database\r
1222 //\r
1223 if (DeviceHandleBuffer != NULL) {\r
1224 gBS->FreePool (DeviceHandleBuffer);\r
1225 }\r
1226\r
1227 return Status;\r
1228}\r