]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiSmbusLibSmbus2Ppi/SmbusLib.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / PeiSmbusLibSmbus2Ppi / SmbusLib.c
CommitLineData
dd51a993 1/** @file\r
2Implementation of SmBusLib class library for PEI phase.\r
3\r
9095d37b 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
dd51a993 6\r
7\r
dd51a993 8**/\r
9\r
dd51a993 10#include "InternalSmbusLib.h"\r
11\r
12/**\r
13 Executes an SMBUS quick read command.\r
14\r
15 Executes an SMBUS quick read command on the SMBUS device specified by SmBusAddress.\r
16 Only the SMBUS slave address field of SmBusAddress is required.\r
17 If Status is not NULL, then the status of the executed command is returned in Status.\r
18 If PEC is set in SmBusAddress, then ASSERT().\r
19 If Command in SmBusAddress is not zero, then ASSERT().\r
20 If Length in SmBusAddress is not zero, then ASSERT().\r
21 If any reserved bits of SmBusAddress are set, then ASSERT().\r
22\r
2fc59a00 23 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 24 SMBUS Command, SMBUS Data Length, and PEC.\r
25 @param Status Return status for the executed command.\r
26 This is an optional parameter and may be NULL.\r
58380e9c 27 RETURN_SUCCESS: The SMBUS command was executed.\r
9095d37b 28 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 29 SMBUS command.\r
9095d37b
LG
30 RETURN_DEVICE_ERROR: The request was not completed because\r
31 a failure reflected in the Host Status Register bit.\r
32 Device errors are a result of a transaction collision,\r
58380e9c 33 illegal command field, unclaimed cycle\r
71871514 34 (host initiated), or bus errors (collisions).\r
58380e9c 35 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 36\r
37**/\r
38VOID\r
39EFIAPI\r
40SmBusQuickRead (\r
2f88bd3a
MK
41 IN UINTN SmBusAddress,\r
42 OUT RETURN_STATUS *Status OPTIONAL\r
dd51a993 43 )\r
44{\r
45 ASSERT (!SMBUS_LIB_PEC (SmBusAddress));\r
46 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r
47 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
2d8debe7 48 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 49\r
50 InternalSmBusExec (EfiSmbusQuickRead, SmBusAddress, 0, NULL, Status);\r
51}\r
52\r
53/**\r
54 Executes an SMBUS quick write command.\r
55\r
56 Executes an SMBUS quick write command on the SMBUS device specified by SmBusAddress.\r
57 Only the SMBUS slave address field of SmBusAddress is required.\r
58 If Status is not NULL, then the status of the executed command is returned in Status.\r
59 If PEC is set in SmBusAddress, then ASSERT().\r
60 If Command in SmBusAddress is not zero, then ASSERT().\r
61 If Length in SmBusAddress is not zero, then ASSERT().\r
62 If any reserved bits of SmBusAddress are set, then ASSERT().\r
63\r
2fc59a00 64 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 65 SMBUS Command, SMBUS Data Length, and PEC.\r
66 @param Status Return status for the executed command.\r
67 This is an optional parameter and may be NULL.\r
58380e9c 68 RETURN_SUCCESS: The SMBUS command was executed.\r
9095d37b 69 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 70 SMBUS command.\r
9095d37b
LG
71 RETURN_DEVICE_ERROR: The request was not completed because\r
72 a failure reflected in the Host Status Register bit. Device\r
73 errors are a result of a transaction collision, illegal\r
74 command field, unclaimed cycle (host initiated), or bus\r
58380e9c 75 errors (collisions).\r
76 RETURN_UNSUPPORTED:: The SMBus operation is not supported.\r
dd51a993 77\r
78**/\r
79VOID\r
80EFIAPI\r
81SmBusQuickWrite (\r
2f88bd3a
MK
82 IN UINTN SmBusAddress,\r
83 OUT RETURN_STATUS *Status OPTIONAL\r
dd51a993 84 )\r
85{\r
86 ASSERT (!SMBUS_LIB_PEC (SmBusAddress));\r
87 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r
88 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
2d8debe7 89 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 90\r
91 InternalSmBusExec (EfiSmbusQuickWrite, SmBusAddress, 0, NULL, Status);\r
92}\r
93\r
94/**\r
95 Executes an SMBUS receive byte command.\r
96\r
97 Executes an SMBUS receive byte command on the SMBUS device specified by SmBusAddress.\r
98 Only the SMBUS slave address field of SmBusAddress is required.\r
99 The byte received from the SMBUS is returned.\r
100 If Status is not NULL, then the status of the executed command is returned in Status.\r
101 If Command in SmBusAddress is not zero, then ASSERT().\r
102 If Length in SmBusAddress is not zero, then ASSERT().\r
103 If any reserved bits of SmBusAddress are set, then ASSERT().\r
104\r
2fc59a00 105 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 106 SMBUS Command, SMBUS Data Length, and PEC.\r
107 @param Status Return status for the executed command.\r
108 This is an optional parameter and may be NULL.\r
58380e9c 109 RETURN_SUCCESS: The SMBUS command was executed.\r
9095d37b 110 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 111 SMBUS command.\r
9095d37b
LG
112 RETURN_DEVICE_ERROR: The request was not completed because\r
113 a failure reflected in the Host Status Register bit.\r
114 Device errors are a result of a transaction collision,\r
58380e9c 115 illegal command field, unclaimed cycle (host initiated),\r
116 or bus errors (collisions).\r
117 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)\r
118 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 119\r
120 @return The byte received from the SMBUS.\r
121\r
122**/\r
123UINT8\r
124EFIAPI\r
125SmBusReceiveByte (\r
126 IN UINTN SmBusAddress,\r
127 OUT RETURN_STATUS *Status OPTIONAL\r
128 )\r
129{\r
2f88bd3a 130 UINT8 Byte;\r
dd51a993 131\r
132 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r
133 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
2d8debe7 134 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 135\r
136 InternalSmBusExec (EfiSmbusReceiveByte, SmBusAddress, 1, &Byte, Status);\r
137\r
138 return Byte;\r
139}\r
140\r
141/**\r
142 Executes an SMBUS send byte command.\r
143\r
144 Executes an SMBUS send byte command on the SMBUS device specified by SmBusAddress.\r
145 The byte specified by Value is sent.\r
146 Only the SMBUS slave address field of SmBusAddress is required. Value is returned.\r
147 If Status is not NULL, then the status of the executed command is returned in Status.\r
148 If Command in SmBusAddress is not zero, then ASSERT().\r
149 If Length in SmBusAddress is not zero, then ASSERT().\r
150 If any reserved bits of SmBusAddress are set, then ASSERT().\r
151\r
2fc59a00 152 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 153 SMBUS Command, SMBUS Data Length, and PEC.\r
154 @param Value The 8-bit value to send.\r
155 @param Status Return status for the executed command.\r
156 This is an optional parameter and may be NULL.\r
58380e9c 157 RETURN_SUCCESS: The SMBUS command was executed.\r
9095d37b 158 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 159 SMBUS command.\r
9095d37b
LG
160 RETURN_DEVICE_ERROR: The request was not completed because\r
161 a failure reflected in the Host Status Register bit. Device\r
162 errors are a result of a transaction collision, illegal\r
163 command field, unclaimed cycle (host initiated), or bus\r
58380e9c 164 errors (collisions).\r
165 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)\r
166 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 167\r
168 @return The parameter of Value.\r
169\r
170**/\r
171UINT8\r
172EFIAPI\r
173SmBusSendByte (\r
174 IN UINTN SmBusAddress,\r
175 IN UINT8 Value,\r
176 OUT RETURN_STATUS *Status OPTIONAL\r
177 )\r
178{\r
2f88bd3a 179 UINT8 Byte;\r
dd51a993 180\r
181 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);\r
182 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
2d8debe7 183 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 184\r
2f88bd3a 185 Byte = Value;\r
dd51a993 186 InternalSmBusExec (EfiSmbusSendByte, SmBusAddress, 1, &Byte, Status);\r
187\r
188 return Value;\r
189}\r
190\r
191/**\r
192 Executes an SMBUS read data byte command.\r
193\r
194 Executes an SMBUS read data byte command on the SMBUS device specified by SmBusAddress.\r
195 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
196 The 8-bit value read from the SMBUS is returned.\r
197 If Status is not NULL, then the status of the executed command is returned in Status.\r
198 If Length in SmBusAddress is not zero, then ASSERT().\r
199 If any reserved bits of SmBusAddress are set, then ASSERT().\r
200\r
2fc59a00 201 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
dd51a993 202 SMBUS Command, SMBUS Data Length, and PEC.\r
71871514 203 @param Status Return status for the executed command.\r
204 This is an optional parameter and may be NULL.\r
58380e9c 205 RETURN_SUCCESS: The SMBUS command was executed.\r
9095d37b 206 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 207 SMBUS command.\r
9095d37b
LG
208 RETURN_DEVICE_ERROR: The request was not completed because\r
209 a failure reflected in the Host Status Register bit.\r
210 Device errors are a result of a transaction collision,\r
58380e9c 211 illegal command field, unclaimed cycle (host initiated),\r
212 or bus errors (collisions).\r
213 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)\r
214 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 215\r
216 @return The byte read from the SMBUS.\r
217\r
218**/\r
219UINT8\r
220EFIAPI\r
221SmBusReadDataByte (\r
222 IN UINTN SmBusAddress,\r
223 OUT RETURN_STATUS *Status OPTIONAL\r
224 )\r
225{\r
2f88bd3a 226 UINT8 Byte;\r
dd51a993 227\r
228 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
2d8debe7 229 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 230\r
231 InternalSmBusExec (EfiSmbusReadByte, SmBusAddress, 1, &Byte, Status);\r
bad46384 232\r
dd51a993 233 return Byte;\r
234}\r
235\r
236/**\r
237 Executes an SMBUS write data byte command.\r
238\r
239 Executes an SMBUS write data byte command on the SMBUS device specified by SmBusAddress.\r
240 The 8-bit value specified by Value is written.\r
241 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
242 Value is returned.\r
243 If Status is not NULL, then the status of the executed command is returned in Status.\r
244 If Length in SmBusAddress is not zero, then ASSERT().\r
245 If any reserved bits of SmBusAddress are set, then ASSERT().\r
246\r
2fc59a00 247 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 248 SMBUS Command, SMBUS Data Length, and PEC.\r
249 @param Value The 8-bit value to write.\r
250 @param Status Return status for the executed command.\r
251 This is an optional parameter and may be NULL.\r
58380e9c 252 RETURN_SUCCESS: The SMBUS command was executed.\r
9095d37b 253 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 254 SMBUS command.\r
9095d37b
LG
255 RETURN_DEVICE_ERROR: The request was not completed because\r
256 a failure reflected in the Host Status Register bit.\r
257 Device errors are a result of a transaction collision,\r
58380e9c 258 illegal command field, unclaimed cycle (host initiated),\r
259 or bus errors (collisions).\r
260 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)\r
261 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 262\r
263 @return The parameter of Value.\r
264\r
265**/\r
266UINT8\r
267EFIAPI\r
268SmBusWriteDataByte (\r
269 IN UINTN SmBusAddress,\r
270 IN UINT8 Value,\r
271 OUT RETURN_STATUS *Status OPTIONAL\r
272 )\r
273{\r
2f88bd3a 274 UINT8 Byte;\r
dd51a993 275\r
276 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
2d8debe7 277 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 278\r
279 Byte = Value;\r
280 InternalSmBusExec (EfiSmbusWriteByte, SmBusAddress, 1, &Byte, Status);\r
bad46384 281\r
dd51a993 282 return Value;\r
283}\r
284\r
285/**\r
286 Executes an SMBUS read data word command.\r
287\r
288 Executes an SMBUS read data word command on the SMBUS device specified by SmBusAddress.\r
289 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
290 The 16-bit value read from the SMBUS is returned.\r
291 If Status is not NULL, then the status of the executed command is returned in Status.\r
292 If Length in SmBusAddress is not zero, then ASSERT().\r
293 If any reserved bits of SmBusAddress are set, then ASSERT().\r
9095d37b 294\r
2fc59a00 295 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 296 SMBUS Command, SMBUS Data Length, and PEC.\r
297 @param Status Return status for the executed command.\r
298 This is an optional parameter and may be NULL.\r
58380e9c 299 RETURN_SUCCESS: The SMBUS command was executed.\r
9095d37b 300 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 301 SMBUS command.\r
9095d37b
LG
302 RETURN_DEVICE_ERROR: The request was not completed because\r
303 a failure reflected in the Host Status Register bit.\r
304 Device errors are a result of a transaction collision,\r
58380e9c 305 illegal command field, unclaimed cycle (host initiated),\r
306 or bus errors (collisions).\r
307 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)\r
308 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 309\r
310 @return The byte read from the SMBUS.\r
311\r
312**/\r
313UINT16\r
314EFIAPI\r
315SmBusReadDataWord (\r
316 IN UINTN SmBusAddress,\r
317 OUT RETURN_STATUS *Status OPTIONAL\r
318 )\r
319{\r
320 UINT16 Word;\r
321\r
322 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
2d8debe7 323 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 324\r
325 InternalSmBusExec (EfiSmbusReadWord, SmBusAddress, 2, &Word, Status);\r
bad46384 326\r
dd51a993 327 return Word;\r
328}\r
329\r
330/**\r
331 Executes an SMBUS write data word command.\r
332\r
333 Executes an SMBUS write data word command on the SMBUS device specified by SmBusAddress.\r
334 The 16-bit value specified by Value is written.\r
335 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
336 Value is returned.\r
337 If Status is not NULL, then the status of the executed command is returned in Status.\r
338 If Length in SmBusAddress is not zero, then ASSERT().\r
339 If any reserved bits of SmBusAddress are set, then ASSERT().\r
340\r
2fc59a00 341 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 342 SMBUS Command, SMBUS Data Length, and PEC.\r
343 @param Value The 16-bit value to write.\r
344 @param Status Return status for the executed command.\r
345 This is an optional parameter and may be NULL.\r
58380e9c 346 RETURN_SUCCESS: The SMBUS command was executed.\r
9095d37b 347 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 348 SMBUS command.\r
9095d37b
LG
349 RETURN_DEVICE_ERROR: The request was not completed because\r
350 a failure reflected in the Host Status Register bit.\r
351 Device errors are a result of a transaction collision,\r
58380e9c 352 illegal command field, unclaimed cycle (host initiated),\r
353 or bus errors (collisions).\r
354 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)\r
355 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 356\r
357 @return The parameter of Value.\r
358\r
359**/\r
360UINT16\r
361EFIAPI\r
362SmBusWriteDataWord (\r
363 IN UINTN SmBusAddress,\r
364 IN UINT16 Value,\r
365 OUT RETURN_STATUS *Status OPTIONAL\r
366 )\r
367{\r
368 UINT16 Word;\r
369\r
370 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
2d8debe7 371 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 372\r
373 Word = Value;\r
374 InternalSmBusExec (EfiSmbusWriteWord, SmBusAddress, 2, &Word, Status);\r
375\r
376 return Value;\r
377}\r
378\r
379/**\r
380 Executes an SMBUS process call command.\r
381\r
382 Executes an SMBUS process call command on the SMBUS device specified by SmBusAddress.\r
383 The 16-bit value specified by Value is written.\r
384 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
385 The 16-bit value returned by the process call command is returned.\r
386 If Status is not NULL, then the status of the executed command is returned in Status.\r
387 If Length in SmBusAddress is not zero, then ASSERT().\r
388 If any reserved bits of SmBusAddress are set, then ASSERT().\r
389\r
2fc59a00 390 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 391 SMBUS Command, SMBUS Data Length, and PEC.\r
392 @param Value The 16-bit value to write.\r
393 @param Status Return status for the executed command.\r
394 This is an optional parameter and may be NULL.\r
58380e9c 395 RETURN_SUCCESS: The SMBUS command was executed.\r
9095d37b 396 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 397 SMBUS command.\r
9095d37b
LG
398 RETURN_DEVICE_ERROR: The request was not completed because\r
399 a failure reflected in the Host Status Register bit.\r
400 Device errors are a result of a transaction collision,\r
58380e9c 401 illegal command field, unclaimed cycle (host initiated),\r
402 or bus errors (collisions).\r
403 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)\r
404 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 405\r
406 @return The 16-bit value returned by the process call command.\r
407\r
408**/\r
409UINT16\r
410EFIAPI\r
411SmBusProcessCall (\r
412 IN UINTN SmBusAddress,\r
413 IN UINT16 Value,\r
414 OUT RETURN_STATUS *Status OPTIONAL\r
415 )\r
416{\r
417 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
2d8debe7 418 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 419\r
420 InternalSmBusExec (EfiSmbusProcessCall, SmBusAddress, 2, &Value, Status);\r
bad46384 421\r
dd51a993 422 return Value;\r
423}\r
424\r
425/**\r
426 Executes an SMBUS read block command.\r
427\r
428 Executes an SMBUS read block command on the SMBUS device specified by SmBusAddress.\r
429 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.\r
430 Bytes are read from the SMBUS and stored in Buffer.\r
431 The number of bytes read is returned, and will never return a value larger than 32-bytes.\r
432 If Status is not NULL, then the status of the executed command is returned in Status.\r
433 It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r
434 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
435 If Length in SmBusAddress is not zero, then ASSERT().\r
436 If Buffer is NULL, then ASSERT().\r
437 If any reserved bits of SmBusAddress are set, then ASSERT().\r
438\r
2fc59a00 439 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 440 SMBUS Command, SMBUS Data Length, and PEC.\r
2fc59a00 441 @param Buffer The pointer to the buffer to store the bytes read from the SMBUS.\r
71871514 442 @param Status Return status for the executed command.\r
443 This is an optional parameter and may be NULL.\r
58380e9c 444 RETURN_SUCCESS: The SMBUS command was executed.\r
9095d37b 445 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 446 SMBUS command.\r
9095d37b
LG
447 RETURN_DEVICE_ERROR: The request was not completed because\r
448 a failure reflected in the Host Status Register bit.\r
449 Device errors are a result of a transaction collision,\r
450 illegal command field, unclaimed cycle (host initiated),\r
58380e9c 451 or bus errors (collisions).\r
452 RETURN_CRC_ERROR: The checksum is not correct. (PEC is incorrect.)\r
453 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 454\r
455 @return The number of bytes read.\r
456\r
457**/\r
458UINTN\r
459EFIAPI\r
460SmBusReadBlock (\r
461 IN UINTN SmBusAddress,\r
462 OUT VOID *Buffer,\r
463 OUT RETURN_STATUS *Status OPTIONAL\r
464 )\r
465{\r
466 ASSERT (Buffer != NULL);\r
467 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);\r
2d8debe7 468 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 469\r
470 return InternalSmBusExec (EfiSmbusReadBlock, SmBusAddress, 0x20, Buffer, Status);\r
471}\r
472\r
473/**\r
474 Executes an SMBUS write block command.\r
475\r
476 Executes an SMBUS write block command on the SMBUS device specified by SmBusAddress.\r
477 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r
478 Bytes are written to the SMBUS from Buffer.\r
479 The number of bytes written is returned, and will never return a value larger than 32-bytes.\r
9095d37b 480 If Status is not NULL, then the status of the executed command is returned in Status.\r
dd51a993 481 If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r
482 If Buffer is NULL, then ASSERT().\r
483 If any reserved bits of SmBusAddress are set, then ASSERT().\r
484\r
2fc59a00 485 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 486 MBUS Command, SMBUS Data Length, and PEC.\r
2fc59a00 487 @param Buffer The pointer to the buffer to store the bytes read from the SMBUS.\r
71871514 488 @param Status Return status for the executed command.\r
489 This is an optional parameter and may be NULL.\r
9095d37b 490 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 491 SMBUS command.\r
9095d37b
LG
492 RETURN_DEVICE_ERROR: The request was not completed because\r
493 a failure reflected in the Host Status Register bit.\r
494 Device errors are a result of a transaction collision,\r
495 illegal command field, unclaimed cycle (host initiated),\r
58380e9c 496 or bus errors (collisions).\r
497 RETURN_CRC_ERROR: The checksum is not correct (PEC is incorrect)\r
498 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 499\r
500 @return The number of bytes written.\r
501\r
502**/\r
503UINTN\r
504EFIAPI\r
505SmBusWriteBlock (\r
506 IN UINTN SmBusAddress,\r
507 OUT VOID *Buffer,\r
508 OUT RETURN_STATUS *Status OPTIONAL\r
509 )\r
510{\r
511 UINTN Length;\r
512\r
513 ASSERT (Buffer != NULL);\r
514 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
515 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
2d8debe7 516 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 517\r
518 Length = SMBUS_LIB_LENGTH (SmBusAddress);\r
519 return InternalSmBusExec (EfiSmbusWriteBlock, SmBusAddress, Length, Buffer, Status);\r
520}\r
521\r
522/**\r
523 Executes an SMBUS block process call command.\r
524\r
525 Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.\r
526 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r
527 Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer.\r
528 If Status is not NULL, then the status of the executed command is returned in Status.\r
529 It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.\r
530 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
531 If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r
532 If WriteBuffer is NULL, then ASSERT().\r
533 If ReadBuffer is NULL, then ASSERT().\r
534 If any reserved bits of SmBusAddress are set, then ASSERT().\r
535\r
2fc59a00 536 @param SmBusAddress The address that encodes the SMBUS Slave Address,\r
71871514 537 SMBUS Command, SMBUS Data Length, and PEC.\r
2fc59a00 538 @param WriteBuffer The pointer to the buffer of bytes to write to the SMBUS.\r
539 @param ReadBuffer The pointer to the buffer of bytes to read from the SMBUS.\r
71871514 540 @param Status Return status for the executed command.\r
541 This is an optional parameter and may be NULL.\r
9095d37b 542 RETURN_TIMEOUT: A timeout occurred while executing the\r
58380e9c 543 SMBUS command.\r
9095d37b
LG
544 RETURN_DEVICE_ERROR: The request was not completed because\r
545 a failure reflected in the Host Status Register bit.\r
546 Device errors are a result of a transaction collision,\r
547 illegal command field, unclaimed cycle (host initiated),\r
58380e9c 548 or bus errors (collisions).\r
549 RETURN_CRC_ERROR The checksum is not correct. (PEC is incorrect.)\r
550 RETURN_UNSUPPORTED: The SMBus operation is not supported.\r
dd51a993 551\r
552 @return The number of bytes written.\r
553\r
554**/\r
555UINTN\r
556EFIAPI\r
557SmBusBlockProcessCall (\r
558 IN UINTN SmBusAddress,\r
559 IN VOID *WriteBuffer,\r
560 OUT VOID *ReadBuffer,\r
561 OUT RETURN_STATUS *Status OPTIONAL\r
562 )\r
563{\r
2f88bd3a 564 UINTN Length;\r
dd51a993 565\r
566 ASSERT (WriteBuffer != NULL);\r
567 ASSERT (ReadBuffer != NULL);\r
568 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
569 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
2d8debe7 570 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress) == 0);\r
dd51a993 571\r
572 Length = SMBUS_LIB_LENGTH (SmBusAddress);\r
573 //\r
574 // Assuming that ReadBuffer is large enough to save another memory copy.\r
575 //\r
576 ReadBuffer = CopyMem (ReadBuffer, WriteBuffer, Length);\r
577 return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, ReadBuffer, Status);\r
578}\r