pci-dma-compat.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* include this file if the platform implements the dma_ DMA Mapping API
  2. * and wants to provide the pci_ DMA Mapping API in terms of it */
  3. #ifndef _ASM_GENERIC_PCI_DMA_COMPAT_H
  4. #define _ASM_GENERIC_PCI_DMA_COMPAT_H
  5. #include <linux/dma-mapping.h>
  6. static inline void *
  7. pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
  8. dma_addr_t *dma_handle)
  9. {
  10. return dma_alloc_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, dma_handle, GFP_ATOMIC);
  11. }
  12. static inline void *
  13. pci_zalloc_consistent(struct pci_dev *hwdev, size_t size,
  14. dma_addr_t *dma_handle)
  15. {
  16. return dma_zalloc_coherent(hwdev == NULL ? NULL : &hwdev->dev,
  17. size, dma_handle, GFP_ATOMIC);
  18. }
  19. static inline void
  20. pci_free_consistent(struct pci_dev *hwdev, size_t size,
  21. void *vaddr, dma_addr_t dma_handle)
  22. {
  23. dma_free_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, vaddr, dma_handle);
  24. }
  25. static inline dma_addr_t
  26. pci_map_single(struct pci_dev *hwdev, void *ptr, size_t size, int direction)
  27. {
  28. return dma_map_single(hwdev == NULL ? NULL : &hwdev->dev, ptr, size, (enum dma_data_direction)direction);
  29. }
  30. static inline void
  31. pci_unmap_single(struct pci_dev *hwdev, dma_addr_t dma_addr,
  32. size_t size, int direction)
  33. {
  34. dma_unmap_single(hwdev == NULL ? NULL : &hwdev->dev, dma_addr, size, (enum dma_data_direction)direction);
  35. }
  36. static inline dma_addr_t
  37. pci_map_page(struct pci_dev *hwdev, struct page *page,
  38. unsigned long offset, size_t size, int direction)
  39. {
  40. return dma_map_page(hwdev == NULL ? NULL : &hwdev->dev, page, offset, size, (enum dma_data_direction)direction);
  41. }
  42. static inline void
  43. pci_unmap_page(struct pci_dev *hwdev, dma_addr_t dma_address,
  44. size_t size, int direction)
  45. {
  46. dma_unmap_page(hwdev == NULL ? NULL : &hwdev->dev, dma_address, size, (enum dma_data_direction)direction);
  47. }
  48. static inline int
  49. pci_map_sg(struct pci_dev *hwdev, struct scatterlist *sg,
  50. int nents, int direction)
  51. {
  52. return dma_map_sg(hwdev == NULL ? NULL : &hwdev->dev, sg, nents, (enum dma_data_direction)direction);
  53. }
  54. static inline void
  55. pci_unmap_sg(struct pci_dev *hwdev, struct scatterlist *sg,
  56. int nents, int direction)
  57. {
  58. dma_unmap_sg(hwdev == NULL ? NULL : &hwdev->dev, sg, nents, (enum dma_data_direction)direction);
  59. }
  60. static inline void
  61. pci_dma_sync_single_for_cpu(struct pci_dev *hwdev, dma_addr_t dma_handle,
  62. size_t size, int direction)
  63. {
  64. dma_sync_single_for_cpu(hwdev == NULL ? NULL : &hwdev->dev, dma_handle, size, (enum dma_data_direction)direction);
  65. }
  66. static inline void
  67. pci_dma_sync_single_for_device(struct pci_dev *hwdev, dma_addr_t dma_handle,
  68. size_t size, int direction)
  69. {
  70. dma_sync_single_for_device(hwdev == NULL ? NULL : &hwdev->dev, dma_handle, size, (enum dma_data_direction)direction);
  71. }
  72. static inline void
  73. pci_dma_sync_sg_for_cpu(struct pci_dev *hwdev, struct scatterlist *sg,
  74. int nelems, int direction)
  75. {
  76. dma_sync_sg_for_cpu(hwdev == NULL ? NULL : &hwdev->dev, sg, nelems, (enum dma_data_direction)direction);
  77. }
  78. static inline void
  79. pci_dma_sync_sg_for_device(struct pci_dev *hwdev, struct scatterlist *sg,
  80. int nelems, int direction)
  81. {
  82. dma_sync_sg_for_device(hwdev == NULL ? NULL : &hwdev->dev, sg, nelems, (enum dma_data_direction)direction);
  83. }
  84. static inline int
  85. pci_dma_mapping_error(struct pci_dev *pdev, dma_addr_t dma_addr)
  86. {
  87. return dma_mapping_error(&pdev->dev, dma_addr);
  88. }
  89. #ifdef CONFIG_PCI
  90. static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask)
  91. {
  92. return dma_set_mask(&dev->dev, mask);
  93. }
  94. static inline int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
  95. {
  96. return dma_set_coherent_mask(&dev->dev, mask);
  97. }
  98. #endif
  99. #endif