Add inf files for PeiSmbusLibSmbus2, PeiDxePostCodeLibReportStatusCode, PeiMemoryLib...
[mirror_edk2.git] / MdePkg / Library / DxeSmbusLib / DxeSmbusLib.c
1 /** @file
2 Implementation of SmBusLib class library for PEI phase.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. 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 Module Name: DxeSmbusLib.c
15
16 **/
17
18
19 #include "InternalSmbusLib.h"
20
21
22 //
23 // Globle varible to cache pointer to Smbus protocol.
24 //
25 STATIC EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL;
26
27 /**
28 The constructor function caches the pointer to Smbus protocol.
29
30 The constructor function locates Smbus protocol from protocol database.
31 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
32
33 @param ImageHandle The firmware allocated handle for the EFI image.
34 @param SystemTable A pointer to the EFI System Table.
35
36 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
37
38 **/
39 EFI_STATUS
40 EFIAPI
41 SmbusLibConstructor (
42 IN EFI_HANDLE ImageHandle,
43 IN EFI_SYSTEM_TABLE *SystemTable
44 )
45 {
46 EFI_STATUS Status;
47
48 Status = gBS->LocateProtocol (&gEfiSmbusHcProtocolGuid, NULL, (VOID**) &mSmbus);
49 ASSERT_EFI_ERROR (Status);
50 ASSERT (mSmbus != NULL);
51
52 return Status;
53 }
54
55 /**
56 Executes an SMBus operation to an SMBus controller.
57
58 This function provides a standard way to execute Smbus script
59 as defined in the SmBus Specification. The data can either be of
60 the Length byte, word, or a block of data.
61
62 @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to
63 execute the SMBus transactions.
64 @param SmBusAddress Address that encodes the SMBUS Slave Address,
65 SMBUS Command, SMBUS Data Length, and PEC.
66 @param Length Signifies the number of bytes that this operation will do. The maximum number of
67 bytes can be revision specific and operation specific.
68 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations
69 require this argument. The length of this buffer is identified by Length.
70 @param Status Return status for the executed command.
71 This is an optional parameter and may be NULL.
72
73 @return The actual number of bytes that are executed for this operation..
74
75 **/
76 UINTN
77 InternalSmBusExec (
78 IN EFI_SMBUS_OPERATION SmbusOperation,
79 IN UINTN SmBusAddress,
80 IN UINTN Length,
81 IN OUT VOID *Buffer,
82 OUT RETURN_STATUS *Status OPTIONAL
83 )
84 {
85 RETURN_STATUS ReturnStatus;
86 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
87
88 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
89
90 ReturnStatus = mSmbus->Execute (
91 mSmbus,
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 }