1 // Option rom scanning code.
3 // Copyright (C) 2009-2010 coresystems GmbH
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
7 #include "bregs.h" // struct bregs
8 #include "farptr.h" // FLATPTR_TO_SEG
9 #include "config.h" // CONFIG_*
10 #include "util.h" // dprintf
11 #include "jpeg.h" // splash
13 /****************************************************************
15 ****************************************************************/
17 /****************************************************************
19 ****************************************************************/
25 struct segoff_s oem_string_ptr;
27 struct segoff_s video_mode_ptr;
30 struct segoff_s oem_vendor_name_ptr;
31 struct segoff_s oem_product_name_ptr;
32 struct segoff_s oem_product_rev_ptr;
47 u16 bytes_per_scanline;
57 u8 number_of_image_pages;
65 u8 reserved_mask_size;
67 u8 direct_color_mode_info;
69 u32 offscreen_mem_offset;
70 u16 offscreen_mem_size;
74 /****************************************************************
76 ****************************************************************/
78 /****************************************************************
79 * VGA text / graphics console
80 ****************************************************************/
81 static void enable_vga_text_console(void)
83 dprintf(1, "Turning on vga text mode console\n");
86 /* Enable VGA text mode */
87 memset(&br, 0, sizeof(br));
91 call16_int(0x10, &br);
94 if (CONFIG_BOOTSPLASH) {
95 /* Switch back to start of the framebuffer
96 * (disable "double buffering")
98 memset(&br, 0, sizeof(br));
105 call16_int(0x10, &br);
110 printf("Starting SeaBIOS (version %s)\n\n", VERSION);
113 void enable_vga_console(void)
115 /* Needs coreboot support for CBFS */
116 if (!CONFIG_BOOTSPLASH || !CONFIG_COREBOOT) {
117 enable_vga_text_console();
122 struct vesa_info *vesa_info;
123 struct vesa_mode_info *mode_info;
124 struct jpeg_decdata *decdata;
126 vesa_info = malloc_tmplow(sizeof(*vesa_info));
127 mode_info = malloc_tmplow(sizeof(*mode_info));
128 decdata = malloc_tmphigh(sizeof(*decdata));
130 /* Check whether we have a VESA 2.0 compliant BIOS */
131 memset(vesa_info, 0, sizeof(struct vesa_info));
132 memcpy(vesa_info, "VBE2", 4);
134 memset(&br, 0, sizeof(br));
137 br.di = FLATPTR_TO_OFFSET(vesa_info);
138 br.es = FLATPTR_TO_SEG(vesa_info);
140 call16_int(0x10, &br);
143 if(strcmp("VESA", (char *)vesa_info) != 0) {
144 dprintf(1,"No VBE2 found.\n");
148 /* Print some debugging information about our card. */
149 char *vendor = SEGOFF_TO_FLATPTR(vesa_info->oem_vendor_name_ptr);
150 char *product = SEGOFF_TO_FLATPTR(vesa_info->oem_product_name_ptr);
152 dprintf(8, "VESA %d.%d\nVENDOR: %s\nPRODUCT: %s\n",
153 vesa_info->vesa_version>>8, vesa_info->vesa_version&0xff,
156 /* Get information about our graphics mode, like the
157 * framebuffer start address
159 memset(&br, 0, sizeof(br));
162 br.cx = (1 << 14) | CONFIG_BOOTSPLASH_VESA_MODE;
163 br.di = FLATPTR_TO_OFFSET(mode_info);
164 br.es = FLATPTR_TO_SEG(mode_info);
166 call16_int(0x10, &br);
169 dprintf(1, "get_mode failed.\n");
170 enable_vga_text_console();
173 unsigned char *framebuffer = (unsigned char *) (mode_info->phys_base_ptr);
175 /* Switch to graphics mode */
176 memset(&br, 0, sizeof(br));
179 br.bx = (1 << 14) | CONFIG_BOOTSPLASH_VESA_MODE;
181 call16_int(0x10, &br);
184 dprintf(1, "set_mode failed.\n");
185 enable_vga_text_console();
189 /* Switching Intel IGD to 1MB video memory will break this. Who cares. */
190 int imagesize = CONFIG_BOOTSPLASH_X * CONFIG_BOOTSPLASH_Y *
191 (CONFIG_BOOTSPLASH_DEPTH / 8);
193 /* We use "double buffering" to make things look nicer */
194 framebuffer += imagesize;
196 dprintf(8, "framebuffer: %x\n", (u32)framebuffer);
197 dprintf(8, "bytes per scanline: %d\n", mode_info->bytes_per_scanline);
198 dprintf(8, "bits per pixel: %d\n", mode_info->bits_per_pixel);
200 /* Look for bootsplash.jpg in CBFS and decompress it... */
202 unsigned char *jpeg = NULL;
204 struct cbfs_file *file = cbfs_finddatafile("bootsplash.jpg");
208 filesize = cbfs_datasize(file);
209 jpeg = malloc_tmphigh(filesize);
211 dprintf(1, "Could not find boot splash screen \"bootsplash.jpg\"\n");
214 dprintf(8, "Copying boot splash screen...\n");
215 cbfs_copyfile(file, jpeg, filesize);
216 dprintf(8, "Decompressing boot splash screen...\n");
217 ret = jpeg_decode(jpeg, framebuffer, CONFIG_BOOTSPLASH_X,
218 CONFIG_BOOTSPLASH_Y, CONFIG_BOOTSPLASH_DEPTH, decdata);
220 dprintf(1, "Failed with return code %d...\n", ret);
226 enable_vga_text_console();
230 /* Show the picture */
231 memset(&br, 0, sizeof(br));
237 call16_int(0x10, &br);
240 dprintf(1, "display_start failed (ax=%04x).\n", br.ax);
241 enable_vga_text_console();
251 disable_bootsplash(void)
253 if (! CONFIG_BOOTSPLASH)
255 enable_vga_text_console();