3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/cntrller.c
6 * PURPOSE: Implements the controller object
7 * PROGRAMMER: David Welch (welch@mcmail.com)
12 /* INCLUDES *****************************************************************/
15 #include <internal/debug.h>
17 /* GLOBALS *******************************************************************/
19 #define TAG_CQE TAG('C', 'Q', 'E', ' ')
20 #define TAG_CONTROLLER TAG('C', 'N', 'T', 'R')
21 #define TAG_CONTROLLER_EXTENSION TAG('C', 'E', 'X', 'T')
23 /* TYPES ********************************************************************/
27 * PURPOSE: A entry in the queue waiting for a controller object
30 KDEVICE_QUEUE_ENTRY Entry
;
31 PDEVICE_OBJECT DeviceObject
;
32 PDRIVER_CONTROL ExecutionRoutine
;
34 } CONTROLLER_QUEUE_ENTRY
, *PCONTROLLER_QUEUE_ENTRY
;
36 /* FUNCTIONS *****************************************************************/
43 IoAllocateController(PCONTROLLER_OBJECT ControllerObject
,
44 PDEVICE_OBJECT DeviceObject
,
45 PDRIVER_CONTROL ExecutionRoutine
,
48 * FUNCTION: Sets up a call to a driver-supplied ControllerControl routine
49 * as soon as the device controller, represented by the given controller
50 * object, is available to carry out an I/O operation for the target device,
51 * represented by the given device object.
53 * ControllerObject = Driver created controller object
54 * DeviceObject = Target device for the current irp
55 * ExecutionRoutine = Routine to be called when the device is available
56 * Context = Driver supplied context to be passed on to the above routine
57 * NOTE: Is the below implementation correct.
60 PCONTROLLER_QUEUE_ENTRY entry
;
61 IO_ALLOCATION_ACTION Result
;
63 ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL
);
66 ExAllocatePoolWithTag(NonPagedPool
, sizeof(CONTROLLER_QUEUE_ENTRY
),
70 entry
->DeviceObject
= DeviceObject
;
71 entry
->ExecutionRoutine
= ExecutionRoutine
;
72 entry
->Context
= Context
;
74 if (KeInsertDeviceQueue(&ControllerObject
->DeviceWaitQueue
,&entry
->Entry
))
78 Result
= ExecutionRoutine(DeviceObject
,DeviceObject
->CurrentIrp
,
80 if (Result
== DeallocateObject
)
82 IoFreeController(ControllerObject
);
92 IoCreateController(ULONG Size
)
94 * FUNCTION: Allocates memory and initializes a controller object
96 * Size = Size (in bytes) to be allocated for the controller extension
97 * RETURNS: A pointer to the created object
100 PCONTROLLER_OBJECT controller
;
102 ASSERT_IRQL(PASSIVE_LEVEL
);
105 ExAllocatePoolWithTag(NonPagedPool
, sizeof(CONTROLLER_OBJECT
),
107 if (controller
==NULL
)
112 controller
->ControllerExtension
=
113 ExAllocatePoolWithTag(NonPagedPool
, Size
, TAG_CONTROLLER_EXTENSION
);
114 if (controller
->ControllerExtension
==NULL
)
116 ExFreePool(controller
);
120 KeInitializeDeviceQueue(&controller
->DeviceWaitQueue
);
129 IoDeleteController(PCONTROLLER_OBJECT ControllerObject
)
131 * FUNCTION: Removes a given controller object from the system
133 * ControllerObject = Controller object to be released
136 ASSERT_IRQL(PASSIVE_LEVEL
);
138 ExFreePool(ControllerObject
->ControllerExtension
);
139 ExFreePool(ControllerObject
);
147 IoFreeController(PCONTROLLER_OBJECT ControllerObject
)
149 * FUNCTION: Releases a previously allocated controller object when a
150 * device has finished an I/O request
152 * ControllerObject = Controller object to be released
155 PKDEVICE_QUEUE_ENTRY QEntry
;
156 CONTROLLER_QUEUE_ENTRY
* Entry
;
157 IO_ALLOCATION_ACTION Result
;
161 QEntry
= KeRemoveDeviceQueue(&ControllerObject
->DeviceWaitQueue
);
162 Entry
= CONTAINING_RECORD(QEntry
,CONTROLLER_QUEUE_ENTRY
,Entry
);
167 Result
= Entry
->ExecutionRoutine(Entry
->DeviceObject
,
168 Entry
->DeviceObject
->CurrentIrp
,
172 } while (Result
== DeallocateObject
);