summaryrefslogtreecommitdiff
path: root/Core/EM/KbcEmul/Kbccore.c
blob: 51516de98f34d15b8f3923063b36e13e70bedc3b (plain)
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
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**         5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/KbcEmulation/ALASKA/KBCEMUL/Kbccore.c 9     1/09/12 1:30a Rameshr $
//
// $Revision: 9 $
//
// $Date: 1/09/12 1:30a $
//
//****************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/KbcEmulation/ALASKA/KBCEMUL/Kbccore.c $
// 
// 9     1/09/12 1:30a Rameshr
// [TAG]  		EIP74128
// [Category]  	Improvement
// [Description]  	Disable the KbcEmulation Smi’s on ACPI enable and
// Disable SMI call
// [Files]  		Kbccore.c, KbcEmuulAcpi.c, KbcEmul.c, KbcEmul.cif,
// KbcEmul.h, KbcEmul.sdl
// 
// 8     1/06/12 3:51a Rameshr
// [TAG]  		EIP78617
// [Category]  	Bug Fix
// [Severity]  	Important
// [Symptom]  	When KBCEmulation is enabled during OS runtime phase,
// system reboots
// [RootCause]  	if the SMI happens from AP, Kbcemulation driver unable to
// handle it.
// [Solution]  	Added logic in KbcCore.c to find the CPU that cause SMI
// and access the corresponding AL register.
// [Files]  		Ap4x.h, KbcCore.c
// 
// 7     1/06/12 3:21a Rameshr
// EIP78617 check-in removed.
// 
// 5     2/10/11 1:02a Rameshr
// [TAG]  		EIP53687
// [Category]  	Improvement
// [Description]  	AMI headers update for KbcEmulation Module 
// [Files]  		KbcEmul.mak,KbcEmul.dxs,KbcEmul.c,KbcEmul.h,KbcEmulLib.h,Kbc
// EmulLib.c,Kbc.h,KbcDevEmul.h,Kbccore.c,Legacykbc.c,Legacykbd.c,LegacyMo
// use.c,VirtualKbc.c,VirtualKbd.c,VirtualMouse.c,Ap4x.h,Ap4x.c,KbcUhci.c,
// KbcUhci.h,KbcEmulIrq.c, KbcOhci.c, Kbcohci.h
// 
// 4     7/08/10 1:56a Rameshr
// Ohci Emulation support Added.
// EIP 39712
// 
// 3     6/30/09 11:30a Rameshr
// Coding Standard and File header updated.
// 
// 2     2/05/09 9:35a Rameshr
// Symptom : With Latest CSM Emulation doesn't work.
// Solution: Added Emulation enable code in outside SMM. This is called
// from Uhcd.c when ever USB mode changes to Legacy
// EIP:18730
// 
// 1     12/14/07 10:26a Rameshraju
// Initial Check-in
//****************************************************************************

//<AMI_FHDR_START>
//**********************************************************************
//
// Name:        Kbccore.c
//
// Description: It has function for port 60 read, 60 write, 64 read and 64 write
//
//**********************************************************************
//<AMI_FHDR_END>

#include "KbcEmul.h"
#include "kbc.h"
#if UHCI_EMUL_SUPPORT
#include "KbcUhci.h"
#else 
#include "KbcOhci.h"
#endif

BOOLEAN         AcpiEmulationDisable=FALSE;
extern KBC*     gVirtualKBC;

#define SYNC_SMI_BIT  (1 << 0)

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   FindSMICpu
//
// Description: In a Multiprocessor environment, any logical CPU can generate
//              the SMI. This function finds the CPU that generates SMI by accessing
//              IO 60/64 Ports
//
// Input:       None
//
// Output:      UINT8 CpuIndex
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
UINT8 FindSMICpu ( ) {
  UINT8                   CpuIndex;
  UINT32                  SmmIoMiscInfo;
  UINT16                  IOAddress;
  UINT32                  Smbase=0;

  for (CpuIndex = 0; CpuIndex < gSmst->NumberOfCpus; CpuIndex++) {
    //
    // Find which CPU caused the SMI
    //    
    Smbase = gSmst->CpuSaveState[CpuIndex].Ia32SaveState.SMBASE;
    SmmIoMiscInfo = *(UINT32 *) (((UINT8 *) (UINTN) Smbase) + 0x8000 + 0x7FA4);
    IOAddress =     SmmIoMiscInfo >> 16;
    if (((IOAddress == 0x60) || (IOAddress == 0x64)) && (SmmIoMiscInfo & SYNC_SMI_BIT)) {
      return CpuIndex;
    }
  }

  return 0xFF;  
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   getTrapAL
//
// Description: Get the port 60 or 64 input value from the CPU save reg
//
// Input:       None
//
// Output:      UINT8 Value
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
UINT8 GetTrapAL()
{

#if UHCI_EMUL_SUPPORT	
	UINT8   CpuIndex;

	CpuIndex = FindSMICpu ();
	ASSERT (CpuIndex != 0xFF);
	return (UINT8)GET_CPUSAVESTATE_REG(CpuIndex, EAX);
#else
	return GetHceInput();
#endif

}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   setTrapAL
//
// Description: Set the port 60 or 64 output value to the CPU save reg
//
// Input:       UINT8 Data
//
// Output:      None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
void SetTrapAL(UINT8 data)
{

#if UHCI_EMUL_SUPPORT
    UINT8   CpuIndex;

    CpuIndex = FindSMICpu();
    ASSERT (CpuIndex != 0xFF);
    *(UINT8*)&GET_CPUSAVESTATE_REG(CpuIndex, EAX) = data;
#endif

}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   trap64w
//
// Description: This function handles the Port64 write command
//
// Input:       None
//
// Output:      None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>

void trap64w()
{
    (*gVirtualKBC->kbc_write_command)( gVirtualKBC,GetTrapAL() );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   setTrapAL
//
// Description: This function handles the Port60 write command
//
// Input:       None
//
// Output:      None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
void trap60w()
{
    (*gVirtualKBC->kbc_write_data)( gVirtualKBC,GetTrapAL() );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   setTrapAL
//
// Description: This function handles the Port64 Read command
//
// Input:       None
//
// Output:      None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
void trap64r()
{
    SetTrapAL((*gVirtualKBC->kbc_read_status)(gVirtualKBC));
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   setTrapAL
//
// Description: This function handles the Port60 Read command
//
// Input:       None
//
// Output:      None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
void trap60r()
{
    SetTrapAL((*gVirtualKBC->kbc_read_data)(gVirtualKBC));
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   hasTrapStatus
//
// Description: return the port 6064 trap status
//
// Input:       None
//
// Output:      TRUE: Trab enabled for port 6064
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOLEAN hasTrapStatus()
{
    BOOLEAN     TrapStatus=FALSE;
#if UHCI_EMUL_SUPPORT
    TrapStatus=Uhci_HasTrapStatus();
#endif
#if OHCI_EMUL_SUPPORT
    TrapStatus=Ohci_HasTrapStatus();
#endif
    return TrapStatus;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   TrapEnable
//
// Description: Enable/disable the port6064 trap
//
// Input:       TRUE : enable the trap.
//              FALSE: Disable the trap.
//
// Output:      TRUE : when suucessfully done else FALSE
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOLEAN TrapEnable(BOOLEAN b)
{

    if(AcpiEmulationDisable) {
        return FALSE;
    }

#if UHCI_EMUL_SUPPORT
    return Uhci_TrapEnable(b);
#endif
#if OHCI_EMUL_SUPPORT
    return Ohci_TrapEnable(b);
#endif
	return TRUE;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   NonSmmTrapEnable
//
// Description: Enable/disable the port6064 trap in Non SMM 
//
// Input:       TRUE : enable the trap.
//              FALSE: Disable the trap.
//
// Output:      TRUE/FALSE
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOLEAN NonSmmTrapEnable(BOOLEAN b)
{
#if UHCI_EMUL_SUPPORT
    return NonSmmUhci_TrapEnable(b);
#endif
#if OHCI_EMUL_SUPPORT
    return NonSmmOhci_TrapEnable(b);
#endif
	return TRUE;
}

//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**         5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************