]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiSmbusLibSmbus2Ppi/SmbusLib.c
2 Implementation of SmBusLib class library for PEI phase.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "InternalSmbusLib.h"
13 Executes an SMBUS quick read command.
15 Executes an SMBUS quick read command on the SMBUS device specified by SmBusAddress.
16 Only the SMBUS slave address field of SmBusAddress is required.
17 If Status is not NULL, then the status of the executed command is returned in Status.
18 If PEC is set in SmBusAddress, then ASSERT().
19 If Command in SmBusAddress is not zero, then ASSERT().
20 If Length in SmBusAddress is not zero, then ASSERT().
21 If any reserved bits of SmBusAddress are set, then ASSERT().
23 @param SmBusAddress The address that encodes the SMBUS Slave Address,
24 SMBUS Command, SMBUS Data Length, and PEC.
25 @param Status Return status for the executed command.
26 This is an optional parameter and may be NULL.
27 RETURN_SUCCESS: The SMBUS command was executed.
28 RETURN_TIMEOUT: A timeout occurred while executing the
30 RETURN_DEVICE_ERROR: The request was not completed because
31 a failure reflected in the Host Status Register bit.
32 Device errors are a result of a transaction collision,
33 illegal command field, unclaimed cycle
34 (host initiated), or bus errors (collisions).
35 RETURN_UNSUPPORTED: The SMBus operation is not supported.
41 IN UINTN SmBusAddress
,
42 OUT RETURN_STATUS
*Status OPTIONAL
45 ASSERT (!SMBUS_LIB_PEC (SmBusAddress
));
46 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress
) == 0);
47 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
48 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
50 InternalSmBusExec (EfiSmbusQuickRead
, SmBusAddress
, 0, NULL
, Status
);
54 Executes an SMBUS quick write command.
56 Executes an SMBUS quick write command on the SMBUS device specified by SmBusAddress.
57 Only the SMBUS slave address field of SmBusAddress is required.
58 If Status is not NULL, then the status of the executed command is returned in Status.
59 If PEC is set in SmBusAddress, then ASSERT().
60 If Command in SmBusAddress is not zero, then ASSERT().
61 If Length in SmBusAddress is not zero, then ASSERT().
62 If any reserved bits of SmBusAddress are set, then ASSERT().
64 @param SmBusAddress The address that encodes the SMBUS Slave Address,
65 SMBUS Command, SMBUS Data Length, and PEC.
66 @param Status Return status for the executed command.
67 This is an optional parameter and may be NULL.
68 RETURN_SUCCESS: The SMBUS command was executed.
69 RETURN_TIMEOUT: A timeout occurred while executing the
71 RETURN_DEVICE_ERROR: The request was not completed because
72 a failure reflected in the Host Status Register bit. Device
73 errors are a result of a transaction collision, illegal
74 command field, unclaimed cycle (host initiated), or bus
76 RETURN_UNSUPPORTED:: The SMBus operation is not supported.
82 IN UINTN SmBusAddress
,
83 OUT RETURN_STATUS
*Status OPTIONAL
86 ASSERT (!SMBUS_LIB_PEC (SmBusAddress
));
87 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress
) == 0);
88 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
89 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
91 InternalSmBusExec (EfiSmbusQuickWrite
, SmBusAddress
, 0, NULL
, Status
);
95 Executes an SMBUS receive byte command.
97 Executes an SMBUS receive byte command on the SMBUS device specified by SmBusAddress.
98 Only the SMBUS slave address field of SmBusAddress is required.
99 The byte received from the SMBUS is returned.
100 If Status is not NULL, then the status of the executed command is returned in Status.
101 If Command in SmBusAddress is not zero, then ASSERT().
102 If Length in SmBusAddress is not zero, then ASSERT().
103 If any reserved bits of SmBusAddress are set, then ASSERT().
105 @param SmBusAddress The address that encodes the SMBUS Slave Address,
106 SMBUS Command, SMBUS Data Length, and PEC.
107 @param Status Return status for the executed command.
108 This is an optional parameter and may be NULL.
109 RETURN_SUCCESS: The SMBUS command was executed.
110 RETURN_TIMEOUT: A timeout occurred while executing the
112 RETURN_DEVICE_ERROR: The request was not completed because
113 a failure reflected in the Host Status Register bit.
114 Device errors are a result of a transaction collision,
115 illegal command field, unclaimed cycle (host initiated),
116 or bus errors (collisions).
117 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)
118 RETURN_UNSUPPORTED: The SMBus operation is not supported.
120 @return The byte received from the SMBUS.
126 IN UINTN SmBusAddress
,
127 OUT RETURN_STATUS
*Status OPTIONAL
132 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress
) == 0);
133 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
134 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
136 InternalSmBusExec (EfiSmbusReceiveByte
, SmBusAddress
, 1, &Byte
, Status
);
142 Executes an SMBUS send byte command.
144 Executes an SMBUS send byte command on the SMBUS device specified by SmBusAddress.
145 The byte specified by Value is sent.
146 Only the SMBUS slave address field of SmBusAddress is required. Value is returned.
147 If Status is not NULL, then the status of the executed command is returned in Status.
148 If Command in SmBusAddress is not zero, then ASSERT().
149 If Length in SmBusAddress is not zero, then ASSERT().
150 If any reserved bits of SmBusAddress are set, then ASSERT().
152 @param SmBusAddress The address that encodes the SMBUS Slave Address,
153 SMBUS Command, SMBUS Data Length, and PEC.
154 @param Value The 8-bit value to send.
155 @param Status Return status for the executed command.
156 This is an optional parameter and may be NULL.
157 RETURN_SUCCESS: The SMBUS command was executed.
158 RETURN_TIMEOUT: A timeout occurred while executing the
160 RETURN_DEVICE_ERROR: The request was not completed because
161 a failure reflected in the Host Status Register bit. Device
162 errors are a result of a transaction collision, illegal
163 command field, unclaimed cycle (host initiated), or bus
165 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)
166 RETURN_UNSUPPORTED: The SMBus operation is not supported.
168 @return The parameter of Value.
174 IN UINTN SmBusAddress
,
176 OUT RETURN_STATUS
*Status OPTIONAL
181 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress
) == 0);
182 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
183 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
186 InternalSmBusExec (EfiSmbusSendByte
, SmBusAddress
, 1, &Byte
, Status
);
192 Executes an SMBUS read data byte command.
194 Executes an SMBUS read data byte command on the SMBUS device specified by SmBusAddress.
195 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
196 The 8-bit value read from the SMBUS is returned.
197 If Status is not NULL, then the status of the executed command is returned in Status.
198 If Length in SmBusAddress is not zero, then ASSERT().
199 If any reserved bits of SmBusAddress are set, then ASSERT().
201 @param SmBusAddress The address that encodes the SMBUS Slave Address,
202 SMBUS Command, SMBUS Data Length, and PEC.
203 @param Status Return status for the executed command.
204 This is an optional parameter and may be NULL.
205 RETURN_SUCCESS: The SMBUS command was executed.
206 RETURN_TIMEOUT: A timeout occurred while executing the
208 RETURN_DEVICE_ERROR: The request was not completed because
209 a failure reflected in the Host Status Register bit.
210 Device errors are a result of a transaction collision,
211 illegal command field, unclaimed cycle (host initiated),
212 or bus errors (collisions).
213 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)
214 RETURN_UNSUPPORTED: The SMBus operation is not supported.
216 @return The byte read from the SMBUS.
222 IN UINTN SmBusAddress
,
223 OUT RETURN_STATUS
*Status OPTIONAL
228 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
229 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
231 InternalSmBusExec (EfiSmbusReadByte
, SmBusAddress
, 1, &Byte
, Status
);
237 Executes an SMBUS write data byte command.
239 Executes an SMBUS write data byte command on the SMBUS device specified by SmBusAddress.
240 The 8-bit value specified by Value is written.
241 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
243 If Status is not NULL, then the status of the executed command is returned in Status.
244 If Length in SmBusAddress is not zero, then ASSERT().
245 If any reserved bits of SmBusAddress are set, then ASSERT().
247 @param SmBusAddress The address that encodes the SMBUS Slave Address,
248 SMBUS Command, SMBUS Data Length, and PEC.
249 @param Value The 8-bit value to write.
250 @param Status Return status for the executed command.
251 This is an optional parameter and may be NULL.
252 RETURN_SUCCESS: The SMBUS command was executed.
253 RETURN_TIMEOUT: A timeout occurred while executing the
255 RETURN_DEVICE_ERROR: The request was not completed because
256 a failure reflected in the Host Status Register bit.
257 Device errors are a result of a transaction collision,
258 illegal command field, unclaimed cycle (host initiated),
259 or bus errors (collisions).
260 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)
261 RETURN_UNSUPPORTED: The SMBus operation is not supported.
263 @return The parameter of Value.
269 IN UINTN SmBusAddress
,
271 OUT RETURN_STATUS
*Status OPTIONAL
276 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
277 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
280 InternalSmBusExec (EfiSmbusWriteByte
, SmBusAddress
, 1, &Byte
, Status
);
286 Executes an SMBUS read data word command.
288 Executes an SMBUS read data word command on the SMBUS device specified by SmBusAddress.
289 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
290 The 16-bit value read from the SMBUS is returned.
291 If Status is not NULL, then the status of the executed command is returned in Status.
292 If Length in SmBusAddress is not zero, then ASSERT().
293 If any reserved bits of SmBusAddress are set, then ASSERT().
295 @param SmBusAddress The address that encodes the SMBUS Slave Address,
296 SMBUS Command, SMBUS Data Length, and PEC.
297 @param Status Return status for the executed command.
298 This is an optional parameter and may be NULL.
299 RETURN_SUCCESS: The SMBUS command was executed.
300 RETURN_TIMEOUT: A timeout occurred while executing the
302 RETURN_DEVICE_ERROR: The request was not completed because
303 a failure reflected in the Host Status Register bit.
304 Device errors are a result of a transaction collision,
305 illegal command field, unclaimed cycle (host initiated),
306 or bus errors (collisions).
307 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)
308 RETURN_UNSUPPORTED: The SMBus operation is not supported.
310 @return The byte read from the SMBUS.
316 IN UINTN SmBusAddress
,
317 OUT RETURN_STATUS
*Status OPTIONAL
322 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
323 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
325 InternalSmBusExec (EfiSmbusReadWord
, SmBusAddress
, 2, &Word
, Status
);
331 Executes an SMBUS write data word command.
333 Executes an SMBUS write data word command on the SMBUS device specified by SmBusAddress.
334 The 16-bit value specified by Value is written.
335 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
337 If Status is not NULL, then the status of the executed command is returned in Status.
338 If Length in SmBusAddress is not zero, then ASSERT().
339 If any reserved bits of SmBusAddress are set, then ASSERT().
341 @param SmBusAddress The address that encodes the SMBUS Slave Address,
342 SMBUS Command, SMBUS Data Length, and PEC.
343 @param Value The 16-bit value to write.
344 @param Status Return status for the executed command.
345 This is an optional parameter and may be NULL.
346 RETURN_SUCCESS: The SMBUS command was executed.
347 RETURN_TIMEOUT: A timeout occurred while executing the
349 RETURN_DEVICE_ERROR: The request was not completed because
350 a failure reflected in the Host Status Register bit.
351 Device errors are a result of a transaction collision,
352 illegal command field, unclaimed cycle (host initiated),
353 or bus errors (collisions).
354 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)
355 RETURN_UNSUPPORTED: The SMBus operation is not supported.
357 @return The parameter of Value.
363 IN UINTN SmBusAddress
,
365 OUT RETURN_STATUS
*Status OPTIONAL
370 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
371 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
374 InternalSmBusExec (EfiSmbusWriteWord
, SmBusAddress
, 2, &Word
, Status
);
380 Executes an SMBUS process call command.
382 Executes an SMBUS process call command on the SMBUS device specified by SmBusAddress.
383 The 16-bit value specified by Value is written.
384 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
385 The 16-bit value returned by the process call command is returned.
386 If Status is not NULL, then the status of the executed command is returned in Status.
387 If Length in SmBusAddress is not zero, then ASSERT().
388 If any reserved bits of SmBusAddress are set, then ASSERT().
390 @param SmBusAddress The address that encodes the SMBUS Slave Address,
391 SMBUS Command, SMBUS Data Length, and PEC.
392 @param Value The 16-bit value to write.
393 @param Status Return status for the executed command.
394 This is an optional parameter and may be NULL.
395 RETURN_SUCCESS: The SMBUS command was executed.
396 RETURN_TIMEOUT: A timeout occurred while executing the
398 RETURN_DEVICE_ERROR: The request was not completed because
399 a failure reflected in the Host Status Register bit.
400 Device errors are a result of a transaction collision,
401 illegal command field, unclaimed cycle (host initiated),
402 or bus errors (collisions).
403 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)
404 RETURN_UNSUPPORTED: The SMBus operation is not supported.
406 @return The 16-bit value returned by the process call command.
412 IN UINTN SmBusAddress
,
414 OUT RETURN_STATUS
*Status OPTIONAL
417 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
418 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
420 InternalSmBusExec (EfiSmbusProcessCall
, SmBusAddress
, 2, &Value
, Status
);
426 Executes an SMBUS read block command.
428 Executes an SMBUS read block command on the SMBUS device specified by SmBusAddress.
429 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
430 Bytes are read from the SMBUS and stored in Buffer.
431 The number of bytes read is returned, and will never return a value larger than 32-bytes.
432 If Status is not NULL, then the status of the executed command is returned in Status.
433 It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
434 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.
435 If Length in SmBusAddress is not zero, then ASSERT().
436 If Buffer is NULL, then ASSERT().
437 If any reserved bits of SmBusAddress are set, then ASSERT().
439 @param SmBusAddress The address that encodes the SMBUS Slave Address,
440 SMBUS Command, SMBUS Data Length, and PEC.
441 @param Buffer The pointer to the buffer to store the bytes read from the SMBUS.
442 @param Status Return status for the executed command.
443 This is an optional parameter and may be NULL.
444 RETURN_SUCCESS: The SMBUS command was executed.
445 RETURN_TIMEOUT: A timeout occurred while executing the
447 RETURN_DEVICE_ERROR: The request was not completed because
448 a failure reflected in the Host Status Register bit.
449 Device errors are a result of a transaction collision,
450 illegal command field, unclaimed cycle (host initiated),
451 or bus errors (collisions).
452 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)
453 RETURN_UNSUPPORTED: The SMBus operation is not supported.
455 @return The number of bytes read.
461 IN UINTN SmBusAddress
,
463 OUT RETURN_STATUS
*Status OPTIONAL
466 ASSERT (Buffer
!= NULL
);
467 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
468 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
470 return InternalSmBusExec (EfiSmbusReadBlock
, SmBusAddress
, 0x20, Buffer
, Status
);
474 Executes an SMBUS write block command.
476 Executes an SMBUS write block command on the SMBUS device specified by SmBusAddress.
477 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.
478 Bytes are written to the SMBUS from Buffer.
479 The number of bytes written is returned, and will never return a value larger than 32-bytes.
480 If Status is not NULL, then the status of the executed command is returned in Status.
481 If Length in SmBusAddress is zero or greater than 32, then ASSERT().
482 If Buffer is NULL, then ASSERT().
483 If any reserved bits of SmBusAddress are set, then ASSERT().
485 @param SmBusAddress The address that encodes the SMBUS Slave Address,
486 MBUS Command, SMBUS Data Length, and PEC.
487 @param Buffer The pointer to the buffer to store the bytes read from the SMBUS.
488 @param Status Return status for the executed command.
489 This is an optional parameter and may be NULL.
490 RETURN_TIMEOUT: A timeout occurred while executing the
492 RETURN_DEVICE_ERROR: The request was not completed because
493 a failure reflected in the Host Status Register bit.
494 Device errors are a result of a transaction collision,
495 illegal command field, unclaimed cycle (host initiated),
496 or bus errors (collisions).
497 RETURN_CRC_ERROR: The checksum is not correct (PEC is incorrect)
498 RETURN_UNSUPPORTED: The SMBus operation is not supported.
500 @return The number of bytes written.
506 IN UINTN SmBusAddress
,
508 OUT RETURN_STATUS
*Status OPTIONAL
513 ASSERT (Buffer
!= NULL
);
514 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) >= 1);
515 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) <= 32);
516 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
518 Length
= SMBUS_LIB_LENGTH (SmBusAddress
);
519 return InternalSmBusExec (EfiSmbusWriteBlock
, SmBusAddress
, Length
, Buffer
, Status
);
523 Executes an SMBUS block process call command.
525 Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.
526 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.
527 Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer.
528 If Status is not NULL, then the status of the executed command is returned in Status.
529 It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.
530 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.
531 If Length in SmBusAddress is zero or greater than 32, then ASSERT().
532 If WriteBuffer is NULL, then ASSERT().
533 If ReadBuffer is NULL, then ASSERT().
534 If any reserved bits of SmBusAddress are set, then ASSERT().
536 @param SmBusAddress The address that encodes the SMBUS Slave Address,
537 SMBUS Command, SMBUS Data Length, and PEC.
538 @param WriteBuffer The pointer to the buffer of bytes to write to the SMBUS.
539 @param ReadBuffer The pointer to the buffer of bytes to read from the SMBUS.
540 @param Status Return status for the executed command.
541 This is an optional parameter and may be NULL.
542 RETURN_TIMEOUT: A timeout occurred while executing the
544 RETURN_DEVICE_ERROR: The request was not completed because
545 a failure reflected in the Host Status Register bit.
546 Device errors are a result of a transaction collision,
547 illegal command field, unclaimed cycle (host initiated),
548 or bus errors (collisions).
549 RETURN_CRC_ERROR The checksum is not correct. (PEC is incorrect.)
550 RETURN_UNSUPPORTED: The SMBus operation is not supported.
552 @return The number of bytes written.
557 SmBusBlockProcessCall (
558 IN UINTN SmBusAddress
,
559 IN VOID
*WriteBuffer
,
560 OUT VOID
*ReadBuffer
,
561 OUT RETURN_STATUS
*Status OPTIONAL
566 ASSERT (WriteBuffer
!= NULL
);
567 ASSERT (ReadBuffer
!= NULL
);
568 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) >= 1);
569 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) <= 32);
570 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
572 Length
= SMBUS_LIB_LENGTH (SmBusAddress
);
574 // Assuming that ReadBuffer is large enough to save another memory copy.
576 ReadBuffer
= CopyMem (ReadBuffer
, WriteBuffer
, Length
);
577 return InternalSmBusExec (EfiSmbusBWBRProcessCall
, SmBusAddress
, Length
, ReadBuffer
, Status
);