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)
9 /* INCLUDES ******************************************************************/
15 /* GLOBALS *******************************************************************/
19 /* PRIVATE FUNCTIONS *********************************************************/
23 HalpRegisterKdSupportFunctions(VOID
)
25 /* Register PCI Device Functions */
26 KdSetupPciDeviceForDebugging
= HalpSetupPciDeviceForDebugging
;
27 KdReleasePciDeviceforDebugging
= HalpReleasePciDeviceForDebugging
;
29 /* Register memory functions */
30 KdMapPhysicalMemory64
= HalpMapPhysicalMemory64
;
31 KdUnmapVirtualAddress
= HalpUnmapVirtualAddress
;
33 /* Register ACPI stub */
34 KdCheckPowerButton
= HalpCheckPowerButton
;
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
,
46 IN OUT PCM_RESOURCE_LIST
*AllocatedResources
)
48 BUS_HANDLER BusHandler
;
51 /* Only PCI is supported */
52 if (BusType
!= PCIBus
) return STATUS_NOT_IMPLEMENTED
;
54 /* Setup fake PCI Bus handler */
55 RtlCopyMemory(&BusHandler
, &HalpFakePciBusHandler
, sizeof(BUS_HANDLER
));
56 BusHandler
.BusNumber
= BusNumber
;
58 /* Call the PCI function */
59 return HalpAssignPCISlotResources(&BusHandler
,
71 HalpTranslateBusAddress(IN INTERFACE_TYPE InterfaceType
,
73 IN PHYSICAL_ADDRESS BusAddress
,
74 IN OUT PULONG AddressSpace
,
75 OUT PPHYSICAL_ADDRESS TranslatedAddress
)
77 /* Translation is easy */
78 TranslatedAddress
->QuadPart
= BusAddress
.QuadPart
;
84 HalpGetSystemInterruptVector(IN ULONG BusNumber
,
85 IN ULONG BusInterruptLevel
,
86 IN ULONG BusInterruptVector
,
88 OUT PKAFFINITY Affinity
)
90 ULONG Vector
= IRQ2VECTOR(BusInterruptLevel
);
91 *Irql
= (KIRQL
)VECTOR2IRQL(Vector
);
92 *Affinity
= 0xFFFFFFFF;
98 HalpFindBusAddressTranslation(IN PHYSICAL_ADDRESS BusAddress
,
99 IN OUT PULONG AddressSpace
,
100 OUT PPHYSICAL_ADDRESS TranslatedAddress
,
101 IN OUT PULONG_PTR Context
,
104 /* Make sure we have a context */
105 if (!Context
) return FALSE
;
107 /* If we have data in the context, then this shouldn't be a new lookup */
108 if ((*Context
) && (NextBus
== TRUE
)) return FALSE
;
110 /* Return bus data */
111 TranslatedAddress
->QuadPart
= BusAddress
.QuadPart
;
113 /* Set context value and return success */
120 HalpInitNonBusHandler(VOID
)
122 /* These should be written by the PCI driver later, but we give defaults */
123 HalPciTranslateBusAddress
= HalpTranslateBusAddress
;
124 HalPciAssignSlotResources
= HalpAssignSlotResources
;
125 HalFindBusAddressTranslation
= HalpFindBusAddressTranslation
;
128 /* PUBLIC FUNCTIONS **********************************************************/
135 HalAdjustResourceList(IN PCM_RESOURCE_LIST Resources
)
137 /* Deprecated, return success */
138 return STATUS_SUCCESS
;
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
,
153 IN OUT PCM_RESOURCE_LIST
*AllocatedResources
)
155 /* Check the bus type */
156 if (BusType
!= PCIBus
)
158 /* Call our internal handler */
159 return HalpAssignSlotResources(RegistryPath
,
170 /* Call the PCI registered function */
171 return HalPciAssignSlotResources(RegistryPath
,
187 HalGetBusData(IN BUS_DATA_TYPE BusDataType
,
193 /* Call the extended function */
194 return HalGetBusDataByOffset(BusDataType
,
207 HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType
,
214 BUS_HANDLER BusHandler
;
216 /* Look as the bus type */
217 if (BusDataType
== Cmos
)
219 /* Call CMOS Function */
220 return HalpGetCmosData(0, SlotNumber
, Buffer
, Length
);
222 else if (BusDataType
== EisaConfiguration
)
227 else if ((BusDataType
== PCIConfiguration
) &&
228 (HalpPCIConfigInitialized
) &&
229 ((BusNumber
>= HalpMinPciBus
) && (BusNumber
<= HalpMaxPciBus
)))
231 /* Setup fake PCI Bus handler */
232 RtlCopyMemory(&BusHandler
, &HalpFakePciBusHandler
, sizeof(BUS_HANDLER
));
233 BusHandler
.BusNumber
= BusNumber
;
235 /* Call PCI function */
236 return HalpGetPCIData(&BusHandler
,
238 *(PPCI_SLOT_NUMBER
)&SlotNumber
,
253 HalGetInterruptVector(IN INTERFACE_TYPE InterfaceType
,
255 IN ULONG BusInterruptLevel
,
256 IN ULONG BusInterruptVector
,
258 OUT PKAFFINITY Affinity
)
260 /* Call the system bus translator */
261 return HalpGetSystemInterruptVector(BusNumber
,
273 HalSetBusData(IN BUS_DATA_TYPE BusDataType
,
279 /* Call the extended function */
280 return HalSetBusDataByOffset(BusDataType
,
293 HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType
,
300 BUS_HANDLER BusHandler
;
302 /* Look as the bus type */
303 if (BusDataType
== Cmos
)
305 /* Call CMOS Function */
306 return HalpSetCmosData(0, SlotNumber
, Buffer
, Length
);
308 else if ((BusDataType
== PCIConfiguration
) && (HalpPCIConfigInitialized
))
310 /* Setup fake PCI Bus handler */
311 RtlCopyMemory(&BusHandler
, &HalpFakePciBusHandler
, sizeof(BUS_HANDLER
));
312 BusHandler
.BusNumber
= BusNumber
;
314 /* Call PCI function */
315 return HalpSetPCIData(&BusHandler
,
317 *(PPCI_SLOT_NUMBER
)&SlotNumber
,
332 HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType
,
334 IN PHYSICAL_ADDRESS BusAddress
,
335 IN OUT PULONG AddressSpace
,
336 OUT PPHYSICAL_ADDRESS TranslatedAddress
)
338 /* Look as the bus type */
339 if (InterfaceType
== PCIBus
)
341 /* Call the PCI registered function */
342 return HalPciTranslateBusAddress(PCIBus
,
350 /* Translation is easy */
351 TranslatedAddress
->QuadPart
= BusAddress
.QuadPart
;