1*8b06bdc9SMark Johnston /*- 2*8b06bdc9SMark Johnston * SPDX-License-Identifier: BSD-2-Clause 3*8b06bdc9SMark Johnston * 4*8b06bdc9SMark Johnston * Copyright (c) 2011 NetApp, Inc. 5*8b06bdc9SMark Johnston * All rights reserved. 6*8b06bdc9SMark Johnston * 7*8b06bdc9SMark Johnston * Redistribution and use in source and binary forms, with or without 8*8b06bdc9SMark Johnston * modification, are permitted provided that the following conditions 9*8b06bdc9SMark Johnston * are met: 10*8b06bdc9SMark Johnston * 1. Redistributions of source code must retain the above copyright 11*8b06bdc9SMark Johnston * notice, this list of conditions and the following disclaimer. 12*8b06bdc9SMark Johnston * 2. Redistributions in binary form must reproduce the above copyright 13*8b06bdc9SMark Johnston * notice, this list of conditions and the following disclaimer in the 14*8b06bdc9SMark Johnston * documentation and/or other materials provided with the distribution. 15*8b06bdc9SMark Johnston * 16*8b06bdc9SMark Johnston * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 17*8b06bdc9SMark Johnston * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*8b06bdc9SMark Johnston * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*8b06bdc9SMark Johnston * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 20*8b06bdc9SMark Johnston * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*8b06bdc9SMark Johnston * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*8b06bdc9SMark Johnston * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*8b06bdc9SMark Johnston * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*8b06bdc9SMark Johnston * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*8b06bdc9SMark Johnston * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*8b06bdc9SMark Johnston * SUCH DAMAGE. 27*8b06bdc9SMark Johnston */ 28*8b06bdc9SMark Johnston 29*8b06bdc9SMark Johnston #include <sys/types.h> 30*8b06bdc9SMark Johnston #include <sys/ioctl.h> 31*8b06bdc9SMark Johnston 32*8b06bdc9SMark Johnston #include <machine/vmm.h> 33*8b06bdc9SMark Johnston 34*8b06bdc9SMark Johnston #include <string.h> 35*8b06bdc9SMark Johnston 36*8b06bdc9SMark Johnston #include "vmmapi.h" 37*8b06bdc9SMark Johnston #include "internal.h" 38*8b06bdc9SMark Johnston 39*8b06bdc9SMark Johnston int 40*8b06bdc9SMark Johnston vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func) 41*8b06bdc9SMark Johnston { 42*8b06bdc9SMark Johnston struct vm_pptdev pptdev; 43*8b06bdc9SMark Johnston 44*8b06bdc9SMark Johnston bzero(&pptdev, sizeof(pptdev)); 45*8b06bdc9SMark Johnston pptdev.bus = bus; 46*8b06bdc9SMark Johnston pptdev.slot = slot; 47*8b06bdc9SMark Johnston pptdev.func = func; 48*8b06bdc9SMark Johnston 49*8b06bdc9SMark Johnston return (ioctl(ctx->fd, VM_BIND_PPTDEV, &pptdev)); 50*8b06bdc9SMark Johnston } 51*8b06bdc9SMark Johnston 52*8b06bdc9SMark Johnston int 53*8b06bdc9SMark Johnston vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func) 54*8b06bdc9SMark Johnston { 55*8b06bdc9SMark Johnston struct vm_pptdev pptdev; 56*8b06bdc9SMark Johnston 57*8b06bdc9SMark Johnston bzero(&pptdev, sizeof(pptdev)); 58*8b06bdc9SMark Johnston pptdev.bus = bus; 59*8b06bdc9SMark Johnston pptdev.slot = slot; 60*8b06bdc9SMark Johnston pptdev.func = func; 61*8b06bdc9SMark Johnston 62*8b06bdc9SMark Johnston return (ioctl(ctx->fd, VM_UNBIND_PPTDEV, &pptdev)); 63*8b06bdc9SMark Johnston } 64*8b06bdc9SMark Johnston 65*8b06bdc9SMark Johnston int 66*8b06bdc9SMark Johnston vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, 67*8b06bdc9SMark Johnston vm_paddr_t gpa, size_t len, vm_paddr_t hpa) 68*8b06bdc9SMark Johnston { 69*8b06bdc9SMark Johnston struct vm_pptdev_mmio pptmmio; 70*8b06bdc9SMark Johnston 71*8b06bdc9SMark Johnston bzero(&pptmmio, sizeof(pptmmio)); 72*8b06bdc9SMark Johnston pptmmio.bus = bus; 73*8b06bdc9SMark Johnston pptmmio.slot = slot; 74*8b06bdc9SMark Johnston pptmmio.func = func; 75*8b06bdc9SMark Johnston pptmmio.gpa = gpa; 76*8b06bdc9SMark Johnston pptmmio.len = len; 77*8b06bdc9SMark Johnston pptmmio.hpa = hpa; 78*8b06bdc9SMark Johnston 79*8b06bdc9SMark Johnston return (ioctl(ctx->fd, VM_MAP_PPTDEV_MMIO, &pptmmio)); 80*8b06bdc9SMark Johnston } 81*8b06bdc9SMark Johnston 82*8b06bdc9SMark Johnston int 83*8b06bdc9SMark Johnston vm_unmap_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func, 84*8b06bdc9SMark Johnston vm_paddr_t gpa, size_t len) 85*8b06bdc9SMark Johnston { 86*8b06bdc9SMark Johnston struct vm_pptdev_mmio pptmmio; 87*8b06bdc9SMark Johnston 88*8b06bdc9SMark Johnston bzero(&pptmmio, sizeof(pptmmio)); 89*8b06bdc9SMark Johnston pptmmio.bus = bus; 90*8b06bdc9SMark Johnston pptmmio.slot = slot; 91*8b06bdc9SMark Johnston pptmmio.func = func; 92*8b06bdc9SMark Johnston pptmmio.gpa = gpa; 93*8b06bdc9SMark Johnston pptmmio.len = len; 94*8b06bdc9SMark Johnston 95*8b06bdc9SMark Johnston return (ioctl(ctx->fd, VM_UNMAP_PPTDEV_MMIO, &pptmmio)); 96*8b06bdc9SMark Johnston } 97*8b06bdc9SMark Johnston 98*8b06bdc9SMark Johnston int 99*8b06bdc9SMark Johnston vm_setup_pptdev_msi(struct vmctx *ctx, int bus, int slot, int func, 100*8b06bdc9SMark Johnston uint64_t addr, uint64_t msg, int numvec) 101*8b06bdc9SMark Johnston { 102*8b06bdc9SMark Johnston struct vm_pptdev_msi pptmsi; 103*8b06bdc9SMark Johnston 104*8b06bdc9SMark Johnston bzero(&pptmsi, sizeof(pptmsi)); 105*8b06bdc9SMark Johnston pptmsi.bus = bus; 106*8b06bdc9SMark Johnston pptmsi.slot = slot; 107*8b06bdc9SMark Johnston pptmsi.func = func; 108*8b06bdc9SMark Johnston pptmsi.msg = msg; 109*8b06bdc9SMark Johnston pptmsi.addr = addr; 110*8b06bdc9SMark Johnston pptmsi.numvec = numvec; 111*8b06bdc9SMark Johnston 112*8b06bdc9SMark Johnston return (ioctl(ctx->fd, VM_PPTDEV_MSI, &pptmsi)); 113*8b06bdc9SMark Johnston } 114*8b06bdc9SMark Johnston 115*8b06bdc9SMark Johnston int 116*8b06bdc9SMark Johnston vm_setup_pptdev_msix(struct vmctx *ctx, int bus, int slot, int func, 117*8b06bdc9SMark Johnston int idx, uint64_t addr, uint64_t msg, uint32_t vector_control) 118*8b06bdc9SMark Johnston { 119*8b06bdc9SMark Johnston struct vm_pptdev_msix pptmsix; 120*8b06bdc9SMark Johnston 121*8b06bdc9SMark Johnston bzero(&pptmsix, sizeof(pptmsix)); 122*8b06bdc9SMark Johnston pptmsix.bus = bus; 123*8b06bdc9SMark Johnston pptmsix.slot = slot; 124*8b06bdc9SMark Johnston pptmsix.func = func; 125*8b06bdc9SMark Johnston pptmsix.idx = idx; 126*8b06bdc9SMark Johnston pptmsix.msg = msg; 127*8b06bdc9SMark Johnston pptmsix.addr = addr; 128*8b06bdc9SMark Johnston pptmsix.vector_control = vector_control; 129*8b06bdc9SMark Johnston 130*8b06bdc9SMark Johnston return (ioctl(ctx->fd, VM_PPTDEV_MSIX, &pptmsix)); 131*8b06bdc9SMark Johnston } 132*8b06bdc9SMark Johnston 133*8b06bdc9SMark Johnston int 134*8b06bdc9SMark Johnston vm_disable_pptdev_msix(struct vmctx *ctx, int bus, int slot, int func) 135*8b06bdc9SMark Johnston { 136*8b06bdc9SMark Johnston struct vm_pptdev ppt; 137*8b06bdc9SMark Johnston 138*8b06bdc9SMark Johnston bzero(&ppt, sizeof(ppt)); 139*8b06bdc9SMark Johnston ppt.bus = bus; 140*8b06bdc9SMark Johnston ppt.slot = slot; 141*8b06bdc9SMark Johnston ppt.func = func; 142*8b06bdc9SMark Johnston 143*8b06bdc9SMark Johnston return (ioctl(ctx->fd, VM_PPTDEV_DISABLE_MSIX, &ppt)); 144*8b06bdc9SMark Johnston } 145