1 // SPDX-License-Identifier: GPL-2.0
3 * Hypervisor filesystem for Linux on s390.
4 * Set Partition-Resource Parameter interface.
6 * Copyright IBM Corp. 2013
7 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
10 #include <linux/compat.h>
11 #include <linux/errno.h>
12 #include <linux/gfp.h>
13 #include <linux/string.h>
14 #include <linux/types.h>
15 #include <linux/uaccess.h>
20 #define DIAG304_SET_WEIGHTS 0
21 #define DIAG304_QUERY_PRP 1
22 #define DIAG304_SET_CAPPING 2
24 #define DIAG304_CMD_MAX 2
26 static inline unsigned long __hypfs_sprp_diag304(void *data, unsigned long cmd)
28 union register_pair r1 = { .even = (unsigned long)data, };
30 asm volatile("diag %[r1],%[r3],0x304\n"
31 : [r1] "+&d" (r1.pair)
37 static unsigned long hypfs_sprp_diag304(void *data, unsigned long cmd)
39 diag_stat_inc(DIAG_STAT_X304);
40 return __hypfs_sprp_diag304(data, cmd);
43 static void hypfs_sprp_free(const void *data)
45 free_page((unsigned long) data);
48 static int hypfs_sprp_create(void **data_ptr, void **free_ptr, size_t *size)
53 data = (void *) get_zeroed_page(GFP_KERNEL);
56 rc = hypfs_sprp_diag304(data, DIAG304_QUERY_PRP);
58 *data_ptr = *free_ptr = NULL;
60 free_page((unsigned long) data);
63 *data_ptr = *free_ptr = data;
68 static int __hypfs_sprp_ioctl(void __user *user_area)
70 struct hypfs_diag304 *diag304;
77 data = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
78 diag304 = kzalloc(sizeof(*diag304), GFP_KERNEL);
79 if (!data || !diag304)
83 if (copy_from_user(diag304, user_area, sizeof(*diag304)))
86 if ((diag304->args[0] >> 8) != 0 || diag304->args[1] > DIAG304_CMD_MAX)
90 udata = (void __user *)(unsigned long) diag304->data;
91 if (diag304->args[1] == DIAG304_SET_WEIGHTS ||
92 diag304->args[1] == DIAG304_SET_CAPPING)
93 if (copy_from_user(data, udata, PAGE_SIZE))
96 cmd = *(unsigned long *) &diag304->args[0];
97 diag304->rc = hypfs_sprp_diag304(data, cmd);
99 if (diag304->args[1] == DIAG304_QUERY_PRP)
100 if (copy_to_user(udata, data, PAGE_SIZE)) {
105 rc = copy_to_user(user_area, diag304, sizeof(*diag304)) ? -EFAULT : 0;
108 free_page((unsigned long) data);
112 static long hypfs_sprp_ioctl(struct file *file, unsigned int cmd,
117 if (!capable(CAP_SYS_ADMIN))
119 if (is_compat_task())
120 argp = compat_ptr(arg);
122 argp = (void __user *) arg;
125 return __hypfs_sprp_ioctl(argp);
126 default: /* unknown ioctl number */
132 static struct hypfs_dbfs_file hypfs_sprp_file = {
134 .data_create = hypfs_sprp_create,
135 .data_free = hypfs_sprp_free,
136 .unlocked_ioctl = hypfs_sprp_ioctl,
139 void hypfs_sprp_init(void)
143 hypfs_dbfs_create_file(&hypfs_sprp_file);
146 void hypfs_sprp_exit(void)
150 hypfs_dbfs_remove_file(&hypfs_sprp_file);