summaryrefslogtreecommitdiff
path: root/Core/EM/Terminal/TerminalAcpi.c
blob: da033722ed5de82817035bb1ef1d41f78225ebd8 (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
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************

//*************************************************************************
// $Header: /Alaska/BIN/Modules/Terminal/TerminalAcpi.c 1     12/22/11 1:34a Rajeshms $
//
// $Revision: 1 $
//
// $Date: 12/22/11 1:34a $
//*************************************************************************
// Revision History
// ----------------
// $Log: /Alaska/BIN/Modules/Terminal/TerminalAcpi.c $
// 
// 1     12/22/11 1:34a Rajeshms
// [TAG]  		EIP57579
// [Category]  	Improvement
// [Description]  	PCI legacy console redirection causes Legacy OS
// installation slow because when Redirection is enabled for Legacy OS,
// Legacy Serial Redirection enables the PCI Serial interrupt for
// redirection and sometime after that OS uses its own IVT but still PCI
// Serial interrupt is generated and not handled.So, disable redirection
// at OS level. we disable redirection on ACPI enable/disable call and
// reset the Interrupt Enable Register so that interrupt is not generated.
// [Files]  		Terminal.sdl, Terminal.mak, Terminal.cif, TerminalAcpi.c
// 
// 
//*************************************************************************
//<AMI_FHDR_START>
//
// Name:        TerminalAcpi.c
//
// Description: This file contains function to disable the PCI redirection 
//              at ACPI enable call.
//
//<AMI_FHDR_END>
//*************************************************************************

//----------------------------------------------------------------------------
// Include(s)
//----------------------------------------------------------------------------

#include <Token.h>
#include <AmiDxeLib.h>
#if defined(PI_SPECIFICATION_VERSION)&&(PI_SPECIFICATION_VERSION>=0x0001000A)
#include <Protocol\SmmSwDispatch2.h>
#define AMI_SMM_SW_DISPATCH_CONTEXT  EFI_SMM_SW_REGISTER_CONTEXT
#else
#include <Protocol\SmmSwDispatch.h>
#define AMI_SMM_SW_DISPATCH_CONTEXT  EFI_SMM_SW_DISPATCH_CONTEXT
#endif
#include "TerminalSetupVar.h"

#define     CFG_SPACE_INDEX_REG         0xCF8
#define     CFG_SPACE_DATA_REG          0xCFC
#define     PCI_BAR0                    0x0010
#define     INT08h_SEGMENT              0xF000             
#define     INT08h_OFFSET               0xFEA5

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:   TerminalAcpiEnableDisableCallBack
//
// Description: This routine will be called to disable PCI redirection at ACPI
//              enable/disable call and reset Interrupt Enable Register to 
//              disable interrupt from PCI Serial device & replace actual INT08h.
//
// Input:       None 
//
// Output:      None
//
// Notes:       None
//----------------------------------------------------------------------------
//<AMI_PHDR_END>

VOID
TerminalAcpiEnableDisableCallBack(
    IN EFI_HANDLE                   DispatchHandle,
    IN AMI_SMM_SW_DISPATCH_CONTEXT  *DispatchContext
)
{
#if (TOTAL_PCI_SERIAL_PORTS > 0)
    EFI_STATUS  Status;
    UINT8       RegNum = PCI_BAR0;
    UINT32      PciAddr;
    UINT32      BarAddress;
    UINT8       i,DevFunc;

    UINT8   gTotalSioSerialPorts = TOTAL_SIO_SERIAL_PORTS;
    EFI_GUID gTerminalVarGuid   = TERMINAL_VAR_GUID;
    UINTN PciSerialPortsLocationVarSize = 
                                    sizeof(PCI_SERIAL_PORTS_LOCATION_VAR);
    PCI_SERIAL_PORTS_LOCATION_VAR PciSerialPortsLocationVar; 

    UINTN SerialPortsEnabledVarSize = sizeof(SERIAL_PORTS_ENABLED_VAR); 
    UINT32 SerialPortsEnabledVarAttributes=0;
    SERIAL_PORTS_ENABLED_VAR SerialPortsEnabledVar;


    Status = pRS->GetVariable(SERIAL_PORTS_ENABLED_VAR_C_NAME, 
                                &gTerminalVarGuid,
                                &SerialPortsEnabledVarAttributes, 
                                &SerialPortsEnabledVarSize, 
                                &SerialPortsEnabledVar);

    if (!EFI_ERROR(Status)) {
        Status = pRS->GetVariable(PCI_SERIAL_PORTS_LOCATION_VAR_C_NAME, 
                                &gTerminalVarGuid, 
                                NULL, 
                                &PciSerialPortsLocationVarSize, 
                                &PciSerialPortsLocationVar);

        if (!EFI_ERROR(Status)) {
            for (i = 0; i < TOTAL_PCI_SERIAL_PORTS; i++) {
                //
                // Look for the PCI device that are enabled.
                //
                if (SerialPortsEnabledVar.PortsEnabled[gTotalSioSerialPorts+i]) {
                    if ((PciSerialPortsLocationVar.Bus[i] == 0) &&
                        (PciSerialPortsLocationVar.Device[i] == 0) &&
                        (PciSerialPortsLocationVar.Function[i] == 0)) {
                        continue;
                    }
                    
                    DevFunc = (PciSerialPortsLocationVar.Device[i] << 3) + PciSerialPortsLocationVar.Function[i];
                    PciAddr = ((UINT32) (( (UINT16) PciSerialPortsLocationVar.Bus[i] ) << 8) +  DevFunc) << 8;
                    PciAddr += (RegNum & 0xfc);
                    PciAddr |= 0x80000000;

                    IoWrite32(CFG_SPACE_INDEX_REG, PciAddr);
                    BarAddress = IoRead32(CFG_SPACE_DATA_REG);
                    //
                    // Reset the IER register of UART.
                    //
                    if(BarAddress & 1) {
                        IoWrite32(BarAddress, 0);
                    } else {
                        *(UINTN*)( (BarAddress & 0xfffffff0) + 1) = 0;
                    }
                }
            }
            //
            // Replace the Actual INT08h routine which was hooked by Legacy console Redirection 
            //
            *(UINT16*)0x0020 = (UINT16)INT08h_OFFSET;
            *(UINT16*)0x0022 = (UINT16)INT08h_SEGMENT;

            IoWrite8(0x80,0x99);
        }
    }
#endif
    return;
}

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