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