drm/amdgpu: add vram_type and vram_bit_width for interface query (v2)
authorKen Wang <Qingqing.Wang@amd.com>
Wed, 3 Jun 2015 13:02:01 +0000 (21:02 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 4 Jun 2015 01:04:04 +0000 (21:04 -0400)
Track the type of vram on the board and provide a query for it.
User mode drivers and tools want this information for determining
bandwidth information and form informational purposes.

v2: fix build when CI support is not enabled

Signed-off-by: Ken Wang <Qingqing.Wang@amd.com>
Reviewed-by: Jammy Zhou <Jammy.Zhou@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
drivers/gpu/drm/amd/amdgpu/ci_dpm.c
drivers/gpu/drm/amd/amdgpu/cikd.h
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
drivers/gpu/drm/amd/amdgpu/vid.h
include/uapi/drm/amdgpu_drm.h

index 4bdc3265b410ce1fa9ddd3aacafc65cfe26f9ccc..149b769130910dcde19d3d90b29bb7a2c6aef9dc 100644 (file)
@@ -767,7 +767,7 @@ struct amdgpu_mc {
        const struct firmware   *fw;    /* MC firmware */
        uint32_t                fw_version;
        struct amdgpu_irq_src   vm_fault;
-       bool                    is_gddr5;
+       uint32_t                vram_type;
 };
 
 /*
index f1e5d87ef1f79dccf95090b9f6150472807a15cc..5533434c7a8fad8dd22bab138c84236befe13167 100644 (file)
@@ -457,6 +457,8 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
                dev_info.cu_ao_mask = cu_info.ao_cu_mask;
                dev_info.ce_ram_size = adev->gfx.ce_ram_size;
                memcpy(&dev_info.cu_bitmap[0], &cu_info.bitmap[0], sizeof(cu_info.bitmap));
+               dev_info.vram_type = adev->mc.vram_type;
+               dev_info.vram_bit_width = adev->mc.vram_width;
 
                return copy_to_user(out, &dev_info,
                                    min((size_t)size, sizeof(dev_info))) ? -EFAULT : 0;
index b1a4fbc22e69d7cde4c3d6a1f9ada06a7a8a6975..82e8d073051759f7b0307b7675282a8dfea280e8 100644 (file)
@@ -891,7 +891,7 @@ static void ci_dpm_powergate_uvd(struct amdgpu_device *adev, bool gate)
 static bool ci_dpm_vblank_too_short(struct amdgpu_device *adev)
 {
        u32 vblank_time = amdgpu_dpm_get_vblank_time(adev);
-       u32 switch_limit = adev->mc.is_gddr5 ? 450 : 300;
+       u32 switch_limit = adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5 ? 450 : 300;
 
        if (vblank_time < switch_limit)
                return true;
@@ -2920,7 +2920,7 @@ static int ci_calculate_mclk_params(struct amdgpu_device *adev,
        mpll_ad_func_cntl &= ~MPLL_AD_FUNC_CNTL__YCLK_POST_DIV_MASK;
        mpll_ad_func_cntl |= (mpll_param.post_div << MPLL_AD_FUNC_CNTL__YCLK_POST_DIV__SHIFT);
 
-       if (adev->mc.is_gddr5) {
+       if (adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5) {
                mpll_dq_func_cntl &= ~(MPLL_DQ_FUNC_CNTL__YCLK_SEL_MASK |
                                MPLL_AD_FUNC_CNTL__YCLK_POST_DIV_MASK);
                mpll_dq_func_cntl |= (mpll_param.yclk_sel << MPLL_DQ_FUNC_CNTL__YCLK_SEL__SHIFT) |
@@ -3043,7 +3043,7 @@ static int ci_populate_single_memory_level(struct amdgpu_device *adev,
            (memory_clock <= pi->mclk_strobe_mode_threshold))
                memory_level->StrobeEnable = 1;
 
-       if (adev->mc.is_gddr5) {
+       if (adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5) {
                memory_level->StrobeRatio =
                        ci_get_mclk_frequency_ratio(memory_clock, memory_level->StrobeEnable);
                if (pi->mclk_edc_enable_threshold &&
@@ -3681,7 +3681,7 @@ static int ci_init_smc_table(struct amdgpu_device *adev)
        if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC)
                table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
 
-       if (adev->mc.is_gddr5)
+       if (adev->mc.vram_type == AMDGPU_VRAM_TYPE_GDDR5)
                table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
 
        if (ulv->supported) {
@@ -4498,14 +4498,14 @@ static int ci_set_mc_special_registers(struct amdgpu_device *adev,
                        for (k = 0; k < table->num_entries; k++) {
                                table->mc_reg_table_entry[k].mc_data[j] =
                                        (temp_reg & 0xffff0000) | (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
-                               if (!adev->mc.is_gddr5)
+                               if (adev->mc.vram_type != AMDGPU_VRAM_TYPE_GDDR5)
                                        table->mc_reg_table_entry[k].mc_data[j] |= 0x100;
                        }
                        j++;
                        if (j > SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE)
                                return -EINVAL;
 
-                       if (!adev->mc.is_gddr5) {
+                       if (adev->mc.vram_type != AMDGPU_VRAM_TYPE_GDDR5) {
                                table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD;
                                table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD;
                                for (k = 0; k < table->num_entries; k++) {
index 11828e2cdf348ca54bf7a467489af249241bb81b..220865a44814a59a1934b4de16a87d1d797a3541 100644 (file)
 #ifndef CIK_H
 #define CIK_H
 
-#define MC_SEQ_MISC0__GDDR5__SHIFT     0x1c
-#define MC_SEQ_MISC0__GDDR5_MASK       0xf0000000
-#define MC_SEQ_MISC0__GDDR5_VALUE      5
+#define MC_SEQ_MISC0__MT__MASK 0xf0000000
+#define MC_SEQ_MISC0__MT__GDDR1  0x10000000
+#define MC_SEQ_MISC0__MT__DDR2   0x20000000
+#define MC_SEQ_MISC0__MT__GDDR3  0x30000000
+#define MC_SEQ_MISC0__MT__GDDR4  0x40000000
+#define MC_SEQ_MISC0__MT__GDDR5  0x50000000
+#define MC_SEQ_MISC0__MT__HBM    0x60000000
+#define MC_SEQ_MISC0__MT__DDR3   0xB0000000
 
 #define CP_ME_TABLE_SIZE    96
 
index 01cd6b207d261b8124bc03adf5897e10f3e5c0ad..ae37fce36520197645050c46f8b2f5a269761e33 100644 (file)
@@ -812,6 +812,28 @@ static void gmc_v7_0_enable_hdp_ls(struct amdgpu_device *adev,
                WREG32(mmHDP_MEM_POWER_LS, data);
 }
 
+static int gmc_v7_0_convert_vram_type(int mc_seq_vram_type)
+{
+       switch (mc_seq_vram_type) {
+       case MC_SEQ_MISC0__MT__GDDR1:
+               return AMDGPU_VRAM_TYPE_GDDR1;
+       case MC_SEQ_MISC0__MT__DDR2:
+               return AMDGPU_VRAM_TYPE_DDR2;
+       case MC_SEQ_MISC0__MT__GDDR3:
+               return AMDGPU_VRAM_TYPE_GDDR3;
+       case MC_SEQ_MISC0__MT__GDDR4:
+               return AMDGPU_VRAM_TYPE_GDDR4;
+       case MC_SEQ_MISC0__MT__GDDR5:
+               return AMDGPU_VRAM_TYPE_GDDR5;
+       case MC_SEQ_MISC0__MT__HBM:
+               return AMDGPU_VRAM_TYPE_HBM;
+       case MC_SEQ_MISC0__MT__DDR3:
+               return AMDGPU_VRAM_TYPE_DDR3;
+       default:
+               return AMDGPU_VRAM_TYPE_UNKNOWN;
+       }
+}
+
 static int gmc_v7_0_early_init(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -820,15 +842,11 @@ static int gmc_v7_0_early_init(void *handle)
        gmc_v7_0_set_irq_funcs(adev);
 
        if (adev->flags & AMDGPU_IS_APU) {
-               adev->mc.is_gddr5 = false;
+               adev->mc.vram_type = AMDGPU_VRAM_TYPE_UNKNOWN;
        } else {
                u32 tmp = RREG32(mmMC_SEQ_MISC0);
-
-               if (((tmp & MC_SEQ_MISC0__GDDR5_MASK) >>
-                    MC_SEQ_MISC0__GDDR5__SHIFT) == MC_SEQ_MISC0__GDDR5_VALUE)
-                       adev->mc.is_gddr5 = true;
-               else
-                       adev->mc.is_gddr5 = false;
+               tmp &= MC_SEQ_MISC0__MT__MASK;
+               adev->mc.vram_type = gmc_v7_0_convert_vram_type(tmp);
        }
 
        return 0;
index 675483a612c226cff90c773c90ab314e8f436fb0..6206fcd39df90a269ae63ea0e194d0332d17c6ba 100644 (file)
@@ -38,6 +38,7 @@
 #include "vid.h"
 #include "vi.h"
 
+
 static void gmc_v8_0_set_gart_funcs(struct amdgpu_device *adev);
 static void gmc_v8_0_set_irq_funcs(struct amdgpu_device *adev);
 
@@ -786,6 +787,28 @@ static void gmc_v8_0_vm_decode_fault(struct amdgpu_device *adev,
               "write" : "read", block, mc_client, mc_id);
 }
 
+static int gmc_v8_0_convert_vram_type(int mc_seq_vram_type)
+{
+       switch (mc_seq_vram_type) {
+       case MC_SEQ_MISC0__MT__GDDR1:
+               return AMDGPU_VRAM_TYPE_GDDR1;
+       case MC_SEQ_MISC0__MT__DDR2:
+               return AMDGPU_VRAM_TYPE_DDR2;
+       case MC_SEQ_MISC0__MT__GDDR3:
+               return AMDGPU_VRAM_TYPE_GDDR3;
+       case MC_SEQ_MISC0__MT__GDDR4:
+               return AMDGPU_VRAM_TYPE_GDDR4;
+       case MC_SEQ_MISC0__MT__GDDR5:
+               return AMDGPU_VRAM_TYPE_GDDR5;
+       case MC_SEQ_MISC0__MT__HBM:
+               return AMDGPU_VRAM_TYPE_HBM;
+       case MC_SEQ_MISC0__MT__DDR3:
+               return AMDGPU_VRAM_TYPE_DDR3;
+       default:
+               return AMDGPU_VRAM_TYPE_UNKNOWN;
+       }
+}
+
 static int gmc_v8_0_early_init(void *handle)
 {
        struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -794,15 +817,11 @@ static int gmc_v8_0_early_init(void *handle)
        gmc_v8_0_set_irq_funcs(adev);
 
        if (adev->flags & AMDGPU_IS_APU) {
-               adev->mc.is_gddr5 = false;
+               adev->mc.vram_type = AMDGPU_VRAM_TYPE_UNKNOWN;
        } else {
                u32 tmp = RREG32(mmMC_SEQ_MISC0);
-
-               if (((tmp & MC_SEQ_MISC0__GDDR5_MASK) >>
-                    MC_SEQ_MISC0__GDDR5__SHIFT) == MC_SEQ_MISC0__GDDR5_VALUE)
-                       adev->mc.is_gddr5 = true;
-               else
-                       adev->mc.is_gddr5 = false;
+               tmp &= MC_SEQ_MISC0__MT__MASK;
+               adev->mc.vram_type = gmc_v8_0_convert_vram_type(tmp);
        }
 
        return 0;
index 385267c31d11a1aee69684d5574314d80f6a1c97..31bb89452e1245d5b78fc71015a6d2d021403c76 100644 (file)
 
 #define RB_BITMAP_WIDTH_PER_SH     2
 
-#define MC_SEQ_MISC0__GDDR5__SHIFT     0x1c
-#define MC_SEQ_MISC0__GDDR5_MASK       0xf0000000
-#define MC_SEQ_MISC0__GDDR5_VALUE      5
+#define MC_SEQ_MISC0__MT__MASK 0xf0000000
+#define MC_SEQ_MISC0__MT__GDDR1  0x10000000
+#define MC_SEQ_MISC0__MT__DDR2   0x20000000
+#define MC_SEQ_MISC0__MT__GDDR3  0x30000000
+#define MC_SEQ_MISC0__MT__GDDR4  0x40000000
+#define MC_SEQ_MISC0__MT__GDDR5  0x50000000
+#define MC_SEQ_MISC0__MT__HBM    0x60000000
+#define MC_SEQ_MISC0__MT__DDR3   0xB0000000
 
 /*
  * PM4
index 3af5bd0e23a8260cb3b4e37bb5e3e3629117a80a..c90f4f0d059ed718a2b707b239cb7f2c2e2be7dd 100644 (file)
@@ -540,6 +540,15 @@ struct drm_amdgpu_info_firmware {
        uint32_t feature;
 };
 
+#define AMDGPU_VRAM_TYPE_UNKNOWN 0
+#define AMDGPU_VRAM_TYPE_GDDR1 1
+#define AMDGPU_VRAM_TYPE_DDR2  2
+#define AMDGPU_VRAM_TYPE_GDDR3 3
+#define AMDGPU_VRAM_TYPE_GDDR4 4
+#define AMDGPU_VRAM_TYPE_GDDR5 5
+#define AMDGPU_VRAM_TYPE_HBM   6
+#define AMDGPU_VRAM_TYPE_DDR3  7
+
 struct drm_amdgpu_info_device {
        /** PCI Device ID */
        uint32_t device_id;
@@ -575,6 +584,10 @@ struct drm_amdgpu_info_device {
        uint32_t gart_page_size;
        /** constant engine ram size*/
        uint32_t ce_ram_size;
+       /** video memory type infro*/
+       uint32_t vram_type;
+       /** video memory bit width*/
+       uint32_t vram_bit_width;
 };
 
 struct drm_amdgpu_info_hw_ip {