1 // Simple framebuffer vgabios for use with coreboot native vga init.
3 // Copyright (C) 2014 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
7 #include "biosvar.h" // GET_BDA
8 #include "cbvga.h" // cbvga_setup
9 #include "output.h" // dprintf
10 #include "stdvga.h" // SEG_CTEXT
11 #include "string.h" // memset16_far
12 #include "util.h" // find_cb_table
13 #include "vgabios.h" // VGAREG_*
15 static int CBmode VAR16;
16 static struct vgamode_s CBmodeinfo VAR16;
17 static struct vgamode_s CBemulinfo VAR16;
18 static u32 CBlinelength VAR16;
20 struct vgamode_s *cbvga_find_mode(int mode)
22 if (mode == GET_GLOBAL(CBmode))
30 cbvga_list_modes(u16 seg, u16 *dest, u16 *last)
33 SET_FARVAR(seg, *dest, GET_GLOBAL(CBmode));
36 SET_FARVAR(seg, *dest, 0xffff);
40 cbvga_get_window(struct vgamode_s *vmode_g, int window)
46 cbvga_set_window(struct vgamode_s *vmode_g, int window, int val)
52 cbvga_get_linelength(struct vgamode_s *vmode_g)
54 return GET_GLOBAL(CBlinelength);
58 cbvga_set_linelength(struct vgamode_s *vmode_g, int val)
64 cbvga_get_displaystart(struct vgamode_s *vmode_g)
70 cbvga_set_displaystart(struct vgamode_s *vmode_g, int val)
76 cbvga_get_dacformat(struct vgamode_s *vmode_g)
82 cbvga_set_dacformat(struct vgamode_s *vmode_g, int val)
88 cbvga_save_restore(int cmd, u16 seg, void *data)
90 if (cmd & (SR_HARDWARE|SR_DAC|SR_REGISTERS))
92 return bda_save_restore(cmd, seg, data);
96 cbvga_set_mode(struct vgamode_s *vmode_g, int flags)
98 u8 emul = vmode_g == &CBemulinfo || GET_GLOBAL(CBmode) == 0x03;
99 MASK_BDA_EXT(flags, BF_EMULATE_TEXT, emul ? BF_EMULATE_TEXT : 0);
100 if (!(flags & MF_NOCLEARMEM)) {
101 if (GET_GLOBAL(CBmodeinfo.memmodel) == MM_TEXT) {
102 memset16_far(SEG_CTEXT, (void*)0, 0x0720, 80*25*2);
106 init_gfx_op(&op, vmode_g);
108 op.xlen = GET_GLOBAL(CBmodeinfo.width);
109 op.ylen = GET_GLOBAL(CBmodeinfo.height);
116 #define CB_TAG_FRAMEBUFFER 0x0012
117 struct cb_framebuffer {
121 u64 physical_address;
132 u8 reserved_mask_pos;
133 u8 reserved_mask_size;
139 dprintf(1, "coreboot vga init\n");
141 if (GET_GLOBAL(HaveRunInit))
144 struct cb_header *cbh = find_cb_table();
146 dprintf(1, "Unable to find coreboot table\n");
149 struct cb_framebuffer *cbfb = find_cb_subtable(cbh, CB_TAG_FRAMEBUFFER);
151 // Assume there is an EGA text framebuffer.
152 dprintf(1, "Did not find coreboot framebuffer - assuming EGA text\n");
153 SET_VGA(CBmode, 0x03);
154 SET_VGA(CBlinelength, 80*2);
155 SET_VGA(CBmodeinfo.memmodel, MM_TEXT);
156 SET_VGA(CBmodeinfo.width, 80);
157 SET_VGA(CBmodeinfo.height, 25);
158 SET_VGA(CBmodeinfo.depth, 4);
159 SET_VGA(CBmodeinfo.cwidth, 9);
160 SET_VGA(CBmodeinfo.cheight, 16);
161 SET_VGA(CBmodeinfo.sstart, SEG_CTEXT);
165 u64 addr = GET_FARVAR(0, cbfb->physical_address);
166 u8 bpp = GET_FARVAR(0, cbfb->bits_per_pixel);
167 u32 xlines = GET_FARVAR(0, cbfb->x_resolution);
168 u32 ylines = GET_FARVAR(0, cbfb->y_resolution);
169 u32 linelength = GET_FARVAR(0, cbfb->bytes_per_line);
170 dprintf(1, "Found FB @ %llx %dx%d with %d bpp (%d stride)\n"
171 , addr, xlines, ylines, bpp, linelength);
173 if (!addr || addr > 0xffffffff
174 || (bpp != 15 && bpp != 16 && bpp != 24 && bpp != 32)) {
175 dprintf(1, "Unable to use FB\n");
179 SET_VGA(CBmode, 0x140);
180 SET_VGA(VBE_framebuffer, addr);
181 SET_VGA(VBE_total_memory, linelength * ylines);
182 SET_VGA(CBlinelength, linelength);
183 SET_VGA(CBmodeinfo.memmodel, MM_DIRECT);
184 SET_VGA(CBmodeinfo.width, xlines);
185 SET_VGA(CBmodeinfo.height, ylines);
186 SET_VGA(CBmodeinfo.depth, bpp);
187 SET_VGA(CBmodeinfo.cwidth, 8);
188 SET_VGA(CBmodeinfo.cheight, 16);
189 memcpy_far(get_global_seg(), &CBemulinfo
190 , get_global_seg(), &CBmodeinfo, sizeof(CBemulinfo));