phytium_cpu.h 2.2 KB

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