blob: 5517c4a4e11d32c8ac7ab5addc0dbe52c6ff30fe [file] [log] [blame]
yshang1dd51a992007-06-29 05:29:46 +00001/** @file
lgao4484c7782008-11-13 08:30:16 +00002Implementation of SmBusLib class library for DXE phase.
yshang1dd51a992007-06-29 05:29:46 +00003
4Copyright (c) 2006, Intel Corporation<BR>
vanjeffbad46382007-07-05 06:59:50 +00005All rights reserved. This 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.
yshang1dd51a992007-06-29 05:29:46 +000012
13
yshang1dd51a992007-06-29 05:29:46 +000014**/
15
vanjeffbad46382007-07-05 06:59:50 +000016
yshang1dd51a992007-06-29 05:29:46 +000017#include "InternalSmbusLib.h"
18
yshang1dd51a992007-06-29 05:29:46 +000019
20//
21// Globle varible to cache pointer to Smbus protocol.
22//
jji4fe467412008-10-30 05:58:52 +000023EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL;
yshang1dd51a992007-06-29 05:29:46 +000024
25/**
26 The constructor function caches the pointer to Smbus protocol.
vanjeffbad46382007-07-05 06:59:50 +000027
yshang1dd51a992007-06-29 05:29:46 +000028 The constructor function locates Smbus protocol from protocol database.
vanjeffbad46382007-07-05 06:59:50 +000029 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
yshang1dd51a992007-06-29 05:29:46 +000030
31 @param ImageHandle The firmware allocated handle for the EFI image.
32 @param SystemTable A pointer to the EFI System Table.
vanjeffbad46382007-07-05 06:59:50 +000033
yshang1dd51a992007-06-29 05:29:46 +000034 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
35
36**/
37EFI_STATUS
38EFIAPI
39SmbusLibConstructor (
40 IN EFI_HANDLE ImageHandle,
41 IN EFI_SYSTEM_TABLE *SystemTable
42 )
43{
44 EFI_STATUS Status;
vanjeffbad46382007-07-05 06:59:50 +000045
yshang1dd51a992007-06-29 05:29:46 +000046 Status = gBS->LocateProtocol (&gEfiSmbusHcProtocolGuid, NULL, (VOID**) &mSmbus);
47 ASSERT_EFI_ERROR (Status);
48 ASSERT (mSmbus != NULL);
49
50 return Status;
51}
52
53/**
vanjeffbad46382007-07-05 06:59:50 +000054 Executes an SMBus operation to an SMBus controller.
yshang1dd51a992007-06-29 05:29:46 +000055
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 that it will use to
61 execute the SMBus transactions.
62 @param SmBusAddress 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. The maximum number of
65 bytes can be revision specific and operation specific.
66 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations
67 require this argument. The length of this buffer is identified by Length.
68 @param Status Return status for the executed command.
69 This is an optional parameter and may be NULL.
70
71 @return The actual number of bytes that are executed for this operation..
72
73**/
74UINTN
75InternalSmBusExec (
76 IN EFI_SMBUS_OPERATION SmbusOperation,
77 IN UINTN SmBusAddress,
78 IN UINTN Length,
79 IN OUT VOID *Buffer,
80 OUT RETURN_STATUS *Status OPTIONAL
81 )
82{
83 RETURN_STATUS ReturnStatus;
84 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
85
86 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
87
88 ReturnStatus = mSmbus->Execute (
89 mSmbus,
90 SmbusDeviceAddress,
91 SMBUS_LIB_COMMAND (SmBusAddress),
92 SmbusOperation,
vanjeffbad46382007-07-05 06:59:50 +000093 SMBUS_LIB_PEC (SmBusAddress),
yshang1dd51a992007-06-29 05:29:46 +000094 &Length,
95 Buffer
96 );
97 if (Status != NULL) {
98 *Status = ReturnStatus;
99 }
100
101 return Length;
102}