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