Added version resource to dd and fs.
[reactos.git] / reactos / drivers / dd / vidport / vidport.c
1 /* $Id: vidport.c,v 1.9 1999/12/04 20:58:42 ea Exp $
2 *
3 * VideoPort driver
4 * Written by Rex Jolliff
5 */
6
7 #include <ddk/ntddk.h>
8 #include <ddk/ntddvid.h>
9 #include <internal/halio.h>
10
11 #include "vidport.h"
12
13 #define UNIMPLEMENTED do {DbgPrint("%s:%d: Function not implemented", __FILE__, __LINE__); for(;;);} while (0)
14
15 #define VERSION "0.0.0"
16
17 static VOID VidStartIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
18 static NTSTATUS VidDispatchOpenClose(IN PDEVICE_OBJECT pDO, IN PIRP Irp);
19 static NTSTATUS VidDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
20
21 // ------------------------------------------------------- Public Interface
22
23 // DriverEntry
24 //
25 // DESCRIPTION:
26 // This function initializes the driver.
27 //
28 // RUN LEVEL:
29 // PASSIVE_LEVEL
30 //
31 // ARGUMENTS:
32 // IN PDRIVER_OBJECT DriverObject System allocated Driver Object
33 // for this driver
34 // IN PUNICODE_STRING RegistryPath Name of registry driver service
35 // key
36 //
37 // RETURNS:
38 // NTSTATUS
39
40 STDCALL NTSTATUS
41 DriverEntry(IN PDRIVER_OBJECT DriverObject,
42 IN PUNICODE_STRING RegistryPath)
43 {
44
45 DbgPrint("VideoPort Driver %s\n", VERSION);
46
47 // Export other driver entry points...
48 DriverObject->DriverStartIo = VidStartIo;
49 DriverObject->MajorFunction[IRP_MJ_CREATE] = VidDispatchOpenClose;
50 DriverObject->MajorFunction[IRP_MJ_CLOSE] = VidDispatchOpenClose;
51 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VidDispatchDeviceControl;
52
53 return STATUS_SUCCESS;
54 }
55
56 ULONG
57 STDCALL
58 VideoPortCompareMemory(IN PVOID Source1,
59 IN PVOID Source2,
60 IN ULONG Length)
61 {
62 return RtlCompareMemory(Source1, Source2, Length);
63 }
64
65 VOID
66 STDCALL
67 VideoPortDebugPrint(IN ULONG DebugPrintLevel,
68 IN PCHAR DebugMessage, ...)
69 {
70 UNIMPLEMENTED;
71 }
72
73 VP_STATUS
74 STDCALL
75 VideoPortDisableInterrupt(IN PVOID HwDeviceExtension)
76 {
77 UNIMPLEMENTED;
78 }
79
80 VP_STATUS
81 STDCALL
82 VideoPortEnableInterrupt(IN PVOID HwDeviceExtension)
83 {
84 UNIMPLEMENTED;
85 }
86
87 VOID
88 STDCALL
89 VideoPortFreeDeviceBase(IN PVOID HwDeviceExtension,
90 IN PVOID MappedAddress)
91 {
92 UNIMPLEMENTED;
93 }
94
95 ULONG
96 STDCALL
97 VideoPortGetBusData(IN PVOID HwDeviceExtension,
98 IN BUS_DATA_TYPE BusDataType,
99 IN ULONG SlotNumber,
100 OUT PVOID Buffer,
101 IN ULONG Offset,
102 IN ULONG Length)
103 {
104 return HalGetBusDataByOffset(BusDataType,
105 0,
106 SlotNumber,
107 Buffer,
108 Offset,
109 Length);
110 }
111
112 UCHAR
113 STDCALL
114 VideoPortGetCurrentIrql(VOID)
115 {
116 return KeGetCurrentIrql();
117 }
118
119 PVOID
120 STDCALL
121 VideoPortGetDeviceBase(IN PVOID HwDeviceExtension,
122 IN PHYSICAL_ADDRESS IoAddress,
123 IN ULONG NumberOfUchars,
124 IN UCHAR InIoSpace)
125 {
126 if (InIoSpace)
127 {
128 return MmMapIoSpace(IoAddress, NumberOfUchars, FALSE);
129 }
130 else
131 {
132 UNIMPLEMENTED;
133 return NULL;
134 }
135 }
136
137 VP_STATUS
138 STDCALL
139 VideoPortGetDeviceData(IN PVOID HwDeviceExtension,
140 IN VIDEO_DEVICE_DATA_TYPE DeviceDataType,
141 IN PMINIPORT_QUERY_DEVICE_ROUTINE CallbackRoutine,
142 IN PVOID Context)
143 {
144 UNIMPLEMENTED;
145 }
146
147 VP_STATUS
148 STDCALL
149 VideoPortGetAccessRanges(IN PVOID HwDeviceExtension,
150 IN ULONG NumRequestedResources,
151 IN PIO_RESOURCE_DESCRIPTOR RequestedResources OPTIONAL,
152 IN ULONG NumAccessRanges,
153 IN PVIDEO_ACCESS_RANGE AccessRanges,
154 IN PVOID VendorId,
155 IN PVOID DeviceId,
156 IN PULONG Slot)
157 {
158 UNIMPLEMENTED;
159 }
160
161 VP_STATUS
162 STDCALL
163 VideoPortGetRegistryParameters(IN PVOID HwDeviceExtension,
164 IN PWSTR ParameterName,
165 IN UCHAR IsParameterFileName,
166 IN PMINIPORT_GET_REGISTRY_ROUTINE GetRegistryRoutine,
167 IN PVOID Context)
168 {
169 UNIMPLEMENTED;
170 }
171
172 ULONG
173 STDCALL
174 VideoPortInitialize(IN PVOID Context1,
175 IN PVOID Context2,
176 IN PVIDEO_HW_INITIALIZATION_DATA HwInitializationData,
177 IN PVOID HwContext)
178 {
179 UCHAR Again;
180 WCHAR UnicodeBuffer[18];
181 NTSTATUS Status;
182 ANSI_STRING AnsiName;
183 UNICODE_STRING UnicodeName;
184 PDRIVER_OBJECT MPDriverObject = (PDRIVER_OBJECT) Context1;
185 PDEVICE_OBJECT MPDeviceObject;
186 VIDEO_PORT_CONFIG_INFO ConfigInfo;
187 PVIDEOPORT_EXTENSION_DATA ExtensionData;
188
189 /* Build Dispatch table from passed data */
190 MPDriverObject->DriverStartIo = (PDRIVER_STARTIO) HwInitializationData->HwStartIO;
191
192 /* Create a unicode device name */
193 Again = FALSE;
194 do
195 {
196 /* FIXME: Need to add a device index for multiple adapters */
197 RtlInitAnsiString(&AnsiName, "\\Device\\Display");
198 UnicodeName.MaximumLength = 18 * sizeof(WCHAR);
199 UnicodeName.Buffer = UnicodeBuffer;
200 RtlAnsiStringToUnicodeString(&UnicodeName, &AnsiName, FALSE);
201
202 /* Create the device */
203 Status = IoCreateDevice(MPDriverObject,
204 HwInitializationData->HwDeviceExtensionSize +
205 sizeof(VIDEOPORT_EXTENSION_DATA),
206 &UnicodeName,
207 FILE_DEVICE_VIDEO,
208 0,
209 TRUE,
210 &MPDeviceObject);
211 if (!NT_SUCCESS(Status))
212 {
213 DbgPrint("IoCreateDevice call failed\n",0);
214 return Status;
215 }
216 ExtensionData =
217 (PVIDEOPORT_EXTENSION_DATA) MPDeviceObject->DeviceExtension;
218 ExtensionData->DeviceObject = MPDeviceObject;
219
220 /* Set the buffering strategy here... */
221 MPDeviceObject->Flags |= DO_BUFFERED_IO;
222
223 /* Call HwFindAdapter entry point */
224 /* FIXME: Need to figure out what string to pass as param 3 */
225 Status = HwInitializationData->HwFindAdapter(VPExtensionToMPExtension(ExtensionData),
226 Context2,
227 L"",
228 &ConfigInfo,
229 &Again);
230 if (!NT_SUCCESS(Status))
231 {
232 DbgPrint("HwFindAdapter call failed");
233 IoDeleteDevice(MPDeviceObject);
234
235 return Status;
236 }
237
238 /* FIXME: Allocate hardware resources for device */
239
240 /* Allocate interrupt for device */
241 if (HwInitializationData->HwInterrupt != NULL &&
242 !(ConfigInfo.BusInterruptLevel == 0 &&
243 ConfigInfo.BusInterruptVector == 0))
244 {
245 ExtensionData->IRQL = ConfigInfo.BusInterruptLevel;
246 ExtensionData->InterruptLevel =
247 HalGetInterruptVector(ConfigInfo.AdapterInterfaceType,
248 ConfigInfo.SystemIoBusNumber,
249 ConfigInfo.BusInterruptLevel,
250 ConfigInfo.BusInterruptVector,
251 &ExtensionData->IRQL,
252 &ExtensionData->Affinity);
253 KeInitializeSpinLock(&ExtensionData->InterruptSpinLock);
254 Status = IoConnectInterrupt(&ExtensionData->InterruptObject,
255 (PKSERVICE_ROUTINE)
256 HwInitializationData->HwInterrupt,
257 VPExtensionToMPExtension(ExtensionData),
258 &ExtensionData->InterruptSpinLock,
259 ExtensionData->InterruptLevel,
260 ExtensionData->IRQL,
261 ExtensionData->IRQL,
262 ConfigInfo.InterruptMode,
263 FALSE,
264 ExtensionData->Affinity,
265 FALSE);
266 if (!NT_SUCCESS(Status))
267 {
268 DbgPrint("IoConnectInterrupt failed\n");
269 IoDeleteDevice(MPDeviceObject);
270
271 return Status;
272 }
273
274 }
275 }
276 while (Again);
277
278 /* FIXME: initialize timer routine for MP Driver */
279 if (HwInitializationData->HwTimer != NULL)
280 {
281 Status = IoInitializeTimer(MPDeviceObject,
282 (PIO_TIMER_ROUTINE)
283 HwInitializationData->HwTimer,
284 VPExtensionToMPExtension(ExtensionData));
285 if (!NT_SUCCESS(Status))
286 {
287 DbgPrint("IoInitializeTimer failed\n");
288
289 if (HwInitializationData->HwInterrupt != NULL)
290 {
291 IoDisconnectInterrupt(&ExtensionData->InterruptObject);
292 }
293 IoDeleteDevice(MPDeviceObject);
294
295 return Status;
296 }
297 }
298
299 return STATUS_SUCCESS;
300 }
301
302 VP_STATUS
303 STDCALL
304 VideoPortInt10(IN PVOID HwDeviceExtension,
305 IN PVIDEO_X86_BIOS_ARGUMENTS BiosArguments)
306 {
307 UNIMPLEMENTED;
308 }
309
310 VOID
311 STDCALL
312 VideoPortLogError(IN PVOID HwDeviceExtension,
313 IN PVIDEO_REQUEST_PACKET Vrp OPTIONAL,
314 IN VP_STATUS ErrorCode,
315 IN ULONG UniqueId)
316 {
317 UNIMPLEMENTED;
318 }
319
320 VP_STATUS
321 STDCALL
322 VideoPortMapBankedMemory(IN PVOID HwDeviceExtension,
323 IN PHYSICAL_ADDRESS PhysicalAddress,
324 IN PULONG Length,
325 IN PULONG InIoSpace,
326 OUT PVOID *VirtualAddress,
327 IN ULONG BankLength,
328 IN UCHAR ReadWriteBank,
329 IN PBANKED_SECTION_ROUTINE BankRoutine,
330 IN PVOID Context)
331 {
332 UNIMPLEMENTED;
333 }
334
335 VP_STATUS
336 STDCALL
337 VideoPortMapMemory(IN PVOID HwDeviceExtension,
338 IN PHYSICAL_ADDRESS PhysicalAddress,
339 IN PULONG Length,
340 IN PULONG InIoSpace,
341 OUT PVOID *VirtualAddress)
342 {
343 if (*InIoSpace)
344 {
345 *VirtualAddress = MmMapIoSpace(PhysicalAddress, *Length, FALSE);
346
347 return *VirtualAddress != NULL ? STATUS_SUCCESS :
348 STATUS_INSUFFICIENT_RESOURCES;
349 }
350 else
351 {
352 UNIMPLEMENTED;
353 }
354
355 return STATUS_SUCCESS;
356 }
357
358 VOID
359 STDCALL
360 VideoPortMoveMemory(OUT PVOID Destination,
361 IN PVOID Source,
362 IN ULONG Length)
363 {
364 RtlMoveMemory(Destination, Source, Length);
365 }
366
367 UCHAR
368 STDCALL
369 VideoPortReadPortUchar(IN PUCHAR Port)
370 {
371 return READ_PORT_UCHAR(Port);
372 }
373
374 USHORT
375 STDCALL
376 VideoPortReadPortUshort(IN PUSHORT Port)
377 {
378 return READ_PORT_USHORT(Port);
379 }
380
381 ULONG
382 STDCALL
383 VideoPortReadPortUlong(IN PULONG Port)
384 {
385 return READ_PORT_ULONG(Port);
386 }
387
388 VOID
389 STDCALL
390 VideoPortReadPortBufferUchar(IN PUCHAR Port,
391 OUT PUCHAR Buffer,
392 IN ULONG Count)
393 {
394 READ_PORT_BUFFER_UCHAR(Port, Buffer, Count);
395 }
396
397 VOID
398 STDCALL
399 VideoPortReadPortBufferUshort(IN PUSHORT Port,
400 OUT PUSHORT Buffer,
401 IN ULONG Count)
402 {
403 READ_PORT_BUFFER_USHORT(Port, Buffer, Count);
404 }
405
406 VOID
407 STDCALL
408 VideoPortReadPortBufferUlong(IN PULONG Port,
409 OUT PULONG Buffer,
410 IN ULONG Count)
411 {
412 READ_PORT_BUFFER_ULONG(Port, Buffer, Count);
413 }
414
415 UCHAR
416 STDCALL
417 VideoPortReadRegisterUchar(IN PUCHAR Register)
418 {
419 return READ_REGISTER_UCHAR(Register);
420 }
421
422 USHORT
423 STDCALL
424 VideoPortReadRegisterUshort(IN PUSHORT Register)
425 {
426 return READ_REGISTER_USHORT(Register);
427 }
428
429 ULONG
430 STDCALL
431 VideoPortReadRegisterUlong(IN PULONG Register)
432 {
433 return READ_REGISTER_ULONG(Register);
434 }
435
436 VOID
437 STDCALL
438 VideoPortReadRegisterBufferUchar(IN PUCHAR Register,
439 OUT PUCHAR Buffer,
440 IN ULONG Count)
441 {
442 READ_REGISTER_BUFFER_UCHAR(Register, Buffer, Count);
443 }
444
445 VOID
446 STDCALL
447 VideoPortReadRegisterBufferUshort(IN PUSHORT Register,
448 OUT PUSHORT Buffer,
449 IN ULONG Count)
450 {
451 READ_REGISTER_BUFFER_USHORT(Register, Buffer, Count);
452 }
453
454 VOID
455 STDCALL
456 VideoPortReadRegisterBufferUlong(IN PULONG Register,
457 OUT PULONG Buffer,
458 IN ULONG Count)
459 {
460 READ_REGISTER_BUFFER_ULONG(Register, Buffer, Count);
461 }
462
463 BOOLEAN
464 STDCALL
465 VideoPortScanRom(IN PVOID HwDeviceExtension,
466 IN PUCHAR RomBase,
467 IN ULONG RomLength,
468 IN PUCHAR String)
469 {
470 UNIMPLEMENTED;
471 }
472
473 ULONG
474 STDCALL
475 VideoPortSetBusData(IN PVOID HwDeviceExtension,
476 IN BUS_DATA_TYPE BusDataType,
477 IN ULONG SlotNumber,
478 IN PVOID Buffer,
479 IN ULONG Offset,
480 IN ULONG Length)
481 {
482 return HalSetBusDataByOffset(BusDataType,
483 0,
484 SlotNumber,
485 Buffer,
486 Offset,
487 Length);
488 }
489
490 VP_STATUS
491 STDCALL
492 VideoPortSetRegistryParameters(IN PVOID HwDeviceExtension,
493 IN PWSTR ValueName,
494 IN PVOID ValueData,
495 IN ULONG ValueLength)
496 {
497 UNIMPLEMENTED;
498 }
499
500 VP_STATUS
501 STDCALL
502 VideoPortSetTrappedEmulatorPorts(IN PVOID HwDeviceExtension,
503 IN ULONG NumAccessRanges,
504 IN PVIDEO_ACCESS_RANGE AccessRange)
505 {
506 UNIMPLEMENTED;
507 }
508
509 VOID
510 STDCALL
511 VideoPortStallExecution(IN ULONG Microseconds)
512 {
513 KeStallExecutionProcessor(Microseconds);
514 }
515
516 VOID
517 STDCALL
518 VideoPortStartTimer(IN PVOID HwDeviceExtension)
519 {
520 PVIDEOPORT_EXTENSION_DATA ExtensionData =
521 MPExtensionToVPExtension(HwDeviceExtension);
522
523 IoStartTimer(ExtensionData->DeviceObject);
524 }
525
526 VOID
527 STDCALL
528 VideoPortStopTimer(IN PVOID HwDeviceExtension)
529 {
530 PVIDEOPORT_EXTENSION_DATA ExtensionData =
531 MPExtensionToVPExtension(HwDeviceExtension);
532
533 IoStopTimer(ExtensionData->DeviceObject);
534 }
535
536 BOOLEAN
537 STDCALL
538 VideoPortSynchronizeExecution(IN PVOID HwDeviceExtension,
539 IN VIDEO_SYNCHRONIZE_PRIORITY Priority,
540 IN PMINIPORT_SYNCHRONIZE_ROUTINE SynchronizeRoutine,
541 OUT PVOID Context)
542 {
543 UNIMPLEMENTED;
544 }
545
546 VP_STATUS
547 STDCALL
548 VideoPortUnmapMemory(IN PVOID HwDeviceExtension,
549 IN PVOID VirtualAddress,
550 IN HANDLE ProcessHandle)
551 {
552 UNIMPLEMENTED;
553 }
554
555 VP_STATUS
556 STDCALL
557 VideoPortVerifyAccessRanges(IN PVOID HwDeviceExtension,
558 IN ULONG NumAccessRanges,
559 IN PVIDEO_ACCESS_RANGE AccessRanges)
560 {
561 UNIMPLEMENTED;
562 }
563
564 VOID
565 STDCALL
566 VideoPortWritePortUchar(IN PUCHAR Port,
567 IN UCHAR Value)
568 {
569 UNIMPLEMENTED;
570 }
571
572 VOID
573 STDCALL
574 VideoPortWritePortUshort(IN PUSHORT Port,
575 IN USHORT Value)
576 {
577 UNIMPLEMENTED;
578 }
579
580 VOID
581 STDCALL
582 VideoPortWritePortUlong(IN PULONG Port,
583 IN ULONG Value)
584 {
585 UNIMPLEMENTED;
586 }
587
588 VOID
589 STDCALL
590 VideoPortWritePortBufferUchar(IN PUCHAR Port,
591 IN PUCHAR Buffer,
592 IN ULONG Count)
593 {
594 UNIMPLEMENTED;
595 }
596
597 VOID
598 STDCALL
599 VideoPortWritePortBufferUshort(IN PUSHORT Port,
600 IN PUSHORT Buffer,
601 IN ULONG Count)
602 {
603 UNIMPLEMENTED;
604 }
605
606 VOID
607 STDCALL
608 VideoPortWritePortBufferUlong(IN PULONG Port,
609 IN PULONG Buffer,
610 IN ULONG Count)
611 {
612 UNIMPLEMENTED;
613 }
614
615 VOID
616 STDCALL
617 VideoPortWriteRegisterUchar(IN PUCHAR Register,
618 IN UCHAR Value)
619 {
620 UNIMPLEMENTED;
621 }
622
623 VOID
624 STDCALL
625 VideoPortWriteRegisterUshort(IN PUSHORT Register,
626 IN USHORT Value)
627 {
628 UNIMPLEMENTED;
629 }
630
631 VOID
632 STDCALL
633 VideoPortWriteRegisterUlong(IN PULONG Register,
634 IN ULONG Value)
635 {
636 UNIMPLEMENTED;
637 }
638
639 VOID
640 STDCALL
641 VideoPortWriteRegisterBufferUchar(IN PUCHAR Register,
642 IN PUCHAR Buffer,
643 IN ULONG Count)
644 {
645 UNIMPLEMENTED;
646 }
647
648 VOID
649 STDCALL
650 VideoPortWriteRegisterBufferUshort(IN PUSHORT Register,
651 IN PUSHORT Buffer,
652 IN ULONG Count)
653 {
654 UNIMPLEMENTED;
655 }
656
657 VOID
658 STDCALL
659 VideoPortWriteRegisterBufferUlong(IN PULONG Register,
660 IN PULONG Buffer,
661 IN ULONG Count)
662 {
663 UNIMPLEMENTED;
664 }
665
666 VOID
667 STDCALL
668 VideoPortZeroMemory(OUT PVOID Destination,
669 IN ULONG Length)
670 {
671 RtlZeroMemory (Destination, Length);
672 }
673
674 VOID
675 STDCALL
676 VideoPortZeroDeviceMemory(OUT PVOID Destination,
677 IN ULONG Length)
678 {
679 UNIMPLEMENTED;
680 }
681
682
683 // ------------------------------------------- Nondiscardable statics
684
685 // VidDispatchOpenClose
686 //
687 // DESCRIPTION:
688 // Answer requests for Open/Close calls: a null operation
689 //
690 // RUN LEVEL:
691 // PASSIVE_LEVEL
692 //
693 // ARGUMENTS:
694 // Standard dispatch arguments
695 //
696 // RETURNS:
697 // NTSTATUS
698 //
699
700 static NTSTATUS
701 VidDispatchOpenClose(IN PDEVICE_OBJECT pDO,
702 IN PIRP Irp)
703 {
704 Irp->IoStatus.Status = STATUS_SUCCESS;
705 Irp->IoStatus.Information = FILE_OPENED;
706 IoCompleteRequest(Irp, IO_NO_INCREMENT);
707
708 return STATUS_SUCCESS;
709 }
710
711 // VidStartIo
712 //
713 // DESCRIPTION:
714 // Get the next requested I/O packet started
715 //
716 // RUN LEVEL:
717 // DISPATCH_LEVEL
718 //
719 // ARGUMENTS:
720 // Dispatch routine standard arguments
721 //
722 // RETURNS:
723 // NTSTATUS
724 //
725
726 static VOID
727 VidStartIo(IN PDEVICE_OBJECT DeviceObject,
728 IN PIRP Irp)
729 {
730 UNIMPLEMENTED;
731 }
732
733 // VidDispatchDeviceControl
734 //
735 // DESCRIPTION:
736 // Answer requests for device control calls
737 //
738 // RUN LEVEL:
739 // PASSIVE_LEVEL
740 //
741 // ARGUMENTS:
742 // Standard dispatch arguments
743 //
744 // RETURNS:
745 // NTSTATUS
746 //
747
748 static NTSTATUS
749 VidDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject,
750 IN PIRP Irp)
751 {
752 UNIMPLEMENTED;
753 }
754
755