[PATCH] drm/amdgpu: Pass adev pointers to functions
Alex Deucher
alexdeucher at gmail.com
Mon Jun 30 15:07:13 UTC 2025
On Mon, Jun 30, 2025 at 10:03 AM Lijo Lazar <lijo.lazar at amd.com> wrote:
>
> Pass amdgpu device context instead of drm device context to some
> amdgpu_device_* functions. DRM device context is not required in those
> functions. No functional change.
>
> Signed-off-by: Lijo Lazar <lijo.lazar at amd.com>
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu.h | 24 ++++----
> drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 8 +--
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 65 ++++++++++------------
> drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 15 +++--
> drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 +-
> drivers/gpu/drm/amd/pm/amdgpu_pm.c | 4 +-
> 6 files changed, 57 insertions(+), 63 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index f9c981a3ea05..ebc1a2203492 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1583,16 +1583,16 @@ void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
>
> int amdgpu_device_mode1_reset(struct amdgpu_device *adev);
> int amdgpu_device_link_reset(struct amdgpu_device *adev);
> -bool amdgpu_device_supports_atpx(struct drm_device *dev);
> -bool amdgpu_device_supports_px(struct drm_device *dev);
> -bool amdgpu_device_supports_boco(struct drm_device *dev);
> -bool amdgpu_device_supports_smart_shift(struct drm_device *dev);
> -int amdgpu_device_supports_baco(struct drm_device *dev);
> +bool amdgpu_device_supports_atpx(struct amdgpu_device *adev);
> +bool amdgpu_device_supports_px(struct amdgpu_device *adev);
> +bool amdgpu_device_supports_boco(struct amdgpu_device *adev);
> +bool amdgpu_device_supports_smart_shift(struct amdgpu_device *adev);
> +int amdgpu_device_supports_baco(struct amdgpu_device *adev);
> void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev);
> bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
> struct amdgpu_device *peer_adev);
> -int amdgpu_device_baco_enter(struct drm_device *dev);
> -int amdgpu_device_baco_exit(struct drm_device *dev);
> +int amdgpu_device_baco_enter(struct amdgpu_device *adev);
> +int amdgpu_device_baco_exit(struct amdgpu_device *adev);
>
> void amdgpu_device_flush_hdp(struct amdgpu_device *adev,
> struct amdgpu_ring *ring);
> @@ -1695,7 +1695,8 @@ int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
> u8 perf_req, bool advertise);
> int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,
> u8 dev_state, bool drv_state);
> -int amdgpu_acpi_smart_shift_update(struct drm_device *dev, enum amdgpu_ss ss_state);
> +int amdgpu_acpi_smart_shift_update(struct amdgpu_device *adev,
> + enum amdgpu_ss ss_state);
> int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
> int amdgpu_acpi_get_tmr_info(struct amdgpu_device *adev, u64 *tmr_offset,
> u64 *tmr_size);
> @@ -1726,8 +1727,11 @@ static inline void amdgpu_acpi_release(void) { }
> static inline bool amdgpu_acpi_is_power_shift_control_supported(void) { return false; }
> static inline int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,
> u8 dev_state, bool drv_state) { return 0; }
> -static inline int amdgpu_acpi_smart_shift_update(struct drm_device *dev,
> - enum amdgpu_ss ss_state) { return 0; }
> +static inline int amdgpu_acpi_smart_shift_update(struct amdgpu_device *adev,
> + enum amdgpu_ss ss_state)
> +{
> + return 0;
> +}
> static inline void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps) { }
> #endif
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
> index ae2d08cf027e..6c62e27b9800 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
> @@ -811,18 +811,18 @@ int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,
> /**
> * amdgpu_acpi_smart_shift_update - update dGPU device state to SBIOS
> *
> - * @dev: drm_device pointer
> + * @adev: amdgpu device pointer
> * @ss_state: current smart shift event
> *
> * returns 0 on success,
> * otherwise return error number.
> */
> -int amdgpu_acpi_smart_shift_update(struct drm_device *dev, enum amdgpu_ss ss_state)
> +int amdgpu_acpi_smart_shift_update(struct amdgpu_device *adev,
> + enum amdgpu_ss ss_state)
> {
> - struct amdgpu_device *adev = drm_to_adev(dev);
> int r;
>
> - if (!amdgpu_device_supports_smart_shift(dev))
> + if (!amdgpu_device_supports_smart_shift(adev))
> return 0;
>
> switch (ss_state) {
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 30173daeff85..154b1f18400a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -413,19 +413,16 @@ static const struct attribute_group amdgpu_board_attrs_group = {
>
> static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev);
>
> -
> /**
> * amdgpu_device_supports_px - Is the device a dGPU with ATPX power control
> *
> - * @dev: drm_device pointer
> + * @adev: amdgpu device pointer
> *
> * Returns true if the device is a dGPU with ATPX power control,
> * otherwise return false.
> */
> -bool amdgpu_device_supports_px(struct drm_device *dev)
> +bool amdgpu_device_supports_px(struct amdgpu_device *adev)
> {
> - struct amdgpu_device *adev = drm_to_adev(dev);
> -
> if ((adev->flags & AMD_IS_PX) && !amdgpu_is_atpx_hybrid())
> return true;
> return false;
> @@ -434,15 +431,13 @@ bool amdgpu_device_supports_px(struct drm_device *dev)
> /**
> * amdgpu_device_supports_boco - Is the device a dGPU with ACPI power resources
> *
> - * @dev: drm_device pointer
> + * @adev: amdgpu device pointer
> *
> * Returns true if the device is a dGPU with ACPI power control,
> * otherwise return false.
> */
> -bool amdgpu_device_supports_boco(struct drm_device *dev)
> +bool amdgpu_device_supports_boco(struct amdgpu_device *adev)
> {
> - struct amdgpu_device *adev = drm_to_adev(dev);
> -
> if (!IS_ENABLED(CONFIG_HOTPLUG_PCI_PCIE))
> return false;
>
> @@ -455,29 +450,24 @@ bool amdgpu_device_supports_boco(struct drm_device *dev)
> /**
> * amdgpu_device_supports_baco - Does the device support BACO
> *
> - * @dev: drm_device pointer
> + * @adev: amdgpu device pointer
> *
> * Return:
> * 1 if the device supports BACO;
> * 3 if the device supports MACO (only works if BACO is supported)
> * otherwise return 0.
> */
> -int amdgpu_device_supports_baco(struct drm_device *dev)
> +int amdgpu_device_supports_baco(struct amdgpu_device *adev)
> {
> - struct amdgpu_device *adev = drm_to_adev(dev);
> -
> return amdgpu_asic_supports_baco(adev);
> }
>
> void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
> {
> - struct drm_device *dev;
> int bamaco_support;
>
> - dev = adev_to_drm(adev);
> -
> adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
> - bamaco_support = amdgpu_device_supports_baco(dev);
> + bamaco_support = amdgpu_device_supports_baco(adev);
>
> switch (amdgpu_runtime_pm) {
> case 2:
> @@ -497,10 +487,12 @@ void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
> break;
> case -1:
> case -2:
> - if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime mode */
> + if (amdgpu_device_supports_px(adev)) {
> + /* enable PX as runtime mode */
> adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
> dev_info(adev->dev, "Using ATPX for runtime pm\n");
> - } else if (amdgpu_device_supports_boco(dev)) { /* enable boco as runtime mode */
> + } else if (amdgpu_device_supports_boco(adev)) {
> + /* enable boco as runtime mode */
> adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
> dev_info(adev->dev, "Using BOCO for runtime pm\n");
> } else {
> @@ -549,14 +541,14 @@ void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
> * amdgpu_device_supports_smart_shift - Is the device dGPU with
> * smart shift support
> *
> - * @dev: drm_device pointer
> + * @adev: amdgpu device pointer
> *
> * Returns true if the device is a dGPU with Smart Shift support,
> * otherwise returns false.
> */
> -bool amdgpu_device_supports_smart_shift(struct drm_device *dev)
> +bool amdgpu_device_supports_smart_shift(struct amdgpu_device *adev)
> {
> - return (amdgpu_device_supports_boco(dev) &&
> + return (amdgpu_device_supports_boco(adev) &&
> amdgpu_acpi_is_power_shift_control_supported());
> }
>
> @@ -2202,7 +2194,8 @@ static void amdgpu_switcheroo_set_state(struct pci_dev *pdev,
> struct drm_device *dev = pci_get_drvdata(pdev);
> int r;
>
> - if (amdgpu_device_supports_px(dev) && state == VGA_SWITCHEROO_OFF)
> + if (amdgpu_device_supports_px(drm_to_adev(dev)) &&
> + state == VGA_SWITCHEROO_OFF)
> return;
>
> if (state == VGA_SWITCHEROO_ON) {
> @@ -4194,13 +4187,13 @@ static void amdgpu_device_xgmi_reset_func(struct work_struct *__work)
> if (amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) {
>
> task_barrier_enter(&hive->tb);
> - adev->asic_reset_res = amdgpu_device_baco_enter(adev_to_drm(adev));
> + adev->asic_reset_res = amdgpu_device_baco_enter(adev);
>
> if (adev->asic_reset_res)
> goto fail;
>
> task_barrier_exit(&hive->tb);
> - adev->asic_reset_res = amdgpu_device_baco_exit(adev_to_drm(adev));
> + adev->asic_reset_res = amdgpu_device_baco_exit(adev);
>
> if (adev->asic_reset_res)
> goto fail;
> @@ -4355,7 +4348,6 @@ static void amdgpu_device_set_mcbp(struct amdgpu_device *adev)
> int amdgpu_device_init(struct amdgpu_device *adev,
> uint32_t flags)
> {
> - struct drm_device *ddev = adev_to_drm(adev);
> struct pci_dev *pdev = adev->pdev;
> int r, i;
> bool px = false;
> @@ -4816,7 +4808,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
> if ((adev->pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
> vga_client_register(adev->pdev, amdgpu_device_vga_set_decode);
>
> - px = amdgpu_device_supports_px(ddev);
> + px = amdgpu_device_supports_px(adev);
>
> if (px || (!dev_is_removable(&adev->pdev->dev) &&
> apple_gmux_detect(NULL, NULL)))
> @@ -4982,7 +4974,7 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
> kfree(adev->xcp_mgr);
> adev->xcp_mgr = NULL;
>
> - px = amdgpu_device_supports_px(adev_to_drm(adev));
> + px = amdgpu_device_supports_px(adev);
>
> if (px || (!dev_is_removable(&adev->pdev->dev) &&
> apple_gmux_detect(NULL, NULL)))
> @@ -5155,7 +5147,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)
> return r;
> }
>
> - if (amdgpu_acpi_smart_shift_update(dev, AMDGPU_SS_DEV_D3))
> + if (amdgpu_acpi_smart_shift_update(adev, AMDGPU_SS_DEV_D3))
> dev_warn(adev->dev, "smart shift update failed\n");
>
> if (notify_clients)
> @@ -5324,7 +5316,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients)
> }
> adev->in_suspend = false;
>
> - if (amdgpu_acpi_smart_shift_update(dev, AMDGPU_SS_DEV_D0))
> + if (amdgpu_acpi_smart_shift_update(adev, AMDGPU_SS_DEV_D0))
> dev_warn(adev->dev, "smart shift update failed\n");
>
> return 0;
> @@ -6369,7 +6361,8 @@ static int amdgpu_device_sched_resume(struct list_head *device_list,
> amdgpu_vf_error_put(tmp_adev, AMDGIM_ERROR_VF_GPU_RESET_FAIL, 0, r);
> } else {
> dev_info(tmp_adev->dev, "GPU reset(%d) succeeded!\n", atomic_read(&tmp_adev->gpu_reset_counter));
> - if (amdgpu_acpi_smart_shift_update(adev_to_drm(tmp_adev), AMDGPU_SS_DEV_D0))
> + if (amdgpu_acpi_smart_shift_update(tmp_adev,
> + AMDGPU_SS_DEV_D0))
> dev_warn(tmp_adev->dev,
> "smart shift update failed\n");
> }
> @@ -6837,12 +6830,11 @@ bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
> #endif
> }
>
> -int amdgpu_device_baco_enter(struct drm_device *dev)
> +int amdgpu_device_baco_enter(struct amdgpu_device *adev)
> {
> - struct amdgpu_device *adev = drm_to_adev(dev);
> struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
>
> - if (!amdgpu_device_supports_baco(dev))
> + if (!amdgpu_device_supports_baco(adev))
> return -ENOTSUPP;
>
> if (ras && adev->ras_enabled &&
> @@ -6852,13 +6844,12 @@ int amdgpu_device_baco_enter(struct drm_device *dev)
> return amdgpu_dpm_baco_enter(adev);
> }
>
> -int amdgpu_device_baco_exit(struct drm_device *dev)
> +int amdgpu_device_baco_exit(struct amdgpu_device *adev)
> {
> - struct amdgpu_device *adev = drm_to_adev(dev);
> struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
> int ret = 0;
>
> - if (!amdgpu_device_supports_baco(dev))
> + if (!amdgpu_device_supports_baco(adev))
> return -ENOTSUPP;
>
> ret = amdgpu_dpm_baco_exit(adev);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index b299e15bb5e5..4f8632737574 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -2457,10 +2457,10 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
>
> if (adev->pm.rpm_mode != AMDGPU_RUNPM_NONE) {
> /* only need to skip on ATPX */
> - if (amdgpu_device_supports_px(ddev))
> + if (amdgpu_device_supports_px(adev))
> dev_pm_set_driver_flags(ddev->dev, DPM_FLAG_NO_DIRECT_COMPLETE);
> /* we want direct complete for BOCO */
> - if (amdgpu_device_supports_boco(ddev))
> + if (amdgpu_device_supports_boco(adev))
> dev_pm_set_driver_flags(ddev->dev, DPM_FLAG_SMART_PREPARE |
> DPM_FLAG_SMART_SUSPEND |
> DPM_FLAG_MAY_SKIP_RESUME);
> @@ -2493,9 +2493,9 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
> * into D0 state. Then there will be a PMFW-aware D-state
> * transition(D0->D3) on runpm suspend.
> */
> - if (amdgpu_device_supports_baco(ddev) &&
> + if (amdgpu_device_supports_baco(adev) &&
> !(adev->flags & AMD_IS_APU) &&
> - (adev->asic_type >= CHIP_NAVI10))
> + adev->asic_type >= CHIP_NAVI10)
> amdgpu_get_secondary_funcs(adev);
> }
>
> @@ -2560,8 +2560,7 @@ static int amdgpu_pmops_prepare(struct device *dev)
> /* Return a positive number here so
> * DPM_FLAG_SMART_SUSPEND works properly
> */
> - if (amdgpu_device_supports_boco(drm_dev) &&
> - pm_runtime_suspended(dev))
> + if (amdgpu_device_supports_boco(adev) && pm_runtime_suspended(dev))
> return 1;
>
> /* if we will not support s3 or s2i for the device
> @@ -2834,7 +2833,7 @@ static int amdgpu_pmops_runtime_suspend(struct device *dev)
> /* nothing to do */
> } else if ((adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) ||
> (adev->pm.rpm_mode == AMDGPU_RUNPM_BAMACO)) {
> - amdgpu_device_baco_enter(drm_dev);
> + amdgpu_device_baco_enter(adev);
> }
>
> dev_dbg(&pdev->dev, "asic/device is runtime suspended\n");
> @@ -2875,7 +2874,7 @@ static int amdgpu_pmops_runtime_resume(struct device *dev)
> pci_set_master(pdev);
> } else if ((adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) ||
> (adev->pm.rpm_mode == AMDGPU_RUNPM_BAMACO)) {
> - amdgpu_device_baco_exit(drm_dev);
> + amdgpu_device_baco_exit(adev);
> }
> ret = amdgpu_device_resume(drm_dev, false);
> if (ret) {
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 5d38276fc900..4aab5e394ce2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -91,7 +91,7 @@ void amdgpu_driver_unload_kms(struct drm_device *dev)
> if (adev->rmmio == NULL)
> return;
>
> - if (amdgpu_acpi_smart_shift_update(dev, AMDGPU_SS_DRV_UNLOAD))
> + if (amdgpu_acpi_smart_shift_update(adev, AMDGPU_SS_DRV_UNLOAD))
> DRM_WARN("smart shift update failed\n");
>
> amdgpu_acpi_fini(adev);
> @@ -161,7 +161,7 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
> if (acpi_status)
> dev_dbg(dev->dev, "Error during ACPI methods call\n");
>
> - if (amdgpu_acpi_smart_shift_update(dev, AMDGPU_SS_DRV_LOAD))
> + if (amdgpu_acpi_smart_shift_update(adev, AMDGPU_SS_DRV_LOAD))
> DRM_WARN("smart shift update failed\n");
>
> out:
> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> index 5537dcf23b5c..c2fde0e33b38 100644
> --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> @@ -1897,7 +1897,7 @@ static ssize_t amdgpu_set_smartshift_bias(struct device *dev,
> static int ss_power_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
> uint32_t mask, enum amdgpu_device_attr_states *states)
> {
> - if (!amdgpu_device_supports_smart_shift(adev_to_drm(adev)))
> + if (!amdgpu_device_supports_smart_shift(adev))
> *states = ATTR_STATE_UNSUPPORTED;
>
> return 0;
> @@ -1908,7 +1908,7 @@ static int ss_bias_attr_update(struct amdgpu_device *adev, struct amdgpu_device_
> {
> uint32_t ss_power;
>
> - if (!amdgpu_device_supports_smart_shift(adev_to_drm(adev)))
> + if (!amdgpu_device_supports_smart_shift(adev))
> *states = ATTR_STATE_UNSUPPORTED;
> else if (amdgpu_hwmon_get_sensor_generic(adev, AMDGPU_PP_SENSOR_SS_APU_SHARE,
> (void *)&ss_power))
> --
> 2.49.0
>
More information about the amd-gfx
mailing list