xref: /freebsd/stand/i386/libi386/vbe.h (revision 58661b3ba9ebe82f889cbc336afe618ad7f7940a)
13630506bSToomas Soome /*-
23630506bSToomas Soome  * Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
33630506bSToomas Soome  * All rights reserved.
43630506bSToomas Soome  *
53630506bSToomas Soome  * Redistribution and use in source and binary forms, with or without
63630506bSToomas Soome  * modification, are permitted provided that the following conditions
73630506bSToomas Soome  * are met:
83630506bSToomas Soome  * 1. Redistributions of source code must retain the above copyright
93630506bSToomas Soome  *    notice, this list of conditions and the following disclaimer.
103630506bSToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
113630506bSToomas Soome  *    notice, this list of conditions and the following disclaimer in the
123630506bSToomas Soome  *    documentation and/or other materials provided with the distribution.
133630506bSToomas Soome  *
143630506bSToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
153630506bSToomas Soome  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
163630506bSToomas Soome  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
173630506bSToomas Soome  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
183630506bSToomas Soome  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
193630506bSToomas Soome  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
203630506bSToomas Soome  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
213630506bSToomas Soome  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
223630506bSToomas Soome  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
233630506bSToomas Soome  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
243630506bSToomas Soome  * POSSIBILITY OF SUCH DAMAGE.
253630506bSToomas Soome  */
263630506bSToomas Soome 
273630506bSToomas Soome /*
283630506bSToomas Soome  * Default mode for VESA frame buffer.
293630506bSToomas Soome  * This mode is selected when there is no EDID inormation and
303630506bSToomas Soome  * mode is not provided by user.
313630506bSToomas Soome  * To provide consistent look with UEFI GOP, we use 800x600 here,
323630506bSToomas Soome  * and if this mode is not available, we fall back to text mode and
333630506bSToomas Soome  * VESA disabled.
343630506bSToomas Soome  */
353630506bSToomas Soome 
363630506bSToomas Soome #define VBE_DEFAULT_MODE	"800x600"
373630506bSToomas Soome 
383630506bSToomas Soome struct vbeinfoblock {
393630506bSToomas Soome 	char VbeSignature[4];
403630506bSToomas Soome 	uint16_t VbeVersion;
413630506bSToomas Soome 	uint32_t OemStringPtr;
423630506bSToomas Soome 	uint32_t Capabilities;
433630506bSToomas Soome #define	VBE_CAP_DAC8	(1 << 0)	/* Can switch DAC */
443630506bSToomas Soome #define	VBE_CAP_NONVGA	(1 << 1)	/* Controller is not VGA comp. */
453630506bSToomas Soome #define	VBE_CAP_SNOW	(1 << 2)	/* Set data during Vertical Reterace */
463630506bSToomas Soome 	uint32_t VideoModePtr;
473630506bSToomas Soome 	uint16_t TotalMemory;
483630506bSToomas Soome 	uint16_t OemSoftwareRev;
493630506bSToomas Soome 	uint32_t OemVendorNamePtr, OemProductNamePtr, OemProductRevPtr;
503630506bSToomas Soome 	/* data area, in total max 512 bytes for VBE 2.0 */
513630506bSToomas Soome 	uint8_t Reserved[222];
523630506bSToomas Soome 	uint8_t OemData[256];
533630506bSToomas Soome } __packed;
543630506bSToomas Soome 
553630506bSToomas Soome struct modeinfoblock {
563630506bSToomas Soome 	/* Mandatory information for all VBE revisions */
573630506bSToomas Soome 	uint16_t ModeAttributes;
583630506bSToomas Soome 	uint8_t WinAAttributes, WinBAttributes;
593630506bSToomas Soome 	uint16_t WinGranularity, WinSize, WinASegment, WinBSegment;
603630506bSToomas Soome 	uint32_t WinFuncPtr;
613630506bSToomas Soome 	uint16_t BytesPerScanLine;
623630506bSToomas Soome 	/* Mandatory information for VBE 1.2 and above */
633630506bSToomas Soome 	uint16_t XResolution, YResolution;
643630506bSToomas Soome 	uint8_t XCharSize, YCharSize, NumberOfPlanes, BitsPerPixel;
653630506bSToomas Soome 	uint8_t NumberOfBanks, MemoryModel, BankSize, NumberOfImagePages;
663630506bSToomas Soome 	uint8_t Reserved1;
673630506bSToomas Soome 	/* Direct Color fields
683630506bSToomas Soome 	   (required for direct/6 and YUV/7 memory models) */
693630506bSToomas Soome 	uint8_t RedMaskSize, RedFieldPosition;
703630506bSToomas Soome 	uint8_t GreenMaskSize, GreenFieldPosition;
713630506bSToomas Soome 	uint8_t BlueMaskSize, BlueFieldPosition;
723630506bSToomas Soome 	uint8_t RsvdMaskSize, RsvdFieldPosition;
733630506bSToomas Soome 	uint8_t DirectColorModeInfo;
743630506bSToomas Soome 	/* Mandatory information for VBE 2.0 and above */
753630506bSToomas Soome 	uint32_t PhysBasePtr;
763630506bSToomas Soome 	uint32_t OffScreenMemOffset;	/* reserved in VBE 3.0 and above */
773630506bSToomas Soome 	uint16_t OffScreenMemSize;	/* reserved in VBE 3.0 and above */
783630506bSToomas Soome 
793630506bSToomas Soome 	/* Mandatory information for VBE 3.0 and above */
803630506bSToomas Soome 	uint16_t LinBytesPerScanLine;
813630506bSToomas Soome 	uint8_t BnkNumberOfImagePages;
823630506bSToomas Soome 	uint8_t LinNumberOfImagePages;
833630506bSToomas Soome 	uint8_t LinRedMaskSize, LinRedFieldPosition;
843630506bSToomas Soome 	uint8_t LinGreenMaskSize, LinGreenFieldPosition;
853630506bSToomas Soome 	uint8_t LinBlueMaskSize, LinBlueFieldPosition;
863630506bSToomas Soome 	uint8_t LinRsvdMaskSize, LinRsvdFieldPosition;
873630506bSToomas Soome 	uint32_t MaxPixelClock;
883630506bSToomas Soome 	/* + 1 will fix the size to 256 bytes */
893630506bSToomas Soome 	uint8_t Reserved4[189 + 1];
903630506bSToomas Soome } __packed;
913630506bSToomas Soome 
923630506bSToomas Soome struct crtciinfoblock {
933630506bSToomas Soome 	uint16_t HorizontalTotal;
943630506bSToomas Soome 	uint16_t HorizontalSyncStart;
953630506bSToomas Soome 	uint16_t HorizontalSyncEnd;
963630506bSToomas Soome 	uint16_t VerticalTotal;
973630506bSToomas Soome 	uint16_t VerticalSyncStart;
983630506bSToomas Soome 	uint16_t VerticalSyncEnd;
993630506bSToomas Soome 	uint8_t Flags;
1003630506bSToomas Soome 	uint32_t PixelClock;
1013630506bSToomas Soome 	uint16_t RefreshRate;
1023630506bSToomas Soome 	uint8_t Reserved[40];
1033630506bSToomas Soome } __packed;
1043630506bSToomas Soome 
1053630506bSToomas Soome struct paletteentry {
1063630506bSToomas Soome 	uint8_t Blue;
1073630506bSToomas Soome 	uint8_t Green;
1083630506bSToomas Soome 	uint8_t Red;
1093630506bSToomas Soome 	uint8_t Reserved;
1103630506bSToomas Soome } __packed;
1113630506bSToomas Soome 
1123630506bSToomas Soome struct flatpanelinfo
1133630506bSToomas Soome {
1143630506bSToomas Soome 	uint16_t HorizontalSize;
1153630506bSToomas Soome 	uint16_t VerticalSize;
1163630506bSToomas Soome 	uint16_t PanelType;
1173630506bSToomas Soome 	uint8_t RedBPP;
1183630506bSToomas Soome 	uint8_t GreenBPP;
1193630506bSToomas Soome 	uint8_t BlueBPP;
1203630506bSToomas Soome 	uint8_t ReservedBPP;
1213630506bSToomas Soome 	uint32_t ReservedOffScreenMemSize;
1223630506bSToomas Soome 	uint32_t ReservedOffScreenMemPtr;
1233630506bSToomas Soome 
1243630506bSToomas Soome 	uint8_t Reserved[14];
1253630506bSToomas Soome } __packed;
1263630506bSToomas Soome 
1273630506bSToomas Soome #define	VBE_BASE_MODE		(0x100)		/* VBE 3.0 page 18 */
1283630506bSToomas Soome #define	VBE_VALID_MODE(a)	((a) >= VBE_BASE_MODE)
1293630506bSToomas Soome #define	VBE_ERROR(a)		(((a) & 0xFF) != 0x4F || ((a) & 0xFF00) != 0)
1303630506bSToomas Soome #define	VBE_SUCCESS		(0x004F)
1313630506bSToomas Soome #define	VBE_FAILED		(0x014F)
1323630506bSToomas Soome #define	VBE_NOTSUP		(0x024F)
1333630506bSToomas Soome #define	VBE_INVALID		(0x034F)
1343630506bSToomas Soome 
1353630506bSToomas Soome #define	VGA_TEXT_MODE		(3)		/* 80x25 text mode */
1363630506bSToomas Soome #define	TEXT_ROWS		(25)		/* VGATEXT rows */
1373630506bSToomas Soome #define	TEXT_COLS		(80)		/* VGATEXT columns */
1383630506bSToomas Soome 
1393630506bSToomas Soome extern struct paletteentry *pe8;
1403630506bSToomas Soome extern int palette_format;
1413630506bSToomas Soome 
1423630506bSToomas Soome int vga_get_reg(int, int);
1433630506bSToomas Soome int vga_get_atr(int, int);
1443630506bSToomas Soome void vga_set_atr(int, int, int);
1453630506bSToomas Soome void vga_set_indexed(int, int, int, uint8_t, uint8_t);
1463630506bSToomas Soome int vga_get_indexed(int, int, int, uint8_t);
1473630506bSToomas Soome int vga_get_crtc(int, int);
1483630506bSToomas Soome void vga_set_crtc(int, int, int);
1493630506bSToomas Soome int vga_get_seq(int, int);
1503630506bSToomas Soome void vga_set_seq(int, int, int);
1513630506bSToomas Soome int vga_get_grc(int, int);
1523630506bSToomas Soome void vga_set_grc(int, int, int);
1533630506bSToomas Soome 
1543630506bSToomas Soome /* high-level VBE helpers, from vbe.c */
155*58661b3bSToomas Soome bool vbe_is_vga(void);
1563630506bSToomas Soome void bios_set_text_mode(int);
1573630506bSToomas Soome int biosvbe_palette_format(int *);
1583630506bSToomas Soome void vbe_init(void);
1593630506bSToomas Soome bool vbe_available(void);
1603630506bSToomas Soome int vbe_default_mode(void);
1613630506bSToomas Soome int vbe_set_mode(int);
1623630506bSToomas Soome int vbe_get_mode(void);
1633630506bSToomas Soome int vbe_set_palette(const struct paletteentry *, size_t);
1643630506bSToomas Soome void vbe_modelist(int);
165