aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-graphics/drm/libdrm-2.4.66/0119-amdgpu-add-vram-memory-info.patch
blob: a52e792db64ebe9e55b4c4fc04121e3a851922ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
From 4bbad6a36ed6416d254a8c0e4bbab07fe29a7acf Mon Sep 17 00:00:00 2001
From: Junwei Zhang <Jerry.Zhang@amd.com>
Date: Wed, 21 Sep 2016 10:43:40 +0800
Subject: [PATCH 02/10] amdgpu: add vram memory info
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Change-Id: Ic73eb5ad601496530be5e8c84a6c2b18aa43f0f1
Signed-off-by: Junwei Zhang <Jerry.Zhang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
---
 amdgpu/amdgpu.h          | 50 ++++++++++++++++++++++++++++++++++++++++++
 amdgpu/amdgpu_gpu_info.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 107 insertions(+)

diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
index 8b87990..7b466dd 100644
--- a/amdgpu/amdgpu.h
+++ b/amdgpu/amdgpu.h
@@ -415,6 +415,40 @@ struct amdgpu_heap_info {
 	uint64_t max_allocation;
 };
 
+struct amdgpu_heap_info2 {
+	/** max. physical memory */
+	uint64_t total_heap_size;
+
+	/** Theoretical max. available memory in the given heap */
+	uint64_t usable_heap_size;
+
+	/**
+	 * Number of bytes allocated in the heap. This includes all processes
+	 * and private allocations in the kernel. It changes when new buffers
+	 * are allocated, freed, and moved. It cannot be larger than
+	 * heap_size.
+	 */
+	uint64_t heap_usage;
+
+	/**
+	 * Theoretical possible max. size of buffer which
+	 * could be allocated in the given heap
+	 */
+	uint64_t max_allocation;
+};
+
+/**
+ * Structure which provide information about heap
+ *
+ * \sa amdgpu_query_memory_info()
+ *
+ */
+struct amdgpu_memory_info {
+	struct amdgpu_heap_info2 vram;
+	struct amdgpu_heap_info2 cpu_accessible_vram;
+	struct amdgpu_heap_info2 gtt;
+};
+
 /**
  * Describe GPU h/w info needed for UMD correct initialization
  *
@@ -1141,6 +1175,22 @@ int amdgpu_query_heap_info(amdgpu_device_handle dev, uint32_t heap,
 			   uint32_t flags, struct amdgpu_heap_info *info);
 
 /**
+ * Query memory information
+ *
+ * This query allows UMD to query potentially available memory resources
+ * and total memory size.
+ *
+ * \param   dev  - \c [in] Device handle. See #amdgpu_device_initialize()
+ * \param   mem  - \c [out] Pointer to structure to get memory information
+ *
+ * \return   0 on success\n
+ *          <0 - Negative POSIX Error code
+ *
+*/
+int amdgpu_query_memory_info(amdgpu_device_handle dev,
+			struct amdgpu_memory_info *mem);
+
+/**
  * Get the CRTC ID from the mode object ID
  *
  * \param   dev    - \c [in] Device handle. See #amdgpu_device_initialize()
diff --git a/amdgpu/amdgpu_gpu_info.c b/amdgpu/amdgpu_gpu_info.c
index d801b86..d3796ac 100644
--- a/amdgpu/amdgpu_gpu_info.c
+++ b/amdgpu/amdgpu_gpu_info.c
@@ -243,6 +243,63 @@ int amdgpu_query_gpu_info(amdgpu_device_handle dev,
 	return 0;
 }
 
+int amdgpu_query_memory_info(amdgpu_device_handle dev,
+			struct amdgpu_memory_info *mem)
+{
+	struct drm_amdgpu_info_vram_gtt vram_gtt_info = {};
+	struct drm_amdgpu_info_vram_gtt_total vram_gtt_total_info = {};
+	struct drm_amdgpu_info_vram_gtt_max vram_gtt_max_info = {};
+	int r;
+
+	r = amdgpu_query_info(dev, AMDGPU_INFO_VRAM_GTT,
+			      sizeof(vram_gtt_info), &vram_gtt_info);
+	if (r)
+		return r;
+
+	r = amdgpu_query_info(dev, AMDGPU_INFO_VRAM_GTT_TOTAL,
+			      sizeof(vram_gtt_total_info), &vram_gtt_total_info);
+	if (r)
+		return r;
+
+	r = amdgpu_query_info(dev, AMDGPU_INFO_VRAM_GTT_MAX,
+			      sizeof(vram_gtt_max_info), &vram_gtt_max_info);
+	if (r)
+		return r;
+
+	/* vram info */
+	mem->vram.total_heap_size = vram_gtt_total_info.vram_total_size;
+	mem->vram.usable_heap_size = vram_gtt_info.vram_size;
+	mem->vram.max_allocation = vram_gtt_max_info.vram_max_size;
+	r = amdgpu_query_info(dev, AMDGPU_INFO_VRAM_USAGE,
+			      sizeof(mem->vram.heap_usage),
+			      &mem->vram.heap_usage);
+	if (r)
+		return r;
+
+	/* visible vram info */
+	mem->cpu_accessible_vram.total_heap_size = vram_gtt_total_info.vram_cpu_accessible_total_size;
+	mem->cpu_accessible_vram.usable_heap_size = vram_gtt_info.vram_cpu_accessible_size;
+	mem->cpu_accessible_vram.max_allocation = vram_gtt_max_info.vram_cpu_accessible_max_size;
+	r = amdgpu_query_info(dev, AMDGPU_INFO_VIS_VRAM_USAGE,
+			      sizeof(mem->cpu_accessible_vram.heap_usage),
+			      &mem->cpu_accessible_vram.heap_usage);
+	if (r)
+		return r;
+
+	/* gtt info */
+	mem->gtt.total_heap_size = vram_gtt_total_info.gtt_total_size;
+	mem->gtt.usable_heap_size = vram_gtt_info.gtt_size;
+	mem->gtt.max_allocation = vram_gtt_max_info.gtt_max_size;
+
+	r = amdgpu_query_info(dev, AMDGPU_INFO_GTT_USAGE,
+			sizeof(mem->gtt.heap_usage),
+			&mem->gtt.heap_usage);
+	if (r)
+		return r;
+
+	return 0;
+}
+
 int amdgpu_query_heap_info(amdgpu_device_handle dev,
 			uint32_t heap,
 			uint32_t flags,
-- 
2.7.4