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
/** @file
  Platform Hooks file
 
  @copyright
  Copyright 1999 - 2021 Intel Corporation. <BR>
 
  SPDX-License-Identifier: BSD-2-Clause-Patent
**/
 
#include <Base.h>
#include <Library/IoLib.h>
#include <Library/PciLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Include/SioRegs.h>
 
UINT8
IsSimPlatform (VOID)
{
  return 0;
}
 
/**
 
    Read Aspeed AHB register.
 
    @param RegIndex: register index of Aspeed.
 
    @retval value of register.
 
**/
UINT32
ReadAHBDword (
  UINT32 RegIndex
  )
{
  UINT8    bValue;
  UINT32   rdValue = 0;
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, REG_LOGICAL_DEVICE);
  IoWrite8 (0xED, 0);//short delay.
  IoWrite8 (ASPEED2500_SIO_DATA_PORT, ASPEED2500_SIO_SMI);
  IoWrite8 (0xED, 0);//short delay.
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0x30);
  IoWrite8 (0xED, 0);//short delay.
  IoWrite8 (ASPEED2500_SIO_DATA_PORT, 1);
  IoWrite8 (0xED, 0);//short delay.
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0xf8);
  bValue = IoRead8(ASPEED2500_SIO_DATA_PORT);
  bValue &= 0xfc;
  bValue |= 2;  // 4 byte window.
  IoWrite8 (ASPEED2500_SIO_DATA_PORT, bValue);
  IoWrite8 (0xED, 0);//short delay.
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0xf0);
  IoWrite8 (0xED, 0);//short delay.
  IoWrite8 (ASPEED2500_SIO_DATA_PORT,  (UINT8)((RegIndex >> 24)& 0xff));
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0xf1);
  IoWrite8 (0xED, 0);//short delay.
  IoWrite8 (ASPEED2500_SIO_DATA_PORT,  (UINT8)((RegIndex >> 16)& 0xff));
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0xf2);
  IoWrite8 (0xED, 0);//short delay.
  IoWrite8 (ASPEED2500_SIO_DATA_PORT,  (UINT8)((RegIndex >> 8) & 0xff));
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0xf3);
  IoWrite8 (0xED, 0);//short delay.
  IoWrite8 (ASPEED2500_SIO_DATA_PORT,  (UINT8)((RegIndex )& 0xff));
 
  // trigger read
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0xfe);
  IoRead8 (ASPEED2500_SIO_DATA_PORT);
 
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0xf4);
  rdValue += IoRead8 (ASPEED2500_SIO_DATA_PORT);
  rdValue <<= 8;
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0xf5);
  rdValue += IoRead8 (ASPEED2500_SIO_DATA_PORT);
  rdValue <<= 8;
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0xf6);
  rdValue += IoRead8 (ASPEED2500_SIO_DATA_PORT);
  rdValue <<= 8;
 
  IoWrite8 (ASPEED2500_SIO_INDEX_PORT, 0xf7);
  rdValue += IoRead8 (ASPEED2500_SIO_DATA_PORT);
 
 
  return rdValue;
 
}
 
/**
 * Checks for the presence of ASPEED SIO
 * @return TRUE if its present. FALSE if not.
 */
BOOLEAN
IsAspeedPresent (
  VOID
 )
{
 BOOLEAN PresenceStatus = FALSE;
 UINT32 DeviceID;
 
 //
 //ASPEED AST2500/AST2600
 //
 IoWrite8 (ASPEED2500_SIO_INDEX_PORT, ASPEED2500_SIO_UNLOCK);
 IoWrite8 (ASPEED2500_SIO_INDEX_PORT, ASPEED2500_SIO_UNLOCK);
 IoWrite8 (ASPEED2500_SIO_INDEX_PORT, REG_LOGICAL_DEVICE);
 IoWrite8 (ASPEED2500_SIO_DATA_PORT, ASPEED2500_SIO_UART1);
 if (IoRead8 (ASPEED2500_SIO_DATA_PORT) == ASPEED2500_SIO_UART1) {
  //
  //right now, maybe it is ASPEED. to detect the  device ID.
  //
  DeviceID = ReadAHBDword (SCU7C);
  //
  //There is a Aspeed card need to support as well. it's type is AST2500 A1 EVB.
  //
  //AST2300-A0 0x01000003
  //AST2300-A1 0x01010303
  //AST1300-A1 0x01010003
  //AST1050-A1 0x01010203
  //AST2400-A0 0x02000303
  //AST2400-A1 0x02010303
  //AST1400-A1 0x02010103
  //AST1250-A1 0x02010303
  //AST2500-A0 0x04000303
  //AST2510-A0 0x04000103
  //AST2520-A0 0x04000203
  //AST2530-A0 0x04000403
  //AST2500-A1 0x04010303
  //AST2510-A1 0x04010103
  //AST2520-A1 0x04010203
  //AST2530-A1 0x04010403
  //
  if ((DeviceID & 0xff0000ff) == 0x04000003) {
   PresenceStatus = TRUE;
  }
 }
 IoWrite8 (ASPEED2500_SIO_INDEX_PORT, ASPEED2500_SIO_LOCK);
 return PresenceStatus;
}
 
/**
 * Checks for the presence of Nuvoton SIO
 * @return TRUE if its present. FALSE if not.
 */
BOOLEAN
IsNuvotonPresent (
  VOID
  )
{
  BOOLEAN PresenceStatus = FALSE;
 
  //
  // Nuvoton NCT5104D
  //
  IoWrite8 (NCT5104D_SIO_INDEX_PORT, NCT5104D_ENTER_THE_EXTENDED_FUNCTION_MODE);
  IoWrite8 (NCT5104D_SIO_INDEX_PORT, NCT5104D_ENTER_THE_EXTENDED_FUNCTION_MODE);
  IoWrite8 (NCT5104D_SIO_INDEX_PORT, NCT5104D_CHIP_ID_REG);
  if (IoRead8 (NCT5104D_SIO_DATA_PORT) == NCT5104D_CHIP_ID) {
    PresenceStatus = TRUE;
  }
  return PresenceStatus;
}
 
/**
 * Checks for the presence of the following SIO:
 *  -ASPEED AST2500
 *  -Nuvoton NCT5104D
 *
 * @return An UINT32 with the corresponding bit set for each SIO.
 *         -ASPEED_EXIST     BIT4
 *         -NCT5104D_EXIST   BIT3
 *         -PC8374_EXIST     BIT1
 *         -PILOTIV_EXIST    BIT0
 */
UINT32
IsSioExist (
  VOID
  )
{
  UINT32   SioExit = 0;
 
  if (IsAspeedPresent ()) {
    SioExit |= ASPEED_EXIST;
  }
 
  if (IsNuvotonPresent ()) {
    SioExit |= NCT5104D_EXIST;
  }
 
  DEBUG((DEBUG_INFO, "[SIO] Current system SIO exist bit:%x \n", SioExit));
 
  return SioExit;
}