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