--- /dev/null
+/** @file\r
+Implementation of SmBusLib class library for PEI phase.\r
+\r
+Copyright (c) 2006, Intel Corporation<BR>\r
+All rights reserved. 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
+Module Name: DxeSmbusLib.c\r
+\r
+**/\r
+\r
+#include "InternalSmbusLib.h"\r
+\r
+//\r
+// Globle varible to cache pointer to Smbus protocol.\r
+//\r
+STATIC EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL; \r
+\r
+/**\r
+ The constructor function caches the pointer to Smbus protocol.\r
+ \r
+ The constructor function locates Smbus protocol from protocol database.\r
+ It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
+\r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
+ @param SystemTable A pointer to the EFI System Table.\r
+ \r
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmbusLibConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ \r
+ Status = gBS->LocateProtocol (&gEfiSmbusProtocolGuid, NULL, (VOID**) &mSmbus);\r
+ ASSERT_EFI_ERROR (Status);\r
+ ASSERT (mSmbus != NULL);\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Executes an SMBus operation to an SMBus controller. \r
+\r
+ This function provides a standard way to execute Smbus script\r
+ as defined in the SmBus Specification. The data can either be of\r
+ the Length byte, word, or a block of data.\r
+\r
+ @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to\r
+ execute the SMBus transactions.\r
+ @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
+ SMBUS Command, SMBUS Data Length, and PEC.\r
+ @param Length Signifies the number of bytes that this operation will do. The maximum number of\r
+ bytes can be revision specific and operation specific.\r
+ @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations\r
+ require this argument. The length of this buffer is identified by Length.\r
+ @param Status Return status for the executed command.\r
+ This is an optional parameter and may be NULL.\r
+\r
+ @return The actual number of bytes that are executed for this operation..\r
+\r
+**/\r
+UINTN\r
+InternalSmBusExec (\r
+ IN EFI_SMBUS_OPERATION SmbusOperation,\r
+ IN UINTN SmBusAddress,\r
+ IN UINTN Length,\r
+ IN OUT VOID *Buffer,\r
+ OUT RETURN_STATUS *Status OPTIONAL\r
+ )\r
+{\r
+ RETURN_STATUS ReturnStatus;\r
+ EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;\r
+\r
+ SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);\r
+\r
+ ReturnStatus = mSmbus->Execute (\r
+ mSmbus,\r
+ SmbusDeviceAddress,\r
+ SMBUS_LIB_COMMAND (SmBusAddress),\r
+ SmbusOperation,\r
+ SMBUS_LIB_PEC (SmBusAddress), \r
+ &Length,\r
+ Buffer\r
+ );\r
+ if (Status != NULL) {\r
+ *Status = ReturnStatus;\r
+ }\r
+\r
+ return Length;\r
+}\r