2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/multimedia/portcls/adapter.c
5 * PURPOSE: Port Class driver / DriverEntry and IRP handlers
6 * PROGRAMMER: Andrew Greenwood
15 This is called from DriverEntry so that PortCls can take care of some
16 IRPs and map some others to the main KS driver. In most cases this will
17 be the first function called by an audio driver.
19 First 2 parameters are from DriverEntry.
21 The AddDevice parameter is a driver-supplied pointer to a function which
22 typically then calls PcAddAdapterDevice (see below.)
25 PcInitializeAdapterDriver(
26 IN PDRIVER_OBJECT DriverObject
,
27 IN PUNICODE_STRING RegistryPathName
,
28 IN PDRIVER_ADD_DEVICE AddDevice
)
31 (* = implement here, otherwise KS default)
41 * IRP_MJ_SYSTEM_CONTROL
48 DPRINT("PcInitializeAdapterDriver\n");
51 /* Set default stub - is this a good idea? */
52 DPRINT1("Setting IRP stub\n");
53 for ( i
= 0; i
<= IRP_MJ_MAXIMUM_FUNCTION
; i
++ )
55 DriverObject
->MajorFunction
[i
] = IrpStub
;
59 /* Our IRP handlers */
60 DPRINT1("Setting IRP handlers\n");
61 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = PcDispatchIrp
;
62 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = PcDispatchIrp
;
63 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = PcDispatchIrp
;
64 DriverObject
->MajorFunction
[IRP_MJ_SYSTEM_CONTROL
] = PcDispatchIrp
;
66 /* The driver-supplied AddDevice */
67 DriverObject
->DriverExtension
->AddDevice
= AddDevice
;
69 /* KS handles these */
70 DPRINT1("Setting KS function handlers\n");
71 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_CLOSE
);
72 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_DEVICE_CONTROL
);
73 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_FLUSH_BUFFERS
);
74 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_QUERY_SECURITY
);
75 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_READ
);
76 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_SET_SECURITY
);
77 KsSetMajorFunctionHandler(DriverObject
, IRP_MJ_WRITE
);
79 DPRINT1("PortCls has finished initializing the adapter driver\n");
81 return STATUS_SUCCESS
;
85 Typically called by a driver's AddDevice function, which is set when
86 calling PcInitializeAdapterDriver. This performs some common driver
87 operations, such as creating a device extension.
89 The StartDevice parameter is a driver-supplied function which gets
90 called in response to IRP_MJ_PNP / IRP_MN_START_DEVICE.
94 IN PDRIVER_OBJECT DriverObject
,
95 IN PDEVICE_OBJECT PhysicalDeviceObject
,
96 IN PCPFNSTARTDEVICE StartDevice
,
98 IN ULONG DeviceExtensionSize
)
101 Note - after this has been called, we can
102 handle IRP_MN_START_DEVICE by calling StartDevice
105 Validate DeviceExtensionSize!! (et al...)
108 NTSTATUS status
= STATUS_UNSUCCESSFUL
;
109 PDEVICE_OBJECT fdo
= NULL
;
110 PCExtension
* portcls_ext
;
112 DPRINT1("PcAddAdapterDevice called\n");
116 DPRINT("DriverObject is NULL!\n");
117 return STATUS_INVALID_PARAMETER
;
120 if ( ! PhysicalDeviceObject
)
122 DPRINT("PhysicalDeviceObject is NULL!\n");
123 return STATUS_INVALID_PARAMETER
;
128 DPRINT("No StartDevice parameter!\n");
129 return STATUS_INVALID_PARAMETER
;
132 /* TODO: Make sure this is right */
133 if ( DeviceExtensionSize
< PORT_CLASS_DEVICE_EXTENSION_SIZE
)
135 if ( DeviceExtensionSize
!= 0 )
138 DPRINT("DeviceExtensionSize is invalid\n");
139 return STATUS_INVALID_PARAMETER
;
143 DPRINT("portcls is creating a device\n");
144 status
= IoCreateDevice(DriverObject
,
148 PhysicalDeviceObject
->Characteristics
, /* TODO: Check */
152 if ( ! NT_SUCCESS(status
) )
154 DPRINT("IoCreateDevice() failed with status 0x%08lx\n", status
);
158 /* Obtain the new device extension */
159 portcls_ext
= (PCExtension
*) fdo
->DeviceExtension
;
164 RtlZeroMemory(portcls_ext
, sizeof(PCExtension
));
165 portcls_ext
->StartDevice
= StartDevice
;
167 status
= KsAllocateDeviceHeader(&portcls_ext
->KsDeviceHeader
, 0, NULL
);
168 if (!NT_SUCCESS(status
))
174 DPRINT("PcAddAdapterDriver succeeded\n");
182 IN PDEVICE_OBJECT DeviceObject
,
185 DPRINT1("PortClsSysControl called\n");
189 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
190 Irp
->IoStatus
.Information
= 0;
191 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
193 return STATUS_SUCCESS
;
198 IN PDEVICE_OBJECT DeviceObject
,
202 PCExtension
* DeviceExt
;
205 if (!DeviceObject
|| !Name
|| !Unknown
)
206 return STATUS_INVALID_PARAMETER
;
208 DeviceExt
= (PCExtension
*)DeviceObject
->DeviceExtension
;
210 return STATUS_UNSUCCESSFUL
;
212 Status
= KsAddObjectCreateItemToDeviceHeader(DeviceExt
->KsDeviceHeader
, PciDriverDispatch
, (PVOID
)Unknown
, Name
, NULL
);
215 return STATUS_UNSUCCESSFUL
;