summaryrefslogtreecommitdiff
path: root/Chipset/SB/CSM/LegacyInterrupt/LegacyInterrupt.c
blob: 6177f8ae3a4bad9fc5bff2136b45cbc4ee7d996a (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
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2010, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**           5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093      **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/CSM/Generic/Chipset/SouthBridge/LegacyInterrupt.c 14    7/28/10 2:46p Olegi $
//
// $Revision: 14 $
//
// $Date: 7/28/10 2:46p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/CSM/Generic/Chipset/SouthBridge/LegacyInterrupt.c $
// 
// 14    7/28/10 2:46p Olegi
// 
// 13    1/12/10 11:51a Olegi
// Copyright message updated.
//
// 12    10/14/09 12:26p Krishnakumarg
// CloseEvent funtion used instead of a static variable in callback
// routines - EIP 27065
// 
// 11    4/27/07 5:43p Olegi
//
// 10    4/27/07 5:39p Olegi
//
// 9     4/27/07 5:21p Olegi
// CSM.CHM preparations.
//
// 8     10/13/06 12:32a Felixp
// UEFI2.0 compliance: use CreateReadyToBootEvent instead of
// CreateEvent(READY_TO_BOOT)
//
// 7     5/27/05 4:24p Markw
// Added Boot Script.
//
// 6     4/04/05 4:19p Sivagarn
// Updated to latest template format
//
// 2     2/22/05 10:00a Sivagarn
// - Updated to latest labeled CSM & Core
//
// 5     1/18/05 3:22p Felixp
// PrintDebugMessage renamed to Trace
//
// 4     12/09/04 10:59a Olegi
//
// 3     12/06/04 9:37a Olegi
// Added interrupt router registers' buffering.
//
// 2     12/03/04 9:55a Olegi
//
// 1     10/26/04 9:48a Olegi
//
// 3     8/31/04 5:46p Markw
// Fixed bug. Using wrong value to index PirqReg.
//
// 2     8/25/04 4:58p Markw
// Added comments.
//
// 1     8/25/04 3:01p Markw
//
// 1     8/13/04 2:39p Markw
//
//**********************************************************************
//<AMI_FHDR_START>
//
// Name: 8259InterruptController.c
//
// Description: Initialize and provide a protocol to set PIRQ values
//
//<AMI_FHDR_END>
//**********************************************************************

#include <AmiDxeLib.h>
#include <Protocol\PciRootBridgeIo.h>
#include <Protocol\LegacyInterrupt.h>
#include <Protocol\BootScriptSave.h>

extern  UINT8   bMaxPIRQ;
extern  UINT8   bRouterBus;
extern  UINT8   bRouterDevice;
extern  UINT8   bRouterFunction;

EFI_GUID gEfiLegacyInterruptProtocolGuid    = EFI_LEGACY_INTERRUPT_PROTOCOL_GUID;
EFI_GUID gEfiPciRootBridgeIoProtocolGuid    = EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID;
EFI_GUID gEfiBootScriptSaveGuid             = EFI_BOOT_SCRIPT_SAVE_GUID;

EFI_EVENT   gEvtBootScript;

extern
EFI_STATUS
SBGen_InitializeRouterRegisters (
        EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *gPciRootBridgeIo);

extern
EFI_STATUS
SBGen_ReadPirq (
    IN EFI_LEGACY_INTERRUPT_PROTOCOL    *This,
    IN UINT8                            PirqNumber,
    OUT UINT8                           *PirqData);

EFI_STATUS
SBGen_WritePirq(
    IN EFI_LEGACY_INTERRUPT_PROTOCOL    *This,
    IN UINT8                            PirqNumber,
    IN UINT8                            PirqData);

EFI_STATUS SBGen_WriteBootScript(
    IN EFI_BOOT_SCRIPT_SAVE_PROTOCOL *BootScriptSave
);

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure:   GetNumberPirqs
//
// Description:  Return number of supported Pirqs.
//
// Input:
//  IN EFI_LEGACY_INTERRUPT_PROTOCOL    *This
//  OUT UINT8                           *NumberPirqs
//
// Output:
//  Status of the operation
//
// Notes:
//  Here is the control flow of this function:
//  1. Set NumberPirqs to number of supported Pirqs.
//  2. Return EFI_SUCCESS;
//
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS GetNumberPirqs(
    IN EFI_LEGACY_INTERRUPT_PROTOCOL    *This,
    OUT UINT8                           *NumberPirqs
    )
{
    *NumberPirqs = bMaxPIRQ;
    return EFI_SUCCESS;
}

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure:   GetLocation
//
// Description: Return location of device controlling the Pirqs.
//
// Input:
//  IN EFI_LEGACY_INTERRUPT_PROTOCOL    *This
//  OUT UINT8                           *Bus
//  OUT UINT8                           *Device
//  OUT UINT8                           *Function
//
// Output:
//  Status of the operation
//
// Notes:
//  Here is the control flow of this function:
//  1. Set Bus, Device, and Function.
//  2. Return EFI_SUCCESS.
//
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS GetLocation(
    IN EFI_LEGACY_INTERRUPT_PROTOCOL    *This,
    OUT UINT8                           *Bus,
    OUT UINT8                           *Device,
    OUT UINT8                           *Function
    )
{
    *Bus        = bRouterBus;
    *Device     = bRouterDevice;
    *Function   = bRouterFunction;
    return EFI_SUCCESS;
}



EFI_LEGACY_INTERRUPT_PROTOCOL gEfiLegacyInterruptProtocol =
{
    GetNumberPirqs, GetLocation,
    SBGen_ReadPirq, SBGen_WritePirq
};

//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure:   CallbackBootScript
//
// Description: Saves the PIRQ registers to Boot Script
//
// Input:
//      IN EFI_EVENT    Event
//      IN VOID         *Context
// Output:
//      None
//
//<AMI_PHDR_END>
//**********************************************************************
VOID CallbackBootScript(IN EFI_EVENT Event, IN VOID *Context)
{
    EFI_BOOT_SCRIPT_SAVE_PROTOCOL *BootScriptSave;
    EFI_STATUS  Status;


    Status = pBS->LocateProtocol(
        &gEfiBootScriptSaveGuid,
        NULL,
        &BootScriptSave
        );
    if (EFI_ERROR(Status)) return;

    SBGen_WriteBootScript(BootScriptSave);
	
    //
    //Kill the Event
	//
    pBS->CloseEvent(Event);

}


//**********************************************************************
//<AMI_PHDR_START>
//
// Procedure:   InitializeLegacyInterrupt
//
// Description: Install Legacy Interrupt Protocol.
//
// Input:
//  IN EFI_HANDLE        ImageHandle
//  IN EFI_SYSTEM_TABLE  *SystemTable
//
// Output:
//  EFI_STATUS
//
// Notes:
//  Here is the control flow of this function:
//  1. Intialize Library.
//  2. Locate PciRootBridgeIo. If error, return error.
//  3. Install Legacy Interrupt protocol.
//  4. Return its Status.
//<AMI_PHDR_END>
//**********************************************************************
EFI_STATUS InitializeLegacyInterrupt(
    IN EFI_HANDLE        ImageHandle,
    IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
    EFI_STATUS                      Status;
    EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *gPciRootBridgeIo;

    InitAmiLib(ImageHandle, SystemTable);

    Status = pBS->LocateProtocol(
        &gEfiPciRootBridgeIoProtocolGuid,
        NULL,
        &gPciRootBridgeIo
    );
    if (EFI_ERROR(Status)) return Status;

    //Create event for boot script
    Status = CreateReadyToBootEvent(
        TPL_NOTIFY,
        CallbackBootScript,
        NULL,
        &gEvtBootScript
    );
    ASSERT_EFI_ERROR(Status);

    //
    // Initialize router registers buffer
    //
    Status = SBGen_InitializeRouterRegisters (gPciRootBridgeIo);
    if (EFI_ERROR(Status)) return Status;

    return pBS->InstallMultipleProtocolInterfaces(
        &ImageHandle,
        &gEfiLegacyInterruptProtocolGuid, &gEfiLegacyInterruptProtocol,
        NULL
        );
}

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