hc
2024-03-25 edb30157bad0c0001c32b854271ace01d3b9a16a
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
368
369
370
371
372
373
374
375
376
377
/** @file
  Header file for Serial IO Private Lib implementation.
 
  Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
  SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _SERIAL_IO_PRIVATE_LIB_H_
#define _SERIAL_IO_PRIVATE_LIB_H_
 
#include <SerialIoDevices.h>
#include <Library/SerialIoAccessLib.h>
 
/**
  Serial Io Pci Device State structure.
  Used to preserve current information about the device when it is configured in Pci mode prior to Pch Initialization.
**/
typedef struct {
  UINT64 PciCfgBar0;       ///< Pci Config Space Base Address Register
  UINT8  PciCfgCommand;    ///< Pci Config Space Command Register
  UINT8  PciCfgPmeCtrlSts; ///< Pci Config Space Pme Control Status
  UINT8  PprReset;         ///< MMIO Proprietary Reset Register
} SERIAL_IO_PCI_DEVICE_STATE;
 
/**
  Checks if higher functions are enabled.
  Used for Function 0 Serial Io Device disabling
 
  @param[in] DeviceNum       Device Number
 
  @retval TRUE               At least one higher function device is enabled
          FALSE              Higher functions are disabled
**/
BOOLEAN
SerialIoHigherFunctionsEnabled (
  IN UINT8                    DeviceNum
  );
 
/**
  Places SerialIo device in D3
 
  @param[in] PciCfgBase       Pci Config Offset
 
**/
VOID
SerialIoSetD3 (
  IN UINT64                    PciCfgBase
  );
 
/**
  Places SerialIo device in D0
 
  @param[in] PciCfgBase       Pci Config Offset
 
**/
VOID
SerialIoSetD0 (
  IN UINT64                    PciCfgBase
  );
 
/**
  Allows Memory Access
 
  @param[in] PciCfgBase       Pci Config Offset
  @param[in] Hidden           Mode that determines access type
 
**/
VOID
SerialIoEnableMse (
  IN UINT64                    PciCfgBase,
  IN BOOLEAN                   Hidden
  );
 
/**
  Disable SerialIo memory access
 
  @param[in] PciCfgBase       Pci Config Offset
 
**/
VOID
SerialIoDisableMse (
  IN UINT64                    PciCfgBase
  );
 
/**
  Disable SerialIo memory encoding
  Designated for Pci modes
 
  @param[in] PciCfgBase       Pci Config Offset
  @param[in] RemoveTempBar    Remove temporary mem base address or not
 
**/
VOID
SerialIoMmioDisable (
  IN UINT64                    PciCfgBase,
  IN BOOLEAN                   RemoveBar
  );
 
/**
  Gets Fixed Base Address used for BAR0
 
  @param[in] SpiNumber               Serial IO device SPI number
 
  @retval                            Config control offset
**/
UINT32
GetSerialIoSpiFixedMmioAddress (
  IN UINT8       SpiNumber
  );
 
/**
  Gets Fixed Address used for Pci Config Space manipulation
 
  @param[in] SpiNumber               Serial IO device SPI number
 
  @retval                            Pci Config Address
**/
UINT32
GetSerialIoSpiFixedPciCfgAddress (
  IN UINT8       SpiNumber
  );
 
/**
  Gets Spi Device Id
 
  @param[in] SpiNumber               Serial IO device SPI number
 
  @retval                            Device Id
**/
UINT16
GetSerialIoSpiDeviceId (
  IN UINT8       SpiNumber
  );
 
/**
  Checks if SPI is Hidden, and it's Pci Config space available
 
  @param[in] SpiNumber       Selects Serial IO SPI device
 
  @retval   TRUE             SPI is in hidden mode
  @retval   FALSE            SPI is not in hidden mode
**/
BOOLEAN
IsSerialIoSpiHidden (
  IN UINT8               SpiNumber
  );
 
/**
  Configures Serial IO Controller before control is passd to the OS
 
  @param[in] SpiNumber         SPI Number
  @param[in] SpiDeviceConfig   SerialIo SPI Config
 
**/
VOID
SerialIoSpiBootHandler (
  IN UINT8                      SpiNumber,
  IN SERIAL_IO_SPI_CONFIG       *SpiDeviceConfig
  );
 
/**
  Sets Pme Control Status and Command register values required for S3 Boot Script
 
  @param[in]     SpiNumber         SPI Number
  @param[in]     SpiDeviceConfig   SerialIo SPI Config
  @param[in/out] S3PciCfgBase      S3 Boot Script Pci Config Base
  @param[in/out] Command           Pci Command register data to save
  @param[in/out] Pme               Pci Pme Control register data to save
 
**/
VOID
SerialIoSpiS3Handler (
  IN     UINT8                 SpiNumber,
  IN     SERIAL_IO_SPI_CONFIG  *SpiDeviceConfig,
  IN OUT UINT64                *S3PciCfgBase,
  IN OUT UINT32                *Command,
  IN OUT UINT32                *Pme
  );
 
/**
  Gets Pci Config control offset
 
  @param[in] UartNumber              Serial IO device UART number
 
  @retval                            Config control offset
**/
UINT16
GetSerialIoUartConfigControlOffset (
  IN UINT8       UartNumber
  );
 
/**
  Gets Fixed Base Address used for BAR0
 
  @param[in] UartNumber              Serial IO device UART number
 
  @retval                            Config control offset
**/
UINT32
GetSerialIoUartFixedMmioAddress (
  IN UINT8       UartNumber
  );
 
/**
  Gets Fixed Address used for Pci Config Space manipulation
 
  @param[in] UartNumber              Serial IO device UART number
 
  @retval                            Pci Config Address
**/
UINT32
GetSerialIoUartFixedPciCfgAddress (
  IN UINT8       UartNumber
  );
 
/**
  Returns UART S3 boot script PCI address
 
  @param[in] UartNumber         UART Number
 
  @retval    UART  S3 boot script PCI address
**/
UINT64
GetSerialIoUartS3PciBase (
  IN UINT8        UartNumber
  );
 
/**
  Returns SPI S3 boot script PCI address
 
  @param[in] UartNumber         UART Number
 
  @retval    SPI S3 boot script PCI address
**/
UINT64
GetSerialIoSpiS3PciBase (
  IN UINT8        SpiNumber
  );
 
/**
  Returns I2C S3 boot script PCI address
 
  @param[in] I2cNumber         I2C Number
 
  @retval    I2C  S3 boot script PCI address
**/
UINT64
GetSerialIoI2cS3PciBase (
  IN UINT8        I2cNumber
  );
 
/**
  Gets Uarts Device Id
 
  @param[in] UartNumbe               Serial IO device UART number
 
  @retval                            Device Id
**/
UINT16
GetSerialIoUartDeviceId (
  IN UINT8       UartNumber
  );
 
/**
  Checks if UART is Hidden, and it's Pci Config space available
 
  @param[in]      UartNumber     Selects Serial IO UART device
 
  @retval   TRUE             UART is in hidden mode
  @retval   FALSE            UART is not in hidden mode
**/
BOOLEAN
IsSerialIoUartHidden (
  IN UINT8               UartNumber
  );
 
/**
  Configures Serial IO Controller before control is passd to the OS
 
  @param[in] UartNumber         UART Number
  @param[in] UartDeviceConfig   SerialIo UART Config
 
**/
VOID
SerialIoUartBootHandler (
  IN UINT8                      UartNumber,
  IN SERIAL_IO_UART_CONFIG      *UartDeviceConfig
  );
 
/**
  Sets Pme Control Status and Command register values required for S3 Boot Script
 
  @param[in]     UartNumber         UART Number
  @param[in]     UartDeviceConfig   SerialIo UART Config
  @param[in/out] S3PciCfgBase       S3 Boot Script Pci Config Base
  @param[in/out] Command            Pci Command register data to save
  @param[in/out] Pme                Pci Pme Control register data to save
 
**/
VOID
SerialIoUartS3Handler (
  IN     UINT8                  UartNumber,
  IN     SERIAL_IO_UART_CONFIG  *UartDeviceConfig,
  IN OUT UINT64                 *S3PciCfgBase,
  IN OUT UINT32                 *Command,
  IN OUT UINT32                 *Pme
  );
 
/**
  Gets Fixed Address used for Pci Config Space manipulation
 
  @param[in] I2cNumber               Serial IO device I2C number
 
  @retval                            Pci Config Address
**/
UINT32
GetSerialIoI2cFixedPciCfgAddress (
  IN UINT8       I2cNumber
  );
 
/**
  Gets I2C Device Id
 
  @param[in] I2cNumber               Serial IO device I2C number
 
  @retval                            Device Id
**/
UINT16
GetSerialIoI2cDeviceId (
  IN UINT8       I2cNumber
  );
 
/**
  Checks if I2C is Hidden, and it's Pci Config space available
 
  @param[in] 2cNumber        Selects Serial IO I2C device
 
  @retval   TRUE             I2C is in hidden mode
  @retval   FALSE            I2C is not in hidden mode
**/
BOOLEAN
IsSerialIoI2cHidden (
  IN UINT8               I2cNumber
  );
 
/**
  Configures Serial IO Controller before control is passd to the OS
 
  @param[in] I2cNumber         I2C Number
  @param[in] I2cDeviceConfig   SerialIo I2C Config
 
**/
VOID
SerialIoI2cBootHandler (
  IN UINT8                      I2cNumber,
  IN SERIAL_IO_I2C_CONFIG       *I2cDeviceConfig
  );
 
/**
  Sets Pme Control Status and Command register values required for S3 Boot Script
 
  @param[in]     I2cNumber         I2C Number
  @param[in]     I2cDeviceConfig   SerialIo I2C Config
  @param[in/out] S3PciCfgBase      S3 Boot Script Pci Config Base
  @param[in/out] Command           Pci Command register data to save
  @param[in/out] Pme               Pci Pme Control register data to save
 
**/
VOID
SerialIoI2cS3Handler (
  IN     UINT8                 I2cNumber,
  IN     SERIAL_IO_I2C_CONFIG  *I2cDeviceConfig,
  IN OUT UINT64                *S3PciCfgBase,
  IN OUT UINT32                *Command,
  IN OUT UINT32                *Pme
  );
 
#endif // _SERIAL_IO_PRIVATE_LIB_H_