msm_ringbuffer.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "msm_ringbuffer.h"
  18. #include "msm_gpu.h"
  19. struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int size)
  20. {
  21. struct msm_ringbuffer *ring;
  22. int ret;
  23. if (WARN_ON(!is_power_of_2(size)))
  24. return ERR_PTR(-EINVAL);
  25. ring = kzalloc(sizeof(*ring), GFP_KERNEL);
  26. if (!ring) {
  27. ret = -ENOMEM;
  28. goto fail;
  29. }
  30. ring->gpu = gpu;
  31. ring->bo = msm_gem_new(gpu->dev, size, MSM_BO_WC);
  32. if (IS_ERR(ring->bo)) {
  33. ret = PTR_ERR(ring->bo);
  34. ring->bo = NULL;
  35. goto fail;
  36. }
  37. ring->start = msm_gem_get_vaddr_locked(ring->bo);
  38. if (IS_ERR(ring->start)) {
  39. ret = PTR_ERR(ring->start);
  40. goto fail;
  41. }
  42. ring->end = ring->start + (size / 4);
  43. ring->cur = ring->start;
  44. ring->size = size;
  45. return ring;
  46. fail:
  47. if (ring)
  48. msm_ringbuffer_destroy(ring);
  49. return ERR_PTR(ret);
  50. }
  51. void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)
  52. {
  53. if (ring->bo) {
  54. msm_gem_put_vaddr(ring->bo);
  55. drm_gem_object_unreference_unlocked(ring->bo);
  56. }
  57. kfree(ring);
  58. }