aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Goz <ben.goz@amd.com>2014-07-16 17:18:51 -0400
committerOded Gabbay <oded.gabbay@amd.com>2014-07-16 17:18:51 -0400
commited8aab4594e0c5054b25b4a8810901ccf70efdcf (patch)
tree6aa45d020d96588a7621167ca64f6c2372c9e5f6
parentb17f068a09fbe9b193a18080ff8ad5114a900124 (diff)
amdkfd: Add queue module
The queue module enables allocating and initializing queues uniformly. v3: Removed typedef and redundant memset call. Broke long pr_debug print to one liners and Added documentation. v5: Move amdkfd from drm/radeon/ to drm/amd/ Signed-off-by: Ben Goz <ben.goz@amd.com> Signed-off-by: Oded Gabbay <oded.gabbay@amd.com>
-rw-r--r--drivers/gpu/drm/amd/amdkfd/Makefile2
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_priv.h124
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_queue.c85
3 files changed, 209 insertions, 2 deletions
diff --git a/drivers/gpu/drm/amd/amdkfd/Makefile b/drivers/gpu/drm/amd/amdkfd/Makefile
index e829a3fa7d8e..42df022a0912 100644
--- a/drivers/gpu/drm/amd/amdkfd/Makefile
+++ b/drivers/gpu/drm/amd/amdkfd/Makefile
@@ -6,6 +6,6 @@ ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/amd/include/
6 6
7amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \ 7amdkfd-y := kfd_module.o kfd_device.o kfd_chardev.o kfd_topology.o \
8 kfd_pasid.o kfd_doorbell.o kfd_flat_memory.o \ 8 kfd_pasid.o kfd_doorbell.o kfd_flat_memory.o \
9 kfd_process.o 9 kfd_process.o kfd_queue.o
10 10
11obj-$(CONFIG_HSA_AMD) += amdkfd.o 11obj-$(CONFIG_HSA_AMD) += amdkfd.o
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index 431a09bbab62..5f6f13d1a20d 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -57,7 +57,6 @@ extern int max_num_of_queues_per_process;
57#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT 128 57#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT 128
58#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024 58#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024
59 59
60
61struct kfd_device_info { 60struct kfd_device_info {
62 unsigned int max_pasid_bits; 61 unsigned int max_pasid_bits;
63 size_t ih_ring_entry_size; 62 size_t ih_ring_entry_size;
@@ -120,6 +119,129 @@ void kfd_chardev_exit(void);
120struct device *kfd_chardev(void); 119struct device *kfd_chardev(void);
121 120
122 121
122/**
123 * enum kfd_queue_type
124 *
125 * @KFD_QUEUE_TYPE_COMPUTE: Regular user mode queue type.
126 *
127 * @KFD_QUEUE_TYPE_SDMA: Sdma user mode queue type.
128 *
129 * @KFD_QUEUE_TYPE_HIQ: HIQ queue type.
130 *
131 * @KFD_QUEUE_TYPE_DIQ: DIQ queue type.
132 */
133enum kfd_queue_type {
134 KFD_QUEUE_TYPE_COMPUTE,
135 KFD_QUEUE_TYPE_SDMA,
136 KFD_QUEUE_TYPE_HIQ,
137 KFD_QUEUE_TYPE_DIQ
138};
139
140/**
141 * struct queue_properties
142 *
143 * @type: The queue type.
144 *
145 * @queue_id: Queue identifier.
146 *
147 * @queue_address: Queue ring buffer address.
148 *
149 * @queue_size: Queue ring buffer size.
150 *
151 * @priority: Defines the queue priority relative to other queues in the
152 * process.
153 * This is just an indication and HW scheduling may override the priority as
154 * necessary while keeping the relative prioritization.
155 * the priority granularity is from 0 to f which f is the highest priority.
156 * currently all queues are initialized with the highest priority.
157 *
158 * @queue_percent: This field is partially implemented and currently a zero in
159 * this field defines that the queue is non active.
160 *
161 * @read_ptr: User space address which points to the number of dwords the
162 * cp read from the ring buffer. This field updates automatically by the H/W.
163 *
164 * @write_ptr: Defines the number of dwords written to the ring buffer.
165 *
166 * @doorbell_ptr: This field aim is to notify the H/W of new packet written to
167 * the queue ring buffer. This field should be similar to write_ptr and the user
168 * should update this field after he updated the write_ptr.
169 *
170 * @doorbell_off: The doorbell offset in the doorbell pci-bar.
171 *
172 * @is_interop: Defines if this is a interop queue. Interop queue means that the
173 * queue can access both graphics and compute resources.
174 *
175 * @is_active: Defines if the queue is active or not.
176 *
177 * @vmid: If the scheduling mode is no cp scheduling the field defines the vmid
178 * of the queue.
179 *
180 * This structure represents the queue properties for each queue no matter if
181 * it's user mode or kernel mode queue.
182 *
183 */
184struct queue_properties {
185 enum kfd_queue_type type;
186 unsigned int queue_id;
187 uint64_t queue_address;
188 uint64_t queue_size;
189 uint32_t priority;
190 uint32_t queue_percent;
191 uint32_t *read_ptr;
192 uint32_t *write_ptr;
193 uint32_t *doorbell_ptr;
194 uint32_t doorbell_off;
195 bool is_interop;
196 bool is_active;
197 /* Not relevant for user mode queues in cp scheduling */
198 unsigned int vmid;
199};
200
201/**
202 * struct queue
203 *
204 * @list: Queue linked list.
205 *
206 * @mqd: The queue MQD.
207 *
208 * @mqd_mem_obj: The MQD local gpu memory object.
209 *
210 * @gart_mqd_addr: The MQD gart mc address.
211 *
212 * @properties: The queue properties.
213 *
214 * @mec: Used only in no cp scheduling mode and identifies to micro engine id
215 * that the queue should be execute on.
216 *
217 * @pipe: Used only in no cp scheduling mode and identifies the queue's pipe id.
218 *
219 * @queue: Used only in no cp scheduliong mode and identifies the queue's slot.
220 *
221 * @process: The kfd process that created this queue.
222 *
223 * @device: The kfd device that created this queue.
224 *
225 * This structure represents user mode compute queues.
226 * It contains all the necessary data to handle such queues.
227 *
228 */
229
230struct queue {
231 struct list_head list;
232 void *mqd;
233 struct kfd_mem_obj *mqd_mem_obj;
234 uint64_t gart_mqd_addr;
235 struct queue_properties properties;
236
237 uint32_t mec;
238 uint32_t pipe;
239 uint32_t queue;
240
241 struct kfd_process *process;
242 struct kfd_dev *device;
243};
244
123/* Data that is per-process-per device. */ 245/* Data that is per-process-per device. */
124struct kfd_process_device { 246struct kfd_process_device {
125 /* 247 /*
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_queue.c b/drivers/gpu/drm/amd/amdkfd/kfd_queue.c
new file mode 100644
index 000000000000..9a0c90b0702e
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_queue.c
@@ -0,0 +1,85 @@
1/*
2 * Copyright 2014 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
23
24#include <linux/slab.h>
25#include "kfd_priv.h"
26
27void print_queue_properties(struct queue_properties *q)
28{
29 if (!q)
30 return;
31
32 pr_debug("Printing queue properties:\n");
33 pr_debug("Queue Type: %u\n", q->type);
34 pr_debug("Queue Size: %llu\n", q->queue_size);
35 pr_debug("Queue percent: %u\n", q->queue_percent);
36 pr_debug("Queue Address: 0x%llX\n", q->queue_address);
37 pr_debug("Queue Id: %u\n", q->queue_id);
38 pr_debug("Queue Process Vmid: %u\n", q->vmid);
39 pr_debug("Queue Read Pointer: 0x%p\n", q->read_ptr);
40 pr_debug("Queue Write Pointer: 0x%p\n", q->write_ptr);
41 pr_debug("Queue Doorbell Pointer: 0x%p\n", q->doorbell_ptr);
42 pr_debug("Queue Doorbell Offset: %u\n", q->doorbell_off);
43}
44
45void print_queue(struct queue *q)
46{
47 if (!q)
48 return;
49 pr_debug("Printing queue:\n");
50 pr_debug("Queue Type: %u\n", q->properties.type);
51 pr_debug("Queue Size: %llu\n", q->properties.queue_size);
52 pr_debug("Queue percent: %u\n", q->properties.queue_percent);
53 pr_debug("Queue Address: 0x%llX\n", q->properties.queue_address);
54 pr_debug("Queue Id: %u\n", q->properties.queue_id);
55 pr_debug("Queue Process Vmid: %u\n", q->properties.vmid);
56 pr_debug("Queue Read Pointer: 0x%p\n", q->properties.read_ptr);
57 pr_debug("Queue Write Pointer: 0x%p\n", q->properties.write_ptr);
58 pr_debug("Queue Doorbell Pointer: 0x%p\n", q->properties.doorbell_ptr);
59 pr_debug("Queue Doorbell Offset: %u\n", q->properties.doorbell_off);
60 pr_debug("Queue MQD Address: 0x%p\n", q->mqd);
61 pr_debug("Queue MQD Gart: 0x%llX\n", q->gart_mqd_addr);
62 pr_debug("Queue Process Address: 0x%p\n", q->process);
63 pr_debug("Queue Device Address: 0x%p\n", q->device);
64}
65
66int init_queue(struct queue **q, struct queue_properties properties)
67{
68 struct queue *tmp;
69
70 BUG_ON(!q);
71
72 tmp = kzalloc(sizeof(struct queue), GFP_KERNEL);
73 if (!tmp)
74 return -ENOMEM;
75
76 memcpy(&tmp->properties, &properties, sizeof(struct queue_properties));
77
78 *q = tmp;
79 return 0;
80}
81
82void uninit_queue(struct queue *q)
83{
84 kfree(q);
85}