ReactOS  0.4.15-dev-5462-g4d0d22a
ioctl.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS framebuffer driver for NEC PC-98 series
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: I/O control handling
5  * COPYRIGHT: Copyright 2020 Dmitry Borisov (di.sean@protonmail.com)
6  */
7 
8 /* INCLUDES *******************************************************************/
9 
10 #include "pc98vid.h"
11 
12 /* FUNCTIONS ******************************************************************/
13 
14 static
15 CODE_SEG("PAGE")
16 VOID
19  _In_ PHW_DEVICE_EXTENSION DeviceExtension,
20  _In_ ULONG ModeNumber,
22 {
23  PAGED_CODE();
24 
25  VideoDebugPrint((Trace, "%s() Mode %d\n", __FUNCTION__, ModeNumber));
26 
27  VideoMode->Length = sizeof(VIDEO_MODE_INFORMATION);
28  VideoMode->ModeIndex = ModeNumber;
29  VideoMode->VisScreenWidth = VideoModes[ModeNumber].HResolution;
30  VideoMode->VisScreenHeight = VideoModes[ModeNumber].VResolution;
31  VideoMode->ScreenStride = VideoModes[ModeNumber].HResolution;
32  VideoMode->NumberOfPlanes = 1;
33  VideoMode->BitsPerPlane = 8;
34  VideoMode->Frequency = VideoModes[ModeNumber].RefreshRate;
35  VideoMode->XMillimeter = 320;
36  VideoMode->YMillimeter = 240;
37  VideoMode->NumberRedBits =
38  VideoMode->NumberGreenBits =
39  VideoMode->NumberBlueBits = 8;
40  VideoMode->RedMask =
41  VideoMode->GreenMask =
42  VideoMode->BlueMask = 0;
43  VideoMode->AttributeFlags = VIDEO_MODE_COLOR | VIDEO_MODE_GRAPHICS |
45 }
46 
47 static
48 CODE_SEG("PAGE")
52  _In_ PHW_DEVICE_EXTENSION DeviceExtension,
53  _Out_ PVIDEO_MODE_INFORMATION ModeInformation,
54  _Out_ PSTATUS_BLOCK StatusBlock)
55 {
56  UCHAR ModeNumber;
58 
59  PAGED_CODE();
60 
61  VideoDebugPrint((Trace, "%s()\n", __FUNCTION__));
62 
63  for (ModeNumber = 0, VideoMode = ModeInformation;
64  ModeNumber < DeviceExtension->ModeCount;
65  ++ModeNumber, ++VideoMode)
66  {
67  Pc98VidQueryMode(DeviceExtension, ModeNumber, VideoMode);
68  }
69 
70  StatusBlock->Information = sizeof(VIDEO_MODE_INFORMATION) * DeviceExtension->ModeCount;
71 
72  return NO_ERROR;
73 }
74 
75 static
76 CODE_SEG("PAGE")
80  _In_ PHW_DEVICE_EXTENSION DeviceExtension,
82  _Out_ PSTATUS_BLOCK StatusBlock)
83 {
84  PAGED_CODE();
85 
86  VideoDebugPrint((Trace, "%s()\n", __FUNCTION__));
87 
88  Modes->NumModes = DeviceExtension->ModeCount;
89  Modes->ModeInformationLength = sizeof(VIDEO_MODE_INFORMATION);
90 
91  StatusBlock->Information = sizeof(VIDEO_NUM_MODES);
92 
93  return NO_ERROR;
94 }
95 
96 static
97 CODE_SEG("PAGE")
101  _In_ PHW_DEVICE_EXTENSION DeviceExtension,
103  _Out_ PSTATUS_BLOCK StatusBlock)
104 {
105  PAGED_CODE();
106 
107  VideoDebugPrint((Trace, "%s() Mode %d\n",
108  __FUNCTION__, DeviceExtension->CurrentMode));
109 
110  Pc98VidQueryMode(DeviceExtension, DeviceExtension->CurrentMode, VideoMode);
111 
112  StatusBlock->Information = sizeof(VIDEO_MODE_INFORMATION);
113 
114  return NO_ERROR;
115 }
116 
117 static
118 CODE_SEG("PAGE")
119 VP_STATUS
120 FASTCALL
122  _In_ PHW_DEVICE_EXTENSION DeviceExtension,
123  _In_ PVIDEO_MEMORY RequestedAddress,
124  _Out_ PVIDEO_MEMORY_INFORMATION MapInformation,
125  _Out_ PSTATUS_BLOCK StatusBlock)
126 {
128  ULONG inIoSpace = VIDEO_MEMORY_SPACE_MEMORY;
129 
130  PAGED_CODE();
131 
132  VideoDebugPrint((Trace, "%s()\n", __FUNCTION__));
133 
134  MapInformation->VideoRamBase = RequestedAddress->RequestedVirtualAddress;
135  MapInformation->VideoRamLength = DeviceExtension->FrameBufferLength;
136 
137  Status = VideoPortMapMemory(DeviceExtension,
138  DeviceExtension->FrameBuffer,
139  &MapInformation->VideoRamLength,
140  &inIoSpace,
141  &MapInformation->VideoRamBase);
142  if (Status != NO_ERROR)
143  {
144  VideoDebugPrint((Error, "%s() Failed to map framebuffer memory\n",
145  __FUNCTION__));
146  }
147  else
148  {
149  MapInformation->FrameBufferBase = MapInformation->VideoRamBase;
150  MapInformation->FrameBufferLength = MapInformation->VideoRamLength;
151 
152  StatusBlock->Information = sizeof(VIDEO_MEMORY_INFORMATION);
153  }
154 
155  return Status;
156 }
157 
158 static
159 CODE_SEG("PAGE")
160 VP_STATUS
161 FASTCALL
163  _In_ PHW_DEVICE_EXTENSION DeviceExtension,
164  _In_ PVIDEO_MEMORY VideoMemory)
165 {
166  PAGED_CODE();
167 
168  VideoDebugPrint((Trace, "%s()\n", __FUNCTION__));
169 
170  return VideoPortUnmapMemory(DeviceExtension,
171  VideoMemory->RequestedVirtualAddress,
172  NULL);
173 }
174 
175 static
176 CODE_SEG("PAGE")
177 VP_STATUS
178 FASTCALL
180 {
181  PAGED_CODE();
182 
183  VideoDebugPrint((Trace, "%s()\n", __FUNCTION__));
184 
185  return NO_ERROR;
186 }
187 
188 static
189 CODE_SEG("PAGE")
190 VP_STATUS
191 FASTCALL
193  _In_ PHW_DEVICE_EXTENSION DeviceExtension,
194  _In_ PULONG ChildIndex,
195  _Out_ PULONG ChildState,
196  _Out_ PSTATUS_BLOCK StatusBlock)
197 {
198  PAGED_CODE();
199 
200  VideoDebugPrint((Trace, "%s() Child %d\n", __FUNCTION__, *ChildIndex));
201 
202  *ChildState = VIDEO_CHILD_ACTIVE;
203 
204  StatusBlock->Information = sizeof(ULONG);
205 
206  return NO_ERROR;
207 }
208 
209 CODE_SEG("PAGE")
210 BOOLEAN
211 NTAPI
213  _In_ PVOID HwDeviceExtension,
214  _Inout_ PVIDEO_REQUEST_PACKET RequestPacket)
215 {
217 
218  PAGED_CODE();
219 
220  VideoDebugPrint((Trace, "%s() IOCTL 0x%lX\n",
221  __FUNCTION__, RequestPacket->IoControlCode));
222 
223  switch (RequestPacket->IoControlCode)
224  {
226  {
227  if (RequestPacket->OutputBufferLength < sizeof(VIDEO_NUM_MODES))
228  {
230  break;
231  }
232 
234  (PVIDEO_NUM_MODES)RequestPacket->OutputBuffer,
235  RequestPacket->StatusBlock);
236  break;
237  }
238 
240  {
241  if (RequestPacket->OutputBufferLength < sizeof(VIDEO_MODE_INFORMATION) *
242  ((PHW_DEVICE_EXTENSION)HwDeviceExtension)->ModeCount)
243  {
245  break;
246  }
247 
249  (PVIDEO_MODE_INFORMATION)RequestPacket->OutputBuffer,
250  RequestPacket->StatusBlock);
251  break;
252  }
253 
255  {
256  if (RequestPacket->InputBufferLength < sizeof(VIDEO_MODE))
257  {
259  break;
260  }
261 
263  (PVIDEO_MODE)RequestPacket->InputBuffer);
264  break;
265  }
266 
268  {
269  if (RequestPacket->OutputBufferLength < sizeof(VIDEO_MODE_INFORMATION))
270  {
272  break;
273  }
274 
276  (PVIDEO_MODE_INFORMATION)RequestPacket->OutputBuffer,
277  RequestPacket->StatusBlock);
278  break;
279  }
280 
282  {
283  if (RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY) ||
284  RequestPacket->OutputBufferLength < sizeof(VIDEO_MEMORY_INFORMATION))
285  {
287  break;
288  }
289 
291  (PVIDEO_MEMORY)RequestPacket->InputBuffer,
292  (PVIDEO_MEMORY_INFORMATION)RequestPacket->OutputBuffer,
293  RequestPacket->StatusBlock);
294  break;
295  }
296 
298  {
299  if (RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY))
300  {
302  break;
303  }
304 
306  (PVIDEO_MEMORY)RequestPacket->InputBuffer);
307  break;
308  }
309 
311  {
313  break;
314  }
315 
317  {
318  if (RequestPacket->InputBufferLength < sizeof(VIDEO_CLUT))
319  {
321  break;
322  }
323 
324  Status = Pc98VidSetColorRegisters((PVIDEO_CLUT)RequestPacket->InputBuffer);
325  break;
326  }
327 
329  {
330  if (RequestPacket->InputBufferLength < sizeof(ULONG) ||
331  RequestPacket->OutputBufferLength < sizeof(ULONG))
332  {
334  break;
335  }
336 
337  Status = Pc98VidGetChildState((PHW_DEVICE_EXTENSION)HwDeviceExtension,
338  (PULONG)RequestPacket->InputBuffer,
339  (PULONG)RequestPacket->OutputBuffer,
340  RequestPacket->StatusBlock);
341  break;
342  }
343 
344  default:
346  }
347 
348  if (Status != NO_ERROR)
349  VideoDebugPrint((Trace, "%s() Failed 0x%lX\n", __FUNCTION__, Status));
350 
351  RequestPacket->StatusBlock->Status = Status;
352 
353  return TRUE;
354 }
struct _VIDEO_NUM_MODES VIDEO_NUM_MODES
#define _Inout_
Definition: ms_sal.h:378
#define VIDEO_MODE_MANAGED_PALETTE
Definition: ntddvdeo.h:297
#define _Out_
Definition: ms_sal.h:345
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define TRUE
Definition: types.h:120
static VP_STATUS FASTCALL Pc98VidMapVideoMemory(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _In_ PVIDEO_MEMORY RequestedAddress, _Out_ PVIDEO_MEMORY_INFORMATION MapInformation, _Out_ PSTATUS_BLOCK StatusBlock)
Definition: ioctl.c:121
static const VBE_MODE Modes[VBE_MODE_COUNT]
Definition: vbe.c:189
#define IOCTL_VIDEO_RESET_DEVICE
Definition: ntddvdeo.h:137
#define IOCTL_VIDEO_MAP_VIDEO_MEMORY
Definition: ntddvdeo.h:104
#define NO_ERROR
Definition: dderror.h:5
#define FASTCALL
Definition: nt_native.h:50
VP_STATUS FASTCALL Pc98VidSetColorRegisters(_In_ PVIDEO_CLUT ColorLookUpTable)
Definition: hardware.c:261
#define IOCTL_VIDEO_QUERY_CURRENT_MODE
Definition: ntddvdeo.h:113
#define IOCTL_VIDEO_SET_CURRENT_MODE
Definition: ntddvdeo.h:152
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
VP_STATUS FASTCALL Pc98VidSetCurrentMode(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _In_ PVIDEO_MODE RequestedMode)
Definition: hardware.c:83
unsigned char BOOLEAN
#define _In_
Definition: ms_sal.h:308
static VP_STATUS FASTCALL Pc98VidQueryCurrentMode(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _Out_ PVIDEO_MODE_INFORMATION VideoMode, _Out_ PSTATUS_BLOCK StatusBlock)
Definition: ioctl.c:100
#define IOCTL_VIDEO_UNMAP_VIDEO_MEMORY
Definition: ntddvdeo.h:179
struct _VideoMode VideoMode
static CONST VGA_MODE VideoModes[BIOS_MAX_VIDEO_MODE+1]
Definition: vidbios.c:1941
Status
Definition: gdiplustypes.h:24
static VP_STATUS FASTCALL Pc98VidQueryAvailModes(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _Out_ PVIDEO_MODE_INFORMATION ModeInformation, _Out_ PSTATUS_BLOCK StatusBlock)
Definition: ioctl.c:51
VPAPI VP_STATUS NTAPI VideoPortMapMemory(IN PVOID HwDeviceExtension, IN PHYSICAL_ADDRESS PhysicalAddress, IN OUT PULONG Length, IN PULONG InIoSpace, IN OUT PVOID *VirtualAddress)
static VP_STATUS FASTCALL Pc98VidUnmapVideoMemory(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _In_ PVIDEO_MEMORY VideoMemory)
Definition: ioctl.c:162
struct _VIDEO_MEMORY_INFORMATION VIDEO_MEMORY_INFORMATION
BOOL Error
Definition: chkdsk.c:66
#define VIDEO_MODE_PALETTE_DRIVEN
Definition: ntddvdeo.h:296
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES
Definition: ntddvdeo.h:122
#define Trace(x)
Definition: inflate.c:42
#define IOCTL_VIDEO_QUERY_AVAIL_MODES
Definition: ntddvdeo.h:107
VPAPI VP_STATUS NTAPI VideoPortUnmapMemory(IN PVOID HwDeviceExtension, IN OUT PVOID VirtualAddress, IN HANDLE ProcessHandle)
#define VideoDebugPrint(x)
Definition: video.h:75
#define VIDEO_MODE_COLOR
Definition: ntddvdeo.h:294
#define VIDEO_CHILD_ACTIVE
Definition: ntddvdeo.h:539
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define IOCTL_VIDEO_GET_CHILD_STATE
Definition: ntddvdeo.h:95
static VOID FASTCALL Pc98VidQueryMode(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _In_ ULONG ModeNumber, _Out_ PVIDEO_MODE_INFORMATION VideoMode)
Definition: ioctl.c:18
unsigned int ULONG
Definition: retypes.h:1
LONG VP_STATUS
Definition: video.h:153
static VP_STATUS FASTCALL Pc98VidQueryNumAvailModes(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _Out_ PVIDEO_NUM_MODES Modes, _Out_ PSTATUS_BLOCK StatusBlock)
Definition: ioctl.c:79
#define VIDEO_MEMORY_SPACE_MEMORY
Definition: video.h:132
struct _VIDEO_MODE_INFORMATION VIDEO_MODE_INFORMATION
#define __FUNCTION__
Definition: types.h:112
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
BOOLEAN NTAPI Pc98VidStartIO(_In_ PVOID HwDeviceExtension, _Inout_ PVIDEO_REQUEST_PACKET RequestPacket)
Definition: ioctl.c:212
static VP_STATUS FASTCALL Pc98VidGetChildState(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _In_ PULONG ChildIndex, _Out_ PULONG ChildState, _Out_ PSTATUS_BLOCK StatusBlock)
Definition: ioctl.c:192
static VP_STATUS FASTCALL Pc98VidResetDevice(VOID)
Definition: ioctl.c:179
#define IOCTL_VIDEO_SET_COLOR_REGISTERS
Definition: ntddvdeo.h:149
#define PAGED_CODE()
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define VIDEO_MODE_GRAPHICS
Definition: ntddvdeo.h:295