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