All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>,
	Alex Deucher <alexander.deucher@amd.com>
Cc: amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 2/3] drm/amdgpu/dma-buf: Add helpers to map/unmap BAR I/O with dma_map_resource()
Date: Mon, 22 Sep 2025 13:27:46 +0200	[thread overview]
Message-ID: <ab4e2e75-0e36-485b-86d3-9daf345033cd@amd.com> (raw)
In-Reply-To: <20250912111148.833465-3-srinivasan.shanmugam@amd.com>

Please squash that together with patch #3 in this series.

On 12.09.25 13:11, Srinivasan Shanmugam wrote:
> Add helpers to map/unmap a hardware MMIO register window (PCI BAR) as a
> 1-entry sg_table using dma_map_resource()/dma_unmap_resource(). This
> will be used by MMIO_REMAP.
> 
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 51 +++++++++++++++++++++
>  1 file changed, 51 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
> index ff98c87b2e0b..33fa17a927ce 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
> @@ -37,11 +37,15 @@
>  #include "amdgpu_dma_buf.h"
>  #include "amdgpu_xgmi.h"
>  #include "amdgpu_vm.h"
> +#include "amdgpu_object.h"
>  #include <drm/amdgpu_drm.h>
>  #include <drm/ttm/ttm_tt.h>
>  #include <linux/dma-buf.h>
>  #include <linux/dma-fence-array.h>
>  #include <linux/pci-p2pdma.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/scatterlist.h>
> +#include <linux/slab.h>
>  
>  static const struct dma_buf_attach_ops amdgpu_dma_buf_attach_ops;
>  
> @@ -146,6 +150,53 @@ static void amdgpu_dma_buf_unpin(struct dma_buf_attachment *attach)
>  	amdgpu_bo_unpin(bo);
>  }
>  
> +/* Map a BAR-backed I/O span as a 1-entry sg_table via dma_map_resource(). */
> +static __maybe_unused struct sg_table *
> +amdgpu_dmabuf_map_iomem(struct device *dev, resource_size_t phys,
> +			size_t size, enum dma_data_direction dir)
> +{
> +	struct sg_table *sgt;
> +	unsigned long attrs = DMA_ATTR_SKIP_CPU_SYNC; /* no P2PDMA attr */
> +	dma_addr_t dma;
> +
> +	sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
> +	if (!sgt)
> +		return ERR_PTR(-ENOMEM);
> +
> +	if (sg_alloc_table(sgt, 1, GFP_KERNEL)) {
> +		kfree(sgt);
> +		return ERR_PTR(-ENOMEM);
> +	}
> +
> +	/* No struct page backing for I/O regions. */
> +	sg_set_page(sgt->sgl, NULL, size, 0);
> +
> +	dma = dma_map_resource(dev, phys, size, dir, attrs);
> +	if (dma_mapping_error(dev, dma)) {
> +		sg_free_table(sgt);
> +		kfree(sgt);
> +		return ERR_PTR(-EIO);
> +	}
> +
> +	sg_dma_address(sgt->sgl) = dma;
> +	sg_dma_len(sgt->sgl) = size;
> +	return sgt;
> +}
> +
> +static __maybe_unused void
> +amdgpu_dmabuf_unmap_iomem(struct device *dev, struct sg_table *sgt,
> +			  enum dma_data_direction dir)
> +{
> +	/* attrs must match map side; we only used SKIP_CPU_SYNC above */
> +	dma_unmap_resource(dev,
> +			   sg_dma_address(sgt->sgl),
> +			   sg_dma_len(sgt->sgl),
> +			   dir,
> +			   0);
> +	sg_free_table(sgt);
> +	kfree(sgt);
> +}
> +
>  /**
>   * amdgpu_dma_buf_map - &dma_buf_ops.map_dma_buf implementation
>   * @attach: DMA-buf attachment


  reply	other threads:[~2025-09-22 11:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-12 11:11 [PATCH v2 0/3] drm/amdgpu: Handle MMIO_REMAP as fixed I/O via dma-buf Srinivasan Shanmugam
2025-09-12 11:11 ` [PATCH v2 1/3] drm/amdgpu/ttm: Pin 4K MMIO_REMAP Singleton BO at Init Srinivasan Shanmugam
2025-09-22 11:26   ` Christian König
2025-09-12 11:11 ` [PATCH v2 2/3] drm/amdgpu/dma-buf: Add helpers to map/unmap BAR I/O with dma_map_resource() Srinivasan Shanmugam
2025-09-22 11:27   ` Christian König [this message]
2025-09-12 11:11 ` [PATCH v2 3/3] drm/amdgpu/dma-buf: Map/Unmap MMIO_REMAP as BAR register window (dma_map_resource) Srinivasan Shanmugam
2025-09-22 11:31   ` Christian König
2025-10-06 14:16 ` [PATCH v3 0/2] drm/amdgpu: Handle MMIO_REMAP as fixed I/O via dma-buf v3 Srinivasan Shanmugam
2025-10-06 14:16   ` [PATCH v3 1/2] drm/amdgpu/ttm: Pin 4K MMIO_REMAP Singleton BO at Init Srinivasan Shanmugam
2025-10-06 14:16   ` [PATCH v3 2/2] drm/amdgpu: Map/Unmap MMIO_REMAP as BAR register window; add TTM sg helpers; wire dma-buf Srinivasan Shanmugam
2025-11-06 17:10     ` Alex Deucher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ab4e2e75-0e36-485b-86d3-9daf345033cd@amd.com \
    --to=christian.koenig@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=srinivasan.shanmugam@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.