cpu_spin_table.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * 2023-02-21 GuEe-GUI replace with ofw
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #define DBG_TAG "cpu.aa64"
  13. #define DBG_LVL DBG_INFO
  14. #include <rtdbg.h>
  15. #include <cpu.h>
  16. #include <cpuport.h>
  17. #include <ioremap.h>
  18. #include <drivers/core/dm.h>
  19. #ifdef RT_USING_OFW
  20. static rt_uint64_t cpu_release_addr[RT_CPUS_NR];
  21. static int spin_table_cpu_init(rt_uint32_t cpuid, void *param)
  22. {
  23. struct rt_ofw_node *cpu_np = param;
  24. rt_ofw_prop_read_u64(cpu_np, "cpu-release-addr", &cpu_release_addr[cpuid]);
  25. LOG_D("Using release address 0x%p for CPU %d", cpu_release_addr[cpuid], cpuid);
  26. return 0;
  27. }
  28. static int spin_table_cpu_boot(rt_uint32_t cpuid, rt_uint64_t entry)
  29. {
  30. void *cpu_release_vaddr;
  31. cpu_release_vaddr = rt_ioremap((void *)cpu_release_addr[cpuid], sizeof(cpu_release_addr[0]));
  32. if (!cpu_release_vaddr)
  33. {
  34. LOG_E("IO remap failing");
  35. return -1;
  36. }
  37. __asm__ volatile ("str %0, [%1]" ::"rZ"(entry), "r"(cpu_release_vaddr));
  38. rt_hw_barrier(dsb, sy);
  39. rt_hw_sev();
  40. rt_iounmap(cpu_release_vaddr);
  41. return 0;
  42. }
  43. struct cpu_ops_t cpu_spin_table_ops =
  44. {
  45. .method = "spin-table",
  46. .cpu_init = spin_table_cpu_init,
  47. .cpu_boot = spin_table_cpu_boot,
  48. };
  49. #endif