.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2006, 2007, 2009 Rusty Russell, IBM Corporation |
---|
3 | 4 | * Copyright (C) 2009, 2010, 2011 Red Hat, Inc. |
---|
4 | 5 | * Copyright (C) 2009, 2010, 2011 Amit Shah <amit.shah@redhat.com> |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as published by |
---|
8 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
9 | | - * (at your option) any later version. |
---|
10 | | - * |
---|
11 | | - * This program is distributed in the hope that it will be useful, |
---|
12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | | - * GNU General Public License for more details. |
---|
15 | | - * |
---|
16 | | - * You should have received a copy of the GNU General Public License |
---|
17 | | - * along with this program; if not, write to the Free Software |
---|
18 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | 6 | */ |
---|
20 | 7 | #include <linux/cdev.h> |
---|
21 | 8 | #include <linux/debugfs.h> |
---|
.. | .. |
---|
125 | 112 | unsigned int sgpages; |
---|
126 | 113 | |
---|
127 | 114 | /* sg is used if spages > 0. sg must be the last in is struct */ |
---|
128 | | - struct scatterlist sg[0]; |
---|
| 115 | + struct scatterlist sg[]; |
---|
129 | 116 | }; |
---|
130 | 117 | |
---|
131 | 118 | /* |
---|
.. | .. |
---|
448 | 435 | /* |
---|
449 | 436 | * Allocate DMA memory from ancestor. When a virtio |
---|
450 | 437 | * device is created by remoteproc, the DMA memory is |
---|
451 | | - * associated with the grandparent device: |
---|
452 | | - * vdev => rproc => platform-dev. |
---|
| 438 | + * associated with the parent device: |
---|
| 439 | + * virtioY => remoteprocX#vdevYbuffer. |
---|
453 | 440 | */ |
---|
454 | | - if (!vdev->dev.parent || !vdev->dev.parent->parent) |
---|
| 441 | + buf->dev = vdev->dev.parent; |
---|
| 442 | + if (!buf->dev) |
---|
455 | 443 | goto free_buf; |
---|
456 | | - buf->dev = vdev->dev.parent->parent; |
---|
457 | 444 | |
---|
458 | 445 | /* Increase device refcnt to avoid freeing it */ |
---|
459 | 446 | get_device(buf->dev); |
---|
.. | .. |
---|
884 | 871 | return 0; |
---|
885 | 872 | |
---|
886 | 873 | /* Try lock this page */ |
---|
887 | | - if (pipe_buf_steal(pipe, buf) == 0) { |
---|
| 874 | + if (pipe_buf_try_steal(pipe, buf)) { |
---|
888 | 875 | /* Get reference and unlock page for moving */ |
---|
889 | 876 | get_page(buf->page); |
---|
890 | 877 | unlock_page(buf->page); |
---|
.. | .. |
---|
932 | 919 | .pos = *ppos, |
---|
933 | 920 | .u.data = &sgl, |
---|
934 | 921 | }; |
---|
| 922 | + unsigned int occupancy; |
---|
935 | 923 | |
---|
936 | 924 | /* |
---|
937 | 925 | * Rproc_serial does not yet support splice. To support splice |
---|
.. | .. |
---|
942 | 930 | if (is_rproc_serial(port->out_vq->vdev)) |
---|
943 | 931 | return -EINVAL; |
---|
944 | 932 | |
---|
945 | | - /* |
---|
946 | | - * pipe->nrbufs == 0 means there are no data to transfer, |
---|
947 | | - * so this returns just 0 for no data. |
---|
948 | | - */ |
---|
949 | 933 | pipe_lock(pipe); |
---|
950 | | - if (!pipe->nrbufs) { |
---|
951 | | - ret = 0; |
---|
| 934 | + ret = 0; |
---|
| 935 | + if (pipe_empty(pipe->head, pipe->tail)) |
---|
952 | 936 | goto error_out; |
---|
953 | | - } |
---|
954 | 937 | |
---|
955 | 938 | ret = wait_port_writable(port, filp->f_flags & O_NONBLOCK); |
---|
956 | 939 | if (ret < 0) |
---|
957 | 940 | goto error_out; |
---|
958 | 941 | |
---|
959 | | - buf = alloc_buf(port->portdev->vdev, 0, pipe->nrbufs); |
---|
| 942 | + occupancy = pipe_occupancy(pipe->head, pipe->tail); |
---|
| 943 | + buf = alloc_buf(port->portdev->vdev, 0, occupancy); |
---|
| 944 | + |
---|
960 | 945 | if (!buf) { |
---|
961 | 946 | ret = -ENOMEM; |
---|
962 | 947 | goto error_out; |
---|
.. | .. |
---|
964 | 949 | |
---|
965 | 950 | sgl.n = 0; |
---|
966 | 951 | sgl.len = 0; |
---|
967 | | - sgl.size = pipe->nrbufs; |
---|
| 952 | + sgl.size = occupancy; |
---|
968 | 953 | sgl.sg = buf->sg; |
---|
969 | 954 | sg_init_table(sgl.sg, sgl.size); |
---|
970 | 955 | ret = __splice_from_pipe(pipe, &sd, pipe_to_sg); |
---|
.. | .. |
---|
1309 | 1294 | .attrs = port_sysfs_entries, |
---|
1310 | 1295 | }; |
---|
1311 | 1296 | |
---|
1312 | | -static int debugfs_show(struct seq_file *s, void *data) |
---|
| 1297 | +static int port_debugfs_show(struct seq_file *s, void *data) |
---|
1313 | 1298 | { |
---|
1314 | 1299 | struct port *port = s->private; |
---|
1315 | 1300 | |
---|
.. | .. |
---|
1327 | 1312 | return 0; |
---|
1328 | 1313 | } |
---|
1329 | 1314 | |
---|
1330 | | -static int debugfs_open(struct inode *inode, struct file *file) |
---|
1331 | | -{ |
---|
1332 | | - return single_open(file, debugfs_show, inode->i_private); |
---|
1333 | | -} |
---|
1334 | | - |
---|
1335 | | -static const struct file_operations port_debugfs_ops = { |
---|
1336 | | - .owner = THIS_MODULE, |
---|
1337 | | - .open = debugfs_open, |
---|
1338 | | - .read = seq_read, |
---|
1339 | | - .llseek = seq_lseek, |
---|
1340 | | - .release = single_release, |
---|
1341 | | -}; |
---|
| 1315 | +DEFINE_SHOW_ATTRIBUTE(port_debugfs); |
---|
1342 | 1316 | |
---|
1343 | 1317 | static void set_console_size(struct port *port, u16 rows, u16 cols) |
---|
1344 | 1318 | { |
---|
.. | .. |
---|
1492 | 1466 | port->debugfs_file = debugfs_create_file(debugfs_name, 0444, |
---|
1493 | 1467 | pdrvdata.debugfs_dir, |
---|
1494 | 1468 | port, |
---|
1495 | | - &port_debugfs_ops); |
---|
| 1469 | + &port_debugfs_fops); |
---|
1496 | 1470 | } |
---|
1497 | 1471 | return 0; |
---|
1498 | 1472 | |
---|
.. | .. |
---|
1985 | 1959 | list_del(&portdev->list); |
---|
1986 | 1960 | spin_unlock_irq(&pdrvdata_lock); |
---|
1987 | 1961 | |
---|
| 1962 | + /* Device is going away, exit any polling for buffers */ |
---|
| 1963 | + virtio_break_device(vdev); |
---|
| 1964 | + if (use_multiport(portdev)) |
---|
| 1965 | + flush_work(&portdev->control_work); |
---|
| 1966 | + else |
---|
| 1967 | + flush_work(&portdev->config_work); |
---|
| 1968 | + |
---|
1988 | 1969 | /* Disable interrupts for vqs */ |
---|
1989 | 1970 | vdev->config->reset(vdev); |
---|
1990 | 1971 | /* Finish up work that's lined up */ |
---|
.. | .. |
---|
2138 | 2119 | return err; |
---|
2139 | 2120 | } |
---|
2140 | 2121 | |
---|
2141 | | -static struct virtio_device_id id_table[] = { |
---|
| 2122 | +static const struct virtio_device_id id_table[] = { |
---|
2142 | 2123 | { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID }, |
---|
2143 | 2124 | { 0 }, |
---|
2144 | 2125 | }; |
---|
2145 | 2126 | MODULE_DEVICE_TABLE(virtio, id_table); |
---|
2146 | 2127 | |
---|
2147 | | -static unsigned int features[] = { |
---|
| 2128 | +static const unsigned int features[] = { |
---|
2148 | 2129 | VIRTIO_CONSOLE_F_SIZE, |
---|
2149 | 2130 | VIRTIO_CONSOLE_F_MULTIPORT, |
---|
2150 | 2131 | }; |
---|
2151 | 2132 | |
---|
2152 | | -static struct virtio_device_id rproc_serial_id_table[] = { |
---|
| 2133 | +static const struct virtio_device_id rproc_serial_id_table[] = { |
---|
2153 | 2134 | #if IS_ENABLED(CONFIG_REMOTEPROC) |
---|
2154 | 2135 | { VIRTIO_ID_RPROC_SERIAL, VIRTIO_DEV_ANY_ID }, |
---|
2155 | 2136 | #endif |
---|
.. | .. |
---|
2157 | 2138 | }; |
---|
2158 | 2139 | MODULE_DEVICE_TABLE(virtio, rproc_serial_id_table); |
---|
2159 | 2140 | |
---|
2160 | | -static unsigned int rproc_serial_features[] = { |
---|
| 2141 | +static const unsigned int rproc_serial_features[] = { |
---|
2161 | 2142 | }; |
---|
2162 | 2143 | |
---|
2163 | 2144 | #ifdef CONFIG_PM_SLEEP |
---|
.. | .. |
---|
2258 | 2239 | .remove = virtcons_remove, |
---|
2259 | 2240 | }; |
---|
2260 | 2241 | |
---|
2261 | | -static int __init init(void) |
---|
| 2242 | +static int __init virtio_console_init(void) |
---|
2262 | 2243 | { |
---|
2263 | 2244 | int err; |
---|
2264 | 2245 | |
---|
.. | .. |
---|
2295 | 2276 | return err; |
---|
2296 | 2277 | } |
---|
2297 | 2278 | |
---|
2298 | | -static void __exit fini(void) |
---|
| 2279 | +static void __exit virtio_console_fini(void) |
---|
2299 | 2280 | { |
---|
2300 | 2281 | reclaim_dma_bufs(); |
---|
2301 | 2282 | |
---|
.. | .. |
---|
2305 | 2286 | class_destroy(pdrvdata.class); |
---|
2306 | 2287 | debugfs_remove_recursive(pdrvdata.debugfs_dir); |
---|
2307 | 2288 | } |
---|
2308 | | -module_init(init); |
---|
2309 | | -module_exit(fini); |
---|
| 2289 | +module_init(virtio_console_init); |
---|
| 2290 | +module_exit(virtio_console_fini); |
---|
2310 | 2291 | |
---|
2311 | 2292 | MODULE_DESCRIPTION("Virtio console driver"); |
---|
2312 | 2293 | MODULE_LICENSE("GPL"); |
---|