processor.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #ifndef __ASM_BFIN_PROCESSOR_H
  2. #define __ASM_BFIN_PROCESSOR_H
  3. /*
  4. * Default implementation of macro that returns current
  5. * instruction pointer ("program counter").
  6. */
  7. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  8. #include <asm/blackfin.h>
  9. #include <asm/segment.h>
  10. #include <linux/compiler.h>
  11. static inline unsigned long rdusp(void)
  12. {
  13. unsigned long usp;
  14. __asm__ __volatile__("%0 = usp;\n\t":"=da"(usp));
  15. return usp;
  16. }
  17. static inline void wrusp(unsigned long usp)
  18. {
  19. __asm__ __volatile__("usp = %0;\n\t"::"da"(usp));
  20. }
  21. static inline unsigned long __get_SP(void)
  22. {
  23. unsigned long sp;
  24. __asm__ __volatile__("%0 = sp;\n\t" : "=da"(sp));
  25. return sp;
  26. }
  27. /*
  28. * User space process size: 1st byte beyond user address space.
  29. * Fairly meaningless on nommu. Parts of user programs can be scattered
  30. * in a lot of places, so just disable this by setting it to 0xFFFFFFFF.
  31. */
  32. #define TASK_SIZE 0xFFFFFFFF
  33. #ifdef __KERNEL__
  34. #define STACK_TOP TASK_SIZE
  35. #endif
  36. #define TASK_UNMAPPED_BASE 0
  37. struct thread_struct {
  38. unsigned long ksp; /* kernel stack pointer */
  39. unsigned long usp; /* user stack pointer */
  40. unsigned short seqstat; /* saved status register */
  41. unsigned long esp0; /* points to SR of stack frame pt_regs */
  42. unsigned long pc; /* instruction pointer */
  43. void * debuggerinfo;
  44. };
  45. #define INIT_THREAD { \
  46. sizeof(init_stack) + (unsigned long) init_stack, 0, \
  47. PS_S, 0, 0 \
  48. }
  49. /*
  50. * Do necessary setup to start up a newly executed thread.
  51. *
  52. * pass the data segment into user programs if it exists,
  53. * it can't hurt anything as far as I can tell
  54. */
  55. #ifndef CONFIG_SMP
  56. #define start_thread(_regs, _pc, _usp) \
  57. do { \
  58. set_fs(USER_DS); \
  59. (_regs)->pc = (_pc); \
  60. if (current->mm) \
  61. (_regs)->p5 = current->mm->start_data; \
  62. task_thread_info(current)->l1_task_info.stack_start \
  63. = (void *)current->mm->context.stack_start; \
  64. task_thread_info(current)->l1_task_info.lowest_sp = (void *)(_usp); \
  65. memcpy(L1_SCRATCH_TASK_INFO, &task_thread_info(current)->l1_task_info, \
  66. sizeof(*L1_SCRATCH_TASK_INFO)); \
  67. wrusp(_usp); \
  68. } while(0)
  69. #else
  70. #define start_thread(_regs, _pc, _usp) \
  71. do { \
  72. set_fs(USER_DS); \
  73. (_regs)->pc = (_pc); \
  74. if (current->mm) \
  75. (_regs)->p5 = current->mm->start_data; \
  76. wrusp(_usp); \
  77. } while (0)
  78. #endif
  79. /* Forward declaration, a strange C thing */
  80. struct task_struct;
  81. /* Free all resources held by a thread. */
  82. static inline void release_thread(struct task_struct *dead_task)
  83. {
  84. }
  85. #define prepare_to_copy(tsk) do { } while (0)
  86. extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);
  87. /*
  88. * Free current thread data structures etc..
  89. */
  90. static inline void exit_thread(void)
  91. {
  92. }
  93. /*
  94. * Return saved PC of a blocked thread.
  95. */
  96. #define thread_saved_pc(tsk) (tsk->thread.pc)
  97. unsigned long get_wchan(struct task_struct *p);
  98. #define KSTK_EIP(tsk) \
  99. ({ \
  100. unsigned long eip = 0; \
  101. if ((tsk)->thread.esp0 > PAGE_SIZE && \
  102. MAP_NR((tsk)->thread.esp0) < max_mapnr) \
  103. eip = ((struct pt_regs *) (tsk)->thread.esp0)->pc; \
  104. eip; })
  105. #define KSTK_ESP(tsk) ((tsk) == current ? rdusp() : (tsk)->thread.usp)
  106. #define cpu_relax() smp_mb()
  107. /* Get the Silicon Revision of the chip */
  108. static inline uint32_t __pure bfin_revid(void)
  109. {
  110. /* stored in the upper 4 bits */
  111. uint32_t revid = bfin_read_CHIPID() >> 28;
  112. #ifdef CONFIG_BF52x
  113. /* ANOMALY_05000357
  114. * Incorrect Revision Number in DSPID Register
  115. */
  116. if (revid == 0)
  117. switch (bfin_read16(_BOOTROM_GET_DXE_ADDRESS_TWI)) {
  118. case 0x0010:
  119. revid = 0;
  120. break;
  121. case 0x2796:
  122. revid = 1;
  123. break;
  124. default:
  125. revid = 0xFFFF;
  126. break;
  127. }
  128. #endif
  129. return revid;
  130. }
  131. static inline uint16_t __pure bfin_cpuid(void)
  132. {
  133. return (bfin_read_CHIPID() & CHIPID_FAMILY) >> 12;
  134. }
  135. static inline uint32_t __pure bfin_dspid(void)
  136. {
  137. return bfin_read_DSPID();
  138. }
  139. static inline uint32_t __pure bfin_compiled_revid(void)
  140. {
  141. #if defined(CONFIG_BF_REV_0_0)
  142. return 0;
  143. #elif defined(CONFIG_BF_REV_0_1)
  144. return 1;
  145. #elif defined(CONFIG_BF_REV_0_2)
  146. return 2;
  147. #elif defined(CONFIG_BF_REV_0_3)
  148. return 3;
  149. #elif defined(CONFIG_BF_REV_0_4)
  150. return 4;
  151. #elif defined(CONFIG_BF_REV_0_5)
  152. return 5;
  153. #elif defined(CONFIG_BF_REV_0_6)
  154. return 6;
  155. #elif defined(CONFIG_BF_REV_ANY)
  156. return 0xffff;
  157. #else
  158. return -1;
  159. #endif
  160. }
  161. #endif