From patchwork Tue Sep 24 07:36:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 1988796 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XCWsF3jTxz1xsw for ; Tue, 24 Sep 2024 17:37:05 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1st06S-0003gF-FV; Tue, 24 Sep 2024 07:36:56 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1st06Q-0003fU-HD for kernel-team@lists.ubuntu.com; Tue, 24 Sep 2024 07:36:54 +0000 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 132D03F129 for ; Tue, 24 Sep 2024 07:36:54 +0000 (UTC) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2053f4938c7so45621955ad.2 for ; Tue, 24 Sep 2024 00:36:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727163412; x=1727768212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WHFtXmxe31Za3eom1WUOeSu4eRzvc31KA9vHBoVyvXc=; b=OAFsPbjoyXOttXnTkuO+Sn2gI0SoJmAxFqxhpPWXpsth64TVquepdnrR9hDU2cv2wV xzN6f94YDWuS+AQG9ygpTNuWF3Q6FN675Wp7MqjuOzPrNSpS1hyUcFvw2wNSMKqnfWM9 m/8IxD8hbex9KTggVYX1bsVBRWWeO5SDmATkiypbyan9DhmWAdDl/nRYGx4uLk2hCAnM Mwx/Cec8ob8nFbq4CNUsvZd/MBo9NA8DMnPbkAXATQbXcKbp90Uy4TS0eT/AcH1cx2XJ p4Xp2dbPLPNlJK+tb3b59dlEM67SjKQ0G2W67PnTNzHeGsNSjFCTxMa6NDpSq4RavfhU W5rQ== X-Gm-Message-State: AOJu0YxRXgN1wZ3xExPTSkr/D4fHT5KjMpm3DzGOWrRMXPDPfHA1Ktp3 bXROxq9VamiWJPwLF005eqovw3ZDS8jMtSDFrRuDQ3YJwSreho1YhLwj25xFYsRk8esmQT+Ot4o n0HgPt4Hn/1uLPHU+R5WQlH0tdB7695eFAZ/sqKgAfUhN98I5HS0cybd8Js7TdLnO8GnnRVd47b 1GcjhZ4vboSA== X-Received: by 2002:a17:902:f546:b0:205:5de3:b964 with SMTP id d9443c01a7336-208d97f3450mr211297345ad.5.1727163412280; Tue, 24 Sep 2024 00:36:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXBTzUxUNLovI9qiLu2lgrALbPNE8Zgrb7NFSxB+4PoXE/ujHlifWu0g4AvniwLRwiPncjeg== X-Received: by 2002:a17:902:f546:b0:205:5de3:b964 with SMTP id d9443c01a7336-208d97f3450mr211297195ad.5.1727163411825; Tue, 24 Sep 2024 00:36:51 -0700 (PDT) Received: from localhost.localdomain (114-36-223-64.dynamic-ip.hinet.net. [114.36.223.64]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20af1863562sm5581595ad.298.2024.09.24.00.36.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 00:36:51 -0700 (PDT) From: Chris Chiu To: kernel-team@lists.ubuntu.com Subject: [SRU][N][PATCH 1/3] drm/i915/display: add generic to_intel_display() macro Date: Tue, 24 Sep 2024 15:36:44 +0800 Message-Id: <20240924073646.1036150-2-chris.chiu@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240924073646.1036150-1-chris.chiu@canonical.com> References: <20240924073646.1036150-1-chris.chiu@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jani Nikula BugLink: https://bugs.launchpad.net/bugs/2081786 Convert various pointers to struct intel_display * using _Generic(). Add some macro magic to make adding new conversions easier, and somewhat abstract the need to cast each generic association. The cast is required because all associations needs to compile, regardless of the type and the generic selection. The use of *p in the generic selection assignment expression removes the need to add separate associations for const pointers. Note: This intentionally does *not* cover struct drm_i915_private or struct xe_device. They are not to be used in the long run, so avoid using this macro for them. Reviewed-by: Rodrigo Vivi Signed-off-by: Jani Nikula Link: https://patchwork.freedesktop.org/patch/msgid/02cf407961200db4379370856c779ea62b3eaa90.1713358679.git.jani.nikula@intel.com (cherry picked from commit 8d7077f53e6051ac284d642341db84f01625904b) Signed-off-by: Chris Chiu --- .../drm/i915/display/intel_display_types.h | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/gpu/drm/i915/display/intel_display_types.h b/drivers/gpu/drm/i915/display/intel_display_types.h index 1b754edb4ad7..f106f5958c00 100644 --- a/drivers/gpu/drm/i915/display/intel_display_types.h +++ b/drivers/gpu/drm/i915/display/intel_display_types.h @@ -2161,4 +2161,41 @@ static inline int to_bpp_x16(int bpp) return bpp << 4; } +/* + * Conversion functions/macros from various pointer types to struct + * intel_display pointer. + */ +#define __drm_device_to_intel_display(p) \ + (&to_i915(p)->display) +#define __intel_connector_to_intel_display(p) \ + __drm_device_to_intel_display((p)->base.dev) +#define __intel_crtc_to_intel_display(p) \ + __drm_device_to_intel_display((p)->base.dev) +#define __intel_crtc_state_to_intel_display(p) \ + __drm_device_to_intel_display((p)->uapi.crtc->dev) +#define __intel_digital_port_to_intel_display(p) \ + __drm_device_to_intel_display((p)->base.base.dev) +#define __intel_dp_to_intel_display(p) \ + __drm_device_to_intel_display(dp_to_dig_port(p)->base.base.dev) +#define __intel_encoder_to_intel_display(p) \ + __drm_device_to_intel_display((p)->base.dev) +#define __intel_hdmi_to_intel_display(p) \ + __drm_device_to_intel_display(hdmi_to_dig_port(p)->base.base.dev) + +/* Helper for generic association. Map types to conversion functions/macros. */ +#define __assoc(type, p) \ + struct type: __##type##_to_intel_display((struct type *)(p)) + +/* Convert various pointer types to struct intel_display pointer. */ +#define to_intel_display(p) \ + _Generic(*p, \ + __assoc(drm_device, p), \ + __assoc(intel_connector, p), \ + __assoc(intel_crtc, p), \ + __assoc(intel_crtc_state, p), \ + __assoc(intel_digital_port, p), \ + __assoc(intel_dp, p), \ + __assoc(intel_encoder, p), \ + __assoc(intel_hdmi, p)) + #endif /* __INTEL_DISPLAY_TYPES_H__ */