]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Implementation of SmBusLib class library for PEI phase.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
7 | **/\r | |
8 | \r | |
9 | #include "InternalSmbusLib.h"\r | |
10 | \r | |
11 | /**\r | |
12 | Gets Smbus PPIs.\r | |
13 | \r | |
14 | This internal function retrieves Smbus PPI from PPI database.\r | |
15 | If gEfiPeiSmbusPpiGuid can not be located, then ASSERT()\r | |
16 | \r | |
17 | @return The pointer to Smbus PPI.\r | |
18 | \r | |
19 | **/\r | |
20 | EFI_PEI_SMBUS_PPI *\r | |
21 | InternalGetSmbusPpi (\r | |
22 | VOID\r | |
23 | )\r | |
24 | {\r | |
25 | EFI_STATUS Status;\r | |
26 | EFI_PEI_SMBUS_PPI *SmbusPpi;\r | |
27 | \r | |
28 | Status = PeiServicesLocatePpi (&gEfiPeiSmbusPpiGuid, 0, NULL, (VOID **) &SmbusPpi);\r | |
29 | ASSERT_EFI_ERROR (Status);\r | |
30 | ASSERT (SmbusPpi != NULL);\r | |
31 | \r | |
32 | return SmbusPpi;\r | |
33 | }\r | |
34 | \r | |
35 | /**\r | |
36 | Executes an SMBus operation to an SMBus controller.\r | |
37 | \r | |
38 | This function provides a standard way to execute Smbus script\r | |
39 | as defined in the SmBus Specification. The data can either be of\r | |
40 | the Length byte, word, or a block of data.\r | |
41 | \r | |
42 | @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to\r | |
43 | execute the SMBus transactions.\r | |
44 | @param SmBusAddress Address that encodes the SMBUS Slave Address,\r | |
45 | SMBUS Command, SMBUS Data Length, and PEC.\r | |
46 | @param Length Signifies the number of bytes that this operation will do. The maximum number of\r | |
47 | bytes can be revision specific and operation specific.\r | |
48 | @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations\r | |
49 | require this argument. The length of this buffer is identified by Length.\r | |
50 | @param Status Return status for the executed command.\r | |
51 | This is an optional parameter and may be NULL.\r | |
52 | \r | |
53 | @return The actual number of bytes that are executed for this operation..\r | |
54 | \r | |
55 | **/\r | |
56 | UINTN\r | |
57 | InternalSmBusExec (\r | |
58 | IN EFI_SMBUS_OPERATION SmbusOperation,\r | |
59 | IN UINTN SmBusAddress,\r | |
60 | IN UINTN Length,\r | |
61 | IN OUT VOID *Buffer,\r | |
62 | OUT RETURN_STATUS *Status OPTIONAL\r | |
63 | )\r | |
64 | {\r | |
65 | EFI_PEI_SMBUS_PPI *SmbusPpi;\r | |
66 | CONST EFI_PEI_SERVICES **PeiServices;\r | |
67 | RETURN_STATUS ReturnStatus;\r | |
68 | EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;\r | |
69 | \r | |
70 | PeiServices = GetPeiServicesTablePointer ();\r | |
71 | SmbusPpi = InternalGetSmbusPpi ();\r | |
72 | SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);\r | |
73 | \r | |
74 | ReturnStatus = SmbusPpi->Execute (\r | |
75 | (EFI_PEI_SERVICES **) PeiServices,\r | |
76 | SmbusPpi,\r | |
77 | SmbusDeviceAddress,\r | |
78 | SMBUS_LIB_COMMAND (SmBusAddress),\r | |
79 | SmbusOperation,\r | |
80 | SMBUS_LIB_PEC (SmBusAddress),\r | |
81 | &Length,\r | |
82 | Buffer\r | |
83 | );\r | |
84 | if (Status != NULL) {\r | |
85 | *Status = ReturnStatus;\r | |
86 | }\r | |
87 | \r | |
88 | return Length;\r | |
89 | }\r |