ReactOS 0.4.16-dev-297-gc569aee
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
14static
15CODE_SEG("PAGE")
16VOID
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;
45}
46
47static
48CODE_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
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
75static
76CODE_SEG("PAGE")
80 _In_ PHW_DEVICE_EXTENSION DeviceExtension,
82 _Out_ PSTATUS_BLOCK StatusBlock)
83{
84 PAGED_CODE();
85
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
96static
97CODE_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
117static
118CODE_SEG("PAGE")
122 _In_ PHW_DEVICE_EXTENSION DeviceExtension,
123 _In_ PVIDEO_MEMORY RequestedAddress,
124 _Out_ PVIDEO_MEMORY_INFORMATION MapInformation,
125 _Out_ PSTATUS_BLOCK StatusBlock)
126{
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
158static
159CODE_SEG("PAGE")
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
175static
176CODE_SEG("PAGE")
180{
181 PAGED_CODE();
182
183 VideoDebugPrint((Trace, "%s()\n", __FUNCTION__));
184
185 return NO_ERROR;
186}
187
188static
189CODE_SEG("PAGE")
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
209CODE_SEG("PAGE")
211NTAPI
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
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}
#define PAGED_CODE()
#define CODE_SEG(...)
unsigned char BOOLEAN
BOOL Error
Definition: chkdsk.c:66
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
struct _VideoMode VideoMode
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define Trace(x)
Definition: inflate.c:42
#define __FUNCTION__
Definition: types.h:116
Status
Definition: gdiplustypes.h:25
#define _Inout_
Definition: no_sal2.h:162
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define FASTCALL
Definition: nt_native.h:50
#define IOCTL_VIDEO_MAP_VIDEO_MEMORY
Definition: ntddvdeo.h:173
#define VIDEO_MODE_GRAPHICS
Definition: ntddvdeo.h:364
#define IOCTL_VIDEO_UNMAP_VIDEO_MEMORY
Definition: ntddvdeo.h:248
#define VIDEO_MODE_COLOR
Definition: ntddvdeo.h:363
#define VIDEO_MODE_PALETTE_DRIVEN
Definition: ntddvdeo.h:365
#define IOCTL_VIDEO_QUERY_CURRENT_MODE
Definition: ntddvdeo.h:182
#define IOCTL_VIDEO_GET_CHILD_STATE
Definition: ntddvdeo.h:164
#define VIDEO_MODE_MANAGED_PALETTE
Definition: ntddvdeo.h:366
#define IOCTL_VIDEO_SET_CURRENT_MODE
Definition: ntddvdeo.h:221
#define IOCTL_VIDEO_SET_COLOR_REGISTERS
Definition: ntddvdeo.h:218
#define IOCTL_VIDEO_RESET_DEVICE
Definition: ntddvdeo.h:206
struct _VIDEO_NUM_MODES VIDEO_NUM_MODES
struct _VIDEO_MEMORY_INFORMATION VIDEO_MEMORY_INFORMATION
#define VIDEO_CHILD_ACTIVE
Definition: ntddvdeo.h:608
struct _VIDEO_MODE_INFORMATION VIDEO_MODE_INFORMATION
#define IOCTL_VIDEO_QUERY_AVAIL_MODES
Definition: ntddvdeo.h:176
#define IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES
Definition: ntddvdeo.h:191
VPAPI VP_STATUS NTAPI VideoPortUnmapMemory(IN PVOID HwDeviceExtension, IN OUT PVOID VirtualAddress, IN HANDLE ProcessHandle)
LONG VP_STATUS
Definition: video.h:153
VPAPI VP_STATUS NTAPI VideoPortMapMemory(IN PVOID HwDeviceExtension, IN PHYSICAL_ADDRESS PhysicalAddress, IN OUT PULONG Length, IN PULONG InIoSpace, IN OUT PVOID *VirtualAddress)
#define VIDEO_MEMORY_SPACE_MEMORY
Definition: video.h:132
#define VideoDebugPrint(x)
Definition: video.h:75
static const VBE_MODE Modes[VBE_MODE_COUNT]
Definition: vbe.c:189
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59
static CONST VGA_MODE VideoModes[BIOS_MAX_VIDEO_MODE+1]
Definition: vidbios.c:1941
VP_STATUS FASTCALL Pc98VidSetColorRegisters(_In_ PVIDEO_CLUT ColorLookUpTable)
Definition: hardware.c:261
VP_STATUS FASTCALL Pc98VidSetCurrentMode(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _In_ PVIDEO_MODE RequestedMode)
Definition: hardware.c:83
static VP_STATUS FASTCALL Pc98VidUnmapVideoMemory(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _In_ PVIDEO_MEMORY VideoMemory)
Definition: ioctl.c:162
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 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 Pc98VidQueryNumAvailModes(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _Out_ PVIDEO_NUM_MODES Modes, _Out_ PSTATUS_BLOCK StatusBlock)
Definition: ioctl.c:79
BOOLEAN NTAPI Pc98VidStartIO(_In_ PVOID HwDeviceExtension, _Inout_ PVIDEO_REQUEST_PACKET RequestPacket)
Definition: ioctl.c:212
static VP_STATUS FASTCALL Pc98VidQueryAvailModes(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _Out_ PVIDEO_MODE_INFORMATION ModeInformation, _Out_ PSTATUS_BLOCK StatusBlock)
Definition: ioctl.c:51
static VOID FASTCALL Pc98VidQueryMode(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _In_ ULONG ModeNumber, _Out_ PVIDEO_MODE_INFORMATION VideoMode)
Definition: ioctl.c:18
static VP_STATUS FASTCALL Pc98VidResetDevice(VOID)
Definition: ioctl.c:179
static VP_STATUS FASTCALL Pc98VidQueryCurrentMode(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _Out_ PVIDEO_MODE_INFORMATION VideoMode, _Out_ PSTATUS_BLOCK StatusBlock)
Definition: ioctl.c:100
unsigned char UCHAR
Definition: xmlstorage.h:181