From 1b96a22c6c222e18cbf1616776feb7822b6a2de5 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Wed, 18 Oct 2006 17:46:55 +0000 Subject: [PATCH] - Combine PnpInit1/2 since they were called one after the other. - Load RAW driver while loading boot drivers. - Cleanup IoInitSystem a bit more. svn path=/trunk/; revision=24563 --- reactos/ntoskrnl/io/iomgr/driver.c | 45 ++++++++- reactos/ntoskrnl/io/iomgr/iomgr.c | 62 +----------- reactos/ntoskrnl/io/pnpmgr/pnpmgr.c | 147 ++++++++++++++-------------- 3 files changed, 120 insertions(+), 134 deletions(-) diff --git a/reactos/ntoskrnl/io/iomgr/driver.c b/reactos/ntoskrnl/io/iomgr/driver.c index 5dcdf15e172..f33c1111719 100644 --- a/reactos/ntoskrnl/io/iomgr/driver.c +++ b/reactos/ntoskrnl/io/iomgr/driver.c @@ -918,7 +918,6 @@ IopInitializeBuiltinDriver( * Return Value * None */ - VOID FASTCALL IopInitializeBootDrivers(VOID) @@ -926,6 +925,50 @@ IopInitializeBootDrivers(VOID) PLIST_ENTRY ListHead, NextEntry; PLDR_DATA_TABLE_ENTRY LdrEntry; UNICODE_STRING NtosSymName = RTL_CONSTANT_STRING(L"ntoskrnl.sym"); + PDEVICE_NODE DeviceNode; + PDRIVER_OBJECT DriverObject; + LDR_DATA_TABLE_ENTRY ModuleObject; + NTSTATUS Status; + + /* Use IopRootDeviceNode for now */ + Status = IopCreateDeviceNode(IopRootDeviceNode, NULL, &DeviceNode); + if (!NT_SUCCESS(Status)) return; + + /* Setup the module object for the RAW FS Driver */ + ModuleObject.DllBase = NULL; + ModuleObject.SizeOfImage = 0; + ModuleObject.EntryPoint = RawFsDriverEntry; + + /* Initialize it */ + Status = IopInitializeDriverModule(DeviceNode, + &ModuleObject, + &DeviceNode->ServiceName, + TRUE, + &DriverObject); + if (!NT_SUCCESS(Status)) + { + /* Fail */ + IopFreeDeviceNode(DeviceNode); + return; + } + + /* Now initialize the associated device */ + Status = IopInitializeDevice(DeviceNode, DriverObject); + if (!NT_SUCCESS(Status)) + { + /* Fail */ + IopFreeDeviceNode(DeviceNode); + return; + } + + /* Start it up */ + Status = IopStartDevice(DeviceNode); + if (!NT_SUCCESS(Status)) + { + /* Fail */ + IopFreeDeviceNode(DeviceNode); + return; + } /* Hack for NTOSKRNL.SYM */ KDB_SYMBOLFILE_HOOK(&NtosSymName); diff --git a/reactos/ntoskrnl/io/iomgr/iomgr.c b/reactos/ntoskrnl/io/iomgr/iomgr.c index 31a87329427..70c1139c1c8 100644 --- a/reactos/ntoskrnl/io/iomgr/iomgr.c +++ b/reactos/ntoskrnl/io/iomgr/iomgr.c @@ -442,9 +442,6 @@ NTAPI IoInitSystem(IN PLOADER_PARAMETER_BLOCK LoaderBlock) { LARGE_INTEGER ExpireTime; - PDEVICE_NODE DeviceNode; - PDRIVER_OBJECT DriverObject; - LDR_DATA_TABLE_ENTRY ModuleObject; NTSTATUS Status; CHAR Buffer[256]; ANSI_STRING NtBootPath, RootString; @@ -497,66 +494,17 @@ IoInitSystem(IN PLOADER_PARAMETER_BLOCK LoaderBlock) /* Create Object Directories */ if (!IopCreateRootDirectories()) return FALSE; - /* - * Initialize PnP manager - */ + /* Initialize PnP manager */ PnpInit(); - PnpInit2(); - - IoCreateDriverList(); - - KeInitializeSpinLock (&IoStatisticsLock); - - /* Initialize raw filesystem driver */ - - /* Use IopRootDeviceNode for now */ - Status = IopCreateDeviceNode(IopRootDeviceNode, NULL, &DeviceNode); - if (!NT_SUCCESS(Status)) - { - CPRINT("IopCreateDeviceNode() failed with status (%x)\n", Status); - return FALSE; - } - - ModuleObject.DllBase = NULL; - ModuleObject.SizeOfImage = 0; - ModuleObject.EntryPoint = RawFsDriverEntry; - - Status = IopInitializeDriverModule(DeviceNode, - &ModuleObject, - &DeviceNode->ServiceName, - TRUE, - &DriverObject); - if (!NT_SUCCESS(Status)) - { - IopFreeDeviceNode(DeviceNode); - CPRINT("IopInitializeDriver() failed with status (%x)\n", Status); - return FALSE; - } - - Status = IopInitializeDevice(DeviceNode, DriverObject); - if (!NT_SUCCESS(Status)) - { - IopFreeDeviceNode(DeviceNode); - CPRINT("IopInitializeDevice() failed with status (%x)\n", Status); - return FALSE; - } - - Status = IopStartDevice(DeviceNode); - if (!NT_SUCCESS(Status)) - { - IopFreeDeviceNode(DeviceNode); - CPRINT("IopInitializeDevice() failed with status (%x)\n", Status); - return FALSE; - } - - /* - * Initialize PnP root releations - */ + /* Initialize PnP root relations */ IoSynchronousInvalidateDeviceRelations(IopRootDeviceNode-> PhysicalDeviceObject, BusRelations); + /* Create the group driver list */ + IoCreateDriverList(); + /* Load boot start drivers */ IopInitializeBootDrivers(); diff --git a/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c b/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c index b4692aac8d4..f6b671c8071 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c @@ -2610,73 +2610,6 @@ cleanup: ExFreePool(Data); } -VOID INIT_FUNCTION -PnpInit(VOID) -{ - PDEVICE_OBJECT Pdo; - NTSTATUS Status; - - DPRINT("PnpInit()\n"); - - KeInitializeSpinLock(&IopDeviceTreeLock); - - /* Initialize the Bus Type GUID List */ - IopBusTypeGuidList = ExAllocatePool(PagedPool, sizeof(IO_BUS_TYPE_GUID_LIST)); - RtlZeroMemory(IopBusTypeGuidList, sizeof(IO_BUS_TYPE_GUID_LIST)); - ExInitializeFastMutex(&IopBusTypeGuidList->Lock); - - /* Initialize PnP-Event notification support */ - Status = IopInitPlugPlayEvents(); - if (!NT_SUCCESS(Status)) - { - CPRINT("IopInitPlugPlayEvents() failed\n"); - KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0); - } - - /* - * Create root device node - */ - - Status = IopCreateDriverObject(&IopRootDriverObject, NULL, 0, FALSE, NULL, 0); - if (!NT_SUCCESS(Status)) - { - CPRINT("IoCreateDriverObject() failed\n"); - KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0); - } - - Status = IoCreateDevice(IopRootDriverObject, 0, NULL, FILE_DEVICE_CONTROLLER, - 0, FALSE, &Pdo); - if (!NT_SUCCESS(Status)) - { - CPRINT("IoCreateDevice() failed\n"); - KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0); - } - - Status = IopCreateDeviceNode(NULL, Pdo, &IopRootDeviceNode); - if (!NT_SUCCESS(Status)) - { - CPRINT("Insufficient resources\n"); - KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0); - } - - if (!RtlCreateUnicodeString(&IopRootDeviceNode->InstancePath, - L"HTREE\\ROOT\\0")) - { - CPRINT("Failed to create the instance path!\n"); - KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, STATUS_NO_MEMORY, 0, 0, 0); - } - - /* Report the device to the user-mode pnp manager */ - IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL, - &IopRootDeviceNode->InstancePath); - - IopRootDeviceNode->PhysicalDeviceObject->Flags |= DO_BUS_ENUMERATED_DEVICE; - PnpRootDriverEntry(IopRootDriverObject, NULL); - IopRootDriverObject->DriverExtension->AddDevice( - IopRootDriverObject, - IopRootDeviceNode->PhysicalDeviceObject); -} - static NTSTATUS INIT_FUNCTION IopEnumerateDetectedDevices( IN HANDLE hBaseKey, @@ -3297,17 +3230,79 @@ IopUpdateRootKey(VOID) } VOID INIT_FUNCTION -PnpInit2(VOID) +PnpInit(VOID) { - NTSTATUS Status; + PDEVICE_OBJECT Pdo; + NTSTATUS Status; - /* Move information about devices detected by Freeloader to SYSTEM\CurrentControlSet\Root\ */ - Status = IopUpdateRootKey(); - if (!NT_SUCCESS(Status)) - { - CPRINT("IopUpdateRootKey() failed\n"); - KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0); - } + DPRINT("PnpInit()\n"); + + KeInitializeSpinLock(&IopDeviceTreeLock); + + /* Initialize the Bus Type GUID List */ + IopBusTypeGuidList = ExAllocatePool(PagedPool, sizeof(IO_BUS_TYPE_GUID_LIST)); + RtlZeroMemory(IopBusTypeGuidList, sizeof(IO_BUS_TYPE_GUID_LIST)); + ExInitializeFastMutex(&IopBusTypeGuidList->Lock); + + /* Initialize PnP-Event notification support */ + Status = IopInitPlugPlayEvents(); + if (!NT_SUCCESS(Status)) + { + CPRINT("IopInitPlugPlayEvents() failed\n"); + KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0); + } + + /* + * Create root device node + */ + + Status = IopCreateDriverObject(&IopRootDriverObject, NULL, 0, FALSE, NULL, 0); + if (!NT_SUCCESS(Status)) + { + CPRINT("IoCreateDriverObject() failed\n"); + KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0); + } + + Status = IoCreateDevice(IopRootDriverObject, 0, NULL, FILE_DEVICE_CONTROLLER, + 0, FALSE, &Pdo); + if (!NT_SUCCESS(Status)) + { + CPRINT("IoCreateDevice() failed\n"); + KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0); + } + + Status = IopCreateDeviceNode(NULL, Pdo, &IopRootDeviceNode); + if (!NT_SUCCESS(Status)) + { + CPRINT("Insufficient resources\n"); + KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0); + } + + if (!RtlCreateUnicodeString(&IopRootDeviceNode->InstancePath, + L"HTREE\\ROOT\\0")) + { + CPRINT("Failed to create the instance path!\n"); + KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, STATUS_NO_MEMORY, 0, 0, 0); + } + + /* Report the device to the user-mode pnp manager */ + IopQueueTargetDeviceEvent(&GUID_DEVICE_ARRIVAL, + &IopRootDeviceNode->InstancePath); + + IopRootDeviceNode->PhysicalDeviceObject->Flags |= DO_BUS_ENUMERATED_DEVICE; + PnpRootDriverEntry(IopRootDriverObject, NULL); + IopRootDriverObject->DriverExtension->AddDevice( + IopRootDriverObject, + IopRootDeviceNode->PhysicalDeviceObject); + + /* Move information about devices detected by Freeloader to SYSTEM\CurrentControlSet\Root\ */ + Status = IopUpdateRootKey(); + if (!NT_SUCCESS(Status)) + { + CPRINT("IopUpdateRootKey() failed\n"); + KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0); + } } + /* EOF */