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