Skip to content

Commit a394f12

Browse files
committed
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 <[email protected]> Link: https://lore.kernel.org/r/3cd06aa2483e68f19401292e9d4c28bf2977fce5.1757582214.git.jani.nikula@intel.com Signed-off-by: Jani Nikula <[email protected]>
1 parent 72136ef commit a394f12

File tree

6 files changed

+73
-63
lines changed

6 files changed

+73
-63
lines changed

drivers/gpu/drm/i915/gt/intel_context_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "i915_active_types.h"
1616
#include "i915_sw_fence.h"
17-
#include "i915_utils.h"
1817
#include "intel_engine_types.h"
1918
#include "intel_sseu.h"
2019
#include "intel_wakeref.h"

drivers/gpu/drm/i915/gt/intel_timeline.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "i915_active.h"
1212
#include "i915_syncmap.h"
13+
#include "i915_utils.h"
1314
#include "intel_timeline_types.h"
1415

1516
struct drm_printer;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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__ */

drivers/gpu/drm/i915/i915_request.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,20 @@
3131
#include <linux/llist.h>
3232
#include <linux/lockdep.h>
3333

34+
#include <uapi/drm/i915_drm.h>
35+
3436
#include "gem/i915_gem_context_types.h"
3537
#include "gt/intel_context_types.h"
3638
#include "gt/intel_engine_types.h"
3739
#include "gt/intel_timeline_types.h"
3840

3941
#include "i915_gem.h"
42+
#include "i915_ptr_util.h"
4043
#include "i915_scheduler.h"
4144
#include "i915_selftest.h"
4245
#include "i915_sw_fence.h"
4346
#include "i915_vma_resource.h"
4447

45-
#include <uapi/drm/i915_drm.h>
46-
4748
struct drm_file;
4849
struct drm_i915_gem_object;
4950
struct drm_printer;

drivers/gpu/drm/i915/i915_utils.h

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -67,64 +67,12 @@ bool i915_error_injected(void);
6767
drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \
6868
})
6969

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-
10470
#define fetch_and_zero(ptr) ({ \
10571
typeof(*ptr) __T = *(ptr); \
10672
*(ptr) = (typeof(*ptr))0; \
10773
__T; \
10874
})
10975

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-
12876
/*
12977
* check_user_mbz: Check that a user value exists and is zero
13078
*
@@ -143,11 +91,6 @@ static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
14391
get_user(mbz__, (U)) ? -EFAULT : mbz__ ? -EINVAL : 0; \
14492
})
14593

146-
#define u64_to_ptr(T, x) ({ \
147-
typecheck(u64, x); \
148-
(T *)(uintptr_t)(x); \
149-
})
150-
15194
#define __mask_next_bit(mask) ({ \
15295
int __idx = ffs(mask) - 1; \
15396
mask &= ~BIT(__idx); \

drivers/gpu/drm/i915/i915_vma.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030

3131
#include <drm/drm_mm.h>
3232

33-
#include "gt/intel_ggtt_fencing.h"
3433
#include "gem/i915_gem_object.h"
35-
36-
#include "i915_gem_gtt.h"
34+
#include "gt/intel_ggtt_fencing.h"
3735

3836
#include "i915_active.h"
37+
#include "i915_gem_gtt.h"
38+
#include "i915_ptr_util.h"
3939
#include "i915_request.h"
4040
#include "i915_vma_resource.h"
4141
#include "i915_vma_types.h"

0 commit comments

Comments
 (0)