dd51a993 |
1 | /** @file\r |
2 | Implementation of SmBusLib class library for PEI phase.\r |
3 | \r |
4 | Copyright (c) 2006, Intel Corporation<BR>\r |
bad46384 |
5 | All rights reserved. This program and the accompanying materials\r |
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 |
8 | http://opensource.org/licenses/bsd-license.php\r |
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 |
bad46384 |
23 | STATIC 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 |
60 | @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to\r |
61 | execute the SMBus transactions.\r |
62 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r |
63 | SMBUS Command, SMBUS Data Length, and PEC.\r |
64 | @param Length Signifies the number of bytes that this operation will do. The maximum number of\r |
65 | bytes can be revision specific and operation specific.\r |
66 | @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations\r |
67 | require this argument. The length of this buffer is identified by Length.\r |
68 | @param Status Return status for the executed command.\r |
69 | This is an optional parameter and may be NULL.\r |
70 | \r |
71 | @return The actual number of bytes that are executed for this operation..\r |
72 | \r |
73 | **/\r |
74 | UINTN\r |
75 | InternalSmBusExec (\r |
76 | IN EFI_SMBUS_OPERATION SmbusOperation,\r |
77 | IN UINTN SmBusAddress,\r |
78 | IN UINTN Length,\r |
79 | IN OUT VOID *Buffer,\r |
80 | OUT RETURN_STATUS *Status OPTIONAL\r |
81 | )\r |
82 | {\r |
83 | RETURN_STATUS ReturnStatus;\r |
84 | EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;\r |
85 | \r |
86 | SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);\r |
87 | \r |
88 | ReturnStatus = mSmbus->Execute (\r |
89 | mSmbus,\r |
90 | SmbusDeviceAddress,\r |
91 | SMBUS_LIB_COMMAND (SmBusAddress),\r |
92 | SmbusOperation,\r |
bad46384 |
93 | SMBUS_LIB_PEC (SmBusAddress),\r |
dd51a993 |
94 | &Length,\r |
95 | Buffer\r |
96 | );\r |
97 | if (Status != NULL) {\r |
98 | *Status = ReturnStatus;\r |
99 | }\r |
100 | \r |
101 | return Length;\r |
102 | }\r |