msm_submitqueue.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Copyright (c) 2017 The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/kref.h>
  14. #include "msm_gpu.h"
  15. void msm_submitqueue_destroy(struct kref *kref)
  16. {
  17. struct msm_gpu_submitqueue *queue = container_of(kref,
  18. struct msm_gpu_submitqueue, ref);
  19. kfree(queue);
  20. }
  21. struct msm_gpu_submitqueue *msm_submitqueue_get(struct msm_file_private *ctx,
  22. u32 id)
  23. {
  24. struct msm_gpu_submitqueue *entry;
  25. if (!ctx)
  26. return NULL;
  27. read_lock(&ctx->queuelock);
  28. list_for_each_entry(entry, &ctx->submitqueues, node) {
  29. if (entry->id == id) {
  30. kref_get(&entry->ref);
  31. read_unlock(&ctx->queuelock);
  32. return entry;
  33. }
  34. }
  35. read_unlock(&ctx->queuelock);
  36. return NULL;
  37. }
  38. void msm_submitqueue_close(struct msm_file_private *ctx)
  39. {
  40. struct msm_gpu_submitqueue *entry, *tmp;
  41. if (!ctx)
  42. return;
  43. /*
  44. * No lock needed in close and there won't
  45. * be any more user ioctls coming our way
  46. */
  47. list_for_each_entry_safe(entry, tmp, &ctx->submitqueues, node)
  48. msm_submitqueue_put(entry);
  49. }
  50. int msm_submitqueue_create(struct msm_file_private *ctx, u32 prio, u32 flags,
  51. u32 *id)
  52. {
  53. struct msm_gpu_submitqueue *queue;
  54. if (!ctx)
  55. return -ENODEV;
  56. queue = kzalloc(sizeof(*queue), GFP_KERNEL);
  57. if (!queue)
  58. return -ENOMEM;
  59. kref_init(&queue->ref);
  60. queue->flags = flags;
  61. queue->prio = prio;
  62. write_lock(&ctx->queuelock);
  63. queue->id = ctx->queueid++;
  64. if (id)
  65. *id = queue->id;
  66. list_add_tail(&queue->node, &ctx->submitqueues);
  67. write_unlock(&ctx->queuelock);
  68. return 0;
  69. }
  70. int msm_submitqueue_init(struct msm_file_private *ctx)
  71. {
  72. if (!ctx)
  73. return 0;
  74. INIT_LIST_HEAD(&ctx->submitqueues);
  75. rwlock_init(&ctx->queuelock);
  76. return msm_submitqueue_create(ctx, 2, 0, NULL);
  77. }
  78. int msm_submitqueue_remove(struct msm_file_private *ctx, u32 id)
  79. {
  80. struct msm_gpu_submitqueue *entry;
  81. if (!ctx)
  82. return 0;
  83. /*
  84. * id 0 is the "default" queue and can't be destroyed
  85. * by the user
  86. */
  87. if (!id)
  88. return -ENOENT;
  89. write_lock(&ctx->queuelock);
  90. list_for_each_entry(entry, &ctx->submitqueues, node) {
  91. if (entry->id == id) {
  92. list_del(&entry->node);
  93. write_unlock(&ctx->queuelock);
  94. msm_submitqueue_put(entry);
  95. return 0;
  96. }
  97. }
  98. write_unlock(&ctx->queuelock);
  99. return -ENOENT;
  100. }