xref: /dflybsd-src/sys/dev/drm/amd/amdgpu/amdgpu_gfx.c (revision 789731325bde747251c28a37e0a00ed4efb88c46)
1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev  * Copyright 2014 Advanced Micro Devices, Inc.
3b843c749SSergey Zigachev  * Copyright 2008 Red Hat Inc.
4b843c749SSergey Zigachev  * Copyright 2009 Jerome Glisse.
5b843c749SSergey Zigachev  *
6b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
7b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
8b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
9b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
11b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
12b843c749SSergey Zigachev  *
13b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
14b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
15b843c749SSergey Zigachev  *
16b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
23b843c749SSergey Zigachev  *
24b843c749SSergey Zigachev  */
25b843c749SSergey Zigachev #include <drm/drmP.h>
26b843c749SSergey Zigachev #include "amdgpu.h"
27b843c749SSergey Zigachev #include "amdgpu_gfx.h"
28b843c749SSergey Zigachev 
29b843c749SSergey Zigachev /*
30b843c749SSergey Zigachev  * GPU scratch registers helpers function.
31b843c749SSergey Zigachev  */
32b843c749SSergey Zigachev /**
33b843c749SSergey Zigachev  * amdgpu_gfx_scratch_get - Allocate a scratch register
34b843c749SSergey Zigachev  *
35b843c749SSergey Zigachev  * @adev: amdgpu_device pointer
36b843c749SSergey Zigachev  * @reg: scratch register mmio offset
37b843c749SSergey Zigachev  *
38b843c749SSergey Zigachev  * Allocate a CP scratch register for use by the driver (all asics).
39b843c749SSergey Zigachev  * Returns 0 on success or -EINVAL on failure.
40b843c749SSergey Zigachev  */
amdgpu_gfx_scratch_get(struct amdgpu_device * adev,uint32_t * reg)41b843c749SSergey Zigachev int amdgpu_gfx_scratch_get(struct amdgpu_device *adev, uint32_t *reg)
42b843c749SSergey Zigachev {
43b843c749SSergey Zigachev 	int i;
44b843c749SSergey Zigachev 
45b843c749SSergey Zigachev 	i = ffs(adev->gfx.scratch.free_mask);
46b843c749SSergey Zigachev 	if (i != 0 && i <= adev->gfx.scratch.num_reg) {
47b843c749SSergey Zigachev 		i--;
48b843c749SSergey Zigachev 		adev->gfx.scratch.free_mask &= ~(1u << i);
49b843c749SSergey Zigachev 		*reg = adev->gfx.scratch.reg_base + i;
50b843c749SSergey Zigachev 		return 0;
51b843c749SSergey Zigachev 	}
52b843c749SSergey Zigachev 	return -EINVAL;
53b843c749SSergey Zigachev }
54b843c749SSergey Zigachev 
55b843c749SSergey Zigachev /**
56b843c749SSergey Zigachev  * amdgpu_gfx_scratch_free - Free a scratch register
57b843c749SSergey Zigachev  *
58b843c749SSergey Zigachev  * @adev: amdgpu_device pointer
59b843c749SSergey Zigachev  * @reg: scratch register mmio offset
60b843c749SSergey Zigachev  *
61b843c749SSergey Zigachev  * Free a CP scratch register allocated for use by the driver (all asics)
62b843c749SSergey Zigachev  */
amdgpu_gfx_scratch_free(struct amdgpu_device * adev,uint32_t reg)63b843c749SSergey Zigachev void amdgpu_gfx_scratch_free(struct amdgpu_device *adev, uint32_t reg)
64b843c749SSergey Zigachev {
65b843c749SSergey Zigachev 	adev->gfx.scratch.free_mask |= 1u << (reg - adev->gfx.scratch.reg_base);
66b843c749SSergey Zigachev }
67b843c749SSergey Zigachev 
68b843c749SSergey Zigachev /**
69b843c749SSergey Zigachev  * amdgpu_gfx_parse_disable_cu - Parse the disable_cu module parameter
70b843c749SSergey Zigachev  *
71b843c749SSergey Zigachev  * @mask: array in which the per-shader array disable masks will be stored
72b843c749SSergey Zigachev  * @max_se: number of SEs
73b843c749SSergey Zigachev  * @max_sh: number of SHs
74b843c749SSergey Zigachev  *
75b843c749SSergey Zigachev  * The bitmask of CUs to be disabled in the shader array determined by se and
76b843c749SSergey Zigachev  * sh is stored in mask[se * max_sh + sh].
77b843c749SSergey Zigachev  */
amdgpu_gfx_parse_disable_cu(unsigned * mask,unsigned max_se,unsigned max_sh)78b843c749SSergey Zigachev void amdgpu_gfx_parse_disable_cu(unsigned *mask, unsigned max_se, unsigned max_sh)
79b843c749SSergey Zigachev {
80b843c749SSergey Zigachev 	unsigned se, sh, cu;
81b843c749SSergey Zigachev 	const char *p;
82b843c749SSergey Zigachev 
83b843c749SSergey Zigachev 	memset(mask, 0, sizeof(*mask) * max_se * max_sh);
84b843c749SSergey Zigachev 
85b843c749SSergey Zigachev 	if (!amdgpu_disable_cu || !*amdgpu_disable_cu)
86b843c749SSergey Zigachev 		return;
87b843c749SSergey Zigachev 
88b843c749SSergey Zigachev 	p = amdgpu_disable_cu;
89b843c749SSergey Zigachev 	for (;;) {
90b843c749SSergey Zigachev 		char *next;
91*78973132SSergey Zigachev 		int ret = ksscanf(p, "%u.%u.%u", &se, &sh, &cu);
92b843c749SSergey Zigachev 		if (ret < 3) {
93b843c749SSergey Zigachev 			DRM_ERROR("amdgpu: could not parse disable_cu\n");
94b843c749SSergey Zigachev 			return;
95b843c749SSergey Zigachev 		}
96b843c749SSergey Zigachev 
97b843c749SSergey Zigachev 		if (se < max_se && sh < max_sh && cu < 16) {
98b843c749SSergey Zigachev 			DRM_INFO("amdgpu: disabling CU %u.%u.%u\n", se, sh, cu);
99b843c749SSergey Zigachev 			mask[se * max_sh + sh] |= 1u << cu;
100b843c749SSergey Zigachev 		} else {
101b843c749SSergey Zigachev 			DRM_ERROR("amdgpu: disable_cu %u.%u.%u is out of range\n",
102b843c749SSergey Zigachev 				  se, sh, cu);
103b843c749SSergey Zigachev 		}
104b843c749SSergey Zigachev 
105b843c749SSergey Zigachev 		next = strchr(p, ',');
106b843c749SSergey Zigachev 		if (!next)
107b843c749SSergey Zigachev 			break;
108b843c749SSergey Zigachev 		p = next + 1;
109b843c749SSergey Zigachev 	}
110b843c749SSergey Zigachev }
111b843c749SSergey Zigachev 
amdgpu_gfx_is_multipipe_capable(struct amdgpu_device * adev)112b843c749SSergey Zigachev static bool amdgpu_gfx_is_multipipe_capable(struct amdgpu_device *adev)
113b843c749SSergey Zigachev {
114b843c749SSergey Zigachev 	if (amdgpu_compute_multipipe != -1) {
115b843c749SSergey Zigachev 		DRM_INFO("amdgpu: forcing compute pipe policy %d\n",
116b843c749SSergey Zigachev 			 amdgpu_compute_multipipe);
117b843c749SSergey Zigachev 		return amdgpu_compute_multipipe == 1;
118b843c749SSergey Zigachev 	}
119b843c749SSergey Zigachev 
120b843c749SSergey Zigachev 	/* FIXME: spreading the queues across pipes causes perf regressions
121b843c749SSergey Zigachev 	 * on POLARIS11 compute workloads */
122b843c749SSergey Zigachev 	if (adev->asic_type == CHIP_POLARIS11)
123b843c749SSergey Zigachev 		return false;
124b843c749SSergey Zigachev 
125b843c749SSergey Zigachev 	return adev->gfx.mec.num_mec > 1;
126b843c749SSergey Zigachev }
127b843c749SSergey Zigachev 
amdgpu_gfx_compute_queue_acquire(struct amdgpu_device * adev)128b843c749SSergey Zigachev void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)
129b843c749SSergey Zigachev {
130b843c749SSergey Zigachev 	int i, queue, pipe, mec;
131b843c749SSergey Zigachev 	bool multipipe_policy = amdgpu_gfx_is_multipipe_capable(adev);
132b843c749SSergey Zigachev 
133b843c749SSergey Zigachev 	/* policy for amdgpu compute queue ownership */
134b843c749SSergey Zigachev 	for (i = 0; i < AMDGPU_MAX_COMPUTE_QUEUES; ++i) {
135b843c749SSergey Zigachev 		queue = i % adev->gfx.mec.num_queue_per_pipe;
136b843c749SSergey Zigachev 		pipe = (i / adev->gfx.mec.num_queue_per_pipe)
137b843c749SSergey Zigachev 			% adev->gfx.mec.num_pipe_per_mec;
138b843c749SSergey Zigachev 		mec = (i / adev->gfx.mec.num_queue_per_pipe)
139b843c749SSergey Zigachev 			/ adev->gfx.mec.num_pipe_per_mec;
140b843c749SSergey Zigachev 
141b843c749SSergey Zigachev 		/* we've run out of HW */
142b843c749SSergey Zigachev 		if (mec >= adev->gfx.mec.num_mec)
143b843c749SSergey Zigachev 			break;
144b843c749SSergey Zigachev 
145b843c749SSergey Zigachev 		if (multipipe_policy) {
146b843c749SSergey Zigachev 			/* policy: amdgpu owns the first two queues of the first MEC */
147b843c749SSergey Zigachev 			if (mec == 0 && queue < 2)
148b843c749SSergey Zigachev 				set_bit(i, adev->gfx.mec.queue_bitmap);
149b843c749SSergey Zigachev 		} else {
150b843c749SSergey Zigachev 			/* policy: amdgpu owns all queues in the first pipe */
151b843c749SSergey Zigachev 			if (mec == 0 && pipe == 0)
152b843c749SSergey Zigachev 				set_bit(i, adev->gfx.mec.queue_bitmap);
153b843c749SSergey Zigachev 		}
154b843c749SSergey Zigachev 	}
155b843c749SSergey Zigachev 
156b843c749SSergey Zigachev 	/* update the number of active compute rings */
157b843c749SSergey Zigachev 	adev->gfx.num_compute_rings =
158b843c749SSergey Zigachev 		bitmap_weight(adev->gfx.mec.queue_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
159b843c749SSergey Zigachev 
160b843c749SSergey Zigachev 	/* If you hit this case and edited the policy, you probably just
161b843c749SSergey Zigachev 	 * need to increase AMDGPU_MAX_COMPUTE_RINGS */
162b843c749SSergey Zigachev 	if (WARN_ON(adev->gfx.num_compute_rings > AMDGPU_MAX_COMPUTE_RINGS))
163b843c749SSergey Zigachev 		adev->gfx.num_compute_rings = AMDGPU_MAX_COMPUTE_RINGS;
164b843c749SSergey Zigachev }
165b843c749SSergey Zigachev 
amdgpu_gfx_kiq_acquire(struct amdgpu_device * adev,struct amdgpu_ring * ring)166b843c749SSergey Zigachev static int amdgpu_gfx_kiq_acquire(struct amdgpu_device *adev,
167b843c749SSergey Zigachev 				  struct amdgpu_ring *ring)
168b843c749SSergey Zigachev {
169b843c749SSergey Zigachev 	int queue_bit;
170b843c749SSergey Zigachev 	int mec, pipe, queue;
171b843c749SSergey Zigachev 
172b843c749SSergey Zigachev 	queue_bit = adev->gfx.mec.num_mec
173b843c749SSergey Zigachev 		    * adev->gfx.mec.num_pipe_per_mec
174b843c749SSergey Zigachev 		    * adev->gfx.mec.num_queue_per_pipe;
175b843c749SSergey Zigachev 
176b843c749SSergey Zigachev 	while (queue_bit-- >= 0) {
177b843c749SSergey Zigachev 		if (test_bit(queue_bit, adev->gfx.mec.queue_bitmap))
178b843c749SSergey Zigachev 			continue;
179b843c749SSergey Zigachev 
180b843c749SSergey Zigachev 		amdgpu_gfx_bit_to_queue(adev, queue_bit, &mec, &pipe, &queue);
181b843c749SSergey Zigachev 
182b843c749SSergey Zigachev 		/*
183b843c749SSergey Zigachev 		 * 1. Using pipes 2/3 from MEC 2 seems cause problems.
184b843c749SSergey Zigachev 		 * 2. It must use queue id 0, because CGPG_IDLE/SAVE/LOAD/RUN
185b843c749SSergey Zigachev 		 * only can be issued on queue 0.
186b843c749SSergey Zigachev 		 */
187b843c749SSergey Zigachev 		if ((mec == 1 && pipe > 1) || queue != 0)
188b843c749SSergey Zigachev 			continue;
189b843c749SSergey Zigachev 
190b843c749SSergey Zigachev 		ring->me = mec + 1;
191b843c749SSergey Zigachev 		ring->pipe = pipe;
192b843c749SSergey Zigachev 		ring->queue = queue;
193b843c749SSergey Zigachev 
194b843c749SSergey Zigachev 		return 0;
195b843c749SSergey Zigachev 	}
196b843c749SSergey Zigachev 
197b843c749SSergey Zigachev 	dev_err(adev->dev, "Failed to find a queue for KIQ\n");
198b843c749SSergey Zigachev 	return -EINVAL;
199b843c749SSergey Zigachev }
200b843c749SSergey Zigachev 
amdgpu_gfx_kiq_init_ring(struct amdgpu_device * adev,struct amdgpu_ring * ring,struct amdgpu_irq_src * irq)201b843c749SSergey Zigachev int amdgpu_gfx_kiq_init_ring(struct amdgpu_device *adev,
202b843c749SSergey Zigachev 			     struct amdgpu_ring *ring,
203b843c749SSergey Zigachev 			     struct amdgpu_irq_src *irq)
204b843c749SSergey Zigachev {
205b843c749SSergey Zigachev 	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
206b843c749SSergey Zigachev 	int r = 0;
207b843c749SSergey Zigachev 
208*78973132SSergey Zigachev 	lockinit(&kiq->ring_lock, "agkiqrl", 0, LK_CANRECURSE);
209b843c749SSergey Zigachev 
210b843c749SSergey Zigachev 	r = amdgpu_device_wb_get(adev, &adev->virt.reg_val_offs);
211b843c749SSergey Zigachev 	if (r)
212b843c749SSergey Zigachev 		return r;
213b843c749SSergey Zigachev 
214b843c749SSergey Zigachev 	ring->adev = NULL;
215b843c749SSergey Zigachev 	ring->ring_obj = NULL;
216b843c749SSergey Zigachev 	ring->use_doorbell = true;
217b843c749SSergey Zigachev 	ring->doorbell_index = AMDGPU_DOORBELL_KIQ;
218b843c749SSergey Zigachev 
219b843c749SSergey Zigachev 	r = amdgpu_gfx_kiq_acquire(adev, ring);
220b843c749SSergey Zigachev 	if (r)
221b843c749SSergey Zigachev 		return r;
222b843c749SSergey Zigachev 
223b843c749SSergey Zigachev 	ring->eop_gpu_addr = kiq->eop_gpu_addr;
224*78973132SSergey Zigachev 	ksprintf(ring->name, "kiq_%d.%d.%d", ring->me, ring->pipe, ring->queue);
225b843c749SSergey Zigachev 	r = amdgpu_ring_init(adev, ring, 1024,
226b843c749SSergey Zigachev 			     irq, AMDGPU_CP_KIQ_IRQ_DRIVER0);
227b843c749SSergey Zigachev 	if (r)
228b843c749SSergey Zigachev 		dev_warn(adev->dev, "(%d) failed to init kiq ring\n", r);
229b843c749SSergey Zigachev 
230b843c749SSergey Zigachev 	return r;
231b843c749SSergey Zigachev }
232b843c749SSergey Zigachev 
amdgpu_gfx_kiq_free_ring(struct amdgpu_ring * ring,struct amdgpu_irq_src * irq)233b843c749SSergey Zigachev void amdgpu_gfx_kiq_free_ring(struct amdgpu_ring *ring,
234b843c749SSergey Zigachev 			      struct amdgpu_irq_src *irq)
235b843c749SSergey Zigachev {
236b843c749SSergey Zigachev 	amdgpu_device_wb_free(ring->adev, ring->adev->virt.reg_val_offs);
237b843c749SSergey Zigachev 	amdgpu_ring_fini(ring);
238b843c749SSergey Zigachev }
239b843c749SSergey Zigachev 
amdgpu_gfx_kiq_fini(struct amdgpu_device * adev)240b843c749SSergey Zigachev void amdgpu_gfx_kiq_fini(struct amdgpu_device *adev)
241b843c749SSergey Zigachev {
242b843c749SSergey Zigachev 	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
243b843c749SSergey Zigachev 
244b843c749SSergey Zigachev 	amdgpu_bo_free_kernel(&kiq->eop_obj, &kiq->eop_gpu_addr, NULL);
245b843c749SSergey Zigachev }
246b843c749SSergey Zigachev 
amdgpu_gfx_kiq_init(struct amdgpu_device * adev,unsigned hpd_size)247b843c749SSergey Zigachev int amdgpu_gfx_kiq_init(struct amdgpu_device *adev,
248b843c749SSergey Zigachev 			unsigned hpd_size)
249b843c749SSergey Zigachev {
250b843c749SSergey Zigachev 	int r;
251b843c749SSergey Zigachev 	u32 *hpd;
252b843c749SSergey Zigachev 	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
253b843c749SSergey Zigachev 
254b843c749SSergey Zigachev 	r = amdgpu_bo_create_kernel(adev, hpd_size, PAGE_SIZE,
255b843c749SSergey Zigachev 				    AMDGPU_GEM_DOMAIN_GTT, &kiq->eop_obj,
256b843c749SSergey Zigachev 				    &kiq->eop_gpu_addr, (void **)&hpd);
257b843c749SSergey Zigachev 	if (r) {
258b843c749SSergey Zigachev 		dev_warn(adev->dev, "failed to create KIQ bo (%d).\n", r);
259b843c749SSergey Zigachev 		return r;
260b843c749SSergey Zigachev 	}
261b843c749SSergey Zigachev 
262b843c749SSergey Zigachev 	memset(hpd, 0, hpd_size);
263b843c749SSergey Zigachev 
264b843c749SSergey Zigachev 	r = amdgpu_bo_reserve(kiq->eop_obj, true);
265b843c749SSergey Zigachev 	if (unlikely(r != 0))
266b843c749SSergey Zigachev 		dev_warn(adev->dev, "(%d) reserve kiq eop bo failed\n", r);
267b843c749SSergey Zigachev 	amdgpu_bo_kunmap(kiq->eop_obj);
268b843c749SSergey Zigachev 	amdgpu_bo_unreserve(kiq->eop_obj);
269b843c749SSergey Zigachev 
270b843c749SSergey Zigachev 	return 0;
271b843c749SSergey Zigachev }
272b843c749SSergey Zigachev 
273b843c749SSergey Zigachev /* create MQD for each compute queue */
amdgpu_gfx_compute_mqd_sw_init(struct amdgpu_device * adev,unsigned mqd_size)274b843c749SSergey Zigachev int amdgpu_gfx_compute_mqd_sw_init(struct amdgpu_device *adev,
275b843c749SSergey Zigachev 				   unsigned mqd_size)
276b843c749SSergey Zigachev {
277b843c749SSergey Zigachev 	struct amdgpu_ring *ring = NULL;
278b843c749SSergey Zigachev 	int r, i;
279b843c749SSergey Zigachev 
280b843c749SSergey Zigachev 	/* create MQD for KIQ */
281b843c749SSergey Zigachev 	ring = &adev->gfx.kiq.ring;
282b843c749SSergey Zigachev 	if (!ring->mqd_obj) {
283b843c749SSergey Zigachev 		/* originaly the KIQ MQD is put in GTT domain, but for SRIOV VRAM domain is a must
284b843c749SSergey Zigachev 		 * otherwise hypervisor trigger SAVE_VF fail after driver unloaded which mean MQD
285b843c749SSergey Zigachev 		 * deallocated and gart_unbind, to strict diverage we decide to use VRAM domain for
286b843c749SSergey Zigachev 		 * KIQ MQD no matter SRIOV or Bare-metal
287b843c749SSergey Zigachev 		 */
288b843c749SSergey Zigachev 		r = amdgpu_bo_create_kernel(adev, mqd_size, PAGE_SIZE,
289b843c749SSergey Zigachev 					    AMDGPU_GEM_DOMAIN_VRAM, &ring->mqd_obj,
290*78973132SSergey Zigachev 					    (u64 *)&ring->mqd_gpu_addr, &ring->mqd_ptr);
291b843c749SSergey Zigachev 		if (r) {
292b843c749SSergey Zigachev 			dev_warn(adev->dev, "failed to create ring mqd ob (%d)", r);
293b843c749SSergey Zigachev 			return r;
294b843c749SSergey Zigachev 		}
295b843c749SSergey Zigachev 
296b843c749SSergey Zigachev 		/* prepare MQD backup */
297*78973132SSergey Zigachev 		adev->gfx.mec.mqd_backup[AMDGPU_MAX_COMPUTE_RINGS] = kmalloc(mqd_size, M_DRM, GFP_KERNEL);
298b843c749SSergey Zigachev 		if (!adev->gfx.mec.mqd_backup[AMDGPU_MAX_COMPUTE_RINGS])
299b843c749SSergey Zigachev 				dev_warn(adev->dev, "no memory to create MQD backup for ring %s\n", ring->name);
300b843c749SSergey Zigachev 	}
301b843c749SSergey Zigachev 
302b843c749SSergey Zigachev 	/* create MQD for each KCQ */
303b843c749SSergey Zigachev 	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
304b843c749SSergey Zigachev 		ring = &adev->gfx.compute_ring[i];
305b843c749SSergey Zigachev 		if (!ring->mqd_obj) {
306b843c749SSergey Zigachev 			r = amdgpu_bo_create_kernel(adev, mqd_size, PAGE_SIZE,
307b843c749SSergey Zigachev 						    AMDGPU_GEM_DOMAIN_GTT, &ring->mqd_obj,
308*78973132SSergey Zigachev 						    (u64 *)&ring->mqd_gpu_addr, &ring->mqd_ptr);
309b843c749SSergey Zigachev 			if (r) {
310b843c749SSergey Zigachev 				dev_warn(adev->dev, "failed to create ring mqd ob (%d)", r);
311b843c749SSergey Zigachev 				return r;
312b843c749SSergey Zigachev 			}
313b843c749SSergey Zigachev 
314b843c749SSergey Zigachev 			/* prepare MQD backup */
315*78973132SSergey Zigachev 			adev->gfx.mec.mqd_backup[i] = kmalloc(mqd_size, M_DRM, GFP_KERNEL);
316b843c749SSergey Zigachev 			if (!adev->gfx.mec.mqd_backup[i])
317b843c749SSergey Zigachev 				dev_warn(adev->dev, "no memory to create MQD backup for ring %s\n", ring->name);
318b843c749SSergey Zigachev 		}
319b843c749SSergey Zigachev 	}
320b843c749SSergey Zigachev 
321b843c749SSergey Zigachev 	return 0;
322b843c749SSergey Zigachev }
323b843c749SSergey Zigachev 
amdgpu_gfx_compute_mqd_sw_fini(struct amdgpu_device * adev)324b843c749SSergey Zigachev void amdgpu_gfx_compute_mqd_sw_fini(struct amdgpu_device *adev)
325b843c749SSergey Zigachev {
326b843c749SSergey Zigachev 	struct amdgpu_ring *ring = NULL;
327b843c749SSergey Zigachev 	int i;
328b843c749SSergey Zigachev 
329b843c749SSergey Zigachev 	for (i = 0; i < adev->gfx.num_compute_rings; i++) {
330b843c749SSergey Zigachev 		ring = &adev->gfx.compute_ring[i];
331b843c749SSergey Zigachev 		kfree(adev->gfx.mec.mqd_backup[i]);
332b843c749SSergey Zigachev 		amdgpu_bo_free_kernel(&ring->mqd_obj,
333*78973132SSergey Zigachev 				      (u64 *)&ring->mqd_gpu_addr,
334b843c749SSergey Zigachev 				      &ring->mqd_ptr);
335b843c749SSergey Zigachev 	}
336b843c749SSergey Zigachev 
337b843c749SSergey Zigachev 	ring = &adev->gfx.kiq.ring;
338b843c749SSergey Zigachev 	kfree(adev->gfx.mec.mqd_backup[AMDGPU_MAX_COMPUTE_RINGS]);
339b843c749SSergey Zigachev 	amdgpu_bo_free_kernel(&ring->mqd_obj,
340*78973132SSergey Zigachev 			      (u64 *)&ring->mqd_gpu_addr,
341b843c749SSergey Zigachev 			      &ring->mqd_ptr);
342b843c749SSergey Zigachev }
343