2 * PROJECT: ReactOS VGA Miniport Driver
3 * LICENSE: Microsoft NT4 DDK Sample Code License
4 * FILE: boot/drivers/video/miniport/vga/vga.h
5 * PURPOSE: Main Header File
6 * PROGRAMMERS: Copyright (c) 1992 Microsoft Corporation
7 * ReactOS Portable Systems Group
21 // Base address of VGA memory range. Also used as base address of VGA
22 // memory when loading a font, which is done with the VGA mapped at A0000.
25 #define MEM_VGA 0xA0000
26 #define MEM_VGA_SIZE 0x20000
29 // For memory mapped IO
32 #define MEMORY_MAPPED_IO_OFFSET (0xB8000 - 0xA0000)
35 // Port definitions for filling the ACCESS_RANGES structure in the miniport
36 // information, defines the range of I/O ports the VGA spans.
37 // There is a break in the IO ports - a few ports are used for the parallel
38 // port. Those cannot be defined in the ACCESS_RANGE, but are still mapped
39 // so all VGA ports are in one address range.
42 #define VGA_BASE_IO_PORT 0x000003B0
43 #define VGA_START_BREAK_PORT 0x000003BB
44 #define VGA_END_BREAK_PORT 0x000003C0
45 #define VGA_MAX_IO_PORT 0x000003DF
48 // VGA register definitions
50 // eVb: 3.1 [VGA] - Use offsets from the VGA Port Address instead of absolute
51 #define CRTC_ADDRESS_PORT_MONO 0x0004 // CRT Controller Address and
52 #define CRTC_DATA_PORT_MONO 0x0005 // Data registers in mono mode
53 #define FEAT_CTRL_WRITE_PORT_MONO 0x000A // Feature Control write port
55 #define INPUT_STATUS_1_MONO 0x000A // Input Status 1 register read
57 #define ATT_INITIALIZE_PORT_MONO INPUT_STATUS_1_MONO
58 // Register to read to reset
59 // Attribute Controller index/data
61 #define ATT_ADDRESS_PORT 0x0010 // Attribute Controller Address and
62 #define ATT_DATA_WRITE_PORT 0x0010 // Data registers share one port
63 // for writes, but only Address is
65 #define ATT_DATA_READ_PORT 0x0011 // Attribute Controller Data reg is
67 #define MISC_OUTPUT_REG_WRITE_PORT 0x0012 // Miscellaneous Output reg write
69 #define INPUT_STATUS_0_PORT 0x0012 // Input Status 0 register read
71 #define VIDEO_SUBSYSTEM_ENABLE_PORT 0x0013 // Bit 0 enables/disables the
72 // entire VGA subsystem
73 #define SEQ_ADDRESS_PORT 0x0014 // Sequence Controller Address and
74 #define SEQ_DATA_PORT 0x0015 // Data registers
75 #define DAC_PIXEL_MASK_PORT 0x0016 // DAC pixel mask reg
76 #define DAC_ADDRESS_READ_PORT 0x0017 // DAC register read index reg,
78 #define DAC_STATE_PORT 0x0017 // DAC state (read/write),
80 #define DAC_ADDRESS_WRITE_PORT 0x0018 // DAC register write index reg
81 #define DAC_DATA_REG_PORT 0x0019 // DAC data transfer reg
82 #define FEAT_CTRL_READ_PORT 0x001A // Feature Control read port
83 #define MISC_OUTPUT_REG_READ_PORT 0x001C // Miscellaneous Output reg read
85 #define GRAPH_ADDRESS_PORT 0x001E // Graphics Controller Address
86 #define GRAPH_DATA_PORT 0x001F // and Data registers
88 #define CRTC_ADDRESS_PORT_COLOR 0x0024 // CRT Controller Address and
89 #define CRTC_DATA_PORT_COLOR 0x0025 // Data registers in color mode
90 #define FEAT_CTRL_WRITE_PORT_COLOR 0x002A // Feature Control write port
91 #define INPUT_STATUS_1_COLOR 0x002A // Input Status 1 register read
94 #define ATT_INITIALIZE_PORT_COLOR INPUT_STATUS_1_COLOR
95 // Register to read to reset
96 // Attribute Controller index/data
97 // toggle in color mode
100 // Offsets in HardwareStateHeader->PortValue[] of save areas for non-indexed
104 #define CRTC_ADDRESS_MONO_OFFSET 0x04
105 #define FEAT_CTRL_WRITE_MONO_OFFSET 0x0A
106 #define ATT_ADDRESS_OFFSET 0x10
107 #define MISC_OUTPUT_REG_WRITE_OFFSET 0x12
108 #define VIDEO_SUBSYSTEM_ENABLE_OFFSET 0x13
109 #define SEQ_ADDRESS_OFFSET 0x14
110 #define DAC_PIXEL_MASK_OFFSET 0x16
111 #define DAC_STATE_OFFSET 0x17
112 #define DAC_ADDRESS_WRITE_OFFSET 0x18
113 #define GRAPH_ADDRESS_OFFSET 0x1E
114 #define CRTC_ADDRESS_COLOR_OFFSET 0x24
115 #define FEAT_CTRL_WRITE_COLOR_OFFSET 0x2A
117 // toggle in color mode
119 // VGA indexed register indexes.
122 // CL-GD542x specific registers:
124 #define IND_CL_EXTS_ENB 0x06 // index in Sequencer to enable exts
125 #define IND_NORD_SCRATCH_PAD 0x09 // index in Seq of Nordic scratch pad
126 #define IND_CL_SCRATCH_PAD 0x0A // index in Seq of 542x scratch pad
127 #define IND_ALP_SCRATCH_PAD 0x15 // index in Seq of Alpine scratch pad
128 #define IND_CL_REV_REG 0x25 // index in CRTC of ID Register
129 #define IND_CL_ID_REG 0x27 // index in CRTC of ID Register
131 #define IND_CURSOR_START 0x0A // index in CRTC of the Cursor Start
132 #define IND_CURSOR_END 0x0B // and End registers
133 #define IND_CURSOR_HIGH_LOC 0x0E // index in CRTC of the Cursor Location
134 #define IND_CURSOR_LOW_LOC 0x0F // High and Low Registers
135 #define IND_VSYNC_END 0x11 // index in CRTC of the Vertical Sync
136 // End register, which has the bit
137 // that protects/unprotects CRTC
138 // index registers 0-7
139 #define IND_CR2C 0x2C // Nordic LCD Interface Register
140 #define IND_CR2D 0x2D // Nordic LCD Display Control
141 #define IND_SET_RESET_ENABLE 0x01 // index of Set/Reset Enable reg in GC
142 #define IND_DATA_ROTATE 0x03 // index of Data Rotate reg in GC
143 #define IND_READ_MAP 0x04 // index of Read Map reg in Graph Ctlr
144 #define IND_GRAPH_MODE 0x05 // index of Mode reg in Graph Ctlr
145 #define IND_GRAPH_MISC 0x06 // index of Misc reg in Graph Ctlr
146 #define IND_BIT_MASK 0x08 // index of Bit Mask reg in Graph Ctlr
147 #define IND_SYNC_RESET 0x00 // index of Sync Reset reg in Seq
148 #define IND_MAP_MASK 0x02 // index of Map Mask in Sequencer
149 #define IND_MEMORY_MODE 0x04 // index of Memory Mode reg in Seq
150 #define IND_CRTC_PROTECT 0x11 // index of reg containing regs 0-7 in
152 #define IND_CRTC_COMPAT 0x34 // index of CRTC Compatibility reg
154 #define IND_PERF_TUNING 0x16 // index of performance tuning in Seq
155 #define START_SYNC_RESET_VALUE 0x01 // value for Sync Reset reg to start
157 #define END_SYNC_RESET_VALUE 0x03 // value for Sync Reset reg to end
161 // Value to write to Extensions Control register values extensions.
164 #define CL64xx_EXTENSION_ENABLE_INDEX 0x0A // GR0A to be exact!
165 #define CL64xx_EXTENSION_ENABLE_VALUE 0xEC
166 #define CL64xx_EXTENSION_DISABLE_VALUE 0xCE
167 #define CL64xx_TRISTATE_CONTROL_REG 0xA1
169 #define CL6340_ENABLE_READBACK_REGISTER 0xE0
170 #define CL6340_ENABLE_READBACK_ALLSEL_VALUE 0xF0
171 #define CL6340_ENABLE_READBACK_OFF_VALUE 0x00
172 #define CL6340_IDENTIFICATION_REGISTER 0xE9
174 // Values for Attribute Controller Index register to turn video off
175 // and on, by setting bit 5 to 0 (off) or 1 (on).
178 #define VIDEO_DISABLE 0
179 #define VIDEO_ENABLE 0x20
181 #define INDEX_ENABLE_AUTO_START 0x31
183 // Masks to keep only the significant bits of the Graphics Controller and
184 // Sequencer Address registers. Masking is necessary because some VGAs, such
185 // as S3-based ones, don't return unused bits set to 0, and some SVGAs use
186 // these bits if extensions are enabled.
189 #define GRAPH_ADDR_MASK 0x0F
190 #define SEQ_ADDR_MASK 0x07
193 // Mask used to toggle Chain4 bit in the Sequencer's Memory Mode register.
196 #define CHAIN4_MASK 0x08
199 // Value written to the Read Map register when identifying the existence of
200 // a VGA in VgaInitialize. This value must be different from the final test
201 // value written to the Bit Mask in that routine.
204 #define READ_MAP_TEST_SETTING 0x03
207 // Default text mode setting for various registers, used to restore their
208 // states if VGA detection fails after they've been modified.
211 #define MEMORY_MODE_TEXT_DEFAULT 0x02
212 #define BIT_MASK_DEFAULT 0xFF
213 #define READ_MAP_DEFAULT 0x00
217 // Palette-related info.
221 // Highest valid DAC color register index.
224 #define VIDEO_MAX_COLOR_REGISTER 0xFF
227 // Highest valid palette register index
230 #define VIDEO_MAX_PALETTE_REGISTER 0x0F
233 // Driver Specific Attribute Flags
236 #define CAPS_NO_HOST_XFER 0x00000002 // Do not use host xfers to
238 #define CAPS_SW_POINTER 0x00000004 // Use software pointer.
239 #define CAPS_TRUE_COLOR 0x00000008 // Set upper color registers.
240 #define CAPS_MM_IO 0x00000010 // Use memory mapped IO.
241 #define CAPS_BLT_SUPPORT 0x00000020 // BLTs are supported
242 #define CAPS_IS_542x 0x00000040 // This is a 542x
243 #define CAPS_IS_5436 0x00000080 // This is a 5436
244 #define CAPS_CURSOR_VERT_EXP 0x00000100 // Flag set if 8x6 panel,
245 // but 6x4 resolution
248 // Structure used to describe each video mode in ModesVGA[].
252 USHORT fbType
; // color or monochrome, text or graphics, via
253 // VIDEO_MODE_COLOR and VIDEO_MODE_GRAPHICS
254 USHORT numPlanes
; // # of video memory planes
255 USHORT bitsPerPlane
; // # of bits of color in each plane
256 SHORT col
; // # of text columns across screen with default font
257 SHORT row
; // # of text rows down screen with default font
258 USHORT hres
; // # of pixels across screen
259 USHORT vres
; // # of scan lines down screen
260 // eVb: 3.2 [VGA] - Store frequency next to resolution data
261 ULONG Frequency
; // Vertical Frequency
263 USHORT wbytes
; // # of bytes from start of one scan line to start of next
264 ULONG sbytes
; // total size of addressable display memory in bytes
265 // eVb: 3.3 [VBE] - Add VBE mode and bank flag
269 PUSHORT CmdStream
; // pointer to array of register-setting commands to
271 // eVb: 3.4 [VBE] - Add fields to track linear addresses/sizes and flags
273 ULONG FrameBufferBase
;
274 ULONG FrameBufferSize
;
280 } VIDEOMODE
, *PVIDEOMODE
;
283 // Mode into which to put the VGA before starting a VDM, so it's a plain
284 // vanilla VGA. (This is the mode's index in ModesVGA[], currently standard
288 #define DEFAULT_MODE 0
292 // Info used by the Validator functions and save/restore code.
293 // Structure used to trap register accesses that must be done atomically.
296 #define VGA_MAX_VALIDATOR_DATA 100
298 #define VGA_VALIDATOR_UCHAR_ACCESS 1
299 #define VGA_VALIDATOR_USHORT_ACCESS 2
300 #define VGA_VALIDATOR_ULONG_ACCESS 3
302 typedef struct _VGA_VALIDATOR_DATA
{
306 } VGA_VALIDATOR_DATA
, *PVGA_VALIDATOR_DATA
;
309 // Number of bytes to save in each plane.
312 #define VGA_PLANE_SIZE 0x10000
315 // Number of each type of indexed register in a standard VGA, used by
316 // validator and state save/restore functions.
318 // Note: VDMs currently only support basic VGAs only.
321 #define VGA_NUM_SEQUENCER_PORTS 5
322 #define VGA_NUM_CRTC_PORTS 25
323 #define VGA_NUM_GRAPH_CONT_PORTS 9
324 #define VGA_NUM_ATTRIB_CONT_PORTS 21
325 #define VGA_NUM_DAC_ENTRIES 256
327 #define EXT_NUM_GRAPH_CONT_PORTS 0
328 #define EXT_NUM_SEQUENCER_PORTS 0
329 #define EXT_NUM_CRTC_PORTS 0
330 #define EXT_NUM_ATTRIB_CONT_PORTS 0
331 #define EXT_NUM_DAC_ENTRIES 0
334 // These constants determine the offsets within the
335 // VIDEO_HARDWARE_STATE_HEADER structure that are used to save and
336 // restore the VGA's state.
339 #define VGA_HARDWARE_STATE_SIZE sizeof(VIDEO_HARDWARE_STATE_HEADER)
341 #define VGA_BASIC_SEQUENCER_OFFSET (VGA_HARDWARE_STATE_SIZE + 0)
342 #define VGA_BASIC_CRTC_OFFSET (VGA_BASIC_SEQUENCER_OFFSET + \
343 VGA_NUM_SEQUENCER_PORTS)
344 #define VGA_BASIC_GRAPH_CONT_OFFSET (VGA_BASIC_CRTC_OFFSET + \
346 #define VGA_BASIC_ATTRIB_CONT_OFFSET (VGA_BASIC_GRAPH_CONT_OFFSET + \
347 VGA_NUM_GRAPH_CONT_PORTS)
348 #define VGA_BASIC_DAC_OFFSET (VGA_BASIC_ATTRIB_CONT_OFFSET + \
349 VGA_NUM_ATTRIB_CONT_PORTS)
350 #define VGA_BASIC_LATCHES_OFFSET (VGA_BASIC_DAC_OFFSET + \
351 (3 * VGA_NUM_DAC_ENTRIES))
353 #define VGA_EXT_SEQUENCER_OFFSET (VGA_BASIC_LATCHES_OFFSET + 4)
354 #define VGA_EXT_CRTC_OFFSET (VGA_EXT_SEQUENCER_OFFSET + \
355 EXT_NUM_SEQUENCER_PORTS)
356 #define VGA_EXT_GRAPH_CONT_OFFSET (VGA_EXT_CRTC_OFFSET + \
358 #define VGA_EXT_ATTRIB_CONT_OFFSET (VGA_EXT_GRAPH_CONT_OFFSET +\
359 EXT_NUM_GRAPH_CONT_PORTS)
360 #define VGA_EXT_DAC_OFFSET (VGA_EXT_ATTRIB_CONT_OFFSET + \
361 EXT_NUM_ATTRIB_CONT_PORTS)
363 #define VGA_VALIDATOR_OFFSET (VGA_EXT_DAC_OFFSET + 4 * EXT_NUM_DAC_ENTRIES)
365 #define VGA_VALIDATOR_AREA_SIZE sizeof (ULONG) + (VGA_MAX_VALIDATOR_DATA * \
366 sizeof (VGA_VALIDATOR_DATA)) + \
369 sizeof (PVIDEO_ACCESS_RANGE)
371 #define VGA_MISC_DATA_AREA_OFFSET VGA_VALIDATOR_OFFSET + VGA_VALIDATOR_AREA_SIZE
373 #define VGA_MISC_DATA_AREA_SIZE 0
375 #define VGA_PLANE_0_OFFSET VGA_MISC_DATA_AREA_OFFSET + VGA_MISC_DATA_AREA_SIZE
377 #define VGA_PLANE_1_OFFSET VGA_PLANE_0_OFFSET + VGA_PLANE_SIZE
378 #define VGA_PLANE_2_OFFSET VGA_PLANE_1_OFFSET + VGA_PLANE_SIZE
379 #define VGA_PLANE_3_OFFSET VGA_PLANE_2_OFFSET + VGA_PLANE_SIZE
382 // Space needed to store all state data.
385 #define VGA_TOTAL_STATE_SIZE VGA_PLANE_3_OFFSET + VGA_PLANE_SIZE
389 // Device extension for the driver object. This data is only used
390 // locally, so this structure can be added to as needed.
393 typedef struct _HW_DEVICE_EXTENSION
{
395 PHYSICAL_ADDRESS PhysicalVideoMemoryBase
; // physical memory address and
396 PHYSICAL_ADDRESS PhysicalFrameOffset
; // physical memory address and
397 ULONG PhysicalVideoMemoryLength
; // length of display memory
398 ULONG PhysicalFrameLength
; // length of display memory for
401 PUCHAR IOAddress
; // base I/O address of VGA ports
402 PUCHAR VideoMemoryAddress
; // base virtual memory address of VGA memory
403 ULONG ModeIndex
; // index of current mode in ModesVGA[]
404 PVIDEOMODE CurrentMode
; // pointer to VIDEOMODE structure for
407 VIDEO_CURSOR_POSITION CursorPosition
; // current cursor position
409 UCHAR CursorEnable
; // whether cursor is enabled or not
410 UCHAR CursorTopScanLine
; // Cursor Start register setting (top scan)
411 UCHAR CursorBottomScanLine
; // Cursor End register setting (bottom scan)
412 // eVb: 3.5 [VBE] - Add fields for VBE support and XP+ INT10 interface
413 VIDEO_PORT_INT10_INTERFACE Int10Interface
;
416 } HW_DEVICE_EXTENSION
, *PHW_DEVICE_EXTENSION
;
420 // Function prototypes.
424 // Entry points for the VGA validator. Used in VgaEmulatorAccessEntries[].
429 // Vga init scripts for font loading
432 extern USHORT EnableA000Data
[];
433 extern USHORT DisableA000Color
[];
439 extern ULONG NumVideoModes
;
440 extern VIDEOMODE ModesVGA
[];
441 extern PVIDEOMODE VgaModeList
;
443 // eVb: 3.5 [VGA] - Add ATI/Mach64 Access Range
444 #define NUM_VGA_ACCESS_RANGES 5
446 extern VIDEO_ACCESS_RANGE VgaAccessRange
[];
448 /* VESA Bios Magic number */
449 #define VESA_MAGIC ('V' + ('E' << 8) + ('S' << 16) + ('A' << 24))
453 #endif /* _VGA_NEW_PCH_ */