]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeSmbusLib/DxeSmbusLib.c
37cf17937f92bb3ce05eae574173916d6a44fd1a
[mirror_edk2.git] / MdePkg / Library / DxeSmbusLib / DxeSmbusLib.c
1 /** @file
2 Implementation of SmBusLib class library for DXE phase.
3
4 Copyright (c) 2006 - 2008, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13
14 **/
15
16
17 #include "InternalSmbusLib.h"
18
19
20 //
21 // Globle varible to cache pointer to Smbus protocol.
22 //
23 EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL;
24
25 /**
26 The constructor function caches the pointer to Smbus protocol.
27
28 The constructor function locates Smbus protocol from protocol database.
29 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
30
31 @param ImageHandle The firmware allocated handle for the EFI image.
32 @param SystemTable A pointer to the EFI System Table.
33
34 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
35
36 **/
37 EFI_STATUS
38 EFIAPI
39 SmbusLibConstructor (
40 IN EFI_HANDLE ImageHandle,
41 IN EFI_SYSTEM_TABLE *SystemTable
42 )
43 {
44 EFI_STATUS Status;
45
46 Status = gBS->LocateProtocol (&gEfiSmbusHcProtocolGuid, NULL, (VOID**) &mSmbus);
47 ASSERT_EFI_ERROR (Status);
48 ASSERT (mSmbus != NULL);
49
50 return Status;
51 }
52
53 /**
54 Executes an SMBus operation to an SMBus controller.
55
56 This function provides a standard way to execute Smbus script
57 as defined in the SmBus Specification. The data can either be of
58 the Length byte, word, or a block of data.
59
60 @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to
61 execute the SMBus transactions.
62 @param SmBusAddress Address that encodes the SMBUS Slave Address,
63 SMBUS Command, SMBUS Data Length, and PEC.
64 @param Length Signifies the number of bytes that this operation will do. The maximum number of
65 bytes can be revision specific and operation specific.
66 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations
67 require this argument. The length of this buffer is identified by Length.
68 @param Status Return status for the executed command.
69 This is an optional parameter and may be NULL.
70
71 @return The actual number of bytes that are executed for this operation.
72
73 **/
74 UINTN
75 InternalSmBusExec (
76 IN EFI_SMBUS_OPERATION SmbusOperation,
77 IN UINTN SmBusAddress,
78 IN UINTN Length,
79 IN OUT VOID *Buffer,
80 OUT RETURN_STATUS *Status OPTIONAL
81 )
82 {
83 RETURN_STATUS ReturnStatus;
84 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
85
86 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
87
88 ReturnStatus = mSmbus->Execute (
89 mSmbus,
90 SmbusDeviceAddress,
91 SMBUS_LIB_COMMAND (SmBusAddress),
92 SmbusOperation,
93 SMBUS_LIB_PEC (SmBusAddress),
94 &Length,
95 Buffer
96 );
97 if (Status != NULL) {
98 *Status = ReturnStatus;
99 }
100
101 return Length;
102 }