switch_to.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_SWITCH_TO_H
  15. #define _ASM_TILE_SWITCH_TO_H
  16. #include <arch/sim_def.h>
  17. /*
  18. * switch_to(n) should switch tasks to task nr n, first
  19. * checking that n isn't the current task, in which case it does nothing.
  20. * The number of callee-saved registers saved on the kernel stack
  21. * is defined here for use in copy_thread() and must agree with __switch_to().
  22. */
  23. #define CALLEE_SAVED_FIRST_REG 30
  24. #define CALLEE_SAVED_REGS_COUNT 24 /* r30 to r52, plus an empty to align */
  25. #ifndef __ASSEMBLY__
  26. struct task_struct;
  27. /*
  28. * Pause the DMA engine and static network before task switching.
  29. */
  30. #define prepare_arch_switch(next) _prepare_arch_switch(next)
  31. void _prepare_arch_switch(struct task_struct *next);
  32. struct task_struct;
  33. #define switch_to(prev, next, last) ((last) = _switch_to((prev), (next)))
  34. extern struct task_struct *_switch_to(struct task_struct *prev,
  35. struct task_struct *next);
  36. /* Helper function for _switch_to(). */
  37. extern struct task_struct *__switch_to(struct task_struct *prev,
  38. struct task_struct *next,
  39. unsigned long new_system_save_k_0);
  40. /* Address that switched-away from tasks are at. */
  41. extern unsigned long get_switch_to_pc(void);
  42. /*
  43. * Kernel threads can check to see if they need to migrate their
  44. * stack whenever they return from a context switch; for user
  45. * threads, we defer until they are returning to user-space.
  46. * We defer homecache migration until the runqueue lock is released.
  47. */
  48. #define finish_arch_post_lock_switch() do { \
  49. __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_SWITCH | \
  50. (current->pid << _SIM_CONTROL_OPERATOR_BITS)); \
  51. if (current->mm == NULL && !kstack_hash && \
  52. current_thread_info()->homecache_cpu != raw_smp_processor_id()) \
  53. homecache_migrate_kthread(); \
  54. } while (0)
  55. /* Support function for forking a new task. */
  56. void ret_from_fork(void);
  57. /* Support function for forking a new kernel thread. */
  58. void ret_from_kernel_thread(void *fn, void *arg);
  59. /* Called from ret_from_xxx() when a new process starts up. */
  60. struct task_struct *sim_notify_fork(struct task_struct *prev);
  61. #endif /* !__ASSEMBLY__ */
  62. #endif /* _ASM_TILE_SWITCH_TO_H */