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