Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_passthru.c
Show First 20 Lines • Show All 622 Lines • ▼ Show 20 Lines | if (pci_msix_table_bar(pi) >= 0) { | ||||||||||||
} | } | ||||||||||||
} | } | ||||||||||||
error = 0; /* success */ | error = 0; /* success */ | ||||||||||||
done: | done: | ||||||||||||
return (error); | 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) { | |||||||||||||
sc->psc_pcir_rhandler[i] = rhandler; | |||||||||||||
sc->psc_pcir_whandler[i] = whandler; | |||||||||||||
} | |||||||||||||
return 0; | |||||||||||||
markjUnsubmitted Not Done Inline Actions
markj: | |||||||||||||
} | |||||||||||||
static int | static int | ||||||||||||
passthru_legacy_config(nvlist_t *nvl, const char *opts) | passthru_legacy_config(nvlist_t *nvl, const char *opts) | ||||||||||||
{ | { | ||||||||||||
const char *cp; | const char *cp; | ||||||||||||
char *tofree; | char *tofree; | ||||||||||||
char value[16]; | char value[16]; | ||||||||||||
int bus, slot, func; | int bus, slot, func; | ||||||||||||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | #define GET_INT_CONFIG(var, name) do { \ | ||||||||||||
if ((error = cfginit(pi, bus, slot, func)) != 0) | if ((error = cfginit(pi, bus, slot, func)) != 0) | ||||||||||||
goto done; | goto done; | ||||||||||||
/* initialize ROM */ | /* initialize ROM */ | ||||||||||||
if ((error = passthru_init_rom(sc, | if ((error = passthru_init_rom(sc, | ||||||||||||
get_config_value_node(nvl, "rom"))) != 0) | get_config_value_node(nvl, "rom"))) != 0) | ||||||||||||
goto done; | goto done; | ||||||||||||
/* | |||||||||||||
* Default PCI config register to accessing the config register of the | |||||||||||||
* physical device. | |||||||||||||
*/ | |||||||||||||
if ((error = set_pcir_handler(sc, 0, PCI_REGMAX + 1, | |||||||||||||
passthru_cfgread_default, passthru_cfgwrite_default)) != 0) | |||||||||||||
goto done; | |||||||||||||
markjUnsubmitted Not Done Inline ActionsAlternately, can cfgread/write just call cfgread/write_default if no handler is installed? That might be a bit simpler and easier to follow. markj: Alternately, can cfgread/write just call cfgread/write_default if no handler is installed? That… | |||||||||||||
markjUnsubmitted Not Done Inline ActionsBut now this call isn't needed, right? And set_pcir_handler() can assert that a handler is not already set? markj: But now this call isn't needed, right? And set_pcir_handler() can assert that a handler is not… | |||||||||||||
error = 0; /* success */ | error = 0; /* success */ | ||||||||||||
done: | done: | ||||||||||||
if (error) { | if (error) { | ||||||||||||
free(sc); | free(sc); | ||||||||||||
vm_unassign_pptdev(pi->pi_vmctx, bus, slot, func); | vm_unassign_pptdev(pi->pi_vmctx, bus, slot, func); | ||||||||||||
} | } | ||||||||||||
return (error); | return (error); | ||||||||||||
} | } | ||||||||||||
Show All 36 Lines | |||||||||||||
static int | static int | ||||||||||||
passthru_cfgread(struct pci_devinst *pi, int coff, int bytes, uint32_t *rv) | passthru_cfgread(struct pci_devinst *pi, int coff, int bytes, uint32_t *rv) | ||||||||||||
{ | { | ||||||||||||
struct passthru_softc *sc; | struct passthru_softc *sc; | ||||||||||||
sc = pi->pi_arg; | sc = pi->pi_arg; | ||||||||||||
return (sc->psc_pcir_rhandler[coff](sc, pi, coff, bytes, rv)); | |||||||||||||
} | |||||||||||||
int | |||||||||||||
passthru_cfgread_default(struct passthru_softc *sc, | |||||||||||||
struct pci_devinst *pi __unused, int coff, int bytes, uint32_t *rv) | |||||||||||||
{ | |||||||||||||
/* | /* | ||||||||||||
* PCI BARs and MSI capability is emulated. | * PCI BARs and MSI capability is emulated. | ||||||||||||
*/ | */ | ||||||||||||
if (bar_access(coff) || msicap_access(sc, coff) || | if (bar_access(coff) || msicap_access(sc, coff) || | ||||||||||||
msixcap_access(sc, coff)) | msixcap_access(sc, coff)) | ||||||||||||
return (-1); | return (-1); | ||||||||||||
#ifdef LEGACY_SUPPORT | #ifdef LEGACY_SUPPORT | ||||||||||||
Show All 24 Lines | #endif | ||||||||||||
*rv = read_config(&sc->psc_sel, coff, bytes); | *rv = read_config(&sc->psc_sel, coff, bytes); | ||||||||||||
return (0); | return (0); | ||||||||||||
} | } | ||||||||||||
static int | static int | ||||||||||||
passthru_cfgwrite(struct pci_devinst *pi, int coff, int bytes, uint32_t val) | passthru_cfgwrite(struct pci_devinst *pi, int coff, int bytes, uint32_t val) | ||||||||||||
{ | { | ||||||||||||
int error, msix_table_entries, i; | |||||||||||||
struct passthru_softc *sc; | struct passthru_softc *sc; | ||||||||||||
uint16_t cmd_old; | |||||||||||||
sc = pi->pi_arg; | sc = pi->pi_arg; | ||||||||||||
return (sc->psc_pcir_whandler[coff](sc, pi, coff, bytes, val)); | |||||||||||||
} | |||||||||||||
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 | * PCI BARs are emulated | ||||||||||||
*/ | */ | ||||||||||||
if (bar_access(coff)) | if (bar_access(coff)) | ||||||||||||
return (-1); | return (-1); | ||||||||||||
/* | /* | ||||||||||||
▲ Show 20 Lines • Show All 255 Lines • Show Last 20 Lines |