3 * (C) COPYRIGHT 2011-2016 ARM Limited. All rights reserved.
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
18 #ifndef _KBASE_CONTEXT_H_
19 #define _KBASE_CONTEXT_H_
21 #include <linux/atomic.h>
24 int kbase_context_set_create_flags(struct kbase_context *kctx, u32 flags);
27 * kbase_ctx_flag - Check if @flag is set on @kctx
28 * @kctx: Pointer to kbase context to check
29 * @flag: Flag to check
31 * Return: true if @flag is set on @kctx, false if not.
33 static inline bool kbase_ctx_flag(struct kbase_context *kctx,
34 enum kbase_context_flags flag)
36 return atomic_read(&kctx->flags) & flag;
40 * kbase_ctx_flag_clear - Clear @flag on @kctx
41 * @kctx: Pointer to kbase context
42 * @flag: Flag to clear
44 * Clear the @flag on @kctx. This is done atomically, so other flags being
45 * cleared or set at the same time will be safe.
47 * Some flags have locking requirements, check the documentation for the
50 static inline void kbase_ctx_flag_clear(struct kbase_context *kctx,
51 enum kbase_context_flags flag)
53 #if KERNEL_VERSION(4, 3, 0) > LINUX_VERSION_CODE
55 * Earlier kernel versions doesn't have atomic_andnot() or
56 * atomic_and(). atomic_clear_mask() was only available on some
57 * architectures and removed on arm in v3.13 on arm and arm64.
59 * Use a compare-exchange loop to clear the flag on pre 4.3 kernels,
60 * when atomic_andnot() becomes available.
65 old = atomic_read(&kctx->flags);
68 } while (atomic_cmpxchg(&kctx->flags, old, new) != old);
70 atomic_andnot(flag, &kctx->flags);
75 * kbase_ctx_flag_set - Set @flag on @kctx
76 * @kctx: Pointer to kbase context
77 * @flag: Flag to clear
79 * Set the @flag on @kctx. This is done atomically, so other flags being
80 * cleared or set at the same time will be safe.
82 * Some flags have locking requirements, check the documentation for the
85 static inline void kbase_ctx_flag_set(struct kbase_context *kctx,
86 enum kbase_context_flags flag)
88 atomic_or(flag, &kctx->flags);
90 #endif /* _KBASE_CONTEXT_H_ */