[IMM32] Improve ImmGetImeInfoEx (#3833)
[reactos.git] / hal / halppc / generic / bus.c
1 /*
2 * PROJECT: ReactOS HAL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: hal/halppc/generic/bus.c
5 * PURPOSE: Bus Support Routines
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <hal.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS *******************************************************************/
16
17 ULONG HalpBusType;
18
19 /* PRIVATE FUNCTIONS *********************************************************/
20
21 VOID
22 NTAPI
23 HalpRegisterKdSupportFunctions(VOID)
24 {
25 /* Register PCI Device Functions */
26 KdSetupPciDeviceForDebugging = HalpSetupPciDeviceForDebugging;
27 KdReleasePciDeviceforDebugging = HalpReleasePciDeviceForDebugging;
28
29 /* Register memory functions */
30 KdMapPhysicalMemory64 = HalpMapPhysicalMemory64;
31 KdUnmapVirtualAddress = HalpUnmapVirtualAddress;
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(IN ULONG BusNumber,
85 IN ULONG BusInterruptLevel,
86 IN ULONG BusInterruptVector,
87 OUT PKIRQL Irql,
88 OUT PKAFFINITY Affinity)
89 {
90 ULONG Vector = IRQ2VECTOR(BusInterruptLevel);
91 *Irql = (KIRQL)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 != 0) && (NextBus != FALSE)) 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 VOID
119 NTAPI
120 HalpInitNonBusHandler(VOID)
121 {
122 /* These should be written by the PCI driver later, but we give defaults */
123 HalPciTranslateBusAddress = HalpTranslateBusAddress;
124 HalPciAssignSlotResources = HalpAssignSlotResources;
125 HalFindBusAddressTranslation = HalpFindBusAddressTranslation;
126 }
127
128 /* PUBLIC FUNCTIONS **********************************************************/
129
130 /*
131 * @implemented
132 */
133 NTSTATUS
134 NTAPI
135 HalAdjustResourceList(IN PCM_RESOURCE_LIST Resources)
136 {
137 /* Deprecated, return success */
138 return STATUS_SUCCESS;
139 }
140
141 /*
142 * @implemented
143 */
144 NTSTATUS
145 NTAPI
146 HalAssignSlotResources(IN PUNICODE_STRING RegistryPath,
147 IN PUNICODE_STRING DriverClassName,
148 IN PDRIVER_OBJECT DriverObject,
149 IN PDEVICE_OBJECT DeviceObject,
150 IN INTERFACE_TYPE BusType,
151 IN ULONG BusNumber,
152 IN ULONG SlotNumber,
153 IN OUT PCM_RESOURCE_LIST *AllocatedResources)
154 {
155 /* Check the bus type */
156 if (BusType != PCIBus)
157 {
158 /* Call our internal handler */
159 return HalpAssignSlotResources(RegistryPath,
160 DriverClassName,
161 DriverObject,
162 DeviceObject,
163 BusType,
164 BusNumber,
165 SlotNumber,
166 AllocatedResources);
167 }
168 else
169 {
170 /* Call the PCI registered function */
171 return HalPciAssignSlotResources(RegistryPath,
172 DriverClassName,
173 DriverObject,
174 DeviceObject,
175 PCIBus,
176 BusNumber,
177 SlotNumber,
178 AllocatedResources);
179 }
180 }
181
182 /*
183 * @implemented
184 */
185 ULONG
186 NTAPI
187 HalGetBusData(IN BUS_DATA_TYPE BusDataType,
188 IN ULONG BusNumber,
189 IN ULONG SlotNumber,
190 IN PVOID Buffer,
191 IN ULONG Length)
192 {
193 /* Call the extended function */
194 return HalGetBusDataByOffset(BusDataType,
195 BusNumber,
196 SlotNumber,
197 Buffer,
198 0,
199 Length);
200 }
201
202 /*
203 * @implemented
204 */
205 ULONG
206 NTAPI
207 HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType,
208 IN ULONG BusNumber,
209 IN ULONG SlotNumber,
210 IN PVOID Buffer,
211 IN ULONG Offset,
212 IN ULONG Length)
213 {
214 BUS_HANDLER BusHandler;
215
216 /* Look as the bus type */
217 if (BusDataType == Cmos)
218 {
219 /* Call CMOS Function */
220 return HalpGetCmosData(0, SlotNumber, Buffer, Length);
221 }
222 else if (BusDataType == EisaConfiguration)
223 {
224 /* FIXME: TODO */
225 ASSERT(FALSE);
226 }
227 else if ((BusDataType == PCIConfiguration) &&
228 (HalpPCIConfigInitialized) &&
229 ((BusNumber >= HalpMinPciBus) && (BusNumber <= HalpMaxPciBus)))
230 {
231 /* Setup fake PCI Bus handler */
232 RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
233 BusHandler.BusNumber = BusNumber;
234
235 /* Call PCI function */
236 return HalpGetPCIData(&BusHandler,
237 &BusHandler,
238 *(PPCI_SLOT_NUMBER)&SlotNumber,
239 Buffer,
240 Offset,
241 Length);
242 }
243
244 /* Invalid bus */
245 return 0;
246 }
247
248 /*
249 * @implemented
250 */
251 ULONG
252 NTAPI
253 HalGetInterruptVector(IN INTERFACE_TYPE InterfaceType,
254 IN ULONG BusNumber,
255 IN ULONG BusInterruptLevel,
256 IN ULONG BusInterruptVector,
257 OUT PKIRQL Irql,
258 OUT PKAFFINITY Affinity)
259 {
260 /* Call the system bus translator */
261 return HalpGetSystemInterruptVector(BusNumber,
262 BusInterruptLevel,
263 BusInterruptVector,
264 Irql,
265 Affinity);
266 }
267
268 /*
269 * @implemented
270 */
271 ULONG
272 NTAPI
273 HalSetBusData(IN BUS_DATA_TYPE BusDataType,
274 IN ULONG BusNumber,
275 IN ULONG SlotNumber,
276 IN PVOID Buffer,
277 IN ULONG Length)
278 {
279 /* Call the extended function */
280 return HalSetBusDataByOffset(BusDataType,
281 BusNumber,
282 SlotNumber,
283 Buffer,
284 0,
285 Length);
286 }
287
288 /*
289 * @implemented
290 */
291 ULONG
292 NTAPI
293 HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType,
294 IN ULONG BusNumber,
295 IN ULONG SlotNumber,
296 IN PVOID Buffer,
297 IN ULONG Offset,
298 IN ULONG Length)
299 {
300 BUS_HANDLER BusHandler;
301
302 /* Look as the bus type */
303 if (BusDataType == Cmos)
304 {
305 /* Call CMOS Function */
306 return HalpSetCmosData(0, SlotNumber, Buffer, Length);
307 }
308 else if ((BusDataType == PCIConfiguration) && (HalpPCIConfigInitialized))
309 {
310 /* Setup fake PCI Bus handler */
311 RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
312 BusHandler.BusNumber = BusNumber;
313
314 /* Call PCI function */
315 return HalpSetPCIData(&BusHandler,
316 &BusHandler,
317 *(PPCI_SLOT_NUMBER)&SlotNumber,
318 Buffer,
319 Offset,
320 Length);
321 }
322
323 /* Invalid bus */
324 return 0;
325 }
326
327 /*
328 * @implemented
329 */
330 BOOLEAN
331 NTAPI
332 HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType,
333 IN ULONG BusNumber,
334 IN PHYSICAL_ADDRESS BusAddress,
335 IN OUT PULONG AddressSpace,
336 OUT PPHYSICAL_ADDRESS TranslatedAddress)
337 {
338 /* Look as the bus type */
339 if (InterfaceType == PCIBus)
340 {
341 /* Call the PCI registered function */
342 return HalPciTranslateBusAddress(PCIBus,
343 BusNumber,
344 BusAddress,
345 AddressSpace,
346 TranslatedAddress);
347 }
348 else
349 {
350 /* Translation is easy */
351 TranslatedAddress->QuadPart = BusAddress.QuadPart;
352 return TRUE;
353 }
354 }
355
356 /* EOF */