Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 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 | #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 Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 33 | #include <linux/kfd_ioctl.h> |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 34 | #include <kgd_kfd_interface.h> |
| 35 | |
Yong Zhao | e596b90 | 2017-09-20 18:10:19 -0400 | [diff] [blame] | 36 | #include "amd_shared.h" |
| 37 | |
Evgeny Pinchuk | 5b5c4e4 | 2014-07-16 21:22:32 +0300 | [diff] [blame] | 38 | #define KFD_SYSFS_FILE_MODE 0444 |
| 39 | |
Andrew Lewycky | f3a3981 | 2015-05-10 12:15:46 +0300 | [diff] [blame] | 40 | #define KFD_MMAP_DOORBELL_MASK 0x8000000000000 |
| 41 | #define KFD_MMAP_EVENTS_MASK 0x4000000000000 |
| 42 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 43 | /* |
| 44 | * When working with cp scheduler we should assign the HIQ manually or via |
| 45 | * the radeon driver to a fixed hqd slot, here are the fixed HIQ hqd slot |
| 46 | * definitions for Kaveri. In Kaveri only the first ME queues participates |
| 47 | * in the cp scheduling taking that in mind we set the HIQ slot in the |
| 48 | * second ME. |
| 49 | */ |
| 50 | #define KFD_CIK_HIQ_PIPE 4 |
| 51 | #define KFD_CIK_HIQ_QUEUE 0 |
| 52 | |
Evgeny Pinchuk | 5b5c4e4 | 2014-07-16 21:22:32 +0300 | [diff] [blame] | 53 | /* GPU ID hash width in bits */ |
| 54 | #define KFD_GPU_ID_HASH_WIDTH 16 |
| 55 | |
| 56 | /* Macro for allocating structures */ |
| 57 | #define kfd_alloc_struct(ptr_to_struct) \ |
| 58 | ((typeof(ptr_to_struct)) kzalloc(sizeof(*ptr_to_struct), GFP_KERNEL)) |
| 59 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 60 | #define KFD_MAX_NUM_OF_PROCESSES 512 |
Oded Gabbay | b8cbab0 | 2015-01-18 13:18:01 +0200 | [diff] [blame] | 61 | #define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024 |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 62 | |
| 63 | /* |
Oded Gabbay | b8cbab0 | 2015-01-18 13:18:01 +0200 | [diff] [blame] | 64 | * Kernel module parameter to specify maximum number of supported queues per |
| 65 | * device |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 66 | */ |
Oded Gabbay | b8cbab0 | 2015-01-18 13:18:01 +0200 | [diff] [blame] | 67 | extern int max_num_of_queues_per_device; |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 68 | |
Oded Gabbay | b8cbab0 | 2015-01-18 13:18:01 +0200 | [diff] [blame] | 69 | #define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT 4096 |
| 70 | #define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE \ |
| 71 | (KFD_MAX_NUM_OF_PROCESSES * \ |
| 72 | KFD_MAX_NUM_OF_QUEUES_PER_PROCESS) |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 73 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 74 | #define KFD_KERNEL_QUEUE_SIZE 2048 |
| 75 | |
Ben Goz | 31c21fe | 2014-07-17 00:48:28 +0300 | [diff] [blame] | 76 | /* Kernel module parameter to specify the scheduling policy */ |
| 77 | extern int sched_policy; |
| 78 | |
Oded Gabbay | 8166301 | 2014-12-24 13:30:52 +0200 | [diff] [blame] | 79 | /* |
| 80 | * Kernel module parameter to specify whether to send sigterm to HSA process on |
| 81 | * unhandled exception |
| 82 | */ |
| 83 | extern int send_sigterm; |
| 84 | |
Ben Goz | 31c21fe | 2014-07-17 00:48:28 +0300 | [diff] [blame] | 85 | /** |
| 86 | * enum kfd_sched_policy |
| 87 | * |
| 88 | * @KFD_SCHED_POLICY_HWS: H/W scheduling policy known as command processor (cp) |
| 89 | * scheduling. In this scheduling mode we're using the firmware code to |
| 90 | * schedule the user mode queues and kernel queues such as HIQ and DIQ. |
| 91 | * the HIQ queue is used as a special queue that dispatches the configuration |
| 92 | * to the cp and the user mode queues list that are currently running. |
| 93 | * the DIQ queue is a debugging queue that dispatches debugging commands to the |
| 94 | * firmware. |
| 95 | * in this scheduling mode user mode queues over subscription feature is |
| 96 | * enabled. |
| 97 | * |
| 98 | * @KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION: The same as above but the over |
| 99 | * subscription feature disabled. |
| 100 | * |
| 101 | * @KFD_SCHED_POLICY_NO_HWS: no H/W scheduling policy is a mode which directly |
| 102 | * set the command processor registers and sets the queues "manually". This |
| 103 | * mode is used *ONLY* for debugging proposes. |
| 104 | * |
| 105 | */ |
| 106 | enum kfd_sched_policy { |
| 107 | KFD_SCHED_POLICY_HWS = 0, |
| 108 | KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION, |
| 109 | KFD_SCHED_POLICY_NO_HWS |
| 110 | }; |
| 111 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 112 | enum cache_policy { |
| 113 | cache_policy_coherent, |
| 114 | cache_policy_noncoherent |
| 115 | }; |
| 116 | |
Andrew Lewycky | f3a3981 | 2015-05-10 12:15:46 +0300 | [diff] [blame] | 117 | struct kfd_event_interrupt_class { |
| 118 | bool (*interrupt_isr)(struct kfd_dev *dev, |
| 119 | const uint32_t *ih_ring_entry); |
| 120 | void (*interrupt_wq)(struct kfd_dev *dev, |
| 121 | const uint32_t *ih_ring_entry); |
| 122 | }; |
| 123 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 124 | struct kfd_device_info { |
Yong Zhao | e596b90 | 2017-09-20 18:10:19 -0400 | [diff] [blame] | 125 | enum amd_asic_type asic_family; |
Andrew Lewycky | f3a3981 | 2015-05-10 12:15:46 +0300 | [diff] [blame] | 126 | const struct kfd_event_interrupt_class *event_interrupt_class; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 127 | unsigned int max_pasid_bits; |
Yair Shachar | 992839a | 2015-05-20 13:43:04 +0300 | [diff] [blame] | 128 | unsigned int max_no_of_hqd; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 129 | size_t ih_ring_entry_size; |
Alexey Skidanov | f7c826a | 2014-10-13 16:35:12 +0300 | [diff] [blame] | 130 | uint8_t num_of_watch_points; |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 131 | uint16_t mqd_size_aligned; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 132 | }; |
| 133 | |
Oded Gabbay | 36b5c08 | 2014-10-26 09:53:10 +0200 | [diff] [blame] | 134 | struct kfd_mem_obj { |
| 135 | uint32_t range_start; |
| 136 | uint32_t range_end; |
| 137 | uint64_t gpu_addr; |
| 138 | uint32_t *cpu_ptr; |
| 139 | }; |
| 140 | |
Yong Zhao | 44008d7 | 2017-09-20 18:10:18 -0400 | [diff] [blame] | 141 | struct kfd_vmid_info { |
| 142 | uint32_t first_vmid_kfd; |
| 143 | uint32_t last_vmid_kfd; |
| 144 | uint32_t vmid_num_kfd; |
| 145 | }; |
| 146 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 147 | struct kfd_dev { |
| 148 | struct kgd_dev *kgd; |
| 149 | |
| 150 | const struct kfd_device_info *device_info; |
| 151 | struct pci_dev *pdev; |
| 152 | |
| 153 | unsigned int id; /* topology stub index */ |
| 154 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 155 | phys_addr_t doorbell_base; /* Start of actual doorbells used by |
| 156 | * KFD. It is aligned for mapping |
| 157 | * into user mode |
| 158 | */ |
| 159 | size_t doorbell_id_offset; /* Doorbell offset (from KFD doorbell |
| 160 | * to HW doorbell, GFX reserved some |
| 161 | * at the start) |
| 162 | */ |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 163 | u32 __iomem *doorbell_kernel_ptr; /* This is a pointer for a doorbells |
| 164 | * page used by kernel queue |
| 165 | */ |
| 166 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 167 | struct kgd2kfd_shared_resources shared_resources; |
Yong Zhao | 44008d7 | 2017-09-20 18:10:18 -0400 | [diff] [blame] | 168 | struct kfd_vmid_info vm_info; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 169 | |
Xihan Zhang | cea405b | 2015-03-17 19:32:53 +0800 | [diff] [blame] | 170 | const struct kfd2kgd_calls *kfd2kgd; |
| 171 | struct mutex doorbell_mutex; |
Joe Perches | f761d8b | 2015-05-19 18:37:51 -0700 | [diff] [blame] | 172 | DECLARE_BITMAP(doorbell_available_index, |
| 173 | KFD_MAX_NUM_OF_QUEUES_PER_PROCESS); |
Xihan Zhang | cea405b | 2015-03-17 19:32:53 +0800 | [diff] [blame] | 174 | |
Oded Gabbay | 36b5c08 | 2014-10-26 09:53:10 +0200 | [diff] [blame] | 175 | void *gtt_mem; |
| 176 | uint64_t gtt_start_gpu_addr; |
| 177 | void *gtt_start_cpu_ptr; |
| 178 | void *gtt_sa_bitmap; |
| 179 | struct mutex gtt_sa_lock; |
| 180 | unsigned int gtt_sa_chunk_size; |
| 181 | unsigned int gtt_sa_num_of_chunks; |
| 182 | |
Andrew Lewycky | 2249d55 | 2014-07-17 01:37:30 +0300 | [diff] [blame] | 183 | /* Interrupts */ |
| 184 | void *interrupt_ring; |
| 185 | size_t interrupt_ring_size; |
| 186 | atomic_t interrupt_ring_rptr; |
| 187 | atomic_t interrupt_ring_wptr; |
| 188 | struct work_struct interrupt_work; |
| 189 | spinlock_t interrupt_lock; |
| 190 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 191 | /* QCM Device instance */ |
| 192 | struct device_queue_manager *dqm; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 193 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 194 | bool init_complete; |
Andrew Lewycky | 2249d55 | 2014-07-17 01:37:30 +0300 | [diff] [blame] | 195 | /* |
| 196 | * Interrupts of interest to KFD are copied |
| 197 | * from the HW ring into a SW ring. |
| 198 | */ |
| 199 | bool interrupts_active; |
Yair Shachar | fbeb661 | 2015-05-20 13:48:26 +0300 | [diff] [blame] | 200 | |
| 201 | /* Debug manager */ |
| 202 | struct kfd_dbgmgr *dbgmgr; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | /* KGD2KFD callbacks */ |
| 206 | void kgd2kfd_exit(void); |
Xihan Zhang | cea405b | 2015-03-17 19:32:53 +0800 | [diff] [blame] | 207 | struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, |
| 208 | struct pci_dev *pdev, const struct kfd2kgd_calls *f2g); |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 209 | bool kgd2kfd_device_init(struct kfd_dev *kfd, |
Xihan Zhang | cea405b | 2015-03-17 19:32:53 +0800 | [diff] [blame] | 210 | const struct kgd2kfd_shared_resources *gpu_resources); |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 211 | void kgd2kfd_device_exit(struct kfd_dev *kfd); |
| 212 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 213 | enum kfd_mempool { |
| 214 | KFD_MEMPOOL_SYSTEM_CACHEABLE = 1, |
| 215 | KFD_MEMPOOL_SYSTEM_WRITECOMBINE = 2, |
| 216 | KFD_MEMPOOL_FRAMEBUFFER = 3, |
| 217 | }; |
| 218 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 219 | /* Character device interface */ |
| 220 | int kfd_chardev_init(void); |
| 221 | void kfd_chardev_exit(void); |
| 222 | struct device *kfd_chardev(void); |
| 223 | |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 224 | /** |
Yong Zhao | 7da2bcf | 2017-09-27 00:09:48 -0400 | [diff] [blame] | 225 | * enum kfd_unmap_queues_filter |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 226 | * |
Yong Zhao | 7da2bcf | 2017-09-27 00:09:48 -0400 | [diff] [blame] | 227 | * @KFD_UNMAP_QUEUES_FILTER_SINGLE_QUEUE: Preempts single queue. |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 228 | * |
Yong Zhao | 7da2bcf | 2017-09-27 00:09:48 -0400 | [diff] [blame] | 229 | * @KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES: Preempts all queues in the |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 230 | * running queues list. |
| 231 | * |
Yong Zhao | 7da2bcf | 2017-09-27 00:09:48 -0400 | [diff] [blame] | 232 | * @KFD_UNMAP_QUEUES_FILTER_BY_PASID: Preempts queues that belongs to |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 233 | * specific process. |
| 234 | * |
| 235 | */ |
Yong Zhao | 7da2bcf | 2017-09-27 00:09:48 -0400 | [diff] [blame] | 236 | enum kfd_unmap_queues_filter { |
| 237 | KFD_UNMAP_QUEUES_FILTER_SINGLE_QUEUE, |
| 238 | KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES, |
| 239 | KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, |
| 240 | KFD_UNMAP_QUEUES_FILTER_BY_PASID |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 241 | }; |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 242 | |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 243 | /** |
| 244 | * enum kfd_queue_type |
| 245 | * |
| 246 | * @KFD_QUEUE_TYPE_COMPUTE: Regular user mode queue type. |
| 247 | * |
| 248 | * @KFD_QUEUE_TYPE_SDMA: Sdma user mode queue type. |
| 249 | * |
| 250 | * @KFD_QUEUE_TYPE_HIQ: HIQ queue type. |
| 251 | * |
| 252 | * @KFD_QUEUE_TYPE_DIQ: DIQ queue type. |
| 253 | */ |
| 254 | enum kfd_queue_type { |
| 255 | KFD_QUEUE_TYPE_COMPUTE, |
| 256 | KFD_QUEUE_TYPE_SDMA, |
| 257 | KFD_QUEUE_TYPE_HIQ, |
| 258 | KFD_QUEUE_TYPE_DIQ |
| 259 | }; |
| 260 | |
Ben Goz | 6e99df5 | 2014-07-17 00:36:17 +0300 | [diff] [blame] | 261 | enum kfd_queue_format { |
| 262 | KFD_QUEUE_FORMAT_PM4, |
| 263 | KFD_QUEUE_FORMAT_AQL |
| 264 | }; |
| 265 | |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 266 | /** |
| 267 | * struct queue_properties |
| 268 | * |
| 269 | * @type: The queue type. |
| 270 | * |
| 271 | * @queue_id: Queue identifier. |
| 272 | * |
| 273 | * @queue_address: Queue ring buffer address. |
| 274 | * |
| 275 | * @queue_size: Queue ring buffer size. |
| 276 | * |
| 277 | * @priority: Defines the queue priority relative to other queues in the |
| 278 | * process. |
| 279 | * This is just an indication and HW scheduling may override the priority as |
| 280 | * necessary while keeping the relative prioritization. |
| 281 | * the priority granularity is from 0 to f which f is the highest priority. |
| 282 | * currently all queues are initialized with the highest priority. |
| 283 | * |
| 284 | * @queue_percent: This field is partially implemented and currently a zero in |
| 285 | * this field defines that the queue is non active. |
| 286 | * |
| 287 | * @read_ptr: User space address which points to the number of dwords the |
| 288 | * cp read from the ring buffer. This field updates automatically by the H/W. |
| 289 | * |
| 290 | * @write_ptr: Defines the number of dwords written to the ring buffer. |
| 291 | * |
| 292 | * @doorbell_ptr: This field aim is to notify the H/W of new packet written to |
Kent Russell | 8eabaf5 | 2017-08-15 23:00:04 -0400 | [diff] [blame] | 293 | * the queue ring buffer. This field should be similar to write_ptr and the |
| 294 | * user should update this field after he updated the write_ptr. |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 295 | * |
| 296 | * @doorbell_off: The doorbell offset in the doorbell pci-bar. |
| 297 | * |
Kent Russell | 8eabaf5 | 2017-08-15 23:00:04 -0400 | [diff] [blame] | 298 | * @is_interop: Defines if this is a interop queue. Interop queue means that |
| 299 | * the queue can access both graphics and compute resources. |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 300 | * |
| 301 | * @is_active: Defines if the queue is active or not. |
| 302 | * |
| 303 | * @vmid: If the scheduling mode is no cp scheduling the field defines the vmid |
| 304 | * of the queue. |
| 305 | * |
| 306 | * This structure represents the queue properties for each queue no matter if |
| 307 | * it's user mode or kernel mode queue. |
| 308 | * |
| 309 | */ |
| 310 | struct queue_properties { |
| 311 | enum kfd_queue_type type; |
Ben Goz | 6e99df5 | 2014-07-17 00:36:17 +0300 | [diff] [blame] | 312 | enum kfd_queue_format format; |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 313 | unsigned int queue_id; |
| 314 | uint64_t queue_address; |
| 315 | uint64_t queue_size; |
| 316 | uint32_t priority; |
| 317 | uint32_t queue_percent; |
| 318 | uint32_t *read_ptr; |
| 319 | uint32_t *write_ptr; |
Oded Gabbay | 5cd78de | 2014-11-20 16:14:56 +0200 | [diff] [blame] | 320 | uint32_t __iomem *doorbell_ptr; |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 321 | uint32_t doorbell_off; |
| 322 | bool is_interop; |
| 323 | bool is_active; |
| 324 | /* Not relevant for user mode queues in cp scheduling */ |
| 325 | unsigned int vmid; |
Ben Goz | 77669eb | 2015-01-03 22:12:31 +0200 | [diff] [blame] | 326 | /* Relevant only for sdma queues*/ |
| 327 | uint32_t sdma_engine_id; |
| 328 | uint32_t sdma_queue_id; |
| 329 | uint32_t sdma_vm_addr; |
Ben Goz | ff3d04a | 2015-01-04 10:37:18 +0200 | [diff] [blame] | 330 | /* Relevant only for VI */ |
| 331 | uint64_t eop_ring_buffer_address; |
| 332 | uint32_t eop_ring_buffer_size; |
| 333 | uint64_t ctx_save_restore_area_address; |
| 334 | uint32_t ctx_save_restore_area_size; |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 335 | }; |
| 336 | |
| 337 | /** |
| 338 | * struct queue |
| 339 | * |
| 340 | * @list: Queue linked list. |
| 341 | * |
| 342 | * @mqd: The queue MQD. |
| 343 | * |
| 344 | * @mqd_mem_obj: The MQD local gpu memory object. |
| 345 | * |
| 346 | * @gart_mqd_addr: The MQD gart mc address. |
| 347 | * |
| 348 | * @properties: The queue properties. |
| 349 | * |
| 350 | * @mec: Used only in no cp scheduling mode and identifies to micro engine id |
Kent Russell | 8eabaf5 | 2017-08-15 23:00:04 -0400 | [diff] [blame] | 351 | * that the queue should be execute on. |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 352 | * |
Kent Russell | 8eabaf5 | 2017-08-15 23:00:04 -0400 | [diff] [blame] | 353 | * @pipe: Used only in no cp scheduling mode and identifies the queue's pipe |
| 354 | * id. |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 355 | * |
| 356 | * @queue: Used only in no cp scheduliong mode and identifies the queue's slot. |
| 357 | * |
| 358 | * @process: The kfd process that created this queue. |
| 359 | * |
| 360 | * @device: The kfd device that created this queue. |
| 361 | * |
| 362 | * This structure represents user mode compute queues. |
| 363 | * It contains all the necessary data to handle such queues. |
| 364 | * |
| 365 | */ |
| 366 | |
| 367 | struct queue { |
| 368 | struct list_head list; |
| 369 | void *mqd; |
| 370 | struct kfd_mem_obj *mqd_mem_obj; |
| 371 | uint64_t gart_mqd_addr; |
| 372 | struct queue_properties properties; |
| 373 | |
| 374 | uint32_t mec; |
| 375 | uint32_t pipe; |
| 376 | uint32_t queue; |
| 377 | |
Ben Goz | 77669eb | 2015-01-03 22:12:31 +0200 | [diff] [blame] | 378 | unsigned int sdma_id; |
| 379 | |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 380 | struct kfd_process *process; |
| 381 | struct kfd_dev *device; |
| 382 | }; |
| 383 | |
Ben Goz | 6e99df5 | 2014-07-17 00:36:17 +0300 | [diff] [blame] | 384 | /* |
| 385 | * Please read the kfd_mqd_manager.h description. |
| 386 | */ |
| 387 | enum KFD_MQD_TYPE { |
Ben Goz | 85d258f | 2015-01-04 10:36:30 +0200 | [diff] [blame] | 388 | KFD_MQD_TYPE_COMPUTE = 0, /* for no cp scheduling */ |
| 389 | KFD_MQD_TYPE_HIQ, /* for hiq */ |
| 390 | KFD_MQD_TYPE_CP, /* for cp queues and diq */ |
| 391 | KFD_MQD_TYPE_SDMA, /* for sdma queues */ |
Ben Goz | 6e99df5 | 2014-07-17 00:36:17 +0300 | [diff] [blame] | 392 | KFD_MQD_TYPE_MAX |
| 393 | }; |
| 394 | |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 395 | struct scheduling_resources { |
| 396 | unsigned int vmid_mask; |
| 397 | enum kfd_queue_type type; |
| 398 | uint64_t queue_mask; |
| 399 | uint64_t gws_mask; |
| 400 | uint32_t oac_mask; |
| 401 | uint32_t gds_heap_base; |
| 402 | uint32_t gds_heap_size; |
| 403 | }; |
| 404 | |
| 405 | struct process_queue_manager { |
| 406 | /* data */ |
| 407 | struct kfd_process *process; |
| 408 | unsigned int num_concurrent_processes; |
| 409 | struct list_head queues; |
| 410 | unsigned long *queue_slot_bitmap; |
| 411 | }; |
| 412 | |
| 413 | struct qcm_process_device { |
| 414 | /* The Device Queue Manager that owns this data */ |
| 415 | struct device_queue_manager *dqm; |
| 416 | struct process_queue_manager *pqm; |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 417 | /* Queues list */ |
| 418 | struct list_head queues_list; |
| 419 | struct list_head priv_queue_list; |
| 420 | |
| 421 | unsigned int queue_count; |
| 422 | unsigned int vmid; |
| 423 | bool is_debug; |
Felix Kuehling | 9fd3f1bf | 2017-09-27 00:09:52 -0400 | [diff] [blame^] | 424 | |
| 425 | /* This flag tells if we should reset all wavefronts on |
| 426 | * process termination |
| 427 | */ |
| 428 | bool reset_wavefronts; |
| 429 | |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 430 | /* |
| 431 | * All the memory management data should be here too |
| 432 | */ |
| 433 | uint64_t gds_context_area; |
| 434 | uint32_t sh_mem_config; |
| 435 | uint32_t sh_mem_bases; |
| 436 | uint32_t sh_mem_ape1_base; |
| 437 | uint32_t sh_mem_ape1_limit; |
| 438 | uint32_t page_table_base; |
| 439 | uint32_t gds_size; |
| 440 | uint32_t num_gws; |
| 441 | uint32_t num_oac; |
Moses Reuben | 6a1c951 | 2017-08-15 23:00:20 -0400 | [diff] [blame] | 442 | uint32_t sh_hidden_private_base; |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 443 | }; |
| 444 | |
Yong Zhao | 733fa1f | 2017-09-20 18:10:14 -0400 | [diff] [blame] | 445 | |
| 446 | enum kfd_pdd_bound { |
| 447 | PDD_UNBOUND = 0, |
| 448 | PDD_BOUND, |
| 449 | PDD_BOUND_SUSPENDED, |
| 450 | }; |
| 451 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 452 | /* Data that is per-process-per device. */ |
| 453 | struct kfd_process_device { |
| 454 | /* |
| 455 | * List of all per-device data for a process. |
| 456 | * Starts from kfd_process.per_device_data. |
| 457 | */ |
| 458 | struct list_head per_device_list; |
| 459 | |
| 460 | /* The device that owns this data. */ |
| 461 | struct kfd_dev *dev; |
| 462 | |
Felix Kuehling | 9fd3f1bf | 2017-09-27 00:09:52 -0400 | [diff] [blame^] | 463 | /* The process that owns this kfd_process_device. */ |
| 464 | struct kfd_process *process; |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 465 | |
Ben Goz | 4510204 | 2014-07-17 01:04:10 +0300 | [diff] [blame] | 466 | /* per-process-per device QCM data structure */ |
| 467 | struct qcm_process_device qpd; |
| 468 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 469 | /*Apertures*/ |
| 470 | uint64_t lds_base; |
| 471 | uint64_t lds_limit; |
| 472 | uint64_t gpuvm_base; |
| 473 | uint64_t gpuvm_limit; |
| 474 | uint64_t scratch_base; |
| 475 | uint64_t scratch_limit; |
| 476 | |
| 477 | /* Is this process/pasid bound to this device? (amd_iommu_bind_pasid) */ |
Yong Zhao | 733fa1f | 2017-09-20 18:10:14 -0400 | [diff] [blame] | 478 | enum kfd_pdd_bound bound; |
Ben Goz | a82918f | 2015-03-25 13:12:20 +0200 | [diff] [blame] | 479 | |
Felix Kuehling | 9fd3f1bf | 2017-09-27 00:09:52 -0400 | [diff] [blame^] | 480 | /* Flag used to tell the pdd has dequeued from the dqm. |
| 481 | * This is used to prevent dev->dqm->ops.process_termination() from |
| 482 | * being called twice when it is already called in IOMMU callback |
| 483 | * function. |
Ben Goz | a82918f | 2015-03-25 13:12:20 +0200 | [diff] [blame] | 484 | */ |
Felix Kuehling | 9fd3f1bf | 2017-09-27 00:09:52 -0400 | [diff] [blame^] | 485 | bool already_dequeued; |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 486 | }; |
| 487 | |
Alexey Skidanov | 52a5fdc | 2014-11-19 17:07:00 +0200 | [diff] [blame] | 488 | #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd) |
| 489 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 490 | /* Process data */ |
| 491 | struct kfd_process { |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 492 | /* |
| 493 | * kfd_process are stored in an mm_struct*->kfd_process* |
| 494 | * hash table (kfd_processes in kfd_process.c) |
| 495 | */ |
| 496 | struct hlist_node kfd_processes; |
| 497 | |
| 498 | struct mm_struct *mm; |
| 499 | |
| 500 | struct mutex mutex; |
| 501 | |
| 502 | /* |
| 503 | * In any process, the thread that started main() is the lead |
| 504 | * thread and outlives the rest. |
| 505 | * It is here because amd_iommu_bind_pasid wants a task_struct. |
| 506 | */ |
| 507 | struct task_struct *lead_thread; |
| 508 | |
| 509 | /* We want to receive a notification when the mm_struct is destroyed */ |
| 510 | struct mmu_notifier mmu_notifier; |
| 511 | |
| 512 | /* Use for delayed freeing of kfd_process structure */ |
| 513 | struct rcu_head rcu; |
| 514 | |
| 515 | unsigned int pasid; |
Felix Kuehling | a91e70e | 2017-08-26 02:00:57 -0400 | [diff] [blame] | 516 | unsigned int doorbell_index; |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 517 | |
| 518 | /* |
| 519 | * List of kfd_process_device structures, |
| 520 | * one for each device the process is using. |
| 521 | */ |
| 522 | struct list_head per_device_data; |
| 523 | |
Ben Goz | 4510204 | 2014-07-17 01:04:10 +0300 | [diff] [blame] | 524 | struct process_queue_manager pqm; |
| 525 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 526 | /* The process's queues. */ |
| 527 | size_t queue_array_size; |
| 528 | |
| 529 | /* Size is queue_array_size, up to MAX_PROCESS_QUEUES. */ |
| 530 | struct kfd_queue **queues; |
| 531 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 532 | /*Is the user space process 32 bit?*/ |
| 533 | bool is_32bit_user_mode; |
Andrew Lewycky | f3a3981 | 2015-05-10 12:15:46 +0300 | [diff] [blame] | 534 | |
| 535 | /* Event-related data */ |
| 536 | struct mutex event_mutex; |
| 537 | /* All events in process hashed by ID, linked on kfd_event.events. */ |
| 538 | DECLARE_HASHTABLE(events, 4); |
Kent Russell | 8eabaf5 | 2017-08-15 23:00:04 -0400 | [diff] [blame] | 539 | /* struct slot_page_header.event_pages */ |
| 540 | struct list_head signal_event_pages; |
Andrew Lewycky | f3a3981 | 2015-05-10 12:15:46 +0300 | [diff] [blame] | 541 | u32 next_nonsignal_event_id; |
| 542 | size_t signal_event_count; |
Felix Kuehling | c986169 | 2017-09-20 18:10:22 -0400 | [diff] [blame] | 543 | bool signal_event_limit_reached; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 544 | }; |
| 545 | |
Oded Gabbay | 76baee6 | 2014-12-29 14:20:05 +0200 | [diff] [blame] | 546 | /** |
| 547 | * Ioctl function type. |
| 548 | * |
| 549 | * \param filep pointer to file structure. |
| 550 | * \param p amdkfd process pointer. |
| 551 | * \param data pointer to arg that was copied from user. |
| 552 | */ |
| 553 | typedef int amdkfd_ioctl_t(struct file *filep, struct kfd_process *p, |
| 554 | void *data); |
| 555 | |
| 556 | struct amdkfd_ioctl_desc { |
| 557 | unsigned int cmd; |
| 558 | int flags; |
| 559 | amdkfd_ioctl_t *func; |
| 560 | unsigned int cmd_drv; |
| 561 | const char *name; |
| 562 | }; |
| 563 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 564 | void kfd_process_create_wq(void); |
| 565 | void kfd_process_destroy_wq(void); |
| 566 | struct kfd_process *kfd_create_process(const struct task_struct *); |
| 567 | struct kfd_process *kfd_get_process(const struct task_struct *); |
Andrew Lewycky | f3a3981 | 2015-05-10 12:15:46 +0300 | [diff] [blame] | 568 | struct kfd_process *kfd_lookup_process_by_pasid(unsigned int pasid); |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 569 | |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 570 | struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev, |
Yong Zhao | 733fa1f | 2017-09-20 18:10:14 -0400 | [diff] [blame] | 571 | struct kfd_process *p); |
| 572 | int kfd_bind_processes_to_device(struct kfd_dev *dev); |
| 573 | void kfd_unbind_processes_from_device(struct kfd_dev *dev); |
| 574 | void kfd_process_iommu_unbind_callback(struct kfd_dev *dev, unsigned int pasid); |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 575 | struct kfd_process_device *kfd_get_process_device_data(struct kfd_dev *dev, |
Alexey Skidanov | 093c7d8 | 2014-11-18 14:00:04 +0200 | [diff] [blame] | 576 | struct kfd_process *p); |
| 577 | struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev, |
| 578 | struct kfd_process *p); |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 579 | |
Alexey Skidanov | 775921e | 2014-07-17 01:49:36 +0300 | [diff] [blame] | 580 | /* Process device data iterator */ |
Kent Russell | 8eabaf5 | 2017-08-15 23:00:04 -0400 | [diff] [blame] | 581 | struct kfd_process_device *kfd_get_first_process_device_data( |
| 582 | struct kfd_process *p); |
| 583 | struct kfd_process_device *kfd_get_next_process_device_data( |
| 584 | struct kfd_process *p, |
Alexey Skidanov | 775921e | 2014-07-17 01:49:36 +0300 | [diff] [blame] | 585 | struct kfd_process_device *pdd); |
| 586 | bool kfd_has_process_device_data(struct kfd_process *p); |
| 587 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 588 | /* PASIDs */ |
| 589 | int kfd_pasid_init(void); |
| 590 | void kfd_pasid_exit(void); |
| 591 | bool kfd_set_pasid_limit(unsigned int new_limit); |
| 592 | unsigned int kfd_get_pasid_limit(void); |
| 593 | unsigned int kfd_pasid_alloc(void); |
| 594 | void kfd_pasid_free(unsigned int pasid); |
| 595 | |
| 596 | /* Doorbells */ |
Felix Kuehling | 735df2b | 2017-08-15 23:00:10 -0400 | [diff] [blame] | 597 | int kfd_doorbell_init(struct kfd_dev *kfd); |
| 598 | void kfd_doorbell_fini(struct kfd_dev *kfd); |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 599 | int kfd_doorbell_mmap(struct kfd_process *process, struct vm_area_struct *vma); |
| 600 | u32 __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd, |
| 601 | unsigned int *doorbell_off); |
| 602 | void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr); |
| 603 | u32 read_kernel_doorbell(u32 __iomem *db); |
| 604 | void write_kernel_doorbell(u32 __iomem *db, u32 value); |
| 605 | unsigned int kfd_queue_id_to_doorbell(struct kfd_dev *kfd, |
| 606 | struct kfd_process *process, |
| 607 | unsigned int queue_id); |
Felix Kuehling | a91e70e | 2017-08-26 02:00:57 -0400 | [diff] [blame] | 608 | phys_addr_t kfd_get_process_doorbells(struct kfd_dev *dev, |
| 609 | struct kfd_process *process); |
| 610 | int kfd_alloc_process_doorbells(struct kfd_process *process); |
| 611 | void kfd_free_process_doorbells(struct kfd_process *process); |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 612 | |
Oded Gabbay | 6e81090 | 2014-10-27 14:36:07 +0200 | [diff] [blame] | 613 | /* GTT Sub-Allocator */ |
| 614 | |
| 615 | int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size, |
| 616 | struct kfd_mem_obj **mem_obj); |
| 617 | |
| 618 | int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj); |
| 619 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 620 | extern struct device *kfd_device; |
| 621 | |
Evgeny Pinchuk | 5b5c4e4 | 2014-07-16 21:22:32 +0300 | [diff] [blame] | 622 | /* Topology */ |
| 623 | int kfd_topology_init(void); |
| 624 | void kfd_topology_shutdown(void); |
| 625 | int kfd_topology_add_device(struct kfd_dev *gpu); |
| 626 | int kfd_topology_remove_device(struct kfd_dev *gpu); |
| 627 | struct kfd_dev *kfd_device_by_id(uint32_t gpu_id); |
| 628 | struct kfd_dev *kfd_device_by_pci_dev(const struct pci_dev *pdev); |
| 629 | struct kfd_dev *kfd_topology_enum_kfd_devices(uint8_t idx); |
| 630 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 631 | /* Interrupts */ |
Andrew Lewycky | 2249d55 | 2014-07-17 01:37:30 +0300 | [diff] [blame] | 632 | int kfd_interrupt_init(struct kfd_dev *dev); |
| 633 | void kfd_interrupt_exit(struct kfd_dev *dev); |
Andrew Lewycky | b3f5e6b | 2014-07-17 01:37:30 +0300 | [diff] [blame] | 634 | void kgd2kfd_interrupt(struct kfd_dev *kfd, const void *ih_ring_entry); |
Andrew Lewycky | 2249d55 | 2014-07-17 01:37:30 +0300 | [diff] [blame] | 635 | bool enqueue_ih_ring_entry(struct kfd_dev *kfd, const void *ih_ring_entry); |
| 636 | bool interrupt_is_wanted(struct kfd_dev *dev, const uint32_t *ih_ring_entry); |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 637 | |
| 638 | /* Power Management */ |
Andrew Lewycky | b3f5e6b | 2014-07-17 01:37:30 +0300 | [diff] [blame] | 639 | void kgd2kfd_suspend(struct kfd_dev *kfd); |
| 640 | int kgd2kfd_resume(struct kfd_dev *kfd); |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 641 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 642 | /* amdkfd Apertures */ |
| 643 | int kfd_init_apertures(struct kfd_process *process); |
| 644 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 645 | /* Queue Context Management */ |
Ben Goz | 77669eb | 2015-01-03 22:12:31 +0200 | [diff] [blame] | 646 | struct cik_sdma_rlc_registers *get_sdma_mqd(void *mqd); |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 647 | |
Edward O'Callaghan | e88a614 | 2016-09-17 15:01:45 +1000 | [diff] [blame] | 648 | int init_queue(struct queue **q, const struct queue_properties *properties); |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 649 | void uninit_queue(struct queue *q); |
Ben Goz | 4510204 | 2014-07-17 01:04:10 +0300 | [diff] [blame] | 650 | void print_queue_properties(struct queue_properties *q); |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 651 | void print_queue(struct queue *q); |
| 652 | |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 653 | struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type, |
| 654 | struct kfd_dev *dev); |
Ben Goz | 4b8f589 | 2015-01-04 11:24:25 +0200 | [diff] [blame] | 655 | struct mqd_manager *mqd_manager_init_cik(enum KFD_MQD_TYPE type, |
| 656 | struct kfd_dev *dev); |
| 657 | struct mqd_manager *mqd_manager_init_vi(enum KFD_MQD_TYPE type, |
| 658 | struct kfd_dev *dev); |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 659 | struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev); |
| 660 | void device_queue_manager_uninit(struct device_queue_manager *dqm); |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 661 | struct kernel_queue *kernel_queue_init(struct kfd_dev *dev, |
| 662 | enum kfd_queue_type type); |
| 663 | void kernel_queue_uninit(struct kernel_queue *kq); |
| 664 | |
Ben Goz | 4510204 | 2014-07-17 01:04:10 +0300 | [diff] [blame] | 665 | /* Process Queue Manager */ |
| 666 | struct process_queue_node { |
| 667 | struct queue *q; |
| 668 | struct kernel_queue *kq; |
| 669 | struct list_head process_queue_list; |
| 670 | }; |
| 671 | |
Felix Kuehling | 9fd3f1bf | 2017-09-27 00:09:52 -0400 | [diff] [blame^] | 672 | void kfd_process_dequeue_from_device(struct kfd_process_device *pdd); |
| 673 | void kfd_process_dequeue_from_all_devices(struct kfd_process *p); |
Ben Goz | 4510204 | 2014-07-17 01:04:10 +0300 | [diff] [blame] | 674 | int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p); |
| 675 | void pqm_uninit(struct process_queue_manager *pqm); |
| 676 | int pqm_create_queue(struct process_queue_manager *pqm, |
| 677 | struct kfd_dev *dev, |
| 678 | struct file *f, |
| 679 | struct queue_properties *properties, |
| 680 | unsigned int flags, |
| 681 | enum kfd_queue_type type, |
| 682 | unsigned int *qid); |
| 683 | int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid); |
| 684 | int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid, |
| 685 | struct queue_properties *p); |
Yair Shachar | fbeb661 | 2015-05-20 13:48:26 +0300 | [diff] [blame] | 686 | struct kernel_queue *pqm_get_kernel_queue(struct process_queue_manager *pqm, |
| 687 | unsigned int qid); |
Ben Goz | 4510204 | 2014-07-17 01:04:10 +0300 | [diff] [blame] | 688 | |
Yair Shachar | 788bf83 | 2015-05-20 13:58:12 +0300 | [diff] [blame] | 689 | int amdkfd_fence_wait_timeout(unsigned int *fence_addr, |
| 690 | unsigned int fence_value, |
Yong Zhao | 8c72c3d | 2017-09-20 18:10:15 -0400 | [diff] [blame] | 691 | unsigned int timeout_ms); |
Yair Shachar | 788bf83 | 2015-05-20 13:58:12 +0300 | [diff] [blame] | 692 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 693 | /* Packet Manager */ |
| 694 | |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 695 | #define KFD_FENCE_COMPLETED (100) |
| 696 | #define KFD_FENCE_INIT (10) |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 697 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 698 | struct packet_manager { |
| 699 | struct device_queue_manager *dqm; |
| 700 | struct kernel_queue *priv_queue; |
| 701 | struct mutex lock; |
| 702 | bool allocated; |
| 703 | struct kfd_mem_obj *ib_buffer_obj; |
| 704 | }; |
| 705 | |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 706 | int pm_init(struct packet_manager *pm, struct device_queue_manager *dqm); |
| 707 | void pm_uninit(struct packet_manager *pm); |
| 708 | int pm_send_set_resources(struct packet_manager *pm, |
| 709 | struct scheduling_resources *res); |
| 710 | int pm_send_runlist(struct packet_manager *pm, struct list_head *dqm_queues); |
| 711 | int pm_send_query_status(struct packet_manager *pm, uint64_t fence_address, |
| 712 | uint32_t fence_value); |
| 713 | |
| 714 | int pm_send_unmap_queue(struct packet_manager *pm, enum kfd_queue_type type, |
Yong Zhao | 7da2bcf | 2017-09-27 00:09:48 -0400 | [diff] [blame] | 715 | enum kfd_unmap_queues_filter mode, |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 716 | uint32_t filter_param, bool reset, |
| 717 | unsigned int sdma_engine); |
| 718 | |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 719 | void pm_release_ib(struct packet_manager *pm); |
| 720 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 721 | uint64_t kfd_get_number_elems(struct kfd_dev *kfd); |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 722 | |
Andrew Lewycky | f3a3981 | 2015-05-10 12:15:46 +0300 | [diff] [blame] | 723 | /* Events */ |
| 724 | extern const struct kfd_event_interrupt_class event_interrupt_class_cik; |
Alexey Skidanov | 930c5ff | 2014-11-25 10:34:31 +0200 | [diff] [blame] | 725 | extern const struct kfd_device_global_init_class device_global_init_class_cik; |
Andrew Lewycky | f3a3981 | 2015-05-10 12:15:46 +0300 | [diff] [blame] | 726 | |
| 727 | enum kfd_event_wait_result { |
| 728 | KFD_WAIT_COMPLETE, |
| 729 | KFD_WAIT_TIMEOUT, |
| 730 | KFD_WAIT_ERROR |
| 731 | }; |
| 732 | |
| 733 | void kfd_event_init_process(struct kfd_process *p); |
| 734 | void kfd_event_free_process(struct kfd_process *p); |
| 735 | int kfd_event_mmap(struct kfd_process *process, struct vm_area_struct *vma); |
| 736 | int kfd_wait_on_events(struct kfd_process *p, |
Alexey Skidanov | 59d3e8b | 2015-04-14 18:05:49 +0300 | [diff] [blame] | 737 | uint32_t num_events, void __user *data, |
Andrew Lewycky | f3a3981 | 2015-05-10 12:15:46 +0300 | [diff] [blame] | 738 | bool all, uint32_t user_timeout_ms, |
| 739 | enum kfd_event_wait_result *wait_result); |
| 740 | void kfd_signal_event_interrupt(unsigned int pasid, uint32_t partial_id, |
| 741 | uint32_t valid_id_bits); |
Alexey Skidanov | 59d3e8b | 2015-04-14 18:05:49 +0300 | [diff] [blame] | 742 | void kfd_signal_iommu_event(struct kfd_dev *dev, |
| 743 | unsigned int pasid, unsigned long address, |
| 744 | bool is_write_requested, bool is_execute_requested); |
Alexey Skidanov | 930c5ff | 2014-11-25 10:34:31 +0200 | [diff] [blame] | 745 | void kfd_signal_hw_exception_event(unsigned int pasid); |
Andrew Lewycky | f3a3981 | 2015-05-10 12:15:46 +0300 | [diff] [blame] | 746 | int kfd_set_event(struct kfd_process *p, uint32_t event_id); |
| 747 | int kfd_reset_event(struct kfd_process *p, uint32_t event_id); |
| 748 | int kfd_event_create(struct file *devkfd, struct kfd_process *p, |
| 749 | uint32_t event_type, bool auto_reset, uint32_t node_id, |
| 750 | uint32_t *event_id, uint32_t *event_trigger_data, |
| 751 | uint64_t *event_page_offset, uint32_t *event_slot_index); |
| 752 | int kfd_event_destroy(struct kfd_process *p, uint32_t event_id); |
| 753 | |
Ben Goz | c3447e8 | 2015-05-20 18:05:44 +0300 | [diff] [blame] | 754 | int dbgdev_wave_reset_wavefronts(struct kfd_dev *dev, struct kfd_process *p); |
| 755 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 756 | #endif |