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
|
/*++
Copyright (c) Microsoft Corporation
Module Name:
purge.c
Abstract:
This module contains the code that is very specific to purge
operations in the serial driver
Environment:
Kernel mode
--*/
#include "precomp.h"
#if defined(EVENT_TRACING)
#include "purge.tmh"
#endif
VOID
SerialStartPurge(
IN PSERIAL_DEVICE_EXTENSION Extension
)
/*++
Routine Description:
Depending on the mask in the current request, purge the interrupt
buffer, the read queue, or the write queue, or all of the above.
Arguments:
Extension - Pointer to the device extension.
Return Value:
Will return STATUS_SUCCESS always. This is reasonable
since the DPC completion code that calls this routine doesn't
care and the purge request always goes through to completion
once it's started.
--*/
{
WDFREQUEST NewRequest;
PREQUEST_CONTEXT reqContext;
do {
ULONG Mask;
reqContext = SerialGetRequestContext(Extension->CurrentPurgeRequest);
Mask = *((ULONG *) (reqContext->SystemBuffer));
if (Mask & SERIAL_PURGE_TXABORT) {
SerialFlushRequests(
Extension->WriteQueue,
&Extension->CurrentWriteRequest
);
SerialFlushRequests(
Extension->WriteQueue,
&Extension->CurrentXoffRequest
);
}
if (Mask & SERIAL_PURGE_RXABORT) {
SerialFlushRequests(
Extension->ReadQueue,
&Extension->CurrentReadRequest
);
}
if (Mask & SERIAL_PURGE_RXCLEAR) {
//
// Clean out the interrupt buffer.
//
// Note that we do this under protection of the
// the drivers control lock so that we don't hose
// the pointers if there is currently a read that
// is reading out of the buffer.
//
WdfInterruptSynchronize(
Extension->WdfInterrupt,
SerialPurgeInterruptBuff,
Extension
);
}
reqContext->Status = STATUS_SUCCESS;
reqContext->Information = 0;
SerialGetNextRequest(
&Extension->CurrentPurgeRequest,
Extension->PurgeQueue,
&NewRequest,
TRUE,
Extension
);
} while (NewRequest);
return;
}
BOOLEAN
SerialPurgeInterruptBuff(
IN WDFINTERRUPT Interrupt,
IN PVOID Context
)
/*++
Routine Description:
This routine simply resets the interrupt (typeahead) buffer.
NOTE: This routine is being called from WdfInterruptSynchronize.
Arguments:
Context - Really a pointer to the device extension.
Return Value:
Always false.
--*/
{
PSERIAL_DEVICE_EXTENSION Extension = Context;
UNREFERENCED_PARAMETER(Interrupt);
//
// The typeahead buffer is by definition empty if there
// currently is a read owned by the isr.
//
if (Extension->ReadBufferBase == Extension->InterruptReadBuffer) {
Extension->CurrentCharSlot = Extension->InterruptReadBuffer;
Extension->FirstReadableChar = Extension->InterruptReadBuffer;
Extension->LastCharSlot = Extension->InterruptReadBuffer +
(Extension->BufferSize - 1);
Extension->CharsInInterruptBuffer = 0;
SerialHandleReducedIntBuffer(Extension);
}
return FALSE;
}
|