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