Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/i915: split out i915_ptr_util.h

Move pointer related utilities from i915_utils.h to a separate new
i915_ptr_util.h header. Clean up related includes.

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://lore.kernel.org/r/3cd06aa2483e68f19401292e9d4c28bf2977fce5.1757582214.git.jani.nikula@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>

+73 -63
-1
drivers/gpu/drm/i915/gt/intel_context_types.h
··· 14 14 15 15 #include "i915_active_types.h" 16 16 #include "i915_sw_fence.h" 17 - #include "i915_utils.h" 18 17 #include "intel_engine_types.h" 19 18 #include "intel_sseu.h" 20 19 #include "intel_wakeref.h"
+1
drivers/gpu/drm/i915/gt/intel_timeline.h
··· 10 10 11 11 #include "i915_active.h" 12 12 #include "i915_syncmap.h" 13 + #include "i915_utils.h" 13 14 #include "intel_timeline_types.h" 14 15 15 16 struct drm_printer;
+66
drivers/gpu/drm/i915/i915_ptr_util.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* Copyright © 2025 Intel Corporation */ 3 + 4 + #ifndef __I915_PTR_UTIL_H__ 5 + #define __I915_PTR_UTIL_H__ 6 + 7 + #include <linux/types.h> 8 + 9 + #define ptr_mask_bits(ptr, n) ({ \ 10 + unsigned long __v = (unsigned long)(ptr); \ 11 + (typeof(ptr))(__v & -BIT(n)); \ 12 + }) 13 + 14 + #define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1)) 15 + 16 + #define ptr_unpack_bits(ptr, bits, n) ({ \ 17 + unsigned long __v = (unsigned long)(ptr); \ 18 + *(bits) = __v & (BIT(n) - 1); \ 19 + (typeof(ptr))(__v & -BIT(n)); \ 20 + }) 21 + 22 + #define ptr_pack_bits(ptr, bits, n) ({ \ 23 + unsigned long __bits = (bits); \ 24 + GEM_BUG_ON(__bits & -BIT(n)); \ 25 + ((typeof(ptr))((unsigned long)(ptr) | __bits)); \ 26 + }) 27 + 28 + #define ptr_dec(ptr) ({ \ 29 + unsigned long __v = (unsigned long)(ptr); \ 30 + (typeof(ptr))(__v - 1); \ 31 + }) 32 + 33 + #define ptr_inc(ptr) ({ \ 34 + unsigned long __v = (unsigned long)(ptr); \ 35 + (typeof(ptr))(__v + 1); \ 36 + }) 37 + 38 + #define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT) 39 + #define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT) 40 + #define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT) 41 + #define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT) 42 + 43 + static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b) 44 + { 45 + return a - b; 46 + } 47 + 48 + #define u64_to_ptr(T, x) ({ \ 49 + typecheck(u64, x); \ 50 + (T *)(uintptr_t)(x); \ 51 + }) 52 + 53 + /* 54 + * container_of_user: Extract the superclass from a pointer to a member. 55 + * 56 + * Exactly like container_of() with the exception that it plays nicely 57 + * with sparse for __user @ptr. 58 + */ 59 + #define container_of_user(ptr, type, member) ({ \ 60 + void __user *__mptr = (void __user *)(ptr); \ 61 + BUILD_BUG_ON_MSG(!__same_type(*(ptr), typeof_member(type, member)) && \ 62 + !__same_type(*(ptr), void), \ 63 + "pointer type mismatch in container_of()"); \ 64 + ((type __user *)(__mptr - offsetof(type, member))); }) 65 + 66 + #endif /* __I915_PTR_UTIL_H__ */
+3 -2
drivers/gpu/drm/i915/i915_request.h
··· 31 31 #include <linux/llist.h> 32 32 #include <linux/lockdep.h> 33 33 34 + #include <uapi/drm/i915_drm.h> 35 + 34 36 #include "gem/i915_gem_context_types.h" 35 37 #include "gt/intel_context_types.h" 36 38 #include "gt/intel_engine_types.h" 37 39 #include "gt/intel_timeline_types.h" 38 40 39 41 #include "i915_gem.h" 42 + #include "i915_ptr_util.h" 40 43 #include "i915_scheduler.h" 41 44 #include "i915_selftest.h" 42 45 #include "i915_sw_fence.h" 43 46 #include "i915_vma_resource.h" 44 - 45 - #include <uapi/drm/i915_drm.h> 46 47 47 48 struct drm_file; 48 49 struct drm_i915_gem_object;
-57
drivers/gpu/drm/i915/i915_utils.h
··· 67 67 drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \ 68 68 }) 69 69 70 - #define ptr_mask_bits(ptr, n) ({ \ 71 - unsigned long __v = (unsigned long)(ptr); \ 72 - (typeof(ptr))(__v & -BIT(n)); \ 73 - }) 74 - 75 - #define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1)) 76 - 77 - #define ptr_unpack_bits(ptr, bits, n) ({ \ 78 - unsigned long __v = (unsigned long)(ptr); \ 79 - *(bits) = __v & (BIT(n) - 1); \ 80 - (typeof(ptr))(__v & -BIT(n)); \ 81 - }) 82 - 83 - #define ptr_pack_bits(ptr, bits, n) ({ \ 84 - unsigned long __bits = (bits); \ 85 - GEM_BUG_ON(__bits & -BIT(n)); \ 86 - ((typeof(ptr))((unsigned long)(ptr) | __bits)); \ 87 - }) 88 - 89 - #define ptr_dec(ptr) ({ \ 90 - unsigned long __v = (unsigned long)(ptr); \ 91 - (typeof(ptr))(__v - 1); \ 92 - }) 93 - 94 - #define ptr_inc(ptr) ({ \ 95 - unsigned long __v = (unsigned long)(ptr); \ 96 - (typeof(ptr))(__v + 1); \ 97 - }) 98 - 99 - #define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT) 100 - #define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT) 101 - #define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT) 102 - #define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT) 103 - 104 70 #define fetch_and_zero(ptr) ({ \ 105 71 typeof(*ptr) __T = *(ptr); \ 106 72 *(ptr) = (typeof(*ptr))0; \ 107 73 __T; \ 108 74 }) 109 - 110 - static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b) 111 - { 112 - return a - b; 113 - } 114 - 115 - /* 116 - * container_of_user: Extract the superclass from a pointer to a member. 117 - * 118 - * Exactly like container_of() with the exception that it plays nicely 119 - * with sparse for __user @ptr. 120 - */ 121 - #define container_of_user(ptr, type, member) ({ \ 122 - void __user *__mptr = (void __user *)(ptr); \ 123 - BUILD_BUG_ON_MSG(!__same_type(*(ptr), typeof_member(type, member)) && \ 124 - !__same_type(*(ptr), void), \ 125 - "pointer type mismatch in container_of()"); \ 126 - ((type __user *)(__mptr - offsetof(type, member))); }) 127 75 128 76 /* 129 77 * check_user_mbz: Check that a user value exists and is zero ··· 89 141 #define check_user_mbz(U) ({ \ 90 142 typeof(*(U)) mbz__; \ 91 143 get_user(mbz__, (U)) ? -EFAULT : mbz__ ? -EINVAL : 0; \ 92 - }) 93 - 94 - #define u64_to_ptr(T, x) ({ \ 95 - typecheck(u64, x); \ 96 - (T *)(uintptr_t)(x); \ 97 144 }) 98 145 99 146 #define __mask_next_bit(mask) ({ \
+3 -3
drivers/gpu/drm/i915/i915_vma.h
··· 30 30 31 31 #include <drm/drm_mm.h> 32 32 33 - #include "gt/intel_ggtt_fencing.h" 34 33 #include "gem/i915_gem_object.h" 35 - 36 - #include "i915_gem_gtt.h" 34 + #include "gt/intel_ggtt_fencing.h" 37 35 38 36 #include "i915_active.h" 37 + #include "i915_gem_gtt.h" 38 + #include "i915_ptr_util.h" 39 39 #include "i915_request.h" 40 40 #include "i915_vma_resource.h" 41 41 #include "i915_vma_types.h"