ReactOS  0.4.13-dev-259-g5ca9c9c
vga.c File Reference
#include "vga.h"
#include <devioctl.h>
Include dependency graph for vga.c:

Go to the source code of this file.

Functions

VP_STATUS NTAPI VgaFindAdapter (PVOID HwDeviceExtension, PVOID HwContext, PWSTR ArgumentString, PVIDEO_PORT_CONFIG_INFO ConfigInfo, PUCHAR Again)
 
BOOLEAN NTAPI VgaInitialize (PVOID HwDeviceExtension)
 
BOOLEAN NTAPI VgaStartIO (PVOID HwDeviceExtension, PVIDEO_REQUEST_PACKET RequestPacket)
 
VP_STATUS NTAPI VgaQueryAvailableModes (PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_MODE_INFORMATION ModeInformation, ULONG ModeInformationSize, PULONG_PTR OutputSize)
 
VP_STATUS NTAPI VgaQueryNumberOfAvailableModes (PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_NUM_MODES NumModes, ULONG NumModesSize, PULONG_PTR OutputSize)
 
VP_STATUS NTAPI VgaQueryCurrentMode (PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_MODE_INFORMATION ModeInformation, ULONG ModeInformationSize, PULONG_PTR OutputSize)
 
VP_STATUS NTAPI VgaSetMode (PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_MODE Mode, ULONG ModeSize, PULONG PhysPtrChange)
 
BOOLEAN NTAPI VgaIsPresent (PHW_DEVICE_EXTENSION HwDeviceExtension)
 
VP_STATUS NTAPI VgaInterpretCmdStream (PHW_DEVICE_EXTENSION HwDeviceExtension, PUSHORT pusCmdStream)
 
VP_STATUS NTAPI VgaSetPaletteReg (PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_PALETTE_DATA PaletteBuffer, ULONG PaletteBufferSize)
 
VP_STATUS NTAPI VgaSetColorLookup (PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_CLUT ClutBuffer, ULONG ClutBufferSize)
 
VP_STATUS NTAPI GetDeviceDataCallback (PVOID HwDeviceExtension, PVOID Context, VIDEO_DEVICE_DATA_TYPE DeviceDataType, PVOID Identifier, ULONG IdentifierLength, PVOID ConfigurationData, ULONG ConfigurationDataLength, PVOID ComponentInformation, ULONG ComponentInformationLength)
 
VP_STATUS NTAPI VgaAcquireResources (PHW_DEVICE_EXTENSION DeviceExtension)
 
ULONG NTAPI DriverEntry (PVOID Context1, PVOID Context2)
 

Function Documentation

◆ DriverEntry()

ULONG NTAPI DriverEntry ( PVOID  Context1,
PVOID  Context2 
)

Definition at line 153 of file vga.c.

179 {
180 
181  VIDEO_HW_INITIALIZATION_DATA hwInitData;
182  ULONG status;
183  ULONG initializationStatus = (ULONG) -1;
184 
185  //
186  // Zero out structure.
187  //
188 
190 
191  //
192  // Specify sizes of structure and extension.
193  //
194 
195  hwInitData.HwInitDataSize = sizeof(VIDEO_HW_INITIALIZATION_DATA);
196 
197  //
198  // Set entry points.
199  //
200 
201  hwInitData.HwFindAdapter = VgaFindAdapter;
202  hwInitData.HwInitialize = VgaInitialize;
203  hwInitData.HwInterrupt = NULL;
204  hwInitData.HwStartIO = VgaStartIO;
205 
206  //
207  // Determine the size we require for the device extension.
208  //
209 
210  hwInitData.HwDeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);
211 
212  //
213  // Always start with parameters for device0 in this case.
214  // We can leave it like this since we know we will only ever find one
215  // VGA type adapter in a machine.
216  //
217 
218  // hwInitData.StartingDeviceNumber = 0;
219 
220  //
221  // Once all the relevant information has been stored, call the video
222  // port driver to do the initialization.
223  // For this device we will repeat this call three times, for ISA, EISA
224  // and PCI.
225  // We will return the minimum of all return values.
226  //
227 
228  //
229  // We will try the PCI bus first so that our ISA detection does'nt claim
230  // PCI cards (since it is impossible to differentiate between the two
231  // by looking at the registers).
232  //
233 
234  //
235  // NOTE: since this driver only supports one adapter, we will return
236  // as soon as we find a device, without going on to the following buses.
237  // Normally one would call for each bus type and return the smallest
238  // value.
239  //
240 
241 #if !defined(_ALPHA_)
242 
243  //
244  // Before we can enable this on ALPHA we need to find a way to map a
245  // sparse view of a 4MB region successfully.
246  //
247 
248  hwInitData.AdapterInterfaceType = PCIBus;
249 
250  initializationStatus = VideoPortInitialize(Context1,
251  Context2,
252  &hwInitData,
253  NULL);
254 
255  if (initializationStatus == NO_ERROR)
256  {
257  return initializationStatus;
258  }
259 
260 #endif
261 
262  hwInitData.AdapterInterfaceType = MicroChannel;
263 
264  initializationStatus = VideoPortInitialize(Context1,
265  Context2,
266  &hwInitData,
267  NULL);
268 
269  //
270  // Return immediately instead of checkin for smallest return code.
271  //
272 
273  if (initializationStatus == NO_ERROR)
274  {
275  return initializationStatus;
276  }
277 
278 
279  hwInitData.AdapterInterfaceType = Internal;
280 
281  initializationStatus = VideoPortInitialize(Context1,
282  Context2,
283  &hwInitData,
284  NULL);
285 
286  if (initializationStatus == NO_ERROR)
287  {
288  return initializationStatus;
289  }
290 
291 
292  hwInitData.AdapterInterfaceType = Isa;
293 
294  initializationStatus = VideoPortInitialize(Context1,
295  Context2,
296  &hwInitData,
297  NULL);
298 
299  if (initializationStatus == NO_ERROR)
300  {
301  return initializationStatus;
302  }
303 
304 
305 
306  hwInitData.AdapterInterfaceType = Eisa;
307 
309  Context2,
310  &hwInitData,
311  NULL);
312 
313  if (initializationStatus > status) {
314  initializationStatus = status;
315  }
316 
317  return initializationStatus;
318 
319 } // end DriverEntry()
INTERFACE_TYPE AdapterInterfaceType
Definition: video.h:665
VPAPI ULONG NTAPI VideoPortInitialize(IN PVOID Argument1, IN PVOID Argument2, IN PVIDEO_HW_INITIALIZATION_DATA HwInitializationData, IN PVOID HwContext)
Definition: videoprt.c:455
#define NO_ERROR
Definition: dderror.h:5
VPAPI VOID NTAPI VideoPortZeroMemory(IN PVOID Destination, IN ULONG Length)
PVIDEO_HW_START_IO HwStartIO
Definition: video.h:669
struct _HW_DEVICE_EXTENSION HW_DEVICE_EXTENSION
smooth NULL
Definition: ftsmooth.c:416
struct _VIDEO_HW_INITIALIZATION_DATA VIDEO_HW_INITIALIZATION_DATA
PVIDEO_HW_INITIALIZE HwInitialize
Definition: video.h:667
BOOLEAN NTAPI VgaStartIO(PVOID HwDeviceExtension, PVIDEO_REQUEST_PACKET RequestPacket)
Definition: vga.c:550
PVIDEO_HW_FIND_ADAPTER HwFindAdapter
Definition: video.h:666
VP_STATUS NTAPI VgaFindAdapter(PVOID HwDeviceExtension, PVOID HwContext, PWSTR ArgumentString, PVIDEO_PORT_CONFIG_INFO ConfigInfo, PUCHAR Again)
Definition: vga.c:324
BOOLEAN NTAPI VgaInitialize(PVOID HwDeviceExtension)
Definition: vga.c:507
PVIDEO_HW_INTERRUPT HwInterrupt
Definition: video.h:668
_In_ PNET_PNP_EVENT _In_ PTDI_PNP_CONTEXT _In_ PTDI_PNP_CONTEXT Context2
Definition: tdikrnl.h:1094
_In_ PNET_PNP_EVENT _In_ PTDI_PNP_CONTEXT Context1
Definition: tdikrnl.h:1094
unsigned int ULONG
Definition: retypes.h:1
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ GetDeviceDataCallback()

VP_STATUS NTAPI GetDeviceDataCallback ( PVOID  HwDeviceExtension,
PVOID  Context,
VIDEO_DEVICE_DATA_TYPE  DeviceDataType,
PVOID  Identifier,
ULONG  IdentifierLength,
PVOID  ConfigurationData,
ULONG  ConfigurationDataLength,
PVOID  ComponentInformation,
ULONG  ComponentInformationLength 
)

Definition at line 1462 of file vga.c.

1512 {
1513  VideoDebugPrint((Error, "Detected internal VGA chip on embedded board, todo\n"));
1514  while (TRUE);
1515  return NO_ERROR;
1516 
1517 } //end GetDeviceDataCallback()
#define TRUE
Definition: types.h:120
#define NO_ERROR
Definition: dderror.h:5
BOOL Error
Definition: chkdsk.c:66
#define VideoDebugPrint(x)
Definition: video.h:75

Referenced by VgaFindAdapter().

◆ VgaAcquireResources()

VP_STATUS NTAPI VgaAcquireResources ( PHW_DEVICE_EXTENSION  DeviceExtension)

Definition at line 1522 of file vga.c.

1525 {
1527  ULONG Ranges, i;
1528 
1529  //
1530  // Try exclusive ranges (vga + ati)
1531  //
1532 
1533  Ranges = NUM_VGA_ACCESS_RANGES;
1534  for (i = 0; i < Ranges; i++) VgaAccessRange[i].RangeShareable = FALSE;
1535  if (VideoPortVerifyAccessRanges(DeviceExtension, Ranges, VgaAccessRange) != NO_ERROR)
1536  {
1537  //
1538  // Not worked, try vga only
1539  //
1540 
1541  Ranges = 3;
1542  if (VideoPortVerifyAccessRanges(DeviceExtension, Ranges, VgaAccessRange) != NO_ERROR)
1543  {
1544  //
1545  // Still not, try shared ranges
1546  //
1547 
1548  for (i = 0; i < Ranges; i++) VgaAccessRange[i].RangeShareable = TRUE;
1549  Status = VideoPortVerifyAccessRanges(DeviceExtension, Ranges, VgaAccessRange);
1550  if (Status == NO_ERROR)
1551  {
1552  //
1553  // It did work
1554  //
1555 
1556  VideoPortVerifyAccessRanges(DeviceExtension, 0, 0);
1557  Status = NO_ERROR;
1558  }
1559  }
1560  }
1561 
1562  if (Status == NO_ERROR)
1563  {
1564  //
1565  // Worked with exclusive, also try shared
1566  //
1567 
1568  for (i = 0; i < Ranges; i++) VgaAccessRange[i].RangeShareable = TRUE;
1569  Status = VideoPortVerifyAccessRanges(DeviceExtension, Ranges, VgaAccessRange);
1570  }
1571 
1572  return Status;
1573 }
#define TRUE
Definition: types.h:120
#define NO_ERROR
Definition: dderror.h:5
#define NUM_VGA_ACCESS_RANGES
Definition: vga.h:444
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
VIDEO_ACCESS_RANGE VgaAccessRange[]
Definition: vgadata.c:16
Status
Definition: gdiplustypes.h:24
VPAPI VP_STATUS NTAPI VideoPortVerifyAccessRanges(IN PVOID HwDeviceExtension, IN ULONG NumAccessRanges, IN PVIDEO_ACCESS_RANGE AccessRanges)
Definition: resource.c:816
unsigned int ULONG
Definition: retypes.h:1
LONG VP_STATUS
Definition: video.h:153

Referenced by VgaFindAdapter().

◆ VgaFindAdapter()

VP_STATUS NTAPI VgaFindAdapter ( PVOID  HwDeviceExtension,
PVOID  HwContext,
PWSTR  ArgumentString,
PVIDEO_PORT_CONFIG_INFO  ConfigInfo,
PUCHAR  Again 
)

Definition at line 324 of file vga.c.

379 {
380 
381  PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
382 
383  //
384  // Make sure the size of the structure is at least as large as what we
385  // are expecting (check version of the config info structure).
386  //
387 
388  if (ConfigInfo->Length < sizeof(VIDEO_PORT_CONFIG_INFO)) {
389 
391 
392  }
393 // eVb: 1.4 [CIRRUS] - Remove CIRRUS-specific support
394  //
395  // Check internal VGA (MIPS and ARM systems)
396  //
397 
398  if ((ConfigInfo->AdapterInterfaceType == Internal) &&
399  (VideoPortGetDeviceData(HwDeviceExtension,
403  {
405  }
406 // eVb: 1.4 [END]
407  //
408  // No interrupt information is necessary.
409  //
410 
411  //
412  // Check to see if there is a hardware resource conflict.
413  //
414 // eVb: 1.5 [RESOURCE] - Use new function for acquiring VGA resources (I/O, memory)
415  if (VgaAcquireResources(hwDeviceExtension) != NO_ERROR) return ERROR_INVALID_PARAMETER;
416 // eVb: 1.5 [END]
417  //
418  // Get logical IO port addresses.
419  //
420 
421  if ((hwDeviceExtension->IOAddress =
422  VideoPortGetDeviceBase(hwDeviceExtension,
426  {
427  VideoDebugPrint((0, "VgaFindAdapter - Fail to get io address\n"));
428 
430  }
431 
432  //
433  // Determine whether a VGA is present.
434  //
435 
436  if (!VgaIsPresent(hwDeviceExtension)) {
437 
438  VideoDebugPrint((0, "VgaFindAdapter - VGA Failed\n"));
439  return ERROR_DEV_NOT_EXIST;
440  }
441 
442  //
443  // Minimum size of the buffer required to store the hardware state
444  // information returned by IOCTL_VIDEO_SAVE_HARDWARE_STATE.
445  //
446 
448 
449  //
450  // Pass a pointer to the emulator range we are using.
451  //
452 // eVb: 1.6 [VDM] - Disable VDM for now
453  ConfigInfo->NumEmulatorAccessEntries = 0;
454  ConfigInfo->EmulatorAccessEntries = NULL;
455  ConfigInfo->EmulatorAccessEntriesContext = 0;
456 // eVb: 1.6 [END]
457  //
458  // BUGBUG
459  //
460  // There is really no reason to have the frame buffer mapped. On an
461  // x86 we use if for save/restore (supposedly) but even then we
462  // would only need to map a 64K window, not all 16 Meg!
463  //
464 
465 #ifdef _X86_
466 
467  //
468  // Map the video memory into the system virtual address space so we can
469  // clear it out and use it for save and restore.
470  //
471 
472  if ( (hwDeviceExtension->VideoMemoryAddress =
473  VideoPortGetDeviceBase(hwDeviceExtension,
474  VgaAccessRange[2].RangeStart,
475  VgaAccessRange[2].RangeLength,
476  FALSE)) == NULL)
477  {
478  VideoDebugPrint((0, "VgaFindAdapter - Fail to get memory address\n"));
479 
481  }
482 
483  VideoDebugPrint((0, "vga mapped at %x\n", hwDeviceExtension->VideoMemoryAddress));
484 #endif
485 // eVb: 1.7 [VDM] - Disable VDM for now
486  ConfigInfo->VdmPhysicalVideoMemoryAddress.QuadPart = 0;
487  ConfigInfo->VdmPhysicalVideoMemoryLength = 0;
488 // eVb: 1.7 [END]
489  //
490  // Indicate we do not wish to be called again for another initialization.
491  //
492 
493  *Again = 0;
494 
495  //
496  // Indicate a successful completion status.
497  //
498 
499  return NO_ERROR;
500 
501 
502 } // VgaFindAdapter()
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
PUCHAR IOAddress
Definition: vga.h:401
#define VGA_BASE_IO_PORT
Definition: vga.h:42
ULONG NumEmulatorAccessEntries
Definition: video.h:173
VPAPI PVOID NTAPI VideoPortGetDeviceBase(IN PVOID HwDeviceExtension, IN PHYSICAL_ADDRESS IoAddress, IN ULONG NumberOfUchars, IN UCHAR InIoSpace)
Definition: resource.c:450
#define NO_ERROR
Definition: dderror.h:5
INTERFACE_TYPE AdapterInterfaceType
Definition: video.h:169
#define VGA_MAX_IO_PORT
Definition: vga.h:45
PEMULATOR_ACCESS_ENTRY EmulatorAccessEntries
Definition: video.h:174
ULONG_PTR EmulatorAccessEntriesContext
Definition: video.h:175
VPAPI VP_STATUS NTAPI VideoPortGetDeviceData(IN PVOID HwDeviceExtension, IN VIDEO_DEVICE_DATA_TYPE DeviceDataType, IN PMINIPORT_QUERY_DEVICE_ROUTINE CallbackRoutine, IN PVOID Context)
Definition: resource.c:896
smooth NULL
Definition: ftsmooth.c:416
PHYSICAL_ADDRESS VdmPhysicalVideoMemoryAddress
Definition: video.h:176
VP_STATUS NTAPI GetDeviceDataCallback(PVOID HwDeviceExtension, PVOID Context, VIDEO_DEVICE_DATA_TYPE DeviceDataType, PVOID Identifier, ULONG IdentifierLength, PVOID ConfigurationData, ULONG ConfigurationDataLength, PVOID ComponentInformation, ULONG ComponentInformationLength)
Definition: vga.c:1462
VP_STATUS NTAPI VgaAcquireResources(PHW_DEVICE_EXTENSION DeviceExtension)
Definition: vga.c:1522
BOOLEAN NTAPI VgaIsPresent(PHW_DEVICE_EXTENSION HwDeviceExtension)
Definition: vga.c:940
UCHAR RangeInIoSpace
Definition: video.h:217
VIDEO_ACCESS_RANGE VgaAccessRange[]
Definition: vgadata.c:16
#define VideoDebugPrint(x)
Definition: video.h:75
PUCHAR VideoMemoryAddress
Definition: vga.h:402
#define VGA_TOTAL_STATE_SIZE
Definition: vga.h:385
#define ERROR_DEV_NOT_EXIST
Definition: dderror.h:8
ULONG VdmPhysicalVideoMemoryLength
Definition: video.h:177
LONGLONG QuadPart
Definition: typedefs.h:112
PHYSICAL_ADDRESS RangeStart
Definition: video.h:215

Referenced by DriverEntry().

◆ VgaInitialize()

BOOLEAN NTAPI VgaInitialize ( PVOID  HwDeviceExtension)

Definition at line 507 of file vga.c.

527 {
528  PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
529 
530  //
531  // set up the default cursor position and type.
532  //
533 
534  hwDeviceExtension->CursorPosition.Column = 0;
535  hwDeviceExtension->CursorPosition.Row = 0;
536  hwDeviceExtension->CursorTopScanLine = 0;
537  hwDeviceExtension->CursorBottomScanLine = 31;
538  hwDeviceExtension->CursorEnable = TRUE;
539 
540 // eVb: 1.8 [VBE] - Initialize VBE modes
541  InitializeModeTable(hwDeviceExtension);
542 // eVb: 1.8 [END]
543  return TRUE;
544 
545 } // VgaInitialize()
#define TRUE
Definition: types.h:120
VOID NTAPI InitializeModeTable(IN PHW_DEVICE_EXTENSION VgaExtension)
Definition: vbemodes.c:159
UCHAR CursorBottomScanLine
Definition: vga.h:411
UCHAR CursorTopScanLine
Definition: vga.h:410
VIDEO_CURSOR_POSITION CursorPosition
Definition: vga.h:407
UCHAR CursorEnable
Definition: vga.h:409

Referenced by DriverEntry().

◆ VgaInterpretCmdStream()

VP_STATUS NTAPI VgaInterpretCmdStream ( PHW_DEVICE_EXTENSION  HwDeviceExtension,
PUSHORT  pusCmdStream 
)

Definition at line 74 of file modeset.c.

100 {
101  ULONG ulCmd;
102  ULONG_PTR ulPort;
103  UCHAR jValue;
104  USHORT usValue;
105  ULONG culCount;
106  ULONG ulIndex;
107  ULONG_PTR ulBase;
108 
109  if (pusCmdStream == NULL) {
110 
111  VideoDebugPrint((1, "VgaInterpretCmdStream - Invalid pusCmdStream\n"));
112  return TRUE;
113  }
114 
115  ulBase = (ULONG_PTR)HwDeviceExtension->IOAddress;
116 
117  //
118  // Now set the adapter to the desired mode.
119  //
120 
121  while ((ulCmd = *pusCmdStream++) != EOD) {
122 
123  //
124  // Determine major command type
125  //
126 
127  switch (ulCmd & 0xF0) {
128 
129  //
130  // Basic input/output command
131  //
132 
133  case INOUT:
134 
135  //
136  // Determine type of inout instruction
137  //
138 
139  if (!(ulCmd & IO)) {
140 
141  //
142  // Out instruction. Single or multiple outs?
143  //
144 
145  if (!(ulCmd & MULTI)) {
146 
147  //
148  // Single out. Byte or word out?
149  //
150 
151  if (!(ulCmd & BW)) {
152 
153  //
154  // Single byte out
155  //
156 
157  ulPort = *pusCmdStream++;
158  jValue = (UCHAR) *pusCmdStream++;
159  VideoPortWritePortUchar((PUCHAR)(ulBase+ulPort),
160  jValue);
161 
162  } else {
163 
164  //
165  // Single word out
166  //
167 
168  ulPort = *pusCmdStream++;
169  usValue = *pusCmdStream++;
170  VideoPortWritePortUshort((PUSHORT)(ulBase+ulPort),
171  usValue);
172 
173  }
174 
175  } else {
176 
177  //
178  // Output a string of values
179  // Byte or word outs?
180  //
181 
182  if (!(ulCmd & BW)) {
183 
184  //
185  // String byte outs. Do in a loop; can't use
186  // VideoPortWritePortBufferUchar because the data
187  // is in USHORT form
188  //
189 
190  ulPort = ulBase + *pusCmdStream++;
191  culCount = *pusCmdStream++;
192 
193  while (culCount--) {
194  jValue = (UCHAR) *pusCmdStream++;
196  jValue);
197 
198  }
199 
200  } else {
201 
202  //
203  // String word outs
204  //
205 
206  ulPort = *pusCmdStream++;
207  culCount = *pusCmdStream++;
209  (ulBase + ulPort), pusCmdStream, culCount);
210  pusCmdStream += culCount;
211 
212  }
213  }
214 
215  } else {
216 
217  // In instruction
218  //
219  // Currently, string in instructions aren't supported; all
220  // in instructions are handled as single-byte ins
221  //
222  // Byte or word in?
223  //
224 
225  if (!(ulCmd & BW)) {
226  //
227  // Single byte in
228  //
229 
230  ulPort = *pusCmdStream++;
231  jValue = VideoPortReadPortUchar((PUCHAR)ulBase+ulPort);
232 
233  } else {
234 
235  //
236  // Single word in
237  //
238 
239  ulPort = *pusCmdStream++;
240  usValue = VideoPortReadPortUshort((PUSHORT)
241  (ulBase+ulPort));
242 
243  }
244 
245  }
246 
247  break;
248 
249  //
250  // Higher-level input/output commands
251  //
252 
253  case METAOUT:
254 
255  //
256  // Determine type of metaout command, based on minor
257  // command field
258  //
259  switch (ulCmd & 0x0F) {
260 
261  //
262  // Indexed outs
263  //
264 
265  case INDXOUT:
266 
267  ulPort = ulBase + *pusCmdStream++;
268  culCount = *pusCmdStream++;
269  ulIndex = *pusCmdStream++;
270 
271  while (culCount--) {
272 
273  usValue = (USHORT) (ulIndex +
274  (((ULONG)(*pusCmdStream++)) << 8));
275  VideoPortWritePortUshort((PUSHORT)ulPort, usValue);
276 
277  ulIndex++;
278 
279  }
280 
281  break;
282 
283  //
284  // Masked out (read, AND, XOR, write)
285  //
286 
287  case MASKOUT:
288 
289  ulPort = *pusCmdStream++;
290  jValue = VideoPortReadPortUchar((PUCHAR)ulBase+ulPort);
291  jValue &= *pusCmdStream++;
292  jValue ^= *pusCmdStream++;
293  VideoPortWritePortUchar((PUCHAR)ulBase + ulPort,
294  jValue);
295  break;
296 
297  //
298  // Attribute Controller out
299  //
300 
301  case ATCOUT:
302 
303  ulPort = ulBase + *pusCmdStream++;
304  culCount = *pusCmdStream++;
305  ulIndex = *pusCmdStream++;
306 
307  while (culCount--) {
308 
309  // Write Attribute Controller index
311  (UCHAR)ulIndex);
312 
313  // Write Attribute Controller data
314  jValue = (UCHAR) *pusCmdStream++;
315  VideoPortWritePortUchar((PUCHAR)ulPort, jValue);
316 
317  ulIndex++;
318 
319  }
320 
321  break;
322 
323  //
324  // None of the above; error
325  //
326  default:
327 
328  return FALSE;
329 
330  }
331 
332 
333  break;
334 
335  //
336  // NOP
337  //
338 
339  case NCMD:
340 
341  break;
342 
343  //
344  // Unknown command; error
345  //
346 
347  default:
348 
349  return FALSE;
350 
351  }
352 
353  }
354 
355  return TRUE;
356 
357 } // end VgaInterpretCmdStream()
PUCHAR IOAddress
Definition: vga.h:401
#define TRUE
Definition: types.h:120
VPAPI VOID NTAPI VideoPortWritePortBufferUshort(IN PUSHORT Port, IN PUSHORT Buffer, IN ULONG Count)
unsigned char * PUCHAR
Definition: retypes.h:3
#define METAOUT
Definition: cmdcnst.h:63
#define INOUT
Definition: cmdcnst.h:62
VPAPI USHORT NTAPI VideoPortReadPortUshort(IN PUSHORT Port)
#define EOD
Definition: cmdcnst.h:61
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define IO
Definition: cmdcnst.h:72
while(1)
Definition: macro.lex.yy.c:740
VPAPI UCHAR NTAPI VideoPortReadPortUchar(IN PUCHAR Port)
#define MASKOUT
Definition: cmdcnst.h:78
smooth NULL
Definition: ftsmooth.c:416
VPAPI VOID NTAPI VideoPortWritePortUshort(IN PUSHORT Port, IN USHORT Value)
#define BW
Definition: cmdcnst.h:71
#define NCMD
Definition: cmdcnst.h:64
unsigned char UCHAR
Definition: xmlstorage.h:181
#define ATCOUT
Definition: cmdcnst.h:77
ULONG ulIndex
Definition: symbols.c:92
#define VideoDebugPrint(x)
Definition: video.h:75
unsigned short USHORT
Definition: pedump.c:61
#define MULTI
Definition: cmdcnst.h:70
#define INDXOUT
Definition: cmdcnst.h:76
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
VPAPI VOID NTAPI VideoPortWritePortUchar(IN PUCHAR Port, IN UCHAR Value)
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by VgaSetMode(), and VgaZeroVideoMemory().

◆ VgaIsPresent()

BOOLEAN NTAPI VgaIsPresent ( PHW_DEVICE_EXTENSION  HwDeviceExtension)

Definition at line 940 of file vga.c.

989 {
990  UCHAR originalGCAddr;
991  UCHAR originalSCAddr;
992  UCHAR originalBitMask;
993  UCHAR originalReadMap;
994  UCHAR originalMemoryMode;
995  UCHAR testMask;
996  BOOLEAN returnStatus;
997 
998  //
999  // Remember the original state of the Graphics Controller Address register.
1000  //
1001 
1002  originalGCAddr = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1004 
1005  //
1006  // Write the Read Map register with a known state so we can verify
1007  // that it isn't changed after we fool with the Bit Mask. This ensures
1008  // that we're dealing with indexed registers, since both the Read Map and
1009  // the Bit Mask are addressed at GRAPH_DATA_PORT.
1010  //
1011 
1012  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1014 
1015  //
1016  // If we can't read back the Graphics Address register setting we just
1017  // performed, it's not readable and this isn't a VGA.
1018  //
1019 
1020  if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1022 
1023  return FALSE;
1024  }
1025 
1026  //
1027  // Set the Read Map register to a known state.
1028  //
1029 
1030  originalReadMap = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1031  GRAPH_DATA_PORT);
1032  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1034 
1035  if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1037 
1038  //
1039  // The Read Map setting we just performed can't be read back; not a
1040  // VGA. Restore the default Read Map state.
1041  //
1042 
1043  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1045 
1046  return FALSE;
1047  }
1048 
1049  //
1050  // Remember the original setting of the Bit Mask register.
1051  //
1052 
1053  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1055  if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1057 
1058  //
1059  // The Graphics Address register setting we just made can't be read
1060  // back; not a VGA. Restore the default Read Map state.
1061  //
1062 
1063  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1065  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1067 
1068  return FALSE;
1069  }
1070 
1071  originalBitMask = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1072  GRAPH_DATA_PORT);
1073 
1074  //
1075  // Set up the initial test mask we'll write to and read from the Bit Mask.
1076  //
1077 
1078  testMask = 0xBB;
1079 
1080  do {
1081 
1082  //
1083  // Write the test mask to the Bit Mask.
1084  //
1085 
1086  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1087  GRAPH_DATA_PORT, testMask);
1088 
1089  //
1090  // Make sure the Bit Mask remembered the value.
1091  //
1092 
1093  if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1094  GRAPH_DATA_PORT) != testMask) {
1095 
1096  //
1097  // The Bit Mask is not properly writable and readable; not a VGA.
1098  // Restore the Bit Mask and Read Map to their default states.
1099  //
1100 
1101  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1103  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1105  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1107 
1108  return FALSE;
1109  }
1110 
1111  //
1112  // Cycle the mask for next time.
1113  //
1114 
1115  testMask >>= 1;
1116 
1117  } while (testMask != 0);
1118 
1119  //
1120  // There's something readable at GRAPH_DATA_PORT; now switch back and
1121  // make sure that the Read Map register hasn't changed, to verify that
1122  // we're dealing with indexed registers.
1123  //
1124 
1125  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1127  if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1129 
1130  //
1131  // The Read Map is not properly writable and readable; not a VGA.
1132  // Restore the Bit Mask and Read Map to their default states, in case
1133  // this is an EGA, so subsequent writes to the screen aren't garbled.
1134  //
1135 
1136  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1138  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1140  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1142 
1143  return FALSE;
1144  }
1145 
1146  //
1147  // We've pretty surely verified the existence of the Bit Mask register.
1148  // Put the Graphics Controller back to the original state.
1149  //
1150 
1151  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1152  GRAPH_DATA_PORT, originalReadMap);
1153  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1155  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1156  GRAPH_DATA_PORT, originalBitMask);
1157  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1158  GRAPH_ADDRESS_PORT, originalGCAddr);
1159 
1160  //
1161  // Now, check for the existence of the Chain4 bit.
1162  //
1163 
1164  //
1165  // Remember the original states of the Sequencer Address and Memory Mode
1166  // registers.
1167  //
1168 
1169  originalSCAddr = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1171  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1173  if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1175 
1176  //
1177  // Couldn't read back the Sequencer Address register setting we just
1178  // performed.
1179  //
1180 
1181  return FALSE;
1182  }
1183  originalMemoryMode = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1184  SEQ_DATA_PORT);
1185 
1186  //
1187  // Toggle the Chain4 bit and read back the result. This must be done during
1188  // sync reset, since we're changing the chaining state.
1189  //
1190 
1191  //
1192  // Begin sync reset.
1193  //
1194 
1195  VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
1198 
1199  //
1200  // Toggle the Chain4 bit.
1201  //
1202 
1203  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1205  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1206  SEQ_DATA_PORT, (UCHAR)(originalMemoryMode ^ CHAIN4_MASK));
1207 
1208  if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1209  SEQ_DATA_PORT) != (UCHAR) (originalMemoryMode ^ CHAIN4_MASK)) {
1210 
1211  //
1212  // Chain4 bit not there; not a VGA.
1213  // Set text mode default for Memory Mode register.
1214  //
1215 
1216  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1218  //
1219  // End sync reset.
1220  //
1221 
1222  VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
1225 
1226  returnStatus = FALSE;
1227 
1228  } else {
1229 
1230  //
1231  // It's a VGA.
1232  //
1233 
1234  //
1235  // Restore the original Memory Mode setting.
1236  //
1237 
1238  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1239  SEQ_DATA_PORT, originalMemoryMode);
1240 
1241  //
1242  // End sync reset.
1243  //
1244 
1245  VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
1248 
1249  //
1250  // Restore the original Sequencer Address setting.
1251  //
1252 
1253  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1254  SEQ_ADDRESS_PORT, originalSCAddr);
1255 
1256  returnStatus = TRUE;
1257  }
1258 
1259  return returnStatus;
1260 
1261 } // VgaIsPresent()
PUCHAR IOAddress
Definition: vga.h:401
#define END_SYNC_RESET_VALUE
Definition: vga.h:157
#define TRUE
Definition: types.h:120
#define GRAPH_ADDRESS_PORT
Definition: vga.h:85
#define START_SYNC_RESET_VALUE
Definition: vga.h:155
#define IND_READ_MAP
Definition: vga.h:143
#define GRAPH_DATA_PORT
Definition: vga.h:86
#define READ_MAP_TEST_SETTING
Definition: vga.h:204
VPAPI UCHAR NTAPI VideoPortReadPortUchar(IN PUCHAR Port)
#define READ_MAP_DEFAULT
Definition: vga.h:213
#define SEQ_DATA_PORT
Definition: vga.h:74
#define IND_SYNC_RESET
Definition: vga.h:147
unsigned char BOOLEAN
VPAPI VOID NTAPI VideoPortWritePortUshort(IN PUSHORT Port, IN USHORT Value)
#define BIT_MASK_DEFAULT
Definition: vga.h:212
#define MEMORY_MODE_TEXT_DEFAULT
Definition: vga.h:211
#define SEQ_ADDRESS_PORT
Definition: vga.h:73
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IND_BIT_MASK
Definition: vga.h:146
#define IND_MEMORY_MODE
Definition: vga.h:149
unsigned short USHORT
Definition: pedump.c:61
#define GRAPH_ADDR_MASK
Definition: vga.h:189
#define SEQ_ADDR_MASK
Definition: vga.h:190
VPAPI VOID NTAPI VideoPortWritePortUchar(IN PUCHAR Port, IN UCHAR Value)
#define CHAIN4_MASK
Definition: vga.h:196
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by VgaFindAdapter().

◆ VgaQueryAvailableModes()

VP_STATUS NTAPI VgaQueryAvailableModes ( PHW_DEVICE_EXTENSION  HwDeviceExtension,
PVIDEO_MODE_INFORMATION  ModeInformation,
ULONG  ModeInformationSize,
PULONG_PTR  OutputSize 
)

Definition at line 517 of file modeset.c.

553 {
554  PVIDEO_MODE_INFORMATION videoModes = ModeInformation;
555  ULONG i;
556 
557  //
558  // Find out the size of the data to be put in the buffer and return
559  // that in the status information (whether or not the information is
560  // there). If the buffer passed in is not large enough return an
561  // appropriate error code.
562  //
563 
564  if (ModeInformationSize < (*OutputSize =
565 // eVb: 2.10 [VBE] - We store VBE/VGA mode count in this global, not in DevExt like Cirrus
566  NumVideoModes *
567 // eVb: 2.10 [END]
568  sizeof(VIDEO_MODE_INFORMATION)) ) {
569 
571 
572  }
573 
574  //
575  // For each mode supported by the card, store the mode characteristics
576  // in the output buffer.
577  //
578 
579  for (i = 0; i < NumVideoModes; i++)
580  {
581  videoModes->Length = sizeof(VIDEO_MODE_INFORMATION);
582  videoModes->ModeIndex = i;
583 // eVb: 2.11 [VBE] - Use dynamic VBE mode list instead of hard-coded VGA list
584  videoModes->VisScreenWidth = VgaModeList[i].hres;
585  videoModes->ScreenStride = VgaModeList[i].wbytes;
586  videoModes->VisScreenHeight = VgaModeList[i].vres;
587  videoModes->NumberOfPlanes = VgaModeList[i].numPlanes;
588  videoModes->BitsPerPlane = VgaModeList[i].bitsPerPlane;
589  videoModes->Frequency = VgaModeList[i].Frequency;
590  videoModes->XMillimeter = 320; // temporary hardcoded constant
591  videoModes->YMillimeter = 240; // temporary hardcoded constant
592  videoModes->AttributeFlags = VgaModeList[i].fbType;
593 // eVb: 2.11 [END]
594 
595  if ((VgaModeList[i].bitsPerPlane == 32) ||
596  (VgaModeList[i].bitsPerPlane == 24))
597  {
598 
599  videoModes->NumberRedBits = 8;
600  videoModes->NumberGreenBits = 8;
601  videoModes->NumberBlueBits = 8;
602  videoModes->RedMask = 0xff0000;
603  videoModes->GreenMask = 0x00ff00;
604  videoModes->BlueMask = 0x0000ff;
605 
606  }
607  else if (VgaModeList[i].bitsPerPlane == 16)
608  {
609 
610  videoModes->NumberRedBits = 6;
611  videoModes->NumberGreenBits = 6;
612  videoModes->NumberBlueBits = 6;
613  videoModes->RedMask = 0x1F << 11;
614  videoModes->GreenMask = 0x3F << 5;
615  videoModes->BlueMask = 0x1F;
616 
617  }
618 // eVb: 2.12 [VGA] - Add support for 15bpp modes, which Cirrus doesn't support
619  else if (VgaModeList[i].bitsPerPlane == 15)
620  {
621 
622  videoModes->NumberRedBits = 6;
623  videoModes->NumberGreenBits = 6;
624  videoModes->NumberBlueBits = 6;
625  videoModes->RedMask = 0x3E << 9;
626  videoModes->GreenMask = 0x1F << 5;
627  videoModes->BlueMask = 0x1F;
628  }
629 // eVb: 2.12 [END]
630  else
631  {
632 
633  videoModes->NumberRedBits = 6;
634  videoModes->NumberGreenBits = 6;
635  videoModes->NumberBlueBits = 6;
636  videoModes->RedMask = 0;
637  videoModes->GreenMask = 0;
638  videoModes->BlueMask = 0;
639  }
640 
641 // eVb: 2.13 [VGA] - All modes are palette managed/driven, unlike Cirrus
644 // eVb: 2.13 [END]
645  videoModes++;
646 
647  }
648 
649  return NO_ERROR;
650 
651 } // end VgaGetAvailableModes()
USHORT vres
Definition: vga.h:259
ULONG NumVideoModes
Definition: vgadata.c:433
#define VIDEO_MODE_MANAGED_PALETTE
Definition: ntddvdeo.h:296
ULONG Frequency
Definition: vga.h:261
USHORT numPlanes
Definition: vga.h:254
USHORT hres
Definition: vga.h:258
#define NO_ERROR
Definition: dderror.h:5
PVIDEOMODE VgaModeList
Definition: vgadata.c:434
USHORT bitsPerPlane
Definition: vga.h:255
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
USHORT fbType
Definition: vga.h:252
USHORT wbytes
Definition: vga.h:263
#define VIDEO_MODE_PALETTE_DRIVEN
Definition: ntddvdeo.h:295
unsigned int ULONG
Definition: retypes.h:1
struct _VIDEO_MODE_INFORMATION VIDEO_MODE_INFORMATION
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by VgaStartIO().

◆ VgaQueryCurrentMode()

VP_STATUS NTAPI VgaQueryCurrentMode ( PHW_DEVICE_EXTENSION  HwDeviceExtension,
PVIDEO_MODE_INFORMATION  ModeInformation,
ULONG  ModeInformationSize,
PULONG_PTR  OutputSize 
)

Definition at line 719 of file modeset.c.

754 {
755  //
756  // check if a mode has been set
757  //
758 
759  if (HwDeviceExtension->CurrentMode == NULL ) {
760 
761  return ERROR_INVALID_FUNCTION;
762 
763  }
764 
765  //
766  // Find out the size of the data to be put in the the buffer and return
767  // that in the status information (whether or not the information is
768  // there). If the buffer passed in is not large enough return an
769  // appropriate error code.
770  //
771 
772  if (ModeInformationSize < (*OutputSize = sizeof(VIDEO_MODE_INFORMATION))) {
773 
775 
776  }
777 
778  //
779  // Store the characteristics of the current mode into the buffer.
780  //
781 
782  ModeInformation->Length = sizeof(VIDEO_MODE_INFORMATION);
783  ModeInformation->ModeIndex = HwDeviceExtension->ModeIndex;
784  ModeInformation->VisScreenWidth = HwDeviceExtension->CurrentMode->hres;
785  ModeInformation->ScreenStride = HwDeviceExtension->CurrentMode->wbytes;
786  ModeInformation->VisScreenHeight = HwDeviceExtension->CurrentMode->vres;
787  ModeInformation->NumberOfPlanes = HwDeviceExtension->CurrentMode->numPlanes;
788  ModeInformation->BitsPerPlane = HwDeviceExtension->CurrentMode->bitsPerPlane;
789  ModeInformation->Frequency = HwDeviceExtension->CurrentMode->Frequency;
790  ModeInformation->XMillimeter = 320; // temporary hardcoded constant
791  ModeInformation->YMillimeter = 240; // temporary hardcoded constant
792 
793  ModeInformation->AttributeFlags = HwDeviceExtension->CurrentMode->fbType;
794 
795  if ((ModeInformation->BitsPerPlane == 32) ||
796  (ModeInformation->BitsPerPlane == 24))
797  {
798 
799  ModeInformation->NumberRedBits = 8;
800  ModeInformation->NumberGreenBits = 8;
801  ModeInformation->NumberBlueBits = 8;
802  ModeInformation->RedMask = 0xff0000;
803  ModeInformation->GreenMask = 0x00ff00;
804  ModeInformation->BlueMask = 0x0000ff;
805 
806  }
807  else if (ModeInformation->BitsPerPlane == 16)
808  {
809 
810  ModeInformation->NumberRedBits = 6;
811  ModeInformation->NumberGreenBits = 6;
812  ModeInformation->NumberBlueBits = 6;
813  ModeInformation->RedMask = 0x1F << 11;
814  ModeInformation->GreenMask = 0x3F << 5;
815  ModeInformation->BlueMask = 0x1F;
816 
817  }
818 // eVb: 2.12 [VGA] - Add support for 15bpp modes, which Cirrus doesn't support
819  else if (ModeInformation->BitsPerPlane == 15)
820  {
821 
822  ModeInformation->NumberRedBits = 6;
823  ModeInformation->NumberGreenBits = 6;
824  ModeInformation->NumberBlueBits = 6;
825  ModeInformation->RedMask = 0x3E << 9;
826  ModeInformation->GreenMask = 0x1F << 5;
827  ModeInformation->BlueMask = 0x1F;
828  }
829 // eVb: 2.12 [END]
830  else
831  {
832 
833  ModeInformation->NumberRedBits = 6;
834  ModeInformation->NumberGreenBits = 6;
835  ModeInformation->NumberBlueBits = 6;
836  ModeInformation->RedMask = 0;
837  ModeInformation->GreenMask = 0;
838  ModeInformation->BlueMask = 0;
839  }
840 
841 // eVb: 2.13 [VGA] - All modes are palette managed/driven, unlike Cirrus
842  ModeInformation->AttributeFlags |= VIDEO_MODE_PALETTE_DRIVEN |
844 // eVb: 2.13 [END]
845 
846  return NO_ERROR;
847 
848 } // end VgaQueryCurrentMode()
USHORT vres
Definition: vga.h:259
#define VIDEO_MODE_MANAGED_PALETTE
Definition: ntddvdeo.h:296
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
ULONG Frequency
Definition: vga.h:261
USHORT numPlanes
Definition: vga.h:254
USHORT hres
Definition: vga.h:258
#define NO_ERROR
Definition: dderror.h:5
USHORT bitsPerPlane
Definition: vga.h:255
PVIDEOMODE CurrentMode
Definition: vga.h:404
USHORT fbType
Definition: vga.h:252
smooth NULL
Definition: ftsmooth.c:416
ULONG ModeIndex
Definition: vga.h:403
USHORT wbytes
Definition: vga.h:263
#define VIDEO_MODE_PALETTE_DRIVEN
Definition: ntddvdeo.h:295
struct _VIDEO_MODE_INFORMATION VIDEO_MODE_INFORMATION
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by VgaStartIO().

◆ VgaQueryNumberOfAvailableModes()

VP_STATUS NTAPI VgaQueryNumberOfAvailableModes ( PHW_DEVICE_EXTENSION  HwDeviceExtension,
PVIDEO_NUM_MODES  NumModes,
ULONG  NumModesSize,
PULONG_PTR  OutputSize 
)

Definition at line 655 of file modeset.c.

690 {
691  //
692  // Find out the size of the data to be put in the the buffer and return
693  // that in the status information (whether or not the information is
694  // there). If the buffer passed in is not large enough return an
695  // appropriate error code.
696  //
697 
698  if (NumModesSize < (*OutputSize = sizeof(VIDEO_NUM_MODES)) ) {
699 
701 
702  }
703 
704  //
705  // Store the number of modes into the buffer.
706  //
707 
708 // eVb: 2.14 [VBE] - We store VBE/VGA mode count in this global, not in DevExt like Cirrus
709  NumModes->NumModes = NumVideoModes;
710 // eVb: 2.14 [END]
711  NumModes->ModeInformationLength = sizeof(VIDEO_MODE_INFORMATION);
712 
713  return NO_ERROR;
714 
715 } // end VgaGetNumberOfAvailableModes()
ULONG ModeInformationLength
Definition: ntddvdeo.h:328
ULONG NumVideoModes
Definition: vgadata.c:433
#define NO_ERROR
Definition: dderror.h:5
struct _VIDEO_MODE_INFORMATION VIDEO_MODE_INFORMATION
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by VgaStartIO().

◆ VgaSetColorLookup()

VP_STATUS NTAPI VgaSetColorLookup ( PHW_DEVICE_EXTENSION  HwDeviceExtension,
PVIDEO_CLUT  ClutBuffer,
ULONG  ClutBufferSize 
)

Definition at line 1356 of file vga.c.

1387 {
1388  PVIDEOMODE CurrentMode = HwDeviceExtension->CurrentMode;
1389  USHORT i;
1390 
1391  //
1392  // Check if the size of the data in the input buffer is large enough.
1393  //
1394 
1395  if ( (ClutBufferSize < sizeof(VIDEO_CLUT) - sizeof(ULONG)) ||
1396  (ClutBufferSize < sizeof(VIDEO_CLUT) +
1397  (sizeof(ULONG) * (ClutBuffer->NumEntries - 1)) ) ) {
1398 
1400 
1401  }
1402 
1403  //
1404  // Check to see if the parameters are valid.
1405  //
1406 
1407  if ( (ClutBuffer->NumEntries == 0) ||
1408  (ClutBuffer->FirstEntry > VIDEO_MAX_COLOR_REGISTER) ||
1409  (ClutBuffer->FirstEntry + ClutBuffer->NumEntries >
1410  VIDEO_MAX_COLOR_REGISTER + 1) ) {
1411 
1412  return ERROR_INVALID_PARAMETER;
1413 
1414  }
1415 // eVb: 1.14 [VBE] - Add VBE color support
1416  //
1417  // Check SVGA mode
1418  //
1419 
1420  if (CurrentMode->bitsPerPlane >= 8) return VbeSetColorLookup(HwDeviceExtension, ClutBuffer);
1421 // eVb: 1.14 [END]
1422  //
1423  // Path for VGA mode
1424  //
1425 // eVb: 1.15 [VBE] - Add VBE support for non-VGA-compatible detected modes
1426  if (!CurrentMode->NonVgaMode)
1427  {
1428 // eVb: 1.15 [END]
1429  //
1430  // Set CLUT registers directly on the hardware
1431  //
1432 
1433  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1434  DAC_ADDRESS_WRITE_PORT, (UCHAR) ClutBuffer->FirstEntry);
1435 
1436  for (i = 0; i < ClutBuffer->NumEntries; i++) {
1437  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1439  (UCHAR)(i + ClutBuffer->FirstEntry));
1440 
1441  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1443  ClutBuffer->LookupTable[i].RgbArray.Red);
1444 
1445  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1447  ClutBuffer->LookupTable[i].RgbArray.Green);
1448 
1449  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1451  ClutBuffer->LookupTable[i].RgbArray.Blue);
1452  }
1453  return NO_ERROR;
1454  }
1455 
1456  return ERROR_INVALID_PARAMETER;
1457 
1458 } // end VgaSetColorLookup()
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
PUCHAR IOAddress
Definition: vga.h:401
USHORT FirstEntry
Definition: ntddvdeo.h:520
ULONG NonVgaMode
Definition: vga.h:277
VIDEO_CLUTDATA RgbArray
Definition: ntddvdeo.h:522
#define NO_ERROR
Definition: dderror.h:5
#define VIDEO_MAX_COLOR_REGISTER
Definition: vga.h:224
USHORT bitsPerPlane
Definition: vga.h:255
Definition: vga.h:251
PVIDEOMODE CurrentMode
Definition: vga.h:404
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
#define DAC_DATA_REG_PORT
Definition: vga.h:81
USHORT NumEntries
Definition: ntddvdeo.h:519
unsigned char UCHAR
Definition: xmlstorage.h:181
#define DAC_ADDRESS_WRITE_PORT
Definition: vga.h:80
unsigned short USHORT
Definition: pedump.c:61
union VIDEO_CLUT::@3034 LookupTable[1]
unsigned int ULONG
Definition: retypes.h:1
VP_STATUS NTAPI VbeSetColorLookup(IN PHW_DEVICE_EXTENSION VgaExtension, IN PVIDEO_CLUT ClutBuffer)
Definition: vbe.c:141
VPAPI VOID NTAPI VideoPortWritePortUchar(IN PUCHAR Port, IN UCHAR Value)
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by VgaStartIO().

◆ VgaSetMode()

VP_STATUS NTAPI VgaSetMode ( PHW_DEVICE_EXTENSION  HwDeviceExtension,
PVIDEO_MODE  Mode,
ULONG  ModeSize,
PULONG  PhysPtrChange 
)

Definition at line 361 of file modeset.c.

396 {
397  PVIDEOMODE pRequestedMode;
399  ULONG RequestedModeNum;
400 // eVb: 2.3 [SET MODE] - Add new output parameter for framebuffer update functionality
401  *PhysPtrChange = FALSE;
402 // eVb: 2.3 [END]
403  //
404  // Check if the size of the data in the input buffer is large enough.
405  //
406 
407  if (ModeSize < sizeof(VIDEO_MODE))
408  {
410  }
411 
412  //
413  // Extract the clear memory, and map linear bits.
414  //
415 
416  RequestedModeNum = Mode->RequestedMode &
418 
419 
420  if (!(Mode->RequestedMode & VIDEO_MODE_NO_ZERO_MEMORY))
421  {
422 #if defined(_X86_)
423  VgaZeroVideoMemory(HwDeviceExtension);
424 #endif
425  }
426 
427  //
428  // Check to see if we are requesting a valid mode
429  //
430 // eVb: 2.4 [CIRRUS] - Remove Cirrus-specific check for valid mode
431  if ( (RequestedModeNum >= NumVideoModes) )
432 // eVb: 2.4 [END]
433  {
434  VideoDebugPrint((0, "Invalide Mode Number = %d!\n", RequestedModeNum));
435 
437  }
438 
439  VideoDebugPrint((2, "Attempting to set mode %d\n",
440  RequestedModeNum));
441 // eVb: 2.5 [VBE] - Use dynamic VBE mode list instead of hard-coded VGA list
442  pRequestedMode = &VgaModeList[RequestedModeNum];
443 // eVb: 2.5 [END]
444  VideoDebugPrint((2, "Info on Requested Mode:\n"
445  "\tResolution: %dx%d\n",
446  pRequestedMode->hres,
447  pRequestedMode->vres ));
448 
449  //
450  // VESA BIOS mode switch
451  //
452 // eVb: 2.6 [VBE] - VBE Mode Switch Support
453  status = VbeSetMode(HwDeviceExtension, pRequestedMode, PhysPtrChange);
455  {
456  //
457  // VGA mode switch
458  //
459 
460  if (!pRequestedMode->CmdStream) return ERROR_INVALID_FUNCTION;
461  if (!VgaInterpretCmdStream(HwDeviceExtension, pRequestedMode->CmdStream)) return ERROR_INVALID_FUNCTION;
462  goto Cleanup;
463  }
464  else if (status != NO_ERROR) return status;
465 // eVb: 2.6 [END]
466 // eVb: 2.7 [MODE-X] - Windows VGA Miniport Supports Mode-X, we should too
467  //
468  // ModeX check
469  //
470 
471  if (pRequestedMode->hres == 320)
472  {
473  VideoDebugPrint((0, "ModeX not support!!!\n"));
475  }
476 // eVb: 2.7 [END]
477  //
478  // Text mode check
479  //
480 
481  if (!(pRequestedMode->fbType & VIDEO_MODE_GRAPHICS))
482  {
483 // eVb: 2.8 [TODO] - This code path is not implemented yet
484  VideoDebugPrint((0, "Text-mode not support!!!\n"));
486 // eVb: 2.8 [END]
487  }
488 
489 Cleanup:
490  //
491  // Update the location of the physical frame buffer within video memory.
492  //
493 // eVb: 2.9 [VBE] - Linear and banked support is unified in VGA, unlike Cirrus
494  HwDeviceExtension->PhysicalVideoMemoryBase.LowPart = pRequestedMode->PhysBase;
495  HwDeviceExtension->PhysicalVideoMemoryLength = pRequestedMode->PhysSize;
496 
497  HwDeviceExtension->PhysicalFrameLength =
498  pRequestedMode->FrameBufferSize;
499 
500  HwDeviceExtension->PhysicalFrameOffset.LowPart =
501  pRequestedMode->FrameBufferBase;
502 // eVb: 2.9 [END]
503 
504  //
505  // Store the new mode value.
506  //
507 
508  HwDeviceExtension->CurrentMode = pRequestedMode;
509  HwDeviceExtension->ModeIndex = Mode->RequestedMode;
510 
511  return NO_ERROR;
512 
513 } //end VgaSetMode()
ULONG PhysSize
Definition: vga.h:275
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
USHORT vres
Definition: vga.h:259
ULONG NumVideoModes
Definition: vgadata.c:433
_In_ ULONG Mode
Definition: hubbusif.h:303
PUSHORT CmdStream
Definition: vga.h:269
ULONG PhysicalFrameLength
Definition: vga.h:398
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
ULONG FrameBufferSize
Definition: vga.h:274
ULONG FrameBufferBase
Definition: vga.h:273
#define VIDEO_MODE_NO_ZERO_MEMORY
Definition: ntddvdeo.h:286
ULONG PhysicalVideoMemoryLength
Definition: vga.h:397
USHORT hres
Definition: vga.h:258
PHYSICAL_ADDRESS PhysicalVideoMemoryBase
Definition: vga.h:395
#define NO_ERROR
Definition: dderror.h:5
PVIDEOMODE VgaModeList
Definition: vgadata.c:434
Definition: vga.h:251
PVIDEOMODE CurrentMode
Definition: vga.h:404
USHORT fbType
Definition: vga.h:252
ULONG PhysBase
Definition: vga.h:272
#define VIDEO_MODE_MAP_MEM_LINEAR
Definition: ntddvdeo.h:285
VP_STATUS NTAPI VgaInterpretCmdStream(PHW_DEVICE_EXTENSION HwDeviceExtension, PUSHORT pusCmdStream)
Definition: modeset.c:74
ULONG ModeIndex
Definition: vga.h:403
ULONG LowPart
Definition: typedefs.h:104
static const WCHAR Cleanup[]
Definition: register.c:80
#define VideoDebugPrint(x)
Definition: video.h:75
VOID NTAPI VgaZeroVideoMemory(PHW_DEVICE_EXTENSION HwDeviceExtension)
Definition: modeset.c:852
PHYSICAL_ADDRESS PhysicalFrameOffset
Definition: vga.h:396
unsigned int ULONG
Definition: retypes.h:1
LONG VP_STATUS
Definition: video.h:153
static SERVICE_STATUS status
Definition: service.c:31
VP_STATUS NTAPI VbeSetMode(IN PHW_DEVICE_EXTENSION VgaDeviceExtension, IN PVIDEOMODE VgaMode, OUT PULONG PhysPtrChange)
Definition: vbemodes.c:88
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define VIDEO_MODE_GRAPHICS
Definition: ntddvdeo.h:294
Definition: ps.c:97

Referenced by VgaStartIO().

◆ VgaSetPaletteReg()

VP_STATUS NTAPI VgaSetPaletteReg ( PHW_DEVICE_EXTENSION  HwDeviceExtension,
PVIDEO_PALETTE_DATA  PaletteBuffer,
ULONG  PaletteBufferSize 
)

Definition at line 1266 of file vga.c.

1297 {
1298  USHORT i;
1299 
1300  //
1301  // Check if the size of the data in the input buffer is large enough.
1302  //
1303 
1304  if ((PaletteBufferSize) < (sizeof(VIDEO_PALETTE_DATA)) ||
1305  (PaletteBufferSize < (sizeof(VIDEO_PALETTE_DATA) +
1306  (sizeof(USHORT) * (PaletteBuffer->NumEntries -1)) ))) {
1307 
1309 
1310  }
1311 
1312  //
1313  // Check to see if the parameters are valid.
1314  //
1315 
1316  if ( (PaletteBuffer->FirstEntry > VIDEO_MAX_COLOR_REGISTER ) ||
1317  (PaletteBuffer->NumEntries == 0) ||
1318  (PaletteBuffer->FirstEntry + PaletteBuffer->NumEntries >
1319  VIDEO_MAX_PALETTE_REGISTER + 1 ) ) {
1320 
1321  return ERROR_INVALID_PARAMETER;
1322 
1323  }
1324 
1325  //
1326  // Reset ATC to index mode
1327  //
1328 
1329  VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
1331 
1332  //
1333  // Blast out our palette values.
1334  //
1335 
1336  for (i = 0; i < PaletteBuffer->NumEntries; i++) {
1337 
1338  VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ATT_ADDRESS_PORT,
1339  (UCHAR)(i+PaletteBuffer->FirstEntry));
1340 
1341  VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
1343  (UCHAR)PaletteBuffer->Colors[i]);
1344  }
1345 
1346  VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ATT_ADDRESS_PORT,
1347  VIDEO_ENABLE);
1348 
1349  return NO_ERROR;
1350 
1351 } // end VgaSetPaletteReg()
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
PUCHAR IOAddress
Definition: vga.h:401
#define ATT_INITIALIZE_PORT_COLOR
Definition: vga.h:94
#define ATT_DATA_WRITE_PORT
Definition: vga.h:62
#define NO_ERROR
Definition: dderror.h:5
#define VIDEO_MAX_COLOR_REGISTER
Definition: vga.h:224
VPAPI UCHAR NTAPI VideoPortReadPortUchar(IN PUCHAR Port)
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
#define ATT_ADDRESS_PORT
Definition: vga.h:61
unsigned char UCHAR
Definition: xmlstorage.h:181
static WORD PaletteBuffer[]
Definition: screen.c:11
#define VIDEO_ENABLE
Definition: vga.h:179
unsigned short USHORT
Definition: pedump.c:61
VPAPI VOID NTAPI VideoPortWritePortUchar(IN PUCHAR Port, IN UCHAR Value)
#define VIDEO_MAX_PALETTE_REGISTER
Definition: vga.h:230
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by VgaStartIO().

◆ VgaStartIO()

BOOLEAN NTAPI VgaStartIO ( PVOID  HwDeviceExtension,
PVIDEO_REQUEST_PACKET  RequestPacket 
)

Definition at line 550 of file vga.c.

578 {
579  PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
581  VIDEO_MODE videoMode;
582  PVIDEO_MEMORY_INFORMATION memoryInformation;
583  ULONG inIoSpace;
584  ULONG Result;
585 
586  //
587  // Switch on the IoContolCode in the RequestPacket. It indicates which
588  // function must be performed by the driver.
589  //
590 // eVb: 1.9 [IOCTL] - Remove IOCTLs not needed yet
591  switch (RequestPacket->IoControlCode)
592  {
594 
595  VideoDebugPrint((2, "VgaStartIO - ShareVideoMemory\n"));
596 
598 
599  break;
600 
602 
603  VideoDebugPrint((2, "VgaStartIO - UnshareVideoMemory\n"));
604 
606 
607  break;
608 
609 
611 
612  VideoDebugPrint((2, "VgaStartIO - MapVideoMemory\n"));
613 
614  if ( (RequestPacket->OutputBufferLength <
615  (RequestPacket->StatusBlock->Information =
616  sizeof(VIDEO_MEMORY_INFORMATION))) ||
617  (RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY)) )
618  {
620  }
621 
622  memoryInformation = RequestPacket->OutputBuffer;
623 
624  memoryInformation->VideoRamBase = ((PVIDEO_MEMORY)
625  (RequestPacket->InputBuffer))->RequestedVirtualAddress;
626 
627  //
628  // We reserved 16 meg for the frame buffer, however, it makes
629  // no sense to map more memory than there is on the card. So
630  // only map the amount of memory we have on the card.
631  //
632 // eVb: 1.10 [CIRRUS] - On VGA, we have VRAM size since boot, use it
633  memoryInformation->VideoRamLength =
634  hwDeviceExtension->PhysicalVideoMemoryLength;
635 // eVb: 1.10 [END]
636  //
637  // If you change to using a dense space frame buffer, make this
638  // value a 4 for the ALPHA.
639  //
640 
641  inIoSpace = 0;
642 
643  status = VideoPortMapMemory(hwDeviceExtension,
644  hwDeviceExtension->PhysicalVideoMemoryBase,
645 // eVb: 1.11 [CIRRUS] - On VGA, we have VRAM size since boot, use it
646  &memoryInformation->VideoRamLength,
647 // eVb: 1.11 [END]
648  &inIoSpace,
649  &(memoryInformation->VideoRamBase));
650 
651  if (status != NO_ERROR) {
652  VideoDebugPrint((0, "VgaStartIO - IOCTL_VIDEO_MAP_VIDEO_MEMORY failed VideoPortMapMemory (%x)\n", status));
653  }
654 
655  memoryInformation->FrameBufferBase =
656  ((PUCHAR) (memoryInformation->VideoRamBase)) +
657  hwDeviceExtension->PhysicalFrameOffset.LowPart;
658 
659  memoryInformation->FrameBufferLength =
660  hwDeviceExtension->PhysicalFrameLength ?
661  hwDeviceExtension->PhysicalFrameLength :
662  memoryInformation->VideoRamLength;
663 
664 
665  VideoDebugPrint((2, "physical VideoMemoryBase %08lx\n", hwDeviceExtension->PhysicalVideoMemoryBase));
666  VideoDebugPrint((2, "physical VideoMemoryLength %08lx\n", hwDeviceExtension->PhysicalVideoMemoryLength));
667  VideoDebugPrint((2, "VideoMemoryBase %08lx\n", memoryInformation->VideoRamBase));
668  VideoDebugPrint((2, "VideoMemoryLength %08lx\n", memoryInformation->VideoRamLength));
669 
670  VideoDebugPrint((2, "physical framebuf offset %08lx\n", hwDeviceExtension->PhysicalFrameOffset.LowPart));
671  VideoDebugPrint((2, "framebuf base %08lx\n", memoryInformation->FrameBufferBase));
672  VideoDebugPrint((2, "physical framebuf len %08lx\n", hwDeviceExtension->PhysicalFrameLength));
673  VideoDebugPrint((2, "framebuf length %08lx\n", memoryInformation->FrameBufferLength));
674 
675  break;
676 
678 
679  VideoDebugPrint((2, "VgaStartIO - UnMapVideoMemory\n"));
680 
682 
683  break;
684 
685 
687 
688  VideoDebugPrint((2, "VgaStartIO - QueryAvailableModes\n"));
689 
690  status = VgaQueryAvailableModes(HwDeviceExtension,
692  RequestPacket->OutputBuffer,
693  RequestPacket->OutputBufferLength,
694  &RequestPacket->StatusBlock->Information);
695 
696  break;
697 
698 
700 
701  VideoDebugPrint((2, "VgaStartIO - QueryNumAvailableModes\n"));
702 
703  status = VgaQueryNumberOfAvailableModes(HwDeviceExtension,
705  RequestPacket->OutputBuffer,
706  RequestPacket->OutputBufferLength,
707  &RequestPacket->StatusBlock->Information);
708 
709  break;
710 
711 
713 
714  VideoDebugPrint((2, "VgaStartIO - QueryCurrentMode\n"));
715 
716  status = VgaQueryCurrentMode(HwDeviceExtension,
717  (PVIDEO_MODE_INFORMATION) RequestPacket->OutputBuffer,
718  RequestPacket->OutputBufferLength,
719  &RequestPacket->StatusBlock->Information);
720 
721  break;
722 
723 
725 
726  VideoDebugPrint((2, "VgaStartIO - SetCurrentModes\n"));
727 
728  status = VgaSetMode(HwDeviceExtension,
729  (PVIDEO_MODE) RequestPacket->InputBuffer,
730  RequestPacket->InputBufferLength,
731 // eVb: 1.12 [SET MODE] - Use new output parameter for framebuffer update functionality
732  &Result);
733 // eVb: 1.12 [END]
734 
735  break;
736 
737 
739 
740  VideoDebugPrint((2, "VgaStartIO - Reset Device\n"));
741 
742  videoMode.RequestedMode = 0;
743 
744  VgaSetMode(HwDeviceExtension,
745  (PVIDEO_MODE) &videoMode,
746  sizeof(videoMode),
747 // eVb: 1.13 [SET MODE] - Use new output parameter for framebuffer update functionality
748  &Result);
749 // eVb: 1.13 [END]
750 
751  //
752  // Always return succcess since settings the text mode will fail on
753  // non-x86.
754  //
755  // Also, failiure to set the text mode is not fatal in any way, since
756  // this operation must be followed by another set mode operation.
757  //
758 
759  status = NO_ERROR;
760 
761  break;
762 
763 
765 
766  VideoDebugPrint((2, "VgaStartIO - LoadAndSetFont\n"));
767 
769 
770  break;
771 
772 
774 
775  VideoDebugPrint((2, "VgaStartIO - QueryCursorPosition\n"));
776 
778 
779  break;
780 
781 
783 
784  VideoDebugPrint((2, "VgaStartIO - SetCursorPosition\n"));
785 
787 
788  break;
789 
790 
792 
793  VideoDebugPrint((2, "VgaStartIO - QueryCursorAttributes\n"));
794 
796 
797  break;
798 
799 
801 
802  VideoDebugPrint((2, "VgaStartIO - SetCursorAttributes\n"));
803 
805 
806  break;
807 
808 
810 
811  VideoDebugPrint((2, "VgaStartIO - SetPaletteRegs\n"));
812 
813  status = VgaSetPaletteReg(HwDeviceExtension,
814  (PVIDEO_PALETTE_DATA) RequestPacket->InputBuffer,
815  RequestPacket->InputBufferLength);
816 
817  break;
818 
819 
821 
822  VideoDebugPrint((2, "VgaStartIO - SetColorRegs\n"));
823 
824  status = VgaSetColorLookup(HwDeviceExtension,
825  (PVIDEO_CLUT) RequestPacket->InputBuffer,
826  RequestPacket->InputBufferLength);
827 
828  break;
829 
830 
832 
833  VideoDebugPrint((2, "VgaStartIO - EnableVDM\n"));
834 
836 
837  break;
838 
839 
841 
842  VideoDebugPrint((2, "VgaStartIO - RestoreHardwareState\n"));
843 
845 
846  break;
847 
848 
850 
851  VideoDebugPrint((2, "VgaStartIO - SaveHardwareState\n"));
852 
854 
855  break;
856 
858 
859  VideoDebugPrint((2, "VgaStartIO - GetBankSelectCode\n"));
860 
862  break;
863 
865  {
866  PVIDEO_PUBLIC_ACCESS_RANGES portAccess;
867  ULONG physicalPortLength;
868 
869  VideoDebugPrint((2, "VgaStartIO - Query Public Address Ranges\n"));
870 
871  if (RequestPacket->OutputBufferLength <
873  {
875  break;
876  }
877 
878  RequestPacket->StatusBlock->Information =
880 
881  portAccess = RequestPacket->OutputBuffer;
882 
883  //
884  // The first public access range is the IO ports.
885  //
886 
887  portAccess->VirtualAddress = (PVOID) NULL;
888  portAccess->InIoSpace = TRUE;
889  portAccess->MappedInIoSpace = portAccess->InIoSpace;
890  physicalPortLength = VGA_MAX_IO_PORT - VGA_BASE_IO_PORT + 1;
891 
892  status = VideoPortMapMemory(hwDeviceExtension,
894  &physicalPortLength,
895  &(portAccess->MappedInIoSpace),
896  &(portAccess->VirtualAddress));
897 // eVb: 1.17 [GCG] - Fix lvalue error
898  portAccess->VirtualAddress = (PVOID)((ULONG_PTR)portAccess->VirtualAddress - VGA_BASE_IO_PORT);
899 // eVb: 1.17 [END]
900  VideoDebugPrint((2, "VgaStartIO - mapping ports to (%x)\n", portAccess->VirtualAddress));
901  }
902 
903  break;
904 
906 
907  VideoDebugPrint((2, "VgaStartIO - Free Public Access Ranges\n"));
908 
910  break;
911 
912  //
913  // if we get here, an invalid IoControlCode was specified.
914  //
915 
916  default:
917 
918  VideoDebugPrint((0, "Fell through vga startIO routine - invalid command\n"));
919 
921 
922  break;
923 
924  }
925 // eVb: 1.9 [END]
926  RequestPacket->StatusBlock->Status = status;
927 
928  return TRUE;
929 
930 } // VgaStartIO()
VP_STATUS NTAPI VgaSetPaletteReg(PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_PALETTE_DATA PaletteBuffer, ULONG PaletteBufferSize)
Definition: vga.c:1266
#define TRUE
Definition: types.h:120
#define IOCTL_VIDEO_UNSHARE_VIDEO_MEMORY
Definition: ntddvdeo.h:182
ULONG PhysicalFrameLength
Definition: vga.h:398
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define VGA_BASE_IO_PORT
Definition: vga.h:42
unsigned char * PUCHAR
Definition: retypes.h:3
#define IOCTL_VIDEO_ENABLE_VDM
Definition: ntddvdeo.h:41
VP_STATUS NTAPI VgaQueryCurrentMode(PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_MODE_INFORMATION ModeInformation, ULONG ModeInformationSize, PULONG_PTR OutputSize)
Definition: modeset.c:719
ULONG PhysicalVideoMemoryLength
Definition: vga.h:397
#define IOCTL_VIDEO_RESET_DEVICE
Definition: ntddvdeo.h:137
PHYSICAL_ADDRESS PhysicalVideoMemoryBase
Definition: vga.h:395
#define IOCTL_VIDEO_MAP_VIDEO_MEMORY
Definition: ntddvdeo.h:104
ULONG InputBufferLength
Definition: video.h:333
#define NO_ERROR
Definition: dderror.h:5
#define IOCTL_VIDEO_GET_BANK_SELECT_CODE
Definition: ntddvdeo.h:92
#define IOCTL_VIDEO_FREE_PUBLIC_ACCESS_RANGES
Definition: ntddvdeo.h:89
struct _VIDEO_PUBLIC_ACCESS_RANGES VIDEO_PUBLIC_ACCESS_RANGES
#define IOCTL_VIDEO_QUERY_CURRENT_MODE
Definition: ntddvdeo.h:113
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define IOCTL_VIDEO_SET_CURRENT_MODE
Definition: ntddvdeo.h:152
#define VGA_MAX_IO_PORT
Definition: vga.h:45
VP_STATUS NTAPI VgaSetMode(PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_MODE Mode, ULONG ModeSize, PULONG PhysPtrChange)
Definition: modeset.c:361
ULONG RequestedMode
Definition: ntddvdeo.h:289
VP_STATUS NTAPI VgaQueryNumberOfAvailableModes(PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_NUM_MODES NumModes, ULONG NumModesSize, PULONG_PTR OutputSize)
Definition: modeset.c:655
#define IOCTL_VIDEO_SET_PALETTE_REGISTERS
Definition: ntddvdeo.h:161
#define IOCTL_VIDEO_SET_CURSOR_POSITION
Definition: ntddvdeo.h:158
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define IOCTL_VIDEO_QUERY_CURSOR_ATTR
Definition: ntddvdeo.h:116
void * PVOID
Definition: retypes.h:9
ULONG OutputBufferLength
Definition: video.h:335
#define IOCTL_VIDEO_SET_CURSOR_ATTR
Definition: ntddvdeo.h:155
#define IOCTL_VIDEO_UNMAP_VIDEO_MEMORY
Definition: ntddvdeo.h:179
#define IOCTL_VIDEO_QUERY_CURSOR_POSITION
Definition: ntddvdeo.h:119
VPAPI VP_STATUS NTAPI VideoPortMapMemory(IN PVOID HwDeviceExtension, IN PHYSICAL_ADDRESS PhysicalAddress, IN OUT PULONG Length, IN PULONG InIoSpace, IN OUT PVOID *VirtualAddress)
VP_STATUS Status
Definition: video.h:323
#define IOCTL_VIDEO_LOAD_AND_SET_FONT
Definition: ntddvdeo.h:101
ULONG LowPart
Definition: typedefs.h:104
#define IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES
Definition: ntddvdeo.h:122
#define IOCTL_VIDEO_QUERY_AVAIL_MODES
Definition: ntddvdeo.h:107
VP_STATUS NTAPI VgaSetColorLookup(PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_CLUT ClutBuffer, ULONG ClutBufferSize)
Definition: vga.c:1356
#define IOCTL_VIDEO_SHARE_VIDEO_MEMORY
Definition: ntddvdeo.h:173
VIDEO_ACCESS_RANGE VgaAccessRange[]
Definition: vgadata.c:16
#define VideoDebugPrint(x)
Definition: video.h:75
struct _VIDEO_MEMORY * PVIDEO_MEMORY
PSTATUS_BLOCK StatusBlock
Definition: video.h:331
#define IOCTL_VIDEO_QUERY_PUBLIC_ACCESS_RANGES
Definition: ntddvdeo.h:134
PHYSICAL_ADDRESS PhysicalFrameOffset
Definition: vga.h:396
unsigned int ULONG
Definition: retypes.h:1
LONG VP_STATUS
Definition: video.h:153
VP_STATUS NTAPI VgaQueryAvailableModes(PHW_DEVICE_EXTENSION HwDeviceExtension, PVIDEO_MODE_INFORMATION ModeInformation, ULONG ModeInformationSize, PULONG_PTR OutputSize)
Definition: modeset.c:517
#define IOCTL_VIDEO_RESTORE_HARDWARE_STATE
Definition: ntddvdeo.h:140
static SERVICE_STATUS status
Definition: service.c:31
#define IOCTL_VIDEO_SAVE_HARDWARE_STATE
Definition: ntddvdeo.h:143
ULONG_PTR Information
Definition: video.h:326
#define IOCTL_VIDEO_SET_COLOR_REGISTERS
Definition: ntddvdeo.h:149
PHYSICAL_ADDRESS RangeStart
Definition: video.h:215
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
Definition: ps.c:97

Referenced by DriverEntry().