git: ff1e10c8f626 - stable/13 - bhyve: dynamically register FwCtl ports

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Mon, 17 Jan 2022 16:22:17 UTC
The branch stable/13 has been updated by manu:

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

commit ff1e10c8f6268840a990bd9bbfb3722b300d49fd
Author:     Corvin Köhne <CorvinK@beckhoff.com>
AuthorDate: 2022-01-03 13:20:38 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-01-17 12:53:28 +0000

    bhyve: dynamically register FwCtl ports
    
    Qemu's FwCfg uses the same ports as Bhyve's FwCtl. Static allocated
    ports wouldn't allow to switch between Qemu's FwCfg and Bhyve's
    FwCtl.
    
    Reviewed by:    markj
    MFC after:      2 weeks
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D33496
    
    (cherry picked from commit 9fe79f2f2b22ea068e5acb2af23d130a13d2ab06)
---
 usr.sbin/bhyve/fwctl.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/bhyve/fwctl.c b/usr.sbin/bhyve/fwctl.c
index abb234fe1de4..7c27d7e92532 100644
--- a/usr.sbin/bhyve/fwctl.c
+++ b/usr.sbin/bhyve/fwctl.c
@@ -540,12 +540,32 @@ fwctl_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
 
 	return (0);
 }
-INOUT_PORT(fwctl_wreg, FWCTL_OUT, IOPORT_F_INOUT, fwctl_handler);
-INOUT_PORT(fwctl_rreg, FWCTL_IN,  IOPORT_F_IN,    fwctl_handler);
 
 void
 fwctl_init(void)
 {
+	struct inout_port iop;
+	int error;
+
+	bzero(&iop, sizeof(iop));
+	iop.name = "fwctl_wreg";
+	iop.port = FWCTL_OUT;
+	iop.size = 1;
+	iop.flags = IOPORT_F_INOUT;
+	iop.handler = fwctl_handler;
+	
+	error = register_inout(&iop);
+	assert(error == 0);
+
+	bzero(&iop, sizeof(iop));
+	iop.name = "fwctl_rreg";
+	iop.port = FWCTL_IN;
+	iop.size = 1;
+	iop.flags = IOPORT_F_IN;
+	iop.handler = fwctl_handler;
+
+	error = register_inout(&iop);
+	assert(error == 0);
 
 	ops[OP_GET_LEN] = &fgetlen_info;
 	ops[OP_GET]     = &fgetval_info;