xref: /reactos/win32ss/drivers/videoprt/videoprt.h (revision 3121aee5)
1 /*
2  * VideoPort driver
3  *
4  * Copyright (C) 2002, 2003, 2004 ReactOS Team
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 
22 #ifndef VIDEOPRT_H
23 #define VIDEOPRT_H
24 
25 #include <ntifs.h>
26 
27 #define __BROKEN__
28 #include <miniport.h>
29 #include <video.h>
30 #include <ntagp.h>
31 #include <dderror.h>
32 #include <windef.h>
33 #include <wdmguid.h>
34 
35 /* PSEH for SEH Support */
36 #include <pseh/pseh2.h>
37 
38 #define TAG_VIDEO_PORT          'PDIV'
39 #define TAG_VIDEO_PORT_BUFFER   '\0mpV'
40 #define TAG_REQUEST_PACKET      'qRpV'
41 
42 #define GUID_STRING_LENGTH (38 * sizeof(WCHAR))
43 
44 typedef struct _VIDEO_PORT_ADDRESS_MAPPING
45 {
46    LIST_ENTRY List;
47    PVOID MappedAddress;
48    ULONG NumberOfUchars;
49    PHYSICAL_ADDRESS IoAddress;
50    ULONG SystemIoBusNumber;
51    UINT MappingCount;
52 } VIDEO_PORT_ADDRESS_MAPPING, *PVIDEO_PORT_ADDRESS_MAPPING;
53 
54 struct _VIDEO_PORT_AGP_VIRTUAL_MAPPING;
55 
56 typedef struct _VIDEO_PORT_AGP_MAPPING
57 {
58    ULONG NumberOfPages;
59    PVOID MapHandle;
60    PHYSICAL_ADDRESS PhysicalAddress;
61 } VIDEO_PORT_AGP_MAPPING, *PVIDEO_PORT_AGP_MAPPING;
62 
63 typedef struct _VIDEO_PORT_AGP_VIRTUAL_MAPPING
64 {
65    PVIDEO_PORT_AGP_MAPPING AgpMapping;
66    HANDLE ProcessHandle;
67    PVOID MappedAddress;
68 } VIDEO_PORT_AGP_VIRTUAL_MAPPING, *PVIDEO_PORT_AGP_VIRTUAL_MAPPING;
69 
70 typedef struct _VIDEO_PORT_DRIVER_EXTENSION
71 {
72    VIDEO_HW_INITIALIZATION_DATA InitializationData;
73    PVOID HwContext;
74    UNICODE_STRING RegistryPath;
75 } VIDEO_PORT_DRIVER_EXTENSION, *PVIDEO_PORT_DRIVER_EXTENSION;
76 
77 typedef struct _VIDEO_PORT_COMMON_EXTENSION
78 {
79     BOOLEAN Fdo;
80 } VIDEO_PORT_COMMON_EXTENSION, *PVIDEO_PORT_COMMON_EXTENSION;
81 
82 typedef struct _VIDEO_PORT_DEVICE_EXTENSTION
83 {
84    VIDEO_PORT_COMMON_EXTENSION Common;
85    ULONG DeviceNumber;
86    PDRIVER_OBJECT DriverObject;
87    PDEVICE_OBJECT PhysicalDeviceObject;
88    PDEVICE_OBJECT FunctionalDeviceObject;
89    PDEVICE_OBJECT NextDeviceObject;
90    UNICODE_STRING RegistryPath;
91    UNICODE_STRING NewRegistryPath;
92    PKINTERRUPT InterruptObject;
93    KSPIN_LOCK InterruptSpinLock;
94    PCM_RESOURCE_LIST AllocatedResources;
95    ULONG InterruptVector;
96    ULONG InterruptLevel;
97    BOOLEAN InterruptShared;
98    INTERFACE_TYPE AdapterInterfaceType;
99    ULONG SystemIoBusNumber;
100    ULONG SystemIoSlotNumber;
101    LIST_ENTRY AddressMappingListHead;
102    KDPC DpcObject;
103    VIDEO_PORT_DRIVER_EXTENSION *DriverExtension;
104    ULONG DeviceOpened;
105    AGP_BUS_INTERFACE_STANDARD AgpInterface;
106    KMUTEX DeviceLock;
107    LIST_ENTRY DmaAdapterList, ChildDeviceList;
108    LIST_ENTRY HwResetListEntry;
109    ULONG SessionId;
110    USHORT AdapterNumber;
111    USHORT DisplayNumber;
112    ULONG NumberOfSecondaryDisplays;
113    CHAR POINTER_ALIGNMENT MiniPortDeviceExtension[1];
114 } VIDEO_PORT_DEVICE_EXTENSION, *PVIDEO_PORT_DEVICE_EXTENSION;
115 
116 typedef struct _VIDEO_PORT_CHILD_EXTENSION
117 {
118     VIDEO_PORT_COMMON_EXTENSION Common;
119 
120     ULONG ChildId;
121     VIDEO_CHILD_TYPE ChildType;
122     UCHAR ChildDescriptor[256];
123 
124     BOOLEAN EdidValid;
125 
126     PDRIVER_OBJECT DriverObject;
127     PDEVICE_OBJECT PhysicalDeviceObject;
128 
129     LIST_ENTRY ListEntry;
130 
131     CHAR ChildDeviceExtension[1];
132 } VIDEO_PORT_CHILD_EXTENSION, *PVIDEO_PORT_CHILD_EXTENSION;
133 
134 #define VIDEO_PORT_GET_CHILD_EXTENSION(MiniportExtension) \
135    CONTAINING_RECORD( \
136        MiniportExtension, \
137        VIDEO_PORT_CHILD_EXTENSION, \
138        ChildDeviceExtension)
139 
140 #define VIDEO_PORT_GET_DEVICE_EXTENSION(MiniportExtension) \
141    CONTAINING_RECORD( \
142       MiniportExtension, \
143       VIDEO_PORT_DEVICE_EXTENSION, \
144       MiniPortDeviceExtension)
145 
146 typedef struct _VIDEO_PORT_EVENT
147 {
148     ENG_EVENT;
149 } VIDEO_PORT_EVENT, *PVIDEO_PORT_EVENT;
150 
151 /* agp.c */
152 
153 NTSTATUS
154 IopInitiatePnpIrp(
155   PDEVICE_OBJECT DeviceObject,
156   PIO_STATUS_BLOCK IoStatusBlock,
157   UCHAR MinorFunction,
158   PIO_STACK_LOCATION Stack OPTIONAL);
159 
160 NTSTATUS NTAPI
161 IntAgpGetInterface(
162    IN PVOID HwDeviceExtension,
163    IN OUT PINTERFACE Interface);
164 
165 /* child.c */
166 
167 NTSTATUS NTAPI
168 IntVideoPortDispatchPdoPnp(
169    IN PDEVICE_OBJECT DeviceObject,
170    IN PIRP Irp);
171 
172 /* dispatch.c */
173 
174 NTSTATUS NTAPI
175 IntVideoPortAddDevice(
176    IN PDRIVER_OBJECT DriverObject,
177    IN PDEVICE_OBJECT PhysicalDeviceObject);
178 
179 NTSTATUS NTAPI
180 IntVideoPortDispatchOpen(
181    IN PDEVICE_OBJECT DeviceObject,
182    IN PIRP Irp);
183 
184 NTSTATUS NTAPI
185 IntVideoPortDispatchClose(
186    IN PDEVICE_OBJECT DeviceObject,
187    IN PIRP Irp);
188 
189 NTSTATUS NTAPI
190 IntVideoPortDispatchCleanup(
191    IN PDEVICE_OBJECT DeviceObject,
192    IN PIRP Irp);
193 
194 NTSTATUS NTAPI
195 IntVideoPortDispatchDeviceControl(
196    IN PDEVICE_OBJECT DeviceObject,
197    IN PIRP Irp);
198 
199 NTSTATUS NTAPI
200 IntVideoPortDispatchPnp(
201    IN PDEVICE_OBJECT DeviceObject,
202    IN PIRP Irp);
203 
204 NTSTATUS NTAPI
205 IntVideoPortDispatchPower(
206    IN PDEVICE_OBJECT DeviceObject,
207    IN PIRP Irp);
208 
209 NTSTATUS NTAPI
210 IntVideoPortDispatchSystemControl(
211    IN PDEVICE_OBJECT DeviceObject,
212    IN PIRP Irp);
213 
214 VOID NTAPI
215 IntVideoPortUnload(PDRIVER_OBJECT DriverObject);
216 
217 /* timer.c */
218 
219 BOOLEAN NTAPI
220 IntVideoPortSetupTimer(
221    IN PDEVICE_OBJECT DeviceObject,
222    IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension);
223 
224 /* interrupt.c */
225 
226 BOOLEAN NTAPI
227 IntVideoPortSetupInterrupt(
228    IN PDEVICE_OBJECT DeviceObject,
229    IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension,
230    IN PVIDEO_PORT_CONFIG_INFO ConfigInfo);
231 
232 /* resource.c */
233 
234 NTSTATUS NTAPI
235 IntVideoPortFilterResourceRequirements(
236    IN PDEVICE_OBJECT DeviceObject,
237    IN PIO_STACK_LOCATION IrpStack,
238    IN PIRP Irp);
239 
240 VOID
241 IntVideoPortReleaseResources(
242     _In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension);
243 
244 NTSTATUS NTAPI
245 IntVideoPortMapPhysicalMemory(
246    IN HANDLE Process,
247    IN PHYSICAL_ADDRESS PhysicalAddress,
248    IN ULONG SizeInBytes,
249    IN ULONG Protect,
250    IN OUT PVOID *VirtualAddress  OPTIONAL);
251 
252 /* videoprt.c */
253 
254 extern PKPROCESS CsrProcess;
255 extern ULONG VideoPortDeviceNumber;
256 extern BOOLEAN VideoPortUseNewKey;
257 extern KMUTEX VideoPortInt10Mutex;
258 extern KSPIN_LOCK HwResetAdaptersLock;
259 extern LIST_ENTRY HwResetAdaptersList;
260 
261 VOID FASTCALL
262 IntAttachToCSRSS(PKPROCESS *CallingProcess, PKAPC_STATE ApcState);
263 
264 VOID FASTCALL
265 IntDetachFromCSRSS(PKPROCESS *CallingProcess, PKAPC_STATE ApcState);
266 
267 NTSTATUS NTAPI
268 IntVideoPortCreateAdapterDeviceObject(
269    _In_ PDRIVER_OBJECT DriverObject,
270    _In_ PVIDEO_PORT_DRIVER_EXTENSION DriverExtension,
271    _In_opt_ PDEVICE_OBJECT PhysicalDeviceObject,
272    _In_ USHORT AdapterNumber,
273    _In_ USHORT DisplayNumber,
274    _Out_opt_ PDEVICE_OBJECT *DeviceObject);
275 
276 NTSTATUS NTAPI
277 IntVideoPortFindAdapter(
278    IN PDRIVER_OBJECT DriverObject,
279    IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension,
280    IN PDEVICE_OBJECT DeviceObject);
281 
282 PVOID NTAPI
283 IntVideoPortGetProcAddress(
284    IN PVOID HwDeviceExtension,
285    IN PUCHAR FunctionName);
286 
287 NTSTATUS NTAPI
288 IntVideoPortEnumerateChildren(
289     IN PDEVICE_OBJECT DeviceObject,
290     IN PIRP Irp);
291 
292 /* int10.c */
293 
294 NTSTATUS
295 NTAPI
296 IntInitializeVideoAddressSpace(VOID);
297 
298 VP_STATUS NTAPI
299 IntInt10AllocateBuffer(
300    IN PVOID Context,
301    OUT PUSHORT Seg,
302    OUT PUSHORT Off,
303    IN OUT PULONG Length);
304 
305 VP_STATUS NTAPI
306 IntInt10FreeBuffer(
307    IN PVOID Context,
308    IN USHORT Seg,
309    IN USHORT Off);
310 
311 VP_STATUS NTAPI
312 IntInt10ReadMemory(
313    IN PVOID Context,
314    IN USHORT Seg,
315    IN USHORT Off,
316    OUT PVOID Buffer,
317    IN ULONG Length);
318 
319 VP_STATUS NTAPI
320 IntInt10WriteMemory(
321    IN PVOID Context,
322    IN USHORT Seg,
323    IN USHORT Off,
324    IN PVOID Buffer,
325    IN ULONG Length);
326 
327 VP_STATUS NTAPI
328 IntInt10CallBios(
329    IN PVOID Context,
330    IN OUT PINT10_BIOS_ARGUMENTS BiosArguments);
331 
332 /* registry.c */
333 
334 NTSTATUS
335 NTAPI
336 IntCopyRegistryKey(
337     _In_ HANDLE SourceKeyHandle,
338     _In_ HANDLE DestKeyHandle);
339 
340 NTSTATUS
341 NTAPI
342 IntCopyRegistryValue(
343     HANDLE SourceKeyHandle,
344     HANDLE DestKeyHandle,
345     PWSTR ValueName);
346 
347 NTSTATUS
348 NTAPI
349 IntSetupDeviceSettingsKey(
350     PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension);
351 
352 NTSTATUS
353 NTAPI
354 IntCreateNewRegistryPath(
355     PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension);
356 
357 NTSTATUS
358 NTAPI
359 IntCreateRegistryPath(
360     IN PCUNICODE_STRING DriverRegistryPath,
361     IN ULONG DeviceNumber,
362     OUT PUNICODE_STRING DeviceRegistryPath);
363 
364 
365 #endif /* VIDEOPRT_H */
366