]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add I2C bus DXE driver and I2C host DXE driver following PI 1.3 spec.
authorElvin Li <elvin.li@intel.com>
Wed, 14 Aug 2013 01:16:06 +0000 (01:16 +0000)
committerli-elvin <li-elvin@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 14 Aug 2013 01:16:06 +0000 (01:16 +0000)
Signed-off-by: Elvin Li <elvin.li@intel.com>
Reviewed-by: Leahy Leroy P <leroy.p.leahy@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14549 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/I2c/I2cDxe/I2cBus.c [new file with mode: 0644]
MdeModulePkg/Bus/I2c/I2cDxe/I2cBusDxe.inf [new file with mode: 0644]
MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.c [new file with mode: 0644]
MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.h [new file with mode: 0644]
MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.inf [new file with mode: 0644]
MdeModulePkg/Bus/I2c/I2cDxe/I2cHost.c [new file with mode: 0644]
MdeModulePkg/Bus/I2c/I2cDxe/I2cHostDxe.inf [new file with mode: 0644]
MdeModulePkg/MdeModulePkg.dsc

diff --git a/MdeModulePkg/Bus/I2c/I2cDxe/I2cBus.c b/MdeModulePkg/Bus/I2c/I2cDxe/I2cBus.c
new file mode 100644 (file)
index 0000000..3da1474
--- /dev/null
@@ -0,0 +1,1468 @@
+/** @file\r
+  This file implements I2C IO Protocol which enables the user to manipulate a single \r
+  I2C device independent of the host controller and I2C design.\r
+\r
+  Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "I2cDxe.h"\r
+\r
+//\r
+//  EFI_DRIVER_BINDING_PROTOCOL instance\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL gI2cBusDriverBinding = {\r
+  I2cBusDriverSupported,\r
+  I2cBusDriverStart,\r
+  I2cBusDriverStop,\r
+  0x10,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+//\r
+// Template for I2C Bus Child Device.\r
+//\r
+I2C_DEVICE_CONTEXT gI2cDeviceContextTemplate = {\r
+  I2C_DEVICE_SIGNATURE,\r
+  NULL,\r
+  {                     // I2cIo Protocol\r
+    I2cBusQueueRequest, // QueueRequest\r
+    NULL,               // DeviceGuid\r
+    0,                  // DeviceIndex\r
+    0,                  // HardwareRevision\r
+    NULL                // I2cControllerCapabilities\r
+  },\r
+  NULL,                 // DevicePath\r
+  NULL,                 // I2cDevice\r
+  NULL,                 // I2cBusContext\r
+};\r
+\r
+//\r
+// Template for controller device path node.\r
+//\r
+CONTROLLER_DEVICE_PATH gControllerDevicePathTemplate = {\r
+  {\r
+    HARDWARE_DEVICE_PATH,\r
+    HW_CONTROLLER_DP,\r
+    {\r
+      (UINT8) (sizeof (CONTROLLER_DEVICE_PATH)),\r
+      (UINT8) ((sizeof (CONTROLLER_DEVICE_PATH)) >> 8)\r
+    }\r
+  },\r
+  0\r
+};\r
+\r
+//\r
+// Template for vendor device path node.\r
+//\r
+VENDOR_DEVICE_PATH gVendorDevicePathTemplate = {\r
+  {\r
+    HARDWARE_DEVICE_PATH,\r
+    HW_VENDOR_DP,\r
+    {\r
+      (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
+      (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
+    }\r
+  },\r
+  { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }}\r
+};\r
+\r
+//\r
+// Driver name table \r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mI2cBusDriverNameTable[] = {\r
+  { "eng;en", (CHAR16 *) L"I2C Bus Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gI2cBusComponentName = {\r
+  (EFI_COMPONENT_NAME_GET_DRIVER_NAME) I2cBusComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME_GET_CONTROLLER_NAME) I2cBusComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Component Name 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gI2cBusComponentName2 = {\r
+  I2cBusComponentNameGetDriverName,\r
+  I2cBusComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           mI2cBusDriverNameTable,\r
+           DriverName,\r
+           (BOOLEAN)(This != &gI2cBusComponentName2)\r
+           );\r
+}\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Check if the child of I2C controller has been created.\r
+\r
+  @param[in] This                         A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.   \r
+  @param[in] Controller                   I2C controller handle.\r
+  @param[in] RemainingDevicePath          A pointer to the remaining portion of a device path.\r
+  @param[in] RemainingHasControllerNode   Indicate if RemainingDevicePath contains CONTROLLER_DEVICE_PATH.\r
+  @param[in] RemainingControllerNumber    Controller number in CONTROLLER_DEVICE_PATH.\r
+  \r
+  @retval EFI_SUCCESS                     The child of I2C controller is not created.\r
+  @retval Others                          The child of I2C controller has been created or other errors happen.\r
+\r
+**/\r
+EFI_STATUS\r
+CheckRemainingDevicePath (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath,\r
+  IN BOOLEAN                      RemainingHasControllerNode,\r
+  IN UINT32                       RemainingControllerNumber\r
+  )\r
+{\r
+  EFI_STATUS                              Status;\r
+  EFI_DEVICE_PATH_PROTOCOL                *SystemDevicePath;\r
+  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY     *OpenInfoBuffer;\r
+  UINTN                                   EntryCount;\r
+  UINTN                                   Index;\r
+  BOOLEAN                                 SystemHasControllerNode;\r
+  UINT32                                  SystemControllerNumber;  \r
+\r
+  SystemHasControllerNode = FALSE;\r
+  SystemControllerNumber    = 0;\r
+  \r
+  Status = gBS->OpenProtocolInformation (\r
+                  Controller,\r
+                  &gEfiI2cHostProtocolGuid,\r
+                  &OpenInfoBuffer,\r
+                  &EntryCount\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  for (Index = 0; Index < EntryCount; Index++) {\r
+    if ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
+      Status = gBS->OpenProtocol (\r
+                      OpenInfoBuffer[Index].ControllerHandle,\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      (VOID **) &SystemDevicePath,\r
+                      This->DriverBindingHandle,\r
+                      Controller,\r
+                      EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                      );\r
+      if (!EFI_ERROR (Status)) {\r
+        //\r
+        // Find vendor device path node and compare\r
+        //    \r
+        while (!IsDevicePathEnd (SystemDevicePath)) {\r
+          if ((DevicePathType (SystemDevicePath) == HARDWARE_DEVICE_PATH) &&\r
+              (DevicePathSubType (SystemDevicePath) == HW_VENDOR_DP)) {\r
+            //\r
+            // Check if vendor device path is same between system device path and remaining device path\r
+            //\r
+            if (CompareMem (SystemDevicePath, RemainingDevicePath, sizeof (VENDOR_DEVICE_PATH)) == 0) {\r
+              //\r
+              // Get controller node appended after vendor node\r
+              //\r
+              SystemDevicePath = NextDevicePathNode (SystemDevicePath);\r
+              if ((DevicePathType (SystemDevicePath) == HARDWARE_DEVICE_PATH) &&\r
+                  (DevicePathSubType (SystemDevicePath) == HW_CONTROLLER_DP)) {\r
+                SystemHasControllerNode = TRUE;\r
+                SystemControllerNumber    = ((CONTROLLER_DEVICE_PATH *) SystemDevicePath)->ControllerNumber;\r
+              } else {\r
+                SystemHasControllerNode = FALSE;\r
+                SystemControllerNumber    = 0;\r
+              }\r
+              if (((SystemHasControllerNode)  && (!RemainingHasControllerNode) && (SystemControllerNumber == 0)) ||\r
+                  ((!SystemHasControllerNode) && (RemainingHasControllerNode)  && (RemainingControllerNumber == 0)) ||\r
+                  ((SystemHasControllerNode)  && (RemainingHasControllerNode)  && (SystemControllerNumber == RemainingControllerNumber)) ||\r
+                  ((!SystemHasControllerNode) && (!RemainingHasControllerNode))) {\r
+                  DEBUG ((EFI_D_ERROR, "This I2C device has been already started.\n"));\r
+                  Status = EFI_UNSUPPORTED;\r
+                  break;\r
+              }\r
+            }\r
+          }\r
+          SystemDevicePath = NextDevicePathNode (SystemDevicePath);\r
+        }\r
+        if (EFI_ERROR (Status)) {\r
+          break;\r
+        }\r
+      }\r
+    }\r
+  }\r
+  FreePool (OpenInfoBuffer);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Tests to see if this driver supports a given controller. If a child device is provided,\r
+  it further tests to see if this driver supports creating a handle for the specified child device.\r
+\r
+  This function checks to see if the driver specified by This supports the device specified by\r
+  ControllerHandle. Drivers will typically use the device path attached to\r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to\r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function\r
+  may be called many times during platform initialization. In order to reduce boot times, the tests\r
+  performed by this function must be very small, and take as little time as possible to execute. This\r
+  function must not change the state of any hardware devices, and this function must be aware that the\r
+  device specified by ControllerHandle may already be managed by the same driver or a\r
+  different driver. This function must match its calls to AllocatePages() with FreePages(),\r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
+  Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For bus drivers, if this parameter is not NULL, then\r
+                                   the bus driver must determine if the bus controller specified\r
+                                   by ControllerHandle and the child controller specified\r
+                                   by RemainingDevicePath are both supported by this\r
+                                   bus driver.\r
+\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusDriverSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_I2C_ENUMERATE_PROTOCOL          *I2cEnumerate;\r
+  EFI_I2C_HOST_PROTOCOL               *I2cHost;\r
+  EFI_DEVICE_PATH_PROTOCOL            *ParentDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL            *DevPathNode;\r
+  BOOLEAN                             RemainingHasControllerNode;\r
+  UINT32                              RemainingControllerNumber;\r
+\r
+  RemainingHasControllerNode = FALSE;\r
+  RemainingControllerNumber    = 0;\r
+\r
+  //\r
+  //  Determine if the I2c Enumerate Protocol is available\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiI2cEnumerateProtocolGuid,\r
+                  (VOID **) &I2cEnumerate,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {\r
+    return Status;\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiI2cEnumerateProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {\r
+    return Status;\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiDevicePathProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+  }\r
+\r
+  if ((RemainingDevicePath != NULL) && !IsDevicePathEnd (RemainingDevicePath)) {\r
+    //\r
+    // Check if the first node of RemainingDevicePath is a hardware vendor device path\r
+    //\r
+    if ((DevicePathType (RemainingDevicePath) != HARDWARE_DEVICE_PATH) ||\r
+        (DevicePathSubType (RemainingDevicePath) != HW_VENDOR_DP)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    //\r
+    // Check if the second node of RemainingDevicePath is a controller node\r
+    //\r
+    DevPathNode = NextDevicePathNode (RemainingDevicePath);\r
+    if (!IsDevicePathEnd (DevPathNode)) {\r
+      if ((DevicePathType (DevPathNode) != HARDWARE_DEVICE_PATH) ||\r
+          (DevicePathSubType (DevPathNode) != HW_CONTROLLER_DP)) {\r
+        return EFI_UNSUPPORTED;\r
+      } else {\r
+        RemainingHasControllerNode = TRUE;\r
+        RemainingControllerNumber    = ((CONTROLLER_DEVICE_PATH *) DevPathNode)->ControllerNumber;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Determine if the I2C Host Protocol is available\r
+  //\r
+  Status = gBS->OpenProtocol ( \r
+                  Controller,\r
+                  &gEfiI2cHostProtocolGuid,\r
+                  (VOID **) &I2cHost,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiI2cHostProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+  }\r
+\r
+\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    if ((RemainingDevicePath == NULL) || \r
+        ((RemainingDevicePath != NULL) && IsDevicePathEnd (RemainingDevicePath))) {\r
+      //\r
+      // If RemainingDevicePath is NULL or is the End of Device Path Node, return EFI_SUCCESS.\r
+      //\r
+      Status = EFI_SUCCESS;\r
+    } else {\r
+      //\r
+      // Test if the child with the RemainingDevicePath has already been created.\r
+      //    \r
+      Status = CheckRemainingDevicePath (\r
+                 This,\r
+                 Controller,\r
+                 RemainingDevicePath,\r
+                 RemainingHasControllerNode,\r
+                 RemainingControllerNumber\r
+                 );\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Starts a device controller or a bus controller.\r
+\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this\r
+  common boot service. It is legal to call Start() from other locations,\r
+  but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles\r
+                                   for all the children of Controller are created by this driver.\r
+                                   If this parameter is not NULL and the first Device Path Node is\r
+                                   not the End of Device Path Node, then only the handle for the\r
+                                   child device specified by the first Device Path Node of\r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is\r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusDriverStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_I2C_ENUMERATE_PROTOCOL *I2cEnumerate;\r
+  EFI_I2C_HOST_PROTOCOL      *I2cHost;\r
+  I2C_BUS_CONTEXT            *I2cBusContext;\r
+  EFI_STATUS                 Status;\r
+  EFI_DEVICE_PATH_PROTOCOL   *ParentDevicePath;\r
+\r
+  I2cBusContext     = NULL;\r
+  ParentDevicePath  = NULL;\r
+  I2cEnumerate      = NULL;\r
+  I2cHost           = NULL;\r
+\r
+  //\r
+  //  Determine if the I2C controller is available\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiI2cHostProtocolGuid,\r
+                  (VOID**)&I2cHost,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r
+    DEBUG ((EFI_D_ERROR, "I2cBus: open I2C host error, Status = %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    Status = gBS->OpenProtocol (\r
+                    Controller,\r
+                    &gEfiCallerIdGuid,\r
+                    (VOID **) &I2cBusContext,\r
+                    This->DriverBindingHandle,\r
+                    Controller,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "I2cBus: open private protocol error, Status = %r.\n", Status));\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //\r
+  //  Get the I2C bus enumeration API\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiI2cEnumerateProtocolGuid,\r
+                  (VOID**)&I2cEnumerate,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r
+    DEBUG ((EFI_D_ERROR, "I2cBus: open I2C enumerate error, Status = %r\n", Status));\r
+    goto Error;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                   Controller,\r
+                   &gEfiDevicePathProtocolGuid,\r
+                   (VOID **) &ParentDevicePath,\r
+                   This->DriverBindingHandle,\r
+                   Controller,\r
+                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                   );\r
+  if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {\r
+    DEBUG ((EFI_D_ERROR, "I2cBus: open device path error, Status = %r\n", Status));\r
+    goto Error;\r
+  }\r
+\r
+  if ((RemainingDevicePath != NULL) && IsDevicePathEnd (RemainingDevicePath)) {\r
+    //\r
+    // If RemainingDevicePath is the End of Device Path Node,\r
+    // don't create any child device and return EFI_SUCESS\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Allocate the buffer for I2C_BUS_CONTEXT if it is not allocated before.\r
+  //\r
+  if (I2cBusContext == NULL) {\r
+    //\r
+    //  Allocate the I2C context structure for the current I2C controller\r
+    //\r
+    I2cBusContext = AllocateZeroPool (sizeof (I2C_BUS_CONTEXT));\r
+    if (I2cBusContext == NULL) {\r
+      DEBUG ((EFI_D_ERROR, "I2cBus: there is no enough memory to allocate.\n"));\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Error;\r
+    }\r
+    \r
+    /*\r
+       +----------------+\r
+    .->| I2C_BUS_CONTEXT|<----- This file Protocol (gEfiCallerIdGuid) installed on I2C Controller handle\r
+    |  +----------------+\r
+    |\r
+    |  +----------------------------+\r
+    |  | I2C_DEVICE_CONTEXT         |\r
+    `--|                            |\r
+       |                            |\r
+       | I2C IO Protocol Structure  | <----- I2C IO Protocol\r
+       |                            |\r
+       +----------------------------+\r
+    \r
+    */\r
+    I2cBusContext->I2cHost      = I2cHost;\r
+    I2cBusContext->I2cEnumerate = I2cEnumerate;\r
+    //\r
+    // Parent controller used to create children\r
+    //\r
+    I2cBusContext->Controller   = Controller;\r
+    //\r
+    // Parent controller device path used to create children device path\r
+    //\r
+    I2cBusContext->ParentDevicePath = ParentDevicePath;\r
+    \r
+    I2cBusContext->DriverBindingHandle = This->DriverBindingHandle;\r
+    \r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &Controller,\r
+                    &gEfiCallerIdGuid,\r
+                    I2cBusContext,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "I2cBus: install private protocol error, Status = %r.\n", Status));\r
+      goto Error;\r
+    }\r
+  }\r
+\r
+  //\r
+  //  Start the driver\r
+  //\r
+  Status = RegisterI2cDevice (I2cBusContext, Controller, RemainingDevicePath);\r
+\r
+  return Status;\r
+\r
+Error:\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "I2cBus: Start() function failed, Status = %r\n", Status));\r
+    if (ParentDevicePath != NULL) {\r
+      gBS->CloseProtocol ( \r
+            Controller,\r
+            &gEfiDevicePathProtocolGuid,\r
+            This->DriverBindingHandle,\r
+            Controller\r
+            );\r
+    }\r
+\r
+    if (I2cHost != NULL) {\r
+      gBS->CloseProtocol (\r
+            Controller,\r
+            &gEfiI2cHostProtocolGuid,\r
+            This->DriverBindingHandle,\r
+            Controller\r
+            );\r
+    }\r
+\r
+    if (I2cEnumerate != NULL) {\r
+      gBS->CloseProtocol ( \r
+            Controller,\r
+            &gEfiI2cEnumerateProtocolGuid,\r
+            This->DriverBindingHandle,\r
+            Controller\r
+            );\r
+    }\r
+    \r
+    if (I2cBusContext != NULL) {\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      &Controller,\r
+                      gEfiCallerIdGuid,\r
+                      I2cBusContext,\r
+                      NULL\r
+                      );\r
+      FreePool (I2cBusContext);\r
+    }\r
+  }\r
+\r
+  //\r
+  //  Return the operation status.\r
+  //\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Stops a device controller or a bus controller.\r
+\r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
+  As a result, much of the error checking on the parameters to Stop() has been moved\r
+  into this common boot service. It is legal to call Stop() from other locations,\r
+  but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+\r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must\r
+                                support a bus specific I/O protocol for the driver\r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL\r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusDriverStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Controller,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+{\r
+  I2C_BUS_CONTEXT             *I2cBusContext;\r
+  EFI_STATUS                  Status;\r
+  BOOLEAN                     AllChildrenStopped;\r
+  UINTN                       Index;\r
+\r
+  if (NumberOfChildren == 0) {\r
+    gBS->CloseProtocol ( \r
+          Controller,\r
+          &gEfiDevicePathProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiI2cHostProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiI2cEnumerateProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+\r
+    Status = gBS->OpenProtocol (\r
+                    Controller,\r
+                    &gEfiCallerIdGuid,\r
+                    (VOID **) &I2cBusContext,\r
+                    This->DriverBindingHandle,\r
+                    Controller,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      gBS->UninstallMultipleProtocolInterfaces (\r
+            Controller,\r
+            &gEfiCallerIdGuid,\r
+            I2cBusContext,\r
+            NULL\r
+            );\r
+      //\r
+      // No more child now, free bus context data.\r
+      //\r
+      FreePool (I2cBusContext);\r
+    }\r
+    return Status;\r
+  }\r
+\r
+  AllChildrenStopped = TRUE;\r
+\r
+  for (Index = 0; Index < NumberOfChildren; Index++) {\r
+\r
+    Status = UnRegisterI2cDevice (This, Controller, ChildHandleBuffer[Index]);\r
+    if (EFI_ERROR (Status)) {\r
+      AllChildrenStopped = FALSE;\r
+    }\r
+  }\r
+\r
+  if (!AllChildrenStopped) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Enumerate the I2C bus\r
+\r
+  This routine walks the platform specific data describing the\r
+  I2C bus to create the I2C devices where driver GUIDs were\r
+  specified.\r
+\r
+  @param[in] I2cBusContext            Address of an I2C_BUS_CONTEXT structure\r
+  @param[in] Controller               Handle to the controller\r
+  @param[in] RemainingDevicePath      A pointer to the remaining portion of a device path.\r
+\r
+  @retval EFI_SUCCESS       The bus is successfully configured\r
+\r
+**/\r
+EFI_STATUS\r
+RegisterI2cDevice (\r
+  IN I2C_BUS_CONTEXT            *I2cBusContext,\r
+  IN EFI_HANDLE                 Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL   *RemainingDevicePath\r
+  )\r
+{\r
+  I2C_DEVICE_CONTEXT                *I2cDeviceContext;\r
+  EFI_STATUS                        Status;\r
+  CONST EFI_I2C_DEVICE              *Device;\r
+  CONST EFI_I2C_DEVICE              *TempDevice;\r
+  UINT32                            RemainingPathDeviceIndex;\r
+  EFI_DEVICE_PATH_PROTOCOL          *DevPathNode;\r
+  BOOLEAN                           BuildControllerNode;\r
+  UINTN                             Count;\r
+\r
+  Status                   = EFI_SUCCESS;\r
+  BuildControllerNode      = TRUE;\r
+\r
+  //\r
+  // Default DeviceIndex\r
+  //\r
+  RemainingPathDeviceIndex = 0;\r
+  \r
+  //\r
+  // Determine the controller number in Controller Node Device Path when RemainingDevicePath is not NULL.\r
+  //\r
+  if (RemainingDevicePath != NULL) {\r
+    //\r
+    // Check if there is a controller node appended after vendor node\r
+    //    \r
+    DevPathNode = NextDevicePathNode (RemainingDevicePath);\r
+    if ((DevicePathType (DevPathNode) == HARDWARE_DEVICE_PATH) &&\r
+        (DevicePathSubType(DevPathNode) == HW_CONTROLLER_DP)) {\r
+      //\r
+      // RemainingDevicePath != NULL and RemainingDevicePath contains Controller Node,\r
+      // add Controller Node to Device Path on child handle.\r
+      //\r
+      RemainingPathDeviceIndex = ((CONTROLLER_DEVICE_PATH *) DevPathNode)->ControllerNumber;\r
+    } else {\r
+      //\r
+      // RemainingDevicePath != NULL and RemainingDevicePath does not contain Controller Node,\r
+      // do not add controller node to Device Path on child handle.\r
+      //\r
+      BuildControllerNode = FALSE;\r
+    }\r
+  }\r
+\r
+  //\r
+  //  Walk the list of I2C devices on this bus\r
+  //\r
+  Device = NULL;\r
+  while (TRUE) {\r
+    //\r
+    //  Get the next I2C device\r
+    //\r
+    Status = I2cBusContext->I2cEnumerate->Enumerate (I2cBusContext->I2cEnumerate, &Device);\r
+    if (EFI_ERROR (Status) || Device == NULL) {\r
+      if (RemainingDevicePath != NULL) {\r
+        Status = EFI_NOT_FOUND;\r
+      } else {\r
+        Status = EFI_SUCCESS;\r
+      }\r
+      break;\r
+    }\r
+\r
+    //\r
+    //  Determine if the device info is valid\r
+    //\r
+    if ((Device->DeviceGuid == NULL) || (Device->SlaveAddressCount == 0) || (Device->SlaveAddressArray == NULL)) {\r
+      DEBUG ((EFI_D_ERROR, "Invalid EFI_I2C_DEVICE reported by I2c Enumerate protocol.\n"));\r
+      continue;\r
+    }\r
+\r
+    if (RemainingDevicePath == NULL) {\r
+      if (Device->DeviceIndex == 0) {\r
+        //\r
+        // Determine if the controller node is necessary when controller number is zero in I2C device\r
+        //\r
+        TempDevice = NULL;\r
+        Count      = 0;\r
+        while (TRUE) {\r
+          //\r
+          //  Get the next I2C device\r
+          //\r
+          Status = I2cBusContext->I2cEnumerate->Enumerate (I2cBusContext->I2cEnumerate, &TempDevice);\r
+          if (EFI_ERROR (Status) || TempDevice == NULL) {\r
+            Status = EFI_SUCCESS;\r
+            break;\r
+          }\r
+          if (CompareGuid (Device->DeviceGuid, TempDevice->DeviceGuid)) {\r
+            Count++;\r
+          }\r
+        }\r
+        if (Count == 1) {\r
+          //\r
+          // RemainingDevicePath == NULL and only DeviceIndex 0 is present on the I2C bus,\r
+          // do not add Controller Node to Device Path on child handle.\r
+          //\r
+          BuildControllerNode = FALSE;\r
+        }\r
+      }\r
+    } else {\r
+      //\r
+      // Find I2C device reported in Remaining Device Path\r
+      //\r
+      if ((!CompareGuid (&((VENDOR_DEVICE_PATH *)RemainingDevicePath)->Guid, Device->DeviceGuid)) ||\r
+          (RemainingPathDeviceIndex != Device->DeviceIndex)) {\r
+        continue; \r
+      }\r
+    }\r
+\r
+    //\r
+    // Build the device context for current I2C device.\r
+    //\r
+    I2cDeviceContext = NULL;\r
+    I2cDeviceContext = AllocateCopyPool (sizeof (I2C_DEVICE_CONTEXT), &gI2cDeviceContextTemplate);\r
+    ASSERT (I2cDeviceContext != NULL);\r
+    if (I2cDeviceContext == NULL) {\r
+      continue;\r
+    }\r
+\r
+    //\r
+    //  Initialize the specific device context\r
+    //\r
+    I2cDeviceContext->I2cBusContext          = I2cBusContext;\r
+    I2cDeviceContext->I2cDevice              = Device;\r
+    I2cDeviceContext->I2cIo.DeviceGuid       = Device->DeviceGuid;\r
+    I2cDeviceContext->I2cIo.DeviceIndex      = Device->DeviceIndex;\r
+    I2cDeviceContext->I2cIo.HardwareRevision = Device->HardwareRevision;\r
+    I2cDeviceContext->I2cIo.I2cControllerCapabilities = I2cBusContext->I2cHost->I2cControllerCapabilities;\r
+\r
+    //\r
+    //  Build the device path\r
+    //\r
+    Status = I2cBusDevicePathAppend (I2cDeviceContext, BuildControllerNode);\r
+    ASSERT_EFI_ERROR (Status);\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+\r
+    //\r
+    //  Install the protocol\r
+    //\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+              &I2cDeviceContext->Handle,\r
+              &gEfiI2cIoProtocolGuid,\r
+              &I2cDeviceContext->I2cIo,\r
+              &gEfiDevicePathProtocolGuid,\r
+              I2cDeviceContext->DevicePath,\r
+              NULL );\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Free resources for this I2C device\r
+      //\r
+      ReleaseI2cDeviceContext (I2cDeviceContext);\r
+      continue;\r
+    }\r
+    \r
+    //\r
+    // Create the child handle\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    Controller,\r
+                    &gEfiI2cHostProtocolGuid,\r
+                    (VOID **) &I2cBusContext->I2cHost,\r
+                    I2cBusContext->DriverBindingHandle,\r
+                    I2cDeviceContext->Handle,\r
+                    EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      I2cDeviceContext->Handle,\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      I2cDeviceContext->DevicePath,\r
+                      &gEfiI2cIoProtocolGuid,\r
+                      &I2cDeviceContext->I2cIo,\r
+                      NULL\r
+                      );\r
+      //\r
+      // Free resources for this I2C device\r
+      //\r
+      ReleaseI2cDeviceContext (I2cDeviceContext);\r
+      continue;      \r
+    }\r
+\r
+    if (RemainingDevicePath != NULL) {\r
+      //\r
+      // Child has been created successfully\r
+      //\r
+      break;\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Queue an I2C transaction for execution on the I2C device.\r
+\r
+  This routine must be called at or below TPL_NOTIFY.  For synchronous\r
+  requests this routine must be called at or below TPL_CALLBACK.\r
+\r
+  This routine queues an I2C transaction to the I2C controller for\r
+  execution on the I2C bus.\r
+\r
+  When Event is NULL, QueueRequest() operates synchronously and returns\r
+  the I2C completion status as its return value.\r
+\r
+  When Event is not NULL, QueueRequest() synchronously returns EFI_SUCCESS\r
+  indicating that the asynchronous I2C transaction was queued.  The values\r
+  above are returned in the buffer pointed to by I2cStatus upon the\r
+  completion of the I2C transaction when I2cStatus is not NULL.\r
+\r
+  The upper layer driver writer provides the following to the platform\r
+  vendor:\r
+  \r
+  1.  Vendor specific GUID for the I2C part\r
+  2.  Guidance on proper construction of the slave address array when the\r
+      I2C device uses more than one slave address.  The I2C bus protocol\r
+      uses the SlaveAddressIndex to perform relative to physical address\r
+      translation to access the blocks of hardware within the I2C device.\r
+\r
+  @param[in] This               Pointer to an EFI_I2C_IO_PROTOCOL structure.\r
+  @param[in] SlaveAddressIndex  Index value into an array of slave addresses\r
+                                for the I2C device.  The values in the array\r
+                                are specified by the board designer, with the\r
+                                third party I2C device driver writer providing\r
+                                the slave address order.\r
+\r
+                                For devices that have a single slave address,\r
+                                this value must be zero.  If the I2C device\r
+                                uses more than one slave address then the\r
+                                third party (upper level) I2C driver writer\r
+                                needs to specify the order of entries in the\r
+                                slave address array.\r
+\r
+                                \ref ThirdPartyI2cDrivers "Third Party I2C\r
+                                Drivers" section in I2cMaster.h.\r
+  @param[in] Event              Event to signal for asynchronous transactions,\r
+                                NULL for synchronous transactions\r
+  @param[in] RequestPacket      Pointer to an EFI_I2C_REQUEST_PACKET structure\r
+                                describing the I2C transaction\r
+  @param[out] I2cStatus         Optional buffer to receive the I2C transaction\r
+                                completion status\r
+\r
+  @retval EFI_SUCCESS           The asynchronous transaction was successfully\r
+                                queued when Event is not NULL.\r
+  @retval EFI_SUCCESS           The transaction completed successfully when\r
+                                Event is NULL.\r
+  @retval EFI_ABORTED           The request did not complete because the driver\r
+                                binding Stop() routine was called.\r
+  @retval EFI_BAD_BUFFER_SIZE   The RequestPacket->LengthInBytes value is too\r
+                                large.\r
+  @retval EFI_DEVICE_ERROR      There was an I2C error (NACK) during the\r
+                                transaction.\r
+  @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
+  @retval EFI_NOT_FOUND         Reserved bit set in the SlaveAddress parameter\r
+  @retval EFI_NO_MAPPING        The EFI_I2C_HOST_PROTOCOL could not set the\r
+                                bus configuration required to access this I2C\r
+                                device.\r
+  @retval EFI_NO_RESPONSE       The I2C device is not responding to the slave\r
+                                address selected by SlaveAddressIndex.\r
+                                EFI_DEVICE_ERROR will be returned if the\r
+                                controller cannot distinguish when the NACK\r
+                                occurred.\r
+  @retval EFI_OUT_OF_RESOURCES  Insufficient memory for I2C transaction\r
+  @retval EFI_UNSUPPORTED       The controller does not support the requested\r
+                                transaction.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusQueueRequest (\r
+  IN CONST EFI_I2C_IO_PROTOCOL  *This,\r
+  IN UINTN                      SlaveAddressIndex,\r
+  IN EFI_EVENT                  Event               OPTIONAL,\r
+  IN EFI_I2C_REQUEST_PACKET     *RequestPacket,\r
+  OUT EFI_STATUS                *I2cStatus          OPTIONAL\r
+  )\r
+{\r
+  CONST EFI_I2C_DEVICE        *I2cDevice;\r
+  I2C_BUS_CONTEXT             *I2cBusContext;\r
+  CONST EFI_I2C_HOST_PROTOCOL *I2cHost;\r
+  I2C_DEVICE_CONTEXT          *I2cDeviceContext;\r
+  EFI_STATUS                  Status;\r
+\r
+  if (RequestPacket == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  //  Validate the I2C slave index\r
+  //\r
+  I2cDeviceContext = I2C_DEVICE_CONTEXT_FROM_PROTOCOL (This);\r
+  I2cDevice        = I2cDeviceContext->I2cDevice;\r
+  if ( SlaveAddressIndex >= I2cDevice->SlaveAddressCount ) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  //  Locate the I2c Host Protocol to queue request\r
+  //\r
+  I2cBusContext = I2cDeviceContext->I2cBusContext;\r
+  I2cHost       = I2cBusContext->I2cHost;\r
+\r
+  //\r
+  //  Start the I2C operation\r
+  //\r
+  Status = I2cHost->QueueRequest (\r
+                      I2cHost,\r
+                      I2cDevice->I2cBusConfiguration,\r
+                      I2cDevice->SlaveAddressArray [SlaveAddressIndex],\r
+                      Event,\r
+                      RequestPacket,\r
+                      I2cStatus\r
+                      );\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Release all the resources allocated for the I2C device.\r
+\r
+  This function releases all the resources allocated for the I2C device.\r
+\r
+  @param  I2cDeviceContext         The I2C child device involved for the operation.\r
+\r
+**/\r
+VOID\r
+ReleaseI2cDeviceContext (\r
+  IN I2C_DEVICE_CONTEXT          *I2cDeviceContext\r
+  )\r
+{\r
+  if (I2cDeviceContext == NULL) {\r
+    return;\r
+  }\r
+  \r
+  if (I2cDeviceContext->DevicePath != NULL) {\r
+    FreePool (I2cDeviceContext->DevicePath);\r
+  }\r
+\r
+  FreePool (I2cDeviceContext);\r
+}\r
+\r
+/**\r
+  Unregister an I2C device.\r
+\r
+  This function removes the protocols installed on the controller handle and\r
+  frees the resources allocated for the I2C device.\r
+\r
+  @param  This                  The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param  Controller            The controller handle of the I2C device.\r
+  @param  Handle                The child handle.\r
+\r
+  @retval EFI_SUCCESS           The I2C device is successfully unregistered.\r
+  @return Others                Some error occurs when unregistering the I2C device.\r
+\r
+**/\r
+EFI_STATUS\r
+UnRegisterI2cDevice (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN  EFI_HANDLE                     Controller,\r
+  IN  EFI_HANDLE                     Handle\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  I2C_DEVICE_CONTEXT          *I2cDeviceContext;\r
+  EFI_I2C_IO_PROTOCOL         *I2cIo;\r
+  EFI_I2C_HOST_PROTOCOL       *I2cHost;\r
+\r
+  I2cIo = NULL;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiI2cIoProtocolGuid,\r
+                  (VOID **) &I2cIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Get I2c device context data.\r
+  //\r
+  I2cDeviceContext = I2C_DEVICE_CONTEXT_FROM_PROTOCOL (I2cIo);\r
+\r
+  //\r
+  // Close the child handle\r
+  //\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiI2cHostProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Handle\r
+         );\r
+\r
+  //\r
+  // The I2C Bus driver installs the I2C Io and Device Path Protocol in the DriverBindingStart().\r
+  // Here should uninstall them.\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  I2cDeviceContext->DevicePath,\r
+                  &gEfiI2cIoProtocolGuid,\r
+                  &I2cDeviceContext->I2cIo,\r
+                  NULL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Keep parent and child relationship\r
+    //\r
+    gBS->OpenProtocol (\r
+          Controller,\r
+          &gEfiI2cHostProtocolGuid,\r
+          (VOID **) &I2cHost,\r
+          This->DriverBindingHandle,\r
+          Handle,\r
+          EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+          );\r
+    return Status;\r
+  }\r
+  \r
+  //\r
+  // Free resources for this I2C device\r
+  //\r
+  ReleaseI2cDeviceContext (I2cDeviceContext);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Create a path for the I2C device\r
+\r
+  Append the I2C slave path to the I2C master controller path.\r
+\r
+  @param[in] I2cDeviceContext           Address of an I2C_DEVICE_CONTEXT structure.\r
+  @param[in] BuildControllerNode        Flag to build controller node in device path.\r
+\r
+  @retval EFI_SUCCESS           The I2C device path is built successfully.\r
+  @return Others                It is failed to built device path.\r
+\r
+**/\r
+EFI_STATUS\r
+I2cBusDevicePathAppend (\r
+  IN I2C_DEVICE_CONTEXT     *I2cDeviceContext,\r
+  IN BOOLEAN                BuildControllerNode\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *PreviousDevicePath;\r
+  \r
+  PreviousDevicePath = NULL;\r
+\r
+  //\r
+  // Build vendor device path\r
+  //  \r
+  CopyMem (&gVendorDevicePathTemplate.Guid, I2cDeviceContext->I2cDevice->DeviceGuid, sizeof (EFI_GUID));\r
+  I2cDeviceContext->DevicePath                    = AppendDevicePathNode (\r
+                                                      I2cDeviceContext->I2cBusContext->ParentDevicePath,\r
+                                                      (EFI_DEVICE_PATH_PROTOCOL *) &gVendorDevicePathTemplate\r
+                                                      );\r
+  ASSERT (I2cDeviceContext->DevicePath != NULL);\r
+  if (I2cDeviceContext->DevicePath == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  \r
+  if ((BuildControllerNode) && (I2cDeviceContext->DevicePath != NULL)) {\r
+    //\r
+    // Build the final I2C device path with controller node\r
+    //\r
+    PreviousDevicePath = I2cDeviceContext->DevicePath;\r
+    gControllerDevicePathTemplate.ControllerNumber = I2cDeviceContext->I2cDevice->DeviceIndex; \r
+    I2cDeviceContext->DevicePath          = AppendDevicePathNode (\r
+                                              I2cDeviceContext->DevicePath,\r
+                                              (EFI_DEVICE_PATH_PROTOCOL *) &gControllerDevicePathTemplate\r
+                                              );\r
+    gBS->FreePool (PreviousDevicePath);\r
+    ASSERT (I2cDeviceContext->DevicePath != NULL);\r
+    if (I2cDeviceContext->DevicePath == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  The user entry point for the I2C bus module. The user code starts with\r
+  this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeI2cBus(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gI2cBusDriverBinding,\r
+             NULL,\r
+             &gI2cBusComponentName,\r
+             &gI2cBusComponentName2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  \r
+  return Status;\r
+}\r
+\r
+/**\r
+  This is the unload handle for I2C bus module.\r
+\r
+  Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r
+  Uninstall all the protocols installed in the driver entry point.\r
+\r
+  @param[in] ImageHandle           The drivers' driver image.\r
+\r
+  @retval    EFI_SUCCESS           The image is unloaded.\r
+  @retval    Others                Failed to unload the image.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusUnload (\r
+  IN EFI_HANDLE             ImageHandle\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_HANDLE                        *DeviceHandleBuffer;\r
+  UINTN                             DeviceHandleCount;\r
+  UINTN                             Index;\r
+\r
+  //\r
+  // Get the list of all I2C Controller handles in the handle database.\r
+  // If there is an error getting the list, then the unload\r
+  // operation fails.\r
+  //\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gEfiI2cHostProtocolGuid,\r
+                  NULL,\r
+                  &DeviceHandleCount,\r
+                  &DeviceHandleBuffer\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Disconnect the driver specified by Driver BindingHandle from all\r
+  // the devices in the handle database.\r
+  //\r
+  for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+    Status = gBS->DisconnectController (\r
+                    DeviceHandleBuffer[Index],\r
+                    gI2cBusDriverBinding.DriverBindingHandle,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Uninstall all the protocols installed in the driver entry point\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  gI2cBusDriverBinding.DriverBindingHandle,\r
+                  &gEfiDriverBindingProtocolGuid,\r
+                  &gI2cBusDriverBinding,\r
+                  &gEfiComponentNameProtocolGuid,\r
+                  &gI2cBusComponentName,\r
+                  &gEfiComponentName2ProtocolGuid,\r
+                  &gI2cBusComponentName2,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+Done:\r
+  //\r
+  // Free the buffer containing the list of handles from the handle database\r
+  //\r
+  if (DeviceHandleBuffer != NULL) {\r
+    gBS->FreePool (DeviceHandleBuffer);\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/MdeModulePkg/Bus/I2c/I2cDxe/I2cBusDxe.inf b/MdeModulePkg/Bus/I2c/I2cDxe/I2cBusDxe.inf
new file mode 100644 (file)
index 0000000..12b42ab
--- /dev/null
@@ -0,0 +1,54 @@
+## @file\r
+#  This driver enumerates I2C devices on I2C bus and produce I2C\r
+#  IO Protocol on I2C devices.\r
+#\r
+#  Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = I2cBusDxe\r
+  FILE_GUID                      = 0C34B372-2622-4A13-A46E-BFD0DEB48BFF\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = InitializeI2cBus\r
+  UNLOAD_IMAGE                   = I2cBusUnload\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  I2cDxe.h\r
+  I2cBus.c\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
+  DebugLib\r
+  DevicePathLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+[Protocols]\r
+  gEfiI2cIoProtocolGuid                             ## BY_START\r
+  gEfiI2cHostProtocolGuid                           ## BY_START\r
+  gEfiI2cMasterProtocolGuid                         ## TO_START\r
+  gEfiI2cEnumerateProtocolGuid                      ## TO_START\r
+  gEfiI2cBusConfigurationManagementProtocolGuid     ## TO_START\r
+  gEfiI2cHostProtocolGuid                           ## TO_START\r
diff --git a/MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.c b/MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.c
new file mode 100644 (file)
index 0000000..fb985f9
--- /dev/null
@@ -0,0 +1,75 @@
+/** @file\r
+  This file implements the entrypoint and unload function for I2C DXE module.\r
+\r
+  Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "I2cDxe.h"\r
+\r
+/**\r
+  The user Entry Point for I2C module. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeI2c(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = InitializeI2cHost ( ImageHandle, SystemTable );\r
+  if ( !EFI_ERROR ( Status ))\r
+  {\r
+    Status = InitializeI2cBus ( ImageHandle, SystemTable );\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This is the unload handle for I2C module.\r
+\r
+  Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r
+  Uninstall all the protocols installed in the driver entry point.\r
+\r
+  @param[in] ImageHandle           The drivers' driver image.\r
+\r
+  @retval    EFI_SUCCESS           The image is unloaded.\r
+  @retval    Others                Failed to unload the image.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cUnload (\r
+  IN EFI_HANDLE             ImageHandle\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+\r
+  //\r
+  //  Disconnect the drivers\r
+  //\r
+  Status = I2cBusUnload ( ImageHandle );\r
+  if ( !EFI_ERROR ( Status )) {\r
+    Status = I2cHostUnload ( ImageHandle );\r
+  }\r
+  return Status;\r
+}\r
diff --git a/MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.h b/MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.h
new file mode 100644 (file)
index 0000000..1490d42
--- /dev/null
@@ -0,0 +1,1097 @@
+/** @file\r
+  Private data structures for the I2C DXE driver.\r
+\r
+  This file defines common data structures, macro definitions and some module\r
+  internal function header files.\r
+\r
+  Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __I2C_DXE_H__\r
+#define __I2C_DXE_H__\r
+\r
+#include <Uefi.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#include <Protocol/DriverBinding.h>\r
+#include <Protocol/I2cEnumerate.h>\r
+#include <Protocol/I2cHost.h>\r
+#include <Protocol/I2cIo.h>\r
+#include <Protocol/I2cMaster.h>\r
+#include <Protocol/I2cBusConfigurationManagement.h>\r
+#include <Protocol/LoadedImage.h>\r
+\r
+#define I2C_DEVICE_SIGNATURE          SIGNATURE_32 ('I', '2', 'C', 'D')\r
+#define I2C_HOST_SIGNATURE            SIGNATURE_32 ('I', '2', 'C', 'H')\r
+#define I2C_REQUEST_SIGNATURE         SIGNATURE_32 ('I', '2', 'C', 'R')\r
+\r
+//\r
+// Synchronize access to the list of requests\r
+//\r
+#define TPL_I2C_SYNC                  TPL_NOTIFY\r
+\r
+//\r
+//  I2C bus context\r
+//\r
+typedef struct {\r
+  EFI_I2C_ENUMERATE_PROTOCOL       *I2cEnumerate;\r
+  EFI_I2C_HOST_PROTOCOL            *I2cHost;\r
+  EFI_HANDLE                       Controller;\r
+  EFI_DEVICE_PATH_PROTOCOL         *ParentDevicePath;\r
+  EFI_HANDLE                       DriverBindingHandle;  \r
+} I2C_BUS_CONTEXT;\r
+\r
+//\r
+// I2C device context\r
+//\r
+typedef struct {\r
+  //\r
+  // Structure identification\r
+  //\r
+  UINT32                        Signature;\r
+\r
+  //\r
+  // I2c device handle\r
+  //\r
+  EFI_HANDLE                    Handle;\r
+\r
+  //\r
+  // Upper level API to support the I2C device I/O\r
+  //\r
+  EFI_I2C_IO_PROTOCOL           I2cIo;\r
+\r
+  //\r
+  // Device path for this device\r
+  //\r
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
+\r
+  //\r
+  // Platform specific data for this device\r
+  //\r
+  CONST EFI_I2C_DEVICE          *I2cDevice;\r
+\r
+  //\r
+  // Context for the common I/O support including the\r
+  // lower level API to the host controller.\r
+  //\r
+  I2C_BUS_CONTEXT               *I2cBusContext;\r
+} I2C_DEVICE_CONTEXT;\r
+\r
+#define I2C_DEVICE_CONTEXT_FROM_PROTOCOL(a) CR (a, I2C_DEVICE_CONTEXT, I2cIo, I2C_DEVICE_SIGNATURE)\r
+\r
+//\r
+// I2C Request\r
+//\r
+typedef struct {\r
+  //\r
+  // Signature\r
+  //\r
+  UINT32                            Signature;\r
+  \r
+  //\r
+  // Next request in the pending request list\r
+  //\r
+  LIST_ENTRY                        Link;\r
+\r
+  //\r
+  // I2C bus configuration for the operation\r
+  //\r
+  UINTN                             I2cBusConfiguration;\r
+\r
+  //\r
+  // I2C slave address for the operation\r
+  //\r
+  UINTN                             SlaveAddress;\r
+\r
+  //\r
+  // Event to set for asynchronous operations, NULL for\r
+  // synchronous operations\r
+  //\r
+  EFI_EVENT                         Event;\r
+\r
+  //\r
+  // I2C operation description\r
+  //\r
+  EFI_I2C_REQUEST_PACKET            *RequestPacket;\r
+\r
+  //\r
+  // Optional buffer to receive the I2C operation completion status\r
+  //\r
+  EFI_STATUS                        *Status;\r
+} I2C_REQUEST;\r
+\r
+#define I2C_REQUEST_FROM_ENTRY(a)         CR (a, I2C_REQUEST, Link, I2C_REQUEST_SIGNATURE);\r
+\r
+//\r
+// I2C host context\r
+//\r
+typedef struct {\r
+  //\r
+  // Structure identification\r
+  //\r
+  UINTN Signature;\r
+\r
+  //\r
+  // Current I2C bus configuration\r
+  //\r
+  UINTN I2cBusConfiguration;\r
+\r
+  //\r
+  // I2C bus configuration management event\r
+  //\r
+  EFI_EVENT I2cBusConfigurationEvent;\r
+\r
+  //\r
+  // I2C operation completion event\r
+  //\r
+  EFI_EVENT I2cEvent;\r
+\r
+  //\r
+  // I2C operation and I2C bus configuration management status\r
+  //\r
+  EFI_STATUS Status;\r
+\r
+  //\r
+  // I2C bus configuration management operation pending\r
+  //\r
+  BOOLEAN I2cBusConfigurationManagementPending;\r
+\r
+  //\r
+  // I2C request list maintained by I2C Host\r
+  //\r
+  LIST_ENTRY                  RequestList;\r
+\r
+  //\r
+  // Upper level API\r
+  //\r
+  EFI_I2C_HOST_PROTOCOL       I2cHost;\r
+\r
+  //\r
+  // I2C bus configuration management protocol\r
+  //\r
+  EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL *I2cBusConfigurationManagement;\r
+\r
+  //\r
+  // Lower level API for I2C master (controller)\r
+  //\r
+  EFI_I2C_MASTER_PROTOCOL *I2cMaster;\r
+} I2C_HOST_CONTEXT;\r
+\r
+#define I2C_HOST_CONTEXT_FROM_PROTOCOL(a) CR (a, I2C_HOST_CONTEXT, I2cHost, I2C_HOST_SIGNATURE)\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_COMPONENT_NAME_PROTOCOL    gI2cBusComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL   gI2cBusComponentName2;\r
+extern EFI_DRIVER_BINDING_PROTOCOL    gI2cBusDriverBinding;\r
+\r
+extern EFI_COMPONENT_NAME_PROTOCOL    gI2cHostComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL   gI2cHostComponentName2;\r
+extern EFI_DRIVER_BINDING_PROTOCOL    gI2cHostDriverBinding;\r
+\r
+/**\r
+  Start the I2C driver\r
+\r
+  This routine allocates the necessary resources for the driver.\r
+\r
+  This routine is called by I2cBusDriverStart to complete the driver\r
+  initialization.\r
+\r
+  @param[in] I2cBus                   Address of an I2C_BUS_CONTEXT structure\r
+  @param[in] Controller               Handle to the controller\r
+  @param[in] RemainingDevicePath      A pointer to the remaining portion of a device path.\r
+\r
+  @retval EFI_SUCCESS                 Driver API properly initialized\r
+  \r
+**/\r
+EFI_STATUS\r
+RegisterI2cDevice (\r
+  IN I2C_BUS_CONTEXT           *I2cBus,\r
+  IN EFI_HANDLE                 Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath\r
+  );\r
+\r
+/**\r
+  Unregister an I2C device.\r
+\r
+  This function removes the protocols installed on the controller handle and\r
+  frees the resources allocated for the I2C device.\r
+\r
+  @param  This                  The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param  Controller            The controller handle of the I2C device.\r
+  @param  Handle                The child handle.\r
+\r
+  @retval EFI_SUCCESS           The I2C device is successfully unregistered.\r
+  @return Others                Some error occurs when unregistering the I2C device.\r
+\r
+**/\r
+EFI_STATUS\r
+UnRegisterI2cDevice (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN  EFI_HANDLE                     Controller,\r
+  IN  EFI_HANDLE                     Handle\r
+  );\r
+\r
+/**\r
+  Create a path for the I2C device\r
+\r
+  Append the I2C slave path to the I2C master controller path.\r
+\r
+  @param[in] I2cDeviceContext           Address of an I2C_DEVICE_CONTEXT structure.\r
+  @param[in] BuildControllerNode        Flag to build controller node in device path.\r
+\r
+  @retval EFI_SUCCESS           The I2C device path is built successfully.\r
+  @return Others                It is failed to built device path.\r
+\r
+**/\r
+EFI_STATUS\r
+I2cBusDevicePathAppend (\r
+  IN I2C_DEVICE_CONTEXT     *I2cDeviceContext,\r
+  IN BOOLEAN                BuildControllerNode\r
+  );\r
+\r
+/**\r
+  Queue an I2C transaction for execution on the I2C device.\r
+\r
+  This routine must be called at or below TPL_NOTIFY.  For synchronous\r
+  requests this routine must be called at or below TPL_CALLBACK.\r
+\r
+  This routine queues an I2C transaction to the I2C controller for\r
+  execution on the I2C bus.\r
+\r
+  When Event is NULL, QueueRequest() operates synchronously and returns\r
+  the I2C completion status as its return value.\r
+\r
+  When Event is not NULL, QueueRequest() synchronously returns EFI_SUCCESS\r
+  indicating that the asynchronous I2C transaction was queued.  The values\r
+  above are returned in the buffer pointed to by I2cStatus upon the\r
+  completion of the I2C transaction when I2cStatus is not NULL.\r
+\r
+  The upper layer driver writer provides the following to the platform\r
+  vendor:\r
+  \r
+  1.  Vendor specific GUID for the I2C part\r
+  2.  Guidance on proper construction of the slave address array when the\r
+      I2C device uses more than one slave address.  The I2C bus protocol\r
+      uses the SlaveAddressIndex to perform relative to physical address\r
+      translation to access the blocks of hardware within the I2C device.\r
+\r
+  @param[in] This               Pointer to an EFI_I2C_IO_PROTOCOL structure.\r
+  @param[in] SlaveAddressIndex  Index value into an array of slave addresses\r
+                                for the I2C device.  The values in the array\r
+                                are specified by the board designer, with the\r
+                                third party I2C device driver writer providing\r
+                                the slave address order.\r
+\r
+                                For devices that have a single slave address,\r
+                                this value must be zero.  If the I2C device\r
+                                uses more than one slave address then the\r
+                                third party (upper level) I2C driver writer\r
+                                needs to specify the order of entries in the\r
+                                slave address array.\r
+\r
+                                \ref ThirdPartyI2cDrivers "Third Party I2C\r
+                                Drivers" section in I2cMaster.h.\r
+  @param[in] Event              Event to signal for asynchronous transactions,\r
+                                NULL for synchronous transactions\r
+  @param[in] RequestPacket      Pointer to an EFI_I2C_REQUEST_PACKET structure\r
+                                describing the I2C transaction\r
+  @param[out] I2cStatus         Optional buffer to receive the I2C transaction\r
+                                completion status\r
+\r
+  @retval EFI_SUCCESS           The asynchronous transaction was successfully\r
+                                queued when Event is not NULL.\r
+  @retval EFI_SUCCESS           The transaction completed successfully when\r
+                                Event is NULL.\r
+  @retval EFI_ABORTED           The request did not complete because the driver\r
+                                binding Stop() routine was called.\r
+  @retval EFI_BAD_BUFFER_SIZE   The RequestPacket->LengthInBytes value is too\r
+                                large.\r
+  @retval EFI_DEVICE_ERROR      There was an I2C error (NACK) during the\r
+                                transaction.\r
+  @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
+  @retval EFI_NOT_FOUND         Reserved bit set in the SlaveAddress parameter\r
+  @retval EFI_NO_MAPPING        The EFI_I2C_HOST_PROTOCOL could not set the\r
+                                bus configuration required to access this I2C\r
+                                device.\r
+  @retval EFI_NO_RESPONSE       The I2C device is not responding to the slave\r
+                                address selected by SlaveAddressIndex.\r
+                                EFI_DEVICE_ERROR will be returned if the\r
+                                controller cannot distinguish when the NACK\r
+                                occurred.\r
+  @retval EFI_OUT_OF_RESOURCES  Insufficient memory for I2C transaction\r
+  @retval EFI_UNSUPPORTED       The controller does not support the requested\r
+                                transaction.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusQueueRequest (\r
+  IN CONST EFI_I2C_IO_PROTOCOL  *This,\r
+  IN UINTN                      SlaveAddressIndex,\r
+  IN EFI_EVENT                  Event               OPTIONAL,\r
+  IN EFI_I2C_REQUEST_PACKET     *RequestPacket,\r
+  OUT EFI_STATUS                *I2cStatus          OPTIONAL\r
+  );\r
+\r
+/**\r
+  Tests to see if this driver supports a given controller. If a child device is provided,\r
+  it further tests to see if this driver supports creating a handle for the specified child device.\r
+\r
+  This function checks to see if the driver specified by This supports the device specified by\r
+  ControllerHandle. Drivers will typically use the device path attached to\r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to\r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function\r
+  may be called many times during platform initialization. In order to reduce boot times, the tests\r
+  performed by this function must be very small, and take as little time as possible to execute. This\r
+  function must not change the state of any hardware devices, and this function must be aware that the\r
+  device specified by ControllerHandle may already be managed by the same driver or a\r
+  different driver. This function must match its calls to AllocatePages() with FreePages(),\r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
+  Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For bus drivers, if this parameter is not NULL, then\r
+                                   the bus driver must determine if the bus controller specified\r
+                                   by ControllerHandle and the child controller specified\r
+                                   by RemainingDevicePath are both supported by this\r
+                                   bus driver.\r
+\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusDriverSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+/**\r
+  Starts a device controller or a bus controller.\r
+\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this\r
+  common boot service. It is legal to call Start() from other locations,\r
+  but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles\r
+                                   for all the children of Controller are created by this driver.\r
+                                   If this parameter is not NULL and the first Device Path Node is\r
+                                   not the End of Device Path Node, then only the handle for the\r
+                                   child device specified by the first Device Path Node of\r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is\r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusDriverStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+/**\r
+  Stops a device controller or a bus controller.\r
+\r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
+  As a result, much of the error checking on the parameters to Stop() has been moved\r
+  into this common boot service. It is legal to call Stop() from other locations,\r
+  but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+\r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must\r
+                                support a bus specific I/O protocol for the driver\r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL\r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusDriverStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Controller,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  );\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+  \r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL                    *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+/**\r
+  The user entry point for the I2C bus module. The user code starts with\r
+  this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeI2cBus(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  );\r
+\r
+/**\r
+  This is the unload handle for I2C bus module.\r
+\r
+  Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r
+  Uninstall all the protocols installed in the driver entry point.\r
+\r
+  @param[in] ImageHandle           The drivers' driver image.\r
+\r
+  @retval    EFI_SUCCESS           The image is unloaded.\r
+  @retval    Others                Failed to unload the image.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cBusUnload (\r
+  IN EFI_HANDLE             ImageHandle\r
+  );\r
+\r
+/**\r
+  Release all the resources allocated for the I2C device.\r
+\r
+  This function releases all the resources allocated for the I2C device.\r
+\r
+  @param  I2cDeviceContext         The I2C child device involved for the operation.\r
+\r
+**/\r
+VOID\r
+ReleaseI2cDeviceContext (\r
+  IN I2C_DEVICE_CONTEXT          *I2cDeviceContext\r
+  );\r
+\r
+/**\r
+  Complete the current request\r
+\r
+  @param[in] I2cHost  Address of an I2C_HOST_CONTEXT structure.\r
+  @param[in] Status   Status of the I<sub>2</sub>C operation.\r
+\r
+  @return This routine returns the input status value.\r
+\r
+**/\r
+EFI_STATUS\r
+I2cHostRequestComplete (\r
+  I2C_HOST_CONTEXT *I2cHost,\r
+  EFI_STATUS       Status\r
+  );\r
+\r
+/**\r
+  Enable access to the I2C bus configuration\r
+\r
+  @param[in] I2cHostContext     Address of an I2C_HOST_CONTEXT structure\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_ABORTED           The request did not complete because the driver\r
+                                was shutdown.\r
+  @retval EFI_BAD_BUFFER_SIZE   The WriteBytes or ReadBytes buffer size is too large.\r
+  @retval EFI_DEVICE_ERROR      There was an I2C error (NACK) during the operation.\r
+                                This could indicate the slave device is not present.\r
+  @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
+  @retval EFI_NO_MAPPING        Invalid I2cBusConfiguration value\r
+  @retval EFI_NO_RESPONSE       The I2C device is not responding to the\r
+                                slave address.  EFI_DEVICE_ERROR may also be\r
+                                returned if the controller can not distinguish\r
+                                when the NACK occurred.\r
+  @retval EFI_NOT_FOUND         I2C slave address exceeds maximum address\r
+  @retval EFI_NOT_READY         I2C bus is busy or operation pending, wait for\r
+                                the event and then read status.\r
+  @retval EFI_OUT_OF_RESOURCES  Insufficient memory for I2C operation\r
+  @retval EFI_TIMEOUT           The transaction did not complete within an internally\r
+                                specified timeout period.\r
+\r
+**/\r
+EFI_STATUS\r
+I2cHostRequestEnable (\r
+  I2C_HOST_CONTEXT *I2cHost\r
+  );\r
+\r
+/**\r
+  Tests to see if this driver supports a given controller. If a child device is provided,\r
+  it further tests to see if this driver supports creating a handle for the specified child device.\r
+\r
+  This function checks to see if the driver specified by This supports the device specified by\r
+  ControllerHandle. Drivers will typically use the device path attached to\r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to\r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function\r
+  may be called many times during platform initialization. In order to reduce boot times, the tests\r
+  performed by this function must be very small, and take as little time as possible to execute. This\r
+  function must not change the state of any hardware devices, and this function must be aware that the\r
+  device specified by ControllerHandle may already be managed by the same driver or a\r
+  different driver. This function must match its calls to AllocatePages() with FreePages(),\r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
+  Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For bus drivers, if this parameter is not NULL, then\r
+                                   the bus driver must determine if the bus controller specified\r
+                                   by ControllerHandle and the child controller specified\r
+                                   by RemainingDevicePath are both supported by this\r
+                                   bus driver.\r
+\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostDriverSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+/**\r
+  Starts a device controller or a bus controller.\r
+\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this\r
+  common boot service. It is legal to call Start() from other locations,\r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles\r
+                                   for all the children of Controller are created by this driver.\r
+                                   If this parameter is not NULL and the first Device Path Node is\r
+                                   not the End of Device Path Node, then only the handle for the\r
+                                   child device specified by the first Device Path Node of\r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is\r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostDriverStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL        *This,\r
+  IN EFI_HANDLE                         Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL           *RemainingDevicePath\r
+  );\r
+  \r
+/**\r
+  Stops a device controller or a bus controller.\r
+\r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
+  As a result, much of the error checking on the parameters to Stop() has been moved\r
+  into this common boot service. It is legal to call Stop() from other locations,\r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+\r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must\r
+                                support a bus specific I/O protocol for the driver\r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL\r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostDriverStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL       *This,\r
+  IN  EFI_HANDLE                        Controller,\r
+  IN  UINTN                             NumberOfChildren,\r
+  IN  EFI_HANDLE                        *ChildHandleBuffer\r
+  );\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+  \r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL                    *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+/**\r
+  Handle the bus available event\r
+\r
+  This routine is called at TPL_I2C_SYNC.\r
+\r
+  @param[in] Event    Address of an EFI_EVENT handle\r
+  @param[in] Context  Address of an I2C_HOST_CONTEXT structure\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+I2cHostRequestCompleteEvent (\r
+  IN EFI_EVENT Event,\r
+  IN VOID *Context\r
+  );\r
+\r
+/**\r
+  Handle the I2C bus configuration available event\r
+\r
+  This routine is called at TPL_I2C_SYNC.\r
+\r
+  @param[in] Event    Address of an EFI_EVENT handle\r
+  @param[in] Context  Address of an I2C_HOST_CONTEXT structure\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+I2cHostI2cBusConfigurationAvailable (\r
+  IN EFI_EVENT Event,\r
+  IN VOID *Context\r
+  );\r
+\r
+/**\r
+  Queue an I2C operation for execution on the I2C controller.\r
+\r
+  This routine must be called at or below TPL_NOTIFY.  For synchronous\r
+  requests this routine must be called at or below TPL_CALLBACK.\r
+\r
+  N.B. The typical consumers of this API are the I2C bus driver and\r
+  on rare occasions the I2C test application.  Extreme care must be\r
+  taken by other consumers of this API to prevent confusing the\r
+  third party I2C drivers due to a state change at the I2C device\r
+  which the third party I2C drivers did not initiate.  I2C platform\r
+  drivers may use this API within these guidelines.\r
+\r
+  This layer uses the concept of I2C bus configurations to describe\r
+  the I2C bus.  An I2C bus configuration is defined as a unique\r
+  setting of the multiplexers and switches in the I2C bus which\r
+  enable access to one or more I2C devices.  When using a switch\r
+  to divide a bus, due to speed differences, the I2C platform layer\r
+  would define an I2C bus configuration for the I2C devices on each\r
+  side of the switch.  When using a multiplexer, the I2C platform\r
+  layer defines an I2C bus configuration for each of the selector\r
+  values required to control the multiplexer.  See Figure 1 in the\r
+  <a href="http://www.nxp.com/documents/user_manual/UM10204.pdf">I<sup>2</sup>C\r
+  Specification</a> for a complex I2C bus configuration.\r
+\r
+  The I2C host driver processes all operations in FIFO order.  Prior to\r
+  performing the operation, the I2C host driver calls the I2C platform\r
+  driver to reconfigure the switches and multiplexers in the I2C bus\r
+  enabling access to the specified I2C device.  The I2C platform driver\r
+  also selects the maximum bus speed for the device.  After the I2C bus\r
+  is configured, the I2C host driver calls the I2C port driver to\r
+  initialize the I2C controller and start the I2C operation.\r
+\r
+  @param[in] This             Address of an EFI_I2C_HOST_PROTOCOL instance.\r
+  @param[in] I2cBusConfiguration  I2C bus configuration to access the I2C\r
+                                  device.\r
+  @param[in] SlaveAddress     Address of the device on the I2C bus.\r
+  @param[in] Event            Event to set for asynchronous operations,\r
+                              NULL for synchronous operations\r
+  @param[in] RequestPacket    Address of an EFI_I2C_REQUEST_PACKET\r
+                              structure describing the I2C operation\r
+  @param[out] I2cStatus       Optional buffer to receive the I2C operation\r
+                              completion status\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_ABORTED           The request did not complete because the driver\r
+                                was shutdown.\r
+  @retval EFI_BAD_BUFFER_SIZE   The WriteBytes or ReadBytes buffer size is too large.\r
+  @retval EFI_DEVICE_ERROR      There was an I2C error (NACK) during the operation.\r
+                                This could indicate the slave device is not present.\r
+  @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
+  @retval EFI_INVALID_PARAMETER TPL is too high\r
+  @retval EFI_NO_MAPPING        Invalid I2cBusConfiguration value\r
+  @retval EFI_NO_RESPONSE       The I2C device is not responding to the\r
+                                slave address.  EFI_DEVICE_ERROR may also be\r
+                                returned if the controller can not distinguish\r
+                                when the NACK occurred.\r
+  @retval EFI_NOT_FOUND         I2C slave address exceeds maximum address\r
+  @retval EFI_NOT_READY         I2C bus is busy or operation pending, wait for\r
+                                the event and then read status pointed to by\r
+                                the request packet.\r
+  @retval EFI_OUT_OF_RESOURCES  Insufficient memory for I2C operation\r
+  @retval EFI_TIMEOUT           The transaction did not complete within an internally\r
+                                specified timeout period.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostQueueRequest (\r
+  IN CONST EFI_I2C_HOST_PROTOCOL  *This,\r
+  IN UINTN                        I2cBusConfiguration,\r
+  IN UINTN                        SlaveAddress,\r
+  IN EFI_EVENT                    Event            OPTIONAL,\r
+  IN EFI_I2C_REQUEST_PACKET       *RequestPacket,\r
+  OUT EFI_STATUS                  *I2cStatus       OPTIONAL\r
+  );\r
+\r
+/**\r
+  The user Entry Point for I2C host module. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeI2cHost(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  );\r
+\r
+/**\r
+  This is the unload handle for I2C host module.\r
+\r
+  Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r
+  Uninstall all the protocols installed in the driver entry point.\r
+\r
+  @param[in] ImageHandle           The drivers' driver image.\r
+\r
+  @retval    EFI_SUCCESS           The image is unloaded.\r
+  @retval    Others                Failed to unload the image.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostUnload (\r
+  IN EFI_HANDLE             ImageHandle\r
+  );\r
+\r
+#endif  //  __I2C_DXE_H__\r
diff --git a/MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.inf b/MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.inf
new file mode 100644 (file)
index 0000000..8600531
--- /dev/null
@@ -0,0 +1,56 @@
+## @file\r
+#  This driver produce I2C Host Protocol on I2C controller handle, enumerate I2C\r
+#  devices on I2C bus and produce I2C IO Protocol on I2C devices.\r
+#\r
+#  Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = I2cDxe\r
+  FILE_GUID                      = ECA2AE9E-7594-4901-871C-449DA1A11660\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = InitializeI2c\r
+  UNLOAD_IMAGE                   = I2cUnload\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  I2cDxe.c\r
+  I2cDxe.h\r
+  I2cHost.c\r
+  I2cBus.c\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
+  DebugLib\r
+  DevicePathLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+[Protocols]\r
+  gEfiI2cIoProtocolGuid                             ## BY_START\r
+  gEfiI2cHostProtocolGuid                           ## BY_START\r
+  gEfiI2cMasterProtocolGuid                         ## TO_START\r
+  gEfiI2cEnumerateProtocolGuid                      ## TO_START\r
+  gEfiI2cBusConfigurationManagementProtocolGuid     ## TO_START\r
+  gEfiI2cHostProtocolGuid                           ## TO_START\r
diff --git a/MdeModulePkg/Bus/I2c/I2cDxe/I2cHost.c b/MdeModulePkg/Bus/I2c/I2cDxe/I2cHost.c
new file mode 100644 (file)
index 0000000..e153a4d
--- /dev/null
@@ -0,0 +1,1169 @@
+/** @file\r
+  This file implements I2C Host Protocol which provides callers with the ability to \r
+  do I/O transactions to all of the devices on the I2C bus.\r
+\r
+  Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "I2cDxe.h"\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gI2cHostDriverBinding = {\r
+  I2cHostDriverSupported,\r
+  I2cHostDriverStart,\r
+  I2cHostDriverStop,\r
+  0x10,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+//\r
+// Driver name table \r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mI2cHostDriverNameTable[] = {\r
+  { "eng;en", L"I2c Host Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gI2cHostComponentName = {\r
+  (EFI_COMPONENT_NAME_GET_DRIVER_NAME) I2cHostComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME_GET_CONTROLLER_NAME) I2cHostComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Component Name 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gI2cHostComponentName2 = {\r
+  I2cHostComponentNameGetDriverName,\r
+  I2cHostComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           mI2cHostDriverNameTable,\r
+           DriverName,\r
+           (BOOLEAN)(This != &gI2cHostComponentName2)\r
+           );\r
+}\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL                    *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Tests to see if this driver supports a given controller. If a child device is provided,\r
+  it further tests to see if this driver supports creating a handle for the specified child device.\r
+\r
+  This function checks to see if the driver specified by This supports the device specified by\r
+  ControllerHandle. Drivers will typically use the device path attached to\r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to\r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function\r
+  may be called many times during platform initialization. In order to reduce boot times, the tests\r
+  performed by this function must be very small, and take as little time as possible to execute. This\r
+  function must not change the state of any hardware devices, and this function must be aware that the\r
+  device specified by ControllerHandle may already be managed by the same driver or a\r
+  different driver. This function must match its calls to AllocatePages() with FreePages(),\r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
+  Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
+  to guarantee the state of ControllerHandle is not modified by this function.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For bus drivers, if this parameter is not NULL, then\r
+                                   the bus driver must determine if the bus controller specified\r
+                                   by ControllerHandle and the child controller specified\r
+                                   by RemainingDevicePath are both supported by this\r
+                                   bus driver.\r
+\r
+  @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is supported by the driver specified by This.\r
+  @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by the driver\r
+                                   specified by This.\r
+  @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is already being managed by a different\r
+                                   driver or an application that requires exclusive access.\r
+                                   Currently not implemented.\r
+  @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and\r
+                                   RemainingDevicePath is not supported by the driver specified by This.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostDriverSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_I2C_MASTER_PROTOCOL                       *I2cMaster;\r
+  EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL *I2cBusConfigurationManagement;\r
+  EFI_STATUS                                    Status;\r
+\r
+  //\r
+  //  Locate I2C Bus Configuration Management Protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiI2cBusConfigurationManagementProtocolGuid,\r
+                  (VOID **)&I2cBusConfigurationManagement,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Close the protocol because we don't use it here\r
+  //\r
+  gBS->CloseProtocol (\r
+                  Controller,\r
+                  &gEfiI2cBusConfigurationManagementProtocolGuid,\r
+                  This->DriverBindingHandle,\r
+                  Controller\r
+                  );\r
+\r
+  //\r
+  //  Locate I2C Master Protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiI2cMasterProtocolGuid,\r
+                  (VOID **)&I2cMaster,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Starts a device controller or a bus controller.\r
+\r
+  The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
+  As a result, much of the error checking on the parameters to Start() has been moved into this\r
+  common boot service. It is legal to call Start() from other locations,\r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE.\r
+  2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
+     EFI_DEVICE_PATH_PROTOCOL.\r
+  3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
+\r
+  @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles\r
+                                   for all the children of Controller are created by this driver.\r
+                                   If this parameter is not NULL and the first Device Path Node is\r
+                                   not the End of Device Path Node, then only the handle for the\r
+                                   child device specified by the first Device Path Node of\r
+                                   RemainingDevicePath is created by this driver.\r
+                                   If the first Device Path Node of RemainingDevicePath is\r
+                                   the End of Device Path Node, no child handle is created by this\r
+                                   driver.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostDriverStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL        *This,\r
+  IN EFI_HANDLE                         Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL           *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                                          Status;\r
+  EFI_I2C_MASTER_PROTOCOL                             *I2cMaster;\r
+  EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL       *I2cBusConfigurationManagement;\r
+  I2C_HOST_CONTEXT                                    *I2cHostContext;\r
+\r
+  I2cMaster                     = NULL;\r
+  I2cHostContext                = NULL;\r
+  I2cBusConfigurationManagement = NULL;\r
+\r
+  //\r
+  // Locate I2C Bus Configuration Management Protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiI2cBusConfigurationManagementProtocolGuid,\r
+                  (VOID **)&I2cBusConfigurationManagement,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "I2cHost: Open I2C bus configuration error, Status = %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Locate I2C Master Protocol\r
+  //\r
+  Status = gBS->OpenProtocol ( \r
+                  Controller,\r
+                  &gEfiI2cMasterProtocolGuid,\r
+                  (VOID **)&I2cMaster,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "I2cHost: Open I2C master error, Status = %r\n", Status));\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Allocate the I2C Host Context structure\r
+  //\r
+  I2cHostContext = AllocateZeroPool (sizeof (I2C_HOST_CONTEXT));\r
+  if (I2cHostContext == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "I2cHost: there is no enough memory to allocate.\n"));\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Initialize the context structure for the current I2C Controller\r
+  //\r
+  I2cHostContext->Signature                     = I2C_HOST_SIGNATURE;\r
+  I2cHostContext->I2cMaster                     = I2cMaster;\r
+  I2cHostContext->I2cBusConfigurationManagement = I2cBusConfigurationManagement;\r
+  I2cHostContext->I2cBusConfiguration           = (UINTN) -1;\r
+  InitializeListHead(&I2cHostContext->RequestList);\r
+\r
+  //\r
+  // Reset the controller\r
+  //\r
+  Status = I2cMaster->Reset (I2cMaster);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "I2cHost: I2C controller reset failed!\n"));\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Create the I2C transaction complete event\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_I2C_SYNC,\r
+                  I2cHostRequestCompleteEvent,\r
+                  I2cHostContext,\r
+                  &I2cHostContext->I2cEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "I2cHost: create complete event error, Status = %r\n", Status));\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Get the bus management event\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_I2C_SYNC,\r
+                  I2cHostI2cBusConfigurationAvailable,\r
+                  I2cHostContext,\r
+                  &I2cHostContext->I2cBusConfigurationEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "I2cHost: create bus available event error, Status = %r\n", Status));\r
+    goto Exit;\r
+  }  \r
+\r
+  //\r
+  // Build the I2C host protocol for the current I2C controller\r
+  //\r
+  I2cHostContext->I2cHost.QueueRequest              = I2cHostQueueRequest;\r
+  I2cHostContext->I2cHost.I2cControllerCapabilities = I2cMaster->I2cControllerCapabilities;\r
+\r
+  //\r
+  //  Install the driver protocol\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Controller,\r
+                  &gEfiI2cHostProtocolGuid,\r
+                  &I2cHostContext->I2cHost,\r
+                  NULL\r
+                  );\r
+Exit:\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "I2cHost: Start() function failed, Status = %r\n", Status));\r
+    if (I2cBusConfigurationManagement != NULL) {\r
+      gBS->CloseProtocol (\r
+                      Controller,\r
+                      &gEfiI2cBusConfigurationManagementProtocolGuid,\r
+                      This->DriverBindingHandle,\r
+                      Controller\r
+                      );      \r
+    }\r
+    \r
+    if ((I2cHostContext != NULL) && (I2cHostContext->I2cEvent != NULL)) {\r
+      gBS->CloseEvent (I2cHostContext->I2cEvent);\r
+      I2cHostContext->I2cEvent = NULL;\r
+    }\r
+\r
+    if ((I2cHostContext != NULL) && (I2cHostContext->I2cBusConfigurationEvent != NULL)) {\r
+      gBS->CloseEvent (I2cHostContext->I2cBusConfigurationEvent);\r
+      I2cHostContext->I2cBusConfigurationEvent = NULL;\r
+    }\r
+\r
+    //\r
+    //  Release the context structure upon failure\r
+    //\r
+    if (I2cHostContext != NULL) {\r
+      FreePool (I2cHostContext);\r
+    }\r
+  }\r
+\r
+  //\r
+  //  Return the operation status.\r
+  //\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Stops a device controller or a bus controller.\r
+\r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
+  As a result, much of the error checking on the parameters to Stop() has been moved\r
+  into this common boot service. It is legal to call Stop() from other locations,\r
+  but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
+  1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
+     same driver's Start() function.\r
+  2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
+     EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
+     Start() function, and the Start() function must have called OpenProtocol() on\r
+     ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
+\r
+  @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must\r
+                                support a bus specific I/O protocol for the driver\r
+                                to use to stop the device.\r
+  @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL\r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostDriverStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL       *This,\r
+  IN  EFI_HANDLE                        Controller,\r
+  IN  UINTN                             NumberOfChildren,\r
+  IN  EFI_HANDLE                        *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_STATUS                  Status;  \r
+  I2C_HOST_CONTEXT            *I2cHostContext;\r
+  EFI_I2C_HOST_PROTOCOL       *I2cHost;\r
+  EFI_TPL                     TplPrevious;\r
+\r
+  TplPrevious = EfiGetCurrentTpl ();\r
+  if (TplPrevious > TPL_I2C_SYNC) {\r
+    DEBUG ((EFI_D_ERROR, "I2cHost: TPL %d is too high in Stop.\n", TplPrevious));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiI2cHostProtocolGuid,\r
+                  (VOID **) &I2cHost,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  I2cHostContext = I2C_HOST_CONTEXT_FROM_PROTOCOL (I2cHost);\r
+\r
+  //\r
+  // Raise TPL for critical section\r
+  //\r
+  TplPrevious = gBS->RaiseTPL (TPL_I2C_SYNC);\r
+  \r
+  //\r
+  // If there is pending request or pending bus configuration, do not stop\r
+  //\r
+  Status = EFI_DEVICE_ERROR;\r
+  if (( !I2cHostContext->I2cBusConfigurationManagementPending )\r
+    && IsListEmpty (&I2cHostContext->RequestList)) {\r
+    \r
+    //\r
+    //  Remove the I2C host protocol\r
+    //\r
+    Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                    Controller,\r
+                    &gEfiI2cHostProtocolGuid,\r
+                    I2cHost,\r
+                    NULL\r
+                    );\r
+  }\r
+  \r
+  //\r
+  // Leave critical section\r
+  //\r
+  gBS->RestoreTPL (TplPrevious);\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           Controller,\r
+           &gEfiI2cBusConfigurationManagementProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
+\r
+    //\r
+    // Release I2c Host resources\r
+    //\r
+    if (I2cHostContext->I2cBusConfigurationEvent != NULL) {\r
+      gBS->CloseEvent (I2cHostContext->I2cBusConfigurationEvent);\r
+      I2cHostContext->I2cBusConfigurationEvent = NULL;\r
+    }\r
+    \r
+    if (I2cHostContext->I2cEvent != NULL) {\r
+      gBS->CloseEvent (I2cHostContext->I2cEvent);\r
+      I2cHostContext->I2cEvent = NULL;\r
+    }\r
+    \r
+    FreePool (I2cHostContext);\r
+  }\r
+\r
+  //\r
+  //  Return the stop status\r
+  //\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Handle the I2C bus configuration available event\r
+\r
+  This routine is called at TPL_I2C_SYNC.\r
+\r
+  @param[in] Event    Address of an EFI_EVENT handle\r
+  @param[in] Context  Address of an I2C_HOST_CONTEXT structure\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+I2cHostI2cBusConfigurationAvailable (\r
+  IN EFI_EVENT Event,\r
+  IN VOID *Context\r
+  )\r
+{\r
+  I2C_HOST_CONTEXT            *I2cHostContext;\r
+  EFI_I2C_MASTER_PROTOCOL     *I2cMaster;\r
+  I2C_REQUEST                 *I2cRequest;\r
+  LIST_ENTRY                  *EntryHeader;\r
+  LIST_ENTRY                  *Entry;\r
+  EFI_STATUS                  Status;\r
+\r
+  //\r
+  // Mark this I2C bus configuration management operation as complete\r
+  //\r
+  I2cHostContext = (I2C_HOST_CONTEXT *)Context;\r
+  I2cMaster      = I2cHostContext->I2cMaster;\r
+  ASSERT (I2cMaster != NULL);\r
+  //\r
+  // Clear flag to indicate I2C bus configuration is finished\r
+  //\r
+  I2cHostContext->I2cBusConfigurationManagementPending = FALSE;\r
+\r
+  //\r
+  //  Validate the completion status\r
+  //\r
+  if (EFI_ERROR (I2cHostContext->Status)) {\r
+    //\r
+    // Setting I2C bus configuration failed before\r
+    //\r
+    I2cHostRequestComplete (I2cHostContext, I2cHostContext->Status);\r
+\r
+    //\r
+    // Unknown I2C bus configuration\r
+    // Force next operation to enable the I2C bus configuration\r
+    //\r
+    I2cHostContext->I2cBusConfiguration = (UINTN) -1;\r
+    \r
+    //\r
+    // Do not continue current I2C request\r
+    //\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Get the first request in the link with FIFO order\r
+  //\r
+  EntryHeader = &I2cHostContext->RequestList;\r
+  Entry = GetFirstNode (EntryHeader);\r
+  I2cRequest = I2C_REQUEST_FROM_ENTRY (Entry);\r
+\r
+  //\r
+  // Update the I2C bus configuration of the current I2C request\r
+  //\r
+  I2cHostContext->I2cBusConfiguration = I2cRequest->I2cBusConfiguration;\r
+\r
+  //\r
+  // Start an I2C operation on the host, the status is returned by I2cHostContext->Status\r
+  //\r
+  Status = I2cMaster->StartRequest ( \r
+                        I2cMaster,\r
+                        I2cRequest->SlaveAddress,\r
+                        I2cRequest->RequestPacket,\r
+                        I2cHostContext->I2cEvent,\r
+                        &I2cHostContext->Status\r
+                        );\r
+}\r
+\r
+/**\r
+  Complete the current request\r
+\r
+  This routine is called at TPL_I2C_SYNC.\r
+\r
+  @param[in] I2cHostContext  Address of an I2C_HOST_CONTEXT structure.\r
+  @param[in] Status          Status of the I2C operation.\r
+\r
+  @return This routine returns the input status value.\r
+\r
+**/\r
+EFI_STATUS\r
+I2cHostRequestComplete (\r
+  I2C_HOST_CONTEXT *I2cHostContext,\r
+  EFI_STATUS       Status\r
+  )\r
+{\r
+  I2C_REQUEST *I2cRequest;\r
+  LIST_ENTRY  *EntryHeader;\r
+  LIST_ENTRY  *Entry;\r
+\r
+  //\r
+  // Remove the current I2C request from the list\r
+  //\r
+  EntryHeader = &I2cHostContext->RequestList;\r
+  Entry = GetFirstNode (EntryHeader);\r
+  I2cRequest = I2C_REQUEST_FROM_ENTRY (Entry);\r
+\r
+  //\r
+  // Save the status for QueueRequest\r
+  //\r
+  if ( NULL != I2cRequest->Status ) {\r
+    *I2cRequest->Status = Status;\r
+  }\r
+\r
+  //\r
+  //  Notify the user of the I2C request completion\r
+  //\r
+  if ( NULL != I2cRequest->Event ) {\r
+    gBS->SignalEvent (I2cRequest->Event);\r
+  }\r
+\r
+  //\r
+  // Done with this request, remove the current request from list\r
+  //\r
+  RemoveEntryList (&I2cRequest->Link);\r
+  FreePool (I2cRequest->RequestPacket);\r
+  FreePool (I2cRequest);\r
+\r
+  //\r
+  // If there is more I2C request, start next one\r
+  //\r
+  if(!IsListEmpty (EntryHeader)) {\r
+    I2cHostRequestEnable (I2cHostContext);\r
+  }\r
+  \r
+  return Status;\r
+}\r
+\r
+/**\r
+  Handle the bus available event\r
+\r
+  This routine is called at TPL_I2C_SYNC.\r
+\r
+  @param[in] Event    Address of an EFI_EVENT handle\r
+  @param[in] Context  Address of an I2C_HOST_CONTEXT structure\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+I2cHostRequestCompleteEvent (\r
+  IN EFI_EVENT Event,\r
+  IN VOID *Context\r
+  )\r
+{\r
+  I2C_HOST_CONTEXT *I2cHostContext;\r
+\r
+  //\r
+  // Handle the completion event\r
+  //\r
+  I2cHostContext = (I2C_HOST_CONTEXT *)Context;\r
+  I2cHostRequestComplete (I2cHostContext, I2cHostContext->Status);\r
+}\r
+\r
+/**\r
+  Enable access to the I2C bus configuration\r
+\r
+  @param[in] I2cHostContext     Address of an I2C_HOST_CONTEXT structure\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_ABORTED           The request did not complete because the driver\r
+                                was shutdown.\r
+  @retval EFI_BAD_BUFFER_SIZE   The WriteBytes or ReadBytes buffer size is too large.\r
+  @retval EFI_DEVICE_ERROR      There was an I2C error (NACK) during the operation.\r
+                                This could indicate the slave device is not present.\r
+  @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
+  @retval EFI_NO_MAPPING        Invalid I2cBusConfiguration value\r
+  @retval EFI_NO_RESPONSE       The I2C device is not responding to the\r
+                                slave address.  EFI_DEVICE_ERROR may also be\r
+                                returned if the controller can not distinguish\r
+                                when the NACK occurred.\r
+  @retval EFI_NOT_FOUND         I2C slave address exceeds maximum address\r
+  @retval EFI_NOT_READY         I2C bus is busy or operation pending, wait for\r
+                                the event and then read status.\r
+  @retval EFI_OUT_OF_RESOURCES  Insufficient memory for I2C operation\r
+  @retval EFI_TIMEOUT           The transaction did not complete within an internally\r
+                                specified timeout period.\r
+\r
+**/\r
+EFI_STATUS\r
+I2cHostRequestEnable (\r
+  I2C_HOST_CONTEXT *I2cHostContext\r
+  )\r
+{\r
+  UINTN                                                 I2cBusConfiguration;\r
+  CONST EFI_I2C_BUS_CONFIGURATION_MANAGEMENT_PROTOCOL   *I2cBusConfigurationManagement;\r
+  I2C_REQUEST                                           *I2cRequest;\r
+  EFI_STATUS                                            Status;\r
+  EFI_TPL                                               TplPrevious;\r
+  LIST_ENTRY                                            *EntryHeader;\r
+  LIST_ENTRY                                            *Entry;\r
+\r
+  //\r
+  //  Assume pending request\r
+  //\r
+  Status = EFI_NOT_READY;\r
+\r
+  I2cBusConfigurationManagement = I2cHostContext->I2cBusConfigurationManagement;\r
+\r
+  //\r
+  //  Validate the I2c bus configuration\r
+  //\r
+  EntryHeader = &I2cHostContext->RequestList;\r
+  Entry       = GetFirstNode (EntryHeader);\r
+  I2cRequest = I2C_REQUEST_FROM_ENTRY (Entry);\r
+\r
+  I2cBusConfiguration = I2cRequest->I2cBusConfiguration;\r
+\r
+  if (I2cHostContext->I2cBusConfiguration != I2cBusConfiguration ) {\r
+    //\r
+    // Set flag to indicate I2C bus configuration is in progress\r
+    //\r
+    I2cHostContext->I2cBusConfigurationManagementPending = TRUE;\r
+    //\r
+    //  Update bus configuration for this device's requesting bus configuration\r
+    //\r
+    Status = I2cBusConfigurationManagement->EnableI2cBusConfiguration (\r
+                I2cBusConfigurationManagement,\r
+                I2cBusConfiguration,\r
+                I2cHostContext->I2cBusConfigurationEvent,\r
+                &I2cHostContext->Status\r
+                );\r
+  } else {\r
+    //\r
+    //  I2C bus configuration is same, no need change configuration and start I2c transaction directly\r
+    //\r
+    TplPrevious = gBS->RaiseTPL ( TPL_I2C_SYNC );\r
+\r
+    //\r
+    //  Same I2C bus configuration\r
+    //\r
+    I2cHostContext->Status = EFI_SUCCESS;\r
+    I2cHostI2cBusConfigurationAvailable (I2cHostContext->I2cBusConfigurationEvent, I2cHostContext);\r
+\r
+    //\r
+    //  Release the thread synchronization\r
+    //\r
+    gBS->RestoreTPL ( TplPrevious );\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Queue an I2C operation for execution on the I2C controller.\r
+\r
+  This routine must be called at or below TPL_NOTIFY.  For synchronous\r
+  requests this routine must be called at or below TPL_CALLBACK.\r
+\r
+  N.B. The typical consumers of this API are the I2C bus driver and\r
+  on rare occasions the I2C test application.  Extreme care must be\r
+  taken by other consumers of this API to prevent confusing the\r
+  third party I2C drivers due to a state change at the I2C device\r
+  which the third party I2C drivers did not initiate.  I2C platform\r
+  drivers may use this API within these guidelines.\r
+\r
+  This layer uses the concept of I2C bus configurations to describe\r
+  the I2C bus.  An I2C bus configuration is defined as a unique\r
+  setting of the multiplexers and switches in the I2C bus which\r
+  enable access to one or more I2C devices.  When using a switch\r
+  to divide a bus, due to speed differences, the I2C platform layer\r
+  would define an I2C bus configuration for the I2C devices on each\r
+  side of the switch.  When using a multiplexer, the I2C platform\r
+  layer defines an I2C bus configuration for each of the selector\r
+  values required to control the multiplexer.  See Figure 1 in the\r
+  <a href="http://www.nxp.com/documents/user_manual/UM10204.pdf">I<sup>2</sup>C\r
+  Specification</a> for a complex I2C bus configuration.\r
+\r
+  The I2C host driver processes all operations in FIFO order.  Prior to\r
+  performing the operation, the I2C host driver calls the I2C platform\r
+  driver to reconfigure the switches and multiplexers in the I2C bus\r
+  enabling access to the specified I2C device.  The I2C platform driver\r
+  also selects the maximum bus speed for the device.  After the I2C bus\r
+  is configured, the I2C host driver calls the I2C port driver to\r
+  initialize the I2C controller and start the I2C operation.\r
+\r
+  @param[in] This             Address of an EFI_I2C_HOST_PROTOCOL instance.\r
+  @param[in] I2cBusConfiguration  I2C bus configuration to access the I2C\r
+                                  device.\r
+  @param[in] SlaveAddress     Address of the device on the I2C bus.\r
+  @param[in] Event            Event to set for asynchronous operations,\r
+                              NULL for synchronous operations\r
+  @param[in] RequestPacket    Address of an EFI_I2C_REQUEST_PACKET\r
+                              structure describing the I2C operation\r
+  @param[out] I2cStatus       Optional buffer to receive the I2C operation\r
+                              completion status\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_ABORTED           The request did not complete because the driver\r
+                                was shutdown.\r
+  @retval EFI_BAD_BUFFER_SIZE   The WriteBytes or ReadBytes buffer size is too large.\r
+  @retval EFI_DEVICE_ERROR      There was an I2C error (NACK) during the operation.\r
+                                This could indicate the slave device is not present.\r
+  @retval EFI_INVALID_PARAMETER RequestPacket is NULL\r
+  @retval EFI_INVALID_PARAMETER TPL is too high\r
+  @retval EFI_NO_MAPPING        Invalid I2cBusConfiguration value\r
+  @retval EFI_NO_RESPONSE       The I2C device is not responding to the\r
+                                slave address.  EFI_DEVICE_ERROR may also be\r
+                                returned if the controller can not distinguish\r
+                                when the NACK occurred.\r
+  @retval EFI_NOT_FOUND         I2C slave address exceeds maximum address\r
+  @retval EFI_NOT_READY         I2C bus is busy or operation pending, wait for\r
+                                the event and then read status pointed to by\r
+                                the request packet.\r
+  @retval EFI_OUT_OF_RESOURCES  Insufficient memory for I2C operation\r
+  @retval EFI_TIMEOUT           The transaction did not complete within an internally\r
+                                specified timeout period.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostQueueRequest (\r
+  IN CONST EFI_I2C_HOST_PROTOCOL  *This,\r
+  IN UINTN                        I2cBusConfiguration,\r
+  IN UINTN                        SlaveAddress,\r
+  IN EFI_EVENT                    Event            OPTIONAL,\r
+  IN EFI_I2C_REQUEST_PACKET       *RequestPacket,\r
+  OUT EFI_STATUS                  *I2cStatus       OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  EFI_EVENT         SyncEvent;\r
+  EFI_TPL           TplPrevious;\r
+  I2C_REQUEST       *I2cRequest;\r
+  I2C_HOST_CONTEXT  *I2cHostContext;\r
+  BOOLEAN           FirstRequest;\r
+  UINTN             RequestPacketSize;\r
+\r
+  SyncEvent    = NULL;\r
+  FirstRequest = FALSE;\r
+  Status       = EFI_SUCCESS;\r
+\r
+  if (RequestPacket == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  I2cHostContext = I2C_HOST_CONTEXT_FROM_PROTOCOL (This);\r
+\r
+  if (Event == NULL) {\r
+    //\r
+    // For synchronous transaction, register an event used to wait for finishing synchronous transaction\r
+    //\r
+    Status = gBS->CreateEvent ( \r
+                0,\r
+                TPL_I2C_SYNC,\r
+                NULL,\r
+                NULL,\r
+                &SyncEvent\r
+                );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
\r
+  //\r
+  // TPL should be at or below TPL_NOTIFY.\r
+  // For synchronous requests this routine must be called at or below TPL_CALLBACK.\r
+  //\r
+  TplPrevious = EfiGetCurrentTpl ();\r
+  if ((TplPrevious > TPL_I2C_SYNC) || ((Event == NULL) && (TplPrevious > TPL_CALLBACK))) {\r
+    DEBUG ((EFI_D_ERROR, "ERROR - TPL %d is too high!\n", TplPrevious));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Allocate the request structure\r
+  //\r
+  I2cRequest = AllocateZeroPool (sizeof (I2C_REQUEST));\r
+  if (I2cRequest == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "WARNING - Failed to allocate I2C_REQUEST!\n"));\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Initialize the request\r
+  //\r
+  I2cRequest->Signature           = I2C_REQUEST_SIGNATURE;\r
+  I2cRequest->I2cBusConfiguration = I2cBusConfiguration;\r
+  I2cRequest->SlaveAddress        = SlaveAddress;\r
+  I2cRequest->Event               = (Event == NULL) ? SyncEvent : Event;\r
+  I2cRequest->Status              = I2cStatus;\r
+\r
+  //\r
+  // Copy request packet into private buffer, as RequestPacket may be freed during asynchronous transaction\r
+  //\r
+  RequestPacketSize = sizeof (UINTN) + RequestPacket->OperationCount * sizeof (EFI_I2C_OPERATION);\r
+  I2cRequest->RequestPacket = AllocateZeroPool (RequestPacketSize);\r
+  CopyMem (I2cRequest->RequestPacket, RequestPacket, RequestPacketSize);\r
+\r
+  //\r
+  // Synchronize with the other threads\r
+  //\r
+  gBS->RaiseTPL ( TPL_I2C_SYNC );\r
+  \r
+  FirstRequest = IsListEmpty (&I2cHostContext->RequestList);\r
+  \r
+  //\r
+  // Insert new I2C request in the list\r
+  //\r
+  InsertTailList (&I2cHostContext->RequestList, &I2cRequest->Link);\r
+\r
+  //\r
+  // Release the thread synchronization\r
+  //\r
+  gBS->RestoreTPL (TplPrevious);\r
+  \r
+  if (FirstRequest) {\r
+    //\r
+    // Start the first I2C request, then the subsequent of I2C request will continue\r
+    //\r
+    Status = I2cHostRequestEnable (I2cHostContext);\r
+  }\r
+\r
+  if (Event != NULL) {\r
+    //\r
+    // For asynchronous, return EFI_SUCCESS indicating that the asynchronously I2C transaction was queued.\r
+    // No real I2C operation status in I2cStatus\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // For synchronous transaction, wait for the operation completion\r
+  //\r
+  do {\r
+    Status = gBS->CheckEvent (SyncEvent);\r
+  } while (Status == EFI_NOT_READY);\r
+\r
+  //\r
+  // Get the I2C operation status\r
+  //\r
+  Status = I2cHostContext->Status;\r
+\r
+  //\r
+  // Return the I2C operation status\r
+  //\r
+  if (I2cStatus != NULL) {\r
+    *I2cStatus = Status;\r
+  }\r
+\r
+  //\r
+  // Close the event if necessary\r
+  //\r
+  if (SyncEvent != NULL) {\r
+    gBS->CloseEvent (SyncEvent);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  The user Entry Point for I2C host module. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeI2cHost(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gI2cHostDriverBinding,\r
+             ImageHandle,\r
+             &gI2cHostComponentName,\r
+             &gI2cHostComponentName2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This is the unload handle for I2C host module.\r
+\r
+  Disconnect the driver specified by ImageHandle from all the devices in the handle database.\r
+  Uninstall all the protocols installed in the driver entry point.\r
+\r
+  @param[in] ImageHandle           The drivers' driver image.\r
+\r
+  @retval    EFI_SUCCESS           The image is unloaded.\r
+  @retval    Others                Failed to unload the image.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+I2cHostUnload (\r
+  IN EFI_HANDLE             ImageHandle\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_HANDLE                        *DeviceHandleBuffer;\r
+  UINTN                             DeviceHandleCount;\r
+  UINTN                             Index;\r
+\r
+  //\r
+  // Get the list of all I2C Controller handles in the handle database.\r
+  // If there is an error getting the list, then the unload\r
+  // operation fails.\r
+  //\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gEfiI2cHostProtocolGuid,\r
+                  NULL,\r
+                  &DeviceHandleCount,\r
+                  &DeviceHandleBuffer\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Disconnect the driver specified by ImageHandle from all\r
+  // the devices in the handle database.\r
+  //\r
+  for (Index = 0; Index < DeviceHandleCount; Index++) {\r
+    Status = gBS->DisconnectController (\r
+                    DeviceHandleBuffer[Index],\r
+                    ImageHandle,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Uninstall all the protocols installed in the driver entry point\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  gI2cHostDriverBinding.DriverBindingHandle,\r
+                  &gEfiDriverBindingProtocolGuid,\r
+                  &gI2cHostDriverBinding,\r
+                  &gEfiComponentNameProtocolGuid,\r
+                  &gI2cHostComponentName,\r
+                  &gEfiComponentName2ProtocolGuid,\r
+                  &gI2cHostComponentName2,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+Done:\r
+  //\r
+  // Free the buffer containing the list of handles from the handle database\r
+  //\r
+  if (DeviceHandleBuffer != NULL) {\r
+    gBS->FreePool (DeviceHandleBuffer);\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/MdeModulePkg/Bus/I2c/I2cDxe/I2cHostDxe.inf b/MdeModulePkg/Bus/I2c/I2cDxe/I2cHostDxe.inf
new file mode 100644 (file)
index 0000000..ebd9fca
--- /dev/null
@@ -0,0 +1,53 @@
+## @file\r
+#  This driver produce I2C Host Protocol on I2C controller handle.\r
+#\r
+#  Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = I2cHostDxe\r
+  FILE_GUID                      = CDEC3671-816E-43DC-A002-DCD645229338\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = InitializeI2cHost\r
+  UNLOAD_IMAGE                   = I2cHostUnload\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  I2cDxe.h\r
+  I2cHost.c\r
+\r
+[LibraryClasses]\r
+  BaseMemoryLib\r
+  DebugLib\r
+  DevicePathLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+[Protocols]\r
+  gEfiI2cIoProtocolGuid                             ## BY_START\r
+  gEfiI2cHostProtocolGuid                           ## BY_START\r
+  gEfiI2cMasterProtocolGuid                         ## TO_START\r
+  gEfiI2cEnumerateProtocolGuid                      ## TO_START\r
+  gEfiI2cBusConfigurationManagementProtocolGuid     ## TO_START\r
+  gEfiI2cHostProtocolGuid                           ## TO_START\r
index 2ff9dc5fae30f93cc09fbef89d5f0c2fe6de63a3..a2248697db38c0dd7bfb044f35ea9f3021e9f38c 100644 (file)
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf\r
   MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointerDxe.inf\r
   MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.inf\r
+  MdeModulePkg/Bus/I2c/I2cDxe/I2cBusDxe.inf\r
+  MdeModulePkg/Bus/I2c/I2cDxe/I2cHostDxe.inf\r
+  MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.inf\r
 \r
   MdeModulePkg/Core/Dxe/DxeMain.inf {\r
     <LibraryClasses>\r