1 #ifndef _ASM_X86_INVPCID_H_
2 #define _ASM_X86_INVPCID_H_
3 
4 #include <xen/types.h>
5 
6 extern bool use_invpcid;
7 
8 #define INVPCID_OPCODE ".byte 0x66, 0x0f, 0x38, 0x82\n"
9 #define MODRM_ECX_01   ".byte 0x01\n"
10 
invpcid(unsigned int pcid,unsigned long addr,unsigned int type)11 static inline void invpcid(unsigned int pcid, unsigned long addr,
12                            unsigned int type)
13 {
14     struct {
15         uint64_t pcid:12;
16         uint64_t reserved:52;
17         uint64_t addr;
18     } desc = { .pcid = pcid, .addr = addr };
19 
20     asm volatile (
21 #ifdef HAVE_AS_INVPCID
22                   "invpcid %[desc], %q[type]"
23                   : /* No output */
24                   : [desc] "m" (desc), [type] "r" (type)
25 #else
26                   INVPCID_OPCODE MODRM_ECX_01
27                   : /* No output */
28                   : "a" (type), "c" (&desc)
29 #endif
30                   : "memory" );
31 }
32 
33 /* Flush all mappings for a given PCID and addr, not including globals */
invpcid_flush_one(unsigned int pcid,unsigned long addr)34 static inline void invpcid_flush_one(unsigned int pcid, unsigned long addr)
35 {
36     invpcid(pcid, addr, X86_INVPCID_INDIV_ADDR);
37 }
38 
39 /* Flush all mappings for a given PCID, not including globals */
invpcid_flush_single_context(unsigned int pcid)40 static inline void invpcid_flush_single_context(unsigned int pcid)
41 {
42     invpcid(pcid, 0, X86_INVPCID_SINGLE_CTXT);
43 }
44 
45 /* Flush all mappings, including globals, for all PCIDs */
invpcid_flush_all(void)46 static inline void invpcid_flush_all(void)
47 {
48     invpcid(0, 0, X86_INVPCID_ALL_INCL_GLOBAL);
49 }
50 
51 /* Flush all mappings for all PCIDs, excluding globals */
invpcid_flush_all_nonglobals(void)52 static inline void invpcid_flush_all_nonglobals(void)
53 {
54     invpcid(0, 0, X86_INVPCID_ALL_NON_GLOBAL);
55 }
56 
57 #endif	/* _ASM_X86_INVPCID_H_ */
58 
59 /*
60  * Local variables:
61  * mode: C
62  * c-file-style: "BSD"
63  * c-basic-offset: 4
64  * tab-width: 4
65  * indent-tabs-mode: nil
66  * End:
67  */
68