cpu_spin_table.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include <rthw.h>
  10. #include <rtthread.h>
  11. #include <ioremap.h>
  12. #include "cpu.h"
  13. #define DBG_TAG "libcpu.aarch64.cpu_spin_table"
  14. #define DBG_LVL DBG_INFO
  15. #include <rtdbg.h>
  16. #ifdef RT_USING_FDT
  17. #include <dtb_node.h>
  18. #include "entry_point.h"
  19. static rt_uint64_t cpu_release_addr[RT_CPUS_NR];
  20. static int spin_table_cpu_init(rt_uint32_t cpuid)
  21. {
  22. struct dtb_node *cpu = get_cpu_node(cpuid);
  23. if (!cpu)
  24. return -1; /* uninitialized cpu node in fdt */
  25. int size;
  26. rt_uint64_t *phead = (rt_uint64_t*)dtb_node_get_dtb_node_property_value(cpu, "cpu-release-addr", &size);
  27. cpu_release_addr[cpuid] = fdt64_to_cpu(*phead);
  28. LOG_D("Using release address 0x%p for CPU %d", cpu_release_addr[cpuid], cpuid);
  29. return 0;
  30. }
  31. static int spin_table_cpu_boot(rt_uint32_t cpuid)
  32. {
  33. rt_uint64_t secondary_entry_pa = (rt_uint64_t)_secondary_cpu_entry + PV_OFFSET;
  34. // map release_addr to addressable place
  35. void *rel_va = rt_ioremap((void *)cpu_release_addr[cpuid], sizeof(cpu_release_addr[0]));
  36. if (!rel_va)
  37. {
  38. LOG_E("IO remap failing");
  39. return -1;
  40. }
  41. __asm__ volatile("str %0, [%1]" ::"rZ"(secondary_entry_pa), "r"(rel_va));
  42. __asm__ volatile("dsb sy");
  43. __asm__ volatile("sev");
  44. rt_iounmap(rel_va);
  45. return 0;
  46. }
  47. #endif /* RT_USING_FDT */
  48. struct cpu_ops_t cpu_ops_spin_tbl = {
  49. .method = "spin-table",
  50. #ifdef RT_USING_FDT
  51. .cpu_init = spin_table_cpu_init,
  52. .cpu_boot = spin_table_cpu_boot,
  53. #endif
  54. };