pci-p2pdma.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * PCI Peer 2 Peer DMA support.
  4. *
  5. * Copyright (c) 2016-2018, Logan Gunthorpe
  6. * Copyright (c) 2016-2017, Microsemi Corporation
  7. * Copyright (c) 2017, Christoph Hellwig
  8. * Copyright (c) 2018, Eideticom Inc.
  9. */
  10. #ifndef _LINUX_PCI_P2PDMA_H
  11. #define _LINUX_PCI_P2PDMA_H
  12. #include <linux/pci.h>
  13. struct block_device;
  14. struct scatterlist;
  15. #ifdef CONFIG_PCI_P2PDMA
  16. int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
  17. u64 offset);
  18. int pci_p2pdma_distance_many(struct pci_dev *provider, struct device **clients,
  19. int num_clients, bool verbose);
  20. bool pci_has_p2pmem(struct pci_dev *pdev);
  21. struct pci_dev *pci_p2pmem_find_many(struct device **clients, int num_clients);
  22. void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size);
  23. void pci_free_p2pmem(struct pci_dev *pdev, void *addr, size_t size);
  24. pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev, void *addr);
  25. struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
  26. unsigned int *nents, u32 length);
  27. void pci_p2pmem_free_sgl(struct pci_dev *pdev, struct scatterlist *sgl);
  28. void pci_p2pmem_publish(struct pci_dev *pdev, bool publish);
  29. int pci_p2pdma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
  30. int nents, enum dma_data_direction dir, unsigned long attrs);
  31. void pci_p2pdma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
  32. int nents, enum dma_data_direction dir, unsigned long attrs);
  33. int pci_p2pdma_enable_store(const char *page, struct pci_dev **p2p_dev,
  34. bool *use_p2pdma);
  35. ssize_t pci_p2pdma_enable_show(char *page, struct pci_dev *p2p_dev,
  36. bool use_p2pdma);
  37. #else /* CONFIG_PCI_P2PDMA */
  38. static inline int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar,
  39. size_t size, u64 offset)
  40. {
  41. return -EOPNOTSUPP;
  42. }
  43. static inline int pci_p2pdma_distance_many(struct pci_dev *provider,
  44. struct device **clients, int num_clients, bool verbose)
  45. {
  46. return -1;
  47. }
  48. static inline bool pci_has_p2pmem(struct pci_dev *pdev)
  49. {
  50. return false;
  51. }
  52. static inline struct pci_dev *pci_p2pmem_find_many(struct device **clients,
  53. int num_clients)
  54. {
  55. return NULL;
  56. }
  57. static inline void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size)
  58. {
  59. return NULL;
  60. }
  61. static inline void pci_free_p2pmem(struct pci_dev *pdev, void *addr,
  62. size_t size)
  63. {
  64. }
  65. static inline pci_bus_addr_t pci_p2pmem_virt_to_bus(struct pci_dev *pdev,
  66. void *addr)
  67. {
  68. return 0;
  69. }
  70. static inline struct scatterlist *pci_p2pmem_alloc_sgl(struct pci_dev *pdev,
  71. unsigned int *nents, u32 length)
  72. {
  73. return NULL;
  74. }
  75. static inline void pci_p2pmem_free_sgl(struct pci_dev *pdev,
  76. struct scatterlist *sgl)
  77. {
  78. }
  79. static inline void pci_p2pmem_publish(struct pci_dev *pdev, bool publish)
  80. {
  81. }
  82. static inline int pci_p2pdma_map_sg_attrs(struct device *dev,
  83. struct scatterlist *sg, int nents, enum dma_data_direction dir,
  84. unsigned long attrs)
  85. {
  86. return 0;
  87. }
  88. static inline void pci_p2pdma_unmap_sg_attrs(struct device *dev,
  89. struct scatterlist *sg, int nents, enum dma_data_direction dir,
  90. unsigned long attrs)
  91. {
  92. }
  93. static inline int pci_p2pdma_enable_store(const char *page,
  94. struct pci_dev **p2p_dev, bool *use_p2pdma)
  95. {
  96. *use_p2pdma = false;
  97. return 0;
  98. }
  99. static inline ssize_t pci_p2pdma_enable_show(char *page,
  100. struct pci_dev *p2p_dev, bool use_p2pdma)
  101. {
  102. return sprintf(page, "none\n");
  103. }
  104. #endif /* CONFIG_PCI_P2PDMA */
  105. static inline int pci_p2pdma_distance(struct pci_dev *provider,
  106. struct device *client, bool verbose)
  107. {
  108. return pci_p2pdma_distance_many(provider, &client, 1, verbose);
  109. }
  110. static inline struct pci_dev *pci_p2pmem_find(struct device *client)
  111. {
  112. return pci_p2pmem_find_many(&client, 1);
  113. }
  114. static inline int pci_p2pdma_map_sg(struct device *dev, struct scatterlist *sg,
  115. int nents, enum dma_data_direction dir)
  116. {
  117. return pci_p2pdma_map_sg_attrs(dev, sg, nents, dir, 0);
  118. }
  119. static inline void pci_p2pdma_unmap_sg(struct device *dev,
  120. struct scatterlist *sg, int nents, enum dma_data_direction dir)
  121. {
  122. pci_p2pdma_unmap_sg_attrs(dev, sg, nents, dir, 0);
  123. }
  124. #endif /* _LINUX_PCI_P2P_H */