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
/** @file
  This file contains internal PSF routines for PCH PSF lib usage
 
  Copyright (c) 2019 Intel Corporation. All rights reserved. <BR>
 
  SPDX-License-Identifier: BSD-2-Clause-Patent
**/
 
#include <Uefi/UefiBaseType.h>
#include <Library/IoLib.h>
#include <Library/DebugLib.h>
#include <Library/PchPcrLib.h>
#include <Library/PchInfoLib.h>
#include <Library/SataLib.h>
#include <Library/BaseMemoryLib.h>
#include <Register/PchRegsPsf.h>
#include <Register/PchRegsPsfCnl.h>
#include <Register/PchRegsPcie.h>
#include "PchPsfPrivateLibInternal.h"
 
GLOBAL_REMOVE_IF_UNREFERENCED UINT16 mPchLpSerialIoI2cPsfRegs[] =
{
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_I2C0_REG_BASE,
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_I2C1_REG_BASE,
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_I2C2_REG_BASE,
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_I2C3_REG_BASE,
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_I2C4_REG_BASE,
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_I2C5_REG_BASE
};
 
GLOBAL_REMOVE_IF_UNREFERENCED UINT16 mPchHSerialIoI2cPsfRegs[] =
{
  R_CNL_PCH_H_PSF3_PCR_T0_SHDW_I2C0_REG_BASE,
  R_CNL_PCH_H_PSF3_PCR_T0_SHDW_I2C1_REG_BASE,
  R_CNL_PCH_H_PSF3_PCR_T0_SHDW_I2C2_REG_BASE,
  R_CNL_PCH_H_PSF3_PCR_T0_SHDW_I2C3_REG_BASE
};
 
/**
  Return PSF_PORT for SerialIO I2C device
 
  @param[in] I2cNum  Serial IO I2C device (I2C0, I2C1, ....)
 
  @retval  PsfPort   PSF PORT structure for SerialIO I2C device
**/
PSF_PORT
PsfSerialIoI2cPort (
  IN UINT32  I2cNum
  )
{
  PSF_PORT PsfPort;
 
  PsfPort.PsfPid = PID_PSF3;
 
  if (IsPchLp ()) {
    if (I2cNum < ARRAY_SIZE(mPchLpSerialIoI2cPsfRegs)) {
      PsfPort.RegBase = mPchLpSerialIoI2cPsfRegs[I2cNum];
      return PsfPort;
    }
  } else {
    if (I2cNum < ARRAY_SIZE(mPchHSerialIoI2cPsfRegs)) {
      PsfPort.RegBase = mPchHSerialIoI2cPsfRegs[I2cNum];
      return PsfPort;
    }
  }
 
  ASSERT(FALSE);
  return PSF_PORT_NULL;
}
 
GLOBAL_REMOVE_IF_UNREFERENCED UINT16 mPchLpSerialIoSpiPsfRegs[] =
{
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_SPI0_REG_BASE,
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_SPI1_REG_BASE,
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_SPI2_REG_BASE
};
 
GLOBAL_REMOVE_IF_UNREFERENCED UINT16 mPchHSerialIoSpiPsfRegs[] =
{
  R_CNL_PCH_H_PSF3_PCR_T0_SHDW_SPI0_REG_BASE,
  R_CNL_PCH_H_PSF3_PCR_T0_SHDW_SPI1_REG_BASE,
  R_CNL_PCH_H_PSF3_PCR_T0_SHDW_SPI2_REG_BASE
};
 
/**
  Return PSF_PORT for SerialIO SPI device
 
  @param[in] SpiNum  Serial IO SPI device (SPI0, SPI1, ....)
 
  @retval  PsfPort   PSF PORT structure for SerialIO SPI device
**/
PSF_PORT
PsfSerialIoSpiPort (
  IN UINT32  SpiNum
  )
{
  PSF_PORT PsfPort;
 
  PsfPort.PsfPid = PID_PSF3;
 
  if (IsPchLp ()) {
    if (SpiNum < ARRAY_SIZE(mPchLpSerialIoSpiPsfRegs)) {
      PsfPort.RegBase = mPchLpSerialIoSpiPsfRegs[SpiNum];
      return PsfPort;
    }
  } else {
    if (SpiNum < ARRAY_SIZE(mPchHSerialIoSpiPsfRegs)) {
      PsfPort.RegBase = mPchHSerialIoSpiPsfRegs[SpiNum];
      return PsfPort;
    }
  }
 
  ASSERT(FALSE);
  return PSF_PORT_NULL;
}
 
GLOBAL_REMOVE_IF_UNREFERENCED UINT16 mPchLpSerialIoUartPsfRegs[] =
{
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_UART0_REG_BASE,
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_UART1_REG_BASE,
  R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_UART2_REG_BASE
};
 
GLOBAL_REMOVE_IF_UNREFERENCED UINT16 mPchHSerialIoUartPsfRegs[] =
{
  R_CNL_PCH_H_PSF3_PCR_T0_SHDW_UART0_REG_BASE,
  R_CNL_PCH_H_PSF3_PCR_T0_SHDW_UART1_REG_BASE,
  R_CNL_PCH_H_PSF3_PCR_T0_SHDW_UART2_REG_BASE
};
 
/**
  Return PSF_PORT for SerialIO UART device
 
  @param[in] UartNum  Serial IO UART device (UART0, UART1, ....)
 
  @retval  PsfPort    PSF PORT structure for SerialIO UART device
**/
PSF_PORT
PsfSerialIoUartPort (
  IN UINT32  UartNum
  )
{
  PSF_PORT PsfPort;
 
  PsfPort.PsfPid = PID_PSF3;
 
  if (IsPchLp ()) {
    if (UartNum < ARRAY_SIZE(mPchLpSerialIoUartPsfRegs)) {
      PsfPort.RegBase = mPchLpSerialIoUartPsfRegs[UartNum];
      return PsfPort;
    }
  } else {
    if (UartNum < ARRAY_SIZE(mPchHSerialIoUartPsfRegs)) {
      PsfPort.RegBase = mPchHSerialIoUartPsfRegs[UartNum];
      return PsfPort;
    }
  }
 
  ASSERT(FALSE);
  return PSF_PORT_NULL;
}
 
/**
  Get EOI register data for given PSF ID
 
  @param[in]  PsfId           PSF ID (1 - PSF1, 2 - PSF2, ...)
  @param[out] EoiTargetBase   EOI Target register
  @param[out] EoiControlBase  EOI Control register
 
  @retval MaxTargets          Number of supported targets
 
**/
UINT8
PsfEoiRegData (
  UINT32        PsfId,
  UINT16        *EoiTargetBase,
  UINT16        *EoiControlBase
  )
{
  UINT8  MaxTargets;
 
  MaxTargets = 0;
  *EoiTargetBase = 0;
  *EoiControlBase = 0;
 
  switch (PsfId) {
    case 1:
      if (IsPchLp ()) {
        *EoiTargetBase = R_CNL_PCH_LP_PSF1_PCR_PSF_MC_AGENT_MCAST0_TGT0_EOI;
        *EoiControlBase = R_CNL_PCH_LP_PSF1_PCR_PSF_MC_CONTROL_MCAST0_EOI;
        MaxTargets = 17;
      } else {
        *EoiTargetBase = R_CNL_PCH_H_PSF1_PCR_PSF_MC_AGENT_MCAST0_TGT0_EOI;
        *EoiControlBase = R_CNL_PCH_H_PSF1_PCR_PSF_MC_CONTROL_MCAST0_EOI;
        MaxTargets = 7;
      }
      break;
 
    case 3:
      *EoiTargetBase = R_CNL_PCH_PSF3_PCR_PSF_MC_AGENT_MCAST0_TGT0_EOI;
      *EoiControlBase = R_CNL_PCH_PSF3_PCR_PSF_MC_CONTROL_MCAST0_EOI;
      MaxTargets = 1;
      break;
 
    case 6:
      if (IsPchH ()) {
        *EoiTargetBase = R_CNL_PCH_H_PSF6_PCR_PSF_MC_AGENT_MCAST0_TGT0_EOI;
        *EoiControlBase = R_CNL_PCH_H_PSF6_PCR_PSF_MC_CONTROL_MCAST0_EOI;
        MaxTargets = 8;
      }
      break;
 
    case 7:
      if (IsPchH ()) {
        *EoiTargetBase = R_CNL_PCH_H_PSF7_PCR_PSF_MC_AGENT_MCAST0_TGT0_EOI;
        *EoiControlBase = R_CNL_PCH_H_PSF7_PCR_PSF_MC_CONTROL_MCAST0_EOI;
        MaxTargets = 8;
      }
      break;
 
    case 8:
      if (IsPchH ()) {
        *EoiTargetBase = R_CNL_PCH_H_PSF8_PCR_PSF_MC_AGENT_MCAST0_TGT0_EOI;
        *EoiControlBase = R_CNL_PCH_H_PSF8_PCR_PSF_MC_CONTROL_MCAST0_EOI;
        MaxTargets = 8;
      }
      break;
  }
  return MaxTargets;
}
 
GLOBAL_REMOVE_IF_UNREFERENCED PSF_PORT_DEST_ID PchLpRpDestId[] =
{
  {0x18000}, {0x18001}, {0x18002}, {0x18003}, // SPA: PSF1, PortID = 0
  {0x18200}, {0x18201}, {0x18202}, {0x18203}, // SPB: PSF1, PortID = 2
  {0x18400}, {0x18401}, {0x18402}, {0x18403}, // SPC: PSF1, PortID = 4
  {0x18600}, {0x18601}, {0x18602}, {0x18603}  // SPD: PSF1, PortID = 6
};
 
GLOBAL_REMOVE_IF_UNREFERENCED PSF_PORT_DEST_ID PchHRpDestId[] =
{
  {0x68000}, {0x68001}, {0x68002}, {0x68003}, // SPA: PSF6, PortID = 0
  {0x88000}, {0x88001}, {0x88002}, {0x88003}, // SPB: PSF8, PortID = 0
  {0x68100}, {0x68101}, {0x68102}, {0x68103}, // SPC: PSF6, PortID = 1
  {0x78000}, {0x78001}, {0x78002}, {0x78003}, // SPD: PSF7, PortID = 0
  {0x78100}, {0x78101}, {0x78102}, {0x78103}, // SPE: PSF7, PortID = 1
  {0x88100}, {0x88101}, {0x88102}, {0x88103}  // SPF: PSF8, PortID = 1
};
 
/**
  PCIe PSF port destination ID (psf_id:port_group_id:port_id:channel_id)
 
  @param[in] RpIndex        PCIe Root Port Index (0 based)
 
  @retval Destination ID
**/
PSF_PORT_DEST_ID
PsfPcieDestinationId (
  IN UINT32  RpIndex
  )
{
  if (IsPchLp ()) {
    if (RpIndex < ARRAY_SIZE(PchLpRpDestId)) {
      return PchLpRpDestId[RpIndex];
    }
  } else {
    if (RpIndex < ARRAY_SIZE(PchHRpDestId)) {
      return PchHRpDestId[RpIndex];
    }
  }
  ASSERT (FALSE);
  return (PSF_PORT_DEST_ID){0};
}
 
 
/**
  Return PSF_PORT for PMC device
 
  @retval    PsfPort         PSF PORT structure for PMC device
**/
PSF_PORT
PsfPmcPort (
  VOID
  )
{
  PSF_PORT PsfPort;
 
  PsfPort.PsfPid = PID_PSF3;
 
  if (IsPchLp ()) {
    PsfPort.RegBase = R_CNL_PCH_LP_PSF3_PCR_T0_SHDW_PMC_REG_BASE;
  } else {
    PsfPort.RegBase = R_CNL_PCH_H_PSF3_PCR_T0_SHDW_PMC_REG_BASE;
  }
  return PsfPort;
}
 
GLOBAL_REMOVE_IF_UNREFERENCED PSF_SEGMENT mPchLpPsfTable[] =
{
  {1, PID_PSF1},
  {2, PID_PSF2},
  {3, PID_PSF3},
  {4, PID_PSF4},
  {5, PID_CSME_PSF}
};
 
GLOBAL_REMOVE_IF_UNREFERENCED PSF_SEGMENT mPchHPsfTable[]  =
{
  {1, PID_PSF1},
  {2, PID_PSF2},
  {3, PID_PSF3},
  {4, PID_PSF4},
  {5, PID_CSME_PSF},
  {6, PID_PSF6},
  {7, PID_PSF7},
  {8, PID_PSF8}
};
 
/**
  Get list of supported PSF segments.
 
  @param[out] PsfTable        Array of supported PSF segments
  @param[out] PsfTableLength  Length of PsfTable
**/
VOID
PsfSegments (
  OUT PSF_SEGMENT  **PsfTable,
  OUT UINT32       *PsfTableLength
  )
{
  if (IsPchLp ()) {
    *PsfTable = mPchLpPsfTable;
    *PsfTableLength = ARRAY_SIZE(mPchLpPsfTable);
  } else {
    *PsfTable = mPchHPsfTable;
    *PsfTableLength = ARRAY_SIZE(mPchHPsfTable);
  }
}