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 PeiSmbusLib.c 16 17 Abstract: 18 19 PEI Smbus Lib internal functions 20 21 --*/ 22 23 #include "PeiSmbusLibInternal.h" 24 25 /** 26 Gets Smbus PPIs. 27 28 This internal function retrieves Smbus PPI from PPI database. 29 30 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES published by the PEI Foundation. 31 32 @return The pointer to Smbus PPI. 33 34 **/ 35 EFI_PEI_SMBUS_PPI * 36 InternalGetSmbusPpi ( 37 EFI_PEI_SERVICES **PeiServices 38 ) 39 { 40 EFI_STATUS Status; 41 EFI_PEI_SMBUS_PPI *SmbusPpi; 42 43 Status = (*PeiServices)->LocatePpi (PeiServices, &gEfiPeiSmbusPpiGuid, 0, NULL, (VOID **) &SmbusPpi); 44 ASSERT_EFI_ERROR (Status); 45 ASSERT (SmbusPpi != NULL); 46 47 return SmbusPpi; 48 } 49 50 /** 51 Executes an SMBus operation to an SMBus controller. 52 53 This function provides a standard way to execute Smbus script 54 as defined in the SmBus Specification. The data can either be of 55 the Length byte, word, or a block of data. 56 57 @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to 58 execute the SMBus transactions. 59 @param SmBusAddress Address that encodes the SMBUS Slave Address, 60 SMBUS Command, SMBUS Data Length, and PEC. 61 @param Length Signifies the number of bytes that this operation will do. The maximum number of 62 bytes can be revision specific and operation specific. 63 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations 64 require this argument. The length of this buffer is identified by Length. 65 @param Status Return status for the executed command. 66 This is an optional parameter and may be NULL. 67 68 @return The actual number of bytes that are executed for this operation.. 69 70 **/ 71 UINTN 72 InternalSmBusExec ( 73 IN EFI_SMBUS_OPERATION SmbusOperation, 74 IN UINTN SmBusAddress, 75 IN UINTN Length, 76 IN OUT VOID *Buffer, 77 OUT RETURN_STATUS *Status OPTIONAL 78 ) 79 { 80 EFI_PEI_SMBUS_PPI *SmbusPpi; 81 EFI_PEI_SERVICES **PeiServices; 82 RETURN_STATUS ReturnStatus; 83 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress; 84 85 PeiServices = GetPeiServicesTablePointer (); 86 SmbusPpi = InternalGetSmbusPpi (PeiServices); 87 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress); 88 89 ReturnStatus = SmbusPpi->Execute ( 90 PeiServices, 91 SmbusPpi, 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