processor.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright 2004-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #ifndef __ASM_BFIN_PROCESSOR_H
  7. #define __ASM_BFIN_PROCESSOR_H
  8. /*
  9. * Default implementation of macro that returns current
  10. * instruction pointer ("program counter").
  11. */
  12. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  13. #include <asm/ptrace.h>
  14. #include <mach/blackfin.h>
  15. static inline unsigned long rdusp(void)
  16. {
  17. unsigned long usp;
  18. __asm__ __volatile__("%0 = usp;\n\t":"=da"(usp));
  19. return usp;
  20. }
  21. static inline void wrusp(unsigned long usp)
  22. {
  23. __asm__ __volatile__("usp = %0;\n\t"::"da"(usp));
  24. }
  25. static inline unsigned long __get_SP(void)
  26. {
  27. unsigned long sp;
  28. __asm__ __volatile__("%0 = sp;\n\t" : "=da"(sp));
  29. return sp;
  30. }
  31. /*
  32. * User space process size: 1st byte beyond user address space.
  33. * Fairly meaningless on nommu. Parts of user programs can be scattered
  34. * in a lot of places, so just disable this by setting it to 0xFFFFFFFF.
  35. */
  36. #define TASK_SIZE 0xFFFFFFFF
  37. #ifdef __KERNEL__
  38. #define STACK_TOP TASK_SIZE
  39. #endif
  40. #define TASK_UNMAPPED_BASE 0
  41. struct thread_struct {
  42. unsigned long ksp; /* kernel stack pointer */
  43. unsigned long usp; /* user stack pointer */
  44. unsigned short seqstat; /* saved status register */
  45. unsigned long esp0; /* points to SR of stack frame pt_regs */
  46. unsigned long pc; /* instruction pointer */
  47. void * debuggerinfo;
  48. };
  49. #define INIT_THREAD { \
  50. sizeof(init_stack) + (unsigned long) init_stack, 0, \
  51. PS_S, 0, 0 \
  52. }
  53. extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
  54. unsigned long new_sp);
  55. /* Forward declaration, a strange C thing */
  56. struct task_struct;
  57. /* Free all resources held by a thread. */
  58. static inline void release_thread(struct task_struct *dead_task)
  59. {
  60. }
  61. extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);
  62. /*
  63. * Free current thread data structures etc..
  64. */
  65. static inline void exit_thread(void)
  66. {
  67. }
  68. /*
  69. * Return saved PC of a blocked thread.
  70. */
  71. #define thread_saved_pc(tsk) (tsk->thread.pc)
  72. unsigned long get_wchan(struct task_struct *p);
  73. #define KSTK_EIP(tsk) \
  74. ({ \
  75. unsigned long eip = 0; \
  76. if ((tsk)->thread.esp0 > PAGE_SIZE && \
  77. MAP_NR((tsk)->thread.esp0) < max_mapnr) \
  78. eip = ((struct pt_regs *) (tsk)->thread.esp0)->pc; \
  79. eip; })
  80. #define KSTK_ESP(tsk) ((tsk) == current ? rdusp() : (tsk)->thread.usp)
  81. #define cpu_relax() smp_mb()
  82. /* Get the Silicon Revision of the chip */
  83. static inline uint32_t __pure bfin_revid(void)
  84. {
  85. /* Always use CHIPID, to work around ANOMALY_05000234 */
  86. uint32_t revid = (bfin_read_CHIPID() & CHIPID_VERSION) >> 28;
  87. #ifdef _BOOTROM_GET_DXE_ADDRESS_TWI
  88. /*
  89. * ANOMALY_05000364
  90. * Incorrect Revision Number in DSPID Register
  91. */
  92. if (ANOMALY_05000364 &&
  93. bfin_read16(_BOOTROM_GET_DXE_ADDRESS_TWI) == 0x2796)
  94. revid = 1;
  95. #endif
  96. return revid;
  97. }
  98. static inline uint16_t __pure bfin_cpuid(void)
  99. {
  100. return (bfin_read_CHIPID() & CHIPID_FAMILY) >> 12;
  101. }
  102. static inline uint32_t __pure bfin_dspid(void)
  103. {
  104. return bfin_read_DSPID();
  105. }
  106. #define blackfin_core_id() (bfin_dspid() & 0xff)
  107. static inline uint32_t __pure bfin_compiled_revid(void)
  108. {
  109. #if defined(CONFIG_BF_REV_0_0)
  110. return 0;
  111. #elif defined(CONFIG_BF_REV_0_1)
  112. return 1;
  113. #elif defined(CONFIG_BF_REV_0_2)
  114. return 2;
  115. #elif defined(CONFIG_BF_REV_0_3)
  116. return 3;
  117. #elif defined(CONFIG_BF_REV_0_4)
  118. return 4;
  119. #elif defined(CONFIG_BF_REV_0_5)
  120. return 5;
  121. #elif defined(CONFIG_BF_REV_0_6)
  122. return 6;
  123. #elif defined(CONFIG_BF_REV_ANY)
  124. return 0xffff;
  125. #else
  126. return -1;
  127. #endif
  128. }
  129. #endif