7 #include <acpi_drivers.h>
13 #pragma alloc_text (INIT, DriverEntry)
14 #pragma alloc_text (PAGE, Bus_AddDevice)
23 PDRIVER_OBJECT DriverObject
,
24 PDEVICE_OBJECT PhysicalDeviceObject
29 PDEVICE_OBJECT deviceObject
= NULL
;
30 PFDO_DEVICE_DATA deviceData
= NULL
;
31 PWCHAR deviceName
= NULL
;
36 DPRINT("Add Device: 0x%p\n", PhysicalDeviceObject
);
38 DPRINT1("#################### Bus_CreateClose Creating FDO Device ####################\n");
39 status
= IoCreateDevice(DriverObject
,
40 sizeof(FDO_DEVICE_DATA
),
43 FILE_DEVICE_SECURE_OPEN
,
46 if (!NT_SUCCESS(status
))
48 DPRINT1("IoCreateDevice() failed with status 0x%X\n", status
);
52 deviceData
= (PFDO_DEVICE_DATA
) deviceObject
->DeviceExtension
;
53 RtlZeroMemory (deviceData
, sizeof (FDO_DEVICE_DATA
));
56 // Set the initial state of the FDO
59 INITIALIZE_PNP_STATE(deviceData
->Common
);
61 deviceData
->Common
.IsFDO
= TRUE
;
63 deviceData
->Common
.Self
= deviceObject
;
65 ExInitializeFastMutex (&deviceData
->Mutex
);
67 InitializeListHead (&deviceData
->ListOfPDOs
);
69 // Set the PDO for use with PlugPlay functions
71 deviceData
->UnderlyingPDO
= PhysicalDeviceObject
;
74 // Set the initial powerstate of the FDO
77 deviceData
->Common
.DevicePowerState
= PowerDeviceUnspecified
;
78 deviceData
->Common
.SystemPowerState
= PowerSystemWorking
;
80 deviceObject
->Flags
|= DO_POWER_PAGABLE
;
83 // Attach our FDO to the device stack.
84 // The return value of IoAttachDeviceToDeviceStack is the top of the
85 // attachment chain. This is where all the IRPs should be routed.
88 deviceData
->NextLowerDriver
= IoAttachDeviceToDeviceStack (
90 PhysicalDeviceObject
);
92 if (NULL
== deviceData
->NextLowerDriver
) {
94 status
= STATUS_NO_SUCH_DEVICE
;
101 // We will demonstrate here the step to retrieve the name of the PDO
104 status
= IoGetDeviceProperty (PhysicalDeviceObject
,
105 DevicePropertyPhysicalDeviceObjectName
,
110 if (status
!= STATUS_BUFFER_TOO_SMALL
)
112 DPRINT1("AddDevice:IoGDP failed (0x%x)\n", status
);
116 deviceName
= ExAllocatePoolWithTag (NonPagedPool
,
119 if (NULL
== deviceName
) {
120 DPRINT1("AddDevice: no memory to alloc for deviceName(0x%x)\n", nameLength
);
121 status
= STATUS_INSUFFICIENT_RESOURCES
;
125 status
= IoGetDeviceProperty (PhysicalDeviceObject
,
126 DevicePropertyPhysicalDeviceObjectName
,
131 if (!NT_SUCCESS (status
)) {
133 DPRINT1("AddDevice:IoGDP(2) failed (0x%x)", status
);
137 DPRINT1("AddDevice: %p to %p->%p (%ws) \n",
139 deviceData
->NextLowerDriver
,
140 PhysicalDeviceObject
,
146 // We are done with initializing, so let's indicate that and return.
147 // This should be the final step in the AddDevice process.
149 deviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
153 ExFreePool(deviceName
);
155 if (!NT_SUCCESS(status
) && deviceObject
){
156 if (deviceData
&& deviceData
->NextLowerDriver
){
157 IoDetachDevice (deviceData
->NextLowerDriver
);
159 IoDeleteDevice (deviceObject
);
167 ACPIDispatchDeviceControl(
168 IN PDEVICE_OBJECT DeviceObject
,
171 PIO_STACK_LOCATION IrpSp
;
174 DPRINT("Called. IRP is at (0x%X)\n", Irp
);
176 Irp
->IoStatus
.Information
= 0;
178 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
179 switch (IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
) {
181 DPRINT("Unknown IOCTL 0x%X\n", IrpSp
->Parameters
.DeviceIoControl
.IoControlCode
);
182 Status
= STATUS_NOT_IMPLEMENTED
;
186 if (Status
!= STATUS_PENDING
) {
187 Irp
->IoStatus
.Status
= Status
;
189 DPRINT("Completing IRP at 0x%X\n", Irp
);
191 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
194 DPRINT("Leaving. Status 0x%X\n", Status
);
202 PDRIVER_OBJECT DriverObject
,
203 PUNICODE_STRING RegistryPath
206 DPRINT("Driver Entry \n");
209 // Set entry points into the driver
211 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = ACPIDispatchDeviceControl
;
212 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = Bus_PnP
;
213 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = Bus_Power
;
215 DriverObject
->DriverExtension
->AddDevice
= Bus_AddDevice
;
217 return STATUS_SUCCESS
;