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