kfd_kernel_queue.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_KERNEL_QUEUE_H_
  24. #define KFD_KERNEL_QUEUE_H_
  25. #include <linux/list.h>
  26. #include <linux/types.h>
  27. #include "kfd_priv.h"
  28. /**
  29. * struct kernel_queue_ops
  30. *
  31. * @initialize: Initialize a kernel queue, including allocations of GART memory
  32. * needed for the queue.
  33. *
  34. * @uninitialize: Uninitialize a kernel queue and free all its memory usages.
  35. *
  36. * @acquire_packet_buffer: Returns a pointer to the location in the kernel
  37. * queue ring buffer where the calling function can write its packet. It is
  38. * Guaranteed that there is enough space for that packet. It also updates the
  39. * pending write pointer to that location so subsequent calls to
  40. * acquire_packet_buffer will get a correct write pointer
  41. *
  42. * @submit_packet: Update the write pointer and doorbell of a kernel queue.
  43. *
  44. * @sync_with_hw: Wait until the write pointer and the read pointer of a kernel
  45. * queue are equal, which means the CP has read all the submitted packets.
  46. *
  47. * @rollback_packet: This routine is called if we failed to build an acquired
  48. * packet for some reason. It just overwrites the pending wptr with the current
  49. * one
  50. *
  51. */
  52. struct kernel_queue_ops {
  53. bool (*initialize)(struct kernel_queue *kq, struct kfd_dev *dev,
  54. enum kfd_queue_type type, unsigned int queue_size);
  55. void (*uninitialize)(struct kernel_queue *kq);
  56. int (*acquire_packet_buffer)(struct kernel_queue *kq,
  57. size_t packet_size_in_dwords,
  58. unsigned int **buffer_ptr);
  59. void (*submit_packet)(struct kernel_queue *kq);
  60. void (*rollback_packet)(struct kernel_queue *kq);
  61. };
  62. struct kernel_queue {
  63. struct kernel_queue_ops ops;
  64. struct kernel_queue_ops ops_asic_specific;
  65. /* data */
  66. struct kfd_dev *dev;
  67. struct mqd_manager *mqd;
  68. struct queue *queue;
  69. uint32_t pending_wptr;
  70. unsigned int nop_packet;
  71. struct kfd_mem_obj *rptr_mem;
  72. uint32_t *rptr_kernel;
  73. uint64_t rptr_gpu_addr;
  74. struct kfd_mem_obj *wptr_mem;
  75. uint32_t *wptr_kernel;
  76. uint64_t wptr_gpu_addr;
  77. struct kfd_mem_obj *pq;
  78. uint64_t pq_gpu_addr;
  79. uint32_t *pq_kernel_addr;
  80. struct kfd_mem_obj *eop_mem;
  81. uint64_t eop_gpu_addr;
  82. uint32_t *eop_kernel_addr;
  83. struct kfd_mem_obj *fence_mem_obj;
  84. uint64_t fence_gpu_addr;
  85. void *fence_kernel_address;
  86. struct list_head list;
  87. };
  88. void kernel_queue_init_cik(struct kernel_queue_ops *ops);
  89. void kernel_queue_init_vi(struct kernel_queue_ops *ops);
  90. #endif /* KFD_KERNEL_QUEUE_H_ */