162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 OR MIT 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright 2014-2022 Advanced Micro Devices, Inc. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 662306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 762306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 862306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 962306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 1062306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 1362306a36Sopenharmony_ci * all copies or substantial portions of the Software. 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1662306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1762306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1862306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 1962306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2062306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2162306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 2262306a36Sopenharmony_ci * 2362306a36Sopenharmony_ci */ 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#include <linux/slab.h> 2662306a36Sopenharmony_ci#include "kfd_priv.h" 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_civoid print_queue_properties(struct queue_properties *q) 2962306a36Sopenharmony_ci{ 3062306a36Sopenharmony_ci if (!q) 3162306a36Sopenharmony_ci return; 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci pr_debug("Printing queue properties:\n"); 3462306a36Sopenharmony_ci pr_debug("Queue Type: %u\n", q->type); 3562306a36Sopenharmony_ci pr_debug("Queue Size: %llu\n", q->queue_size); 3662306a36Sopenharmony_ci pr_debug("Queue percent: %u\n", q->queue_percent); 3762306a36Sopenharmony_ci pr_debug("Queue Address: 0x%llX\n", q->queue_address); 3862306a36Sopenharmony_ci pr_debug("Queue Id: %u\n", q->queue_id); 3962306a36Sopenharmony_ci pr_debug("Queue Process Vmid: %u\n", q->vmid); 4062306a36Sopenharmony_ci pr_debug("Queue Read Pointer: 0x%px\n", q->read_ptr); 4162306a36Sopenharmony_ci pr_debug("Queue Write Pointer: 0x%px\n", q->write_ptr); 4262306a36Sopenharmony_ci pr_debug("Queue Doorbell Pointer: 0x%p\n", q->doorbell_ptr); 4362306a36Sopenharmony_ci pr_debug("Queue Doorbell Offset: %u\n", q->doorbell_off); 4462306a36Sopenharmony_ci} 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_civoid print_queue(struct queue *q) 4762306a36Sopenharmony_ci{ 4862306a36Sopenharmony_ci if (!q) 4962306a36Sopenharmony_ci return; 5062306a36Sopenharmony_ci pr_debug("Printing queue:\n"); 5162306a36Sopenharmony_ci pr_debug("Queue Type: %u\n", q->properties.type); 5262306a36Sopenharmony_ci pr_debug("Queue Size: %llu\n", q->properties.queue_size); 5362306a36Sopenharmony_ci pr_debug("Queue percent: %u\n", q->properties.queue_percent); 5462306a36Sopenharmony_ci pr_debug("Queue Address: 0x%llX\n", q->properties.queue_address); 5562306a36Sopenharmony_ci pr_debug("Queue Id: %u\n", q->properties.queue_id); 5662306a36Sopenharmony_ci pr_debug("Queue Process Vmid: %u\n", q->properties.vmid); 5762306a36Sopenharmony_ci pr_debug("Queue Read Pointer: 0x%px\n", q->properties.read_ptr); 5862306a36Sopenharmony_ci pr_debug("Queue Write Pointer: 0x%px\n", q->properties.write_ptr); 5962306a36Sopenharmony_ci pr_debug("Queue Doorbell Pointer: 0x%p\n", q->properties.doorbell_ptr); 6062306a36Sopenharmony_ci pr_debug("Queue Doorbell Offset: %u\n", q->properties.doorbell_off); 6162306a36Sopenharmony_ci pr_debug("Queue MQD Address: 0x%p\n", q->mqd); 6262306a36Sopenharmony_ci pr_debug("Queue MQD Gart: 0x%llX\n", q->gart_mqd_addr); 6362306a36Sopenharmony_ci pr_debug("Queue Process Address: 0x%p\n", q->process); 6462306a36Sopenharmony_ci pr_debug("Queue Device Address: 0x%p\n", q->device); 6562306a36Sopenharmony_ci} 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ciint init_queue(struct queue **q, const struct queue_properties *properties) 6862306a36Sopenharmony_ci{ 6962306a36Sopenharmony_ci struct queue *tmp_q; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci tmp_q = kzalloc(sizeof(*tmp_q), GFP_KERNEL); 7262306a36Sopenharmony_ci if (!tmp_q) 7362306a36Sopenharmony_ci return -ENOMEM; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci memcpy(&tmp_q->properties, properties, sizeof(*properties)); 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci *q = tmp_q; 7862306a36Sopenharmony_ci return 0; 7962306a36Sopenharmony_ci} 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_civoid uninit_queue(struct queue *q) 8262306a36Sopenharmony_ci{ 8362306a36Sopenharmony_ci kfree(q); 8462306a36Sopenharmony_ci} 85