amdgpu_ctx.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2018 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 __AMDGPU_CTX_H__
  24. #define __AMDGPU_CTX_H__
  25. #include "amdgpu_ring.h"
  26. struct drm_device;
  27. struct drm_file;
  28. struct amdgpu_fpriv;
  29. struct amdgpu_ctx_ring {
  30. uint64_t sequence;
  31. struct dma_fence **fences;
  32. struct drm_sched_entity entity;
  33. };
  34. struct amdgpu_ctx {
  35. struct kref refcount;
  36. struct amdgpu_device *adev;
  37. unsigned reset_counter;
  38. unsigned reset_counter_query;
  39. uint32_t vram_lost_counter;
  40. spinlock_t ring_lock;
  41. struct dma_fence **fences;
  42. struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
  43. bool preamble_presented;
  44. enum drm_sched_priority init_priority;
  45. enum drm_sched_priority override_priority;
  46. struct mutex lock;
  47. atomic_t guilty;
  48. };
  49. struct amdgpu_ctx_mgr {
  50. struct amdgpu_device *adev;
  51. struct mutex lock;
  52. /* protected by lock */
  53. struct idr ctx_handles;
  54. };
  55. struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
  56. int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
  57. int amdgpu_ctx_get_ring(struct amdgpu_ctx *ctx,
  58. u32 hw_ip, u32 instance, u32 ring,
  59. struct amdgpu_ring **out_ring);
  60. int amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
  61. struct dma_fence *fence, uint64_t *seq);
  62. struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
  63. struct amdgpu_ring *ring, uint64_t seq);
  64. void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx,
  65. enum drm_sched_priority priority);
  66. int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
  67. struct drm_file *filp);
  68. int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx, unsigned ring_id);
  69. void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
  70. void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr);
  71. void amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr);
  72. void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
  73. #endif