aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/virtio_console.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2014-12-01 06:17:40 -0500
committerMichael S. Tsirkin <mst@redhat.com>2014-12-09 05:06:32 -0500
commit1f0f9106f92c7d49ec92baa6ac757aa8b0590eff (patch)
treeb79ea77ccee79d3495f48081a6e78694b4120246 /drivers/char/virtio_console.c
parentdc9e51534b70e5c4a99235e940dc6f0f466fe175 (diff)
virtio_console: virtio 1.0 support
Pretty straight-forward, just use accessors for all fields. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'drivers/char/virtio_console.c')
-rw-r--r--drivers/char/virtio_console.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 8d00aa7f60f0..775c89821364 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -566,9 +566,9 @@ static ssize_t __send_control_msg(struct ports_device *portdev, u32 port_id,
566 if (!use_multiport(portdev)) 566 if (!use_multiport(portdev))
567 return 0; 567 return 0;
568 568
569 cpkt.id = port_id; 569 cpkt.id = cpu_to_virtio32(portdev->vdev, port_id);
570 cpkt.event = event; 570 cpkt.event = cpu_to_virtio16(portdev->vdev, event);
571 cpkt.value = value; 571 cpkt.value = cpu_to_virtio16(portdev->vdev, value);
572 572
573 vq = portdev->c_ovq; 573 vq = portdev->c_ovq;
574 574
@@ -1602,7 +1602,8 @@ static void unplug_port(struct port *port)
1602} 1602}
1603 1603
1604/* Any private messages that the Host and Guest want to share */ 1604/* Any private messages that the Host and Guest want to share */
1605static void handle_control_message(struct ports_device *portdev, 1605static void handle_control_message(struct virtio_device *vdev,
1606 struct ports_device *portdev,
1606 struct port_buffer *buf) 1607 struct port_buffer *buf)
1607{ 1608{
1608 struct virtio_console_control *cpkt; 1609 struct virtio_console_control *cpkt;
@@ -1612,15 +1613,16 @@ static void handle_control_message(struct ports_device *portdev,
1612 1613
1613 cpkt = (struct virtio_console_control *)(buf->buf + buf->offset); 1614 cpkt = (struct virtio_console_control *)(buf->buf + buf->offset);
1614 1615
1615 port = find_port_by_id(portdev, cpkt->id); 1616 port = find_port_by_id(portdev, virtio32_to_cpu(vdev, cpkt->id));
1616 if (!port && cpkt->event != VIRTIO_CONSOLE_PORT_ADD) { 1617 if (!port &&
1618 cpkt->event != cpu_to_virtio16(vdev, VIRTIO_CONSOLE_PORT_ADD)) {
1617 /* No valid header at start of buffer. Drop it. */ 1619 /* No valid header at start of buffer. Drop it. */
1618 dev_dbg(&portdev->vdev->dev, 1620 dev_dbg(&portdev->vdev->dev,
1619 "Invalid index %u in control packet\n", cpkt->id); 1621 "Invalid index %u in control packet\n", cpkt->id);
1620 return; 1622 return;
1621 } 1623 }
1622 1624
1623 switch (cpkt->event) { 1625 switch (virtio16_to_cpu(vdev, cpkt->event)) {
1624 case VIRTIO_CONSOLE_PORT_ADD: 1626 case VIRTIO_CONSOLE_PORT_ADD:
1625 if (port) { 1627 if (port) {
1626 dev_dbg(&portdev->vdev->dev, 1628 dev_dbg(&portdev->vdev->dev,
@@ -1628,13 +1630,15 @@ static void handle_control_message(struct ports_device *portdev,
1628 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); 1630 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1);
1629 break; 1631 break;
1630 } 1632 }
1631 if (cpkt->id >= portdev->config.max_nr_ports) { 1633 if (virtio32_to_cpu(vdev, cpkt->id) >=
1634 portdev->config.max_nr_ports) {
1632 dev_warn(&portdev->vdev->dev, 1635 dev_warn(&portdev->vdev->dev,
1633 "Request for adding port with out-of-bound id %u, max. supported id: %u\n", 1636 "Request for adding port with "
1637 "out-of-bound id %u, max. supported id: %u\n",
1634 cpkt->id, portdev->config.max_nr_ports - 1); 1638 cpkt->id, portdev->config.max_nr_ports - 1);
1635 break; 1639 break;
1636 } 1640 }
1637 add_port(portdev, cpkt->id); 1641 add_port(portdev, virtio32_to_cpu(vdev, cpkt->id));
1638 break; 1642 break;
1639 case VIRTIO_CONSOLE_PORT_REMOVE: 1643 case VIRTIO_CONSOLE_PORT_REMOVE:
1640 unplug_port(port); 1644 unplug_port(port);
@@ -1670,7 +1674,7 @@ static void handle_control_message(struct ports_device *portdev,
1670 break; 1674 break;
1671 } 1675 }
1672 case VIRTIO_CONSOLE_PORT_OPEN: 1676 case VIRTIO_CONSOLE_PORT_OPEN:
1673 port->host_connected = cpkt->value; 1677 port->host_connected = virtio16_to_cpu(vdev, cpkt->value);
1674 wake_up_interruptible(&port->waitqueue); 1678 wake_up_interruptible(&port->waitqueue);
1675 /* 1679 /*
1676 * If the host port got closed and the host had any 1680 * If the host port got closed and the host had any
@@ -1752,7 +1756,7 @@ static void control_work_handler(struct work_struct *work)
1752 buf->len = len; 1756 buf->len = len;
1753 buf->offset = 0; 1757 buf->offset = 0;
1754 1758
1755 handle_control_message(portdev, buf); 1759 handle_control_message(vq->vdev, portdev, buf);
1756 1760
1757 spin_lock(&portdev->c_ivq_lock); 1761 spin_lock(&portdev->c_ivq_lock);
1758 if (add_inbuf(portdev->c_ivq, buf) < 0) { 1762 if (add_inbuf(portdev->c_ivq, buf) < 0) {
@@ -2126,6 +2130,7 @@ static struct virtio_device_id id_table[] = {
2126static unsigned int features[] = { 2130static unsigned int features[] = {
2127 VIRTIO_CONSOLE_F_SIZE, 2131 VIRTIO_CONSOLE_F_SIZE,
2128 VIRTIO_CONSOLE_F_MULTIPORT, 2132 VIRTIO_CONSOLE_F_MULTIPORT,
2133 VIRTIO_F_VERSION_1,
2129}; 2134};
2130 2135
2131static struct virtio_device_id rproc_serial_id_table[] = { 2136static struct virtio_device_id rproc_serial_id_table[] = {