| 1 | /* SPDX-License-Identifier: MIT */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Copyright © 2024 Intel Corporation | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef _TTM_BACKUP_H_ | 
|---|
| 7 | #define _TTM_BACKUP_H_ | 
|---|
| 8 |  | 
|---|
| 9 | #include <linux/mm_types.h> | 
|---|
| 10 | #include <linux/shmem_fs.h> | 
|---|
| 11 |  | 
|---|
| 12 | /** | 
|---|
| 13 | * ttm_backup_handle_to_page_ptr() - Convert handle to struct page pointer | 
|---|
| 14 | * @handle: The handle to convert. | 
|---|
| 15 | * | 
|---|
| 16 | * Converts an opaque handle received from the | 
|---|
| 17 | * ttm_backup_backup_page() function to an (invalid) | 
|---|
| 18 | * struct page pointer suitable for a struct page array. | 
|---|
| 19 | * | 
|---|
| 20 | * Return: An (invalid) struct page pointer. | 
|---|
| 21 | */ | 
|---|
| 22 | static inline struct page * | 
|---|
| 23 | ttm_backup_handle_to_page_ptr(unsigned long handle) | 
|---|
| 24 | { | 
|---|
| 25 | return (struct page *)(handle << 1 | 1); | 
|---|
| 26 | } | 
|---|
| 27 |  | 
|---|
| 28 | /** | 
|---|
| 29 | * ttm_backup_page_ptr_is_handle() - Whether a struct page pointer is a handle | 
|---|
| 30 | * @page: The struct page pointer to check. | 
|---|
| 31 | * | 
|---|
| 32 | * Return: true if the struct page pointer is a handld returned from | 
|---|
| 33 | * ttm_backup_handle_to_page_ptr(). False otherwise. | 
|---|
| 34 | */ | 
|---|
| 35 | static inline bool ttm_backup_page_ptr_is_handle(const struct page *page) | 
|---|
| 36 | { | 
|---|
| 37 | return (unsigned long)page & 1; | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | /** | 
|---|
| 41 | * ttm_backup_page_ptr_to_handle() - Convert a struct page pointer to a handle | 
|---|
| 42 | * @page: The struct page pointer to convert | 
|---|
| 43 | * | 
|---|
| 44 | * Return: The handle that was previously used in | 
|---|
| 45 | * ttm_backup_handle_to_page_ptr() to obtain a struct page pointer, suitable | 
|---|
| 46 | * for use as argument in the struct ttm_backup_drop() or | 
|---|
| 47 | * ttm_backup_copy_page() functions. | 
|---|
| 48 | */ | 
|---|
| 49 | static inline unsigned long | 
|---|
| 50 | ttm_backup_page_ptr_to_handle(const struct page *page) | 
|---|
| 51 | { | 
|---|
| 52 | WARN_ON(!ttm_backup_page_ptr_is_handle(page)); | 
|---|
| 53 | return (unsigned long)page >> 1; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | void ttm_backup_drop(struct file *backup, pgoff_t handle); | 
|---|
| 57 |  | 
|---|
| 58 | int ttm_backup_copy_page(struct file *backup, struct page *dst, | 
|---|
| 59 | pgoff_t handle, bool intr); | 
|---|
| 60 |  | 
|---|
| 61 | s64 | 
|---|
| 62 | ttm_backup_backup_page(struct file *backup, struct page *page, | 
|---|
| 63 | bool writeback, pgoff_t idx, gfp_t page_gfp, | 
|---|
| 64 | gfp_t alloc_gfp); | 
|---|
| 65 |  | 
|---|
| 66 | void ttm_backup_fini(struct file *backup); | 
|---|
| 67 |  | 
|---|
| 68 | u64 ttm_backup_bytes_avail(void); | 
|---|
| 69 |  | 
|---|
| 70 | struct file *ttm_backup_shmem_create(loff_t size); | 
|---|
| 71 |  | 
|---|
| 72 | #endif | 
|---|
| 73 |  | 
|---|