s5p_mfc_shm.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * linux/drivers/media/video/s5p-mfc/s5p_mfc_shm.c
  3. *
  4. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com/
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #ifdef CONFIG_ARCH_EXYNOS4
  13. #include <linux/dma-mapping.h>
  14. #endif
  15. #include <linux/io.h>
  16. #include "s5p_mfc_common.h"
  17. #include "s5p_mfc_debug.h"
  18. int s5p_mfc_init_shm(struct s5p_mfc_ctx *ctx)
  19. {
  20. struct s5p_mfc_dev *dev = ctx->dev;
  21. void *shm_alloc_ctx = dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
  22. ctx->shm_alloc = vb2_dma_contig_memops.alloc(shm_alloc_ctx,
  23. SHARED_BUF_SIZE);
  24. if (IS_ERR(ctx->shm_alloc)) {
  25. mfc_err("failed to allocate shared memory\n");
  26. return PTR_ERR(ctx->shm_alloc);
  27. }
  28. /* shm_ofs only keeps the offset from base (port a) */
  29. ctx->shm_ofs = s5p_mfc_mem_cookie(shm_alloc_ctx, ctx->shm_alloc)
  30. - dev->bank1;
  31. BUG_ON(ctx->shm_ofs & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
  32. ctx->shm = vb2_dma_contig_memops.vaddr(ctx->shm_alloc);
  33. if (!ctx->shm) {
  34. vb2_dma_contig_memops.put(ctx->shm_alloc);
  35. ctx->shm_ofs = 0;
  36. ctx->shm_alloc = NULL;
  37. mfc_err("failed to virt addr of shared memory\n");
  38. return -ENOMEM;
  39. }
  40. memset((void *)ctx->shm, 0, SHARED_BUF_SIZE);
  41. wmb();
  42. return 0;
  43. }