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