xref: /linux/arch/s390/kernel/diag/diag_misc.c (revision 1260ed77798502de9c98020040d2995008de10cc)
12478d43eSSumanth Korikkar // SPDX-License-Identifier: GPL-2.0
22478d43eSSumanth Korikkar /*
32478d43eSSumanth Korikkar  * Provide diagnose information via misc device /dev/diag.
42478d43eSSumanth Korikkar  *
52478d43eSSumanth Korikkar  * Copyright IBM Corp. 2024
62478d43eSSumanth Korikkar  */
72478d43eSSumanth Korikkar 
82478d43eSSumanth Korikkar #include <linux/fs.h>
92478d43eSSumanth Korikkar #include <linux/init.h>
102478d43eSSumanth Korikkar #include <linux/ioctl.h>
112478d43eSSumanth Korikkar #include <linux/kernel.h>
122478d43eSSumanth Korikkar #include <linux/miscdevice.h>
132478d43eSSumanth Korikkar #include <linux/types.h>
142478d43eSSumanth Korikkar 
1590e6f191SSumanth Korikkar #include <uapi/asm/diag.h>
1690e6f191SSumanth Korikkar #include "diag_ioctl.h"
1790e6f191SSumanth Korikkar 
182478d43eSSumanth Korikkar static long diag_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
192478d43eSSumanth Korikkar {
202478d43eSSumanth Korikkar 	long rc;
212478d43eSSumanth Korikkar 
222478d43eSSumanth Korikkar 	switch (cmd) {
2390e6f191SSumanth Korikkar 	case DIAG324_GET_PIBLEN:
2490e6f191SSumanth Korikkar 		rc = diag324_piblen(arg);
2590e6f191SSumanth Korikkar 		break;
2690e6f191SSumanth Korikkar 	case DIAG324_GET_PIBBUF:
2790e6f191SSumanth Korikkar 		rc = diag324_pibbuf(arg);
2890e6f191SSumanth Korikkar 		break;
29*0d308717SMete Durlu 	case DIAG310_GET_STRIDE:
30*0d308717SMete Durlu 		rc = diag310_memtop_stride(arg);
31*0d308717SMete Durlu 		break;
32*0d308717SMete Durlu 	case DIAG310_GET_MEMTOPLEN:
33*0d308717SMete Durlu 		rc = diag310_memtop_len(arg);
34*0d308717SMete Durlu 		break;
35*0d308717SMete Durlu 	case DIAG310_GET_MEMTOPBUF:
36*0d308717SMete Durlu 		rc = diag310_memtop_buf(arg);
37*0d308717SMete Durlu 		break;
382478d43eSSumanth Korikkar 	default:
392478d43eSSumanth Korikkar 		rc = -ENOIOCTLCMD;
402478d43eSSumanth Korikkar 		break;
412478d43eSSumanth Korikkar 	}
422478d43eSSumanth Korikkar 	return rc;
432478d43eSSumanth Korikkar }
442478d43eSSumanth Korikkar 
452478d43eSSumanth Korikkar static const struct file_operations fops = {
462478d43eSSumanth Korikkar 	.owner		= THIS_MODULE,
472478d43eSSumanth Korikkar 	.open		= nonseekable_open,
482478d43eSSumanth Korikkar 	.unlocked_ioctl	= diag_ioctl,
492478d43eSSumanth Korikkar };
502478d43eSSumanth Korikkar 
512478d43eSSumanth Korikkar static struct miscdevice diagdev = {
522478d43eSSumanth Korikkar 	.name	= "diag",
532478d43eSSumanth Korikkar 	.minor	= MISC_DYNAMIC_MINOR,
542478d43eSSumanth Korikkar 	.fops	= &fops,
552478d43eSSumanth Korikkar 	.mode	= 0444,
562478d43eSSumanth Korikkar };
572478d43eSSumanth Korikkar 
582478d43eSSumanth Korikkar static int diag_init(void)
592478d43eSSumanth Korikkar {
602478d43eSSumanth Korikkar 	return misc_register(&diagdev);
612478d43eSSumanth Korikkar }
622478d43eSSumanth Korikkar 
632478d43eSSumanth Korikkar device_initcall(diag_init);
64