diff options
-rw-r--r-- | drivers/char/virtio_console.c | 29 | ||||
-rw-r--r-- | include/uapi/linux/virtio_console.h | 7 |
2 files changed, 21 insertions, 15 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 */ |
1605 | static void handle_control_message(struct ports_device *portdev, | 1605 | static 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[] = { | |||
2126 | static unsigned int features[] = { | 2130 | static 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 | ||
2131 | static struct virtio_device_id rproc_serial_id_table[] = { | 2136 | static struct virtio_device_id rproc_serial_id_table[] = { |
diff --git a/include/uapi/linux/virtio_console.h b/include/uapi/linux/virtio_console.h index ba260dd0b33a..b7fb108c9310 100644 --- a/include/uapi/linux/virtio_console.h +++ b/include/uapi/linux/virtio_console.h | |||
@@ -32,6 +32,7 @@ | |||
32 | #ifndef _UAPI_LINUX_VIRTIO_CONSOLE_H | 32 | #ifndef _UAPI_LINUX_VIRTIO_CONSOLE_H |
33 | #define _UAPI_LINUX_VIRTIO_CONSOLE_H | 33 | #define _UAPI_LINUX_VIRTIO_CONSOLE_H |
34 | #include <linux/types.h> | 34 | #include <linux/types.h> |
35 | #include <linux/virtio_types.h> | ||
35 | #include <linux/virtio_ids.h> | 36 | #include <linux/virtio_ids.h> |
36 | #include <linux/virtio_config.h> | 37 | #include <linux/virtio_config.h> |
37 | 38 | ||
@@ -58,9 +59,9 @@ struct virtio_console_config { | |||
58 | * particular port. | 59 | * particular port. |
59 | */ | 60 | */ |
60 | struct virtio_console_control { | 61 | struct virtio_console_control { |
61 | __u32 id; /* Port number */ | 62 | __virtio32 id; /* Port number */ |
62 | __u16 event; /* The kind of control event (see below) */ | 63 | __virtio16 event; /* The kind of control event (see below) */ |
63 | __u16 value; /* Extra information for the key */ | 64 | __virtio16 value; /* Extra information for the key */ |
64 | }; | 65 | }; |
65 | 66 | ||
66 | /* Some events for control messages */ | 67 | /* Some events for control messages */ |