- Create device instance key for root device node.

- Add DeviceReference value for each non-root device node.

svn path=/trunk/; revision=15796
This commit is contained in:
Eric Kohl 2005-06-04 22:55:58 +00:00
parent 607f793fc0
commit 355593bafa
3 changed files with 118 additions and 37 deletions

View file

@ -16,8 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id$ /*
*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: include/internal/io.h * FILE: include/internal/io.h
@ -340,6 +339,9 @@ extern ULONGLONG IoOtherTransferCount;
VOID VOID
PnpInit(VOID); PnpInit(VOID);
VOID
PnpInit2(VOID);
VOID VOID
IopInitDriverImplementation(VOID); IopInitDriverImplementation(VOID);

View file

@ -40,7 +40,7 @@ NPAGED_LOOKASIDE_LIST IoLargeIrpLookaside;
NPAGED_LOOKASIDE_LIST IoSmallIrpLookaside; NPAGED_LOOKASIDE_LIST IoSmallIrpLookaside;
/* INIT FUNCTIONS ************************************************************/ /* INIT FUNCTIONS ************************************************************/
VOID VOID
INIT_FUNCTION INIT_FUNCTION
IoInitCancelHandling(VOID) IoInitCancelHandling(VOID)
@ -64,11 +64,11 @@ IopInitLookasideLists(VOID)
ULONG i; ULONG i;
PKPRCB Prcb; PKPRCB Prcb;
PNPAGED_LOOKASIDE_LIST CurrentList = NULL; PNPAGED_LOOKASIDE_LIST CurrentList = NULL;
/* Calculate the sizes */ /* Calculate the sizes */
LargeIrpSize = sizeof(IRP) + (8 * sizeof(IO_STACK_LOCATION)); LargeIrpSize = sizeof(IRP) + (8 * sizeof(IO_STACK_LOCATION));
SmallIrpSize = sizeof(IRP) + sizeof(IO_STACK_LOCATION); SmallIrpSize = sizeof(IRP) + sizeof(IO_STACK_LOCATION);
/* Initialize the Lookaside List for Large IRPs */ /* Initialize the Lookaside List for Large IRPs */
ExInitializeNPagedLookasideList(&IoLargeIrpLookaside, ExInitializeNPagedLookasideList(&IoLargeIrpLookaside,
NULL, NULL,
@ -77,7 +77,7 @@ IopInitLookasideLists(VOID)
LargeIrpSize, LargeIrpSize,
IO_LARGEIRP, IO_LARGEIRP,
0); 0);
/* Initialize the Lookaside List for Small IRPs */ /* Initialize the Lookaside List for Small IRPs */
ExInitializeNPagedLookasideList(&IoSmallIrpLookaside, ExInitializeNPagedLookasideList(&IoSmallIrpLookaside,
NULL, NULL,
@ -95,14 +95,14 @@ IopInitLookasideLists(VOID)
sizeof(IO_COMPLETION_PACKET), sizeof(IO_COMPLETION_PACKET),
IOC_TAG1, IOC_TAG1,
0); 0);
/* Now allocate the per-processor lists */ /* Now allocate the per-processor lists */
for (i = 0; i < KeNumberProcessors; i++) for (i = 0; i < KeNumberProcessors; i++)
{ {
/* Get the PRCB for this CPU */ /* Get the PRCB for this CPU */
Prcb = ((PKPCR)(KPCR_BASE + i * PAGE_SIZE))->Prcb; Prcb = ((PKPCR)(KPCR_BASE + i * PAGE_SIZE))->Prcb;
DPRINT("Setting up lookaside for CPU: %x, PRCB: %p\n", i, Prcb); DPRINT("Setting up lookaside for CPU: %x, PRCB: %p\n", i, Prcb);
/* Set the Large IRP List */ /* Set the Large IRP List */
Prcb->PPLookasideList[LookasideLargeIrpList].L = &IoLargeIrpLookaside.L; Prcb->PPLookasideList[LookasideLargeIrpList].L = &IoLargeIrpLookaside.L;
CurrentList = ExAllocatePoolWithTag(NonPagedPool, CurrentList = ExAllocatePoolWithTag(NonPagedPool,
@ -124,7 +124,7 @@ IopInitLookasideLists(VOID)
CurrentList = &IoLargeIrpLookaside; CurrentList = &IoLargeIrpLookaside;
} }
Prcb->PPLookasideList[LookasideLargeIrpList].P = &CurrentList->L; Prcb->PPLookasideList[LookasideLargeIrpList].P = &CurrentList->L;
/* Set the Small IRP List */ /* Set the Small IRP List */
Prcb->PPLookasideList[LookasideSmallIrpList].L = &IoSmallIrpLookaside.L; Prcb->PPLookasideList[LookasideSmallIrpList].L = &IoSmallIrpLookaside.L;
CurrentList = ExAllocatePoolWithTag(NonPagedPool, CurrentList = ExAllocatePoolWithTag(NonPagedPool,
@ -146,7 +146,7 @@ IopInitLookasideLists(VOID)
CurrentList = &IoSmallIrpLookaside; CurrentList = &IoSmallIrpLookaside;
} }
Prcb->PPLookasideList[LookasideSmallIrpList].P = &CurrentList->L; Prcb->PPLookasideList[LookasideSmallIrpList].P = &CurrentList->L;
/* Set the I/O Completion List */ /* Set the I/O Completion List */
Prcb->PPLookasideList[LookasideCompletionList].L = &IoCompletionPacketLookaside.L; Prcb->PPLookasideList[LookasideCompletionList].L = &IoCompletionPacketLookaside.L;
CurrentList = ExAllocatePoolWithTag(NonPagedPool, CurrentList = ExAllocatePoolWithTag(NonPagedPool,
@ -169,7 +169,7 @@ IopInitLookasideLists(VOID)
} }
Prcb->PPLookasideList[LookasideCompletionList].P = &CurrentList->L; Prcb->PPLookasideList[LookasideCompletionList].P = &CurrentList->L;
} }
DPRINT("Done allocation\n"); DPRINT("Done allocation\n");
} }
@ -187,7 +187,7 @@ IoInit (VOID)
IopInitDriverImplementation(); IopInitDriverImplementation();
DPRINT("Creating Device Object Type\n"); DPRINT("Creating Device Object Type\n");
/* Initialize the Driver object type */ /* Initialize the Driver object type */
RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer)); RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
RtlInitUnicodeString(&Name, L"Device"); RtlInitUnicodeString(&Name, L"Device");
@ -198,16 +198,16 @@ IoInit (VOID)
ObjectTypeInitializer.UseDefaultObject = TRUE; ObjectTypeInitializer.UseDefaultObject = TRUE;
ObjectTypeInitializer.GenericMapping = IopFileMapping; ObjectTypeInitializer.GenericMapping = IopFileMapping;
ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &IoDeviceObjectType); ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &IoDeviceObjectType);
/* Do the Adapter Type */ /* Do the Adapter Type */
RtlInitUnicodeString(&Name, L"Adapter"); RtlInitUnicodeString(&Name, L"Adapter");
ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &IoAdapterObjectType); ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &IoAdapterObjectType);
/* Do the Controller Type */ /* Do the Controller Type */
RtlInitUnicodeString(&Name, L"Controller"); RtlInitUnicodeString(&Name, L"Controller");
ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(CONTROLLER_OBJECT); ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(CONTROLLER_OBJECT);
ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &IoControllerObjectType); ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &IoControllerObjectType);
/* Initialize the File object type */ /* Initialize the File object type */
RtlInitUnicodeString(&Name, L"File"); RtlInitUnicodeString(&Name, L"File");
ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer); ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
@ -315,7 +315,7 @@ IoInit (VOID)
*/ */
PnpInit(); PnpInit();
} }
VOID VOID
INIT_FUNCTION INIT_FUNCTION
IoInit2(BOOLEAN BootLog) IoInit2(BOOLEAN BootLog)
@ -325,6 +325,8 @@ IoInit2(BOOLEAN BootLog)
MODULE_OBJECT ModuleObject; MODULE_OBJECT ModuleObject;
NTSTATUS Status; NTSTATUS Status;
PnpInit2();
IoCreateDriverList(); IoCreateDriverList();
KeInitializeSpinLock (&IoStatisticsLock); KeInitializeSpinLock (&IoStatisticsLock);

View file

@ -1,5 +1,4 @@
/* $Id$ /*
*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/pnpmgr.c * FILE: ntoskrnl/io/pnpmgr.c
@ -893,6 +892,39 @@ IopSetDeviceInstanceData(HANDLE InstanceKey,
ZwClose(LogConfKey); ZwClose(LogConfKey);
} }
if (DeviceNode->PhysicalDeviceObject != NULL)
{
/* Create the 'Control' key */
RtlInitUnicodeString(&KeyName,
L"Control");
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE | OBJ_OPENIF,
InstanceKey,
NULL);
Status = ZwCreateKey(&LogConfKey,
KEY_ALL_ACCESS,
&ObjectAttributes,
0,
NULL,
REG_OPTION_VOLATILE,
NULL);
if (NT_SUCCESS(Status))
{
ULONG Reference = (ULONG)DeviceNode->PhysicalDeviceObject;
RtlInitUnicodeString(&KeyName,
L"DeviceReference");
Status = ZwSetValueKey(LogConfKey,
&KeyName,
0,
REG_DWORD,
&Reference,
sizeof(PVOID));
ZwClose(LogConfKey);
}
}
DPRINT("IopSetDeviceInstanceData() done\n"); DPRINT("IopSetDeviceInstanceData() done\n");
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -909,17 +941,17 @@ IopAssignDeviceResources(
ULONG NumberOfResources = 0; ULONG NumberOfResources = 0;
ULONG i; ULONG i;
NTSTATUS Status; NTSTATUS Status;
/* Fill DeviceNode->ResourceList and DeviceNode->ResourceListTranslated; /* Fill DeviceNode->ResourceList and DeviceNode->ResourceListTranslated;
* by using DeviceNode->ResourceRequirements */ * by using DeviceNode->ResourceRequirements */
if (!DeviceNode->ResourceRequirements if (!DeviceNode->ResourceRequirements
|| DeviceNode->ResourceRequirements->AlternativeLists == 0) || DeviceNode->ResourceRequirements->AlternativeLists == 0)
{ {
DeviceNode->ResourceList = DeviceNode->ResourceListTranslated = NULL; DeviceNode->ResourceList = DeviceNode->ResourceListTranslated = NULL;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/* FIXME: that's here that PnP arbiter should go */ /* FIXME: that's here that PnP arbiter should go */
/* Actually, simply use resource list #0 as assigned resource list */ /* Actually, simply use resource list #0 as assigned resource list */
ResourceList = &DeviceNode->ResourceRequirements->List[0]; ResourceList = &DeviceNode->ResourceRequirements->List[0];
@ -928,45 +960,45 @@ IopAssignDeviceResources(
Status = STATUS_REVISION_MISMATCH; Status = STATUS_REVISION_MISMATCH;
goto ByeBye; goto ByeBye;
} }
DeviceNode->ResourceList = ExAllocatePool(PagedPool, DeviceNode->ResourceList = ExAllocatePool(PagedPool,
sizeof(CM_RESOURCE_LIST) + ResourceList->Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)); sizeof(CM_RESOURCE_LIST) + ResourceList->Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
if (!DeviceNode->ResourceList) if (!DeviceNode->ResourceList)
{ {
Status = STATUS_INSUFFICIENT_RESOURCES; Status = STATUS_INSUFFICIENT_RESOURCES;
goto ByeBye; goto ByeBye;
} }
DeviceNode->ResourceListTranslated = ExAllocatePool(PagedPool, DeviceNode->ResourceListTranslated = ExAllocatePool(PagedPool,
sizeof(CM_RESOURCE_LIST) + ResourceList->Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)); sizeof(CM_RESOURCE_LIST) + ResourceList->Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
if (!DeviceNode->ResourceListTranslated) if (!DeviceNode->ResourceListTranslated)
{ {
Status = STATUS_INSUFFICIENT_RESOURCES; Status = STATUS_INSUFFICIENT_RESOURCES;
goto ByeBye; goto ByeBye;
} }
DeviceNode->ResourceList->Count = 1; DeviceNode->ResourceList->Count = 1;
DeviceNode->ResourceList->List[0].InterfaceType = DeviceNode->ResourceRequirements->InterfaceType; DeviceNode->ResourceList->List[0].InterfaceType = DeviceNode->ResourceRequirements->InterfaceType;
DeviceNode->ResourceList->List[0].BusNumber = DeviceNode->ResourceRequirements->BusNumber; DeviceNode->ResourceList->List[0].BusNumber = DeviceNode->ResourceRequirements->BusNumber;
DeviceNode->ResourceList->List[0].PartialResourceList.Version = 1; DeviceNode->ResourceList->List[0].PartialResourceList.Version = 1;
DeviceNode->ResourceList->List[0].PartialResourceList.Revision = 1; DeviceNode->ResourceList->List[0].PartialResourceList.Revision = 1;
DeviceNode->ResourceListTranslated->Count = 1; DeviceNode->ResourceListTranslated->Count = 1;
DeviceNode->ResourceListTranslated->List[0].InterfaceType = DeviceNode->ResourceRequirements->InterfaceType; DeviceNode->ResourceListTranslated->List[0].InterfaceType = DeviceNode->ResourceRequirements->InterfaceType;
DeviceNode->ResourceListTranslated->List[0].BusNumber = DeviceNode->ResourceRequirements->BusNumber; DeviceNode->ResourceListTranslated->List[0].BusNumber = DeviceNode->ResourceRequirements->BusNumber;
DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Version = 1; DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Version = 1;
DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Revision = 1; DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Revision = 1;
for (i = 0; i < ResourceList->Count; i++) for (i = 0; i < ResourceList->Count; i++)
{ {
ResourceDescriptor = &ResourceList->Descriptors[i]; ResourceDescriptor = &ResourceList->Descriptors[i];
if (ResourceDescriptor->Option == 0 || ResourceDescriptor->Option == IO_RESOURCE_PREFERRED) if (ResourceDescriptor->Option == 0 || ResourceDescriptor->Option == IO_RESOURCE_PREFERRED)
{ {
DescriptorRaw = &DeviceNode->ResourceList->List[0].PartialResourceList.PartialDescriptors[NumberOfResources]; DescriptorRaw = &DeviceNode->ResourceList->List[0].PartialResourceList.PartialDescriptors[NumberOfResources];
DescriptorTranslated = &DeviceNode->ResourceListTranslated->List[0].PartialResourceList.PartialDescriptors[NumberOfResources]; DescriptorTranslated = &DeviceNode->ResourceListTranslated->List[0].PartialResourceList.PartialDescriptors[NumberOfResources];
NumberOfResources++; NumberOfResources++;
/* Copy ResourceDescriptor to DescriptorRaw and DescriptorTranslated */ /* Copy ResourceDescriptor to DescriptorRaw and DescriptorTranslated */
DescriptorRaw->Type = DescriptorTranslated->Type = ResourceDescriptor->Type; DescriptorRaw->Type = DescriptorTranslated->Type = ResourceDescriptor->Type;
DescriptorRaw->ShareDisposition = DescriptorTranslated->ShareDisposition = ResourceDescriptor->ShareDisposition; DescriptorRaw->ShareDisposition = DescriptorTranslated->ShareDisposition = ResourceDescriptor->ShareDisposition;
@ -1001,7 +1033,7 @@ IopAssignDeviceResources(
DescriptorRaw->u.Interrupt.Vector = 9; DescriptorRaw->u.Interrupt.Vector = 9;
else else
DescriptorRaw->u.Interrupt.Vector = ResourceDescriptor->u.Interrupt.MinimumVector; DescriptorRaw->u.Interrupt.Vector = ResourceDescriptor->u.Interrupt.MinimumVector;
DescriptorTranslated->u.Interrupt.Vector = HalGetInterruptVector( DescriptorTranslated->u.Interrupt.Vector = HalGetInterruptVector(
DeviceNode->ResourceRequirements->InterfaceType, DeviceNode->ResourceRequirements->InterfaceType,
DeviceNode->ResourceRequirements->BusNumber, DeviceNode->ResourceRequirements->BusNumber,
@ -1069,12 +1101,12 @@ IopAssignDeviceResources(
NumberOfResources--; NumberOfResources--;
} }
} }
} }
DeviceNode->ResourceList->List[0].PartialResourceList.Count = NumberOfResources; DeviceNode->ResourceList->List[0].PartialResourceList.Count = NumberOfResources;
DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Count = NumberOfResources; DeviceNode->ResourceListTranslated->List[0].PartialResourceList.Count = NumberOfResources;
return STATUS_SUCCESS; return STATUS_SUCCESS;
ByeBye: ByeBye:
@ -1818,7 +1850,8 @@ IopInitializePnpServices(
DeviceNode, DeviceNode,
IopActionInitBootServices, IopActionInitBootServices,
DeviceNode); DeviceNode);
} else }
else
{ {
IopInitDeviceTreeTraverseContext( IopInitDeviceTreeTraverseContext(
&Context, &Context,
@ -1981,6 +2014,35 @@ IopInvalidateDeviceRelations(
} }
static NTSTATUS INIT_FUNCTION
IopSetRootDeviceInstanceData(PDEVICE_NODE DeviceNode)
{
PWSTR KeyBuffer;
HANDLE InstanceKey = NULL;
NTSTATUS Status;
/* Create registry key for the instance id, if it doesn't exist yet */
KeyBuffer = ExAllocatePool(PagedPool,
(49 * sizeof(WCHAR)) + DeviceNode->InstancePath.Length);
wcscpy(KeyBuffer, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
wcscat(KeyBuffer, DeviceNode->InstancePath.Buffer);
Status = IopCreateDeviceKeyPath(KeyBuffer,
&InstanceKey);
ExFreePool(KeyBuffer);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to create the instance key! (Status %lx)\n", Status);
return Status;
}
/* FIXME: Set 'ConfigFlags' value */
ZwClose(InstanceKey);
return Status;
}
VOID INIT_FUNCTION VOID INIT_FUNCTION
PnpInit(VOID) PnpInit(VOID)
{ {
@ -2026,7 +2088,7 @@ PnpInit(VOID)
} }
if (!IopCreateUnicodeString(&IopRootDeviceNode->InstancePath, if (!IopCreateUnicodeString(&IopRootDeviceNode->InstancePath,
L"HTREE\\Root\\0", L"HTREE\\ROOT\\0",
PagedPool)) PagedPool))
{ {
CPRINT("Failed to create the instance path!\n"); CPRINT("Failed to create the instance path!\n");
@ -2044,4 +2106,19 @@ PnpInit(VOID)
IopRootDeviceNode->PhysicalDeviceObject); IopRootDeviceNode->PhysicalDeviceObject);
} }
VOID INIT_FUNCTION
PnpInit2(VOID)
{
NTSTATUS Status;
/* Set root device instance data */
Status = IopSetRootDeviceInstanceData(IopRootDeviceNode);
if (!NT_SUCCESS(Status))
{
CPRINT("Failed to set instance data\n");
KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
}
}
/* EOF */ /* EOF */