Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers into modules, and delete rossubsys.

This commit is contained in:
Colin Finck 2017-10-03 07:45:34 +00:00
parent b94e2d8ca0
commit c2c66aff7d
24198 changed files with 0 additions and 37285 deletions

View file

@ -0,0 +1,449 @@
/*
* PROJECT: ReactOS HAL
* LICENSE: GPL - See COPYING in the top level directory
* FILE: hal/halx86/legacy/bus/bushndlr.c
* PURPOSE: Generic HAL Bus Handler Support
* PROGRAMMERS: Stefan Ginsberg (stefan.ginsberg@reactos.org)
*/
/* INCLUDES *******************************************************************/
#include <hal.h>
#define NDEBUG
#include <debug.h>
/* GLOBALS ********************************************************************/
KSPIN_LOCK HalpBusDatabaseSpinLock;
KEVENT HalpBusDatabaseEvent;
LIST_ENTRY HalpAllBusHandlers;
PARRAY HalpBusTable;
PARRAY HalpConfigTable;
/* PRIVATE FUNCTIONS **********************************************************/
PARRAY
NTAPI
HalpAllocateArray(IN ULONG ArraySize)
{
PARRAY Array;
ULONG Size;
/* Compute array size */
if (ArraySize == MAXULONG) ArraySize = 0;
Size = ArraySize * sizeof(PARRAY) + sizeof(ARRAY);
/* Allocate the array */
Array = ExAllocatePoolWithTag(NonPagedPool,
Size,
TAG_BUS_HANDLER);
if (!Array) KeBugCheckEx(HAL_MEMORY_ALLOCATION, Size, 0, (ULONG_PTR)__FILE__, __LINE__);
/* Initialize it */
Array->ArraySize = ArraySize;
RtlZeroMemory(Array->Element, sizeof(PVOID) * (ArraySize + 1));
return Array;
}
VOID
NTAPI
HalpGrowArray(IN PARRAY *CurrentArray,
IN PARRAY *NewArray)
{
PVOID Tmp;
/* Check if the current array doesn't exist yet, or if it's smaller than the new one */
if (!(*CurrentArray) || ((*NewArray)->ArraySize > (*CurrentArray)->ArraySize))
{
/* Does it exist (and can it fit?) */
if (*CurrentArray)
{
/* Copy the current array into the new one */
RtlCopyMemory(&(*NewArray)->Element,
&(*CurrentArray)->Element,
sizeof(PVOID) * ((*CurrentArray)->ArraySize + 1));
}
/* Swap the pointers (XOR swap would be more l33t) */
Tmp = *CurrentArray;
*CurrentArray = *NewArray;
*NewArray = Tmp;
}
}
PBUS_HANDLER
FASTCALL
HalpLookupHandler(IN PARRAY Array,
IN ULONG Type,
IN ULONG Number,
IN BOOLEAN AddReference)
{
PHAL_BUS_HANDLER Bus;
PBUS_HANDLER Handler = NULL;
/* Make sure the entry exists */
if (Array->ArraySize >= Type)
{
/* Retrieve it */
Array = Array->Element[Type];
/* Make sure the entry array exists */
if ((Array) && (Array->ArraySize >= Number))
{
/* Retrieve the bus and its handler */
Bus = Array->Element[Number];
Handler = &Bus->Handler;
/* Reference the handler if needed */
if (AddReference) Bus->ReferenceCount++;
}
}
/* Return the handler */
return Handler;
}
ULONG
NTAPI
HalpNoBusData(IN PBUS_HANDLER BusHandler,
IN PBUS_HANDLER RootHandler,
IN ULONG SlotNumber,
IN PVOID Buffer,
IN ULONG Offset,
IN ULONG Length)
{
/* Not implemented */
DPRINT1("STUB GetSetBusData\n");
return 0;
}
NTSTATUS
NTAPI
HalpNoAdjustResourceList(IN PBUS_HANDLER BusHandler,
IN PBUS_HANDLER RootHandler,
IN OUT PIO_RESOURCE_REQUIREMENTS_LIST *pResourceList)
{
DPRINT1("STUB Adjustment\n");
return STATUS_UNSUCCESSFUL;
}
NTSTATUS
NTAPI
HalpNoAssignSlotResources(IN PBUS_HANDLER BusHandler,
IN PBUS_HANDLER RootHandler,
IN PUNICODE_STRING RegistryPath,
IN PUNICODE_STRING DriverClassName OPTIONAL,
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT DeviceObject OPTIONAL,
IN ULONG SlotNumber,
IN OUT PCM_RESOURCE_LIST *AllocatedResources)
{
DPRINT1("STUB Assignment\n");
return STATUS_NOT_SUPPORTED;
}
VOID
FASTCALL
HaliReferenceBusHandler(IN PBUS_HANDLER Handler)
{
PHAL_BUS_HANDLER Bus;
/* Find and reference the bus handler */
Bus = CONTAINING_RECORD(Handler, HAL_BUS_HANDLER, Handler);
Bus->ReferenceCount++;
}
VOID
FASTCALL
HaliDereferenceBusHandler(IN PBUS_HANDLER Handler)
{
PHAL_BUS_HANDLER Bus;
/* Find and dereference the bus handler */
Bus = CONTAINING_RECORD(Handler, HAL_BUS_HANDLER, Handler);
Bus->ReferenceCount--;
ASSERT(Bus->ReferenceCount != 0);
}
PBUS_HANDLER
FASTCALL
HaliHandlerForBus(IN INTERFACE_TYPE InterfaceType,
IN ULONG BusNumber)
{
/* Lookup the interface in the bus table */
return HalpLookupHandler(HalpBusTable, InterfaceType, BusNumber, FALSE);
}
PBUS_HANDLER
FASTCALL
HaliHandlerForConfigSpace(IN BUS_DATA_TYPE ConfigType,
IN ULONG BusNumber)
{
/* Lookup the configuration in the configuration table */
return HalpLookupHandler(HalpConfigTable, ConfigType, BusNumber, FALSE);
}
PBUS_HANDLER
FASTCALL
HaliReferenceHandlerForBus(IN INTERFACE_TYPE InterfaceType,
IN ULONG BusNumber)
{
/* Lookup the interface in the bus table, and reference the handler */
return HalpLookupHandler(HalpBusTable, InterfaceType, BusNumber, TRUE);
}
PBUS_HANDLER
FASTCALL
HaliReferenceHandlerForConfigSpace(IN BUS_DATA_TYPE ConfigType,
IN ULONG BusNumber)
{
/* Lookup the configuration in the configuration table and add a reference */
return HalpLookupHandler(HalpConfigTable, ConfigType, BusNumber, TRUE);
}
PBUS_HANDLER
NTAPI
HalpContextToBusHandler(IN ULONG_PTR ContextValue)
{
PLIST_ENTRY NextEntry;
PHAL_BUS_HANDLER BusHandler, ThisHandler;
/* Start lookup */
NextEntry = HalpAllBusHandlers.Flink;
ThisHandler = CONTAINING_RECORD(NextEntry, HAL_BUS_HANDLER, AllHandlers);
if (ContextValue)
{
/* If the list is empty, quit */
if (IsListEmpty(&HalpAllBusHandlers)) return NULL;
/* Otherwise, scan the list */
BusHandler = CONTAINING_RECORD(ContextValue, HAL_BUS_HANDLER, Handler);
do
{
/* Check if we've reached the right one */
ThisHandler = CONTAINING_RECORD(NextEntry, HAL_BUS_HANDLER, AllHandlers);
if (ThisHandler == BusHandler) break;
/* Try the next one */
NextEntry = NextEntry->Flink;
} while (NextEntry != &HalpAllBusHandlers);
}
/* If we looped back to the end, we didn't find anything */
if (NextEntry == &HalpAllBusHandlers) return NULL;
/* Otherwise return the handler */
return &ThisHandler->Handler;
}
#ifndef _MINIHAL_
NTSTATUS
NTAPI
HaliRegisterBusHandler(IN INTERFACE_TYPE InterfaceType,
IN BUS_DATA_TYPE ConfigType,
IN ULONG BusNumber,
IN INTERFACE_TYPE ParentBusType,
IN ULONG ParentBusNumber,
IN ULONG ExtraData,
IN PINSTALL_BUS_HANDLER InstallCallback,
OUT PBUS_HANDLER *ReturnedBusHandler)
{
PHAL_BUS_HANDLER Bus, OldHandler = NULL;
PHAL_BUS_HANDLER* BusEntry;
//PVOID CodeHandle;
PARRAY InterfaceArray, InterfaceBusNumberArray, ConfigArray, ConfigBusNumberArray;
PBUS_HANDLER ParentHandler;
KIRQL OldIrql;
NTSTATUS Status;
/* Make sure we have a valid handler */
ASSERT((InterfaceType != InterfaceTypeUndefined) ||
(ConfigType != ConfigurationSpaceUndefined));
/* Allocate the bus handler */
Bus = ExAllocatePoolWithTag(NonPagedPool,
sizeof(HAL_BUS_HANDLER) + ExtraData,
TAG_BUS_HANDLER);
if (!Bus) return STATUS_INSUFFICIENT_RESOURCES;
/* Return the handler */
*ReturnedBusHandler = &Bus->Handler;
/* FIXME: Fix the kernel first. Don't page us out */
//CodeHandle = MmLockPagableDataSection(&HaliRegisterBusHandler);
/* Synchronize with anyone else */
KeWaitForSingleObject(&HalpBusDatabaseEvent,
WrExecutive,
KernelMode,
FALSE,
NULL);
/* Check for unknown/root bus */
if (BusNumber == -1)
{
/* We must have an interface */
ASSERT(InterfaceType != InterfaceTypeUndefined);
/* Find the right bus */
BusNumber = 0;
while (HaliHandlerForBus(InterfaceType, BusNumber)) BusNumber++;
}
/* Allocate arrays for the handler */
InterfaceArray = HalpAllocateArray(InterfaceType);
InterfaceBusNumberArray = HalpAllocateArray(BusNumber);
ConfigArray = HalpAllocateArray(ConfigType);
ConfigBusNumberArray = HalpAllocateArray(BusNumber);
/* Only proceed if all allocations succeeded */
if ((InterfaceArray) && (InterfaceBusNumberArray) && (ConfigArray) && (ConfigBusNumberArray))
{
/* Find the parent handler if any */
ParentHandler = HaliReferenceHandlerForBus(ParentBusType, ParentBusNumber);
/* Initialize the handler */
RtlZeroMemory(Bus, sizeof(HAL_BUS_HANDLER) + ExtraData);
Bus->ReferenceCount = 1;
/* Fill out bus data */
Bus->Handler.BusNumber = BusNumber;
Bus->Handler.InterfaceType = InterfaceType;
Bus->Handler.ConfigurationType = ConfigType;
Bus->Handler.ParentHandler = ParentHandler;
/* Fill out dummy handlers */
Bus->Handler.GetBusData = HalpNoBusData;
Bus->Handler.SetBusData = HalpNoBusData;
Bus->Handler.AdjustResourceList = HalpNoAdjustResourceList;
Bus->Handler.AssignSlotResources = HalpNoAssignSlotResources;
/* Make space for extra data */
if (ExtraData) Bus->Handler.BusData = Bus + 1;
/* Check for a parent handler */
if (ParentHandler)
{
/* Inherit the parent routines */
Bus->Handler.GetBusData = ParentHandler->GetBusData;
Bus->Handler.SetBusData = ParentHandler->SetBusData;
Bus->Handler.AdjustResourceList = ParentHandler->AdjustResourceList;
Bus->Handler.AssignSlotResources = ParentHandler->AssignSlotResources;
Bus->Handler.TranslateBusAddress = ParentHandler->TranslateBusAddress;
Bus->Handler.GetInterruptVector = ParentHandler->GetInterruptVector;
}
/* We don't support this yet */
ASSERT(!InstallCallback);
/* Lock the buses */
KeAcquireSpinLock(&HalpBusDatabaseSpinLock, &OldIrql);
/* Make space for the interface */
HalpGrowArray(&HalpBusTable, &InterfaceArray);
/* Check if we really have an interface */
if (InterfaceType != InterfaceTypeUndefined)
{
/* Make space for the association */
HalpGrowArray((PARRAY*)&HalpBusTable->Element[InterfaceType],
&InterfaceBusNumberArray);
/* Get the bus handler pointer */
BusEntry = (PHAL_BUS_HANDLER*)&((PARRAY)HalpBusTable->Element[InterfaceType])->Element[BusNumber];
/* Check if there was already a handler there, and set the new one */
if (*BusEntry) OldHandler = *BusEntry;
*BusEntry = Bus;
}
/* Now add a space for the configuration space */
HalpGrowArray(&HalpConfigTable, &ConfigArray);
/* Check if we really have one */
if (ConfigType != ConfigurationSpaceUndefined)
{
/* Make space for this association */
HalpGrowArray((PARRAY*)&HalpConfigTable->Element[ConfigType],
&ConfigBusNumberArray);
/* Get the bus handler pointer */
BusEntry = (PHAL_BUS_HANDLER*)&((PARRAY)HalpConfigTable->Element[ConfigType])->Element[BusNumber];
if (*BusEntry)
{
/* Get the old entry, but make sure it's the same we had before */
ASSERT((OldHandler == NULL) || (OldHandler == *BusEntry));
OldHandler = *BusEntry;
}
/* Set the new entry */
*BusEntry = Bus;
}
/* Link the adapter */
InsertTailList(&HalpAllBusHandlers, &Bus->AllHandlers);
/* Remove the old linkage */
Bus = OldHandler;
if (Bus) RemoveEntryList(&Bus->AllHandlers);
/* Release the lock */
KeReleaseSpinLock(&HalpBusDatabaseSpinLock, OldIrql);
Status = STATUS_SUCCESS;
}
else
{
/* Fail */
Status = STATUS_INSUFFICIENT_RESOURCES;
}
/* Signal the event */
KeSetEvent(&HalpBusDatabaseEvent, 0, FALSE);
/* FIXME: Fix the kernel first. Re-page the function */
//MmUnlockPagableImageSection(CodeHandle);
/* Free all allocations */
if (Bus) ExFreePoolWithTag(Bus, TAG_BUS_HANDLER);
if (InterfaceArray) ExFreePoolWithTag(InterfaceArray, TAG_BUS_HANDLER);
if (InterfaceBusNumberArray) ExFreePoolWithTag(InterfaceBusNumberArray, TAG_BUS_HANDLER);
if (ConfigArray) ExFreePoolWithTag(ConfigArray, TAG_BUS_HANDLER);
if (ConfigBusNumberArray) ExFreePoolWithTag(ConfigBusNumberArray, TAG_BUS_HANDLER);
/* And we're done */
return Status;
}
#endif
VOID
NTAPI
HalpInitBusHandler(VOID)
{
/* Setup the bus lock */
KeInitializeSpinLock(&HalpBusDatabaseSpinLock);
/* Setup the bus event */
KeInitializeEvent(&HalpBusDatabaseEvent, SynchronizationEvent, TRUE);
/* Setup the bus configuration and bus table */
HalpBusTable = HalpAllocateArray(0);
HalpConfigTable = HalpAllocateArray(0);
/* Setup the bus list */
InitializeListHead(&HalpAllBusHandlers);
/* Setup the HAL Dispatch routines */
#ifndef _MINIHAL_
HalRegisterBusHandler = HaliRegisterBusHandler;
HalHandlerForBus = HaliHandlerForBus;
HalHandlerForConfigSpace = HaliHandlerForConfigSpace;
HalReferenceHandlerForBus = HaliReferenceHandlerForBus;
HalReferenceBusHandler = HaliReferenceBusHandler;
HalDereferenceBusHandler = HaliDereferenceBusHandler;
#endif
HalPciAssignSlotResources = HalpAssignSlotResources;
HalPciTranslateBusAddress = HaliTranslateBusAddress; /* PCI Driver can override */
if (!HalFindBusAddressTranslation) HalFindBusAddressTranslation = HaliFindBusAddressTranslation;
}
/* EOF */

View file

@ -0,0 +1,45 @@
/*
* PROJECT: ReactOS HAL
* LICENSE: GPL - See COPYING in the top level directory
* FILE: hal/halx86/legacy/bus/cmosbus.c
* PURPOSE:
* PROGRAMMERS: Stefan Ginsberg (stefan.ginsberg@reactos.org)
*/
/* INCLUDES *******************************************************************/
#include <hal.h>
#define NDEBUG
#include <debug.h>
/* GLOBALS ********************************************************************/
/* PRIVATE FUNCTIONS **********************************************************/
ULONG
NTAPI
HalpcGetCmosData(IN PBUS_HANDLER BusHandler,
IN PBUS_HANDLER RootHandler,
IN ULONG SlotNumber,
IN PVOID Buffer,
IN ULONG Offset,
IN ULONG Length)
{
UNIMPLEMENTED_DBGBREAK("CMOS GetData\n");
return 0;
}
ULONG
NTAPI
HalpcSetCmosData(IN PBUS_HANDLER BusHandler,
IN PBUS_HANDLER RootHandler,
IN ULONG SlotNumber,
IN PVOID Buffer,
IN ULONG Offset,
IN ULONG Length)
{
UNIMPLEMENTED_DBGBREAK("CMOS SetData\n");
return 0;
}
/* EOF */

View file

@ -0,0 +1,51 @@
/*
* PROJECT: ReactOS HAL
* LICENSE: GPL - See COPYING in the top level directory
* FILE: hal/halx86/legacy/bus/isabus.c
* PURPOSE:
* PROGRAMMERS: Stefan Ginsberg (stefan.ginsberg@reactos.org)
*/
/* INCLUDES *******************************************************************/
#include <hal.h>
#define NDEBUG
#include <debug.h>
/* GLOBALS ********************************************************************/
/* PRIVATE FUNCTIONS **********************************************************/
BOOLEAN
NTAPI
HalpTranslateIsaBusAddress(IN PBUS_HANDLER BusHandler,
IN PBUS_HANDLER RootHandler,
IN PHYSICAL_ADDRESS BusAddress,
IN OUT PULONG AddressSpace,
OUT PPHYSICAL_ADDRESS TranslatedAddress)
{
BOOLEAN Status;
/* Use system translation */
Status = HalpTranslateSystemBusAddress(BusHandler,
RootHandler,
BusAddress,
AddressSpace,
TranslatedAddress);
/* If it didn't work and it was memory address space... */
if (!(Status) && (*AddressSpace == 0))
{
/* Try EISA translation instead */
Status = HalTranslateBusAddress(Eisa,
BusHandler->BusNumber,
BusAddress,
AddressSpace,
TranslatedAddress);
}
/* Return the result */
return Status;
}
/* EOF */

View file

@ -0,0 +1,214 @@
#
# Extracted from the pci.ids database at http://pci-ids.ucw.cz/
#
#
# List of PCI ID's
#
# Version: 2017.05.25
# Date: 2017-05-25 03:15:02
#
# Maintained by Albert Pool, Martin Mares, and other volunteers from
# the PCI ID Project at http://pci-ids.ucw.cz/.
#
# New data are always welcome, especially if they are accurate. If you have
# anything to contribute, please follow the instructions at the web site.
#
# This file can be distributed under either the GNU General Public License
# (version 2 or higher) or the 3-clause BSD License.
#
# List of known device classes, subclasses and programming interfaces
# Syntax:
# C class class_name
# subclass subclass_name <-- single tab
# prog-if prog-if_name <-- two tabs
C 00 Unclassified device
00 Non-VGA unclassified device
01 VGA compatible unclassified device
C 01 Mass storage controller
00 SCSI storage controller
01 IDE interface
02 Floppy disk controller
03 IPI bus controller
04 RAID bus controller
05 ATA controller
20 ADMA single stepping
30 ADMA continuous operation
06 SATA controller
00 Vendor specific
01 AHCI 1.0
02 Serial Storage Bus
07 Serial Attached SCSI controller
01 Serial Storage Bus
08 Non-Volatile memory controller
01 NVMHCI
02 NVM Express
80 Mass storage controller
C 02 Network controller
00 Ethernet controller
01 Token ring network controller
02 FDDI network controller
03 ATM network controller
04 ISDN controller
05 WorldFip controller
06 PICMG controller
07 Infiniband controller
08 Fabric controller
80 Network controller
C 03 Display controller
00 VGA compatible controller
00 VGA controller
01 8514 controller
01 XGA compatible controller
02 3D controller
80 Display controller
C 04 Multimedia controller
00 Multimedia video controller
01 Multimedia audio controller
02 Computer telephony device
03 Audio device
80 Multimedia controller
C 05 Memory controller
00 RAM memory
01 FLASH memory
80 Memory controller
C 06 Bridge
00 Host bridge
01 ISA bridge
02 EISA bridge
03 MicroChannel bridge
04 PCI bridge
00 Normal decode
01 Subtractive decode
05 PCMCIA bridge
06 NuBus bridge
07 CardBus bridge
08 RACEway bridge
00 Transparent mode
01 Endpoint mode
09 Semi-transparent PCI-to-PCI bridge
40 Primary bus towards host CPU
80 Secondary bus towards host CPU
0a InfiniBand to PCI host bridge
80 Bridge
C 07 Communication controller
00 Serial controller
00 8250
01 16450
02 16550
03 16650
04 16750
05 16850
06 16950
01 Parallel controller
00 SPP
01 BiDir
02 ECP
03 IEEE1284
fe IEEE1284 Target
02 Multiport serial controller
03 Modem
00 Generic
01 Hayes/16450
02 Hayes/16550
03 Hayes/16650
04 Hayes/16750
04 GPIB controller
05 Smard Card controller
80 Communication controller
C 08 Generic system peripheral
00 PIC
00 8259
01 ISA PIC
02 EISA PIC
10 IO-APIC
20 IO(X)-APIC
01 DMA controller
00 8237
01 ISA DMA
02 EISA DMA
02 Timer
00 8254
01 ISA Timer
02 EISA Timers
03 HPET
03 RTC
00 Generic
01 ISA RTC
04 PCI Hot-plug controller
05 SD Host controller
06 IOMMU
80 System peripheral
C 09 Input device controller
00 Keyboard controller
01 Digitizer Pen
02 Mouse controller
03 Scanner controller
04 Gameport controller
00 Generic
10 Extended
80 Input device controller
C 0a Docking station
00 Generic Docking Station
80 Docking Station
C 0b Processor
00 386
01 486
02 Pentium
10 Alpha
20 Power PC
30 MIPS
40 Co-processor
C 0c Serial bus controller
00 FireWire (IEEE 1394)
00 Generic
10 OHCI
01 ACCESS Bus
02 SSA
03 USB controller
00 UHCI
10 OHCI
20 EHCI
30 XHCI
80 Unspecified
fe USB Device
04 Fibre Channel
05 SMBus
06 InfiniBand
07 IPMI SMIC interface
08 SERCOS interface
09 CANBUS
C 0d Wireless controller
00 IRDA controller
01 Consumer IR controller
10 RF controller
11 Bluetooth
12 Broadband
20 802.1a controller
21 802.1b controller
80 Wireless controller
C 0e Intelligent controller
00 I2O
C 0f Satellite communications controller
01 Satellite TV controller
02 Satellite audio communication controller
03 Satellite voice communication controller
04 Satellite data communication controller
C 10 Encryption controller
00 Network and computing encryption device
10 Entertainment encryption device
80 Encryption controller
C 11 Signal processing controller
00 DPIO module
01 Performance counters
10 Communication synchronizer
20 Signal processing management
80 Signal processing controller
C 12 Processing accelerators
00 Processing accelerators
C 13 Non-Essential Instrumentation
C 40 Coprocessor
C ff Unassigned class

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,164 @@
/*
* PROJECT: ReactOS HAL
* LICENSE: GPL - See COPYING in the top level directory
* FILE: hal/halx86/legacy/bus/sysbus.c
* PURPOSE:
* PROGRAMMERS: Stefan Ginsberg (stefan.ginsberg@reactos.org)
*/
/* INCLUDES *******************************************************************/
#include <hal.h>
#define NDEBUG
#include <debug.h>
/* GLOBALS ********************************************************************/
/* PRIVATE FUNCTIONS **********************************************************/
BOOLEAN
NTAPI
HalpTranslateSystemBusAddress(IN PBUS_HANDLER BusHandler,
IN PBUS_HANDLER RootHandler,
IN PHYSICAL_ADDRESS BusAddress,
IN OUT PULONG AddressSpace,
OUT PPHYSICAL_ADDRESS TranslatedAddress)
{
PSUPPORTED_RANGE Range = NULL;
/* Check what kind of address space this is */
switch (*AddressSpace)
{
/* Memory address */
case 0:
/* Loop all prefetch memory */
for (Range = &BusHandler->BusAddresses->PrefetchMemory;
Range;
Range = Range->Next)
{
/* Check if it's in a valid range */
if ((BusAddress.QuadPart >= Range->Base) &&
(BusAddress.QuadPart <= Range->Limit))
{
/* Get out */
break;
}
}
/* Check if we haven't found anything yet */
if (!Range)
{
/* Loop all bus memory */
for (Range = &BusHandler->BusAddresses->Memory;
Range;
Range = Range->Next)
{
/* Check if it's in a valid range */
if ((BusAddress.QuadPart >= Range->Base) &&
(BusAddress.QuadPart <= Range->Limit))
{
/* Get out */
break;
}
}
}
/* Done */
break;
/* I/O Space */
case 1:
/* Loop all bus I/O memory */
for (Range = &BusHandler->BusAddresses->IO;
Range;
Range = Range->Next)
{
/* Check if it's in a valid range */
if ((BusAddress.QuadPart >= Range->Base) &&
(BusAddress.QuadPart <= Range->Limit))
{
/* Get out */
break;
}
}
/* Done */
break;
}
/* Check if we found a range */
if (Range)
{
/* Do the translation and return the kind of address space this is */
TranslatedAddress->QuadPart = BusAddress.QuadPart + Range->SystemBase;
if ((TranslatedAddress->QuadPart != BusAddress.QuadPart) ||
(*AddressSpace != Range->SystemAddressSpace))
{
/* Different than what the old HAL would do */
DPRINT1("Translation of %I64x is %I64x %s\n",
BusAddress.QuadPart, TranslatedAddress->QuadPart,
Range->SystemAddressSpace ? "In I/O Space" : "In RAM");
}
*AddressSpace = Range->SystemAddressSpace;
return TRUE;
}
/* Nothing found */
DPRINT1("Translation of %I64x failed!\n", BusAddress.QuadPart);
return FALSE;
}
ULONG
NTAPI
HalpGetRootInterruptVector(IN ULONG BusInterruptLevel,
IN ULONG BusInterruptVector,
OUT PKIRQL Irql,
OUT PKAFFINITY Affinity)
{
UCHAR SystemVector;
/* Validate the IRQ */
if (BusInterruptLevel > 23)
{
/* Invalid vector */
DPRINT1("IRQ %lx is too high!\n", BusInterruptLevel);
return 0;
}
/* Get the system vector */
SystemVector = HalpIrqToVector((UCHAR)BusInterruptLevel);
/* Return the IRQL and affinity */
*Irql = HalpVectorToIrql(SystemVector);
*Affinity = HalpDefaultInterruptAffinity;
ASSERT(HalpDefaultInterruptAffinity);
/* Return the vector */
return SystemVector;
}
ULONG
NTAPI
HalpGetSystemInterruptVector(IN PBUS_HANDLER BusHandler,
IN PBUS_HANDLER RootHandler,
IN ULONG BusInterruptLevel,
IN ULONG BusInterruptVector,
OUT PKIRQL Irql,
OUT PKAFFINITY Affinity)
{
ULONG Vector;
/* Get the root vector */
Vector = HalpGetRootInterruptVector(BusInterruptLevel,
BusInterruptVector,
Irql,
Affinity);
/* Check if the vector is owned by the HAL and fail if it is */
if (HalpIDTUsageFlags[Vector].Flags & IDT_REGISTERED) DPRINT1("Vector %lx is ALREADY IN USE!\n", Vector);
return (HalpIDTUsageFlags[Vector].Flags & IDT_REGISTERED) ? 0 : Vector;
}
/* EOF */

1632
hal/halx86/legacy/bussupp.c Normal file

File diff suppressed because it is too large Load diff

135
hal/halx86/legacy/halpcat.c Normal file
View file

@ -0,0 +1,135 @@
/*
* PROJECT: ReactOS HAL
* LICENSE: BSD - See COPYING.ARM in the top level directory
* FILE: hal/halx86/legacy/halpcat.c
* PURPOSE: HAL Legacy Support Code
* PROGRAMMERS: ReactOS Portable Systems Group
*/
/* INCLUDES *******************************************************************/
#include <hal.h>
#define NDEBUG
#include <debug.h>
#if defined(ALLOC_PRAGMA) && !defined(_MINIHAL_)
//#pragma alloc_text(INIT, HaliInitPnpDriver)
#pragma alloc_text(INIT, HalpBuildAddressMap)
#pragma alloc_text(INIT, HalpGetDebugPortTable)
#pragma alloc_text(INIT, HalpIs16BitPortDecodeSupported)
#pragma alloc_text(INIT, HalpSetupAcpiPhase0)
#pragma alloc_text(INIT, HalReportResourceUsage)
#endif
/* GLOBALS ********************************************************************/
/* This determines the HAL type */
BOOLEAN HalDisableFirmwareMapper = FALSE;
PWCHAR HalHardwareIdString = L"e_isa_up";
PWCHAR HalName = L"PC Compatible Eisa/Isa HAL";
/* PRIVATE FUNCTIONS **********************************************************/
INIT_SECTION
NTSTATUS
NTAPI
HalpSetupAcpiPhase0(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
/* There is no ACPI on these HALs */
return STATUS_NO_SUCH_DEVICE;
}
INIT_SECTION
VOID
NTAPI
HalpBuildAddressMap(VOID)
{
/* FIXME: Inherit ROM blocks from the registry */
//HalpInheritROMBlocks();
/* FIXME: Add the ROM blocks to our ranges */
//HalpAddROMRanges();
}
INIT_SECTION
BOOLEAN
NTAPI
HalpGetDebugPortTable(VOID)
{
/* No ACPI */
return FALSE;
}
INIT_SECTION
ULONG
NTAPI
HalpIs16BitPortDecodeSupported(VOID)
{
/* Only EISA systems support this */
return (HalpBusType == MACHINE_TYPE_EISA) ? CM_RESOURCE_PORT_16_BIT_DECODE : 0;
}
#if 0
INIT_SECTION
NTSTATUS
NTAPI
HaliInitPnpDriver(VOID)
{
/* On PC-AT, this will interface with the PCI driver */
//HalpDebugPciBus();
return STATUS_SUCCESS;
}
#endif
/*
* @implemented
*/
INIT_SECTION
VOID
NTAPI
HalReportResourceUsage(VOID)
{
INTERFACE_TYPE InterfaceType;
UNICODE_STRING HalString;
/* FIXME: Initialize MCA bus */
/* Initialize PCI bus. */
HalpInitializePciBus();
/* Initialize the stubs */
HalpInitializePciStubs();
/* What kind of bus is this? */
switch (HalpBusType)
{
/* ISA Machine */
case MACHINE_TYPE_ISA:
InterfaceType = Isa;
break;
/* EISA Machine */
case MACHINE_TYPE_EISA:
InterfaceType = Eisa;
break;
/* MCA Machine */
case MACHINE_TYPE_MCA:
InterfaceType = MicroChannel;
break;
/* Unknown */
default:
InterfaceType = Internal;
break;
}
/* Build HAL usage */
RtlInitUnicodeString(&HalString, HalName);
HalpReportResourceUsage(&HalString, InterfaceType);
/* Setup PCI debugging and Hibernation */
HalpRegisterPciDebuggingDeviceInfo();
}
/* EOF */

View file

@ -0,0 +1,942 @@
/*
* PROJECT: ReactOS HAL
* LICENSE: BSD - See COPYING.ARM in the top level directory
* FILE: hal/halx86/legacy/halpnpdd.c
* PURPOSE: HAL Plug and Play Device Driver
* PROGRAMMERS: ReactOS Portable Systems Group
*/
/* INCLUDES *******************************************************************/
#include <hal.h>
#define NDEBUG
#include <debug.h>
typedef enum _EXTENSION_TYPE
{
PdoExtensionType = 0xC0,
FdoExtensionType
} EXTENSION_TYPE;
typedef enum _PDO_TYPE
{
AcpiPdo = 0x80,
WdPdo
} PDO_TYPE;
typedef struct _FDO_EXTENSION
{
EXTENSION_TYPE ExtensionType;
struct _PDO_EXTENSION* ChildPdoList;
PDEVICE_OBJECT PhysicalDeviceObject;
PDEVICE_OBJECT FunctionalDeviceObject;
PDEVICE_OBJECT AttachedDeviceObject;
} FDO_EXTENSION, *PFDO_EXTENSION;
typedef struct _PDO_EXTENSION
{
EXTENSION_TYPE ExtensionType;
struct _PDO_EXTENSION* Next;
PDEVICE_OBJECT PhysicalDeviceObject;
PFDO_EXTENSION ParentFdoExtension;
PDO_TYPE PdoType;
PDESCRIPTION_HEADER WdTable;
LONG InterfaceReferenceCount;
} PDO_EXTENSION, *PPDO_EXTENSION;
/* GLOBALS ********************************************************************/
PDRIVER_OBJECT HalpDriverObject;
/* PRIVATE FUNCTIONS **********************************************************/
VOID
NTAPI
HalpReportDetectedDevices(IN PDRIVER_OBJECT DriverObject,
IN PVOID Context,
IN ULONG Count)
{
PFDO_EXTENSION FdoExtension = Context;
PPDO_EXTENSION PdoExtension;
PDEVICE_OBJECT PdoDeviceObject;
NTSTATUS Status;
/* Create the PDO */
Status = IoCreateDevice(DriverObject,
sizeof(PDO_EXTENSION),
NULL,
FILE_DEVICE_BUS_EXTENDER,
FILE_AUTOGENERATED_DEVICE_NAME,
FALSE,
&PdoDeviceObject);
if (!NT_SUCCESS(Status))
{
/* Fail */
DPRINT1("HAL: Could not create ACPI device object status=0x%08x\n", Status);
return;
}
/* Setup the PDO device extension */
PdoExtension = PdoDeviceObject->DeviceExtension;
PdoExtension->ExtensionType = PdoExtensionType;
PdoExtension->PhysicalDeviceObject = PdoDeviceObject;
PdoExtension->ParentFdoExtension = FdoExtension;
PdoExtension->PdoType = AcpiPdo;
/* Add the PDO to the head of the list */
PdoExtension->Next = FdoExtension->ChildPdoList;
FdoExtension->ChildPdoList = PdoExtension;
/* Initialization is finished */
PdoDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
/* Invalidate device relations since we added a new device */
IoSynchronousInvalidateDeviceRelations(FdoExtension->PhysicalDeviceObject, BusRelations);
}
NTSTATUS
NTAPI
HalpAddDevice(IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT TargetDevice)
{
NTSTATUS Status;
PFDO_EXTENSION FdoExtension;
PDEVICE_OBJECT DeviceObject, AttachedDevice;
// PDESCRIPTION_HEADER Wdrt;
DPRINT("HAL: PnP Driver ADD!\n");
/* Create the FDO */
Status = IoCreateDevice(DriverObject,
sizeof(FDO_EXTENSION),
NULL,
FILE_DEVICE_BUS_EXTENDER,
0,
FALSE,
&DeviceObject);
if (!NT_SUCCESS(Status))
{
/* Should not happen */
DbgBreakPoint();
return Status;
}
/* Setup the FDO extension */
FdoExtension = DeviceObject->DeviceExtension;
FdoExtension->ExtensionType = FdoExtensionType;
FdoExtension->PhysicalDeviceObject = TargetDevice;
FdoExtension->FunctionalDeviceObject = DeviceObject;
FdoExtension->ChildPdoList = NULL;
/* FDO is done initializing */
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
/* Attach to the physical device object (the bus) */
AttachedDevice = IoAttachDeviceToDeviceStack(DeviceObject, TargetDevice);
if (!AttachedDevice)
{
/* Failed, undo everything */
IoDeleteDevice(DeviceObject);
return STATUS_NO_SUCH_DEVICE;
}
/* Save the attachment */
FdoExtension->AttachedDeviceObject = AttachedDevice;
/* Register for reinitialization to report devices later */
IoRegisterBootDriverReinitialization(DriverObject,
HalpReportDetectedDevices,
FdoExtension);
/* Return status */
DPRINT("Device added %lx\n", Status);
return Status;
}
NTSTATUS
NTAPI
HalpQueryInterface(IN PDEVICE_OBJECT DeviceObject,
IN CONST GUID* InterfaceType,
IN USHORT Version,
IN PVOID InterfaceSpecificData,
IN ULONG InterfaceBufferSize,
IN PINTERFACE Interface,
OUT PULONG Length)
{
UNIMPLEMENTED;
return STATUS_NOT_SUPPORTED;
}
NTSTATUS
NTAPI
HalpQueryDeviceRelations(IN PDEVICE_OBJECT DeviceObject,
IN DEVICE_RELATION_TYPE RelationType,
OUT PDEVICE_RELATIONS* DeviceRelations)
{
EXTENSION_TYPE ExtensionType;
PPDO_EXTENSION PdoExtension;
PFDO_EXTENSION FdoExtension;
PDEVICE_RELATIONS PdoRelations, FdoRelations;
PDEVICE_OBJECT* ObjectEntry;
ULONG i = 0, PdoCount = 0;
/* Get FDO device extension and PDO count */
FdoExtension = DeviceObject->DeviceExtension;
ExtensionType = FdoExtension->ExtensionType;
/* What do they want? */
if (RelationType == BusRelations)
{
/* This better be an FDO */
if (ExtensionType == FdoExtensionType)
{
/* Count how many PDOs we have */
PdoExtension = FdoExtension->ChildPdoList;
while (PdoExtension)
{
/* Next one */
PdoExtension = PdoExtension->Next;
PdoCount++;
}
/* Add the PDOs that already exist in the device relations */
if (*DeviceRelations)
{
PdoCount += (*DeviceRelations)->Count;
}
/* Allocate our structure */
FdoRelations = ExAllocatePoolWithTag(PagedPool,
FIELD_OFFSET(DEVICE_RELATIONS,
Objects) +
sizeof(PDEVICE_OBJECT) * PdoCount,
TAG_HAL);
if (!FdoRelations) return STATUS_INSUFFICIENT_RESOURCES;
/* Save our count */
FdoRelations->Count = PdoCount;
/* Query existing relations */
ObjectEntry = FdoRelations->Objects;
if (*DeviceRelations)
{
/* Check if there were any */
if ((*DeviceRelations)->Count)
{
/* Loop them all */
do
{
/* Copy into our structure */
*ObjectEntry++ = (*DeviceRelations)->Objects[i];
}
while (++i < (*DeviceRelations)->Count);
}
/* Free existing structure */
ExFreePool(*DeviceRelations);
}
/* Now check if we have a PDO list */
PdoExtension = FdoExtension->ChildPdoList;
if (PdoExtension)
{
/* Loop the PDOs */
do
{
/* Save our own PDO and reference it */
*ObjectEntry++ = PdoExtension->PhysicalDeviceObject;
ObReferenceObject(PdoExtension->PhysicalDeviceObject);
/* Go to our next PDO */
PdoExtension = PdoExtension->Next;
}
while (PdoExtension);
}
/* Return the new structure */
*DeviceRelations = FdoRelations;
return STATUS_SUCCESS;
}
}
else
{
/* The only other thing we support is a target relation for the PDO */
if ((RelationType == TargetDeviceRelation) &&
(ExtensionType == PdoExtensionType))
{
/* Only one entry */
PdoRelations = ExAllocatePoolWithTag(PagedPool,
sizeof(DEVICE_RELATIONS),
TAG_HAL);
if (!PdoRelations) return STATUS_INSUFFICIENT_RESOURCES;
/* Fill it out and reference us */
PdoRelations->Count = 1;
PdoRelations->Objects[0] = DeviceObject;
ObReferenceObject(DeviceObject);
/* Return it */
*DeviceRelations = PdoRelations;
return STATUS_SUCCESS;
}
}
/* We don't support anything else */
return STATUS_NOT_SUPPORTED;
}
NTSTATUS
NTAPI
HalpQueryCapabilities(IN PDEVICE_OBJECT DeviceObject,
OUT PDEVICE_CAPABILITIES Capabilities)
{
//PPDO_EXTENSION PdoExtension;
NTSTATUS Status;
PAGED_CODE();
/* Get the extension and check for valid version */
//PdoExtension = DeviceObject->DeviceExtension;
ASSERT(Capabilities->Version == 1);
if (Capabilities->Version == 1)
{
/* Can't lock or eject us */
Capabilities->LockSupported = FALSE;
Capabilities->EjectSupported = FALSE;
/* Can't remove or dock us */
Capabilities->Removable = FALSE;
Capabilities->DockDevice = FALSE;
/* Can't access us raw */
Capabilities->RawDeviceOK = FALSE;
/* We have a unique ID, and don't bother the user */
Capabilities->UniqueID = TRUE;
Capabilities->SilentInstall = TRUE;
/* Fill out the adress */
Capabilities->Address = InterfaceTypeUndefined;
Capabilities->UINumber = InterfaceTypeUndefined;
/* Fill out latencies */
Capabilities->D1Latency = 0;
Capabilities->D2Latency = 0;
Capabilities->D3Latency = 0;
/* Fill out supported device states */
Capabilities->DeviceState[PowerSystemWorking] = PowerDeviceD0;
Capabilities->DeviceState[PowerSystemHibernate] = PowerDeviceD3;
Capabilities->DeviceState[PowerSystemShutdown] = PowerDeviceD3;
Capabilities->DeviceState[PowerSystemSleeping3] = PowerDeviceD3;
/* Done */
Status = STATUS_SUCCESS;
}
else
{
/* Fail */
Status = STATUS_NOT_SUPPORTED;
}
/* Return status */
return Status;
}
NTSTATUS
NTAPI
HalpQueryResources(IN PDEVICE_OBJECT DeviceObject,
OUT PCM_RESOURCE_LIST *Resources)
{
PPDO_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
NTSTATUS Status;
PCM_RESOURCE_LIST ResourceList;
// PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
// PIO_RESOURCE_DESCRIPTOR Descriptor;
// PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDesc;
// ULONG i;
PAGED_CODE();
/* Only the ACPI PDO has requirements */
if (DeviceExtension->PdoType == AcpiPdo)
{
#if 0
/* Query ACPI requirements */
Status = HalpQueryAcpiResourceRequirements(&RequirementsList);
if (!NT_SUCCESS(Status)) return Status;
ASSERT(RequirementsList->AlternativeLists == 1);
#endif
/* Allocate the resourcel ist */
ResourceList = ExAllocatePoolWithTag(PagedPool,
sizeof(CM_RESOURCE_LIST),
TAG_HAL);
if (!ResourceList )
{
/* Fail, no memory */
Status = STATUS_INSUFFICIENT_RESOURCES;
// ExFreePoolWithTag(RequirementsList, TAG_HAL);
return Status;
}
/* Initialize it */
RtlZeroMemory(ResourceList, sizeof(CM_RESOURCE_LIST));
ResourceList->Count = 1;
/* Setup the list fields */
ResourceList->List[0].BusNumber = 0;
ResourceList->List[0].InterfaceType = PCIBus;
ResourceList->List[0].PartialResourceList.Version = 1;
ResourceList->List[0].PartialResourceList.Revision = 1;
ResourceList->List[0].PartialResourceList.Count = 0;
/* Setup the first descriptor */
//PartialDesc = ResourceList->List[0].PartialResourceList.PartialDescriptors;
/* Find the requirement descriptor for the SCI */
#if 0
for (i = 0; i < RequirementsList->List[0].Count; i++)
{
/* Get this descriptor */
Descriptor = &RequirementsList->List[0].Descriptors[i];
if (Descriptor->Type == CmResourceTypeInterrupt)
{
/* Copy requirements descriptor into resource descriptor */
PartialDesc->Type = CmResourceTypeInterrupt;
PartialDesc->ShareDisposition = Descriptor->ShareDisposition;
PartialDesc->Flags = Descriptor->Flags;
ASSERT(Descriptor->u.Interrupt.MinimumVector ==
Descriptor->u.Interrupt.MaximumVector);
PartialDesc->u.Interrupt.Vector = Descriptor->u.Interrupt.MinimumVector;
PartialDesc->u.Interrupt.Level = Descriptor->u.Interrupt.MinimumVector;
PartialDesc->u.Interrupt.Affinity = 0xFFFFFFFF;
ResourceList->List[0].PartialResourceList.Count++;
break;
}
}
#endif
/* Return resources and success */
*Resources = ResourceList;
// ExFreePoolWithTag(RequirementsList, TAG_HAL);
return STATUS_SUCCESS;
}
else if (DeviceExtension->PdoType == WdPdo)
{
/* Watchdog doesn't */
return STATUS_NOT_SUPPORTED;
}
else
{
/* This shouldn't happen */
return STATUS_UNSUCCESSFUL;
}
}
NTSTATUS
NTAPI
HalpQueryResourceRequirements(IN PDEVICE_OBJECT DeviceObject,
OUT PIO_RESOURCE_REQUIREMENTS_LIST *Requirements)
{
PPDO_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
PAGED_CODE();
/* Only the ACPI PDO has requirements */
if (DeviceExtension->PdoType == AcpiPdo)
{
/* Query ACPI requirements */
// return HalpQueryAcpiResourceRequirements(Requirements);
return STATUS_SUCCESS;
}
else if (DeviceExtension->PdoType == WdPdo)
{
/* Watchdog doesn't */
return STATUS_NOT_SUPPORTED;
}
else
{
/* This shouldn't happen */
return STATUS_UNSUCCESSFUL;
}
}
NTSTATUS
NTAPI
HalpQueryIdPdo(IN PDEVICE_OBJECT DeviceObject,
IN BUS_QUERY_ID_TYPE IdType,
OUT PUSHORT *BusQueryId)
{
PPDO_EXTENSION PdoExtension;
PDO_TYPE PdoType;
PWCHAR CurrentId;
WCHAR Id[100];
NTSTATUS Status;
ULONG Length = 0;
PWCHAR Buffer;
/* Get the PDO type */
PdoExtension = DeviceObject->DeviceExtension;
PdoType = PdoExtension->PdoType;
/* What kind of ID is being requested? */
DPRINT("ID: %d\n", IdType);
switch (IdType)
{
case BusQueryDeviceID:
case BusQueryHardwareIDs:
/* What kind of PDO is this? */
if (PdoType == AcpiPdo)
{
/* ACPI ID */
CurrentId = L"PCI_HAL\\PNP0A03";
RtlCopyMemory(Id, CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
CurrentId = L"*PNP0A03";
RtlCopyMemory(&Id[wcslen(Id) + 1], CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
}
#if 0
else if (PdoType == WdPdo)
{
/* WatchDog ID */
CurrentId = L"ACPI_HAL\\PNP0C18";
RtlCopyMemory(Id, CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
CurrentId = L"*PNP0C18";
RtlCopyMemory(&Id[wcslen(Id) + 1], CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
}
#endif
else
{
/* Unknown */
return STATUS_NOT_SUPPORTED;
}
break;
case BusQueryInstanceID:
/* Instance ID */
CurrentId = L"0";
RtlCopyMemory(Id, CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
break;
case BusQueryCompatibleIDs:
default:
/* We don't support anything else */
return STATUS_NOT_SUPPORTED;
}
/* Allocate the buffer */
Buffer = ExAllocatePoolWithTag(PagedPool,
Length + sizeof(UNICODE_NULL),
TAG_HAL);
if (Buffer)
{
/* Copy the string and null-terminate it */
RtlCopyMemory(Buffer, Id, Length);
Buffer[Length / sizeof(WCHAR)] = UNICODE_NULL;
/* Return string */
*BusQueryId = Buffer;
Status = STATUS_SUCCESS;
DPRINT("Returning: %S\n", *BusQueryId);
}
else
{
/* Fail */
Status = STATUS_INSUFFICIENT_RESOURCES;
}
/* Return status */
return Status;
}
NTSTATUS
NTAPI
HalpQueryIdFdo(IN PDEVICE_OBJECT DeviceObject,
IN BUS_QUERY_ID_TYPE IdType,
OUT PUSHORT *BusQueryId)
{
NTSTATUS Status;
ULONG Length;
PWCHAR Id;
PWCHAR Buffer;
/* What kind of ID is being requested? */
DPRINT("ID: %d\n", IdType);
switch (IdType)
{
case BusQueryDeviceID:
/* HACK */
Id = L"Root\\PCI_HAL";
break;
case BusQueryHardwareIDs:
/* This is our hardware ID */
Id = HalHardwareIdString;
break;
case BusQueryInstanceID:
/* And our instance ID */
Id = L"0";
break;
default:
/* We don't support anything else */
return STATUS_NOT_SUPPORTED;
}
/* Calculate the length */
Length = (wcslen(Id) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
/* Allocate the buffer */
Buffer = ExAllocatePoolWithTag(PagedPool,
Length + sizeof(UNICODE_NULL),
TAG_HAL);
if (Buffer)
{
/* Copy the string and null-terminate it */
RtlCopyMemory(Buffer, Id, Length);
Buffer[Length / sizeof(WCHAR)] = UNICODE_NULL;
/* Return string */
*BusQueryId = Buffer;
Status = STATUS_SUCCESS;
DPRINT("Returning: %S\n", *BusQueryId);
}
else
{
/* Fail */
Status = STATUS_INSUFFICIENT_RESOURCES;
}
/* Return status */
return Status;
}
NTSTATUS
NTAPI
HalpDispatchPnp(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
PIO_STACK_LOCATION IoStackLocation;
//PPDO_EXTENSION PdoExtension;
PFDO_EXTENSION FdoExtension;
NTSTATUS Status;
UCHAR Minor;
/* Get the device extension and stack location */
FdoExtension = DeviceObject->DeviceExtension;
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
Minor = IoStackLocation->MinorFunction;
/* FDO? */
if (FdoExtension->ExtensionType == FdoExtensionType)
{
/* Query the IRP type */
switch (Minor)
{
case IRP_MN_QUERY_DEVICE_RELATIONS:
/* Call the worker */
DPRINT("Querying device relations for FDO\n");
Status = HalpQueryDeviceRelations(DeviceObject,
IoStackLocation->Parameters.QueryDeviceRelations.Type,
(PVOID)&Irp->IoStatus.Information);
break;
case IRP_MN_QUERY_INTERFACE:
/* Call the worker */
DPRINT("Querying interface for FDO\n");
Status = HalpQueryInterface(DeviceObject,
IoStackLocation->Parameters.QueryInterface.InterfaceType,
IoStackLocation->Parameters.QueryInterface.Size,
IoStackLocation->Parameters.QueryInterface.InterfaceSpecificData,
IoStackLocation->Parameters.QueryInterface.Version,
IoStackLocation->Parameters.QueryInterface.Interface,
(PVOID)&Irp->IoStatus.Information);
break;
case IRP_MN_QUERY_ID:
/* Call the worker */
DPRINT("Querying ID for FDO\n");
Status = HalpQueryIdFdo(DeviceObject,
IoStackLocation->Parameters.QueryId.IdType,
(PVOID)&Irp->IoStatus.Information);
break;
case IRP_MN_QUERY_CAPABILITIES:
/* Call the worker */
DPRINT("Querying the capabilities for the FDO\n");
Status = HalpQueryCapabilities(DeviceObject,
IoStackLocation->Parameters.DeviceCapabilities.Capabilities);
break;
default:
DPRINT("Other IRP: %lx\n", Minor);
Status = Irp->IoStatus.Status;
break;
}
/* Nowhere for the IRP to go since we also own the PDO */
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
}
else
{
/* This is a PDO instead */
ASSERT(FdoExtension->ExtensionType == PdoExtensionType);
//PdoExtension = (PPDO_EXTENSION)FdoExtension;
/* Query the IRP type */
Status = STATUS_SUCCESS;
switch (Minor)
{
case IRP_MN_START_DEVICE:
/* We only care about a PCI PDO */
DPRINT("Start device received\n");
/* Complete the IRP normally */
break;
case IRP_MN_REMOVE_DEVICE:
/* Check if this is a PCI device */
DPRINT("Remove device received\n");
/* We're done */
Status = STATUS_SUCCESS;
break;
case IRP_MN_SURPRISE_REMOVAL:
/* Inherit whatever status we had */
DPRINT("Surprise removal IRP\n");
Status = Irp->IoStatus.Status;
break;
case IRP_MN_QUERY_DEVICE_RELATIONS:
/* Query the device relations */
DPRINT("Querying PDO relations\n");
Status = HalpQueryDeviceRelations(DeviceObject,
IoStackLocation->Parameters.QueryDeviceRelations.Type,
(PVOID)&Irp->IoStatus.Information);
break;
case IRP_MN_QUERY_INTERFACE:
/* Call the worker */
DPRINT("Querying interface for PDO\n");
Status = HalpQueryInterface(DeviceObject,
IoStackLocation->Parameters.QueryInterface.InterfaceType,
IoStackLocation->Parameters.QueryInterface.Size,
IoStackLocation->Parameters.QueryInterface.InterfaceSpecificData,
IoStackLocation->Parameters.QueryInterface.Version,
IoStackLocation->Parameters.QueryInterface.Interface,
(PVOID)&Irp->IoStatus.Information);
break;
case IRP_MN_QUERY_CAPABILITIES:
/* Call the worker */
DPRINT("Querying the capabilities for the PDO\n");
Status = HalpQueryCapabilities(DeviceObject,
IoStackLocation->Parameters.DeviceCapabilities.Capabilities);
break;
case IRP_MN_QUERY_RESOURCES:
/* Call the worker */
DPRINT("Querying the resources for the PDO\n");
Status = HalpQueryResources(DeviceObject, (PVOID)&Irp->IoStatus.Information);
break;
case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
/* Call the worker */
DPRINT("Querying the resource requirements for the PDO\n");
Status = HalpQueryResourceRequirements(DeviceObject,
(PVOID)&Irp->IoStatus.Information);
break;
case IRP_MN_QUERY_ID:
/* Call the worker */
DPRINT("Query the ID for the PDO\n");
Status = HalpQueryIdPdo(DeviceObject,
IoStackLocation->Parameters.QueryId.IdType,
(PVOID)&Irp->IoStatus.Information);
break;
case IRP_MN_QUERY_DEVICE_TEXT:
/* Inherit whatever status we had */
DPRINT("Query text for the PDO\n");
Status = Irp->IoStatus.Status;
break;
case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
/* Inherit whatever status we had */
DPRINT("Filter resource requirements for the PDO\n");
Status = Irp->IoStatus.Status;
break;
case IRP_MN_QUERY_PNP_DEVICE_STATE:
/* Inherit whatever status we had */
DPRINT("Query device state for the PDO\n");
Status = Irp->IoStatus.Status;
break;
case IRP_MN_QUERY_BUS_INFORMATION:
/* Inherit whatever status we had */
DPRINT("Query bus information for the PDO\n");
Status = Irp->IoStatus.Status;
break;
default:
/* We don't handle anything else, so inherit the old state */
DPRINT1("Illegal IRP: %lx\n", Minor);
Status = Irp->IoStatus.Status;
break;
}
/* If it's not supported, inherit the old status */
if (Status == STATUS_NOT_SUPPORTED) Status = Irp->IoStatus.Status;
/* Complete the IRP */
DPRINT("IRP completed with status: %lx\n", Status);
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
}
}
NTSTATUS
NTAPI
HalpDispatchWmi(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
UNIMPLEMENTED_DBGBREAK("HAL: PnP Driver WMI!\n");
return STATUS_SUCCESS;
}
NTSTATUS
NTAPI
HalpDispatchPower(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
PFDO_EXTENSION FdoExtension;
DPRINT1("HAL: PnP Driver Power!\n");
FdoExtension = DeviceObject->DeviceExtension;
if (FdoExtension->ExtensionType == FdoExtensionType)
{
PoStartNextPowerIrp(Irp);
IoSkipCurrentIrpStackLocation(Irp);
return PoCallDriver(FdoExtension->AttachedDeviceObject, Irp);
}
else
{
PoStartNextPowerIrp(Irp);
Irp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
}
NTSTATUS
NTAPI
HalpDriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath)
{
NTSTATUS Status;
PDEVICE_OBJECT TargetDevice = NULL;
DPRINT("HAL: PnP Driver ENTRY!\n");
/* This is us */
HalpDriverObject = DriverObject;
/* Set up add device */
DriverObject->DriverExtension->AddDevice = HalpAddDevice;
/* Set up the callouts */
DriverObject->MajorFunction[IRP_MJ_PNP] = HalpDispatchPnp;
DriverObject->MajorFunction[IRP_MJ_POWER] = HalpDispatchPower;
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = HalpDispatchWmi;
/* Create the PDO */
Status = IoCreateDevice(DriverObject,
0,
NULL,
FILE_DEVICE_CONTROLLER,
0,
FALSE,
&TargetDevice);
if (!NT_SUCCESS(Status))
return Status;
TargetDevice->Flags &= ~DO_DEVICE_INITIALIZING;
/* Set up the device stack */
Status = HalpAddDevice(DriverObject, TargetDevice);
if (!NT_SUCCESS(Status))
{
IoDeleteDevice(TargetDevice);
return Status;
}
/* Tell the PnP manager about us */
Status = IoReportDetectedDevice(DriverObject,
InterfaceTypeUndefined,
-1,
-1,
NULL,
NULL,
FALSE,
&TargetDevice);
/* Return to kernel */
return Status;
}
NTSTATUS
NTAPI
HaliInitPnpDriver(VOID)
{
NTSTATUS Status;
UNICODE_STRING DriverString;
PAGED_CODE();
/* Create the driver */
RtlInitUnicodeString(&DriverString, L"\\Driver\\PCI_HAL");
Status = IoCreateDriver(&DriverString, HalpDriverEntry);
/* Return status */
return Status;
}
/* EOF */