aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
diff options
context:
space:
mode:
authorKent Russell <kent.russell@amd.com>2019-02-28 07:05:02 -0500
committerAlex Deucher <alexander.deucher@amd.com>2019-03-19 16:04:02 -0400
commit55c374e9eb72be0de5d4fe2ef4d7803cd4ea6329 (patch)
tree9f36f51832e46db2ab74948a91dec83864073bf6 /drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
parent07740adcbcd326060e142f6af674a036a5106c6f (diff)
drm/amdgpu: Add sysfs files for returning VRAM/GTT info v2
Add 6 files that return (in bytes): The total amount of VRAM/visible VRAM/GTT and the current total used VRAM/visible VRAM/GTT v2: Split used and total into separate files Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Kent Russell <kent.russell@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index da7b1b92d9cf..62591d081856 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -37,6 +37,47 @@ struct amdgpu_gtt_node {
37}; 37};
38 38
39/** 39/**
40 * DOC: mem_info_gtt_total
41 *
42 * The amdgpu driver provides a sysfs API for reporting current total size of
43 * the GTT.
44 * The file mem_info_gtt_total is used for this, and returns the total size of
45 * the GTT block, in bytes
46 */
47static ssize_t amdgpu_mem_info_gtt_total_show(struct device *dev,
48 struct device_attribute *attr, char *buf)
49{
50 struct drm_device *ddev = dev_get_drvdata(dev);
51 struct amdgpu_device *adev = ddev->dev_private;
52
53 return snprintf(buf, PAGE_SIZE, "%llu\n",
54 (adev->mman.bdev.man[TTM_PL_TT].size) * PAGE_SIZE);
55}
56
57/**
58 * DOC: mem_info_gtt_used
59 *
60 * The amdgpu driver provides a sysfs API for reporting current total amount of
61 * used GTT.
62 * The file mem_info_gtt_used is used for this, and returns the current used
63 * size of the GTT block, in bytes
64 */
65static ssize_t amdgpu_mem_info_gtt_used_show(struct device *dev,
66 struct device_attribute *attr, char *buf)
67{
68 struct drm_device *ddev = dev_get_drvdata(dev);
69 struct amdgpu_device *adev = ddev->dev_private;
70
71 return snprintf(buf, PAGE_SIZE, "%llu\n",
72 amdgpu_gtt_mgr_usage(&adev->mman.bdev.man[TTM_PL_TT]));
73}
74
75static DEVICE_ATTR(mem_info_gtt_total, S_IRUGO,
76 amdgpu_mem_info_gtt_total_show, NULL);
77static DEVICE_ATTR(mem_info_gtt_used, S_IRUGO,
78 amdgpu_mem_info_gtt_used_show, NULL);
79
80/**
40 * amdgpu_gtt_mgr_init - init GTT manager and DRM MM 81 * amdgpu_gtt_mgr_init - init GTT manager and DRM MM
41 * 82 *
42 * @man: TTM memory type manager 83 * @man: TTM memory type manager
@@ -50,6 +91,7 @@ static int amdgpu_gtt_mgr_init(struct ttm_mem_type_manager *man,
50 struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev); 91 struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
51 struct amdgpu_gtt_mgr *mgr; 92 struct amdgpu_gtt_mgr *mgr;
52 uint64_t start, size; 93 uint64_t start, size;
94 int ret;
53 95
54 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); 96 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
55 if (!mgr) 97 if (!mgr)
@@ -61,6 +103,18 @@ static int amdgpu_gtt_mgr_init(struct ttm_mem_type_manager *man,
61 spin_lock_init(&mgr->lock); 103 spin_lock_init(&mgr->lock);
62 atomic64_set(&mgr->available, p_size); 104 atomic64_set(&mgr->available, p_size);
63 man->priv = mgr; 105 man->priv = mgr;
106
107 ret = device_create_file(adev->dev, &dev_attr_mem_info_gtt_total);
108 if (ret) {
109 DRM_ERROR("Failed to create device file mem_info_gtt_total\n");
110 return ret;
111 }
112 ret = device_create_file(adev->dev, &dev_attr_mem_info_gtt_used);
113 if (ret) {
114 DRM_ERROR("Failed to create device file mem_info_gtt_used\n");
115 return ret;
116 }
117
64 return 0; 118 return 0;
65} 119}
66 120
@@ -74,12 +128,17 @@ static int amdgpu_gtt_mgr_init(struct ttm_mem_type_manager *man,
74 */ 128 */
75static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager *man) 129static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager *man)
76{ 130{
131 struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
77 struct amdgpu_gtt_mgr *mgr = man->priv; 132 struct amdgpu_gtt_mgr *mgr = man->priv;
78 spin_lock(&mgr->lock); 133 spin_lock(&mgr->lock);
79 drm_mm_takedown(&mgr->mm); 134 drm_mm_takedown(&mgr->mm);
80 spin_unlock(&mgr->lock); 135 spin_unlock(&mgr->lock);
81 kfree(mgr); 136 kfree(mgr);
82 man->priv = NULL; 137 man->priv = NULL;
138
139 device_remove_file(adev->dev, &dev_attr_mem_info_gtt_total);
140 device_remove_file(adev->dev, &dev_attr_mem_info_gtt_used);
141
83 return 0; 142 return 0;
84} 143}
85 144