xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_bo_list.h (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: amdgpu_bo_list.h,v 1.2 2021/12/18 23:44:58 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2018 Advanced Micro Devices, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */
25 #ifndef __AMDGPU_BO_LIST_H__
26 #define __AMDGPU_BO_LIST_H__
27 
28 #include <drm/ttm/ttm_execbuf_util.h>
29 #include <drm/amdgpu_drm.h>
30 
31 struct amdgpu_device;
32 struct amdgpu_bo;
33 struct amdgpu_bo_va;
34 struct amdgpu_fpriv;
35 
36 struct amdgpu_bo_list_entry {
37 	struct ttm_validate_buffer	tv;
38 	struct amdgpu_bo_va		*bo_va;
39 	uint32_t			priority;
40 	struct page			**user_pages;
41 	bool				user_invalidated;
42 };
43 
44 struct amdgpu_bo_list {
45 	struct rcu_head rhead;
46 	struct kref refcount;
47 	struct amdgpu_bo *gds_obj;
48 	struct amdgpu_bo *gws_obj;
49 	struct amdgpu_bo *oa_obj;
50 	unsigned first_userptr;
51 	unsigned num_entries;
52 };
53 
54 int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
55 		       struct amdgpu_bo_list **result);
56 void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
57 			     struct list_head *validated);
58 void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
59 int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
60 				      struct drm_amdgpu_bo_list_entry **info_param);
61 
62 int amdgpu_bo_list_create(struct amdgpu_device *adev,
63 				 struct drm_file *filp,
64 				 struct drm_amdgpu_bo_list_entry *info,
65 				 unsigned num_entries,
66 				 struct amdgpu_bo_list **list);
67 
68 static inline struct amdgpu_bo_list_entry *
amdgpu_bo_list_array_entry(struct amdgpu_bo_list * list,unsigned index)69 amdgpu_bo_list_array_entry(struct amdgpu_bo_list *list, unsigned index)
70 {
71 	struct amdgpu_bo_list_entry *array = (void *)&list[1];
72 
73 	return &array[index];
74 }
75 
76 #define amdgpu_bo_list_for_each_entry(e, list) \
77 	for (e = amdgpu_bo_list_array_entry(list, 0); \
78 	     e != amdgpu_bo_list_array_entry(list, (list)->num_entries); \
79 	     ++e)
80 
81 #define amdgpu_bo_list_for_each_userptr_entry(e, list) \
82 	for (e = amdgpu_bo_list_array_entry(list, (list)->first_userptr); \
83 	     e != amdgpu_bo_list_array_entry(list, (list)->num_entries); \
84 	     ++e)
85 
86 #endif
87