]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Csm/CsmSupportLib/LegacyInterrupt.c
cd984174ab905459aad10c52a9fcb512e22ece9d
[mirror_edk2.git] / OvmfPkg / Csm / CsmSupportLib / LegacyInterrupt.c
1 /** @file
2 Legacy Interrupt Support
3
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials are
7 licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "LegacyInterrupt.h"
17
18 //
19 // Handle for the Legacy Interrupt Protocol instance produced by this driver
20 //
21 STATIC EFI_HANDLE mLegacyInterruptHandle = NULL;
22
23 //
24 // The Legacy Interrupt Protocol instance produced by this driver
25 //
26 STATIC EFI_LEGACY_INTERRUPT_PROTOCOL mLegacyInterrupt = {
27 GetNumberPirqs,
28 GetLocation,
29 ReadPirq,
30 WritePirq
31 };
32
33 STATIC UINT8 PirqReg[MAX_PIRQ_NUMBER] = { PIRQA, PIRQB, PIRQC, PIRQD, PIRQE, PIRQF, PIRQG, PIRQH };
34
35
36 /**
37 Return the number of PIRQs supported by this chipset.
38
39 @param[in] This Pointer to LegacyInterrupt Protocol
40 @param[out] NumberPirqs The pointer to return the max IRQ number supported
41
42 @retval EFI_SUCCESS Max PIRQs successfully returned
43
44 **/
45 EFI_STATUS
46 EFIAPI
47 GetNumberPirqs (
48 IN EFI_LEGACY_INTERRUPT_PROTOCOL *This,
49 OUT UINT8 *NumberPirqs
50 )
51 {
52 *NumberPirqs = MAX_PIRQ_NUMBER;
53
54 return EFI_SUCCESS;
55 }
56
57
58 /**
59 Return PCI location of this device.
60 $PIR table requires this info.
61
62 @param[in] This - Protocol instance pointer.
63 @param[out] Bus - PCI Bus
64 @param[out] Device - PCI Device
65 @param[out] Function - PCI Function
66
67 @retval EFI_SUCCESS Bus/Device/Function returned
68
69 **/
70 EFI_STATUS
71 EFIAPI
72 GetLocation (
73 IN EFI_LEGACY_INTERRUPT_PROTOCOL *This,
74 OUT UINT8 *Bus,
75 OUT UINT8 *Device,
76 OUT UINT8 *Function
77 )
78 {
79 *Bus = LEGACY_INT_BUS;
80 *Device = LEGACY_INT_DEV;
81 *Function = LEGACY_INT_FUNC;
82
83 return EFI_SUCCESS;
84 }
85
86
87 /**
88 Builds the PCI configuration address for the register specified by PirqNumber
89
90 @param[in] PirqNumber - The PIRQ number to build the PCI configuration address for
91
92 @return The PCI Configuration address for the PIRQ
93 **/
94 UINTN
95 GetAddress (
96 UINT8 PirqNumber
97 )
98 {
99 return PCI_LIB_ADDRESS(
100 LEGACY_INT_BUS,
101 LEGACY_INT_DEV,
102 LEGACY_INT_FUNC,
103 PirqReg[PirqNumber]
104 );
105 }
106
107 /**
108 Read the given PIRQ register
109
110 @param[in] This Protocol instance pointer
111 @param[in] PirqNumber The Pirq register 0 = A, 1 = B etc
112 @param[out] PirqData Value read
113
114 @retval EFI_SUCCESS Decoding change affected.
115 @retval EFI_INVALID_PARAMETER Invalid PIRQ number
116
117 **/
118 EFI_STATUS
119 EFIAPI
120 ReadPirq (
121 IN EFI_LEGACY_INTERRUPT_PROTOCOL *This,
122 IN UINT8 PirqNumber,
123 OUT UINT8 *PirqData
124 )
125 {
126 if (PirqNumber >= MAX_PIRQ_NUMBER) {
127 return EFI_INVALID_PARAMETER;
128 }
129
130 *PirqData = PciRead8 (GetAddress (PirqNumber));
131 *PirqData = (UINT8) (*PirqData & 0x7f);
132
133 return EFI_SUCCESS;
134 }
135
136
137 /**
138 Write the given PIRQ register
139
140 @param[in] This Protocol instance pointer
141 @param[in] PirqNumber The Pirq register 0 = A, 1 = B etc
142 @param[out] PirqData Value to write
143
144 @retval EFI_SUCCESS Decoding change affected.
145 @retval EFI_INVALID_PARAMETER Invalid PIRQ number
146
147 **/
148 EFI_STATUS
149 EFIAPI
150 WritePirq (
151 IN EFI_LEGACY_INTERRUPT_PROTOCOL *This,
152 IN UINT8 PirqNumber,
153 IN UINT8 PirqData
154 )
155 {
156 if (PirqNumber >= MAX_PIRQ_NUMBER) {
157 return EFI_INVALID_PARAMETER;
158 }
159
160 PciWrite8 (GetAddress (PirqNumber), PirqData);
161 return EFI_SUCCESS;
162 }
163
164
165 /**
166 Initialize Legacy Interrupt support
167
168 @retval EFI_SUCCESS Successfully initialized
169
170 **/
171 EFI_STATUS
172 LegacyInterruptInstall (
173 VOID
174 )
175 {
176 EFI_STATUS Status;
177
178 //
179 // Make sure the Legacy Interrupt Protocol is not already installed in the system
180 //
181 ASSERT_PROTOCOL_ALREADY_INSTALLED(NULL, &gEfiLegacyInterruptProtocolGuid);
182
183 //
184 // Make a new handle and install the protocol
185 //
186 Status = gBS->InstallMultipleProtocolInterfaces (
187 &mLegacyInterruptHandle,
188 &gEfiLegacyInterruptProtocolGuid,
189 &mLegacyInterrupt,
190 NULL
191 );
192 ASSERT_EFI_ERROR(Status);
193
194 return Status;
195 }
196