Nico Huber | 3db7653 | 2017-05-18 18:07:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
| 8 | * license, and/or sell copies of the Software, and to permit persons to whom |
| 9 | * the Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #include <console/console.h> |
| 24 | #include <edid.h> |
| 25 | #include <boot/coreboot_tables.h> |
| 26 | |
| 27 | static int fb_valid; |
| 28 | static struct lb_framebuffer edid_fb; |
| 29 | |
| 30 | /* |
| 31 | * Take an edid, and create a framebuffer. Set fb_valid to 1. |
| 32 | */ |
| 33 | void set_vbe_mode_info_valid(const struct edid *edid, uintptr_t fb_addr) |
| 34 | { |
| 35 | edid_fb.physical_address = fb_addr; |
| 36 | edid_fb.x_resolution = edid->x_resolution; |
| 37 | edid_fb.y_resolution = edid->y_resolution; |
| 38 | edid_fb.bytes_per_line = edid->bytes_per_line; |
| 39 | /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention |
| 40 | * nowadays seems to be to round it up to the nearest reasonable |
| 41 | * boundary, because otherwise the byte-packing is hideous. |
| 42 | * So, for example, in RGB with no alpha, the bytes are still |
| 43 | * packed into 32-bit words, the so-called 32bpp-no-alpha mode. |
| 44 | * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words, |
| 45 | * and in 4:4:4 mode, they are packed into 16-bit words. |
| 46 | * Good call on the hardware guys part. |
| 47 | * It's not clear we're covering all cases here, but |
| 48 | * I'm not sure with grahpics you ever can. |
| 49 | */ |
| 50 | edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel; |
| 51 | edid_fb.reserved_mask_pos = 0; |
| 52 | edid_fb.reserved_mask_size = 0; |
| 53 | switch (edid->framebuffer_bits_per_pixel) { |
| 54 | case 32: |
| 55 | case 24: |
| 56 | /* packed into 4-byte words */ |
| 57 | edid_fb.reserved_mask_pos = 24; |
| 58 | edid_fb.reserved_mask_size = 8; |
| 59 | edid_fb.red_mask_pos = 16; |
| 60 | edid_fb.red_mask_size = 8; |
| 61 | edid_fb.green_mask_pos = 8; |
| 62 | edid_fb.green_mask_size = 8; |
| 63 | edid_fb.blue_mask_pos = 0; |
| 64 | edid_fb.blue_mask_size = 8; |
| 65 | break; |
| 66 | case 16: |
| 67 | /* packed into 2-byte words */ |
| 68 | edid_fb.red_mask_pos = 11; |
| 69 | edid_fb.red_mask_size = 5; |
| 70 | edid_fb.green_mask_pos = 5; |
| 71 | edid_fb.green_mask_size = 6; |
| 72 | edid_fb.blue_mask_pos = 0; |
| 73 | edid_fb.blue_mask_size = 5; |
| 74 | break; |
| 75 | default: |
| 76 | printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__, |
| 77 | edid->framebuffer_bits_per_pixel); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | fb_valid = 1; |
| 82 | } |
| 83 | |
| 84 | int fill_lb_framebuffer(struct lb_framebuffer *framebuffer) |
| 85 | { |
| 86 | if (!fb_valid) |
| 87 | return -1; |
| 88 | |
| 89 | *framebuffer = edid_fb; |
| 90 | |
| 91 | return 0; |
| 92 | } |