From nobody Wed Oct 04 16:54:14 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 4S114Q72nGz4wH64; Wed, 4 Oct 2023 16:54:14 +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 4S114Q5yy7z3DMG; Wed, 4 Oct 2023 16:54:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696438454; 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=R0IzUI5Gsvvgp7jvrtpnUFCJwgZEnJ02MnjW5Sna/NM=; b=cb/PrJdnjAXa0A0Cq8bL+yjrLrIHrfETm+garQmn+HsIp+7/xetNiHG48rrKaMk2Solu3V DcjGlTZJZNNMWD4wg7O9F7fv3WR/OUw842g3hv+A59bBibJwy0qcNe7IifS/S+7ChRnUKR t1j50gB/f/U+ZHApuF6TfS/vjvQM1ziV8195bWrtnhdn8AWjKkcwoIWNrodnL/zJY6B/7V yjgCqapyfU/IDHALDxcZAZ97Bg/x//aELr7YbzSYDHv68KPfQgH7pSnsrjRB3w2YGnQGm6 p5Kcs+zCzH0Oln5wh8TA2b4VfTkXMQ2N/95dHnLoh/QS2W97B44prMpTP4hhXA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696438454; a=rsa-sha256; cv=none; b=Q7pnQ2deBr0ULwewoYm+mD5h0J5Bdnp2f8Hd7BGx7BrSbwwB9d0vDscIyLEXLaqYJVDJeo NCFGkiNoRdemhrli3oBiPDxYGKb7j41Ve7wzUDksCtTp73OB43xKCVbyW6YS41XNiO+uBG arrMI1H/UXss0kYppDkiwp7Y3fgPWI8CsrXLjf8AUSuJ8HnG4jJY50bY2Jah0fbUuixNAM XqVCqikuXcvqlL+kiafXWXqX7xeO0k4nxErvNwLX2Pl57PTFW9r0L4KXEIjjtLxpk9iC4D pnA0R/CpkySKEsnYn8/LG4KssxEt/9lfXSgEULInyzge7rOGR2dm3xr0nwfzpg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696438454; 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=R0IzUI5Gsvvgp7jvrtpnUFCJwgZEnJ02MnjW5Sna/NM=; b=SbyHU1sGZp70LzGZlUHJyVl5SJRc0J65waNZYCX43hAqBqNIjIXT39AvwgzXC7KwhFBWGX g9dAWw1PPWyEFEu5Qyb2mSxCSMQux3RQiJP/ifOfKjt5S01TjdoYEhXBOExqQRhnGWUpXB bMBiGy8Gbtbs8dmtZzXK5PzTrS1C7fJEskKDr/5YMAdWWH+uXsrZYjjl/YrN42Z252swbX M5Fxkh7mX4xLbIQ0X3P4D1NOYv54g/QtAkXBnaTVBKNirKq8JZhhrv+wj3Bj6S1MPJHGGB ipidR403vjE/W3WOIunsWj9RrRtApJPcaGi29rUJktt8HUDrhacUclbUf9yAkQ== 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 4S114Q53w1zlxK; Wed, 4 Oct 2023 16:54:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 394GsELa038304; Wed, 4 Oct 2023 16:54:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 394GsEDH038301; Wed, 4 Oct 2023 16:54:14 GMT (envelope-from git) Date: Wed, 4 Oct 2023 16:54:14 GMT Message-Id: <202310041654.394GsEDH038301@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: f82af74c7603 - main - bhyve: Move most early initialization into an MD routine 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f82af74c76030029d4d8af95c29f2036a20796a4 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f82af74c76030029d4d8af95c29f2036a20796a4 commit f82af74c76030029d4d8af95c29f2036a20796a4 Author: Mark Johnston AuthorDate: 2023-10-04 16:27:54 +0000 Commit: Mark Johnston CommitDate: 2023-10-04 16:53:17 +0000 bhyve: Move most early initialization into an MD routine Prior to initializing PCI devices, main() calls a number of initialization routines, many of which are amd64-specific. Move this list of calls to bhyverun_machdep.c. Similarly, add an MD function to handle late initialization. No functional change intended. Reviewed by: corvink, jhb MFC after: 1 week Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D40989 --- usr.sbin/bhyve/amd64/bhyverun_machdep.c | 62 +++++++++++++++++++++++ usr.sbin/bhyve/amd64/xmsr.c | 7 +-- usr.sbin/bhyve/bhyverun.c | 88 ++------------------------------- usr.sbin/bhyve/bhyverun.h | 2 + 4 files changed, 72 insertions(+), 87 deletions(-) diff --git a/usr.sbin/bhyve/amd64/bhyverun_machdep.c b/usr.sbin/bhyve/amd64/bhyverun_machdep.c index c6926abe61bc..40325a7f52c9 100644 --- a/usr.sbin/bhyve/amd64/bhyverun_machdep.c +++ b/usr.sbin/bhyve/amd64/bhyverun_machdep.c @@ -33,9 +33,21 @@ #include +#include "acpi.h" +#include "atkbdc.h" #include "bhyverun.h" #include "config.h" +#include "e820.h" +#include "fwctl.h" +#include "ioapic.h" +#include "inout.h" +#include "kernemu_dev.h" +#include "mptbl.h" +#include "pci_irq.h" #include "pci_lpc.h" +#include "rtc.h" +#include "smbiostbl.h" +#include "xmsr.h" void bhyve_init_config(void) @@ -123,3 +135,53 @@ bhyve_start_vcpu(struct vcpu *vcpu, bool bsp) fbsdrun_addcpu(vcpu_id(vcpu)); } + +int +bhyve_init_platform(struct vmctx *ctx, struct vcpu *bsp __unused) +{ + int error; + + error = init_msr(); + if (error != 0) + return (error); + init_inout(); + kernemu_dev_init(); + atkbdc_init(ctx); + pci_irq_init(ctx); + ioapic_init(ctx); + rtc_init(ctx); + sci_init(ctx); + error = e820_init(ctx); + if (error != 0) + return (error); + + return (0); +} + +int +bhyve_init_platform_late(struct vmctx *ctx, struct vcpu *bsp __unused) +{ + int error; + + if (get_config_bool_default("x86.mptable", true)) { + error = mptable_build(ctx, guest_ncpus); + if (error != 0) + return (error); + } + error = smbios_build(ctx); + if (error != 0) + return (error); + error = e820_finalize(); + if (error != 0) + return (error); + + if (lpc_bootrom() && strcmp(lpc_fwcfg(), "bhyve") == 0) + fwctl_init(); + + if (get_config_bool("acpi_tables")) { + error = acpi_build(ctx, guest_ncpus); + assert(error == 0); + } + + return (0); +} diff --git a/usr.sbin/bhyve/amd64/xmsr.c b/usr.sbin/bhyve/amd64/xmsr.c index 99e758e84fff..7481df4669e7 100644 --- a/usr.sbin/bhyve/amd64/xmsr.c +++ b/usr.sbin/bhyve/amd64/xmsr.c @@ -33,12 +33,13 @@ #include #include -#include - +#include #include #include #include +#include + #include "debug.h" #include "xmsr.h" @@ -236,7 +237,7 @@ init_msr(void) cpu_vendor_intel = 1; } else { EPRINTLN("Unknown cpu vendor \"%s\"", cpu_vendor); - error = -1; + error = ENOENT; } return (error); } diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index f42db8147d54..8d9ad3750d43 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -71,52 +71,27 @@ #include -#include "bhyverun.h" #include "acpi.h" -#ifdef __amd64__ -#include "amd64/atkbdc.h" -#endif +#include "bhyverun.h" #include "bootrom.h" #include "config.h" -#ifdef __amd64__ -#include "amd64/inout.h" -#endif #include "debug.h" -#ifdef __amd64__ -#include "amd64/e820.h" -#include "amd64/fwctl.h" -#endif #ifdef BHYVE_GDB #include "gdb.h" #endif -#ifdef __amd64__ -#include "amd64/ioapic.h" -#include "amd64/kernemu_dev.h" -#endif #include "mem.h" #include "mevent.h" -#ifdef __amd64__ -#include "amd64/mptbl.h" -#endif #include "pci_emul.h" #ifdef __amd64__ -#include "amd64/pci_irq.h" #include "amd64/pci_lpc.h" #endif #include "qemu_fwcfg.h" -#include "smbiostbl.h" #ifdef BHYVE_SNAPSHOT #include "snapshot.h" #endif #include "tpm_device.h" -#ifdef __amd64__ -#include "amd64/rtc.h" -#endif #include "vmgenc.h" #include "vmexit.h" -#ifdef __amd64__ -#include "amd64/xmsr.h" -#endif #define MB (1024UL * 1024) #define GB (1024UL * MB) @@ -970,30 +945,10 @@ main(int argc, char *argv[]) exit(4); } -#ifdef __amd64__ - error = init_msr(); - if (error) { - fprintf(stderr, "init_msr error %d", error); - exit(4); - } -#endif - init_mem(guest_ncpus); -#ifdef __amd64__ - init_inout(); - kernemu_dev_init(); -#endif init_bootrom(ctx); -#ifdef __amd64__ - atkbdc_init(ctx); - pci_irq_init(ctx); - ioapic_init(ctx); -#endif - -#ifdef __amd64__ - rtc_init(ctx); - sci_init(ctx); -#endif + if (bhyve_init_platform(ctx, bsp) != 0) + exit(4); if (qemu_fwcfg_init(ctx) != 0) { fprintf(stderr, "qemu fwcfg initialization error"); @@ -1006,13 +961,6 @@ main(int argc, char *argv[]) exit(4); } -#ifdef __amd64__ - if (e820_init(ctx) != 0) { - fprintf(stderr, "Unable to setup E820"); - exit(4); - } -#endif - /* * Exit if a device emulation finds an error in its initialization */ @@ -1076,37 +1024,9 @@ main(int argc, char *argv[]) } #endif -#ifdef __amd64__ - if (get_config_bool_default("x86.mptable", true)) { - error = mptable_build(ctx, guest_ncpus); - if (error) { - perror("error to build the guest tables"); - exit(4); - } - } -#endif - - error = smbios_build(ctx); - if (error != 0) + if (bhyve_init_platform_late(ctx, bsp) != 0) exit(4); - if (get_config_bool("acpi_tables")) { - error = acpi_build(ctx, guest_ncpus); - assert(error == 0); - } - -#ifdef __amd64__ - error = e820_finalize(); - if (error != 0) - exit(4); -#endif - -#ifdef __amd64__ - if (lpc_bootrom() && strcmp(lpc_fwcfg(), "bhyve") == 0) { - fwctl_init(); - } -#endif - /* * Change the proc title to include the VM name. */ diff --git a/usr.sbin/bhyve/bhyverun.h b/usr.sbin/bhyve/bhyverun.h index 39e0916f08ef..5fe97ca07f0b 100644 --- a/usr.sbin/bhyve/bhyverun.h +++ b/usr.sbin/bhyve/bhyverun.h @@ -60,5 +60,7 @@ typedef int (*vmexit_handler_t)(struct vmctx *, struct vcpu *, struct vm_run *); void bhyve_init_config(void); void bhyve_init_vcpu(struct vcpu *vcpu); void bhyve_start_vcpu(struct vcpu *vcpu, bool bsp); +int bhyve_init_platform(struct vmctx *ctx, struct vcpu *bsp); +int bhyve_init_platform_late(struct vmctx *ctx, struct vcpu *bsp); #endif