aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm
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
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')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c59
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c109
2 files changed, 168 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
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 3f9d5d00c9b3..ec9ea3fdbb4a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -33,6 +33,85 @@ struct amdgpu_vram_mgr {
33}; 33};
34 34
35/** 35/**
36 * DOC: mem_info_vram_total
37 *
38 * The amdgpu driver provides a sysfs API for reporting current total VRAM
39 * available on the device
40 * The file mem_info_vram_total is used for this and returns the total
41 * amount of VRAM in bytes
42 */
43static ssize_t amdgpu_mem_info_vram_total_show(struct device *dev,
44 struct device_attribute *attr, char *buf)
45{
46 struct drm_device *ddev = dev_get_drvdata(dev);
47 struct amdgpu_device *adev = ddev->dev_private;
48
49 return snprintf(buf, PAGE_SIZE, "%llu\n", adev->gmc.real_vram_size);
50}
51
52/**
53 * DOC: mem_info_vis_vram_total
54 *
55 * The amdgpu driver provides a sysfs API for reporting current total
56 * visible VRAM available on the device
57 * The file mem_info_vis_vram_total is used for this and returns the total
58 * amount of visible VRAM in bytes
59 */
60static ssize_t amdgpu_mem_info_vis_vram_total_show(struct device *dev,
61 struct device_attribute *attr, char *buf)
62{
63 struct drm_device *ddev = dev_get_drvdata(dev);
64 struct amdgpu_device *adev = ddev->dev_private;
65
66 return snprintf(buf, PAGE_SIZE, "%llu\n", adev->gmc.visible_vram_size);
67}
68
69/**
70 * DOC: mem_info_vram_used
71 *
72 * The amdgpu driver provides a sysfs API for reporting current total VRAM
73 * available on the device
74 * The file mem_info_vram_used is used for this and returns the total
75 * amount of currently used VRAM in bytes
76 */
77static ssize_t amdgpu_mem_info_vram_used_show(struct device *dev,
78 struct device_attribute *attr, char *buf)
79{
80 struct drm_device *ddev = dev_get_drvdata(dev);
81 struct amdgpu_device *adev = ddev->dev_private;
82
83 return snprintf(buf, PAGE_SIZE, "%llu\n",
84 amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]));
85}
86
87/**
88 * DOC: mem_info_vis_vram_used
89 *
90 * The amdgpu driver provides a sysfs API for reporting current total of
91 * used visible VRAM
92 * The file mem_info_vis_vram_used is used for this and returns the total
93 * amount of currently used visible VRAM in bytes
94 */
95static ssize_t amdgpu_mem_info_vis_vram_used_show(struct device *dev,
96 struct device_attribute *attr, char *buf)
97{
98 struct drm_device *ddev = dev_get_drvdata(dev);
99 struct amdgpu_device *adev = ddev->dev_private;
100
101 return snprintf(buf, PAGE_SIZE, "%llu\n",
102 amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]));
103}
104
105static DEVICE_ATTR(mem_info_vram_total, S_IRUGO,
106 amdgpu_mem_info_vram_total_show, NULL);
107static DEVICE_ATTR(mem_info_vis_vram_total, S_IRUGO,
108 amdgpu_mem_info_vis_vram_total_show,NULL);
109static DEVICE_ATTR(mem_info_vram_used, S_IRUGO,
110 amdgpu_mem_info_vram_used_show, NULL);
111static DEVICE_ATTR(mem_info_vis_vram_used, S_IRUGO,
112 amdgpu_mem_info_vis_vram_used_show, NULL);
113
114/**
36 * amdgpu_vram_mgr_init - init VRAM manager and DRM MM 115 * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
37 * 116 *
38 * @man: TTM memory type manager 117 * @man: TTM memory type manager
@@ -43,7 +122,9 @@ struct amdgpu_vram_mgr {
43static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, 122static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man,
44 unsigned long p_size) 123 unsigned long p_size)
45{ 124{
125 struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
46 struct amdgpu_vram_mgr *mgr; 126 struct amdgpu_vram_mgr *mgr;
127 int ret;
47 128
48 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); 129 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
49 if (!mgr) 130 if (!mgr)
@@ -52,6 +133,29 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man,
52 drm_mm_init(&mgr->mm, 0, p_size); 133 drm_mm_init(&mgr->mm, 0, p_size);
53 spin_lock_init(&mgr->lock); 134 spin_lock_init(&mgr->lock);
54 man->priv = mgr; 135 man->priv = mgr;
136
137 /* Add the two VRAM-related sysfs files */
138 ret = device_create_file(adev->dev, &dev_attr_mem_info_vram_total);
139 if (ret) {
140 DRM_ERROR("Failed to create device file mem_info_vram_total\n");
141 return ret;
142 }
143 ret = device_create_file(adev->dev, &dev_attr_mem_info_vis_vram_total);
144 if (ret) {
145 DRM_ERROR("Failed to create device file mem_info_vis_vram_total\n");
146 return ret;
147 }
148 ret = device_create_file(adev->dev, &dev_attr_mem_info_vram_used);
149 if (ret) {
150 DRM_ERROR("Failed to create device file mem_info_vram_used\n");
151 return ret;
152 }
153 ret = device_create_file(adev->dev, &dev_attr_mem_info_vis_vram_used);
154 if (ret) {
155 DRM_ERROR("Failed to create device file mem_info_vis_vram_used\n");
156 return ret;
157 }
158
55 return 0; 159 return 0;
56} 160}
57 161
@@ -65,6 +169,7 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man,
65 */ 169 */
66static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man) 170static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man)
67{ 171{
172 struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
68 struct amdgpu_vram_mgr *mgr = man->priv; 173 struct amdgpu_vram_mgr *mgr = man->priv;
69 174
70 spin_lock(&mgr->lock); 175 spin_lock(&mgr->lock);
@@ -72,6 +177,10 @@ static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man)
72 spin_unlock(&mgr->lock); 177 spin_unlock(&mgr->lock);
73 kfree(mgr); 178 kfree(mgr);
74 man->priv = NULL; 179 man->priv = NULL;
180 device_remove_file(adev->dev, &dev_attr_mem_info_vram_total);
181 device_remove_file(adev->dev, &dev_attr_mem_info_vis_vram_total);
182 device_remove_file(adev->dev, &dev_attr_mem_info_vram_used);
183 device_remove_file(adev->dev, &dev_attr_mem_info_vis_vram_used);
75 return 0; 184 return 0;
76} 185}
77 186