git: 8b06bdc91ddf - main - libvmmapi: Move PCI passthrough ioctl wrappers into a separate file
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 10 Apr 2024 15:19:08 UTC
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=8b06bdc91ddff995beed7bdcb6e5541c5ca227ef commit 8b06bdc91ddff995beed7bdcb6e5541c5ca227ef Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2024-04-03 16:56:22 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2024-04-10 15:17:56 +0000 libvmmapi: Move PCI passthrough ioctl wrappers into a separate file The arm64 port doesn't implement PCI passthrough and in particular doesn't define the ioctls used by these wrappers. It might be that the ppt ioctl interface will require modification to support arm64. Until that's sorted out one way or another, put this code in a separate file so that it's easy to conditionally compile. No functional change intended. Reviewed by: corvink, jhb MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D41003 --- lib/libvmmapi/amd64/Makefile.inc | 3 +- lib/libvmmapi/ppt.c | 144 +++++++++++++++++++++++++++++++++++++++ lib/libvmmapi/vmmapi.c | 107 ----------------------------- 3 files changed, 146 insertions(+), 108 deletions(-) diff --git a/lib/libvmmapi/amd64/Makefile.inc b/lib/libvmmapi/amd64/Makefile.inc index e51b9f9c2bfa..d122f742a667 100644 --- a/lib/libvmmapi/amd64/Makefile.inc +++ b/lib/libvmmapi/amd64/Makefile.inc @@ -1,2 +1,3 @@ -SRCS+= vmmapi_machdep.c \ +SRCS+= ppt.c \ + vmmapi_machdep.c \ vmmapi_freebsd_machdep.c diff --git a/lib/libvmmapi/ppt.c b/lib/libvmmapi/ppt.c new file mode 100644 index 000000000000..fd49f8eed168 --- /dev/null +++ b/lib/libvmmapi/ppt.c @@ -0,0 +1,144 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2011 NetApp, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <sys/ioctl.h> + +#include <machine/vmm.h> + +#include <string.h> + +#include "vmmapi.h" +#include "internal.h" + +int +vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func) +{ + struct vm_pptdev pptdev; + + bzero(&pptdev, sizeof(pptdev)); + pptdev.bus = bus; + pptdev.slot = slot; + pptdev.func = func; + + return (ioctl(ctx->fd, VM_BIND_PPTDEV, &pptdev)); +} + +int +vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func) +{ + struct vm_pptdev pptdev; + + bzero(&pptdev, sizeof(pptdev)); + pptdev.bus = bus; + pptdev.slot = slot; + pptdev.func = func; + + return (ioctl(ctx->fd, VM_UNBIND_PPTDEV, &pptdev)); +} + +int +vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, + vm_paddr_t gpa, size_t len, vm_paddr_t hpa) +{ + struct vm_pptdev_mmio pptmmio; + + bzero(&pptmmio, sizeof(pptmmio)); + pptmmio.bus = bus; + pptmmio.slot = slot; + pptmmio.func = func; + pptmmio.gpa = gpa; + pptmmio.len = len; + pptmmio.hpa = hpa; + + return (ioctl(ctx->fd, VM_MAP_PPTDEV_MMIO, &pptmmio)); +} + +int +vm_unmap_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, + vm_paddr_t gpa, size_t len) +{ + struct vm_pptdev_mmio pptmmio; + + bzero(&pptmmio, sizeof(pptmmio)); + pptmmio.bus = bus; + pptmmio.slot = slot; + pptmmio.func = func; + pptmmio.gpa = gpa; + pptmmio.len = len; + + return (ioctl(ctx->fd, VM_UNMAP_PPTDEV_MMIO, &pptmmio)); +} + +int +vm_setup_pptdev_msi(struct vmctx *ctx, int bus, int slot, int func, + uint64_t addr, uint64_t msg, int numvec) +{ + struct vm_pptdev_msi pptmsi; + + bzero(&pptmsi, sizeof(pptmsi)); + pptmsi.bus = bus; + pptmsi.slot = slot; + pptmsi.func = func; + pptmsi.msg = msg; + pptmsi.addr = addr; + pptmsi.numvec = numvec; + + return (ioctl(ctx->fd, VM_PPTDEV_MSI, &pptmsi)); +} + +int +vm_setup_pptdev_msix(struct vmctx *ctx, int bus, int slot, int func, + int idx, uint64_t addr, uint64_t msg, uint32_t vector_control) +{ + struct vm_pptdev_msix pptmsix; + + bzero(&pptmsix, sizeof(pptmsix)); + pptmsix.bus = bus; + pptmsix.slot = slot; + pptmsix.func = func; + pptmsix.idx = idx; + pptmsix.msg = msg; + pptmsix.addr = addr; + pptmsix.vector_control = vector_control; + + return (ioctl(ctx->fd, VM_PPTDEV_MSIX, &pptmsix)); +} + +int +vm_disable_pptdev_msix(struct vmctx *ctx, int bus, int slot, int func) +{ + struct vm_pptdev ppt; + + bzero(&ppt, sizeof(ppt)); + ppt.bus = bus; + ppt.slot = slot; + ppt.func = func; + + return (ioctl(ctx->fd, VM_PPTDEV_DISABLE_MSIX, &ppt)); +} diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c index 4bf4ded17481..63f0fe0f16fe 100644 --- a/lib/libvmmapi/vmmapi.c +++ b/lib/libvmmapi/vmmapi.c @@ -728,113 +728,6 @@ vm_set_capability(struct vcpu *vcpu, enum vm_cap_type cap, int val) return (vcpu_ioctl(vcpu, VM_SET_CAPABILITY, &vmcap)); } -int -vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func) -{ - struct vm_pptdev pptdev; - - bzero(&pptdev, sizeof(pptdev)); - pptdev.bus = bus; - pptdev.slot = slot; - pptdev.func = func; - - return (ioctl(ctx->fd, VM_BIND_PPTDEV, &pptdev)); -} - -int -vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func) -{ - struct vm_pptdev pptdev; - - bzero(&pptdev, sizeof(pptdev)); - pptdev.bus = bus; - pptdev.slot = slot; - pptdev.func = func; - - return (ioctl(ctx->fd, VM_UNBIND_PPTDEV, &pptdev)); -} - -int -vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, - vm_paddr_t gpa, size_t len, vm_paddr_t hpa) -{ - struct vm_pptdev_mmio pptmmio; - - bzero(&pptmmio, sizeof(pptmmio)); - pptmmio.bus = bus; - pptmmio.slot = slot; - pptmmio.func = func; - pptmmio.gpa = gpa; - pptmmio.len = len; - pptmmio.hpa = hpa; - - return (ioctl(ctx->fd, VM_MAP_PPTDEV_MMIO, &pptmmio)); -} - -int -vm_unmap_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, - vm_paddr_t gpa, size_t len) -{ - struct vm_pptdev_mmio pptmmio; - - bzero(&pptmmio, sizeof(pptmmio)); - pptmmio.bus = bus; - pptmmio.slot = slot; - pptmmio.func = func; - pptmmio.gpa = gpa; - pptmmio.len = len; - - return (ioctl(ctx->fd, VM_UNMAP_PPTDEV_MMIO, &pptmmio)); -} - -int -vm_setup_pptdev_msi(struct vmctx *ctx, int bus, int slot, int func, - uint64_t addr, uint64_t msg, int numvec) -{ - struct vm_pptdev_msi pptmsi; - - bzero(&pptmsi, sizeof(pptmsi)); - pptmsi.bus = bus; - pptmsi.slot = slot; - pptmsi.func = func; - pptmsi.msg = msg; - pptmsi.addr = addr; - pptmsi.numvec = numvec; - - return (ioctl(ctx->fd, VM_PPTDEV_MSI, &pptmsi)); -} - -int -vm_setup_pptdev_msix(struct vmctx *ctx, int bus, int slot, int func, - int idx, uint64_t addr, uint64_t msg, uint32_t vector_control) -{ - struct vm_pptdev_msix pptmsix; - - bzero(&pptmsix, sizeof(pptmsix)); - pptmsix.bus = bus; - pptmsix.slot = slot; - pptmsix.func = func; - pptmsix.idx = idx; - pptmsix.msg = msg; - pptmsix.addr = addr; - pptmsix.vector_control = vector_control; - - return ioctl(ctx->fd, VM_PPTDEV_MSIX, &pptmsix); -} - -int -vm_disable_pptdev_msix(struct vmctx *ctx, int bus, int slot, int func) -{ - struct vm_pptdev ppt; - - bzero(&ppt, sizeof(ppt)); - ppt.bus = bus; - ppt.slot = slot; - ppt.func = func; - - return ioctl(ctx->fd, VM_PPTDEV_DISABLE_MSIX, &ppt); -} - uint64_t * vm_get_stats(struct vcpu *vcpu, struct timeval *ret_tv, int *ret_entries)