// SPDX-License-Identifier: GPL-2.0 OR MIT /* * Copyright 2014-2022 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. *
*/
/* For CIK family asics, kq->eop_mem is not needed */ if (dev->adev->asic_type > CHIP_MULLINS) {
retval = kfd_gtt_sa_allocate(dev, PAGE_SIZE, &kq->eop_mem); if (retval != 0) goto err_eop_allocate_vidmem;
/* When rptr == wptr, the buffer is empty. * When rptr == wptr + 1, the buffer is full. * It is always rptr that advances to the position of wptr, rather than * the opposite. So we can only use up to queue_size_dwords - 1 dwords.
*/
rptr = *kq->rptr_kernel;
wptr = kq->pending_wptr;
wptr64 = kq->pending_wptr64;
queue_address = (unsignedint *)kq->pq_kernel_addr;
queue_size_dwords = kq->queue->properties.queue_size / 4;
if (packet_size_in_dwords > available_size) { /* * make sure calling functions know * acquire_packet_buffer() failed
*/ goto err_no_space;
}
if (wptr + packet_size_in_dwords >= queue_size_dwords) { /* make sure after rolling back to position 0, there is * still enough space.
*/ if (packet_size_in_dwords >= rptr) goto err_no_space;
/* fill nops, roll back and start at position 0 */ while (wptr > 0) {
queue_address[wptr] = kq->nop_packet;
wptr = (wptr + 1) % queue_size_dwords;
wptr64++;
}
}
int kq_submit_packet(struct kernel_queue *kq)
{ #ifdef DEBUG int i;
for (i = *kq->wptr_kernel; i < kq->pending_wptr; i++) {
pr_debug("0x%2X ", kq->pq_kernel_addr[i]); if (i % 15 == 0)
pr_debug("\n");
}
pr_debug("\n"); #endif /* Fatal err detected, packet submission won't go through */ if (amdgpu_amdkfd_is_fed(kq->dev->adev)) return -EIO;
/* Make sure ring buffer is updated before wptr updated */
mb();
if (kq->dev->kfd->device_info.doorbell_size == 8) {
*kq->wptr64_kernel = kq->pending_wptr64;
mb(); /* Make sure wptr updated before ring doorbell */
write_kernel_doorbell64(kq->queue->properties.doorbell_ptr,
kq->pending_wptr64);
} else {
*kq->wptr_kernel = kq->pending_wptr;
mb(); /* Make sure wptr updated before ring doorbell */
write_kernel_doorbell(kq->queue->properties.doorbell_ptr,
kq->pending_wptr);
}
/* FIXME: Can this test be removed? */ static __attribute__((unused)) void test_kq(struct kfd_node *dev)
{ struct kernel_queue *kq;
uint32_t *buffer, i; int retval;
kq = kernel_queue_init(dev, KFD_QUEUE_TYPE_HIQ); if (unlikely(!kq)) {
dev_err(dev->adev->dev, " Failed to initialize HIQ\n");
dev_err(dev->adev->dev, "Kernel queue test failed\n"); return;
}
retval = kq_acquire_packet_buffer(kq, 5, &buffer); if (unlikely(retval != 0)) {
dev_err(dev->adev->dev, " Failed to acquire packet buffer\n");
dev_err(dev->adev->dev, "Kernel queue test failed\n"); return;
} for (i = 0; i < 5; i++)
buffer[i] = kq->nop_packet;
kq_submit_packet(kq);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.