msm_ringbuffer.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. size = ALIGN(size, 4); /* size should be dword aligned */
  24. ring = kzalloc(sizeof(*ring), GFP_KERNEL);
  25. if (!ring) {
  26. ret = -ENOMEM;
  27. goto fail;
  28. }
  29. ring->gpu = gpu;
  30. ring->bo = msm_gem_new(gpu->dev, size, MSM_BO_WC);
  31. if (IS_ERR(ring->bo)) {
  32. ret = PTR_ERR(ring->bo);
  33. ring->bo = NULL;
  34. goto fail;
  35. }
  36. ring->start = msm_gem_vaddr_locked(ring->bo);
  37. ring->end = ring->start + (size / 4);
  38. ring->cur = ring->start;
  39. ring->size = size;
  40. return ring;
  41. fail:
  42. if (ring)
  43. msm_ringbuffer_destroy(ring);
  44. return ERR_PTR(ret);
  45. }
  46. void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)
  47. {
  48. if (ring->bo)
  49. drm_gem_object_unreference(ring->bo);
  50. kfree(ring);
  51. }