xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_irq.h (revision 5be1b89f6410ef5bef63407d9dfa6d60a6bcbdce)
1*5be1b89fSriastradh /*	$NetBSD: amdgpu_irq.h,v 1.5 2021/12/19 10:20:17 riastradh Exp $	*/
2efa246c0Sriastradh 
3efa246c0Sriastradh /*
4efa246c0Sriastradh  * Copyright 2014 Advanced Micro Devices, Inc.
5efa246c0Sriastradh  *
6efa246c0Sriastradh  * Permission is hereby granted, free of charge, to any person obtaining a
7efa246c0Sriastradh  * copy of this software and associated documentation files (the "Software"),
8efa246c0Sriastradh  * to deal in the Software without restriction, including without limitation
9efa246c0Sriastradh  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10efa246c0Sriastradh  * and/or sell copies of the Software, and to permit persons to whom the
11efa246c0Sriastradh  * Software is furnished to do so, subject to the following conditions:
12efa246c0Sriastradh  *
13efa246c0Sriastradh  * The above copyright notice and this permission notice shall be included in
14efa246c0Sriastradh  * all copies or substantial portions of the Software.
15efa246c0Sriastradh  *
16efa246c0Sriastradh  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17efa246c0Sriastradh  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18efa246c0Sriastradh  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19efa246c0Sriastradh  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20efa246c0Sriastradh  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21efa246c0Sriastradh  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22efa246c0Sriastradh  * OTHER DEALINGS IN THE SOFTWARE.
23efa246c0Sriastradh  *
24efa246c0Sriastradh  */
25efa246c0Sriastradh 
26efa246c0Sriastradh #ifndef __AMDGPU_IRQ_H__
27efa246c0Sriastradh #define __AMDGPU_IRQ_H__
28efa246c0Sriastradh 
2941ec0267Sriastradh #include <linux/irqdomain.h>
3041ec0267Sriastradh #include "soc15_ih_clientid.h"
31efa246c0Sriastradh #include "amdgpu_ih.h"
32efa246c0Sriastradh 
33efa246c0Sriastradh #define AMDGPU_MAX_IRQ_SRC_ID		0x100
3441ec0267Sriastradh #define AMDGPU_MAX_IRQ_CLIENT_ID	0x100
3541ec0267Sriastradh 
3641ec0267Sriastradh #define AMDGPU_IRQ_CLIENTID_LEGACY	0
3741ec0267Sriastradh #define AMDGPU_IRQ_CLIENTID_MAX		SOC15_IH_CLIENTID_MAX
3841ec0267Sriastradh 
3941ec0267Sriastradh #define AMDGPU_IRQ_SRC_DATA_MAX_SIZE_DW	4
40efa246c0Sriastradh 
41efa246c0Sriastradh struct amdgpu_device;
42efa246c0Sriastradh 
43efa246c0Sriastradh enum amdgpu_interrupt_state {
44efa246c0Sriastradh 	AMDGPU_IRQ_STATE_DISABLE,
45efa246c0Sriastradh 	AMDGPU_IRQ_STATE_ENABLE,
46efa246c0Sriastradh };
47efa246c0Sriastradh 
4841ec0267Sriastradh struct amdgpu_iv_entry {
4941ec0267Sriastradh 	unsigned client_id;
5041ec0267Sriastradh 	unsigned src_id;
5141ec0267Sriastradh 	unsigned ring_id;
5241ec0267Sriastradh 	unsigned vmid;
5341ec0267Sriastradh 	unsigned vmid_src;
5441ec0267Sriastradh 	uint64_t timestamp;
5541ec0267Sriastradh 	unsigned timestamp_src;
5641ec0267Sriastradh 	unsigned pasid;
5741ec0267Sriastradh 	unsigned pasid_src;
5841ec0267Sriastradh 	unsigned src_data[AMDGPU_IRQ_SRC_DATA_MAX_SIZE_DW];
5941ec0267Sriastradh 	const uint32_t *iv_entry;
6041ec0267Sriastradh };
6141ec0267Sriastradh 
62efa246c0Sriastradh struct amdgpu_irq_src {
63efa246c0Sriastradh 	unsigned				num_types;
64efa246c0Sriastradh 	atomic_t				*enabled_types;
65efa246c0Sriastradh 	const struct amdgpu_irq_src_funcs	*funcs;
66efa246c0Sriastradh 	void *data;
67efa246c0Sriastradh };
68efa246c0Sriastradh 
6941ec0267Sriastradh struct amdgpu_irq_client {
7041ec0267Sriastradh 	struct amdgpu_irq_src **sources;
7141ec0267Sriastradh };
7241ec0267Sriastradh 
73efa246c0Sriastradh /* provided by interrupt generating IP blocks */
74efa246c0Sriastradh struct amdgpu_irq_src_funcs {
75efa246c0Sriastradh 	int (*set)(struct amdgpu_device *adev, struct amdgpu_irq_src *source,
76efa246c0Sriastradh 		   unsigned type, enum amdgpu_interrupt_state state);
77efa246c0Sriastradh 
78efa246c0Sriastradh 	int (*process)(struct amdgpu_device *adev,
79efa246c0Sriastradh 		       struct amdgpu_irq_src *source,
80efa246c0Sriastradh 		       struct amdgpu_iv_entry *entry);
81efa246c0Sriastradh };
82efa246c0Sriastradh 
83efa246c0Sriastradh struct amdgpu_irq {
84efa246c0Sriastradh 	bool				installed;
85efa246c0Sriastradh 	spinlock_t			lock;
86efa246c0Sriastradh 	/* interrupt sources */
8741ec0267Sriastradh 	struct amdgpu_irq_client	client[AMDGPU_IRQ_CLIENTID_MAX];
88efa246c0Sriastradh 
89efa246c0Sriastradh 	/* status, etc. */
90efa246c0Sriastradh 	bool				msi_enabled; /* msi enabled */
91efa246c0Sriastradh 
9241ec0267Sriastradh 	/* interrupt rings */
9341ec0267Sriastradh 	struct amdgpu_ih_ring		ih, ih1, ih2;
94efa246c0Sriastradh 	const struct amdgpu_ih_funcs    *ih_funcs;
9541ec0267Sriastradh 	struct work_struct		ih1_work, ih2_work;
9641ec0267Sriastradh 	struct amdgpu_irq_src		self_irq;
9741ec0267Sriastradh 
9841ec0267Sriastradh 	/* gen irq stuff */
9941ec0267Sriastradh 	struct irq_domain		*domain; /* GPU irq controller domain */
10041ec0267Sriastradh 	unsigned			virq[AMDGPU_MAX_IRQ_SRC_ID];
10141ec0267Sriastradh 	uint32_t                        srbm_soft_reset;
102efa246c0Sriastradh };
103efa246c0Sriastradh 
10441ec0267Sriastradh void amdgpu_irq_disable_all(struct amdgpu_device *adev);
105*5be1b89fSriastradh irqreturn_t amdgpu_irq_handler(DRM_IRQ_ARGS);
106efa246c0Sriastradh 
107efa246c0Sriastradh int amdgpu_irq_init(struct amdgpu_device *adev);
108efa246c0Sriastradh void amdgpu_irq_fini(struct amdgpu_device *adev);
10941ec0267Sriastradh int amdgpu_irq_add_id(struct amdgpu_device *adev,
11041ec0267Sriastradh 		      unsigned client_id, unsigned src_id,
111efa246c0Sriastradh 		      struct amdgpu_irq_src *source);
112efa246c0Sriastradh void amdgpu_irq_dispatch(struct amdgpu_device *adev,
11341ec0267Sriastradh 			 struct amdgpu_ih_ring *ih);
114efa246c0Sriastradh int amdgpu_irq_update(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
115efa246c0Sriastradh 		      unsigned type);
116efa246c0Sriastradh int amdgpu_irq_get(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
117efa246c0Sriastradh 		   unsigned type);
118efa246c0Sriastradh int amdgpu_irq_put(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
119efa246c0Sriastradh 		   unsigned type);
120efa246c0Sriastradh bool amdgpu_irq_enabled(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
121efa246c0Sriastradh 			unsigned type);
12241ec0267Sriastradh void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev);
12341ec0267Sriastradh 
12441ec0267Sriastradh int amdgpu_irq_add_domain(struct amdgpu_device *adev);
12541ec0267Sriastradh void amdgpu_irq_remove_domain(struct amdgpu_device *adev);
12641ec0267Sriastradh unsigned amdgpu_irq_create_mapping(struct amdgpu_device *adev, unsigned src_id);
127efa246c0Sriastradh 
128efa246c0Sriastradh #endif
129