2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
27 #include "amd_shared.h"
28 #include <linux/module.h>
29 #include <linux/moduleparam.h>
30 #include "amdgpu_pm.h"
31 #include <drm/amdgpu_drm.h>
32 #include "amdgpu_powerplay.h"
37 static int amdgpu_pp_early_init(void *handle)
39 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
40 struct amd_powerplay *amd_pp;
43 amd_pp = &(adev->powerplay);
44 amd_pp->pp_handle = (void *)adev;
46 switch (adev->asic_type) {
57 amd_pp->cgs_device = amdgpu_cgs_create_device(adev);
58 amd_pp->ip_funcs = &pp_ip_funcs;
59 amd_pp->pp_funcs = &pp_dpm_funcs;
61 /* These chips don't have powerplay implemenations */
62 #ifdef CONFIG_DRM_AMDGPU_SI
68 amd_pp->ip_funcs = &si_dpm_ip_funcs;
69 amd_pp->pp_funcs = &si_dpm_funcs;
72 #ifdef CONFIG_DRM_AMDGPU_CIK
75 if (amdgpu_dpm == -1) {
76 amd_pp->ip_funcs = &ci_dpm_ip_funcs;
77 amd_pp->pp_funcs = &ci_dpm_funcs;
79 amd_pp->cgs_device = amdgpu_cgs_create_device(adev);
80 amd_pp->ip_funcs = &pp_ip_funcs;
81 amd_pp->pp_funcs = &pp_dpm_funcs;
87 amd_pp->ip_funcs = &kv_dpm_ip_funcs;
88 amd_pp->pp_funcs = &kv_dpm_funcs;
96 if (adev->powerplay.ip_funcs->early_init)
97 ret = adev->powerplay.ip_funcs->early_init(adev);
103 static int amdgpu_pp_late_init(void *handle)
106 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
108 if (adev->powerplay.ip_funcs->late_init)
109 ret = adev->powerplay.ip_funcs->late_init(
110 adev->powerplay.pp_handle);
115 static int amdgpu_pp_sw_init(void *handle)
118 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
120 if (adev->powerplay.ip_funcs->sw_init)
121 ret = adev->powerplay.ip_funcs->sw_init(
122 adev->powerplay.pp_handle);
127 static int amdgpu_pp_sw_fini(void *handle)
130 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
132 if (adev->powerplay.ip_funcs->sw_fini)
133 ret = adev->powerplay.ip_funcs->sw_fini(
134 adev->powerplay.pp_handle);
141 static int amdgpu_pp_hw_init(void *handle)
144 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
146 if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
147 amdgpu_ucode_init_bo(adev);
149 if (adev->powerplay.ip_funcs->hw_init)
150 ret = adev->powerplay.ip_funcs->hw_init(
151 adev->powerplay.pp_handle);
156 static int amdgpu_pp_hw_fini(void *handle)
159 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
161 if (adev->powerplay.ip_funcs->hw_fini)
162 ret = adev->powerplay.ip_funcs->hw_fini(
163 adev->powerplay.pp_handle);
165 if (adev->firmware.load_type == AMDGPU_FW_LOAD_SMU)
166 amdgpu_ucode_fini_bo(adev);
171 static void amdgpu_pp_late_fini(void *handle)
173 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
175 if (adev->powerplay.ip_funcs->late_fini)
176 adev->powerplay.ip_funcs->late_fini(
177 adev->powerplay.pp_handle);
179 if (adev->powerplay.cgs_device)
180 amdgpu_cgs_destroy_device(adev->powerplay.cgs_device);
183 static int amdgpu_pp_suspend(void *handle)
186 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
188 if (adev->powerplay.ip_funcs->suspend)
189 ret = adev->powerplay.ip_funcs->suspend(
190 adev->powerplay.pp_handle);
194 static int amdgpu_pp_resume(void *handle)
197 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
199 if (adev->powerplay.ip_funcs->resume)
200 ret = adev->powerplay.ip_funcs->resume(
201 adev->powerplay.pp_handle);
205 static int amdgpu_pp_set_clockgating_state(void *handle,
206 enum amd_clockgating_state state)
209 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
211 if (adev->powerplay.ip_funcs->set_clockgating_state)
212 ret = adev->powerplay.ip_funcs->set_clockgating_state(
213 adev->powerplay.pp_handle, state);
217 static int amdgpu_pp_set_powergating_state(void *handle,
218 enum amd_powergating_state state)
221 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
223 if (adev->powerplay.ip_funcs->set_powergating_state)
224 ret = adev->powerplay.ip_funcs->set_powergating_state(
225 adev->powerplay.pp_handle, state);
230 static bool amdgpu_pp_is_idle(void *handle)
233 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
235 if (adev->powerplay.ip_funcs->is_idle)
236 ret = adev->powerplay.ip_funcs->is_idle(
237 adev->powerplay.pp_handle);
241 static int amdgpu_pp_wait_for_idle(void *handle)
244 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
246 if (adev->powerplay.ip_funcs->wait_for_idle)
247 ret = adev->powerplay.ip_funcs->wait_for_idle(
248 adev->powerplay.pp_handle);
252 static int amdgpu_pp_soft_reset(void *handle)
255 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
257 if (adev->powerplay.ip_funcs->soft_reset)
258 ret = adev->powerplay.ip_funcs->soft_reset(
259 adev->powerplay.pp_handle);
263 static const struct amd_ip_funcs amdgpu_pp_ip_funcs = {
264 .name = "amdgpu_powerplay",
265 .early_init = amdgpu_pp_early_init,
266 .late_init = amdgpu_pp_late_init,
267 .sw_init = amdgpu_pp_sw_init,
268 .sw_fini = amdgpu_pp_sw_fini,
269 .hw_init = amdgpu_pp_hw_init,
270 .hw_fini = amdgpu_pp_hw_fini,
271 .late_fini = amdgpu_pp_late_fini,
272 .suspend = amdgpu_pp_suspend,
273 .resume = amdgpu_pp_resume,
274 .is_idle = amdgpu_pp_is_idle,
275 .wait_for_idle = amdgpu_pp_wait_for_idle,
276 .soft_reset = amdgpu_pp_soft_reset,
277 .set_clockgating_state = amdgpu_pp_set_clockgating_state,
278 .set_powergating_state = amdgpu_pp_set_powergating_state,
281 const struct amdgpu_ip_block_version amdgpu_pp_ip_block =
283 .type = AMD_IP_BLOCK_TYPE_SMC,
287 .funcs = &amdgpu_pp_ip_funcs,