]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkPkg/Library/PeiSmbusLibSmbusPpi/PeiSmbusLib.c
IntelFrameworkPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkPkg / Library / PeiSmbusLibSmbusPpi / PeiSmbusLib.c
CommitLineData
a67d1f18 1/** @file\r
b2cefd7c 2 Implementation of SmBusLib class library for PEI phase.\r
a67d1f18 3\r
1c2f052d 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
22a69a5e 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
a67d1f18 6\r
a67d1f18 7**/\r
8\r
9#include "InternalSmbusLib.h"\r
10\r
11/**\r
12 Gets Smbus PPIs.\r
13\r
14 This internal function retrieves Smbus PPI from PPI database.\r
b2cefd7c 15 If gEfiPeiSmbusPpiGuid can not be located, then ASSERT()\r
1c2f052d 16\r
a67d1f18 17 @return The pointer to Smbus PPI.\r
18\r
19**/\r
20EFI_PEI_SMBUS_PPI *\r
21InternalGetSmbusPpi (\r
22936e95 22 VOID\r
1c2f052d 23 )\r
a67d1f18 24{\r
25 EFI_STATUS Status;\r
26 EFI_PEI_SMBUS_PPI *SmbusPpi;\r
27\r
22936e95 28 Status = PeiServicesLocatePpi (&gEfiPeiSmbusPpiGuid, 0, NULL, (VOID **) &SmbusPpi);\r
a67d1f18 29 ASSERT_EFI_ERROR (Status);\r
30 ASSERT (SmbusPpi != NULL);\r
31\r
32 return SmbusPpi;\r
33}\r
34\r
35/**\r
1c2f052d 36 Executes an SMBus operation to an SMBus controller.\r
a67d1f18 37\r
38 This function provides a standard way to execute Smbus script\r
39 as defined in the SmBus Specification. The data can either be of\r
40 the Length byte, word, or a block of data.\r
41\r
42 @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to\r
43 execute the SMBus transactions.\r
44 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
45 SMBUS Command, SMBUS Data Length, and PEC.\r
46 @param Length Signifies the number of bytes that this operation will do. The maximum number of\r
47 bytes can be revision specific and operation specific.\r
48 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations\r
49 require this argument. The length of this buffer is identified by Length.\r
50 @param Status Return status for the executed command.\r
51 This is an optional parameter and may be NULL.\r
52\r
53 @return The actual number of bytes that are executed for this operation..\r
54\r
55**/\r
56UINTN\r
57InternalSmBusExec (\r
58 IN EFI_SMBUS_OPERATION SmbusOperation,\r
59 IN UINTN SmBusAddress,\r
60 IN UINTN Length,\r
61 IN OUT VOID *Buffer,\r
62 OUT RETURN_STATUS *Status OPTIONAL\r
63 )\r
64{\r
65 EFI_PEI_SMBUS_PPI *SmbusPpi;\r
0c39efcc 66 CONST EFI_PEI_SERVICES **PeiServices;\r
a67d1f18 67 RETURN_STATUS ReturnStatus;\r
68 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;\r
69\r
70 PeiServices = GetPeiServicesTablePointer ();\r
22936e95 71 SmbusPpi = InternalGetSmbusPpi ();\r
a67d1f18 72 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);\r
73\r
74 ReturnStatus = SmbusPpi->Execute (\r
0c39efcc 75 (EFI_PEI_SERVICES **) PeiServices,\r
a67d1f18 76 SmbusPpi,\r
77 SmbusDeviceAddress,\r
78 SMBUS_LIB_COMMAND (SmBusAddress),\r
79 SmbusOperation,\r
1c2f052d 80 SMBUS_LIB_PEC (SmBusAddress),\r
a67d1f18 81 &Length,\r
82 Buffer\r
83 );\r
84 if (Status != NULL) {\r
85 *Status = ReturnStatus;\r
86 }\r
87\r
88 return Length;\r
89}\r