xref: /linux/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h (revision cb8fef4b07f71da01843457b66e579ad248a625e)
1 /*
2  * Copyright 2017 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 #ifndef __AMDGPU_IDS_H__
24 #define __AMDGPU_IDS_H__
25 
26 #include <linux/types.h>
27 #include <linux/mutex.h>
28 #include <linux/list.h>
29 #include <linux/bitops.h>
30 #include <linux/find.h>
31 #include <linux/dma-fence.h>
32 
33 #include "amdgpu_sync.h"
34 
35 /* maximum number of VMIDs */
36 #define AMDGPU_NUM_VMID	16
37 
38 /**
39  * for_each_vmid_and_zero - iterate over VMID 0 plus every VMID set in a hub's
40  *                          vmid_mask
41  * @vmid:	loop cursor (int / unsigned int)
42  * @adev:	struct amdgpu_device *
43  * @hub:	vmhub index into adev->vm_manager.id_mgr[]
44  *
45  * Equivalent to OR-ing BIT(0) into id_mgr[hub].vmid_mask and walking
46  * the result with for_each_set_bit(). Used by the gfx_v*_constants_init()
47  * paths which must always touch VMID 0 (system) in addition to the regular
48  * VMIDs owned by the hub.
49  *
50  * Relies on AMDGPU_NUM_VMID (16) fitting in a single unsigned long, i.e.
51  * vmid_mask[] being a 1-element bitmap.
52  */
53 #define for_each_vmid_and_zero(vmid, adev, hub)				\
54 	for (unsigned long __vmid_mask =				\
55 		(adev)->vm_manager.id_mgr[(hub)].vmid_mask[0] | BIT(0);	\
56 	     __vmid_mask; __vmid_mask = 0)				\
57 		for_each_set_bit((vmid), &__vmid_mask, AMDGPU_NUM_VMID)
58 
59 struct amdgpu_device;
60 struct amdgpu_fpriv;
61 struct amdgpu_vm;
62 struct amdgpu_ring;
63 struct amdgpu_sync;
64 struct amdgpu_job;
65 
66 struct amdgpu_vmid {
67 	struct list_head	list;
68 	struct amdgpu_sync	active;
69 	struct dma_fence	*last_flush;
70 	uint64_t		owner;
71 
72 	uint64_t		pd_gpu_addr;
73 	/* last flushed PD/PT update */
74 	uint64_t		flushed_updates;
75 
76 	uint32_t                current_gpu_reset_count;
77 
78 	uint32_t		gds_base;
79 	uint32_t		gds_size;
80 	uint32_t		gws_base;
81 	uint32_t		gws_size;
82 	uint32_t		oa_base;
83 	uint32_t		oa_size;
84 
85 	unsigned		pasid;
86 	struct dma_fence	*pasid_mapping;
87 };
88 
89 struct amdgpu_kq_vmid_mgr {
90 	struct mutex		lock;
91 	struct list_head	ids_lru;
92 	struct amdgpu_vmid	ids[AMDGPU_NUM_VMID];
93 	bool			reserved_vmid;
94 	DECLARE_BITMAP(vmid_mask, AMDGPU_NUM_VMID);
95 };
96 
97 int amdgpu_pasid_alloc(unsigned int bits, struct amdgpu_fpriv *fpriv);
98 void amdgpu_pasid_lock(unsigned long *flags);
99 void amdgpu_pasid_unlock(unsigned long flags);
100 struct amdgpu_fpriv *amdgpu_pasid_get_fpriv_locked(u32 pasid);
101 void amdgpu_pasid_free(u32 pasid);
102 void amdgpu_pasid_free_delayed(struct dma_resv *resv,
103 			       u32 pasid);
104 void amdgpu_pasid_mgr_cleanup(void);
105 
106 bool amdgpu_vmid_had_gpu_reset(struct amdgpu_device *adev,
107 			       struct amdgpu_vmid *id);
108 bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub);
109 int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
110 			       unsigned vmhub);
111 void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
112 			       unsigned vmhub);
113 int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
114 		     struct amdgpu_job *job, struct dma_fence **fence);
115 void amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub,
116 		       unsigned vmid);
117 void amdgpu_vmid_reset_all(struct amdgpu_device *adev);
118 
119 void amdgpu_vmid_mgr_init(struct amdgpu_device *adev);
120 void amdgpu_vmid_mgr_fini(struct amdgpu_device *adev);
121 void amdgpu_vmid_mgr_set_vmid_mask(struct amdgpu_device *adev,
122 				   unsigned long vmid_mask, bool for_mmhub);
123 
124 #endif
125