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