phytium_cpu.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Email: opensource_embedded@phytium.com.cn
  7. *
  8. * Change Logs:
  9. * Date Author Notes
  10. * 2022-10-26 huanghe first commit
  11. *
  12. */
  13. #ifndef __PHYTIUM_CPU_H__
  14. #define __PHYTIUM_CPU_H__
  15. #include <rthw.h>
  16. #include <rtthread.h>
  17. #include <gicv3.h>
  18. #include "fparameters.h"
  19. #include "fio.h"
  20. #include "faarch.h"
  21. #include "tlb.h"
  22. #ifdef RT_USING_SMART
  23. #include"ioremap.h"
  24. #endif
  25. #define ARM_GIC_MAX_NR 1
  26. #if defined(TARGET_FT2000_4) || defined(TARGET_D2000)
  27. #define MAX_HANDLERS 160
  28. #endif
  29. #if defined(TARGET_PE220X)
  30. #define MAX_HANDLERS 270
  31. #endif
  32. #if defined(TARGET_PD2408)
  33. #define MAX_HANDLERS 1024
  34. #endif
  35. #define GIC_IRQ_START 0
  36. #define GIC_ACK_INTID_MASK 0x000003ff
  37. #define RT_CORE_AFF(x) (CORE##x##_AFF | 0x80000000)
  38. rt_uint64_t get_main_cpu_affval(void);
  39. rt_inline rt_uint32_t platform_get_gic_dist_base(void)
  40. {
  41. return GICV3_DISTRIBUTOR_BASE_ADDR;
  42. }
  43. /* the basic constants and interfaces needed by gic */
  44. rt_inline uintptr_t platform_get_gic_redist_base(void)
  45. {
  46. uintptr_t redis_base, mpidr_aff, gicr_typer_aff;
  47. mpidr_aff = (uintptr_t)(GetAffinity() & CORE_AFF_MASK);
  48. for (redis_base = GICV3_RD_BASE_ADDR; redis_base < GICV3_RD_BASE_ADDR + GICV3_RD_SIZE; redis_base += GICV3_RD_OFFSET)
  49. {
  50. #ifdef RT_USING_SMART
  51. uintptr_t redis_base_virtual = (uintptr_t)rt_ioremap((void *)redis_base, GICV3_RD_OFFSET);
  52. rt_hw_tlb_invalidate_all();
  53. if (redis_base_virtual == 0)
  54. {
  55. continue;
  56. }
  57. #if defined(TARGET_ARMV8_AARCH64)
  58. gicr_typer_aff = GIC_RDIST_TYPER(redis_base_virtual) >> 32;
  59. #else
  60. gicr_typer_aff = GIC_RDIST_TYPER(redis_base_virtual + 0x4);
  61. #endif
  62. if (mpidr_aff == gicr_typer_aff)
  63. {
  64. return redis_base_virtual;
  65. }
  66. else
  67. {
  68. rt_iounmap(redis_base_virtual);
  69. }
  70. #else
  71. #if defined(TARGET_ARMV8_AARCH64)
  72. gicr_typer_aff = GIC_RDIST_TYPER(redis_base) >> 32;
  73. #else
  74. gicr_typer_aff = GIC_RDIST_TYPER(redis_base + 0x4);
  75. #endif
  76. if (mpidr_aff == gicr_typer_aff)
  77. {
  78. return redis_base;
  79. }
  80. #endif
  81. }
  82. return 0;
  83. }
  84. #if defined(TARGET_ARMV8_AARCH64)
  85. rt_inline rt_uint32_t platform_get_gic_cpu_base(void)
  86. {
  87. return 0; /* unused in gicv3 */
  88. }
  89. #endif
  90. int phytium_cpu_id_mapping(int cpu_id);
  91. #endif // !