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