1 /** @file 2 Implementation of SmBusLib class library for DXE phase. 3 4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> 5 This program and the accompanying materials 6 are licensed and made available under the terms and conditions of the BSD License 7 which accompanies this distribution. The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php. 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13 14 **/ 15 16 17 #include "InternalSmbusLib.h" 18 19 20 // 21 // Globle varible to cache pointer to Smbus protocol. 22 // 23 EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL; 24 25 /** 26 The constructor function caches the pointer to Smbus protocol. 27 28 The constructor function locates Smbus protocol from protocol database. 29 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. 30 31 @param ImageHandle The firmware allocated handle for the EFI image. 32 @param SystemTable A pointer to the EFI System Table. 33 34 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. 35 36 **/ 37 EFI_STATUS 38 EFIAPI 39 SmbusLibConstructor ( 40 IN EFI_HANDLE ImageHandle, 41 IN EFI_SYSTEM_TABLE *SystemTable 42 ) 43 { 44 EFI_STATUS Status; 45 46 Status = gBS->LocateProtocol (&gEfiSmbusHcProtocolGuid, NULL, (VOID**) &mSmbus); 47 ASSERT_EFI_ERROR (Status); 48 ASSERT (mSmbus != NULL); 49 50 return Status; 51 } 52 53 /** 54 Executes an SMBus operation to an SMBus controller. 55 56 This function provides a standard way to execute Smbus script 57 as defined in the SmBus Specification. The data can either be of 58 the Length byte, word, or a block of data. 59 60 @param SmbusOperation Signifies which particular SMBus hardware protocol instance 61 that it will use to execute the SMBus transactions. 62 @param SmBusAddress The address that encodes the SMBUS Slave Address, 63 SMBUS Command, SMBUS Data Length, and PEC. 64 @param Length Signifies the number of bytes that this operation will do. 65 The maximum number of bytes can be revision specific 66 and operation specific. 67 @param Buffer Contains the value of data to execute to the SMBus slave 68 device. Not all operations require this argument. The 69 length of this buffer is identified by Length. 70 @param Status Return status for the executed command. 71 This is an optional parameter and may be NULL. 72 73 @return The actual number of bytes that are executed for this operation. 74 75 **/ 76 UINTN 77 InternalSmBusExec ( 78 IN EFI_SMBUS_OPERATION SmbusOperation, 79 IN UINTN SmBusAddress, 80 IN UINTN Length, 81 IN OUT VOID *Buffer, 82 OUT RETURN_STATUS *Status OPTIONAL 83 ) 84 { 85 RETURN_STATUS ReturnStatus; 86 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress; 87 88 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress); 89 90 ReturnStatus = mSmbus->Execute ( 91 mSmbus, 92 SmbusDeviceAddress, 93 SMBUS_LIB_COMMAND (SmBusAddress), 94 SmbusOperation, 95 SMBUS_LIB_PEC (SmBusAddress), 96 &Length, 97 Buffer 98 ); 99 if (Status != NULL) { 100 *Status = ReturnStatus; 101 } 102 103 return Length; 104 } 105