From nobody Wed Apr 10 15:19:08 2024 X-Original-To: dev-commits-src-all@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 4VF61T1VdRz5HHGv; Wed, 10 Apr 2024 15:19:09 +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 4VF61S6MBhz4myS; Wed, 10 Apr 2024 15:19:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712762348; 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=c6XzE7XsNt5aa+9q05CXjrFuCOXtIhjpPISyFwlRBNk=; b=s6OWV+PqHMfgS71/5lLkiyyMzYwjENKhmsxZyDjm6zzOJwti36ngaoEB2sov5mWYyOxTjM DMEoA7kJr9DayYnbQDHgF9myNnLxvTWce1wnDIWcEih2ooR+zh1gVxvf1+zzt7Wp6188xq z0AJQ/Hc+hMVri5jGebffcuPUZArNugYHkBHT9WkTDjeD8l+IN9C2Es2RZhqLbpZdUkPNB 3sR9nRTTF1qUAQgFBizkP5GaiomJo8GmNd7nMNfXQXPsuRNo3E0Y19p/o8bkzyOcy3GInC B4HjeNXNMIQP+gVf6dwGu8JmX/r+PYNhJOUza84sBN45vhoogv3Eqk3QZyyWWQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712762348; a=rsa-sha256; cv=none; b=tI/q9HVp3gzHw1YMIYzfyxy66eRdSo9kyZSKZ6rgvfdcBQO5zqgGc2JADNMzQ7UuVzbFwB EiFwSF2X43Aj/sbk91xsOxjFL01GyN2yVAkla9jS0qTqvlpkOrrbmb3YEfK4AMy0CfYiHR OlkZKxKNqDc5YMyWIAmzraPguwNh54gPpk6E6ddJWidTxT5pJKiLpZre66ulLYVtJ0pcNk mrzneDgZYsW7XEH6qgGYB/Jbc0ii8bHZ74y7T0bCdVsNYsMPIXmOO2nulYqq/vwghtf/2A zfb2rLiQ4fhLy1h0IxZ/LL+HuUr+7vbc6ZKpYMtxVUpbhmJS/Dlpm9ws67SawA== 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=1712762348; 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=c6XzE7XsNt5aa+9q05CXjrFuCOXtIhjpPISyFwlRBNk=; b=mbk+Uaqs5LEHtp5P4V1x+U3NIdZ2OibyzgXurOkuqApw9QhZ/EvT9ivo2VALYH+KGZHobK IPrhMPOClkynLF1/kDNXTlOgtyl8akzTbzDls8pwUiITcf/0u4oXCtFhpBgp8gXHVI+fsi E2VWp7+RY1vujrpd2odq4ThK1zToIhz0UGUbT4aN6486PHV7xkBpouRa/jxBWVVbMsIGMm 9KtD+6zlbm/2G7c/gJ1aqSNFbe/BqJ2VH64WEljaWAh8Yt5Z2G9AbqKfOy+SC2uabLrzz4 z5QT2lCwiOQH6GykBJSlmKH54rMpvTcZTRZ7oAy0TARFBafg+EHyywCkTqeY9Q== 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 4VF61S5y2rzjsJ; Wed, 10 Apr 2024 15:19:08 +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 43AFJ89H092964; Wed, 10 Apr 2024 15:19:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43AFJ87C092961; Wed, 10 Apr 2024 15:19:08 GMT (envelope-from git) Date: Wed, 10 Apr 2024 15:19:08 GMT Message-Id: <202404101519.43AFJ87C092961@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: 8b06bdc91ddf - main - libvmmapi: Move PCI passthrough ioctl wrappers into a separate file List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: dev-commits-src-all+owner@freebsd.org X-BeenThere: dev-commits-src-all@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: 8b06bdc91ddff995beed7bdcb6e5541c5ca227ef Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=8b06bdc91ddff995beed7bdcb6e5541c5ca227ef commit 8b06bdc91ddff995beed7bdcb6e5541c5ca227ef Author: Mark Johnston AuthorDate: 2024-04-03 16:56:22 +0000 Commit: Mark Johnston 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 +#include + +#include + +#include + +#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)