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