1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Provide diagnose information via misc device /dev/diag.
4 *
5 * Copyright IBM Corp. 2024
6 */
7
8 #include <linux/fs.h>
9 #include <linux/init.h>
10 #include <linux/ioctl.h>
11 #include <linux/kernel.h>
12 #include <linux/miscdevice.h>
13 #include <linux/types.h>
14
15 #include <uapi/asm/diag.h>
16 #include "diag_ioctl.h"
17
diag_ioctl(struct file * filp,unsigned int cmd,unsigned long arg)18 static long diag_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
19 {
20 long rc;
21
22 switch (cmd) {
23 case DIAG324_GET_PIBLEN:
24 rc = diag324_piblen(arg);
25 break;
26 case DIAG324_GET_PIBBUF:
27 rc = diag324_pibbuf(arg);
28 break;
29 case DIAG310_GET_STRIDE:
30 rc = diag310_memtop_stride(arg);
31 break;
32 case DIAG310_GET_MEMTOPLEN:
33 rc = diag310_memtop_len(arg);
34 break;
35 case DIAG310_GET_MEMTOPBUF:
36 rc = diag310_memtop_buf(arg);
37 break;
38 default:
39 rc = -ENOIOCTLCMD;
40 break;
41 }
42 return rc;
43 }
44
45 static const struct file_operations fops = {
46 .owner = THIS_MODULE,
47 .open = nonseekable_open,
48 .unlocked_ioctl = diag_ioctl,
49 };
50
51 static struct miscdevice diagdev = {
52 .name = "diag",
53 .minor = MISC_DYNAMIC_MINOR,
54 .fops = &fops,
55 .mode = 0444,
56 };
57
diag_init(void)58 static int diag_init(void)
59 {
60 return misc_register(&diagdev);
61 }
62
63 device_initcall(diag_init);
64