xref: /dpdk/drivers/power/amd_uncore/amd_uncore.h (revision da4d64d0e80343d54ec22b583c6cc606826e73ba)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2024 Advanced Micro Devices, Inc.
3  */
4 
5 #ifndef POWER_AMD_UNCORE_H
6 #define POWER_AMD_UNCORE_H
7 
8 /**
9  * @file
10  * AMD Uncore Frequency Management
11  */
12 
13 #include "power_uncore_ops.h"
14 
15 /**
16  * Initialize uncore frequency management for specific die on a package.
17  * It will get the available frequencies and prepare to set new die frequencies.
18  *
19  * This function should NOT be called in the fast path.
20  *
21  * @param pkg
22  *  Package number.
23  *  Each physical CPU in a system is referred to as a package.
24  * @param die
25  *  Die number.
26  *  Each package can have several dies connected together via the uncore mesh.
27  *
28  * @return
29  *  - 0 on success.
30  *  - Negative on error.
31  */
32 int
33 power_amd_uncore_init(unsigned int pkg, unsigned int die);
34 
35 /**
36  * Exit uncore frequency management on a specific die on a package.
37  * It will restore uncore min and* max values to previous values
38  * before initialization of API.
39  *
40  * This function should NOT be called in the fast path.
41  *
42  * @param pkg
43  *  Package number.
44  *  Each physical CPU in a system is referred to as a package.
45  * @param die
46  *  Die number.
47  *  Each package can have several dies connected together via the uncore mesh.
48  *
49  * @return
50  *  - 0 on success.
51  *  - Negative on error.
52  */
53 int
54 power_amd_uncore_exit(unsigned int pkg, unsigned int die);
55 
56 /**
57  * Return the current index of available frequencies of a specific die on a package.
58  * It should be protected outside of this function for threadsafe.
59  *
60  * This function should NOT be called in the fast path.
61  *
62  * @param pkg
63  *  Package number.
64  *  Each physical CPU in a system is referred to as a package.
65  * @param die
66  *  Die number.
67  *  Each package can have several dies connected together via the uncore mesh.
68  *
69  * @return
70  *  The current index of available frequencies.
71  *  If error, it will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)'.
72  */
73 uint32_t
74 power_get_amd_uncore_freq(unsigned int pkg, unsigned int die);
75 
76 /**
77  * Set minimum and maximum uncore frequency for specified die on a package
78  * to specified index value.
79  * It should be protected outside of this function for threadsafe.
80  *
81  * This function should NOT be called in the fast path.
82  *
83  * @param pkg
84  *  Package number.
85  *  Each physical CPU in a system is referred to as a package.
86  * @param die
87  *  Die number.
88  *  Each package can have several dies connected together via the uncore mesh.
89  * @param index
90  *  The index of available frequencies.
91  *
92  * @return
93  *  - 1 on success with frequency changed.
94  *  - 0 on success without frequency changed.
95  *  - Negative on error.
96  */
97 int
98 power_set_amd_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index);
99 
100 /**
101  * Set minimum and maximum uncore frequency for specified die on a package
102  * to maximum value according to the available frequencies.
103  * It should be protected outside of this function for threadsafe.
104  *
105  * This function should NOT be called in the fast path.
106  *
107  * @param pkg
108  *  Package number.
109  *  Each physical CPU in a system is referred to as a package.
110  * @param die
111  *  Die number.
112  *  Each package can have several dies connected together via the uncore mesh.
113  *
114  * @return
115  *  - 1 on success with frequency changed.
116  *  - 0 on success without frequency changed.
117  *  - Negative on error.
118  */
119 int
120 power_amd_uncore_freq_max(unsigned int pkg, unsigned int die);
121 
122 /**
123  * Set minimum and maximum uncore frequency for specified die on a package
124  * to minimum value according to the available frequencies.
125  * It should be protected outside of this function for threadsafe.
126  *
127  * This function should NOT be called in the fast path.
128  *
129  * @param pkg
130  *  Package number.
131  *  Each physical CPU in a system is referred to as a package.
132  * @param die
133  *  Die number.
134  *  Each package can have several dies connected together via the uncore mesh.
135  *
136  * @return
137  *  - 1 on success with frequency changed.
138  *  - 0 on success without frequency changed.
139  *  - Negative on error.
140  */
141 int
142 power_amd_uncore_freq_min(unsigned int pkg, unsigned int die);
143 
144 /**
145  * Return the list of available frequencies in the index array.
146  *
147  * This function should NOT be called in the fast path.
148  *
149  * @param pkg
150  *  Package number.
151  *  Each physical CPU in a system is referred to as a package.
152  * @param die
153  *  Die number.
154  *  Each package can have several dies connected together via the uncore mesh.
155  * @param freqs
156  *  The buffer array to save the frequencies.
157  * @param num
158  *  The number of frequencies to get.
159  *
160  * @return
161  *  - The number of available index's in frequency array.
162  *  - Negative on error.
163  */
164 int
165 power_amd_uncore_freqs(unsigned int pkg, unsigned int die,
166 		unsigned int *freqs, unsigned int num);
167 
168 /**
169  * Return the list length of available frequencies in the index array.
170  *
171  * This function should NOT be called in the fast path.
172  *
173  * @param pkg
174  *  Package number.
175  *  Each physical CPU in a system is referred to as a package.
176  * @param die
177  *  Die number.
178  *  Each package can have several dies connected together via the uncore mesh.
179  *
180  * @return
181  *  - The number of available index's in frequency array.
182  *  - Negative on error.
183  */
184 int
185 power_amd_uncore_get_num_freqs(unsigned int pkg, unsigned int die);
186 
187 /**
188  * Return the number of packages (CPUs) on a system
189  * by parsing the uncore sysfs directory.
190  *
191  * This function should NOT be called in the fast path.
192  *
193  * @return
194  *  - Zero on error.
195  *  - Number of package on system on success.
196  */
197 unsigned int
198 power_amd_uncore_get_num_pkgs(void);
199 
200 /**
201  * Return the number of dies for pakckages (CPUs) specified
202  * from parsing the uncore sysfs directory.
203  *
204  * This function should NOT be called in the fast path.
205  *
206  * @param pkg
207  *  Package number.
208  *  Each physical CPU in a system is referred to as a package.
209  *
210  * @return
211  *  - Zero on error.
212  *  - Number of dies for package on sucecss.
213  */
214 unsigned int
215 power_amd_uncore_get_num_dies(unsigned int pkg);
216 
217 #endif /* POWER_INTEL_UNCORE_H */
218