SmbusLib.c 25 KB

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