kfd_priv.h 24 KB

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