Patrick Georgi | 593124d | 2020-05-10 19:44:08 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: MIT */ |
Nico Huber | 3db7653 | 2017-05-18 18:07:34 +0200 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <edid.h> |
| 5 | #include <boot/coreboot_tables.h> |
| 6 | |
| 7 | static int fb_valid; |
| 8 | static struct lb_framebuffer edid_fb; |
| 9 | |
| 10 | /* |
| 11 | * Take an edid, and create a framebuffer. Set fb_valid to 1. |
| 12 | */ |
| 13 | void set_vbe_mode_info_valid(const struct edid *edid, uintptr_t fb_addr) |
| 14 | { |
| 15 | edid_fb.physical_address = fb_addr; |
| 16 | edid_fb.x_resolution = edid->x_resolution; |
| 17 | edid_fb.y_resolution = edid->y_resolution; |
| 18 | edid_fb.bytes_per_line = edid->bytes_per_line; |
| 19 | /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention |
| 20 | * nowadays seems to be to round it up to the nearest reasonable |
| 21 | * boundary, because otherwise the byte-packing is hideous. |
| 22 | * So, for example, in RGB with no alpha, the bytes are still |
| 23 | * packed into 32-bit words, the so-called 32bpp-no-alpha mode. |
| 24 | * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words, |
| 25 | * and in 4:4:4 mode, they are packed into 16-bit words. |
| 26 | * Good call on the hardware guys part. |
| 27 | * It's not clear we're covering all cases here, but |
| 28 | * I'm not sure with grahpics you ever can. |
| 29 | */ |
| 30 | edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel; |
| 31 | edid_fb.reserved_mask_pos = 0; |
| 32 | edid_fb.reserved_mask_size = 0; |
| 33 | switch (edid->framebuffer_bits_per_pixel) { |
| 34 | case 32: |
| 35 | case 24: |
| 36 | /* packed into 4-byte words */ |
| 37 | edid_fb.reserved_mask_pos = 24; |
| 38 | edid_fb.reserved_mask_size = 8; |
| 39 | edid_fb.red_mask_pos = 16; |
| 40 | edid_fb.red_mask_size = 8; |
| 41 | edid_fb.green_mask_pos = 8; |
| 42 | edid_fb.green_mask_size = 8; |
| 43 | edid_fb.blue_mask_pos = 0; |
| 44 | edid_fb.blue_mask_size = 8; |
| 45 | break; |
| 46 | case 16: |
| 47 | /* packed into 2-byte words */ |
| 48 | edid_fb.red_mask_pos = 11; |
| 49 | edid_fb.red_mask_size = 5; |
| 50 | edid_fb.green_mask_pos = 5; |
| 51 | edid_fb.green_mask_size = 6; |
| 52 | edid_fb.blue_mask_pos = 0; |
| 53 | edid_fb.blue_mask_size = 5; |
| 54 | break; |
| 55 | default: |
| 56 | printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__, |
| 57 | edid->framebuffer_bits_per_pixel); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | fb_valid = 1; |
| 62 | } |
| 63 | |
Nicolas Boichat | 87f265b | 2019-08-06 08:29:52 +0800 | [diff] [blame] | 64 | void set_vbe_framebuffer_orientation(enum lb_fb_orientation orientation) |
| 65 | { |
| 66 | edid_fb.orientation = orientation; |
| 67 | } |
| 68 | |
Nico Huber | 3db7653 | 2017-05-18 18:07:34 +0200 | [diff] [blame] | 69 | int fill_lb_framebuffer(struct lb_framebuffer *framebuffer) |
| 70 | { |
| 71 | if (!fb_valid) |
| 72 | return -1; |
| 73 | |
| 74 | *framebuffer = edid_fb; |
| 75 | |
| 76 | return 0; |
| 77 | } |