ReactOS 0.4.15-dev-7670-g69b08be
enable.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Framebuffer Display Driver
3 * LICENSE: Microsoft NT4 DDK Sample Code License
4 * FILE: win32ss/drivers/displays/vga_new/enable.c
5 * PURPOSE: Main Driver Initialization and PDEV Enabling
6 * PROGRAMMERS: Copyright (c) 1992-1995 Microsoft Corporation
7 * ReactOS Portable Systems Group
8 */
9
10#include "driver.h"
11
12// The driver function table with all function index/address pairs
13
14static DRVFN gadrvfn[] =
15{
22// eVb: 1.2 [VGARISC Change] - Disable hardware palette support
24// eVb: 1.2 [END]
25// eVb: 1.1 [VGARISC Change] - Disable hardware pointer support
26#if 0
29#endif
30// eVb: 1.1 [END]
32};
33
34// Define the functions you want to hook for 8/16/24/32 pel formats
35
36#define HOOKS_BMF8BPP 0
37
38#define HOOKS_BMF16BPP 0
39
40#define HOOKS_BMF24BPP 0
41
42#define HOOKS_BMF32BPP 0
43
44/******************************Public*Routine******************************\
45* DrvEnableDriver
46*
47* Enables the driver by retrieving the drivers function table and version.
48*
49\**************************************************************************/
50
52ULONG iEngineVersion,
53ULONG cj,
55{
56// Engine Version is passed down so future drivers can support previous
57// engine versions. A next generation driver can support both the old
58// and new engine conventions if told what version of engine it is
59// working with. For the first version the driver does nothing with it.
60// eVb: 1.1 [DDK Change] - Remove bogus statement
61 //iEngineVersion;
62// eVb: 1.1 [END]
63// Fill in as much as we can.
64
65 if (cj >= sizeof(DRVENABLEDATA))
66 pded->pdrvfn = gadrvfn;
67
68 if (cj >= (sizeof(ULONG) * 2))
69 pded->c = sizeof(gadrvfn) / sizeof(DRVFN);
70
71// DDI version this driver was targeted for is passed back to engine.
72// Future graphic's engine may break calls down to old driver format.
73
74 if (cj >= sizeof(ULONG))
75// eVb: 1.2 [DDK Change] - Use DDI_DRIVER_VERSION_NT4 instead of DDI_DRIVER_VERSION
77// eVb: 1.2 [END]
78
79 return TRUE;
80}
81
82/******************************Public*Routine******************************\
83* DrvEnablePDEV
84*
85* DDI function, Enables the Physical Device.
86*
87* Return Value: device handle to pdev.
88*
89\**************************************************************************/
90
92DEVMODEW *pDevmode, // Pointer to DEVMODE
93PWSTR pwszLogAddress, // Logical address
94ULONG cPatterns, // number of patterns
95HSURF *ahsurfPatterns, // return standard patterns
96ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
97ULONG *pGdiInfo, // Pointer to GdiInfo structure
98ULONG cjDevInfo, // Length of following PDEVINFO structure
99DEVINFO *pDevInfo, // physical device information structure
100HDEV hdev, // HDEV, used for callbacks
101PWSTR pwszDeviceName, // DeviceName - not used
102HANDLE hDriver) // Handle to base driver
103{
104 GDIINFO GdiInfo;
105 DEVINFO DevInfo;
106 PPDEV ppdev = NULL;
107
110
111 // Allocate a physical device structure.
112
113 ppdev = (PPDEV) EngAllocMem(0, sizeof(PDEV), ALLOC_TAG);
114
115 if (ppdev == NULL)
116 {
117 RIP("DISP DrvEnablePDEV failed EngAllocMem\n");
118 return NULL;
119 }
120
121 memset(ppdev, 0, sizeof(PDEV));
122
123 // Save the screen handle in the PDEV.
124
125 ppdev->hDriver = hDriver;
126
127 // Get the current screen mode information. Set up device caps and devinfo.
128
129 if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
130 {
131 DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
132 goto error_free;
133 }
134
135// eVb: 1.2 [VGARISC Change] - Disable hardware pointer support
136#if 0
137 // Initialize the cursor information.
138
139 if (!bInitPointer(ppdev, &DevInfo))
140 {
141 // Not a fatal error...
142 DISPDBG((0, "DrvEnablePDEV failed bInitPointer\n"));
143 }
144
145#endif
146// eVb: 1.2 [END]
147 // Initialize palette information.
148
149 if (!bInitPaletteInfo(ppdev, &DevInfo))
150 {
151 RIP("DrvEnablePDEV failed bInitPalette\n");
152 goto error_free;
153 }
154
155 // Copy the devinfo into the engine buffer.
156
157 memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
158
159 // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
160 // pdev.
161
162 memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
163
164 return (DHPDEV)ppdev;
165
166 // Error case for failure.
167error_free:
168 EngFreeMem(ppdev);
169 return NULL;
170}
171
172/******************************Public*Routine******************************\
173* DrvCompletePDEV
174*
175* Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
176*
177\**************************************************************************/
178
180DHPDEV dhpdev,
181HDEV hdev)
182{
183 ((PPDEV) dhpdev)->hdevEng = hdev;
184}
185
186/******************************Public*Routine******************************\
187* DrvDisablePDEV
188*
189* Release the resources allocated in DrvEnablePDEV. If a surface has been
190* enabled DrvDisableSurface will have already been called.
191*
192\**************************************************************************/
193
195DHPDEV dhpdev)
196{
197 vDisablePalette((PPDEV) dhpdev);
198 EngFreeMem(dhpdev);
199}
200
201/******************************Public*Routine******************************\
202* DrvEnableSurface
203*
204* Enable the surface for the device. Hook the calls this driver supports.
205*
206* Return: Handle to the surface if successful, 0 for failure.
207*
208\**************************************************************************/
209
211DHPDEV dhpdev)
212{
213 PPDEV ppdev;
214 HSURF hsurf;
215 SIZEL sizl;
216 ULONG ulBitmapType;
217#if 0
218 FLONG flHooks;
219#endif
220 HSURF hSurfBitmap;
221
222 // Create engine bitmap around frame buffer.
223
224 ppdev = (PPDEV) dhpdev;
225
226 if (!bInitSURF(ppdev, TRUE))
227 {
228 RIP("DISP DrvEnableSurface failed bInitSURF\n");
229 return NULL;
230 }
231
232 sizl.cx = ppdev->cxScreen;
233 sizl.cy = ppdev->cyScreen;
234
235// eVb: 1.3 [VGARISC Change] - Disable dynamic palette and > 4BPP support
236#if 0
237 if (ppdev->ulBitCount == 8)
238 {
239 if (!bInit256ColorPalette(ppdev)) {
240 RIP("DISP DrvEnableSurface failed to init the 8bpp palette\n");
241 return NULL;
242 }
243 ulBitmapType = BMF_8BPP;
244 flHooks = HOOKS_BMF8BPP;
245 }
246 else if (ppdev->ulBitCount == 16)
247 {
248 ulBitmapType = BMF_16BPP;
249 flHooks = HOOKS_BMF16BPP;
250 }
251 else if (ppdev->ulBitCount == 24)
252 {
253 ulBitmapType = BMF_24BPP;
254 flHooks = HOOKS_BMF24BPP;
255 }
256 else
257 {
258 ulBitmapType = BMF_32BPP;
259 flHooks = HOOKS_BMF32BPP;
260 }
261// eVb: 1.3 [DDK Change] - Support new VGA Miniport behavior w.r.t updated framebuffer remapping
262 ppdev->flHooks = flHooks;
263// eVb: 1.3 [END]
264#else
265 ulBitmapType = BMF_4BPP;
266#endif
267// eVb: 1.3 [END]
268// eVb: 1.4 [DDK Change] - Use EngCreateDeviceSurface instead of EngCreateBitmap
269 hsurf = (HSURF)EngCreateDeviceSurface((DHSURF)ppdev,
270 sizl,
271 ulBitmapType);
272
273 if (hsurf == NULL)
274 {
275 RIP("DISP DrvEnableSurface failed EngCreateDeviceSurface\n");
276 return NULL;
277 }
278// eVb: 1.4 [END]
279
280// eVb: 1.5 [DDK Change] - Use EngModifySurface instead of EngAssociateSurface
281 if ( !EngModifySurface(hsurf,
282 ppdev->hdevEng,
283 ppdev->flHooks | HOOK_SYNCHRONIZE,
285 (DHSURF)ppdev,
286 ppdev->pjScreen,
287 ppdev->lDeltaScreen,
288 NULL))
289 {
290 RIP("DISP DrvEnableSurface failed EngModifySurface\n");
291 return NULL;
292 }
293// eVb: 1.5 [END]
294 ppdev->hsurfEng = hsurf;
295// eVb: 1.4 [VGARISC Change] - Allocate 4BPP DIB that will store GDI drawing
296 hSurfBitmap = (HSURF)EngCreateBitmap(sizl, 0, ulBitmapType, 0, NULL);
297 if (hSurfBitmap == NULL)
298 {
299 RIP("DISP DrvEnableSurface failed EngCreateBitmap\n");
300 return NULL;
301 }
302
303 if ( !EngModifySurface(hSurfBitmap,
304 ppdev->hdevEng,
305 ppdev->flHooks | HOOK_SYNCHRONIZE,
307 (DHSURF)ppdev,
308 ppdev->pjScreen,
309 ppdev->lDeltaScreen,
310 NULL))
311 {
312 RIP("DISP DrvEnableSurface failed second EngModifySurface\n");
313 return NULL;
314 }
315
316 ppdev->pso = EngLockSurface(hSurfBitmap);
317 if (ppdev->pso == NULL)
318 {
319 RIP("DISP DrvEnableSurface failed EngLockSurface\n");
320 return NULL;
321 }
322// eVb: 1.4 [END]
323 return hsurf;
324}
325
326/******************************Public*Routine******************************\
327* DrvDisableSurface
328*
329* Free resources allocated by DrvEnableSurface. Release the surface.
330*
331\**************************************************************************/
332
334DHPDEV dhpdev)
335{
336 EngDeleteSurface(((PPDEV) dhpdev)->hsurfEng);
337 vDisableSURF((PPDEV) dhpdev);
338 ((PPDEV) dhpdev)->hsurfEng = NULL;
339}
340
341/******************************Public*Routine******************************\
342* DrvAssertMode
343*
344* This asks the device to reset itself to the mode of the pdev passed in.
345*
346\**************************************************************************/
347
349DHPDEV dhpdev,
351{
352 PPDEV ppdev = (PPDEV) dhpdev;
353 ULONG ulReturn;
354 PBYTE pjScreen;
355
356 if (bEnable)
357 {
358 //
359 // The screen must be reenabled, reinitialize the device to clean state.
360 //
361// eVb: 1.6 [DDK Change] - Support new VGA Miniport behavior w.r.t updated framebuffer remapping
362 pjScreen = ppdev->pjScreen;
363
364 if (!bInitSURF(ppdev, FALSE))
365 {
366 DISPDBG((0, "DISP DrvAssertMode failed bInitSURF\n"));
367 return (FALSE);
368 }
369
370 if (pjScreen != ppdev->pjScreen) {
371
372 if ( !EngModifySurface(ppdev->hsurfEng,
373 ppdev->hdevEng,
374 ppdev->flHooks | HOOK_SYNCHRONIZE,
376 (DHSURF)ppdev,
377 ppdev->pjScreen,
378 ppdev->lDeltaScreen,
379 NULL))
380 {
381 DISPDBG((0, "DISP DrvAssertMode failed EngModifySurface\n"));
382 return (FALSE);
383 }
384 }
385// eVb: 1.6 [END]
386 return (TRUE);
387 }
388 else
389 {
390 //
391 // We must give up the display.
392 // Call the kernel driver to reset the device to a known state.
393 //
394
395 if (EngDeviceIoControl(ppdev->hDriver,
397 NULL,
398 0,
399 NULL,
400 0,
401 &ulReturn))
402 {
403 RIP("DISP DrvAssertMode failed IOCTL");
404 return FALSE;
405 }
406 else
407 {
408 return TRUE;
409 }
410 }
411}
412
413/******************************Public*Routine******************************\
414* DrvGetModes
415*
416* Returns the list of available modes for the device.
417*
418\**************************************************************************/
419
423DEVMODEW *pdm)
424
425{
426
427 DWORD cModes;
428 DWORD cbOutputSize;
429 PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp;
430 DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
431 DWORD cbModeSize;
432
433 DISPDBG((3, "DrvGetModes\n"));
434
435 cModes = getAvailableModes(hDriver,
436 (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
437 &cbModeSize);
438
439 if (cModes == 0)
440 {
441 DISPDBG((0, "DrvGetModes failed to get mode information"));
442 return 0;
443 }
444
445 if (pdm == NULL)
446 {
447 cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
448 }
449 else
450 {
451 //
452 // Now copy the information for the supported modes back into the output
453 // buffer
454 //
455
456 cbOutputSize = 0;
457
458 pVideoTemp = pVideoModeInformation;
459
460 do
461 {
462 if (pVideoTemp->Length != 0)
463 {
464 if (cOutputModes == 0)
465 {
466 break;
467 }
468
469 //
470 // Zero the entire structure to start off with.
471 //
472
473 memset(pdm, 0, sizeof(DEVMODEW));
474
475 //
476 // Set the name of the device to the name of the DLL.
477 //
478
479 memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
480
483 pdm->dmSize = sizeof(DEVMODEW);
485
486 pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
487 pVideoTemp->BitsPerPlane;
488 pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
489 pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
490 pdm->dmDisplayFrequency = pVideoTemp->Frequency;
491 pdm->dmDisplayFlags = 0;
492
493 pdm->dmFields = DM_BITSPERPEL |
498
499 //
500 // Go to the next DEVMODE entry in the buffer.
501 //
502
503 cOutputModes--;
504
505 pdm = (LPDEVMODEW) ( ((ULONG)pdm) + sizeof(DEVMODEW) +
507
508 cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
509
510 }
511
512 pVideoTemp = (PVIDEO_MODE_INFORMATION)
513 (((PUCHAR)pVideoTemp) + cbModeSize);
514
515 } while (--cModes);
516 }
517
518 EngFreeMem(pVideoModeInformation);
519
520 return cbOutputSize;
521
522}
#define ALLOC_TAG
Definition: btrfs_drv.h:87
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define APIENTRY
Definition: api.h:79
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _PDEV * PPDEV
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55
unsigned long FLONG
Definition: ntbasedef.h:366
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
struct _VIDEO_MODE_INFORMATION * PVIDEO_MODE_INFORMATION
#define IOCTL_VIDEO_RESET_DEVICE
Definition: ntddvdeo.h:206
BYTE * PBYTE
Definition: pedump.c:66
#define EngFreeMem
Definition: polytest.cpp:56
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
#define memset(x, y, z)
Definition: compat.h:39
Definition: winddi.h:529
Definition: framebuf.h:34
LONG flHooks
Definition: driver.h:49
SURFOBJ * pso
Definition: driver.h:52
HSURF hsurfEng
Definition: driver.h:24
PBYTE pjScreen
Definition: driver.h:26
HDEV hdevEng
Definition: driver.h:23
ULONG ulBitCount
Definition: driver.h:40
HANDLE hDriver
Definition: framebuf.h:35
LONG lDeltaScreen
Definition: driver.h:30
ULONG cyScreen
Definition: driver.h:28
ULONG cxScreen
Definition: driver.h:27
DWORD dmBitsPerPel
Definition: wingdi.h:1647
WCHAR dmDeviceName[CCHDEVICENAME]
Definition: wingdi.h:1617
DWORD dmFields
Definition: wingdi.h:1622
DWORD dmPelsWidth
Definition: wingdi.h:1648
WORD dmDriverExtra
Definition: wingdi.h:1621
WORD dmSpecVersion
Definition: wingdi.h:1618
DWORD dmDisplayFlags
Definition: wingdi.h:1651
DWORD dmPelsHeight
Definition: wingdi.h:1649
DWORD dmDisplayFrequency
Definition: wingdi.h:1654
WORD dmSize
Definition: wingdi.h:1620
WORD dmDriverVersion
Definition: wingdi.h:1619
ULONG iDriverVersion
Definition: winddi.h:542
DRVFN * pdrvfn
Definition: winddi.h:544
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define DLL_NAME
Definition: vgaddi.h:247
#define DRIVER_EXTRA_SIZE
Definition: vgaddi.h:245
DWORD getAvailableModes(IN HANDLE Driver, OUT PVIDEO_MODE_INFORMATION *modeInformation, OUT DWORD *ModeSize)
Definition: screen.c:38
#define RIP(x)
Definition: debug.h:24
#define DISPDBG(arg)
Definition: debug.h:23
BOOL bInitPointer(PPDEV, DEVINFO *)
BOOL bInitSURF(PPDEV, BOOL)
Definition: screen.c:168
BOOL bInitPDEV(PPDEV, PDEVMODEW, GDIINFO *, DEVINFO *)
VOID vDisablePalette(PPDEV)
Definition: palette.c:82
BOOL bInitPaletteInfo(PPDEV, DEVINFO *)
Definition: palette.c:67
VOID vDisableSURF(PPDEV)
Definition: screen.c:297
BOOL bInit256ColorPalette(PPDEV)
Definition: palette.c:226
static DRVFN gadrvfn[]
Definition: enable.c:14
#define HOOKS_BMF32BPP
Definition: enable.c:42
#define HOOKS_BMF8BPP
Definition: enable.c:36
#define HOOKS_BMF16BPP
Definition: enable.c:38
#define HOOKS_BMF24BPP
Definition: enable.c:40
#define INDEX_DrvSetPointerShape
Definition: winddi.h:445
#define BMF_16BPP
Definition: winddi.h:358
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG cjDevInfo
Definition: winddi.h:3553
#define BMF_8BPP
Definition: winddi.h:357
#define DDI_DRIVER_VERSION_NT4
Definition: winddi.h:535
LONG_PTR(APIENTRY * PFN)()
Definition: winddi.h:133
typedef DHPDEV(APIENTRY FN_DrvEnablePDEV)(_In_ DEVMODEW *pdm
ENGAPI BOOL APIENTRY EngDeleteSurface(_In_ _Post_ptr_invalid_ HSURF hsurf)
Definition: surface.c:567
FN_DrvSetPalette DrvSetPalette
#define INDEX_DrvDisableSurface
Definition: winddi.h:420
ENGAPI SURFOBJ *APIENTRY EngLockSurface(_In_ HSURF hsurf)
Definition: surface.c:607
#define INDEX_DrvMovePointer
Definition: winddi.h:446
ENGAPI BOOL APIENTRY EngModifySurface(_In_ HSURF hsurf, _In_ HDEV hdev, _In_ FLONG flHooks, _In_ FLONG flSurface, _In_ DHSURF dhsurf, _In_ PVOID pvScan0, _In_ LONG lDelta, _Reserved_ PVOID pvReserved)
Definition: surface.c:471
ENGAPI HBITMAP APIENTRY EngCreateBitmap(_In_ SIZEL sizl, _In_ LONG lWidth, _In_ ULONG iFormat, _In_ FLONG fl, _In_opt_ PVOID pvBits)
_In_ HDEV hdev
Definition: winddi.h:3449
_In_ LPWSTR pwszLogAddress
Definition: winddi.h:3548
FN_DrvSetPointerShape DrvSetPointerShape
#define MS_NOTSYSTEMMEMORY
Definition: winddi.h:2129
FN_DrvGetModes DrvGetModes
#define INDEX_DrvCompletePDEV
Definition: winddi.h:417
_Must_inspect_result_ ENGAPI HSURF APIENTRY EngCreateDeviceSurface(_In_ DHSURF dhsurf, _In_ SIZEL sizl, _In_ ULONG iFormatCompat)
Definition: surface.c:391
#define INDEX_DrvSetPalette
Definition: winddi.h:438
_In_ ULONG cj
Definition: winddi.h:3540
#define BMF_24BPP
Definition: winddi.h:359
FN_DrvEnableSurface DrvEnableSurface
#define INDEX_DrvEnablePDEV
Definition: winddi.h:416
#define BMF_32BPP
Definition: winddi.h:360
FN_DrvMovePointer DrvMovePointer
typedef HSURF(APIENTRY FN_DrvEnableSurface)(_In_ DHPDEV dhpdev)
FN_DrvCompletePDEV DrvCompletePDEV
#define INDEX_DrvAssertMode
Definition: winddi.h:421
_In_ ULONG cjSize
Definition: winddi.h:3634
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR pwszDeviceName
Definition: winddi.h:3556
_In_ BOOL bEnable
Definition: winddi.h:3426
#define HOOK_SYNCHRONIZE
Definition: winddi.h:1431
FN_DrvEnablePDEV DrvEnablePDEV
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3557
FN_DrvEnableDriver DrvEnableDriver
FN_DrvAssertMode DrvAssertMode
#define BMF_4BPP
Definition: winddi.h:356
FN_DrvDisableSurface DrvDisableSurface
FN_DrvDisablePDEV DrvDisablePDEV
_In_ SIZEL sizl
Definition: winddi.h:3467
#define INDEX_DrvEnableSurface
Definition: winddi.h:419
#define INDEX_DrvDisablePDEV
Definition: winddi.h:418
#define INDEX_DrvGetModes
Definition: winddi.h:457
#define DM_DISPLAYFREQUENCY
Definition: wingdi.h:1272
#define DM_PELSWIDTH
Definition: wingdi.h:1269
struct _devicemodeW * LPDEVMODEW
struct _devicemodeW DEVMODEW
#define DM_BITSPERPEL
Definition: wingdi.h:1268
#define DM_SPECVERSION
Definition: wingdi.h:1243
#define DM_PELSHEIGHT
Definition: wingdi.h:1270
#define DM_DISPLAYFLAGS
Definition: wingdi.h:1271