hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/char/virtio_console.c
....@@ -1,21 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2006, 2007, 2009 Rusty Russell, IBM Corporation
34 * Copyright (C) 2009, 2010, 2011 Red Hat, Inc.
45 * 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
196 */
207 #include <linux/cdev.h>
218 #include <linux/debugfs.h>
....@@ -125,7 +112,7 @@
125112 unsigned int sgpages;
126113
127114 /* sg is used if spages > 0. sg must be the last in is struct */
128
- struct scatterlist sg[0];
115
+ struct scatterlist sg[];
129116 };
130117
131118 /*
....@@ -448,12 +435,12 @@
448435 /*
449436 * Allocate DMA memory from ancestor. When a virtio
450437 * 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.
453440 */
454
- if (!vdev->dev.parent || !vdev->dev.parent->parent)
441
+ buf->dev = vdev->dev.parent;
442
+ if (!buf->dev)
455443 goto free_buf;
456
- buf->dev = vdev->dev.parent->parent;
457444
458445 /* Increase device refcnt to avoid freeing it */
459446 get_device(buf->dev);
....@@ -884,7 +871,7 @@
884871 return 0;
885872
886873 /* Try lock this page */
887
- if (pipe_buf_steal(pipe, buf) == 0) {
874
+ if (pipe_buf_try_steal(pipe, buf)) {
888875 /* Get reference and unlock page for moving */
889876 get_page(buf->page);
890877 unlock_page(buf->page);
....@@ -932,6 +919,7 @@
932919 .pos = *ppos,
933920 .u.data = &sgl,
934921 };
922
+ unsigned int occupancy;
935923
936924 /*
937925 * Rproc_serial does not yet support splice. To support splice
....@@ -942,21 +930,18 @@
942930 if (is_rproc_serial(port->out_vq->vdev))
943931 return -EINVAL;
944932
945
- /*
946
- * pipe->nrbufs == 0 means there are no data to transfer,
947
- * so this returns just 0 for no data.
948
- */
949933 pipe_lock(pipe);
950
- if (!pipe->nrbufs) {
951
- ret = 0;
934
+ ret = 0;
935
+ if (pipe_empty(pipe->head, pipe->tail))
952936 goto error_out;
953
- }
954937
955938 ret = wait_port_writable(port, filp->f_flags & O_NONBLOCK);
956939 if (ret < 0)
957940 goto error_out;
958941
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
+
960945 if (!buf) {
961946 ret = -ENOMEM;
962947 goto error_out;
....@@ -964,7 +949,7 @@
964949
965950 sgl.n = 0;
966951 sgl.len = 0;
967
- sgl.size = pipe->nrbufs;
952
+ sgl.size = occupancy;
968953 sgl.sg = buf->sg;
969954 sg_init_table(sgl.sg, sgl.size);
970955 ret = __splice_from_pipe(pipe, &sd, pipe_to_sg);
....@@ -1309,7 +1294,7 @@
13091294 .attrs = port_sysfs_entries,
13101295 };
13111296
1312
-static int debugfs_show(struct seq_file *s, void *data)
1297
+static int port_debugfs_show(struct seq_file *s, void *data)
13131298 {
13141299 struct port *port = s->private;
13151300
....@@ -1327,18 +1312,7 @@
13271312 return 0;
13281313 }
13291314
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);
13421316
13431317 static void set_console_size(struct port *port, u16 rows, u16 cols)
13441318 {
....@@ -1492,7 +1466,7 @@
14921466 port->debugfs_file = debugfs_create_file(debugfs_name, 0444,
14931467 pdrvdata.debugfs_dir,
14941468 port,
1495
- &port_debugfs_ops);
1469
+ &port_debugfs_fops);
14961470 }
14971471 return 0;
14981472
....@@ -1985,6 +1959,13 @@
19851959 list_del(&portdev->list);
19861960 spin_unlock_irq(&pdrvdata_lock);
19871961
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
+
19881969 /* Disable interrupts for vqs */
19891970 vdev->config->reset(vdev);
19901971 /* Finish up work that's lined up */
....@@ -2138,18 +2119,18 @@
21382119 return err;
21392120 }
21402121
2141
-static struct virtio_device_id id_table[] = {
2122
+static const struct virtio_device_id id_table[] = {
21422123 { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID },
21432124 { 0 },
21442125 };
21452126 MODULE_DEVICE_TABLE(virtio, id_table);
21462127
2147
-static unsigned int features[] = {
2128
+static const unsigned int features[] = {
21482129 VIRTIO_CONSOLE_F_SIZE,
21492130 VIRTIO_CONSOLE_F_MULTIPORT,
21502131 };
21512132
2152
-static struct virtio_device_id rproc_serial_id_table[] = {
2133
+static const struct virtio_device_id rproc_serial_id_table[] = {
21532134 #if IS_ENABLED(CONFIG_REMOTEPROC)
21542135 { VIRTIO_ID_RPROC_SERIAL, VIRTIO_DEV_ANY_ID },
21552136 #endif
....@@ -2157,7 +2138,7 @@
21572138 };
21582139 MODULE_DEVICE_TABLE(virtio, rproc_serial_id_table);
21592140
2160
-static unsigned int rproc_serial_features[] = {
2141
+static const unsigned int rproc_serial_features[] = {
21612142 };
21622143
21632144 #ifdef CONFIG_PM_SLEEP
....@@ -2258,7 +2239,7 @@
22582239 .remove = virtcons_remove,
22592240 };
22602241
2261
-static int __init init(void)
2242
+static int __init virtio_console_init(void)
22622243 {
22632244 int err;
22642245
....@@ -2295,7 +2276,7 @@
22952276 return err;
22962277 }
22972278
2298
-static void __exit fini(void)
2279
+static void __exit virtio_console_fini(void)
22992280 {
23002281 reclaim_dma_bufs();
23012282
....@@ -2305,8 +2286,8 @@
23052286 class_destroy(pdrvdata.class);
23062287 debugfs_remove_recursive(pdrvdata.debugfs_dir);
23072288 }
2308
-module_init(init);
2309
-module_exit(fini);
2289
+module_init(virtio_console_init);
2290
+module_exit(virtio_console_fini);
23102291
23112292 MODULE_DESCRIPTION("Virtio console driver");
23122293 MODULE_LICENSE("GPL");