PipeWire  0.3.33
cpu.h
Go to the documentation of this file.
1 /* Simple Plugin API
2  *
3  * Copyright © 2018 Wim Taymans
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef SPA_CPU_H
26 #define SPA_CPU_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <stdarg.h>
33 
34 #include <spa/utils/defs.h>
35 #include <spa/utils/hook.h>
36 
49 #define SPA_TYPE_INTERFACE_CPU SPA_TYPE_INFO_INTERFACE_BASE "CPU"
50 
51 #define SPA_VERSION_CPU 0
52 struct spa_cpu { struct spa_interface iface; };
53 
54 /* x86 specific */
55 #define SPA_CPU_FLAG_MMX (1<<0)
56 #define SPA_CPU_FLAG_MMXEXT (1<<1)
57 #define SPA_CPU_FLAG_3DNOW (1<<2)
58 #define SPA_CPU_FLAG_SSE (1<<3)
59 #define SPA_CPU_FLAG_SSE2 (1<<4)
60 #define SPA_CPU_FLAG_3DNOWEXT (1<<5)
61 #define SPA_CPU_FLAG_SSE3 (1<<6)
62 #define SPA_CPU_FLAG_SSSE3 (1<<7)
63 #define SPA_CPU_FLAG_SSE41 (1<<8)
64 #define SPA_CPU_FLAG_SSE42 (1<<9)
65 #define SPA_CPU_FLAG_AESNI (1<<10)
66 #define SPA_CPU_FLAG_AVX (1<<11)
67 #define SPA_CPU_FLAG_XOP (1<<12)
68 #define SPA_CPU_FLAG_FMA4 (1<<13)
69 #define SPA_CPU_FLAG_CMOV (1<<14)
70 #define SPA_CPU_FLAG_AVX2 (1<<15)
71 #define SPA_CPU_FLAG_FMA3 (1<<16)
72 #define SPA_CPU_FLAG_BMI1 (1<<17)
73 #define SPA_CPU_FLAG_BMI2 (1<<18)
74 #define SPA_CPU_FLAG_AVX512 (1<<19)
75 #define SPA_CPU_FLAG_SLOW_UNALIGNED (1<<20)
77 /* PPC specific */
78 #define SPA_CPU_FLAG_ALTIVEC (1<<0)
79 #define SPA_CPU_FLAG_VSX (1<<1)
80 #define SPA_CPU_FLAG_POWER8 (1<<2)
82 /* ARM specific */
83 #define SPA_CPU_FLAG_ARMV5TE (1 << 0)
84 #define SPA_CPU_FLAG_ARMV6 (1 << 1)
85 #define SPA_CPU_FLAG_ARMV6T2 (1 << 2)
86 #define SPA_CPU_FLAG_VFP (1 << 3)
87 #define SPA_CPU_FLAG_VFPV3 (1 << 4)
88 #define SPA_CPU_FLAG_NEON (1 << 5)
89 #define SPA_CPU_FLAG_ARMV8 (1 << 6)
90 
91 #define SPA_CPU_FORCE_AUTODETECT ((uint32_t)-1)
92 
93 #define SPA_CPU_VM_NONE (0)
94 #define SPA_CPU_VM_OTHER (1 << 0)
95 #define SPA_CPU_VM_KVM (1 << 1)
96 #define SPA_CPU_VM_QEMU (1 << 2)
97 #define SPA_CPU_VM_BOCHS (1 << 3)
98 #define SPA_CPU_VM_XEN (1 << 4)
99 #define SPA_CPU_VM_UML (1 << 5)
100 #define SPA_CPU_VM_VMWARE (1 << 6)
101 #define SPA_CPU_VM_ORACLE (1 << 7)
102 #define SPA_CPU_VM_MICROSOFT (1 << 8)
103 #define SPA_CPU_VM_ZVM (1 << 9)
104 #define SPA_CPU_VM_PARALLELS (1 << 10)
105 #define SPA_CPU_VM_BHYVE (1 << 11)
106 #define SPA_CPU_VM_QNX (1 << 12)
107 #define SPA_CPU_VM_ACRN (1 << 13)
108 #define SPA_CPU_VM_POWERVM (1 << 14)
109 
116 #define SPA_VERSION_CPU_METHODS 1
117  uint32_t version;
118 
120  uint32_t (*get_flags) (void *object);
121 
123  int (*force_flags) (void *object, uint32_t flags);
124 
126  uint32_t (*get_count) (void *object);
127 
129  uint32_t (*get_max_align) (void *object);
130 
131  /* check if running in a VM. Since:1 */
132  uint32_t (*get_vm_type) (void *object);
133 };
134 
135 #define spa_cpu_method(o,method,version,...) \
136 ({ \
137  int _res = -ENOTSUP; \
138  struct spa_cpu *_c = o; \
139  spa_interface_call_res(&_c->iface, \
140  struct spa_cpu_methods, _res, \
141  method, version, ##__VA_ARGS__); \
142  _res; \
143 })
144 #define spa_cpu_get_flags(c) spa_cpu_method(c, get_flags, 0)
145 #define spa_cpu_force_flags(c,f) spa_cpu_method(c, force_flags, 0, f)
146 #define spa_cpu_get_count(c) spa_cpu_method(c, get_count, 0)
147 #define spa_cpu_get_max_align(c) spa_cpu_method(c, get_max_align, 0)
148 #define spa_cpu_get_vm_type(c) spa_cpu_method(c, get_vm_type, 1)
149 
151 #define SPA_KEY_CPU_FORCE "cpu.force"
152 #define SPA_KEY_CPU_VM_TYPE "cpu.vm.type"
158 #ifdef __cplusplus
159 } /* extern "C" */
160 #endif
161 
162 #endif /* SPA_CPU_H */
spa_interface
Definition: hook.h:146
spa_cpu
Definition: cpu.h:52
spa_cpu::iface
struct spa_interface iface
Definition: cpu.h:52
spa_cpu_methods
methods
Definition: cpu.h:113
spa_cpu_methods::version
uint32_t version
Definition: cpu.h:117
spa_cpu_methods::get_flags
uint32_t(* get_flags)(void *object)
get CPU flags
Definition: cpu.h:120
defs.h
spa_cpu_methods::get_max_align
uint32_t(* get_max_align)(void *object)
get maximum required alignment of data
Definition: cpu.h:129
hook.h
spa_cpu_methods::get_count
uint32_t(* get_count)(void *object)
get number of CPU cores
Definition: cpu.h:126
spa_cpu_methods::force_flags
int(* force_flags)(void *object, uint32_t flags)
force CPU flags, use SPA_CPU_FORCE_AUTODETECT to autodetect CPU flags
Definition: cpu.h:123
spa_cpu_methods::get_vm_type
uint32_t(* get_vm_type)(void *object)
Definition: cpu.h:132