1/**
2 * \file
3 * \brief VESA BIOS Extensions (VBE) driver.
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2009, 2010, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef VBE_H
16#define VBE_H
17
18#include <stdbool.h>
19#include <pci/mem.h>
20
21#define VBE_OK          0x004f
22
23struct vbeinfoblock {
24    // All VBE revisions
25    char        signature[4];
26    uint16_t    version;
27    uint32_t    oemstringptr;
28    uint32_t    capabilities;
29    uint32_t    videomodeptr;
30    uint16_t    totalmemory;
31
32    // VBE 2.0 and up
33    uint16_t    oemsoftwarerev;
34    uint32_t    oemvendornameptr;
35    uint32_t    oemproductnameptr;
36    uint32_t    oemproductrevptr;
37    uint8_t     reserved[222];
38    uint8_t     oemdata[256];
39} __attribute__ ((packed));
40
41struct vbemodeinfoblock {
42    // All VBE revisions
43    uint16_t    modeattributes;
44    uint8_t     winaattributes, winbattributes;
45    uint16_t    wingranularity;
46    uint16_t    winsize;
47    uint16_t    winasegment, winbsegment;
48    uint32_t    winfuncptr;
49    uint16_t    bytesperscanline;
50
51    // VBE 1.2 and up
52    uint16_t    xresolution, yresolution;
53    uint8_t     xcharsize, ycharsize;
54    uint8_t     numberofplanes;
55    uint8_t     bitsperpixel;
56    uint8_t     numberofbanks;
57    uint8_t     memorymodel;
58    uint8_t     banksize;
59    uint8_t     numberofimagepanes;
60    uint8_t     reserved;
61
62    // Direct color fields
63    uint8_t     redmasksize, redfieldposition;
64    uint8_t     greenmasksize, greenfieldposition;
65    uint8_t     bluemasksize, bluefieldposition;
66    uint8_t     rsvdmasksize, rsvdfieldposition;
67    uint8_t     directcolormodeinfo;
68
69    // VBE 2.0 and up
70    uint32_t    physbaseptr;
71    uint32_t    offscreenmemoffset;
72    uint16_t    offscreenmemsize;
73    uint8_t     reserved2[206];
74} __attribute__ ((packed));
75
76enum modeattributes {
77    MODE_SUPPORTED              = 1 << 0,
78    TTY_OUTPUT_SUPPORTED        = 1 << 2,
79    COLOR_MODE                  = 1 << 3,
80    GRAPHICS_MODE               = 1 << 4,
81    MODE_NOT_VGA_COMPATIBLE     = 1 << 5,
82    WINDOWED_MODE_NOT_AVAILABLE = 1 << 6,
83    LINEAR_MODE_AVAILABLE       = 1 << 7
84};
85
86enum windowattributes {
87    RELOCATABLE_WINDOWS_SUPPORTED       = 1 << 0,
88    WINDOW_READABLE                     = 1 << 1,
89    WINDOW_WRITEABLE                    = 1 << 2
90};
91
92enum memorymodel {
93    MODEL_TEXT = 0,
94    MODEL_CGA = 1,
95    MODEL_HERCULES = 2,
96    MODEL_PLANAR = 3,
97    MODEL_PACKED_PIXEL = 4,
98    MODEL_NON_CHAIN_4 = 5,
99    MODEL_DIRECT_COLOR = 6,
100    MODEL_YUV = 7
101};
102
103enum directcolormode {
104    DCM_RAMP_PROGRAMMABLE       = 1 << 0,
105    DCM_RSVD_BITS_USABLE        = 1 << 1
106};
107
108uint32_t vbe_controller_info(struct vbeinfoblock *ib);
109uint32_t vbe_mode_info(uint16_t mode, struct vbemodeinfoblock *mib);
110uint32_t vbe_setmode(uint16_t mode, bool linear, bool clear);
111uint32_t vbe_getmode(uint16_t *retmode, bool *retlinear);
112uint16_t *vbe_getmodes(void);
113uint32_t vbe_savestate(void);
114uint32_t vbe_restorestate(void);
115errval_t vbe_get_framebuffer_cap(struct capref *cap, size_t *offset);
116void vbe_vsync(void);
117
118void vbe_init(void *arg, struct device_mem *bar_info, int nr_mapped_regions);
119
120void vbe_driver_init_done(void);
121
122#endif
123