]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Implementation of SmBusLib class library for DXE phase.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
7 | \r | |
8 | **/\r | |
9 | \r | |
10 | #include "InternalSmbusLib.h"\r | |
11 | \r | |
12 | //\r | |
13 | // Global variable to cache pointer to Smbus protocol.\r | |
14 | //\r | |
15 | EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL;\r | |
16 | \r | |
17 | /**\r | |
18 | The constructor function caches the pointer to Smbus protocol.\r | |
19 | \r | |
20 | The constructor function locates Smbus protocol from protocol database.\r | |
21 | It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.\r | |
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 | |
25 | \r | |
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 | |
32 | IN EFI_HANDLE ImageHandle,\r | |
33 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
34 | )\r | |
35 | {\r | |
36 | EFI_STATUS Status;\r | |
37 | \r | |
38 | Status = gBS->LocateProtocol (&gEfiSmbusHcProtocolGuid, NULL, (VOID **)&mSmbus);\r | |
39 | ASSERT_EFI_ERROR (Status);\r | |
40 | ASSERT (mSmbus != NULL);\r | |
41 | \r | |
42 | return Status;\r | |
43 | }\r | |
44 | \r | |
45 | /**\r | |
46 | Executes an SMBus operation to an SMBus controller.\r | |
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 | |
52 | @param SmbusOperation Signifies which particular SMBus hardware protocol instance\r | |
53 | that it will use to execute the SMBus transactions.\r | |
54 | @param SmBusAddress The address that encodes the SMBUS Slave Address,\r | |
55 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
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 | |
58 | and operation specific.\r | |
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 | |
61 | length of this buffer is identified by Length.\r | |
62 | @param Status Return status for the executed command.\r | |
63 | This is an optional parameter and may be NULL.\r | |
64 | \r | |
65 | @return The actual number of bytes that are executed for this operation.\r | |
66 | \r | |
67 | **/\r | |
68 | UINTN\r | |
69 | InternalSmBusExec (\r | |
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 | |
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 | |
87 | SMBUS_LIB_PEC (SmBusAddress),\r | |
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 |