git: 4f2bd4027b32 - main - bhyve: Start moving machine-dependent code into subdirectories

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 04 Oct 2023 16:53:55 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=4f2bd4027b3261d159f6d673dc9ee9e84b4a3538

commit 4f2bd4027b3261d159f6d673dc9ee9e84b4a3538
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-10-04 16:20:37 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-10-04 16:53:16 +0000

    bhyve: Start moving machine-dependent code into subdirectories
    
    In preparation for an arm64 port, make an easy change which puts some
    machine-dependent code in its own directory.
    
    Going forward, code which is only used on one platform should live in a
    MD directory.  We should strive to layer modules in such a way as to
    avoid polluting shared code with lots of ifdefs.  For some existing
    files this will take some effort.
    
    task_switch.c and fwctl.c are an easy place to start: the former is very
    x86-specific, and the latter provides an I/O port interface which can't
    be used on anything other than x86.  (fwcfg as implemented has the same
    problem, but QEMU also supports a MMIO fwcfg interface.)  So I propose
    that we start by simply making those files conditional.
    
    Reviewed by:    corvink, jhb
    MFC after:      1 week
    Sponsored by:   Innovate UK
    Differential Revision:  https://reviews.freebsd.org/D40501
---
 usr.sbin/bhyve/Makefile                  | 16 +++++++++-------
 usr.sbin/bhyve/amd64/Makefile.inc        |  6 ++++++
 usr.sbin/bhyve/{ => amd64}/fwctl.c       |  0
 usr.sbin/bhyve/{ => amd64}/fwctl.h       |  0
 usr.sbin/bhyve/{ => amd64}/task_switch.c |  2 ++
 usr.sbin/bhyve/bhyverun.c                |  8 +++++++-
 usr.sbin/bhyve/bhyverun.h                |  2 --
 usr.sbin/bhyve/snapshot.c                |  1 -
 8 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile
index a720c6b3c7a4..794bfbe4c8a3 100644
--- a/usr.sbin/bhyve/Makefile
+++ b/usr.sbin/bhyve/Makefile
@@ -2,9 +2,6 @@
 #
 
 .include <src.opts.mk>
-CFLAGS+=-I${.CURDIR}/../../contrib/lib9p
-CFLAGS+=-I${SRCTOP}/sys
-.PATH:  ${SRCTOP}/sys/libkern ${SRCTOP}/sys/cam/ctl
 
 PROG=	bhyve
 PACKAGE=	bhyve
@@ -13,6 +10,10 @@ MAN=	bhyve.8 bhyve_config.5
 
 BHYVE_SYSDIR?=${SRCTOP}
 
+.PATH:	${.CURDIR}/${MACHINE_CPUARCH}	\
+	${SRCTOP}/sys/libkern		\
+	${SRCTOP}/sys/cam/ctl
+
 SRCS=	\
 	acpi.c			\
 	acpi_device.c		\
@@ -29,7 +30,6 @@ SRCS=	\
 	ctl_scsi_all.c		\
 	ctl_util.c		\
 	e820.c			\
-	fwctl.c			\
 	gdb.c			\
 	hda_codec.c		\
 	inout.c			\
@@ -73,7 +73,6 @@ SRCS=	\
 	smbiostbl.c		\
 	sockstream.c		\
 	spinup_ap.c		\
-	task_switch.c		\
 	tpm_device.c		\
 	tpm_emul_passthru.c	\
 	tpm_intf_crb.c		\
@@ -90,10 +89,13 @@ SRCS=	\
 SRCS+=	snapshot.c
 .endif
 
+.include "${MACHINE_CPUARCH}/Makefile.inc"
+
 CFLAGS.kernemu_dev.c+=	-I${SRCTOP}/sys/amd64
 
-.PATH:  ${BHYVE_SYSDIR}/sys/amd64/vmm
-SRCS+=	vmm_instruction_emul.c
+CFLAGS+=-I${.CURDIR}		\
+	-I${.CURDIR}/../../contrib/lib9p \
+	-I${SRCTOP}/sys
 
 LIBADD=	vmmapi md nv pthread z util sbuf cam 9p
 
diff --git a/usr.sbin/bhyve/amd64/Makefile.inc b/usr.sbin/bhyve/amd64/Makefile.inc
new file mode 100644
index 000000000000..62de5f211a23
--- /dev/null
+++ b/usr.sbin/bhyve/amd64/Makefile.inc
@@ -0,0 +1,6 @@
+SRCS+=	\
+	fwctl.c		\
+	task_switch.c
+
+.PATH:  ${BHYVE_SYSDIR}/sys/amd64/vmm
+SRCS+=	vmm_instruction_emul.c
diff --git a/usr.sbin/bhyve/fwctl.c b/usr.sbin/bhyve/amd64/fwctl.c
similarity index 100%
rename from usr.sbin/bhyve/fwctl.c
rename to usr.sbin/bhyve/amd64/fwctl.c
diff --git a/usr.sbin/bhyve/fwctl.h b/usr.sbin/bhyve/amd64/fwctl.h
similarity index 100%
rename from usr.sbin/bhyve/fwctl.h
rename to usr.sbin/bhyve/amd64/fwctl.h
diff --git a/usr.sbin/bhyve/task_switch.c b/usr.sbin/bhyve/amd64/task_switch.c
similarity index 99%
rename from usr.sbin/bhyve/task_switch.c
rename to usr.sbin/bhyve/amd64/task_switch.c
index 351df7fb738b..c316d18142a7 100644
--- a/usr.sbin/bhyve/task_switch.c
+++ b/usr.sbin/bhyve/amd64/task_switch.c
@@ -700,6 +700,8 @@ push_errcode(struct vcpu *vcpu, struct vm_guest_paging *paging,
 			return (VMEXIT_CONTINUE);			\
 	} while (0)
 
+int vmexit_task_switch(struct vmctx *, struct vcpu *, struct vm_run *);
+
 int
 vmexit_task_switch(struct vmctx *ctx, struct vcpu *vcpu, struct vm_run *vmrun)
 {
diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
index 1d4cf048b59b..4e2d5467cfaf 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -88,7 +88,9 @@
 #include "inout.h"
 #include "debug.h"
 #include "e820.h"
-#include "fwctl.h"
+#ifdef __amd64__
+#include "amd64/fwctl.h"
+#endif
 #include "gdb.h"
 #include "ioapic.h"
 #include "kernemu_dev.h"
@@ -921,6 +923,8 @@ vmexit_ipi(struct vmctx *ctx __unused, struct vcpu *vcpu __unused,
 	return (error);
 }
 
+int vmexit_task_switch(struct vmctx *, struct vcpu *, struct vm_run *);
+
 static const vmexit_handler_t handler[VM_EXITCODE_MAX] = {
 	[VM_EXITCODE_INOUT]  = vmexit_inout,
 	[VM_EXITCODE_INOUT_STR]  = vmexit_inout,
@@ -1576,9 +1580,11 @@ main(int argc, char *argv[])
 	}
 	free(e820_fwcfg_item);
 
+#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 1131e18baed2..fc0d2595e66b 100644
--- a/usr.sbin/bhyve/bhyverun.h
+++ b/usr.sbin/bhyve/bhyverun.h
@@ -46,6 +46,4 @@ uintptr_t paddr_host2guest(struct vmctx *ctx, void *addr);
 
 int  fbsdrun_virtio_msix(void);
 
-int vmexit_task_switch(struct vmctx *, struct vcpu *, struct vm_run *);
-
 #endif
diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c
index ec56bd0fed9a..7d8959756757 100644
--- a/usr.sbin/bhyve/snapshot.c
+++ b/usr.sbin/bhyve/snapshot.c
@@ -79,7 +79,6 @@
 #include "debug.h"
 #include "inout.h"
 #include "ipc.h"
-#include "fwctl.h"
 #include "ioapic.h"
 #include "mem.h"
 #include "mevent.h"