]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiSmbusLibSmbus2/PeiSmbusLib.c
Add inf files for PeiSmbusLibSmbus2, PeiDxePostCodeLibReportStatusCode, PeiMemoryLib...
[mirror_edk2.git] / MdePkg / Library / PeiSmbusLibSmbus2 / PeiSmbusLib.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: PeiSmbusLib.c\r
15\r
16**/\r
17\r
dd51a993 18#include "InternalSmbusLib.h"\r
19\r
20/**\r
21 Gets Smbus PPIs.\r
22\r
23 This internal function retrieves Smbus PPI from PPI database.\r
24\r
25 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES published by the PEI Foundation.\r
26\r
27 @return The pointer to Smbus PPI.\r
28\r
29**/\r
30EFI_PEI_SMBUS2_PPI *\r
31InternalGetSmbusPpi (\r
32 EFI_PEI_SERVICES **PeiServices\r
bad46384 33 )\r
dd51a993 34{\r
35 EFI_STATUS Status;\r
36 EFI_PEI_SMBUS2_PPI *SmbusPpi;\r
37\r
38 Status = (*PeiServices)->LocatePpi (PeiServices, &gEfiPeiSmbus2PpiGuid, 0, NULL, (VOID **) &SmbusPpi);\r
39 ASSERT_EFI_ERROR (Status);\r
40 ASSERT (SmbusPpi != NULL);\r
41\r
42 return SmbusPpi;\r
43}\r
44\r
45/**\r
bad46384 46 Executes an SMBus operation to an SMBus controller.\r
dd51a993 47\r
48 This function provides a standard way to execute Smbus script\r
49 as defined in the SmBus Specification. The data can either be of\r
50 the Length byte, word, or a block of data.\r
51\r
52 @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to\r
53 execute the SMBus transactions.\r
54 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
55 SMBUS Command, SMBUS Data Length, and PEC.\r
56 @param Length Signifies the number of bytes that this operation will do. The maximum number of\r
57 bytes can be revision specific and operation specific.\r
58 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations\r
59 require this argument. The length of this buffer is identified by Length.\r
60 @param Status Return status for the executed command.\r
61 This is an optional parameter and may be NULL.\r
62\r
63 @return The actual number of bytes that are executed for this operation..\r
64\r
65**/\r
66UINTN\r
67InternalSmBusExec (\r
68 IN EFI_SMBUS_OPERATION SmbusOperation,\r
69 IN UINTN SmBusAddress,\r
70 IN UINTN Length,\r
71 IN OUT VOID *Buffer,\r
72 OUT RETURN_STATUS *Status OPTIONAL\r
73 )\r
74{\r
75 EFI_PEI_SMBUS2_PPI *SmbusPpi;\r
76 EFI_PEI_SERVICES **PeiServices;\r
77 RETURN_STATUS ReturnStatus;\r
78 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;\r
79\r
80 PeiServices = GetPeiServicesTablePointer ();\r
81 SmbusPpi = InternalGetSmbusPpi (PeiServices);\r
82 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);\r
83\r
84 ReturnStatus = SmbusPpi->Execute (\r
85 SmbusPpi,\r
86 SmbusDeviceAddress,\r
87 SMBUS_LIB_COMMAND (SmBusAddress),\r
88 SmbusOperation,\r
bad46384 89 SMBUS_LIB_PEC (SmBusAddress),\r
dd51a993 90 &Length,\r
91 Buffer\r
92 );\r
93 if (Status != NULL) {\r
94 *Status = ReturnStatus;\r
95 }\r
96\r
97 return Length;\r
98}\r