xref: /dpdk/lib/eal/include/generic/rte_cpuflags.h (revision 86a308fffa7752e460dcc9d8dba632f21ec3a8f3)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_CPUFLAGS_H_
699a2dd95SBruce Richardson #define _RTE_CPUFLAGS_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  * Architecture specific API to determine available CPU features at runtime.
1199a2dd95SBruce Richardson  */
1299a2dd95SBruce Richardson 
1399a2dd95SBruce Richardson #include "rte_common.h"
1499a2dd95SBruce Richardson #include <errno.h>
1599a2dd95SBruce Richardson 
1699a2dd95SBruce Richardson #include <rte_compat.h>
1799a2dd95SBruce Richardson 
18*719834a6SMattias Rönnblom #ifdef __cplusplus
19*719834a6SMattias Rönnblom extern "C" {
20*719834a6SMattias Rönnblom #endif
21*719834a6SMattias Rönnblom 
2299a2dd95SBruce Richardson /**
2399a2dd95SBruce Richardson  * Structure used to describe platform-specific intrinsics that may or may not
2499a2dd95SBruce Richardson  * be supported at runtime.
2599a2dd95SBruce Richardson  */
2699a2dd95SBruce Richardson struct rte_cpu_intrinsics {
2799a2dd95SBruce Richardson 	uint32_t power_monitor : 1;
2899a2dd95SBruce Richardson 	/**< indicates support for rte_power_monitor function */
2999a2dd95SBruce Richardson 	uint32_t power_pause : 1;
3099a2dd95SBruce Richardson 	/**< indicates support for rte_power_pause function */
3166834f29SAnatoly Burakov 	uint32_t power_monitor_multi : 1;
3266834f29SAnatoly Burakov 	/**< indicates support for rte_power_monitor_multi function */
3399a2dd95SBruce Richardson };
3499a2dd95SBruce Richardson 
3599a2dd95SBruce Richardson /**
3699a2dd95SBruce Richardson  * Check CPU support for various intrinsics at runtime.
3799a2dd95SBruce Richardson  *
3899a2dd95SBruce Richardson  * @param intrinsics
3999a2dd95SBruce Richardson  *     Pointer to a structure to be filled.
4099a2dd95SBruce Richardson  */
4199a2dd95SBruce Richardson void
4299a2dd95SBruce Richardson rte_cpu_get_intrinsics_support(struct rte_cpu_intrinsics *intrinsics);
4399a2dd95SBruce Richardson 
4499a2dd95SBruce Richardson /**
4599a2dd95SBruce Richardson  * Enumeration of all CPU features supported
4699a2dd95SBruce Richardson  */
4799a2dd95SBruce Richardson __extension__
4899a2dd95SBruce Richardson enum rte_cpu_flag_t;
4999a2dd95SBruce Richardson 
5099a2dd95SBruce Richardson /**
5199a2dd95SBruce Richardson  * Get name of CPU flag
5299a2dd95SBruce Richardson  *
5399a2dd95SBruce Richardson  * @param feature
5499a2dd95SBruce Richardson  *     CPU flag ID
5599a2dd95SBruce Richardson  * @return
5699a2dd95SBruce Richardson  *     flag name
5799a2dd95SBruce Richardson  *     NULL if flag ID is invalid
5899a2dd95SBruce Richardson  */
5999a2dd95SBruce Richardson __extension__
6099a2dd95SBruce Richardson const char *
6199a2dd95SBruce Richardson rte_cpu_get_flag_name(enum rte_cpu_flag_t feature);
6299a2dd95SBruce Richardson 
6399a2dd95SBruce Richardson /**
6499a2dd95SBruce Richardson  * Function for checking a CPU flag availability
6599a2dd95SBruce Richardson  *
6699a2dd95SBruce Richardson  * @param feature
6799a2dd95SBruce Richardson  *     CPU flag to query CPU for
6899a2dd95SBruce Richardson  * @return
6999a2dd95SBruce Richardson  *     1 if flag is available
7099a2dd95SBruce Richardson  *     0 if flag is not available
7199a2dd95SBruce Richardson  *     -ENOENT if flag is invalid
7299a2dd95SBruce Richardson  */
7399a2dd95SBruce Richardson __extension__
7499a2dd95SBruce Richardson int
7599a2dd95SBruce Richardson rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature);
7699a2dd95SBruce Richardson 
7799a2dd95SBruce Richardson /**
7899a2dd95SBruce Richardson  * This function checks that the currently used CPU supports the CPU features
7999a2dd95SBruce Richardson  * that were specified at compile time. It is called automatically within the
8099a2dd95SBruce Richardson  * EAL, so does not need to be used by applications.  This version returns a
8199a2dd95SBruce Richardson  * result so that decisions may be made (for instance, graceful shutdowns).
8299a2dd95SBruce Richardson  */
8399a2dd95SBruce Richardson int
8499a2dd95SBruce Richardson rte_cpu_is_supported(void);
8599a2dd95SBruce Richardson 
8699a2dd95SBruce Richardson /**
8799a2dd95SBruce Richardson  * This function attempts to retrieve a value from the auxiliary vector.
8899a2dd95SBruce Richardson  * If it is unsuccessful, the result will be 0, and errno will be set.
8999a2dd95SBruce Richardson  *
9099a2dd95SBruce Richardson  * @return A value from the auxiliary vector.  When the value is 0, check
9199a2dd95SBruce Richardson  * errno to determine if an error occurred.
9299a2dd95SBruce Richardson  */
9399a2dd95SBruce Richardson unsigned long
9499a2dd95SBruce Richardson rte_cpu_getauxval(unsigned long type);
9599a2dd95SBruce Richardson 
9699a2dd95SBruce Richardson /**
9799a2dd95SBruce Richardson  * This function retrieves a value from the auxiliary vector, and compares it
9899a2dd95SBruce Richardson  * as a string against the value retrieved.
9999a2dd95SBruce Richardson  *
10099a2dd95SBruce Richardson  * @return The result of calling strcmp() against the value retrieved from
10199a2dd95SBruce Richardson  * the auxiliary vector.  When the value is 0 (meaning a match is found),
10299a2dd95SBruce Richardson  * check errno to determine if an error occurred.
10399a2dd95SBruce Richardson  */
10499a2dd95SBruce Richardson int
10599a2dd95SBruce Richardson rte_cpu_strcmp_auxval(unsigned long type, const char *str);
10699a2dd95SBruce Richardson 
107*719834a6SMattias Rönnblom #ifdef __cplusplus
108*719834a6SMattias Rönnblom }
109*719834a6SMattias Rönnblom #endif
110*719834a6SMattias Rönnblom 
11199a2dd95SBruce Richardson #endif /* _RTE_CPUFLAGS_H_ */
112