multicalls.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _XEN_MULTICALLS_H
  3. #define _XEN_MULTICALLS_H
  4. #include <trace/events/xen.h>
  5. #include "xen-ops.h"
  6. /* Multicalls */
  7. struct multicall_space
  8. {
  9. struct multicall_entry *mc;
  10. void *args;
  11. };
  12. /* Allocate room for a multicall and its args */
  13. struct multicall_space __xen_mc_entry(size_t args);
  14. DECLARE_PER_CPU(unsigned long, xen_mc_irq_flags);
  15. /* Call to start a batch of multiple __xen_mc_entry()s. Must be
  16. paired with xen_mc_issue() */
  17. static inline void xen_mc_batch(void)
  18. {
  19. unsigned long flags;
  20. /* need to disable interrupts until this entry is complete */
  21. local_irq_save(flags);
  22. trace_xen_mc_batch(paravirt_get_lazy_mode());
  23. __this_cpu_write(xen_mc_irq_flags, flags);
  24. }
  25. static inline struct multicall_space xen_mc_entry(size_t args)
  26. {
  27. xen_mc_batch();
  28. return __xen_mc_entry(args);
  29. }
  30. /* Flush all pending multicalls */
  31. void xen_mc_flush(void);
  32. /* Issue a multicall if we're not in a lazy mode */
  33. static inline void xen_mc_issue(unsigned mode)
  34. {
  35. trace_xen_mc_issue(mode);
  36. if ((paravirt_get_lazy_mode() & mode) == 0)
  37. xen_mc_flush();
  38. /* restore flags saved in xen_mc_batch */
  39. local_irq_restore(this_cpu_read(xen_mc_irq_flags));
  40. }
  41. /* Set up a callback to be called when the current batch is flushed */
  42. void xen_mc_callback(void (*fn)(void *), void *data);
  43. /*
  44. * Try to extend the arguments of the previous multicall command. The
  45. * previous command's op must match. If it does, then it attempts to
  46. * extend the argument space allocated to the multicall entry by
  47. * arg_size bytes.
  48. *
  49. * The returned multicall_space will return with mc pointing to the
  50. * command on success, or NULL on failure, and args pointing to the
  51. * newly allocated space.
  52. */
  53. struct multicall_space xen_mc_extend_args(unsigned long op, size_t arg_size);
  54. #endif /* _XEN_MULTICALLS_H */