drivers/gpu/drm/i915/gem/i915_gem_stolen.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/gem/i915_gem_stolen.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/i915/gem/i915_gem_stolen.c
Extension
.c
Size
29623 bytes
Lines
1105
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct intel_stolen_node {
	struct drm_i915_private *i915;
	struct drm_mm_node node;
};

/*
 * The BIOS typically reserves some of the system's memory for the exclusive
 * use of the integrated graphics. This memory is no longer available for
 * use by the OS and so the user finds that his system has less memory
 * available than he put in. We refer to this memory as stolen.
 *
 * The BIOS will allocate its framebuffer from the stolen memory. Our
 * goal is try to reuse that object for our own fbcon which must always
 * be available for panics. Anything else we can reuse the stolen memory
 * for is a boon.
 */

static int __i915_gem_stolen_insert_node_in_range(struct drm_i915_private *i915,
						  struct drm_mm_node *node, u64 size,
						  unsigned int alignment, u64 start, u64 end)
{
	int ret;

	if (!drm_mm_initialized(&i915->mm.stolen))
		return -ENODEV;

	/* WaSkipStolenMemoryFirstPage:bdw+ */
	if (GRAPHICS_VER(i915) >= 8 && start < 4096)
		start = 4096;

	mutex_lock(&i915->mm.stolen_lock);
	ret = drm_mm_insert_node_in_range(&i915->mm.stolen, node,
					  size, alignment, 0,
					  start, end, DRM_MM_INSERT_BEST);
	mutex_unlock(&i915->mm.stolen_lock);

	return ret;
}

static int i915_gem_stolen_insert_node_in_range(struct intel_stolen_node *node, u64 size,
						unsigned int alignment, u64 start, u64 end)
{
	return __i915_gem_stolen_insert_node_in_range(node->i915, &node->node,
						      size, alignment,
						      start, end);
}

static int __i915_gem_stolen_insert_node(struct drm_i915_private *i915,
					 struct drm_mm_node *node, u64 size,
					 unsigned int alignment)
{
	return __i915_gem_stolen_insert_node_in_range(i915, node,
						      size, alignment,
						      I915_GEM_STOLEN_BIAS,
						      U64_MAX);
}

static int i915_gem_stolen_insert_node(struct intel_stolen_node *node, u64 size,
				       unsigned int alignment)
{
	return __i915_gem_stolen_insert_node(node->i915, &node->node, size, alignment);
}

static void __i915_gem_stolen_remove_node(struct drm_i915_private *i915,
					  struct drm_mm_node *node)
{
	mutex_lock(&i915->mm.stolen_lock);
	drm_mm_remove_node(node);
	mutex_unlock(&i915->mm.stolen_lock);
}

static void i915_gem_stolen_remove_node(struct intel_stolen_node *node)
{
	__i915_gem_stolen_remove_node(node->i915, &node->node);
}

static bool valid_stolen_size(struct drm_i915_private *i915, struct resource *dsm)
{
	return (dsm->start != 0 || HAS_LMEMBAR_SMEM_STOLEN(i915)) && dsm->end > dsm->start;
}

static int adjust_stolen(struct drm_i915_private *i915,
			 struct resource *dsm)
{
	struct i915_ggtt *ggtt = to_gt(i915)->ggtt;
	struct intel_uncore *uncore = ggtt->vm.gt->uncore;

	if (!valid_stolen_size(i915, dsm))
		return -EINVAL;

Annotation

Implementation Notes