8ba5b984297eb1d034ba7bb8675e1847bdcc3244
[reactos.git] / reactos / drivers / net / ndis / ndis / io.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS library
4 * FILE: ndis/io.c
5 * PURPOSE: I/O related routines
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * REVISIONS:
8 * CSH 01/08-2000 Created
9 */
10 #include <ndissys.h>
11 #include <miniport.h>
12
13
14 VOID STDCALL HandleDeferredProcessing(
15 IN PKDPC Dpc,
16 IN PVOID DeferredContext,
17 IN PVOID SystemArgument1,
18 IN PVOID SystemArgument2)
19 /*
20 * FUNCTION: Deferred interrupt processing routine
21 * ARGUMENTS:
22 * Dpc = Pointer to DPC object
23 * DeferredContext = Pointer to context information (LOGICAL_ADAPTER)
24 * SystemArgument1 = Unused
25 * SystemArgument2 = Unused
26 */
27 {
28 BOOLEAN WasBusy;
29 PLOGICAL_ADAPTER Adapter = GET_LOGICAL_ADAPTER(DeferredContext);
30
31 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
32
33 KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
34 WasBusy = Adapter->MiniportBusy;
35 Adapter->MiniportBusy = TRUE;
36 KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
37
38 /* Call the deferred interrupt service handler for this adapter */
39 (*Adapter->Miniport->Chars.HandleInterruptHandler)(
40 Adapter->NdisMiniportBlock.MiniportAdapterContext);
41
42 KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
43 if ((!WasBusy) && (Adapter->WorkQueueHead)) {
44 KeInsertQueueDpc(&Adapter->MiniportDpc, NULL, NULL);
45 } else {
46 Adapter->MiniportBusy = WasBusy;
47 }
48 KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
49
50 NDIS_DbgPrint(MAX_TRACE, ("Leaving.\n"));
51 }
52
53
54 BOOLEAN STDCALL ServiceRoutine(
55 IN PKINTERRUPT Interrupt,
56 IN PVOID ServiceContext)
57 /*
58 * FUNCTION: Interrupt service routine
59 * ARGUMENTS:
60 * Interrupt = Pointer to interrupt object
61 * ServiceContext = Pointer to context information (LOGICAL_ADAPTER)
62 * RETURNS
63 * TRUE if a miniport controlled device generated the interrupt
64 */
65 {
66 BOOLEAN InterruptRecognized;
67 BOOLEAN QueueMiniportHandleInterrupt;
68 PLOGICAL_ADAPTER Adapter = GET_LOGICAL_ADAPTER(ServiceContext);
69
70 NDIS_DbgPrint(MAX_TRACE, ("Called. Adapter (0x%X)\n", Adapter));
71
72 (*Adapter->Miniport->Chars.ISRHandler)(&InterruptRecognized,
73 &QueueMiniportHandleInterrupt,
74 Adapter->NdisMiniportBlock.MiniportAdapterContext);
75
76 if (QueueMiniportHandleInterrupt) {
77 NDIS_DbgPrint(MAX_TRACE, ("Queueing DPC.\n"));
78 KeInsertQueueDpc(&Adapter->NdisMiniportBlock.Interrupt->InterruptDpc, NULL, NULL);
79 }
80
81 NDIS_DbgPrint(MAX_TRACE, ("Leaving.\n"));
82
83 return InterruptRecognized;
84 }
85
86
87 VOID
88 EXPORT
89 NdisCompleteDmaTransfer(
90 OUT PNDIS_STATUS Status,
91 IN PNDIS_HANDLE NdisDmaHandle,
92 IN PNDIS_BUFFER Buffer,
93 IN ULONG Offset,
94 IN ULONG Length,
95 IN BOOLEAN WriteToDevice)
96 {
97 UNIMPLEMENTED
98 }
99
100
101 VOID
102 EXPORT
103 NdisFlushBuffer(
104 IN PNDIS_BUFFER Buffer,
105 IN BOOLEAN WriteToDevice)
106 {
107 UNIMPLEMENTED
108 }
109
110
111 ULONG
112 EXPORT
113 NdisGetCacheFillSize(
114 VOID)
115 {
116 UNIMPLEMENTED
117
118 return 0;
119 }
120
121
122 VOID
123 EXPORT
124 NdisImmediateReadPortUchar(
125 IN NDIS_HANDLE WrapperConfigurationContext,
126 IN ULONG Port,
127 OUT PUCHAR Data)
128 {
129 UNIMPLEMENTED
130 }
131
132
133 VOID
134 EXPORT
135 NdisImmediateReadPortUlong(
136 IN NDIS_HANDLE WrapperConfigurationContext,
137 IN ULONG Port,
138 OUT PULONG Data)
139 {
140 UNIMPLEMENTED
141 }
142
143
144 VOID
145 EXPORT
146 NdisImmediateReadPortUshort(
147 IN NDIS_HANDLE WrapperConfigurationContext,
148 IN ULONG Port,
149 OUT PUSHORT Data)
150 {
151 UNIMPLEMENTED
152 }
153
154
155 VOID
156 EXPORT
157 NdisImmediateWritePortUchar(
158 IN NDIS_HANDLE WrapperConfigurationContext,
159 IN ULONG Port,
160 IN UCHAR Data)
161 {
162 UNIMPLEMENTED
163 }
164
165
166 VOID
167 EXPORT
168 NdisImmediateWritePortUlong(
169 IN NDIS_HANDLE WrapperConfigurationContext,
170 IN ULONG Port,
171 IN ULONG Data)
172 {
173 UNIMPLEMENTED
174 }
175
176
177 VOID
178 EXPORT
179 NdisImmediateWritePortUshort(
180 IN NDIS_HANDLE WrapperConfigurationContext,
181 IN ULONG Port,
182 IN USHORT Data)
183 {
184 UNIMPLEMENTED
185 }
186
187
188 NDIS_STATUS
189 EXPORT
190 NdisMAllocateMapRegisters(
191 IN NDIS_HANDLE MiniportAdapterHandle,
192 IN UINT DmaChannel,
193 IN BOOLEAN Dma32BitAddresses,
194 IN ULONG PhysicalMapRegistersNeeded,
195 IN ULONG MaximumPhysicalMapping)
196 {
197 UNIMPLEMENTED
198
199 return NDIS_STATUS_FAILURE;
200 }
201
202
203 VOID
204 EXPORT
205 NdisMCompleteDmaTransfer(
206 OUT PNDIS_STATUS Status,
207 IN PNDIS_HANDLE MiniportDmaHandle,
208 IN PNDIS_BUFFER Buffer,
209 IN ULONG Offset,
210 IN ULONG Length,
211 IN BOOLEAN WriteToDevice)
212 {
213 UNIMPLEMENTED
214 }
215
216
217 VOID
218 EXPORT
219 NdisMDeregisterDmaChannel(
220 IN PNDIS_HANDLE MiniportDmaHandle)
221 {
222 UNIMPLEMENTED
223 }
224
225
226 VOID
227 EXPORT
228 NdisMDeregisterInterrupt(
229 IN PNDIS_MINIPORT_INTERRUPT Interrupt)
230 /*
231 * FUNCTION: Releases an interrupt vector
232 * ARGUMENTS:
233 * Interrupt = Pointer to interrupt object
234 */
235 {
236 IoDisconnectInterrupt(Interrupt->InterruptObject);
237 }
238
239
240 VOID
241 EXPORT
242 NdisMDeregisterIoPortRange(
243 IN NDIS_HANDLE MiniportAdapterHandle,
244 IN UINT InitialPort,
245 IN UINT NumberOfPorts,
246 IN PVOID PortOffset)
247 /*
248 * FUNCTION: Releases a register mapping to I/O ports
249 * ARGUMENTS:
250 * MiniportAdapterHandle = Specifies handle input to MiniportInitialize
251 * InitialPort = Bus-relative base port address of a range to be mapped
252 * NumberOfPorts = Specifies number of ports to be mapped
253 * PortOffset = Pointer to mapped base port address
254 */
255 {
256 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
257
258 /* Thank you */
259 }
260
261
262 VOID
263 EXPORT
264 NdisMFreeMapRegisters(
265 IN NDIS_HANDLE MiniportAdapterHandle)
266 {
267 UNIMPLEMENTED
268 }
269
270
271 NDIS_STATUS
272 EXPORT
273 NdisMMapIoSpace(
274 OUT PVOID *VirtualAddress,
275 IN NDIS_HANDLE MiniportAdapterHandle,
276 IN NDIS_PHYSICAL_ADDRESS PhysicalAddress,
277 IN UINT Length)
278 {
279 UNIMPLEMENTED
280
281 return NDIS_STATUS_FAILURE;
282 }
283
284
285 ULONG
286 EXPORT
287 NdisMReadDmaCounter(
288 IN NDIS_HANDLE MiniportDmaHandle)
289 {
290 UNIMPLEMENTED
291
292 return 0;
293 }
294
295
296 NDIS_STATUS
297 EXPORT
298 NdisMRegisterDmaChannel(
299 OUT PNDIS_HANDLE MiniportDmaHandle,
300 IN NDIS_HANDLE MiniportAdapterHandle,
301 IN UINT DmaChannel,
302 IN BOOLEAN Dma32BitAddresses,
303 IN PNDIS_DMA_DESCRIPTION DmaDescription,
304 IN ULONG MaximumLength)
305 {
306 UNIMPLEMENTED
307
308 return NDIS_STATUS_FAILURE;
309 }
310
311
312 NDIS_STATUS
313 EXPORT
314 NdisMRegisterInterrupt(
315 OUT PNDIS_MINIPORT_INTERRUPT Interrupt,
316 IN NDIS_HANDLE MiniportAdapterHandle,
317 IN UINT InterruptVector,
318 IN UINT InterruptLevel,
319 IN BOOLEAN RequestIsr,
320 IN BOOLEAN SharedInterrupt,
321 IN NDIS_INTERRUPT_MODE InterruptMode)
322 /*
323 * FUNCTION: Claims access to an interrupt vector
324 * ARGUMENTS:
325 * Interrupt = Address of interrupt object to initialize
326 * MiniportAdapterHandle = Specifies handle input to MiniportInitialize
327 * InterruptVector = Specifies bus-relative vector to register
328 * InterruptLevel = Specifies bus-relative DIRQL vector for interrupt
329 * RequestIsr = TRUE if MiniportISR should always be called
330 * SharedInterrupt = TRUE if other devices may use the same interrupt
331 * InterruptMode = Specifies type of interrupt
332 * RETURNS:
333 * Status of operation
334 */
335 {
336 NTSTATUS Status;
337 ULONG MappedIRQ;
338 KIRQL DIrql;
339 KAFFINITY Affinity;
340 PLOGICAL_ADAPTER Adapter = GET_LOGICAL_ADAPTER(MiniportAdapterHandle);
341
342 NDIS_DbgPrint(MAX_TRACE, ("Called. InterruptVector (0x%X) InterruptLevel (0x%X) "
343 "SharedInterrupt (%d) InterruptMode (0x%X)\n",
344 InterruptVector, InterruptLevel, SharedInterrupt, InterruptMode));
345
346 RtlZeroMemory(Interrupt, sizeof(NDIS_MINIPORT_INTERRUPT));
347
348 KeInitializeSpinLock(&Interrupt->DpcCountLock);
349
350 KeInitializeDpc(&Interrupt->InterruptDpc,
351 HandleDeferredProcessing,
352 Adapter);
353
354 KeInitializeEvent(&Interrupt->DpcsCompletedEvent,
355 NotificationEvent,
356 FALSE);
357
358 Interrupt->SharedInterrupt = SharedInterrupt;
359
360 Adapter->NdisMiniportBlock.Interrupt = Interrupt;
361
362 MappedIRQ = HalGetInterruptVector(Internal, /* Adapter->AdapterType, */
363 0,
364 InterruptLevel,
365 InterruptVector,
366 &DIrql,
367 &Affinity);
368
369 NDIS_DbgPrint(MAX_TRACE, ("Connecting to interrupt vector (0x%X) Affinity (0x%X).\n", MappedIRQ, Affinity));
370
371 Status = IoConnectInterrupt(&Interrupt->InterruptObject,
372 ServiceRoutine,
373 Adapter,
374 &Interrupt->DpcCountLock,
375 MappedIRQ,
376 DIrql,
377 DIrql,
378 InterruptMode,
379 SharedInterrupt,
380 Affinity,
381 FALSE);
382
383 NDIS_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X).\n", Status));
384
385 if (NT_SUCCESS(Status))
386 return NDIS_STATUS_SUCCESS;
387
388 if (Status == STATUS_INSUFFICIENT_RESOURCES) {
389 /* FIXME: Log error */
390 return NDIS_STATUS_RESOURCE_CONFLICT;
391 }
392
393 return NDIS_STATUS_FAILURE;
394 }
395
396
397 NDIS_STATUS
398 EXPORT
399 NdisMRegisterIoPortRange(
400 OUT PVOID *PortOffset,
401 IN NDIS_HANDLE MiniportAdapterHandle,
402 IN UINT InitialPort,
403 IN UINT NumberOfPorts)
404 /*
405 * FUNCTION: Sets up driver access to device I/O ports
406 * ARGUMENTS:
407 * PortOffset = Address of buffer to place mapped base port address
408 * MiniportAdapterHandle = Specifies handle input to MiniportInitialize
409 * InitialPort = Bus-relative base port address of a range to be mapped
410 * NumberOfPorts = Specifies number of ports to be mapped
411 * RETURNS:
412 * Status of operation
413 */
414 {
415 #if 0
416 NTSTATUS Status;
417 BOOLEAN ConflictDetected;
418 PLOGICAL_ADAPTER Adapter = GET_LOGICAL_ADAPTER(MiniportAdapterHandle);
419 PMINIPORT_DRIVER Miniport = Adapter->Miniport;
420
421 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
422
423 /* Non-PnP hardware. NT5 function */
424 Status = IoReportResourceForDetection(Miniport->DriverObject,
425 NULL,
426 0,
427 NULL,
428 NULL,
429 0,
430 &ConflictDetected);
431 return NDIS_STATUS_FAILURE;
432 #else
433 NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
434
435 /* It's yours! */
436 *PortOffset = (PVOID)InitialPort;
437
438 return NDIS_STATUS_SUCCESS;
439 #endif
440 }
441
442
443 VOID
444 EXPORT
445 NdisMSetupDmaTransfer(
446 OUT PNDIS_STATUS Status,
447 IN PNDIS_HANDLE MiniportDmaHandle,
448 IN PNDIS_BUFFER Buffer,
449 IN ULONG Offset,
450 IN ULONG Length,
451 IN BOOLEAN WriteToDevice)
452 {
453 UNIMPLEMENTED
454 }
455
456
457 VOID
458 EXPORT
459 NdisMUnmapIoSpace(
460 IN NDIS_HANDLE MiniportAdapterHandle,
461 IN PVOID VirtualAddress,
462 IN UINT Length)
463 {
464 UNIMPLEMENTED
465 }
466
467 /* EOF */