Now that dma_buf_mapping_attach() ensures a mapping_type exists, even for exporters and importers that don't provide it, route operations through the map_type.
For map/unmap this will go through dma_buf_sgt_compat_map_dma_buf() which calls the same attach->dmabuf->ops->map_dma_buf(). Move the debugfs processing unique to SGT into a callback too. Signed-off-by: Jason Gunthorpe <[email protected]> --- drivers/dma-buf/dma-buf.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index 6e89fcfdad3015..4211ae2b462bdd 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1149,12 +1149,14 @@ EXPORT_SYMBOL_NS_GPL(dma_buf_unpin, "DMA_BUF"); struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, enum dma_data_direction direction) { + const struct dma_buf_mapping_sgt_exp_ops *sgt_exp_ops = + dma_buf_get_sgt_ops(attach); struct sg_table *sg_table; signed long ret; might_sleep(); - if (WARN_ON(!attach || !attach->dmabuf)) + if (WARN_ON(!attach || !attach->dmabuf || !sgt_exp_ops)) return ERR_PTR(-EINVAL); dma_resv_assert_held(attach->dmabuf->resv); @@ -1170,7 +1172,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, return ERR_PTR(ret); } - sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); + sg_table = sgt_exp_ops->map_dma_buf(attach, direction); if (!sg_table) sg_table = ERR_PTR(-ENOMEM); if (IS_ERR(sg_table)) @@ -1208,7 +1210,7 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, return sg_table; error_unmap: - attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction); + sgt_exp_ops->unmap_dma_buf(attach, sg_table, direction); sg_table = ERR_PTR(ret); error_unpin: @@ -1261,15 +1263,18 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, struct sg_table *sg_table, enum dma_data_direction direction) { + const struct dma_buf_mapping_sgt_exp_ops *sgt_exp_ops = + dma_buf_get_sgt_ops(attach); + might_sleep(); - if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) + if (WARN_ON(!attach || !attach->dmabuf || !sg_table || !sgt_exp_ops)) return; dma_resv_assert_held(attach->dmabuf->resv); mangle_sg_table(sg_table); - attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction); + sgt_exp_ops->unmap_dma_buf(attach, sg_table, direction); if (dma_buf_pin_on_map(attach)) attach->dmabuf->ops->unpin(attach); @@ -1700,7 +1705,11 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused) attach_count = 0; list_for_each_entry(attach_obj, &buf_obj->attachments, node) { - seq_printf(s, "\t%s\n", dev_name(attach_obj->dev)); + seq_printf(s, "\t%s:", attach_obj->map_type.type->name); + if (attach_obj->map_type.type->debugfs_dump) + attach_obj->map_type.type->debugfs_dump( + s, attach_obj); + seq_putc(s, '\n'); attach_count++; } dma_resv_unlock(buf_obj->resv); -- 2.43.0
