1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
/** @file
PCH Smbus PEIM. This file is used when we want ARP support.
@copyright
Copyright (c) 2009 - 2012 Intel Corporation. All rights reserved
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
This file contains an 'Intel Peripheral Driver' and uniquely
identified as "Intel Reference Module" and is
licensed for Intel CPUs and chipsets under the terms of your
license agreement with Intel or your vendor. This file may
be modified by the user, subject to additional terms of the
license agreement
**/
#include "PchSmbus.h"
static EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEndOfPeiSignalPpiGuid,
EndOfPeiCallback
};
EFI_GUID mEfiSmbusArpMapGuid = EFI_SMBUS_ARP_MAP_GUID;
/**
Set Slave address for an Smbus device with a known UDID or perform a general
ARP of all devices.
@param[in] PeiServices Pointer to the PEI Services table.
@param[in] This Pointer to the instance of the PEI_SMBUS_PPI.
@param[in] ArpAll If TRUE, do a full ARP. Otherwise, just ARP the specified UDID.
@param[in] SmbusUdid When doing a directed ARP, ARP the device with this UDID.
@param[in, out] SlaveAddress Buffer to store new Slave Address during directed ARP.
@exception EFI_UNSUPPORTED This functionality is not supported
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
EFIAPI
SmbusArpDevice (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_SMBUS_PPI * This,
IN BOOLEAN ArpAll,
IN EFI_SMBUS_UDID * SmbusUdid OPTIONAL,
IN OUT EFI_SMBUS_DEVICE_ADDRESS * SlaveAddress OPTIONAL
)
{
SMBUS_INSTANCE *Private;
EFI_STATUS Status;
UINT8 OldMapEntries;
DEBUG ((EFI_D_INFO, "PEI SmbusArpDevice() Start\n"));
Private = SMBUS_PRIVATE_DATA_FROM_PPI_THIS (This);
OldMapEntries = Private->DeviceMapEntries;
if (ArpAll) {
Status = SmbusFullArp (Private);
} else {
if ((SmbusUdid == NULL) || (SlaveAddress == NULL)) {
return EFI_INVALID_PARAMETER;
}
Status = SmbusDirectedArp (Private, SmbusUdid, SlaveAddress);
}
if (EFI_ERROR (Status)) {
return Status;
}
///
/// If we just added the first entry in the device map, set up a callback so
/// we can pass the map to DXE via a HOB at the end of PEI.
///
if ((OldMapEntries == 0) && (Private->DeviceMapEntries > 0)) {
Status = (**PeiServices).NotifyPpi (PeiServices, &mNotifyList);
ASSERT_EFI_ERROR (Status);
}
DEBUG ((EFI_D_INFO, "PEI SmbusArpDevice() End\n"));
return EFI_SUCCESS;
}
/**
Get a pointer to the assigned mappings of UDID's to Slave Addresses.
@param[in] PeiServices Pointer to the PEI Services table.
@param[in] This Pointer to the instance of the PEI_SMBUS_PPI.
@param[in, out] Length Buffer to contain the lenght of the Device Map.
@param[in, out] SmbusDeviceMap Buffer to contian a pointer to the Device Map.
@exception EFI_UNSUPPORTED This functionality is not supported
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
EFIAPI
SmbusGetArpMap (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_SMBUS_PPI *This,
IN OUT UINTN *Length,
IN OUT EFI_SMBUS_DEVICE_MAP **SmbusDeviceMap
)
{
SMBUS_INSTANCE *Private;
Private = SMBUS_PRIVATE_DATA_FROM_PPI_THIS (This);
*Length = Private->DeviceMapEntries * sizeof (EFI_SMBUS_DEVICE_MAP);
*SmbusDeviceMap = Private->DeviceMap;
return EFI_SUCCESS;
}
/**
Register a callback in the event of a Host Notify command being sent by a
specified Slave Device.
@param[in] PeiServices The general PEI Services
@param[in] This The PPI instance
@param[in] SlaveAddress Address of the device whose Host Notify command we want to trap.
@param[in] Data Data of the Host Notify command we want to trap.
@param[in] NotifyFunction Function to be called in the event the desired Host Notify command occurs.
@exception EFI_UNSUPPORTED This functionality is not supported
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
EFIAPI
SmbusNotify (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_SMBUS_PPI *This,
IN EFI_SMBUS_DEVICE_ADDRESS SlaveAddress,
IN UINTN Data,
IN EFI_PEI_SMBUS_NOTIFY_FUNCTION NotifyFunction
)
{
SMBUS_INSTANCE *Private;
DEBUG ((EFI_D_INFO, "PEI SmbusNotify() Start\n"));
Private = SMBUS_PRIVATE_DATA_FROM_PPI_THIS (This);
if (NotifyFunction == NULL) {
return EFI_INVALID_PARAMETER;
}
///
/// NOTE: Currently there is no periodic event in PEI.
/// So we just check the Notification at the end of in each
/// Smbus.Execute function.
///
if (Private->NotifyFunctionNum >= MAX_SMBUS_NOTIFICATION) {
return EFI_OUT_OF_RESOURCES;
}
Private->NotifyFunctionList[Private->NotifyFunctionNum].SlaveAddress.SmbusDeviceAddress = SlaveAddress.SmbusDeviceAddress;
Private->NotifyFunctionList[Private->NotifyFunctionNum].Data = Data;
Private->NotifyFunctionList[Private->NotifyFunctionNum].NotifyFunction = NotifyFunction;
Private->NotifyFunctionNum++;
///
/// Last step, check notification
///
CheckNotification (Private);
DEBUG ((EFI_D_INFO, "PEI SmbusNotify() End\n"));
return EFI_SUCCESS;
}
/**
This function gets called back at the end of PEI if any devices were ARPed
during PEI. It will build a HOB to describe to DXE what devices were ARPed.
@param[in] PeiServices General purpose services available to every PEIM.
@param[in] NotifyDescriptor The notification structure this PEIM registered on install.
@param[in] Ppi The EndOfPeiSignal PPI.
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
EndOfPeiCallback (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
IN VOID *Ppi
)
{
EFI_STATUS Status;
EFI_PEI_PPI_DESCRIPTOR *SmbusDescriptor;
PEI_SMBUS_PPI *SmbusPpi;
SMBUS_INSTANCE *Private;
UINTN BufferSize;
VOID *Hob;
DEBUG ((EFI_D_INFO, "PEI EndOfPeiCallback() Start\n"));
Status = (**PeiServices).LocatePpi (
PeiServices,
&gPeiSmbusPpiGuid, /// GUID
0, /// INSTANCE
&SmbusDescriptor, /// PEI_PPI_DESCRIPTOR
&SmbusPpi /// PPI
);
ASSERT_EFI_ERROR (Status);
Private = SMBUS_PRIVATE_DATA_FROM_DESCRIPTOR_THIS (SmbusDescriptor);
BufferSize = sizeof (EFI_SMBUS_DEVICE_MAP) * Private->DeviceMapEntries;
Hob = BuildGuidDataHob (
&mEfiSmbusArpMapGuid,
Private->DeviceMap,
BufferSize
);
ASSERT (Hob != NULL);
DEBUG ((EFI_D_INFO, "PEI EndOfPeiCallback() End\n"));
return EFI_SUCCESS;
}
/**
Function to be called when SMBus.Execute happens. This will check if
the SMBus Host Controller has received a Host Notify command. If so, it will
see if a notification has been reqested on that event and make any callbacks
that may be necessary.
@param[in] Private Pointer to the SMBUS_INSTANCE
@retval None
**/
VOID
CheckNotification (
IN SMBUS_INSTANCE *Private
)
{
EFI_SMBUS_DEVICE_ADDRESS SlaveAddress;
UINT8 SstsReg;
UINTN Data;
UINTN Index;
DEBUG ((EFI_D_INFO, "PEI CheckNotification() Start\n"));
if (Private->NotifyFunctionNum == 0) {
///
/// Since no one register it, not need to check.
///
return;
}
SstsReg = SmbusIoRead (R_PCH_SMBUS_SSTS);
if (!(SstsReg & B_PCH_SMBUS_HOST_NOTIFY_STS)) {
///
/// Host Notify has not been received
///
return;
}
///
/// There was a Host Notify, see if any one wants to know about it
///
SlaveAddress.SmbusDeviceAddress = (SmbusIoRead (R_PCH_SMBUS_NDA)) >> 1;
for (Index = 0; Index < Private->NotifyFunctionNum; Index++) {
if (Private->NotifyFunctionList[Index].SlaveAddress.SmbusDeviceAddress == SlaveAddress.SmbusDeviceAddress) {
Data = (SmbusIoRead (R_PCH_SMBUS_NDHB) << 8) + (SmbusIoRead (R_PCH_SMBUS_NDLB));
if ((UINT16) Private->NotifyFunctionList[Index].Data == (UINT16) Data) {
///
/// We have a match, notify the requested function
///
Private->NotifyFunctionList[Index].NotifyFunction (
Private->PeiServices,
&Private->SmbusPpi,
SlaveAddress,
Data
);
}
}
}
///
/// Clear the Notify Status bit and exit.
///
SmbusIoWrite (R_PCH_SMBUS_SSTS, B_PCH_SMBUS_HOST_NOTIFY_STS);
DEBUG ((EFI_D_INFO, "PEI CheckNotification() End\n"));
}
|