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