Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_passthru.c
Show First 20 Lines • Show All 613 Lines • ▼ Show 20 Lines | pci_set_cfgdata16(pi, PCIR_COMMAND, read_config(&sc->psc_sel, | ||||
PCIR_COMMAND, 2)); | PCIR_COMMAND, 2)); | ||||
error = 0; /* success */ | error = 0; /* success */ | ||||
done: | done: | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | static int | ||||
passthru_legacy_config(nvlist_t *nvl, const char *opts) | passthru_legacy_config(config_node_t *node, const char *opts) | ||||
{ | { | ||||
char value[16]; | char value[16]; | ||||
int bus, slot, func; | int bus, slot, func; | ||||
if (opts == NULL) | if (opts == NULL) | ||||
return (0); | return (0); | ||||
if (sscanf(opts, "%d/%d/%d", &bus, &slot, &func) != 3) { | if (sscanf(opts, "%d/%d/%d", &bus, &slot, &func) != 3) { | ||||
EPRINTLN("passthru: invalid options \"%s\"", opts); | EPRINTLN("passthru: invalid options \"%s\"", opts); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
snprintf(value, sizeof(value), "%d", bus); | snprintf(value, sizeof(value), "%d", bus); | ||||
set_config_value_node(nvl, "bus", value); | set_config_value_node(node, "bus", value); | ||||
snprintf(value, sizeof(value), "%d", slot); | snprintf(value, sizeof(value), "%d", slot); | ||||
set_config_value_node(nvl, "slot", value); | set_config_value_node(node, "slot", value); | ||||
snprintf(value, sizeof(value), "%d", func); | snprintf(value, sizeof(value), "%d", func); | ||||
set_config_value_node(nvl, "func", value); | set_config_value_node(node, "func", value); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
passthru_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) | passthru_init(struct vmctx *ctx, struct pci_devinst *pi, config_node_t *node) | ||||
{ | { | ||||
int bus, slot, func, error, memflags; | int bus, slot, func, error, memflags; | ||||
struct passthru_softc *sc; | struct passthru_softc *sc; | ||||
const char *value; | const char *value; | ||||
#ifndef WITHOUT_CAPSICUM | #ifndef WITHOUT_CAPSICUM | ||||
cap_rights_t rights; | cap_rights_t rights; | ||||
cap_ioctl_t pci_ioctls[] = { PCIOCREAD, PCIOCWRITE, PCIOCGETBAR }; | cap_ioctl_t pci_ioctls[] = { PCIOCREAD, PCIOCWRITE, PCIOCGETBAR }; | ||||
cap_ioctl_t io_ioctls[] = { IODEV_PIO }; | cap_ioctl_t io_ioctls[] = { IODEV_PIO }; | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
#ifndef WITHOUT_CAPSICUM | #ifndef WITHOUT_CAPSICUM | ||||
cap_rights_clear(&rights, CAP_IOCTL); | cap_rights_clear(&rights, CAP_IOCTL); | ||||
cap_rights_set(&rights, CAP_MMAP_RW); | cap_rights_set(&rights, CAP_MMAP_RW); | ||||
if (caph_rights_limit(memfd, &rights) == -1) | if (caph_rights_limit(memfd, &rights) == -1) | ||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | errx(EX_OSERR, "Unable to apply rights for sandbox"); | ||||
#endif | #endif | ||||
#define GET_INT_CONFIG(var, name) do { \ | #define GET_INT_CONFIG(var, name) do { \ | ||||
value = get_config_value_node(nvl, name); \ | value = get_config_value_node(node, name); \ | ||||
if (value == NULL) { \ | if (value == NULL) { \ | ||||
EPRINTLN("passthru: missing required %s setting", name); \ | EPRINTLN("passthru: missing required %s setting", name); \ | ||||
return (error); \ | return (error); \ | ||||
} \ | } \ | ||||
var = atoi(value); \ | var = atoi(value); \ | ||||
} while (0) | } while (0) | ||||
GET_INT_CONFIG(bus, "bus"); | GET_INT_CONFIG(bus, "bus"); | ||||
▲ Show 20 Lines • Show All 332 Lines • Show Last 20 Lines |