xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/mali_kbase_mem_migrate.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2022-2023 ARM Limited. All rights reserved.
5  *
6  * This program is free software and is provided to you under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation, and any use by you of this program is subject to the terms
9  * of such GNU license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you can access it online at
18  * http://www.gnu.org/licenses/gpl-2.0.html.
19  *
20  */
21 
22 /**
23  * DOC: Base kernel page migration implementation.
24  */
25 
26 #define PAGE_STATUS_MASK ((u8)0x3F)
27 #define PAGE_STATUS_GET(status) (status & PAGE_STATUS_MASK)
28 #define PAGE_STATUS_SET(status, value) ((status & ~PAGE_STATUS_MASK) | (value & PAGE_STATUS_MASK))
29 
30 #define PAGE_ISOLATE_SHIFT (7)
31 #define PAGE_ISOLATE_MASK ((u8)1 << PAGE_ISOLATE_SHIFT)
32 #define PAGE_ISOLATE_SET(status, value)                                                            \
33 	((status & ~PAGE_ISOLATE_MASK) | (value << PAGE_ISOLATE_SHIFT))
34 #define IS_PAGE_ISOLATED(status) ((bool)(status & PAGE_ISOLATE_MASK))
35 
36 #define PAGE_MOVABLE_SHIFT (6)
37 #define PAGE_MOVABLE_MASK ((u8)1 << PAGE_MOVABLE_SHIFT)
38 #define PAGE_MOVABLE_CLEAR(status) ((status) & ~PAGE_MOVABLE_MASK)
39 #define PAGE_MOVABLE_SET(status) (status | PAGE_MOVABLE_MASK)
40 
41 #define IS_PAGE_MOVABLE(status) ((bool)(status & PAGE_MOVABLE_MASK))
42 
43 /* Global integer used to determine if module parameter value has been
44  * provided and if page migration feature is enabled.
45  */
46 extern int kbase_page_migration_enabled;
47 
48 /**
49  * kbase_alloc_page_metadata - Allocate and initialize page metadata
50  * @kbdev:    Pointer to kbase device.
51  * @p:        Page to assign metadata to.
52  * @dma_addr: DMA address mapped to paged.
53  * @group_id: Memory group ID associated with the entity that is
54  *            allocating the page metadata.
55  *
56  * This will allocate memory for the page's metadata, initialize it and
57  * assign a reference to the page's private field. Importantly, once
58  * the metadata is set and ready this function will mark the page as
59  * movable.
60  *
61  * Return: true if successful or false otherwise.
62  */
63 bool kbase_alloc_page_metadata(struct kbase_device *kbdev, struct page *p, dma_addr_t dma_addr,
64 			       u8 group_id);
65 
66 /**
67  * kbase_free_page_later - Defer freeing of given page.
68  * @kbdev:  Pointer to kbase device
69  * @p:      Page to free
70  *
71  * This will add given page to a list of pages which will be freed at
72  * a later time.
73  */
74 void kbase_free_page_later(struct kbase_device *kbdev, struct page *p);
75 
76 #if (KERNEL_VERSION(6, 0, 0) > LINUX_VERSION_CODE)
77 /*
78  * kbase_mem_migrate_set_address_space_ops - Set address space operations
79  *
80  * @kbdev: Pointer to object representing an instance of GPU platform device.
81  * @filp:  Pointer to the struct file corresponding to device file
82  *         /dev/malixx instance, passed to the file's open method.
83  *
84  * Assign address space operations to the given file struct @filp and
85  * add a reference to @kbdev.
86  */
87 void kbase_mem_migrate_set_address_space_ops(struct kbase_device *kbdev, struct file *const filp);
88 #endif
89 
90 /*
91  * kbase_mem_migrate_init - Initialise kbase page migration
92  *
93  * @kbdev: Pointer to kbase device
94  *
95  * Enables page migration by default based on GPU and setup work queue to
96  * defer freeing pages during page migration callbacks.
97  */
98 void kbase_mem_migrate_init(struct kbase_device *kbdev);
99 
100 /*
101  * kbase_mem_migrate_term - Terminate kbase page migration
102  *
103  * @kbdev: Pointer to kbase device
104  *
105  * This will flush any work left to free pages from page migration
106  * and destroy workqueue associated.
107  */
108 void kbase_mem_migrate_term(struct kbase_device *kbdev);
109