blob: 5821e9bb6d8066acaf7e9931c927ae946214e211 [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/** @file
2Implementation of SmBusLib class library for PEI phase.
3
4Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5This program and the accompanying materials
6are licensed and made available under the terms and conditions of the BSD License
7which accompanies this distribution. The full text of the license may be found at
8http://opensource.org/licenses/bsd-license.php
9
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11WITHOUT 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
22 @param VOID
23
24 @return The pointer to Smbus PPI.
25
26**/
27EFI_PEI_SMBUS2_PPI *
28InternalGetSmbusPpi (
29 VOID
30 )
31{
32 EFI_STATUS Status;
33 EFI_PEI_SMBUS2_PPI *SmbusPpi;
34
35 Status = PeiServicesLocatePpi (&gEfiPeiSmbus2PpiGuid, 0, NULL, (VOID **) &SmbusPpi);
36 ASSERT_EFI_ERROR (Status);
37 ASSERT (SmbusPpi != NULL);
38
39 return SmbusPpi;
40}
41
42/**
43 Executes an SMBus operation to an SMBus controller.
44
45 This function provides a standard way to execute Smbus script
46 as defined in the SmBus Specification. The data can either be of
47 the Length byte, word, or a block of data.
48
49 @param SmbusOperation Signifies which particular SMBus hardware protocol instance
50 that it will use to execute the SMBus transactions.
51 @param SmBusAddress The address that encodes the SMBUS Slave Address,
52 SMBUS Command, SMBUS Data Length, and PEC.
53 @param Length Signifies the number of bytes that this operation will
54 do. The maximum number of bytes can be revision specific
55 and operation specific.
56 @param Buffer Contains the value of data to execute to the SMBus slave
57 device. Not all operations require this argument. The
58 length of this buffer is identified by Length.
59 @param Status Return status for the executed command.
60 This is an optional parameter and may be NULL.
61
62 @return The actual number of bytes that are executed for this operation.
63
64**/
65UINTN
66InternalSmBusExec (
67 IN EFI_SMBUS_OPERATION SmbusOperation,
68 IN UINTN SmBusAddress,
69 IN UINTN Length,
70 IN OUT VOID *Buffer,
71 OUT RETURN_STATUS *Status OPTIONAL
72 )
73{
74 EFI_PEI_SMBUS2_PPI *SmbusPpi;
75 RETURN_STATUS ReturnStatus;
76 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
77
78 SmbusPpi = InternalGetSmbusPpi ();
79 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
80
81 ReturnStatus = SmbusPpi->Execute (
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}