mp.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2015 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. *
  6. * Taken from coreboot file of the same name
  7. */
  8. #ifndef _X86_MP_H_
  9. #define _X86_MP_H_
  10. #include <asm/atomic.h>
  11. typedef int (*mp_callback_t)(struct udevice *cpu, void *arg);
  12. /*
  13. * A mp_flight_record details a sequence of calls for the APs to perform
  14. * along with the BSP to coordinate sequencing. Each flight record either
  15. * provides a barrier for each AP before calling the callback or the APs
  16. * are allowed to perform the callback without waiting. Regardless, each
  17. * record has the cpus_entered field incremented for each record. When
  18. * the BSP observes that the cpus_entered matches the number of APs
  19. * the bsp_call is called with bsp_arg and upon returning releases the
  20. * barrier allowing the APs to make further progress.
  21. *
  22. * Note that ap_call() and bsp_call() can be NULL. In the NULL case the
  23. * callback will just not be called.
  24. */
  25. struct mp_flight_record {
  26. atomic_t barrier;
  27. atomic_t cpus_entered;
  28. mp_callback_t ap_call;
  29. void *ap_arg;
  30. mp_callback_t bsp_call;
  31. void *bsp_arg;
  32. } __attribute__((aligned(ARCH_DMA_MINALIGN)));
  33. #define MP_FLIGHT_RECORD(barrier_, ap_func_, ap_arg_, bsp_func_, bsp_arg_) \
  34. { \
  35. .barrier = ATOMIC_INIT(barrier_), \
  36. .cpus_entered = ATOMIC_INIT(0), \
  37. .ap_call = ap_func_, \
  38. .ap_arg = ap_arg_, \
  39. .bsp_call = bsp_func_, \
  40. .bsp_arg = bsp_arg_, \
  41. }
  42. #define MP_FR_BLOCK_APS(ap_func, ap_arg, bsp_func, bsp_arg) \
  43. MP_FLIGHT_RECORD(0, ap_func, ap_arg, bsp_func, bsp_arg)
  44. #define MP_FR_NOBLOCK_APS(ap_func, ap_arg, bsp_func, bsp_arg) \
  45. MP_FLIGHT_RECORD(1, ap_func, ap_arg, bsp_func, bsp_arg)
  46. /*
  47. * The mp_params structure provides the arguments to the mp subsystem
  48. * for bringing up APs.
  49. *
  50. * At present this is overkill for U-Boot, but it may make it easier to add
  51. * SMM support.
  52. */
  53. struct mp_params {
  54. int parallel_microcode_load;
  55. const void *microcode_pointer;
  56. /* Flight plan for APs and BSP */
  57. struct mp_flight_record *flight_plan;
  58. int num_records;
  59. };
  60. /*
  61. * mp_init() will set up the SIPI vector and bring up the APs according to
  62. * mp_params. Each flight record will be executed according to the plan. Note
  63. * that the MP infrastructure uses SMM default area without saving it. It's
  64. * up to the chipset or mainboard to either e820 reserve this area or save this
  65. * region prior to calling mp_init() and restoring it after mp_init returns.
  66. *
  67. * At the time mp_init() is called the MTRR MSRs are mirrored into APs then
  68. * caching is enabled before running the flight plan.
  69. *
  70. * The MP init has the following properties:
  71. * 1. APs are brought up in parallel.
  72. * 2. The ordering of cpu number and APIC ids is not deterministic.
  73. * Therefore, one cannot rely on this property or the order of devices in
  74. * the device tree unless the chipset or mainboard know the APIC ids
  75. * a priori.
  76. *
  77. * mp_init() returns < 0 on error, 0 on success.
  78. */
  79. int mp_init(struct mp_params *params);
  80. /* Probes the CPU device */
  81. int mp_init_cpu(struct udevice *cpu, void *unused);
  82. #endif /* _X86_MP_H_ */