1 // Option rom scanning code.
3 // Copyright (C) 2009-2010 coresystems GmbH
4 // Copyright (C) 2010 Kevin O'Connor <kevin@koconnor.net>
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
8 #include "bregs.h" // struct bregs
9 #include "farptr.h" // FLATPTR_TO_SEG
10 #include "config.h" // CONFIG_*
11 #include "util.h" // dprintf
12 #include "jpeg.h" // splash
13 #include "biosvar.h" // SET_EBDA
16 /****************************************************************
18 ****************************************************************/
24 struct segoff_s oem_string_ptr;
26 struct segoff_s video_mode_ptr;
29 struct segoff_s oem_vendor_name_ptr;
30 struct segoff_s oem_product_name_ptr;
31 struct segoff_s oem_product_rev_ptr;
36 #define VESA_SIGNATURE 0x41534556 // VESA
37 #define VBE2_SIGNATURE 0x32454256 // VBE2
49 u16 bytes_per_scanline;
59 u8 number_of_image_pages;
67 u8 reserved_mask_size;
69 u8 direct_color_mode_info;
71 u32 offscreen_mem_offset;
72 u16 offscreen_mem_size;
76 /****************************************************************
78 ****************************************************************/
80 // Call int10 vga handler.
82 call16_int10(struct bregs *br)
91 /****************************************************************
92 * VGA text / graphics console
93 ****************************************************************/
95 static void enable_vga_text_console(void)
97 dprintf(1, "Turning on vga text mode console\n");
100 /* Enable VGA text mode */
101 memset(&br, 0, sizeof(br));
106 printf("SeaBIOS (version %s)\n\n", VERSION);
110 find_videomode(struct vesa_info *vesa_info, struct vesa_mode_info *mode_info
111 , int width, int height)
113 dprintf(3, "Finding vesa mode with dimensions %d/%d\n", width, height);
114 u16 *videomodes = SEGOFF_TO_FLATPTR(vesa_info->video_mode_ptr);
115 for (;; videomodes++) {
116 u16 videomode = *videomodes;
117 if (videomode == 0xffff) {
118 dprintf(1, "Unable to find vesa video mode dimensions %d/%d\n"
123 memset(&br, 0, sizeof(br));
125 br.cx = (1 << 14) | videomode;
126 br.di = FLATPTR_TO_OFFSET(mode_info);
127 br.es = FLATPTR_TO_SEG(mode_info);
130 dprintf(1, "get_mode failed.\n");
133 if (mode_info->x_resolution != width
134 || mode_info->y_resolution != height)
136 u8 depth = mode_info->bits_per_pixel;
137 if (depth != 16 && depth != 24 && depth != 32)
143 void enable_vga_console(void)
145 struct vesa_info *vesa_info = NULL;
146 struct vesa_mode_info *mode_info = NULL;
147 struct jpeg_decdata *jpeg = NULL;
148 u8 *filedata = NULL, *picture = NULL;
150 /* Needs coreboot support for CBFS */
151 if (!CONFIG_BOOTSPLASH || !CONFIG_COREBOOT)
153 struct cbfs_file *file = cbfs_finddatafile("bootsplash.jpg");
156 int filesize = cbfs_datasize(file);
158 filedata = malloc_tmphigh(filesize);
159 vesa_info = malloc_tmplow(sizeof(*vesa_info));
160 mode_info = malloc_tmplow(sizeof(*mode_info));
162 if (!filedata || !jpeg || !vesa_info || !mode_info) {
167 /* Check whether we have a VESA 2.0 compliant BIOS */
168 memset(vesa_info, 0, sizeof(struct vesa_info));
169 vesa_info->vesa_signature = VBE2_SIGNATURE;
171 memset(&br, 0, sizeof(br));
173 br.di = FLATPTR_TO_OFFSET(vesa_info);
174 br.es = FLATPTR_TO_SEG(vesa_info);
176 if (vesa_info->vesa_signature != VESA_SIGNATURE) {
177 dprintf(1,"No VBE2 found.\n");
181 /* Print some debugging information about our card. */
182 char *vendor = SEGOFF_TO_FLATPTR(vesa_info->oem_vendor_name_ptr);
183 char *product = SEGOFF_TO_FLATPTR(vesa_info->oem_product_name_ptr);
184 dprintf(3, "VESA %d.%d\nVENDOR: %s\nPRODUCT: %s\n",
185 vesa_info->vesa_version>>8, vesa_info->vesa_version&0xff,
188 // Parse jpeg and get image size.
189 cbfs_copyfile(file, filedata, filesize);
190 int ret = jpeg_decode(jpeg, filedata);
192 dprintf(1, "jpeg_decode failed with return code %d...\n", ret);
196 jpeg_get_size(jpeg, &width, &height);
198 // Try to find a graphics mode with the corresponding dimensions.
199 int videomode = find_videomode(vesa_info, mode_info, width, height);
202 void *framebuffer = mode_info->phys_base_ptr;
203 int depth = mode_info->bits_per_pixel;
204 dprintf(3, "mode: %04x\n", videomode);
205 dprintf(3, "framebuffer: %p\n", framebuffer);
206 dprintf(3, "bytes per scanline: %d\n", mode_info->bytes_per_scanline);
207 dprintf(3, "bits per pixel: %d\n", depth);
209 // Allocate space for image and decompress it.
210 int imagesize = width * height * (depth / 8);
211 picture = malloc_tmphigh(imagesize);
216 ret = jpeg_show(jpeg, picture, width, height, depth);
218 dprintf(1, "jpeg_show failed with return code %d...\n", ret);
222 /* Switch to graphics mode */
223 memset(&br, 0, sizeof(br));
225 br.bx = (1 << 14) | videomode;
228 dprintf(1, "set_mode failed.\n");
232 /* Show the picture */
233 iomemcpy(framebuffer, picture, imagesize);
234 SET_EBDA(bootsplash_active, 1);
244 enable_vga_text_console();
249 disable_bootsplash(void)
251 if (!CONFIG_BOOTSPLASH || !CONFIG_COREBOOT || !GET_EBDA(bootsplash_active))
253 SET_EBDA(bootsplash_active, 0);
254 enable_vga_text_console();