blob: b7bd7afd6fcf993f1582ea283a4545762751eb04 [file] [log] [blame]
Oded Gabbay4a488a72014-07-16 21:08:55 +03001/*
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#ifndef KFD_PRIV_H_INCLUDED
24#define KFD_PRIV_H_INCLUDED
25
26#include <linux/hashtable.h>
27#include <linux/mmu_notifier.h>
28#include <linux/mutex.h>
29#include <linux/types.h>
30#include <linux/atomic.h>
31#include <linux/workqueue.h>
32#include <linux/spinlock.h>
Oded Gabbay19f6d2a2014-07-16 23:25:31 +030033#include <linux/kfd_ioctl.h>
Oded Gabbay4a488a72014-07-16 21:08:55 +030034#include <kgd_kfd_interface.h>
35
Evgeny Pinchuk5b5c4e42014-07-16 21:22:32 +030036#define KFD_SYSFS_FILE_MODE 0444
37
Ben Gozed6e6a32014-07-17 00:45:35 +030038/*
39 * When working with cp scheduler we should assign the HIQ manually or via
40 * the radeon driver to a fixed hqd slot, here are the fixed HIQ hqd slot
41 * definitions for Kaveri. In Kaveri only the first ME queues participates
42 * in the cp scheduling taking that in mind we set the HIQ slot in the
43 * second ME.
44 */
45#define KFD_CIK_HIQ_PIPE 4
46#define KFD_CIK_HIQ_QUEUE 0
47
Evgeny Pinchuk5b5c4e42014-07-16 21:22:32 +030048/* GPU ID hash width in bits */
49#define KFD_GPU_ID_HASH_WIDTH 16
50
51/* Macro for allocating structures */
52#define kfd_alloc_struct(ptr_to_struct) \
53 ((typeof(ptr_to_struct)) kzalloc(sizeof(*ptr_to_struct), GFP_KERNEL))
54
Oded Gabbay19f6d2a2014-07-16 23:25:31 +030055#define KFD_MAX_NUM_OF_PROCESSES 512
Oded Gabbayb8cbab02015-01-18 13:18:01 +020056#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024
Oded Gabbay19f6d2a2014-07-16 23:25:31 +030057
58/*
Oded Gabbayb8cbab02015-01-18 13:18:01 +020059 * Kernel module parameter to specify maximum number of supported queues per
60 * device
Oded Gabbay19f6d2a2014-07-16 23:25:31 +030061 */
Oded Gabbayb8cbab02015-01-18 13:18:01 +020062extern int max_num_of_queues_per_device;
Oded Gabbay19f6d2a2014-07-16 23:25:31 +030063
Oded Gabbayb8cbab02015-01-18 13:18:01 +020064#define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT 4096
65#define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE \
66 (KFD_MAX_NUM_OF_PROCESSES * \
67 KFD_MAX_NUM_OF_QUEUES_PER_PROCESS)
Oded Gabbay19f6d2a2014-07-16 23:25:31 +030068
Ben Gozed6e6a32014-07-17 00:45:35 +030069#define KFD_KERNEL_QUEUE_SIZE 2048
70
Ben Goz31c21fe2014-07-17 00:48:28 +030071/* Kernel module parameter to specify the scheduling policy */
72extern int sched_policy;
73
74/**
75 * enum kfd_sched_policy
76 *
77 * @KFD_SCHED_POLICY_HWS: H/W scheduling policy known as command processor (cp)
78 * scheduling. In this scheduling mode we're using the firmware code to
79 * schedule the user mode queues and kernel queues such as HIQ and DIQ.
80 * the HIQ queue is used as a special queue that dispatches the configuration
81 * to the cp and the user mode queues list that are currently running.
82 * the DIQ queue is a debugging queue that dispatches debugging commands to the
83 * firmware.
84 * in this scheduling mode user mode queues over subscription feature is
85 * enabled.
86 *
87 * @KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION: The same as above but the over
88 * subscription feature disabled.
89 *
90 * @KFD_SCHED_POLICY_NO_HWS: no H/W scheduling policy is a mode which directly
91 * set the command processor registers and sets the queues "manually". This
92 * mode is used *ONLY* for debugging proposes.
93 *
94 */
95enum kfd_sched_policy {
96 KFD_SCHED_POLICY_HWS = 0,
97 KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION,
98 KFD_SCHED_POLICY_NO_HWS
99};
100
Ben Gozed6e6a32014-07-17 00:45:35 +0300101enum cache_policy {
102 cache_policy_coherent,
103 cache_policy_noncoherent
104};
105
Ben Goz0da75582015-01-01 17:10:01 +0200106enum asic_family_type {
107 CHIP_KAVERI = 0,
108 CHIP_CARRIZO
109};
110
Oded Gabbay4a488a72014-07-16 21:08:55 +0300111struct kfd_device_info {
Ben Goz0da75582015-01-01 17:10:01 +0200112 unsigned int asic_family;
Oded Gabbay4a488a72014-07-16 21:08:55 +0300113 unsigned int max_pasid_bits;
114 size_t ih_ring_entry_size;
Alexey Skidanovf7c826a2014-10-13 16:35:12 +0300115 uint8_t num_of_watch_points;
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300116 uint16_t mqd_size_aligned;
Oded Gabbay4a488a72014-07-16 21:08:55 +0300117};
118
Oded Gabbay36b5c082014-10-26 09:53:10 +0200119struct kfd_mem_obj {
120 uint32_t range_start;
121 uint32_t range_end;
122 uint64_t gpu_addr;
123 uint32_t *cpu_ptr;
124};
125
Oded Gabbay4a488a72014-07-16 21:08:55 +0300126struct kfd_dev {
127 struct kgd_dev *kgd;
128
129 const struct kfd_device_info *device_info;
130 struct pci_dev *pdev;
131
132 unsigned int id; /* topology stub index */
133
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300134 phys_addr_t doorbell_base; /* Start of actual doorbells used by
135 * KFD. It is aligned for mapping
136 * into user mode
137 */
138 size_t doorbell_id_offset; /* Doorbell offset (from KFD doorbell
139 * to HW doorbell, GFX reserved some
140 * at the start)
141 */
142 size_t doorbell_process_limit; /* Number of processes we have doorbell
143 * space for.
144 */
145 u32 __iomem *doorbell_kernel_ptr; /* This is a pointer for a doorbells
146 * page used by kernel queue
147 */
148
Oded Gabbay4a488a72014-07-16 21:08:55 +0300149 struct kgd2kfd_shared_resources shared_resources;
150
Oded Gabbay36b5c082014-10-26 09:53:10 +0200151 void *gtt_mem;
152 uint64_t gtt_start_gpu_addr;
153 void *gtt_start_cpu_ptr;
154 void *gtt_sa_bitmap;
155 struct mutex gtt_sa_lock;
156 unsigned int gtt_sa_chunk_size;
157 unsigned int gtt_sa_num_of_chunks;
158
Ben Gozed6e6a32014-07-17 00:45:35 +0300159 /* QCM Device instance */
160 struct device_queue_manager *dqm;
Oded Gabbay4a488a72014-07-16 21:08:55 +0300161
Ben Gozed6e6a32014-07-17 00:45:35 +0300162 bool init_complete;
Oded Gabbay4a488a72014-07-16 21:08:55 +0300163};
164
165/* KGD2KFD callbacks */
166void kgd2kfd_exit(void);
167struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, struct pci_dev *pdev);
168bool kgd2kfd_device_init(struct kfd_dev *kfd,
169 const struct kgd2kfd_shared_resources *gpu_resources);
170void kgd2kfd_device_exit(struct kfd_dev *kfd);
171
172extern const struct kfd2kgd_calls *kfd2kgd;
173
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300174enum kfd_mempool {
175 KFD_MEMPOOL_SYSTEM_CACHEABLE = 1,
176 KFD_MEMPOOL_SYSTEM_WRITECOMBINE = 2,
177 KFD_MEMPOOL_FRAMEBUFFER = 3,
178};
179
Oded Gabbay4a488a72014-07-16 21:08:55 +0300180/* Character device interface */
181int kfd_chardev_init(void);
182void kfd_chardev_exit(void);
183struct device *kfd_chardev(void);
184
Ben Goz241f24f2014-07-17 00:55:28 +0300185/**
186 * enum kfd_preempt_type_filter
187 *
188 * @KFD_PREEMPT_TYPE_FILTER_SINGLE_QUEUE: Preempts single queue.
189 *
190 * @KFD_PRERMPT_TYPE_FILTER_ALL_QUEUES: Preempts all queues in the
191 * running queues list.
192 *
193 * @KFD_PRERMPT_TYPE_FILTER_BY_PASID: Preempts queues that belongs to
194 * specific process.
195 *
196 */
197enum kfd_preempt_type_filter {
198 KFD_PREEMPT_TYPE_FILTER_SINGLE_QUEUE,
199 KFD_PREEMPT_TYPE_FILTER_ALL_QUEUES,
200 KFD_PREEMPT_TYPE_FILTER_BY_PASID
201};
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300202
Ben Goz6e99df52014-07-17 00:36:17 +0300203enum kfd_preempt_type {
204 KFD_PREEMPT_TYPE_WAVEFRONT,
205 KFD_PREEMPT_TYPE_WAVEFRONT_RESET
206};
207
Ben Gozed8aab42014-07-17 00:18:51 +0300208/**
209 * enum kfd_queue_type
210 *
211 * @KFD_QUEUE_TYPE_COMPUTE: Regular user mode queue type.
212 *
213 * @KFD_QUEUE_TYPE_SDMA: Sdma user mode queue type.
214 *
215 * @KFD_QUEUE_TYPE_HIQ: HIQ queue type.
216 *
217 * @KFD_QUEUE_TYPE_DIQ: DIQ queue type.
218 */
219enum kfd_queue_type {
220 KFD_QUEUE_TYPE_COMPUTE,
221 KFD_QUEUE_TYPE_SDMA,
222 KFD_QUEUE_TYPE_HIQ,
223 KFD_QUEUE_TYPE_DIQ
224};
225
Ben Goz6e99df52014-07-17 00:36:17 +0300226enum kfd_queue_format {
227 KFD_QUEUE_FORMAT_PM4,
228 KFD_QUEUE_FORMAT_AQL
229};
230
Ben Gozed8aab42014-07-17 00:18:51 +0300231/**
232 * struct queue_properties
233 *
234 * @type: The queue type.
235 *
236 * @queue_id: Queue identifier.
237 *
238 * @queue_address: Queue ring buffer address.
239 *
240 * @queue_size: Queue ring buffer size.
241 *
242 * @priority: Defines the queue priority relative to other queues in the
243 * process.
244 * This is just an indication and HW scheduling may override the priority as
245 * necessary while keeping the relative prioritization.
246 * the priority granularity is from 0 to f which f is the highest priority.
247 * currently all queues are initialized with the highest priority.
248 *
249 * @queue_percent: This field is partially implemented and currently a zero in
250 * this field defines that the queue is non active.
251 *
252 * @read_ptr: User space address which points to the number of dwords the
253 * cp read from the ring buffer. This field updates automatically by the H/W.
254 *
255 * @write_ptr: Defines the number of dwords written to the ring buffer.
256 *
257 * @doorbell_ptr: This field aim is to notify the H/W of new packet written to
258 * the queue ring buffer. This field should be similar to write_ptr and the user
259 * should update this field after he updated the write_ptr.
260 *
261 * @doorbell_off: The doorbell offset in the doorbell pci-bar.
262 *
263 * @is_interop: Defines if this is a interop queue. Interop queue means that the
264 * queue can access both graphics and compute resources.
265 *
266 * @is_active: Defines if the queue is active or not.
267 *
268 * @vmid: If the scheduling mode is no cp scheduling the field defines the vmid
269 * of the queue.
270 *
271 * This structure represents the queue properties for each queue no matter if
272 * it's user mode or kernel mode queue.
273 *
274 */
275struct queue_properties {
276 enum kfd_queue_type type;
Ben Goz6e99df52014-07-17 00:36:17 +0300277 enum kfd_queue_format format;
Ben Gozed8aab42014-07-17 00:18:51 +0300278 unsigned int queue_id;
279 uint64_t queue_address;
280 uint64_t queue_size;
281 uint32_t priority;
282 uint32_t queue_percent;
283 uint32_t *read_ptr;
284 uint32_t *write_ptr;
Oded Gabbay5cd78de2014-11-20 16:14:56 +0200285 uint32_t __iomem *doorbell_ptr;
Ben Gozed8aab42014-07-17 00:18:51 +0300286 uint32_t doorbell_off;
287 bool is_interop;
288 bool is_active;
289 /* Not relevant for user mode queues in cp scheduling */
290 unsigned int vmid;
Ben Goz77669eb2015-01-03 22:12:31 +0200291 /* Relevant only for sdma queues*/
292 uint32_t sdma_engine_id;
293 uint32_t sdma_queue_id;
294 uint32_t sdma_vm_addr;
Ben Gozff3d04a2015-01-04 10:37:18 +0200295 /* Relevant only for VI */
296 uint64_t eop_ring_buffer_address;
297 uint32_t eop_ring_buffer_size;
298 uint64_t ctx_save_restore_area_address;
299 uint32_t ctx_save_restore_area_size;
Ben Gozed8aab42014-07-17 00:18:51 +0300300};
301
302/**
303 * struct queue
304 *
305 * @list: Queue linked list.
306 *
307 * @mqd: The queue MQD.
308 *
309 * @mqd_mem_obj: The MQD local gpu memory object.
310 *
311 * @gart_mqd_addr: The MQD gart mc address.
312 *
313 * @properties: The queue properties.
314 *
315 * @mec: Used only in no cp scheduling mode and identifies to micro engine id
316 * that the queue should be execute on.
317 *
318 * @pipe: Used only in no cp scheduling mode and identifies the queue's pipe id.
319 *
320 * @queue: Used only in no cp scheduliong mode and identifies the queue's slot.
321 *
322 * @process: The kfd process that created this queue.
323 *
324 * @device: The kfd device that created this queue.
325 *
326 * This structure represents user mode compute queues.
327 * It contains all the necessary data to handle such queues.
328 *
329 */
330
331struct queue {
332 struct list_head list;
333 void *mqd;
334 struct kfd_mem_obj *mqd_mem_obj;
335 uint64_t gart_mqd_addr;
336 struct queue_properties properties;
337
338 uint32_t mec;
339 uint32_t pipe;
340 uint32_t queue;
341
Ben Goz77669eb2015-01-03 22:12:31 +0200342 unsigned int sdma_id;
343
Ben Gozed8aab42014-07-17 00:18:51 +0300344 struct kfd_process *process;
345 struct kfd_dev *device;
346};
347
Ben Goz6e99df52014-07-17 00:36:17 +0300348/*
349 * Please read the kfd_mqd_manager.h description.
350 */
351enum KFD_MQD_TYPE {
Ben Goz85d258f2015-01-04 10:36:30 +0200352 KFD_MQD_TYPE_COMPUTE = 0, /* for no cp scheduling */
353 KFD_MQD_TYPE_HIQ, /* for hiq */
354 KFD_MQD_TYPE_CP, /* for cp queues and diq */
355 KFD_MQD_TYPE_SDMA, /* for sdma queues */
Ben Goz6e99df52014-07-17 00:36:17 +0300356 KFD_MQD_TYPE_MAX
357};
358
Ben Goz241f24f2014-07-17 00:55:28 +0300359struct scheduling_resources {
360 unsigned int vmid_mask;
361 enum kfd_queue_type type;
362 uint64_t queue_mask;
363 uint64_t gws_mask;
364 uint32_t oac_mask;
365 uint32_t gds_heap_base;
366 uint32_t gds_heap_size;
367};
368
369struct process_queue_manager {
370 /* data */
371 struct kfd_process *process;
372 unsigned int num_concurrent_processes;
373 struct list_head queues;
374 unsigned long *queue_slot_bitmap;
375};
376
377struct qcm_process_device {
378 /* The Device Queue Manager that owns this data */
379 struct device_queue_manager *dqm;
380 struct process_queue_manager *pqm;
Ben Goz241f24f2014-07-17 00:55:28 +0300381 /* Queues list */
382 struct list_head queues_list;
383 struct list_head priv_queue_list;
384
385 unsigned int queue_count;
386 unsigned int vmid;
387 bool is_debug;
388 /*
389 * All the memory management data should be here too
390 */
391 uint64_t gds_context_area;
392 uint32_t sh_mem_config;
393 uint32_t sh_mem_bases;
394 uint32_t sh_mem_ape1_base;
395 uint32_t sh_mem_ape1_limit;
396 uint32_t page_table_base;
397 uint32_t gds_size;
398 uint32_t num_gws;
399 uint32_t num_oac;
400};
401
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300402/* Data that is per-process-per device. */
403struct kfd_process_device {
404 /*
405 * List of all per-device data for a process.
406 * Starts from kfd_process.per_device_data.
407 */
408 struct list_head per_device_list;
409
410 /* The device that owns this data. */
411 struct kfd_dev *dev;
412
413
Ben Goz45102042014-07-17 01:04:10 +0300414 /* per-process-per device QCM data structure */
415 struct qcm_process_device qpd;
416
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300417 /*Apertures*/
418 uint64_t lds_base;
419 uint64_t lds_limit;
420 uint64_t gpuvm_base;
421 uint64_t gpuvm_limit;
422 uint64_t scratch_base;
423 uint64_t scratch_limit;
424
425 /* Is this process/pasid bound to this device? (amd_iommu_bind_pasid) */
426 bool bound;
427};
428
Alexey Skidanov52a5fdc2014-11-19 17:07:00 +0200429#define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd)
430
Oded Gabbay4a488a72014-07-16 21:08:55 +0300431/* Process data */
432struct kfd_process {
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300433 /*
434 * kfd_process are stored in an mm_struct*->kfd_process*
435 * hash table (kfd_processes in kfd_process.c)
436 */
437 struct hlist_node kfd_processes;
438
439 struct mm_struct *mm;
440
441 struct mutex mutex;
442
443 /*
444 * In any process, the thread that started main() is the lead
445 * thread and outlives the rest.
446 * It is here because amd_iommu_bind_pasid wants a task_struct.
447 */
448 struct task_struct *lead_thread;
449
450 /* We want to receive a notification when the mm_struct is destroyed */
451 struct mmu_notifier mmu_notifier;
452
453 /* Use for delayed freeing of kfd_process structure */
454 struct rcu_head rcu;
455
456 unsigned int pasid;
457
458 /*
459 * List of kfd_process_device structures,
460 * one for each device the process is using.
461 */
462 struct list_head per_device_data;
463
Ben Goz45102042014-07-17 01:04:10 +0300464 struct process_queue_manager pqm;
465
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300466 /* The process's queues. */
467 size_t queue_array_size;
468
469 /* Size is queue_array_size, up to MAX_PROCESS_QUEUES. */
470 struct kfd_queue **queues;
471
472 unsigned long allocated_queue_bitmap[DIV_ROUND_UP(KFD_MAX_NUM_OF_QUEUES_PER_PROCESS, BITS_PER_LONG)];
473
474 /*Is the user space process 32 bit?*/
475 bool is_32bit_user_mode;
Oded Gabbay4a488a72014-07-16 21:08:55 +0300476};
477
Oded Gabbay76baee62014-12-29 14:20:05 +0200478/**
479 * Ioctl function type.
480 *
481 * \param filep pointer to file structure.
482 * \param p amdkfd process pointer.
483 * \param data pointer to arg that was copied from user.
484 */
485typedef int amdkfd_ioctl_t(struct file *filep, struct kfd_process *p,
486 void *data);
487
488struct amdkfd_ioctl_desc {
489 unsigned int cmd;
490 int flags;
491 amdkfd_ioctl_t *func;
492 unsigned int cmd_drv;
493 const char *name;
494};
495
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300496void kfd_process_create_wq(void);
497void kfd_process_destroy_wq(void);
498struct kfd_process *kfd_create_process(const struct task_struct *);
499struct kfd_process *kfd_get_process(const struct task_struct *);
500
Ben Goz64c7f8c2014-07-17 01:27:00 +0300501struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev,
502 struct kfd_process *p);
Oded Gabbayb17f0682014-07-17 00:06:27 +0300503void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid);
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300504struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev,
Alexey Skidanov093c7d82014-11-18 14:00:04 +0200505 struct kfd_process *p);
506struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
507 struct kfd_process *p);
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300508
Alexey Skidanov775921e2014-07-17 01:49:36 +0300509/* Process device data iterator */
510struct kfd_process_device *kfd_get_first_process_device_data(struct kfd_process *p);
511struct kfd_process_device *kfd_get_next_process_device_data(struct kfd_process *p,
512 struct kfd_process_device *pdd);
513bool kfd_has_process_device_data(struct kfd_process *p);
514
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300515/* PASIDs */
516int kfd_pasid_init(void);
517void kfd_pasid_exit(void);
518bool kfd_set_pasid_limit(unsigned int new_limit);
519unsigned int kfd_get_pasid_limit(void);
520unsigned int kfd_pasid_alloc(void);
521void kfd_pasid_free(unsigned int pasid);
522
523/* Doorbells */
524void kfd_doorbell_init(struct kfd_dev *kfd);
525int kfd_doorbell_mmap(struct kfd_process *process, struct vm_area_struct *vma);
526u32 __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd,
527 unsigned int *doorbell_off);
528void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr);
529u32 read_kernel_doorbell(u32 __iomem *db);
530void write_kernel_doorbell(u32 __iomem *db, u32 value);
531unsigned int kfd_queue_id_to_doorbell(struct kfd_dev *kfd,
532 struct kfd_process *process,
533 unsigned int queue_id);
534
Oded Gabbay6e810902014-10-27 14:36:07 +0200535/* GTT Sub-Allocator */
536
537int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size,
538 struct kfd_mem_obj **mem_obj);
539
540int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj);
541
Oded Gabbay4a488a72014-07-16 21:08:55 +0300542extern struct device *kfd_device;
543
Evgeny Pinchuk5b5c4e42014-07-16 21:22:32 +0300544/* Topology */
545int kfd_topology_init(void);
546void kfd_topology_shutdown(void);
547int kfd_topology_add_device(struct kfd_dev *gpu);
548int kfd_topology_remove_device(struct kfd_dev *gpu);
549struct kfd_dev *kfd_device_by_id(uint32_t gpu_id);
550struct kfd_dev *kfd_device_by_pci_dev(const struct pci_dev *pdev);
551struct kfd_dev *kfd_topology_enum_kfd_devices(uint8_t idx);
552
Oded Gabbay4a488a72014-07-16 21:08:55 +0300553/* Interrupts */
Andrew Lewyckyb3f5e6b2014-07-17 01:37:30 +0300554void kgd2kfd_interrupt(struct kfd_dev *kfd, const void *ih_ring_entry);
Oded Gabbay4a488a72014-07-16 21:08:55 +0300555
556/* Power Management */
Andrew Lewyckyb3f5e6b2014-07-17 01:37:30 +0300557void kgd2kfd_suspend(struct kfd_dev *kfd);
558int kgd2kfd_resume(struct kfd_dev *kfd);
Oded Gabbay4a488a72014-07-16 21:08:55 +0300559
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300560/* amdkfd Apertures */
561int kfd_init_apertures(struct kfd_process *process);
562
Ben Gozed6e6a32014-07-17 00:45:35 +0300563/* Queue Context Management */
Ben Goz241f24f2014-07-17 00:55:28 +0300564inline uint32_t lower_32(uint64_t x);
565inline uint32_t upper_32(uint64_t x);
Ben Goz77669eb2015-01-03 22:12:31 +0200566struct cik_sdma_rlc_registers *get_sdma_mqd(void *mqd);
567inline uint32_t get_sdma_base_addr(struct cik_sdma_rlc_registers *m);
Ben Goz241f24f2014-07-17 00:55:28 +0300568
Ben Gozed6e6a32014-07-17 00:45:35 +0300569int init_queue(struct queue **q, struct queue_properties properties);
570void uninit_queue(struct queue *q);
Ben Goz45102042014-07-17 01:04:10 +0300571void print_queue_properties(struct queue_properties *q);
Ben Gozed6e6a32014-07-17 00:45:35 +0300572void print_queue(struct queue *q);
573
Ben Goz64c7f8c2014-07-17 01:27:00 +0300574struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type,
575 struct kfd_dev *dev);
Ben Goz4b8f5892015-01-04 11:24:25 +0200576struct mqd_manager *mqd_manager_init_cik(enum KFD_MQD_TYPE type,
577 struct kfd_dev *dev);
578struct mqd_manager *mqd_manager_init_vi(enum KFD_MQD_TYPE type,
579 struct kfd_dev *dev);
Ben Goz64c7f8c2014-07-17 01:27:00 +0300580struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev);
581void device_queue_manager_uninit(struct device_queue_manager *dqm);
Ben Goz241f24f2014-07-17 00:55:28 +0300582struct kernel_queue *kernel_queue_init(struct kfd_dev *dev,
583 enum kfd_queue_type type);
584void kernel_queue_uninit(struct kernel_queue *kq);
585
Ben Goz45102042014-07-17 01:04:10 +0300586/* Process Queue Manager */
587struct process_queue_node {
588 struct queue *q;
589 struct kernel_queue *kq;
590 struct list_head process_queue_list;
591};
592
593int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p);
594void pqm_uninit(struct process_queue_manager *pqm);
595int pqm_create_queue(struct process_queue_manager *pqm,
596 struct kfd_dev *dev,
597 struct file *f,
598 struct queue_properties *properties,
599 unsigned int flags,
600 enum kfd_queue_type type,
601 unsigned int *qid);
602int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid);
603int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
604 struct queue_properties *p);
605
Ben Gozed6e6a32014-07-17 00:45:35 +0300606/* Packet Manager */
607
Ben Goz241f24f2014-07-17 00:55:28 +0300608#define KFD_HIQ_TIMEOUT (500)
609
Ben Goz64c7f8c2014-07-17 01:27:00 +0300610#define KFD_FENCE_COMPLETED (100)
611#define KFD_FENCE_INIT (10)
Ben Goz241f24f2014-07-17 00:55:28 +0300612#define KFD_UNMAP_LATENCY (150)
613
Ben Gozed6e6a32014-07-17 00:45:35 +0300614struct packet_manager {
615 struct device_queue_manager *dqm;
616 struct kernel_queue *priv_queue;
617 struct mutex lock;
618 bool allocated;
619 struct kfd_mem_obj *ib_buffer_obj;
620};
621
Ben Goz64c7f8c2014-07-17 01:27:00 +0300622int pm_init(struct packet_manager *pm, struct device_queue_manager *dqm);
623void pm_uninit(struct packet_manager *pm);
624int pm_send_set_resources(struct packet_manager *pm,
625 struct scheduling_resources *res);
626int pm_send_runlist(struct packet_manager *pm, struct list_head *dqm_queues);
627int pm_send_query_status(struct packet_manager *pm, uint64_t fence_address,
628 uint32_t fence_value);
629
630int pm_send_unmap_queue(struct packet_manager *pm, enum kfd_queue_type type,
631 enum kfd_preempt_type_filter mode,
632 uint32_t filter_param, bool reset,
633 unsigned int sdma_engine);
634
Ben Goz241f24f2014-07-17 00:55:28 +0300635void pm_release_ib(struct packet_manager *pm);
636
Oded Gabbay19f6d2a2014-07-16 23:25:31 +0300637uint64_t kfd_get_number_elems(struct kfd_dev *kfd);
638phys_addr_t kfd_get_process_doorbells(struct kfd_dev *dev,
639 struct kfd_process *process);
640
Oded Gabbay4a488a72014-07-16 21:08:55 +0300641#endif