Skip to content

Commit fbb82b0

Browse files
committed
sh: machine_ops based reboot support.
This provides a machine_ops-based reboot interface loosely cloned from x86, and converts the native sh32 and sh64 cases over to it. Necessary both for tying in SMP support and also enabling platforms like SDK7786 to add support for their microcontroller-based power managers. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 2efa53b commit fbb82b0

11 files changed

Lines changed: 156 additions & 90 deletions

File tree

‎arch/sh/include/asm/reboot.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __ASM_SH_REBOOT_H
2+
#define __ASM_SH_REBOOT_H
3+
4+
#include <linux/kdebug.h>
5+
6+
struct pt_regs;
7+
8+
struct machine_ops {
9+
void (*restart)(char *cmd);
10+
void (*halt)(void);
11+
void (*power_off)(void);
12+
void (*shutdown)(void);
13+
void (*crash_shutdown)(struct pt_regs *);
14+
};
15+
16+
extern struct machine_ops machine_ops;
17+
18+
/* arch/sh/kernel/machine_kexec.c */
19+
void native_machine_crash_shutdown(struct pt_regs *regs);
20+
21+
#endif /* __ASM_SH_REBOOT_H */

‎arch/sh/include/asm/system.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ extern struct dentry *sh_debugfs_root;
143143
void per_cpu_trap_init(void);
144144
void default_idle(void);
145145
void cpu_idle_wait(void);
146+
void stop_this_cpu(void *);
146147

147148
#ifdef CONFIG_SUPERH32
148149
#define BUILD_TRAP_HANDLER(name) \

‎arch/sh/include/asm/system_32.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __ASM_SH_SYSTEM_32_H
33

44
#include <linux/types.h>
5+
#include <asm/mmu.h>
56

67
#ifdef CONFIG_SH_DSP
78

@@ -216,6 +217,17 @@ static inline reg_size_t register_align(void *val)
216217
int handle_unaligned_access(insn_size_t instruction, struct pt_regs *regs,
217218
struct mem_access *ma, int);
218219

220+
static inline void trigger_address_error(void)
221+
{
222+
if (__in_29bit_mode())
223+
__asm__ __volatile__ (
224+
"ldc %0, sr\n\t"
225+
"mov.l @%1, %0"
226+
:
227+
: "r" (0x10000000), "r" (0x80000001)
228+
);
229+
}
230+
219231
asmlinkage void do_address_error(struct pt_regs *regs,
220232
unsigned long writeaccess,
221233
unsigned long address);

‎arch/sh/include/asm/system_64.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ static inline reg_size_t register_align(void *val)
4848
return (unsigned long long)(signed long long)(signed long)val;
4949
}
5050

51+
extern void phys_stext(void);
52+
53+
static inline void trigger_address_error(void)
54+
{
55+
phys_stext();
56+
}
57+
5158
#define SR_BL_LL 0x0000000010000000LL
5259

5360
static inline void set_bl_bit(void)

‎arch/sh/kernel/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ CFLAGS_REMOVE_return_address.o = -pg
1414
obj-y := debugtraps.o dma-nommu.o dumpstack.o \
1515
idle.o io.o io_generic.o irq.o \
1616
irq_$(BITS).o machvec.o nmi_debug.o process.o \
17-
process_$(BITS).o ptrace_$(BITS).o return_address.o \
17+
process_$(BITS).o ptrace_$(BITS).o \
18+
reboot.o return_address.o \
1819
setup.o signal_$(BITS).o sys_sh.o sys_sh$(BITS).o \
1920
syscalls_$(BITS).o time.o topology.o traps.o \
2021
traps_$(BITS).o unwinder.o

‎arch/sh/kernel/idle.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
#include <asm/system.h>
2121
#include <asm/atomic.h>
2222

23-
static int hlt_counter;
2423
void (*pm_idle)(void) = NULL;
25-
void (*pm_power_off)(void);
26-
EXPORT_SYMBOL(pm_power_off);
24+
25+
static int hlt_counter;
2726

2827
static int __init nohlt_setup(char *__unused)
2928
{
@@ -131,6 +130,15 @@ static void do_nothing(void *unused)
131130
{
132131
}
133132

133+
void stop_this_cpu(void *unused)
134+
{
135+
local_irq_disable();
136+
cpu_clear(smp_processor_id(), cpu_online_map);
137+
138+
for (;;)
139+
cpu_sleep();
140+
}
141+
134142
/*
135143
* cpu_idle_wait - Used to ensure that all the CPUs discard old value of
136144
* pm_idle and update to new pm_idle value. Required while changing pm_idle

‎arch/sh/kernel/machine_kexec.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <asm/io.h>
2323
#include <asm/cacheflush.h>
2424
#include <asm/sh_bios.h>
25+
#include <asm/reboot.h>
2526

2627
typedef void (*relocate_new_kernel_t)(unsigned long indirection_page,
2728
unsigned long reboot_code_buffer,
@@ -31,12 +32,9 @@ extern const unsigned char relocate_new_kernel[];
3132
extern const unsigned int relocate_new_kernel_size;
3233
extern void *vbr_base;
3334

34-
void machine_shutdown(void)
35-
{
36-
}
37-
38-
void machine_crash_shutdown(struct pt_regs *regs)
35+
void native_machine_crash_shutdown(struct pt_regs *regs)
3936
{
37+
/* Nothing to do for UP, but definitely broken for SMP.. */
4038
}
4139

4240
/*

‎arch/sh/kernel/process_32.c‎

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,15 @@
1616
#include <linux/module.h>
1717
#include <linux/mm.h>
1818
#include <linux/elfcore.h>
19-
#include <linux/pm.h>
2019
#include <linux/kallsyms.h>
21-
#include <linux/kexec.h>
22-
#include <linux/kdebug.h>
23-
#include <linux/tick.h>
24-
#include <linux/reboot.h>
2520
#include <linux/fs.h>
2621
#include <linux/ftrace.h>
27-
#include <linux/preempt.h>
2822
#include <linux/hw_breakpoint.h>
2923
#include <asm/uaccess.h>
3024
#include <asm/mmu_context.h>
31-
#include <asm/pgalloc.h>
3225
#include <asm/system.h>
3326
#include <asm/fpu.h>
3427
#include <asm/syscalls.h>
35-
#include <asm/watchdog.h>
36-
37-
#ifdef CONFIG_32BIT
38-
static void watchdog_trigger_immediate(void)
39-
{
40-
sh_wdt_write_cnt(0xFF);
41-
sh_wdt_write_csr(0xC2);
42-
}
43-
44-
void machine_restart(char * __unused)
45-
{
46-
local_irq_disable();
47-
48-
/* Use watchdog timer to trigger reset */
49-
watchdog_trigger_immediate();
50-
51-
while (1)
52-
cpu_sleep();
53-
}
54-
#else
55-
void machine_restart(char * __unused)
56-
{
57-
/* SR.BL=1 and invoke address error to let CPU reset (manual reset) */
58-
asm volatile("ldc %0, sr\n\t"
59-
"mov.l @%1, %0" : : "r" (0x10000000), "r" (0x80000001));
60-
}
61-
#endif
62-
63-
void machine_halt(void)
64-
{
65-
local_irq_disable();
66-
67-
while (1)
68-
cpu_sleep();
69-
}
70-
71-
void machine_power_off(void)
72-
{
73-
if (pm_power_off)
74-
pm_power_off();
75-
}
7628

7729
void show_regs(struct pt_regs * regs)
7830
{

‎arch/sh/kernel/process_64.c‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,7 @@
3232

3333
struct task_struct *last_task_used_math = NULL;
3434

35-
void machine_restart(char * __unused)
36-
{
37-
extern void phys_stext(void);
38-
39-
phys_stext();
40-
}
41-
42-
void machine_halt(void)
43-
{
44-
for (;;);
45-
}
46-
47-
void machine_power_off(void)
48-
{
49-
__asm__ __volatile__ (
50-
"sleep\n\t"
51-
"synci\n\t"
52-
"nop;nop;nop;nop\n\t"
53-
);
54-
55-
panic("Unexpected wakeup!\n");
56-
}
57-
58-
void show_regs(struct pt_regs * regs)
35+
void show_regs(struct pt_regs *regs)
5936
{
6037
unsigned long long ah, al, bh, bl, ch, cl;
6138

‎arch/sh/kernel/reboot.c‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#include <linux/pm.h>
2+
#include <linux/kexec.h>
3+
#include <linux/kernel.h>
4+
#include <linux/reboot.h>
5+
#include <linux/module.h>
6+
#ifdef CONFIG_SUPERH32
7+
#include <asm/watchdog.h>
8+
#endif
9+
#include <asm/addrspace.h>
10+
#include <asm/reboot.h>
11+
#include <asm/system.h>
12+
13+
void (*pm_power_off)(void);
14+
EXPORT_SYMBOL(pm_power_off);
15+
16+
#ifdef CONFIG_SUPERH32
17+
static void watchdog_trigger_immediate(void)
18+
{
19+
sh_wdt_write_cnt(0xFF);
20+
sh_wdt_write_csr(0xC2);
21+
}
22+
#endif
23+
24+
static void native_machine_restart(char * __unused)
25+
{
26+
local_irq_disable();
27+
28+
/* Address error with SR.BL=1 first. */
29+
trigger_address_error();
30+
31+
#ifdef CONFIG_SUPERH32
32+
/* If that fails or is unsupported, go for the watchdog next. */
33+
watchdog_trigger_immediate();
34+
#endif
35+
36+
/*
37+
* Give up and sleep.
38+
*/
39+
while (1)
40+
cpu_sleep();
41+
}
42+
43+
static void native_machine_shutdown(void)
44+
{
45+
smp_send_stop();
46+
}
47+
48+
static void native_machine_power_off(void)
49+
{
50+
if (pm_power_off)
51+
pm_power_off();
52+
}
53+
54+
static void native_machine_halt(void)
55+
{
56+
/* stop other cpus */
57+
machine_shutdown();
58+
59+
/* stop this cpu */
60+
stop_this_cpu(NULL);
61+
}
62+
63+
struct machine_ops machine_ops = {
64+
.power_off = native_machine_power_off,
65+
.shutdown = native_machine_shutdown,
66+
.restart = native_machine_restart,
67+
.halt = native_machine_halt,
68+
#ifdef CONFIG_KEXEC
69+
.crash_shutdown = native_machine_crash_shutdown,
70+
#endif
71+
};
72+
73+
void machine_power_off(void)
74+
{
75+
machine_ops.power_off();
76+
}
77+
78+
void machine_shutdown(void)
79+
{
80+
machine_ops.shutdown();
81+
}
82+
83+
void machine_restart(char *cmd)
84+
{
85+
machine_ops.restart(cmd);
86+
}
87+
88+
void machine_halt(void)
89+
{
90+
machine_ops.halt();
91+
}
92+
93+
#ifdef CONFIG_KEXEC
94+
void machine_crash_shutdown(struct pt_regs *regs)
95+
{
96+
machine_ops.crash_shutdown(regs);
97+
}
98+
#endif

0 commit comments

Comments
 (0)