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 | |
Evgeny Pinchuk | 5b5c4e4 | 2014-07-16 21:22:32 +0300 | [diff] [blame] | 36 | #define KFD_SYSFS_FILE_MODE 0444 |
| 37 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 38 | /* |
| 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 Pinchuk | 5b5c4e4 | 2014-07-16 21:22:32 +0300 | [diff] [blame] | 48 | /* 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 Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 55 | #define KFD_MAX_NUM_OF_PROCESSES 512 |
Oded Gabbay | b8cbab0 | 2015-01-18 13:18:01 +0200 | [diff] [blame] | 56 | #define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024 |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 57 | |
| 58 | /* |
Oded Gabbay | b8cbab0 | 2015-01-18 13:18:01 +0200 | [diff] [blame] | 59 | * Kernel module parameter to specify maximum number of supported queues per |
| 60 | * device |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 61 | */ |
Oded Gabbay | b8cbab0 | 2015-01-18 13:18:01 +0200 | [diff] [blame] | 62 | extern int max_num_of_queues_per_device; |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 63 | |
Oded Gabbay | b8cbab0 | 2015-01-18 13:18:01 +0200 | [diff] [blame] | 64 | #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 Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 68 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 69 | #define KFD_KERNEL_QUEUE_SIZE 2048 |
| 70 | |
Ben Goz | 31c21fe | 2014-07-17 00:48:28 +0300 | [diff] [blame] | 71 | /* Kernel module parameter to specify the scheduling policy */ |
| 72 | extern 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 | */ |
| 95 | enum 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 Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 101 | enum cache_policy { |
| 102 | cache_policy_coherent, |
| 103 | cache_policy_noncoherent |
| 104 | }; |
| 105 | |
Ben Goz | 0da7558 | 2015-01-01 17:10:01 +0200 | [diff] [blame] | 106 | enum asic_family_type { |
| 107 | CHIP_KAVERI = 0, |
| 108 | CHIP_CARRIZO |
| 109 | }; |
| 110 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 111 | struct kfd_device_info { |
Ben Goz | 0da7558 | 2015-01-01 17:10:01 +0200 | [diff] [blame] | 112 | unsigned int asic_family; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 113 | unsigned int max_pasid_bits; |
| 114 | size_t ih_ring_entry_size; |
Alexey Skidanov | f7c826a | 2014-10-13 16:35:12 +0300 | [diff] [blame] | 115 | uint8_t num_of_watch_points; |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 116 | uint16_t mqd_size_aligned; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 117 | }; |
| 118 | |
Oded Gabbay | 36b5c08 | 2014-10-26 09:53:10 +0200 | [diff] [blame] | 119 | struct 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 Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 126 | struct 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 Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 134 | 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 Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 149 | struct kgd2kfd_shared_resources shared_resources; |
| 150 | |
Xihan Zhang | cea405b | 2015-03-17 19:32:53 +0800 | [diff] [blame] | 151 | const struct kfd2kgd_calls *kfd2kgd; |
| 152 | struct mutex doorbell_mutex; |
| 153 | unsigned long doorbell_available_index[DIV_ROUND_UP( |
| 154 | KFD_MAX_NUM_OF_QUEUES_PER_PROCESS, BITS_PER_LONG)]; |
| 155 | |
Oded Gabbay | 36b5c08 | 2014-10-26 09:53:10 +0200 | [diff] [blame] | 156 | void *gtt_mem; |
| 157 | uint64_t gtt_start_gpu_addr; |
| 158 | void *gtt_start_cpu_ptr; |
| 159 | void *gtt_sa_bitmap; |
| 160 | struct mutex gtt_sa_lock; |
| 161 | unsigned int gtt_sa_chunk_size; |
| 162 | unsigned int gtt_sa_num_of_chunks; |
| 163 | |
Andrew Lewycky | 2249d55 | 2014-07-17 01:37:30 +0300 | [diff] [blame^] | 164 | /* Interrupts */ |
| 165 | void *interrupt_ring; |
| 166 | size_t interrupt_ring_size; |
| 167 | atomic_t interrupt_ring_rptr; |
| 168 | atomic_t interrupt_ring_wptr; |
| 169 | struct work_struct interrupt_work; |
| 170 | spinlock_t interrupt_lock; |
| 171 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 172 | /* QCM Device instance */ |
| 173 | struct device_queue_manager *dqm; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 174 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 175 | bool init_complete; |
Andrew Lewycky | 2249d55 | 2014-07-17 01:37:30 +0300 | [diff] [blame^] | 176 | /* |
| 177 | * Interrupts of interest to KFD are copied |
| 178 | * from the HW ring into a SW ring. |
| 179 | */ |
| 180 | bool interrupts_active; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | /* KGD2KFD callbacks */ |
| 184 | void kgd2kfd_exit(void); |
Xihan Zhang | cea405b | 2015-03-17 19:32:53 +0800 | [diff] [blame] | 185 | struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, |
| 186 | struct pci_dev *pdev, const struct kfd2kgd_calls *f2g); |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 187 | bool kgd2kfd_device_init(struct kfd_dev *kfd, |
Xihan Zhang | cea405b | 2015-03-17 19:32:53 +0800 | [diff] [blame] | 188 | const struct kgd2kfd_shared_resources *gpu_resources); |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 189 | void kgd2kfd_device_exit(struct kfd_dev *kfd); |
| 190 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 191 | enum kfd_mempool { |
| 192 | KFD_MEMPOOL_SYSTEM_CACHEABLE = 1, |
| 193 | KFD_MEMPOOL_SYSTEM_WRITECOMBINE = 2, |
| 194 | KFD_MEMPOOL_FRAMEBUFFER = 3, |
| 195 | }; |
| 196 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 197 | /* Character device interface */ |
| 198 | int kfd_chardev_init(void); |
| 199 | void kfd_chardev_exit(void); |
| 200 | struct device *kfd_chardev(void); |
| 201 | |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 202 | /** |
| 203 | * enum kfd_preempt_type_filter |
| 204 | * |
| 205 | * @KFD_PREEMPT_TYPE_FILTER_SINGLE_QUEUE: Preempts single queue. |
| 206 | * |
| 207 | * @KFD_PRERMPT_TYPE_FILTER_ALL_QUEUES: Preempts all queues in the |
| 208 | * running queues list. |
| 209 | * |
| 210 | * @KFD_PRERMPT_TYPE_FILTER_BY_PASID: Preempts queues that belongs to |
| 211 | * specific process. |
| 212 | * |
| 213 | */ |
| 214 | enum kfd_preempt_type_filter { |
| 215 | KFD_PREEMPT_TYPE_FILTER_SINGLE_QUEUE, |
| 216 | KFD_PREEMPT_TYPE_FILTER_ALL_QUEUES, |
| 217 | KFD_PREEMPT_TYPE_FILTER_BY_PASID |
| 218 | }; |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 219 | |
Ben Goz | 6e99df5 | 2014-07-17 00:36:17 +0300 | [diff] [blame] | 220 | enum kfd_preempt_type { |
| 221 | KFD_PREEMPT_TYPE_WAVEFRONT, |
| 222 | KFD_PREEMPT_TYPE_WAVEFRONT_RESET |
| 223 | }; |
| 224 | |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 225 | /** |
| 226 | * enum kfd_queue_type |
| 227 | * |
| 228 | * @KFD_QUEUE_TYPE_COMPUTE: Regular user mode queue type. |
| 229 | * |
| 230 | * @KFD_QUEUE_TYPE_SDMA: Sdma user mode queue type. |
| 231 | * |
| 232 | * @KFD_QUEUE_TYPE_HIQ: HIQ queue type. |
| 233 | * |
| 234 | * @KFD_QUEUE_TYPE_DIQ: DIQ queue type. |
| 235 | */ |
| 236 | enum kfd_queue_type { |
| 237 | KFD_QUEUE_TYPE_COMPUTE, |
| 238 | KFD_QUEUE_TYPE_SDMA, |
| 239 | KFD_QUEUE_TYPE_HIQ, |
| 240 | KFD_QUEUE_TYPE_DIQ |
| 241 | }; |
| 242 | |
Ben Goz | 6e99df5 | 2014-07-17 00:36:17 +0300 | [diff] [blame] | 243 | enum kfd_queue_format { |
| 244 | KFD_QUEUE_FORMAT_PM4, |
| 245 | KFD_QUEUE_FORMAT_AQL |
| 246 | }; |
| 247 | |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 248 | /** |
| 249 | * struct queue_properties |
| 250 | * |
| 251 | * @type: The queue type. |
| 252 | * |
| 253 | * @queue_id: Queue identifier. |
| 254 | * |
| 255 | * @queue_address: Queue ring buffer address. |
| 256 | * |
| 257 | * @queue_size: Queue ring buffer size. |
| 258 | * |
| 259 | * @priority: Defines the queue priority relative to other queues in the |
| 260 | * process. |
| 261 | * This is just an indication and HW scheduling may override the priority as |
| 262 | * necessary while keeping the relative prioritization. |
| 263 | * the priority granularity is from 0 to f which f is the highest priority. |
| 264 | * currently all queues are initialized with the highest priority. |
| 265 | * |
| 266 | * @queue_percent: This field is partially implemented and currently a zero in |
| 267 | * this field defines that the queue is non active. |
| 268 | * |
| 269 | * @read_ptr: User space address which points to the number of dwords the |
| 270 | * cp read from the ring buffer. This field updates automatically by the H/W. |
| 271 | * |
| 272 | * @write_ptr: Defines the number of dwords written to the ring buffer. |
| 273 | * |
| 274 | * @doorbell_ptr: This field aim is to notify the H/W of new packet written to |
| 275 | * the queue ring buffer. This field should be similar to write_ptr and the user |
| 276 | * should update this field after he updated the write_ptr. |
| 277 | * |
| 278 | * @doorbell_off: The doorbell offset in the doorbell pci-bar. |
| 279 | * |
| 280 | * @is_interop: Defines if this is a interop queue. Interop queue means that the |
| 281 | * queue can access both graphics and compute resources. |
| 282 | * |
| 283 | * @is_active: Defines if the queue is active or not. |
| 284 | * |
| 285 | * @vmid: If the scheduling mode is no cp scheduling the field defines the vmid |
| 286 | * of the queue. |
| 287 | * |
| 288 | * This structure represents the queue properties for each queue no matter if |
| 289 | * it's user mode or kernel mode queue. |
| 290 | * |
| 291 | */ |
| 292 | struct queue_properties { |
| 293 | enum kfd_queue_type type; |
Ben Goz | 6e99df5 | 2014-07-17 00:36:17 +0300 | [diff] [blame] | 294 | enum kfd_queue_format format; |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 295 | unsigned int queue_id; |
| 296 | uint64_t queue_address; |
| 297 | uint64_t queue_size; |
| 298 | uint32_t priority; |
| 299 | uint32_t queue_percent; |
| 300 | uint32_t *read_ptr; |
| 301 | uint32_t *write_ptr; |
Oded Gabbay | 5cd78de | 2014-11-20 16:14:56 +0200 | [diff] [blame] | 302 | uint32_t __iomem *doorbell_ptr; |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 303 | uint32_t doorbell_off; |
| 304 | bool is_interop; |
| 305 | bool is_active; |
| 306 | /* Not relevant for user mode queues in cp scheduling */ |
| 307 | unsigned int vmid; |
Ben Goz | 77669eb | 2015-01-03 22:12:31 +0200 | [diff] [blame] | 308 | /* Relevant only for sdma queues*/ |
| 309 | uint32_t sdma_engine_id; |
| 310 | uint32_t sdma_queue_id; |
| 311 | uint32_t sdma_vm_addr; |
Ben Goz | ff3d04a | 2015-01-04 10:37:18 +0200 | [diff] [blame] | 312 | /* Relevant only for VI */ |
| 313 | uint64_t eop_ring_buffer_address; |
| 314 | uint32_t eop_ring_buffer_size; |
| 315 | uint64_t ctx_save_restore_area_address; |
| 316 | uint32_t ctx_save_restore_area_size; |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | /** |
| 320 | * struct queue |
| 321 | * |
| 322 | * @list: Queue linked list. |
| 323 | * |
| 324 | * @mqd: The queue MQD. |
| 325 | * |
| 326 | * @mqd_mem_obj: The MQD local gpu memory object. |
| 327 | * |
| 328 | * @gart_mqd_addr: The MQD gart mc address. |
| 329 | * |
| 330 | * @properties: The queue properties. |
| 331 | * |
| 332 | * @mec: Used only in no cp scheduling mode and identifies to micro engine id |
| 333 | * that the queue should be execute on. |
| 334 | * |
| 335 | * @pipe: Used only in no cp scheduling mode and identifies the queue's pipe id. |
| 336 | * |
| 337 | * @queue: Used only in no cp scheduliong mode and identifies the queue's slot. |
| 338 | * |
| 339 | * @process: The kfd process that created this queue. |
| 340 | * |
| 341 | * @device: The kfd device that created this queue. |
| 342 | * |
| 343 | * This structure represents user mode compute queues. |
| 344 | * It contains all the necessary data to handle such queues. |
| 345 | * |
| 346 | */ |
| 347 | |
| 348 | struct queue { |
| 349 | struct list_head list; |
| 350 | void *mqd; |
| 351 | struct kfd_mem_obj *mqd_mem_obj; |
| 352 | uint64_t gart_mqd_addr; |
| 353 | struct queue_properties properties; |
| 354 | |
| 355 | uint32_t mec; |
| 356 | uint32_t pipe; |
| 357 | uint32_t queue; |
| 358 | |
Ben Goz | 77669eb | 2015-01-03 22:12:31 +0200 | [diff] [blame] | 359 | unsigned int sdma_id; |
| 360 | |
Ben Goz | ed8aab4 | 2014-07-17 00:18:51 +0300 | [diff] [blame] | 361 | struct kfd_process *process; |
| 362 | struct kfd_dev *device; |
| 363 | }; |
| 364 | |
Ben Goz | 6e99df5 | 2014-07-17 00:36:17 +0300 | [diff] [blame] | 365 | /* |
| 366 | * Please read the kfd_mqd_manager.h description. |
| 367 | */ |
| 368 | enum KFD_MQD_TYPE { |
Ben Goz | 85d258f | 2015-01-04 10:36:30 +0200 | [diff] [blame] | 369 | KFD_MQD_TYPE_COMPUTE = 0, /* for no cp scheduling */ |
| 370 | KFD_MQD_TYPE_HIQ, /* for hiq */ |
| 371 | KFD_MQD_TYPE_CP, /* for cp queues and diq */ |
| 372 | KFD_MQD_TYPE_SDMA, /* for sdma queues */ |
Ben Goz | 6e99df5 | 2014-07-17 00:36:17 +0300 | [diff] [blame] | 373 | KFD_MQD_TYPE_MAX |
| 374 | }; |
| 375 | |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 376 | struct scheduling_resources { |
| 377 | unsigned int vmid_mask; |
| 378 | enum kfd_queue_type type; |
| 379 | uint64_t queue_mask; |
| 380 | uint64_t gws_mask; |
| 381 | uint32_t oac_mask; |
| 382 | uint32_t gds_heap_base; |
| 383 | uint32_t gds_heap_size; |
| 384 | }; |
| 385 | |
| 386 | struct process_queue_manager { |
| 387 | /* data */ |
| 388 | struct kfd_process *process; |
| 389 | unsigned int num_concurrent_processes; |
| 390 | struct list_head queues; |
| 391 | unsigned long *queue_slot_bitmap; |
| 392 | }; |
| 393 | |
| 394 | struct qcm_process_device { |
| 395 | /* The Device Queue Manager that owns this data */ |
| 396 | struct device_queue_manager *dqm; |
| 397 | struct process_queue_manager *pqm; |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 398 | /* Queues list */ |
| 399 | struct list_head queues_list; |
| 400 | struct list_head priv_queue_list; |
| 401 | |
| 402 | unsigned int queue_count; |
| 403 | unsigned int vmid; |
| 404 | bool is_debug; |
| 405 | /* |
| 406 | * All the memory management data should be here too |
| 407 | */ |
| 408 | uint64_t gds_context_area; |
| 409 | uint32_t sh_mem_config; |
| 410 | uint32_t sh_mem_bases; |
| 411 | uint32_t sh_mem_ape1_base; |
| 412 | uint32_t sh_mem_ape1_limit; |
| 413 | uint32_t page_table_base; |
| 414 | uint32_t gds_size; |
| 415 | uint32_t num_gws; |
| 416 | uint32_t num_oac; |
| 417 | }; |
| 418 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 419 | /* Data that is per-process-per device. */ |
| 420 | struct kfd_process_device { |
| 421 | /* |
| 422 | * List of all per-device data for a process. |
| 423 | * Starts from kfd_process.per_device_data. |
| 424 | */ |
| 425 | struct list_head per_device_list; |
| 426 | |
| 427 | /* The device that owns this data. */ |
| 428 | struct kfd_dev *dev; |
| 429 | |
| 430 | |
Ben Goz | 4510204 | 2014-07-17 01:04:10 +0300 | [diff] [blame] | 431 | /* per-process-per device QCM data structure */ |
| 432 | struct qcm_process_device qpd; |
| 433 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 434 | /*Apertures*/ |
| 435 | uint64_t lds_base; |
| 436 | uint64_t lds_limit; |
| 437 | uint64_t gpuvm_base; |
| 438 | uint64_t gpuvm_limit; |
| 439 | uint64_t scratch_base; |
| 440 | uint64_t scratch_limit; |
| 441 | |
| 442 | /* Is this process/pasid bound to this device? (amd_iommu_bind_pasid) */ |
| 443 | bool bound; |
| 444 | }; |
| 445 | |
Alexey Skidanov | 52a5fdc | 2014-11-19 17:07:00 +0200 | [diff] [blame] | 446 | #define qpd_to_pdd(x) container_of(x, struct kfd_process_device, qpd) |
| 447 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 448 | /* Process data */ |
| 449 | struct kfd_process { |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 450 | /* |
| 451 | * kfd_process are stored in an mm_struct*->kfd_process* |
| 452 | * hash table (kfd_processes in kfd_process.c) |
| 453 | */ |
| 454 | struct hlist_node kfd_processes; |
| 455 | |
| 456 | struct mm_struct *mm; |
| 457 | |
| 458 | struct mutex mutex; |
| 459 | |
| 460 | /* |
| 461 | * In any process, the thread that started main() is the lead |
| 462 | * thread and outlives the rest. |
| 463 | * It is here because amd_iommu_bind_pasid wants a task_struct. |
| 464 | */ |
| 465 | struct task_struct *lead_thread; |
| 466 | |
| 467 | /* We want to receive a notification when the mm_struct is destroyed */ |
| 468 | struct mmu_notifier mmu_notifier; |
| 469 | |
| 470 | /* Use for delayed freeing of kfd_process structure */ |
| 471 | struct rcu_head rcu; |
| 472 | |
| 473 | unsigned int pasid; |
| 474 | |
| 475 | /* |
| 476 | * List of kfd_process_device structures, |
| 477 | * one for each device the process is using. |
| 478 | */ |
| 479 | struct list_head per_device_data; |
| 480 | |
Ben Goz | 4510204 | 2014-07-17 01:04:10 +0300 | [diff] [blame] | 481 | struct process_queue_manager pqm; |
| 482 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 483 | /* The process's queues. */ |
| 484 | size_t queue_array_size; |
| 485 | |
| 486 | /* Size is queue_array_size, up to MAX_PROCESS_QUEUES. */ |
| 487 | struct kfd_queue **queues; |
| 488 | |
| 489 | unsigned long allocated_queue_bitmap[DIV_ROUND_UP(KFD_MAX_NUM_OF_QUEUES_PER_PROCESS, BITS_PER_LONG)]; |
| 490 | |
| 491 | /*Is the user space process 32 bit?*/ |
| 492 | bool is_32bit_user_mode; |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 493 | }; |
| 494 | |
Oded Gabbay | 76baee6 | 2014-12-29 14:20:05 +0200 | [diff] [blame] | 495 | /** |
| 496 | * Ioctl function type. |
| 497 | * |
| 498 | * \param filep pointer to file structure. |
| 499 | * \param p amdkfd process pointer. |
| 500 | * \param data pointer to arg that was copied from user. |
| 501 | */ |
| 502 | typedef int amdkfd_ioctl_t(struct file *filep, struct kfd_process *p, |
| 503 | void *data); |
| 504 | |
| 505 | struct amdkfd_ioctl_desc { |
| 506 | unsigned int cmd; |
| 507 | int flags; |
| 508 | amdkfd_ioctl_t *func; |
| 509 | unsigned int cmd_drv; |
| 510 | const char *name; |
| 511 | }; |
| 512 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 513 | void kfd_process_create_wq(void); |
| 514 | void kfd_process_destroy_wq(void); |
| 515 | struct kfd_process *kfd_create_process(const struct task_struct *); |
| 516 | struct kfd_process *kfd_get_process(const struct task_struct *); |
| 517 | |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 518 | struct kfd_process_device *kfd_bind_process_to_device(struct kfd_dev *dev, |
| 519 | struct kfd_process *p); |
Oded Gabbay | b17f068 | 2014-07-17 00:06:27 +0300 | [diff] [blame] | 520 | void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid); |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 521 | 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] | 522 | struct kfd_process *p); |
| 523 | struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev, |
| 524 | struct kfd_process *p); |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 525 | |
Alexey Skidanov | 775921e | 2014-07-17 01:49:36 +0300 | [diff] [blame] | 526 | /* Process device data iterator */ |
| 527 | struct kfd_process_device *kfd_get_first_process_device_data(struct kfd_process *p); |
| 528 | struct kfd_process_device *kfd_get_next_process_device_data(struct kfd_process *p, |
| 529 | struct kfd_process_device *pdd); |
| 530 | bool kfd_has_process_device_data(struct kfd_process *p); |
| 531 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 532 | /* PASIDs */ |
| 533 | int kfd_pasid_init(void); |
| 534 | void kfd_pasid_exit(void); |
| 535 | bool kfd_set_pasid_limit(unsigned int new_limit); |
| 536 | unsigned int kfd_get_pasid_limit(void); |
| 537 | unsigned int kfd_pasid_alloc(void); |
| 538 | void kfd_pasid_free(unsigned int pasid); |
| 539 | |
| 540 | /* Doorbells */ |
| 541 | void kfd_doorbell_init(struct kfd_dev *kfd); |
| 542 | int kfd_doorbell_mmap(struct kfd_process *process, struct vm_area_struct *vma); |
| 543 | u32 __iomem *kfd_get_kernel_doorbell(struct kfd_dev *kfd, |
| 544 | unsigned int *doorbell_off); |
| 545 | void kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr); |
| 546 | u32 read_kernel_doorbell(u32 __iomem *db); |
| 547 | void write_kernel_doorbell(u32 __iomem *db, u32 value); |
| 548 | unsigned int kfd_queue_id_to_doorbell(struct kfd_dev *kfd, |
| 549 | struct kfd_process *process, |
| 550 | unsigned int queue_id); |
| 551 | |
Oded Gabbay | 6e81090 | 2014-10-27 14:36:07 +0200 | [diff] [blame] | 552 | /* GTT Sub-Allocator */ |
| 553 | |
| 554 | int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size, |
| 555 | struct kfd_mem_obj **mem_obj); |
| 556 | |
| 557 | int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj); |
| 558 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 559 | extern struct device *kfd_device; |
| 560 | |
Evgeny Pinchuk | 5b5c4e4 | 2014-07-16 21:22:32 +0300 | [diff] [blame] | 561 | /* Topology */ |
| 562 | int kfd_topology_init(void); |
| 563 | void kfd_topology_shutdown(void); |
| 564 | int kfd_topology_add_device(struct kfd_dev *gpu); |
| 565 | int kfd_topology_remove_device(struct kfd_dev *gpu); |
| 566 | struct kfd_dev *kfd_device_by_id(uint32_t gpu_id); |
| 567 | struct kfd_dev *kfd_device_by_pci_dev(const struct pci_dev *pdev); |
| 568 | struct kfd_dev *kfd_topology_enum_kfd_devices(uint8_t idx); |
| 569 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 570 | /* Interrupts */ |
Andrew Lewycky | 2249d55 | 2014-07-17 01:37:30 +0300 | [diff] [blame^] | 571 | int kfd_interrupt_init(struct kfd_dev *dev); |
| 572 | void kfd_interrupt_exit(struct kfd_dev *dev); |
Andrew Lewycky | b3f5e6b | 2014-07-17 01:37:30 +0300 | [diff] [blame] | 573 | void kgd2kfd_interrupt(struct kfd_dev *kfd, const void *ih_ring_entry); |
Andrew Lewycky | 2249d55 | 2014-07-17 01:37:30 +0300 | [diff] [blame^] | 574 | bool enqueue_ih_ring_entry(struct kfd_dev *kfd, const void *ih_ring_entry); |
| 575 | 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] | 576 | |
| 577 | /* Power Management */ |
Andrew Lewycky | b3f5e6b | 2014-07-17 01:37:30 +0300 | [diff] [blame] | 578 | void kgd2kfd_suspend(struct kfd_dev *kfd); |
| 579 | int kgd2kfd_resume(struct kfd_dev *kfd); |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 580 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 581 | /* amdkfd Apertures */ |
| 582 | int kfd_init_apertures(struct kfd_process *process); |
| 583 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 584 | /* Queue Context Management */ |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 585 | inline uint32_t lower_32(uint64_t x); |
| 586 | inline uint32_t upper_32(uint64_t x); |
Ben Goz | 77669eb | 2015-01-03 22:12:31 +0200 | [diff] [blame] | 587 | struct cik_sdma_rlc_registers *get_sdma_mqd(void *mqd); |
| 588 | inline uint32_t get_sdma_base_addr(struct cik_sdma_rlc_registers *m); |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 589 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 590 | int init_queue(struct queue **q, struct queue_properties properties); |
| 591 | void uninit_queue(struct queue *q); |
Ben Goz | 4510204 | 2014-07-17 01:04:10 +0300 | [diff] [blame] | 592 | void print_queue_properties(struct queue_properties *q); |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 593 | void print_queue(struct queue *q); |
| 594 | |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 595 | struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type, |
| 596 | struct kfd_dev *dev); |
Ben Goz | 4b8f589 | 2015-01-04 11:24:25 +0200 | [diff] [blame] | 597 | struct mqd_manager *mqd_manager_init_cik(enum KFD_MQD_TYPE type, |
| 598 | struct kfd_dev *dev); |
| 599 | struct mqd_manager *mqd_manager_init_vi(enum KFD_MQD_TYPE type, |
| 600 | struct kfd_dev *dev); |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 601 | struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev); |
| 602 | void device_queue_manager_uninit(struct device_queue_manager *dqm); |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 603 | struct kernel_queue *kernel_queue_init(struct kfd_dev *dev, |
| 604 | enum kfd_queue_type type); |
| 605 | void kernel_queue_uninit(struct kernel_queue *kq); |
| 606 | |
Ben Goz | 4510204 | 2014-07-17 01:04:10 +0300 | [diff] [blame] | 607 | /* Process Queue Manager */ |
| 608 | struct process_queue_node { |
| 609 | struct queue *q; |
| 610 | struct kernel_queue *kq; |
| 611 | struct list_head process_queue_list; |
| 612 | }; |
| 613 | |
| 614 | int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p); |
| 615 | void pqm_uninit(struct process_queue_manager *pqm); |
| 616 | int pqm_create_queue(struct process_queue_manager *pqm, |
| 617 | struct kfd_dev *dev, |
| 618 | struct file *f, |
| 619 | struct queue_properties *properties, |
| 620 | unsigned int flags, |
| 621 | enum kfd_queue_type type, |
| 622 | unsigned int *qid); |
| 623 | int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid); |
| 624 | int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid, |
| 625 | struct queue_properties *p); |
| 626 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 627 | /* Packet Manager */ |
| 628 | |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 629 | #define KFD_HIQ_TIMEOUT (500) |
| 630 | |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 631 | #define KFD_FENCE_COMPLETED (100) |
| 632 | #define KFD_FENCE_INIT (10) |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 633 | #define KFD_UNMAP_LATENCY (150) |
| 634 | |
Ben Goz | ed6e6a3 | 2014-07-17 00:45:35 +0300 | [diff] [blame] | 635 | struct packet_manager { |
| 636 | struct device_queue_manager *dqm; |
| 637 | struct kernel_queue *priv_queue; |
| 638 | struct mutex lock; |
| 639 | bool allocated; |
| 640 | struct kfd_mem_obj *ib_buffer_obj; |
| 641 | }; |
| 642 | |
Ben Goz | 64c7f8c | 2014-07-17 01:27:00 +0300 | [diff] [blame] | 643 | int pm_init(struct packet_manager *pm, struct device_queue_manager *dqm); |
| 644 | void pm_uninit(struct packet_manager *pm); |
| 645 | int pm_send_set_resources(struct packet_manager *pm, |
| 646 | struct scheduling_resources *res); |
| 647 | int pm_send_runlist(struct packet_manager *pm, struct list_head *dqm_queues); |
| 648 | int pm_send_query_status(struct packet_manager *pm, uint64_t fence_address, |
| 649 | uint32_t fence_value); |
| 650 | |
| 651 | int pm_send_unmap_queue(struct packet_manager *pm, enum kfd_queue_type type, |
| 652 | enum kfd_preempt_type_filter mode, |
| 653 | uint32_t filter_param, bool reset, |
| 654 | unsigned int sdma_engine); |
| 655 | |
Ben Goz | 241f24f | 2014-07-17 00:55:28 +0300 | [diff] [blame] | 656 | void pm_release_ib(struct packet_manager *pm); |
| 657 | |
Oded Gabbay | 19f6d2a | 2014-07-16 23:25:31 +0300 | [diff] [blame] | 658 | uint64_t kfd_get_number_elems(struct kfd_dev *kfd); |
| 659 | phys_addr_t kfd_get_process_doorbells(struct kfd_dev *dev, |
| 660 | struct kfd_process *process); |
| 661 | |
Oded Gabbay | 4a488a7 | 2014-07-16 21:08:55 +0300 | [diff] [blame] | 662 | #endif |