phytium_cpu.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_E2000)
  30. #define MAX_HANDLERS 270
  31. #endif
  32. #define GIC_IRQ_START 0
  33. #define GIC_ACK_INTID_MASK 0x000003ff
  34. rt_uint64_t get_main_cpu_affval(void);
  35. rt_inline rt_uint32_t platform_get_gic_dist_base(void)
  36. {
  37. return GICV3_DISTRIBUTOR_BASE_ADDR;
  38. }
  39. /* the basic constants and interfaces needed by gic */
  40. rt_inline uintptr_t platform_get_gic_redist_base(void)
  41. {
  42. uintptr_t redis_base, mpidr_aff, gicr_typer_aff;
  43. mpidr_aff = (uintptr_t)(GetAffinity() & 0xfff);
  44. for (redis_base = GICV3_RD_BASE_ADDR; redis_base < GICV3_RD_BASE_ADDR + GICV3_RD_SIZE; redis_base += GICV3_RD_OFFSET)
  45. {
  46. #ifdef RT_USING_SMART
  47. uintptr_t redis_base_virtual = (uintptr_t)rt_ioremap((void *)redis_base, GICV3_RD_OFFSET);
  48. rt_hw_tlb_invalidate_all();
  49. if (redis_base_virtual == 0)
  50. {
  51. continue;
  52. }
  53. #if defined(TARGET_ARMV8_AARCH64)
  54. gicr_typer_aff = GIC_RDIST_TYPER(redis_base_virtual) >> 32;
  55. #else
  56. gicr_typer_aff = GIC_RDIST_TYPER(redis_base_virtual + 0x4);
  57. #endif
  58. if (mpidr_aff == gicr_typer_aff)
  59. {
  60. return redis_base_virtual;
  61. }
  62. else
  63. {
  64. rt_iounmap(redis_base_virtual);
  65. }
  66. #else
  67. #if defined(TARGET_ARMV8_AARCH64)
  68. gicr_typer_aff = GIC_RDIST_TYPER(redis_base) >> 32;
  69. #else
  70. gicr_typer_aff = GIC_RDIST_TYPER(redis_base + 0x4);
  71. #endif
  72. if (mpidr_aff == gicr_typer_aff)
  73. {
  74. return redis_base;
  75. }
  76. #endif
  77. }
  78. return 0;
  79. }
  80. #if defined(TARGET_ARMV8_AARCH64)
  81. rt_inline rt_uint32_t platform_get_gic_cpu_base(void)
  82. {
  83. return 0; /* unused in gicv3 */
  84. }
  85. #endif
  86. int phytium_cpu_id_mapping(int cpu_id);
  87. #endif // !