Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *    Hypervisor filesystem for Linux on s390.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *    Set Partition-Resource Parameter interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *    Copyright IBM Corp. 2013
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *    Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/sclp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "hypfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define DIAG304_SET_WEIGHTS	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define DIAG304_QUERY_PRP	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DIAG304_SET_CAPPING	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define DIAG304_CMD_MAX		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static inline unsigned long __hypfs_sprp_diag304(void *data, unsigned long cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	register unsigned long _data asm("2") = (unsigned long) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	register unsigned long _rc asm("3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	register unsigned long _cmd asm("4") = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	asm volatile("diag %1,%2,0x304\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		     : "=d" (_rc) : "d" (_data), "d" (_cmd) : "memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return _rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static unsigned long hypfs_sprp_diag304(void *data, unsigned long cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	diag_stat_inc(DIAG_STAT_X304);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return __hypfs_sprp_diag304(data, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static void hypfs_sprp_free(const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	free_page((unsigned long) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static int hypfs_sprp_create(void **data_ptr, void **free_ptr, size_t *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	unsigned long rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	data = (void *) get_zeroed_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	rc = hypfs_sprp_diag304(data, DIAG304_QUERY_PRP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (rc != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		*data_ptr = *free_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		*size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		free_page((unsigned long) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	*data_ptr = *free_ptr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	*size = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static int __hypfs_sprp_ioctl(void __user *user_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct hypfs_diag304 *diag304;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	unsigned long cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	void __user *udata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	data = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	diag304 = kzalloc(sizeof(*diag304), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (!data || !diag304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (copy_from_user(diag304, user_area, sizeof(*diag304)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if ((diag304->args[0] >> 8) != 0 || diag304->args[1] > DIAG304_CMD_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	udata = (void __user *)(unsigned long) diag304->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (diag304->args[1] == DIAG304_SET_WEIGHTS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	    diag304->args[1] == DIAG304_SET_CAPPING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (copy_from_user(data, udata, PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	cmd = *(unsigned long *) &diag304->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	diag304->rc = hypfs_sprp_diag304(data, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (diag304->args[1] == DIAG304_QUERY_PRP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (copy_to_user(udata, data, PAGE_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	rc = copy_to_user(user_area, diag304, sizeof(*diag304)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	kfree(diag304);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	free_page((unsigned long) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static long hypfs_sprp_ioctl(struct file *file, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			       unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	void __user *argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (is_compat_task())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		argp = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		argp = (void __user *) arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	case HYPFS_DIAG304:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return __hypfs_sprp_ioctl(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	default: /* unknown ioctl number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static struct hypfs_dbfs_file hypfs_sprp_file = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	.name		= "diag_304",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	.data_create	= hypfs_sprp_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	.data_free	= hypfs_sprp_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	.unlocked_ioctl = hypfs_sprp_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) void hypfs_sprp_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (!sclp.has_sprp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	hypfs_dbfs_create_file(&hypfs_sprp_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) void hypfs_sprp_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (!sclp.has_sprp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	hypfs_dbfs_remove_file(&hypfs_sprp_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }