]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeSmbusLib/SmbusLib.c
2 Implementation of SmBusLib class library for DXE phase.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "InternalSmbusLib.h"
19 Executes an SMBUS quick read command.
21 Executes an SMBUS quick read command on the SMBUS device specified by SmBusAddress.
22 Only the SMBUS slave address field of SmBusAddress is required.
23 If Status is not NULL, then the status of the executed command is returned in Status.
24 If PEC is set in SmBusAddress, then ASSERT().
25 If Command in SmBusAddress is not zero, then ASSERT().
26 If Length in SmBusAddress is not zero, then ASSERT().
27 If any reserved bits of SmBusAddress are set, then ASSERT().
29 @param SmBusAddress Address that encodes the SMBUS Slave Address,
30 SMBUS Command, SMBUS Data Length, and PEC.
31 @param Status Return status for the executed command.
32 This is an optional parameter and may be NULL.
38 IN UINTN SmBusAddress
,
39 OUT RETURN_STATUS
*Status OPTIONAL
42 ASSERT (!SMBUS_LIB_PEC (SmBusAddress
));
43 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress
) == 0);
44 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
45 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
47 InternalSmBusExec (EfiSmbusQuickRead
, SmBusAddress
, 0, NULL
, Status
);
51 Executes an SMBUS quick write command.
53 Executes an SMBUS quick write command on the SMBUS device specified by SmBusAddress.
54 Only the SMBUS slave address field of SmBusAddress is required.
55 If Status is not NULL, then the status of the executed command is returned in Status.
56 If PEC is set in SmBusAddress, then ASSERT().
57 If Command in SmBusAddress is not zero, then ASSERT().
58 If Length in SmBusAddress is not zero, then ASSERT().
59 If any reserved bits of SmBusAddress are set, then ASSERT().
61 @param SmBusAddress Address that encodes the SMBUS Slave Address,
62 SMBUS Command, SMBUS Data Length, and PEC.
63 @param Status Return status for the executed command.
64 This is an optional parameter and may be NULL.
70 IN UINTN SmBusAddress
,
71 OUT RETURN_STATUS
*Status OPTIONAL
74 ASSERT (!SMBUS_LIB_PEC (SmBusAddress
));
75 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress
) == 0);
76 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
77 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
79 InternalSmBusExec (EfiSmbusQuickWrite
, SmBusAddress
, 0, NULL
, Status
);
83 Executes an SMBUS receive byte command.
85 Executes an SMBUS receive byte command on the SMBUS device specified by SmBusAddress.
86 Only the SMBUS slave address field of SmBusAddress is required.
87 The byte received from the SMBUS is returned.
88 If Status is not NULL, then the status of the executed command is returned in Status.
89 If Command in SmBusAddress is not zero, then ASSERT().
90 If Length in SmBusAddress is not zero, then ASSERT().
91 If any reserved bits of SmBusAddress are set, then ASSERT().
93 @param SmBusAddress Address that encodes the SMBUS Slave Address,
94 SMBUS Command, SMBUS Data Length, and PEC.
95 @param Status Return status for the executed command.
96 This is an optional parameter and may be NULL.
98 @return The byte received from the SMBUS.
104 IN UINTN SmBusAddress
,
105 OUT RETURN_STATUS
*Status OPTIONAL
110 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress
) == 0);
111 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
112 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
114 InternalSmBusExec (EfiSmbusReceiveByte
, SmBusAddress
, 1, &Byte
, Status
);
120 Executes an SMBUS send byte command.
122 Executes an SMBUS send byte command on the SMBUS device specified by SmBusAddress.
123 The byte specified by Value is sent.
124 Only the SMBUS slave address field of SmBusAddress is required. Value is returned.
125 If Status is not NULL, then the status of the executed command is returned in Status.
126 If Command in SmBusAddress is not zero, then ASSERT().
127 If Length in SmBusAddress is not zero, then ASSERT().
128 If any reserved bits of SmBusAddress are set, then ASSERT().
130 @param SmBusAddress Address that encodes the SMBUS Slave Address,
131 SMBUS Command, SMBUS Data Length, and PEC.
132 @param Value The 8-bit value to send.
133 @param Status Return status for the executed command.
134 This is an optional parameter and may be NULL.
136 @return The parameter of Value.
142 IN UINTN SmBusAddress
,
144 OUT RETURN_STATUS
*Status OPTIONAL
149 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress
) == 0);
150 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
151 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
154 InternalSmBusExec (EfiSmbusSendByte
, SmBusAddress
, 1, &Byte
, Status
);
160 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().
169 @param SmBusAddress Address that encodes the SMBUS Slave Address,
170 SMBUS Command, SMBUS Data Length, and PEC.
171 @param Status Return status for the executed command.
172 This is an optional parameter and may be NULL.
174 @return The byte read from the SMBUS.
180 IN UINTN SmBusAddress
,
181 OUT RETURN_STATUS
*Status OPTIONAL
186 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
187 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
189 InternalSmBusExec (EfiSmbusReadByte
, SmBusAddress
, 1, &Byte
, Status
);
195 Executes an SMBUS write data byte command.
197 Executes an SMBUS write data byte command on the SMBUS device specified by SmBusAddress.
198 The 8-bit value specified by Value is written.
199 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
201 If Status is not NULL, then the status of the executed command is returned in Status.
202 If Length in SmBusAddress is not zero, then ASSERT().
203 If any reserved bits of SmBusAddress are set, then ASSERT().
205 @param SmBusAddress Address that encodes the SMBUS Slave Address,
206 SMBUS Command, SMBUS Data Length, and PEC.
207 @param Value The 8-bit value to write.
208 @param Status Return status for the executed command.
209 This is an optional parameter and may be NULL.
211 @return The parameter of Value.
217 IN UINTN SmBusAddress
,
219 OUT RETURN_STATUS
*Status OPTIONAL
224 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
225 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
228 InternalSmBusExec (EfiSmbusWriteByte
, SmBusAddress
, 1, &Byte
, Status
);
234 Executes an SMBUS read data word command.
236 Executes an SMBUS read data word command on the SMBUS device specified by SmBusAddress.
237 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
238 The 16-bit value read from the SMBUS is returned.
239 If Status is not NULL, then the status of the executed command is returned in Status.
240 If Length in SmBusAddress is not zero, then ASSERT().
241 If any reserved bits of SmBusAddress are set, then ASSERT().
243 @param SmBusAddress Address that encodes the SMBUS Slave Address,
244 SMBUS Command, SMBUS Data Length, and PEC.
245 @param Status Return status for the executed command.
246 This is an optional parameter and may be NULL.
248 @return The byte read from the SMBUS.
254 IN UINTN SmBusAddress
,
255 OUT RETURN_STATUS
*Status OPTIONAL
260 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
261 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
263 InternalSmBusExec (EfiSmbusReadWord
, SmBusAddress
, 2, &Word
, Status
);
269 Executes an SMBUS write data word command.
271 Executes an SMBUS write data word command on the SMBUS device specified by SmBusAddress.
272 The 16-bit value specified by Value is written.
273 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
275 If Status is not NULL, then the status of the executed command is returned in Status.
276 If Length in SmBusAddress is not zero, then ASSERT().
277 If any reserved bits of SmBusAddress are set, then ASSERT().
279 @param SmBusAddress Address that encodes the SMBUS Slave Address,
280 SMBUS Command, SMBUS Data Length, and PEC.
281 @param Value The 16-bit value to write.
282 @param Status Return status for the executed command.
283 This is an optional parameter and may be NULL.
285 @return The parameter of Value.
291 IN UINTN SmBusAddress
,
293 OUT RETURN_STATUS
*Status OPTIONAL
298 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
299 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
302 InternalSmBusExec (EfiSmbusWriteWord
, SmBusAddress
, 2, &Word
, Status
);
308 Executes an SMBUS process call command.
310 Executes an SMBUS process call command on the SMBUS device specified by SmBusAddress.
311 The 16-bit value specified by Value is written.
312 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
313 The 16-bit value returned by the process call command is returned.
314 If Status is not NULL, then the status of the executed command is returned in Status.
315 If Length in SmBusAddress is not zero, then ASSERT().
316 If any reserved bits of SmBusAddress are set, then ASSERT().
318 @param SmBusAddress Address that encodes the SMBUS Slave Address,
319 SMBUS Command, SMBUS Data Length, and PEC.
320 @param Value The 16-bit value to write.
321 @param Status Return status for the executed command.
322 This is an optional parameter and may be NULL.
324 @return The 16-bit value returned by the process call command.
330 IN UINTN SmBusAddress
,
332 OUT RETURN_STATUS
*Status OPTIONAL
335 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
336 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
338 InternalSmBusExec (EfiSmbusProcessCall
, SmBusAddress
, 2, &Value
, Status
);
344 Executes an SMBUS read block command.
346 Executes an SMBUS read block command on the SMBUS device specified by SmBusAddress.
347 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
348 Bytes are read from the SMBUS and stored in Buffer.
349 The number of bytes read is returned, and will never return a value larger than 32-bytes.
350 If Status is not NULL, then the status of the executed command is returned in Status.
351 It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
352 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.
353 If Length in SmBusAddress is not zero, then ASSERT().
354 If Buffer is NULL, then ASSERT().
355 If any reserved bits of SmBusAddress are set, then ASSERT().
357 @param SmBusAddress Address that encodes the SMBUS Slave Address,
358 SMBUS Command, SMBUS Data Length, and PEC.
359 @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.
360 @param Status Return status for the executed command.
361 This is an optional parameter and may be NULL.
363 @return The number of bytes read.
369 IN UINTN SmBusAddress
,
371 OUT RETURN_STATUS
*Status OPTIONAL
374 ASSERT (Buffer
!= NULL
);
375 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) == 0);
376 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
378 return InternalSmBusExec (EfiSmbusReadBlock
, SmBusAddress
, 0x20, Buffer
, Status
);
382 Executes an SMBUS write block command.
384 Executes an SMBUS write block command on the SMBUS device specified by SmBusAddress.
385 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.
386 Bytes are written to the SMBUS from Buffer.
387 The number of bytes written is returned, and will never return a value larger than 32-bytes.
388 If Status is not NULL, then the status of the executed command is returned in Status.
389 If Length in SmBusAddress is zero or greater than 32, then ASSERT().
390 If Buffer is NULL, then ASSERT().
391 If any reserved bits of SmBusAddress are set, then ASSERT().
393 @param SmBusAddress Address that encodes the SMBUS Slave Address,
394 SMBUS Command, SMBUS Data Length, and PEC.
395 @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.
396 @param Status Return status for the executed command.
397 This is an optional parameter and may be NULL.
399 @return The number of bytes written.
405 IN UINTN SmBusAddress
,
407 OUT RETURN_STATUS
*Status OPTIONAL
412 ASSERT (Buffer
!= NULL
);
413 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) >= 1);
414 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) <= 32);
415 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
417 Length
= SMBUS_LIB_LENGTH (SmBusAddress
);
418 return InternalSmBusExec (EfiSmbusWriteBlock
, SmBusAddress
, Length
, Buffer
, Status
);
422 Executes an SMBUS block process call command.
424 Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.
425 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.
426 Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer.
427 If Status is not NULL, then the status of the executed command is returned in Status.
428 It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.
429 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.
430 If Length in SmBusAddress is zero or greater than 32, then ASSERT().
431 If WriteBuffer is NULL, then ASSERT().
432 If ReadBuffer is NULL, then ASSERT().
433 If any reserved bits of SmBusAddress are set, then ASSERT().
435 @param SmBusAddress Address that encodes the SMBUS Slave Address,
436 SMBUS Command, SMBUS Data Length, and PEC.
437 @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS.
438 @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS.
439 @param Status Return status for the executed command.
440 This is an optional parameter and may be NULL.
442 @return The number of bytes written.
447 SmBusBlockProcessCall (
448 IN UINTN SmBusAddress
,
449 IN VOID
*WriteBuffer
,
450 OUT VOID
*ReadBuffer
,
451 OUT RETURN_STATUS
*Status OPTIONAL
456 ASSERT (WriteBuffer
!= NULL
);
457 ASSERT (ReadBuffer
!= NULL
);
458 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) >= 1);
459 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress
) <= 32);
460 ASSERT (SMBUS_LIB_RESERVED (SmBusAddress
) == 0);
462 Length
= SMBUS_LIB_LENGTH (SmBusAddress
);
464 // Assuming that ReadBuffer is large enough to save another memory copy.
466 ReadBuffer
= CopyMem (ReadBuffer
, WriteBuffer
, Length
);
467 return InternalSmBusExec (EfiSmbusBWBRProcessCall
, SmBusAddress
, Length
, ReadBuffer
, Status
);