Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_virtio_console.c
| Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
| #include <string.h> | #include <string.h> | ||||
| #include <unistd.h> | #include <unistd.h> | ||||
| #include <assert.h> | #include <assert.h> | ||||
| #include <pthread.h> | #include <pthread.h> | ||||
| #include <libgen.h> | #include <libgen.h> | ||||
| #include <sysexits.h> | #include <sysexits.h> | ||||
| #include "bhyverun.h" | #include "bhyverun.h" | ||||
| #include "config.h" | |||||
| #include "debug.h" | #include "debug.h" | ||||
| #include "pci_emul.h" | #include "pci_emul.h" | ||||
| #include "virtio.h" | #include "virtio.h" | ||||
| #include "mevent.h" | #include "mevent.h" | ||||
| #include "sockstream.h" | #include "sockstream.h" | ||||
| #define VTCON_RINGSZ 64 | #define VTCON_RINGSZ 64 | ||||
| #define VTCON_MAXPORTS 16 | #define VTCON_MAXPORTS 16 | ||||
| ▲ Show 20 Lines • Show All 540 Lines • ▼ Show 20 Lines | pci_vtcon_notify_rx(void *vsc, struct vqueue_info *vq) | ||||
| if (!port->vsp_rx_ready) { | if (!port->vsp_rx_ready) { | ||||
| port->vsp_rx_ready = 1; | port->vsp_rx_ready = 1; | ||||
| vq_kick_disable(vq); | vq_kick_disable(vq); | ||||
| } | } | ||||
| } | } | ||||
| static int | static int | ||||
| pci_vtcon_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) | pci_vtcon_legacy_config(nvlist_t *nvl, const char *opts) | ||||
| { | { | ||||
| char *name, *opt, *path, *str, *tofree; | |||||
| nvlist_t *ports_nvl; | |||||
| ports_nvl = create_relative_config_node(nvl, "ports"); | |||||
| tofree = str = strdup(opts); | |||||
| while ((opt = strsep(&str, ",")) != NULL) { | |||||
| name = strsep(&opt, "="); | |||||
| path = opt; | |||||
| if (path != NULL) { | |||||
| EPRINTLN("vtcon: port %s requires a path", name); | |||||
| return (-1); | |||||
| } | |||||
| set_config_value_node(ports_nvl, name, path); | |||||
| } | |||||
| free(tofree); | |||||
| return (0); | |||||
| } | |||||
| static int | |||||
| pci_vtcon_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) | |||||
| { | |||||
| struct pci_vtcon_softc *sc; | struct pci_vtcon_softc *sc; | ||||
| char *portname = NULL; | nvlist_t *ports_nvl; | ||||
| char *portpath = NULL; | |||||
| char *opt; | |||||
| int i; | int i; | ||||
| sc = calloc(1, sizeof(struct pci_vtcon_softc)); | sc = calloc(1, sizeof(struct pci_vtcon_softc)); | ||||
| sc->vsc_config = calloc(1, sizeof(struct pci_vtcon_config)); | sc->vsc_config = calloc(1, sizeof(struct pci_vtcon_config)); | ||||
| sc->vsc_config->max_nr_ports = VTCON_MAXPORTS; | sc->vsc_config->max_nr_ports = VTCON_MAXPORTS; | ||||
| sc->vsc_config->cols = 80; | sc->vsc_config->cols = 80; | ||||
| sc->vsc_config->rows = 25; | sc->vsc_config->rows = 25; | ||||
| vi_softc_linkup(&sc->vsc_vs, &vtcon_vi_consts, sc, pi, sc->vsc_queues); | vi_softc_linkup(&sc->vsc_vs, &vtcon_vi_consts, sc, pi, sc->vsc_queues); | ||||
| Show All 19 Lines | pci_vtcon_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) | ||||
| /* create control port */ | /* create control port */ | ||||
| sc->vsc_control_port.vsp_sc = sc; | sc->vsc_control_port.vsp_sc = sc; | ||||
| sc->vsc_control_port.vsp_txq = 2; | sc->vsc_control_port.vsp_txq = 2; | ||||
| sc->vsc_control_port.vsp_rxq = 3; | sc->vsc_control_port.vsp_rxq = 3; | ||||
| sc->vsc_control_port.vsp_cb = pci_vtcon_control_tx; | sc->vsc_control_port.vsp_cb = pci_vtcon_control_tx; | ||||
| sc->vsc_control_port.vsp_enabled = true; | sc->vsc_control_port.vsp_enabled = true; | ||||
| while ((opt = strsep(&opts, ",")) != NULL) { | ports_nvl = find_relative_config_node(nvl, "ports"); | ||||
| portname = strsep(&opt, "="); | if (ports_nvl != NULL) { | ||||
| portpath = opt; | const char *name; | ||||
| void *cookie; | |||||
| int type; | |||||
| /* create port */ | cookie = NULL; | ||||
| if (pci_vtcon_sock_add(sc, portname, portpath) < 0) { | while ((name = nvlist_next(ports_nvl, &type, &cookie)) != | ||||
| NULL) { | |||||
| const char *path; | |||||
| if (type != NV_TYPE_STRING) | |||||
| continue; | |||||
| path = get_config_value_node(ports_nvl, name); | |||||
| if (pci_vtcon_sock_add(sc, name, path) < 0) { | |||||
| EPRINTLN("cannot create port %s: %s", | EPRINTLN("cannot create port %s: %s", | ||||
| portname, strerror(errno)); | name, strerror(errno)); | ||||
| return (1); | return (1); | ||||
| } | |||||
| } | } | ||||
| } | } | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| struct pci_devemu pci_de_vcon = { | struct pci_devemu pci_de_vcon = { | ||||
| .pe_emu = "virtio-console", | .pe_emu = "virtio-console", | ||||
| .pe_init = pci_vtcon_init, | .pe_init = pci_vtcon_init, | ||||
| .pe_barwrite = vi_pci_write, | .pe_barwrite = vi_pci_write, | ||||
| .pe_barread = vi_pci_read | .pe_barread = vi_pci_read | ||||
| }; | }; | ||||
| PCI_EMUL_SET(pci_de_vcon); | PCI_EMUL_SET(pci_de_vcon); | ||||