vc4_bo.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright © 2015 Broadcom
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. /* DOC: VC4 GEM BO management support.
  9. *
  10. * The VC4 GPU architecture (both scanout and rendering) has direct
  11. * access to system memory with no MMU in between. To support it, we
  12. * use the GEM CMA helper functions to allocate contiguous ranges of
  13. * physical memory for our BOs.
  14. */
  15. #include "vc4_drv.h"
  16. struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size)
  17. {
  18. struct drm_gem_cma_object *cma_obj;
  19. cma_obj = drm_gem_cma_create(dev, size);
  20. if (IS_ERR(cma_obj))
  21. return NULL;
  22. else
  23. return to_vc4_bo(&cma_obj->base);
  24. }
  25. int vc4_dumb_create(struct drm_file *file_priv,
  26. struct drm_device *dev,
  27. struct drm_mode_create_dumb *args)
  28. {
  29. int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
  30. struct vc4_bo *bo = NULL;
  31. int ret;
  32. if (args->pitch < min_pitch)
  33. args->pitch = min_pitch;
  34. if (args->size < args->pitch * args->height)
  35. args->size = args->pitch * args->height;
  36. bo = vc4_bo_create(dev, roundup(args->size, PAGE_SIZE));
  37. if (!bo)
  38. return -ENOMEM;
  39. ret = drm_gem_handle_create(file_priv, &bo->base.base, &args->handle);
  40. drm_gem_object_unreference_unlocked(&bo->base.base);
  41. return ret;
  42. }