1*d87f36a0SRajneesh Bhardwaj // SPDX-License-Identifier: GPL-2.0 OR MIT
2ed8aab45SBen Goz /*
3*d87f36a0SRajneesh Bhardwaj  * Copyright 2014-2022 Advanced Micro Devices, Inc.
4ed8aab45SBen Goz  *
5ed8aab45SBen Goz  * Permission is hereby granted, free of charge, to any person obtaining a
6ed8aab45SBen Goz  * copy of this software and associated documentation files (the "Software"),
7ed8aab45SBen Goz  * to deal in the Software without restriction, including without limitation
8ed8aab45SBen Goz  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9ed8aab45SBen Goz  * and/or sell copies of the Software, and to permit persons to whom the
10ed8aab45SBen Goz  * Software is furnished to do so, subject to the following conditions:
11ed8aab45SBen Goz  *
12ed8aab45SBen Goz  * The above copyright notice and this permission notice shall be included in
13ed8aab45SBen Goz  * all copies or substantial portions of the Software.
14ed8aab45SBen Goz  *
15ed8aab45SBen Goz  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16ed8aab45SBen Goz  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17ed8aab45SBen Goz  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18ed8aab45SBen Goz  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19ed8aab45SBen Goz  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20ed8aab45SBen Goz  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21ed8aab45SBen Goz  * OTHER DEALINGS IN THE SOFTWARE.
22ed8aab45SBen Goz  *
23ed8aab45SBen Goz  */
24ed8aab45SBen Goz 
25ed8aab45SBen Goz #include <linux/slab.h>
26ed8aab45SBen Goz #include "kfd_priv.h"
27ed8aab45SBen Goz 
print_queue_properties(struct queue_properties * q)28ed8aab45SBen Goz void print_queue_properties(struct queue_properties *q)
29ed8aab45SBen Goz {
30ed8aab45SBen Goz 	if (!q)
31ed8aab45SBen Goz 		return;
32ed8aab45SBen Goz 
33ed8aab45SBen Goz 	pr_debug("Printing queue properties:\n");
34ed8aab45SBen Goz 	pr_debug("Queue Type: %u\n", q->type);
35ed8aab45SBen Goz 	pr_debug("Queue Size: %llu\n", q->queue_size);
36ed8aab45SBen Goz 	pr_debug("Queue percent: %u\n", q->queue_percent);
37ed8aab45SBen Goz 	pr_debug("Queue Address: 0x%llX\n", q->queue_address);
38ed8aab45SBen Goz 	pr_debug("Queue Id: %u\n", q->queue_id);
39ed8aab45SBen Goz 	pr_debug("Queue Process Vmid: %u\n", q->vmid);
40fa7e6514SPhilip Yang 	pr_debug("Queue Read Pointer: 0x%px\n", q->read_ptr);
41fa7e6514SPhilip Yang 	pr_debug("Queue Write Pointer: 0x%px\n", q->write_ptr);
42ed8aab45SBen Goz 	pr_debug("Queue Doorbell Pointer: 0x%p\n", q->doorbell_ptr);
43ed8aab45SBen Goz 	pr_debug("Queue Doorbell Offset: %u\n", q->doorbell_off);
44ed8aab45SBen Goz }
45ed8aab45SBen Goz 
print_queue(struct queue * q)46ed8aab45SBen Goz void print_queue(struct queue *q)
47ed8aab45SBen Goz {
48ed8aab45SBen Goz 	if (!q)
49ed8aab45SBen Goz 		return;
50ed8aab45SBen Goz 	pr_debug("Printing queue:\n");
51ed8aab45SBen Goz 	pr_debug("Queue Type: %u\n", q->properties.type);
52ed8aab45SBen Goz 	pr_debug("Queue Size: %llu\n", q->properties.queue_size);
53ed8aab45SBen Goz 	pr_debug("Queue percent: %u\n", q->properties.queue_percent);
54ed8aab45SBen Goz 	pr_debug("Queue Address: 0x%llX\n", q->properties.queue_address);
55ed8aab45SBen Goz 	pr_debug("Queue Id: %u\n", q->properties.queue_id);
56ed8aab45SBen Goz 	pr_debug("Queue Process Vmid: %u\n", q->properties.vmid);
57fa7e6514SPhilip Yang 	pr_debug("Queue Read Pointer: 0x%px\n", q->properties.read_ptr);
58fa7e6514SPhilip Yang 	pr_debug("Queue Write Pointer: 0x%px\n", q->properties.write_ptr);
59ed8aab45SBen Goz 	pr_debug("Queue Doorbell Pointer: 0x%p\n", q->properties.doorbell_ptr);
60ed8aab45SBen Goz 	pr_debug("Queue Doorbell Offset: %u\n", q->properties.doorbell_off);
61ed8aab45SBen Goz 	pr_debug("Queue MQD Address: 0x%p\n", q->mqd);
62ed8aab45SBen Goz 	pr_debug("Queue MQD Gart: 0x%llX\n", q->gart_mqd_addr);
63ed8aab45SBen Goz 	pr_debug("Queue Process Address: 0x%p\n", q->process);
64ed8aab45SBen Goz 	pr_debug("Queue Device Address: 0x%p\n", q->device);
65ed8aab45SBen Goz }
66ed8aab45SBen Goz 
init_queue(struct queue ** q,const struct queue_properties * properties)67e88a614cSEdward O'Callaghan int init_queue(struct queue **q, const struct queue_properties *properties)
68ed8aab45SBen Goz {
69dbf56ab1SKent Russell 	struct queue *tmp_q;
70ed8aab45SBen Goz 
71dbf56ab1SKent Russell 	tmp_q = kzalloc(sizeof(*tmp_q), GFP_KERNEL);
72dbf56ab1SKent Russell 	if (!tmp_q)
73ed8aab45SBen Goz 		return -ENOMEM;
74ed8aab45SBen Goz 
75dbf56ab1SKent Russell 	memcpy(&tmp_q->properties, properties, sizeof(*properties));
76ed8aab45SBen Goz 
77dbf56ab1SKent Russell 	*q = tmp_q;
78ed8aab45SBen Goz 	return 0;
79ed8aab45SBen Goz }
80ed8aab45SBen Goz 
uninit_queue(struct queue * q)81ed8aab45SBen Goz void uninit_queue(struct queue *q)
82ed8aab45SBen Goz {
83ed8aab45SBen Goz 	kfree(q);
84ed8aab45SBen Goz }
85