xref: /reactos/sdk/include/ddk/nt_vdd.h (revision d6eebaa4)
1 /*
2  * nt_vdd.h
3  *
4  * Windows NT Device Driver Kit
5  *
6  * This file is part of the ReactOS DDK package.
7  *
8  * Contributors:
9  *   Hermes Belusca-Maito (hermes.belusca@sfr.fr)
10  *
11  * THIS SOFTWARE IS NOT COPYRIGHTED
12  *
13  * This source code is offered for use in the public domain. You may
14  * use, modify or distribute it freely.
15  *
16  * This code is distributed in the hope that it will be useful but
17  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18  * DISCLAIMED. This includes but is not limited to warranties of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  */
22 
23 #pragma once
24 
25 #define _NT_VDD
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /* VDM Control */
32 
33 VOID
34 WINAPI
35 VDDSimulate16(VOID);
36 
37 VOID
38 WINAPI
39 VDDTerminateVDM(VOID);
40 
41 
42 /* VDD User Hooks */
43 
44 typedef VOID
45 (WINAPI *PFNVDD_UCREATE)(USHORT DosPDB);
46 
47 typedef VOID
48 (WINAPI *PFNVDD_UTERMINATE)(USHORT DosPDB);
49 
50 typedef VOID
51 (WINAPI *PFNVDD_UBLOCK)(VOID);
52 
53 typedef VOID
54 (WINAPI *PFNVDD_URESUME)(VOID);
55 
56 // NOTE: Kept there for WinDDK compatibility, but it is in any case unused.
57 #ifndef NO_NTVDD_COMPAT
58 typedef struct _VDD_USER_HANDLERS {
59   HANDLE hvdd;
60   PFNVDD_UCREATE ucr_handler;
61   PFNVDD_UTERMINATE uterm_handler;
62   PFNVDD_UBLOCK ublock_handler;
63   PFNVDD_URESUME uresume_handler;
64   struct _VDD_USER_HANDLERS* next;
65 } VDD_USER_HANDLERS, *PVDD_USER_HANDLERS;
66 #endif
67 
68 BOOL
69 WINAPI
70 VDDInstallUserHook(
71   _In_ HANDLE hVdd,
72   _In_ PFNVDD_UCREATE Ucr_Handler,
73   _In_ PFNVDD_UTERMINATE Uterm_Handler,
74   _In_ PFNVDD_UBLOCK Ublock_Handler,
75   _In_ PFNVDD_URESUME Uresume_Handler);
76 
77 BOOL
78 WINAPI
79 VDDDeInstallUserHook(
80   _In_ HANDLE hVdd);
81 
82 
83 /* IRQ services */
84 
85 WORD
86 WINAPI
87 VDDReserveIrqLine(
88   _In_ HANDLE hVdd,
89   _In_ WORD IrqLine);
90 
91 BOOL
92 WINAPI
93 VDDReleaseIrqLine(
94   _In_ HANDLE hVdd,
95   _In_ WORD IrqLine);
96 
97 
98 /* I/O Port services */
99 
100 typedef VOID
101 (WINAPI *PFNVDD_INB)(
102   WORD iport,
103   PBYTE data);
104 
105 typedef VOID
106 (WINAPI *PFNVDD_INW)(
107   WORD iport,
108   PWORD data);
109 
110 typedef VOID
111 (WINAPI *PFNVDD_INSB)(
112   WORD iport,
113   PBYTE data,
114   WORD count);
115 
116 typedef VOID
117 (WINAPI *PFNVDD_INSW)(
118   WORD iport,
119   PWORD data,
120   WORD count);
121 
122 typedef VOID
123 (WINAPI *PFNVDD_OUTB)(
124   WORD iport,
125   BYTE data);
126 
127 typedef VOID
128 (WINAPI *PFNVDD_OUTW)(
129   WORD iport,
130   WORD data);
131 
132 typedef VOID
133 (WINAPI *PFNVDD_OUTSB)(
134   WORD iport,
135   PBYTE data,
136   WORD count);
137 
138 typedef VOID
139 (WINAPI *PFNVDD_OUTSW)(
140   WORD iport,
141   PWORD data,
142   WORD count);
143 
144 typedef struct _VDD_IO_HANDLERS {
145   PFNVDD_INB inb_handler;
146   PFNVDD_INW inw_handler;
147   PFNVDD_INSB insb_handler;
148   PFNVDD_INSW insw_handler;
149   PFNVDD_OUTB outb_handler;
150   PFNVDD_OUTW outw_handler;
151   PFNVDD_OUTSB outsb_handler;
152   PFNVDD_OUTSW outsw_handler;
153 } VDD_IO_HANDLERS, *PVDD_IO_HANDLERS;
154 
155 typedef struct _VDD_IO_PORTRANGE {
156   WORD First;
157   WORD Last;
158 } VDD_IO_PORTRANGE, *PVDD_IO_PORTRANGE;
159 
160 BOOL
161 WINAPI
162 VDDInstallIOHook(
163   _In_ HANDLE hVdd,
164   _In_ WORD cPortRange,
165   _In_ PVDD_IO_PORTRANGE pPortRange,
166   _In_ PVDD_IO_HANDLERS IoHandlers);
167 
168 VOID
169 WINAPI
170 VDDDeInstallIOHook(
171   _In_ HANDLE hVdd,
172   _In_ WORD cPortRange,
173   _In_ PVDD_IO_PORTRANGE pPortRange);
174 
175 
176 /* DMA services */
177 
178 typedef struct _VDD_DMA_INFO {
179   WORD addr;
180   WORD count;
181   WORD page;
182   BYTE status;
183   BYTE mode;
184   BYTE mask;
185 } VDD_DMA_INFO, *PVDD_DMA_INFO;
186 
187 #define VDD_DMA_ADDR   0x01
188 #define VDD_DMA_COUNT  0x02
189 #define VDD_DMA_PAGE   0x04
190 #define VDD_DMA_STATUS 0x08
191 #define VDD_DMA_ALL    (VDD_DMA_ADDR | VDD_DMA_COUNT | VDD_DMA_PAGE | VDD_DMA_STATUS)
192 
193 DWORD
194 WINAPI
195 VDDRequestDMA(
196   _In_ HANDLE hVdd,
197   _In_ WORD iChannel,
198   _Inout_ PVOID Buffer,
199   _In_ DWORD length);
200 
201 BOOL
202 WINAPI
203 VDDQueryDMA(
204   _In_ HANDLE hVdd,
205   _In_ WORD iChannel,
206   _In_ PVDD_DMA_INFO pDmaInfo);
207 
208 BOOL
209 WINAPI
210 VDDSetDMA(
211   _In_ HANDLE hVdd,
212   _In_ WORD iChannel,
213   _In_ WORD fDMA,
214   _In_ PVDD_DMA_INFO pDmaInfo);
215 
216 
217 /* Memory services */
218 
219 typedef enum {
220   VDM_V86,
221   VDM_PM
222 } VDM_MODE;
223 
224 #ifndef MSW_PE
225 #define MSW_PE 0x0001
226 #endif
227 
228 #define getMODE() ((getMSW() & MSW_PE) ? VDM_PM : VDM_V86)
229 
230 typedef VOID
231 (WINAPI *PVDD_MEMORY_HANDLER)(
232   PVOID FaultAddress,
233   ULONG RWMode);
234 
235 PVOID
236 WINAPI
237 VdmMapFlat(
238   _In_ USHORT Segment,
239   _In_ ULONG Offset,
240   _In_ VDM_MODE Mode);
241 
242 #ifdef _X86_
243 
244 #define VdmFlushCache(sel, off, len, mode) TRUE
245 #define VdmUnmapFlat(sel, off, buf, mode) TRUE
246 
247 #else
248 
249 BOOL
250 WINAPI
251 VdmFlushCache(
252   _In_ USHORT Segment,
253   _In_ ULONG Offset,
254   _In_ ULONG Size,
255   _In_ VDM_MODE Mode);
256 
257 BOOL
258 WINAPI
259 VdmUnmapFlat(
260   _In_ USHORT Segment,
261   _In_ ULONG Offset,
262   _In_ PVOID Buffer,
263   _In_ VDM_MODE Mode);
264 
265 #endif
266 
267 BOOL
268 WINAPI
269 VDDInstallMemoryHook(
270   _In_ HANDLE hVdd,
271   _In_ PVOID pStart,
272   _In_ DWORD dwCount,
273   _In_ PVDD_MEMORY_HANDLER MemoryHandler);
274 
275 BOOL
276 WINAPI
277 VDDDeInstallMemoryHook(
278   _In_ HANDLE hVdd,
279   _In_ PVOID pStart,
280   _In_ DWORD dwCount);
281 
282 BOOL
283 WINAPI
284 VDDAllocMem(
285   _In_ HANDLE hVdd,
286   _In_ PVOID Address,
287   _In_ ULONG Size);
288 
289 BOOL
290 WINAPI
291 VDDFreeMem(
292   _In_ HANDLE hVdd,
293   _In_ PVOID Address,
294   _In_ ULONG Size);
295 
296 BOOL
297 WINAPI
298 VDDIncludeMem(
299   _In_ HANDLE hVdd,
300   _In_ PVOID Address,
301   _In_ ULONG Size);
302 
303 BOOL
304 WINAPI
305 VDDExcludeMem(
306   _In_ HANDLE hVdd,
307   _In_ PVOID Address,
308   _In_ ULONG Size);
309 
310 #ifdef __cplusplus
311 }
312 #endif
313 
314 /* EOF */
315