delta-mem.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) STMicroelectronics SA 2015
  4. * Author: Hugues Fruchet <hugues.fruchet@st.com> for STMicroelectronics.
  5. */
  6. #include "delta.h"
  7. #include "delta-mem.h"
  8. int hw_alloc(struct delta_ctx *ctx, u32 size, const char *name,
  9. struct delta_buf *buf)
  10. {
  11. struct delta_dev *delta = ctx->dev;
  12. dma_addr_t dma_addr;
  13. void *addr;
  14. unsigned long attrs = DMA_ATTR_WRITE_COMBINE;
  15. addr = dma_alloc_attrs(delta->dev, size, &dma_addr,
  16. GFP_KERNEL | __GFP_NOWARN, attrs);
  17. if (!addr) {
  18. dev_err(delta->dev,
  19. "%s hw_alloc:dma_alloc_coherent failed for %s (size=%d)\n",
  20. ctx->name, name, size);
  21. ctx->sys_errors++;
  22. return -ENOMEM;
  23. }
  24. buf->size = size;
  25. buf->paddr = dma_addr;
  26. buf->vaddr = addr;
  27. buf->name = name;
  28. buf->attrs = attrs;
  29. dev_dbg(delta->dev,
  30. "%s allocate %d bytes of HW memory @(virt=0x%p, phy=0x%pad): %s\n",
  31. ctx->name, size, buf->vaddr, &buf->paddr, buf->name);
  32. return 0;
  33. }
  34. void hw_free(struct delta_ctx *ctx, struct delta_buf *buf)
  35. {
  36. struct delta_dev *delta = ctx->dev;
  37. dev_dbg(delta->dev,
  38. "%s free %d bytes of HW memory @(virt=0x%p, phy=0x%pad): %s\n",
  39. ctx->name, buf->size, buf->vaddr, &buf->paddr, buf->name);
  40. dma_free_attrs(delta->dev, buf->size,
  41. buf->vaddr, buf->paddr, buf->attrs);
  42. }