xref: /openbsd-src/sys/dev/pci/drm/amd/amdgpu/amdgpu_ih.h (revision f005ef32267c16bdb134f0e9fa4477dbe07c263a)
1fb4d8502Sjsg /*
2fb4d8502Sjsg  * Copyright 2014 Advanced Micro Devices, Inc.
3fb4d8502Sjsg  *
4fb4d8502Sjsg  * Permission is hereby granted, free of charge, to any person obtaining a
5fb4d8502Sjsg  * copy of this software and associated documentation files (the "Software"),
6fb4d8502Sjsg  * to deal in the Software without restriction, including without limitation
7fb4d8502Sjsg  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8fb4d8502Sjsg  * and/or sell copies of the Software, and to permit persons to whom the
9fb4d8502Sjsg  * Software is furnished to do so, subject to the following conditions:
10fb4d8502Sjsg  *
11fb4d8502Sjsg  * The above copyright notice and this permission notice shall be included in
12fb4d8502Sjsg  * all copies or substantial portions of the Software.
13fb4d8502Sjsg  *
14fb4d8502Sjsg  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15fb4d8502Sjsg  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16fb4d8502Sjsg  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17fb4d8502Sjsg  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18fb4d8502Sjsg  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19fb4d8502Sjsg  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20fb4d8502Sjsg  * OTHER DEALINGS IN THE SOFTWARE.
21fb4d8502Sjsg  *
22fb4d8502Sjsg  */
23fb4d8502Sjsg 
24fb4d8502Sjsg #ifndef __AMDGPU_IH_H__
25fb4d8502Sjsg #define __AMDGPU_IH_H__
26fb4d8502Sjsg 
27c349dbc7Sjsg /* Maximum number of IVs processed at once */
28c349dbc7Sjsg #define AMDGPU_IH_MAX_NUM_IVS	32
29fb4d8502Sjsg 
30*f005ef32Sjsg #define IH_RING_SIZE	(256 * 1024)
31*f005ef32Sjsg #define IH_SW_RING_SIZE	(16 * 1024)	/* enough for 512 CAM entries */
32*f005ef32Sjsg 
33fb4d8502Sjsg struct amdgpu_device;
34c349dbc7Sjsg struct amdgpu_iv_entry;
35fb4d8502Sjsg 
365ca02815Sjsg struct amdgpu_ih_regs {
375ca02815Sjsg 	uint32_t ih_rb_base;
385ca02815Sjsg 	uint32_t ih_rb_base_hi;
395ca02815Sjsg 	uint32_t ih_rb_cntl;
405ca02815Sjsg 	uint32_t ih_rb_wptr;
415ca02815Sjsg 	uint32_t ih_rb_rptr;
425ca02815Sjsg 	uint32_t ih_doorbell_rptr;
435ca02815Sjsg 	uint32_t ih_rb_wptr_addr_lo;
445ca02815Sjsg 	uint32_t ih_rb_wptr_addr_hi;
455ca02815Sjsg 	uint32_t psp_reg_id;
465ca02815Sjsg };
475ca02815Sjsg 
48fb4d8502Sjsg /*
49fb4d8502Sjsg  * R6xx+ IH ring
50fb4d8502Sjsg  */
51fb4d8502Sjsg struct amdgpu_ih_ring {
52fb4d8502Sjsg 	unsigned		ring_size;
53fb4d8502Sjsg 	uint32_t		ptr_mask;
54fb4d8502Sjsg 	u32			doorbell_index;
55fb4d8502Sjsg 	bool			use_doorbell;
56fb4d8502Sjsg 	bool			use_bus_addr;
57c349dbc7Sjsg 
58c349dbc7Sjsg 	struct amdgpu_bo	*ring_obj;
59c349dbc7Sjsg 	volatile uint32_t	*ring;
60c349dbc7Sjsg 	struct drm_dmamem	*dmah;
61c349dbc7Sjsg 	uint64_t		gpu_addr;
62c349dbc7Sjsg 
63c349dbc7Sjsg 	uint64_t		wptr_addr;
64c349dbc7Sjsg 	volatile uint32_t	*wptr_cpu;
65c349dbc7Sjsg 
66c349dbc7Sjsg 	uint64_t		rptr_addr;
67c349dbc7Sjsg 	volatile uint32_t	*rptr_cpu;
68c349dbc7Sjsg 
69c349dbc7Sjsg 	bool                    enabled;
70c349dbc7Sjsg 	unsigned		rptr;
715ca02815Sjsg 	struct amdgpu_ih_regs	ih_regs;
725ca02815Sjsg 
735ca02815Sjsg 	/* For waiting on IH processing at checkpoint. */
745ca02815Sjsg 	wait_queue_head_t wait_process;
751bb76ff1Sjsg 	uint64_t		processed_timestamp;
76fb4d8502Sjsg };
77fb4d8502Sjsg 
781bb76ff1Sjsg /* return true if time stamp t2 is after t1 with 48bit wrap around */
791bb76ff1Sjsg #define amdgpu_ih_ts_after(t1, t2) \
801bb76ff1Sjsg 		(((int64_t)((t2) << 16) - (int64_t)((t1) << 16)) > 0LL)
811bb76ff1Sjsg 
82c349dbc7Sjsg /* provided by the ih block */
83c349dbc7Sjsg struct amdgpu_ih_funcs {
84c349dbc7Sjsg 	/* ring read/write ptr handling, called from interrupt context */
85c349dbc7Sjsg 	u32 (*get_wptr)(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih);
86c349dbc7Sjsg 	void (*decode_iv)(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
87c349dbc7Sjsg 			  struct amdgpu_iv_entry *entry);
881bb76ff1Sjsg 	uint64_t (*decode_iv_ts)(struct amdgpu_ih_ring *ih, u32 rptr,
891bb76ff1Sjsg 				 signed int offset);
90c349dbc7Sjsg 	void (*set_rptr)(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih);
91fb4d8502Sjsg };
92fb4d8502Sjsg 
93c349dbc7Sjsg #define amdgpu_ih_get_wptr(adev, ih) (adev)->irq.ih_funcs->get_wptr((adev), (ih))
94c349dbc7Sjsg #define amdgpu_ih_decode_iv(adev, iv) \
95c349dbc7Sjsg 	(adev)->irq.ih_funcs->decode_iv((adev), (ih), (iv))
961bb76ff1Sjsg #define amdgpu_ih_decode_iv_ts(adev, ih, rptr, offset) \
971bb76ff1Sjsg 	(WARN_ON_ONCE(!(adev)->irq.ih_funcs->decode_iv_ts) ? 0 : \
981bb76ff1Sjsg 	(adev)->irq.ih_funcs->decode_iv_ts((ih), (rptr), (offset)))
99c349dbc7Sjsg #define amdgpu_ih_set_rptr(adev, ih) (adev)->irq.ih_funcs->set_rptr((adev), (ih))
100c349dbc7Sjsg 
101c349dbc7Sjsg int amdgpu_ih_ring_init(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
102c349dbc7Sjsg 			unsigned ring_size, bool use_bus_addr);
103c349dbc7Sjsg void amdgpu_ih_ring_fini(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih);
104*f005ef32Sjsg void amdgpu_ih_ring_write(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih,
105*f005ef32Sjsg 			  const uint32_t *iv, unsigned int num_dw);
1061bb76ff1Sjsg int amdgpu_ih_wait_on_checkpoint_process_ts(struct amdgpu_device *adev,
1075ca02815Sjsg 					    struct amdgpu_ih_ring *ih);
108c349dbc7Sjsg int amdgpu_ih_process(struct amdgpu_device *adev, struct amdgpu_ih_ring *ih);
1095ca02815Sjsg void amdgpu_ih_decode_iv_helper(struct amdgpu_device *adev,
1105ca02815Sjsg 				struct amdgpu_ih_ring *ih,
1115ca02815Sjsg 				struct amdgpu_iv_entry *entry);
1121bb76ff1Sjsg uint64_t amdgpu_ih_decode_iv_ts_helper(struct amdgpu_ih_ring *ih, u32 rptr,
1131bb76ff1Sjsg 				       signed int offset);
114fb4d8502Sjsg #endif
115