mirror of
https://github.com/torvalds/linux.git
synced 2024-10-31 17:21:49 +00:00
a43cb95d54
show_regs() is inherently arch-dependent but it does make sense to print generic debug information and some archs already do albeit in slightly different forms. This patch introduces a generic function to print debug information from show_regs() so that different archs print out the same information and it's much easier to modify what's printed. show_regs_print_info() prints out the same debug info as dump_stack() does plus task and thread_info pointers. * Archs which didn't print debug info now do. alpha, arc, blackfin, c6x, cris, frv, h8300, hexagon, ia64, m32r, metag, microblaze, mn10300, openrisc, parisc, score, sh64, sparc, um, xtensa * Already prints debug info. Replaced with show_regs_print_info(). The printed information is superset of what used to be there. arm, arm64, avr32, mips, powerpc, sh32, tile, unicore32, x86 * s390 is special in that it used to print arch-specific information along with generic debug info. Heiko and Martin think that the arch-specific extra isn't worth keeping s390 specfic implementation. Converted to use the generic version. Note that now all archs print the debug info before actual register dumps. An example BUG() dump follows. kernel BUG at /work/os/work/kernel/workqueue.c:4841! invalid opcode: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.9.0-rc1-work+ #7 Hardware name: empty empty/S3992, BIOS 080011 10/26/2007 task: ffff88007c85e040 ti: ffff88007c860000 task.ti: ffff88007c860000 RIP: 0010:[<ffffffff8234a07e>] [<ffffffff8234a07e>] init_workqueues+0x4/0x6 RSP: 0000:ffff88007c861ec8 EFLAGS: 00010246 RAX: ffff88007c861fd8 RBX: ffffffff824466a8 RCX: 0000000000000001 RDX: 0000000000000046 RSI: 0000000000000001 RDI: ffffffff8234a07a RBP: ffff88007c861ec8 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000001 R11: 0000000000000000 R12: ffffffff8234a07a R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff88007dc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: ffff88015f7ff000 CR3: 00000000021f1000 CR4: 00000000000007f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Stack: ffff88007c861ef8 ffffffff81000312 ffffffff824466a8 ffff88007c85e650 0000000000000003 0000000000000000 ffff88007c861f38 ffffffff82335e5d ffff88007c862080 ffffffff8223d8c0 ffff88007c862080 ffffffff81c47760 Call Trace: [<ffffffff81000312>] do_one_initcall+0x122/0x170 [<ffffffff82335e5d>] kernel_init_freeable+0x9b/0x1c8 [<ffffffff81c47760>] ? rest_init+0x140/0x140 [<ffffffff81c4776e>] kernel_init+0xe/0xf0 [<ffffffff81c6be9c>] ret_from_fork+0x7c/0xb0 [<ffffffff81c47760>] ? rest_init+0x140/0x140 ... v2: Typo fix in x86-32. v3: CPU number dropped from show_regs_print_info() as dump_stack_print_info() has been updated to print it. s390 specific implementation dropped as requested by s390 maintainers. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: David S. Miller <davem@davemloft.net> Acked-by: Jesper Nilsson <jesper.nilsson@axis.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Fengguang Wu <fengguang.wu@intel.com> Cc: Mike Frysinger <vapier@gentoo.org> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Sam Ravnborg <sam@ravnborg.org> Acked-by: Chris Metcalf <cmetcalf@tilera.com> [tile bits] Acked-by: Richard Kuo <rkuo@codeaurora.org> [hexagon bits] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
599 lines
18 KiB
C
599 lines
18 KiB
C
/*
|
|
* Copyright 2010 Tilera Corporation. All Rights Reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation, version 2.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
* NON INFRINGEMENT. See the GNU General Public License for
|
|
* more details.
|
|
*/
|
|
|
|
#include <linux/sched.h>
|
|
#include <linux/preempt.h>
|
|
#include <linux/module.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/kprobes.h>
|
|
#include <linux/elfcore.h>
|
|
#include <linux/tick.h>
|
|
#include <linux/init.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/hardirq.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/tracehook.h>
|
|
#include <linux/signal.h>
|
|
#include <asm/stack.h>
|
|
#include <asm/switch_to.h>
|
|
#include <asm/homecache.h>
|
|
#include <asm/syscalls.h>
|
|
#include <asm/traps.h>
|
|
#include <asm/setup.h>
|
|
#ifdef CONFIG_HARDWALL
|
|
#include <asm/hardwall.h>
|
|
#endif
|
|
#include <arch/chip.h>
|
|
#include <arch/abi.h>
|
|
#include <arch/sim_def.h>
|
|
|
|
/*
|
|
* Use the (x86) "idle=poll" option to prefer low latency when leaving the
|
|
* idle loop over low power while in the idle loop, e.g. if we have
|
|
* one thread per core and we want to get threads out of futex waits fast.
|
|
*/
|
|
static int __init idle_setup(char *str)
|
|
{
|
|
if (!str)
|
|
return -EINVAL;
|
|
|
|
if (!strcmp(str, "poll")) {
|
|
pr_info("using polling idle threads.\n");
|
|
cpu_idle_poll_ctrl(true);
|
|
return 0;
|
|
} else if (!strcmp(str, "halt")) {
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
early_param("idle", idle_setup);
|
|
|
|
void arch_cpu_idle(void)
|
|
{
|
|
__get_cpu_var(irq_stat).idle_timestamp = jiffies;
|
|
_cpu_idle();
|
|
}
|
|
|
|
/*
|
|
* Release a thread_info structure
|
|
*/
|
|
void arch_release_thread_info(struct thread_info *info)
|
|
{
|
|
struct single_step_state *step_state = info->step_state;
|
|
|
|
#ifdef CONFIG_HARDWALL
|
|
/*
|
|
* We free a thread_info from the context of the task that has
|
|
* been scheduled next, so the original task is already dead.
|
|
* Calling deactivate here just frees up the data structures.
|
|
* If the task we're freeing held the last reference to a
|
|
* hardwall fd, it would have been released prior to this point
|
|
* anyway via exit_files(), and the hardwall_task.info pointers
|
|
* would be NULL by now.
|
|
*/
|
|
hardwall_deactivate_all(info->task);
|
|
#endif
|
|
|
|
if (step_state) {
|
|
|
|
/*
|
|
* FIXME: we don't munmap step_state->buffer
|
|
* because the mm_struct for this process (info->task->mm)
|
|
* has already been zeroed in exit_mm(). Keeping a
|
|
* reference to it here seems like a bad move, so this
|
|
* means we can't munmap() the buffer, and therefore if we
|
|
* ptrace multiple threads in a process, we will slowly
|
|
* leak user memory. (Note that as soon as the last
|
|
* thread in a process dies, we will reclaim all user
|
|
* memory including single-step buffers in the usual way.)
|
|
* We should either assign a kernel VA to this buffer
|
|
* somehow, or we should associate the buffer(s) with the
|
|
* mm itself so we can clean them up that way.
|
|
*/
|
|
kfree(step_state);
|
|
}
|
|
}
|
|
|
|
static void save_arch_state(struct thread_struct *t);
|
|
|
|
int copy_thread(unsigned long clone_flags, unsigned long sp,
|
|
unsigned long arg, struct task_struct *p)
|
|
{
|
|
struct pt_regs *childregs = task_pt_regs(p);
|
|
unsigned long ksp;
|
|
unsigned long *callee_regs;
|
|
|
|
/*
|
|
* Set up the stack and stack pointer appropriately for the
|
|
* new child to find itself woken up in __switch_to().
|
|
* The callee-saved registers must be on the stack to be read;
|
|
* the new task will then jump to assembly support to handle
|
|
* calling schedule_tail(), etc., and (for userspace tasks)
|
|
* returning to the context set up in the pt_regs.
|
|
*/
|
|
ksp = (unsigned long) childregs;
|
|
ksp -= C_ABI_SAVE_AREA_SIZE; /* interrupt-entry save area */
|
|
((long *)ksp)[0] = ((long *)ksp)[1] = 0;
|
|
ksp -= CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long);
|
|
callee_regs = (unsigned long *)ksp;
|
|
ksp -= C_ABI_SAVE_AREA_SIZE; /* __switch_to() save area */
|
|
((long *)ksp)[0] = ((long *)ksp)[1] = 0;
|
|
p->thread.ksp = ksp;
|
|
|
|
/* Record the pid of the task that created this one. */
|
|
p->thread.creator_pid = current->pid;
|
|
|
|
if (unlikely(p->flags & PF_KTHREAD)) {
|
|
/* kernel thread */
|
|
memset(childregs, 0, sizeof(struct pt_regs));
|
|
memset(&callee_regs[2], 0,
|
|
(CALLEE_SAVED_REGS_COUNT - 2) * sizeof(unsigned long));
|
|
callee_regs[0] = sp; /* r30 = function */
|
|
callee_regs[1] = arg; /* r31 = arg */
|
|
childregs->ex1 = PL_ICS_EX1(KERNEL_PL, 0);
|
|
p->thread.pc = (unsigned long) ret_from_kernel_thread;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Start new thread in ret_from_fork so it schedules properly
|
|
* and then return from interrupt like the parent.
|
|
*/
|
|
p->thread.pc = (unsigned long) ret_from_fork;
|
|
|
|
/*
|
|
* Do not clone step state from the parent; each thread
|
|
* must make its own lazily.
|
|
*/
|
|
task_thread_info(p)->step_state = NULL;
|
|
|
|
/*
|
|
* Copy the registers onto the kernel stack so the
|
|
* return-from-interrupt code will reload it into registers.
|
|
*/
|
|
*childregs = *current_pt_regs();
|
|
childregs->regs[0] = 0; /* return value is zero */
|
|
if (sp)
|
|
childregs->sp = sp; /* override with new user stack pointer */
|
|
memcpy(callee_regs, &childregs->regs[CALLEE_SAVED_FIRST_REG],
|
|
CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long));
|
|
|
|
/* Save user stack top pointer so we can ID the stack vm area later. */
|
|
p->thread.usp0 = childregs->sp;
|
|
|
|
/*
|
|
* If CLONE_SETTLS is set, set "tp" in the new task to "r4",
|
|
* which is passed in as arg #5 to sys_clone().
|
|
*/
|
|
if (clone_flags & CLONE_SETTLS)
|
|
childregs->tp = childregs->regs[4];
|
|
|
|
|
|
#if CHIP_HAS_TILE_DMA()
|
|
/*
|
|
* No DMA in the new thread. We model this on the fact that
|
|
* fork() clears the pending signals, alarms, and aio for the child.
|
|
*/
|
|
memset(&p->thread.tile_dma_state, 0, sizeof(struct tile_dma_state));
|
|
memset(&p->thread.dma_async_tlb, 0, sizeof(struct async_tlb));
|
|
#endif
|
|
|
|
#if CHIP_HAS_SN_PROC()
|
|
/* Likewise, the new thread is not running static processor code. */
|
|
p->thread.sn_proc_running = 0;
|
|
memset(&p->thread.sn_async_tlb, 0, sizeof(struct async_tlb));
|
|
#endif
|
|
|
|
#if CHIP_HAS_PROC_STATUS_SPR()
|
|
/* New thread has its miscellaneous processor state bits clear. */
|
|
p->thread.proc_status = 0;
|
|
#endif
|
|
|
|
#ifdef CONFIG_HARDWALL
|
|
/* New thread does not own any networks. */
|
|
memset(&p->thread.hardwall[0], 0,
|
|
sizeof(struct hardwall_task) * HARDWALL_TYPES);
|
|
#endif
|
|
|
|
|
|
/*
|
|
* Start the new thread with the current architecture state
|
|
* (user interrupt masks, etc.).
|
|
*/
|
|
save_arch_state(&p->thread);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Return "current" if it looks plausible, or else a pointer to a dummy.
|
|
* This can be helpful if we are just trying to emit a clean panic.
|
|
*/
|
|
struct task_struct *validate_current(void)
|
|
{
|
|
static struct task_struct corrupt = { .comm = "<corrupt>" };
|
|
struct task_struct *tsk = current;
|
|
if (unlikely((unsigned long)tsk < PAGE_OFFSET ||
|
|
(high_memory && (void *)tsk > high_memory) ||
|
|
((unsigned long)tsk & (__alignof__(*tsk) - 1)) != 0)) {
|
|
pr_err("Corrupt 'current' %p (sp %#lx)\n", tsk, stack_pointer);
|
|
tsk = &corrupt;
|
|
}
|
|
return tsk;
|
|
}
|
|
|
|
/* Take and return the pointer to the previous task, for schedule_tail(). */
|
|
struct task_struct *sim_notify_fork(struct task_struct *prev)
|
|
{
|
|
struct task_struct *tsk = current;
|
|
__insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_FORK_PARENT |
|
|
(tsk->thread.creator_pid << _SIM_CONTROL_OPERATOR_BITS));
|
|
__insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_FORK |
|
|
(tsk->pid << _SIM_CONTROL_OPERATOR_BITS));
|
|
return prev;
|
|
}
|
|
|
|
int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
|
|
{
|
|
struct pt_regs *ptregs = task_pt_regs(tsk);
|
|
elf_core_copy_regs(regs, ptregs);
|
|
return 1;
|
|
}
|
|
|
|
#if CHIP_HAS_TILE_DMA()
|
|
|
|
/* Allow user processes to access the DMA SPRs */
|
|
void grant_dma_mpls(void)
|
|
{
|
|
#if CONFIG_KERNEL_PL == 2
|
|
__insn_mtspr(SPR_MPL_DMA_CPL_SET_1, 1);
|
|
__insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_1, 1);
|
|
#else
|
|
__insn_mtspr(SPR_MPL_DMA_CPL_SET_0, 1);
|
|
__insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_0, 1);
|
|
#endif
|
|
}
|
|
|
|
/* Forbid user processes from accessing the DMA SPRs */
|
|
void restrict_dma_mpls(void)
|
|
{
|
|
#if CONFIG_KERNEL_PL == 2
|
|
__insn_mtspr(SPR_MPL_DMA_CPL_SET_2, 1);
|
|
__insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_2, 1);
|
|
#else
|
|
__insn_mtspr(SPR_MPL_DMA_CPL_SET_1, 1);
|
|
__insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_1, 1);
|
|
#endif
|
|
}
|
|
|
|
/* Pause the DMA engine, then save off its state registers. */
|
|
static void save_tile_dma_state(struct tile_dma_state *dma)
|
|
{
|
|
unsigned long state = __insn_mfspr(SPR_DMA_USER_STATUS);
|
|
unsigned long post_suspend_state;
|
|
|
|
/* If we're running, suspend the engine. */
|
|
if ((state & DMA_STATUS_MASK) == SPR_DMA_STATUS__RUNNING_MASK)
|
|
__insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__SUSPEND_MASK);
|
|
|
|
/*
|
|
* Wait for the engine to idle, then save regs. Note that we
|
|
* want to record the "running" bit from before suspension,
|
|
* and the "done" bit from after, so that we can properly
|
|
* distinguish a case where the user suspended the engine from
|
|
* the case where the kernel suspended as part of the context
|
|
* swap.
|
|
*/
|
|
do {
|
|
post_suspend_state = __insn_mfspr(SPR_DMA_USER_STATUS);
|
|
} while (post_suspend_state & SPR_DMA_STATUS__BUSY_MASK);
|
|
|
|
dma->src = __insn_mfspr(SPR_DMA_SRC_ADDR);
|
|
dma->src_chunk = __insn_mfspr(SPR_DMA_SRC_CHUNK_ADDR);
|
|
dma->dest = __insn_mfspr(SPR_DMA_DST_ADDR);
|
|
dma->dest_chunk = __insn_mfspr(SPR_DMA_DST_CHUNK_ADDR);
|
|
dma->strides = __insn_mfspr(SPR_DMA_STRIDE);
|
|
dma->chunk_size = __insn_mfspr(SPR_DMA_CHUNK_SIZE);
|
|
dma->byte = __insn_mfspr(SPR_DMA_BYTE);
|
|
dma->status = (state & SPR_DMA_STATUS__RUNNING_MASK) |
|
|
(post_suspend_state & SPR_DMA_STATUS__DONE_MASK);
|
|
}
|
|
|
|
/* Restart a DMA that was running before we were context-switched out. */
|
|
static void restore_tile_dma_state(struct thread_struct *t)
|
|
{
|
|
const struct tile_dma_state *dma = &t->tile_dma_state;
|
|
|
|
/*
|
|
* The only way to restore the done bit is to run a zero
|
|
* length transaction.
|
|
*/
|
|
if ((dma->status & SPR_DMA_STATUS__DONE_MASK) &&
|
|
!(__insn_mfspr(SPR_DMA_USER_STATUS) & SPR_DMA_STATUS__DONE_MASK)) {
|
|
__insn_mtspr(SPR_DMA_BYTE, 0);
|
|
__insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__REQUEST_MASK);
|
|
while (__insn_mfspr(SPR_DMA_USER_STATUS) &
|
|
SPR_DMA_STATUS__BUSY_MASK)
|
|
;
|
|
}
|
|
|
|
__insn_mtspr(SPR_DMA_SRC_ADDR, dma->src);
|
|
__insn_mtspr(SPR_DMA_SRC_CHUNK_ADDR, dma->src_chunk);
|
|
__insn_mtspr(SPR_DMA_DST_ADDR, dma->dest);
|
|
__insn_mtspr(SPR_DMA_DST_CHUNK_ADDR, dma->dest_chunk);
|
|
__insn_mtspr(SPR_DMA_STRIDE, dma->strides);
|
|
__insn_mtspr(SPR_DMA_CHUNK_SIZE, dma->chunk_size);
|
|
__insn_mtspr(SPR_DMA_BYTE, dma->byte);
|
|
|
|
/*
|
|
* Restart the engine if we were running and not done.
|
|
* Clear a pending async DMA fault that we were waiting on return
|
|
* to user space to execute, since we expect the DMA engine
|
|
* to regenerate those faults for us now. Note that we don't
|
|
* try to clear the TIF_ASYNC_TLB flag, since it's relatively
|
|
* harmless if set, and it covers both DMA and the SN processor.
|
|
*/
|
|
if ((dma->status & DMA_STATUS_MASK) == SPR_DMA_STATUS__RUNNING_MASK) {
|
|
t->dma_async_tlb.fault_num = 0;
|
|
__insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__REQUEST_MASK);
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
static void save_arch_state(struct thread_struct *t)
|
|
{
|
|
#if CHIP_HAS_SPLIT_INTR_MASK()
|
|
t->interrupt_mask = __insn_mfspr(SPR_INTERRUPT_MASK_0_0) |
|
|
((u64)__insn_mfspr(SPR_INTERRUPT_MASK_0_1) << 32);
|
|
#else
|
|
t->interrupt_mask = __insn_mfspr(SPR_INTERRUPT_MASK_0);
|
|
#endif
|
|
t->ex_context[0] = __insn_mfspr(SPR_EX_CONTEXT_0_0);
|
|
t->ex_context[1] = __insn_mfspr(SPR_EX_CONTEXT_0_1);
|
|
t->system_save[0] = __insn_mfspr(SPR_SYSTEM_SAVE_0_0);
|
|
t->system_save[1] = __insn_mfspr(SPR_SYSTEM_SAVE_0_1);
|
|
t->system_save[2] = __insn_mfspr(SPR_SYSTEM_SAVE_0_2);
|
|
t->system_save[3] = __insn_mfspr(SPR_SYSTEM_SAVE_0_3);
|
|
t->intctrl_0 = __insn_mfspr(SPR_INTCTRL_0_STATUS);
|
|
#if CHIP_HAS_PROC_STATUS_SPR()
|
|
t->proc_status = __insn_mfspr(SPR_PROC_STATUS);
|
|
#endif
|
|
#if !CHIP_HAS_FIXED_INTVEC_BASE()
|
|
t->interrupt_vector_base = __insn_mfspr(SPR_INTERRUPT_VECTOR_BASE_0);
|
|
#endif
|
|
#if CHIP_HAS_TILE_RTF_HWM()
|
|
t->tile_rtf_hwm = __insn_mfspr(SPR_TILE_RTF_HWM);
|
|
#endif
|
|
#if CHIP_HAS_DSTREAM_PF()
|
|
t->dstream_pf = __insn_mfspr(SPR_DSTREAM_PF);
|
|
#endif
|
|
}
|
|
|
|
static void restore_arch_state(const struct thread_struct *t)
|
|
{
|
|
#if CHIP_HAS_SPLIT_INTR_MASK()
|
|
__insn_mtspr(SPR_INTERRUPT_MASK_0_0, (u32) t->interrupt_mask);
|
|
__insn_mtspr(SPR_INTERRUPT_MASK_0_1, t->interrupt_mask >> 32);
|
|
#else
|
|
__insn_mtspr(SPR_INTERRUPT_MASK_0, t->interrupt_mask);
|
|
#endif
|
|
__insn_mtspr(SPR_EX_CONTEXT_0_0, t->ex_context[0]);
|
|
__insn_mtspr(SPR_EX_CONTEXT_0_1, t->ex_context[1]);
|
|
__insn_mtspr(SPR_SYSTEM_SAVE_0_0, t->system_save[0]);
|
|
__insn_mtspr(SPR_SYSTEM_SAVE_0_1, t->system_save[1]);
|
|
__insn_mtspr(SPR_SYSTEM_SAVE_0_2, t->system_save[2]);
|
|
__insn_mtspr(SPR_SYSTEM_SAVE_0_3, t->system_save[3]);
|
|
__insn_mtspr(SPR_INTCTRL_0_STATUS, t->intctrl_0);
|
|
#if CHIP_HAS_PROC_STATUS_SPR()
|
|
__insn_mtspr(SPR_PROC_STATUS, t->proc_status);
|
|
#endif
|
|
#if !CHIP_HAS_FIXED_INTVEC_BASE()
|
|
__insn_mtspr(SPR_INTERRUPT_VECTOR_BASE_0, t->interrupt_vector_base);
|
|
#endif
|
|
#if CHIP_HAS_TILE_RTF_HWM()
|
|
__insn_mtspr(SPR_TILE_RTF_HWM, t->tile_rtf_hwm);
|
|
#endif
|
|
#if CHIP_HAS_DSTREAM_PF()
|
|
__insn_mtspr(SPR_DSTREAM_PF, t->dstream_pf);
|
|
#endif
|
|
}
|
|
|
|
|
|
void _prepare_arch_switch(struct task_struct *next)
|
|
{
|
|
#if CHIP_HAS_SN_PROC()
|
|
int snctl;
|
|
#endif
|
|
#if CHIP_HAS_TILE_DMA()
|
|
struct tile_dma_state *dma = ¤t->thread.tile_dma_state;
|
|
if (dma->enabled)
|
|
save_tile_dma_state(dma);
|
|
#endif
|
|
#if CHIP_HAS_SN_PROC()
|
|
/*
|
|
* Suspend the static network processor if it was running.
|
|
* We do not suspend the fabric itself, just like we don't
|
|
* try to suspend the UDN.
|
|
*/
|
|
snctl = __insn_mfspr(SPR_SNCTL);
|
|
current->thread.sn_proc_running =
|
|
(snctl & SPR_SNCTL__FRZPROC_MASK) == 0;
|
|
if (current->thread.sn_proc_running)
|
|
__insn_mtspr(SPR_SNCTL, snctl | SPR_SNCTL__FRZPROC_MASK);
|
|
#endif
|
|
}
|
|
|
|
|
|
struct task_struct *__sched _switch_to(struct task_struct *prev,
|
|
struct task_struct *next)
|
|
{
|
|
/* DMA state is already saved; save off other arch state. */
|
|
save_arch_state(&prev->thread);
|
|
|
|
#if CHIP_HAS_TILE_DMA()
|
|
/*
|
|
* Restore DMA in new task if desired.
|
|
* Note that it is only safe to restart here since interrupts
|
|
* are disabled, so we can't take any DMATLB miss or access
|
|
* interrupts before we have finished switching stacks.
|
|
*/
|
|
if (next->thread.tile_dma_state.enabled) {
|
|
restore_tile_dma_state(&next->thread);
|
|
grant_dma_mpls();
|
|
} else {
|
|
restrict_dma_mpls();
|
|
}
|
|
#endif
|
|
|
|
/* Restore other arch state. */
|
|
restore_arch_state(&next->thread);
|
|
|
|
#if CHIP_HAS_SN_PROC()
|
|
/*
|
|
* Restart static network processor in the new process
|
|
* if it was running before.
|
|
*/
|
|
if (next->thread.sn_proc_running) {
|
|
int snctl = __insn_mfspr(SPR_SNCTL);
|
|
__insn_mtspr(SPR_SNCTL, snctl & ~SPR_SNCTL__FRZPROC_MASK);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_HARDWALL
|
|
/* Enable or disable access to the network registers appropriately. */
|
|
hardwall_switch_tasks(prev, next);
|
|
#endif
|
|
|
|
/*
|
|
* Switch kernel SP, PC, and callee-saved registers.
|
|
* In the context of the new task, return the old task pointer
|
|
* (i.e. the task that actually called __switch_to).
|
|
* Pass the value to use for SYSTEM_SAVE_K_0 when we reset our sp.
|
|
*/
|
|
return __switch_to(prev, next, next_current_ksp0(next));
|
|
}
|
|
|
|
/*
|
|
* This routine is called on return from interrupt if any of the
|
|
* TIF_WORK_MASK flags are set in thread_info->flags. It is
|
|
* entered with interrupts disabled so we don't miss an event
|
|
* that modified the thread_info flags. If any flag is set, we
|
|
* handle it and return, and the calling assembly code will
|
|
* re-disable interrupts, reload the thread flags, and call back
|
|
* if more flags need to be handled.
|
|
*
|
|
* We return whether we need to check the thread_info flags again
|
|
* or not. Note that we don't clear TIF_SINGLESTEP here, so it's
|
|
* important that it be tested last, and then claim that we don't
|
|
* need to recheck the flags.
|
|
*/
|
|
int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
|
|
{
|
|
/* If we enter in kernel mode, do nothing and exit the caller loop. */
|
|
if (!user_mode(regs))
|
|
return 0;
|
|
|
|
/* Enable interrupts; they are disabled again on return to caller. */
|
|
local_irq_enable();
|
|
|
|
if (thread_info_flags & _TIF_NEED_RESCHED) {
|
|
schedule();
|
|
return 1;
|
|
}
|
|
#if CHIP_HAS_TILE_DMA() || CHIP_HAS_SN_PROC()
|
|
if (thread_info_flags & _TIF_ASYNC_TLB) {
|
|
do_async_page_fault(regs);
|
|
return 1;
|
|
}
|
|
#endif
|
|
if (thread_info_flags & _TIF_SIGPENDING) {
|
|
do_signal(regs);
|
|
return 1;
|
|
}
|
|
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
|
|
clear_thread_flag(TIF_NOTIFY_RESUME);
|
|
tracehook_notify_resume(regs);
|
|
return 1;
|
|
}
|
|
if (thread_info_flags & _TIF_SINGLESTEP) {
|
|
single_step_once(regs);
|
|
return 0;
|
|
}
|
|
panic("work_pending: bad flags %#x\n", thread_info_flags);
|
|
}
|
|
|
|
unsigned long get_wchan(struct task_struct *p)
|
|
{
|
|
struct KBacktraceIterator kbt;
|
|
|
|
if (!p || p == current || p->state == TASK_RUNNING)
|
|
return 0;
|
|
|
|
for (KBacktraceIterator_init(&kbt, p, NULL);
|
|
!KBacktraceIterator_end(&kbt);
|
|
KBacktraceIterator_next(&kbt)) {
|
|
if (!in_sched_functions(kbt.it.pc))
|
|
return kbt.it.pc;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Flush thread state. */
|
|
void flush_thread(void)
|
|
{
|
|
/* Nothing */
|
|
}
|
|
|
|
/*
|
|
* Free current thread data structures etc..
|
|
*/
|
|
void exit_thread(void)
|
|
{
|
|
/* Nothing */
|
|
}
|
|
|
|
void show_regs(struct pt_regs *regs)
|
|
{
|
|
struct task_struct *tsk = validate_current();
|
|
int i;
|
|
|
|
pr_err("\n");
|
|
show_regs_print_info(KERN_ERR);
|
|
#ifdef __tilegx__
|
|
for (i = 0; i < 51; i += 3)
|
|
pr_err(" r%-2d: "REGFMT" r%-2d: "REGFMT" r%-2d: "REGFMT"\n",
|
|
i, regs->regs[i], i+1, regs->regs[i+1],
|
|
i+2, regs->regs[i+2]);
|
|
pr_err(" r51: "REGFMT" r52: "REGFMT" tp : "REGFMT"\n",
|
|
regs->regs[51], regs->regs[52], regs->tp);
|
|
pr_err(" sp : "REGFMT" lr : "REGFMT"\n", regs->sp, regs->lr);
|
|
#else
|
|
for (i = 0; i < 52; i += 4)
|
|
pr_err(" r%-2d: "REGFMT" r%-2d: "REGFMT
|
|
" r%-2d: "REGFMT" r%-2d: "REGFMT"\n",
|
|
i, regs->regs[i], i+1, regs->regs[i+1],
|
|
i+2, regs->regs[i+2], i+3, regs->regs[i+3]);
|
|
pr_err(" r52: "REGFMT" tp : "REGFMT" sp : "REGFMT" lr : "REGFMT"\n",
|
|
regs->regs[52], regs->tp, regs->sp, regs->lr);
|
|
#endif
|
|
pr_err(" pc : "REGFMT" ex1: %ld faultnum: %ld\n",
|
|
regs->pc, regs->ex1, regs->faultnum);
|
|
|
|
dump_stack_regs(regs);
|
|
}
|