Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Khatri, Sunil

Sent a new patch based on discussion with Alex.

On 3/19/2024 8:34 PM, Christian König wrote:

Am 19.03.24 um 15:59 schrieb Alex Deucher:

On Tue, Mar 19, 2024 at 10:56 AM Christian König
 wrote:

Am 19.03.24 um 15:26 schrieb Alex Deucher:
On Tue, Mar 19, 2024 at 8:32 AM Sunil Khatri  
wrote:

Refactor the code so debugfs and devcoredump can reuse
the common information and avoid unnecessary copy of it.

created a new file which would be the right place to
hold functions which will be used between sysfs, debugfs
and devcoredump.

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Sunil Khatri 
---
   drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 


   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
   4 files changed, 157 insertions(+), 115 deletions(-)
   create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile

index 4536c8ad0e11..05d34f4b18f5 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o 
amdgpu_doorbell_mgr.o amdgpu_kms.o \
  amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o 
amdgpu_rap.o \

  amdgpu_fw_attestation.o amdgpu_securedisplay.o \
  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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 
amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1609,4 +1609,5 @@ extern const struct attribute_group 
amdgpu_vram_mgr_attr_group;

   extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
   extern const struct attribute_group amdgpu_flash_attr_group;

+int amdgpu_device_info(struct amdgpu_device *adev, struct 
drm_amdgpu_info_device *dev_info);

   #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

new file mode 100644
index ..d2c15a1dcb0d
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 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.h"
+#include "amd_pcie.h"
+
+#include 
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct 
drm_amdgpu_info_device *dev_info)

We can probably keep this in amdgpu_kms.c unless that file is getting
too big.  I don't think it warrants a new file at this point.  If you
do keep it in amdgpu_kms.c, I'd recommend renaming it to something
like amdgpu_kms_device_info() to keep the naming conventions.

We should not be using this for anything new in the first place.

A whole bunch of the stuff inside the devinfo structure has been
deprecated because we found that putting everything into one structure
was a bad idea.

It's a convenient way to collect a lot of useful information that we
want in the core dump.  Plus it's not going anywhere because we need
to keep compatibility in the IOCTL.


Yeah and exactly that is what I'm strictly against. The devinfo wasn't 
used for new stuff because we found that it is way to inflexible.


That's why we have multiple separate IOCTLs for the memory and 
firmware information for example.


We should really *not* reuse that for the device core dumping.

Rather just use the same information from the different IPs and 
subsystems directly. E.g. add a function to the VM, GFX etc for 
printing out devcoredump infos.


I have pushed new v2 based 

Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Christian König

Am 19.03.24 um 15:59 schrieb Alex Deucher:

On Tue, Mar 19, 2024 at 10:56 AM Christian König
 wrote:

Am 19.03.24 um 15:26 schrieb Alex Deucher:

On Tue, Mar 19, 2024 at 8:32 AM Sunil Khatri  wrote:

Refactor the code so debugfs and devcoredump can reuse
the common information and avoid unnecessary copy of it.

created a new file which would be the right place to
hold functions which will be used between sysfs, debugfs
and devcoredump.

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Sunil Khatri 
---
   drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
   4 files changed, 157 insertions(+), 115 deletions(-)
   create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 4536c8ad0e11..05d34f4b18f5 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o 
amdgpu_kms.o \
  amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
  amdgpu_fw_attestation.o amdgpu_securedisplay.o \
  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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 
amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1609,4 +1609,5 @@ extern const struct attribute_group 
amdgpu_vram_mgr_attr_group;
   extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
   extern const struct attribute_group amdgpu_flash_attr_group;

+int amdgpu_device_info(struct amdgpu_device *adev, struct 
drm_amdgpu_info_device *dev_info);
   #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
new file mode 100644
index ..d2c15a1dcb0d
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 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.h"
+#include "amd_pcie.h"
+
+#include 
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct 
drm_amdgpu_info_device *dev_info)

We can probably keep this in amdgpu_kms.c unless that file is getting
too big.  I don't think it warrants a new file at this point.  If you
do keep it in amdgpu_kms.c, I'd recommend renaming it to something
like amdgpu_kms_device_info() to keep the naming conventions.

We should not be using this for anything new in the first place.

A whole bunch of the stuff inside the devinfo structure has been
deprecated because we found that putting everything into one structure
was a bad idea.

It's a convenient way to collect a lot of useful information that we
want in the core dump.  Plus it's not going anywhere because we need
to keep compatibility in the IOCTL.


Yeah and exactly that is what I'm strictly against. The devinfo wasn't 
used for new stuff because we found that it is way to inflexible.


That's why we have multiple separate IOCTLs for the memory and firmware 
information for example.


We should really *not* reuse that for the device core dumping.

Rather just use the same information from the different IPs and 
subsystems directly. E.g. add a function to the VM, GFX etc for printing 
out devcoredump infos.


Christian.



Alex


Regards,
Christian.


+{
+   int ret;
+   uint64_t vm_size;
+   uint32_t pcie_gen_mask;
+
+   if (dev_info == 

Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Alex Deucher
On Tue, Mar 19, 2024 at 10:56 AM Christian König
 wrote:
>
> Am 19.03.24 um 15:26 schrieb Alex Deucher:
> > On Tue, Mar 19, 2024 at 8:32 AM Sunil Khatri  wrote:
> >> Refactor the code so debugfs and devcoredump can reuse
> >> the common information and avoid unnecessary copy of it.
> >>
> >> created a new file which would be the right place to
> >> hold functions which will be used between sysfs, debugfs
> >> and devcoredump.
> >>
> >> Cc: Christian König 
> >> Cc: Alex Deucher 
> >> Signed-off-by: Sunil Khatri 
> >> ---
> >>   drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
> >>   drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
> >>   drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
> >>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
> >>   4 files changed, 157 insertions(+), 115 deletions(-)
> >>   create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> >>
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
> >> b/drivers/gpu/drm/amd/amdgpu/Makefile
> >> index 4536c8ad0e11..05d34f4b18f5 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> >> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> >> @@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o 
> >> amdgpu_kms.o \
> >>  amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
> >>  amdgpu_fw_attestation.o amdgpu_securedisplay.o \
> >>  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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 
> >> amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> >> @@ -1609,4 +1609,5 @@ extern const struct attribute_group 
> >> amdgpu_vram_mgr_attr_group;
> >>   extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
> >>   extern const struct attribute_group amdgpu_flash_attr_group;
> >>
> >> +int amdgpu_device_info(struct amdgpu_device *adev, struct 
> >> drm_amdgpu_info_device *dev_info);
> >>   #endif
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c 
> >> b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> >> new file mode 100644
> >> index ..d2c15a1dcb0d
> >> --- /dev/null
> >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> >> @@ -0,0 +1,151 @@
> >> +// SPDX-License-Identifier: MIT
> >> +/*
> >> + * Copyright 2024 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.h"
> >> +#include "amd_pcie.h"
> >> +
> >> +#include 
> >> +
> >> +int amdgpu_device_info(struct amdgpu_device *adev, struct 
> >> drm_amdgpu_info_device *dev_info)
> > We can probably keep this in amdgpu_kms.c unless that file is getting
> > too big.  I don't think it warrants a new file at this point.  If you
> > do keep it in amdgpu_kms.c, I'd recommend renaming it to something
> > like amdgpu_kms_device_info() to keep the naming conventions.
>
> We should not be using this for anything new in the first place.
>
> A whole bunch of the stuff inside the devinfo structure has been
> deprecated because we found that putting everything into one structure
> was a bad idea.

It's a convenient way to collect a lot of useful information that we
want in the core dump.  Plus it's not going anywhere because we need
to keep compatibility in the IOCTL.

Alex

>
> Regards,
> Christian.
>
> >
> >> +{
> >> +   int ret;
> >> +   uint64_t vm_size;
> >> +   uint32_t pcie_gen_mask;
> >> +
> >> +   if (dev_info == NULL)
> 

Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Christian König

Am 19.03.24 um 15:26 schrieb Alex Deucher:

On Tue, Mar 19, 2024 at 8:32 AM Sunil Khatri  wrote:

Refactor the code so debugfs and devcoredump can reuse
the common information and avoid unnecessary copy of it.

created a new file which would be the right place to
hold functions which will be used between sysfs, debugfs
and devcoredump.

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Sunil Khatri 
---
  drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
  4 files changed, 157 insertions(+), 115 deletions(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 4536c8ad0e11..05d34f4b18f5 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o 
amdgpu_kms.o \
 amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
 amdgpu_fw_attestation.o amdgpu_securedisplay.o \
 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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 
amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1609,4 +1609,5 @@ extern const struct attribute_group 
amdgpu_vram_mgr_attr_group;
  extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
  extern const struct attribute_group amdgpu_flash_attr_group;

+int amdgpu_device_info(struct amdgpu_device *adev, struct 
drm_amdgpu_info_device *dev_info);
  #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
new file mode 100644
index ..d2c15a1dcb0d
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 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.h"
+#include "amd_pcie.h"
+
+#include 
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct 
drm_amdgpu_info_device *dev_info)

We can probably keep this in amdgpu_kms.c unless that file is getting
too big.  I don't think it warrants a new file at this point.  If you
do keep it in amdgpu_kms.c, I'd recommend renaming it to something
like amdgpu_kms_device_info() to keep the naming conventions.


We should not be using this for anything new in the first place.

A whole bunch of the stuff inside the devinfo structure has been 
deprecated because we found that putting everything into one structure 
was a bad idea.


Regards,
Christian.




+{
+   int ret;
+   uint64_t vm_size;
+   uint32_t pcie_gen_mask;
+
+   if (dev_info == NULL)
+   return -EINVAL;
+
+   dev_info->device_id = adev->pdev->device;
+   dev_info->chip_rev = adev->rev_id;
+   dev_info->external_rev = adev->external_rev_id;
+   dev_info->pci_rev = adev->pdev->revision;
+   dev_info->family = adev->family;
+   dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+   dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+   /* return all clocks in KHz */
+   dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+   if (adev->pm.dpm_enabled) {
+   dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 
10;
+   dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 
10;
+   

Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Alex Deucher
On Tue, Mar 19, 2024 at 8:32 AM Sunil Khatri  wrote:
>
> Refactor the code so debugfs and devcoredump can reuse
> the common information and avoid unnecessary copy of it.
>
> created a new file which would be the right place to
> hold functions which will be used between sysfs, debugfs
> and devcoredump.
>
> Cc: Christian König 
> Cc: Alex Deucher 
> Signed-off-by: Sunil Khatri 
> ---
>  drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
>  4 files changed, 157 insertions(+), 115 deletions(-)
>  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
> b/drivers/gpu/drm/amd/amdgpu/Makefile
> index 4536c8ad0e11..05d34f4b18f5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> @@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o 
> amdgpu_kms.o \
> amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
> amdgpu_fw_attestation.o amdgpu_securedisplay.o \
> 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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 
> amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1609,4 +1609,5 @@ extern const struct attribute_group 
> amdgpu_vram_mgr_attr_group;
>  extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
>  extern const struct attribute_group amdgpu_flash_attr_group;
>
> +int amdgpu_device_info(struct amdgpu_device *adev, struct 
> drm_amdgpu_info_device *dev_info);
>  #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> new file mode 100644
> index ..d2c15a1dcb0d
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> @@ -0,0 +1,151 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright 2024 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.h"
> +#include "amd_pcie.h"
> +
> +#include 
> +
> +int amdgpu_device_info(struct amdgpu_device *adev, struct 
> drm_amdgpu_info_device *dev_info)

We can probably keep this in amdgpu_kms.c unless that file is getting
too big.  I don't think it warrants a new file at this point.  If you
do keep it in amdgpu_kms.c, I'd recommend renaming it to something
like amdgpu_kms_device_info() to keep the naming conventions.

> +{
> +   int ret;
> +   uint64_t vm_size;
> +   uint32_t pcie_gen_mask;
> +
> +   if (dev_info == NULL)
> +   return -EINVAL;
> +
> +   dev_info->device_id = adev->pdev->device;
> +   dev_info->chip_rev = adev->rev_id;
> +   dev_info->external_rev = adev->external_rev_id;
> +   dev_info->pci_rev = adev->pdev->revision;
> +   dev_info->family = adev->family;
> +   dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
> +   dev_info->num_shader_arrays_per_engine = 
> adev->gfx.config.max_sh_per_se;
> +   /* return all clocks in KHz */
> +   dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
> +   if (adev->pm.dpm_enabled) {
> +   dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) 
> * 10;
> +   dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) 
> * 10;
> +   dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) 
> * 10;
> +   

Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Alex Deucher
On Tue, Mar 19, 2024 at 10:22 AM Lazar, Lijo  wrote:
>
>
>
> On 3/19/2024 7:27 PM, Khatri, Sunil wrote:
> >
> > On 3/19/2024 7:19 PM, Lazar, Lijo wrote:
> >>
> >> On 3/19/2024 6:02 PM, Sunil Khatri wrote:
> >>> Refactor the code so debugfs and devcoredump can reuse
> >>> the common information and avoid unnecessary copy of it.
> >>>
> >>> created a new file which would be the right place to
> >>> hold functions which will be used between sysfs, debugfs
> >>> and devcoredump.
> >>>
> >>> Cc: Christian König 
> >>> Cc: Alex Deucher 
> >>> Signed-off-by: Sunil Khatri 
> >>> ---
> >>>   drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
> >>>   drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
> >>>   drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
> >>>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
> >>>   4 files changed, 157 insertions(+), 115 deletions(-)
> >>>   create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> >>>
> >>> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
> >>> b/drivers/gpu/drm/amd/amdgpu/Makefile
> >>> index 4536c8ad0e11..05d34f4b18f5 100644
> >>> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> >>> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> >>> @@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o
> >>> amdgpu_kms.o \
> >>>   amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
> >>>   amdgpu_fw_attestation.o amdgpu_securedisplay.o \
> >>>   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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
> >>> amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
> >>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> >>> @@ -1609,4 +1609,5 @@ extern const struct attribute_group
> >>> amdgpu_vram_mgr_attr_group;
> >>>   extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
> >>>   extern const struct attribute_group amdgpu_flash_attr_group;
> >>>   +int amdgpu_device_info(struct amdgpu_device *adev, struct
> >>> drm_amdgpu_info_device *dev_info);
> >>>   #endif
> >>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> >>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> >>> new file mode 100644
> >>> index ..d2c15a1dcb0d
> >>> --- /dev/null
> >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> >>> @@ -0,0 +1,151 @@
> >>> +// SPDX-License-Identifier: MIT
> >>> +/*
> >>> + * Copyright 2024 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.h"
> >>> +#include "amd_pcie.h"
> >>> +
> >>> +#include 
> >>> +
> >>> +int amdgpu_device_info(struct amdgpu_device *adev, struct
> >>> drm_amdgpu_info_device *dev_info)
> >>> +{
> >>> +int ret;
> >>> +uint64_t vm_size;
> >>> +uint32_t pcie_gen_mask;
> >>> +
> >>> +if (dev_info == NULL)
> >>> +return -EINVAL;
> >>> +
> >>> +dev_info->device_id = adev->pdev->device;
> >>> +dev_info->chip_rev = adev->rev_id;
> >>> +dev_info->external_rev = adev->external_rev_id;
> >>> +dev_info->pci_rev = adev->pdev->revision;
> >>> +dev_info->family = adev->family;
> >>> +dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
> >>> +dev_info->num_shader_arrays_per_engine =
> >>> adev->gfx.config.max_sh_per_se;
> >>> +/* return all clocks in KHz */
> >>> +dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
> >>> +if (adev->pm.dpm_enabled) {

Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Khatri, Sunil


On 3/19/2024 7:43 PM, Lazar, Lijo wrote:


On 3/19/2024 7:27 PM, Khatri, Sunil wrote:

On 3/19/2024 7:19 PM, Lazar, Lijo wrote:

On 3/19/2024 6:02 PM, Sunil Khatri wrote:

Refactor the code so debugfs and devcoredump can reuse
the common information and avoid unnecessary copy of it.

created a new file which would be the right place to
hold functions which will be used between sysfs, debugfs
and devcoredump.

Cc: Christian König
Cc: Alex Deucher
Signed-off-by: Sunil Khatri
---
   drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
   drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
   drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
   4 files changed, 157 insertions(+), 115 deletions(-)
   create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 4536c8ad0e11..05d34f4b18f5 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o
amdgpu_kms.o \
   amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
   amdgpu_fw_attestation.o amdgpu_securedisplay.o \
   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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1609,4 +1609,5 @@ extern const struct attribute_group
amdgpu_vram_mgr_attr_group;
   extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
   extern const struct attribute_group amdgpu_flash_attr_group;
   +int amdgpu_device_info(struct amdgpu_device *adev, struct
drm_amdgpu_info_device *dev_info);
   #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
new file mode 100644
index ..d2c15a1dcb0d
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 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.h"
+#include "amd_pcie.h"
+
+#include 
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct
drm_amdgpu_info_device *dev_info)
+{
+    int ret;
+    uint64_t vm_size;
+    uint32_t pcie_gen_mask;
+
+    if (dev_info == NULL)
+    return -EINVAL;
+
+    dev_info->device_id = adev->pdev->device;
+    dev_info->chip_rev = adev->rev_id;
+    dev_info->external_rev = adev->external_rev_id;
+    dev_info->pci_rev = adev->pdev->revision;
+    dev_info->family = adev->family;
+    dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+    dev_info->num_shader_arrays_per_engine =
adev->gfx.config.max_sh_per_se;
+    /* return all clocks in KHz */
+    dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+    if (adev->pm.dpm_enabled) {
+    dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev,
false) * 10;
+    dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev,
false) * 10;
+    dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true)
* 10;
+    dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true)
* 10;
+    } else {
+    dev_info->max_engine_clock =
+    dev_info->min_engine_clock =
+    adev->clock.default_sclk * 10;
+    dev_info->max_memory_clock =
+    dev_info->min_memory_clock =
+    adev->clock.default_mclk * 10;
+    }
+    dev_info->enabled_rb_pipes_mask =
adev->gfx.config.backend_enable_mask;
+    dev_info->num_rb_pipes = 

Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Lazar, Lijo



On 3/19/2024 7:27 PM, Khatri, Sunil wrote:
> 
> On 3/19/2024 7:19 PM, Lazar, Lijo wrote:
>>
>> On 3/19/2024 6:02 PM, Sunil Khatri wrote:
>>> Refactor the code so debugfs and devcoredump can reuse
>>> the common information and avoid unnecessary copy of it.
>>>
>>> created a new file which would be the right place to
>>> hold functions which will be used between sysfs, debugfs
>>> and devcoredump.
>>>
>>> Cc: Christian König 
>>> Cc: Alex Deucher 
>>> Signed-off-by: Sunil Khatri 
>>> ---
>>>   drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
>>>   4 files changed, 157 insertions(+), 115 deletions(-)
>>>   create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
>>> b/drivers/gpu/drm/amd/amdgpu/Makefile
>>> index 4536c8ad0e11..05d34f4b18f5 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
>>> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
>>> @@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o
>>> amdgpu_kms.o \
>>>   amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
>>>   amdgpu_fw_attestation.o amdgpu_securedisplay.o \
>>>   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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o
>>> amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>>> @@ -1609,4 +1609,5 @@ extern const struct attribute_group
>>> amdgpu_vram_mgr_attr_group;
>>>   extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
>>>   extern const struct attribute_group amdgpu_flash_attr_group;
>>>   +int amdgpu_device_info(struct amdgpu_device *adev, struct
>>> drm_amdgpu_info_device *dev_info);
>>>   #endif
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
>>> new file mode 100644
>>> index ..d2c15a1dcb0d
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
>>> @@ -0,0 +1,151 @@
>>> +// SPDX-License-Identifier: MIT
>>> +/*
>>> + * Copyright 2024 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.h"
>>> +#include "amd_pcie.h"
>>> +
>>> +#include 
>>> +
>>> +int amdgpu_device_info(struct amdgpu_device *adev, struct
>>> drm_amdgpu_info_device *dev_info)
>>> +{
>>> +    int ret;
>>> +    uint64_t vm_size;
>>> +    uint32_t pcie_gen_mask;
>>> +
>>> +    if (dev_info == NULL)
>>> +    return -EINVAL;
>>> +
>>> +    dev_info->device_id = adev->pdev->device;
>>> +    dev_info->chip_rev = adev->rev_id;
>>> +    dev_info->external_rev = adev->external_rev_id;
>>> +    dev_info->pci_rev = adev->pdev->revision;
>>> +    dev_info->family = adev->family;
>>> +    dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
>>> +    dev_info->num_shader_arrays_per_engine =
>>> adev->gfx.config.max_sh_per_se;
>>> +    /* return all clocks in KHz */
>>> +    dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
>>> +    if (adev->pm.dpm_enabled) {
>>> +    dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev,
>>> false) * 10;
>>> +    dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev,
>>> false) * 10;
>>> +    dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true)
>>> * 10;
>>> +    

Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Khatri, Sunil



On 3/19/2024 7:19 PM, Lazar, Lijo wrote:


On 3/19/2024 6:02 PM, Sunil Khatri wrote:

Refactor the code so debugfs and devcoredump can reuse
the common information and avoid unnecessary copy of it.

created a new file which would be the right place to
hold functions which will be used between sysfs, debugfs
and devcoredump.

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Sunil Khatri 
---
  drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
  4 files changed, 157 insertions(+), 115 deletions(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 4536c8ad0e11..05d34f4b18f5 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o 
amdgpu_kms.o \
amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
amdgpu_fw_attestation.o amdgpu_securedisplay.o \
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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 
amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1609,4 +1609,5 @@ extern const struct attribute_group 
amdgpu_vram_mgr_attr_group;
  extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
  extern const struct attribute_group amdgpu_flash_attr_group;
  
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);

  #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
new file mode 100644
index ..d2c15a1dcb0d
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 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.h"
+#include "amd_pcie.h"
+
+#include 
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct 
drm_amdgpu_info_device *dev_info)
+{
+   int ret;
+   uint64_t vm_size;
+   uint32_t pcie_gen_mask;
+
+   if (dev_info == NULL)
+   return -EINVAL;
+
+   dev_info->device_id = adev->pdev->device;
+   dev_info->chip_rev = adev->rev_id;
+   dev_info->external_rev = adev->external_rev_id;
+   dev_info->pci_rev = adev->pdev->revision;
+   dev_info->family = adev->family;
+   dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+   dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+   /* return all clocks in KHz */
+   dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+   if (adev->pm.dpm_enabled) {
+   dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 
10;
+   dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 
10;
+   dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 
10;
+   dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 
10;
+   } else {
+   dev_info->max_engine_clock =
+   dev_info->min_engine_clock =
+   adev->clock.default_sclk * 10;
+   dev_info->max_memory_clock =
+   dev_info->min_memory_clock =
+   adev->clock.default_mclk * 10;
+   }
+   

Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Lazar, Lijo



On 3/19/2024 6:02 PM, Sunil Khatri wrote:
> Refactor the code so debugfs and devcoredump can reuse
> the common information and avoid unnecessary copy of it.
> 
> created a new file which would be the right place to
> hold functions which will be used between sysfs, debugfs
> and devcoredump.
> 
> Cc: Christian König 
> Cc: Alex Deucher 
> Signed-off-by: Sunil Khatri 
> ---
>  drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
>  4 files changed, 157 insertions(+), 115 deletions(-)
>  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
> b/drivers/gpu/drm/amd/amdgpu/Makefile
> index 4536c8ad0e11..05d34f4b18f5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> @@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o 
> amdgpu_kms.o \
>   amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
>   amdgpu_fw_attestation.o amdgpu_securedisplay.o \
>   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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 
> amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -1609,4 +1609,5 @@ extern const struct attribute_group 
> amdgpu_vram_mgr_attr_group;
>  extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
>  extern const struct attribute_group amdgpu_flash_attr_group;
>  
> +int amdgpu_device_info(struct amdgpu_device *adev, struct 
> drm_amdgpu_info_device *dev_info);
>  #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> new file mode 100644
> index ..d2c15a1dcb0d
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
> @@ -0,0 +1,151 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright 2024 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.h"
> +#include "amd_pcie.h"
> +
> +#include 
> +
> +int amdgpu_device_info(struct amdgpu_device *adev, struct 
> drm_amdgpu_info_device *dev_info)
> +{
> + int ret;
> + uint64_t vm_size;
> + uint32_t pcie_gen_mask;
> +
> + if (dev_info == NULL)
> + return -EINVAL;
> +
> + dev_info->device_id = adev->pdev->device;
> + dev_info->chip_rev = adev->rev_id;
> + dev_info->external_rev = adev->external_rev_id;
> + dev_info->pci_rev = adev->pdev->revision;
> + dev_info->family = adev->family;
> + dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
> + dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
> + /* return all clocks in KHz */
> + dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
> + if (adev->pm.dpm_enabled) {
> + dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 
> 10;
> + dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 
> 10;
> + dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 
> 10;
> + dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 
> 10;
> + } else {
> + dev_info->max_engine_clock =
> + dev_info->min_engine_clock =
> + adev->clock.default_sclk * 10;
> + dev_info->max_memory_clock =
> + 

Re: [PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Khatri, Sunil
Validated the code by using the function in same way as ioctl would use 
in devcoredump and getting the valid values.


Also this would be the container of the information that we need to 
share between ioctl, debugfs and devcoredump and keep updating this 
based on information needed.



On 3/19/2024 6:02 PM, Sunil Khatri wrote:

Refactor the code so debugfs and devcoredump can reuse
the common information and avoid unnecessary copy of it.

created a new file which would be the right place to
hold functions which will be used between sysfs, debugfs
and devcoredump.

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Sunil Khatri 
---
  drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
  4 files changed, 157 insertions(+), 115 deletions(-)
  create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 4536c8ad0e11..05d34f4b18f5 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o 
amdgpu_kms.o \
amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
amdgpu_fw_attestation.o amdgpu_securedisplay.o \
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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 
amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1609,4 +1609,5 @@ extern const struct attribute_group 
amdgpu_vram_mgr_attr_group;
  extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
  extern const struct attribute_group amdgpu_flash_attr_group;
  
+int amdgpu_device_info(struct amdgpu_device *adev, struct drm_amdgpu_info_device *dev_info);

  #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
new file mode 100644
index ..d2c15a1dcb0d
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 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.h"
+#include "amd_pcie.h"
+
+#include 
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct 
drm_amdgpu_info_device *dev_info)
+{
+   int ret;
+   uint64_t vm_size;
+   uint32_t pcie_gen_mask;
+
+   if (dev_info == NULL)
+   return -EINVAL;
+
+   dev_info->device_id = adev->pdev->device;
+   dev_info->chip_rev = adev->rev_id;
+   dev_info->external_rev = adev->external_rev_id;
+   dev_info->pci_rev = adev->pdev->revision;
+   dev_info->family = adev->family;
+   dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+   dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+   /* return all clocks in KHz */
+   dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+   if (adev->pm.dpm_enabled) {
+   dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 
10;
+   dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 
10;
+   dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 
10;
+   dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 
10;
+   } else {
+   dev_info->max_engine_clock =
+   dev_info->min_engine_clock =
+  

[PATCH] drm/amdgpu: refactor code to reuse system information

2024-03-19 Thread Sunil Khatri
Refactor the code so debugfs and devcoredump can reuse
the common information and avoid unnecessary copy of it.

created a new file which would be the right place to
hold functions which will be used between sysfs, debugfs
and devcoredump.

Cc: Christian König 
Cc: Alex Deucher 
Signed-off-by: Sunil Khatri 
---
 drivers/gpu/drm/amd/amdgpu/Makefile |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu.h |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c | 151 
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 118 +--
 4 files changed, 157 insertions(+), 115 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 4536c8ad0e11..05d34f4b18f5 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -80,7 +80,7 @@ amdgpu-y += amdgpu_device.o amdgpu_doorbell_mgr.o 
amdgpu_kms.o \
amdgpu_umc.o smu_v11_0_i2c.o amdgpu_fru_eeprom.o amdgpu_rap.o \
amdgpu_fw_attestation.o amdgpu_securedisplay.o \
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_ring_mux.o amdgpu_xcp.o amdgpu_seq64.o amdgpu_aca.o 
amdgpu_devinfo.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 9c62552bec34..0267870aa9b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1609,4 +1609,5 @@ extern const struct attribute_group 
amdgpu_vram_mgr_attr_group;
 extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
 extern const struct attribute_group amdgpu_flash_attr_group;
 
+int amdgpu_device_info(struct amdgpu_device *adev, struct 
drm_amdgpu_info_device *dev_info);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
new file mode 100644
index ..d2c15a1dcb0d
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_devinfo.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2024 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.h"
+#include "amd_pcie.h"
+
+#include 
+
+int amdgpu_device_info(struct amdgpu_device *adev, struct 
drm_amdgpu_info_device *dev_info)
+{
+   int ret;
+   uint64_t vm_size;
+   uint32_t pcie_gen_mask;
+
+   if (dev_info == NULL)
+   return -EINVAL;
+
+   dev_info->device_id = adev->pdev->device;
+   dev_info->chip_rev = adev->rev_id;
+   dev_info->external_rev = adev->external_rev_id;
+   dev_info->pci_rev = adev->pdev->revision;
+   dev_info->family = adev->family;
+   dev_info->num_shader_engines = adev->gfx.config.max_shader_engines;
+   dev_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
+   /* return all clocks in KHz */
+   dev_info->gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
+   if (adev->pm.dpm_enabled) {
+   dev_info->max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 
10;
+   dev_info->max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 
10;
+   dev_info->min_engine_clock = amdgpu_dpm_get_sclk(adev, true) * 
10;
+   dev_info->min_memory_clock = amdgpu_dpm_get_mclk(adev, true) * 
10;
+   } else {
+   dev_info->max_engine_clock =
+   dev_info->min_engine_clock =
+   adev->clock.default_sclk * 10;
+   dev_info->max_memory_clock =
+   dev_info->min_memory_clock =
+   adev->clock.default_mclk * 10;
+   }
+   dev_info->enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
+   dev_info->num_rb_pipes =