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