All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Subject: [Intel-gfx] [PATCH] drm/i915: DMA map DSM [stolen memory]
Date: Mon, 12 Oct 2020 14:36:41 +0100	[thread overview]
Message-ID: <20201012133641.5658-1-chris@chris-wilson.co.uk> (raw)

Pass the physical address of our BIOS reserved stolen memory to the dma
mapper so we convert it into a proper dma_addr_t and track access with
the iommu.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 21 ++++++++++++++++++++-
 drivers/gpu/drm/i915/i915_drv.h            |  5 +++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
index 0be5e8683337..ecb4ee6ac19d 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c
@@ -162,6 +162,11 @@ static void i915_gem_cleanup_stolen(struct drm_i915_private *i915)
 	if (!drm_mm_initialized(&i915->mm.stolen))
 		return;
 
+	dma_unmap_resource(i915->drm.dev,
+			   i915->dsm_dma, resource_size(&i915->dsm),
+			   DMA_BIDIRECTIONAL,
+			   DMA_ATTR_NO_WARN);
+
 	drm_mm_takedown(&i915->mm.stolen);
 }
 
@@ -489,6 +494,19 @@ static int i915_gem_init_stolen(struct drm_i915_private *i915)
 	i915->stolen_usable_size =
 		resource_size(&i915->dsm) - reserved_total;
 
+	i915->dsm_dma =
+		dma_map_resource(i915->drm.dev,
+				 i915->dsm.start, resource_size(&i915->dsm),
+				 DMA_BIDIRECTIONAL,
+				 DMA_ATTR_NO_KERNEL_MAPPING |
+				 DMA_ATTR_SKIP_CPU_SYNC);
+	if (dma_mapping_error(i915->drm.dev, i915->dsm_dma)) {
+		drm_err(&i915->drm,
+			"Failed to map stolen memory %pR for use with DMA\n",
+			&i915->dsm);
+		return 0; /* bail; continue to load the driver without stolen */
+	}
+
 	/* Basic memrange allocator for stolen space. */
 	drm_mm_init(&i915->mm.stolen, 0, i915->stolen_usable_size);
 
@@ -504,6 +522,7 @@ i915_pages_create_for_stolen(struct drm_device *dev,
 	struct scatterlist *sg;
 
 	GEM_BUG_ON(range_overflows(offset, size, resource_size(&i915->dsm)));
+	GEM_BUG_ON(dma_mapping_error(dev->dev, i915->dsm_dma));
 
 	/* We hide that we have no struct page backing our stolen object
 	 * by wrapping the contiguous physical allocation with a fake
@@ -523,7 +542,7 @@ i915_pages_create_for_stolen(struct drm_device *dev,
 	sg->offset = 0;
 	sg->length = size;
 
-	sg_dma_address(sg) = (dma_addr_t)i915->dsm.start + offset;
+	sg_dma_address(sg) = i915->dsm_dma + offset;
 	sg_dma_len(sg) = size;
 
 	return st;
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 9c2672c56cc1..44972eda7fb8 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -836,6 +836,11 @@ struct drm_i915_private {
 	 */
 	struct resource dsm_reserved;
 
+	/**
+	 * dma-mapping of the Data Stolen Memory.
+	 */
+	dma_addr_t dsm_dma;
+
 	/*
 	 * Stolen memory is segmented in hardware with different portions
 	 * offlimits to certain functions.
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

             reply	other threads:[~2020-10-12 13:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12 13:36 Chris Wilson [this message]
2020-10-12 14:16 ` [Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915: DMA map DSM [stolen memory] Patchwork
2020-10-12 14:35 ` [Intel-gfx] [PATCH v2] " Chris Wilson
2020-10-12 16:40 ` [Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915: DMA map DSM [stolen memory] (rev2) Patchwork
2020-10-12 19:38 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork

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=20201012133641.5658-1-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    /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.