From nobody Thu Mar 09 16:14:32 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PXZ5521tSz3x633; Thu, 9 Mar 2023 16:14:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PXZ551Kfrz441j; Thu, 9 Mar 2023 16:14:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678378473; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ThCR+DgZ2Le5s2F4nBiJkbliiC7rV5IZULDvwF5kWZk=; b=njoAGyCdxx7Cm7iRDpGVMk2oqkRvLY/gWqNgFwCGr920MY2DcDSoWtky/T5cI7Bgcdpz/f DGrOUk0lSMjlYqU+GVml22MZVY4OtTfUZRlPNdMzV8qCFSnyf8UTO6Eo73eMBZUUY1QYFU 8i+iIbq8pHMTiAKAqNEmHOHOlNnW3EtZDaoysBCuF70aPIVdrgv9/QLTg62CIzPRycM/EV c/aAayaPaxBKOwmDE+jiriT9tbFGYuH95U0ViQ2tBSM6nmuk3YjXkQRxBNPUY7htANIphH EOOdkclp0tHPo1QfqP4FiO+PdY0imENeqJGnYZof8i8z5E+G7inhJ1PjsuwnMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678378473; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ThCR+DgZ2Le5s2F4nBiJkbliiC7rV5IZULDvwF5kWZk=; b=tA1GyRbN255a5rv867iBR5au4h7SpeJQJh1YYjN8X/7CkChbxohxBFVvg/gU2gFDT3qJmh ht55+/zonRgxXh2yj9m68eED1Z3gwX/PoybOiZX0M4nTIeOER8IF6HgxG6lwwiSpEn47kQ 9en6bko1yL+blPmDwWm6VXU5B15O3Oj4OBoOjQtuCUXj6h3Js5Z6Xy1A7o4W/VMhUBxBCq M7FY8OHrSU+J0OllPKnSyN+95awkJ1FnSEpkjQAqMctIMabBWrZBOLlWo9m82ES0P+PppU kUhNvckOtZtZ5E6tnjsmN3fmWydr9+qdhZLcPBvkKgA0BtNtURmQapPPx5cbzw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678378473; a=rsa-sha256; cv=none; b=CdhVUawZ5yUnSfaRwPo1foBYJRNXsJGFs3Q3a2x/oT+KSeiOujcYJaYUZD2GfZUUBk026u 1BBi6qK3+jbsjOLQoR3tWra/pF1Nj0w1vigR4pbik9X7H88jh4cGCw6HSVWgVmWDDAHdAm EXKPgUcxEQXUZiOrVk47HUk6JXvnl0wOkxQwzLeBByUgz6ej2PArhN2e5r2SLmv/uJrsYh ytZ7/f24poYKgjtboP3ascqRBRLQIsi5I7dza1MYSBOJsP7gk+CZdEI+7bGN9P4prbwV6h x2FW0iEn8FBbVh3EV4eUa3cKhoa3QM0ScHFDixE+NRVzEMZrr4DLU042SySi0Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PXZ550DCTzDx5; Thu, 9 Mar 2023 16:14:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 329GEWcM097645; Thu, 9 Mar 2023 16:14:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 329GEW3k097644; Thu, 9 Mar 2023 16:14:32 GMT (envelope-from git) Date: Thu, 9 Mar 2023 16:14:32 GMT Message-Id: <202303091614.329GEW3k097644@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Roger=20Pau=20Monn=C3=A9?= Subject: git: 6f80738b228c - main - xen: fetch dom0 video console information from Xen List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: royger X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6f80738b228c04e3ff3f2d14eea2161d2cf4f81c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by royger: URL: https://cgit.FreeBSD.org/src/commit/?id=6f80738b228c04e3ff3f2d14eea2161d2cf4f81c commit 6f80738b228c04e3ff3f2d14eea2161d2cf4f81c Author: Roger Pau Monné AuthorDate: 2022-11-21 11:40:08 +0000 Commit: Roger Pau Monné CommitDate: 2023-03-09 16:13:17 +0000 xen: fetch dom0 video console information from Xen It's possible for Xen to switch the video mode set by the boot loader, so that the information passed in the kernel metadata is no longer valid. Fetch the video mode used by Xen using an hypercall and update the medatada for the kernel to use the correct video mode. Sponsored by: Citrix Systems R&D --- sys/contrib/xen/platform.h | 5 ++++ sys/x86/xen/pv.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/sys/contrib/xen/platform.h b/sys/contrib/xen/platform.h index 81001335094b..ccd6be741876 100644 --- a/sys/contrib/xen/platform.h +++ b/sys/contrib/xen/platform.h @@ -622,6 +622,10 @@ struct xenpf_symdata { typedef struct xenpf_symdata xenpf_symdata_t; DEFINE_XEN_GUEST_HANDLE(xenpf_symdata_t); +#define XENPF_get_dom0_console 64 +typedef struct dom0_vga_console_info xenpf_dom0_console_t; +DEFINE_XEN_GUEST_HANDLE(xenpf_dom0_console_t); + /* * ` enum neg_errnoval * ` HYPERVISOR_platform_op(const struct xen_platform_op*); @@ -652,6 +656,7 @@ struct xen_platform_op { xenpf_core_parking_t core_parking; xenpf_resource_op_t resource_op; xenpf_symdata_t symdata; + xenpf_dom0_console_t dom0_console; uint8_t pad[128]; } u; }; diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c index 28794db98700..d721e9bb530e 100644 --- a/sys/x86/xen/pv.c +++ b/sys/x86/xen/pv.c @@ -336,6 +336,75 @@ xen_pvh_parse_symtab(void) } #endif +static void +fixup_console(caddr_t kmdp) +{ + struct xen_platform_op op = { + .cmd = XENPF_get_dom0_console, + }; + xenpf_dom0_console_t *console = &op.u.dom0_console; + union { + struct efi_fb efi; + struct vbe_fb vbe; + } *fb = NULL; + int ret; + + ret = HYPERVISOR_platform_op(&op); + if (ret != 0) { + xc_printf("Failed to get dom0 video console info\n"); + return; + } + + switch (console->video_type) { + case XEN_VGATYPE_VESA_LFB: + fb = (__typeof__ (fb))preload_search_info(kmdp, + MODINFO_METADATA | MODINFOMD_VBE_FB); + + if (fb == NULL) { + xc_printf("No VBE FB in kernel metadata\n"); + return; + } + + _Static_assert(offsetof(struct vbe_fb, fb_bpp) == + offsetof(struct efi_fb, fb_mask_reserved) + + sizeof(fb->efi.fb_mask_reserved), + "Bad structure overlay\n"); + fb->vbe.fb_bpp = console->u.vesa_lfb.bits_per_pixel; + /* FALLTHROUGH */ + case XEN_VGATYPE_EFI_LFB: + if (fb == NULL) { + fb = (__typeof__ (fb))preload_search_info(kmdp, + MODINFO_METADATA | MODINFOMD_EFI_FB); + if (fb == NULL) { + xc_printf("No EFI FB in kernel metadata\n"); + return; + } + } + + fb->efi.fb_addr = console->u.vesa_lfb.lfb_base | + ((uint64_t)console->u.vesa_lfb.ext_lfb_base << 32); + fb->efi.fb_size = console->u.vesa_lfb.lfb_size << 16; + fb->efi.fb_height = console->u.vesa_lfb.height; + fb->efi.fb_width = console->u.vesa_lfb.width; + fb->efi.fb_stride = (console->u.vesa_lfb.bytes_per_line << 3) / + console->u.vesa_lfb.bits_per_pixel; +#define FBMASK(c) \ + ((~0u << console->u.vesa_lfb.c ## _pos) & \ + (~0u >> (32 - console->u.vesa_lfb.c ## _pos - \ + console->u.vesa_lfb.c ## _size))) + fb->efi.fb_mask_red = FBMASK(red); + fb->efi.fb_mask_green = FBMASK(green); + fb->efi.fb_mask_blue = FBMASK(blue); + fb->efi.fb_mask_reserved = FBMASK(rsvd); +#undef FBMASK + break; + + default: + xc_printf("Video console type unsupported\n"); + return; + } +} + static caddr_t xen_pvh_parse_preload_data(uint64_t modulep) { @@ -414,6 +483,8 @@ xen_pvh_parse_preload_data(uint64_t modulep) strlcpy(bootmethod, "UEFI", sizeof(bootmethod)); else strlcpy(bootmethod, "BIOS", sizeof(bootmethod)); + + fixup_console(kmdp); } else { /* Parse the extra boot information given by Xen */ if (start_info->cmdline_paddr != 0)