1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 * Copyright(c) 2024 Advanced Micro Devices, Inc. 4 */ 5 6 #ifndef POWER_CPUFREQ_H 7 #define POWER_CPUFREQ_H 8 9 /** 10 * @file 11 * CPU Frequency Management 12 */ 13 14 #include <rte_common.h> 15 #include <rte_log.h> 16 #include <rte_compat.h> 17 18 #define RTE_POWER_DRIVER_NAMESZ 24 19 20 /** 21 * Initialize power management for a specific lcore. If rte_power_set_env() has 22 * not been called then an auto-detect of the environment will start and 23 * initialise the corresponding resources. 24 * 25 * @param lcore_id 26 * lcore id. 27 * 28 * @return 29 * - 0 on success. 30 * - Negative on error. 31 */ 32 typedef int (*rte_power_cpufreq_init_t)(unsigned int lcore_id); 33 34 /** 35 * Exit power management on a specific lcore. This will call the environment 36 * dependent exit function. 37 * 38 * @param lcore_id 39 * lcore id. 40 * 41 * @return 42 * - 0 on success. 43 * - Negative on error. 44 */ 45 typedef int (*rte_power_cpufreq_exit_t)(unsigned int lcore_id); 46 47 /** 48 * Check if a specific power management environment type is supported on a 49 * currently running system. 50 * 51 * @return 52 * - 1 if supported 53 * - 0 if unsupported 54 * - -1 if error, with rte_errno indicating reason for error. 55 */ 56 typedef int (*rte_power_check_env_support_t)(void); 57 58 /** 59 * Get the available frequencies of a specific lcore. 60 * Function pointer definition. Review each environments 61 * specific documentation for usage. 62 * 63 * @param lcore_id 64 * lcore id. 65 * @param freqs 66 * The buffer array to save the frequencies. 67 * @param num 68 * The number of frequencies to get. 69 * 70 * @return 71 * The number of available frequencies. 72 */ 73 typedef uint32_t (*rte_power_freqs_t)(unsigned int lcore_id, 74 uint32_t *freqs, uint32_t num); 75 76 /** 77 * Return the current index of available frequencies of a specific lcore. 78 * Function pointer definition. Review each environments 79 * specific documentation for usage. 80 * 81 * @param lcore_id 82 * lcore id. 83 * 84 * @return 85 * The current index of available frequencies. 86 */ 87 typedef uint32_t (*rte_power_get_freq_t)(unsigned int lcore_id); 88 89 /** 90 * Set the new frequency for a specific lcore by indicating the index of 91 * available frequencies. 92 * Function pointer definition. Review each environments 93 * specific documentation for usage. 94 * 95 * @param lcore_id 96 * lcore id. 97 * @param index 98 * The index of available frequencies. 99 * 100 * @return 101 * - 1 on success with frequency changed. 102 * - 0 on success without frequency changed. 103 * - Negative on error. 104 */ 105 typedef int (*rte_power_set_freq_t)(unsigned int lcore_id, uint32_t index); 106 107 /** 108 * Function pointer definition for generic frequency change functions. Review 109 * each environments specific documentation for usage. 110 * 111 * @param lcore_id 112 * lcore id. 113 * 114 * @return 115 * - 1 on success with frequency changed. 116 * - 0 on success without frequency changed. 117 * - Negative on error. 118 */ 119 typedef int (*rte_power_freq_change_t)(unsigned int lcore_id); 120 121 /** 122 * Function pointer definition for generic frequency change functions. Review 123 * each environments specific documentation for usage. 124 * 125 * @param lcore_id 126 * lcore id. 127 * 128 * @return 129 * - 1 on success with frequency changed. 130 * - 0 on success without frequency changed. 131 * - Negative on error. 132 */ 133 134 /** 135 * Power capabilities summary. 136 */ 137 struct rte_power_core_capabilities { 138 union { 139 uint64_t capabilities; 140 struct { 141 uint64_t turbo:1; /**< Turbo can be enabled. */ 142 uint64_t priority:1; /**< SST-BF high freq core */ 143 }; 144 }; 145 }; 146 147 typedef int (*rte_power_get_capabilities_t)(unsigned int lcore_id, 148 struct rte_power_core_capabilities *caps); 149 150 /** Structure defining core power operations structure */ 151 struct rte_power_cpufreq_ops { 152 RTE_TAILQ_ENTRY(rte_power_cpufreq_ops) next; /**< Next in list. */ 153 char name[RTE_POWER_DRIVER_NAMESZ]; /**< power mgmt driver. */ 154 rte_power_cpufreq_init_t init; /**< Initialize power management. */ 155 rte_power_cpufreq_exit_t exit; /**< Exit power management. */ 156 rte_power_check_env_support_t check_env_support;/**< verify env is supported. */ 157 rte_power_freqs_t get_avail_freqs; /**< Get the available frequencies. */ 158 rte_power_get_freq_t get_freq; /**< Get frequency index. */ 159 rte_power_set_freq_t set_freq; /**< Set frequency index. */ 160 rte_power_freq_change_t freq_up; /**< Scale up frequency. */ 161 rte_power_freq_change_t freq_down; /**< Scale down frequency. */ 162 rte_power_freq_change_t freq_max; /**< Scale up frequency to highest. */ 163 rte_power_freq_change_t freq_min; /**< Scale up frequency to lowest. */ 164 rte_power_freq_change_t turbo_status; /**< Get Turbo status. */ 165 rte_power_freq_change_t enable_turbo; /**< Enable Turbo. */ 166 rte_power_freq_change_t disable_turbo; /**< Disable Turbo. */ 167 rte_power_get_capabilities_t get_caps; /**< power capabilities. */ 168 }; 169 170 /** 171 * Register power cpu frequency operations. 172 * 173 * @param ops 174 * Pointer to an ops structure to register. 175 * @return 176 * - 0: Success. 177 * - Negative on error. 178 */ 179 __rte_internal 180 int rte_power_register_cpufreq_ops(struct rte_power_cpufreq_ops *ops); 181 182 /** 183 * Macro to statically register the ops of a cpufreq driver. 184 */ 185 #define RTE_POWER_REGISTER_CPUFREQ_OPS(ops) \ 186 RTE_INIT(power_hdlr_init_##ops) \ 187 { \ 188 rte_power_register_cpufreq_ops(&ops); \ 189 } 190 191 #endif /* POWER_CPUFREQ_H */ 192