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