On Fri, Oct 4, 2019 at 3:01 PM Messinger, Ori <ori.messin...@amd.com> wrote:
>
> The vram vendor can be found as a separate sysfs file at:
> /sys/class/drm/card[X]/device/mem_info_vram_vendor
> The vram vendor is displayed as a string value.
>
> Change-Id: Iaa3ccf3f483ee6536281fe777772ba241a6e0d43
> Signed-off-by: Ori Messinger <ori.messin...@amd.com>
> ---
>  .../gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c  | 63 ++++++++++++++++++-
>  .../gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h  |  5 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c  | 43 +++++++++++++
>  drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c        |  5 +-
>  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         |  5 +-
>  5 files changed, 114 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c
> index 19913c39588b..59009726494b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c
> @@ -169,8 +169,11 @@ static int convert_atom_mem_type_to_vram_type(struct 
> amdgpu_device *adev,
>         return vram_type;
>  }
>
> -int amdgpu_atomfirmware_get_vram_info(struct amdgpu_device *adev,
> -                                     int *vram_width, int *vram_type)
> +
> +int
> +amdgpu_atomfirmware_get_vram_info(struct amdgpu_device *adev,
> +                                 int *vram_width, int *vram_type,
> +                                 int *vram_vendor)
>  {
>         struct amdgpu_mode_info *mode_info = &adev->mode_info;
>         int index, i = 0;
> @@ -180,6 +183,7 @@ int amdgpu_atomfirmware_get_vram_info(struct 
> amdgpu_device *adev,
>         union vram_module *vram_module;
>         u8 frev, crev;
>         u8 mem_type;
> +       u8 mem_vendor;
>         u32 mem_channel_number;
>         u32 mem_channel_width;
>         u32 module_id;
> @@ -231,6 +235,9 @@ int amdgpu_atomfirmware_get_vram_info(struct 
> amdgpu_device *adev,
>                                 mem_channel_width = 
> vram_module->v9.channel_width;
>                                 if (vram_width)
>                                         *vram_width = mem_channel_number * (1 
> << mem_channel_width);
> +                               mem_vendor = vram_module->v9.vender_rev_id;

Don't you need to mask this?  I think only the lower 4 bits are the vendor.

> +                               if (vram_vendor)
> +                                       *vram_vendor = mem_vendor;
>                                 break;
>                         case 4:
>                                 if (module_id > 
> vram_info->v24.vram_module_num)
> @@ -248,6 +255,9 @@ int amdgpu_atomfirmware_get_vram_info(struct 
> amdgpu_device *adev,
>                                 mem_channel_width = 
> vram_module->v10.channel_width;
>                                 if (vram_width)
>                                         *vram_width = mem_channel_number * (1 
> << mem_channel_width);
> +                               mem_vendor = vram_module->v10.vender_rev_id;

Same comment here.

> +                               if (vram_vendor)
> +                                       *vram_vendor = mem_vendor;
>                                 break;
>                         default:
>                                 return -EINVAL;
> @@ -259,6 +269,55 @@ int amdgpu_atomfirmware_get_vram_info(struct 
> amdgpu_device *adev,
>         return 0;
>  }
>
> +/*
> + * Return vram width from integrated system info table, if available,
> + * or 0 if not.
> + */
> +int amdgpu_atomfirmware_get_vram_width(struct amdgpu_device *adev)
> +{
> +       int vram_width = 0, vram_type = 0, vram_vendor = 0;
> +       int r = amdgpu_atomfirmware_get_vram_info(adev,
> +       &vram_width, &vram_type, &vram_vendor);
> +
> +       if (r)
> +               return 0;
> +
> +       return vram_width;
> +}
> +
> +/*
> + * Return vram type from either integrated system info table
> + * or umc info table, if available, or 0 (TYPE_UNKNOWN) if not
> + */
> +int amdgpu_atomfirmware_get_vram_type(struct amdgpu_device *adev)
> +{
> +       int vram_width = 0, vram_type = 0, vram_vendor = 0;
> +       int r = amdgpu_atomfirmware_get_vram_info(adev,
> +       &vram_width, &vram_type, &vram_vendor);
> +
> +       if (r)
> +               return 0;
> +
> +       return vram_type;
> +}
> +
> +/*
> + * Return vram vendor from either integrated system info table
> + * or umc info table, if available, or 0 (TYPE_UNKNOWN) if not
> + */
> +int amdgpu_atomfirmware_get_vram_vendor(struct amdgpu_device *adev)
> +{
> +       int vram_width = 0, vram_type = 0, vram_vendor = 0;
> +       int r = amdgpu_atomfirmware_get_vram_info(adev,
> +       &vram_width, &vram_type, &vram_vendor);
> +
> +       if (r)
> +               return 0;
> +
> +       return vram_vendor;
> +
> +}

They aren't used.  Drop them.  See my comment below.

> +
>  /*
>   * Return true if vbios enabled ecc by default, if umc info table is 
> available
>   * or false if ecc is not enabled or umc info table is not available
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h
> index 82819f03e444..738e538ee26c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h
> @@ -30,7 +30,10 @@ bool 
> amdgpu_atomfirmware_gpu_supports_virtualization(struct amdgpu_device *adev)
>  void amdgpu_atomfirmware_scratch_regs_init(struct amdgpu_device *adev);
>  int amdgpu_atomfirmware_allocate_fb_scratch(struct amdgpu_device *adev);
>  int amdgpu_atomfirmware_get_vram_info(struct amdgpu_device *adev,
> -                                     int *vram_width, int *vram_type);
> +       int *vram_width, int *vram_type, int *vram_vendor);
> +int amdgpu_atomfirmware_get_vram_width(struct amdgpu_device *adev);
> +int amdgpu_atomfirmware_get_vram_type(struct amdgpu_device *adev);
> +int amdgpu_atomfirmware_get_vram_vendor(struct amdgpu_device *adev);
>  int amdgpu_atomfirmware_get_clock_info(struct amdgpu_device *adev);
>  int amdgpu_atomfirmware_get_gfx_info(struct amdgpu_device *adev);
>  bool amdgpu_atomfirmware_mem_ecc_supported(struct amdgpu_device *adev);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 8887b3964e43..1e8dffe3323a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -24,6 +24,8 @@
>
>  #include "amdgpu.h"
>  #include "amdgpu_vm.h"
> +#include "amdgpu_atomfirmware.h"
> +#include "atom.h"
>
>  struct amdgpu_vram_mgr {
>         struct drm_mm mm;
> @@ -102,6 +104,39 @@ static ssize_t amdgpu_mem_info_vis_vram_used_show(struct 
> device *dev,
>                 amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]));
>  }
>
> +static ssize_t amdgpu_mem_info_vram_vendor(struct device *dev,
> +                                                struct device_attribute 
> *attr,
> +                                                char *buf)
> +{
> +       struct drm_device *ddev = dev_get_drvdata(dev);
> +       struct amdgpu_device *adev = ddev->dev_private;
> +
> +       switch (amdgpu_atomfirmware_get_vram_vendor(adev)) {

Let's not parse the vbios every time the user wants to read the vram
vendor.  Let's cache it in adev->gmc and populate it in gmc sw_init
and just use that here.


> +       case SAMSUNG:
> +               return snprintf(buf, PAGE_SIZE, "samsung\n");
> +       case INFINEON:
> +               return snprintf(buf, PAGE_SIZE, "infineon\n");
> +       case ELPIDA:
> +               return snprintf(buf, PAGE_SIZE, "elpida\n");
> +       case ETRON:
> +               return snprintf(buf, PAGE_SIZE, "etron\n");
> +       case NANYA:
> +               return snprintf(buf, PAGE_SIZE, "nanya\n");
> +       case HYNIX:
> +               return snprintf(buf, PAGE_SIZE, "hynix\n");
> +       case MOSEL:
> +               return snprintf(buf, PAGE_SIZE, "mosel\n");
> +       case WINBOND:
> +               return snprintf(buf, PAGE_SIZE, "winbond\n");
> +       case ESMT:
> +               return snprintf(buf, PAGE_SIZE, "esmt\n");
> +       case MICRON:
> +               return snprintf(buf, PAGE_SIZE, "micron\n");
> +       default:
> +               return snprintf(buf, PAGE_SIZE, "unknown\n");
> +       }
> +}
> +
>  static DEVICE_ATTR(mem_info_vram_total, S_IRUGO,
>                    amdgpu_mem_info_vram_total_show, NULL);
>  static DEVICE_ATTR(mem_info_vis_vram_total, S_IRUGO,
> @@ -110,6 +145,8 @@ static DEVICE_ATTR(mem_info_vram_used, S_IRUGO,
>                    amdgpu_mem_info_vram_used_show, NULL);
>  static DEVICE_ATTR(mem_info_vis_vram_used, S_IRUGO,
>                    amdgpu_mem_info_vis_vram_used_show, NULL);
> +static DEVICE_ATTR(mem_info_vram_vendor, S_IRUGO,
> +                  amdgpu_mem_info_vram_vendor, NULL);
>
>  /**
>   * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
> @@ -155,6 +192,11 @@ static int amdgpu_vram_mgr_init(struct 
> ttm_mem_type_manager *man,
>                 DRM_ERROR("Failed to create device file 
> mem_info_vis_vram_used\n");
>                 return ret;
>         }
> +       ret = device_create_file(adev->dev, &dev_attr_mem_info_vram_vendor);
> +       if (ret) {
> +               DRM_ERROR("Failed to create device file 
> mem_info_vram_vendor\n");
> +               return ret;
> +       }
>
>         return 0;
>  }
> @@ -181,6 +223,7 @@ static int amdgpu_vram_mgr_fini(struct 
> ttm_mem_type_manager *man)
>         device_remove_file(adev->dev, &dev_attr_mem_info_vis_vram_total);
>         device_remove_file(adev->dev, &dev_attr_mem_info_vram_used);
>         device_remove_file(adev->dev, &dev_attr_mem_info_vis_vram_used);
> +       device_remove_file(adev->dev, &dev_attr_mem_info_vram_vendor);
>         return 0;
>  }
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
> index cb3f61873baa..c434483a7791 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
> @@ -624,7 +624,7 @@ static unsigned gmc_v10_0_get_vbios_fb_size(struct 
> amdgpu_device *adev)
>
>  static int gmc_v10_0_sw_init(void *handle)
>  {
> -       int r, vram_width = 0, vram_type = 0;
> +       int r, vram_width = 0, vram_type = 0, vram_vendor = 0;
>         struct amdgpu_device *adev = (struct amdgpu_device *)handle;
>
>         gfxhub_v2_0_init(adev);
> @@ -632,7 +632,8 @@ static int gmc_v10_0_sw_init(void *handle)
>
>         spin_lock_init(&adev->gmc.invalidate_lock);
>
> -       r = amdgpu_atomfirmware_get_vram_info(adev, &vram_width, &vram_type);
> +       r = amdgpu_atomfirmware_get_vram_info(adev,
> +               &vram_width, &vram_type, &vram_vendor);
>         if (!amdgpu_emu_mode)
>                 adev->gmc.vram_width = vram_width;
>         else
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> index 4b11f7e61004..bcd305813788 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> @@ -930,7 +930,7 @@ static unsigned gmc_v9_0_get_vbios_fb_size(struct 
> amdgpu_device *adev)
>
>  static int gmc_v9_0_sw_init(void *handle)
>  {
> -       int r, vram_width = 0, vram_type = 0;
> +       int r, vram_width = 0, vram_type = 0, vram_vendor = 0;
>         struct amdgpu_device *adev = (struct amdgpu_device *)handle;
>
>         gfxhub_v1_0_init(adev);
> @@ -941,7 +941,8 @@ static int gmc_v9_0_sw_init(void *handle)
>
>         spin_lock_init(&adev->gmc.invalidate_lock);
>
> -       r = amdgpu_atomfirmware_get_vram_info(adev, &vram_width, &vram_type);
> +       r = amdgpu_atomfirmware_get_vram_info(adev,
> +               &vram_width, &vram_type, &vram_vendor);
>         if (amdgpu_sriov_vf(adev))
>                 /* For Vega10 SR-IOV, vram_width can't be read from ATOM as 
> RAVEN,
>                  * and DF related registers is not readable, seems hardcord 
> is the
> --
> 2.17.1
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reply via email to