Sync with trunk r63383 .
[reactos.git] / hal / halx86 / acpi / busemul.c
1 /*
2 * PROJECT: ReactOS HAL
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: hal/halx86/generic/acpi/busemul.c
5 * PURPOSE: ACPI HAL Bus Handler Emulation Code
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <hal.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS ********************************************************************/
16
17 /* PRIVATE FUNCTIONS **********************************************************/
18
19 VOID
20 NTAPI
21 HalpRegisterKdSupportFunctions(VOID)
22 {
23 /* Register PCI Device Functions */
24 KdSetupPciDeviceForDebugging = HalpSetupPciDeviceForDebugging;
25 KdReleasePciDeviceforDebugging = HalpReleasePciDeviceForDebugging;
26
27 /* Register memory functions */
28 #ifndef _MINIHAL_
29 KdMapPhysicalMemory64 = HalpMapPhysicalMemory64;
30 KdUnmapVirtualAddress = HalpUnmapVirtualAddress;
31 #endif
32
33 /* Register ACPI stub */
34 KdCheckPowerButton = HalpCheckPowerButton;
35 }
36
37 NTSTATUS
38 NTAPI
39 HalpAssignSlotResources(IN PUNICODE_STRING RegistryPath,
40 IN PUNICODE_STRING DriverClassName,
41 IN PDRIVER_OBJECT DriverObject,
42 IN PDEVICE_OBJECT DeviceObject,
43 IN INTERFACE_TYPE BusType,
44 IN ULONG BusNumber,
45 IN ULONG SlotNumber,
46 IN OUT PCM_RESOURCE_LIST *AllocatedResources)
47 {
48 BUS_HANDLER BusHandler;
49 PAGED_CODE();
50
51 /* Only PCI is supported */
52 if (BusType != PCIBus) return STATUS_NOT_IMPLEMENTED;
53
54 /* Setup fake PCI Bus handler */
55 RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
56 BusHandler.BusNumber = BusNumber;
57
58 /* Call the PCI function */
59 return HalpAssignPCISlotResources(&BusHandler,
60 &BusHandler,
61 RegistryPath,
62 DriverClassName,
63 DriverObject,
64 DeviceObject,
65 SlotNumber,
66 AllocatedResources);
67 }
68
69 BOOLEAN
70 NTAPI
71 HalpTranslateBusAddress(IN INTERFACE_TYPE InterfaceType,
72 IN ULONG BusNumber,
73 IN PHYSICAL_ADDRESS BusAddress,
74 IN OUT PULONG AddressSpace,
75 OUT PPHYSICAL_ADDRESS TranslatedAddress)
76 {
77 /* Translation is easy */
78 TranslatedAddress->QuadPart = BusAddress.QuadPart;
79 return TRUE;
80 }
81
82 ULONG
83 NTAPI
84 HalpGetSystemInterruptVector_Acpi(IN ULONG BusNumber,
85 IN ULONG BusInterruptLevel,
86 IN ULONG BusInterruptVector,
87 OUT PKIRQL Irql,
88 OUT PKAFFINITY Affinity)
89 {
90 UCHAR Vector = IRQ2VECTOR((UCHAR)BusInterruptLevel);
91 *Irql = VECTOR2IRQL(Vector);
92 *Affinity = 0xFFFFFFFF;
93 return Vector;
94 }
95
96 BOOLEAN
97 NTAPI
98 HalpFindBusAddressTranslation(IN PHYSICAL_ADDRESS BusAddress,
99 IN OUT PULONG AddressSpace,
100 OUT PPHYSICAL_ADDRESS TranslatedAddress,
101 IN OUT PULONG_PTR Context,
102 IN BOOLEAN NextBus)
103 {
104 /* Make sure we have a context */
105 if (!Context) return FALSE;
106
107 /* If we have data in the context, then this shouldn't be a new lookup */
108 if ((*Context) && (NextBus == TRUE)) return FALSE;
109
110 /* Return bus data */
111 TranslatedAddress->QuadPart = BusAddress.QuadPart;
112
113 /* Set context value and return success */
114 *Context = 1;
115 return TRUE;
116 }
117
118 /* PUBLIC FUNCTIONS **********************************************************/
119
120 /*
121 * @implemented
122 */
123 NTSTATUS
124 NTAPI
125 HalAdjustResourceList(IN OUT PIO_RESOURCE_REQUIREMENTS_LIST* pRequirementsList)
126 {
127 /* Deprecated, return success */
128 return STATUS_SUCCESS;
129 }
130
131 /*
132 * @implemented
133 */
134 NTSTATUS
135 NTAPI
136 HalAssignSlotResources(IN PUNICODE_STRING RegistryPath,
137 IN PUNICODE_STRING DriverClassName,
138 IN PDRIVER_OBJECT DriverObject,
139 IN PDEVICE_OBJECT DeviceObject,
140 IN INTERFACE_TYPE BusType,
141 IN ULONG BusNumber,
142 IN ULONG SlotNumber,
143 IN OUT PCM_RESOURCE_LIST *AllocatedResources)
144 {
145 /* Check the bus type */
146 if (BusType != PCIBus)
147 {
148 /* Call our internal handler */
149 return HalpAssignSlotResources(RegistryPath,
150 DriverClassName,
151 DriverObject,
152 DeviceObject,
153 BusType,
154 BusNumber,
155 SlotNumber,
156 AllocatedResources);
157 }
158 else
159 {
160 /* Call the PCI registered function */
161 return HalPciAssignSlotResources(RegistryPath,
162 DriverClassName,
163 DriverObject,
164 DeviceObject,
165 PCIBus,
166 BusNumber,
167 SlotNumber,
168 AllocatedResources);
169 }
170 }
171
172 /*
173 * @implemented
174 */
175 ULONG
176 NTAPI
177 HalGetBusData(IN BUS_DATA_TYPE BusDataType,
178 IN ULONG BusNumber,
179 IN ULONG SlotNumber,
180 IN PVOID Buffer,
181 IN ULONG Length)
182 {
183 /* Call the extended function */
184 return HalGetBusDataByOffset(BusDataType,
185 BusNumber,
186 SlotNumber,
187 Buffer,
188 0,
189 Length);
190 }
191
192 /*
193 * @implemented
194 */
195 ULONG
196 NTAPI
197 HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType,
198 IN ULONG BusNumber,
199 IN ULONG SlotNumber,
200 IN PVOID Buffer,
201 IN ULONG Offset,
202 IN ULONG Length)
203 {
204 BUS_HANDLER BusHandler;
205
206 /* Look as the bus type */
207 if (BusDataType == Cmos)
208 {
209 /* Call CMOS Function */
210 return HalpGetCmosData(0, SlotNumber, Buffer, Length);
211 }
212 else if (BusDataType == EisaConfiguration)
213 {
214 /* FIXME: TODO */
215 ASSERT(FALSE);
216 }
217 else if ((BusDataType == PCIConfiguration) &&
218 (HalpPCIConfigInitialized) &&
219 ((BusNumber >= HalpMinPciBus) && (BusNumber <= HalpMaxPciBus)))
220 {
221 /* Setup fake PCI Bus handler */
222 RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
223 BusHandler.BusNumber = BusNumber;
224
225 /* Call PCI function */
226 return HalpGetPCIData(&BusHandler,
227 &BusHandler,
228 *(PPCI_SLOT_NUMBER)&SlotNumber,
229 Buffer,
230 Offset,
231 Length);
232 }
233
234 /* Invalid bus */
235 return 0;
236 }
237
238 /*
239 * @implemented
240 */
241 ULONG
242 NTAPI
243 HalGetInterruptVector(IN INTERFACE_TYPE InterfaceType,
244 IN ULONG BusNumber,
245 IN ULONG BusInterruptLevel,
246 IN ULONG BusInterruptVector,
247 OUT PKIRQL Irql,
248 OUT PKAFFINITY Affinity)
249 {
250 /* Call the system bus translator */
251 return HalpGetSystemInterruptVector_Acpi(BusNumber,
252 BusInterruptLevel,
253 BusInterruptVector,
254 Irql,
255 Affinity);
256 }
257
258 /*
259 * @implemented
260 */
261 ULONG
262 NTAPI
263 HalSetBusData(IN BUS_DATA_TYPE BusDataType,
264 IN ULONG BusNumber,
265 IN ULONG SlotNumber,
266 IN PVOID Buffer,
267 IN ULONG Length)
268 {
269 /* Call the extended function */
270 return HalSetBusDataByOffset(BusDataType,
271 BusNumber,
272 SlotNumber,
273 Buffer,
274 0,
275 Length);
276 }
277
278 /*
279 * @implemented
280 */
281 ULONG
282 NTAPI
283 HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType,
284 IN ULONG BusNumber,
285 IN ULONG SlotNumber,
286 IN PVOID Buffer,
287 IN ULONG Offset,
288 IN ULONG Length)
289 {
290 BUS_HANDLER BusHandler;
291
292 /* Look as the bus type */
293 if (BusDataType == Cmos)
294 {
295 /* Call CMOS Function */
296 return HalpSetCmosData(0, SlotNumber, Buffer, Length);
297 }
298 else if ((BusDataType == PCIConfiguration) && (HalpPCIConfigInitialized))
299 {
300 /* Setup fake PCI Bus handler */
301 RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
302 BusHandler.BusNumber = BusNumber;
303
304 /* Call PCI function */
305 return HalpSetPCIData(&BusHandler,
306 &BusHandler,
307 *(PPCI_SLOT_NUMBER)&SlotNumber,
308 Buffer,
309 Offset,
310 Length);
311 }
312
313 /* Invalid bus */
314 return 0;
315 }
316
317 /*
318 * @implemented
319 */
320 BOOLEAN
321 NTAPI
322 HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType,
323 IN ULONG BusNumber,
324 IN PHYSICAL_ADDRESS BusAddress,
325 IN OUT PULONG AddressSpace,
326 OUT PPHYSICAL_ADDRESS TranslatedAddress)
327 {
328 /* Look as the bus type */
329 if (InterfaceType == PCIBus)
330 {
331 /* Call the PCI registered function */
332 return HalPciTranslateBusAddress(PCIBus,
333 BusNumber,
334 BusAddress,
335 AddressSpace,
336 TranslatedAddress);
337 }
338 else
339 {
340 /* Translation is easy */
341 TranslatedAddress->QuadPart = BusAddress.QuadPart;
342 return TRUE;
343 }
344 }
345
346 /* EOF */