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