diff --git a/src/kboot.c b/src/kboot.c index 249321d31..680099f31 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -36,6 +36,43 @@ static size_t initrd_size = 0; goto err; \ } while (0) +void get_notchless_fb(u64 *fb_base, u64 *fb_height) { + *fb_base = cur_boot_args.video.base; + *fb_height = cur_boot_args.video.height; + + int node = adt_path_offset(adt, "/product"); + + if (node < 0) { + printf("FDT: /product node not found\n"); + return; + } + + u32 val; + + if (ADT_GETPROP(adt, node, "partially-occluded-display", &val) < 0 || !val) { + printf("FDT: No notch detected\n"); + return; + } + + u64 hfrac = cur_boot_args.video.height * 16 / cur_boot_args.video.width; + u64 new_height = cur_boot_args.video.width * hfrac / 16; + + if (new_height == cur_boot_args.video.height) { + printf("FDT: Notch detected, but display aspect is already 16:%lu?\n", hfrac); + return; + } + + u64 offset = cur_boot_args.video.height - new_height; + + printf("display: Hiding notch, %lux%lu -> %lux%lu (+%lu, 16:%lu)\n", + cur_boot_args.video.width, cur_boot_args.video.height, + cur_boot_args.video.width, new_height, + offset, hfrac); + + *fb_base += cur_boot_args.video.stride * offset; + *fb_height = new_height; +} + static int dt_set_chosen(void) { @@ -69,8 +106,9 @@ static int dt_set_chosen(void) if (fb < 0) bail("FDT: /chosen node not found in devtree\n"); - u64 fb_base = cur_boot_args.video.base; - u64 fb_size = cur_boot_args.video.stride * cur_boot_args.video.height; + u64 fb_base, fb_height; + get_notchless_fb(&fb_base, &fb_height); + u64 fb_size = cur_boot_args.video.stride * fb_height; u64 fbreg[2] = {cpu_to_fdt64(fb_base), cpu_to_fdt64(fb_size)}; char fbname[32]; @@ -85,7 +123,7 @@ static int dt_set_chosen(void) if (fdt_setprop_u32(dt, fb, "width", cur_boot_args.video.width)) bail("FDT: couldn't set framebuffer width\n"); - if (fdt_setprop_u32(dt, fb, "height", cur_boot_args.video.height)) + if (fdt_setprop_u32(dt, fb, "height", fb_height)) bail("FDT: couldn't set framebuffer height\n"); if (fdt_setprop_u32(dt, fb, "stride", cur_boot_args.video.stride))