1 /* $NetBSD: vbe.h,v 1.3 2011/02/09 04:37:54 jmcneill Exp $ */
2 
3 /*-
4  * Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #define VBE_DEFAULT_MODE      0x101     /* 640x480x8 */
30 
31 struct vbeinfoblock {
32           char VbeSignature[4];
33           uint16_t VbeVersion;
34           uint32_t OemStringPtr;
35           uint32_t Capabilities;
36           uint32_t VideoModePtr;
37           uint16_t TotalMemory;
38           uint16_t OemSoftwareRev;
39           uint32_t OemVendorNamePtr, OemProductNamePtr, OemProductRevPtr;
40           /* data area, in total max 512 bytes for VBE 2.0 */
41           uint8_t Reserved[222];
42           uint8_t OemData[256];
43 } __packed;
44 
45 struct modeinfoblock {
46           /* Mandatory information for all VBE revisions */
47           uint16_t ModeAttributes;
48           uint8_t WinAAttributes, WinBAttributes;
49           uint16_t WinGranularity, WinSize, WinASegment, WinBSegment;
50           uint32_t WinFuncPtr;
51           uint16_t BytesPerScanLine;
52           /* Mandatory information for VBE 1.2 and above */
53           uint16_t XResolution, YResolution;
54           uint8_t XCharSize, YCharSize, NumberOfPlanes, BitsPerPixel;
55           uint8_t NumberOfBanks, MemoryModel, BankSize, NumberOfImagePages;
56           uint8_t Reserved1;
57           /* Direct Color fields
58              (required for direct/6 and YUV/7 memory models) */
59           uint8_t RedMaskSize, RedFieldPosition;
60           uint8_t GreenMaskSize, GreenFieldPosition;
61           uint8_t BlueMaskSize, BlueFieldPosition;
62           uint8_t RsvdMaskSize, RsvdFieldPosition;
63           uint8_t DirectColorModeInfo;
64           /* Mandatory information for VBE 2.0 and above */
65           uint32_t PhysBasePtr;
66           uint32_t OffScreenMemOffset;  /* reserved in VBE 3.0 and above */
67           uint16_t OffScreenMemSize;    /* reserved in VBE 3.0 and above */
68 
69           /* Mandatory information for VBE 3.0 and above */
70           uint16_t LinBytesPerScanLine;
71           uint8_t BnkNumberOfImagePages;
72           uint8_t LinNumberOfImagePages;
73           uint8_t LinRedMaskSize, LinRedFieldPosition;
74           uint8_t LinGreenMaskSize, LinGreenFieldPosition;
75           uint8_t LinBlueMaskSize, LinBlueFieldPosition;
76           uint8_t LinRsvdMaskSize, LinRsvdFieldPosition;
77           uint32_t MaxPixelClock;
78           uint8_t Reserved4[189];
79 } __packed;
80 
81 struct paletteentry {
82           uint8_t Blue;
83           uint8_t Green;
84           uint8_t Red;
85           uint8_t Alignment;
86 } __packed;
87 
88 /* EDID */
89 #define   EDID_MAGIC          { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }
90 #define   EDID_DESC_BLOCK     0x36
91 
92 /* low-level VBE calls, from biosvbe.S */
93 int biosvbe_info(struct vbeinfoblock *);
94 int biosvbe_set_mode(int);
95 int biosvbe_get_mode_info(int, struct modeinfoblock *);
96 int biosvbe_palette_format(int);
97 int biosvbe_palette_data(int, int, struct paletteentry *);
98 int biosvbe_ddc_caps(void);
99 int biosvbe_ddc_read_edid(int, void *);
100 
101 /* high-level VBE helpers, from vbe.c */
102 void vbe_init(void);
103 int vbe_commit(void);
104 int vbe_available(void);
105 int vbe_set_mode(int);
106 int vbe_set_palette(const uint8_t *, int);
107 void vbe_modelist(void);
108 
109 void command_vesa(char *);
110 
111 /* adjust physical address; boot code runs with %ds having a 64k offset */
112 #define VBEPHYPTR(x)          ((uint8_t *)((x) - (64 * 1024)))
113