]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/DxeSmbusLib/DxeSmbusLib.c
Initial import.
[mirror_edk2.git] / MdePkg / Library / DxeSmbusLib / DxeSmbusLib.c
CommitLineData
878ddf1f 1/** @file\r
2Implementation of SmBusLib class library for PEI phase.\r
3\r
4Copyright (c) 2006, Intel Corporation<BR>\r
5All rights reserved. This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php \r
9 \r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13\r
14Module Name: DxeSmbusLib.c\r
15\r
16**/\r
17\r
18#include "InternalSmbusLib.h"\r
19\r
20//\r
21// Globle varible to cache pointer to Smbus protocol.\r
22//\r
23STATIC EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL; \r
24\r
25/**\r
26 The constructor function caches the pointer to Smbus protocol.\r
27 \r
28 The constructor function locates Smbus protocol from protocol database.\r
29 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
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
33 \r
34 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
35\r
36**/\r
37EFI_STATUS\r
38EFIAPI\r
39SmbusLibConstructor (\r
40 IN EFI_HANDLE ImageHandle,\r
41 IN EFI_SYSTEM_TABLE *SystemTable\r
42 )\r
43{\r
44 EFI_STATUS Status;\r
45 \r
46 Status = gBS->LocateProtocol (\r
47 &gEfiCpuIoProtocolGuid,\r
48 NULL,\r
49 (VOID**) &mSmbus\r
50 );\r
51 ASSERT_EFI_ERROR (Status);\r
52 ASSERT (mSmbus != NULL);\r
53\r
54 return Status;\r
55}\r
56\r
57/**\r
58 Executes an SMBus operation to an SMBus controller. \r
59\r
60 This function provides a standard way to execute Smbus script\r
61 as defined in the SmBus Specification. The data can either be of\r
62 the Length byte, word, or a block of data.\r
63\r
64 @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to\r
65 execute the SMBus transactions.\r
66 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
67 SMBUS Command, SMBUS Data Length, and PEC.\r
68 @param Length Signifies the number of bytes that this operation will do. The maximum number of\r
69 bytes can be revision specific and operation specific.\r
70 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations\r
71 require this argument. The length of this buffer is identified by Length.\r
72 @param Status Return status for the executed command.\r
73 This is an optional parameter and may be NULL.\r
74\r
75 @return The actual number of bytes that are executed for this operation..\r
76\r
77**/\r
78UINTN\r
79InternalSmBusExec (\r
80 IN EFI_SMBUS_OPERATION SmbusOperation,\r
81 IN UINTN SmBusAddress,\r
82 IN UINTN Length,\r
83 IN VOID *Buffer,\r
84 OUT RETURN_STATUS *Status OPTIONAL\r
85 )\r
86{\r
87 RETURN_STATUS ReturnStatus;\r
88 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;\r
89\r
90 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);\r
91\r
92 ReturnStatus = mSmbus->Execute (\r
93 mSmbus,\r
94 SmbusDeviceAddress,\r
95 SMBUS_LIB_COMMAND (SmBusAddress),\r
96 SmbusOperation,\r
97 SMBUS_LIB_PEC (SmBusAddress), \r
98 &Length,\r
99 Buffer\r
100 );\r
101 if (Status != NULL) {\r
102 *Status = ReturnStatus;\r
103 }\r
104\r
105 return Length;\r
106}\r
107\r
108/**\r
109 Assigns an SMBUS slave addresses.\r
110\r
111 Assigns the SMBUS device specified by Uuid the slave address specified by SmBusAddress.\r
112 The status of the executed command is returned.\r
113\r
114 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
115 SMBUS Command, SMBUS Data Length, and PEC.\r
116 @param Uuid Pointer to the UUID of the device to assign a slave address.\r
117 It will assign to all SMBUS slave devices if it is NULL.\r
118\r
119 @retval RETURN_SUCCESS The SMBUS command was executed.\r
120 @retval RETURN_TIMEOUT A timeout occurred while executing the SMBUS command.\r
121 @retval RETURN_DEVICE_ERROR The request was not completed because a failure reflected\r
122 in the Host Status Register bit.\r
123 Device errors are a result of a transaction collision, illegal command field,\r
124 unclaimed cycle (host initiated), or bus errors (collisions).\r
125\r
126**/\r
127RETURN_STATUS\r
128InternalSmBusArpDevice (\r
129 IN UINTN SmBusAddress,\r
130 IN CONST GUID *Uuid OPTIONAL \r
131 )\r
132{\r
133 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;\r
134\r
135 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);\r
136 return (RETURN_STATUS) mSmbus->ArpDevice (\r
137 mSmbus,\r
138 (BOOLEAN) (Uuid == NULL),\r
139 (EFI_SMBUS_UDID *) Uuid,\r
140 &SmbusDeviceAddress\r
141 );\r
142}\r
143\r
144/**\r
145 Retrieves the mapping of all the SMBus devices.\r
146\r
147 The GetArpMap() function returns the mapping of all the SMBus devices \r
148 that are enumerated by the SMBus host driver. \r
149 \r
150 @param Length Size of the buffer that contains the SMBus device map.\r
151 @param SmbusDeviceMap The pointer to the device map as enumerated by the SMBus controller driver.\r
152\r
153 @retval RETURN_SUCCESS The SMBUS command was executed.\r
154 @retval RETURN_TIMEOUT A timeout occurred while executing the SMBUS command.\r
155 @retval RETURN_DEVICE_ERROR The request was not completed because a failure reflected\r
156 in the Host Status Register bit.\r
157 Device errors are a result of a transaction collision, illegal command field,\r
158 unclaimed cycle (host initiated), or bus errors (collisions).\r
159\r
160**/\r
161RETURN_STATUS\r
162InternalGetArpMap (\r
163 OUT UINTN *Length,\r
164 OUT EFI_SMBUS_DEVICE_MAP **SmbusDeviceMap\r
165 )\r
166{\r
167 return (RETURN_STATUS) mSmbus->GetArpMap (mSmbus, Length, SmbusDeviceMap);\r
168}\r