1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2022 Intel Corporation 3 * Copyright(c) 2024 Advanced Micro Devices, Inc. 4 */ 5 6 #ifndef POWER_UNCORE_OPS_H 7 #define POWER_UNCORE_OPS_H 8 9 /** 10 * @file 11 * Uncore Frequency Management 12 */ 13 14 #include <rte_compat.h> 15 #include <rte_common.h> 16 17 #define RTE_POWER_UNCORE_DRIVER_NAMESZ 24 18 19 /** 20 * Initialize uncore frequency management for specific die on a package. 21 * It will get the available frequencies and prepare to set new die frequencies. 22 * 23 * This function should NOT be called in the fast path. 24 * 25 * @param pkg 26 * Package number. 27 * Each physical CPU in a system is referred to as a package. 28 * @param die 29 * Die number. 30 * Each package can have several dies connected together via the uncore mesh. 31 * 32 * @return 33 * - 0 on success. 34 * - Negative on error. 35 */ 36 typedef int (*rte_power_uncore_init_t)(unsigned int pkg, unsigned int die); 37 38 /** 39 * Exit uncore frequency management on a specific die on a package. 40 * It will restore uncore min and* max values to previous values 41 * before initialization of API. 42 * 43 * This function should NOT be called in the fast path. 44 * 45 * @param pkg 46 * Package number. 47 * Each physical CPU in a system is referred to as a package. 48 * @param die 49 * Die number. 50 * Each package can have several dies connected together via the uncore mesh. 51 * 52 * @return 53 * - 0 on success. 54 * - Negative on error. 55 */ 56 typedef int (*rte_power_uncore_exit_t)(unsigned int pkg, unsigned int die); 57 58 /** 59 * Return the current index of available frequencies of a specific die on a package. 60 * It should be protected outside of this function for threadsafe. 61 * 62 * This function should NOT be called in the fast path. 63 * 64 * @param pkg 65 * Package number. 66 * Each physical CPU in a system is referred to as a package. 67 * @param die 68 * Die number. 69 * Each package can have several dies connected together via the uncore mesh. 70 * 71 * @return 72 * The current index of available frequencies. 73 * If error, it will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)'. 74 */ 75 typedef uint32_t (*rte_power_get_uncore_freq_t)(unsigned int pkg, unsigned int die); 76 77 /** 78 * Set minimum and maximum uncore frequency for specified die on a package 79 * to specified index value. 80 * It should be protected outside of this function for threadsafe. 81 * 82 * This function should NOT be called in the fast path. 83 * 84 * @param pkg 85 * Package number. 86 * Each physical CPU in a system is referred to as a package. 87 * @param die 88 * Die number. 89 * Each package can have several dies connected together via the uncore mesh. 90 * @param index 91 * The index of available frequencies. 92 * 93 * @return 94 * - 1 on success with frequency changed. 95 * - 0 on success without frequency changed. 96 * - Negative on error. 97 */ 98 typedef int (*rte_power_set_uncore_freq_t)(unsigned int pkg, unsigned int die, uint32_t index); 99 100 /** 101 * Return the list length of available frequencies in the index array. 102 * 103 * This function should NOT be called in the fast path. 104 * 105 * @param pkg 106 * Package number. 107 * Each physical CPU in a system is referred to as a package. 108 * @param die 109 * Die number. 110 * Each package can have several dies connected together via the uncore mesh. 111 * @param index 112 * The index of available frequencies. 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_set_uncore_freq_t)(unsigned int pkg, unsigned int die, uint32_t index); 120 121 /** 122 * Return the list length of available frequencies in the index array. 123 * 124 * This function should NOT be called in the fast path. 125 * 126 * @param pkg 127 * Package number. 128 * Each physical CPU in a system is referred to as a package. 129 * @param die 130 * Die number. 131 * Each package can have several dies connected together via the uncore mesh. 132 * 133 * @return 134 * - The number of available index's in frequency array. 135 * - Negative on error. 136 */ 137 typedef int (*rte_power_uncore_get_num_freqs_t)(unsigned int pkg, unsigned int die); 138 139 /** 140 * Return the list of available frequencies in the index array. 141 * 142 * This function should NOT be called in the fast path. 143 * 144 * @param pkg 145 * Package number. 146 * Each physical CPU in a system is referred to as a package. 147 * @param die 148 * Die number. 149 * Each package can have several dies connected together via the uncore mesh. 150 * @param freqs 151 * The buffer array to save the frequencies. 152 * @param num 153 * The number of frequencies to get. 154 * 155 * @return 156 * - The number of available index's in frequency array. 157 * - Negative on error. 158 */ 159 typedef int (*rte_power_uncore_freqs_t)(unsigned int pkg, unsigned int die, 160 uint32_t *freqs, uint32_t num); 161 /** 162 * Function pointers for generic frequency change functions. 163 * 164 * @param pkg 165 * Package number. 166 * Each physical CPU in a system is referred to as a package. 167 * @param die 168 * Die number. 169 * Each package can have several dies connected together via the uncore mesh. 170 * 171 * @return 172 * - 1 on success with frequency changed. 173 * - 0 on success without frequency changed. 174 * - Negative on error. 175 */ 176 typedef int (*rte_power_uncore_freq_change_t)(unsigned int pkg, unsigned int die); 177 178 /** 179 * Return the number of packages (CPUs) on a system 180 * by parsing the uncore sysfs directory. 181 * 182 * This function should NOT be called in the fast path. 183 * 184 * @return 185 * - Zero on error. 186 * - Number of package on system on success. 187 */ 188 typedef unsigned int (*rte_power_uncore_get_num_pkgs_t)(void); 189 190 /** 191 * Return the number of dies for pakckages (CPUs) specified 192 * from parsing the uncore sysfs directory. 193 * 194 * This function should NOT be called in the fast path. 195 * 196 * @param pkg 197 * Package number. 198 * Each physical CPU in a system is referred to as a package. 199 * 200 * @return 201 * - Zero on error. 202 * - Number of dies for package on sucecss. 203 */ 204 typedef unsigned int (*rte_power_uncore_get_num_dies_t)(unsigned int pkg); 205 typedef void (*rte_power_uncore_driver_cb_t)(void); 206 207 /** Structure defining uncore power operations structure */ 208 struct rte_power_uncore_ops { 209 RTE_TAILQ_ENTRY(rte_power_uncore_ops) next; /**< Next in list. */ 210 char name[RTE_POWER_UNCORE_DRIVER_NAMESZ]; /**< power mgmt driver. */ 211 rte_power_uncore_driver_cb_t cb; /**< Driver specific callbacks. */ 212 rte_power_uncore_init_t init; /**< Initialize power management. */ 213 rte_power_uncore_exit_t exit; /**< Exit power management. */ 214 rte_power_uncore_get_num_pkgs_t get_num_pkgs; 215 rte_power_uncore_get_num_dies_t get_num_dies; 216 rte_power_uncore_get_num_freqs_t get_num_freqs; /**< Number of available frequencies. */ 217 rte_power_uncore_freqs_t get_avail_freqs; /**< Get the available frequencies. */ 218 rte_power_get_uncore_freq_t get_freq; /**< Get frequency index. */ 219 rte_power_set_uncore_freq_t set_freq; /**< Set frequency index. */ 220 rte_power_uncore_freq_change_t freq_max; /**< Scale up frequency to highest. */ 221 rte_power_uncore_freq_change_t freq_min; /**< Scale up frequency to lowest. */ 222 }; 223 224 /** 225 * Register power uncore frequency operations. 226 * @param ops 227 * Pointer to an ops structure to register. 228 * @return 229 * - 0: Success. 230 * - Negative on error. 231 */ 232 __rte_internal 233 int rte_power_register_uncore_ops(struct rte_power_uncore_ops *ops); 234 235 /** 236 * Macro to statically register the ops of an uncore driver. 237 */ 238 #define RTE_POWER_REGISTER_UNCORE_OPS(ops) \ 239 RTE_INIT(power_hdlr_init_uncore_##ops) \ 240 { \ 241 rte_power_register_uncore_ops(&ops); \ 242 } 243 244 #endif /* POWER_UNCORE_OPS_H */ 245