From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88F5FC5CFCF for ; Fri, 14 Aug 2026 17:18:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 44FFD10F6B1; Fri, 14 Aug 2026 17:18:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="YwtsnZjP"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id B80B310E58A for ; Fri, 14 Aug 2026 17:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1786727894; x=1818263894; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VmvwLwd0FWQH7prxaR9cmYXPWv44Q/k1ISoPtcrI6NA=; b=YwtsnZjPpDFPeehElyD18P0AfM04dZQbUS9/iAG8zXZmXf5DUXk9e8mc QZlvHCHLb9qzOHJs7owVA4VVOkg06YS3ojCzbOVNciHOlJwH4EXd9tV71 4B35ncJBvCrGs1ANJ10wSIxaJl1jOX7iGV8j2O2gozFZbYTg+AJ2QeaH4 uc8TsaGkZOvu1uFfzViZWLZpLvITv+Hn22WXjdQTk9vP/exuuxYfKPwtP V93OcjZ+4SZT9PsM4tKsohH+ot/NUDgggSwFwUJ8bShjM197nnAd2mPPN /5MQYUsy6FMUKQlivFt43WtyLzQgaK5F9q04SXbNx0dEeVYQ/34Vd3tGf g==; X-CSE-ConnectionGUID: 0EDsBKlaS6GNbGQTKzGKFg== X-CSE-MsgGUID: 6GdieWrXTE+L/L6e47XLhQ== X-IronPort-AV: E=McAfee;i="6800,10657,11875"; a="98464003" X-IronPort-AV: E=Sophos;i="6.25,222,1779174000"; d="scan'208";a="98464003" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2026 10:18:14 -0700 X-CSE-ConnectionGUID: 3uwfxSkdRQ+g0xs/rChxCw== X-CSE-MsgGUID: pf1GGNmuTsCA4fKJlRpvZw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,222,1779174000"; d="scan'208";a="262946039" Received: from smoudgil-mobl1.amr.corp.intel.com (HELO mwajdecz-hp.clients.intel.com) ([10.245.117.247]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2026 10:18:13 -0700 From: Michal Wajdeczko To: intel-xe@lists.freedesktop.org Cc: Michal Wajdeczko , Rodrigo Vivi , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Matthew Brost , Mallesh Koujalagi , Jani Nikula Subject: [PATCH v5 01/33] drm/xe: Introduce xe_any helpers Date: Fri, 14 Aug 2026 19:17:27 +0200 Message-ID: <20260814171801.13347-2-michal.wajdeczko@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260814171801.13347-1-michal.wajdeczko@intel.com> References: <20260814171801.13347-1-michal.wajdeczko@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" 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 Cc: Rodrigo Vivi Cc: Thomas Hellström Cc: Matthew Brost Reviewed-by: Rodrigo Vivi Reviewed-by: Mallesh Koujalagi Cc: Jani Nikula --- v2: add include (Sashiko) and const support (Mallesh) reuse existing to_xe() helpers (Michal) v3: fix another typo and fix to_pdev (Sashiko) use assoc macros/helpers (Jani) add support for drm_device (Michal) --- drivers/gpu/drm/xe/xe_any.h | 137 ++++++++++++++++++++++++++++++++++++ 1 file changed, 137 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..5d97afa76915 --- /dev/null +++ b/drivers/gpu/drm/xe/xe_any.h @@ -0,0 +1,137 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2026 Intel Corporation + */ + +#ifndef _XE_ANY_H_ +#define _XE_ANY_H_ + +#include "xe_device.h" + +#define __xe_any_to_self_assoc(type, any) \ + const type * : (any), \ + type * : (any) + +/** + * 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), \ + __xe_any_to_self_assoc(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) + +#define __xe_any_to_other_assoc(const, from, other, p) \ + const struct from * : __##from##_to_##other((const struct from *)(p)) + +#define __xe_tile_to_xe_device(p) tile_to_xe(p) +#define __xe_gt_to_xe_device(p) gt_to_xe(p) +#define __pci_dev_to_xe_device(p) pdev_to_xe_device(p) +#define __device_to_xe_device(p) kdev_to_xe_device(p) +#define __drm_device_to_xe_device(p) to_xe_device(p) +#define __pci_dev_to_device(p) (&(p)->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), \ + __xe_any_to_self_assoc(struct xe_device, (any)), \ + __xe_any_to_other_assoc(/* */, xe_tile, xe_device, (any)), \ + __xe_any_to_other_assoc(const, xe_tile, xe_device, (any)), \ + __xe_any_to_other_assoc(/* */, xe_gt, xe_device, (any)), \ + __xe_any_to_other_assoc(const, xe_gt, xe_device, (any)), \ + __xe_any_to_other_assoc(, drm_device, xe_device, (any)), \ + __xe_any_to_other_assoc(, pci_dev, xe_device, (any)), \ + __xe_any_to_other_assoc(, device, xe_device, (any))) + +/** + * xe_any_to_drm() - Obtain the &drm_device pointer. + * @any: the &pci_dev or the &xe_device or &xe_tile or &xe_gt pointer + * + * Return: the @drm_device pointer or backpointer. + */ +#define xe_any_to_drm(any) \ + _Generic((any), \ + __xe_any_to_self_assoc(struct drm_device, (any)), \ + default : &xe_any_to_xe(any)->drm) + +/** + * 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 @device pointer or backpointer. + */ +#define xe_any_to_dev(any) \ + _Generic((any), \ + __xe_any_to_self_assoc(struct device, (any)), \ + __xe_any_to_other_assoc(, pci_dev, device, (any)), \ + default : xe_any_to_drm(any)->dev) + +/** + * 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), \ + __xe_any_to_self_assoc(struct pci_dev, (any)), \ + default : to_pci_dev(xe_any_to_dev(any))) + +#define __xe_tile_to_id(p) ((p)->id) +#define __xe_gt_to_id(p) ((p)->info.id) + +/** + * 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 not applicable/available. + */ +#define xe_any_id(any) \ + _Generic((any), \ + __xe_any_to_other_assoc(/* */, xe_tile, id, (any)), \ + __xe_any_to_other_assoc(const, xe_tile, id, (any)), \ + __xe_any_to_other_assoc(/* */, xe_gt, id, (any)), \ + __xe_any_to_other_assoc(const, xe_gt, id, (any)), \ + default : 0) + +#endif -- 2.47.1