dma-mapping.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * OpenRISC Linux
  3. *
  4. * Linux architectural port borrowing liberally from similar works of
  5. * others. All original copyrights apply as per the original source
  6. * declaration.
  7. *
  8. * OpenRISC implementation:
  9. * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. */
  16. #ifndef __ASM_OPENRISC_DMA_MAPPING_H
  17. #define __ASM_OPENRISC_DMA_MAPPING_H
  18. /*
  19. * See Documentation/DMA-API-HOWTO.txt and
  20. * Documentation/DMA-API.txt for documentation.
  21. */
  22. #include <linux/dma-debug.h>
  23. #include <asm-generic/dma-coherent.h>
  24. #include <linux/kmemcheck.h>
  25. #include <linux/dma-mapping.h>
  26. #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
  27. extern struct dma_map_ops or1k_dma_map_ops;
  28. static inline struct dma_map_ops *get_dma_ops(struct device *dev)
  29. {
  30. return &or1k_dma_map_ops;
  31. }
  32. #include <asm-generic/dma-mapping-common.h>
  33. #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
  34. static inline void *dma_alloc_attrs(struct device *dev, size_t size,
  35. dma_addr_t *dma_handle, gfp_t gfp,
  36. struct dma_attrs *attrs)
  37. {
  38. struct dma_map_ops *ops = get_dma_ops(dev);
  39. void *memory;
  40. memory = ops->alloc(dev, size, dma_handle, gfp, attrs);
  41. debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
  42. return memory;
  43. }
  44. #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
  45. static inline void dma_free_attrs(struct device *dev, size_t size,
  46. void *cpu_addr, dma_addr_t dma_handle,
  47. struct dma_attrs *attrs)
  48. {
  49. struct dma_map_ops *ops = get_dma_ops(dev);
  50. debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
  51. ops->free(dev, size, cpu_addr, dma_handle, attrs);
  52. }
  53. static inline void *dma_alloc_noncoherent(struct device *dev, size_t size,
  54. dma_addr_t *dma_handle, gfp_t gfp)
  55. {
  56. struct dma_attrs attrs;
  57. dma_set_attr(DMA_ATTR_NON_CONSISTENT, &attrs);
  58. return dma_alloc_attrs(dev, size, dma_handle, gfp, &attrs);
  59. }
  60. static inline void dma_free_noncoherent(struct device *dev, size_t size,
  61. void *cpu_addr, dma_addr_t dma_handle)
  62. {
  63. struct dma_attrs attrs;
  64. dma_set_attr(DMA_ATTR_NON_CONSISTENT, &attrs);
  65. dma_free_attrs(dev, size, cpu_addr, dma_handle, &attrs);
  66. }
  67. static inline int dma_supported(struct device *dev, u64 dma_mask)
  68. {
  69. /* Support 32 bit DMA mask exclusively */
  70. return dma_mask == DMA_BIT_MASK(32);
  71. }
  72. static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  73. {
  74. return 0;
  75. }
  76. static inline int dma_set_mask(struct device *dev, u64 dma_mask)
  77. {
  78. if (!dev->dma_mask || !dma_supported(dev, dma_mask))
  79. return -EIO;
  80. *dev->dma_mask = dma_mask;
  81. return 0;
  82. }
  83. #endif /* __ASM_OPENRISC_DMA_MAPPING_H */