xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/amd/amdkfd/kfd_kernel_queue.h (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: kfd_kernel_queue.h,v 1.3 2021/12/18 23:44:59 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2014 Advanced Micro Devices, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */
25 
26 #ifndef KFD_KERNEL_QUEUE_H_
27 #define KFD_KERNEL_QUEUE_H_
28 
29 #include <linux/list.h>
30 #include <linux/types.h>
31 #include "kfd_priv.h"
32 
33 /**
34  * kq_acquire_packet_buffer: Returns a pointer to the location in the kernel
35  * queue ring buffer where the calling function can write its packet. It is
36  * Guaranteed that there is enough space for that packet. It also updates the
37  * pending write pointer to that location so subsequent calls to
38  * acquire_packet_buffer will get a correct write pointer
39  *
40  * kq_submit_packet: Update the write pointer and doorbell of a kernel queue.
41  *
42  * kq_rollback_packet: This routine is called if we failed to build an acquired
43  * packet for some reason. It just overwrites the pending wptr with the current
44  * one
45  *
46  */
47 
48 int kq_acquire_packet_buffer(struct kernel_queue *kq,
49 				size_t packet_size_in_dwords,
50 				unsigned int **buffer_ptr);
51 void kq_submit_packet(struct kernel_queue *kq);
52 void kq_rollback_packet(struct kernel_queue *kq);
53 
54 
55 struct kernel_queue {
56 	/* data */
57 	struct kfd_dev		*dev;
58 	struct mqd_manager	*mqd_mgr;
59 	struct queue		*queue;
60 	uint64_t		pending_wptr64;
61 	uint32_t		pending_wptr;
62 	unsigned int		nop_packet;
63 
64 	struct kfd_mem_obj	*rptr_mem;
65 	uint32_t		*rptr_kernel;
66 	uint64_t		rptr_gpu_addr;
67 	struct kfd_mem_obj	*wptr_mem;
68 	union {
69 		uint64_t	*wptr64_kernel;
70 		uint32_t	*wptr_kernel;
71 	};
72 	uint64_t		wptr_gpu_addr;
73 	struct kfd_mem_obj	*pq;
74 	uint64_t		pq_gpu_addr;
75 	uint32_t		*pq_kernel_addr;
76 	struct kfd_mem_obj	*eop_mem;
77 	uint64_t		eop_gpu_addr;
78 	uint32_t		*eop_kernel_addr;
79 
80 	struct kfd_mem_obj	*fence_mem_obj;
81 	uint64_t		fence_gpu_addr;
82 	void			*fence_kernel_address;
83 
84 	struct list_head	list;
85 };
86 
87 #endif /* KFD_KERNEL_QUEUE_H_ */
88