aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorAmit Shah <amit.shah@redhat.com>2011-12-22 06:28:27 -0500
committerRusty Russell <rusty@rustcorp.com.au>2012-01-12 00:14:45 -0500
commita0e2dbfc223028b72a1c193f94fcd3f67253ba4a (patch)
tree9995e923c960f0e8e1315f595336597f627e9c96 /drivers/char
parentf0fe6f11503fa9880867554350ac5d3092c47251 (diff)
virtio: console: Move vq and vq buf removal into separate functions
This common code will be shared with the PM freeze function. Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/virtio_console.c68
1 files changed, 40 insertions, 28 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index d1ae1492ee78..9681ffd79904 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1271,6 +1271,20 @@ static void remove_port(struct kref *kref)
1271 kfree(port); 1271 kfree(port);
1272} 1272}
1273 1273
1274static void remove_port_data(struct port *port)
1275{
1276 struct port_buffer *buf;
1277
1278 /* Remove unused data this port might have received. */
1279 discard_port_data(port);
1280
1281 reclaim_consumed_buffers(port);
1282
1283 /* Remove buffers we queued up for the Host to send us data in. */
1284 while ((buf = virtqueue_detach_unused_buf(port->in_vq)))
1285 free_buf(buf);
1286}
1287
1274/* 1288/*
1275 * Port got unplugged. Remove port from portdev's list and drop the 1289 * Port got unplugged. Remove port from portdev's list and drop the
1276 * kref reference. If no userspace has this port opened, it will 1290 * kref reference. If no userspace has this port opened, it will
@@ -1278,8 +1292,6 @@ static void remove_port(struct kref *kref)
1278 */ 1292 */
1279static void unplug_port(struct port *port) 1293static void unplug_port(struct port *port)
1280{ 1294{
1281 struct port_buffer *buf;
1282
1283 spin_lock_irq(&port->portdev->ports_lock); 1295 spin_lock_irq(&port->portdev->ports_lock);
1284 list_del(&port->list); 1296 list_del(&port->list);
1285 spin_unlock_irq(&port->portdev->ports_lock); 1297 spin_unlock_irq(&port->portdev->ports_lock);
@@ -1300,14 +1312,7 @@ static void unplug_port(struct port *port)
1300 hvc_remove(port->cons.hvc); 1312 hvc_remove(port->cons.hvc);
1301 } 1313 }
1302 1314
1303 /* Remove unused data this port might have received. */ 1315 remove_port_data(port);
1304 discard_port_data(port);
1305
1306 reclaim_consumed_buffers(port);
1307
1308 /* Remove buffers we queued up for the Host to send us data in. */
1309 while ((buf = virtqueue_detach_unused_buf(port->in_vq)))
1310 free_buf(buf);
1311 1316
1312 /* 1317 /*
1313 * We should just assume the device itself has gone off -- 1318 * We should just assume the device itself has gone off --
@@ -1659,6 +1664,28 @@ static const struct file_operations portdev_fops = {
1659 .owner = THIS_MODULE, 1664 .owner = THIS_MODULE,
1660}; 1665};
1661 1666
1667static void remove_vqs(struct ports_device *portdev)
1668{
1669 portdev->vdev->config->del_vqs(portdev->vdev);
1670 kfree(portdev->in_vqs);
1671 kfree(portdev->out_vqs);
1672}
1673
1674static void remove_controlq_data(struct ports_device *portdev)
1675{
1676 struct port_buffer *buf;
1677 unsigned int len;
1678
1679 if (!use_multiport(portdev))
1680 return;
1681
1682 while ((buf = virtqueue_get_buf(portdev->c_ivq, &len)))
1683 free_buf(buf);
1684
1685 while ((buf = virtqueue_detach_unused_buf(portdev->c_ivq)))
1686 free_buf(buf);
1687}
1688
1662/* 1689/*
1663 * Once we're further in boot, we get probed like any other virtio 1690 * Once we're further in boot, we get probed like any other virtio
1664 * device. 1691 * device.
@@ -1764,9 +1791,7 @@ free_vqs:
1764 /* The host might want to notify mgmt sw about device add failure */ 1791 /* The host might want to notify mgmt sw about device add failure */
1765 __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, 1792 __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
1766 VIRTIO_CONSOLE_DEVICE_READY, 0); 1793 VIRTIO_CONSOLE_DEVICE_READY, 0);
1767 vdev->config->del_vqs(vdev); 1794 remove_vqs(portdev);
1768 kfree(portdev->in_vqs);
1769 kfree(portdev->out_vqs);
1770free_chrdev: 1795free_chrdev:
1771 unregister_chrdev(portdev->chr_major, "virtio-portsdev"); 1796 unregister_chrdev(portdev->chr_major, "virtio-portsdev");
1772free: 1797free:
@@ -1804,21 +1829,8 @@ static void virtcons_remove(struct virtio_device *vdev)
1804 * have to just stop using the port, as the vqs are going 1829 * have to just stop using the port, as the vqs are going
1805 * away. 1830 * away.
1806 */ 1831 */
1807 if (use_multiport(portdev)) { 1832 remove_controlq_data(portdev);
1808 struct port_buffer *buf; 1833 remove_vqs(portdev);
1809 unsigned int len;
1810
1811 while ((buf = virtqueue_get_buf(portdev->c_ivq, &len)))
1812 free_buf(buf);
1813
1814 while ((buf = virtqueue_detach_unused_buf(portdev->c_ivq)))
1815 free_buf(buf);
1816 }
1817
1818 vdev->config->del_vqs(vdev);
1819 kfree(portdev->in_vqs);
1820 kfree(portdev->out_vqs);
1821
1822 kfree(portdev); 1834 kfree(portdev);
1823} 1835}
1824 1836