1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/*++
Module Name:
Queue.c
Abstract:
This file contains the I/O queue definitions.
Environment:
Kernel-mode Driver Framework
--*/
#include "Driver.h"
#include "queue.tmh"
#ifdef ALLOC_PRAGMA
#pragma alloc_text (PAGE, HardwareRequestQueueInitialize)
#endif
NTSTATUS
HardwareRequestQueueInitialize(
_In_ WDFDEVICE Device
)
/*++
Routine Description:
The I/O dispatch callbacks for the frameworks device object
are configured in this function.
A single I/O Queue is configured for sequential request
processing, and a driver context memory allocation is created
to hold our structure QUEUE_CONTEXT.
Arguments:
Device - Handle to a framework device object.
Returns:
NTSTATUS
--*/
{
TRACE_FUNC_ENTRY(TRACE_QUEUE);
PAGED_CODE();
NTSTATUS status;
WDFQUEUE hardwareRequestQueue;
WDF_IO_QUEUE_CONFIG queueConfig;
PDEVICE_CONTEXT deviceContext;
deviceContext = DeviceGetContext(Device);
WDF_IO_QUEUE_CONFIG_INIT(
&queueConfig,
WdfIoQueueDispatchSequential);
queueConfig.EvtIoDeviceControl = EvtIoDeviceControl;
queueConfig.EvtIoStop = EvtIoStop;
// Create the hardware request queue.
status = WdfIoQueueCreate(Device,
&queueConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&hardwareRequestQueue);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_QUEUE, "WdfIoQueueCreate failed %!STATUS!", status);
goto Exit;
}
// Set this queue as the one to which UcmTcpciCx will forward its hardware requests.
UcmTcpciPortControllerSetHardwareRequestQueue(deviceContext->PortController, hardwareRequestQueue);
Exit:
TRACE_FUNC_EXIT(TRACE_QUEUE);
return status;
}
VOID
EvtIoDeviceControl(
_In_ WDFQUEUE Queue,
_In_ WDFREQUEST Request,
_In_ size_t OutputBufferLength,
_In_ size_t InputBufferLength,
_In_ ULONG IoControlCode
)
/*++
Routine Description:
This event is invoked when the framework receives IRP_MJ_DEVICE_CONTROL request.
Arguments:
Queue - Handle to the framework queue object that is associated with the
I/O request.
Request - Handle to a framework request object.
OutputBufferLength - Size of the output buffer in bytes
InputBufferLength - Size of the input buffer in bytes
IoControlCode - I/O control code.
--*/
{
TRACE_FUNC_ENTRY(TRACE_QUEUE);
WDFDEVICE device;
PDEVICE_CONTEXT deviceContext;
TraceEvents(TRACE_LEVEL_INFORMATION,
TRACE_QUEUE,
"Queue 0x%p, Request 0x%p OutputBufferLength %Iu InputBufferLength %Iu IoControlCode %!UCMTCPCI_PORT_CONTROLLER_IOCTL!",
Queue, Request, OutputBufferLength, InputBufferLength, IoControlCode);
device = WdfIoQueueGetDevice(Queue);
deviceContext = DeviceGetContext(device);
// Save the WDFREQUEST so we can complete it later.
deviceContext->IncomingRequest = Request;
// Check if we recognize the IOCTL.
// The helper functions perform the requested hardware read or write and complete the WDFREQUEST.
// Note: The driver would need to support some of the other IOCTLs from UcmTcpciCx if the
// capabilities indicate that they are supported.
switch (IoControlCode)
{
case IOCTL_UCMTCPCI_PORT_CONTROLLER_GET_STATUS:
PostponeToWorkitem(Request, device, deviceContext->I2CWorkItemGetStatus);
break;
case IOCTL_UCMTCPCI_PORT_CONTROLLER_GET_CONTROL:
PostponeToWorkitem(Request, device, deviceContext->I2CWorkItemGetControl);
break;
case IOCTL_UCMTCPCI_PORT_CONTROLLER_SET_CONTROL:
EvtSetControl(Request, device);
break;
case IOCTL_UCMTCPCI_PORT_CONTROLLER_SET_TRANSMIT:
EvtSetTransmit(Request, device);
break;
case IOCTL_UCMTCPCI_PORT_CONTROLLER_SET_TRANSMIT_BUFFER:
EvtSetTransmitBuffer(Request, device);
break;
case IOCTL_UCMTCPCI_PORT_CONTROLLER_SET_RECEIVE_DETECT:
EvtSetReceiveDetect(Request, device);
break;
case IOCTL_UCMTCPCI_PORT_CONTROLLER_SET_CONFIG_STANDARD_OUTPUT:
EvtSetConfigStandardOutput(Request, device);
break;
case IOCTL_UCMTCPCI_PORT_CONTROLLER_SET_COMMAND:
EvtSetCommand(Request, device);
break;
case IOCTL_UCMTCPCI_PORT_CONTROLLER_SET_MESSAGE_HEADER_INFO:
EvtSetMessageHeaderInfo(Request, device);
break;
default:
TraceEvents(TRACE_LEVEL_ERROR, TRACE_QUEUE,
"Received unexpected IoControlCode %lu", IoControlCode);
deviceContext->IncomingRequest = WDF_NO_HANDLE;
// If we don't recognize the IOCTL, we must complete the WDFREQUEST here.
WdfRequestComplete(Request, STATUS_NOT_SUPPORTED);
}
TRACE_FUNC_EXIT(TRACE_QUEUE);
}
VOID
EvtIoStop(
_In_ WDFQUEUE Queue,
_In_ WDFREQUEST Request,
_In_ ULONG ActionFlags
)
/*++
Routine Description:
This event is invoked for a power-managed queue before the device leaves the working state (D0).
Arguments:
Queue - Handle to the framework queue object that is associated with the
I/O request.
Request - Handle to a framework request object.
ActionFlags - A bitwise OR of one or more WDF_REQUEST_STOP_ACTION_FLAGS-typed flags
that identify the reason that the callback function is being called
and whether the request is cancelable.
--*/
{
TRACE_FUNC_ENTRY(TRACE_QUEUE);
UNREFERENCED_PARAMETER(ActionFlags);
UNREFERENCED_PARAMETER(Request);
WDFDEVICE device;
PDEVICE_CONTEXT deviceContext;
device = WdfIoQueueGetDevice(Queue);
deviceContext = DeviceGetContext(device);
// Attempt to cancel the I2C WDFREQUESTs.
if (deviceContext->I2CAsyncRequest != WDF_NO_HANDLE)
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_QUEUE,
"[WDFREQUEST: 0x%p] Attempting to cancel.", deviceContext->I2CAsyncRequest);
WdfRequestCancelSentRequest(deviceContext->I2CAsyncRequest);
}
TRACE_FUNC_EXIT(TRACE_QUEUE);
}
|