1d87f36a0SRajneesh Bhardwaj /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 2ed6e6a34SBen Goz /* 3d87f36a0SRajneesh Bhardwaj * Copyright 2014-2022 Advanced Micro Devices, Inc. 4ed6e6a34SBen Goz * 5ed6e6a34SBen Goz * Permission is hereby granted, free of charge, to any person obtaining a 6ed6e6a34SBen Goz * copy of this software and associated documentation files (the "Software"), 7ed6e6a34SBen Goz * to deal in the Software without restriction, including without limitation 8ed6e6a34SBen Goz * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9ed6e6a34SBen Goz * and/or sell copies of the Software, and to permit persons to whom the 10ed6e6a34SBen Goz * Software is furnished to do so, subject to the following conditions: 11ed6e6a34SBen Goz * 12ed6e6a34SBen Goz * The above copyright notice and this permission notice shall be included in 13ed6e6a34SBen Goz * all copies or substantial portions of the Software. 14ed6e6a34SBen Goz * 15ed6e6a34SBen Goz * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16ed6e6a34SBen Goz * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17ed6e6a34SBen Goz * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18ed6e6a34SBen Goz * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19ed6e6a34SBen Goz * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20ed6e6a34SBen Goz * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21ed6e6a34SBen Goz * OTHER DEALINGS IN THE SOFTWARE. 22ed6e6a34SBen Goz * 23ed6e6a34SBen Goz */ 24ed6e6a34SBen Goz 25ed6e6a34SBen Goz #ifndef KFD_KERNEL_QUEUE_H_ 26ed6e6a34SBen Goz #define KFD_KERNEL_QUEUE_H_ 27ed6e6a34SBen Goz 28ed6e6a34SBen Goz #include <linux/list.h> 29ed6e6a34SBen Goz #include <linux/types.h> 30ed6e6a34SBen Goz #include "kfd_priv.h" 31ed6e6a34SBen Goz 32443fbd5fSOded Gabbay /** 33a5a4d68cSYong Zhao * kq_acquire_packet_buffer: Returns a pointer to the location in the kernel 34443fbd5fSOded Gabbay * queue ring buffer where the calling function can write its packet. It is 35443fbd5fSOded Gabbay * Guaranteed that there is enough space for that packet. It also updates the 36443fbd5fSOded Gabbay * pending write pointer to that location so subsequent calls to 37443fbd5fSOded Gabbay * acquire_packet_buffer will get a correct write pointer 38443fbd5fSOded Gabbay * 39a5a4d68cSYong Zhao * kq_submit_packet: Update the write pointer and doorbell of a kernel queue. 40443fbd5fSOded Gabbay * 41a5a4d68cSYong Zhao * kq_rollback_packet: This routine is called if we failed to build an acquired 42443fbd5fSOded Gabbay * packet for some reason. It just overwrites the pending wptr with the current 43443fbd5fSOded Gabbay * one 44443fbd5fSOded Gabbay * 45443fbd5fSOded Gabbay */ 46a5a4d68cSYong Zhao 47a5a4d68cSYong Zhao int kq_acquire_packet_buffer(struct kernel_queue *kq, 48ed6e6a34SBen Goz size_t packet_size_in_dwords, 49ed6e6a34SBen Goz unsigned int **buffer_ptr); 50a5a4d68cSYong Zhao void kq_submit_packet(struct kernel_queue *kq); 51a5a4d68cSYong Zhao void kq_rollback_packet(struct kernel_queue *kq); 52ed6e6a34SBen Goz 53443fbd5fSOded Gabbay 54443fbd5fSOded Gabbay struct kernel_queue { 55ed6e6a34SBen Goz /* data */ 56*8dc1db31SMukul Joshi struct kfd_node *dev; 578d5f3552SYong Zhao struct mqd_manager *mqd_mgr; 58ed6e6a34SBen Goz struct queue *queue; 599d7d0248SFelix Kuehling uint64_t pending_wptr64; 60ed6e6a34SBen Goz uint32_t pending_wptr; 61ed6e6a34SBen Goz unsigned int nop_packet; 62ed6e6a34SBen Goz 63ed6e6a34SBen Goz struct kfd_mem_obj *rptr_mem; 64ed6e6a34SBen Goz uint32_t *rptr_kernel; 65ed6e6a34SBen Goz uint64_t rptr_gpu_addr; 66ed6e6a34SBen Goz struct kfd_mem_obj *wptr_mem; 679d7d0248SFelix Kuehling union { 689d7d0248SFelix Kuehling uint64_t *wptr64_kernel; 69ed6e6a34SBen Goz uint32_t *wptr_kernel; 709d7d0248SFelix Kuehling }; 71ed6e6a34SBen Goz uint64_t wptr_gpu_addr; 72ed6e6a34SBen Goz struct kfd_mem_obj *pq; 73ed6e6a34SBen Goz uint64_t pq_gpu_addr; 74ed6e6a34SBen Goz uint32_t *pq_kernel_addr; 756898f0a5SBen Goz struct kfd_mem_obj *eop_mem; 766898f0a5SBen Goz uint64_t eop_gpu_addr; 776898f0a5SBen Goz uint32_t *eop_kernel_addr; 78ed6e6a34SBen Goz 79ed6e6a34SBen Goz struct kfd_mem_obj *fence_mem_obj; 80ed6e6a34SBen Goz uint64_t fence_gpu_addr; 81ed6e6a34SBen Goz void *fence_kernel_address; 82ed6e6a34SBen Goz 83ed6e6a34SBen Goz struct list_head list; 84ed6e6a34SBen Goz }; 85ed6e6a34SBen Goz 86ed6e6a34SBen Goz #endif /* KFD_KERNEL_QUEUE_H_ */ 87