xref: /linux/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.h (revision cdd5b5a9761fd66d17586e4f4ba6588c70e640ea)
1d38ceaf9SAlex Deucher /*
2d38ceaf9SAlex Deucher  * Copyright 2014 Advanced Micro Devices, Inc.
3d38ceaf9SAlex Deucher  *
4d38ceaf9SAlex Deucher  * Permission is hereby granted, free of charge, to any person obtaining a
5d38ceaf9SAlex Deucher  * copy of this software and associated documentation files (the "Software"),
6d38ceaf9SAlex Deucher  * to deal in the Software without restriction, including without limitation
7d38ceaf9SAlex Deucher  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d38ceaf9SAlex Deucher  * and/or sell copies of the Software, and to permit persons to whom the
9d38ceaf9SAlex Deucher  * Software is furnished to do so, subject to the following conditions:
10d38ceaf9SAlex Deucher  *
11d38ceaf9SAlex Deucher  * The above copyright notice and this permission notice shall be included in
12d38ceaf9SAlex Deucher  * all copies or substantial portions of the Software.
13d38ceaf9SAlex Deucher  *
14d38ceaf9SAlex Deucher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15d38ceaf9SAlex Deucher  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16d38ceaf9SAlex Deucher  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17d38ceaf9SAlex Deucher  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18d38ceaf9SAlex Deucher  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19d38ceaf9SAlex Deucher  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20d38ceaf9SAlex Deucher  * OTHER DEALINGS IN THE SOFTWARE.
21d38ceaf9SAlex Deucher  *
22d38ceaf9SAlex Deucher  */
23d38ceaf9SAlex Deucher 
24d38ceaf9SAlex Deucher #ifndef __AMDGPU_IRQ_H__
25d38ceaf9SAlex Deucher #define __AMDGPU_IRQ_H__
26d38ceaf9SAlex Deucher 
275f232365SAlex Deucher #include <linux/irqdomain.h>
281ffdeca6SChristian König #include "soc15_ih_clientid.h"
29d38ceaf9SAlex Deucher #include "amdgpu_ih.h"
30d38ceaf9SAlex Deucher 
31d38ceaf9SAlex Deucher #define AMDGPU_MAX_IRQ_SRC_ID		0x100
32d766e6a3SAlex Deucher #define AMDGPU_MAX_IRQ_CLIENT_ID	0x100
33d38ceaf9SAlex Deucher 
341ffdeca6SChristian König #define AMDGPU_IRQ_CLIENTID_LEGACY	0
351ffdeca6SChristian König #define AMDGPU_IRQ_CLIENTID_MAX		SOC15_IH_CLIENTID_MAX
361ffdeca6SChristian König 
371ffdeca6SChristian König #define AMDGPU_IRQ_SRC_DATA_MAX_SIZE_DW	4
381ffdeca6SChristian König 
39d38ceaf9SAlex Deucher struct amdgpu_device;
40d38ceaf9SAlex Deucher 
41d38ceaf9SAlex Deucher enum amdgpu_interrupt_state {
42d38ceaf9SAlex Deucher 	AMDGPU_IRQ_STATE_DISABLE,
43d38ceaf9SAlex Deucher 	AMDGPU_IRQ_STATE_ENABLE,
44d38ceaf9SAlex Deucher };
45d38ceaf9SAlex Deucher 
461ffdeca6SChristian König struct amdgpu_iv_entry {
4726f32a37SChristian König 	struct amdgpu_ih_ring *ih;
481ffdeca6SChristian König 	unsigned client_id;
491ffdeca6SChristian König 	unsigned src_id;
501ffdeca6SChristian König 	unsigned ring_id;
511ffdeca6SChristian König 	unsigned vmid;
521ffdeca6SChristian König 	unsigned vmid_src;
531ffdeca6SChristian König 	uint64_t timestamp;
541ffdeca6SChristian König 	unsigned timestamp_src;
551ffdeca6SChristian König 	unsigned pasid;
5647659738SLe Ma 	unsigned node_id;
571ffdeca6SChristian König 	unsigned src_data[AMDGPU_IRQ_SRC_DATA_MAX_SIZE_DW];
581ffdeca6SChristian König 	const uint32_t *iv_entry;
591ffdeca6SChristian König };
601ffdeca6SChristian König 
61d38ceaf9SAlex Deucher struct amdgpu_irq_src {
62d38ceaf9SAlex Deucher 	unsigned				num_types;
63d38ceaf9SAlex Deucher 	atomic_t				*enabled_types;
64d38ceaf9SAlex Deucher 	const struct amdgpu_irq_src_funcs	*funcs;
65d38ceaf9SAlex Deucher };
66d38ceaf9SAlex Deucher 
67d766e6a3SAlex Deucher struct amdgpu_irq_client {
68d766e6a3SAlex Deucher 	struct amdgpu_irq_src **sources;
69d766e6a3SAlex Deucher };
70d766e6a3SAlex Deucher 
71d38ceaf9SAlex Deucher /* provided by interrupt generating IP blocks */
72d38ceaf9SAlex Deucher struct amdgpu_irq_src_funcs {
73d38ceaf9SAlex Deucher 	int (*set)(struct amdgpu_device *adev, struct amdgpu_irq_src *source,
74d38ceaf9SAlex Deucher 		   unsigned type, enum amdgpu_interrupt_state state);
75d38ceaf9SAlex Deucher 
76d38ceaf9SAlex Deucher 	int (*process)(struct amdgpu_device *adev,
77d38ceaf9SAlex Deucher 		       struct amdgpu_irq_src *source,
78d38ceaf9SAlex Deucher 		       struct amdgpu_iv_entry *entry);
79d38ceaf9SAlex Deucher };
80d38ceaf9SAlex Deucher 
81d38ceaf9SAlex Deucher struct amdgpu_irq {
82d38ceaf9SAlex Deucher 	bool				installed;
83450d6179SThomas Zimmermann 	unsigned int			irq;
84d38ceaf9SAlex Deucher 	spinlock_t			lock;
85d38ceaf9SAlex Deucher 	/* interrupt sources */
861ffdeca6SChristian König 	struct amdgpu_irq_client	client[AMDGPU_IRQ_CLIENTID_MAX];
87d38ceaf9SAlex Deucher 
88d38ceaf9SAlex Deucher 	/* status, etc. */
89d38ceaf9SAlex Deucher 	bool				msi_enabled; /* msi enabled */
90d38ceaf9SAlex Deucher 
91ad710812SChristian König 	/* interrupt rings */
9226f32a37SChristian König 	struct amdgpu_ih_ring		ih, ih1, ih2, ih_soft;
93d38ceaf9SAlex Deucher 	const struct amdgpu_ih_funcs    *ih_funcs;
9426f32a37SChristian König 	struct work_struct		ih1_work, ih2_work, ih_soft_work;
959dd60c4eSChristian König 	struct amdgpu_irq_src		self_irq;
965f232365SAlex Deucher 
975f232365SAlex Deucher 	/* gen irq stuff */
985f232365SAlex Deucher 	struct irq_domain		*domain; /* GPU irq controller domain */
995f232365SAlex Deucher 	unsigned			virq[AMDGPU_MAX_IRQ_SRC_ID];
1001015a1b1SChunming Zhou 	uint32_t                        srbm_soft_reset;
101318e431bSMukul Joshi 	u32                             retry_cam_doorbell_index;
102318e431bSMukul Joshi 	bool                            retry_cam_enabled;
103d38ceaf9SAlex Deucher };
104d38ceaf9SAlex Deucher 
105*0d81101cSLe Ma enum interrupt_node_id_per_aid {
106*0d81101cSLe Ma 	AID0_NODEID = 0,
10715091a6fSLe Ma 	XCD0_NODEID = 1,
10815091a6fSLe Ma 	XCD1_NODEID = 2,
109*0d81101cSLe Ma 	AID1_NODEID = 4,
11015091a6fSLe Ma 	XCD2_NODEID = 5,
11115091a6fSLe Ma 	XCD3_NODEID = 6,
112*0d81101cSLe Ma 	AID2_NODEID = 8,
11315091a6fSLe Ma 	XCD4_NODEID = 9,
11415091a6fSLe Ma 	XCD5_NODEID = 10,
115*0d81101cSLe Ma 	AID3_NODEID = 12,
11615091a6fSLe Ma 	XCD6_NODEID = 13,
11715091a6fSLe Ma 	XCD7_NODEID = 14,
11815091a6fSLe Ma 	NODEID_MAX,
11915091a6fSLe Ma };
12015091a6fSLe Ma 
12115091a6fSLe Ma extern const int node_id_to_phys_map[NODEID_MAX];
12215091a6fSLe Ma 
1239950cda2SAlex Deucher void amdgpu_irq_disable_all(struct amdgpu_device *adev);
124d38ceaf9SAlex Deucher 
125d38ceaf9SAlex Deucher int amdgpu_irq_init(struct amdgpu_device *adev);
12672c8c97bSAndrey Grodzovsky void amdgpu_irq_fini_sw(struct amdgpu_device *adev);
12772c8c97bSAndrey Grodzovsky void amdgpu_irq_fini_hw(struct amdgpu_device *adev);
128d766e6a3SAlex Deucher int amdgpu_irq_add_id(struct amdgpu_device *adev,
129d766e6a3SAlex Deucher 		      unsigned client_id, unsigned src_id,
130d38ceaf9SAlex Deucher 		      struct amdgpu_irq_src *source);
131d38ceaf9SAlex Deucher void amdgpu_irq_dispatch(struct amdgpu_device *adev,
132e2fb6e0aSChristian König 			 struct amdgpu_ih_ring *ih);
13326f32a37SChristian König void amdgpu_irq_delegate(struct amdgpu_device *adev,
13426f32a37SChristian König 			 struct amdgpu_iv_entry *entry,
13526f32a37SChristian König 			 unsigned int num_dw);
136d38ceaf9SAlex Deucher int amdgpu_irq_update(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
137d38ceaf9SAlex Deucher 		      unsigned type);
138d38ceaf9SAlex Deucher int amdgpu_irq_get(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
139d38ceaf9SAlex Deucher 		   unsigned type);
140d38ceaf9SAlex Deucher int amdgpu_irq_put(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
141d38ceaf9SAlex Deucher 		   unsigned type);
142d38ceaf9SAlex Deucher bool amdgpu_irq_enabled(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
143d38ceaf9SAlex Deucher 			unsigned type);
1440eaeb070SChunming Zhou void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev);
145d38ceaf9SAlex Deucher 
1465f232365SAlex Deucher int amdgpu_irq_add_domain(struct amdgpu_device *adev);
1475f232365SAlex Deucher void amdgpu_irq_remove_domain(struct amdgpu_device *adev);
1485f232365SAlex Deucher unsigned amdgpu_irq_create_mapping(struct amdgpu_device *adev, unsigned src_id);
1495f232365SAlex Deucher 
150d38ceaf9SAlex Deucher #endif
151