drm/i915: make local-memory probing a GT operation
Subsystems (2)
PATCH v4 1/8 drm/i915: make local-memory probing a GT operation
Device local memory is very much a GT thing, therefore it should be the responsibility of the GT to setup the device local memory region.
--- drivers/gpu/drm/i915/gt/intel_gt.c | 32 +++++++++++++++++++++ drivers/gpu/drm/i915/gt/intel_gt.h | 1 + drivers/gpu/drm/i915/gt/intel_region_lmem.c | 10 +++++-- drivers/gpu/drm/i915/gt/intel_region_lmem.h | 4 +-- drivers/gpu/drm/i915/i915_drv.c | 4 +++ drivers/gpu/drm/i915/intel_memory_region.c | 5 ++-- 6 files changed, 49 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gt/intel_gt.c +32 -0
@@ -39,6 +39,38 @@ void intel_gt_init_early(struct intel_gt *gt, struct drm_i915_private *i915)intel_uc_init_early (>->uc); } +int intel_gt_probe_lmem (struct intel_gt *gt) +{ +struct drm_i915_private *i915 = gt->i915; +struct intel_memory_region *mem; +int id; +int err; + + mem =intel_gt_setup_fake_lmem (gt); +if (IS_ERR (mem)) { + err =PTR_ERR (mem); +if (err == -ENODEV ) +return 0 ; + +drm_err (&i915->drm, +"Failed to setup region(%d) type=%d\n" , + err,INTEL_MEMORY_LOCAL ); +return err; + } + + id =INTEL_REGION_LMEM ; + + mem->id = id; + mem->type =INTEL_MEMORY_LOCAL ; + mem->instance =0 ; + +GEM_BUG_ON (!HAS_REGION (i915, id)); +GEM_BUG_ON (i915->mm.regions[id]); + i915->mm.regions[id] = mem; + +return 0 ; +} +void intel_gt_init_hw_early (struct intel_gt *gt,struct i915_ggtt *ggtt) { gt->ggtt = ggtt;
drivers/gpu/drm/i915/gt/intel_gt.h +1 -0
@@ -36,6 +36,7 @@ static inline struct intel_gt *huc_to_gt(struct intel_huc *huc)void intel_gt_init_early (struct intel_gt *gt,struct drm_i915_private *i915);void intel_gt_init_hw_early (struct intel_gt *gt,struct i915_ggtt *ggtt); +int intel_gt_probe_lmem (struct intel_gt *gt);int intel_gt_init_mmio (struct intel_gt *gt);int __must_check intel_gt_init_hw (struct intel_gt *gt);int intel_gt_init (struct intel_gt *gt);
drivers/gpu/drm/i915/gt/intel_region_lmem.c +8 -2
@@ -102,16 +102,22 @@ static const struct intel_memory_region_ops intel_region_lmem_ops = { };struct intel_memory_region * -intel_setup_fake_lmem (struct drm_i915_private *i915) +intel_gt_setup_fake_lmem (struct intel_gt *gt) { +struct drm_i915_private *i915 = gt->i915;struct pci_dev *pdev = i915->drm.pdev;struct intel_memory_region *mem;resource_size_t mappable_end;resource_size_t io_start;resource_size_t start; +if (!HAS_LMEM (i915)) +return ERR_PTR (-ENODEV ); + +if (!i915->params.fake_lmem_start) +return ERR_PTR (-ENODEV ); +GEM_BUG_ON (i915_ggtt_has_aperture (&i915->ggtt)); -GEM_BUG_ON (!i915->params.fake_lmem_start);/* Your mappable aperture belongs to me now! */ mappable_end =pci_resource_len (pdev,2 );
drivers/gpu/drm/i915/gt/intel_region_lmem.h +2 -2
@@ -6,9 +6,9 @@#ifndef __INTEL_REGION_LMEM_H#define __INTEL_REGION_LMEM_H -struct drm_i915_private ; +struct intel_gt ;struct intel_memory_region * -intel_setup_fake_lmem (struct drm_i915_private *i915); +intel_gt_setup_fake_lmem (struct intel_gt *gt);#endif /* !__INTEL_REGION_LMEM_H */
drivers/gpu/drm/i915/i915_drv.c +4 -0
@@ -576,6 +576,10 @@ static int i915_driver_hw_probe(struct drm_i915_private *dev_priv)intel_gt_init_hw_early (&dev_priv->gt, &dev_priv->ggtt); + ret =intel_gt_probe_lmem (&dev_priv->gt); +if (ret) + goto err_mem_regions; + ret =i915_ggtt_enable_hw (dev_priv);if (ret) {drm_err (&dev_priv->drm,"failed to enable GGTT\n" );
drivers/gpu/drm/i915/intel_memory_region.c +2 -3
@@ -258,9 +258,8 @@ int intel_memory_regions_hw_probe(struct drm_i915_private *i915)case INTEL_MEMORY_STOLEN : mem =i915_gem_stolen_setup (i915);break ; -case INTEL_MEMORY_LOCAL : - mem =intel_setup_fake_lmem (i915); -break ; +default : +continue ; }if (IS_ERR (mem)) {
Signature · 6 lines
2.26.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v4 4/8 drm/i915: introduce mem->reserved
From: Abdiel Janulgue <[email protected]>
In the following patch we need to reserve regions unaccessible to the driver during initialization, so add mem->reserved for collecting such regions.
v2: turn into an actual intel_memory_region_reserve api
--- drivers/gpu/drm/i915/intel_memory_region.c | 14 ++++ drivers/gpu/drm/i915/intel_memory_region.h | 5 ++ .../drm/i915/selftests/intel_memory_region.c | 77 +++++++++++++++++++ 3 files changed, 96 insertions(+)
drivers/gpu/drm/i915/intel_memory_region.c +14 -0
@@ -156,9 +156,22 @@ int intel_memory_region_init_buddy(struct intel_memory_region *mem)void intel_memory_region_release_buddy (struct intel_memory_region *mem) { +i915_buddy_free_list (&mem->mm, &mem->reserved);i915_buddy_fini (&mem->mm); } +int intel_memory_region_reserve (struct intel_memory_region *mem, +u64 offset,u64 size) +{ +int ret; + +mutex_lock (&mem->mm_lock); + ret =i915_buddy_alloc_range (&mem->mm, &mem->reserved, offset, size); +mutex_unlock (&mem->mm_lock); + +return ret; +} +struct intel_memory_region * intel_memory_region_create(struct drm_i915_private *i915, resource_size_t start,
@@ -185,6 +198,7 @@ intel_memory_region_create(struct drm_i915_private *i915,mutex_init (&mem->objects.lock);INIT_LIST_HEAD (&mem->objects.list);INIT_LIST_HEAD (&mem->objects.purgeable); +INIT_LIST_HEAD (&mem->reserved);mutex_init (&mem->mm_lock);
drivers/gpu/drm/i915/intel_memory_region.h +5 -0
@@ -89,6 +89,8 @@ struct intel_memory_region {unsigned int id;char name[8 ]; +struct list_head reserved; +dma_addr_t remap_addr;struct {
@@ -113,6 +115,9 @@ void __intel_memory_region_put_pages_buddy(struct intel_memory_region *mem, struct list_head *blocks);void __intel_memory_region_put_block_buddy (struct i915_buddy_block *block); +int intel_memory_region_reserve (struct intel_memory_region *mem, +u64 offset,u64 size); +struct intel_memory_region * intel_memory_region_create(struct drm_i915_private *i915, resource_size_t start,
drivers/gpu/drm/i915/selftests/intel_memory_region.c +77 -0
89 lines not on this page · raw message
Signature · 6 lines
2.26.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v4 3/8 drm/i915: reserve stolen for LMEM region
In reply to Matthew AuldFrom: CQ Tang <[email protected]>
The lmem region needs to remove the stolen part, which should just be a case of snipping it off the end.
--- drivers/gpu/drm/i915/gt/intel_region_lmem.c | 13 +++++++++---- drivers/gpu/drm/i915/i915_reg.h | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gt/intel_region_lmem.c +9 -4
@@ -146,20 +146,24 @@ intel_gt_setup_fake_lmem(struct intel_gt *gt)static struct intel_memory_region *setup_lmem (struct intel_gt *gt) {struct drm_i915_private *i915 = gt->i915; +struct intel_uncore *uncore = gt->uncore;struct pci_dev *pdev = i915->drm.pdev;struct intel_memory_region *mem;resource_size_t io_start; -resource_size_t size; +resource_size_t lmem_size;if (!IS_DGFX (i915))return ERR_PTR (-ENODEV ); +/* Stolen starts from GSMBASE on DG1 */ + lmem_size =intel_uncore_read64 (uncore,GEN12_GSMBASE ); + io_start =pci_resource_start (pdev,2 ); - size =pci_resource_len (pdev,2 ); +GEM_BUG_ON (lmem_size >pci_resource_len (pdev,2 )); mem =intel_memory_region_create (i915,0 , - size, + lmem_size,I915_GTT_PAGE_SIZE_4K , io_start, &intel_region_lmem_ops);
@@ -167,7 +171,8 @@ static struct intel_memory_region *setup_lmem(struct intel_gt *gt)drm_dbg (&i915->drm,"Local memory: %pR\n" , &mem->region);drm_dbg (&i915->drm,"Local memory IO start: %pa\n" , &mem->io_start); -drm_info (&i915->drm,"Local memory available: %pa\n" , &size); +drm_info (&i915->drm,"Local memory available: %pa\n" , + &lmem_size); }return mem;
drivers/gpu/drm/i915/i915_reg.h +2 -0
@@ -12160,6 +12160,8 @@ enum skl_power_gate {#define GEN12_GLOBAL_MOCS (i) _MMIO(0x4000 + (i) * 4)/* Global MOCS regs */ +#define GEN12_GSMBASE _MMIO(0x108100) +/* gamt regs */ #define GEN8_L3_LRA_1_GPGPU _MMIO(0x4dd4)#define GEN8_L3_LRA_1_GPGPU_DEFAULT_VALUE_BDW 0x67F1427F/* max/min for LRA1/2 */
Signature · 6 lines
2.26.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v4 5/8 drm/i915/dg1: Reserve first 1MB of local memory
In reply to Matthew AuldFrom: Imre Deak <[email protected]>
On DG1 A0/B0 steppings the first 1MB of local memory must be reserved. One reason for this is that the 0xA0000-0xB0000 range is not accessible by the display, probably since this region is redirected to another memory location for legacy VGA compatibility.
BSpec: 50586
Testcase: igt/kms_big_fb/linear-64bpp-rotate-0
v2:
- Reserve the memory on B0 as well.
v3: replace DRM_DEBUG/DRM_ERROR with drm_dbg/drm_err
v4: fix the insanity
--- drivers/gpu/drm/i915/gt/intel_region_lmem.c | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+)
drivers/gpu/drm/i915/gt/intel_region_lmem.c +45 -0
@@ -143,6 +143,41 @@ intel_gt_setup_fake_lmem(struct intel_gt *gt)return mem; } +static bool get_legacy_lowmem_region (struct intel_uncore *uncore, +u64 *start,u32 *size) +{ +if (!IS_DG1_REVID (uncore->i915,DG1_REVID_A0 ,DG1_REVID_B0 )) +return false; + + *start =0 ; + *size =SZ_1M ; + +drm_dbg (&uncore->i915->drm,"LMEM: reserved legacy low-memory [0x%llx-0x%llx]\n" , + *start, *start + *size); + +return true; +} + +static int reserve_lowmem_region (struct intel_uncore *uncore, +struct intel_memory_region *mem) +{ +u64 reserve_start; +u32 reserve_size; +int ret; + +if (!get_legacy_lowmem_region (uncore, &reserve_start, &reserve_size)) +return 0 ; + +if (!reserve_size) +return 0 ; + + ret =intel_memory_region_reserve (mem, reserve_start, reserve_size); +if (ret) +drm_err (&uncore->i915->drm,"LMEM: reserving low memory region failed\n" ); + +return ret; +} +static struct intel_memory_region *setup_lmem (struct intel_gt *gt) {struct drm_i915_private *i915 = gt->i915;
@@ -167,6 +202,16 @@ static struct intel_memory_region *setup_lmem(struct intel_gt *gt)I915_GTT_PAGE_SIZE_4K , io_start, &intel_region_lmem_ops); +if (!IS_ERR (mem)) { +int err; + + err =reserve_lowmem_region (uncore, mem); +if (err) { +intel_memory_region_put (mem); +return ERR_PTR (err); + } + } +if (!IS_ERR (mem)) {drm_dbg (&i915->drm,"Local memory: %pR\n" , &mem->region); drm_dbg(&i915->drm, "Local memory IO start: %pa\n",
Signature · 6 lines
2.26.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v4 8/8 drm/i915: allocate cmd ring in lmem
In reply to Matthew AuldFrom: Michel Thierry <[email protected]>
Prefer allocating the cmd ring from LMEM on dgfx.
--- drivers/gpu/drm/i915/gt/intel_ring.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_ring.c +3 -2
@@ -3,6 +3,7 @@* Copyright © 2019 Intel Corporation */ +#include "gem/i915_gem_lmem.h" #include "gem/i915_gem_object.h" #include "i915_drv.h"
@@ -108,8 +109,8 @@ static struct i915_vma *create_ring_vma(struct i915_ggtt *ggtt, int size)struct drm_i915_gem_object *obj;struct i915_vma *vma; - obj =ERR_PTR (-ENODEV ); -if (i915_ggtt_has_aperture (ggtt)) + obj =i915_gem_object_create_lmem (i915, size,I915_BO_ALLOC_VOLATILE ); +if (IS_ERR (obj) &&i915_ggtt_has_aperture (ggtt)) obj =i915_gem_object_create_stolen (i915, size);if (IS_ERR (obj)) obj =i915_gem_object_create_internal (i915, size);
Signature · 6 lines
2.26.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v4 6/8 drm/i915: allocate context from LMEM
In reply to Matthew AuldPrefer allocating the context from LMEM on dgfx.
Based on a patch from Michel Thierry.
v2: flatten the chain
--- drivers/gpu/drm/i915/gt/intel_lrc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/intel_lrc.c +5 -1
@@ -3,6 +3,8 @@* Copyright © 2014 Intel Corporation */ +#include "gem/i915_gem_lmem.h" +#include "gen8_engine_cs.h" #include "i915_drv.h" #include "i915_perf.h"
@@ -808,7 +810,9 @@ __lrc_alloc_state(struct intel_context *ce, struct intel_engine_cs *engine) context_size +=PAGE_SIZE ; } - obj =i915_gem_object_create_shmem (engine->i915, context_size); + obj =i915_gem_object_create_lmem (engine->i915, context_size,0 ); +if (IS_ERR (obj)) + obj =i915_gem_object_create_shmem (engine->i915, context_size);if (IS_ERR (obj))return ERR_CAST (obj);
Signature · 6 lines
2.26.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v4 7/8 drm/i915: move engine scratch to LMEM
In reply to Matthew AuldPrefer allocating the engine scratch from LMEM on dgfx.
v2: flatten the chain
--- drivers/gpu/drm/i915/gt/intel_gt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_gt.c +6 -2
@@ -4,6 +4,8 @@*/ #include "debugfs_gt.h" + +#include "gem/i915_gem_lmem.h" #include "i915_drv.h" #include "intel_context.h" #include "intel_gt.h"
@@ -378,11 +380,13 @@ static int intel_gt_init_scratch(struct intel_gt *gt, unsigned int size)struct i915_vma *vma;int ret; - obj =i915_gem_object_create_stolen (i915, size); + obj =i915_gem_object_create_lmem (i915, size,I915_BO_ALLOC_VOLATILE ); +if (IS_ERR (obj)) + obj =i915_gem_object_create_stolen (i915, size);if (IS_ERR (obj)) obj =i915_gem_object_create_internal (i915, size);if (IS_ERR (obj)) { -DRM_ERROR ("Failed to allocate scratch page\n" ); +drm_err (&i915->drm,"Failed to allocate scratch page\n" );return PTR_ERR (obj); }
Signature · 6 lines
2.26.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v4 2/8 drm/i915: setup the LMEM region
In reply to Matthew AuldHook up the LMEM region. Addresses will start from zero, and for CPU access we get LMEM_BAR which is just a 1:1 mapping of said region.
Based on a patch from Michel Thierry.
v2 by Jani:
- use intel_uncore_read/intel_uncore_write
- remove trailing blank line
v3: s/drm_info/drm_dbg for info which in non-pertinent for the user
--- drivers/gpu/drm/i915/gt/intel_gt.c | 4 ++- drivers/gpu/drm/i915/gt/intel_region_lmem.c | 35 +++++++++++++++++++++ drivers/gpu/drm/i915/gt/intel_region_lmem.h | 2 ++ 3 files changed, 40 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/intel_gt.c +3 -1
@@ -46,7 +46,9 @@ int intel_gt_probe_lmem(struct intel_gt *gt)int id;int err; - mem =intel_gt_setup_fake_lmem (gt); + mem =intel_gt_setup_lmem (gt); +if (mem ==ERR_PTR (-ENODEV )) + mem =intel_gt_setup_fake_lmem (gt);if (IS_ERR (mem)) { err =PTR_ERR (mem);if (err == -ENODEV )
drivers/gpu/drm/i915/gt/intel_region_lmem.c +35 -0
@@ -142,3 +142,38 @@ intel_gt_setup_fake_lmem(struct intel_gt *gt)return mem; } + +static struct intel_memory_region *setup_lmem (struct intel_gt *gt) +{ +struct drm_i915_private *i915 = gt->i915; +struct pci_dev *pdev = i915->drm.pdev; +struct intel_memory_region *mem; +resource_size_t io_start; +resource_size_t size; + +if (!IS_DGFX (i915)) +return ERR_PTR (-ENODEV ); + + io_start =pci_resource_start (pdev,2 ); + size =pci_resource_len (pdev,2 ); + + mem =intel_memory_region_create (i915, +0 , + size, +I915_GTT_PAGE_SIZE_4K , + io_start, + &intel_region_lmem_ops); +if (!IS_ERR (mem)) { +drm_dbg (&i915->drm,"Local memory: %pR\n" , &mem->region); +drm_dbg (&i915->drm,"Local memory IO start: %pa\n" , + &mem->io_start); +drm_info (&i915->drm,"Local memory available: %pa\n" , &size); + } + +return mem; +} + +struct intel_memory_region *intel_gt_setup_lmem (struct intel_gt *gt) +{ +return setup_lmem (gt); +}
drivers/gpu/drm/i915/gt/intel_region_lmem.h +2 -0
@@ -8,6 +8,8 @@struct intel_gt ; +struct intel_memory_region *intel_gt_setup_lmem (struct intel_gt *gt); +struct intel_memory_region *intel_gt_setup_fake_lmem (struct intel_gt *gt);
Signature · 6 lines
2.26.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH v4 5/8] drm/i915/dg1: Reserve first 1MB of local memory
In reply to Matthew AuldQuoting Matthew Auld (2021-01-27 12:48:06)
Quoted 48 lines
From: Imre Deak <[email protected]>
On DG1 A0/B0 steppings the first 1MB of local memory must be reserved. One reason for this is that the 0xA0000-0xB0000 range is not accessible by the display, probably since this region is redirected to another memory location for legacy VGA compatibility.
BSpec: 50586
Testcase: igt/kms_big_fb/linear-64bpp-rotate-0v2:
- Reserve the memory on B0 as well.v3: replace DRM_DEBUG/DRM_ERROR with drm_dbg/drm_err
v4: fix the insanity
Signed-off-by Imre Deak <[email protected]>Signed-off-by Matthew Auld <[email protected]>--- drivers/gpu/drm/i915/gt/intel_region_lmem.c | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+)drivers/gpu/drm/i915/gt/intel_region_lmem.c +17
-0@@ -143,6 +143,41 @@ intel_gt_setup_fake_lmem(struct intel_gt *gt)return mem; } +static bool get_legacy_lowmem_region (struct intel_uncore *uncore, +u64 *start,u32 *size) +{ +if (!IS_DG1_REVID (uncore->i915,DG1_REVID_A0 ,DG1_REVID_B0 )) +return false; + + *start =0 ; + *size =SZ_1M ; + +drm_dbg (&uncore->i915->drm,"LMEM: reserved legacy low-memory [0x%llx-0x%llx]\n" , + *start, *start + *size); + +return true; +} + +static int reserve_lowmem_region (struct intel_uncore *uncore, +struct intel_memory_region *mem)
drivers/gpu/drm/i915/gt/intel_region_lmem.c intel_gt_setup_fake_lmem(struct intel_gt *gt) · line 172
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_region_lmem.c +10
-0+{ +u64 reserve_start; +u32 reserve_size; +int ret; + +if (!get_legacy_lowmem_region (uncore, &reserve_start, &reserve_size)) +return 0 ; + +if (!reserve_size) +return 0 ;
We can remove this check now as well since we can be assured it is handled for us by get_legacy_lowmem_region()
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH v4 5/8] drm/i915/dg1: Reserve first 1MB of local memory
In reply to Matthew AuldQuoting Matthew Auld (2021-01-27 12:48:06)
Quoted 4 lines
static struct
intel_memory_region*setup_lmem(structintel_gt*gt){ struct drm_i915_private *i915 = gt->i915;
drivers/gpu/drm/i915/gt/intel_region_lmem.c static struct intel_memory_region *setup_lmem(struct intel_gt *gt) · line 211
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_region_lmem.c +7
-0@@ -167,6 +202,16 @@ static struct intel_memory_region *setup_lmem(struct intel_gt *gt)I915_GTT_PAGE_SIZE_4K , io_start, &intel_region_lmem_ops); +if (!IS_ERR (mem)) { +int err; + + err =reserve_lowmem_region (uncore, mem); +if (err) { +intel_memory_region_put (mem); +return ERR_PTR (err);
Just a worry here, are we likely to antagonise Joonas by having multiple error paths?
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx