All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Jani Nikula <jani.nikula@intel.com>
Cc: <intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 2/5] drm/i915: split out i915_ptr_util.h
Date: Tue, 9 Sep 2025 09:37:59 -0400	[thread overview]
Message-ID: <aMAtt9WhrmAPoj6a@intel.com> (raw)
In-Reply-To: <ed8f3ef14844bdb1fecb528608f61093a16128cf.1757340520.git.jani.nikula@intel.com>

On Mon, Sep 08, 2025 at 05:11:46PM +0300, Jani Nikula wrote:
> Move pointer related utilities from i915_utils.h to a separate new
> i915_ptr_util.h header. Clean up related includes.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

I wonder if we should add some 'i915_' prefix in them
to avoid pretending they are a global kernel thing...

but the spin off is already a good clean-up start point...

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

> ---
>  drivers/gpu/drm/i915/gt/intel_context_types.h |  1 -
>  drivers/gpu/drm/i915/gt/intel_timeline.h      |  1 +
>  drivers/gpu/drm/i915/i915_ptr_util.h          | 66 +++++++++++++++++++
>  drivers/gpu/drm/i915/i915_request.h           |  5 +-
>  drivers/gpu/drm/i915/i915_utils.h             | 57 ----------------
>  drivers/gpu/drm/i915/i915_vma.h               |  6 +-
>  6 files changed, 73 insertions(+), 63 deletions(-)
>  create mode 100644 drivers/gpu/drm/i915/i915_ptr_util.h
> 
> diff --git a/drivers/gpu/drm/i915/gt/intel_context_types.h b/drivers/gpu/drm/i915/gt/intel_context_types.h
> index 98c7f6052069..10070ee4d74c 100644
> --- a/drivers/gpu/drm/i915/gt/intel_context_types.h
> +++ b/drivers/gpu/drm/i915/gt/intel_context_types.h
> @@ -14,7 +14,6 @@
>  
>  #include "i915_active_types.h"
>  #include "i915_sw_fence.h"
> -#include "i915_utils.h"
>  #include "intel_engine_types.h"
>  #include "intel_sseu.h"
>  #include "intel_wakeref.h"
> diff --git a/drivers/gpu/drm/i915/gt/intel_timeline.h b/drivers/gpu/drm/i915/gt/intel_timeline.h
> index 57308c4d664a..5f8c8f79714e 100644
> --- a/drivers/gpu/drm/i915/gt/intel_timeline.h
> +++ b/drivers/gpu/drm/i915/gt/intel_timeline.h
> @@ -10,6 +10,7 @@
>  
>  #include "i915_active.h"
>  #include "i915_syncmap.h"
> +#include "i915_utils.h"
>  #include "intel_timeline_types.h"
>  
>  struct drm_printer;
> diff --git a/drivers/gpu/drm/i915/i915_ptr_util.h b/drivers/gpu/drm/i915/i915_ptr_util.h
> new file mode 100644
> index 000000000000..9f8931d7d99b
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/i915_ptr_util.h
> @@ -0,0 +1,66 @@
> +/* SPDX-License-Identifier: MIT */
> +/* Copyright © 2025 Intel Corporation */
> +
> +#ifndef __I915_PTR_UTIL_H__
> +#define __I915_PTR_UTIL_H__
> +
> +#include <linux/types.h>
> +
> +#define ptr_mask_bits(ptr, n) ({					\
> +	unsigned long __v = (unsigned long)(ptr);			\
> +	(typeof(ptr))(__v & -BIT(n));					\
> +})
> +
> +#define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1))
> +
> +#define ptr_unpack_bits(ptr, bits, n) ({				\
> +	unsigned long __v = (unsigned long)(ptr);			\
> +	*(bits) = __v & (BIT(n) - 1);					\
> +	(typeof(ptr))(__v & -BIT(n));					\
> +})
> +
> +#define ptr_pack_bits(ptr, bits, n) ({					\
> +	unsigned long __bits = (bits);					\
> +	GEM_BUG_ON(__bits & -BIT(n));					\
> +	((typeof(ptr))((unsigned long)(ptr) | __bits));			\
> +})
> +
> +#define ptr_dec(ptr) ({							\
> +	unsigned long __v = (unsigned long)(ptr);			\
> +	(typeof(ptr))(__v - 1);						\
> +})
> +
> +#define ptr_inc(ptr) ({							\
> +	unsigned long __v = (unsigned long)(ptr);			\
> +	(typeof(ptr))(__v + 1);						\
> +})
> +
> +#define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT)
> +#define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT)
> +#define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
> +#define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
> +
> +static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
> +{
> +	return a - b;
> +}
> +
> +#define u64_to_ptr(T, x) ({						\
> +	typecheck(u64, x);						\
> +	(T *)(uintptr_t)(x);						\
> +})
> +
> +/*
> + * container_of_user: Extract the superclass from a pointer to a member.
> + *
> + * Exactly like container_of() with the exception that it plays nicely
> + * with sparse for __user @ptr.
> + */
> +#define container_of_user(ptr, type, member) ({				\
> +	void __user *__mptr = (void __user *)(ptr);			\
> +	BUILD_BUG_ON_MSG(!__same_type(*(ptr), typeof_member(type, member)) && \
> +			 !__same_type(*(ptr), void),			\
> +			 "pointer type mismatch in container_of()");	\
> +	((type __user *)(__mptr - offsetof(type, member))); })
> +
> +#endif /* __I915_PTR_UTIL_H__ */
> diff --git a/drivers/gpu/drm/i915/i915_request.h b/drivers/gpu/drm/i915/i915_request.h
> index 5f7e8138ec14..b09135301f39 100644
> --- a/drivers/gpu/drm/i915/i915_request.h
> +++ b/drivers/gpu/drm/i915/i915_request.h
> @@ -31,19 +31,20 @@
>  #include <linux/llist.h>
>  #include <linux/lockdep.h>
>  
> +#include <uapi/drm/i915_drm.h>
> +
>  #include "gem/i915_gem_context_types.h"
>  #include "gt/intel_context_types.h"
>  #include "gt/intel_engine_types.h"
>  #include "gt/intel_timeline_types.h"
>  
>  #include "i915_gem.h"
> +#include "i915_ptr_util.h"
>  #include "i915_scheduler.h"
>  #include "i915_selftest.h"
>  #include "i915_sw_fence.h"
>  #include "i915_vma_resource.h"
>  
> -#include <uapi/drm/i915_drm.h>
> -
>  struct drm_file;
>  struct drm_i915_gem_object;
>  struct drm_printer;
> diff --git a/drivers/gpu/drm/i915/i915_utils.h b/drivers/gpu/drm/i915/i915_utils.h
> index eb4d43c40009..dff02a944a57 100644
> --- a/drivers/gpu/drm/i915/i915_utils.h
> +++ b/drivers/gpu/drm/i915/i915_utils.h
> @@ -67,64 +67,12 @@ bool i915_error_injected(void);
>  		drm_err(&(i915)->drm, fmt, ##__VA_ARGS__); \
>  })
>  
> -#define ptr_mask_bits(ptr, n) ({					\
> -	unsigned long __v = (unsigned long)(ptr);			\
> -	(typeof(ptr))(__v & -BIT(n));					\
> -})
> -
> -#define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1))
> -
> -#define ptr_unpack_bits(ptr, bits, n) ({				\
> -	unsigned long __v = (unsigned long)(ptr);			\
> -	*(bits) = __v & (BIT(n) - 1);					\
> -	(typeof(ptr))(__v & -BIT(n));					\
> -})
> -
> -#define ptr_pack_bits(ptr, bits, n) ({					\
> -	unsigned long __bits = (bits);					\
> -	GEM_BUG_ON(__bits & -BIT(n));					\
> -	((typeof(ptr))((unsigned long)(ptr) | __bits));			\
> -})
> -
> -#define ptr_dec(ptr) ({							\
> -	unsigned long __v = (unsigned long)(ptr);			\
> -	(typeof(ptr))(__v - 1);						\
> -})
> -
> -#define ptr_inc(ptr) ({							\
> -	unsigned long __v = (unsigned long)(ptr);			\
> -	(typeof(ptr))(__v + 1);						\
> -})
> -
> -#define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT)
> -#define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT)
> -#define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
> -#define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
> -
>  #define fetch_and_zero(ptr) ({						\
>  	typeof(*ptr) __T = *(ptr);					\
>  	*(ptr) = (typeof(*ptr))0;					\
>  	__T;								\
>  })
>  
> -static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
> -{
> -	return a - b;
> -}
> -
> -/*
> - * container_of_user: Extract the superclass from a pointer to a member.
> - *
> - * Exactly like container_of() with the exception that it plays nicely
> - * with sparse for __user @ptr.
> - */
> -#define container_of_user(ptr, type, member) ({				\
> -	void __user *__mptr = (void __user *)(ptr);			\
> -	BUILD_BUG_ON_MSG(!__same_type(*(ptr), typeof_member(type, member)) && \
> -			 !__same_type(*(ptr), void),			\
> -			 "pointer type mismatch in container_of()");	\
> -	((type __user *)(__mptr - offsetof(type, member))); })
> -
>  /*
>   * check_user_mbz: Check that a user value exists and is zero
>   *
> @@ -143,11 +91,6 @@ static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b)
>  	get_user(mbz__, (U)) ? -EFAULT : mbz__ ? -EINVAL : 0;		\
>  })
>  
> -#define u64_to_ptr(T, x) ({						\
> -	typecheck(u64, x);						\
> -	(T *)(uintptr_t)(x);						\
> -})
> -
>  #define __mask_next_bit(mask) ({					\
>  	int __idx = ffs(mask) - 1;					\
>  	mask &= ~BIT(__idx);						\
> diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h
> index 0f9eee6d18d2..8054047840aa 100644
> --- a/drivers/gpu/drm/i915/i915_vma.h
> +++ b/drivers/gpu/drm/i915/i915_vma.h
> @@ -30,12 +30,12 @@
>  
>  #include <drm/drm_mm.h>
>  
> -#include "gt/intel_ggtt_fencing.h"
>  #include "gem/i915_gem_object.h"
> -
> -#include "i915_gem_gtt.h"
> +#include "gt/intel_ggtt_fencing.h"
>  
>  #include "i915_active.h"
> +#include "i915_gem_gtt.h"
> +#include "i915_ptr_util.h"
>  #include "i915_request.h"
>  #include "i915_vma_resource.h"
>  #include "i915_vma_types.h"
> -- 
> 2.47.3
> 

  reply	other threads:[~2025-09-09 13:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08 14:11 [PATCH 0/5] drm/i915: clean up i915_utils.h Jani Nikula
2025-09-08 14:11 ` [PATCH 1/5] drm/i915: redundant i915_utils.h includes Jani Nikula
2025-09-09 13:36   ` Rodrigo Vivi
2025-09-08 14:11 ` [PATCH 2/5] drm/i915: split out i915_ptr_util.h Jani Nikula
2025-09-09 13:37   ` Rodrigo Vivi [this message]
2025-09-08 14:11 ` [PATCH 3/5] drm/i915: split out i915_timer_util.[ch] Jani Nikula
2025-09-09 13:38   ` Rodrigo Vivi
2025-09-08 14:11 ` [PATCH 4/5] drm/i915: split out i915_list_util.h Jani Nikula
2025-09-09 13:39   ` Rodrigo Vivi
2025-09-08 14:11 ` [PATCH 5/5] drm/i915: split out i915_wait_util.h Jani Nikula
2025-09-09 13:40   ` Rodrigo Vivi
2025-09-10 12:06     ` Jani Nikula
2025-09-10 16:45       ` Rodrigo Vivi
2025-09-08 19:07 ` ✗ Fi.CI.BUILD: failure for drm/i915: clean up i915_utils.h Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aMAtt9WhrmAPoj6a@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.