]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiSmbusLibSmbus2Ppi/PeiSmbusLib.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / PeiSmbusLibSmbus2Ppi / PeiSmbusLib.c
CommitLineData
dd51a993 1/** @file\r
2Implementation of SmBusLib class library for PEI phase.\r
3\r
9095d37b 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
dd51a993 6\r
dd51a993 7**/\r
8\r
dd51a993 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
15\r
f38fdc74 16 @param VOID\r
dd51a993 17\r
18 @return The pointer to Smbus PPI.\r
19\r
20**/\r
21EFI_PEI_SMBUS2_PPI *\r
22InternalGetSmbusPpi (\r
1c280088 23 VOID\r
bad46384 24 )\r
dd51a993 25{\r
26 EFI_STATUS Status;\r
27 EFI_PEI_SMBUS2_PPI *SmbusPpi;\r
28\r
1c280088 29 Status = PeiServicesLocatePpi (&gEfiPeiSmbus2PpiGuid, 0, NULL, (VOID **) &SmbusPpi);\r
dd51a993 30 ASSERT_EFI_ERROR (Status);\r
31 ASSERT (SmbusPpi != NULL);\r
32\r
33 return SmbusPpi;\r
34}\r
35\r
36/**\r
bad46384 37 Executes an SMBus operation to an SMBus controller.\r
dd51a993 38\r
39 This function provides a standard way to execute Smbus script\r
40 as defined in the SmBus Specification. The data can either be of\r
41 the Length byte, word, or a block of data.\r
42\r
9095d37b 43 @param SmbusOperation Signifies which particular SMBus hardware protocol instance\r
58380e9c 44 that it will use to execute the SMBus transactions.\r
2fc59a00 45 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
dd51a993 46 SMBUS Command, SMBUS Data Length, and PEC.\r
9095d37b
LG
47 @param Length Signifies the number of bytes that this operation will\r
48 do. The maximum number of bytes can be revision specific\r
58380e9c 49 and operation specific.\r
9095d37b
LG
50 @param Buffer Contains the value of data to execute to the SMBus slave\r
51 device. Not all operations require this argument. The\r
58380e9c 52 length of this buffer is identified by Length.\r
dd51a993 53 @param Status Return status for the executed command.\r
54 This is an optional parameter and may be NULL.\r
55\r
f38fdc74 56 @return The actual number of bytes that are executed for this operation.\r
dd51a993 57\r
58**/\r
59UINTN\r
60InternalSmBusExec (\r
61 IN EFI_SMBUS_OPERATION SmbusOperation,\r
62 IN UINTN SmBusAddress,\r
63 IN UINTN Length,\r
64 IN OUT VOID *Buffer,\r
65 OUT RETURN_STATUS *Status OPTIONAL\r
66 )\r
67{\r
68 EFI_PEI_SMBUS2_PPI *SmbusPpi;\r
dd51a993 69 RETURN_STATUS ReturnStatus;\r
70 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;\r
71\r
1c280088 72 SmbusPpi = InternalGetSmbusPpi ();\r
dd51a993 73 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);\r
74\r
75 ReturnStatus = SmbusPpi->Execute (\r
76 SmbusPpi,\r
77 SmbusDeviceAddress,\r
78 SMBUS_LIB_COMMAND (SmBusAddress),\r
79 SmbusOperation,\r
bad46384 80 SMBUS_LIB_PEC (SmBusAddress),\r
dd51a993 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