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