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)  *  linux/arch/h8300/kernel/process.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Yoshinori Sato <ysato@users.sourceforge.jp>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Based on:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  linux/arch/m68knommu/kernel/process.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  Copyright (C) 1998  D. Jeff Dionne <jeff@ryeham.ee.ryerson.ca>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *                      Kenneth Albanowski <kjahds@kjahds.com>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *                      The Silver Hammer Group, Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *  linux/arch/m68k/kernel/process.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  Copyright (C) 1995  Hamish Macdonald
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *  68060 fixes by Jesper Skov
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * This file handles the architecture-dependent parts of process handling..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <asm/traps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) void (*pm_power_off)(void) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) EXPORT_SYMBOL(pm_power_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) asmlinkage void ret_from_fork(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) asmlinkage void ret_from_kernel_thread(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * The idle loop on an H8/300..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) void arch_cpu_idle(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	raw_local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	__asm__("sleep");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) void machine_restart(char *__unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	__asm__("jmp @@0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) void machine_halt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	__asm__("sleep");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	for (;;)
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) void machine_power_off(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	__asm__("sleep");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	for (;;)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) void show_regs(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	show_regs_print_info(KERN_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	pr_notice("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	pr_notice("PC: %08lx  Status: %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	       regs->pc, regs->ccr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	pr_notice("ORIG_ER0: %08lx ER0: %08lx ER1: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	       regs->orig_er0, regs->er0, regs->er1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	pr_notice("ER2: %08lx ER3: %08lx ER4: %08lx ER5: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	       regs->er2, regs->er3, regs->er4, regs->er5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	pr_notice("ER6' %08lx ", regs->er6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (user_mode(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		printk("USP: %08lx\n", rdusp());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		printk("\n");
^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) void flush_thread(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int copy_thread(unsigned long clone_flags, unsigned long usp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		unsigned long topstk, struct task_struct *p, unsigned long tls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct pt_regs *childregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (unlikely(p->flags & PF_KTHREAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		memset(childregs, 0, sizeof(struct pt_regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		childregs->retpc = (unsigned long) ret_from_kernel_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		childregs->er4 = topstk; /* arg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		childregs->er5 = usp; /* fn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}  else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		*childregs = *current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		childregs->er0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		childregs->retpc = (unsigned long) ret_from_fork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		p->thread.usp = usp ?: rdusp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	p->thread.ksp = (unsigned long)childregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned long get_wchan(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	unsigned long fp, pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	unsigned long stack_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (!p || p == current || p->state == TASK_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	stack_page = (unsigned long)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	fp = ((struct pt_regs *)p->thread.ksp)->er6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		if (fp < stack_page+sizeof(struct thread_info) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		    fp >= 8184+stack_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		pc = ((unsigned long *)fp)[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (!in_sched_functions(pc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			return pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		fp = *(unsigned long *) fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	} while (count++ < 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* generic sys_clone is not enough registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) asmlinkage int sys_clone(unsigned long __user *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	unsigned long clone_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	unsigned long  newsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	uintptr_t parent_tidptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	uintptr_t child_tidptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct kernel_clone_args kargs = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	get_user(clone_flags, &args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	get_user(newsp, &args[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	get_user(parent_tidptr, &args[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	get_user(child_tidptr, &args[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	kargs.flags		= (lower_32_bits(clone_flags) & ~CSIGNAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	kargs.pidfd		= (int __user *)parent_tidptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	kargs.child_tid		= (int __user *)child_tidptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	kargs.parent_tid	= (int __user *)parent_tidptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	kargs.exit_signal	= (lower_32_bits(clone_flags) & CSIGNAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	kargs.stack		= newsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return kernel_clone(&kargs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }