]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/PeiSmbusLib/SmbusLib.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / PeiSmbusLib / SmbusLib.c
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 PeiSmbus.c
16
17 Abstract:
18
19 Pei Smbus Lib Interfaces
20
21 --*/
22
23 #include "PeiSmbusLibInternal.h"
24
25 /**
26 Executes an SMBUS quick read command.
27
28 Executes an SMBUS quick read command on the SMBUS device specified by SmBusAddress.
29 Only the SMBUS slave address field of SmBusAddress is required.
30 If Status is not NULL, then the status of the executed command is returned in Status.
31 If PEC is set in SmBusAddress, then ASSERT().
32 If Command in SmBusAddress is not zero, then ASSERT().
33 If Length in SmBusAddress is not zero, then ASSERT().
34 If any reserved bits of SmBusAddress are set, then ASSERT().
35
36 @param SmBusAddress Address that encodes the SMBUS Slave Address,
37 SMBUS Command, SMBUS Data Length, and PEC.
38 @param Status Return status for the executed command.
39 This is an optional parameter and may be NULL.
40
41 **/
42 VOID
43 EFIAPI
44 SmBusQuickRead (
45 IN UINTN SmBusAddress,
46 OUT RETURN_STATUS *Status OPTIONAL
47 )
48 {
49 ASSERT (!SMBUS_LIB_PEC (SmBusAddress));
50 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);
51 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);
52 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
53
54 InternalSmBusExec (EfiSmbusQuickRead, SmBusAddress, 0, NULL, Status);
55 }
56
57 /**
58 Executes an SMBUS quick write command.
59
60 Executes an SMBUS quick write 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().
67
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.
72
73 **/
74 VOID
75 EFIAPI
76 SmBusQuickWrite (
77 IN UINTN SmBusAddress,
78 OUT RETURN_STATUS *Status OPTIONAL
79 )
80 {
81 ASSERT (!SMBUS_LIB_PEC (SmBusAddress));
82 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);
83 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);
84 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
85
86 InternalSmBusExec (EfiSmbusQuickWrite, SmBusAddress, 0, NULL, Status);
87 }
88
89 /**
90 Executes an SMBUS receive byte command.
91
92 Executes an SMBUS receive byte command on the SMBUS device specified by SmBusAddress.
93 Only the SMBUS slave address field of SmBusAddress is required.
94 The byte received from the SMBUS is returned.
95 If Status is not NULL, then the status of the executed command is returned in Status.
96 If Command in SmBusAddress is not zero, then ASSERT().
97 If Length in SmBusAddress is not zero, then ASSERT().
98 If any reserved bits of SmBusAddress are set, then ASSERT().
99
100 @param SmBusAddress Address that encodes the SMBUS Slave Address,
101 SMBUS Command, SMBUS Data Length, and PEC.
102 @param Status Return status for the executed command.
103 This is an optional parameter and may be NULL.
104
105 @return The byte received from the SMBUS.
106
107 **/
108 UINT8
109 EFIAPI
110 SmBusReceiveByte (
111 IN UINTN SmBusAddress,
112 OUT RETURN_STATUS *Status OPTIONAL
113 )
114 {
115 UINT8 Byte;
116
117 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);
118 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);
119 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
120
121 InternalSmBusExec (EfiSmbusReceiveByte, SmBusAddress, 1, &Byte, Status);
122
123 return Byte;
124 }
125
126 /**
127 Executes an SMBUS send byte command.
128
129 Executes an SMBUS send byte command on the SMBUS device specified by SmBusAddress.
130 The byte specified by Value is sent.
131 Only the SMBUS slave address field of SmBusAddress is required. Value is returned.
132 If Status is not NULL, then the status of the executed command is returned in Status.
133 If Command in SmBusAddress is not zero, then ASSERT().
134 If Length in SmBusAddress is not zero, then ASSERT().
135 If any reserved bits of SmBusAddress are set, then ASSERT().
136
137 @param SmBusAddress Address that encodes the SMBUS Slave Address,
138 SMBUS Command, SMBUS Data Length, and PEC.
139 @param Value The 8-bit value to send.
140 @param Status Return status for the executed command.
141 This is an optional parameter and may be NULL.
142
143 @return The parameter of Value.
144
145 **/
146 UINT8
147 EFIAPI
148 SmBusSendByte (
149 IN UINTN SmBusAddress,
150 IN UINT8 Value,
151 OUT RETURN_STATUS *Status OPTIONAL
152 )
153 {
154 UINT8 Byte;
155
156 ASSERT (SMBUS_LIB_COMMAND (SmBusAddress) == 0);
157 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);
158 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
159
160 Byte = Value;
161 InternalSmBusExec (EfiSmbusSendByte, SmBusAddress, 1, &Byte, Status);
162
163 return Value;
164 }
165
166 /**
167 Executes an SMBUS read data byte command.
168
169 Executes an SMBUS read data byte command on the SMBUS device specified by SmBusAddress.
170 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
171 The 8-bit value read from the SMBUS is returned.
172 If Status is not NULL, then the status of the executed command is returned in Status.
173 If Length in SmBusAddress is not zero, then ASSERT().
174 If any reserved bits of SmBusAddress are set, then ASSERT().
175
176 @param SmBusAddress Address that encodes the SMBUS Slave Address,
177 SMBUS Command, SMBUS Data Length, and PEC.
178 @param Status Return status for the executed command.
179 This is an optional parameter and may be NULL.
180
181 @return The byte read from the SMBUS.
182
183 **/
184 UINT8
185 EFIAPI
186 SmBusReadDataByte (
187 IN UINTN SmBusAddress,
188 OUT RETURN_STATUS *Status OPTIONAL
189 )
190 {
191 UINT8 Byte;
192
193 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);
194 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
195
196 InternalSmBusExec (EfiSmbusReadByte, SmBusAddress, 1, &Byte, Status);
197
198 return Byte;
199 }
200
201 /**
202 Executes an SMBUS write data byte command.
203
204 Executes an SMBUS write data byte command on the SMBUS device specified by SmBusAddress.
205 The 8-bit value specified by Value is written.
206 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
207 Value is returned.
208 If Status is not NULL, then the status of the executed command is returned in Status.
209 If Length in SmBusAddress is not zero, then ASSERT().
210 If any reserved bits of SmBusAddress are set, then ASSERT().
211
212 @param SmBusAddress Address that encodes the SMBUS Slave Address,
213 SMBUS Command, SMBUS Data Length, and PEC.
214 @param Value The 8-bit value to write.
215 @param Status Return status for the executed command.
216 This is an optional parameter and may be NULL.
217
218 @return The parameter of Value.
219
220 **/
221 UINT8
222 EFIAPI
223 SmBusWriteDataByte (
224 IN UINTN SmBusAddress,
225 IN UINT8 Value,
226 OUT RETURN_STATUS *Status OPTIONAL
227 )
228 {
229 UINT8 Byte;
230
231 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);
232 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
233
234 Byte = Value;
235 InternalSmBusExec (EfiSmbusWriteByte, SmBusAddress, 1, &Byte, Status);
236
237 return Value;
238 }
239
240 /**
241 Executes an SMBUS read data word command.
242
243 Executes an SMBUS read data word command on the SMBUS device specified by SmBusAddress.
244 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
245 The 16-bit value read from the SMBUS is returned.
246 If Status is not NULL, then the status of the executed command is returned in Status.
247 If Length in SmBusAddress is not zero, then ASSERT().
248 If any reserved bits of SmBusAddress are set, then ASSERT().
249
250 @param SmBusAddress Address that encodes the SMBUS Slave Address,
251 SMBUS Command, SMBUS Data Length, and PEC.
252 @param Status Return status for the executed command.
253 This is an optional parameter and may be NULL.
254
255 @return The byte read from the SMBUS.
256
257 **/
258 UINT16
259 EFIAPI
260 SmBusReadDataWord (
261 IN UINTN SmBusAddress,
262 OUT RETURN_STATUS *Status OPTIONAL
263 )
264 {
265 UINT16 Word;
266
267 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);
268 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
269
270 InternalSmBusExec (EfiSmbusReadWord, SmBusAddress, 2, &Word, Status);
271
272 return Word;
273 }
274
275 /**
276 Executes an SMBUS write data word command.
277
278 Executes an SMBUS write data word command on the SMBUS device specified by SmBusAddress.
279 The 16-bit value specified by Value is written.
280 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
281 Value is returned.
282 If Status is not NULL, then the status of the executed command is returned in Status.
283 If Length in SmBusAddress is not zero, then ASSERT().
284 If any reserved bits of SmBusAddress are set, then ASSERT().
285
286 @param SmBusAddress Address that encodes the SMBUS Slave Address,
287 SMBUS Command, SMBUS Data Length, and PEC.
288 @param Value The 16-bit value to write.
289 @param Status Return status for the executed command.
290 This is an optional parameter and may be NULL.
291
292 @return The parameter of Value.
293
294 **/
295 UINT16
296 EFIAPI
297 SmBusWriteDataWord (
298 IN UINTN SmBusAddress,
299 IN UINT16 Value,
300 OUT RETURN_STATUS *Status OPTIONAL
301 )
302 {
303 UINT16 Word;
304
305 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);
306 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
307
308 Word = Value;
309 InternalSmBusExec (EfiSmbusWriteWord, SmBusAddress, 2, &Word, Status);
310
311 return Value;
312 }
313
314 /**
315 Executes an SMBUS process call command.
316
317 Executes an SMBUS process call command on the SMBUS device specified by SmBusAddress.
318 The 16-bit value specified by Value is written.
319 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
320 The 16-bit value returned by the process call command is returned.
321 If Status is not NULL, then the status of the executed command is returned in Status.
322 If Length in SmBusAddress is not zero, then ASSERT().
323 If any reserved bits of SmBusAddress are set, then ASSERT().
324
325 @param SmBusAddress 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
331 @return The 16-bit value returned by the process call command.
332
333 **/
334 UINT16
335 EFIAPI
336 SmBusProcessCall (
337 IN UINTN SmBusAddress,
338 IN UINT16 Value,
339 OUT RETURN_STATUS *Status OPTIONAL
340 )
341 {
342 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);
343 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
344
345 InternalSmBusExec (EfiSmbusProcessCall, SmBusAddress, 2, &Value, Status);
346
347 return Value;
348 }
349
350 /**
351 Executes an SMBUS read block command.
352
353 Executes an SMBUS read block command on the SMBUS device specified by SmBusAddress.
354 Only the SMBUS slave address and SMBUS command fields of SmBusAddress are required.
355 Bytes are read from the SMBUS and stored in Buffer.
356 The number of bytes read is returned, and will never return a value larger than 32-bytes.
357 If Status is not NULL, then the status of the executed command is returned in Status.
358 It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.
359 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.
360 If Length in SmBusAddress is not zero, then ASSERT().
361 If Buffer is NULL, then ASSERT().
362 If any reserved bits of SmBusAddress are set, then ASSERT().
363
364 @param SmBusAddress Address that encodes the SMBUS Slave Address,
365 SMBUS Command, SMBUS Data Length, and PEC.
366 @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.
367 @param Status Return status for the executed command.
368 This is an optional parameter and may be NULL.
369
370 @return The number of bytes read.
371
372 **/
373 UINTN
374 EFIAPI
375 SmBusReadBlock (
376 IN UINTN SmBusAddress,
377 OUT VOID *Buffer,
378 OUT RETURN_STATUS *Status OPTIONAL
379 )
380 {
381 ASSERT (Buffer != NULL);
382 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) == 0);
383 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
384
385 return InternalSmBusExec (EfiSmbusReadBlock, SmBusAddress, 0x20, Buffer, Status);
386 }
387
388 /**
389 Executes an SMBUS write block command.
390
391 Executes an SMBUS write block command on the SMBUS device specified by SmBusAddress.
392 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.
393 Bytes are written to the SMBUS from Buffer.
394 The number of bytes written is returned, and will never return a value larger than 32-bytes.
395 If Status is not NULL, then the status of the executed command is returned in Status.
396 If Length in SmBusAddress is zero or greater than 32, then ASSERT().
397 If Buffer is NULL, then ASSERT().
398 If any reserved bits of SmBusAddress are set, then ASSERT().
399
400 @param SmBusAddress Address that encodes the SMBUS Slave Address,
401 SMBUS Command, SMBUS Data Length, and PEC.
402 @param Buffer Pointer to the buffer to store the bytes read from the SMBUS.
403 @param Status Return status for the executed command.
404 This is an optional parameter and may be NULL.
405
406 @return The number of bytes written.
407
408 **/
409 UINTN
410 EFIAPI
411 SmBusWriteBlock (
412 IN UINTN SmBusAddress,
413 OUT VOID *Buffer,
414 OUT RETURN_STATUS *Status OPTIONAL
415 )
416 {
417 UINTN Length;
418
419 ASSERT (Buffer != NULL);
420 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);
421 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);
422 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
423
424 Length = SMBUS_LIB_LENGTH (SmBusAddress);
425 return InternalSmBusExec (EfiSmbusWriteBlock, SmBusAddress, Length, Buffer, Status);
426 }
427
428 /**
429 Executes an SMBUS block process call command.
430
431 Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.
432 The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.
433 Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer.
434 If Status is not NULL, then the status of the executed command is returned in Status.
435 It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.
436 SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.
437 If Length in SmBusAddress is zero or greater than 32, then ASSERT().
438 If WriteBuffer is NULL, then ASSERT().
439 If ReadBuffer is NULL, then ASSERT().
440 If any reserved bits of SmBusAddress are set, then ASSERT().
441
442 @param SmBusAddress Address that encodes the SMBUS Slave Address,
443 SMBUS Command, SMBUS Data Length, and PEC.
444 @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS.
445 @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS.
446 @param Status Return status for the executed command.
447 This is an optional parameter and may be NULL.
448
449 @return The number of bytes written.
450
451 **/
452 UINTN
453 EFIAPI
454 SmBusBlockProcessCall (
455 IN UINTN SmBusAddress,
456 IN VOID *WriteBuffer,
457 OUT VOID *ReadBuffer,
458 OUT RETURN_STATUS *Status OPTIONAL
459 )
460 {
461 UINTN Length;
462
463 ASSERT (WriteBuffer != NULL);
464 ASSERT (ReadBuffer != NULL);
465 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);
466 ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);
467 ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);
468
469 Length = SMBUS_LIB_LENGTH (SmBusAddress);
470 //
471 // Assuming that ReadBuffer is large enough to save another memory copy.
472 //
473 ReadBuffer = CopyMem (ReadBuffer, WriteBuffer, Length);
474 return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, ReadBuffer, Status);
475 }