Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / powerpc / lib / inst.c
blob9cc17eb62462a64efcb4f9f26f91765a832467f0
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright 2020, IBM Corporation.
4 */
6 #include <linux/uaccess.h>
7 #include <asm/disassemble.h>
8 #include <asm/inst.h>
9 #include <asm/ppc-opcode.h>
11 #ifdef CONFIG_PPC64
12 int probe_user_read_inst(struct ppc_inst *inst,
13 struct ppc_inst __user *nip)
15 unsigned int val, suffix;
16 int err;
18 err = copy_from_user_nofault(&val, nip, sizeof(val));
19 if (err)
20 return err;
21 if (get_op(val) == OP_PREFIX) {
22 err = copy_from_user_nofault(&suffix, (void __user *)nip + 4, 4);
23 *inst = ppc_inst_prefix(val, suffix);
24 } else {
25 *inst = ppc_inst(val);
27 return err;
30 int probe_kernel_read_inst(struct ppc_inst *inst,
31 struct ppc_inst *src)
33 unsigned int val, suffix;
34 int err;
36 err = copy_from_kernel_nofault(&val, src, sizeof(val));
37 if (err)
38 return err;
39 if (get_op(val) == OP_PREFIX) {
40 err = copy_from_kernel_nofault(&suffix, (void *)src + 4, 4);
41 *inst = ppc_inst_prefix(val, suffix);
42 } else {
43 *inst = ppc_inst(val);
45 return err;
47 #else /* !CONFIG_PPC64 */
48 int probe_user_read_inst(struct ppc_inst *inst,
49 struct ppc_inst __user *nip)
51 unsigned int val;
52 int err;
54 err = copy_from_user_nofault(&val, nip, sizeof(val));
55 if (!err)
56 *inst = ppc_inst(val);
58 return err;
61 int probe_kernel_read_inst(struct ppc_inst *inst,
62 struct ppc_inst *src)
64 unsigned int val;
65 int err;
67 err = copy_from_kernel_nofault(&val, src, sizeof(val));
68 if (!err)
69 *inst = ppc_inst(val);
71 return err;
73 #endif /* CONFIG_PPC64 */