Commit 1eca0778 authored by Jani Nikula's avatar Jani Nikula
Browse files

drm/i915: add struct i915_dsm to wrap dsm members together



Wrap the stolen memory related struct drm_i915_private members (dsm,
dsm_reserved, and stolen_usable_size) together in a a new struct
i915_dsm.

Signed-off-by: default avatarJani Nikula <jani.nikula@intel.com>
Reviewed-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230116173422.1858527-1-jani.nikula@intel.com
parent 1af13bc6
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -331,15 +331,15 @@ static void i8xx_fbc_program_cfb(struct intel_fbc *fbc)
{
{
	struct drm_i915_private *i915 = fbc->i915;
	struct drm_i915_private *i915 = fbc->i915;


	GEM_BUG_ON(range_overflows_end_t(u64, i915->dsm.start,
	GEM_BUG_ON(range_overflows_end_t(u64, i915->dsm.stolen.start,
					 fbc->compressed_fb.start, U32_MAX));
					 fbc->compressed_fb.start, U32_MAX));
	GEM_BUG_ON(range_overflows_end_t(u64, i915->dsm.start,
	GEM_BUG_ON(range_overflows_end_t(u64, i915->dsm.stolen.start,
					 fbc->compressed_llb.start, U32_MAX));
					 fbc->compressed_llb.start, U32_MAX));


	intel_de_write(i915, FBC_CFB_BASE,
	intel_de_write(i915, FBC_CFB_BASE,
		       i915->dsm.start + fbc->compressed_fb.start);
		       i915->dsm.stolen.start + fbc->compressed_fb.start);
	intel_de_write(i915, FBC_LL_BASE,
	intel_de_write(i915, FBC_LL_BASE,
		       i915->dsm.start + fbc->compressed_llb.start);
		       i915->dsm.stolen.start + fbc->compressed_llb.start);
}
}


static const struct intel_fbc_funcs i8xx_fbc_funcs = {
static const struct intel_fbc_funcs i8xx_fbc_funcs = {
@@ -712,7 +712,7 @@ static u64 intel_fbc_stolen_end(struct drm_i915_private *i915)
	 * underruns, even if that range is not reserved by the BIOS. */
	 * underruns, even if that range is not reserved by the BIOS. */
	if (IS_BROADWELL(i915) ||
	if (IS_BROADWELL(i915) ||
	    (DISPLAY_VER(i915) == 9 && !IS_BROXTON(i915)))
	    (DISPLAY_VER(i915) == 9 && !IS_BROXTON(i915)))
		end = resource_size(&i915->dsm) - 8 * 1024 * 1024;
		end = resource_size(&i915->dsm.stolen) - 8 * 1024 * 1024;
	else
	else
		end = U64_MAX;
		end = U64_MAX;


+1 −1
Original line number Original line Diff line number Diff line
@@ -170,7 +170,7 @@ static int intelfb_alloc(struct drm_fb_helper *helper,
		 * important and we should probably use that space with FBC or other
		 * important and we should probably use that space with FBC or other
		 * features.
		 * features.
		 */
		 */
		if (size * 2 < dev_priv->stolen_usable_size)
		if (size * 2 < dev_priv->dsm.usable_size)
			obj = i915_gem_object_create_stolen(dev_priv, size);
			obj = i915_gem_object_create_stolen(dev_priv, size);
		if (IS_ERR(obj))
		if (IS_ERR(obj))
			obj = i915_gem_object_create_shmem(dev_priv, size);
			obj = i915_gem_object_create_shmem(dev_priv, size);
+1 −1
Original line number Original line Diff line number Diff line
@@ -107,7 +107,7 @@ initial_plane_vma(struct drm_i915_private *i915,
	 */
	 */
	if (IS_ENABLED(CONFIG_FRAMEBUFFER_CONSOLE) &&
	if (IS_ENABLED(CONFIG_FRAMEBUFFER_CONSOLE) &&
	    mem == i915->mm.stolen_region &&
	    mem == i915->mm.stolen_region &&
	    size * 2 > i915->stolen_usable_size)
	    size * 2 > i915->dsm.usable_size)
		return NULL;
		return NULL;


	obj = i915_gem_object_create_region_at(mem, phys_base, size, 0);
	obj = i915_gem_object_create_region_at(mem, phys_base, size, 0);
+18 −18
Original line number Original line Diff line number Diff line
@@ -211,7 +211,7 @@ static void g4x_get_stolen_reserved(struct drm_i915_private *i915,
					IS_GM45(i915) ?
					IS_GM45(i915) ?
					CTG_STOLEN_RESERVED :
					CTG_STOLEN_RESERVED :
					ELK_STOLEN_RESERVED);
					ELK_STOLEN_RESERVED);
	resource_size_t stolen_top = i915->dsm.end + 1;
	resource_size_t stolen_top = i915->dsm.stolen.end + 1;


	drm_dbg(&i915->drm, "%s_STOLEN_RESERVED = %08x\n",
	drm_dbg(&i915->drm, "%s_STOLEN_RESERVED = %08x\n",
		IS_GM45(i915) ? "CTG" : "ELK", reg_val);
		IS_GM45(i915) ? "CTG" : "ELK", reg_val);
@@ -276,7 +276,7 @@ static void vlv_get_stolen_reserved(struct drm_i915_private *i915,
				    resource_size_t *size)
				    resource_size_t *size)
{
{
	u32 reg_val = intel_uncore_read(uncore, GEN6_STOLEN_RESERVED);
	u32 reg_val = intel_uncore_read(uncore, GEN6_STOLEN_RESERVED);
	resource_size_t stolen_top = i915->dsm.end + 1;
	resource_size_t stolen_top = i915->dsm.stolen.end + 1;


	drm_dbg(&i915->drm, "GEN6_STOLEN_RESERVED = %08x\n", reg_val);
	drm_dbg(&i915->drm, "GEN6_STOLEN_RESERVED = %08x\n", reg_val);


@@ -365,7 +365,7 @@ static void bdw_get_stolen_reserved(struct drm_i915_private *i915,
				    resource_size_t *size)
				    resource_size_t *size)
{
{
	u32 reg_val = intel_uncore_read(uncore, GEN6_STOLEN_RESERVED);
	u32 reg_val = intel_uncore_read(uncore, GEN6_STOLEN_RESERVED);
	resource_size_t stolen_top = i915->dsm.end + 1;
	resource_size_t stolen_top = i915->dsm.stolen.end + 1;


	drm_dbg(&i915->drm, "GEN6_STOLEN_RESERVED = %08x\n", reg_val);
	drm_dbg(&i915->drm, "GEN6_STOLEN_RESERVED = %08x\n", reg_val);


@@ -414,7 +414,7 @@ static void icl_get_stolen_reserved(struct drm_i915_private *i915,
}
}


/*
/*
 * Initialize i915->dsm_reserved to contain the reserved space within the Data
 * Initialize i915->dsm.reserved to contain the reserved space within the Data
 * Stolen Memory. This is a range on the top of DSM that is reserved, not to
 * Stolen Memory. This is a range on the top of DSM that is reserved, not to
 * be used by driver, so must be excluded from the region passed to the
 * be used by driver, so must be excluded from the region passed to the
 * allocator later. In the spec this is also called as WOPCM.
 * allocator later. In the spec this is also called as WOPCM.
@@ -430,7 +430,7 @@ static int init_reserved_stolen(struct drm_i915_private *i915)
	resource_size_t reserved_size;
	resource_size_t reserved_size;
	int ret = 0;
	int ret = 0;


	stolen_top = i915->dsm.end + 1;
	stolen_top = i915->dsm.stolen.end + 1;
	reserved_base = stolen_top;
	reserved_base = stolen_top;
	reserved_size = 0;
	reserved_size = 0;


@@ -471,13 +471,13 @@ static int init_reserved_stolen(struct drm_i915_private *i915)
		goto bail_out;
		goto bail_out;
	}
	}


	i915->dsm_reserved =
	i915->dsm.reserved =
		(struct resource)DEFINE_RES_MEM(reserved_base, reserved_size);
		(struct resource)DEFINE_RES_MEM(reserved_base, reserved_size);


	if (!resource_contains(&i915->dsm, &i915->dsm_reserved)) {
	if (!resource_contains(&i915->dsm.stolen, &i915->dsm.reserved)) {
		drm_err(&i915->drm,
		drm_err(&i915->drm,
			"Stolen reserved area %pR outside stolen memory %pR\n",
			"Stolen reserved area %pR outside stolen memory %pR\n",
			&i915->dsm_reserved, &i915->dsm);
			&i915->dsm.reserved, &i915->dsm.stolen);
		ret = -EINVAL;
		ret = -EINVAL;
		goto bail_out;
		goto bail_out;
	}
	}
@@ -485,7 +485,7 @@ static int init_reserved_stolen(struct drm_i915_private *i915)
	return 0;
	return 0;


bail_out:
bail_out:
	i915->dsm_reserved =
	i915->dsm.reserved =
		(struct resource)DEFINE_RES_MEM(reserved_base, 0);
		(struct resource)DEFINE_RES_MEM(reserved_base, 0);


	return ret;
	return ret;
@@ -517,27 +517,27 @@ static int i915_gem_init_stolen(struct intel_memory_region *mem)
	if (request_smem_stolen(i915, &mem->region))
	if (request_smem_stolen(i915, &mem->region))
		return -ENOSPC;
		return -ENOSPC;


	i915->dsm = mem->region;
	i915->dsm.stolen = mem->region;


	if (init_reserved_stolen(i915))
	if (init_reserved_stolen(i915))
		return -ENOSPC;
		return -ENOSPC;


	/* Exclude the reserved region from driver use */
	/* Exclude the reserved region from driver use */
	mem->region.end = i915->dsm_reserved.start - 1;
	mem->region.end = i915->dsm.reserved.start - 1;
	mem->io_size = min(mem->io_size, resource_size(&mem->region));
	mem->io_size = min(mem->io_size, resource_size(&mem->region));


	i915->stolen_usable_size = resource_size(&mem->region);
	i915->dsm.usable_size = resource_size(&mem->region);


	drm_dbg(&i915->drm,
	drm_dbg(&i915->drm,
		"Memory reserved for graphics device: %lluK, usable: %lluK\n",
		"Memory reserved for graphics device: %lluK, usable: %lluK\n",
		(u64)resource_size(&i915->dsm) >> 10,
		(u64)resource_size(&i915->dsm.stolen) >> 10,
		(u64)i915->stolen_usable_size >> 10);
		(u64)i915->dsm.usable_size >> 10);


	if (i915->stolen_usable_size == 0)
	if (i915->dsm.usable_size == 0)
		return -ENOSPC;
		return -ENOSPC;


	/* Basic memrange allocator for stolen space. */
	/* Basic memrange allocator for stolen space. */
	drm_mm_init(&i915->mm.stolen, 0, i915->stolen_usable_size);
	drm_mm_init(&i915->mm.stolen, 0, i915->dsm.usable_size);


	return 0;
	return 0;
}
}
@@ -587,7 +587,7 @@ i915_pages_create_for_stolen(struct drm_device *dev,
	struct sg_table *st;
	struct sg_table *st;
	struct scatterlist *sg;
	struct scatterlist *sg;


	GEM_BUG_ON(range_overflows(offset, size, resource_size(&i915->dsm)));
	GEM_BUG_ON(range_overflows(offset, size, resource_size(&i915->dsm.stolen)));


	/* We hide that we have no struct page backing our stolen object
	/* We hide that we have no struct page backing our stolen object
	 * by wrapping the contiguous physical allocation with a fake
	 * by wrapping the contiguous physical allocation with a fake
@@ -607,7 +607,7 @@ i915_pages_create_for_stolen(struct drm_device *dev,
	sg->offset = 0;
	sg->offset = 0;
	sg->length = size;
	sg->length = size;


	sg_dma_address(sg) = (dma_addr_t)i915->dsm.start + offset;
	sg_dma_address(sg) = (dma_addr_t)i915->dsm.stolen.start + offset;
	sg_dma_len(sg) = size;
	sg_dma_len(sg) = size;


	return st;
	return st;
+6 −6
Original line number Original line Diff line number Diff line
@@ -301,7 +301,7 @@ static int chv_rc6_init(struct intel_rc6 *rc6)
	pcbr = intel_uncore_read(uncore, VLV_PCBR);
	pcbr = intel_uncore_read(uncore, VLV_PCBR);
	if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) {
	if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) {
		drm_dbg(&i915->drm, "BIOS didn't set up PCBR, fixing up\n");
		drm_dbg(&i915->drm, "BIOS didn't set up PCBR, fixing up\n");
		paddr = i915->dsm.end + 1 - pctx_size;
		paddr = i915->dsm.stolen.end + 1 - pctx_size;
		GEM_BUG_ON(paddr > U32_MAX);
		GEM_BUG_ON(paddr > U32_MAX);


		pctx_paddr = (paddr & ~4095);
		pctx_paddr = (paddr & ~4095);
@@ -325,7 +325,7 @@ static int vlv_rc6_init(struct intel_rc6 *rc6)
		/* BIOS set it up already, grab the pre-alloc'd space */
		/* BIOS set it up already, grab the pre-alloc'd space */
		resource_size_t pcbr_offset;
		resource_size_t pcbr_offset;


		pcbr_offset = (pcbr & ~4095) - i915->dsm.start;
		pcbr_offset = (pcbr & ~4095) - i915->dsm.stolen.start;
		pctx = i915_gem_object_create_region_at(i915->mm.stolen_region,
		pctx = i915_gem_object_create_region_at(i915->mm.stolen_region,
							pcbr_offset,
							pcbr_offset,
							pctx_size,
							pctx_size,
@@ -354,10 +354,10 @@ static int vlv_rc6_init(struct intel_rc6 *rc6)
	}
	}


	GEM_BUG_ON(range_overflows_end_t(u64,
	GEM_BUG_ON(range_overflows_end_t(u64,
					 i915->dsm.start,
					 i915->dsm.stolen.start,
					 pctx->stolen->start,
					 pctx->stolen->start,
					 U32_MAX));
					 U32_MAX));
	pctx_paddr = i915->dsm.start + pctx->stolen->start;
	pctx_paddr = i915->dsm.stolen.start + pctx->stolen->start;
	intel_uncore_write(uncore, VLV_PCBR, pctx_paddr);
	intel_uncore_write(uncore, VLV_PCBR, pctx_paddr);


out:
out:
@@ -448,8 +448,8 @@ static bool bxt_check_bios_rc6_setup(struct intel_rc6 *rc6)
	 */
	 */
	rc6_ctx_base =
	rc6_ctx_base =
		intel_uncore_read(uncore, RC6_CTX_BASE) & RC6_CTX_BASE_MASK;
		intel_uncore_read(uncore, RC6_CTX_BASE) & RC6_CTX_BASE_MASK;
	if (!(rc6_ctx_base >= i915->dsm_reserved.start &&
	if (!(rc6_ctx_base >= i915->dsm.reserved.start &&
	      rc6_ctx_base + PAGE_SIZE < i915->dsm_reserved.end)) {
	      rc6_ctx_base + PAGE_SIZE < i915->dsm.reserved.end)) {
		drm_dbg(&i915->drm, "RC6 Base address not as expected.\n");
		drm_dbg(&i915->drm, "RC6 Base address not as expected.\n");
		enable_rc6 = false;
		enable_rc6 = false;
	}
	}
Loading