smp.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2019 Fraunhofer AISEC,
  4. * Lukas Auer <lukas.auer@aisec.fraunhofer.de>
  5. */
  6. #ifndef _ASM_RISCV_SMP_H
  7. #define _ASM_RISCV_SMP_H
  8. /**
  9. * struct ipi_data - Inter-processor interrupt (IPI) data structure
  10. *
  11. * IPIs are used for SMP support to communicate to other harts what function to
  12. * call. Functions are in the form
  13. * void (*addr)(ulong hart, ulong arg0, ulong arg1).
  14. *
  15. * The function address and the two arguments, arg0 and arg1, are stored in the
  16. * IPI data structure. The hart ID is inserted by the hart handling the IPI and
  17. * calling the function.
  18. *
  19. * @valid is used to determine whether a sent IPI originated from U-Boot. It is
  20. * initialized to zero by board_init_f_alloc_reserve. When U-Boot sends its
  21. * first IPI, it is set to 1. This prevents already-pending IPIs not sent by
  22. * U-Boot from being taken.
  23. *
  24. * @addr: Address of function
  25. * @arg0: First argument of function
  26. * @arg1: Second argument of function
  27. * @valid: Whether this IPI is valid
  28. */
  29. struct ipi_data {
  30. ulong addr;
  31. ulong arg0;
  32. ulong arg1;
  33. unsigned int valid;
  34. };
  35. /**
  36. * handle_ipi() - interrupt handler for software interrupts
  37. *
  38. * The IPI interrupt handler must be called to handle software interrupts. It
  39. * calls the function specified in the hart's IPI data structure.
  40. *
  41. * @hart: Hart ID of the current hart
  42. */
  43. void handle_ipi(ulong hart);
  44. /**
  45. * smp_call_function() - Call a function on all other harts
  46. *
  47. * Send IPIs with the specified function call to all harts.
  48. *
  49. * @addr: Address of function
  50. * @arg0: First argument of function
  51. * @arg1: Second argument of function
  52. * @wait: Wait for harts to acknowledge request
  53. * @return 0 if OK, -ve on error
  54. */
  55. int smp_call_function(ulong addr, ulong arg0, ulong arg1, int wait);
  56. /**
  57. * riscv_init_ipi() - Initialize inter-process interrupt (IPI) driver
  58. *
  59. * Platform code must provide this function. This function is called once after
  60. * the cpu driver is initialized. No other riscv_*_ipi() calls will be made
  61. * before this function is called.
  62. *
  63. * @return 0 if OK, -ve on error
  64. */
  65. int riscv_init_ipi(void);
  66. /**
  67. * riscv_send_ipi() - Send inter-processor interrupt (IPI)
  68. *
  69. * Platform code must provide this function.
  70. *
  71. * @hart: Hart ID of receiving hart
  72. * @return 0 if OK, -ve on error
  73. */
  74. int riscv_send_ipi(int hart);
  75. /**
  76. * riscv_clear_ipi() - Clear inter-processor interrupt (IPI)
  77. *
  78. * Platform code must provide this function.
  79. *
  80. * @hart: Hart ID of hart to be cleared
  81. * @return 0 if OK, -ve on error
  82. */
  83. int riscv_clear_ipi(int hart);
  84. /**
  85. * riscv_get_ipi() - Get status of inter-processor interrupt (IPI)
  86. *
  87. * Platform code must provide this function.
  88. *
  89. * @hart: Hart ID of hart to be checked
  90. * @pending: Pointer to variable with result of the check,
  91. * 1 if IPI is pending, 0 otherwise
  92. * @return 0 if OK, -ve on error
  93. */
  94. int riscv_get_ipi(int hart, int *pending);
  95. #endif