dma-mapping.h 734 B

1234567891011121314151617181920212223
  1. #ifndef __ASM_NIOS2_DMA_MAPPING_H
  2. #define __ASM_NIOS2_DMA_MAPPING_H
  3. /* dma_alloc_coherent() return cache-line aligned allocation which is mapped
  4. * to uncached io region.
  5. *
  6. * IO_REGION_BASE should be defined in board config header file
  7. * 0x80000000 for nommu, 0xe0000000 for mmu
  8. */
  9. static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
  10. {
  11. void *addr = malloc(len + CONFIG_SYS_DCACHELINE_SIZE);
  12. if (!addr)
  13. return 0;
  14. flush_dcache((unsigned long)addr, len + CONFIG_SYS_DCACHELINE_SIZE);
  15. *handle = ((unsigned long)addr +
  16. (CONFIG_SYS_DCACHELINE_SIZE - 1)) &
  17. ~(CONFIG_SYS_DCACHELINE_SIZE - 1) & ~(IO_REGION_BASE);
  18. return (void *)(*handle | IO_REGION_BASE);
  19. }
  20. #endif /* __ASM_NIOS2_DMA_MAPPING_H */