]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/DxeSmbusLib/SmbusLib.c
Removed MdePkg usage of ModuleName: in file headers
[mirror_edk2.git] / MdePkg / Library / DxeSmbusLib / SmbusLib.c
CommitLineData
dd51a993 1/** @file\r
2Implementation of SmBusLib class library for PEI phase.\r
3\r
4Copyright (c) 2006, Intel Corporation<BR>\r
bad46384 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
dd51a993 12\r
13\r
dd51a993 14**/\r
15\r
16#include "InternalSmbusLib.h"\r
17\r
18/**\r
19 Executes an SMBUS quick read command.\r
20\r
21 Executes an SMBUS quick read command on the SMBUS device specified by SmBusAddress.\r
22 Only the SMBUS slave address field of SmBusAddress is required.\r
23 If Status is not NULL, then the status of the executed command is returned in Status.\r
24 If PEC is set in SmBusAddress, then ASSERT().\r
25 If Command in SmBusAddress is not zero, then ASSERT().\r
26 If Length in SmBusAddress is not zero, then ASSERT().\r
27 If any reserved bits of SmBusAddress are set, then ASSERT().\r
28\r
29 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
30 SMBUS Command, SMBUS Data Length, and PEC.\r
31 @param Status Return status for the executed command.\r
32 This is an optional parameter and may be NULL.\r
33\r
34**/\r
35VOID\r
36EFIAPI\r
37SmBusQuickRead (\r
38 IN UINTN SmBusAddress,\r
39 OUT RETURN_STATUS *Status OPTIONAL\r
40 )\r
41{\r
42 ASSERT (!SMBUS_LIB_PEC (SmBusAddress));\r
43 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r
44 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
45 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
46\r
47 InternalSmBusExec (EfiSmbusQuickRead, SmBusAddress, 0, NULL, Status);\r
48}\r
49\r
50/**\r
51 Executes an SMBUS quick write command.\r
52\r
53 Executes an SMBUS quick write command on the SMBUS device specified by SmBusAddress.\r
54 Only the SMBUS slave address field of SmBusAddress is required.\r
55 If Status is not NULL, then the status of the executed command is returned in Status.\r
56 If PEC is set in SmBusAddress, then ASSERT().\r
57 If Command in SmBusAddress is not zero, then ASSERT().\r
58 If Length in SmBusAddress is not zero, then ASSERT().\r
59 If any reserved bits of SmBusAddress are set, then ASSERT().\r
60\r
61 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
62 SMBUS Command, SMBUS Data Length, and PEC.\r
63 @param Status Return status for the executed command.\r
64 This is an optional parameter and may be NULL.\r
65\r
66**/\r
67VOID\r
68EFIAPI\r
69SmBusQuickWrite (\r
70 IN UINTN SmBusAddress,\r
71 OUT RETURN_STATUS *Status OPTIONAL\r
72 )\r
73{\r
74 ASSERT (!SMBUS_LIB_PEC (SmBusAddress));\r
75 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r
76 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
77 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
78\r
79 InternalSmBusExec (EfiSmbusQuickWrite, SmBusAddress, 0, NULL, Status);\r
80}\r
81\r
82/**\r
83 Executes an SMBUS receive byte command.\r
84\r
85 Executes an SMBUS receive byte command on the SMBUS device specified by SmBusAddress.\r
86 Only the SMBUS slave address field of SmBusAddress is required.\r
87 The byte received from the SMBUS is returned.\r
88 If Status is not NULL, then the status of the executed command is returned in Status.\r
89 If Command in SmBusAddress is not zero, then ASSERT().\r
90 If Length in SmBusAddress is not zero, then ASSERT().\r
91 If any reserved bits of SmBusAddress are set, then ASSERT().\r
92\r
93 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
94 SMBUS Command, SMBUS Data Length, and PEC.\r
95 @param Status Return status for the executed command.\r
96 This is an optional parameter and may be NULL.\r
97\r
98 @return The byte received from the SMBUS.\r
99\r
100**/\r
101UINT8\r
102EFIAPI\r
103SmBusReceiveByte (\r
104 IN UINTN SmBusAddress,\r
105 OUT RETURN_STATUS *Status OPTIONAL\r
106 )\r
107{\r
108 UINT8 Byte;\r
109\r
110 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r
111 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
112 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
113\r
114 InternalSmBusExec (EfiSmbusReceiveByte, SmBusAddress, 1, &Byte, Status);\r
115\r
116 return Byte;\r
117}\r
118\r
119/**\r
120 Executes an SMBUS send byte command.\r
121\r
122 Executes an SMBUS send byte command on the SMBUS device specified by SmBusAddress.\r
123 The byte specified by Value is sent.\r
124 Only the SMBUS slave address field of SmBusAddress is required. Value is returned.\r
125 If Status is not NULL, then the status of the executed command is returned in Status.\r
126 If Command in SmBusAddress is not zero, then ASSERT().\r
127 If Length in SmBusAddress is not zero, then ASSERT().\r
128 If any reserved bits of SmBusAddress are set, then ASSERT().\r
129\r
130 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
131 SMBUS Command, SMBUS Data Length, and PEC.\r
132 @param Value The 8-bit value to send.\r
133 @param Status Return status for the executed command.\r
134 This is an optional parameter and may be NULL.\r
135\r
136 @return The parameter of Value.\r
137\r
138**/\r
139UINT8\r
140EFIAPI\r
141SmBusSendByte (\r
142 IN UINTN SmBusAddress,\r
143 IN UINT8 Value,\r
144 OUT RETURN_STATUS *Status OPTIONAL\r
145 )\r
146{\r
147 UINT8 Byte;\r
148\r
149 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r
150 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
151 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
152\r
153 Byte = Value;\r
154 InternalSmBusExec (EfiSmbusSendByte, SmBusAddress, 1, &Byte, Status);\r
155\r
156 return Value;\r
157}\r
158\r
159/**\r
160 Executes an SMBUS read data byte command.\r
161\r
162 Executes an SMBUS read data byte command on the SMBUS device specified by SmBusAddress.\r
163 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
164 The 8-bit value read from the SMBUS is returned.\r
165 If Status is not NULL, then the status of the executed command is returned in Status.\r
166 If Length in SmBusAddress is not zero, then ASSERT().\r
167 If any reserved bits of SmBusAddress are set, then ASSERT().\r
168\r
169 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
170 SMBUS Command, SMBUS Data Length, and PEC.\r
171 @param Status Return status for the executed command.\r
172 This is an optional parameter and may be NULL.\r
173\r
174 @return The byte read from the SMBUS.\r
175\r
176**/\r
177UINT8\r
178EFIAPI\r
179SmBusReadDataByte (\r
180 IN UINTN SmBusAddress,\r
181 OUT RETURN_STATUS *Status OPTIONAL\r
182 )\r
183{\r
184 UINT8 Byte;\r
185\r
186 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
187 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
188\r
189 InternalSmBusExec (EfiSmbusReadByte, SmBusAddress, 1, &Byte, Status);\r
bad46384 190\r
dd51a993 191 return Byte;\r
192}\r
193\r
194/**\r
195 Executes an SMBUS write data byte command.\r
196\r
197 Executes an SMBUS write data byte command on the SMBUS device specified by SmBusAddress.\r
198 The 8-bit value specified by Value is written.\r
199 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
200 Value is returned.\r
201 If Status is not NULL, then the status of the executed command is returned in Status.\r
202 If Length in SmBusAddress is not zero, then ASSERT().\r
203 If any reserved bits of SmBusAddress are set, then ASSERT().\r
204\r
205 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
206 SMBUS Command, SMBUS Data Length, and PEC.\r
207 @param Value The 8-bit value to write.\r
208 @param Status Return status for the executed command.\r
209 This is an optional parameter and may be NULL.\r
210\r
211 @return The parameter of Value.\r
212\r
213**/\r
214UINT8\r
215EFIAPI\r
216SmBusWriteDataByte (\r
217 IN UINTN SmBusAddress,\r
218 IN UINT8 Value,\r
219 OUT RETURN_STATUS *Status OPTIONAL\r
220 )\r
221{\r
222 UINT8 Byte;\r
223\r
224 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
225 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
226\r
227 Byte = Value;\r
228 InternalSmBusExec (EfiSmbusWriteByte, SmBusAddress, 1, &Byte, Status);\r
bad46384 229\r
dd51a993 230 return Value;\r
231}\r
232\r
233/**\r
234 Executes an SMBUS read data word command.\r
235\r
236 Executes an SMBUS read data word command on the SMBUS device specified by SmBusAddress.\r
237 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
238 The 16-bit value read from the SMBUS is returned.\r
239 If Status is not NULL, then the status of the executed command is returned in Status.\r
240 If Length in SmBusAddress is not zero, then ASSERT().\r
241 If any reserved bits of SmBusAddress are set, then ASSERT().\r
bad46384 242\r
dd51a993 243 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
244 SMBUS Command, SMBUS Data Length, and PEC.\r
245 @param Status Return status for the executed command.\r
246 This is an optional parameter and may be NULL.\r
247\r
248 @return The byte read from the SMBUS.\r
249\r
250**/\r
251UINT16\r
252EFIAPI\r
253SmBusReadDataWord (\r
254 IN UINTN SmBusAddress,\r
255 OUT RETURN_STATUS *Status OPTIONAL\r
256 )\r
257{\r
258 UINT16 Word;\r
259\r
260 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
261 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
262\r
263 InternalSmBusExec (EfiSmbusReadWord, SmBusAddress, 2, &Word, Status);\r
bad46384 264\r
dd51a993 265 return Word;\r
266}\r
267\r
268/**\r
269 Executes an SMBUS write data word command.\r
270\r
271 Executes an SMBUS write data word command on the SMBUS device specified by SmBusAddress.\r
272 The 16-bit value specified by Value is written.\r
273 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
274 Value is returned.\r
275 If Status is not NULL, then the status of the executed command is returned in Status.\r
276 If Length in SmBusAddress is not zero, then ASSERT().\r
277 If any reserved bits of SmBusAddress are set, then ASSERT().\r
278\r
279 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
280 SMBUS Command, SMBUS Data Length, and PEC.\r
281 @param Value The 16-bit value to write.\r
282 @param Status Return status for the executed command.\r
283 This is an optional parameter and may be NULL.\r
284\r
285 @return The parameter of Value.\r
286\r
287**/\r
288UINT16\r
289EFIAPI\r
290SmBusWriteDataWord (\r
291 IN UINTN SmBusAddress,\r
292 IN UINT16 Value,\r
293 OUT RETURN_STATUS *Status OPTIONAL\r
294 )\r
295{\r
296 UINT16 Word;\r
297\r
298 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
299 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
300\r
301 Word = Value;\r
302 InternalSmBusExec (EfiSmbusWriteWord, SmBusAddress, 2, &Word, Status);\r
303\r
304 return Value;\r
305}\r
306\r
307/**\r
308 Executes an SMBUS process call command.\r
309\r
310 Executes an SMBUS process call command on the SMBUS device specified by SmBusAddress.\r
311 The 16-bit value specified by Value is written.\r
312 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
313 The 16-bit value returned by the process call command is returned.\r
314 If Status is not NULL, then the status of the executed command is returned in Status.\r
315 If Length in SmBusAddress is not zero, then ASSERT().\r
316 If any reserved bits of SmBusAddress are set, then ASSERT().\r
317\r
318 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
319 SMBUS Command, SMBUS Data Length, and PEC.\r
320 @param Value The 16-bit value to write.\r
321 @param Status Return status for the executed command.\r
322 This is an optional parameter and may be NULL.\r
323\r
324 @return The 16-bit value returned by the process call command.\r
325\r
326**/\r
327UINT16\r
328EFIAPI\r
329SmBusProcessCall (\r
330 IN UINTN SmBusAddress,\r
331 IN UINT16 Value,\r
332 OUT RETURN_STATUS *Status OPTIONAL\r
333 )\r
334{\r
335 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
336 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
337\r
338 InternalSmBusExec (EfiSmbusProcessCall, SmBusAddress, 2, &Value, Status);\r
bad46384 339\r
dd51a993 340 return Value;\r
341}\r
342\r
343/**\r
344 Executes an SMBUS read block command.\r
345\r
346 Executes an SMBUS read block command on the SMBUS device specified by SmBusAddress.\r
347 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
348 Bytes are read from the SMBUS and stored in Buffer.\r
349 The number of bytes read is returned, and will never return a value larger than 32-bytes.\r
350 If Status is not NULL, then the status of the executed command is returned in Status.\r
351 It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r
352 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
353 If Length in SmBusAddress is not zero, then ASSERT().\r
354 If Buffer is NULL, then ASSERT().\r
355 If any reserved bits of SmBusAddress are set, then ASSERT().\r
356\r
357 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
358 SMBUS Command, SMBUS Data Length, and PEC.\r
359 @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.\r
360 @param Status Return status for the executed command.\r
361 This is an optional parameter and may be NULL.\r
362\r
363 @return The number of bytes read.\r
364\r
365**/\r
366UINTN\r
367EFIAPI\r
368SmBusReadBlock (\r
369 IN UINTN SmBusAddress,\r
370 OUT VOID *Buffer,\r
371 OUT RETURN_STATUS *Status OPTIONAL\r
372 )\r
373{\r
374 ASSERT (Buffer != NULL);\r
375 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
376 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
377\r
378 return InternalSmBusExec (EfiSmbusReadBlock, SmBusAddress, 0x20, Buffer, Status);\r
379}\r
380\r
381/**\r
382 Executes an SMBUS write block command.\r
383\r
384 Executes an SMBUS write block command on the SMBUS device specified by SmBusAddress.\r
385 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r
386 Bytes are written to the SMBUS from Buffer.\r
387 The number of bytes written is returned, and will never return a value larger than 32-bytes.\r
bad46384 388 If Status is not NULL, then the status of the executed command is returned in Status.\r
dd51a993 389 If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r
390 If Buffer is NULL, then ASSERT().\r
391 If any reserved bits of SmBusAddress are set, then ASSERT().\r
392\r
393 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
394 SMBUS Command, SMBUS Data Length, and PEC.\r
395 @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.\r
396 @param Status Return status for the executed command.\r
397 This is an optional parameter and may be NULL.\r
398\r
399 @return The number of bytes written.\r
400\r
401**/\r
402UINTN\r
403EFIAPI\r
404SmBusWriteBlock (\r
405 IN UINTN SmBusAddress,\r
406 OUT VOID *Buffer,\r
407 OUT RETURN_STATUS *Status OPTIONAL\r
408 )\r
409{\r
410 UINTN Length;\r
411\r
412 ASSERT (Buffer != NULL);\r
413 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
414 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
415 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
416\r
417 Length = SMBUS_LIB_LENGTH (SmBusAddress);\r
418 return InternalSmBusExec (EfiSmbusWriteBlock, SmBusAddress, Length, Buffer, Status);\r
419}\r
420\r
421/**\r
422 Executes an SMBUS block process call command.\r
423\r
424 Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.\r
425 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r
426 Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer.\r
427 If Status is not NULL, then the status of the executed command is returned in Status.\r
428 It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.\r
429 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
430 If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r
431 If WriteBuffer is NULL, then ASSERT().\r
432 If ReadBuffer is NULL, then ASSERT().\r
433 If any reserved bits of SmBusAddress are set, then ASSERT().\r
434\r
435 @param SmBusAddress Address that encodes the SMBUS Slave Address,\r
436 SMBUS Command, SMBUS Data Length, and PEC.\r
437 @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS.\r
438 @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS.\r
439 @param Status Return status for the executed command.\r
440 This is an optional parameter and may be NULL.\r
441\r
442 @return The number of bytes written.\r
443\r
444**/\r
445UINTN\r
446EFIAPI\r
447SmBusBlockProcessCall (\r
448 IN UINTN SmBusAddress,\r
449 IN VOID *WriteBuffer,\r
450 OUT VOID *ReadBuffer,\r
451 OUT RETURN_STATUS *Status OPTIONAL\r
452 )\r
453{\r
454 UINTN Length;\r
455\r
456 ASSERT (WriteBuffer != NULL);\r
457 ASSERT (ReadBuffer != NULL);\r
458 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
459 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
460 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
461\r
462 Length = SMBUS_LIB_LENGTH (SmBusAddress);\r
463 //\r
464 // Assuming that ReadBuffer is large enough to save another memory copy.\r
465 //\r
466 ReadBuffer = CopyMem (ReadBuffer, WriteBuffer, Length);\r
467 return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, ReadBuffer, Status);\r
468}\r