cp15.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-03-25 quanzhao the first version
  9. */
  10. #ifndef __CP15_H__
  11. #define __CP15_H__
  12. unsigned long rt_cpu_get_smp_id(void);
  13. void rt_cpu_mmu_disable(void);
  14. void rt_cpu_mmu_enable(void);
  15. void rt_cpu_tlb_set(volatile unsigned long*);
  16. void rt_cpu_dcache_clean_flush(void);
  17. void rt_cpu_icache_flush(void);
  18. void rt_cpu_vector_set_base(unsigned int addr);
  19. #ifdef SOC_BCM283x
  20. #ifndef __STATIC_FORCEINLINE
  21. #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
  22. #endif
  23. #define __WFI() __asm__ volatile ("wfi":::"memory")
  24. #define __WFE() __asm__ volatile ("wfe":::"memory")
  25. #define __SEV() __asm__ volatile ("sev")
  26. __STATIC_FORCEINLINE void __ISB(void)
  27. {
  28. __asm__ volatile ("isb 0xF":::"memory");
  29. }
  30. /**
  31. \brief Data Synchronization Barrier
  32. \details Acts as a special kind of Data Memory Barrier.
  33. It completes when all explicit memory accesses before this instruction complete.
  34. */
  35. __STATIC_FORCEINLINE void __DSB(void)
  36. {
  37. __asm__ volatile ("dsb 0xF":::"memory");
  38. }
  39. /**
  40. \brief Data Memory Barrier
  41. \details Ensures the apparent order of the explicit memory operations before
  42. and after the instruction, without ensuring their completion.
  43. */
  44. __STATIC_FORCEINLINE void __DMB(void)
  45. {
  46. __asm__ volatile ("dmb 0xF":::"memory");
  47. }
  48. static inline void send_ipi_msg(int cpu, int ipi_vector)
  49. {
  50. IPI_MAILBOX_SET(cpu) = 1 << ipi_vector;
  51. }
  52. static inline void setup_bootstrap_addr(int cpu, int addr)
  53. {
  54. CORE_MAILBOX3_SET(cpu) = addr;
  55. }
  56. static inline void enable_cpu_ipi_intr(int cpu)
  57. {
  58. COREMB_INTCTL(cpu) = IPI_MAILBOX_INT_MASK;
  59. }
  60. static inline void enable_cpu_timer_intr(int cpu)
  61. {
  62. CORETIMER_INTCTL(cpu) = 0x8;
  63. }
  64. static inline void enable_cntv(void)
  65. {
  66. rt_uint32_t cntv_ctl;
  67. cntv_ctl = 1;
  68. asm volatile ("mcr p15, 0, %0, c14, c3, 1" :: "r"(cntv_ctl)); // write CNTV_CTL
  69. }
  70. static inline void disable_cntv(void)
  71. {
  72. rt_uint32_t cntv_ctl;
  73. cntv_ctl = 0;
  74. asm volatile ("mcr p15, 0, %0, c14, c3, 1" :: "r"(cntv_ctl)); // write CNTV_CTL
  75. }
  76. static inline void mask_cntv(void)
  77. {
  78. rt_uint32_t cntv_ctl;
  79. cntv_ctl = 2;
  80. asm volatile ("mcr p15, 0, %0, c14, c3, 1" :: "r"(cntv_ctl)); // write CNTV_CTL
  81. }
  82. static inline void unmask_cntv(void)
  83. {
  84. rt_uint32_t cntv_ctl;
  85. cntv_ctl = 1;
  86. asm volatile ("mcr p15, 0, %0, c14, c3, 1" :: "r"(cntv_ctl)); // write CNTV_CTL
  87. }
  88. static inline rt_uint64_t read_cntvct(void)
  89. {
  90. rt_uint32_t val,val1;
  91. asm volatile ("mrrc p15, 1, %0, %1, c14" : "=r" (val),"=r" (val1));
  92. return (val);
  93. }
  94. static inline rt_uint64_t read_cntvoff(void)
  95. {
  96. rt_uint64_t val;
  97. asm volatile ("mrrc p15, 4, %Q0, %R0, c14" : "=r" (val));
  98. return (val);
  99. }
  100. static inline rt_uint32_t read_cntv_tval(void)
  101. {
  102. rt_uint32_t val;
  103. asm volatile ("mrc p15, 0, %0, c14, c3, 0" : "=r"(val));
  104. return val;
  105. }
  106. static inline void write_cntv_tval(rt_uint32_t val)
  107. {
  108. asm volatile ("mcr p15, 0, %0, c14, c3, 0" :: "r"(val));
  109. return;
  110. }
  111. static inline rt_uint32_t read_cntfrq(void)
  112. {
  113. rt_uint32_t val;
  114. asm volatile ("mrc p15, 0, %0, c14, c0, 0" : "=r"(val));
  115. return val;
  116. }
  117. static inline rt_uint32_t read_cntctrl(void)
  118. {
  119. rt_uint32_t val;
  120. asm volatile ("mrc p15, 0, %0, c14, c1, 0" : "=r"(val));
  121. return val;
  122. }
  123. static inline uint32_t write_cntctrl(uint32_t val)
  124. {
  125. asm volatile ("mcr p15, 0, %0, c14, c1, 0" : :"r"(val));
  126. return val;
  127. }
  128. #endif
  129. #endif