Re: [PATCH v2 01/22] drm/xe: Introduce xe_any helpers

"Mallesh, Koujalagi" <[email protected]>
Newsgroups org.freedesktop.lists.intel-xe
Message-ID <[email protected]>
On 28-07-2026 09:40 pm, Michal Wajdeczko wrote:
> In upcoming patches we want to define macros that will work with
> either xe_device or xe_tile or xe_gt pointers. To make them work
> and to allow compiler optimizations, introduce set of helpers
> that will return either expected pointer type or NULL or make
> necessary conversions to/from the struct xe/device/pci_dev.
>
> Signed-off-by: Michal Wajdeczko <[email protected]>
> Cc: Rodrigo Vivi <[email protected]>
> Cc: Thomas Hellström <[email protected]>
> Cc: Matthew Brost <[email protected]>
> ---
> v2: add include (Sashiko) and const support (Mallesh)
>      reuse existing to_xe() helpers (Michal)
> ---
>   drivers/gpu/drm/xe/xe_any.h | 112 ++++++++++++++++++++++++++++++++++++
>   1 file changed, 112 insertions(+)
>   create mode 100644 drivers/gpu/drm/xe/xe_any.h
>
> diff --git a/drivers/gpu/drm/xe/xe_any.h b/drivers/gpu/drm/xe/xe_any.h
> new file mode 100644
> index 000000000000..a2b1e42fbc5c
> --- /dev/null
> +++ b/drivers/gpu/drm/xe/xe_any.h
> @@ -0,0 +1,112 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright © 2026 Intel Corporation
> + */
> +
> +#ifndef _XE_ANY_H_
> +#define _XE_ANY_H_
> +
> +#include "xe_device.h"
> +
> +/**
> + * xe_any_if_type() - Get the pointer only if it is @type pointer.
> + * @any: any pointer
> + * @type: data type to look for
> + *
> + * Return: the @type pointer or NULL.
> + */
> +#define xe_any_if_type(any, type)						\
> +	_Generic((any),								\
> +		 type * : (any),						\
> +		 const type * : (any),						\
> +		 default : NULL)
> +
> +/**
> + * xe_any_if_gt() - Get the pointer only if it is &xe_gt.
> + * @any: any pointer
> + *
> + * Return: the @xe_gt pointer or NULL.
> + */
> +#define xe_any_if_gt(any)	xe_any_if_type((any), struct xe_gt)
> +
> +/**
> + * xe_any_if_tile() - Get the pointer only if it is &xe_tile.
> + * @any: any pointer
> + *
> + * Return: the @xe_tile pointer or NULL.
> + */
> +#define xe_any_if_tile(any)	xe_any_if_type((any), struct xe_tile)
> +
> +/**
> + * xe_any_if_xe() - Get the pointer only if it is &xe_device.
> + * @any: any pointer
> + *
> + * Return: the @xe_device pointer or NULL.
> + */
> +#define xe_any_if_xe(any)	xe_any_if_type((any), struct xe_device)
> +
> +/**
> + * xe_any_if_pdev() - Get the pointer only if it is &pci_dev.
> + * @any: any pointer
> + *
> + * Return: the @pci_dev pointer or NULL.
> + */
> +#define xe_any_if_pdev(any)	xe_any_if_type((any), struct pci_dev)
> +
> +/**
> + * xe_any_to_xe() - Obtain the &xe_device pointer.
> + * @any: the &pci_dev or the &xe_device or &xe_tile or &xe_gt pointer
> + *
> + * Return: the @xe_device pointer or backpointer.
> + */
> +#define xe_any_to_xe(any)								\
> +	_Generic((any),									\
> +		 struct xe_device * : (any),						\
> +		 const struct xe_device * : (any),					\
> +		 struct xe_tile * : tile_to_xe((struct xe_tile *)(any)),		\
> +		 const struct xe_tile * : tile_to_xe((const struct xe_tile *)(any)),	\
> +		 struct xe_gt * : gt_to_xe((struct xe_gt *)(any)),			\
> +		 const struct xe_gt * : gt_to_xe((const struct xe_gt *)(any)),		\
> +		 struct pci_dev * : pdev_to_xe_device((struct pci_dev *)(any)),		\
> +		 struct device * : kdev_to_xe_device((struct device *)(any)))
> +
> +/**
> + * xe_any_to_dev() - Obtain the &device pointer.
> + * @any: the &pci_dev or the &xe_device or &xe_tile or &xe_gt pointer
> + *
> + * Return: the @xe_device pointer or backpointer.
> + */
should be device pointer right.
> +#define xe_any_to_dev(any)							\
> +	_Generic((any),								\
> +		 struct device * : (any),					\
> +		 default : xe_any_to_xe(any)->drm.dev)
> +
Add const struct device* as well.
> +/**
> + * xe_any_to_pdev() - Obtain the &pci_dev pointer.
> + * @any: the &pci_dev or the &xe_device or &xe_tile or &xe_gt pointer
> + *
> + * Return: the @pci_dev pointer or backpointer.
> + */
> +#define xe_any_to_pdev(any)							\
> +	_Generic((any),								\
> +		 struct pci_dev * : (any),					\
> +		 default : to_pci_dev(xe_any_to_dev(any)))
Please add struct pci_dev * : &((struct pci_dev *)(any))->dev  and const 
struct pci_dev *.
> +
> +/**
> + * xe_any_id() - Get the identifier of the underlying object.
> + * @any: the &pci_dev or the &xe_device or &xe_tile or &xe_gt pointer
> + *
> + * Return: the identifier of the object, or 0 if nor applicable/available.
> + */

Typo: please change "nor" to "not"

With all above cosmetic changes.

Reviewed-by: Mallesh Koujalagi <[email protected]>

> +#define xe_any_id(any)								\
> +	_Generic((any),								\
> +		 struct xe_gt * : ((struct xe_gt *)(any))->info.id,		\
> +		 const struct xe_gt * : ((const struct xe_gt *)(any))->info.id,	\
> +		 struct xe_tile * : ((struct xe_tile *)(any))->id,		\
> +		 const struct xe_tile * : ((const struct xe_tile *)(any))->id,	\
> +		 struct xe_device * : 0,					\
> +		 const struct xe_device * : 0,					\
> +		 struct pci_dev * : 0,						\
> +		 struct device * : 0)
> +
> +#endif
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.