Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

NTB: core: Add .get_dma_dev() callback to ntb_dev_ops

Some NTB implementations are backed by a PCI function that is not the right
struct device to use with DMA API helpers (e.g. due to IOMMU topology, or
because the NTB device is virtual).

Add an optional .get_dma_dev() callback to struct ntb_dev_ops and provide a
helper, ntb_get_dma_dev(), so NTB clients can use the appropriate struct
device for DMA allocations and mappings.

If the callback is not implemented, ntb_get_dma_dev() returns the current
default (ntb->dev.parent). Drivers that implement .get_dma_dev() must
return a non-NULL device.

Suggested-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Koichiro Den <den@valinux.co.jp>
Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
[bhelgaas: format doc]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Link: https://patch.msgid.link/20260306031443.1911860-2-den@valinux.co.jp

authored by

Koichiro Den and committed by
Bjorn Helgaas
362a4549 396d44dc

+24
+24
include/linux/ntb.h
··· 256 256 * @msg_clear_mask: See ntb_msg_clear_mask(). 257 257 * @msg_read: See ntb_msg_read(). 258 258 * @peer_msg_write: See ntb_peer_msg_write(). 259 + * @get_dma_dev: See ntb_get_dma_dev(). 259 260 */ 260 261 struct ntb_dev_ops { 261 262 int (*port_number)(struct ntb_dev *ntb); ··· 330 329 int (*msg_clear_mask)(struct ntb_dev *ntb, u64 mask_bits); 331 330 u32 (*msg_read)(struct ntb_dev *ntb, int *pidx, int midx); 332 331 int (*peer_msg_write)(struct ntb_dev *ntb, int pidx, int midx, u32 msg); 332 + struct device *(*get_dma_dev)(struct ntb_dev *ntb); 333 333 }; 334 334 335 335 static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops) ··· 393 391 /* !ops->msg_clear_mask == !ops->msg_count && */ 394 392 !ops->msg_read == !ops->msg_count && 395 393 !ops->peer_msg_write == !ops->msg_count && 394 + 395 + /* ops->get_dma_dev is optional */ 396 396 1; 397 397 } 398 398 ··· 1565 1561 return -EINVAL; 1566 1562 1567 1563 return ntb->ops->peer_msg_write(ntb, pidx, midx, msg); 1564 + } 1565 + 1566 + /** 1567 + * ntb_get_dma_dev() - get the device to use for DMA allocations/mappings 1568 + * @ntb: NTB device context. 1569 + * 1570 + * Return a struct device suitable for DMA API allocations and mappings. 1571 + * This is typically the parent of the NTB device, but may be overridden by a 1572 + * driver by implementing .get_dma_dev(). 1573 + * 1574 + * Drivers that implement .get_dma_dev() must return a non-NULL pointer. 1575 + * 1576 + * Return: device pointer to use for DMA operations. 1577 + */ 1578 + static inline struct device *ntb_get_dma_dev(struct ntb_dev *ntb) 1579 + { 1580 + if (!ntb->ops->get_dma_dev) 1581 + return ntb->dev.parent; 1582 + 1583 + return ntb->ops->get_dma_dev(ntb); 1568 1584 } 1569 1585 1570 1586 /**