On 6/8/26 21:47, Shahyan Soltani wrote:
> Move struct amdgpu_uid and helpers from the monolithic amdgpu.h file into a 
> new amdgpu_uid.h file.
> 
> Move functions amdgpu_device_set_uid() and amdgpu_device_get_uid() out of
> amdgpu_device.c into new dedicated amdgpu_uid.c file.

I'm not so familiar with the technical background, could be that it would be 
better to just move the defines into amdgpu_device.h.

@Alex what's you take on that?

Regards,
Christian.

> 
> Update amdgpu/Makefile to build amdgpu_uid.o
> 
> This is part of the ongoing effort to reduce the size of amdgpu.h into their 
> own respective
> separate headers.
> 
> Signed-off-by: Shahyan Soltani <[email protected]>
> ---
>  drivers/gpu/drm/amd/amdgpu/Makefile        |  2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 22 +------
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 50 ---------------
>  drivers/gpu/drm/amd/amdgpu/amdgpu_uid.c    | 75 ++++++++++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_uid.h    | 50 +++++++++++++++
>  5 files changed, 127 insertions(+), 72 deletions(-)
>  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_uid.c
>  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_uid.h
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
> b/drivers/gpu/drm/amd/amdgpu/Makefile
> index e6deb24f73bb..415e73e0a1af 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> @@ -72,7 +72,7 @@ amdgpu-y += amdgpu_device.o amdgpu_reg_access.o 
> amdgpu_doorbell_mgr.o amdgpu_kms
>       amdgpu_eeprom.o amdgpu_mca.o amdgpu_psp_ta.o amdgpu_lsdma.o \
>       amdgpu_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 
> amdgpu_dev_coredump.o \
>       amdgpu_cper.o amdgpu_userq_fence.o amdgpu_eviction_fence.o amdgpu_ip.o \
> -     amdgpu_wb.o
> +     amdgpu_wb.o amdgpu_uid.o
>  
>  amdgpu-$(CONFIG_PROC_FS) += amdgpu_fdinfo.o
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 9a714b4b59bc..0f8743254fe6 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -114,6 +114,7 @@
>  #include "amdgpu_sa.h"
>  #include "amdgpu_wb.h"
>  #include "amdgpu_ip.h"
> +#include "amdgpu_uid.h"
>  #if defined(CONFIG_DRM_AMD_ISP)
>  #include "amdgpu_isp.h"
>  #endif
> @@ -553,21 +554,6 @@ struct amdgpu_mmio_remap {
>       struct amdgpu_bo *bo;
>  };
>  
> -enum amdgpu_uid_type {
> -     AMDGPU_UID_TYPE_XCD,
> -     AMDGPU_UID_TYPE_AID,
> -     AMDGPU_UID_TYPE_SOC,
> -     AMDGPU_UID_TYPE_MID,
> -     AMDGPU_UID_TYPE_MAX
> -};
> -
> -#define AMDGPU_UID_INST_MAX 8 /* max number of instances for each UID type */
> -
> -struct amdgpu_uid {
> -     uint64_t uid[AMDGPU_UID_TYPE_MAX][AMDGPU_UID_INST_MAX];
> -     struct amdgpu_device *adev;
> -};
> -
>  #define MAX_UMA_OPTION_NAME  28
>  #define MAX_UMA_OPTION_ENTRIES       19
>  
> @@ -1530,10 +1516,4 @@ static inline int 
> amdgpu_device_bus_status_check(struct amdgpu_device *adev)
>  
>         return 0;
>  }
> -
> -void amdgpu_device_set_uid(struct amdgpu_uid *uid_info,
> -                        enum amdgpu_uid_type type, uint8_t inst,
> -                        uint64_t uid);
> -uint64_t amdgpu_device_get_uid(struct amdgpu_uid *uid_info,
> -                            enum amdgpu_uid_type type, uint8_t inst);
>  #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 15a6a9010fc8..602e7eb1cc5c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -6872,53 +6872,3 @@ ssize_t amdgpu_show_reset_mask(char *buf, uint32_t 
> supported_reset)
>       size += sysfs_emit_at(buf, size, "\n");
>       return size;
>  }
> -
> -void amdgpu_device_set_uid(struct amdgpu_uid *uid_info,
> -                        enum amdgpu_uid_type type, uint8_t inst,
> -                        uint64_t uid)
> -{
> -     if (!uid_info)
> -             return;
> -
> -     if (type >= AMDGPU_UID_TYPE_MAX) {
> -             dev_err_once(uid_info->adev->dev, "Invalid UID type %d\n",
> -                          type);
> -             return;
> -     }
> -
> -     if (inst >= AMDGPU_UID_INST_MAX) {
> -             dev_err_once(uid_info->adev->dev, "Invalid UID instance %d\n",
> -                          inst);
> -             return;
> -     }
> -
> -     if (uid_info->uid[type][inst] != 0) {
> -             dev_warn_once(
> -                     uid_info->adev->dev,
> -                     "Overwriting existing UID %llu for type %d instance 
> %d\n",
> -                     uid_info->uid[type][inst], type, inst);
> -     }
> -
> -     uid_info->uid[type][inst] = uid;
> -}
> -
> -u64 amdgpu_device_get_uid(struct amdgpu_uid *uid_info,
> -                       enum amdgpu_uid_type type, uint8_t inst)
> -{
> -     if (!uid_info)
> -             return 0;
> -
> -     if (type >= AMDGPU_UID_TYPE_MAX) {
> -             dev_err_once(uid_info->adev->dev, "Invalid UID type %d\n",
> -                          type);
> -             return 0;
> -     }
> -
> -     if (inst >= AMDGPU_UID_INST_MAX) {
> -             dev_err_once(uid_info->adev->dev, "Invalid UID instance %d\n",
> -                          inst);
> -             return 0;
> -     }
> -
> -     return uid_info->uid[type][inst];
> -}
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uid.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_uid.c
> new file mode 100644
> index 000000000000..9b81e8198a73
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uid.c
> @@ -0,0 +1,75 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +/*
> + * Copyright 2026 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +#include "amdgpu_uid.h"
> +#include <linux/dev_printk.h>
> +#include "amdgpu.h"
> +
> +void amdgpu_device_set_uid(struct amdgpu_uid *uid_info,
> +                        enum amdgpu_uid_type type, uint8_t inst,
> +                        uint64_t uid)
> +{
> +     if (!uid_info)
> +             return;
> +
> +     if (type >= AMDGPU_UID_TYPE_MAX) {
> +             dev_err_once(uid_info->adev->dev, "Invalid UID type %d\n",
> +                          type);
> +             return;
> +     }
> +
> +     if (inst >= AMDGPU_UID_INST_MAX) {
> +             dev_err_once(uid_info->adev->dev, "Invalid UID instance %d\n",
> +                          inst);
> +             return;
> +     }
> +
> +     if (uid_info->uid[type][inst] != 0) {
> +             dev_warn_once(
> +                     uid_info->adev->dev,
> +                     "Overwriting existing UID %llu for type %d instance 
> %d\n",
> +                     uid_info->uid[type][inst], type, inst);
> +     }
> +
> +     uid_info->uid[type][inst] = uid;
> +}
> +
> +u64 amdgpu_device_get_uid(struct amdgpu_uid *uid_info,
> +                       enum amdgpu_uid_type type, uint8_t inst)
> +{
> +     if (!uid_info)
> +             return 0;
> +
> +     if (type >= AMDGPU_UID_TYPE_MAX) {
> +             dev_err_once(uid_info->adev->dev, "Invalid UID type %d\n",
> +                          type);
> +             return 0;
> +     }
> +
> +     if (inst >= AMDGPU_UID_INST_MAX) {
> +             dev_err_once(uid_info->adev->dev, "Invalid UID instance %d\n",
> +                          inst);
> +             return 0;
> +     }
> +
> +     return uid_info->uid[type][inst];
> +}
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uid.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_uid.h
> new file mode 100644
> index 000000000000..d92ddcce9f58
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uid.h
> @@ -0,0 +1,50 @@
> +/* SPDX-License-Identifier: GPL-2.0 OR MIT
> + *
> + * Copyright 2026 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +#ifndef __AMDGPU_UID_H__
> +#define __AMDGPU_UID_H__
> +
> +#include <linux/types.h>
> +
> +#define AMDGPU_UID_INST_MAX 8 /* max number of instances for each UID type */
> +
> +struct amdgpu_device;
> +
> +enum amdgpu_uid_type {
> +     AMDGPU_UID_TYPE_XCD,
> +     AMDGPU_UID_TYPE_AID,
> +     AMDGPU_UID_TYPE_SOC,
> +     AMDGPU_UID_TYPE_MID,
> +     AMDGPU_UID_TYPE_MAX
> +};
> +
> +struct amdgpu_uid {
> +     uint64_t uid[AMDGPU_UID_TYPE_MAX][AMDGPU_UID_INST_MAX];
> +     struct amdgpu_device *adev;
> +};
> +
> +void amdgpu_device_set_uid(struct amdgpu_uid *uid_info,
> +                        enum amdgpu_uid_type type, uint8_t inst,
> +                        uint64_t uid);
> +uint64_t amdgpu_device_get_uid(struct amdgpu_uid *uid_info,
> +                            enum amdgpu_uid_type type, uint8_t inst);
> +#endif

Reply via email to