bhyve: define array to protect passthru regs
GPU passthrough requires a special handling of some PCI config register. Therefore, we need a flexible approach for implementing it. Adding an array of handler meets this condition. Start by using the default handler for all accesses to the PCI config space. In upcoming commits, we can start to split the default handler into several handler for each register that requires emulation. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D39291
This commit is contained in:
parent
e976464a50
commit
931bb7bf1c
@ -93,6 +93,9 @@ struct passthru_softc {
|
||||
int capoff;
|
||||
} psc_msix;
|
||||
struct pcisel psc_sel;
|
||||
|
||||
cfgread_handler psc_pcir_rhandler[PCI_REGMAX + 1];
|
||||
cfgwrite_handler psc_pcir_whandler[PCI_REGMAX + 1];
|
||||
};
|
||||
|
||||
static int
|
||||
@ -643,6 +646,23 @@ cfginit(struct pci_devinst *pi, int bus, int slot, int func)
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
set_pcir_handler(struct passthru_softc *sc, int reg, int len,
|
||||
cfgread_handler rhandler, cfgwrite_handler whandler)
|
||||
{
|
||||
if (reg > PCI_REGMAX || reg + len > PCI_REGMAX + 1)
|
||||
return (-1);
|
||||
|
||||
for (int i = reg; i < reg + len; ++i) {
|
||||
assert(sc->psc_pcir_rhandler[i] == NULL || rhandler == NULL);
|
||||
assert(sc->psc_pcir_whandler[i] == NULL || whandler == NULL);
|
||||
sc->psc_pcir_rhandler[i] = rhandler;
|
||||
sc->psc_pcir_whandler[i] = whandler;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
passthru_legacy_config(nvlist_t *nvl, const char *opts)
|
||||
{
|
||||
@ -902,12 +922,9 @@ msixcap_access(struct passthru_softc *sc, int coff)
|
||||
}
|
||||
|
||||
static int
|
||||
passthru_cfgread(struct pci_devinst *pi, int coff, int bytes, uint32_t *rv)
|
||||
passthru_cfgread_default(struct passthru_softc *sc,
|
||||
struct pci_devinst *pi __unused, int coff, int bytes, uint32_t *rv)
|
||||
{
|
||||
struct passthru_softc *sc;
|
||||
|
||||
sc = pi->pi_arg;
|
||||
|
||||
/*
|
||||
* PCI BARs and MSI capability is emulated.
|
||||
*/
|
||||
@ -946,14 +963,25 @@ passthru_cfgread(struct pci_devinst *pi, int coff, int bytes, uint32_t *rv)
|
||||
}
|
||||
|
||||
static int
|
||||
passthru_cfgwrite(struct pci_devinst *pi, int coff, int bytes, uint32_t val)
|
||||
passthru_cfgread(struct pci_devinst *pi, int coff, int bytes, uint32_t *rv)
|
||||
{
|
||||
int error, msix_table_entries, i;
|
||||
struct passthru_softc *sc;
|
||||
uint16_t cmd_old;
|
||||
|
||||
sc = pi->pi_arg;
|
||||
|
||||
if (sc->psc_pcir_rhandler[coff] != NULL)
|
||||
return (sc->psc_pcir_rhandler[coff](sc, pi, coff, bytes, rv));
|
||||
|
||||
return (passthru_cfgread_default(sc, pi, coff, bytes, rv));
|
||||
}
|
||||
|
||||
static int
|
||||
passthru_cfgwrite_default(struct passthru_softc *sc, struct pci_devinst *pi,
|
||||
int coff, int bytes, uint32_t val)
|
||||
{
|
||||
int error, msix_table_entries, i;
|
||||
uint16_t cmd_old;
|
||||
|
||||
/*
|
||||
* PCI BARs are emulated
|
||||
*/
|
||||
@ -1026,6 +1054,19 @@ passthru_cfgwrite(struct pci_devinst *pi, int coff, int bytes, uint32_t val)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
passthru_cfgwrite(struct pci_devinst *pi, int coff, int bytes, uint32_t val)
|
||||
{
|
||||
struct passthru_softc *sc;
|
||||
|
||||
sc = pi->pi_arg;
|
||||
|
||||
if (sc->psc_pcir_whandler[coff] != NULL)
|
||||
return (sc->psc_pcir_whandler[coff](sc, pi, coff, bytes, val));
|
||||
|
||||
return (passthru_cfgwrite_default(sc, pi, coff, bytes, val));
|
||||
}
|
||||
|
||||
static void
|
||||
passthru_write(struct pci_devinst *pi, int baridx, uint64_t offset, int size,
|
||||
uint64_t value)
|
||||
|
@ -11,5 +11,14 @@
|
||||
|
||||
#include "pci_emul.h"
|
||||
|
||||
struct passthru_softc;
|
||||
|
||||
typedef int (*cfgread_handler)(struct passthru_softc *sc,
|
||||
struct pci_devinst *pi, int coff, int bytes, uint32_t *rv);
|
||||
typedef int (*cfgwrite_handler)(struct passthru_softc *sc,
|
||||
struct pci_devinst *pi, int coff, int bytes, uint32_t val);
|
||||
|
||||
uint32_t read_config(const struct pcisel *sel, long reg, int width);
|
||||
void write_config(const struct pcisel *sel, long reg, int width, uint32_t data);
|
||||
int set_pcir_handler(struct passthru_softc *sc, int reg, int len,
|
||||
cfgread_handler rhandler, cfgwrite_handler whandler);
|
||||
|
Loading…
Reference in New Issue
Block a user