Skip to contentSkip to conversation

drm/i915/dg2: Enabling 64k page size and flat ccs

PATCH Superseded Ramalingam C 6 participants 27 messages Oct 11, 2021 – Oct 14, 2021

Subsystems (4)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover drm/i915/dg2: Enabling 64k page size and flat ccs

This series introduces the enabling patches for new flat ccs feature and 64k page support for i915 local memory, along with documentation on the uAPI impact.

64k page support
================

On discrete platforms, starting from DG2, we have to contend with GTT page size restrictions when dealing with I915_MEMORY_CLASS_DEVICE objects. Specifically the hardware only supports 64K or larger GTT page sizes for such memory. The kernel will already ensure that all I915_MEMORY_CLASS_DEVICE memory is allocated using 64K or larger page sizes underneath.

Note that the returned size here will always reflect any required rounding up done by the kernel, i.e 4K will now become 64K on devices such as DG2. The GTT alignment will also need be at least 64K for such objects.

Note that due to how the hardware implements 64K GTT page support, we have some further complications:

1.) The entire PDE(which covers a 2M virtual address range), must contain only 64K PTEs, i.e mixing 4K and 64K PTEs in the same PDE is forbidden by the hardware.

2.) We still need to support 4K PTEs for I915_MEMORY_CLASS_SYSTEM objects.

To handle the above the kernel implements a memory coloring scheme to prevent userspace from mixing I915_MEMORY_CLASS_DEVICE and I915_MEMORY_CLASS_SYSTEM objects in the same PDE. If the kernel is ever unable to evict the required pages for the given PDE(different color) when inserting the object into the GTT then it will simply fail the request.

Since userspace needs to manage the GTT address space themselves, special care is needed to ensure this doesn’t happen. The simplest scheme is to simply align and round up all I915_MEMORY_CLASS_DEVICE objects to 2M, which avoids any issues here. At the very least this is likely needed for objects that can be placed in both I915_MEMORY_CLASS_DEVICE and I915_MEMORY_CLASS_SYSTEM, to avoid potential issues when the kernel needs to migrate the object behind the scenes, since that might also involve evicting other objects.

To summarise the GTT rules, on platforms like DG2:

1.) All objects that can be placed in I915_MEMORY_CLASS_DEVICE must have 64K alignment. The kernel will reject this otherwise.

2.) All I915_MEMORY_CLASS_DEVICE objects must never be placed in the same PDE with other I915_MEMORY_CLASS_SYSTEM objects. The kernel will reject this otherwise.

3.) Objects that can be placed in both I915_MEMORY_CLASS_DEVICE and I915_MEMORY_CLASS_SYSTEM should probably be aligned and padded out to 2M.

Flat CCS:
=========
Gen 12+ devices support 3D surfaces compression and compression formats. This is accomplished by an additional compression control state (CCS) stored for each surface.

Gen 12 devices(TGL and DG1) stores compression state in a separate region of memory. It is managed by userspace and has an associated set of userspace managed page tables used by hardware for address translation.

In Gen 12.5 devices(XEXPSDV and DG2) Flat CCS is introduced to replace the userspace managed AUX pagetable with the flat indexed region of device memory for storing the compression state

GOP Driver steals a chunk of memory for the CCS surface corresponding to the entire range of local memory. The memory required for the CCS of the entire local memory is 1/256 of the main local memory. The Gop driver will also program a secure register (XEHPSDV_FLAT_CCS_BASE_ADDR 0x4910) with this address value.

TODO: add patches for the flatccs modifiers and kdoc for them.

*** BLURB HERE ***

Abdiel Janulgue (1):
drm/i915/lmem: Enable lmem for platforms with Flat CCS

Ayaz A Siddiqui (1):
drm/i915/gt: Clear compress metadata for Gen12.5 >= platforms

Bommu Krishnaiah (1):
drm/i915: Add vm min alignment support

CQ Tang (1):
drm/i915/xehpsdv: Add has_flat_ccs to device info

Matthew Auld (8):
drm/i915/xehpsdv: set min page-size to 64K drm/i915/xehpsdv: enforce min GTT alignment drm/i915: enforce min page size for scratch drm/i915/gtt/xehpsdv: move scratch page to system memory drm/i915/xehpsdv: support 64K GTT pages drm/i915/selftests: account for min_alignment in GTT selftests drm/i915/xehpsdv: implement memory coloring drm/i915/uapi: document behaviour for DG2 64K support

Ramalingam C (1):
Doc/gpu/rfc/i915: i915 DG2 uAPI

Stuart Summers (1):
drm/i915: Add has_64k_pages flag

 Documentation/gpu/rfc/i915_dg2.rst            |  47 ++++++
 Documentation/gpu/rfc/index.rst               |   3 +
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c    |   6 +-
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |  61 ++++++++
 .../i915/gem/selftests/i915_gem_client_blt.c  |  23 ++-
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c          |   1 +
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c          | 145 +++++++++++++++++-
 drivers/gpu/drm/i915/gt/intel_ggtt.c          |   2 +
 drivers/gpu/drm/i915/gt/intel_gpu_commands.h  |  14 ++
 drivers/gpu/drm/i915/gt/intel_gt.c            |  19 +++
 drivers/gpu/drm/i915/gt/intel_gt.h            |   1 +
 drivers/gpu/drm/i915/gt/intel_gtt.c           |  23 ++-
 drivers/gpu/drm/i915/gt/intel_gtt.h           |  20 +++
 drivers/gpu/drm/i915/gt/intel_migrate.c       | 120 ++++++++++++++-
 drivers/gpu/drm/i915/gt/intel_ppgtt.c         |   1 +
 drivers/gpu/drm/i915/gt/intel_region_lmem.c   |  27 +++-
 drivers/gpu/drm/i915/i915_drv.h               |   4 +
 drivers/gpu/drm/i915/i915_gem_evict.c         |  17 ++
 drivers/gpu/drm/i915/i915_pci.c               |   3 +
 drivers/gpu/drm/i915/i915_reg.h               |   3 +
 drivers/gpu/drm/i915/i915_vma.c               |  55 +++++--
 drivers/gpu/drm/i915/intel_device_info.h      |   2 +
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  96 ++++++++----
 drivers/gpu/drm/i915/selftests/mock_gtt.c     |   2 +
 include/uapi/drm/i915_drm.h                   |  61 +++++++-
 25 files changed, 681 insertions(+), 75 deletions(-)
 create mode 100644 Documentation/gpu/rfc/i915_dg2.rst
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/14 drm/i915: Add has_64k_pages flag

From: Stuart Summers <[email protected]>

Add a new platform flag, has_64k_pages, for platforms supporting base page sizes of 64k.

---
 drivers/gpu/drm/i915/i915_drv.h          | 2 ++
 drivers/gpu/drm/i915/i915_pci.c          | 2 ++
 drivers/gpu/drm/i915/intel_device_info.h | 1 +
 3 files changed, 5 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 12256218634f..a16fde38a252 100644
@@ -1714,6 +1714,8 @@ IS_SUBPLATFORM(const struct drm_i915_private *i915,
 #define HAS_MSLICES(dev_priv) \
 	(INTEL_INFO(dev_priv)->has_mslices)
 
+#define HAS_64K_PAGES(dev_priv) (INTEL_INFO(dev_priv)->has_64k_pages)
+
 #define HAS_IPC(dev_priv)		 (INTEL_INFO(dev_priv)->display.has_ipc)
 
 #define HAS_REGION(i915, i) (INTEL_INFO(i915)->memory_regions & (i))
drivers/gpu/drm/i915/i915_pci.c +2 -0
index 169837de395d..8ef484a23652 100644
@@ -1015,6 +1015,7 @@ static const struct intel_device_info xehpsdv_info = {
 	DGFX_FEATURES,
 	PLATFORM(INTEL_XEHPSDV),
 	.display = { },
+	.has_64k_pages = 1,
 	.pipe_mask = 0,
 	.platform_engine_mask =
 		BIT(RCS0) | BIT(BCS0) |
@@ -1033,6 +1034,7 @@ static const struct intel_device_info dg2_info = {
 	.graphics_rel = 55,
 	.media_rel = 55,
 	PLATFORM(INTEL_DG2),
+	.has_64k_pages = 1,
 	.platform_engine_mask =
 		BIT(RCS0) | BIT(BCS0) |
 		BIT(VECS0) | BIT(VECS1) |
drivers/gpu/drm/i915/intel_device_info.h +1 -0
index 8e6f48d1eb7b..dd453b96af19 100644
@@ -123,6 +123,7 @@ enum intel_ppgtt_type {
 	func(is_dgfx); \
 	/* Keep has_* in alphabetical order */ \
 	func(has_64bit_reloc); \
+	func(has_64k_pages); \
 	func(gpu_reset_clobbers_display); \
 	func(has_reset_engine); \
 	func(has_global_mocs); \
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/14 drm/i915/xehpsdv: set min page-size to 64K

In reply to Ramalingam C

From: Matthew Auld <[email protected]>

LMEM should be allocated at 64K granularity, since 4K page support will eventually be dropped for LMEM when using the PPGTT.

---
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c  | 6 +++++-
 drivers/gpu/drm/i915/gt/intel_region_lmem.c | 5 ++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +5 -1
index ddd37ccb1362..f52a06f05fc7 100644
@@ -778,6 +778,7 @@ i915_gem_stolen_lmem_setup(struct drm_i915_private *i915, u16 type,
 	struct intel_uncore *uncore = &i915->uncore;
 	struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
 	struct intel_memory_region *mem;
+	resource_size_t min_page_size;
 	resource_size_t io_start;
 	resource_size_t lmem_size;
 	u64 lmem_base;
@@ -789,8 +790,11 @@ i915_gem_stolen_lmem_setup(struct drm_i915_private *i915, u16 type,
 	lmem_size = pci_resource_len(pdev, 2) - lmem_base;
 	io_start = pci_resource_start(pdev, 2) + lmem_base;
 
+	min_page_size = HAS_64K_PAGES(i915) ? I915_GTT_PAGE_SIZE_64K :
+						I915_GTT_PAGE_SIZE_4K;
+
 	mem = intel_memory_region_create(i915, lmem_base, lmem_size,
-					 I915_GTT_PAGE_SIZE_4K, io_start,
+					 min_page_size, io_start,
 					 type, instance,
 					 &i915_region_stolen_lmem_ops);
 	if (IS_ERR(mem))
drivers/gpu/drm/i915/gt/intel_region_lmem.c +4 -1
index afb35d2e5c73..073d28d96669 100644
@@ -193,6 +193,7 @@ static struct intel_memory_region *setup_lmem(struct intel_gt *gt)
 	struct intel_uncore *uncore = gt->uncore;
 	struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
 	struct intel_memory_region *mem;
+	resource_size_t min_page_size;
 	resource_size_t io_start;
 	resource_size_t lmem_size;
 	int err;
@@ -207,10 +208,12 @@ static struct intel_memory_region *setup_lmem(struct intel_gt *gt)
 	if (GEM_WARN_ON(lmem_size > pci_resource_len(pdev, 2)))
 		return ERR_PTR(-ENODEV);
 
+	min_page_size = HAS_64K_PAGES(i915) ? I915_GTT_PAGE_SIZE_64K :
+						I915_GTT_PAGE_SIZE_4K;
 	mem = intel_memory_region_create(i915,
 					 0,
 					 lmem_size,
-					 I915_GTT_PAGE_SIZE_4K,
+					 min_page_size,
 					 io_start,
 					 INTEL_MEMORY_LOCAL,
 					 0,
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/14 drm/i915/xehpsdv: enforce min GTT alignment

In reply to Ramalingam C

From: Matthew Auld <[email protected]>

For local-memory objects we need to align the GTT addresses to 64K, both for the ppgtt and ggtt.

---
 drivers/gpu/drm/i915/i915_vma.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_vma.c +7 -2
index 4b7fc4647e46..1ea1fa08efdf 100644
@@ -670,8 +670,13 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
 	}
 
 	color = 0;
-	if (vma->obj && i915_vm_has_cache_coloring(vma->vm))
-		color = vma->obj->cache_level;
+	if (vma->obj) {
+		if (HAS_64K_PAGES(vma->vm->i915) && i915_gem_object_is_lmem(vma->obj))
+			alignment = max(alignment, I915_GTT_PAGE_SIZE_64K);
+
+		if (i915_vm_has_cache_coloring(vma->vm))
+			color = vma->obj->cache_level;
+	}
 
 	if (flags & PIN_OFFSET_FIXED) {
 		u64 offset = flags & PIN_OFFSET_MASK;
Signature · 1 line
2.20.1
#4 lore raw

Re: [PATCH 03/14] drm/i915/xehpsdv: enforce min GTT alignment

Quoted 10 lines · Ramalingam C

From: Matthew Auld <[email protected]>

For local-memory objects we need to align the GTT addresses to 64K, both for the ppgtt and ggtt.

Do we still need this with relocations removed? Userspace is picking all the addresses for us, so all we have to check is whether userspace got it right.
-Daniel

Quoted 27 lines
---
 drivers/gpu/drm/i915/i915_vma.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_vma.c +7 -2
index 4b7fc4647e46..1ea1fa08efdf 100644
@@ -670,8 +670,13 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
 	}
 
 	color = 0;
-	if (vma->obj && i915_vm_has_cache_coloring(vma->vm))
-		color = vma->obj->cache_level;
+	if (vma->obj) {
+		if (HAS_64K_PAGES(vma->vm->i915) && i915_gem_object_is_lmem(vma->obj))
+			alignment = max(alignment, I915_GTT_PAGE_SIZE_64K);
+
+		if (i915_vm_has_cache_coloring(vma->vm))
+			color = vma->obj->cache_level;
+	}
 
 	if (flags & PIN_OFFSET_FIXED) {
 		u64 offset = flags & PIN_OFFSET_MASK;
Signature · 1 line
2.20.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#5 lore raw

Re: [PATCH 03/14] drm/i915/xehpsdv: enforce min GTT alignment

Quoted 12 lines · Daniel Vetter
Quoted 10 lines · Ramalingam C

From: Matthew Auld <[email protected]>

For local-memory objects we need to align the GTT addresses to 64K, both for the ppgtt and ggtt.

Quoted 3 lines

Do we still need this with relocations removed? Userspace is picking all the addresses for us, so all we have to check is whether userspace got it right.

Yeah, for OFFSET_FIXED this just validates that the provided address is correctly aligned to 64K, while for the in-kernel insertion stuff we still need to allocate an address that is aligned to 64K. Setting the alignment here handles both cases.

Quoted 31 lines

-Daniel

Quoted 27 lines
---
  drivers/gpu/drm/i915/i915_vma.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_vma.c +7 -2
index 4b7fc4647e46..1ea1fa08efdf 100644
@@ -670,8 +670,13 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
  	}
 
  	color = 0;
-	if (vma->obj && i915_vm_has_cache_coloring(vma->vm))
-		color = vma->obj->cache_level;
+	if (vma->obj) {
+		if (HAS_64K_PAGES(vma->vm->i915) && i915_gem_object_is_lmem(vma->obj))
+			alignment = max(alignment, I915_GTT_PAGE_SIZE_64K);
+
+		if (i915_vm_has_cache_coloring(vma->vm))
+			color = vma->obj->cache_level;
+	}
 
  	if (flags & PIN_OFFSET_FIXED) {
  		u64 offset = flags & PIN_OFFSET_MASK;
Signature · 1 line
2.20.1
#6 lore raw

Re: [PATCH 03/14] drm/i915/xehpsdv: enforce min GTT alignment

Quoted 13 lines · Matthew Auld
Quoted 12 lines · Daniel Vetter
Quoted 10 lines · Ramalingam C

From: Matthew Auld <[email protected]>

For local-memory objects we need to align the GTT addresses to 64K, both for the ppgtt and ggtt.

Quoted 8 lines
Quoted 3 lines

Do we still need this with relocations removed? Userspace is picking all the addresses for us, so all we have to check is whether userspace got it right.

Yeah, for OFFSET_FIXED this just validates that the provided address is correctly aligned to 64K, while for the in-kernel insertion stuff we still need to allocate an address that is aligned to 64K. Setting the alignment here handles both cases.

Can't we just teach any in-kernel allocators to align to 2M and call it a day? Ofc the code can still validate we don't have bugs (always good to check your work). Ofc if the benefits is "no code can be removed anyway since we still need to check" then ofc no point :-)

Just want to make sure we're not carrying complexity around for nothing, since this predates the relocation removal.
-Daniel

Quoted 30 lines
Quoted 30 lines

-Daniel

Quoted 25 lines
---
  drivers/gpu/drm/i915/i915_vma.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_vma.c +7 -2
index 4b7fc4647e46..1ea1fa08efdf 100644
@@ -670,8 +670,13 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
  	}
  	color = 0;
-	if (vma->obj && i915_vm_has_cache_coloring(vma->vm))
-		color = vma->obj->cache_level;
+	if (vma->obj) {
+		if (HAS_64K_PAGES(vma->vm->i915) && i915_gem_object_is_lmem(vma->obj))
+			alignment = max(alignment, I915_GTT_PAGE_SIZE_64K);
+
+		if (i915_vm_has_cache_coloring(vma->vm))
+			color = vma->obj->cache_level;
+	}
  	if (flags & PIN_OFFSET_FIXED) {
  		u64 offset = flags & PIN_OFFSET_MASK;
Signature · 1 line
2.20.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#7 lore raw

Re: [PATCH 03/14] drm/i915/xehpsdv: enforce min GTT alignment

Quoted 23 lines · Daniel Vetter
Quoted 13 lines · Matthew Auld
Quoted 12 lines · Daniel Vetter
Quoted 10 lines · Ramalingam C

From: Matthew Auld <[email protected]>

For local-memory objects we need to align the GTT addresses to 64K, both for the ppgtt and ggtt.

Quoted 8 lines
Quoted 3 lines

Do we still need this with relocations removed? Userspace is picking all the addresses for us, so all we have to check is whether userspace got it right.

Yeah, for OFFSET_FIXED this just validates that the provided address is correctly aligned to 64K, while for the in-kernel insertion stuff we still need to allocate an address that is aligned to 64K. Setting the alignment here handles both cases.

Quoted 4 lines

Can't we just teach any in-kernel allocators to align to 2M and call it a day? Ofc the code can still validate we don't have bugs (always good to check your work). Ofc if the benefits is "no code can be removed anyway since we still need to check" then ofc no point :-)

Yeah, if we want to make it 2M, then we still need to add that here, like with 64K.

Quoted 3 lines

Just want to make sure we're not carrying complexity around for nothing, since this predates the relocation removal.

If we were to just make everything 2M then we can in theory ditch all the colouring stuff. Assuming userspace is happy with 2M or nothing, then it just means potentially terrible utilisation of the ppGTT for the kernel, but maybe that doesn't matter much really? For userspace maybe they will have some kind of sub-allocation scheme?

Well actually I guess it would be 2M alignment + 2M vma padding for anything that can be placed in I915_MEMORY_CLASS_DEVICE, including mixed objects. And then the usual 4K alignment for I915_MEMORY_CLASS_SYSTEM only objects.

Quoted 33 lines

-Daniel

Quoted 30 lines
Quoted 30 lines

-Daniel

Quoted 25 lines
---
   drivers/gpu/drm/i915/i915_vma.c | 9 +++++++--
   1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_vma.c +7 -2
index 4b7fc4647e46..1ea1fa08efdf 100644
@@ -670,8 +670,13 @@ i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
   	}
   	color = 0;
-	if (vma->obj && i915_vm_has_cache_coloring(vma->vm))
-		color = vma->obj->cache_level;
+	if (vma->obj) {
+		if (HAS_64K_PAGES(vma->vm->i915) && i915_gem_object_is_lmem(vma->obj))
+			alignment = max(alignment, I915_GTT_PAGE_SIZE_64K);
+
+		if (i915_vm_has_cache_coloring(vma->vm))
+			color = vma->obj->cache_level;
+	}
   	if (flags & PIN_OFFSET_FIXED) {
   		u64 offset = flags & PIN_OFFSET_MASK;
Signature · 1 line
2.20.1
#8 lore raw

PATCH 4/14 drm/i915: enforce min page size for scratch

In reply to Ramalingam C

From: Matthew Auld <[email protected]>

If the device needs 64K minimum GTT pages for device local-memory, like on XEHPSDV, then we need to fail the allocation if we can't meet it, instead of falling back to 4K pages, otherwise we can't safely support the insertion of device local-memory pages for this vm, since the HW expects the correct physical alignment and size for every PTE, if we mark the page-table as 64K GTT mode.

---
 drivers/gpu/drm/i915/gt/intel_gtt.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/i915/gt/intel_gtt.c +12 -0
index 67d14afa6623..2a6eec5f0d58 100644
@@ -334,6 +334,18 @@ int setup_scratch_page(struct i915_address_space *vm)
 		if (size == I915_GTT_PAGE_SIZE_4K)
 			return -ENOMEM;
 
+		/*
+		 * If we need 64K minimum GTT pages for device local-memory,
+		 * like on XEHPSDV, then we need to fail the allocation here,
+		 * otherwise we can't safely support the insertion of
+		 * local-memory pages for this vm, since the HW expects the
+		 * correct physical alignment and size when the page-table is
+		 * operating in 64K GTT mode, which includes any scratch PTEs,
+		 * since userpsace can still touch them.
+		 */
+		if (HAS_64K_PAGES(vm->i915))
+			return -ENOMEM;
+
 		size = I915_GTT_PAGE_SIZE_4K;
 	} while (1);
 }
Signature · 1 line
2.20.1
#9 lore raw

PATCH 5/14 drm/i915/gtt/xehpsdv: move scratch page to system memory

In reply to Ramalingam C

From: Matthew Auld <[email protected]>

On some platforms the hw has dropped support for 4K GTT pages when dealing with LMEM, and due to the design of 64K GTT pages in the hw, we can only mark the *entire* page-table as operating in 64K GTT mode, since the enable bit is still on the pde, and not the pte. And since we we still need to allow 4K GTT pages for SMEM objects, we can't have a "normal" 4K page-table with scratch pointing to LMEM, since that's undefined from the hw pov. The simplest solution is to just move the 64K scratch page to SMEM on such platforms and call it a day, since that should work for all configurations.

---
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c      |  1 +
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c      | 23 +++++++++++++++++++++--
 drivers/gpu/drm/i915/gt/intel_ggtt.c      |  2 ++
 drivers/gpu/drm/i915/gt/intel_gtt.c       |  2 +-
 drivers/gpu/drm/i915/gt/intel_gtt.h       |  2 ++
 drivers/gpu/drm/i915/selftests/mock_gtt.c |  2 ++
 6 files changed, 29 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/gen6_ppgtt.c +1 -0
index 890191f286e3..49e7651d764a 100644
@@ -440,6 +440,7 @@ struct i915_ppgtt *gen6_ppgtt_create(struct intel_gt *gt)
 	ppgtt->base.vm.cleanup = gen6_ppgtt_cleanup;
 
 	ppgtt->base.vm.alloc_pt_dma = alloc_pt_dma;
+	ppgtt->base.vm.alloc_scratch_dma = alloc_pt_dma;
 	ppgtt->base.vm.pte_encode = ggtt->vm.pte_encode;
 
 	ppgtt->base.pd = __alloc_pd(I915_PDES);
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +21 -2
index 037a9a6e4889..6bff6bf1a450 100644
@@ -777,10 +777,29 @@ struct i915_ppgtt *gen8_ppgtt_create(struct intel_gt *gt,
 	 */
 	ppgtt->vm.has_read_only = !IS_GRAPHICS_VER(gt->i915, 11, 12);
 
-	if (HAS_LMEM(gt->i915))
+	if (HAS_LMEM(gt->i915)) {
 		ppgtt->vm.alloc_pt_dma = alloc_pt_lmem;
-	else
+
+		/*
+		 * On some platforms the hw has dropped support for 4K GTT pages
+		 * when dealing with LMEM, and due to the design of 64K GTT
+		 * pages in the hw, we can only mark the *entire* page-table as
+		 * operating in 64K GTT mode, since the enable bit is still on
+		 * the pde, and not the pte. And since we still need to allow
+		 * 4K GTT pages for SMEM objects, we can't have a "normal" 4K
+		 * page-table with scratch pointing to LMEM, since that's
+		 * undefined from the hw pov. The simplest solution is to just
+		 * move the 64K scratch page to SMEM on such platforms and call
+		 * it a day, since that should work for all configurations.
+		 */
+		if (HAS_64K_PAGES(gt->i915))
+			ppgtt->vm.alloc_scratch_dma = alloc_pt_dma;
+		else
+			ppgtt->vm.alloc_scratch_dma = alloc_pt_lmem;
+	} else {
 		ppgtt->vm.alloc_pt_dma = alloc_pt_dma;
+		ppgtt->vm.alloc_scratch_dma = alloc_pt_dma;
+	}
 
 	err = gen8_init_scratch(&ppgtt->vm);
 	if (err)
drivers/gpu/drm/i915/gt/intel_ggtt.c +2 -0
index f17383e76eb7..289316007029 100644
@@ -1077,6 +1077,7 @@ static int gen6_gmch_probe(struct i915_ggtt *ggtt)
 	ggtt->vm.total = (size / sizeof(gen6_pte_t)) * I915_GTT_PAGE_SIZE;
 
 	ggtt->vm.alloc_pt_dma = alloc_pt_dma;
+	ggtt->vm.alloc_scratch_dma = alloc_pt_dma;
 
 	ggtt->vm.clear_range = nop_clear_range;
 	if (!HAS_FULL_PPGTT(i915) || intel_scanout_needs_vtd_wa(i915))
@@ -1129,6 +1130,7 @@ static int i915_gmch_probe(struct i915_ggtt *ggtt)
 		(struct resource)DEFINE_RES_MEM(gmadr_base, ggtt->mappable_end);
 
 	ggtt->vm.alloc_pt_dma = alloc_pt_dma;
+	ggtt->vm.alloc_scratch_dma = alloc_pt_dma;
 
 	if (needs_idle_maps(i915)) {
 		drm_notice(&i915->drm,
drivers/gpu/drm/i915/gt/intel_gtt.c +1 -1
index 2a6eec5f0d58..56fbd37a6b54 100644
@@ -298,7 +298,7 @@ int setup_scratch_page(struct i915_address_space *vm)
 	do {
 		struct drm_i915_gem_object *obj;
 
-		obj = vm->alloc_pt_dma(vm, size);
+		obj = vm->alloc_scratch_dma(vm, size);
 		if (IS_ERR(obj))
 			goto skip;
 
drivers/gpu/drm/i915/gt/intel_gtt.h +2 -0
index bc6750263359..6d13f4ab4d4a 100644
@@ -265,6 +265,8 @@ struct i915_address_space {
 
 	struct drm_i915_gem_object *
 		(*alloc_pt_dma)(struct i915_address_space *vm, int sz);
+	struct drm_i915_gem_object *
+		(*alloc_scratch_dma)(struct i915_address_space *vm, int sz);
 
 	u64 (*pte_encode)(dma_addr_t addr,
 			  enum i915_cache_level level,
drivers/gpu/drm/i915/selftests/mock_gtt.c +2 -0
index cc047ec594f9..32ca8962d0ab 100644
@@ -78,6 +78,7 @@ struct i915_ppgtt *mock_ppgtt(struct drm_i915_private *i915, const char *name)
 	i915_address_space_init(&ppgtt->vm, VM_CLASS_PPGTT);
 
 	ppgtt->vm.alloc_pt_dma = alloc_pt_dma;
+	ppgtt->vm.alloc_scratch_dma = alloc_pt_dma;
 
 	ppgtt->vm.clear_range = mock_clear_range;
 	ppgtt->vm.insert_page = mock_insert_page;
@@ -118,6 +119,7 @@ void mock_init_ggtt(struct drm_i915_private *i915, struct i915_ggtt *ggtt)
 	ggtt->vm.total = 4096 * PAGE_SIZE;
 
 	ggtt->vm.alloc_pt_dma = alloc_pt_dma;
+	ggtt->vm.alloc_scratch_dma = alloc_pt_dma;
 
 	ggtt->vm.clear_range = mock_clear_range;
 	ggtt->vm.insert_page = mock_insert_page;
Signature · 1 line
2.20.1
#10 lore raw

PATCH 6/14 drm/i915/xehpsdv: support 64K GTT pages

In reply to Ramalingam C

From: Matthew Auld <[email protected]>

XEHPSDV optimises 64K GTT pages for local-memory, since everything should be allocated at 64K granularity. We say goodbye to sparse entries, and instead get a compact 256B page-table for 64K pages, which should be more cache friendly. 4K pages for local-memory are no longer supported by the HW.

---
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |  61 ++++++++++
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c          | 106 +++++++++++++++++-
 drivers/gpu/drm/i915/gt/intel_gtt.h           |   3 +
 drivers/gpu/drm/i915/gt/intel_ppgtt.c         |   1 +
 4 files changed, 168 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gem/selftests/huge_pages.c +61 -0
index 41d0680f3bd7..9c2ffa4090f1 100644
@@ -1451,6 +1451,66 @@ static int igt_ppgtt_sanity_check(void *arg)
 	return err;
 }
 
+static int igt_ppgtt_compact(void *arg)
+{
+	struct i915_gem_context *ctx = arg;
+	struct drm_i915_private *i915 = ctx->i915;
+	struct drm_i915_gem_object *obj;
+	int err;
+
+	/*
+	 * Simple test to catch issues with compact 64K pages -- since the pt is
+	 * compacted to 256B that gives us 32 entries per pt, however since the
+	 * backing page for the pt is 4K, any extra entries we might incorrectly
+	 * write out should be ignored by the HW. If ever hit such a case this
+	 * test should catch it since some of our writes would land in scratch.
+	 */
+
+	if (!HAS_64K_PAGES(i915)) {
+		pr_info("device lacks compact 64K page support, skipping\n");
+		return 0;
+	}
+
+	if (!HAS_LMEM(i915)) {
+		pr_info("device lacks LMEM support, skipping\n");
+		return 0;
+	}
+
+	/* We want the range to cover multiple page-table boundaries. */
+	obj = i915_gem_object_create_lmem(i915, SZ_4M, 0);
+	if (IS_ERR(obj))
+		return err;
+
+	err = i915_gem_object_pin_pages_unlocked(obj);
+	if (err)
+		goto out_put;
+
+	if (obj->mm.page_sizes.phys < I915_GTT_PAGE_SIZE_64K) {
+		pr_info("LMEM compact unable to allocate huge-page(s)\n");
+		goto out_unpin;
+	}
+
+	/*
+	 * Disable 2M GTT pages by forcing the page-size to 64K for the GTT
+	 * insertion.
+	 */
+	obj->mm.page_sizes.sg = I915_GTT_PAGE_SIZE_64K;
+
+	err = igt_write_huge(ctx, obj);
+	if (err)
+		pr_err("LMEM compact write-huge failed\n");
+
+out_unpin:
+	i915_gem_object_unpin_pages(obj);
+out_put:
+	i915_gem_object_put(obj);
+
+	if (err == -ENOMEM)
+		err = 0;
+
+	return err;
+}
+
 static int igt_tmpfs_fallback(void *arg)
 {
 	struct i915_gem_context *ctx = arg;
@@ -1681,6 +1741,7 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *i915)
 		SUBTEST(igt_tmpfs_fallback),
 		SUBTEST(igt_ppgtt_smoke_huge),
 		SUBTEST(igt_ppgtt_sanity_check),
+		SUBTEST(igt_ppgtt_compact),
 	};
 	struct i915_gem_context *ctx;
 	struct i915_address_space *vm;
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +103 -3

132 lines not on this page · raw message

drivers/gpu/drm/i915/gt/intel_gtt.h +3 -0
index 6d13f4ab4d4a..6d0233ffae17 100644
@@ -89,6 +89,8 @@ typedef u64 gen8_pte_t;
 
 #define GEN12_GGTT_PTE_LM	BIT_ULL(1)
 
+#define GEN12_PDE_64K BIT(6)
+
 /*
  * Cacheability Control is a 4-bit value. The low three bits are stored in bits
  * 3:1 of the PTE, while the fourth bit is stored in bit 11 of the PTE.
@@ -154,6 +156,7 @@ struct i915_page_table {
 		atomic_t used;
 		struct i915_page_table *stash;
 	};
+	bool is_compact;
 };
 
 struct i915_page_directory {
drivers/gpu/drm/i915/gt/intel_ppgtt.c +1 -0
index 4396bfd630d8..b8238f5bc8b1 100644
@@ -26,6 +26,7 @@ struct i915_page_table *alloc_pt(struct i915_address_space *vm)
 		return ERR_PTR(-ENOMEM);
 	}
 
+	pt->is_compact = false;
 	atomic_set(&pt->used, 0);
 	return pt;
 }
Signature · 1 line
2.20.1
#11 lore raw

PATCH 7/14 drm/i915: Add vm min alignment support

In reply to Ramalingam C

From: Bommu Krishnaiah <[email protected]>

Replace the hard coded 4K alignment value with vm->min_alignment.

---
 .../i915/gem/selftests/i915_gem_client_blt.c  | 23 ++++++++++++-------
 drivers/gpu/drm/i915/gt/intel_gtt.c           |  9 ++++++++
 drivers/gpu/drm/i915/gt/intel_gtt.h           |  9 ++++++++
 3 files changed, 33 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_client_blt.c +15 -8
index ecbcbb86ae1e..30c8d64df3b8 100644
@@ -32,6 +32,7 @@ struct tiled_blits {
 	struct blit_buffer scratch;
 	struct i915_vma *batch;
 	u64 hole;
+	u64 align;
 	u32 width;
 	u32 height;
 };
@@ -403,14 +404,21 @@ tiled_blits_create(struct intel_engine_cs *engine, struct rnd_state *prng)
 		goto err_free;
 	}
 
-	hole_size = 2 * PAGE_ALIGN(WIDTH * HEIGHT * 4);
+	t->align = I915_GTT_PAGE_SIZE_2M; /* XXX worst case, derive from vm! */
+	t->align = max(t->align,
+		       i915_vm_min_alignment(t->ce->vm, INTEL_MEMORY_LOCAL));
+	t->align = max(t->align,
+		       i915_vm_min_alignment(t->ce->vm, INTEL_MEMORY_SYSTEM));
+
+	hole_size = 2 * round_up(WIDTH * HEIGHT * 4, t->align);
 	hole_size *= 2; /* room to maneuver */
-	hole_size += 2 * I915_GTT_MIN_ALIGNMENT;
+	hole_size += 2 * t->align; /* padding on either side */
 
 	mutex_lock(&t->ce->vm->mutex);
 	memset(&hole, 0, sizeof(hole));
 	err = drm_mm_insert_node_in_range(&t->ce->vm->mm, &hole,
-					  hole_size, 0, I915_COLOR_UNEVICTABLE,
+					  hole_size, t->align,
+					  I915_COLOR_UNEVICTABLE,
 					  0, U64_MAX,
 					  DRM_MM_INSERT_BEST);
 	if (!err)
@@ -421,7 +429,7 @@ tiled_blits_create(struct intel_engine_cs *engine, struct rnd_state *prng)
 		goto err_put;
 	}
 
-	t->hole = hole.start + I915_GTT_MIN_ALIGNMENT;
+	t->hole = hole.start + t->align;
 	pr_info("Using hole at %llx\n", t->hole);
 
 	err = tiled_blits_create_buffers(t, WIDTH, HEIGHT, prng);
@@ -448,7 +456,7 @@ static void tiled_blits_destroy(struct tiled_blits *t)
 static int tiled_blits_prepare(struct tiled_blits *t,
 			       struct rnd_state *prng)
 {
-	u64 offset = PAGE_ALIGN(t->width * t->height * 4);
+	u64 offset = round_up(t->width * t->height * 4, t->align);
 	u32 *map;
 	int err;
 	int i;
@@ -479,8 +487,7 @@ static int tiled_blits_prepare(struct tiled_blits *t,
 
 static int tiled_blits_bounce(struct tiled_blits *t, struct rnd_state *prng)
 {
-	u64 offset =
-		round_up(t->width * t->height * 4, 2 * I915_GTT_MIN_ALIGNMENT);
+	u64 offset = round_up(t->width * t->height * 4, 2 * t->align);
 	int err;
 
 	/* We want to check position invariant tiling across GTT eviction */
@@ -493,7 +500,7 @@ static int tiled_blits_bounce(struct tiled_blits *t, struct rnd_state *prng)
 
 	/* Reposition so that we overlap the old addresses, and slightly off */
 	err = tiled_blit(t,
-			 &t->buffers[2], t->hole + I915_GTT_MIN_ALIGNMENT,
+			 &t->buffers[2], t->hole + t->align,
 			 &t->buffers[1], t->hole + 3 * offset / 2);
 	if (err)
 		return err;
drivers/gpu/drm/i915/gt/intel_gtt.c +9 -0
index 56fbd37a6b54..4743921b7638 100644
@@ -216,6 +216,15 @@ void i915_address_space_init(struct i915_address_space *vm, int subclass)
 
 	GEM_BUG_ON(!vm->total);
 	drm_mm_init(&vm->mm, 0, vm->total);
+
+	memset64(vm->min_alignment, I915_GTT_MIN_ALIGNMENT,
+		 ARRAY_SIZE(vm->min_alignment));
+
+	if (HAS_64K_PAGES(vm->i915)) {
+		vm->min_alignment[INTEL_MEMORY_LOCAL] = I915_GTT_PAGE_SIZE_64K;
+		vm->min_alignment[INTEL_MEMORY_STOLEN_LOCAL] = I915_GTT_PAGE_SIZE_64K;
+	}
+
 	vm->mm.head_node.color = I915_COLOR_UNEVICTABLE;
 
 	INIT_LIST_HEAD(&vm->bound_list);
drivers/gpu/drm/i915/gt/intel_gtt.h +9 -0
index 6d0233ffae17..20101eef4c95 100644
@@ -28,6 +28,8 @@
 #include "gt/intel_reset.h"
 #include "i915_selftest.h"
 #include "i915_vma_types.h"
+#include "i915_params.h"
+#include "intel_memory_region.h"
 
 #define I915_GFP_ALLOW_FAIL (GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN)
 
@@ -224,6 +226,7 @@ struct i915_address_space {
 	struct device *dma;
 	u64 total;		/* size addr space maps (ex. 2GB for ggtt) */
 	u64 reserved;		/* size addr space reserved */
+	u64 min_alignment[INTEL_MEMORY_STOLEN_LOCAL + 1];
 
 	unsigned int bind_async_flags;
 
@@ -382,6 +385,12 @@ i915_vm_has_scratch_64K(struct i915_address_space *vm)
 	return vm->scratch_order == get_order(I915_GTT_PAGE_SIZE_64K);
 }
 
+static inline u64 i915_vm_min_alignment(struct i915_address_space *vm,
+					enum intel_memory_type type)
+{
+	return vm->min_alignment[type];
+}
+
 static inline bool
 i915_vm_has_cache_coloring(struct i915_address_space *vm)
 {
Signature · 1 line
2.20.1
#12 lore raw

PATCH 8/14 drm/i915/selftests: account for min_alignment in GTT selftests

In reply to Ramalingam C

From: Matthew Auld <[email protected]>

We need to support vm->min_alignment > 4K, depending on the vm itself and the type of object we are inserting. With this in mind update the GTT selftests to take this into account.

---
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 96 ++++++++++++-------
 1 file changed, 63 insertions(+), 33 deletions(-)
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +63 -33
index 46f4236039a9..fdb4bf88293b 100644
@@ -237,6 +237,8 @@ static int lowlevel_hole(struct i915_address_space *vm,
 			 u64 hole_start, u64 hole_end,
 			 unsigned long end_time)
 {
+	const unsigned int min_alignment =
+		i915_vm_min_alignment(vm, INTEL_MEMORY_SYSTEM);
 	I915_RND_STATE(seed_prng);
 	struct i915_vma *mock_vma;
 	unsigned int size;
@@ -250,9 +252,10 @@ static int lowlevel_hole(struct i915_address_space *vm,
 		I915_RND_SUBSTATE(prng, seed_prng);
 		struct drm_i915_gem_object *obj;
 		unsigned int *order, count, n;
-		u64 hole_size;
+		u64 hole_size, aligned_size;
 
-		hole_size = (hole_end - hole_start) >> size;
+		aligned_size = max_t(u32, ilog2(min_alignment), size);
+		hole_size = (hole_end - hole_start) >> aligned_size;
 		if (hole_size > KMALLOC_MAX_SIZE / sizeof(u32))
 			hole_size = KMALLOC_MAX_SIZE / sizeof(u32);
 		count = hole_size >> 1;
@@ -273,8 +276,8 @@ static int lowlevel_hole(struct i915_address_space *vm,
 		}
 		GEM_BUG_ON(!order);
 
-		GEM_BUG_ON(count * BIT_ULL(size) > vm->total);
-		GEM_BUG_ON(hole_start + count * BIT_ULL(size) > hole_end);
+		GEM_BUG_ON(count * BIT_ULL(aligned_size) > vm->total);
+		GEM_BUG_ON(hole_start + count * BIT_ULL(aligned_size) > hole_end);
 
 		/* Ignore allocation failures (i.e. don't report them as
 		 * a test failure) as we are purposefully allocating very
@@ -297,10 +300,10 @@ static int lowlevel_hole(struct i915_address_space *vm,
 		}
 
 		for (n = 0; n < count; n++) {
-			u64 addr = hole_start + order[n] * BIT_ULL(size);
+			u64 addr = hole_start + order[n] * BIT_ULL(aligned_size);
 			intel_wakeref_t wakeref;
 
-			GEM_BUG_ON(addr + BIT_ULL(size) > vm->total);
+			GEM_BUG_ON(addr + BIT_ULL(aligned_size) > vm->total);
 
 			if (igt_timeout(end_time,
 					"%s timed out before %d/%d\n",
@@ -343,7 +346,7 @@ static int lowlevel_hole(struct i915_address_space *vm,
 			}
 
 			mock_vma->pages = obj->mm.pages;
-			mock_vma->node.size = BIT_ULL(size);
+			mock_vma->node.size = BIT_ULL(aligned_size);
 			mock_vma->node.start = addr;
 
 			with_intel_runtime_pm(vm->gt->uncore->rpm, wakeref)
@@ -354,7 +357,7 @@ static int lowlevel_hole(struct i915_address_space *vm,
 
 		i915_random_reorder(order, count, &prng);
 		for (n = 0; n < count; n++) {
-			u64 addr = hole_start + order[n] * BIT_ULL(size);
+			u64 addr = hole_start + order[n] * BIT_ULL(aligned_size);
 			intel_wakeref_t wakeref;
 
 			GEM_BUG_ON(addr + BIT_ULL(size) > vm->total);
@@ -398,8 +401,10 @@ static int fill_hole(struct i915_address_space *vm,
 {
 	const u64 hole_size = hole_end - hole_start;
 	struct drm_i915_gem_object *obj;
+	const unsigned int min_alignment =
+		i915_vm_min_alignment(vm, INTEL_MEMORY_SYSTEM);
 	const unsigned long max_pages =
-		min_t(u64, ULONG_MAX - 1, hole_size/2 >> PAGE_SHIFT);
+		min_t(u64, ULONG_MAX - 1, (hole_size / 2) >> ilog2(min_alignment));
 	const unsigned long max_step = max(int_sqrt(max_pages), 2UL);
 	unsigned long npages, prime, flags;
 	struct i915_vma *vma;
@@ -440,14 +445,17 @@ static int fill_hole(struct i915_address_space *vm,
 
 				offset = p->offset;
 				list_for_each_entry(obj, &objects, st_link) {
+					u64 aligned_size = round_up(obj->base.size,
+								    min_alignment);
+
 					vma = i915_vma_instance(obj, vm, NULL);
 					if (IS_ERR(vma))
 						continue;
 
 					if (p->step < 0) {
-						if (offset < hole_start + obj->base.size)
+						if (offset < hole_start + aligned_size)
 							break;
-						offset -= obj->base.size;
+						offset -= aligned_size;
 					}
 
 					err = i915_vma_pin(vma, 0, 0, offset | flags);
@@ -469,22 +477,25 @@ static int fill_hole(struct i915_address_space *vm,
 					i915_vma_unpin(vma);
 
 					if (p->step > 0) {
-						if (offset + obj->base.size > hole_end)
+						if (offset + aligned_size > hole_end)
 							break;
-						offset += obj->base.size;
+						offset += aligned_size;
 					}
 				}
 
 				offset = p->offset;
 				list_for_each_entry(obj, &objects, st_link) {
+					u64 aligned_size = round_up(obj->base.size,
+								    min_alignment);
+
 					vma = i915_vma_instance(obj, vm, NULL);
 					if (IS_ERR(vma))
 						continue;
 
 					if (p->step < 0) {
-						if (offset < hole_start + obj->base.size)
+						if (offset < hole_start + aligned_size)
 							break;
-						offset -= obj->base.size;
+						offset -= aligned_size;
 					}
 
 					if (!drm_mm_node_allocated(&vma->node) ||
@@ -505,22 +516,25 @@ static int fill_hole(struct i915_address_space *vm,
 					}
 
 					if (p->step > 0) {
-						if (offset + obj->base.size > hole_end)
+						if (offset + aligned_size > hole_end)
 							break;
-						offset += obj->base.size;
+						offset += aligned_size;
 					}
 				}
 
 				offset = p->offset;
 				list_for_each_entry_reverse(obj, &objects, st_link) {
+					u64 aligned_size = round_up(obj->base.size,
+								    min_alignment);
+
 					vma = i915_vma_instance(obj, vm, NULL);
 					if (IS_ERR(vma))
 						continue;
 
 					if (p->step < 0) {
-						if (offset < hole_start + obj->base.size)
+						if (offset < hole_start + aligned_size)
 							break;
-						offset -= obj->base.size;
+						offset -= aligned_size;
 					}
 
 					err = i915_vma_pin(vma, 0, 0, offset | flags);
@@ -542,22 +556,25 @@ static int fill_hole(struct i915_address_space *vm,
 					i915_vma_unpin(vma);
 
 					if (p->step > 0) {
-						if (offset + obj->base.size > hole_end)
+						if (offset + aligned_size > hole_end)
 							break;
-						offset += obj->base.size;
+						offset += aligned_size;
 					}
 				}
 
 				offset = p->offset;
 				list_for_each_entry_reverse(obj, &objects, st_link) {
+					u64 aligned_size = round_up(obj->base.size,
+								    min_alignment);
+
 					vma = i915_vma_instance(obj, vm, NULL);
 					if (IS_ERR(vma))
 						continue;
 
 					if (p->step < 0) {
-						if (offset < hole_start + obj->base.size)
+						if (offset < hole_start + aligned_size)
 							break;
-						offset -= obj->base.size;
+						offset -= aligned_size;
 					}
 
 					if (!drm_mm_node_allocated(&vma->node) ||
@@ -578,9 +595,9 @@ static int fill_hole(struct i915_address_space *vm,
 					}
 
 					if (p->step > 0) {
-						if (offset + obj->base.size > hole_end)
+						if (offset + aligned_size > hole_end)
 							break;
-						offset += obj->base.size;
+						offset += aligned_size;
 					}
 				}
 			}
@@ -610,6 +627,7 @@ static int walk_hole(struct i915_address_space *vm,
 	const u64 hole_size = hole_end - hole_start;
 	const unsigned long max_pages =
 		min_t(u64, ULONG_MAX - 1, hole_size >> PAGE_SHIFT);
+	unsigned long min_alignment;
 	unsigned long flags;
 	u64 size;
 
@@ -619,6 +637,8 @@ static int walk_hole(struct i915_address_space *vm,
 	if (i915_is_ggtt(vm))
 		flags |= PIN_GLOBAL;
 
+	min_alignment = i915_vm_min_alignment(vm, INTEL_MEMORY_SYSTEM);
+
 	for_each_prime_number_from(size, 1, max_pages) {
 		struct drm_i915_gem_object *obj;
 		struct i915_vma *vma;
@@ -637,7 +657,7 @@ static int walk_hole(struct i915_address_space *vm,
 
 		for (addr = hole_start;
 		     addr + obj->base.size < hole_end;
-		     addr += obj->base.size) {
+		     addr += round_up(obj->base.size, min_alignment)) {
 			err = i915_vma_pin(vma, 0, 0, addr | flags);
 			if (err) {
 				pr_err("%s bind failed at %llx + %llx [hole %llx- %llx] with err=%d\n",
@@ -689,6 +709,7 @@ static int pot_hole(struct i915_address_space *vm,
 {
 	struct drm_i915_gem_object *obj;
 	struct i915_vma *vma;
+	unsigned int min_alignment;
 	unsigned long flags;
 	unsigned int pot;
 	int err = 0;
@@ -697,6 +718,8 @@ static int pot_hole(struct i915_address_space *vm,
 	if (i915_is_ggtt(vm))
 		flags |= PIN_GLOBAL;
 
+	min_alignment = i915_vm_min_alignment(vm, INTEL_MEMORY_SYSTEM);
+
 	obj = i915_gem_object_create_internal(vm->i915, 2 * I915_GTT_PAGE_SIZE);
 	if (IS_ERR(obj))
 		return PTR_ERR(obj);
@@ -709,13 +732,13 @@ static int pot_hole(struct i915_address_space *vm,
 
 	/* Insert a pair of pages across every pot boundary within the hole */
 	for (pot = fls64(hole_end - 1) - 1;
-	     pot > ilog2(2 * I915_GTT_PAGE_SIZE);
+	     pot > ilog2(2 * min_alignment);
 	     pot--) {
 		u64 step = BIT_ULL(pot);
 		u64 addr;
 
-		for (addr = round_up(hole_start + I915_GTT_PAGE_SIZE, step) - I915_GTT_PAGE_SIZE;
-		     addr <= round_down(hole_end - 2*I915_GTT_PAGE_SIZE, step) - I915_GTT_PAGE_SIZE;
+		for (addr = round_up(hole_start + min_alignment, step) - min_alignment;
+		     addr <= round_down(hole_end - (2 * min_alignment), step) - min_alignment;
 		     addr += step) {
 			err = i915_vma_pin(vma, 0, 0, addr | flags);
 			if (err) {
@@ -760,6 +783,7 @@ static int drunk_hole(struct i915_address_space *vm,
 		      unsigned long end_time)
 {
 	I915_RND_STATE(prng);
+	unsigned int min_alignment;
 	unsigned int size;
 	unsigned long flags;
 
@@ -767,15 +791,18 @@ static int drunk_hole(struct i915_address_space *vm,
 	if (i915_is_ggtt(vm))
 		flags |= PIN_GLOBAL;
 
+	min_alignment = i915_vm_min_alignment(vm, INTEL_MEMORY_SYSTEM);
+
 	/* Keep creating larger objects until one cannot fit into the hole */
 	for (size = 12; (hole_end - hole_start) >> size; size++) {
 		struct drm_i915_gem_object *obj;
 		unsigned int *order, count, n;
 		struct i915_vma *vma;
-		u64 hole_size;
+		u64 hole_size, aligned_size;
 		int err = -ENODEV;
 
-		hole_size = (hole_end - hole_start) >> size;
+		aligned_size = max_t(u32, ilog2(min_alignment), size);
+		hole_size = (hole_end - hole_start) >> aligned_size;
 		if (hole_size > KMALLOC_MAX_SIZE / sizeof(u32))
 			hole_size = KMALLOC_MAX_SIZE / sizeof(u32);
 		count = hole_size >> 1;
@@ -815,7 +842,7 @@ static int drunk_hole(struct i915_address_space *vm,
 		GEM_BUG_ON(vma->size != BIT_ULL(size));
 
 		for (n = 0; n < count; n++) {
-			u64 addr = hole_start + order[n] * BIT_ULL(size);
+			u64 addr = hole_start + order[n] * BIT_ULL(aligned_size);
 
 			err = i915_vma_pin(vma, 0, 0, addr | flags);
 			if (err) {
@@ -867,11 +894,14 @@ static int __shrink_hole(struct i915_address_space *vm,
 {
 	struct drm_i915_gem_object *obj;
 	unsigned long flags = PIN_OFFSET_FIXED | PIN_USER;
+	unsigned int min_alignment;
 	unsigned int order = 12;
 	LIST_HEAD(objects);
 	int err = 0;
 	u64 addr;
 
+	min_alignment = i915_vm_min_alignment(vm, INTEL_MEMORY_SYSTEM);
+
 	/* Keep creating larger objects until one cannot fit into the hole */
 	for (addr = hole_start; addr < hole_end; ) {
 		struct i915_vma *vma;
@@ -912,7 +942,7 @@ static int __shrink_hole(struct i915_address_space *vm,
 		}
 
 		i915_vma_unpin(vma);
-		addr += size;
+		addr += round_up(size, min_alignment);
 
 		/*
 		 * Since we are injecting allocation faults at random intervals,
Signature · 1 line
2.20.1
#13 lore raw

PATCH 9/14 drm/i915/xehpsdv: implement memory coloring

In reply to Ramalingam C

From: Matthew Auld <[email protected]>

The basic idea is that each 2M block(page-table) has a color, depending on if the page-table is occupied by LMEM objects(64K) or SMEM objects(4K), where our goal is to prevent mixing 64K and 4K GTT pages in the page-table, which is not supported by the HW.

---
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c  | 16 ++++++++++
 drivers/gpu/drm/i915/gt/intel_gtt.h   |  6 ++++
 drivers/gpu/drm/i915/i915_gem_evict.c | 17 ++++++++++
 drivers/gpu/drm/i915/i915_vma.c       | 46 +++++++++++++++++++--------
 4 files changed, 71 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/gt/gen8_ppgtt.c +16 -0
index fec0f20f1b93..666745adbe93 100644
@@ -464,6 +464,19 @@ gen8_ppgtt_insert_pte(struct i915_ppgtt *ppgtt,
 	return idx;
 }
 
+static void xehpsdv_ppgtt_color_adjust(const struct drm_mm_node *node,
+				       unsigned long color,
+				       u64 *start,
+				       u64 *end)
+{
+	if (i915_node_color_differs(node, color))
+		*start = round_up(*start, SZ_2M);
+
+	node = list_next_entry(node, node_list);
+	if (i915_node_color_differs(node, color))
+		*end = round_down(*end, SZ_2M);
+}
+
 static void
 xehpsdv_ppgtt_insert_huge(struct i915_vma *vma,
 			  struct sgt_dma *iter,
@@ -901,6 +914,9 @@ struct i915_ppgtt *gen8_ppgtt_create(struct intel_gt *gt,
 		ppgtt->vm.alloc_scratch_dma = alloc_pt_dma;
 	}
 
+	if (HAS_64K_PAGES(gt->i915))
+		ppgtt->vm.mm.color_adjust = xehpsdv_ppgtt_color_adjust;
+
 	err = gen8_init_scratch(&ppgtt->vm);
 	if (err)
 		goto err_free;
drivers/gpu/drm/i915/gt/intel_gtt.h +6 -0
index 20101eef4c95..34696acde342 100644
@@ -397,6 +397,12 @@ i915_vm_has_cache_coloring(struct i915_address_space *vm)
 	return i915_is_ggtt(vm) && vm->mm.color_adjust;
 }
 
+static inline bool
+i915_vm_has_memory_coloring(struct i915_address_space *vm)
+{
+	return !i915_is_ggtt(vm) && vm->mm.color_adjust;
+}
+
 static inline struct i915_ggtt *
 i915_vm_to_ggtt(struct i915_address_space *vm)
 {
drivers/gpu/drm/i915/i915_gem_evict.c +17 -0
index 2b73ddb11c66..006bf4924c24 100644
@@ -292,6 +292,13 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
 
 		/* Always look at the page afterwards to avoid the end-of-GTT */
 		end += I915_GTT_PAGE_SIZE;
+	} else if (i915_vm_has_memory_coloring(vm)) {
+		/*
+		 * Expand the search the cover the page-table boundries, in
+		 * case we need to flip the color of the page-table(s).
+		 */
+		start = round_down(start, SZ_2M);
+		end = round_up(end, SZ_2M);
 	}
 	GEM_BUG_ON(start >= end);
 
@@ -321,6 +328,16 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
 				if (node->color == target->color)
 					continue;
 			}
+		} else if (i915_vm_has_memory_coloring(vm)) {
+			if (node->start + node->size <= target->start) {
+				if (node->color == target->color)
+					continue;
+			}
+
+			if (node->start >= target->start + target->size) {
+				if (node->color == target->color)
+					continue;
+			}
 		}
 
 		if (i915_vma_is_pinned(vma)) {
drivers/gpu/drm/i915/i915_vma.c +32 -14

66 lines not on this page · raw message

Signature · 1 line
2.20.1
#14 lore raw

PATCH 10/14 drm/i915/xehpsdv: Add has_flat_ccs to device info

In reply to Ramalingam C

From: CQ Tang <[email protected]>

Gen12+ devices support 3D surface (buffer) compression and various compression formats. This is accomplished by an additional compression control state (CCS) stored for each surface.

Gen 12 devices(TGL family and DG1) stores compression states in a separate region of memory. It is managed by user-space and has an associated set of user-space managed page tables used by hardware for address translation.

In Gen12.5 devices(XEHPSDV, DG2, etc), there is a new feature introduced i.e Flat CCS. It replaced AUX page tables with a flat indexed region of device memory for storing compression states.

Cc Joonas Lahtinen <[email protected]>
Cc Matthew Auld <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.h          | 2 ++
 drivers/gpu/drm/i915/i915_pci.c          | 1 +
 drivers/gpu/drm/i915/intel_device_info.h | 1 +
 3 files changed, 4 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index a16fde38a252..57948e0ee48b 100644
@@ -1721,6 +1721,8 @@ IS_SUBPLATFORM(const struct drm_i915_private *i915,
 #define HAS_REGION(i915, i) (INTEL_INFO(i915)->memory_regions & (i))
 #define HAS_LMEM(i915) HAS_REGION(i915, REGION_LMEM)
 
+#define HAS_FLAT_CCS(dev_priv)   (INTEL_INFO(dev_priv)->has_flat_ccs)
+
 #define HAS_GT_UC(dev_priv)	(INTEL_INFO(dev_priv)->has_gt_uc)
 
 #define HAS_POOLED_EU(dev_priv)	(INTEL_INFO(dev_priv)->has_pooled_eu)
drivers/gpu/drm/i915/i915_pci.c +1 -0
index 8ef484a23652..68367b505dc4 100644
@@ -991,6 +991,7 @@ static const struct intel_device_info adl_p_info = {
 	XE_HP_PAGE_SIZES, \
 	.dma_mask_size = 46, \
 	.has_64bit_reloc = 1, \
+	.has_flat_ccs = 1, \
 	.has_global_mocs = 1, \
 	.has_gt_uc = 1, \
 	.has_llc = 1, \
drivers/gpu/drm/i915/intel_device_info.h +1 -0
index dd453b96af19..87ee1d86d2ac 100644
@@ -126,6 +126,7 @@ enum intel_ppgtt_type {
 	func(has_64k_pages); \
 	func(gpu_reset_clobbers_display); \
 	func(has_reset_engine); \
+	func(has_flat_ccs); \
 	func(has_global_mocs); \
 	func(has_gt_uc); \
 	func(has_l3_dpf); \
Signature · 1 line
2.20.1
#15 lore raw

PATCH 11/14 drm/i915/lmem: Enable lmem for platforms with Flat CCS

In reply to Ramalingam C

From: Abdiel Janulgue <[email protected]>

A portion of device memory is reserved for Flat CCS so usable device memory will be reduced by size of Flat CCS. Size of Flat CCS is specified in “XEHPSDV_FLAT_CCS_BASE_ADDR”. So to get effective device memory we need to subtract total device memory by Flat CCS memory size.

---
 drivers/gpu/drm/i915/gt/intel_gt.c          | 19 ++++++++++++++++++
 drivers/gpu/drm/i915/gt/intel_gt.h          |  1 +
 drivers/gpu/drm/i915/gt/intel_region_lmem.c | 22 +++++++++++++++++++--
 drivers/gpu/drm/i915/i915_reg.h             |  3 +++
 4 files changed, 43 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_gt.c +19 -0
index 1cb1948ac959..fd82ebee8724 100644
@@ -900,6 +900,25 @@ u32 intel_gt_read_register_fw(struct intel_gt *gt, i915_reg_t reg)
 	return intel_uncore_read_fw(gt->uncore, reg);
 }
 
+u32 intel_gt_read_register(struct intel_gt *gt, i915_reg_t reg)
+{
+	int type;
+	u8 sliceid, subsliceid;
+
+	for (type = 0; type < NUM_STEERING_TYPES; type++) {
+		if (intel_gt_reg_needs_read_steering(gt, reg, type)) {
+			intel_gt_get_valid_steering(gt, type, &sliceid,
+						    &subsliceid);
+			return intel_uncore_read_with_mcr_steering(gt->uncore,
+								   reg,
+								   sliceid,
+								   subsliceid);
+		}
+	}
+
+	return intel_uncore_read(gt->uncore, reg);
+}
+
 void intel_gt_info_print(const struct intel_gt_info *info,
 			 struct drm_printer *p)
 {
drivers/gpu/drm/i915/gt/intel_gt.h +1 -0
index 74e771871a9b..24b78398a587 100644
@@ -84,6 +84,7 @@ static inline bool intel_gt_needs_read_steering(struct intel_gt *gt,
 }
 
 u32 intel_gt_read_register_fw(struct intel_gt *gt, i915_reg_t reg);
+u32 intel_gt_read_register(struct intel_gt *gt, i915_reg_t reg);
 
 void intel_gt_info_print(const struct intel_gt_info *info,
 			 struct drm_printer *p);
drivers/gpu/drm/i915/gt/intel_region_lmem.c +20 -2
index 073d28d96669..d1f88beb26fe 100644
@@ -201,8 +201,26 @@ static struct intel_memory_region *setup_lmem(struct intel_gt *gt)
 	if (!IS_DGFX(i915))
 		return ERR_PTR(-ENODEV);
 
-	/* Stolen starts from GSMBASE on DG1 */
-	lmem_size = intel_uncore_read64(uncore, GEN12_GSMBASE);
+	if (HAS_FLAT_CCS(i915)) {
+		u64 tile_stolen, flat_ccs_base_addr_reg, flat_ccs_base;
+
+		lmem_size = pci_resource_len(pdev, 2);
+		flat_ccs_base_addr_reg = intel_gt_read_register(gt, XEHPSDV_FLAT_CCS_BASE_ADDR);
+		flat_ccs_base = (flat_ccs_base_addr_reg >> XEHPSDV_CCS_BASE_SHIFT) * SZ_64K;
+		tile_stolen = lmem_size - flat_ccs_base;
+
+		/* If the FLAT_CCS_BASE_ADDR register is not populated, flag an error */
+		if (tile_stolen == lmem_size)
+			DRM_ERROR("CCS_BASE_ADDR register did not have expected value\n");
+
+		lmem_size -= tile_stolen;
+	} else {
+		/* Stolen starts from GSMBASE without CCS */
+		lmem_size = intel_uncore_read64(&i915->uncore, GEN12_GSMBASE);
+		if (GEM_WARN_ON(lmem_size > pci_resource_len(pdev, 2)))
+			return ERR_PTR(-ENODEV);
+	}
+
 
 	io_start = pci_resource_start(pdev, 2);
 	if (GEM_WARN_ON(lmem_size > pci_resource_len(pdev, 2)))
drivers/gpu/drm/i915/i915_reg.h +3 -0
index a897f4abea0c..5a14e0ca9d4f 100644
@@ -12480,6 +12480,9 @@ enum skl_power_gate {
 #define GEN12_GSMBASE			_MMIO(0x108100)
 #define GEN12_DSMBASE			_MMIO(0x1080C0)
 
+#define XEHPSDV_FLAT_CCS_BASE_ADDR             _MMIO(0x4910)
+#define   XEHPSDV_CCS_BASE_SHIFT               8
+
 /* 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 · 1 line
2.20.1
#16 lore raw

PATCH 12/14 drm/i915/gt: Clear compress metadata for Gen12.5 >= platforms

In reply to Ramalingam C

From: Ayaz A Siddiqui <[email protected]>

Gen12.5+ devices support Flat CCS which reserved a portion of the device memory to store compression metadata, during the clearing of device memory buffer object we also need to clear the associated CCS buffer.

Flat CCS memory can not be directly accessed by S/W. Address of CCS buffer associated main BO is automatically calculated by device itself. KMD/UMD can only access this buffer indirectly using XY_CTRL_SURF_COPY_BLT cmd via the address of device memory buffer.

---
 drivers/gpu/drm/i915/gt/intel_gpu_commands.h |  14 +++
 drivers/gpu/drm/i915/gt/intel_migrate.c      | 120 ++++++++++++++++++-
 2 files changed, 131 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +14 -0
index f8253012d166..07bf5a1753bd 100644
@@ -203,6 +203,20 @@
 #define GFX_OP_DRAWRECT_INFO     ((0x3<<29)|(0x1d<<24)|(0x80<<16)|(0x3))
 #define GFX_OP_DRAWRECT_INFO_I965  ((0x7900<<16)|0x2)
 
+#define XY_CTRL_SURF_INSTR_SIZE	5
+#define MI_FLUSH_DW_SIZE		3
+#define XY_CTRL_SURF_COPY_BLT		((2 << 29) | (0x48 << 22) | 3)
+#define   SRC_ACCESS_TYPE_SHIFT	21
+#define   DST_ACCESS_TYPE_SHIFT	20
+#define   CCS_SIZE_SHIFT		8
+#define   XY_CTRL_SURF_MOCS_SHIFT	25
+#define   NUM_CCS_BYTES_PER_BLOCK	256
+#define   NUM_CCS_BLKS_PER_XFER	1024
+#define   INDIRECT_ACCESS		0
+#define   DIRECT_ACCESS		1
+#define  MI_FLUSH_LLC			BIT(9)
+#define  MI_FLUSH_CCS			BIT(16)
+
 #define COLOR_BLT_CMD			(2 << 29 | 0x40 << 22 | (5 - 2))
 #define XY_COLOR_BLT_CMD		(2 << 29 | 0x50 << 22)
 #define SRC_COPY_BLT_CMD		(2 << 29 | 0x43 << 22)
drivers/gpu/drm/i915/gt/intel_migrate.c +117 -3

151 lines not on this page · raw message

Signature · 1 line
2.20.1
#17 lore raw

PATCH 13/14 drm/i915/uapi: document behaviour for DG2 64K support

In reply to Ramalingam C

From: Matthew Auld <[email protected]>

On discrete platforms like DG2, we need to support a minimum page size of 64K when dealing with device local-memory. This is quite tricky for various reasons, so try to document the new implicit uapi for this.

---
 include/uapi/drm/i915_drm.h | 61 ++++++++++++++++++++++++++++++++++---
 1 file changed, 56 insertions(+), 5 deletions(-)
include/uapi/drm/i915_drm.h +56 -5
index aa2a7eccfb94..d62e8b7ed8b6 100644
@@ -1118,10 +1118,16 @@ struct drm_i915_gem_exec_object2 {
 	/**
 	 * When the EXEC_OBJECT_PINNED flag is specified this is populated by
 	 * the user with the GTT offset at which this object will be pinned.
+	 *
 	 * When the I915_EXEC_NO_RELOC flag is specified this must contain the
 	 * presumed_offset of the object.
+	 *
 	 * During execbuffer2 the kernel populates it with the value of the
 	 * current GTT offset of the object, for future presumed_offset writes.
+	 *
+	 * See struct drm_i915_gem_create_ext for the rules when dealing with
+	 * alignment restrictions with I915_MEMORY_CLASS_DEVICE, on devices with
+	 * minimum page sizes, like DG2.
 	 */
 	__u64 offset;
 
@@ -3001,11 +3007,56 @@ struct drm_i915_gem_create_ext {
 	 *
 	 * The (page-aligned) allocated size for the object will be returned.
 	 *
-	 * Note that for some devices we have might have further minimum
-	 * page-size restrictions(larger than 4K), like for device local-memory.
-	 * However in general the final size here should always reflect any
-	 * rounding up, if for example using the I915_GEM_CREATE_EXT_MEMORY_REGIONS
-	 * extension to place the object in device local-memory.
+	 * On discrete platforms, starting from DG2, we have to contend with GTT
+	 * page size restrictions when dealing with I915_MEMORY_CLASS_DEVICE
+	 * objects.  Specifically the hardware only supports 64K or larger GTT
+	 * page sizes for such memory. The kernel will already ensure that all
+	 * I915_MEMORY_CLASS_DEVICE memory is allocated using 64K or larger page
+	 * sizes underneath.
+	 *
+	 * Note that the returned size here will always reflect any required
+	 * rounding up done by the kernel, i.e 4K will now become 64K on devices
+	 * such as DG2. The GTT alignment will also need be at least 64K for
+	 * such objects.
+	 *
+	 * Note that due to how the hardware implements 64K GTT page support, we
+	 * have some further complications:
+	 *
+	 *   1.) The entire PDE(which covers a 2M virtual address range), must
+	 *   contain only 64K PTEs, i.e mixing 4K and 64K PTEs in the same
+	 *   PDE is forbidden by the hardware.
+	 *
+	 *   2.) We still need to support 4K PTEs for I915_MEMORY_CLASS_SYSTEM
+	 *   objects.
+	 *
+	 * To handle the above the kernel implements a memory coloring scheme to
+	 * prevent userspace from mixing I915_MEMORY_CLASS_DEVICE and
+	 * I915_MEMORY_CLASS_SYSTEM objects in the same PDE. If the kernel is
+	 * ever unable to evict the required pages for the given PDE(different
+	 * color) when inserting the object into the GTT then it will simply
+	 * fail the request.
+	 *
+	 * Since userspace needs to manage the GTT address space themselves,
+	 * special care is needed to ensure this doesn't happen. The simplest
+	 * scheme is to simply align and round up all I915_MEMORY_CLASS_DEVICE
+	 * objects to 2M, which avoids any issues here. At the very least this
+	 * is likely needed for objects that can be placed in both
+	 * I915_MEMORY_CLASS_DEVICE and I915_MEMORY_CLASS_SYSTEM, to avoid
+	 * potential issues when the kernel needs to migrate the object behind
+	 * the scenes, since that might also involve evicting other objects.
+	 *
+	 * To summarise the GTT rules, on platforms like DG2:
+	 *
+	 *   1.) All objects that can be placed in I915_MEMORY_CLASS_DEVICE must
+	 *   have 64K alignment. The kernel will reject this otherwise.
+	 *
+	 *   2.) All I915_MEMORY_CLASS_DEVICE objects must never be placed in
+	 *   the same PDE with other I915_MEMORY_CLASS_SYSTEM objects. The
+	 *   kernel will reject this otherwise.
+	 *
+	 *   3.) Objects that can be placed in both I915_MEMORY_CLASS_DEVICE and
+	 *   I915_MEMORY_CLASS_SYSTEM should probably be aligned and padded out
+	 *   to 2M.
 	 */
 	__u64 size;
 	/**
Signature · 1 line
2.20.1
#18 lore raw

Re: [PATCH 13/14] drm/i915/uapi: document behaviour for DG2 64K support

Quoted 34 lines · Ramalingam C

From: Matthew Auld <[email protected]>

On discrete platforms like DG2, we need to support a minimum page size of 64K when dealing with device local-memory. This is quite tricky for various reasons, so try to document the new implicit uapi for this.

---
 include/uapi/drm/i915_drm.h | 61 ++++++++++++++++++++++++++++++++++---
 1 file changed, 56 insertions(+), 5 deletions(-)
include/uapi/drm/i915_drm.h +6 -0
index aa2a7eccfb94..d62e8b7ed8b6 100644
@@ -1118,10 +1118,16 @@ struct drm_i915_gem_exec_object2 {
 	/**
 	 * When the EXEC_OBJECT_PINNED flag is specified this is populated by
 	 * the user with the GTT offset at which this object will be pinned.
+	 *
 	 * When the I915_EXEC_NO_RELOC flag is specified this must contain the
 	 * presumed_offset of the object.
+	 *
 	 * During execbuffer2 the kernel populates it with the value of the
 	 * current GTT offset of the object, for future presumed_offset writes.
+	 *
+	 * See struct drm_i915_gem_create_ext for the rules when dealing with
+	 * alignment restrictions with I915_MEMORY_CLASS_DEVICE, on devices with
+	 * minimum page sizes, like DG2.
 	 */
 	__u64 offset;
 

include/uapi/drm/i915_drm.h struct drm_i915_gem_create_ext { · line 3007

Quoted 1 line
include/uapi/drm/i915_drm.h +0 -0
@@ -3001,11 +3007,56 @@ struct drm_i915_gem_create_ext {
 	 *

I think a heading here (or a bit earlier) about Page alignment would be good. Just mark it up as bold or something (since real sphinx headings won't work).

Quoted 9 lines
include/uapi/drm/i915_drm.h +2 -5
 	 * The (page-aligned) allocated size for the object will be returned.
 	 *
-	 * Note that for some devices we have might have further minimum
-	 * page-size restrictions(larger than 4K), like for device local-memory.
-	 * However in general the final size here should always reflect any
-	 * rounding up, if for example using the I915_GEM_CREATE_EXT_MEMORY_REGIONS
-	 * extension to place the object in device local-memory.
+	 * On discrete platforms, starting from DG2, we have to contend with GTT
+	 * page size restrictions when dealing with I915_MEMORY_CLASS_DEVICE

include/uapi/drm/i915_drm.h struct drm_i915_gem_create_ext { · line 3021

Quoted 10 lines
include/uapi/drm/i915_drm.h +10 -0
+	 * objects.  Specifically the hardware only supports 64K or larger GTT
+	 * page sizes for such memory. The kernel will already ensure that all
+	 * I915_MEMORY_CLASS_DEVICE memory is allocated using 64K or larger page
+	 * sizes underneath.
+	 *
+	 * Note that the returned size here will always reflect any required
+	 * rounding up done by the kernel, i.e 4K will now become 64K on devices
+	 * such as DG2. The GTT alignment will also need be at least 64K for
+	 * such objects.
+	 *

I think here we should have a "Special DG2 placement restrictions" heading for clarity

include/uapi/drm/i915_drm.h struct drm_i915_gem_create_ext { · line 3025

Quoted 4 lines
include/uapi/drm/i915_drm.h +4 -0
+	 * Note that due to how the hardware implements 64K GTT page support, we
+	 * have some further complications:
+	 *
+	 *   1.) The entire PDE(which covers a 2M virtual address range), must

Does this really format into a nice list in the html output? Also not both . and ), usually in text it's just )

Quoted 24 lines
include/uapi/drm/i915_drm.h +24 -0
+	 *   contain only 64K PTEs, i.e mixing 4K and 64K PTEs in the same
+	 *   PDE is forbidden by the hardware.
+	 *
+	 *   2.) We still need to support 4K PTEs for I915_MEMORY_CLASS_SYSTEM
+	 *   objects.
+	 *
+	 * To handle the above the kernel implements a memory coloring scheme to
+	 * prevent userspace from mixing I915_MEMORY_CLASS_DEVICE and
+	 * I915_MEMORY_CLASS_SYSTEM objects in the same PDE. If the kernel is
+	 * ever unable to evict the required pages for the given PDE(different
+	 * color) when inserting the object into the GTT then it will simply
+	 * fail the request.
+	 *
+	 * Since userspace needs to manage the GTT address space themselves,
+	 * special care is needed to ensure this doesn't happen. The simplest
+	 * scheme is to simply align and round up all I915_MEMORY_CLASS_DEVICE
+	 * objects to 2M, which avoids any issues here. At the very least this
+	 * is likely needed for objects that can be placed in both
+	 * I915_MEMORY_CLASS_DEVICE and I915_MEMORY_CLASS_SYSTEM, to avoid
+	 * potential issues when the kernel needs to migrate the object behind
+	 * the scenes, since that might also involve evicting other objects.
+	 *
+	 * To summarise the GTT rules, on platforms like DG2:
+	 *

include/uapi/drm/i915_drm.h struct drm_i915_gem_create_ext { · line 3059

Quoted 10 lines
include/uapi/drm/i915_drm.h +10 -0
+	 *   1.) All objects that can be placed in I915_MEMORY_CLASS_DEVICE must
+	 *   have 64K alignment. The kernel will reject this otherwise.
+	 *
+	 *   2.) All I915_MEMORY_CLASS_DEVICE objects must never be placed in
+	 *   the same PDE with other I915_MEMORY_CLASS_SYSTEM objects. The
+	 *   kernel will reject this otherwise.
+	 *
+	 *   3.) Objects that can be placed in both I915_MEMORY_CLASS_DEVICE and
+	 *   I915_MEMORY_CLASS_SYSTEM should probably be aligned and padded out
+	 *   to 2M.

I think this is good for the 64k side of things. Ofc the patch needs as many acks as you can get, so please cc all the userspace people you can get hold of (Jason, Ken on the mesa side, plus media and compute people too).

Quoted 6 lines
include/uapi/drm/i915_drm.h +0 -0
 	 */
 	__u64 size;
 	/**
Signature · 1 line
2.20.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#19 lore raw

PATCH 14/14 Doc/gpu/rfc/i915: i915 DG2 uAPI

In reply to Ramalingam C

Details of the new features getting added as part of DG2 enabling and their implicit impact on the uAPI.

cc Daniel Vetter <[email protected]>
cc Matthew Auld <[email protected]>
---
 Documentation/gpu/rfc/i915_dg2.rst | 47 ++++++++++++++++++++++++++++++
 Documentation/gpu/rfc/index.rst    |  3 ++
 2 files changed, 50 insertions(+)
 create mode 100644 Documentation/gpu/rfc/i915_dg2.rst
Documentation/gpu/rfc/i915_dg2.rst new file +47 -0
new file mode 100644
index 000000000000..a83ca26cd758
@@ -0,0 +1,47 @@
+====================
+I915 DG2 RFC Section
+====================
+
+Upstream plan
+=============
+Plan to upstream the DG2 enabling is:
+
+* Merge basic HW enabling for DG2(Still without pciid)
+* Merge the 64k support for lmem
+* Merge the flat CCS enabling patches
+* Add the pciid for DG2 and enable the DG2 in CI
+
+
+64K page support for lmem
+=========================
+On DG2 hw, local-memory supports minimum GTT page size of 64k only. 4k is not supported anymore.
+
+DG2 hw dont support the 64k(lmem) and 4k(smem) pages in the same ppgtt Page table. Refer the
+struct drm_i915_gem_create_ext for the implication of handling the 64k page size.
+
+.. kernel-doc:: include/uapi/drm/i915_drm.h
+        :functions: drm_i915_gem_create_ext
+
+
+flat CCS support for lmem
+=========================
+Gen 12+ devices support 3D surfaces compression and compression formats. This is
+accomplished by an additional compression control state (CCS) stored for each surface.
+
+Gen 12 devices(TGL and DG1) stores compression state in a separate region of memory.
+It is managed by userspace and has an associated set of userspace managed page tables
+used by hardware for address translation.
+
+In Gen 12.5 devices(XEXPSDV and DG2) Flat CCS is introduced to replace the userspace
+managed AUX pagetable with the flat indexed region of device memory for storing the
+compression state
+
+GOP Driver steals a chunk of memory for the CCS surface corresponding to the entire
+range of local memory. The memory required for the CCS of the entire local memory is
+1/256 of the main local memory. The Gop driver will also program a secure register
+(XEHPSDV_FLAT_CCS_BASE_ADDR 0x4910) with this address value.
+
+So the Total local memory available for driver allocation is Total lmem size - CCS data size
+
+Flat CCS data needs to be cleared when a lmem object is allocated. And CCS data can
+be copied in and out of CCS region through XY_CTRL_SURF_COPY_BLT.
Documentation/gpu/rfc/index.rst +3 -0
index 91e93a705230..afb320ed4028 100644
@@ -20,6 +20,9 @@ host such documentation:
 
     i915_gem_lmem.rst
 
+.. toctree::
+    i915_dg2.rst
+
 .. toctree::
 
     i915_scheduler.rst
Signature · 1 line
2.20.1
#20 lore raw

RE: [PATCH 14/14] Doc/gpu/rfc/i915: i915 DG2 uAPI

Quoted 65 lines

-----Original Message-----
From: C, Ramalingam <[email protected]>
Sent: Monday, October 11, 2021 9:12 AM
To: dri-devel <[email protected]>; intel-gfx <intel- [email protected]>
Cc: Daniel Vetter <[email protected]>; Auld, Matthew <[email protected]>; Tang, CQ <[email protected]>; Hellstrom, Thomas <[email protected]>; C, Ramalingam <[email protected]>; Daniel Vetter <[email protected]>
Subject: [PATCH 14/14] Doc/gpu/rfc/i915: i915 DG2 uAPI

Details of the new features getting added as part of DG2 enabling and their implicit impact on the uAPI.

cc Daniel Vetter <[email protected]>
cc Matthew Auld <[email protected]>
---
 Documentation/gpu/rfc/i915_dg2.rst | 47
++++++++++++++++++++++++++++++
 Documentation/gpu/rfc/index.rst    |  3 ++
 2 files changed, 50 insertions(+)
 create mode 100644 Documentation/gpu/rfc/i915_dg2.rst
Documentation/gpu/rfc/i915_dg2.rst new file +17 -0
new file mode 100644
index 000000000000..a83ca26cd758
@@ -0,0 +1,47 @@
+====================
+I915 DG2 RFC Section
+====================
+
+Upstream plan
+=============
+Plan to upstream the DG2 enabling is:
+
+* Merge basic HW enabling for DG2(Still without pciid)
+* Merge the 64k support for lmem
+* Merge the flat CCS enabling patches
+* Add the pciid for DG2 and enable the DG2 in CI
+
+
+64K page support for lmem
+=========================
+On DG2 hw, local-memory supports minimum GTT page size of 64k only. 4k

is not supported anymore.

Documentation/gpu/rfc/i915_dg2.rst new file +2 -0
+
+DG2 hw dont support the 64k(lmem) and 4k(smem) pages in the same

ppgtt
+Page table. Refer the struct drm_i915_gem_create_ext for the implication of handling the 64k page size.

Documentation/gpu/rfc/i915_dg2.rst new file +9 -0
+
+.. kernel-doc:: include/uapi/drm/i915_drm.h
+        :functions: drm_i915_gem_create_ext
+
+
+flat CCS support for lmem
+=========================
+Gen 12+ devices support 3D surfaces compression and compression
+formats. This is accomplished by an additional compression control state
Quoted 1 line

(CCS) stored for each surface.

General introduction, OK.

Documentation/gpu/rfc/i915_dg2.rst

Quoted 5 lines
Documentation/gpu/rfc/i915_dg2.rst new file +2 -0
+
+Gen 12 devices(TGL and DG1) stores compression state in a separate region

of memory.

Documentation/gpu/rfc/i915_dg2.rst new file +2 -0
+It is managed by userspace and has an associated set of userspace
+managed page tables used by hardware for address translation.

I don't know the purpose of this paragraph, do we need to mention TGL/DG1? This is "Gen 12", not "Gen 12+" in first paragraph.

Documentation/gpu/rfc/i915_dg2.rst

Quoted 4 lines
Documentation/gpu/rfc/i915_dg2.rst new file +4 -0
+
+In Gen 12.5 devices(XEXPSDV and DG2) Flat CCS is introduced to replace
+the userspace managed AUX pagetable with the flat indexed region of
+device memory for storing the compression state

Because this is DG2 document, do we need to mention XeHP SDV?

Quoted 7 lines
Documentation/gpu/rfc/i915_dg2.rst new file +6 -0
+
+GOP Driver steals a chunk of memory for the CCS surface corresponding
+to the entire range of local memory. The memory required for the CCS of
+the entire local memory is
+1/256 of the main local memory. The Gop driver will also program a
+secure register (XEHPSDV_FLAT_CCS_BASE_ADDR 0x4910) with this address

value.

I think it is not necessary to say the CCS base register. This is internal detail.

Documentation/gpu/rfc/i915_dg2.rst

Quoted 3 lines
Documentation/gpu/rfc/i915_dg2.rst new file +3 -0
+
+So the Total local memory available for driver allocation is Total lmem
+size - CCS data size

Well, we need to minus the GTT, lmem stolen (DG2 only), and WOPCM. Maybe just say, total local memory available is smaller because of other reserved regions.

Quoted 4 lines
Documentation/gpu/rfc/i915_dg2.rst new file +3 -0
+
+Flat CCS data needs to be cleared when a lmem object is allocated. And
+CCS data can be copied in and out of CCS region through

XY_CTRL_SURF_COPY_BLT.

OK.

--CQ

Quoted 17 lines
(quoted diff) +0 -0

b/Documentation/gpu/rfc/index.rst index 91e93a705230..afb320ed4028 100644

Documentation/gpu/rfc/index.rst +3 -1
@@ -20,6 +20,9 @@ host such documentation:
 
     i915_gem_lmem.rst
 
+.. toctree::
+    i915_dg2.rst
+
 .. toctree::
 
     i915_scheduler.rst
--

2.20.1

#21 lore raw

Re: [PATCH 14/14] Doc/gpu/rfc/i915: i915 DG2 uAPI

In reply to Ramalingam C
Quoted 19 lines · Ramalingam C

Details of the new features getting added as part of DG2 enabling and their implicit impact on the uAPI.

cc Daniel Vetter <[email protected]>
cc Matthew Auld <[email protected]>
---
 Documentation/gpu/rfc/i915_dg2.rst | 47 ++++++++++++++++++++++++++++++
 Documentation/gpu/rfc/index.rst    |  3 ++
 2 files changed, 50 insertions(+)
 create mode 100644 Documentation/gpu/rfc/i915_dg2.rst
Documentation/gpu/rfc/i915_dg2.rst new file +0 -0
new file mode 100644
index 000000000000..a83ca26cd758

Documentation/gpu/rfc/i915_dg2.rst line 9

Quoted 9 lines
Documentation/gpu/rfc/i915_dg2.rst new file +9 -0
@@ -0,0 +1,47 @@
+====================
+I915 DG2 RFC Section
+====================
+
+Upstream plan
+=============
+Plan to upstream the DG2 enabling is:
+
+* Merge basic HW enabling for DG2(Still without pciid)

here and everywhere below, missing space before (

Documentation/gpu/rfc/i915_dg2.rst line 19

Quoted 10 lines
Documentation/gpu/rfc/i915_dg2.rst new file +10 -0
+* Merge the 64k support for lmem
+* Merge the flat CCS enabling patches
+* Add the pciid for DG2 and enable the DG2 in CI
+
+
+64K page support for lmem
+=========================
+On DG2 hw, local-memory supports minimum GTT page size of 64k only. 4k is not supported anymore.
+
+DG2 hw dont support the 64k(lmem) and 4k(smem) pages in the same ppgtt Page table. Refer the

s/hw dont/doesn't/

Documentation/gpu/rfc/i915_dg2.rst line 26

Quoted 7 lines
Documentation/gpu/rfc/i915_dg2.rst new file +7 -0
+struct drm_i915_gem_create_ext for the implication of handling the 64k page size.
+
+.. kernel-doc:: include/uapi/drm/i915_drm.h
+        :functions: drm_i915_gem_create_ext
+
+
+flat CCS support for lmem

Flat

Documentation/gpu/rfc/i915_dg2.rst line 31

Quoted 5 lines
Documentation/gpu/rfc/i915_dg2.rst new file +5 -0
+=========================
+Gen 12+ devices support 3D surfaces compression and compression formats. This is
+accomplished by an additional compression control state (CCS) stored for each surface.
+
+Gen 12 devices(TGL and DG1) stores compression state in a separate region of memory.

s/stores/store/

Documentation/gpu/rfc/i915_dg2.rst line 35

Quoted 4 lines
Documentation/gpu/rfc/i915_dg2.rst new file +4 -0
+It is managed by userspace and has an associated set of userspace managed page tables
+used by hardware for address translation.
+
+In Gen 12.5 devices(XEXPSDV and DG2) Flat CCS is introduced to replace the userspace

There is no such thing as Gen 12.5. The "Gen" nomenclature stopped on Gen 12.

Lucas De Marchi

Quoted 29 lines
Documentation/gpu/rfc/i915_dg2.rst new file +12 -0
+managed AUX pagetable with the flat indexed region of device memory for storing the
+compression state
+
+GOP Driver steals a chunk of memory for the CCS surface corresponding to the entire
+range of local memory. The memory required for the CCS of the entire local memory is
+1/256 of the main local memory. The Gop driver will also program a secure register
+(XEHPSDV_FLAT_CCS_BASE_ADDR 0x4910) with this address value.
+
+So the Total local memory available for driver allocation is Total lmem size - CCS data size
+
+Flat CCS data needs to be cleared when a lmem object is allocated. And CCS data can
+be copied in and out of CCS region through XY_CTRL_SURF_COPY_BLT.
Documentation/gpu/rfc/index.rst +3 -1
index 91e93a705230..afb320ed4028 100644
@@ -20,6 +20,9 @@ host such documentation:
 
     i915_gem_lmem.rst
 
+.. toctree::
+    i915_dg2.rst
+
 .. toctree::
 
     i915_scheduler.rst
--

2.20.1

#22 lore raw

Re: [PATCH 14/14] Doc/gpu/rfc/i915: i915 DG2 uAPI

In reply to Ramalingam C
Quoted 11 lines · Ramalingam C

Details of the new features getting added as part of DG2 enabling and their implicit impact on the uAPI.

cc Daniel Vetter <[email protected]>
cc Matthew Auld <[email protected]>
---
 Documentation/gpu/rfc/i915_dg2.rst | 47 ++++++++++++++++++++++++++++++
 Documentation/gpu/rfc/index.rst    |  3 ++
 2 files changed, 50 insertions(+)
 create mode 100644 Documentation/gpu/rfc/i915_dg2.rst

Please move this and any uapi doc patch this relies on to the front of the series, so it serves as an intro.

I think the 64k side looks good with the uapi docs, once it's fully reviewed and acked.

What we still need is proper uapi docs for flat CCS. I think for that a separate flat ccs DOC: section would be good, which is then references by the gem_create_ext kerneldoc with a sphinx hyperlink.

The other thing that's missing here are the dg2 flat ccs drm_modifiers. So we need another patch for that, which in it's kerneldoc then also links to the flat ccs DOC: section.

Finally that flat ccs doc section needs to discuss all the flat ccs issues and uapi we've discussed. That patch needs to be acked both by userspace driver folks, and by compositor folks (because of the modifier uapi aspect). Please cc Pekka and Simon Ser for the compositor acks (but feel free to add more people).
-Daniel

Quoted 71 lines
Documentation/gpu/rfc/i915_dg2.rst new file +47 -0
new file mode 100644
index 000000000000..a83ca26cd758
@@ -0,0 +1,47 @@
+====================
+I915 DG2 RFC Section
+====================
+
+Upstream plan
+=============
+Plan to upstream the DG2 enabling is:
+
+* Merge basic HW enabling for DG2(Still without pciid)
+* Merge the 64k support for lmem
+* Merge the flat CCS enabling patches
+* Add the pciid for DG2 and enable the DG2 in CI
+
+
+64K page support for lmem
+=========================
+On DG2 hw, local-memory supports minimum GTT page size of 64k only. 4k is not supported anymore.
+
+DG2 hw dont support the 64k(lmem) and 4k(smem) pages in the same ppgtt Page table. Refer the
+struct drm_i915_gem_create_ext for the implication of handling the 64k page size.
+
+.. kernel-doc:: include/uapi/drm/i915_drm.h
+        :functions: drm_i915_gem_create_ext
+
+
+flat CCS support for lmem
+=========================
+Gen 12+ devices support 3D surfaces compression and compression formats. This is
+accomplished by an additional compression control state (CCS) stored for each surface.
+
+Gen 12 devices(TGL and DG1) stores compression state in a separate region of memory.
+It is managed by userspace and has an associated set of userspace managed page tables
+used by hardware for address translation.
+
+In Gen 12.5 devices(XEXPSDV and DG2) Flat CCS is introduced to replace the userspace
+managed AUX pagetable with the flat indexed region of device memory for storing the
+compression state
+
+GOP Driver steals a chunk of memory for the CCS surface corresponding to the entire
+range of local memory. The memory required for the CCS of the entire local memory is
+1/256 of the main local memory. The Gop driver will also program a secure register
+(XEHPSDV_FLAT_CCS_BASE_ADDR 0x4910) with this address value.
+
+So the Total local memory available for driver allocation is Total lmem size - CCS data size
+
+Flat CCS data needs to be cleared when a lmem object is allocated. And CCS data can
+be copied in and out of CCS region through XY_CTRL_SURF_COPY_BLT.
Documentation/gpu/rfc/index.rst +3 -0
index 91e93a705230..afb320ed4028 100644
@@ -20,6 +20,9 @@ host such documentation:
 
     i915_gem_lmem.rst
 
+.. toctree::
+    i915_dg2.rst
+
 .. toctree::
 
     i915_scheduler.rst
Signature · 1 line
2.20.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#23 lore raw

[Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915/dg2: Enabling 64k page size and flat ccs

In reply to Ramalingam C
== Series Details ==

== Series Details ==

Series: drm/i915/dg2: Enabling 64k page size and flat ccs
URL : https://patchwork.freedesktop.org/series/95686/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
5bf9ba0e1d7d drm/i915: Add has_64k_pages flag
70d612d1a872 drm/i915/xehpsdv: set min page-size to 64K
b2c0a0a180c4 drm/i915/xehpsdv: enforce min GTT alignment
ead605ff4376 drm/i915: enforce min page size for scratch
6f36d1ed51b4 drm/i915/gtt/xehpsdv: move scratch page to system memory
a1536f2e5783 drm/i915/xehpsdv: support 64K GTT pages
b4c9e5a8a623 drm/i915: Add vm min alignment support
147ff265df2f drm/i915/selftests: account for min_alignment in GTT selftests
-:108: WARNING:DEEP_INDENTATION: Too many leading tabs - consider code refactoring
#108: FILE: drivers/gpu/drm/i915/selftests/i915_gem_gtt.c:456:
+						if (offset < hole_start + aligned_size)

-:120: WARNING:DEEP_INDENTATION: Too many leading tabs - consider code refactoring #120: FILE: drivers/gpu/drm/i915/selftests/i915_gem_gtt.c:480:
+ if (offset + aligned_size > hole_end)

-:138: WARNING:DEEP_INDENTATION: Too many leading tabs - consider code refactoring #138: FILE: drivers/gpu/drm/i915/selftests/i915_gem_gtt.c:496:
+ if (offset < hole_start + aligned_size)

-:150: WARNING:DEEP_INDENTATION: Too many leading tabs - consider code refactoring #150: FILE: drivers/gpu/drm/i915/selftests/i915_gem_gtt.c:519:
+ if (offset + aligned_size > hole_end)

-:168: WARNING:DEEP_INDENTATION: Too many leading tabs - consider code refactoring #168: FILE: drivers/gpu/drm/i915/selftests/i915_gem_gtt.c:535:
+ if (offset < hole_start + aligned_size)

-:180: WARNING:DEEP_INDENTATION: Too many leading tabs - consider code refactoring #180: FILE: drivers/gpu/drm/i915/selftests/i915_gem_gtt.c:559:
+ if (offset + aligned_size > hole_end)

-:198: WARNING:DEEP_INDENTATION: Too many leading tabs - consider code refactoring #198: FILE: drivers/gpu/drm/i915/selftests/i915_gem_gtt.c:575:
+ if (offset < hole_start + aligned_size)

-:210: WARNING:DEEP_INDENTATION: Too many leading tabs - consider code refactoring #210: FILE: drivers/gpu/drm/i915/selftests/i915_gem_gtt.c:598:
+ if (offset + aligned_size > hole_end)

total: 0 errors, 8 warnings, 0 checks, 297 lines checked
7062763f0800 drm/i915/xehpsdv: implement memory coloring
79dc6a059d71 drm/i915/xehpsdv: Add has_flat_ccs to device info
4a8a8a8bebf2 drm/i915/lmem: Enable lmem for platforms with Flat CCS
fcae6b137d64 drm/i915/gt: Clear compress metadata for Gen12.5 >= platforms 749ff0849c0e drm/i915/uapi: document behaviour for DG2 64K support
2b517348c6fb Doc/gpu/rfc/i915: i915 DG2 uAPI
-:14: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #14:
new file mode 100644

-:19: WARNING:SPDX_LICENSE_TAG: Missing or malformed SPDX-License-Identifier tag in line 1 #19: FILE: Documentation/gpu/rfc/i915_dg2.rst:1:
+====================

total: 0 errors, 2 warnings, 0 checks, 56 lines checked

#24 lore raw

[Intel-gfx] ✗ Fi.CI.SPARSE: warning for drm/i915/dg2: Enabling 64k page size and flat ccs

In reply to Ramalingam C
== Series Details ==

== Series Details ==

Series: drm/i915/dg2: Enabling 64k page size and flat ccs
URL : https://patchwork.freedesktop.org/series/95686/
State : warning

== Summary ==

$ dim sparse --fast origin/drm-tip
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately.
-
+drivers/gpu/drm/i915/gt/intel_engine_stats.h:27:9: warning: trying to copy expression type 31
+drivers/gpu/drm/i915/gt/intel_engine_stats.h:27:9: warning: trying to copy expression type 31
+drivers/gpu/drm/i915/gt/intel_engine_stats.h:27:9: warning: trying to copy expression type 31
+drivers/gpu/drm/i915/gt/intel_engine_stats.h:32:9: warning: trying to copy expression type 31
+drivers/gpu/drm/i915/gt/intel_engine_stats.h:32:9: warning: trying to copy expression type 31
+drivers/gpu/drm/i915/gt/intel_engine_stats.h:49:9: warning: trying to copy expression type 31
+drivers/gpu/drm/i915/gt/intel_engine_stats.h:49:9: warning: trying to copy expression type 31
+drivers/gpu/drm/i915/gt/intel_engine_stats.h:49:9: warning: trying to copy expression type 31
+drivers/gpu/drm/i915/gt/intel_engine_stats.h:56:9: warning: trying to copy expression type 31
+drivers/gpu/drm/i915/gt/intel_engine_stats.h:56:9: warning: trying to copy expression type 31
+drivers/gpu/drm/i915/gt/intel_reset.c:1392:5: warning: context imbalance in 'intel_gt_reset_trylock' - different lock contexts for basic block
+drivers/gpu/drm/i915/i915_perf.c:1442:15: warning: memset with byte count of 16777216
+drivers/gpu/drm/i915/i915_perf.c:1496:15: warning: memset with byte count of 16777216
+./include/asm-generic/bitops/find.h:112:45: warning: shift count is negative (-262080)
+./include/asm-generic/bitops/find.h:32:31: warning: shift count is negative (-262080)
+./include/linux/spinlock.h:418:9: warning: context imbalance in 'fwtable_read16' - different lock contexts for basic block
+./include/linux/spinlock.h:418:9: warning: context imbalance in 'fwtable_read32' - different lock contexts for basic block
+./include/linux/spinlock.h:418:9: warning: context imbalance in 'fwtable_read64' - different lock contexts for basic block
+./include/linux/spinlock.h:418:9: warning: context imbalance in 'fwtable_read8' - different lock contexts for basic block
+./include/linux/spinlock.h:418:9: warning: context imbalance in 'fwtable_write16' - different lock contexts for basic block
+./include/linux/spinlock.h:418:9: warning: context imbalance in 'fwtable_write32' - different lock contexts for basic block
+./include/linux/spinlock.h:418:9: warning: context imbalance in 'fwtable_write8' - different lock contexts for basic block
+./include/linux/spinlock.h:418:9: warning: context imbalance in 'gen6_write16' - different lock contexts for basic block
+./include/linux/spinlock.h:418:9: warning: context imbalance in 'gen6_write32' - different lock contexts for basic block
+./include/linux/spinlock.h:418:9: warning: context imbalance in 'gen6_write8' - different lock contexts for basic block
#25 lore raw

[Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915/dg2: Enabling 64k page size and flat ccs

In reply to Ramalingam C
== Series Details ==

== Series Details ==

Series: drm/i915/dg2: Enabling 64k page size and flat ccs
URL : https://patchwork.freedesktop.org/series/95686/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_10717 -> Patchwork_21306
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_21306 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_21306, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21306/index.html

Known issues
------------

Here are the changes found in Patchwork_21306 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@amdgpu/amd_cs_nop@sync-fork-compute0:
- fi-snb-2600: NOTRUN -> [SKIP][1] ([fdo#109271]) +17 similar issues
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21306/fi-snb-2600/igt@amdgpu/[email protected]

#### Possible fixes ####

* igt@i915_selftest@live@hangcheck:
- fi-snb-2600: [INCOMPLETE][2] ([i915#3921]) -> [PASS][3]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10717/fi-snb-2600/igt@i915_selftest@[email protected]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21306/fi-snb-2600/igt@i915_selftest@[email protected]

[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[i915#3921]: https://gitlab.freedesktop.org/drm/intel/issues/3921

Participating hosts (37 -> 8)
------------------------------

ERROR: It appears as if the changes made in Patchwork_21306 prevented too many machines from booting.

Missing (29): fi-kbl-soraka fi-rkl-11600 fi-rkl-guc fi-bdw-gvtdvm fi-icl-u2 fi-apl-guc fi-icl-y fi-skl-6600u fi-cml-u2 fi-bxt-dsi fi-bdw-5557u fi-bsw-n3050 fi-glk-dsi fi-kbl-7500u fi-bsw-nick fi-skl-6700k2 fi-kbl-r fi-kbl-7567u fi-tgl-dsi fi-skl-guc fi-cfl-8700k fi-ehl-2 fi-jsl-1 fi-bsw-cyan fi-cfl-guc fi-kbl-guc fi-cfl-8109u fi-kbl-8809g fi-bsw-kefka

Build changes
-------------

* Linux: CI_DRM_10717 -> Patchwork_21306

CI-20190529: 20190529
CI_DRM_10717: 81e199c3565fe949631d8d08343bd89632a8ec0c @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_6242: 721fd85ee95225ed5df322f7182bdfa9b86a3e68 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_21306: 2b517348c6fb5167aa7a9fbbe59a548daef475fb @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

2b517348c6fb Doc/gpu/rfc/i915: i915 DG2 uAPI
749ff0849c0e drm/i915/uapi: document behaviour for DG2 64K support fcae6b137d64 drm/i915/gt: Clear compress metadata for Gen12.5 >= platforms 4a8a8a8bebf2 drm/i915/lmem: Enable lmem for platforms with Flat CCS 79dc6a059d71 drm/i915/xehpsdv: Add has_flat_ccs to device info 7062763f0800 drm/i915/xehpsdv: implement memory coloring 147ff265df2f drm/i915/selftests: account for min_alignment in GTT selftests b4c9e5a8a623 drm/i915: Add vm min alignment support a1536f2e5783 drm/i915/xehpsdv: support 64K GTT pages 6f36d1ed51b4 drm/i915/gtt/xehpsdv: move scratch page to system memory ead605ff4376 drm/i915: enforce min page size for scratch b2c0a0a180c4 drm/i915/xehpsdv: enforce min GTT alignment 70d612d1a872 drm/i915/xehpsdv: set min page-size to 64K 5bf9ba0e1d7d drm/i915: Add has_64k_pages flag

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_21306/index.html

#26 lore raw
In reply to Ramalingam C
Quoted 73 lines · Ramalingam C

This series introduces the enabling patches for new flat ccs feature and 64k page support for i915 local memory, along with documentation on the uAPI impact.

64k page support
================

On discrete platforms, starting from DG2, we have to contend with GTT page size restrictions when dealing with I915_MEMORY_CLASS_DEVICE objects. Specifically the hardware only supports 64K or larger GTT page sizes for such memory. The kernel will already ensure that all I915_MEMORY_CLASS_DEVICE memory is allocated using 64K or larger page sizes underneath.

Note that the returned size here will always reflect any required rounding up done by the kernel, i.e 4K will now become 64K on devices such as DG2. The GTT alignment will also need be at least 64K for such objects.

Note that due to how the hardware implements 64K GTT page support, we have some further complications:

1.) The entire PDE(which covers a 2M virtual address range), must contain only 64K PTEs, i.e mixing 4K and 64K PTEs in the same PDE is forbidden by the hardware.

2.) We still need to support 4K PTEs for I915_MEMORY_CLASS_SYSTEM objects.

To handle the above the kernel implements a memory coloring scheme to prevent userspace from mixing I915_MEMORY_CLASS_DEVICE and I915_MEMORY_CLASS_SYSTEM objects in the same PDE. If the kernel is ever unable to evict the required pages for the given PDE(different color) when inserting the object into the GTT then it will simply fail the request.

Since userspace needs to manage the GTT address space themselves, special care is needed to ensure this doesn’t happen. The simplest scheme is to simply align and round up all I915_MEMORY_CLASS_DEVICE objects to 2M, which avoids any issues here. At the very least this is likely needed for objects that can be placed in both I915_MEMORY_CLASS_DEVICE and I915_MEMORY_CLASS_SYSTEM, to avoid potential issues when the kernel needs to migrate the object behind the scenes, since that might also involve evicting other objects.

To summarise the GTT rules, on platforms like DG2:

1.) All objects that can be placed in I915_MEMORY_CLASS_DEVICE must have 64K alignment. The kernel will reject this otherwise.

2.) All I915_MEMORY_CLASS_DEVICE objects must never be placed in the same PDE with other I915_MEMORY_CLASS_SYSTEM objects. The kernel will reject this otherwise.

3.) Objects that can be placed in both I915_MEMORY_CLASS_DEVICE and I915_MEMORY_CLASS_SYSTEM should probably be aligned and padded out to 2M.

Flat CCS:
=========
Gen 12+ devices support 3D surfaces compression and compression formats. This is accomplished by an additional compression control state (CCS) stored for each surface.

Gen 12 devices(TGL and DG1) stores compression state in a separate region of memory. It is managed by userspace and has an associated set of userspace managed page tables used by hardware for address translation.

In Gen 12.5 devices(XEXPSDV and DG2) Flat CCS is introduced to replace the userspace managed AUX pagetable with the flat indexed region of device memory for storing the compression state

Quoted 7 lines

GOP Driver steals a chunk of memory for the CCS surface corresponding to the entire range of local memory. The memory required for the CCS of the entire local memory is 1/256 of the main local memory. The Gop driver will also program a secure register (XEHPSDV_FLAT_CCS_BASE_ADDR 0x4910) with this address value.

TODO: add patches for the flatccs modifiers and kdoc for them.

Ah it's here too :-)

Since this is uapi we also need link to igts (or at least where the tests are), and to mesa MR (if that hasn't all landed yet).
-Daniel

Quoted 62 lines

*** BLURB HERE ***

Abdiel Janulgue (1):
drm/i915/lmem: Enable lmem for platforms with Flat CCS

Ayaz A Siddiqui (1):
drm/i915/gt: Clear compress metadata for Gen12.5 >= platforms

Bommu Krishnaiah (1):
drm/i915: Add vm min alignment support

CQ Tang (1):
drm/i915/xehpsdv: Add has_flat_ccs to device info

Matthew Auld (8):
drm/i915/xehpsdv: set min page-size to 64K drm/i915/xehpsdv: enforce min GTT alignment drm/i915: enforce min page size for scratch drm/i915/gtt/xehpsdv: move scratch page to system memory drm/i915/xehpsdv: support 64K GTT pages drm/i915/selftests: account for min_alignment in GTT selftests drm/i915/xehpsdv: implement memory coloring drm/i915/uapi: document behaviour for DG2 64K support

Ramalingam C (1):
Doc/gpu/rfc/i915: i915 DG2 uAPI

Stuart Summers (1):
drm/i915: Add has_64k_pages flag

 Documentation/gpu/rfc/i915_dg2.rst            |  47 ++++++
 Documentation/gpu/rfc/index.rst               |   3 +
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c    |   6 +-
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |  61 ++++++++
 .../i915/gem/selftests/i915_gem_client_blt.c  |  23 ++-
 drivers/gpu/drm/i915/gt/gen6_ppgtt.c          |   1 +
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c          | 145 +++++++++++++++++-
 drivers/gpu/drm/i915/gt/intel_ggtt.c          |   2 +
 drivers/gpu/drm/i915/gt/intel_gpu_commands.h  |  14 ++
 drivers/gpu/drm/i915/gt/intel_gt.c            |  19 +++
 drivers/gpu/drm/i915/gt/intel_gt.h            |   1 +
 drivers/gpu/drm/i915/gt/intel_gtt.c           |  23 ++-
 drivers/gpu/drm/i915/gt/intel_gtt.h           |  20 +++
 drivers/gpu/drm/i915/gt/intel_migrate.c       | 120 ++++++++++++++-
 drivers/gpu/drm/i915/gt/intel_ppgtt.c         |   1 +
 drivers/gpu/drm/i915/gt/intel_region_lmem.c   |  27 +++-
 drivers/gpu/drm/i915/i915_drv.h               |   4 +
 drivers/gpu/drm/i915/i915_gem_evict.c         |  17 ++
 drivers/gpu/drm/i915/i915_pci.c               |   3 +
 drivers/gpu/drm/i915/i915_reg.h               |   3 +
 drivers/gpu/drm/i915/i915_vma.c               |  55 +++++--
 drivers/gpu/drm/i915/intel_device_info.h      |   2 +
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  96 ++++++++----
 drivers/gpu/drm/i915/selftests/mock_gtt.c     |   2 +
 include/uapi/drm/i915_drm.h                   |  61 +++++++-
 25 files changed, 681 insertions(+), 75 deletions(-)
 create mode 100644 Documentation/gpu/rfc/i915_dg2.rst
Signature · 1 line
2.20.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch