]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/DxeSmbusLib/DxeSmbusLib.c
Add inf files for PeiSmbusLibSmbus2, PeiDxePostCodeLibReportStatusCode, PeiMemoryLib...
[mirror_edk2.git] / MdePkg / Library / DxeSmbusLib / DxeSmbusLib.c
CommitLineData
dd51a993 1/** @file\r
2Implementation of SmBusLib class library for PEI phase.\r
3\r
4Copyright (c) 2006, Intel Corporation<BR>\r
bad46384 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
dd51a993 12\r
13\r
14Module Name: DxeSmbusLib.c\r
15\r
16**/\r
17\r
bad46384 18\r
dd51a993 19#include "InternalSmbusLib.h"\r
20\r
dd51a993 21\r
22//\r
23// Globle varible to cache pointer to Smbus protocol.\r
24//\r
bad46384 25STATIC EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL;\r
dd51a993 26\r
27/**\r
28 The constructor function caches the pointer to Smbus protocol.\r
bad46384 29\r
dd51a993 30 The constructor function locates Smbus protocol from protocol database.\r
bad46384 31 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.\r
dd51a993 32\r
33 @param ImageHandle The firmware allocated handle for the EFI image.\r
34 @param SystemTable A pointer to the EFI System Table.\r
bad46384 35\r
dd51a993 36 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
37\r
38**/\r
39EFI_STATUS\r
40EFIAPI\r
41SmbusLibConstructor (\r
42 IN EFI_HANDLE ImageHandle,\r
43 IN EFI_SYSTEM_TABLE *SystemTable\r
44 )\r
45{\r
46 EFI_STATUS Status;\r
bad46384 47\r
dd51a993 48 Status = gBS->LocateProtocol (&gEfiSmbusHcProtocolGuid, NULL, (VOID**) &mSmbus);\r
49 ASSERT_EFI_ERROR (Status);\r
50 ASSERT (mSmbus != NULL);\r
51\r
52 return Status;\r
53}\r
54\r
55/**\r
bad46384 56 Executes an SMBus operation to an SMBus controller.\r
dd51a993 57\r
58 This function provides a standard way to execute Smbus script\r
59 as defined in the SmBus Specification. The data can either be of\r
60 the Length byte, word, or a block of data.\r
61\r
62 @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to\r
63 execute the SMBus transactions.\r
64 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
65 SMBUS Command, SMBUS Data Length, and PEC.\r
66 @param Length Signifies the number of bytes that this operation will do. The maximum number of\r
67 bytes can be revision specific and operation specific.\r
68 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations\r
69 require this argument. The length of this buffer is identified by Length.\r
70 @param Status Return status for the executed command.\r
71 This is an optional parameter and may be NULL.\r
72\r
73 @return The actual number of bytes that are executed for this operation..\r
74\r
75**/\r
76UINTN\r
77InternalSmBusExec (\r
78 IN EFI_SMBUS_OPERATION SmbusOperation,\r
79 IN UINTN SmBusAddress,\r
80 IN UINTN Length,\r
81 IN OUT VOID *Buffer,\r
82 OUT RETURN_STATUS *Status OPTIONAL\r
83 )\r
84{\r
85 RETURN_STATUS ReturnStatus;\r
86 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;\r
87\r
88 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);\r
89\r
90 ReturnStatus = mSmbus->Execute (\r
91 mSmbus,\r
92 SmbusDeviceAddress,\r
93 SMBUS_LIB_COMMAND (SmBusAddress),\r
94 SmbusOperation,\r
bad46384 95 SMBUS_LIB_PEC (SmBusAddress),\r
dd51a993 96 &Length,\r
97 Buffer\r
98 );\r
99 if (Status != NULL) {\r
100 *Status = ReturnStatus;\r
101 }\r
102\r
103 return Length;\r
104}\r