2 Smbus Library Services that do SMBus transactions and also enable the operatation
3 to be replayed during an S3 resume. This library class maps directly on top
6 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include <Library/DebugLib.h>
16 #include <Library/S3BootScriptLib.h>
17 #include <Library/SmbusLib.h>
18 #include <Library/S3SmbusLib.h>
21 Saves an SMBus operation to S3 script to be replayed on S3 resume.
23 This function provides a standard way to save SMBus operation to S3 boot Script.
24 The data can either be of the Length byte, word, or a block of data.
25 If it falis to save S3 boot script, then ASSERT ().
27 @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to
28 execute the SMBus transactions.
29 @param SmBusAddress Address that encodes the SMBUS Slave Address,
30 SMBUS Command, SMBUS Data Length, and PEC.
31 @param Length Signifies the number of bytes that this operation will do. The maximum number of
32 bytes can be revision specific and operation specific.
33 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations
34 require this argument. The length of this buffer is identified by Length.
38 InternalSaveSmBusExecToBootScript (
39 IN EFI_SMBUS_OPERATION SmbusOperation
,
40 IN UINTN SmBusAddress
,
47 Status
= S3BootScriptSaveSmbusExecute (
53 ASSERT (Status
== RETURN_SUCCESS
);
57 Executes an SMBUS quick read command and saves the value in the S3 script to be replayed
60 Executes an SMBUS quick read command on the SMBUS device specified by SmBusAddress.
61 Only the SMBUS slave address field of SmBusAddress is required.
62 If Status is not NULL, then the status of the executed command is returned in Status.
63 If PEC is set in SmBusAddress, then ASSERT().
64 If Command in SmBusAddress is not zero, then ASSERT().
65 If Length in SmBusAddress is not zero, then ASSERT().
66 If any reserved bits of SmBusAddress are set, then ASSERT().
68 @param SmBusAddress Address that encodes the SMBUS Slave Address,
69 SMBUS Command, SMBUS Data Length, and PEC.
70 @param Status Return status for the executed command.
71 This is an optional parameter and may be NULL.
77 IN UINTN SmBusAddress
,
78 OUT RETURN_STATUS
*Status OPTIONAL
81 SmBusQuickRead (SmBusAddress
, Status
);
83 InternalSaveSmBusExecToBootScript (EfiSmbusQuickRead
, SmBusAddress
, 0, NULL
);
87 Executes an SMBUS quick write command and saves the value in the S3 script to be replayed
90 Executes an SMBUS quick write command on the SMBUS device specified by SmBusAddress.
91 Only the SMBUS slave address field of SmBusAddress is required.
92 If Status is not NULL, then the status of the executed command is returned in Status.
93 If PEC is set in SmBusAddress, then ASSERT().
94 If Command in SmBusAddress is not zero, then ASSERT().
95 If Length in SmBusAddress is not zero, then ASSERT().
96 If any reserved bits of SmBusAddress are set, then ASSERT().
98 @param SmBusAddress Address that encodes the SMBUS Slave Address,
99 SMBUS Command, SMBUS Data Length, and PEC.
100 @param Status Return status for the executed command.
101 This is an optional parameter and may be NULL.
107 IN UINTN SmBusAddress
,
108 OUT RETURN_STATUS
*Status OPTIONAL
111 SmBusQuickWrite (SmBusAddress
, Status
);
113 InternalSaveSmBusExecToBootScript (EfiSmbusQuickWrite
, SmBusAddress
, 0, NULL
);
117 Executes an SMBUS receive byte command and saves the value in the S3 script to be replayed
120 Executes an SMBUS receive byte command on the SMBUS device specified by SmBusAddress.
121 Only the SMBUS slave address field of SmBusAddress is required.
122 The byte received from the SMBUS is returned.
123 If Status is not NULL, then the status of the executed command is returned in Status.
124 If Command in SmBusAddress is not zero, then ASSERT().
125 If Length in SmBusAddress is not zero, then ASSERT().
126 If any reserved bits of SmBusAddress are set, then ASSERT().
128 @param SmBusAddress Address that encodes the SMBUS Slave Address,
129 SMBUS Command, SMBUS Data Length, and PEC.
130 @param Status Return status for the executed command.
131 This is an optional parameter and may be NULL.
133 @return The byte received from the SMBUS.
139 IN UINTN SmBusAddress
,
140 OUT RETURN_STATUS
*Status OPTIONAL
145 Byte
= SmBusReceiveByte (SmBusAddress
, Status
);
147 InternalSaveSmBusExecToBootScript (EfiSmbusReceiveByte
, SmBusAddress
, 1, &Byte
);
153 Executes an SMBUS send byte command and saves the value in the S3 script to be replayed
156 Executes an SMBUS send byte command on the SMBUS device specified by SmBusAddress.
157 The byte specified by Value is sent.
158 Only the SMBUS slave address field of SmBusAddress is required. Value is returned.
159 If Status is not NULL, then the status of the executed command is returned in Status.
160 If Command in SmBusAddress is not zero, then ASSERT().
161 If Length in SmBusAddress is not zero, then ASSERT().
162 If any reserved bits of SmBusAddress are set, then ASSERT().
164 @param SmBusAddress Address that encodes the SMBUS Slave Address,
165 SMBUS Command, SMBUS Data Length, and PEC.
166 @param Value The 8-bit value to send.
167 @param Status Return status for the executed command.
168 This is an optional parameter and may be NULL.
170 @return The parameter of Value.
176 IN UINTN SmBusAddress
,
178 OUT RETURN_STATUS
*Status OPTIONAL
183 Byte
= SmBusSendByte (SmBusAddress
, Value
, Status
);
185 InternalSaveSmBusExecToBootScript (EfiSmbusSendByte
, SmBusAddress
, 1, &Byte
);
191 Executes an SMBUS read data byte command and saves the value in the S3 script to be replayed
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 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.
206 @return The byte read from the SMBUS.
211 S3SmBusReadDataByte (
212 IN UINTN SmBusAddress
,
213 OUT RETURN_STATUS
*Status OPTIONAL
218 Byte
= SmBusReadDataByte (SmBusAddress
, Status
);
220 InternalSaveSmBusExecToBootScript (EfiSmbusReadByte
, SmBusAddress
, 1, &Byte
);
226 Executes an SMBUS write data byte command and saves the value in the S3 script to be replayed
229 Executes an SMBUS write data byte command on the SMBUS device specified by SmBusAddress.
230 The 8-bit value specified by Value is written.
231 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
233 If Status is not NULL, then the status of the executed command is returned in Status.
234 If Length in SmBusAddress is not zero, then ASSERT().
235 If any reserved bits of SmBusAddress are set, then ASSERT().
237 @param SmBusAddress Address that encodes the SMBUS Slave Address,
238 SMBUS Command, SMBUS Data Length, and PEC.
239 @param Value The 8-bit value to write.
240 @param Status Return status for the executed command.
241 This is an optional parameter and may be NULL.
243 @return The parameter of Value.
248 S3SmBusWriteDataByte (
249 IN UINTN SmBusAddress
,
251 OUT RETURN_STATUS
*Status OPTIONAL
256 Byte
= SmBusWriteDataByte (SmBusAddress
, Value
, Status
);
258 InternalSaveSmBusExecToBootScript (EfiSmbusWriteByte
, SmBusAddress
, 1, &Byte
);
264 Executes an SMBUS read data word command and saves the value in the S3 script to be replayed
267 Executes an SMBUS read data word command on the SMBUS device specified by SmBusAddress.
268 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
269 The 16-bit value read from the SMBUS is returned.
270 If Status is not NULL, then the status of the executed command is returned in Status.
271 If Length in SmBusAddress is not zero, then ASSERT().
272 If any reserved bits of SmBusAddress are set, then ASSERT().
274 @param SmBusAddress Address that encodes the SMBUS Slave Address,
275 SMBUS Command, SMBUS Data Length, and PEC.
276 @param Status Return status for the executed command.
277 This is an optional parameter and may be NULL.
279 @return The byte read from the SMBUS.
284 S3SmBusReadDataWord (
285 IN UINTN SmBusAddress
,
286 OUT RETURN_STATUS
*Status OPTIONAL
291 Word
= SmBusReadDataWord (SmBusAddress
, Status
);
293 InternalSaveSmBusExecToBootScript (EfiSmbusReadWord
, SmBusAddress
, 2, &Word
);
299 Executes an SMBUS write data word command and saves the value in the S3 script to be replayed
302 Executes an SMBUS write data word command on the SMBUS device specified by SmBusAddress.
303 The 16-bit value specified by Value is written.
304 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
306 If Status is not NULL, then the status of the executed command is returned in Status.
307 If Length in SmBusAddress is not zero, then ASSERT().
308 If any reserved bits of SmBusAddress are set, then ASSERT().
310 @param SmBusAddress Address that encodes the SMBUS Slave Address,
311 SMBUS Command, SMBUS Data Length, and PEC.
312 @param Value The 16-bit value to write.
313 @param Status Return status for the executed command.
314 This is an optional parameter and may be NULL.
316 @return The parameter of Value.
321 S3SmBusWriteDataWord (
322 IN UINTN SmBusAddress
,
324 OUT RETURN_STATUS
*Status OPTIONAL
329 Word
= SmBusWriteDataWord (SmBusAddress
, Value
, Status
);
331 InternalSaveSmBusExecToBootScript (EfiSmbusWriteWord
, SmBusAddress
, 2, &Word
);
337 Executes an SMBUS process call command and saves the value in the S3 script to be replayed
340 Executes an SMBUS process call command on the SMBUS device specified by SmBusAddress.
341 The 16-bit value specified by Value is written.
342 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
343 The 16-bit value returned by the process call command is returned.
344 If Status is not NULL, then the status of the executed command is returned in Status.
345 If Length in SmBusAddress is not zero, then ASSERT().
346 If any reserved bits of SmBusAddress are set, then ASSERT().
348 @param SmBusAddress Address that encodes the SMBUS Slave Address,
349 SMBUS Command, SMBUS Data Length, and PEC.
350 @param Value The 16-bit value to write.
351 @param Status Return status for the executed command.
352 This is an optional parameter and may be NULL.
354 @return The 16-bit value returned by the process call command.
360 IN UINTN SmBusAddress
,
362 OUT RETURN_STATUS
*Status OPTIONAL
367 Word
= SmBusProcessCall (SmBusAddress
, Value
, Status
);
369 InternalSaveSmBusExecToBootScript (EfiSmbusProcessCall
, SmBusAddress
, 2, &Value
);
375 Executes an SMBUS read block command and saves the value in the S3 script to be replayed
378 Executes an SMBUS read block command on the SMBUS device specified by SmBusAddress.
379 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
380 Bytes are read from the SMBUS and stored in Buffer.
381 The number of bytes read is returned, and will never return a value larger than 32-bytes.
382 If Status is not NULL, then the status of the executed command is returned in Status.
383 It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
384 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.
385 If Length in SmBusAddress is not zero, then ASSERT().
386 If Buffer is NULL, then ASSERT().
387 If any reserved bits of SmBusAddress are set, then ASSERT().
389 @param SmBusAddress Address that encodes the SMBUS Slave Address,
390 SMBUS Command, SMBUS Data Length, and PEC.
391 @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.
392 @param Status Return status for the executed command.
393 This is an optional parameter and may be NULL.
395 @return The number of bytes read.
401 IN UINTN SmBusAddress
,
403 OUT RETURN_STATUS
*Status OPTIONAL
408 Length
= SmBusReadBlock (SmBusAddress
, Buffer
, Status
);
410 InternalSaveSmBusExecToBootScript (EfiSmbusReadBlock
, SmBusAddress
, Length
, Buffer
);
416 Executes an SMBUS write block command and saves the value in the S3 script to be replayed
419 Executes an SMBUS write block command on the SMBUS device specified by SmBusAddress.
420 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.
421 Bytes are written to the SMBUS from Buffer.
422 The number of bytes written is returned, and will never return a value larger than 32-bytes.
423 If Status is not NULL, then the status of the executed command is returned in Status.
424 If Length in SmBusAddress is zero or greater than 32, then ASSERT().
425 If Buffer is NULL, then ASSERT().
426 If any reserved bits of SmBusAddress are set, then ASSERT().
428 @param SmBusAddress Address that encodes the SMBUS Slave Address,
429 SMBUS Command, SMBUS Data Length, and PEC.
430 @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.
431 @param Status Return status for the executed command.
432 This is an optional parameter and may be NULL.
434 @return The number of bytes written.
440 IN UINTN SmBusAddress
,
442 OUT RETURN_STATUS
*Status OPTIONAL
447 Length
= SmBusWriteBlock (SmBusAddress
, Buffer
, Status
);
449 InternalSaveSmBusExecToBootScript (EfiSmbusWriteBlock
, SmBusAddress
, SMBUS_LIB_LENGTH (SmBusAddress
), Buffer
);
455 Executes an SMBUS block process call command and saves the value in the S3 script to be replayed
458 Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.
459 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.
460 Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer.
461 If Status is not NULL, then the status of the executed command is returned in Status.
462 It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.
463 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.
464 If Length in SmBusAddress is zero or greater than 32, then ASSERT().
465 If WriteBuffer is NULL, then ASSERT().
466 If ReadBuffer is NULL, then ASSERT().
467 If any reserved bits of SmBusAddress are set, then ASSERT().
469 @param SmBusAddress Address that encodes the SMBUS Slave Address,
470 SMBUS Command, SMBUS Data Length, and PEC.
471 @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS.
472 @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS.
473 @param Status Return status for the executed command.
474 This is an optional parameter and may be NULL.
476 @return The number of bytes written.
481 S3SmBusBlockProcessCall (
482 IN UINTN SmBusAddress
,
483 IN VOID
*WriteBuffer
,
484 OUT VOID
*ReadBuffer
,
485 OUT RETURN_STATUS
*Status OPTIONAL
490 Length
= SmBusBlockProcessCall (SmBusAddress
, WriteBuffer
, ReadBuffer
, Status
);
492 InternalSaveSmBusExecToBootScript (EfiSmbusBWBRProcessCall
, SmBusAddress
, SMBUS_LIB_LENGTH (SmBusAddress
), ReadBuffer
);