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