1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7     FxDmaTransactionCallbacks.h
8 
9 Abstract:
10 
11     This module implements the FxDmaTransaction object callbacks
12 
13 Environment:
14 
15     kernel mode only
16 
17 Revision History:
18 
19 --*/
20 
21 #ifndef _FXDMATRANSACTIONCALLBACKS_H
22 #define _FXDMATRANSACTIONCALLBACKS_H
23 
24 //
25 // FxDmaTransactionProgramDma or FxDmaTransactionReserveDma callback delegate
26 // These are mutually exclusive callbacks and are packed together in
27 // the callback structure (C++ won't allow two classes with constructors
28 // to be together in a union, so the containing class can't do the
29 // packing)
30 //
31 class FxDmaTransactionProgramOrReserveDma : public FxCallback {
32 
33 public:
34     union {
35         PFN_WDF_PROGRAM_DMA  ProgramDma;
36         PFN_WDF_RESERVE_DMA  ReserveDma;
37     } Method;
38 
39     FxDmaTransactionProgramOrReserveDma(
40         VOID
41         ) :
42         FxCallback()
43     {
44         Method.ProgramDma = NULL;
45     }
46 
47     BOOLEAN
48     InvokeProgramDma(
49         __in WDFDMATRANSACTION     Transaction,
50         __in WDFDEVICE             Device,
51         __in PVOID                 Context,
52         __in WDF_DMA_DIRECTION     Direction,
53         __in PSCATTER_GATHER_LIST  SgList
54         )
55     {
56         if (Method.ProgramDma) {
57             BOOLEAN cc;
58 
59             CallbackStart();
60             cc = Method.ProgramDma( Transaction,
61                                     Device,
62                                     Context,
63                                     Direction,
64                                     SgList );
65             CallbackEnd();
66 
67             return cc;
68         }
69         else {
70             return FALSE;
71         }
72     }
73 
74     VOID
75     InvokeReserveDma(
76         __in WDFDMATRANSACTION     Transaction,
77         __in PVOID                 Context
78         )
79     {
80         if (Method.ReserveDma) {
81             CallbackStart();
82             Method.ReserveDma( Transaction, Context );
83             CallbackEnd();
84         }
85     }
86 
87     VOID
88     Clear(
89         VOID
90         )
91     {
92         Method.ProgramDma = NULL;
93     }
94 };
95 
96 //
97 // FxDmaTransactionConfigureChannel callback delegate
98 //
99 
100 class FxDmaTransactionConfigureChannel : public FxCallback {
101 
102 public:
103     PFN_WDF_DMA_TRANSACTION_CONFIGURE_DMA_CHANNEL  Method;
104 
105     FxDmaTransactionConfigureChannel(
106         VOID
107         ) :
108         FxCallback()
109     {
110         Method = NULL;
111     }
112 
113     _Must_inspect_result_
114     BOOLEAN
115     Invoke(
116         __in     WDFDMATRANSACTION DmaTransaction,
117         __in     WDFDEVICE         Device,
118         __in     PVOID             Context,
119         __in_opt PMDL              Mdl,
120         __in     size_t            Offset,
121         __in     size_t            Length
122         )
123     {
124         BOOLEAN b = TRUE;
125         if (Method) {
126             CallbackStart();
127             b = Method( DmaTransaction, Device, Context, Mdl, Offset, Length );
128             CallbackEnd();
129         }
130         return b;
131     }
132 };
133 
134 //
135 // FxDmaTransactionTransferComplete callback delegate
136 //
137 
138 class FxDmaTransactionTransferComplete : public FxCallback {
139 
140 public:
141     PFN_WDF_DMA_TRANSACTION_DMA_TRANSFER_COMPLETE  Method;
142 
143     FxDmaTransactionTransferComplete(
144         VOID
145         ) :
146         FxCallback()
147     {
148         Method = NULL;
149     }
150 
151     VOID
152     Invoke(
153         __in WDFDMATRANSACTION Transaction,
154         __in WDFDEVICE Device,
155         __in WDFCONTEXT Context,
156         __in WDF_DMA_DIRECTION Direction,
157         __in DMA_COMPLETION_STATUS Status
158         )
159     {
160         if (Method) {
161             CallbackStart();
162             Method( Transaction, Device, Context, Direction, Status );
163             CallbackEnd();
164         }
165     }
166 };
167 
168 #endif // _FXDMATRANSACTIONCALLBACKS_H
169