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