Lines Matching +full:1 +full:- +full:port

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
13 * 1. Redistributions of source code must retain the above copyright
72 #define VTCON_DEVICE_ADD 1
81 #define VTCON_F_MULTIPORT 1
187 vi_reset_dev(&sc->vsc_vs); in pci_vtcon_reset()
195 sc->vsc_features = negotiated_features; in pci_vtcon_neg_features()
204 ptr = (uint8_t *)sc->vsc_config + offset; in pci_vtcon_cfgread()
219 uint16_t num = vq->vq_num; in pci_vtcon_vq_to_port()
221 if (num == 0 || num == 1) in pci_vtcon_vq_to_port()
222 return (&sc->vsc_ports[0]); in pci_vtcon_vq_to_port()
225 return (&sc->vsc_control_port); in pci_vtcon_vq_to_port()
227 return (&sc->vsc_ports[(num / 2) - 1]); in pci_vtcon_vq_to_port()
231 pci_vtcon_port_to_vq(struct pci_vtcon_port *port, bool tx_queue) in pci_vtcon_port_to_vq() argument
235 qnum = tx_queue ? port->vsp_txq : port->vsp_rxq; in pci_vtcon_port_to_vq()
236 return (&port->vsp_sc->vsc_queues[qnum]); in pci_vtcon_port_to_vq()
243 struct pci_vtcon_port *port; in pci_vtcon_port_add() local
245 port = &sc->vsc_ports[port_id]; in pci_vtcon_port_add()
246 if (port->vsp_enabled) { in pci_vtcon_port_add()
250 port->vsp_id = port_id; in pci_vtcon_port_add()
251 port->vsp_sc = sc; in pci_vtcon_port_add()
252 port->vsp_name = name; in pci_vtcon_port_add()
253 port->vsp_cb = cb; in pci_vtcon_port_add()
254 port->vsp_arg = arg; in pci_vtcon_port_add()
256 if (port->vsp_id == 0) { in pci_vtcon_port_add()
258 port->vsp_txq = 0; in pci_vtcon_port_add()
259 port->vsp_rxq = 1; in pci_vtcon_port_add()
261 port->vsp_txq = (port_id + 1) * 2; in pci_vtcon_port_add()
262 port->vsp_rxq = port->vsp_txq + 1; in pci_vtcon_port_add()
265 port->vsp_enabled = true; in pci_vtcon_port_add()
266 return (port); in pci_vtcon_port_add()
277 long port; in pci_vtcon_sock_add() local
278 int s = -1, fd = -1, error = 0; in pci_vtcon_sock_add()
283 port = strtol(port_name, &cp, 0); in pci_vtcon_sock_add()
284 if (*cp != '\0' || port < 0 || port >= VTCON_MAXPORTS) { in pci_vtcon_sock_add()
285 EPRINTLN("vtcon: Invalid port %s", port_name); in pci_vtcon_sock_add()
286 error = -1; in pci_vtcon_sock_add()
292 EPRINTLN("vtcon: required path missing for port %ld", port); in pci_vtcon_sock_add()
293 error = -1; in pci_vtcon_sock_add()
297 sock = calloc(1, sizeof(struct pci_vtcon_sock)); in pci_vtcon_sock_add()
299 error = -1; in pci_vtcon_sock_add()
305 error = -1; in pci_vtcon_sock_add()
311 error = -1; in pci_vtcon_sock_add()
318 error = -1; in pci_vtcon_sock_add()
329 error = -1; in pci_vtcon_sock_add()
334 error = -1; in pci_vtcon_sock_add()
338 if (listen(s, 1) < 0) { in pci_vtcon_sock_add()
339 error = -1; in pci_vtcon_sock_add()
345 if (caph_rights_limit(s, &rights) == -1) in pci_vtcon_sock_add()
351 EPRINTLN("vtcon: required name missing for port %ld", port); in pci_vtcon_sock_add()
352 error = -1; in pci_vtcon_sock_add()
355 sock->vss_port = pci_vtcon_port_add(sc, port, name, pci_vtcon_sock_tx, sock); in pci_vtcon_sock_add()
356 if (sock->vss_port == NULL) { in pci_vtcon_sock_add()
357 error = -1; in pci_vtcon_sock_add()
361 sock->vss_open = false; in pci_vtcon_sock_add()
362 sock->vss_conn_fd = -1; in pci_vtcon_sock_add()
363 sock->vss_server_fd = s; in pci_vtcon_sock_add()
364 sock->vss_server_evp = mevent_add(s, EVF_READ, pci_vtcon_sock_accept, in pci_vtcon_sock_add()
367 if (sock->vss_server_evp == NULL) { in pci_vtcon_sock_add()
368 error = -1; in pci_vtcon_sock_add()
373 if (fd != -1) in pci_vtcon_sock_add()
377 if (s != -1) in pci_vtcon_sock_add()
391 s = accept(sock->vss_server_fd, NULL, NULL); in pci_vtcon_sock_accept()
395 if (sock->vss_open) { in pci_vtcon_sock_accept()
400 sock->vss_open = true; in pci_vtcon_sock_accept()
401 sock->vss_conn_fd = s; in pci_vtcon_sock_accept()
402 sock->vss_conn_evp = mevent_add(s, EVF_READ, pci_vtcon_sock_rx, sock); in pci_vtcon_sock_accept()
404 pci_vtcon_open_port(sock->vss_port, true); in pci_vtcon_sock_accept()
410 struct pci_vtcon_port *port; in pci_vtcon_sock_rx() local
418 port = sock->vss_port; in pci_vtcon_sock_rx()
419 vq = pci_vtcon_port_to_vq(port, true); in pci_vtcon_sock_rx()
421 if (!sock->vss_open || !port->vsp_rx_ready) { in pci_vtcon_sock_rx()
422 len = read(sock->vss_conn_fd, dummybuf, sizeof(dummybuf)); in pci_vtcon_sock_rx()
430 len = read(sock->vss_conn_fd, dummybuf, sizeof(dummybuf)); in pci_vtcon_sock_rx()
431 vq_endchains(vq, 1); in pci_vtcon_sock_rx()
439 n = vq_getchain(vq, &iov, 1, &req); in pci_vtcon_sock_rx()
440 assert(n == 1); in pci_vtcon_sock_rx()
441 len = readv(sock->vss_conn_fd, &iov, n); in pci_vtcon_sock_rx()
444 vq_retchains(vq, 1); in pci_vtcon_sock_rx()
455 vq_endchains(vq, 1); in pci_vtcon_sock_rx()
458 mevent_delete_close(sock->vss_conn_evp); in pci_vtcon_sock_rx()
459 sock->vss_conn_fd = -1; in pci_vtcon_sock_rx()
460 sock->vss_open = false; in pci_vtcon_sock_rx()
464 pci_vtcon_sock_tx(struct pci_vtcon_port *port __unused, void *arg __unused, in pci_vtcon_sock_tx()
472 if (sock->vss_conn_fd == -1) in pci_vtcon_sock_tx()
476 ret = stream_write(sock->vss_conn_fd, iov[i].iov_base, in pci_vtcon_sock_tx()
483 mevent_delete_close(sock->vss_conn_evp); in pci_vtcon_sock_tx()
484 sock->vss_conn_fd = -1; in pci_vtcon_sock_tx()
485 sock->vss_open = false; in pci_vtcon_sock_tx()
490 pci_vtcon_control_tx(struct pci_vtcon_port *port, void *arg __unused, in pci_vtcon_control_tx() argument
498 assert(niov == 1); in pci_vtcon_control_tx()
500 sc = port->vsp_sc; in pci_vtcon_control_tx()
501 ctrl = (struct pci_vtcon_control *)iov->iov_base; in pci_vtcon_control_tx()
503 switch (ctrl->event) { in pci_vtcon_control_tx()
505 sc->vsc_ready = true; in pci_vtcon_control_tx()
506 /* set port ready events for registered ports */ in pci_vtcon_control_tx()
508 tmp = &sc->vsc_ports[i]; in pci_vtcon_control_tx()
509 if (tmp->vsp_enabled) in pci_vtcon_control_tx()
512 if (tmp->vsp_open) in pci_vtcon_control_tx()
518 tmp = &sc->vsc_ports[ctrl->id]; in pci_vtcon_control_tx()
519 if (ctrl->id >= VTCON_MAXPORTS || !tmp->vsp_enabled) { in pci_vtcon_control_tx()
520 WPRINTF(("VTCON_PORT_READY event for unknown port %d", in pci_vtcon_control_tx()
521 ctrl->id)); in pci_vtcon_control_tx()
525 if (tmp->vsp_console) { in pci_vtcon_control_tx()
527 resp.id = ctrl->id; in pci_vtcon_control_tx()
528 resp.value = 1; in pci_vtcon_control_tx()
536 pci_vtcon_announce_port(struct pci_vtcon_port *port) in pci_vtcon_announce_port() argument
540 event.id = port->vsp_id; in pci_vtcon_announce_port()
542 event.value = 1; in pci_vtcon_announce_port()
543 pci_vtcon_control_send(port->vsp_sc, &event, NULL, 0); in pci_vtcon_announce_port()
546 pci_vtcon_control_send(port->vsp_sc, &event, port->vsp_name, in pci_vtcon_announce_port()
547 strlen(port->vsp_name)); in pci_vtcon_announce_port()
551 pci_vtcon_open_port(struct pci_vtcon_port *port, bool open) in pci_vtcon_open_port() argument
555 if (!port->vsp_sc->vsc_ready) { in pci_vtcon_open_port()
556 port->vsp_open = true; in pci_vtcon_open_port()
560 event.id = port->vsp_id; in pci_vtcon_open_port()
563 pci_vtcon_control_send(port->vsp_sc, &event, NULL, 0); in pci_vtcon_open_port()
575 if (len > SIZE_T_MAX - sizeof(struct pci_vtcon_control)) in pci_vtcon_control_send()
578 vq = pci_vtcon_port_to_vq(&sc->vsc_control_port, true); in pci_vtcon_control_send()
583 n = vq_getchain(vq, &iov, 1, &req); in pci_vtcon_control_send()
584 assert(n == 1); in pci_vtcon_control_send()
596 vq_endchains(vq, 1); in pci_vtcon_control_send()
604 struct pci_vtcon_port *port; in pci_vtcon_notify_tx() local
605 struct iovec iov[1]; in pci_vtcon_notify_tx()
610 port = pci_vtcon_vq_to_port(sc, vq); in pci_vtcon_notify_tx()
613 n = vq_getchain(vq, iov, 1, &req); in pci_vtcon_notify_tx()
614 assert(n == 1); in pci_vtcon_notify_tx()
615 if (port != NULL) in pci_vtcon_notify_tx()
616 port->vsp_cb(port, port->vsp_arg, iov, 1); in pci_vtcon_notify_tx()
623 vq_endchains(vq, 1); /* Generate interrupt if appropriate. */ in pci_vtcon_notify_tx()
630 struct pci_vtcon_port *port; in pci_vtcon_notify_rx() local
633 port = pci_vtcon_vq_to_port(sc, vq); in pci_vtcon_notify_rx()
635 if (!port->vsp_rx_ready) { in pci_vtcon_notify_rx()
636 port->vsp_rx_ready = 1; in pci_vtcon_notify_rx()
642 * Each console device has a "port" node which contains nodes for
643 * each port. Ports are numbered starting at 0.
646 pci_vtcon_legacy_config_port(nvlist_t *nvl, int port, char *opt) in pci_vtcon_legacy_config_port() argument
655 EPRINTLN("vtcon: port %s requires a path", name); in pci_vtcon_legacy_config_port()
656 return (-1); in pci_vtcon_legacy_config_port()
658 if (port >= VTCON_MAXPORTS) { in pci_vtcon_legacy_config_port()
660 return (-1); in pci_vtcon_legacy_config_port()
662 snprintf(node_name, sizeof(node_name), "%d", port); in pci_vtcon_legacy_config_port()
674 int error, port; in pci_vtcon_legacy_config() local
676 ports_nvl = create_relative_config_node(nvl, "port"); in pci_vtcon_legacy_config()
679 port = 0; in pci_vtcon_legacy_config()
681 error = pci_vtcon_legacy_config_port(ports_nvl, port, opt); in pci_vtcon_legacy_config()
684 port++; in pci_vtcon_legacy_config()
697 sc = calloc(1, sizeof(struct pci_vtcon_softc)); in pci_vtcon_init()
698 sc->vsc_config = calloc(1, sizeof(struct pci_vtcon_config)); in pci_vtcon_init()
699 sc->vsc_config->max_nr_ports = VTCON_MAXPORTS; in pci_vtcon_init()
700 sc->vsc_config->cols = 80; in pci_vtcon_init()
701 sc->vsc_config->rows = 25; in pci_vtcon_init()
703 pthread_mutex_init(&sc->vsc_mtx, NULL); in pci_vtcon_init()
705 vi_softc_linkup(&sc->vsc_vs, &vtcon_vi_consts, sc, pi, sc->vsc_queues); in pci_vtcon_init()
706 sc->vsc_vs.vs_mtx = &sc->vsc_mtx; in pci_vtcon_init()
709 sc->vsc_queues[i].vq_qsize = VTCON_RINGSZ; in pci_vtcon_init()
710 sc->vsc_queues[i].vq_notify = i % 2 == 0 in pci_vtcon_init()
722 if (vi_intr_init(&sc->vsc_vs, 1, fbsdrun_virtio_msix())) in pci_vtcon_init()
723 return (1); in pci_vtcon_init()
724 vi_set_io_bar(&sc->vsc_vs, 0); in pci_vtcon_init()
726 /* create control port */ in pci_vtcon_init()
727 sc->vsc_control_port.vsp_sc = sc; in pci_vtcon_init()
728 sc->vsc_control_port.vsp_txq = 2; in pci_vtcon_init()
729 sc->vsc_control_port.vsp_rxq = 3; in pci_vtcon_init()
730 sc->vsc_control_port.vsp_cb = pci_vtcon_control_tx; in pci_vtcon_init()
731 sc->vsc_control_port.vsp_enabled = true; in pci_vtcon_init()
733 ports_nvl = find_relative_config_node(nvl, "port"); in pci_vtcon_init()
747 EPRINTLN("cannot create port %s: %s", in pci_vtcon_init()
749 return (1); in pci_vtcon_init()
758 .pe_emu = "virtio-console",