]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiSmbusLib/PeiSmbusLib.c
Initial import.
[mirror_edk2.git] / MdePkg / Library / PeiSmbusLib / PeiSmbusLib.c
1 /** @file
2 Implementation of SmBusLib class library for PEI phase.
3
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
9
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.
12
13
14 Module Name: PeiSmbusLib.c
15
16 **/
17
18 #include "InternalSmbusLib.h"
19
20 /**
21 Gets Smbus PPIs.
22
23 This internal function retrieves Smbus PPI from PPI database.
24
25 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES published by the PEI Foundation.
26
27 @return The pointer to Smbus PPI.
28
29 **/
30 EFI_PEI_SMBUS_PPI *
31 InternalGetSmbusPpi (
32 EFI_PEI_SERVICES **PeiServices
33 )
34 {
35 EFI_STATUS Status;
36 EFI_PEI_SMBUS_PPI *SmbusPpi;
37
38 Status = (*PeiServices)->LocatePpi (PeiServices, &gEfiPeiSmbusPpiGuid, 0, NULL, (VOID **) &SmbusPpi);
39 ASSERT_EFI_ERROR (Status);
40 ASSERT (SmbusPpi != NULL);
41
42 return SmbusPpi;
43 }
44
45 /**
46 Executes an SMBus operation to an SMBus controller.
47
48 This function provides a standard way to execute Smbus script
49 as defined in the SmBus Specification. The data can either be of
50 the Length byte, word, or a block of data.
51
52 @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to
53 execute the SMBus transactions.
54 @param SmBusAddress Address that encodes the SMBUS Slave Address,
55 SMBUS Command, SMBUS Data Length, and PEC.
56 @param Length Signifies the number of bytes that this operation will do. The maximum number of
57 bytes can be revision specific and operation specific.
58 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations
59 require this argument. The length of this buffer is identified by Length.
60 @param Status Return status for the executed command.
61 This is an optional parameter and may be NULL.
62
63 @return The actual number of bytes that are executed for this operation..
64
65 **/
66 UINTN
67 InternalSmBusExec (
68 IN EFI_SMBUS_OPERATION SmbusOperation,
69 IN UINTN SmBusAddress,
70 IN UINTN Length,
71 IN VOID *Buffer,
72 OUT RETURN_STATUS *Status OPTIONAL
73 )
74 {
75 EFI_PEI_SMBUS_PPI *SmbusPpi;
76 EFI_PEI_SERVICES **PeiServices;
77 RETURN_STATUS ReturnStatus;
78 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
79
80 PeiServices = GetPeiServicesTablePointer ();
81 SmbusPpi = InternalGetSmbusPpi (PeiServices);
82 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
83
84 ReturnStatus = SmbusPpi->Execute (
85 PeiServices,
86 SmbusPpi,
87 SmbusDeviceAddress,
88 SMBUS_LIB_COMMAND (SmBusAddress),
89 SmbusOperation,
90 SMBUS_LIB_PEC (SmBusAddress),
91 &Length,
92 Buffer
93 );
94 if (Status != NULL) {
95 *Status = ReturnStatus;
96 }
97
98 return Length;
99 }
100
101 /**
102 Assigns an SMBUS slave addresses.
103
104 Assigns the SMBUS device specified by Uuid the slave address specified by SmBusAddress.
105 The status of the executed command is returned.
106 If Command in SmBusAddress is not zero, then ASSERT().
107 If Length in SmBusAddress is not zero, then ASSERT().
108 If PEC in SmBusAddress is set, then ASSERT().
109 If any reserved bits of SmBusAddress are set, then ASSERT().
110
111 @param SmBusAddress Address that encodes the SMBUS Slave Address,
112 SMBUS Command, SMBUS Data Length, and PEC.
113 @param Uuid Pointer to the UUID of the device to assign a slave address.
114 It will assign to all SMBUS slave devices if it is NULL.
115
116 @retval RETURN_SUCCESS The SMBUS command was executed.
117 @retval RETURN_TIMEOUT A timeout occurred while executing the SMBUS command.
118 @retval RETURN_DEVICE_ERROR The request was not completed because a failure reflected
119 in the Host Status Register bit.
120 Device errors are a result of a transaction collision, illegal command field,
121 unclaimed cycle (host initiated), or bus errors (collisions).
122
123 **/
124 RETURN_STATUS
125 InternalSmBusArpDevice (
126 IN UINTN SmBusAddress,
127 IN CONST GUID *Uuid OPTIONAL
128 )
129 {
130 EFI_PEI_SMBUS_PPI *SmbusPpi;
131 EFI_PEI_SERVICES **PeiServices;
132 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
133
134 PeiServices = GetPeiServicesTablePointer ();
135 SmbusPpi = InternalGetSmbusPpi (PeiServices);
136
137 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
138 return (RETURN_STATUS) SmbusPpi->ArpDevice (
139 PeiServices,
140 SmbusPpi,
141 (BOOLEAN) (Uuid == NULL),
142 (EFI_SMBUS_UDID *) Uuid,
143 &SmbusDeviceAddress
144 );
145 }
146
147 /**
148 Retrieves the mapping of all the SMBus devices.
149
150 The GetArpMap() function returns the mapping of all the SMBus devices
151 that are enumerated by the SMBus host driver.
152
153 @param Length Size of the buffer that contains the SMBus device map.
154 @param SmbusDeviceMap The pointer to the device map as enumerated by the SMBus controller driver.
155
156 @retval RETURN_SUCCESS The SMBUS command was executed.
157 @retval RETURN_TIMEOUT A timeout occurred while executing the SMBUS command.
158 @retval RETURN_DEVICE_ERROR The request was not completed because a failure reflected
159 in the Host Status Register bit.
160 Device errors are a result of a transaction collision, illegal command field,
161 unclaimed cycle (host initiated), or bus errors (collisions).
162
163 **/
164 RETURN_STATUS
165 InternalGetArpMap (
166 OUT UINTN *Length,
167 OUT EFI_SMBUS_DEVICE_MAP **SmbusDeviceMap
168 )
169 {
170 EFI_PEI_SMBUS_PPI *SmbusPpi;
171 EFI_PEI_SERVICES **PeiServices;
172
173 PeiServices = GetPeiServicesTablePointer ();
174 SmbusPpi = InternalGetSmbusPpi (PeiServices);
175
176 return (RETURN_STATUS) SmbusPpi->GetArpMap (PeiServices, SmbusPpi, Length, SmbusDeviceMap);
177 }