drivers/gpu/drm/ttm/ttm_device.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/ttm/ttm_device.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/ttm/ttm_device.c
Extension
.c
Size
8353 bytes
Lines
320
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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

if (unlikely(glob->dummy_read_page == NULL)) {
			ret = -ENOMEM;
			goto out;
		}
		pr_warn("Using GFP_DMA32 fallback for dummy_read_page\n");
	}

	INIT_LIST_HEAD(&glob->device_list);
	atomic_set(&glob->bo_count, 0);

	debugfs_create_atomic_t("buffer_objects", 0444, ttm_debugfs_root,
				&glob->bo_count);
out:
	if (ret && ttm_debugfs_root)
		debugfs_remove(ttm_debugfs_root);
	if (ret)
		--ttm_glob_use_count;
	mutex_unlock(&ttm_global_mutex);
	return ret;
}

/**
 * ttm_device_prepare_hibernation - move GTT BOs to shmem for hibernation.
 *
 * @bdev: A pointer to a struct ttm_device to prepare hibernation for.
 *
 * Return: 0 on success, negative number on failure.
 */
int ttm_device_prepare_hibernation(struct ttm_device *bdev)
{
	struct ttm_operation_ctx ctx = { };
	int ret;

	do {
		ret = ttm_device_swapout(bdev, &ctx, GFP_KERNEL);
	} while (ret > 0);
	return ret;
}
EXPORT_SYMBOL(ttm_device_prepare_hibernation);

/*
 * A buffer object shrink method that tries to swap out the first
 * buffer object on the global::swap_lru list.
 */
int ttm_global_swapout(struct ttm_operation_ctx *ctx, gfp_t gfp_flags)
{
	struct ttm_global *glob = &ttm_glob;
	struct ttm_device *bdev;
	int ret = 0;

	mutex_lock(&ttm_global_mutex);
	list_for_each_entry(bdev, &glob->device_list, device_list) {
		ret = ttm_device_swapout(bdev, ctx, gfp_flags);
		if (ret > 0) {
			list_move_tail(&bdev->device_list, &glob->device_list);
			break;
		}
	}
	mutex_unlock(&ttm_global_mutex);
	return ret;
}

int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
		       gfp_t gfp_flags)
{
	struct ttm_resource_manager *man;
	unsigned i;
	s64 lret;

	for (i = TTM_PL_SYSTEM; i < TTM_NUM_MEM_TYPES; ++i) {
		man = ttm_manager_type(bdev, i);
		if (!man || !man->use_tt)
			continue;

		lret = ttm_bo_swapout(bdev, ctx, man, gfp_flags, 1);
		/* Can be both positive (num_pages) and negative (error) */
		if (lret)
			return lret;
	}
	return 0;
}
EXPORT_SYMBOL(ttm_device_swapout);

/**
 * ttm_device_init
 *
 * @bdev: A pointer to a struct ttm_device to initialize.
 * @funcs: Function table for the device.
 * @dev: The core kernel device pointer for DMA mappings and allocations.
 * @mapping: The address space to use for this bo.

Annotation

Implementation Notes