xref: /linux/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.h (revision cb8fef4b07f71da01843457b66e579ad248a625e)
1 /*
2  * Copyright 2014 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 
24 #ifndef __AMDGPU_IRQ_H__
25 #define __AMDGPU_IRQ_H__
26 
27 #include <linux/irqdomain.h>
28 #include "soc15_ih_clientid.h"
29 #include "soc_v1_0_ih_clientid.h"
30 #include "soc_v2_0_ih_clientid.h"
31 #include "amdgpu_ih.h"
32 
33 #define AMDGPU_MAX_IRQ_SRC_ID		0x100
34 #define AMDGPU_MAX_IRQ_CLIENT_ID	0x100
35 
36 #define AMDGPU_IRQ_CLIENTID_LEGACY	0
37 #define AMDGPU_IRQ_CLIENTID_MAX		SOC15_IH_CLIENTID_MAX
38 
39 #define AMDGPU_IRQ_SRC_DATA_MAX_SIZE_DW	4
40 
41 struct amdgpu_device;
42 
43 enum amdgpu_interrupt_state {
44 	AMDGPU_IRQ_STATE_DISABLE,
45 	AMDGPU_IRQ_STATE_ENABLE,
46 };
47 
48 struct amdgpu_iv_entry {
49 	struct amdgpu_ih_ring *ih;
50 	unsigned client_id;
51 	unsigned src_id;
52 	unsigned ring_id;
53 	unsigned vmid;
54 	unsigned vmid_src;
55 	uint64_t timestamp;
56 	unsigned timestamp_src;
57 	unsigned pasid;
58 	unsigned node_id;
59 	unsigned src_data[AMDGPU_IRQ_SRC_DATA_MAX_SIZE_DW];
60 	const uint32_t *iv_entry;
61 };
62 
63 struct amdgpu_irq_src {
64 	unsigned				num_types;
65 	atomic_t				*enabled_types;
66 	const struct amdgpu_irq_src_funcs	*funcs;
67 };
68 
69 struct amdgpu_irq_client {
70 	struct amdgpu_irq_src **sources;
71 };
72 
73 /* provided by interrupt generating IP blocks */
74 struct amdgpu_irq_src_funcs {
75 	int (*set)(struct amdgpu_device *adev, struct amdgpu_irq_src *source,
76 		   unsigned type, enum amdgpu_interrupt_state state);
77 
78 	int (*process)(struct amdgpu_device *adev,
79 		       struct amdgpu_irq_src *source,
80 		       struct amdgpu_iv_entry *entry);
81 };
82 
83 struct amdgpu_irq {
84 	bool				installed;
85 	unsigned int			irq;
86 	spinlock_t			lock;
87 	/* interrupt sources */
88 	struct amdgpu_irq_client	client[AMDGPU_IRQ_CLIENTID_MAX];
89 
90 	/* status, etc. */
91 	bool				msi_enabled; /* msi enabled */
92 
93 	/* interrupt rings */
94 	struct amdgpu_ih_ring		ih, ih1, ih2, ih_soft, ih_psp, ih_ualink;
95 	const struct amdgpu_ih_funcs    *ih_funcs;
96 	struct work_struct		ih1_work, ih2_work, ih_soft_work,
97 					ih_psp_work, ih_ualink_work;
98 	struct amdgpu_irq_src		self_irq;
99 
100 	/* gen irq stuff */
101 	struct irq_domain		*domain; /* GPU irq controller domain */
102 	unsigned			virq[AMDGPU_MAX_IRQ_SRC_ID];
103 	uint32_t                        srbm_soft_reset;
104 	u32                             retry_cam_doorbell_index;
105 	bool                            retry_cam_enabled;
106 };
107 
108 enum interrupt_node_id_per_aid {
109 	AID0_NODEID = 0,
110 	XCD0_NODEID = 1,
111 	XCD1_NODEID = 2,
112 	AID1_NODEID = 4,
113 	XCD2_NODEID = 5,
114 	XCD3_NODEID = 6,
115 	AID2_NODEID = 8,
116 	XCD4_NODEID = 9,
117 	XCD5_NODEID = 10,
118 	AID3_NODEID = 12,
119 	XCD6_NODEID = 13,
120 	XCD7_NODEID = 14,
121 	NODEID_MAX,
122 };
123 
124 extern const int node_id_to_phys_map[NODEID_MAX];
125 
126 void amdgpu_irq_disable_all(struct amdgpu_device *adev);
127 
128 int amdgpu_irq_init(struct amdgpu_device *adev);
129 void amdgpu_irq_fini_sw(struct amdgpu_device *adev);
130 void amdgpu_irq_fini_hw(struct amdgpu_device *adev);
131 int amdgpu_irq_add_id(struct amdgpu_device *adev,
132 		      unsigned client_id, unsigned src_id,
133 		      struct amdgpu_irq_src *source);
134 void amdgpu_irq_dispatch(struct amdgpu_device *adev,
135 			 struct amdgpu_ih_ring *ih);
136 void amdgpu_irq_delegate(struct amdgpu_device *adev,
137 			 struct amdgpu_iv_entry *entry,
138 			 unsigned int num_dw);
139 void amdgpu_irq_psp_delegate(struct amdgpu_device *adev,
140 			     struct amdgpu_iv_entry *entry,
141 			     unsigned int num_dw);
142 void amdgpu_irq_ualink_delegate(struct amdgpu_device *adev,
143 				 struct amdgpu_iv_entry *entry,
144 				 unsigned int num_dw);
145 int amdgpu_irq_update(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
146 		      unsigned type);
147 int amdgpu_irq_get(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
148 		   unsigned type);
149 int amdgpu_irq_put(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
150 		   unsigned type);
151 bool amdgpu_irq_enabled(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
152 			unsigned type);
153 void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev);
154 
155 int amdgpu_irq_add_domain(struct amdgpu_device *adev);
156 void amdgpu_irq_remove_domain(struct amdgpu_device *adev);
157 unsigned amdgpu_irq_create_mapping(struct amdgpu_device *adev, unsigned src_id);
158 void amdgpu_restore_msix(struct amdgpu_device *adev);
159 
160 #endif
161