hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/** @file
 
Copyright (c) 2013-2015 Intel Corporation.
 
SPDX-License-Identifier: BSD-2-Clause-Patent
 
 
**/
 
//
// Include common header file for this module.
//
#include "CommonHeader.h"
 
#include "QNCSmm.h"
#include "QNCSmmHelpers.h"
 
//
// #define BIT_ZERO 0x00000001
//
CONST UINT32  BIT_ZERO = 0x00000001;
 
//
// /////////////////////////////////////////////////////////////////////////////
// SUPPORT / HELPER FUNCTIONS (QNC version-independent)
//
BOOLEAN
CompareEnables (
  CONST IN QNC_SMM_SOURCE_DESC *Src1,
  CONST IN QNC_SMM_SOURCE_DESC *Src2
  )
/*++
 
Routine Description:
 
  GC_TODO: Add function description
 
Arguments:
 
  Src1  - GC_TODO: add argument description
  Src2  - GC_TODO: add argument description
 
Returns:
 
  GC_TODO: add return values
 
--*/
{
  BOOLEAN IsEqual;
  UINTN   loopvar;
 
  IsEqual = TRUE;
  for (loopvar = 0; loopvar < NUM_EN_BITS; loopvar++) {
    //
    // It's okay to compare a NULL bit description to a non-NULL bit description.
    // They are unequal and these tests will generate the correct result.
    //
    if (Src1->En[loopvar].Bit != Src2->En[loopvar].Bit ||
        Src1->En[loopvar].Reg.Type != Src2->En[loopvar].Reg.Type ||
        Src1->En[loopvar].Reg.Data.raw != Src2->En[loopvar].Reg.Data.raw
        ) {
      IsEqual = FALSE;
      break;
      //
      // out of for loop
      //
    }
  }
 
  return IsEqual;
}
 
BOOLEAN
CompareStatuses (
  CONST IN QNC_SMM_SOURCE_DESC *Src1,
  CONST IN QNC_SMM_SOURCE_DESC *Src2
  )
/*++
 
Routine Description:
 
  GC_TODO: Add function description
 
Arguments:
 
  Src1  - GC_TODO: add argument description
  Src2  - GC_TODO: add argument description
 
Returns:
 
  GC_TODO: add return values
 
--*/
{
  BOOLEAN IsEqual;
  UINTN   loopvar;
 
  IsEqual = TRUE;
 
  for (loopvar = 0; loopvar < NUM_STS_BITS; loopvar++) {
    //
    // It's okay to compare a NULL bit description to a non-NULL bit description.
    // They are unequal and these tests will generate the correct result.
    //
    if (Src1->Sts[loopvar].Bit != Src2->Sts[loopvar].Bit ||
        Src1->Sts[loopvar].Reg.Type != Src2->Sts[loopvar].Reg.Type ||
        Src1->Sts[loopvar].Reg.Data.raw != Src2->Sts[loopvar].Reg.Data.raw
        ) {
      IsEqual = FALSE;
      break;
      //
      // out of for loop
      //
    }
  }
 
  return IsEqual;
}
 
BOOLEAN
CompareSources (
  CONST IN QNC_SMM_SOURCE_DESC *Src1,
  CONST IN QNC_SMM_SOURCE_DESC *Src2
  )
/*++
 
Routine Description:
 
  GC_TODO: Add function description
 
Arguments:
 
  Src1  - GC_TODO: add argument description
  Src2  - GC_TODO: add argument description
 
Returns:
 
  GC_TODO: add return values
 
--*/
{
  return (BOOLEAN) (CompareEnables (Src1, Src2) && CompareStatuses (Src1, Src2));
}
 
BOOLEAN
SourceIsActive (
  CONST IN QNC_SMM_SOURCE_DESC *Src
  )
/*++
 
Routine Description:
 
  GC_TODO: Add function description
 
Arguments:
 
  Src - GC_TODO: add argument description
 
Returns:
 
  GC_TODO: add return values
 
--*/
{
  BOOLEAN IsActive;
  UINTN   loopvar;
 
  BOOLEAN SciEn;
 
  IsActive  = TRUE;
 
  SciEn     = QNCSmmGetSciEn ();
 
  if ((Src->Flags & QNC_SMM_SCI_EN_DEPENDENT) && (SciEn)) {
    //
    // This source is dependent on SciEn, and SciEn == 1.  An ACPI OS is present,
    // so we shouldn't do anything w/ this source until SciEn == 0.
    //
    IsActive = FALSE;
 
  } else {
    //
    // Read each bit desc from hardware and make sure it's a one
    //
    for (loopvar = 0; loopvar < NUM_EN_BITS; loopvar++) {
 
      if (!IS_BIT_DESC_NULL (Src->En[loopvar])) {
 
        if (ReadBitDesc (&Src->En[loopvar]) == 0) {
          IsActive = FALSE;
          break;
          //
          // out of for loop
          //
        }
 
      }
    }
 
    if (IsActive) {
      //
      // Read each bit desc from hardware and make sure it's a one
      //
      for (loopvar = 0; loopvar < NUM_STS_BITS; loopvar++) {
 
        if (!IS_BIT_DESC_NULL (Src->Sts[loopvar])) {
 
          if (ReadBitDesc (&Src->Sts[loopvar]) == 0) {
            IsActive = FALSE;
            break;
            //
            // out of for loop
            //
          }
 
        }
      }
    }
  }
 
  return IsActive;
}
 
VOID
QNCSmmEnableSource (
  CONST QNC_SMM_SOURCE_DESC *SrcDesc
  )
/*++
 
Routine Description:
 
  GC_TODO: Add function description
 
Arguments:
 
  SrcDesc - GC_TODO: add argument description
 
Returns:
 
  GC_TODO: add return values
 
--*/
{
  UINTN loopvar;
 
  //
  // Set enables to 1 by writing a 1
  //
  for (loopvar = 0; loopvar < NUM_EN_BITS; loopvar++) {
    if (!IS_BIT_DESC_NULL (SrcDesc->En[loopvar])) {
      WriteBitDesc (&SrcDesc->En[loopvar], 1);
    }
  }
 
  QNCSmmClearSource (SrcDesc);
 
}
 
VOID
QNCSmmDisableSource (
  CONST QNC_SMM_SOURCE_DESC *SrcDesc
  )
/*++
 
Routine Description:
 
  GC_TODO: Add function description
 
Arguments:
 
  SrcDesc - GC_TODO: add argument description
 
Returns:
 
  GC_TODO: add return values
 
--*/
{
  UINTN loopvar;
 
  for (loopvar = 0; loopvar < NUM_EN_BITS; loopvar++) {
    if (!IS_BIT_DESC_NULL (SrcDesc->En[loopvar])) {
      WriteBitDesc (&SrcDesc->En[loopvar], 0);
    }
  }
}
 
VOID
QNCSmmClearSource (
  CONST QNC_SMM_SOURCE_DESC *SrcDesc
  )
/*++
 
Routine Description:
 
  GC_TODO: Add function description
 
Arguments:
 
  SrcDesc - GC_TODO: add argument description
 
Returns:
 
  GC_TODO: add return values
 
--*/
{
  UINTN loopvar;
  BOOLEAN ValueToWrite;
 
  ValueToWrite =
    ((SrcDesc->Flags & QNC_SMM_CLEAR_WITH_ZERO) == 0) ? TRUE : FALSE;
 
  for (loopvar = 0; loopvar < NUM_STS_BITS; loopvar++) {
    if (!IS_BIT_DESC_NULL (SrcDesc->Sts[loopvar])) {
      WriteBitDesc (&SrcDesc->Sts[loopvar], ValueToWrite);
    }
  }
}
 
VOID
QNCSmmClearSourceAndBlock (
  CONST QNC_SMM_SOURCE_DESC *SrcDesc
  )
// GC_TODO: function comment should start with '/*++'
/*
  Sets the source to a 1 or 0 and then waits for it to clear.
  Be very careful when calling this function -- it will not
  ASSERT.  An acceptable case to call the function is when
  waiting for the NEWCENTURY_STS bit to clear (which takes
  3 RTCCLKs).
*/
// GC_TODO: function comment should end with '--*/'
// GC_TODO: function comment is missing 'Routine Description:'
// GC_TODO: function comment is missing 'Arguments:'
// GC_TODO: function comment is missing 'Returns:'
// GC_TODO:    SrcDesc - add argument and description to function comment
{
  UINTN   loopvar;
  BOOLEAN IsSet;
  BOOLEAN ValueToWrite;
 
  ValueToWrite =
    ((SrcDesc->Flags & QNC_SMM_CLEAR_WITH_ZERO) == 0) ? TRUE : FALSE;
 
  for (loopvar = 0; loopvar < NUM_STS_BITS; loopvar++) {
 
    if (!IS_BIT_DESC_NULL (SrcDesc->Sts[loopvar])) {
      //
      // Write the bit
      //
      WriteBitDesc (&SrcDesc->Sts[loopvar], ValueToWrite);
 
      //
      // Don't return until the bit actually clears.
      //
      IsSet = TRUE;
      while (IsSet) {
        IsSet = ReadBitDesc (&SrcDesc->Sts[loopvar]);
        //
        // IsSet will eventually clear -- or else we'll have
        // an infinite loop.
        //
      }
    }
  }
}