69 { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }
77 {
"eng;en", (CHAR16 *)L
"I2C Bus Driver" },
143 OUT CHAR16 **DriverName
148 This->SupportedLanguages,
149 mI2cBusDriverNameTable,
151 (BOOLEAN)(This != &gI2cBusComponentName2)
230 OUT CHAR16 **ControllerName
233 return EFI_UNSUPPORTED;
254 IN BOOLEAN RemainingHasControllerNode,
255 IN UINT32 RemainingControllerNumber
263 BOOLEAN SystemHasControllerNode;
264 UINT32 SystemControllerNumber;
266 SystemHasControllerNode =
FALSE;
267 SystemControllerNumber = 0;
269 Status =
gBS->OpenProtocolInformation (
275 if (EFI_ERROR (Status)) {
279 for (Index = 0; Index < EntryCount; Index++) {
280 if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
281 Status =
gBS->OpenProtocol (
282 OpenInfoBuffer[Index].ControllerHandle,
283 &gEfiDevicePathProtocolGuid,
284 (VOID **)&SystemDevicePath,
285 This->DriverBindingHandle,
287 EFI_OPEN_PROTOCOL_GET_PROTOCOL
289 if (!EFI_ERROR (Status)) {
308 SystemHasControllerNode =
TRUE;
311 SystemHasControllerNode =
FALSE;
312 SystemControllerNumber = 0;
315 if (((SystemHasControllerNode) && (!RemainingHasControllerNode) && (SystemControllerNumber == 0)) ||
316 ((!SystemHasControllerNode) && (RemainingHasControllerNode) && (RemainingControllerNumber == 0)) ||
317 ((SystemHasControllerNode) && (RemainingHasControllerNode) && (SystemControllerNumber == RemainingControllerNumber)) ||
318 ((!SystemHasControllerNode) && (!RemainingHasControllerNode)))
320 DEBUG ((DEBUG_ERROR,
"This I2C device has been already started.\n"));
321 Status = EFI_UNSUPPORTED;
330 if (EFI_ERROR (Status)) {
396 BOOLEAN RemainingHasControllerNode;
397 UINT32 RemainingControllerNumber;
399 RemainingHasControllerNode =
FALSE;
400 RemainingControllerNumber = 0;
405 Status =
gBS->OpenProtocol (
408 (VOID **)&I2cEnumerate,
409 This->DriverBindingHandle,
411 EFI_OPEN_PROTOCOL_BY_DRIVER
413 if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {
417 if (!EFI_ERROR (Status)) {
421 This->DriverBindingHandle,
426 Status =
gBS->OpenProtocol (
428 &gEfiDevicePathProtocolGuid,
429 (VOID **)&ParentDevicePath,
430 This->DriverBindingHandle,
432 EFI_OPEN_PROTOCOL_BY_DRIVER
435 if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {
439 if (!EFI_ERROR (Status)) {
442 &gEfiDevicePathProtocolGuid,
443 This->DriverBindingHandle,
455 return EFI_UNSUPPORTED;
466 return EFI_UNSUPPORTED;
468 RemainingHasControllerNode =
TRUE;
477 Status =
gBS->OpenProtocol (
481 This->DriverBindingHandle,
483 EFI_OPEN_PROTOCOL_BY_DRIVER
486 if (!EFI_ERROR (Status)) {
490 This->DriverBindingHandle,
495 if (Status == EFI_ALREADY_STARTED) {
496 if ((RemainingDevicePath ==
NULL) ||
511 RemainingHasControllerNode,
512 RemainingControllerNumber
569 I2cBusContext =
NULL;
570 ParentDevicePath =
NULL;
577 Status =
gBS->OpenProtocol (
581 This->DriverBindingHandle,
583 EFI_OPEN_PROTOCOL_BY_DRIVER
585 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
586 DEBUG ((DEBUG_ERROR,
"I2cBus: open I2C host error, Status = %r\n", Status));
590 if (Status == EFI_ALREADY_STARTED) {
591 Status =
gBS->OpenProtocol (
594 (VOID **)&I2cBusContext,
595 This->DriverBindingHandle,
597 EFI_OPEN_PROTOCOL_GET_PROTOCOL
599 if (EFI_ERROR (Status)) {
600 DEBUG ((DEBUG_ERROR,
"I2cBus: open private protocol error, Status = %r.\n", Status));
608 Status =
gBS->OpenProtocol (
611 (VOID **)&I2cEnumerate,
612 This->DriverBindingHandle,
614 EFI_OPEN_PROTOCOL_BY_DRIVER
616 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
617 DEBUG ((DEBUG_ERROR,
"I2cBus: open I2C enumerate error, Status = %r\n", Status));
621 Status =
gBS->OpenProtocol (
623 &gEfiDevicePathProtocolGuid,
624 (VOID **)&ParentDevicePath,
625 This->DriverBindingHandle,
627 EFI_OPEN_PROTOCOL_BY_DRIVER
629 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
630 DEBUG ((DEBUG_ERROR,
"I2cBus: open device path error, Status = %r\n", Status));
645 if (I2cBusContext ==
NULL) {
650 if (I2cBusContext ==
NULL) {
651 DEBUG ((DEBUG_ERROR,
"I2cBus: there is no enough memory to allocate.\n"));
652 Status = EFI_OUT_OF_RESOURCES;
670 I2cBusContext->I2cHost = I2cHost;
671 I2cBusContext->I2cEnumerate = I2cEnumerate;
675 I2cBusContext->Controller = Controller;
679 I2cBusContext->ParentDevicePath = ParentDevicePath;
681 I2cBusContext->DriverBindingHandle = This->DriverBindingHandle;
683 Status =
gBS->InstallMultipleProtocolInterfaces (
689 if (EFI_ERROR (Status)) {
690 DEBUG ((DEBUG_ERROR,
"I2cBus: install private protocol error, Status = %r.\n", Status));
703 if (EFI_ERROR (Status)) {
704 DEBUG ((DEBUG_ERROR,
"I2cBus: Start() function failed, Status = %r\n", Status));
705 if (ParentDevicePath !=
NULL) {
708 &gEfiDevicePathProtocolGuid,
709 This->DriverBindingHandle,
714 if (I2cHost !=
NULL) {
718 This->DriverBindingHandle,
723 if (I2cEnumerate !=
NULL) {
727 This->DriverBindingHandle,
732 if (I2cBusContext !=
NULL) {
733 Status =
gBS->UninstallMultipleProtocolInterfaces (
786 BOOLEAN AllChildrenStopped;
789 if (NumberOfChildren == 0) {
792 &gEfiDevicePathProtocolGuid,
793 This->DriverBindingHandle,
800 This->DriverBindingHandle,
807 This->DriverBindingHandle,
811 Status =
gBS->OpenProtocol (
814 (VOID **)&I2cBusContext,
815 This->DriverBindingHandle,
817 EFI_OPEN_PROTOCOL_GET_PROTOCOL
819 if (!EFI_ERROR (Status)) {
820 gBS->UninstallMultipleProtocolInterfaces (
835 AllChildrenStopped =
TRUE;
837 for (Index = 0; Index < NumberOfChildren; Index++) {
839 if (EFI_ERROR (Status)) {
840 AllChildrenStopped =
FALSE;
844 if (!AllChildrenStopped) {
845 return EFI_DEVICE_ERROR;
876 UINT32 RemainingPathDeviceIndex;
878 BOOLEAN BuildControllerNode;
882 BuildControllerNode =
TRUE;
887 RemainingPathDeviceIndex = 0;
892 if (RemainingDevicePath !=
NULL) {
910 BuildControllerNode =
FALSE;
922 Status = I2cBusContext->I2cEnumerate->Enumerate (I2cBusContext->I2cEnumerate, &Device);
923 if (EFI_ERROR (Status) || (Device ==
NULL)) {
924 if (RemainingDevicePath !=
NULL) {
925 Status = EFI_NOT_FOUND;
936 if ((Device->DeviceGuid ==
NULL) || (Device->SlaveAddressCount == 0) || (Device->SlaveAddressArray ==
NULL)) {
937 DEBUG ((DEBUG_ERROR,
"Invalid EFI_I2C_DEVICE reported by I2c Enumerate protocol.\n"));
941 if (RemainingDevicePath ==
NULL) {
942 if (Device->DeviceIndex == 0) {
952 Status = I2cBusContext->I2cEnumerate->Enumerate (I2cBusContext->I2cEnumerate, &TempDevice);
953 if (EFI_ERROR (Status) || (TempDevice ==
NULL)) {
958 if (
CompareGuid (Device->DeviceGuid, TempDevice->DeviceGuid)) {
968 BuildControllerNode =
FALSE;
976 (RemainingPathDeviceIndex != Device->DeviceIndex))
985 I2cDeviceContext =
NULL;
987 ASSERT (I2cDeviceContext !=
NULL);
988 if (I2cDeviceContext ==
NULL) {
995 I2cDeviceContext->I2cBusContext = I2cBusContext;
996 I2cDeviceContext->I2cDevice = Device;
997 I2cDeviceContext->I2cIo.
DeviceGuid = Device->DeviceGuid;
998 I2cDeviceContext->I2cIo.
DeviceIndex = Device->DeviceIndex;
1007 if (EFI_ERROR (Status)) {
1014 Status =
gBS->InstallMultipleProtocolInterfaces (
1015 &I2cDeviceContext->Handle,
1017 &I2cDeviceContext->I2cIo,
1018 &gEfiDevicePathProtocolGuid,
1019 I2cDeviceContext->DevicePath,
1022 if (EFI_ERROR (Status)) {
1033 Status =
gBS->OpenProtocol (
1036 (VOID **)&I2cBusContext->I2cHost,
1037 I2cBusContext->DriverBindingHandle,
1038 I2cDeviceContext->Handle,
1039 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1041 if (EFI_ERROR (Status)) {
1042 Status =
gBS->UninstallMultipleProtocolInterfaces (
1043 I2cDeviceContext->Handle,
1044 &gEfiDevicePathProtocolGuid,
1045 I2cDeviceContext->DevicePath,
1047 &I2cDeviceContext->I2cIo,
1057 if (RemainingDevicePath !=
NULL) {
1155 if (RequestPacket ==
NULL) {
1156 return EFI_INVALID_PARAMETER;
1162 I2cDeviceContext = I2C_DEVICE_CONTEXT_FROM_PROTOCOL (This);
1163 I2cDevice = I2cDeviceContext->I2cDevice;
1164 if ( SlaveAddressIndex >= I2cDevice->SlaveAddressCount ) {
1165 return EFI_INVALID_PARAMETER;
1171 I2cBusContext = I2cDeviceContext->I2cBusContext;
1172 I2cHost = I2cBusContext->I2cHost;
1179 I2cDevice->I2cBusConfiguration,
1180 I2cDevice->SlaveAddressArray[SlaveAddressIndex],
1202 if (I2cDeviceContext ==
NULL) {
1206 if (I2cDeviceContext->DevicePath !=
NULL) {
1207 FreePool (I2cDeviceContext->DevicePath);
1241 Status =
gBS->OpenProtocol (
1245 This->DriverBindingHandle,
1247 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1249 if (EFI_ERROR (Status)) {
1256 I2cDeviceContext = I2C_DEVICE_CONTEXT_FROM_PROTOCOL (I2cIo);
1261 gBS->CloseProtocol (
1264 This->DriverBindingHandle,
1272 Status =
gBS->UninstallMultipleProtocolInterfaces (
1274 &gEfiDevicePathProtocolGuid,
1275 I2cDeviceContext->DevicePath,
1277 &I2cDeviceContext->I2cIo,
1281 if (EFI_ERROR (Status)) {
1289 This->DriverBindingHandle,
1291 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1319 IN BOOLEAN BuildControllerNode
1324 PreviousDevicePath =
NULL;
1329 CopyMem (&gVendorDevicePathTemplate.
Guid, I2cDeviceContext->I2cDevice->DeviceGuid, sizeof (
EFI_GUID));
1331 I2cDeviceContext->I2cBusContext->ParentDevicePath,
1334 ASSERT (I2cDeviceContext->DevicePath !=
NULL);
1335 if (I2cDeviceContext->DevicePath ==
NULL) {
1336 return EFI_OUT_OF_RESOURCES;
1339 if ((BuildControllerNode) && (I2cDeviceContext->DevicePath !=
NULL)) {
1343 PreviousDevicePath = I2cDeviceContext->DevicePath;
1344 gControllerDevicePathTemplate.
ControllerNumber = I2cDeviceContext->I2cDevice->DeviceIndex;
1346 I2cDeviceContext->DevicePath,
1349 gBS->FreePool (PreviousDevicePath);
1350 ASSERT (I2cDeviceContext->DevicePath !=
NULL);
1351 if (I2cDeviceContext->DevicePath ==
NULL) {
1352 return EFI_OUT_OF_RESOURCES;
1385 &gI2cBusDriverBinding,
1387 &gI2cBusComponentName,
1388 &gI2cBusComponentName2
1415 UINTN DeviceHandleCount;
1425 Status =
gBS->LocateHandleBuffer (
1433 if (!EFI_ERROR (Status)) {
1438 for (Index = 0; Index < DeviceHandleCount; Index++) {
1439 Status =
gBS->DisconnectController (
1440 DeviceHandleBuffer[Index],
1444 if (EFI_ERROR (Status)) {
1453 Status =
gBS->UninstallMultipleProtocolInterfaces (
1455 &gEfiDriverBindingProtocolGuid,
1456 &gI2cBusDriverBinding,
1470 Status =
gBS->HandleProtocol (
1472 &gEfiComponentNameProtocolGuid,
1473 (VOID **)&ComponentName
1475 if (!EFI_ERROR (Status)) {
1476 gBS->UninstallProtocolInterface (
1478 &gEfiComponentNameProtocolGuid,
1483 Status =
gBS->HandleProtocol (
1485 &gEfiComponentName2ProtocolGuid,
1486 (VOID **)&ComponentName2
1488 if (!EFI_ERROR (Status)) {
1489 gBS->UninstallProtocolInterface (
1491 &gEfiComponentName2ProtocolGuid,
1502 if (DeviceHandleBuffer !=
NULL) {
1503 gBS->FreePool (DeviceHandleBuffer);
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
#define HARDWARE_DEVICE_PATH
UINT8 EFIAPI DevicePathType(IN CONST VOID *Node)
UINT8 EFIAPI DevicePathSubType(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STATUS EFIAPI I2cBusUnload(IN EFI_HANDLE ImageHandle)
EFI_STATUS UnRegisterI2cDevice(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_HANDLE Handle)
EFI_STATUS RegisterI2cDevice(IN I2C_BUS_CONTEXT *I2cBusContext, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS EFIAPI I2cBusDriverStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS I2cBusDevicePathAppend(IN I2C_DEVICE_CONTEXT *I2cDeviceContext, IN BOOLEAN BuildControllerNode)
VOID ReleaseI2cDeviceContext(IN I2C_DEVICE_CONTEXT *I2cDeviceContext)
EFI_STATUS EFIAPI I2cBusDriverSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS EFIAPI I2cBusQueueRequest(IN CONST EFI_I2C_IO_PROTOCOL *This, IN UINTN SlaveAddressIndex, IN EFI_EVENT Event OPTIONAL, IN EFI_I2C_REQUEST_PACKET *RequestPacket, OUT EFI_STATUS *I2cStatus OPTIONAL)
EFI_STATUS EFIAPI InitializeI2cBus(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI I2cBusDriverStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
EFI_STATUS CheckRemainingDevicePath(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath, IN BOOLEAN RemainingHasControllerNode, IN UINT32 RemainingControllerNumber)
EFI_STATUS EFIAPI I2cBusComponentNameGetControllerName(IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName)
EFI_STATUS EFIAPI I2cBusComponentNameGetDriverName(IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
EFI_GUID gEfiI2cEnumerateProtocolGuid
EFI_GUID gEfiI2cHostProtocolGuid
EFI_GUID gEfiI2cIoProtocolGuid
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
EFI_STATUS(EFIAPI * EFI_COMPONENT_NAME_GET_CONTROLLER_NAME)(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName)
EFI_STATUS(EFIAPI * EFI_COMPONENT_NAME_GET_DRIVER_NAME)(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
EFI_STATUS EFIAPI LookupUnicodeString2(IN CONST CHAR8 *Language, IN CONST CHAR8 *SupportedLanguages, IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable, OUT CHAR16 **UnicodeString, IN BOOLEAN Iso639Language)
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
EFI_HANDLE DriverBindingHandle
EFI_I2C_HOST_PROTOCOL_QUEUE_REQUEST QueueRequest
CONST EFI_GUID * DeviceGuid
CONST EFI_I2C_CONTROLLER_CAPABILITIES * I2cControllerCapabilities