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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
/** @file
Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Dimm.c
Abstract:
PPI for reading SPD modules on DIMMs.
--*/
//
// Header Files
//
#include "Platformearlyinit.h"
#define DIMM_SOCKETS 4 // Total number of DIMM sockets allowed on
// the platform
#define DIMM_SEGMENTS 1 // Total number of Segments Per DIMM.
#define MEMORY_CHANNELS 2 // Total number of memory channels
// populated on the system board
//
// Prototypes
//
EFI_STATUS
EFIAPI
GetDimmState (
IN EFI_PEI_SERVICES **PeiServices,
IN PEI_PLATFORM_DIMM_PPI *This,
IN UINT8 Dimm,
OUT PEI_PLATFORM_DIMM_STATE *State
);
EFI_STATUS
EFIAPI
SetDimmState (
IN EFI_PEI_SERVICES **PeiServices,
IN PEI_PLATFORM_DIMM_PPI *This,
IN UINT8 Dimm,
IN PEI_PLATFORM_DIMM_STATE *State
);
EFI_STATUS
EFIAPI
ReadSpd (
IN EFI_PEI_SERVICES **PeiServices,
IN PEI_PLATFORM_DIMM_PPI *This,
IN UINT8 Dimm,
IN UINT8 Offset,
IN UINTN Count,
IN OUT UINT8 *Buffer
);
static PEI_PLATFORM_DIMM_PPI mGchDimmPpi = {
DIMM_SOCKETS,
DIMM_SEGMENTS,
MEMORY_CHANNELS,
GetDimmState,
SetDimmState,
ReadSpd
};
static EFI_PEI_PPI_DESCRIPTOR mPpiPlatformDimm = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gPeiPlatformDimmPpiGuid,
&mGchDimmPpi
};
//
// Functions
//
/**
This function returns the current state of a single DIMM. Present indicates
that the DIMM slot is physically populated. Disabled indicates that the DIMM
should not be used.
@param PeiServices PEI services table pointer
@param This PPI pointer
@param Dimm DIMM to read from
@param State Pointer to a return buffer to be updated with the current state
of the DIMM
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
EFIAPI
GetDimmState (
IN EFI_PEI_SERVICES **PeiServices,
IN PEI_PLATFORM_DIMM_PPI *This,
IN UINT8 Dimm,
OUT PEI_PLATFORM_DIMM_STATE *State
)
{
EFI_STATUS Status;
UINT8 Buffer;
PEI_ASSERT (PeiServices, (Dimm < This->DimmSockets));
//
// A failure here does not necessarily mean that no DIMM is present.
// Read a single byte. All we care about is the return status.
//
Status = ReadSpd (
PeiServices,
This,
Dimm,
0,
1,
&Buffer
);
if (EFI_ERROR (Status)) {
State->Present = 0;
} else {
State->Present = 1;
}
//
// BUGBUG: Update to check platform variable when it is available
//
State->Disabled = 0;
State->Reserved = 0;
return EFI_SUCCESS;
}
/**
This function updates the state of a single DIMM.
@param PeiServices PEI services table pointer
@param This PPI pointer
@param Dimm DIMM to set state for
@param State Pointer to the state information to set.
@retval EFI_SUCCESS The function completed successfully.
@retval EFI_UNSUPPORTED The function is not supported.
**/
EFI_STATUS
EFIAPI
SetDimmState (
IN EFI_PEI_SERVICES **PeiServices,
IN PEI_PLATFORM_DIMM_PPI *This,
IN UINT8 Dimm,
IN PEI_PLATFORM_DIMM_STATE *State
)
{
return EFI_UNSUPPORTED;
}
/**
This function reads SPD information from a DIMM.
PeiServices PEI services table pointer
This PPI pointer
Dimm DIMM to read from
Offset Offset in DIMM
Count Number of bytes
Buffer Return buffer
@param EFI_SUCCESS The function completed successfully.
@param EFI_DEVICE_ERROR The DIMM being accessed reported a device error,
does not have an SPD module, or is not installed in
the system.
@retval EFI_TIMEOUT Time out trying to read the SPD module.
@retval EFI_INVALID_PARAMETER A parameter was outside the legal limits.
**/
EFI_STATUS
EFIAPI
ReadSpd (
IN EFI_PEI_SERVICES **PeiServices,
IN PEI_PLATFORM_DIMM_PPI *This,
IN UINT8 Dimm,
IN UINT8 Offset,
IN UINTN Count,
IN OUT UINT8 *Buffer
)
{
EFI_STATUS Status;
PEI_SMBUS_PPI *Smbus;
UINTN Index;
UINTN Index1;
EFI_SMBUS_DEVICE_ADDRESS SlaveAddress;
EFI_SMBUS_DEVICE_COMMAND Command;
UINTN Length;
Status = (**PeiServices).LocatePpi (
PeiServices,
&gPeiSmbusPpiGuid, // GUID
0, // INSTANCE
NULL, // EFI_PEI_PPI_DESCRIPTOR
&Smbus // PPI
);
ASSERT_PEI_ERROR (PeiServices, Status);
switch (Dimm) {
case 0:
SlaveAddress.SmbusDeviceAddress = SMBUS_ADDR_CH_A_1 >> 1;
break;
case 1:
SlaveAddress.SmbusDeviceAddress = SMBUS_ADDR_CH_A_2 >> 1;
break;
case 2:
SlaveAddress.SmbusDeviceAddress = SMBUS_ADDR_CH_B_1 >> 1;
break;
case 3:
SlaveAddress.SmbusDeviceAddress = SMBUS_ADDR_CH_B_2 >> 1;
break;
default:
return EFI_INVALID_PARAMETER;
}
Index = Count % 4;
if (Index != 0) {
//
// read the first serveral bytes to speed up following reading
//
for (Index1 = 0; Index1 < Index; Index1++) {
Length = 1;
Command = Offset + Index1;
Status = Smbus->Execute (
PeiServices,
Smbus,
SlaveAddress,
Command,
EfiSmbusReadByte,
FALSE,
&Length,
&Buffer[Index1]
);
if (EFI_ERROR(Status)) {
return Status;
}
}
}
//
// Now collect all the remaining bytes on 4 bytes block
//
for (; Index < Count; Index += 2) {
Command = Index + Offset;
Length = 2;
Status = Smbus->Execute (
PeiServices,
Smbus,
SlaveAddress,
Command,
EfiSmbusReadWord,
FALSE,
&Length,
&Buffer[Index]
);
if (EFI_ERROR(Status)) {
return Status;
}
Index += 2;
Command = Index + Offset;
Length = 2;
Status = Smbus->Execute (
PeiServices,
Smbus,
SlaveAddress,
Command,
EfiSmbusReadWord,
FALSE,
&Length,
&Buffer[Index]
);
if (EFI_ERROR(Status)) {
return Status;
}
}
return EFI_SUCCESS;
}
/**
This function initializes the PEIM. It simply installs the DIMM PPI.
@param FfsHeader Not used by this function
@param PeiServices Pointer to PEI services table
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
EFIAPI
PeimInitializeDimm (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
IN VOID *SmbusPpi
)
{
EFI_STATUS Status;
Status = (**PeiServices).InstallPpi (
PeiServices,
&mPpiPlatformDimm
);
ASSERT_PEI_ERROR (PeiServices, Status);
return EFI_SUCCESS;
}
|