kfd_priv.h 22 KB

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