pci_passthru.c (4d846d260e2b9a3d4d0a701462568268cbfe7a5b) | pci_passthru.c (90c3a1b6629c80a7e4c3fa86d6b794596fdf06b4) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2011 NetApp, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 50 unchanged lines hidden (view full) --- 59#include <err.h> 60#include <errno.h> 61#include <fcntl.h> 62#include <sysexits.h> 63#include <unistd.h> 64 65#include <machine/vmm.h> 66 | 1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2011 NetApp, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 50 unchanged lines hidden (view full) --- 59#include <err.h> 60#include <errno.h> 61#include <fcntl.h> 62#include <sysexits.h> 63#include <unistd.h> 64 65#include <machine/vmm.h> 66 |
67#include "config.h" | |
68#include "debug.h" 69#include "mem.h" 70#include "pci_passthru.h" 71 72#ifndef _PATH_DEVPCI 73#define _PATH_DEVPCI "/dev/pci" 74#endif 75 76#define LEGACY_SUPPORT 1 77 78#define MSIX_TABLE_COUNT(ctrl) (((ctrl) & PCIM_MSIXCTRL_TABLE_SIZE) + 1) 79#define MSIX_CAPLEN 12 80 81#define PASSTHRU_MMIO_MAX 2 82 83static int pcifd = -1; 84 | 67#include "debug.h" 68#include "mem.h" 69#include "pci_passthru.h" 70 71#ifndef _PATH_DEVPCI 72#define _PATH_DEVPCI "/dev/pci" 73#endif 74 75#define LEGACY_SUPPORT 1 76 77#define MSIX_TABLE_COUNT(ctrl) (((ctrl) & PCIM_MSIXCTRL_TABLE_SIZE) + 1) 78#define MSIX_CAPLEN 12 79 80#define PASSTHRU_MMIO_MAX 2 81 82static int pcifd = -1; 83 |
84SET_DECLARE(passthru_dev_set, struct passthru_dev); 85 |
|
85struct passthru_softc { 86 struct pci_devinst *psc_pi; 87 /* ROM is handled like a BAR */ 88 struct pcibar psc_bar[PCI_BARMAX_WITH_ROM + 1]; 89 struct { 90 int capoff; 91 int msgctrl; 92 int emulated; --- 758 unchanged lines hidden (view full) --- 851 return (true); 852} 853 854static int 855passthru_init(struct pci_devinst *pi, nvlist_t *nvl) 856{ 857 int bus, slot, func, error, memflags; 858 struct passthru_softc *sc; | 86struct passthru_softc { 87 struct pci_devinst *psc_pi; 88 /* ROM is handled like a BAR */ 89 struct pcibar psc_bar[PCI_BARMAX_WITH_ROM + 1]; 90 struct { 91 int capoff; 92 int msgctrl; 93 int emulated; --- 758 unchanged lines hidden (view full) --- 852 return (true); 853} 854 855static int 856passthru_init(struct pci_devinst *pi, nvlist_t *nvl) 857{ 858 int bus, slot, func, error, memflags; 859 struct passthru_softc *sc; |
860 struct passthru_dev **devpp; 861 struct passthru_dev *devp, *dev = NULL; |
|
859 const char *value; 860 861 sc = NULL; 862 error = 1; 863 864 memflags = vm_get_memflags(pi->pi_vmctx); 865 if (!(memflags & VM_MEM_F_WIRED)) { 866 warnx("passthru requires guest memory to be wired"); --- 47 unchanged lines hidden (view full) --- 914 if ((error = set_pcir_handler(sc, 0, PCIR_MAXLAT + 1, 915 passthru_cfgread_emulate, passthru_cfgwrite_emulate)) != 0) 916 goto done; 917 918 /* Allow access to the physical command and status register. */ 919 if ((error = set_pcir_handler(sc, PCIR_COMMAND, 0x04, NULL, NULL)) != 0) 920 goto done; 921 | 862 const char *value; 863 864 sc = NULL; 865 error = 1; 866 867 memflags = vm_get_memflags(pi->pi_vmctx); 868 if (!(memflags & VM_MEM_F_WIRED)) { 869 warnx("passthru requires guest memory to be wired"); --- 47 unchanged lines hidden (view full) --- 917 if ((error = set_pcir_handler(sc, 0, PCIR_MAXLAT + 1, 918 passthru_cfgread_emulate, passthru_cfgwrite_emulate)) != 0) 919 goto done; 920 921 /* Allow access to the physical command and status register. */ 922 if ((error = set_pcir_handler(sc, PCIR_COMMAND, 0x04, NULL, NULL)) != 0) 923 goto done; 924 |
925 SET_FOREACH(devpp, passthru_dev_set) { 926 devp = *devpp; 927 assert(devp->probe != NULL); 928 if (devp->probe(pi) == 0) { 929 dev = devp; 930 break; 931 } 932 } 933 934 if (dev != NULL) { 935 error = dev->init(pi, nvl); 936 if (error != 0) 937 goto done; 938 } 939 |
|
922 error = 0; /* success */ 923done: 924 if (error) { | 940 error = 0; /* success */ 941done: 942 if (error) { |
943 if (dev != NULL) 944 dev->deinit(pi); |
|
925 free(sc); 926 vm_unassign_pptdev(pi->pi_vmctx, bus, slot, func); 927 } 928 return (error); 929} 930 931static int 932msicap_access(struct passthru_softc *sc, int coff) --- 358 unchanged lines hidden --- | 945 free(sc); 946 vm_unassign_pptdev(pi->pi_vmctx, bus, slot, func); 947 } 948 return (error); 949} 950 951static int 952msicap_access(struct passthru_softc *sc, int coff) --- 358 unchanged lines hidden --- |