drivers/gpu/drm/ttm/ttm_backup.c

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

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/ttm/ttm_backup.c
Extension
.c
Size
5612 bytes
Lines
186
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

folio_clear_dirty_for_io(to_folio)) {
		folio_set_reclaim(to_folio);
		ret = shmem_writeout(to_folio, NULL, NULL);
		if (!folio_test_writeback(to_folio))
			folio_clear_reclaim(to_folio);
		/*
		 * If writeout succeeds, it unlocks the folio.	errors
		 * are otherwise dropped, since writeout is only best
		 * effort here.
		 */
		if (ret)
			folio_unlock(to_folio);
	} else {
		folio_unlock(to_folio);
	}

	folio_put(to_folio);

	return handle;
}

/**
 * ttm_backup_fini() - Free the struct backup resources after last use.
 * @backup: Pointer to the struct backup whose resources to free.
 *
 * After a call to this function, it's illegal to use the @backup pointer.
 */
void ttm_backup_fini(struct file *backup)
{
	fput(backup);
}

/**
 * ttm_backup_bytes_avail() - Report the approximate number of bytes of backup space
 * left for backup.
 *
 * This function is intended also for driver use to indicate whether a
 * backup attempt is meaningful.
 *
 * Return: An approximate size of backup space available.
 */
u64 ttm_backup_bytes_avail(void)
{
	/*
	 * The idea behind backing up to shmem is that shmem objects may
	 * eventually be swapped out. So no point swapping out if there
	 * is no or low swap-space available. But the accuracy of this
	 * number also depends on shmem actually swapping out backed-up
	 * shmem objects without too much buffering.
	 */
	return (u64)get_nr_swap_pages() << PAGE_SHIFT;
}
EXPORT_SYMBOL_GPL(ttm_backup_bytes_avail);

/**
 * ttm_backup_shmem_create() - Create a shmem-based struct backup.
 * @size: The maximum size (in bytes) to back up.
 *
 * Create a backup utilizing shmem objects.
 *
 * Return: A pointer to a struct file on success,
 * an error pointer on error.
 */
struct file *ttm_backup_shmem_create(loff_t size)
{
	return shmem_file_setup("ttm shmem backup", size,
				EMPTY_VMA_FLAGS);
}

Annotation

Implementation Notes