mm: make wait_on_page_writeback() wait for multiple pending writebacks
[linux/fpc-iii.git] / arch / s390 / hypfs / hypfs_sprp.c
blob7d9fb496d155b3dafdc6ffe6154bc063334fd7c8
1 // SPDX-License-Identifier: GPL-2.0
2 /*
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>
8 */
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/diag.h>
17 #include <asm/sclp.h>
18 #include "hypfs.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 register unsigned long _data asm("2") = (unsigned long) data;
29 register unsigned long _rc asm("3");
30 register unsigned long _cmd asm("4") = cmd;
32 asm volatile("diag %1,%2,0x304\n"
33 : "=d" (_rc) : "d" (_data), "d" (_cmd) : "memory");
35 return _rc;
38 static unsigned long hypfs_sprp_diag304(void *data, unsigned long cmd)
40 diag_stat_inc(DIAG_STAT_X304);
41 return __hypfs_sprp_diag304(data, cmd);
44 static void hypfs_sprp_free(const void *data)
46 free_page((unsigned long) data);
49 static int hypfs_sprp_create(void **data_ptr, void **free_ptr, size_t *size)
51 unsigned long rc;
52 void *data;
54 data = (void *) get_zeroed_page(GFP_KERNEL);
55 if (!data)
56 return -ENOMEM;
57 rc = hypfs_sprp_diag304(data, DIAG304_QUERY_PRP);
58 if (rc != 1) {
59 *data_ptr = *free_ptr = NULL;
60 *size = 0;
61 free_page((unsigned long) data);
62 return -EIO;
64 *data_ptr = *free_ptr = data;
65 *size = PAGE_SIZE;
66 return 0;
69 static int __hypfs_sprp_ioctl(void __user *user_area)
71 struct hypfs_diag304 *diag304;
72 unsigned long cmd;
73 void __user *udata;
74 void *data;
75 int rc;
77 rc = -ENOMEM;
78 data = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
79 diag304 = kzalloc(sizeof(*diag304), GFP_KERNEL);
80 if (!data || !diag304)
81 goto out;
83 rc = -EFAULT;
84 if (copy_from_user(diag304, user_area, sizeof(*diag304)))
85 goto out;
86 rc = -EINVAL;
87 if ((diag304->args[0] >> 8) != 0 || diag304->args[1] > DIAG304_CMD_MAX)
88 goto out;
90 rc = -EFAULT;
91 udata = (void __user *)(unsigned long) diag304->data;
92 if (diag304->args[1] == DIAG304_SET_WEIGHTS ||
93 diag304->args[1] == DIAG304_SET_CAPPING)
94 if (copy_from_user(data, udata, PAGE_SIZE))
95 goto out;
97 cmd = *(unsigned long *) &diag304->args[0];
98 diag304->rc = hypfs_sprp_diag304(data, cmd);
100 if (diag304->args[1] == DIAG304_QUERY_PRP)
101 if (copy_to_user(udata, data, PAGE_SIZE)) {
102 rc = -EFAULT;
103 goto out;
106 rc = copy_to_user(user_area, diag304, sizeof(*diag304)) ? -EFAULT : 0;
107 out:
108 kfree(diag304);
109 free_page((unsigned long) data);
110 return rc;
113 static long hypfs_sprp_ioctl(struct file *file, unsigned int cmd,
114 unsigned long arg)
116 void __user *argp;
118 if (!capable(CAP_SYS_ADMIN))
119 return -EACCES;
120 if (is_compat_task())
121 argp = compat_ptr(arg);
122 else
123 argp = (void __user *) arg;
124 switch (cmd) {
125 case HYPFS_DIAG304:
126 return __hypfs_sprp_ioctl(argp);
127 default: /* unknown ioctl number */
128 return -ENOTTY;
130 return 0;
133 static struct hypfs_dbfs_file hypfs_sprp_file = {
134 .name = "diag_304",
135 .data_create = hypfs_sprp_create,
136 .data_free = hypfs_sprp_free,
137 .unlocked_ioctl = hypfs_sprp_ioctl,
140 void hypfs_sprp_init(void)
142 if (!sclp.has_sprp)
143 return;
144 hypfs_dbfs_create_file(&hypfs_sprp_file);
147 void hypfs_sprp_exit(void)
149 if (!sclp.has_sprp)
150 return;
151 hypfs_dbfs_remove_file(&hypfs_sprp_file);