DevVGA.h revision 6afaacf5e6280ae3d82bf16f06d056beb0441433
1N/A/** @file
1N/A *
1N/A * VBox VGA/VESA device
1N/A */
1N/A
1N/A/*
1N/A * Copyright (C) 2006-2007 innotek GmbH
1N/A *
1N/A * This file is part of VirtualBox Open Source Edition (OSE), as
1N/A * available from http://www.virtualbox.org. This file is free software;
1N/A * you can redistribute it and/or modify it under the terms of the GNU
1N/A * General Public License (GPL) as published by the Free Software
1N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
1N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1N/A * --------------------------------------------------------------------
1N/A *
1N/A * This code is based on:
1N/A *
1N/A * QEMU internal VGA defines.
1N/A *
1N/A * Copyright (c) 2003-2004 Fabrice Bellard
1N/A *
1N/A * Permission is hereby granted, free of charge, to any person obtaining a copy
1N/A * of this software and associated documentation files (the "Software"), to deal
1N/A * in the Software without restriction, including without limitation the rights
1N/A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1N/A * copies of the Software, and to permit persons to whom the Software is
1N/A * furnished to do so, subject to the following conditions:
1N/A *
1N/A * The above copyright notice and this permission notice shall be included in
1N/A * all copies or substantial portions of the Software.
1N/A *
1N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1N/A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1N/A * THE SOFTWARE.
1N/A */
1N/A
1N/A#define MSR_COLOR_EMULATION 0x01
1N/A#define MSR_PAGE_SELECT 0x20
1N/A
1N/A#define ST01_V_RETRACE 0x08
1N/A#define ST01_DISP_ENABLE 0x01
1N/A
1N/A/* bochs VBE support */
1N/A#define CONFIG_BOCHS_VBE
1N/A
1N/A#ifdef VBOX
1N/A#define VBE_DISPI_MAX_XRES 16384
1N/A#define VBE_DISPI_MAX_YRES 16384
1N/A#else
1N/A#define VBE_DISPI_MAX_XRES 1600
1N/A#define VBE_DISPI_MAX_YRES 1200
1N/A#endif
1N/A#define VBE_DISPI_MAX_BPP 32
1N/A
1N/A#define VBE_DISPI_INDEX_ID 0x0
1N/A#define VBE_DISPI_INDEX_XRES 0x1
1N/A#define VBE_DISPI_INDEX_YRES 0x2
1N/A#define VBE_DISPI_INDEX_BPP 0x3
1N/A#define VBE_DISPI_INDEX_ENABLE 0x4
1N/A#define VBE_DISPI_INDEX_BANK 0x5
1N/A#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
1N/A#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
1N/A#define VBE_DISPI_INDEX_X_OFFSET 0x8
1N/A#define VBE_DISPI_INDEX_Y_OFFSET 0x9
1N/A#define VBE_DISPI_INDEX_VBOX_VIDEO 0xa
1N/A#define VBE_DISPI_INDEX_NB 0xb
1N/A
1N/A#define VBE_DISPI_ID0 0xB0C0
1N/A#define VBE_DISPI_ID1 0xB0C1
1N/A#define VBE_DISPI_ID2 0xB0C2
1N/A#define VBE_DISPI_ID3 0xB0C3
1N/A#define VBE_DISPI_ID4 0xB0C4
1N/A
1N/A#ifdef VBOX
1N/A/* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_VBOX_VIDEO. */
1N/A#define VBE_DISPI_ID_VBOX_VIDEO 0xBE00
1N/A#endif /* VBOX */
1N/A
1N/A#define VBE_DISPI_DISABLED 0x00
1N/A#define VBE_DISPI_ENABLED 0x01
1N/A#define VBE_DISPI_GETCAPS 0x02
1N/A#define VBE_DISPI_8BIT_DAC 0x20
1N/A#define VBE_DISPI_LFB_ENABLED 0x40
1N/A#define VBE_DISPI_NOCLEARMEM 0x80
1N/A
1N/A#define VBE_DISPI_LFB_PHYSICAL_ADDRESS 0xE0000000
1N/A
1N/A#ifdef CONFIG_BOCHS_VBE
1N/A
1N/A#define VGA_STATE_COMMON_BOCHS_VBE \
1N/A uint16_t vbe_index; \
1N/A uint16_t vbe_regs[VBE_DISPI_INDEX_NB]; \
1N/A uint32_t vbe_start_addr; \
1N/A uint32_t vbe_line_offset; \
1N/A uint32_t vbe_bank_mask;
1N/A
1N/A#else
1N/A
1N/A#define VGA_STATE_COMMON_BOCHS_VBE
1N/A
1N/A#endif /* !CONFIG_BOCHS_VBE */
1N/A
1N/A#define CH_ATTR_SIZE (160 * 100)
1N/A#define VGA_MAX_HEIGHT VBE_DISPI_MAX_YRES
1N/A
1N/A#ifndef VBOX
1N/A#define VGA_STATE_COMMON \
1N/A uint8_t *vram_ptr; \
1N/A unsigned long vram_offset; \
1N/A unsigned int vram_size; \
1N/A uint32_t latch; \
1N/A uint8_t sr_index; \
1N/A uint8_t sr[256]; \
1N/A uint8_t gr_index; \
1N/A uint8_t gr[256]; \
1N/A uint8_t ar_index; \
1N/A uint8_t ar[21]; \
1N/A int ar_flip_flop; \
1N/A uint8_t cr_index; \
1N/A uint8_t cr[256]; /* CRT registers */ \
1N/A uint8_t msr; /* Misc Output Register */ \
1N/A uint8_t fcr; /* Feature Control Register */ \
1N/A uint8_t st00; /* status 0 */ \
1N/A uint8_t st01; /* status 1 */ \
1N/A uint8_t dac_state; \
1N/A uint8_t dac_sub_index; \
1N/A uint8_t dac_read_index; \
1N/A uint8_t dac_write_index; \
1N/A uint8_t dac_cache[3]; /* used when writing */ \
1N/A uint8_t palette[768]; \
1N/A int32_t bank_offset; \
1N/A int (*get_bpp)(struct VGAState *s); \
1N/A void (*get_offsets)(struct VGAState *s, \
1N/A uint32_t *pline_offset, \
1N/A uint32_t *pstart_addr, \
1N/A uint32_t *pline_compare); \
1N/A void (*get_resolution)(struct VGAState *s, \
1N/A int *pwidth, \
1N/A int *pheight); \
1N/A VGA_STATE_COMMON_BOCHS_VBE \
1N/A /* display refresh support */ \
1N/A DisplayState *ds; \
1N/A uint32_t font_offsets[2]; \
1N/A int graphic_mode; \
1N/A uint8_t shift_control; \
1N/A uint8_t double_scan; \
1N/A uint32_t line_offset; \
1N/A uint32_t line_compare; \
1N/A uint32_t start_addr; \
1N/A uint32_t plane_updated; \
1N/A uint8_t last_cw, last_ch; \
1N/A uint32_t last_width, last_height; /* in chars or pixels */ \
1N/A uint32_t last_scr_width, last_scr_height; /* in pixels */ \
1N/A uint8_t cursor_start, cursor_end; \
1N/A uint32_t cursor_offset; \
1N/A unsigned int (*rgb_to_pixel)(unsigned int r, \
1N/A unsigned int g, unsigned b); \
1N/A /* hardware mouse cursor support */ \
1N/A uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
1N/A void (*cursor_invalidate)(struct VGAState *s); \
1N/A void (*cursor_draw_line)(struct VGAState *s, uint8_t *d, int y); \
1N/A /* tell for each page if it has been updated since the last time */ \
1N/A uint32_t last_palette[256]; \
1N/A uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
1N/A
1N/A#else /* VBOX */
1N/A
1N/Astruct VGAState;
1N/Atypedef int FNGETBPP(struct VGAState *s);
1N/Atypedef void FNGETOFFSETS(struct VGAState *s, uint32_t *pline_offset, uint32_t *pstart_addr, uint32_t *pline_compare);
1N/Atypedef void FNGETRESOLUTION(struct VGAState *s, int *pwidth, int *pheight);
1N/Atypedef unsigned int FNRGBTOPIXEL(unsigned int r, unsigned int g, unsigned b);
1N/Atypedef void FNCURSORINVALIDATE(struct VGAState *s);
1N/Atypedef void FNCURSORDRAWLINE(struct VGAState *s, uint8_t *d, int y);
1N/A
1N/A/* bird: vram_offset have been remove, function pointers declared external,
1N/A some type changes, and some padding have been added. */
1N/A#define VGA_STATE_COMMON \
1N/A R3R0PTRTYPE(uint8_t *) vram_ptrHC; \
1N/A uint32_t vram_size; \
1N/A uint32_t latch; \
1N/A uint8_t sr_index; \
1N/A uint8_t sr[256]; \
1N/A uint8_t gr_index; \
1N/A uint8_t gr[256]; \
1N/A uint8_t ar_index; \
1N/A uint8_t ar[21]; \
1N/A int32_t ar_flip_flop; \
1N/A uint8_t cr_index; \
1N/A uint8_t cr[256]; /* CRT registers */ \
1N/A uint8_t msr; /* Misc Output Register */ \
1N/A uint8_t fcr; /* Feature Control Register */ \
1N/A uint8_t st00; /* status 0 */ \
1N/A uint8_t st01; /* status 1 */ \
1N/A uint8_t dac_state; \
1N/A uint8_t dac_sub_index; \
1N/A uint8_t dac_read_index; \
1N/A uint8_t dac_write_index; \
1N/A uint8_t dac_cache[3]; /* used when writing */ \
1N/A uint8_t palette[768]; \
1N/A int32_t bank_offset; \
1N/A int32_t padding0; \
1N/A R3PTRTYPE(FNGETBPP *) get_bpp; \
1N/A R3PTRTYPE(FNGETOFFSETS *) get_offsets; \
1N/A R3PTRTYPE(FNGETRESOLUTION *) get_resolution; \
1N/A VGA_STATE_COMMON_BOCHS_VBE \
1N/A /* display refresh support */ \
1N/A uint32_t font_offsets[2]; \
1N/A int32_t graphic_mode; \
1N/A uint8_t shift_control; \
1N/A uint8_t double_scan; \
1N/A uint8_t padding1[2]; \
1N/A uint32_t line_offset; \
1N/A uint32_t line_compare; \
1N/A uint32_t start_addr; \
1N/A uint32_t plane_updated; \
1N/A uint8_t last_cw, last_ch, padding2[2]; \
1N/A uint32_t last_width, last_height; /* in chars or pixels */ \
1N/A uint32_t last_scr_width, last_scr_height; /* in pixels */ \
1N/A uint32_t last_bpp; \
1N/A uint8_t cursor_start, cursor_end, padding3[2]; \
1N/A uint32_t cursor_offset; \
1N/A uint32_t padding4; \
1N/A R3PTRTYPE(FNRGBTOPIXEL *) rgb_to_pixel; \
1N/A /* hardware mouse cursor support */ \
1N/A uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32]; \
1N/A R3PTRTYPE(FNCURSORINVALIDATE *) cursor_invalidate; \
1N/A R3PTRTYPE(FNCURSORDRAWLINE *) cursor_draw_line; \
1N/A /* tell for each page if it has been updated since the last time */ \
1N/A uint32_t last_palette[256]; \
1N/A uint32_t last_ch_attr[CH_ATTR_SIZE]; /* XXX: make it dynamic */
1N/A
1N/A#endif /* VBOX */
1N/A
1N/Atypedef struct VGAState {
1N/A VGA_STATE_COMMON
1N/A#ifdef VBOX
1N/A /** end-of-common-state-marker */
1N/A uint32_t u32Marker;
/** The physical address the VRAM was assigned. */
RTGCPHYS GCPhysVRAM;
/** Pointer to GC vram mapping. */
GCPTRTYPE(uint8_t *) vram_ptrGC;
/** @todo r=bird: bool not RTUINT (my fault I guess). */
/** LFB was updated flag. */
RTUINT fLFBUpdated;
/** Indicates if the GC extensions are enabled or not. */
RTUINT fGCEnabled;
/** Indicates if the R0 extensions are enabled or not. */
RTUINT fR0Enabled;
/** Pointer to vgaGCLFBAccessHandler(). */
RTGCPTR GCPtrLFBHandler;
/** Flag indicating that there are dirty bits. This is used to optimize the handler resetting. */
bool fHaveDirtyBits;
/** Bitmap tracking dirty pages. */
uint32_t au32DirtyBitmap[VGA_VRAM_MAX / PAGE_SIZE / 32];
/** Pointer to the device instance - HC Ptr. */
R3R0PTRTYPE(PPDMDEVINS) pDevInsHC;
/* * Pointer to the device instance - GC Ptr. */
/*GCPTRTYPE(PPDMDEVINS) pDevInsGC;*/
/** The display port base interface. */
PDMIBASE Base;
/** The display port interface. */
PDMIDISPLAYPORT Port;
/** Pointer to base interface of the driver. */
R3PTRTYPE(PPDMIBASE) pDrvBase;
/** Pointer to display connector interface of the driver. */
R3PTRTYPE(PPDMIDISPLAYCONNECTOR) pDrv;
/** Refresh timer handle - HC. */
PTMTIMERR3 RefreshTimer;
/** Current refresh timer interval. */
uint32_t cMilliesRefreshInterval;
/** Whether to render the guest VRAM to the framebuffer memory. False only for some LFB modes. */
uint32_t fRenderVRAM;
#if HC_ARCH_BITS == 32
uint32_t Padding10;
#endif
/** The PCI device. */
PCIDEVICE Dev;
STAMPROFILE StatGCMemoryRead;
STAMPROFILE StatGCMemoryWrite;
STAMPROFILE StatGCIOPortRead;
STAMPROFILE StatGCIOPortWrite;
#ifdef VBE_BYTEWISE_IO
/** VBE read/write data/index flags */
uint8_t fReadVBEData;
uint8_t fWriteVBEData;
uint8_t fReadVBEIndex;
uint8_t fWriteVBEIndex;
/** VBE write data/index one byte buffer */
uint8_t cbWriteVBEData;
uint8_t cbWriteVBEIndex;
# ifdef VBE_NEW_DYN_LIST
/** VBE Extra Data write address one byte buffer */
uint8_t cbWriteVBEExtraAddress;
uint8_t Padding6; /**< Alignment padding. */
# else
uint8_t Padding6[2]; /**< Alignment padding. */
# endif
#endif
#ifdef VBE_NEW_DYN_LIST
/** The VBE BIOS extra data. */
R3PTRTYPE(uint8_t *) pu8VBEExtraData;
/** The size of the VBE BIOS extra data. */
uint16_t cbVBEExtraData;
/** The VBE BIOS current memory address. */
uint16_t u16VBEExtraAddress;
uint16_t Padding7[2]; /**< Alignment padding. */
#endif
#endif /* VBOX */
} VGAState;
#ifdef VBOX
/** VGA state. */
typedef VGAState VGASTATE;
/** Pointer to the VGA state. */
typedef VGASTATE *PVGASTATE;
#endif
#ifdef VBE_NEW_DYN_LIST
/**
* VBE Bios Extra Data structure.
* @remark duplicated in vbe.h.
*/
typedef struct VBEHeader
{
/** Signature (VBEHEADER_MAGIC). */
uint16_t u16Signature;
/** Data size. */
uint16_t cbData;
} VBEHeader;
/** VBE Extra Data. */
typedef VBEHeader VBEHEADER;
/** Pointer to the VBE Extra Data. */
typedef VBEHEADER *PVBEHEADER;
/** The value of the VBEHEADER::u16Signature field.
* @remark duplicated in vbe.h. */
#define VBEHEADER_MAGIC 0x77CC
/** The extra port which is used to read the mode list.
* @remark duplicated in vbe.h. */
#define VBE_EXTRA_PORT 0x3b6
/** The extra port which is used for debug printf.
* @remark duplicated in vbe.h. */
#define VBE_PRINTF_PORT 0x3b7
#endif /* VBE_NEW_DYN_LIST */
#if !defined(VBOX) || defined(IN_RING3)
static inline int c6_to_8(int v)
{
int b;
v &= 0x3f;
b = v & 1;
return (v << 2) | (b << 1) | b;
}
#endif /* !VBOX || IN_RING3 */
#ifndef VBOX
void vga_common_init(VGAState *s, DisplayState *ds, uint8_t *vga_ram_base,
unsigned long vga_ram_offset, int vga_ram_size);
uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr);
void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val);
void vga_invalidate_scanlines(VGAState *s, int y1, int y2);
void vga_draw_cursor_line_8(uint8_t *d1, const uint8_t *src1,
int poffset, int w,
unsigned int color0, unsigned int color1,
unsigned int color_xor);
void vga_draw_cursor_line_16(uint8_t *d1, const uint8_t *src1,
int poffset, int w,
unsigned int color0, unsigned int color1,
unsigned int color_xor);
void vga_draw_cursor_line_32(uint8_t *d1, const uint8_t *src1,
int poffset, int w,
unsigned int color0, unsigned int color1,
unsigned int color_xor);
extern const uint8_t sr_mask[8];
extern const uint8_t gr_mask[16];
#endif /* !VBOX */