cpu.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #ifndef __RT_HW_CPU_H__
  10. #define __RT_HW_CPU_H__
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include <stdbool.h>
  14. #ifndef RT_CPUS_NR
  15. #define RT_CPUS_NR 1
  16. #endif /* RT_CPUS_NR */
  17. #ifdef RT_USING_SMP
  18. struct cpu_ops_t
  19. {
  20. const char *method;
  21. int (*cpu_init)(rt_uint32_t id);
  22. int (*cpu_boot)(rt_uint32_t id);
  23. void (*cpu_shutdown)(void);
  24. };
  25. /**
  26. * Identifier to mark a wrong CPU MPID.
  27. * All elements in rt_cpu_mpidr_early[] should be initialized with this value
  28. */
  29. #define ID_ERROR __INT64_MAX__
  30. extern rt_uint64_t rt_cpu_mpidr_early[];
  31. extern struct dtb_node *_cpu_node[];
  32. #define cpuid_to_hwid(cpuid) \
  33. ((((cpuid) >= 0) && ((cpuid) < RT_CPUS_NR)) ? rt_cpu_mpidr_early[cpuid] : ID_ERROR)
  34. #define set_hwid(cpuid, hwid) \
  35. ((((cpuid) >= 0) && ((cpuid) < RT_CPUS_NR)) ? (rt_cpu_mpidr_early[cpuid] = (hwid)) : ID_ERROR)
  36. #define get_cpu_node(cpuid) \
  37. ((((cpuid) >= 0) && ((cpuid) < RT_CPUS_NR)) ? _cpu_node[cpuid] : NULL)
  38. #define set_cpu_node(cpuid, node) \
  39. ((((cpuid) >= 0) && ((cpuid) < RT_CPUS_NR)) ? (_cpu_node[cpuid] = node) : NULL)
  40. extern int rt_hw_cpu_init();
  41. extern int rt_hw_cpu_boot_secondary(int num_cpus, rt_uint64_t *cpu_hw_ids, struct cpu_ops_t *cpu_ops[]);
  42. extern void rt_hw_secondary_cpu_idle_exec(void);
  43. extern struct cpu_ops_t cpu_ops_psci;
  44. extern struct cpu_ops_t cpu_ops_spin_tbl;
  45. #endif /* RT_USING_SMP */
  46. extern void (*system_off)(void);
  47. #endif /* __RT_HW_CPU_H__ */