mirror of
https://github.com/reactos/reactos.git
synced 2024-08-26 13:18:51 +00:00
![Timo Kreuzer](/assets/img/avatar_default.png)
* Add an NDK header to define INIT_FUNCTION/INIT_SECTION globally * Use _declspec(allocate(x)) and _declspec(code_seg(x)) on MSVC versions that support it * Use INIT_FUNCTION on functions only and INIT_SECTION on data only (required by MSVC) * Place INIT_FUNCTION before the return type (required by MSVC) * Make sure declarations and implementations share the same modifiers (required by MSVC) * Add a global linker option to suppress warnings about defined but unused INIT section * Merge INIT section into .text in freeldr
353 lines
10 KiB
C
353 lines
10 KiB
C
/*
|
|
* PROJECT: ReactOS HAL
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
|
* FILE: hal/halx86/acpi/busemul.c
|
|
* PURPOSE: ACPI HAL Bus Handler Emulation Code
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
|
*/
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
#include <hal.h>
|
|
#define NDEBUG
|
|
#include <debug.h>
|
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
|
|
|
INIT_FUNCTION
|
|
VOID
|
|
NTAPI
|
|
HalpRegisterKdSupportFunctions(VOID)
|
|
{
|
|
/* Register PCI Device Functions */
|
|
KdSetupPciDeviceForDebugging = HalpSetupPciDeviceForDebugging;
|
|
KdReleasePciDeviceforDebugging = HalpReleasePciDeviceForDebugging;
|
|
|
|
/* Register memory functions */
|
|
#ifndef _MINIHAL_
|
|
#if (NTDDI_VERSION >= NTDDI_VISTA)
|
|
KdMapPhysicalMemory64 = HalpMapPhysicalMemory64Vista;
|
|
KdUnmapVirtualAddress = HalpUnmapVirtualAddressVista;
|
|
#else
|
|
KdMapPhysicalMemory64 = HalpMapPhysicalMemory64;
|
|
KdUnmapVirtualAddress = HalpUnmapVirtualAddress;
|
|
#endif
|
|
#endif
|
|
|
|
/* Register ACPI stub */
|
|
KdCheckPowerButton = HalpCheckPowerButton;
|
|
}
|
|
|
|
NTSTATUS
|
|
NTAPI
|
|
HalpAssignSlotResources(IN PUNICODE_STRING RegistryPath,
|
|
IN PUNICODE_STRING DriverClassName,
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
IN INTERFACE_TYPE BusType,
|
|
IN ULONG BusNumber,
|
|
IN ULONG SlotNumber,
|
|
IN OUT PCM_RESOURCE_LIST *AllocatedResources)
|
|
{
|
|
BUS_HANDLER BusHandler;
|
|
PAGED_CODE();
|
|
|
|
/* Only PCI is supported */
|
|
if (BusType != PCIBus) return STATUS_NOT_IMPLEMENTED;
|
|
|
|
/* Setup fake PCI Bus handler */
|
|
RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
|
|
BusHandler.BusNumber = BusNumber;
|
|
|
|
/* Call the PCI function */
|
|
return HalpAssignPCISlotResources(&BusHandler,
|
|
&BusHandler,
|
|
RegistryPath,
|
|
DriverClassName,
|
|
DriverObject,
|
|
DeviceObject,
|
|
SlotNumber,
|
|
AllocatedResources);
|
|
}
|
|
|
|
BOOLEAN
|
|
NTAPI
|
|
HalpTranslateBusAddress(IN INTERFACE_TYPE InterfaceType,
|
|
IN ULONG BusNumber,
|
|
IN PHYSICAL_ADDRESS BusAddress,
|
|
IN OUT PULONG AddressSpace,
|
|
OUT PPHYSICAL_ADDRESS TranslatedAddress)
|
|
{
|
|
/* Translation is easy */
|
|
TranslatedAddress->QuadPart = BusAddress.QuadPart;
|
|
return TRUE;
|
|
}
|
|
|
|
ULONG
|
|
NTAPI
|
|
HalpGetSystemInterruptVector_Acpi(IN ULONG BusNumber,
|
|
IN ULONG BusInterruptLevel,
|
|
IN ULONG BusInterruptVector,
|
|
OUT PKIRQL Irql,
|
|
OUT PKAFFINITY Affinity)
|
|
{
|
|
UCHAR Vector = IRQ2VECTOR((UCHAR)BusInterruptLevel);
|
|
*Irql = VECTOR2IRQL(Vector);
|
|
*Affinity = 0xFFFFFFFF;
|
|
return Vector;
|
|
}
|
|
|
|
BOOLEAN
|
|
NTAPI
|
|
HalpFindBusAddressTranslation(IN PHYSICAL_ADDRESS BusAddress,
|
|
IN OUT PULONG AddressSpace,
|
|
OUT PPHYSICAL_ADDRESS TranslatedAddress,
|
|
IN OUT PULONG_PTR Context,
|
|
IN BOOLEAN NextBus)
|
|
{
|
|
/* Make sure we have a context */
|
|
if (!Context) return FALSE;
|
|
|
|
/* If we have data in the context, then this shouldn't be a new lookup */
|
|
if ((*Context != 0) && (NextBus != FALSE)) return FALSE;
|
|
|
|
/* Return bus data */
|
|
TranslatedAddress->QuadPart = BusAddress.QuadPart;
|
|
|
|
/* Set context value and return success */
|
|
*Context = 1;
|
|
return TRUE;
|
|
}
|
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
NTSTATUS
|
|
NTAPI
|
|
HalAdjustResourceList(IN OUT PIO_RESOURCE_REQUIREMENTS_LIST* pRequirementsList)
|
|
{
|
|
/* Deprecated, return success */
|
|
return STATUS_SUCCESS;
|
|
}
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
NTSTATUS
|
|
NTAPI
|
|
HalAssignSlotResources(IN PUNICODE_STRING RegistryPath,
|
|
IN PUNICODE_STRING DriverClassName,
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
IN INTERFACE_TYPE BusType,
|
|
IN ULONG BusNumber,
|
|
IN ULONG SlotNumber,
|
|
IN OUT PCM_RESOURCE_LIST *AllocatedResources)
|
|
{
|
|
/* Check the bus type */
|
|
if (BusType != PCIBus)
|
|
{
|
|
/* Call our internal handler */
|
|
return HalpAssignSlotResources(RegistryPath,
|
|
DriverClassName,
|
|
DriverObject,
|
|
DeviceObject,
|
|
BusType,
|
|
BusNumber,
|
|
SlotNumber,
|
|
AllocatedResources);
|
|
}
|
|
else
|
|
{
|
|
/* Call the PCI registered function */
|
|
return HalPciAssignSlotResources(RegistryPath,
|
|
DriverClassName,
|
|
DriverObject,
|
|
DeviceObject,
|
|
PCIBus,
|
|
BusNumber,
|
|
SlotNumber,
|
|
AllocatedResources);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
ULONG
|
|
NTAPI
|
|
HalGetBusData(IN BUS_DATA_TYPE BusDataType,
|
|
IN ULONG BusNumber,
|
|
IN ULONG SlotNumber,
|
|
IN PVOID Buffer,
|
|
IN ULONG Length)
|
|
{
|
|
/* Call the extended function */
|
|
return HalGetBusDataByOffset(BusDataType,
|
|
BusNumber,
|
|
SlotNumber,
|
|
Buffer,
|
|
0,
|
|
Length);
|
|
}
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
ULONG
|
|
NTAPI
|
|
HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType,
|
|
IN ULONG BusNumber,
|
|
IN ULONG SlotNumber,
|
|
IN PVOID Buffer,
|
|
IN ULONG Offset,
|
|
IN ULONG Length)
|
|
{
|
|
BUS_HANDLER BusHandler;
|
|
|
|
/* Look as the bus type */
|
|
if (BusDataType == Cmos)
|
|
{
|
|
/* Call CMOS Function */
|
|
return HalpGetCmosData(0, SlotNumber, Buffer, Length);
|
|
}
|
|
else if (BusDataType == EisaConfiguration)
|
|
{
|
|
/* FIXME: TODO */
|
|
ASSERT(FALSE);
|
|
}
|
|
else if ((BusDataType == PCIConfiguration) &&
|
|
(HalpPCIConfigInitialized) &&
|
|
((BusNumber >= HalpMinPciBus) && (BusNumber <= HalpMaxPciBus)))
|
|
{
|
|
/* Setup fake PCI Bus handler */
|
|
RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
|
|
BusHandler.BusNumber = BusNumber;
|
|
|
|
/* Call PCI function */
|
|
return HalpGetPCIData(&BusHandler,
|
|
&BusHandler,
|
|
SlotNumber,
|
|
Buffer,
|
|
Offset,
|
|
Length);
|
|
}
|
|
|
|
/* Invalid bus */
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
ULONG
|
|
NTAPI
|
|
HalGetInterruptVector(IN INTERFACE_TYPE InterfaceType,
|
|
IN ULONG BusNumber,
|
|
IN ULONG BusInterruptLevel,
|
|
IN ULONG BusInterruptVector,
|
|
OUT PKIRQL Irql,
|
|
OUT PKAFFINITY Affinity)
|
|
{
|
|
/* Call the system bus translator */
|
|
return HalpGetSystemInterruptVector_Acpi(BusNumber,
|
|
BusInterruptLevel,
|
|
BusInterruptVector,
|
|
Irql,
|
|
Affinity);
|
|
}
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
ULONG
|
|
NTAPI
|
|
HalSetBusData(IN BUS_DATA_TYPE BusDataType,
|
|
IN ULONG BusNumber,
|
|
IN ULONG SlotNumber,
|
|
IN PVOID Buffer,
|
|
IN ULONG Length)
|
|
{
|
|
/* Call the extended function */
|
|
return HalSetBusDataByOffset(BusDataType,
|
|
BusNumber,
|
|
SlotNumber,
|
|
Buffer,
|
|
0,
|
|
Length);
|
|
}
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
ULONG
|
|
NTAPI
|
|
HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType,
|
|
IN ULONG BusNumber,
|
|
IN ULONG SlotNumber,
|
|
IN PVOID Buffer,
|
|
IN ULONG Offset,
|
|
IN ULONG Length)
|
|
{
|
|
BUS_HANDLER BusHandler;
|
|
|
|
/* Look as the bus type */
|
|
if (BusDataType == Cmos)
|
|
{
|
|
/* Call CMOS Function */
|
|
return HalpSetCmosData(0, SlotNumber, Buffer, Length);
|
|
}
|
|
else if ((BusDataType == PCIConfiguration) && (HalpPCIConfigInitialized))
|
|
{
|
|
/* Setup fake PCI Bus handler */
|
|
RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
|
|
BusHandler.BusNumber = BusNumber;
|
|
|
|
/* Call PCI function */
|
|
return HalpSetPCIData(&BusHandler,
|
|
&BusHandler,
|
|
SlotNumber,
|
|
Buffer,
|
|
Offset,
|
|
Length);
|
|
}
|
|
|
|
/* Invalid bus */
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
BOOLEAN
|
|
NTAPI
|
|
HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType,
|
|
IN ULONG BusNumber,
|
|
IN PHYSICAL_ADDRESS BusAddress,
|
|
IN OUT PULONG AddressSpace,
|
|
OUT PPHYSICAL_ADDRESS TranslatedAddress)
|
|
{
|
|
/* Look as the bus type */
|
|
if (InterfaceType == PCIBus)
|
|
{
|
|
/* Call the PCI registered function */
|
|
return HalPciTranslateBusAddress(PCIBus,
|
|
BusNumber,
|
|
BusAddress,
|
|
AddressSpace,
|
|
TranslatedAddress);
|
|
}
|
|
else
|
|
{
|
|
/* Translation is easy */
|
|
TranslatedAddress->QuadPart = BusAddress.QuadPart;
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
/* EOF */
|