Re: [PATCH v6 12/36] nds32: Process management

2018-01-18 Thread Arnd Bergmann
On Mon, Jan 15, 2018 at 6:53 AM, Greentime Hu  wrote:

> +void machine_restart(char *__unused)
> +{
> +   /*
> +* Clean and disable cache, and turn off interrupts
> +*/
> +   cpu_proc_fin();
> +
> +   /*
> +* Tell the mm system that we are going to reboot -
> +* we may need it to insert some 1:1 mappings so that
> +* soft boot works.
> +*/
> +   setup_mm_for_reboot(reboot_mode);
> +
> +   /*
> +* Now call the architecture specific reboot code.
> +*/
> +   arch_reset(reboot_mode);
> +
> +   /*
> +* Whoops - the architecture was unable to reboot.
> +* Tell the user!
> +*/
> +   mdelay(1000);
> +   pr_info("Reboot failed -- System halted\n");
> +   while (1) ;
> +}

You should insert a call to do_kernel_restart() in this function to allow e.g. a
watchdog driver to provide a machine-specific reboot method. Otherwise
the patch looks good to me,

Acked-by: Arnd Bergmann 


[PATCH v6 12/36] nds32: Process management

2018-01-14 Thread Greentime Hu
From: Greentime Hu 

This patch includes copy_thread(), start_thread() implementation and cpu_context
structure definition. nds32 uses $r25 to get current task_struct.

Signed-off-by: Vincent Chen 
Signed-off-by: Greentime Hu 
---
 arch/nds32/include/asm/current.h |   12 ++
 arch/nds32/include/asm/processor.h   |  102 +
 arch/nds32/include/asm/thread_info.h |   78 +
 arch/nds32/kernel/process.c  |  204 ++
 4 files changed, 396 insertions(+)
 create mode 100644 arch/nds32/include/asm/current.h
 create mode 100644 arch/nds32/include/asm/processor.h
 create mode 100644 arch/nds32/include/asm/thread_info.h
 create mode 100644 arch/nds32/kernel/process.c

diff --git a/arch/nds32/include/asm/current.h b/arch/nds32/include/asm/current.h
new file mode 100644
index 000..b4dcd22
--- /dev/null
+++ b/arch/nds32/include/asm/current.h
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef _ASM_NDS32_CURRENT_H
+#define _ASM_NDS32_CURRENT_H
+
+#ifndef __ASSEMBLY__
+register struct task_struct *current asm("$r25");
+#endif /* __ASSEMBLY__ */
+#define tsk $r25
+
+#endif /* _ASM_NDS32_CURRENT_H */
diff --git a/arch/nds32/include/asm/processor.h 
b/arch/nds32/include/asm/processor.h
new file mode 100644
index 000..cad9b8c
--- /dev/null
+++ b/arch/nds32/include/asm/processor.h
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_PROCESSOR_H
+#define __ASM_NDS32_PROCESSOR_H
+
+/*
+ * Default implementation of macro that returns current
+ * instruction pointer ("program counter").
+ */
+#define current_text_addr() ({ __label__ _l; _l: &&_l;})
+
+#ifdef __KERNEL__
+
+#include 
+#include 
+#include 
+
+#define KERNEL_STACK_SIZE  PAGE_SIZE
+#define STACK_TOP  TASK_SIZE
+#define STACK_TOP_MAX   TASK_SIZE
+
+struct cpu_context {
+   unsigned long r6;
+   unsigned long r7;
+   unsigned long r8;
+   unsigned long r9;
+   unsigned long r10;
+   unsigned long r11;
+   unsigned long r12;
+   unsigned long r13;
+   unsigned long r14;
+   unsigned long fp;
+   unsigned long pc;
+   unsigned long sp;
+};
+
+struct thread_struct {
+   struct cpu_context cpu_context; /* cpu context */
+   /* fault info */
+   unsigned long address;
+   unsigned long trap_no;
+   unsigned long error_code;
+};
+
+#define INIT_THREAD  { }
+
+#ifdef __NDS32_EB__
+#define PSW_DE PSW_mskBE
+#else
+#define PSW_DE 0x0
+#endif
+
+#ifdef CONFIG_WBNA
+#define PSW_valWBNAPSW_mskWBNA
+#else
+#define PSW_valWBNA0x0
+#endif
+
+#ifdef CONFIG_HWZOL
+#definePSW_valINIT (PSW_CPL_ANY | PSW_mskAEN | PSW_valWBNA | PSW_mskDT 
| PSW_mskIT | PSW_DE | PSW_mskGIE)
+#else
+#definePSW_valINIT (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT 
| PSW_DE | PSW_mskGIE)
+#endif
+
+#define start_thread(regs,pc,stack)\
+({ \
+   memzero(regs, sizeof(struct pt_regs));  \
+   regs->ipsw = PSW_valINIT;   \
+   regs->ir0 = (PSW_CPL_ANY | PSW_valWBNA | PSW_mskDT | PSW_mskIT | PSW_DE 
| PSW_SYSTEM | PSW_INTL_1); \
+   regs->ipc = pc; \
+   regs->sp = stack;   \
+})
+
+/* Forward declaration, a strange C thing */
+struct task_struct;
+
+/* Free all resources held by a thread. */
+#define release_thread(thread) do { } while(0)
+
+/* Prepare to copy thread state - unlazy all lazy status */
+#define prepare_to_copy(tsk)   do { } while (0)
+
+unsigned long get_wchan(struct task_struct *p);
+
+#define cpu_relax()barrier()
+
+#define task_pt_regs(task) \
+   ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \
+   - 8) - 1)
+
+/*
+ * Create a new kernel thread
+ */
+extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);
+
+#define KSTK_EIP(tsk)  instruction_pointer(task_pt_regs(tsk))
+#define KSTK_ESP(tsk)  user_stack_pointer(task_pt_regs(tsk))
+
+#endif
+
+#endif /* __ASM_NDS32_PROCESSOR_H */
diff --git a/arch/nds32/include/asm/thread_info.h 
b/arch/nds32/include/asm/thread_info.h
new file mode 100644
index 000..818e769
--- /dev/null
+++ b/arch/nds32/include/asm/thread_info.h
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2005-2017 Andes Technology Corporation
+
+#ifndef __ASM_NDS32_THREAD_INFO_H
+#define __ASM_NDS32_THREAD_INFO_H
+
+#ifdef __KERNEL__
+
+#define THREAD_SIZE_ORDER  (1)
+#define THREAD_SIZE(PAGE_SIZE << THREAD_SIZE_ORDER)
+
+#ifndef __ASSEMBLY__
+
+struct task_struct;
+
+#include 
+#include 
+
+typedef unsigned long mm_segment_t;
+
+/*
+ * low level task data that entry.S needs immediate access to.
+ *