- 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
This commit is contained in:
Alex Ionescu 2006-10-18 17:46:55 +00:00
parent fd5116b50c
commit 1b96a22c6c
3 changed files with 120 additions and 134 deletions

View file

@ -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);

View file

@ -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();

View file

@ -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 */