xref: /linux/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h (revision a940daa52167e9db8ecce82213813b735a9d9f23)
1a190f8dcSChristian König /*
2a190f8dcSChristian König  * Copyright 2022 Advanced Micro Devices, Inc.
3a190f8dcSChristian König  *
4a190f8dcSChristian König  * Permission is hereby granted, free of charge, to any person obtaining a
5a190f8dcSChristian König  * copy of this software and associated documentation files (the "Software"),
6a190f8dcSChristian König  * to deal in the Software without restriction, including without limitation
7a190f8dcSChristian König  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8a190f8dcSChristian König  * and/or sell copies of the Software, and to permit persons to whom the
9a190f8dcSChristian König  * Software is furnished to do so, subject to the following conditions:
10a190f8dcSChristian König  *
11a190f8dcSChristian König  * The above copyright notice and this permission notice shall be included in
12a190f8dcSChristian König  * all copies or substantial portions of the Software.
13a190f8dcSChristian König  *
14a190f8dcSChristian König  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15a190f8dcSChristian König  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16a190f8dcSChristian König  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17a190f8dcSChristian König  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18a190f8dcSChristian König  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19a190f8dcSChristian König  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20a190f8dcSChristian König  * OTHER DEALINGS IN THE SOFTWARE.
21a190f8dcSChristian König  *
22a190f8dcSChristian König  */
23a190f8dcSChristian König #ifndef __AMDGPU_CS_H__
24a190f8dcSChristian König #define __AMDGPU_CS_H__
25a190f8dcSChristian König 
26a3185f91SChristian König #include <linux/ww_mutex.h>
27*ca6c1e21SChristian König #include <drm/drm_exec.h>
28a3185f91SChristian König 
29a190f8dcSChristian König #include "amdgpu_job.h"
30a190f8dcSChristian König #include "amdgpu_bo_list.h"
31a190f8dcSChristian König #include "amdgpu_ring.h"
32a190f8dcSChristian König 
334624459cSChristian König #define AMDGPU_CS_GANG_SIZE	4
344624459cSChristian König 
35a190f8dcSChristian König struct amdgpu_bo_va_mapping;
36a190f8dcSChristian König 
37a190f8dcSChristian König struct amdgpu_cs_chunk {
38a190f8dcSChristian König 	uint32_t		chunk_id;
39a190f8dcSChristian König 	uint32_t		length_dw;
40a190f8dcSChristian König 	void			*kdata;
41a190f8dcSChristian König };
42a190f8dcSChristian König 
43a190f8dcSChristian König struct amdgpu_cs_post_dep {
44a190f8dcSChristian König 	struct drm_syncobj *syncobj;
45a190f8dcSChristian König 	struct dma_fence_chain *chain;
46a190f8dcSChristian König 	u64 point;
47a190f8dcSChristian König };
48a190f8dcSChristian König 
49a190f8dcSChristian König struct amdgpu_cs_parser {
50a190f8dcSChristian König 	struct amdgpu_device	*adev;
51a190f8dcSChristian König 	struct drm_file		*filp;
52a190f8dcSChristian König 	struct amdgpu_ctx	*ctx;
53a190f8dcSChristian König 
54a190f8dcSChristian König 	/* chunks */
55a190f8dcSChristian König 	unsigned		nchunks;
56a190f8dcSChristian König 	struct amdgpu_cs_chunk	*chunks;
57a190f8dcSChristian König 
584624459cSChristian König 	/* scheduler job objects */
594624459cSChristian König 	unsigned int		gang_size;
60eca13f3cSChristian König 	unsigned int		gang_leader_idx;
614624459cSChristian König 	struct drm_sched_entity	*entities[AMDGPU_CS_GANG_SIZE];
624624459cSChristian König 	struct amdgpu_job	*jobs[AMDGPU_CS_GANG_SIZE];
634624459cSChristian König 	struct amdgpu_job	*gang_leader;
64a190f8dcSChristian König 
65a190f8dcSChristian König 	/* buffer objects */
66*ca6c1e21SChristian König 	struct drm_exec			exec;
67a190f8dcSChristian König 	struct amdgpu_bo_list		*bo_list;
68a190f8dcSChristian König 	struct amdgpu_mn		*mn;
69a190f8dcSChristian König 	struct dma_fence		*fence;
70a190f8dcSChristian König 	uint64_t			bytes_moved_threshold;
71a190f8dcSChristian König 	uint64_t			bytes_moved_vis_threshold;
72a190f8dcSChristian König 	uint64_t			bytes_moved;
73a190f8dcSChristian König 	uint64_t			bytes_moved_vis;
74a190f8dcSChristian König 
75a190f8dcSChristian König 	/* user fence */
76*ca6c1e21SChristian König 	struct amdgpu_bo		*uf_bo;
77a190f8dcSChristian König 
78a190f8dcSChristian König 	unsigned			num_post_deps;
79a190f8dcSChristian König 	struct amdgpu_cs_post_dep	*post_deps;
801728baa7SChristian König 
811728baa7SChristian König 	struct amdgpu_sync		sync;
82a190f8dcSChristian König };
83a190f8dcSChristian König 
84a190f8dcSChristian König int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
85a190f8dcSChristian König 			   uint64_t addr, struct amdgpu_bo **bo,
86a190f8dcSChristian König 			   struct amdgpu_bo_va_mapping **mapping);
87a190f8dcSChristian König 
88a190f8dcSChristian König #endif
89