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) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <xen/interface/platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <asm/xen/hypercall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <xen/xen-ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "xenfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define XEN_KSYM_NAME_LEN 127 /* Hypervisor may have different name length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) struct xensyms {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct xen_platform_op op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	uint32_t namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /* Grab next output page from the hypervisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static int xensyms_next_sym(struct xensyms *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct xenpf_symdata *symdata = &xs->op.u.symdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	uint64_t symnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	memset(xs->name, 0, xs->namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	symdata->namelen = xs->namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	symnum = symdata->symnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	ret = HYPERVISOR_platform_op(&xs->op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	 * If hypervisor's symbol didn't fit into the buffer then allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	 * a larger buffer and try again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (unlikely(symdata->namelen > xs->namelen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		kfree(xs->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		xs->namelen = symdata->namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		xs->name = kzalloc(xs->namelen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		if (!xs->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		set_xen_guest_handle(symdata->name, xs->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		symdata->symnum--; /* Rewind */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		ret = HYPERVISOR_platform_op(&xs->op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (symdata->symnum == symnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		/* End of symbols */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static void *xensyms_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct xensyms *xs = (struct xensyms *)m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	xs->op.u.symdata.symnum = *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (xensyms_next_sym(xs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static void *xensyms_next(struct seq_file *m, void *p, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct xensyms *xs = (struct xensyms *)m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	xs->op.u.symdata.symnum = ++(*pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (xensyms_next_sym(xs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int xensyms_show(struct seq_file *m, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct xensyms *xs = (struct xensyms *)m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct xenpf_symdata *symdata = &xs->op.u.symdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	seq_printf(m, "%016llx %c %s\n", symdata->address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		   symdata->type, xs->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static void xensyms_stop(struct seq_file *m, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static const struct seq_operations xensyms_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.start = xensyms_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.next = xensyms_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	.show = xensyms_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	.stop = xensyms_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int xensyms_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct seq_file *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct xensyms *xs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	ret = seq_open_private(file, &xensyms_seq_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			       sizeof(struct xensyms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	m = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	xs = (struct xensyms *)m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	xs->namelen = XEN_KSYM_NAME_LEN + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	xs->name = kzalloc(xs->namelen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (!xs->name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		seq_release_private(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	set_xen_guest_handle(xs->op.u.symdata.name, xs->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	xs->op.cmd = XENPF_get_symbol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	xs->op.u.symdata.namelen = xs->namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int xensyms_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct seq_file *m = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct xensyms *xs = (struct xensyms *)m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	kfree(xs->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return seq_release_private(inode, 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) const struct file_operations xensyms_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	.open = xensyms_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	.release = xensyms_release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) };