ReactOS 0.4.15-dev-7924-g5949c20
child.c
Go to the documentation of this file.
1/*
2 * VideoPort driver
3 *
4 * Copyright (C) 2012 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#include "videoprt.h"
23#include <stdio.h>
24
25#define NDEBUG
26#include <debug.h>
27
28/* PRIVATE FUNCTIONS **********************************************************/
29
33 IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension,
35{
36 USHORT Manufacturer, Model;
37
38 /* This must be valid to call this function */
39 ASSERT(ChildExtension->EdidValid);
40
41 /* 3 letters 5-bit ANSI manufacturer code (big endian) */
42 /* Letters encoded as A=1 to Z=26 */
43 Manufacturer = ((USHORT)ChildExtension->ChildDescriptor[8] << 8) +
44 (USHORT)ChildExtension->ChildDescriptor[9];
45
46 /* Model number (16-bit little endian) */
47 Model = ((USHORT)ChildExtension->ChildDescriptor[11] << 8) +
48 (USHORT)ChildExtension->ChildDescriptor[10];
49
50 /* Convert the Monitor ID to a readable form */
52 L"%C%C%C%04hx",
53 (WCHAR)((Manufacturer >> 10 & 0x001F) + 'A' - 1),
54 (WCHAR)((Manufacturer >> 5 & 0x001F) + 'A' - 1),
55 (WCHAR)((Manufacturer & 0x001F) + 'A' - 1),
56 Model);
57
58 /* And we're done */
59 return TRUE;
60}
61
66 IN UCHAR DescriptorID,
67 OUT PUCHAR* pDescriptorData)
68{
69 if (Descriptor[0] != 0 || Descriptor[1] != 0 || Descriptor[2] != 0)
70 return FALSE;
71 if (Descriptor[3] != DescriptorID)
72 return FALSE;
73
74 *pDescriptorData = Descriptor + 4;
75 return TRUE;
76}
77
81 IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension,
82 IN UCHAR DescriptorID,
83 OUT PUCHAR* pDescriptorData)
84{
85 if (!ChildExtension->EdidValid)
86 return FALSE;
87
88 if (IntVideoPortSearchDescriptor(ChildExtension->ChildDescriptor + 0x36, DescriptorID, pDescriptorData))
89 return TRUE;
90 if (IntVideoPortSearchDescriptor(ChildExtension->ChildDescriptor + 0x48, DescriptorID, pDescriptorData))
91 return TRUE;
92 if (IntVideoPortSearchDescriptor(ChildExtension->ChildDescriptor + 0x5A, DescriptorID, pDescriptorData))
93 return TRUE;
94 if (IntVideoPortSearchDescriptor(ChildExtension->ChildDescriptor + 0x6C, DescriptorID, pDescriptorData))
95 return TRUE;
96
97 /* FIXME: search in extension? */
98 return FALSE;
99}
100
102NTAPI
104 IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension,
105 OUT PCHAR* pMonitorDescription)
106{
107 PUCHAR MonitorDescription;
108
109 if (!IntVideoPortSearchDescriptors(ChildExtension, 0xFC, &MonitorDescription))
110 return FALSE;
111
112 *pMonitorDescription = (PCHAR)MonitorDescription;
113 return TRUE;
114}
115
118 IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension,
119 IN PIRP Irp,
121{
122 PWCHAR Buffer = NULL, StaticBuffer;
123 UNICODE_STRING UnicodeStr;
124
125 switch (IrpSp->Parameters.QueryId.IdType)
126 {
127 case BusQueryDeviceID:
128 switch (ChildExtension->ChildType)
129 {
130 case Monitor:
131 if (ChildExtension->EdidValid)
132 {
133 StaticBuffer = L"DISPLAY\\";
134 Buffer = ExAllocatePool(PagedPool, (wcslen(StaticBuffer) + 8) * sizeof(WCHAR));
135 if (!Buffer) return STATUS_NO_MEMORY;
136
137 /* Write the static portion */
138 RtlCopyMemory(Buffer, StaticBuffer, wcslen(StaticBuffer) * sizeof(WCHAR));
139
140 /* Add the dynamic portion */
141 IntVideoPortGetMonitorId(ChildExtension,
142 &Buffer[wcslen(StaticBuffer)]);
143 }
144 else
145 {
146 StaticBuffer = L"DISPLAY\\Default_Monitor";
147 Buffer = ExAllocatePool(PagedPool, (wcslen(StaticBuffer) + 1) * sizeof(WCHAR));
148 if (!Buffer) return STATUS_NO_MEMORY;
149
150 /* Copy the default id */
151 RtlCopyMemory(Buffer, StaticBuffer, (wcslen(StaticBuffer) + 1) * sizeof(WCHAR));
152 }
153 break;
154 default:
155 ASSERT(FALSE);
156 break;
157 }
158 break;
160 Buffer = ExAllocatePool(PagedPool, 5 * sizeof(WCHAR));
161 if (!Buffer) return STATUS_NO_MEMORY;
162
163 UnicodeStr.Buffer = Buffer;
164 UnicodeStr.Length = 0;
165 UnicodeStr.MaximumLength = 4 * sizeof(WCHAR);
166 RtlIntegerToUnicodeString(ChildExtension->ChildId, 16, &UnicodeStr);
167 break;
169 switch (ChildExtension->ChildType)
170 {
171 case Monitor:
172 if (ChildExtension->EdidValid)
173 {
174 StaticBuffer = L"MONITOR\\";
175 Buffer = ExAllocatePool(PagedPool, (wcslen(StaticBuffer) + 9) * sizeof(WCHAR));
176 if (!Buffer) return STATUS_NO_MEMORY;
177
178 /* Write the static portion */
179 RtlCopyMemory(Buffer, StaticBuffer, wcslen(StaticBuffer) * sizeof(WCHAR));
180
181 /* Add the dynamic portion */
182 IntVideoPortGetMonitorId(ChildExtension,
183 &Buffer[wcslen(StaticBuffer)]);
184
185 /* Add the second null termination char */
186 Buffer[wcslen(StaticBuffer) + 8] = UNICODE_NULL;
187 }
188 else
189 {
190 StaticBuffer = L"MONITOR\\Default_Monitor";
191 Buffer = ExAllocatePool(PagedPool, (wcslen(StaticBuffer) + 2) * sizeof(WCHAR));
192 if (!Buffer) return STATUS_NO_MEMORY;
193
194 /* Copy the default id */
195 RtlCopyMemory(Buffer, StaticBuffer, (wcslen(StaticBuffer) + 1) * sizeof(WCHAR));
196
197 /* Add the second null terminator */
198 Buffer[wcslen(StaticBuffer) + 1] = UNICODE_NULL;
199 }
200 break;
201 default:
202 ASSERT(FALSE);
203 break;
204 }
205 break;
207 switch (ChildExtension->ChildType)
208 {
209 case Monitor:
210 if (ChildExtension->EdidValid)
211 {
212 StaticBuffer = L"*PNP09FF";
213 Buffer = ExAllocatePool(PagedPool, (wcslen(StaticBuffer) + 2) * sizeof(WCHAR));
214 if (!Buffer) return STATUS_NO_MEMORY;
215
216 RtlCopyMemory(Buffer, StaticBuffer, (wcslen(StaticBuffer) + 1) * sizeof(WCHAR));
217
218 Buffer[wcslen(StaticBuffer)+1] = UNICODE_NULL;
219 }
220 else
221 {
222 /* No PNP ID for non-PnP monitors */
223 return Irp->IoStatus.Status;
224 }
225 break;
226 default:
227 ASSERT(FALSE);
228 break;
229 }
230 break;
231 default:
232 return Irp->IoStatus.Status;
233 }
234
235 INFO_(VIDEOPRT, "Reporting ID: %S\n", Buffer);
236 Irp->IoStatus.Information = (ULONG_PTR)Buffer;
237
238 return STATUS_SUCCESS;
239}
240
243 IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension,
244 IN PIRP Irp,
246{
247 ANSI_STRING StringA;
248 UNICODE_STRING StringU;
250
252 return Irp->IoStatus.Status;
253
254 switch (ChildExtension->ChildType)
255 {
256 case Monitor:
257 if (IntVideoPortGetMonitorDescription(ChildExtension,
258 &StringA.Buffer))
259 {
260 StringA.Buffer++; /* Skip reserved byte */
261 StringA.MaximumLength = 13;
262 for (StringA.Length = 0;
263 StringA.Length < StringA.MaximumLength && StringA.Buffer[StringA.Length] != '\n';
264 StringA.Length++)
265 ;
266 }
267 else
268 RtlInitAnsiString(&StringA, "Monitor");
269 break;
270
271 case VideoChip:
272 /* FIXME: No idea what we return here */
273 RtlInitAnsiString(&StringA, "Video chip");
274 break;
275
276 default: /* Other */
277 RtlInitAnsiString(&StringA, "Other device");
278 break;
279 }
280
281 Status = RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE);
282 if (!NT_SUCCESS(Status))
283 return Status;
284
285 INFO_(VIDEOPRT, "Reporting description: %S\n", StringU.Buffer);
286 Irp->IoStatus.Information = (ULONG_PTR)StringU.Buffer;
287
288 return STATUS_SUCCESS;
289}
290
293 IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension,
294 IN PIRP Irp,
296{
297 PDEVICE_RELATIONS DeviceRelations;
298
300 {
301 WARN_(VIDEOPRT, "Unsupported device relations type\n");
302 return Irp->IoStatus.Status;
303 }
304
305 DeviceRelations = ExAllocatePool(NonPagedPool, sizeof(DEVICE_RELATIONS));
306 if (!DeviceRelations) return STATUS_NO_MEMORY;
307
308 DeviceRelations->Count = 1;
309 DeviceRelations->Objects[0] = ChildExtension->PhysicalDeviceObject;
310
311 ObReferenceObject(DeviceRelations->Objects[0]);
312
313 Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
314
315 return STATUS_SUCCESS;
316}
317
320 IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension,
321 IN PIRP Irp,
323{
324 PDEVICE_CAPABILITIES DeviceCaps = IrpSp->Parameters.DeviceCapabilities.Capabilities;
325 ULONG i;
326
327 /* Set some values */
328 DeviceCaps->LockSupported = FALSE;
329 DeviceCaps->EjectSupported = FALSE;
330 DeviceCaps->DockDevice = FALSE;
331 DeviceCaps->UniqueID = FALSE;
332 DeviceCaps->RawDeviceOK = FALSE;
333 DeviceCaps->WakeFromD0 = FALSE;
334 DeviceCaps->WakeFromD1 = FALSE;
335 DeviceCaps->WakeFromD2 = FALSE;
336 DeviceCaps->WakeFromD3 = FALSE;
337 DeviceCaps->HardwareDisabled = FALSE;
338 DeviceCaps->NoDisplayInUI = FALSE;
339
340 /* Address and UI number are set by default */
341
342 DeviceCaps->DeviceState[PowerSystemWorking] = PowerDeviceD0;
343 for (i = 1; i < POWER_SYSTEM_MAXIMUM; i++)
344 {
345 DeviceCaps->DeviceState[i] = PowerDeviceD3;
346 }
347
348 DeviceCaps->SystemWake = PowerSystemUnspecified;
349 DeviceCaps->DeviceWake = PowerDeviceUnspecified;
350
351 /* FIXME: Device power states */
352 DeviceCaps->DeviceD1 = FALSE;
353 DeviceCaps->DeviceD2 = FALSE;
354 DeviceCaps->D1Latency = 0;
355 DeviceCaps->D2Latency = 0;
356 DeviceCaps->D3Latency = 0;
357
358 switch (ChildExtension->ChildType)
359 {
360 case VideoChip:
361 /* FIXME: Copy capabilities from parent */
362 ASSERT(FALSE);
363 break;
364
365 case NonPrimaryChip: /* Reserved */
366 ASSERT(FALSE);
367 break;
368
369 case Monitor:
370 DeviceCaps->SilentInstall = TRUE;
371 DeviceCaps->Removable = TRUE;
372 DeviceCaps->SurpriseRemovalOK = TRUE;
373 break;
374
375 default: /* Other */
376 DeviceCaps->SilentInstall = FALSE;
377 DeviceCaps->Removable = FALSE;
378 DeviceCaps->SurpriseRemovalOK = FALSE;
379 break;
380 }
381
382 return STATUS_SUCCESS;
383}
384
388 IN PIRP Irp)
389{
391 NTSTATUS Status = Irp->IoStatus.Status;
392
394
395 switch (IrpSp->MinorFunction)
396 {
399 /* Nothing to do */
401 break;
402
405 /* None (keep old status) */
406 break;
407
408 case IRP_MN_QUERY_ID:
409 /* Call our helper */
411 Irp,
412 IrpSp);
413 break;
414
416 /* Call our helper */
418 Irp,
419 IrpSp);
420 break;
421
425 break;
426
428 Irp->IoStatus.Status = STATUS_SUCCESS;
431 return STATUS_SUCCESS;
432
434 /* Call our helper */
436 Irp,
437 IrpSp);
438 break;
439
441 /* Call our helper */
443 Irp,
444 IrpSp);
445 break;
446
447 default:
448 break;
449 }
450
451 Irp->IoStatus.Status = Status;
452
454
455 return Status;
456}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IntVideoPortChildQueryId(IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: child.c:117
BOOLEAN NTAPI IntVideoPortGetMonitorId(IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension, IN OUT PWCHAR Buffer)
Definition: child.c:32
BOOLEAN NTAPI IntVideoPortSearchDescriptor(IN PUCHAR Descriptor, IN UCHAR DescriptorID, OUT PUCHAR *pDescriptorData)
Definition: child.c:64
NTSTATUS NTAPI IntVideoPortChildQueryRelations(IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: child.c:292
NTSTATUS NTAPI IntVideoPortChildQueryCapabilities(IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: child.c:319
NTSTATUS NTAPI IntVideoPortDispatchPdoPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: child.c:386
BOOLEAN NTAPI IntVideoPortSearchDescriptors(IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension, IN UCHAR DescriptorID, OUT PUCHAR *pDescriptorData)
Definition: child.c:80
NTSTATUS NTAPI IntVideoPortChildQueryText(IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension, IN PIRP Irp, IN PIO_STACK_LOCATION IrpSp)
Definition: child.c:242
BOOLEAN NTAPI IntVideoPortGetMonitorDescription(IN PVIDEO_PORT_CHILD_EXTENSION ChildExtension, OUT PCHAR *pMonitorDescription)
Definition: child.c:103
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf
Definition: precomp.h:40
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define ULONG_PTR
Definition: config.h:101
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define UNICODE_NULL
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IoCompleteRequest
Definition: irp.c:1240
#define POWER_SYSTEM_MAXIMUM
Definition: ntpoapi.h:45
@ PowerSystemUnspecified
Definition: ntpoapi.h:35
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceUnspecified
Definition: ntpoapi.h:48
@ PowerDeviceD0
Definition: ntpoapi.h:49
@ PowerDeviceD3
Definition: ntpoapi.h:52
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
@ Monitor
Definition: video.h:270
@ VideoChip
Definition: video.h:272
@ NonPrimaryChip
Definition: video.h:271
#define INFO_(ch,...)
Definition: debug.h:159
#define WARN_(ch,...)
Definition: debug.h:157
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT MaximumLength
Definition: env_spec_w32.h:377
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
union _IO_STACK_LOCATION::@1564 Parameters
struct _IO_STACK_LOCATION::@3978::@4003 QueryDeviceRelations
struct _IO_STACK_LOCATION::@3978::@4010 QueryDeviceText
struct _IO_STACK_LOCATION::@3978::@4005 DeviceCapabilities
struct _IO_STACK_LOCATION::@3978::@4009 QueryId
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
char * PCHAR
Definition: typedefs.h:51
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
@ TargetDeviceRelation
Definition: iotypes.h:2156
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_ID
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_DEVICE_TEXT
#define IRP_MN_QUERY_CAPABILITIES
#define IRP_MN_QUERY_RESOURCES
* PDEVICE_CAPABILITIES
Definition: iotypes.h:965
#define IRP_MN_STOP_DEVICE
@ DeviceTextDescription
Definition: iotypes.h:2945
@ BusQueryCompatibleIDs
Definition: iotypes.h:2938
@ BusQueryInstanceID
Definition: iotypes.h:2939
@ BusQueryDeviceID
Definition: iotypes.h:2936
@ BusQueryHardwareIDs
Definition: iotypes.h:2937
#define IRP_MN_QUERY_REMOVE_DEVICE
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180