dma_addr.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  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. * vineetg: Feb 2009
  9. * -For AA4 board, kernel to DMA address APIs
  10. */
  11. /*
  12. * kernel addresses are 0x800_000 based, while Bus addr are 0 based
  13. */
  14. #ifndef __PLAT_DMA_ADDR_H
  15. #define __PLAT_DMA_ADDR_H
  16. #include <linux/device.h>
  17. static inline unsigned long plat_dma_addr_to_kernel(struct device *dev,
  18. dma_addr_t dma_addr)
  19. {
  20. return dma_addr + PAGE_OFFSET;
  21. }
  22. static inline dma_addr_t plat_kernel_addr_to_dma(struct device *dev, void *ptr)
  23. {
  24. unsigned long addr = (unsigned long)ptr;
  25. /*
  26. * To Catch buggy drivers which can call DMA map API with kernel vaddr
  27. * i.e. for buffers alloc via vmalloc or ioremap which are not
  28. * gaurnateed to be PHY contiguous and hence unfit for DMA anyways.
  29. * On ARC kernel virtual address is 0x7000_0000 to 0x7FFF_FFFF, so
  30. * ideally we want to check this range here, but our implementation is
  31. * better as it checks for even worse user virtual address as well.
  32. */
  33. if (likely(addr >= PAGE_OFFSET))
  34. return addr - PAGE_OFFSET;
  35. BUG();
  36. return addr;
  37. }
  38. #endif