mp.h 3.0 KB

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