xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/context/mali_kbase_context.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2011-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 #ifndef _KBASE_CONTEXT_H_
23 #define _KBASE_CONTEXT_H_
24 
25 #include <linux/atomic.h>
26 
27 /**
28  * kbase_context_debugfs_init - Initialize the kctx platform
29  *                              specific debugfs
30  *
31  * @kctx: kbase context
32  *
33  * This initializes some debugfs interfaces specific to the platform the source
34  * is compiled for.
35  */
36 void kbase_context_debugfs_init(struct kbase_context *const kctx);
37 
38 /**
39  * kbase_context_debugfs_term - Terminate the kctx platform
40  *                              specific debugfs
41  *
42  * @kctx: kbase context
43  *
44  * This terminates some debugfs interfaces specific to the platform the source
45  * is compiled for.
46  */
47 void kbase_context_debugfs_term(struct kbase_context *const kctx);
48 
49 /**
50  * kbase_create_context() - Create a kernel base context.
51  *
52  * @kbdev:       Object representing an instance of GPU platform device,
53  *               allocated from the probe method of the Mali driver.
54  * @is_compat:   Force creation of a 32-bit context
55  * @flags:       Flags to set, which shall be any combination of
56  *               BASEP_CONTEXT_CREATE_KERNEL_FLAGS.
57  * @api_version: Application program interface version, as encoded in
58  *               a single integer by the KBASE_API_VERSION macro.
59  * @filp:        Pointer to the struct file corresponding to device file
60  *               /dev/malixx instance, passed to the file's open method.
61  *
62  * Up to one context can be created for each client that opens the device file
63  * /dev/malixx. Context creation is deferred until a special ioctl() system call
64  * is made on the device file. Each context has its own GPU address space.
65  *
66  * Return: new kbase context or NULL on failure
67  */
68 struct kbase_context *
69 kbase_create_context(struct kbase_device *kbdev, bool is_compat,
70 	base_context_create_flags const flags,
71 	unsigned long api_version,
72 	struct file *filp);
73 
74 /**
75  * kbase_destroy_context - Destroy a kernel base context.
76  * @kctx: Context to destroy
77  *
78  * Will release all outstanding regions.
79  */
80 void kbase_destroy_context(struct kbase_context *kctx);
81 
82 /**
83  * kbase_ctx_flag - Check if @flag is set on @kctx
84  * @kctx: Pointer to kbase context to check
85  * @flag: Flag to check
86  *
87  * Return: true if @flag is set on @kctx, false if not.
88  */
kbase_ctx_flag(struct kbase_context * kctx,enum kbase_context_flags flag)89 static inline bool kbase_ctx_flag(struct kbase_context *kctx,
90 				      enum kbase_context_flags flag)
91 {
92 	return atomic_read(&kctx->flags) & flag;
93 }
94 
95 /**
96  * kbase_ctx_compat_mode - Indicate whether a kbase context needs to operate
97  *                         in compatibility mode for 32-bit userspace.
98  * @kctx: kbase context
99  *
100  * Return: True if needs to maintain compatibility, False otherwise.
101  */
kbase_ctx_compat_mode(struct kbase_context * kctx)102 static inline bool kbase_ctx_compat_mode(struct kbase_context *kctx)
103 {
104 	return !IS_ENABLED(CONFIG_64BIT) ||
105 	       (IS_ENABLED(CONFIG_64BIT) && kbase_ctx_flag(kctx, KCTX_COMPAT));
106 }
107 
108 /**
109  * kbase_ctx_flag_clear - Clear @flag on @kctx
110  * @kctx: Pointer to kbase context
111  * @flag: Flag to clear
112  *
113  * Clear the @flag on @kctx. This is done atomically, so other flags being
114  * cleared or set at the same time will be safe.
115  *
116  * Some flags have locking requirements, check the documentation for the
117  * respective flags.
118  */
kbase_ctx_flag_clear(struct kbase_context * kctx,enum kbase_context_flags flag)119 static inline void kbase_ctx_flag_clear(struct kbase_context *kctx,
120 					enum kbase_context_flags flag)
121 {
122 	atomic_andnot(flag, &kctx->flags);
123 }
124 
125 /**
126  * kbase_ctx_flag_set - Set @flag on @kctx
127  * @kctx: Pointer to kbase context
128  * @flag: Flag to set
129  *
130  * Set the @flag on @kctx. This is done atomically, so other flags being
131  * cleared or set at the same time will be safe.
132  *
133  * Some flags have locking requirements, check the documentation for the
134  * respective flags.
135  */
kbase_ctx_flag_set(struct kbase_context * kctx,enum kbase_context_flags flag)136 static inline void kbase_ctx_flag_set(struct kbase_context *kctx,
137 				      enum kbase_context_flags flag)
138 {
139 	atomic_or(flag, &kctx->flags);
140 }
141 #endif /* _KBASE_CONTEXT_H_ */
142