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>
16 #include <asm/compat.h>
21 #define DIAG304_SET_WEIGHTS 0
22 #define DIAG304_QUERY_PRP 1
23 #define DIAG304_SET_CAPPING 2
25 #define DIAG304_CMD_MAX 2
27 static inline unsigned long __hypfs_sprp_diag304(void *data
, unsigned long cmd
)
29 register unsigned long _data
asm("2") = (unsigned long) data
;
30 register unsigned long _rc
asm("3");
31 register unsigned long _cmd
asm("4") = cmd
;
33 asm volatile("diag %1,%2,0x304\n"
34 : "=d" (_rc
) : "d" (_data
), "d" (_cmd
) : "memory");
39 static unsigned long hypfs_sprp_diag304(void *data
, unsigned long cmd
)
41 diag_stat_inc(DIAG_STAT_X304
);
42 return __hypfs_sprp_diag304(data
, cmd
);
45 static void hypfs_sprp_free(const void *data
)
47 free_page((unsigned long) data
);
50 static int hypfs_sprp_create(void **data_ptr
, void **free_ptr
, size_t *size
)
55 data
= (void *) get_zeroed_page(GFP_KERNEL
);
58 rc
= hypfs_sprp_diag304(data
, DIAG304_QUERY_PRP
);
60 *data_ptr
= *free_ptr
= NULL
;
62 free_page((unsigned long) data
);
65 *data_ptr
= *free_ptr
= data
;
70 static int __hypfs_sprp_ioctl(void __user
*user_area
)
72 struct hypfs_diag304 diag304
;
78 if (copy_from_user(&diag304
, user_area
, sizeof(diag304
)))
80 if ((diag304
.args
[0] >> 8) != 0 || diag304
.args
[1] > DIAG304_CMD_MAX
)
83 data
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
87 udata
= (void __user
*)(unsigned long) diag304
.data
;
88 if (diag304
.args
[1] == DIAG304_SET_WEIGHTS
||
89 diag304
.args
[1] == DIAG304_SET_CAPPING
)
90 if (copy_from_user(data
, udata
, PAGE_SIZE
)) {
95 cmd
= *(unsigned long *) &diag304
.args
[0];
96 diag304
.rc
= hypfs_sprp_diag304(data
, cmd
);
98 if (diag304
.args
[1] == DIAG304_QUERY_PRP
)
99 if (copy_to_user(udata
, data
, PAGE_SIZE
)) {
104 rc
= copy_to_user(user_area
, &diag304
, sizeof(diag304
)) ? -EFAULT
: 0;
106 free_page((unsigned long) data
);
110 static long hypfs_sprp_ioctl(struct file
*file
, unsigned int cmd
,
115 if (!capable(CAP_SYS_ADMIN
))
117 if (is_compat_task())
118 argp
= compat_ptr(arg
);
120 argp
= (void __user
*) arg
;
123 return __hypfs_sprp_ioctl(argp
);
124 default: /* unknown ioctl number */
130 static struct hypfs_dbfs_file hypfs_sprp_file
= {
132 .data_create
= hypfs_sprp_create
,
133 .data_free
= hypfs_sprp_free
,
134 .unlocked_ioctl
= hypfs_sprp_ioctl
,
137 int hypfs_sprp_init(void)
141 return hypfs_dbfs_create_file(&hypfs_sprp_file
);
144 void hypfs_sprp_exit(void)
148 hypfs_dbfs_remove_file(&hypfs_sprp_file
);