3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: hal/halx86/generic/legacy/bussupp.c
5 * PURPOSE: HAL Legacy Bus Support Code
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
15 /* GLOBALS ********************************************************************/
17 /* PRIVATE FUNCTIONS **********************************************************/
21 HalpAllocateBusHandler(IN INTERFACE_TYPE InterfaceType
,
22 IN BUS_DATA_TYPE BusDataType
,
24 IN INTERFACE_TYPE ParentBusInterfaceType
,
25 IN ULONG ParentBusNumber
,
26 IN ULONG BusSpecificData
)
30 /* Register the bus handler */
31 HalRegisterBusHandler(InterfaceType
,
34 ParentBusInterfaceType
,
39 if (!Bus
) return NULL
;
41 /* Check for a valid interface */
42 if (InterfaceType
!= InterfaceTypeUndefined
)
44 /* Allocate address ranges and zero them out */
45 Bus
->BusAddresses
= ExAllocatePoolWithTag(NonPagedPool
,
46 sizeof(SUPPORTED_RANGES
),
48 RtlZeroMemory(Bus
->BusAddresses
, sizeof(SUPPORTED_RANGES
));
50 /* Build the data structure */
51 Bus
->BusAddresses
->Version
= HAL_SUPPORTED_RANGE_VERSION
;
52 Bus
->BusAddresses
->Dma
.Limit
= 7;
53 Bus
->BusAddresses
->Memory
.Limit
= 0xFFFFFFFF;
54 Bus
->BusAddresses
->IO
.Limit
= 0xFFFF;
55 Bus
->BusAddresses
->IO
.SystemAddressSpace
= 1;
56 Bus
->BusAddresses
->PrefetchMemory
.Base
= 1;
59 /* Return the bus address */
65 HalpRegisterInternalBusHandlers(VOID
)
69 /* Only do processor 1 */
70 if (KeGetCurrentPrcb()->Number
) return;
72 /* Register root support */
75 /* Allocate the system bus */
76 Bus
= HalpAllocateBusHandler(Internal
,
77 ConfigurationSpaceUndefined
,
79 InterfaceTypeUndefined
,
82 DPRINT1("Registering Internal Bus: %p\n", Bus
);
86 Bus
->GetInterruptVector
= HalpGetSystemInterruptVector
;
87 Bus
->TranslateBusAddress
= HalpTranslateSystemBusAddress
;
90 /* Allocate the CMOS bus */
91 Bus
= HalpAllocateBusHandler(InterfaceTypeUndefined
,
94 InterfaceTypeUndefined
,
97 DPRINT1("Registering CMOS Bus: %p\n", Bus
);
101 Bus
->GetBusData
= HalpcGetCmosData
;
102 Bus
->SetBusData
= HalpcSetCmosData
;
105 /* Allocate the CMOS bus */
106 Bus
= HalpAllocateBusHandler(InterfaceTypeUndefined
,
109 InterfaceTypeUndefined
,
112 DPRINT1("Registering CMOS Bus: %p\n", Bus
);
116 Bus
->GetBusData
= HalpcGetCmosData
;
117 Bus
->SetBusData
= HalpcSetCmosData
;
120 /* Allocate ISA bus */
121 Bus
= HalpAllocateBusHandler(Isa
,
122 ConfigurationSpaceUndefined
,
127 DPRINT1("Registering ISA Bus: %p\n", Bus
);
131 Bus
->GetBusData
= HalpNoBusData
;
132 Bus
->BusAddresses
->Memory
.Limit
= 0xFFFFFF;
133 Bus
->TranslateBusAddress
= HalpTranslateIsaBusAddress
;
136 /* No support for EISA or MCA */
137 ASSERT(HalpBusType
== MACHINE_TYPE_ISA
);
142 HalpInitializePciBus(VOID
)
144 /* FIXME: Should do legacy PCI bus detection */
146 /* FIXME: Should detect chipset hacks */
148 /* FIXME: Should detect broken PCI hardware and apply hacks */
150 /* FIXME: Should build resource ranges */
155 HalpInitBusHandlers(VOID
)
157 /* Register the HAL Bus Handler support */
158 HalpRegisterInternalBusHandlers();
163 HalpRegisterKdSupportFunctions(VOID
)
165 /* Register PCI Device Functions */
166 KdSetupPciDeviceForDebugging
= HalpSetupPciDeviceForDebugging
;
167 KdReleasePciDeviceforDebugging
= HalpReleasePciDeviceForDebugging
;
169 /* Register memory functions */
171 KdMapPhysicalMemory64
= HalpMapPhysicalMemory64
;
172 KdUnmapVirtualAddress
= HalpUnmapVirtualAddress
;
175 /* Register ACPI stub */
176 KdCheckPowerButton
= HalpCheckPowerButton
;
181 HalpAssignSlotResources(IN PUNICODE_STRING RegistryPath
,
182 IN PUNICODE_STRING DriverClassName
,
183 IN PDRIVER_OBJECT DriverObject
,
184 IN PDEVICE_OBJECT DeviceObject
,
185 IN INTERFACE_TYPE BusType
,
188 IN OUT PCM_RESOURCE_LIST
*AllocatedResources
)
190 BUS_HANDLER BusHandler
;
193 /* Only PCI is supported */
194 if (BusType
!= PCIBus
) return STATUS_NOT_IMPLEMENTED
;
196 /* Setup fake PCI Bus handler */
197 RtlCopyMemory(&BusHandler
, &HalpFakePciBusHandler
, sizeof(BUS_HANDLER
));
198 BusHandler
.BusNumber
= BusNumber
;
200 /* Call the PCI function */
201 return HalpAssignPCISlotResources(&BusHandler
,
213 HalpTranslateBusAddress(IN INTERFACE_TYPE InterfaceType
,
215 IN PHYSICAL_ADDRESS BusAddress
,
216 IN OUT PULONG AddressSpace
,
217 OUT PPHYSICAL_ADDRESS TranslatedAddress
)
219 /* Translation is easy */
220 TranslatedAddress
->QuadPart
= BusAddress
.QuadPart
;
226 HalpGetSystemInterruptVector_Acpi(IN ULONG BusNumber
,
227 IN ULONG BusInterruptLevel
,
228 IN ULONG BusInterruptVector
,
230 OUT PKAFFINITY Affinity
)
232 ULONG Vector
= IRQ2VECTOR(BusInterruptLevel
);
233 *Irql
= (KIRQL
)VECTOR2IRQL(Vector
);
234 *Affinity
= 0xFFFFFFFF;
240 HalpFindBusAddressTranslation(IN PHYSICAL_ADDRESS BusAddress
,
241 IN OUT PULONG AddressSpace
,
242 OUT PPHYSICAL_ADDRESS TranslatedAddress
,
243 IN OUT PULONG_PTR Context
,
246 /* Make sure we have a context */
247 if (!Context
) return FALSE
;
249 /* If we have data in the context, then this shouldn't be a new lookup */
250 if ((*Context
) && (NextBus
== TRUE
)) return FALSE
;
252 /* Return bus data */
253 TranslatedAddress
->QuadPart
= BusAddress
.QuadPart
;
255 /* Set context value and return success */
260 /* PUBLIC FUNCTIONS **********************************************************/
267 HalAdjustResourceList(IN PCM_RESOURCE_LIST Resources
)
269 /* Deprecated, return success */
270 return STATUS_SUCCESS
;
278 HalAssignSlotResources(IN PUNICODE_STRING RegistryPath
,
279 IN PUNICODE_STRING DriverClassName
,
280 IN PDRIVER_OBJECT DriverObject
,
281 IN PDEVICE_OBJECT DeviceObject
,
282 IN INTERFACE_TYPE BusType
,
285 IN OUT PCM_RESOURCE_LIST
*AllocatedResources
)
287 /* Check the bus type */
288 if (BusType
!= PCIBus
)
290 /* Call our internal handler */
291 return HalpAssignSlotResources(RegistryPath
,
302 /* Call the PCI registered function */
303 return HalPciAssignSlotResources(RegistryPath
,
319 HalGetBusData(IN BUS_DATA_TYPE BusDataType
,
325 /* Call the extended function */
326 return HalGetBusDataByOffset(BusDataType
,
339 HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType
,
346 BUS_HANDLER BusHandler
;
348 /* Look as the bus type */
349 if (BusDataType
== Cmos
)
351 /* Call CMOS Function */
352 return HalpGetCmosData(0, SlotNumber
, Buffer
, Length
);
354 else if (BusDataType
== EisaConfiguration
)
359 else if ((BusDataType
== PCIConfiguration
) &&
360 (HalpPCIConfigInitialized
) &&
361 ((BusNumber
>= HalpMinPciBus
) && (BusNumber
<= HalpMaxPciBus
)))
363 /* Setup fake PCI Bus handler */
364 RtlCopyMemory(&BusHandler
, &HalpFakePciBusHandler
, sizeof(BUS_HANDLER
));
365 BusHandler
.BusNumber
= BusNumber
;
367 /* Call PCI function */
368 return HalpGetPCIData(&BusHandler
,
370 *(PPCI_SLOT_NUMBER
)&SlotNumber
,
385 HalGetInterruptVector(IN INTERFACE_TYPE InterfaceType
,
387 IN ULONG BusInterruptLevel
,
388 IN ULONG BusInterruptVector
,
390 OUT PKAFFINITY Affinity
)
392 /* Call the system bus translator */
393 return HalpGetSystemInterruptVector_Acpi(BusNumber
,
405 HalSetBusData(IN BUS_DATA_TYPE BusDataType
,
411 /* Call the extended function */
412 return HalSetBusDataByOffset(BusDataType
,
425 HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType
,
432 BUS_HANDLER BusHandler
;
434 /* Look as the bus type */
435 if (BusDataType
== Cmos
)
437 /* Call CMOS Function */
438 return HalpSetCmosData(0, SlotNumber
, Buffer
, Length
);
440 else if ((BusDataType
== PCIConfiguration
) && (HalpPCIConfigInitialized
))
442 /* Setup fake PCI Bus handler */
443 RtlCopyMemory(&BusHandler
, &HalpFakePciBusHandler
, sizeof(BUS_HANDLER
));
444 BusHandler
.BusNumber
= BusNumber
;
446 /* Call PCI function */
447 return HalpSetPCIData(&BusHandler
,
449 *(PPCI_SLOT_NUMBER
)&SlotNumber
,
464 HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType
,
466 IN PHYSICAL_ADDRESS BusAddress
,
467 IN OUT PULONG AddressSpace
,
468 OUT PPHYSICAL_ADDRESS TranslatedAddress
)
470 /* Look as the bus type */
471 if (InterfaceType
== PCIBus
)
473 /* Call the PCI registered function */
474 return HalPciTranslateBusAddress(PCIBus
,
482 /* Translation is easy */
483 TranslatedAddress
->QuadPart
= BusAddress
.QuadPart
;