Skip to contentSkip to conversation

drm/i915: Introduce concept of a sub-platform

PATCH Superseded Tvrtko Ursulin 5 participants 19 messages Mar 15, 2019 – Mar 18, 2019

Subsystems (2)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: Introduce concept of a sub-platform

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.c          |   7 +-
 drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
 drivers/gpu/drm/i915/i915_pci.c          |   2 +-
 drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
 drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
 5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +4 -3
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv)
 	if (i915_inject_load_failure())
 		return -ENODEV;
 
+	intel_device_info_subplatform_init(dev_priv);
+
 	spin_lock_init(&dev_priv->irq_lock);
 	spin_lock_init(&dev_priv->gpu_error.lock);
 	mutex_init(&dev_priv->backlight_lock);
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
 	if (drm_debug & DRM_UT_DRIVER) {
 		struct drm_printer p = drm_debug_printer("i915 device info:");
 
-		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) gen=%i\n",
 			   INTEL_DEVID(dev_priv),
 			   INTEL_REVID(dev_priv),
 			   intel_platform_name(INTEL_INFO(dev_priv)->platform),
+			   RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],
 			   INTEL_GEN(dev_priv));
 
 		intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
 	memcpy(device_info, match_info, sizeof(*device_info));
 	RUNTIME_INFO(i915)->device_id = pdev->device;
 
-	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-		     BITS_PER_TYPE(device_info->platform_mask));
 	BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 
 	return i915;
drivers/gpu/drm/i915/i915_drv.h +71 -39

147 lines not on this page · raw message

drivers/gpu/drm/i915/i915_pci.c +1 -1
index 3cf697e8f1fa..2b042618e3ca 100644
@@ -32,7 +32,7 @@
 #include "i915_globals.h"
 #include "i915_selftest.h"
 
-#define PLATFORM(x) .platform = (x), .platform_mask = BIT(x)
+#define PLATFORM(x) .platform = (x)
 #define GEN(x) .gen = (x), .gen_mask = BIT((x) - 1)
 
 #define I845_PIPE_OFFSETS \
drivers/gpu/drm/i915/intel_device_info.c +79 -0

85 lines not on this page · raw message

drivers/gpu/drm/i915/intel_device_info.h +24 -4
index 047d10bdd455..b03fbd2e451a 100644
@@ -44,7 +44,7 @@ enum intel_platform {
 	INTEL_I915G,
 	INTEL_I915GM,
 	INTEL_I945G,
-	INTEL_I945GM,
+	INTEL_I945GM = 8,
 	INTEL_G33,
 	INTEL_PINEVIEW,
 	/* gen4 */
@@ -55,7 +55,7 @@ enum intel_platform {
 	/* gen5 */
 	INTEL_IRONLAKE,
 	/* gen6 */
-	INTEL_SANDYBRIDGE,
+	INTEL_SANDYBRIDGE = 16,
 	/* gen7 */
 	INTEL_IVYBRIDGE,
 	INTEL_VALLEYVIEW,
@@ -66,7 +66,7 @@ enum intel_platform {
 	/* gen9 */
 	INTEL_SKYLAKE,
 	INTEL_BROXTON,
-	INTEL_KABYLAKE,
+	INTEL_KABYLAKE = 24,
 	INTEL_GEMINILAKE,
 	INTEL_COFFEELAKE,
 	/* gen10 */
@@ -76,6 +76,24 @@ enum intel_platform {
 	INTEL_MAX_PLATFORMS
 };
 
+/*
+ * Subplatform bits share the same namespace per parent platform. In other words
+ * it is fine for the same bit to be used on multiple parent platforms.
+ */
+
+#define INTEL_SUBPLATFORM_BITS (3)
+
+#define INTEL_SUBPLATFORM_IRONLAKE_M (0)
+
+#define INTEL_SUBPLATFORM_PINEVIEW_G (0)
+#define INTEL_SUBPLATFORM_PINEVIEW_M (1)
+
+#define INTEL_SUBPLATFORM_ULT	  (0)
+#define INTEL_SUBPLATFORM_ULX	  (1)
+#define INTEL_SUBPLATFORM_AML_ULX (2)
+
+#define INTEL_SUBPLATFORM_PORTF (0)
+
 enum intel_ppgtt {
 	INTEL_PPGTT_NONE = I915_GEM_PPGTT_NONE,
 	INTEL_PPGTT_ALIASING = I915_GEM_PPGTT_ALIASING,
@@ -160,7 +178,6 @@ struct intel_device_info {
 	intel_engine_mask_t engine_mask; /* Engines supported by the HW */
 
 	enum intel_platform platform;
-	u32 platform_mask;
 
 	enum intel_ppgtt ppgtt;
 	unsigned int page_sizes; /* page sizes supported by the HW */
@@ -195,6 +212,8 @@ struct intel_device_info {
 };
 
 struct intel_runtime_info {
+	u32 platform_mask[1];
+
 	u16 device_id;
 
 	u8 num_sprites[I915_MAX_PIPES];
@@ -269,6 +288,7 @@ static inline void sseu_set_eus(struct sseu_dev_info *sseu,
 
 const char *intel_platform_name(enum intel_platform platform);
 
+void intel_device_info_subplatform_init(struct drm_i915_private *dev_priv);
 void intel_device_info_runtime_init(struct drm_i915_private *dev_priv);
 void intel_device_info_dump_flags(const struct intel_device_info *info,
 				  struct drm_printer *p);
Signature · 6 lines
2.19.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

Quoting Tvrtko Ursulin (2019-03-15 12:26:33)

Quoted 57 lines

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.c          |   7 +-
 drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
 drivers/gpu/drm/i915/i915_pci.c          |   2 +-
 drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
 drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
 5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +2 -0
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv)
        if (i915_inject_load_failure())
                return -ENODEV;
 
+       intel_device_info_subplatform_init(dev_priv);
+
        spin_lock_init(&dev_priv->irq_lock);
        spin_lock_init(&dev_priv->gpu_error.lock);
        mutex_init(&dev_priv->backlight_lock);

drivers/gpu/drm/i915/i915_drv.c static void i915_welcome_messages(struct drm_i915_private *dev_priv) · line 1761

Quoted 9 lines
drivers/gpu/drm/i915/i915_drv.c +2 -1
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
        if (drm_debug & DRM_UT_DRIVER) {
                struct drm_printer p = drm_debug_printer("i915 device info:");
 
-               drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+               drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) gen=%i\n",
                           INTEL_DEVID(dev_priv),
                           INTEL_REVID(dev_priv),
                           intel_platform_name(INTEL_INFO(dev_priv)->platform),
+                          RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],

I hope that's a one-off!

Quoted 18 lines
drivers/gpu/drm/i915/i915_drv.c +0 -2
                           INTEL_GEN(dev_priv));
 
                intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
        memcpy(device_info, match_info, sizeof(*device_info));
        RUNTIME_INFO(i915)->device_id = pdev->device;
 
-       BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-                    BITS_PER_TYPE(device_info->platform_mask));
        BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 
        return i915;
drivers/gpu/drm/i915/i915_drv.h +0 -0
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int i915_sg_segment_size(void)
 #define IS_REVID(p, since, until) \

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2290

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +7 -1
        (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) (INTEL_INFO(dev_priv)->platform_mask & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \
+({ \
+       const unsigned int pbits__ = \
+               BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+               INTEL_SUBPLATFORM_BITS; \
+       const unsigned int pi__ = (p) / pbits__; \
+       const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \

Oh, p is a compile time constant, so these can all be evaluated at compile time. So not a worry.

Quoted 23 lines
drivers/gpu/drm/i915/i915_drv.h +23 -0
+\
+       BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+       (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \
+})
+
+#define __IS_SUBPLATFORM(dev_priv, p, s) \
+({ \
+       const unsigned int pbits__ = \
+               BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+               INTEL_SUBPLATFORM_BITS; \
+       const unsigned int pi__ = (p) / pbits__; \
+       const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+       BUILD_BUG_ON(!__builtin_constant_p(p)); \
+       BUILD_BUG_ON(!__builtin_constant_p(s)); \
+       BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS); \
+\
+       (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & (BIT(pb__) | BIT(s))); \
+})
+
+static inline bool
+IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p)

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2323

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +10 -0
+{
+       return __IS_PLATFORM(i915, p);
+}
+
+static inline bool
+IS_SUBPLATFORM(const struct drm_i915_private *i915,
+              enum intel_platform p, unsigned int s)
+{
+       return __IS_SUBPLATFORM(i915, p, s);
+}

Ok, that all makes sense as a custom bitmap.

Quoted 13 lines
drivers/gpu/drm/i915/i915_drv.h +13 -0
+void intel_device_info_subplatform_init(struct drm_i915_private *i915)
+{
+       const unsigned int pbits =
+               BITS_PER_TYPE(RUNTIME_INFO(i915)->platform_mask[0]) -
+               INTEL_SUBPLATFORM_BITS;
+       const unsigned int pi = INTEL_INFO(i915)->platform / pbits;
+       const unsigned int pb =
+               INTEL_INFO(i915)->platform % pbits + INTEL_SUBPLATFORM_BITS;
+       struct intel_runtime_info *info = RUNTIME_INFO(i915);
+       u16 devid = INTEL_DEVID(i915);
+
+       BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
+                    pbits * ARRAY_SIZE(RUNTIME_INFO(i915)->platform_mask));

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void)

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +10 -0
+
+       info->platform_mask[pi] = BIT(pb);
+
+       if (IS_PINEVIEW(i915)) {
+               if (devid == 0xa001)
+                       info->platform_mask[pi] |=
+                               BIT(INTEL_SUBPLATFORM_PINEVIEW_G);
+               else if (devid == 0xa011)
+                       info->platform_mask[pi] |=
+                               BIT(INTEL_SUBPLATFORM_PINEVIEW_M);
if (IS_PINEVIEW(i915)) {
	int subplatform = 0;

	if (devid == 0xa001)
		subplatform = INTEL_SUBPLATFORM_PINEVIEW_G;
	else if (devid == 0xa001)
		subplatform = INTEL_SUBPLATFORM_PINEVIEW_M;
	else
		MISSING_CASE(devid);

	info->platform_mask[pi] |= BIT(subplatform);
	WARN_ON(!IS_SUBPLATFORM(i915, INTEL_PLATFORM_PINEVIEW, subplatform));
}

So we catch missing ids, and validate subplatform against SUBPLATFORM_BITS.

Quoted 26 lines

/**
* intel_device_info_runtime_init - initialize runtime info
* @dev_priv: the i915 device

drivers/gpu/drm/i915/intel_device_info.h +2 -2
index 047d10bdd455..b03fbd2e451a 100644
@@ -44,7 +44,7 @@ enum intel_platform {
        INTEL_I915G,
        INTEL_I915GM,
        INTEL_I945G,
-       INTEL_I945GM,
+       INTEL_I945GM = 8,
        INTEL_G33,
        INTEL_PINEVIEW,
        /* gen4 */
@@ -55,7 +55,7 @@ enum intel_platform {
        /* gen5 */
        INTEL_IRONLAKE,
        /* gen6 */
-       INTEL_SANDYBRIDGE,
+       INTEL_SANDYBRIDGE = 16,
        /* gen7 */
        INTEL_IVYBRIDGE,
        INTEL_VALLEYVIEW,

drivers/gpu/drm/i915/intel_device_info.h enum intel_platform { · line 69

Quoted 5 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -1
@@ -66,7 +66,7 @@ enum intel_platform {
        /* gen9 */
        INTEL_SKYLAKE,
        INTEL_BROXTON,
-       INTEL_KABYLAKE,
+       INTEL_KABYLAKE = 24,

Looks like you are just keeping a tally, and no I have no idea how to add a comment to make that clear.

/* tally */
/* tally so far */

Quoted 5 lines
drivers/gpu/drm/i915/intel_device_info.h +0 -0
        INTEL_GEMINILAKE,
        INTEL_COFFEELAKE,
        /* gen10 */
@@ -76,6 +76,24 @@ enum intel_platform {
        INTEL_MAX_PLATFORMS

drivers/gpu/drm/i915/intel_device_info.h enum intel_platform { · line 86

Quoted 10 lines
drivers/gpu/drm/i915/intel_device_info.h +7 -0
 };
 
+/*
+ * Subplatform bits share the same namespace per parent platform. In other words
+ * it is fine for the same bit to be used on multiple parent platforms.
+ */
+
+#define INTEL_SUBPLATFORM_BITS (3)
 
+#define INTEL_SUBPLATFORM_IRONLAKE_M (0)

I can't believe you haven't done i852/i855! (Or whatever that variant was called.)

Couldn't spot anything wrong, and so long as subplatform remains clear in the error state, hint hint, I'm happy.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw
Quoted 61 lines · Chris Wilson

Quoting Tvrtko Ursulin (2019-03-15 12:26:33)

Quoted 60 lines

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>
---
  drivers/gpu/drm/i915/i915_drv.c          |   7 +-
  drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
  drivers/gpu/drm/i915/i915_pci.c          |   2 +-
  drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
  drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
  5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +2 -0
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv)
         if (i915_inject_load_failure())
                 return -ENODEV;
 
+       intel_device_info_subplatform_init(dev_priv);
+
         spin_lock_init(&dev_priv->irq_lock);
         spin_lock_init(&dev_priv->gpu_error.lock);
         mutex_init(&dev_priv->backlight_lock);
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
         if (drm_debug & DRM_UT_DRIVER) {
                 struct drm_printer p = drm_debug_printer("i915 device info:");
 
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.c static void i915_welcome_messages(struct drm_i915_private *dev_priv) · line 1761

Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.c +2 -1
-               drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+               drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) gen=%i\n",
                            INTEL_DEVID(dev_priv),
                            INTEL_REVID(dev_priv),
                            intel_platform_name(INTEL_INFO(dev_priv)->platform),
+                          RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],

I hope that's a one-off!

It's indeed horrible. I was thinking of adding a helper but decided to wait for some general acks first.

Quoted 59 lines
Quoted 18 lines
drivers/gpu/drm/i915/i915_drv.c +0 -2
                            INTEL_GEN(dev_priv));
 
                 intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
         memcpy(device_info, match_info, sizeof(*device_info));
         RUNTIME_INFO(i915)->device_id = pdev->device;
 
-       BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-                    BITS_PER_TYPE(device_info->platform_mask));
         BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 
         return i915;
drivers/gpu/drm/i915/i915_drv.h +0 -0
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int i915_sg_segment_size(void)
  #define IS_REVID(p, since, until) \

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2290

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +7 -1
         (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) (INTEL_INFO(dev_priv)->platform_mask & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \
+({ \
+       const unsigned int pbits__ = \
+               BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+               INTEL_SUBPLATFORM_BITS; \
+       const unsigned int pi__ = (p) / pbits__; \
+       const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \

Oh, p is a compile time constant, so these can all be evaluated at compile time. So not a worry.

Quoted 27 lines
drivers/gpu/drm/i915/i915_drv.h +27 -0
+\
+       BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+       (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \
+})
+
+#define __IS_SUBPLATFORM(dev_priv, p, s) \
+({ \
+       const unsigned int pbits__ = \
+               BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+               INTEL_SUBPLATFORM_BITS; \
+       const unsigned int pi__ = (p) / pbits__; \
+       const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+       BUILD_BUG_ON(!__builtin_constant_p(p)); \
+       BUILD_BUG_ON(!__builtin_constant_p(s)); \
+       BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS); \
+\
+       (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & (BIT(pb__) | BIT(s))); \
+})
+
+static inline bool
+IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p)
+{
+       return __IS_PLATFORM(i915, p);
+}
+
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2323

Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.h +6 -0
+static inline bool
+IS_SUBPLATFORM(const struct drm_i915_private *i915,
+              enum intel_platform p, unsigned int s)
+{
+       return __IS_SUBPLATFORM(i915, p, s);
+}

Ok, that all makes sense as a custom bitmap.

Hm head scratch.. why I needed macro and a static inline? I'll check if I can get away with only the latter. This fiddling was all about keeping WARN_ON strings readable (and short!).

Quoted 26 lines
Quoted 14 lines
drivers/gpu/drm/i915/i915_drv.h +13 -0
+void intel_device_info_subplatform_init(struct drm_i915_private *i915)
+{
+       const unsigned int pbits =
+               BITS_PER_TYPE(RUNTIME_INFO(i915)->platform_mask[0]) -
+               INTEL_SUBPLATFORM_BITS;
+       const unsigned int pi = INTEL_INFO(i915)->platform / pbits;
+       const unsigned int pb =
+               INTEL_INFO(i915)->platform % pbits + INTEL_SUBPLATFORM_BITS;
+       struct intel_runtime_info *info = RUNTIME_INFO(i915);
+       u16 devid = INTEL_DEVID(i915);
+
+       BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
+                    pbits * ARRAY_SIZE(RUNTIME_INFO(i915)->platform_mask));

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void)

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +10 -0
+
+       info->platform_mask[pi] = BIT(pb);
+
+       if (IS_PINEVIEW(i915)) {
+               if (devid == 0xa001)
+                       info->platform_mask[pi] |=
+                               BIT(INTEL_SUBPLATFORM_PINEVIEW_G);
+               else if (devid == 0xa011)
+                       info->platform_mask[pi] |=
+                               BIT(INTEL_SUBPLATFORM_PINEVIEW_M);
if (IS_PINEVIEW(i915)) {
Quoted 8 lines
	int subplatform = 0;

	if (devid == 0xa001)
		subplatform = INTEL_SUBPLATFORM_PINEVIEW_G;
	else if (devid == 0xa001)
		subplatform = INTEL_SUBPLATFORM_PINEVIEW_M;
	else
		MISSING_CASE(devid);

With MISSING_CASE you are talking specifically for Pineview since it only has a total of two ids? You expect more parts to ship? :))

Otherwise the logic here is only to mention ids which are special, not all platform knows of. So as a general pattern MISSING_CASE wouldn't work.

Quoted 7 lines
	info->platform_mask[pi] |= BIT(subplatform);
	WARN_ON(!IS_SUBPLATFORM(i915, INTEL_PLATFORM_PINEVIEW, subplatform));
}

So we catch missing ids, and validate subplatform against SUBPLATFORM_BITS.

Not so straightforward with the ULT and ULX bunch since some of those are both.

What I have added locally however is this:

	GEM_BUG_ON(mask & ~INTEL_SUBPLATFORM_BITS);

	RUNTIME_INFO(i915)->platform_mask[pi] |= mask;

Moved the mask assignment to end so that I can check subplatform did not overflow the allocated space.

Quoted 35 lines
Quoted 26 lines

/**
* intel_device_info_runtime_init - initialize runtime info
* @dev_priv: the i915 device

drivers/gpu/drm/i915/intel_device_info.h +2 -2
index 047d10bdd455..b03fbd2e451a 100644
@@ -44,7 +44,7 @@ enum intel_platform {
         INTEL_I915G,
         INTEL_I915GM,
         INTEL_I945G,
-       INTEL_I945GM,
+       INTEL_I945GM = 8,
         INTEL_G33,
         INTEL_PINEVIEW,
         /* gen4 */
@@ -55,7 +55,7 @@ enum intel_platform {
         /* gen5 */
         INTEL_IRONLAKE,
         /* gen6 */
-       INTEL_SANDYBRIDGE,
+       INTEL_SANDYBRIDGE = 16,
         /* gen7 */
         INTEL_IVYBRIDGE,
         INTEL_VALLEYVIEW,

drivers/gpu/drm/i915/intel_device_info.h enum intel_platform { · line 69

Quoted 5 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -1
@@ -66,7 +66,7 @@ enum intel_platform {
         /* gen9 */
         INTEL_SKYLAKE,
         INTEL_BROXTON,
-       INTEL_KABYLAKE,
+       INTEL_KABYLAKE = 24,

Looks like you are just keeping a tally, and no I have no idea how to add a comment to make that clear.

Quoted 2 lines

/* tally */
/* tally so far */

Yeah.. I kept re-counting to see how it will look when the array is expanded, whether I should reserve more suplatfoms bits right now for cut-off to fall somewhere reasonable.

I can remove these markers, they are not that useful.

Quoted 15 lines
Quoted 14 lines
drivers/gpu/drm/i915/intel_device_info.h +6 -0
         INTEL_GEMINILAKE,
         INTEL_COFFEELAKE,
         /* gen10 */
@@ -76,6 +76,24 @@ enum intel_platform {
         INTEL_MAX_PLATFORMS
  };
 
+/*
+ * Subplatform bits share the same namespace per parent platform. In other words
+ * it is fine for the same bit to be used on multiple parent platforms.
+ */
+
+#define INTEL_SUBPLATFORM_BITS (3)
Quoted 4 lines

drivers/gpu/drm/i915/intel_device_info.h enum intel_platform { · line 86

Quoted 1 line
drivers/gpu/drm/i915/intel_device_info.h +1 -0
+#define INTEL_SUBPLATFORM_IRONLAKE_M (0)

I can't believe you haven't done i852/i855! (Or whatever that variant was called.)

IS_I85X? I don't see any sub-platforms there.

Quoted 2 lines

Couldn't spot anything wrong, and so long as subplatform remains clear in the error state, hint hint, I'm happy.

Like how? With a string like platform names? Would be possible but is it really needed on top of devid?

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw

Quoting Tvrtko Ursulin (2019-03-15 13:32:54)

Quoted 182 lines · Chris Wilson
Quoted 61 lines

Quoting Tvrtko Ursulin (2019-03-15 12:26:33)

Quoted 60 lines

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>
---
  drivers/gpu/drm/i915/i915_drv.c          |   7 +-
  drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
  drivers/gpu/drm/i915/i915_pci.c          |   2 +-
  drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
  drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
  5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +2 -0
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv)
         if (i915_inject_load_failure())
                 return -ENODEV;
 
+       intel_device_info_subplatform_init(dev_priv);
+
         spin_lock_init(&dev_priv->irq_lock);
         spin_lock_init(&dev_priv->gpu_error.lock);
         mutex_init(&dev_priv->backlight_lock);
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
         if (drm_debug & DRM_UT_DRIVER) {
                 struct drm_printer p = drm_debug_printer("i915 device info:");
 
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.c static void i915_welcome_messages(struct drm_i915_private *dev_priv) · line 1761

Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.c +2 -1
-               drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+               drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) gen=%i\n",
                            INTEL_DEVID(dev_priv),
                            INTEL_REVID(dev_priv),
                            intel_platform_name(INTEL_INFO(dev_priv)->platform),
+                          RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],

I hope that's a one-off!

It's indeed horrible. I was thinking of adding a helper but decided to wait for some general acks first.

Quoted 59 lines
Quoted 18 lines
drivers/gpu/drm/i915/i915_drv.c +0 -2
                            INTEL_GEN(dev_priv));
 
                 intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
         memcpy(device_info, match_info, sizeof(*device_info));
         RUNTIME_INFO(i915)->device_id = pdev->device;
 
-       BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-                    BITS_PER_TYPE(device_info->platform_mask));
         BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 
         return i915;
drivers/gpu/drm/i915/i915_drv.h +0 -0
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int i915_sg_segment_size(void)
  #define IS_REVID(p, since, until) \

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2290

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +7 -1
         (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) (INTEL_INFO(dev_priv)->platform_mask & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \
+({ \
+       const unsigned int pbits__ = \
+               BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+               INTEL_SUBPLATFORM_BITS; \
+       const unsigned int pi__ = (p) / pbits__; \
+       const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \

Oh, p is a compile time constant, so these can all be evaluated at compile time. So not a worry.

Quoted 27 lines
drivers/gpu/drm/i915/i915_drv.h +27 -0
+\
+       BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+       (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \
+})
+
+#define __IS_SUBPLATFORM(dev_priv, p, s) \
+({ \
+       const unsigned int pbits__ = \
+               BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+               INTEL_SUBPLATFORM_BITS; \
+       const unsigned int pi__ = (p) / pbits__; \
+       const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+       BUILD_BUG_ON(!__builtin_constant_p(p)); \
+       BUILD_BUG_ON(!__builtin_constant_p(s)); \
+       BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS); \
+\
+       (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & (BIT(pb__) | BIT(s))); \
+})
+
+static inline bool
+IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p)
+{
+       return __IS_PLATFORM(i915, p);
+}
+
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2323

Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.h +6 -0
+static inline bool
+IS_SUBPLATFORM(const struct drm_i915_private *i915,
+              enum intel_platform p, unsigned int s)
+{
+       return __IS_SUBPLATFORM(i915, p, s);
+}

Ok, that all makes sense as a custom bitmap.

Hm head scratch.. why I needed macro and a static inline? I'll check if I can get away with only the latter. This fiddling was all about keeping WARN_ON strings readable (and short!).

Quoted 26 lines
Quoted 14 lines
drivers/gpu/drm/i915/i915_drv.h +13 -0
+void intel_device_info_subplatform_init(struct drm_i915_private *i915)
+{
+       const unsigned int pbits =
+               BITS_PER_TYPE(RUNTIME_INFO(i915)->platform_mask[0]) -
+               INTEL_SUBPLATFORM_BITS;
+       const unsigned int pi = INTEL_INFO(i915)->platform / pbits;
+       const unsigned int pb =
+               INTEL_INFO(i915)->platform % pbits + INTEL_SUBPLATFORM_BITS;
+       struct intel_runtime_info *info = RUNTIME_INFO(i915);
+       u16 devid = INTEL_DEVID(i915);
+
+       BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
+                    pbits * ARRAY_SIZE(RUNTIME_INFO(i915)->platform_mask));

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void)

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +10 -0
+
+       info->platform_mask[pi] = BIT(pb);
+
+       if (IS_PINEVIEW(i915)) {
+               if (devid == 0xa001)
+                       info->platform_mask[pi] |=
+                               BIT(INTEL_SUBPLATFORM_PINEVIEW_G);
+               else if (devid == 0xa011)
+                       info->platform_mask[pi] |=
+                               BIT(INTEL_SUBPLATFORM_PINEVIEW_M);
if (IS_PINEVIEW(i915)) {
Quoted 8 lines
      int subplatform = 0;

      if (devid == 0xa001)
              subplatform = INTEL_SUBPLATFORM_PINEVIEW_G;
      else if (devid == 0xa001)
              subplatform = INTEL_SUBPLATFORM_PINEVIEW_M;
      else
              MISSING_CASE(devid);
Quoted 5 lines

With MISSING_CASE you are talking specifically for Pineview since it only has a total of two ids? You expect more parts to ship? :))

Otherwise the logic here is only to mention ids which are special, not all platform knows of. So as a general pattern MISSING_CASE wouldn't work.

Hmm. I worried about forgetting to add subplatform fields in future.

would

	int subplatform = 0;
	switch (devid) {
	case BORING_A:
	...
	case BORING_Z:
		break;

	case SUB_AA:
	...
	case SUB_AZ:
		subplatform = A;
		break;
	case SUB_BA:
	...
	case SUB_BZ:
		subplatform = B;
		break;

	default:
		CI_MISSING_CASE(devid);
		break;
	}

compile away the jumptable for the defaults when !CI?

However, that does imply that we see an example of every subplatform in CI. Which, off course, we do!

Quoted 10 lines
Quoted 6 lines
      info->platform_mask[pi] |= BIT(subplatform);
      WARN_ON(!IS_SUBPLATFORM(i915, INTEL_PLATFORM_PINEVIEW, subplatform));
}

So we catch missing ids, and validate subplatform against SUBPLATFORM_BITS.

Not so straightforward with the ULT and ULX bunch since some of those are both.

Quoted 8 lines

What I have added locally however is this:

        GEM_BUG_ON(mask & ~INTEL_SUBPLATFORM_BITS);

        RUNTIME_INFO(i915)->platform_mask[pi] |= mask;

Moved the mask assignment to end so that I can check subplatform did not overflow the allocated space.

Fair enough.

Quoted 59 lines
Quoted 35 lines
Quoted 26 lines

/**
* intel_device_info_runtime_init - initialize runtime info
* @dev_priv: the i915 device

drivers/gpu/drm/i915/intel_device_info.h +2 -2
index 047d10bdd455..b03fbd2e451a 100644
@@ -44,7 +44,7 @@ enum intel_platform {
         INTEL_I915G,
         INTEL_I915GM,
         INTEL_I945G,
-       INTEL_I945GM,
+       INTEL_I945GM = 8,
         INTEL_G33,
         INTEL_PINEVIEW,
         /* gen4 */
@@ -55,7 +55,7 @@ enum intel_platform {
         /* gen5 */
         INTEL_IRONLAKE,
         /* gen6 */
-       INTEL_SANDYBRIDGE,
+       INTEL_SANDYBRIDGE = 16,
         /* gen7 */
         INTEL_IVYBRIDGE,
         INTEL_VALLEYVIEW,

drivers/gpu/drm/i915/intel_device_info.h enum intel_platform { · line 69

Quoted 5 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -1
@@ -66,7 +66,7 @@ enum intel_platform {
         /* gen9 */
         INTEL_SKYLAKE,
         INTEL_BROXTON,
-       INTEL_KABYLAKE,
+       INTEL_KABYLAKE = 24,

Looks like you are just keeping a tally, and no I have no idea how to add a comment to make that clear.

Quoted 2 lines

/* tally */
/* tally so far */

Yeah.. I kept re-counting to see how it will look when the array is expanded, whether I should reserve more suplatfoms bits right now for cut-off to fall somewhere reasonable.

I can remove these markers, they are not that useful.

Quoted 15 lines
Quoted 14 lines
drivers/gpu/drm/i915/intel_device_info.h +6 -0
         INTEL_GEMINILAKE,
         INTEL_COFFEELAKE,
         /* gen10 */
@@ -76,6 +76,24 @@ enum intel_platform {
         INTEL_MAX_PLATFORMS
  };
 
+/*
+ * Subplatform bits share the same namespace per parent platform. In other words
+ * it is fine for the same bit to be used on multiple parent platforms.
+ */
+
+#define INTEL_SUBPLATFORM_BITS (3)
Quoted 6 lines
Quoted 4 lines

drivers/gpu/drm/i915/intel_device_info.h enum intel_platform { · line 86

Quoted 1 line
drivers/gpu/drm/i915/intel_device_info.h +1 -0
+#define INTEL_SUBPLATFORM_IRONLAKE_M (0)

I can't believe you haven't done i852/i855! (Or whatever that variant was called.)

IS_I85X? I don't see any sub-platforms there.

The gpu is slightly different; but nothing so far for us to do. Basically, in my grand plan, where there is just one header that defines all known pci-ids, features, and marketing strings we would need to differentiate.

Quoted 5 lines
Quoted 2 lines

Couldn't spot anything wrong, and so long as subplatform remains clear in the error state, hint hint, I'm happy.

Like how? With a string like platform names? Would be possible but is it really needed on top of devid?

Because I have every devid memorized!

I'd take the subplatform %x; that's enough to see a pattern or to investigate if might be subplatform specific.
-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw
In reply to Tvrtko Ursulin
Quoted 131 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.c          |   7 +-
 drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
 drivers/gpu/drm/i915/i915_pci.c          |   2 +-
 drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
 drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
 5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +4 -3
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv)
 	if (i915_inject_load_failure())
 		return -ENODEV;
 
+	intel_device_info_subplatform_init(dev_priv);
+
 	spin_lock_init(&dev_priv->irq_lock);
 	spin_lock_init(&dev_priv->gpu_error.lock);
 	mutex_init(&dev_priv->backlight_lock);
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
 	if (drm_debug & DRM_UT_DRIVER) {
 		struct drm_printer p = drm_debug_printer("i915 device info:");
 
-		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) gen=%i\n",
 			   INTEL_DEVID(dev_priv),
 			   INTEL_REVID(dev_priv),
 			   intel_platform_name(INTEL_INFO(dev_priv)->platform),
+			   RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],
 			   INTEL_GEN(dev_priv));
 
 		intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
 	memcpy(device_info, match_info, sizeof(*device_info));
 	RUNTIME_INFO(i915)->device_id = pdev->device;
 
-	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-		     BITS_PER_TYPE(device_info->platform_mask));
 	BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 
 	return i915;
drivers/gpu/drm/i915/i915_drv.h +40 -1
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int i915_sg_segment_size(void)
 #define IS_REVID(p, since, until) \
 	(INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) (INTEL_INFO(dev_priv)->platform_mask & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \
+({ \
+	const unsigned int pbits__ = \
+		BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+		INTEL_SUBPLATFORM_BITS; \
+	const unsigned int pi__ = (p) / pbits__; \
+	const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+	BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+	(RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \
+})
+
+#define __IS_SUBPLATFORM(dev_priv, p, s) \
+({ \
+	const unsigned int pbits__ = \
+		BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+		INTEL_SUBPLATFORM_BITS; \
+	const unsigned int pi__ = (p) / pbits__; \
+	const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+	BUILD_BUG_ON(!__builtin_constant_p(p)); \
+	BUILD_BUG_ON(!__builtin_constant_p(s)); \
+	BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS); \
+\
+	(RUNTIME_INFO(dev_priv)->platform_mask[pi__] & (BIT(pb__) | BIT(s))); \
+})
+
+static inline bool
+IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p)
+{
+	return __IS_PLATFORM(i915, p);
+}
+
+static inline bool
+IS_SUBPLATFORM(const struct drm_i915_private *i915,
+	       enum intel_platform p, unsigned int s)
+{
+	return __IS_SUBPLATFORM(i915, p, s);
+}
 
 #define IS_I830(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I830)
 #define IS_I845G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I845G)

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2342

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +4 -2
@@ -2296,11 +2335,15 @@ static inline unsigned int i915_sg_segment_size(void)
 #define IS_G45(dev_priv)	IS_PLATFORM(dev_priv, INTEL_G45)
 #define IS_GM45(dev_priv)	IS_PLATFORM(dev_priv, INTEL_GM45)
 #define IS_G4X(dev_priv)	(IS_G45(dev_priv) || IS_GM45(dev_priv))
-#define IS_PINEVIEW_G(dev_priv)	(INTEL_DEVID(dev_priv) == 0xa001)
-#define IS_PINEVIEW_M(dev_priv)	(INTEL_DEVID(dev_priv) == 0xa011)
+#define IS_PINEVIEW_G(dev_priv)	\
+	IS_SUBPLATFORM(dev_priv, INTEL_PINEVIEW, INTEL_SUBPLATFORM_PINEVIEW_G)
+#define IS_PINEVIEW_M(dev_priv)	\
+	IS_SUBPLATFORM(dev_priv, INTEL_PINEVIEW, INTEL_SUBPLATFORM_PINEVIEW_M)
 #define IS_PINEVIEW(dev_priv)	IS_PLATFORM(dev_priv, INTEL_PINEVIEW)

I have a feeling we should just use the normal IS_MOBILE() thing here. But untangling that mess might be a bit of work.

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2346

Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +3 -1
 #define IS_G33(dev_priv)	IS_PLATFORM(dev_priv, INTEL_G33)
-#define IS_IRONLAKE_M(dev_priv)	(INTEL_DEVID(dev_priv) == 0x0046)
+#define IS_IRONLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_IRONLAKE)
+#define IS_IRONLAKE_M(dev_priv)	\
+	IS_SUBPLATFORM(dev_priv, INTEL_IRONLAKE, INTEL_SUBPLATFORM_IRONLAKE_M)

This is clearly just IS_MOBILE().

Or we just keep the current pci id checks. Frankly I see no benefit in abstracting these few exceptions.

Quoted 51 lines
drivers/gpu/drm/i915/i915_drv.h +8 -29
 #define IS_IVYBRIDGE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_IVYBRIDGE)
 #define IS_IVB_GT1(dev_priv)	(IS_IVYBRIDGE(dev_priv) && \
 				 INTEL_INFO(dev_priv)->gt == 1)
@@ -2318,42 +2361,31 @@ static inline unsigned int i915_sg_segment_size(void)
 #define IS_MOBILE(dev_priv)	(INTEL_INFO(dev_priv)->is_mobile)
 #define IS_HSW_EARLY_SDV(dev_priv) (IS_HASWELL(dev_priv) && \
 				    (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0C00)
-#define IS_BDW_ULT(dev_priv)	(IS_BROADWELL(dev_priv) && \
-				 ((INTEL_DEVID(dev_priv) & 0xf) == 0x6 ||	\
-				 (INTEL_DEVID(dev_priv) & 0xf) == 0xb ||	\
-				 (INTEL_DEVID(dev_priv) & 0xf) == 0xe))
-/* ULX machines are also considered ULT. */
-#define IS_BDW_ULX(dev_priv)	(IS_BROADWELL(dev_priv) && \
-				 (INTEL_DEVID(dev_priv) & 0xf) == 0xe)
+#define IS_BDW_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULT)
+#define IS_BDW_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULX)
 #define IS_BDW_GT3(dev_priv)	(IS_BROADWELL(dev_priv) && \
 				 INTEL_INFO(dev_priv)->gt == 3)
-#define IS_HSW_ULT(dev_priv)	(IS_HASWELL(dev_priv) && \
-				 (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0A00)
+#define IS_HSW_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULT)
 #define IS_HSW_GT3(dev_priv)	(IS_HASWELL(dev_priv) && \
 				 INTEL_INFO(dev_priv)->gt == 3)
 #define IS_HSW_GT1(dev_priv)	(IS_HASWELL(dev_priv) && \
 				 INTEL_INFO(dev_priv)->gt == 1)
 /* ULX machines are also considered ULT. */
-#define IS_HSW_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x0A0E || \
-				 INTEL_DEVID(dev_priv) == 0x0A1E)
-#define IS_SKL_ULT(dev_priv)	(INTEL_DEVID(dev_priv) == 0x1906 || \
-				 INTEL_DEVID(dev_priv) == 0x1913 || \
-				 INTEL_DEVID(dev_priv) == 0x1916 || \
-				 INTEL_DEVID(dev_priv) == 0x1921 || \
-				 INTEL_DEVID(dev_priv) == 0x1926)
-#define IS_SKL_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x190E || \
-				 INTEL_DEVID(dev_priv) == 0x1915 || \
-				 INTEL_DEVID(dev_priv) == 0x191E)
-#define IS_KBL_ULT(dev_priv)	(INTEL_DEVID(dev_priv) == 0x5906 || \
-				 INTEL_DEVID(dev_priv) == 0x5913 || \
-				 INTEL_DEVID(dev_priv) == 0x5916 || \
-				 INTEL_DEVID(dev_priv) == 0x5921 || \
-				 INTEL_DEVID(dev_priv) == 0x5926)
-#define IS_KBL_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x590E || \
-				 INTEL_DEVID(dev_priv) == 0x5915 || \
-				 INTEL_DEVID(dev_priv) == 0x591E)
-#define IS_AML_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x591C || \
-				 INTEL_DEVID(dev_priv) == 0x87C0)
+#define IS_HSW_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULX)

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2388

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +10 -0
+#define IS_SKL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULT)
+#define IS_SKL_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULX)
+#define IS_KBL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULT)
+#define IS_KBL_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULX)
+#define IS_AML_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_AML_ULX)

Why is AML_ULX different from normal ULX?

Quoted 13 lines
drivers/gpu/drm/i915/i915_drv.h +2 -2
 #define IS_SKL_GT2(dev_priv)	(IS_SKYLAKE(dev_priv) && \
 				 INTEL_INFO(dev_priv)->gt == 2)
 #define IS_SKL_GT3(dev_priv)	(IS_SKYLAKE(dev_priv) && \
@@ -2364,16 +2396,16 @@ static inline unsigned int i915_sg_segment_size(void)
 				 INTEL_INFO(dev_priv)->gt == 2)
 #define IS_KBL_GT3(dev_priv)	(IS_KABYLAKE(dev_priv) && \
 				 INTEL_INFO(dev_priv)->gt == 3)
-#define IS_CFL_ULT(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
-				 (INTEL_DEVID(dev_priv) & 0x00F0) == 0x00A0)
+#define IS_CFL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULT)
 #define IS_CFL_GT2(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
 				 INTEL_INFO(dev_priv)->gt == 2)

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2408

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +4 -4
 #define IS_CFL_GT3(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
 				 INTEL_INFO(dev_priv)->gt == 3)
-#define IS_CNL_WITH_PORT_F(dev_priv)   (IS_CANNONLAKE(dev_priv) && \
-					(INTEL_DEVID(dev_priv) & 0x0004) == 0x0004)
-#define IS_ICL_WITH_PORT_F(dev_priv)   (IS_ICELAKE(dev_priv) && \
-					INTEL_DEVID(dev_priv) != 0x8A51)
+#define IS_CNL_WITH_PORT_F(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_CANNONLAKE, INTEL_SUBPLATFORM_PORTF)
+#define IS_ICL_WITH_PORT_F(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_ICELAKE, INTEL_SUBPLATFORM_PORTF)

God that PORTF thing is ugly. I would suggest we just add port_mask or something along those lines into the device info.

Then we could perhaps even avoid adding more and more branches to intel_setup_outputs(). Although I'm not sure we need anything for that since we'll look at the VBT anyway (which *maybe* doesn't advertize ports that aren't present?).

Quoted 129 lines
drivers/gpu/drm/i915/i915_drv.h +0 -0
 #define IS_ALPHA_SUPPORT(intel_info) ((intel_info)->is_alpha_support)
 
drivers/gpu/drm/i915/i915_pci.c +1 -1
index 3cf697e8f1fa..2b042618e3ca 100644
@@ -32,7 +32,7 @@
 #include "i915_globals.h"
 #include "i915_selftest.h"
 
-#define PLATFORM(x) .platform = (x), .platform_mask = BIT(x)
+#define PLATFORM(x) .platform = (x)
 #define GEN(x) .gen = (x), .gen_mask = BIT((x) - 1)
 
 #define I845_PIPE_OFFSETS \
drivers/gpu/drm/i915/intel_device_info.c +79 -0
index aac19b1c419c..b8a7e17cb443 100644
@@ -707,6 +707,85 @@ static u32 read_timestamp_frequency(struct drm_i915_private *dev_priv)
 	return 0;
 }
 
+void intel_device_info_subplatform_init(struct drm_i915_private *i915)
+{
+	const unsigned int pbits =
+		BITS_PER_TYPE(RUNTIME_INFO(i915)->platform_mask[0]) -
+		INTEL_SUBPLATFORM_BITS;
+	const unsigned int pi = INTEL_INFO(i915)->platform / pbits;
+	const unsigned int pb =
+		INTEL_INFO(i915)->platform % pbits + INTEL_SUBPLATFORM_BITS;
+	struct intel_runtime_info *info = RUNTIME_INFO(i915);
+	u16 devid = INTEL_DEVID(i915);
+
+	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
+		     pbits * ARRAY_SIZE(RUNTIME_INFO(i915)->platform_mask));
+
+	info->platform_mask[pi] = BIT(pb);
+
+	if (IS_PINEVIEW(i915)) {
+		if (devid == 0xa001)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_PINEVIEW_G);
+		else if (devid == 0xa011)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_PINEVIEW_M);
+	} else if (IS_IRONLAKE(i915)) {
+		if (devid == 0x0046)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_IRONLAKE_M);
+	} else if (IS_HASWELL(i915)) {
+		if ((devid & 0xFF00) == 0x0A00)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		/* ULX machines are also considered ULT. */
+		if (devid == 0x0A0E || devid == 0x0A1E)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+	} else if (IS_BROADWELL(i915)) {
+		if ((devid & 0xf) == 0x6 ||
+		    (devid & 0xf) == 0xb ||
+		    (devid & 0xf) == 0xe)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		/* ULX machines are also considered ULT. */
+		if ((devid & 0xf) == 0xe)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+	} else if (IS_SKYLAKE(i915)) {
+		if (devid == 0x1906 ||
+		    devid == 0x1913 ||
+		    devid == 0x1916 ||
+		    devid == 0x1921 ||
+		    devid == 0x1926)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		else if (devid == 0x190E ||
+			 devid == 0x1915 ||
+			 devid == 0x191E)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+	} else if (IS_KABYLAKE(i915)) {
+		if (devid == 0x5906 ||
+		    devid == 0x5913 ||
+		    devid == 0x5916 ||
+		    devid == 0x5921 ||
+		    devid  == 0x5926)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		else if (devid == 0x590E ||
+			 devid == 0x5915 ||
+			 devid == 0x591E)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+		else if (devid == 0x591C ||
+			 devid == 0x87C0)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_AML_ULX);
+	} else if (IS_COFFEELAKE(i915)) {
+		if ((devid & 0x00F0) == 0x00A0)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+	} else if (IS_CANNONLAKE(i915)) {
+		if ((devid & 0x0004) == 0x0004)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_PORTF);
+	} else if (IS_ICELAKE(i915)) {
+		if (devid != 0x8A51)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_PORTF);
+	}
+}
+
 /**
  * intel_device_info_runtime_init - initialize runtime info
  * @dev_priv: the i915 device
drivers/gpu/drm/i915/intel_device_info.h +2 -2
index 047d10bdd455..b03fbd2e451a 100644
@@ -44,7 +44,7 @@ enum intel_platform {
 	INTEL_I915G,
 	INTEL_I915GM,
 	INTEL_I945G,
-	INTEL_I945GM,
+	INTEL_I945GM = 8,
 	INTEL_G33,
 	INTEL_PINEVIEW,
 	/* gen4 */
@@ -55,7 +55,7 @@ enum intel_platform {
 	/* gen5 */
 	INTEL_IRONLAKE,
 	/* gen6 */
-	INTEL_SANDYBRIDGE,
+	INTEL_SANDYBRIDGE = 16,
 	/* gen7 */
 	INTEL_IVYBRIDGE,
 	INTEL_VALLEYVIEW,

drivers/gpu/drm/i915/intel_device_info.h enum intel_platform { · line 69

Quoted 5 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -1
@@ -66,7 +66,7 @@ enum intel_platform {
 	/* gen9 */
 	INTEL_SKYLAKE,
 	INTEL_BROXTON,
-	INTEL_KABYLAKE,
+	INTEL_KABYLAKE = 24,

Too much magic. Looks rather fragile.

Quoted 60 lines
drivers/gpu/drm/i915/intel_device_info.h +21 -1
 	INTEL_GEMINILAKE,
 	INTEL_COFFEELAKE,
 	/* gen10 */
@@ -76,6 +76,24 @@ enum intel_platform {
 	INTEL_MAX_PLATFORMS
 };
 
+/*
+ * Subplatform bits share the same namespace per parent platform. In other words
+ * it is fine for the same bit to be used on multiple parent platforms.
+ */
+
+#define INTEL_SUBPLATFORM_BITS (3)
+
+#define INTEL_SUBPLATFORM_IRONLAKE_M (0)
+
+#define INTEL_SUBPLATFORM_PINEVIEW_G (0)
+#define INTEL_SUBPLATFORM_PINEVIEW_M (1)
+
+#define INTEL_SUBPLATFORM_ULT	  (0)
+#define INTEL_SUBPLATFORM_ULX	  (1)
+#define INTEL_SUBPLATFORM_AML_ULX (2)
+
+#define INTEL_SUBPLATFORM_PORTF (0)
+
 enum intel_ppgtt {
 	INTEL_PPGTT_NONE = I915_GEM_PPGTT_NONE,
 	INTEL_PPGTT_ALIASING = I915_GEM_PPGTT_ALIASING,
@@ -160,7 +178,6 @@ struct intel_device_info {
 	intel_engine_mask_t engine_mask; /* Engines supported by the HW */
 
 	enum intel_platform platform;
-	u32 platform_mask;
 
 	enum intel_ppgtt ppgtt;
 	unsigned int page_sizes; /* page sizes supported by the HW */
@@ -195,6 +212,8 @@ struct intel_device_info {
 };
 
 struct intel_runtime_info {
+	u32 platform_mask[1];
+
 	u16 device_id;
 
 	u8 num_sprites[I915_MAX_PIPES];
@@ -269,6 +288,7 @@ static inline void sseu_set_eus(struct sseu_dev_info *sseu,
 
 const char *intel_platform_name(enum intel_platform platform);
 
+void intel_device_info_subplatform_init(struct drm_i915_private *dev_priv);
 void intel_device_info_runtime_init(struct drm_i915_private *dev_priv);
 void intel_device_info_dump_flags(const struct intel_device_info *info,
 				  struct drm_printer *p);
Signature · 6 lines
2.19.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw
Quoted 146 lines · Ville Syrjälä
Quoted 131 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>
---
  drivers/gpu/drm/i915/i915_drv.c          |   7 +-
  drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
  drivers/gpu/drm/i915/i915_pci.c          |   2 +-
  drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
  drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
  5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +4 -3
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv)
  	if (i915_inject_load_failure())
  		return -ENODEV;
 
+	intel_device_info_subplatform_init(dev_priv);
+
  	spin_lock_init(&dev_priv->irq_lock);
  	spin_lock_init(&dev_priv->gpu_error.lock);
  	mutex_init(&dev_priv->backlight_lock);
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
  	if (drm_debug & DRM_UT_DRIVER) {
  		struct drm_printer p = drm_debug_printer("i915 device info:");
 
-		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) gen=%i\n",
  			   INTEL_DEVID(dev_priv),
  			   INTEL_REVID(dev_priv),
  			   intel_platform_name(INTEL_INFO(dev_priv)->platform),
+			   RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],
  			   INTEL_GEN(dev_priv));
 
  		intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
  	memcpy(device_info, match_info, sizeof(*device_info));
  	RUNTIME_INFO(i915)->device_id = pdev->device;
 
-	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-		     BITS_PER_TYPE(device_info->platform_mask));
  	BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 
  	return i915;
drivers/gpu/drm/i915/i915_drv.h +40 -1
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int i915_sg_segment_size(void)
  #define IS_REVID(p, since, until) \
  	(INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) (INTEL_INFO(dev_priv)->platform_mask & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \
+({ \
+	const unsigned int pbits__ = \
+		BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+		INTEL_SUBPLATFORM_BITS; \
+	const unsigned int pi__ = (p) / pbits__; \
+	const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+	BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+	(RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \
+})
+
+#define __IS_SUBPLATFORM(dev_priv, p, s) \
+({ \
+	const unsigned int pbits__ = \
+		BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+		INTEL_SUBPLATFORM_BITS; \
+	const unsigned int pi__ = (p) / pbits__; \
+	const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+	BUILD_BUG_ON(!__builtin_constant_p(p)); \
+	BUILD_BUG_ON(!__builtin_constant_p(s)); \
+	BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS); \
+\
+	(RUNTIME_INFO(dev_priv)->platform_mask[pi__] & (BIT(pb__) | BIT(s))); \
+})
+
+static inline bool
+IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p)
+{
+	return __IS_PLATFORM(i915, p);
+}
+
+static inline bool
+IS_SUBPLATFORM(const struct drm_i915_private *i915,
+	       enum intel_platform p, unsigned int s)
+{
+	return __IS_SUBPLATFORM(i915, p, s);
+}
 
  #define IS_I830(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I830)
  #define IS_I845G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I845G)

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2342

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +4 -2
@@ -2296,11 +2335,15 @@ static inline unsigned int i915_sg_segment_size(void)
  #define IS_G45(dev_priv)	IS_PLATFORM(dev_priv, INTEL_G45)
  #define IS_GM45(dev_priv)	IS_PLATFORM(dev_priv, INTEL_GM45)
  #define IS_G4X(dev_priv)	(IS_G45(dev_priv) || IS_GM45(dev_priv))
-#define IS_PINEVIEW_G(dev_priv)	(INTEL_DEVID(dev_priv) == 0xa001)
-#define IS_PINEVIEW_M(dev_priv)	(INTEL_DEVID(dev_priv) == 0xa011)
+#define IS_PINEVIEW_G(dev_priv)	\
+	IS_SUBPLATFORM(dev_priv, INTEL_PINEVIEW, INTEL_SUBPLATFORM_PINEVIEW_G)
+#define IS_PINEVIEW_M(dev_priv)	\
+	IS_SUBPLATFORM(dev_priv, INTEL_PINEVIEW, INTEL_SUBPLATFORM_PINEVIEW_M)
  #define IS_PINEVIEW(dev_priv)	IS_PLATFORM(dev_priv, INTEL_PINEVIEW)

I have a feeling we should just use the normal IS_MOBILE() thing here. But untangling that mess might be a bit of work.

Quoted 7 lines

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2346

Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +3 -1
  #define IS_G33(dev_priv)	IS_PLATFORM(dev_priv, INTEL_G33)
-#define IS_IRONLAKE_M(dev_priv)	(INTEL_DEVID(dev_priv) == 0x0046)
+#define IS_IRONLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_IRONLAKE)
+#define IS_IRONLAKE_M(dev_priv)	\
+	IS_SUBPLATFORM(dev_priv, INTEL_IRONLAKE, INTEL_SUBPLATFORM_IRONLAKE_M)

This is clearly just IS_MOBILE().

Ok.

Quoted 2 lines

Or we just keep the current pci id checks. Frankly I see no benefit in abstracting these few exceptions.

Are you referring to Ironlake only or in general?

Quoted 56 lines
Quoted 56 lines
drivers/gpu/drm/i915/i915_drv.h +12 -29
  #define IS_IVYBRIDGE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_IVYBRIDGE)
  #define IS_IVB_GT1(dev_priv)	(IS_IVYBRIDGE(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 1)
@@ -2318,42 +2361,31 @@ static inline unsigned int i915_sg_segment_size(void)
  #define IS_MOBILE(dev_priv)	(INTEL_INFO(dev_priv)->is_mobile)
  #define IS_HSW_EARLY_SDV(dev_priv) (IS_HASWELL(dev_priv) && \
  				    (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0C00)
-#define IS_BDW_ULT(dev_priv)	(IS_BROADWELL(dev_priv) && \
-				 ((INTEL_DEVID(dev_priv) & 0xf) == 0x6 ||	\
-				 (INTEL_DEVID(dev_priv) & 0xf) == 0xb ||	\
-				 (INTEL_DEVID(dev_priv) & 0xf) == 0xe))
-/* ULX machines are also considered ULT. */
-#define IS_BDW_ULX(dev_priv)	(IS_BROADWELL(dev_priv) && \
-				 (INTEL_DEVID(dev_priv) & 0xf) == 0xe)
+#define IS_BDW_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULT)
+#define IS_BDW_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULX)
  #define IS_BDW_GT3(dev_priv)	(IS_BROADWELL(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 3)
-#define IS_HSW_ULT(dev_priv)	(IS_HASWELL(dev_priv) && \
-				 (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0A00)
+#define IS_HSW_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULT)
  #define IS_HSW_GT3(dev_priv)	(IS_HASWELL(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 3)
  #define IS_HSW_GT1(dev_priv)	(IS_HASWELL(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 1)
  /* ULX machines are also considered ULT. */
-#define IS_HSW_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x0A0E || \
-				 INTEL_DEVID(dev_priv) == 0x0A1E)
-#define IS_SKL_ULT(dev_priv)	(INTEL_DEVID(dev_priv) == 0x1906 || \
-				 INTEL_DEVID(dev_priv) == 0x1913 || \
-				 INTEL_DEVID(dev_priv) == 0x1916 || \
-				 INTEL_DEVID(dev_priv) == 0x1921 || \
-				 INTEL_DEVID(dev_priv) == 0x1926)
-#define IS_SKL_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x190E || \
-				 INTEL_DEVID(dev_priv) == 0x1915 || \
-				 INTEL_DEVID(dev_priv) == 0x191E)
-#define IS_KBL_ULT(dev_priv)	(INTEL_DEVID(dev_priv) == 0x5906 || \
-				 INTEL_DEVID(dev_priv) == 0x5913 || \
-				 INTEL_DEVID(dev_priv) == 0x5916 || \
-				 INTEL_DEVID(dev_priv) == 0x5921 || \
-				 INTEL_DEVID(dev_priv) == 0x5926)
-#define IS_KBL_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x590E || \
-				 INTEL_DEVID(dev_priv) == 0x5915 || \
-				 INTEL_DEVID(dev_priv) == 0x591E)
-#define IS_AML_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x591C || \
-				 INTEL_DEVID(dev_priv) == 0x87C0)
+#define IS_HSW_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULX)
+#define IS_SKL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULT)
+#define IS_SKL_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULX)
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2388

Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.h +6 -0
+#define IS_KBL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULT)
+#define IS_KBL_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULX)
+#define IS_AML_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_AML_ULX)

Why is AML_ULX different from normal ULX?

As far as I could it is a different devid which we officially call Amberlake, but did not add it as separate platform.

Given how this macro is used, which is always in conjuction with IS_KBL_ULX, I considered just removing it and adding the devid to KBL_ULX, but did not want to interferre with other people's ideas.

Quoted 28 lines
Quoted 14 lines
drivers/gpu/drm/i915/i915_drv.h +2 -2
  #define IS_SKL_GT2(dev_priv)	(IS_SKYLAKE(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 2)
  #define IS_SKL_GT3(dev_priv)	(IS_SKYLAKE(dev_priv) && \
@@ -2364,16 +2396,16 @@ static inline unsigned int i915_sg_segment_size(void)
  				 INTEL_INFO(dev_priv)->gt == 2)
  #define IS_KBL_GT3(dev_priv)	(IS_KABYLAKE(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 3)
-#define IS_CFL_ULT(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
-				 (INTEL_DEVID(dev_priv) & 0x00F0) == 0x00A0)
+#define IS_CFL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULT)
  #define IS_CFL_GT2(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 2)

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2408

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +4 -4
  #define IS_CFL_GT3(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 3)
-#define IS_CNL_WITH_PORT_F(dev_priv)   (IS_CANNONLAKE(dev_priv) && \
-					(INTEL_DEVID(dev_priv) & 0x0004) == 0x0004)
-#define IS_ICL_WITH_PORT_F(dev_priv)   (IS_ICELAKE(dev_priv) && \
-					INTEL_DEVID(dev_priv) != 0x8A51)
+#define IS_CNL_WITH_PORT_F(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_CANNONLAKE, INTEL_SUBPLATFORM_PORTF)
+#define IS_ICL_WITH_PORT_F(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_ICELAKE, INTEL_SUBPLATFORM_PORTF)

God that PORTF thing is ugly. I would suggest we just add port_mask or something along those lines into the device info.

Quoted 4 lines

Then we could perhaps even avoid adding more and more branches to intel_setup_outputs(). Although I'm not sure we need anything for that since we'll look at the VBT anyway (which *maybe* doesn't advertize ports that aren't present?).

No idea, sounds like a question for you display folks to decide separately of this proposal probably?

Quoted 129 lines
Quoted 129 lines
drivers/gpu/drm/i915/i915_drv.h +0 -0
  #define IS_ALPHA_SUPPORT(intel_info) ((intel_info)->is_alpha_support)
 
drivers/gpu/drm/i915/i915_pci.c +1 -1
index 3cf697e8f1fa..2b042618e3ca 100644
@@ -32,7 +32,7 @@
  #include "i915_globals.h"
  #include "i915_selftest.h"
 
-#define PLATFORM(x) .platform = (x), .platform_mask = BIT(x)
+#define PLATFORM(x) .platform = (x)
  #define GEN(x) .gen = (x), .gen_mask = BIT((x) - 1)
 
  #define I845_PIPE_OFFSETS \
drivers/gpu/drm/i915/intel_device_info.c +79 -0
index aac19b1c419c..b8a7e17cb443 100644
@@ -707,6 +707,85 @@ static u32 read_timestamp_frequency(struct drm_i915_private *dev_priv)
  	return 0;
  }
 
+void intel_device_info_subplatform_init(struct drm_i915_private *i915)
+{
+	const unsigned int pbits =
+		BITS_PER_TYPE(RUNTIME_INFO(i915)->platform_mask[0]) -
+		INTEL_SUBPLATFORM_BITS;
+	const unsigned int pi = INTEL_INFO(i915)->platform / pbits;
+	const unsigned int pb =
+		INTEL_INFO(i915)->platform % pbits + INTEL_SUBPLATFORM_BITS;
+	struct intel_runtime_info *info = RUNTIME_INFO(i915);
+	u16 devid = INTEL_DEVID(i915);
+
+	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
+		     pbits * ARRAY_SIZE(RUNTIME_INFO(i915)->platform_mask));
+
+	info->platform_mask[pi] = BIT(pb);
+
+	if (IS_PINEVIEW(i915)) {
+		if (devid == 0xa001)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_PINEVIEW_G);
+		else if (devid == 0xa011)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_PINEVIEW_M);
+	} else if (IS_IRONLAKE(i915)) {
+		if (devid == 0x0046)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_IRONLAKE_M);
+	} else if (IS_HASWELL(i915)) {
+		if ((devid & 0xFF00) == 0x0A00)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		/* ULX machines are also considered ULT. */
+		if (devid == 0x0A0E || devid == 0x0A1E)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+	} else if (IS_BROADWELL(i915)) {
+		if ((devid & 0xf) == 0x6 ||
+		    (devid & 0xf) == 0xb ||
+		    (devid & 0xf) == 0xe)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		/* ULX machines are also considered ULT. */
+		if ((devid & 0xf) == 0xe)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+	} else if (IS_SKYLAKE(i915)) {
+		if (devid == 0x1906 ||
+		    devid == 0x1913 ||
+		    devid == 0x1916 ||
+		    devid == 0x1921 ||
+		    devid == 0x1926)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		else if (devid == 0x190E ||
+			 devid == 0x1915 ||
+			 devid == 0x191E)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+	} else if (IS_KABYLAKE(i915)) {
+		if (devid == 0x5906 ||
+		    devid == 0x5913 ||
+		    devid == 0x5916 ||
+		    devid == 0x5921 ||
+		    devid  == 0x5926)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		else if (devid == 0x590E ||
+			 devid == 0x5915 ||
+			 devid == 0x591E)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+		else if (devid == 0x591C ||
+			 devid == 0x87C0)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_AML_ULX);
+	} else if (IS_COFFEELAKE(i915)) {
+		if ((devid & 0x00F0) == 0x00A0)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+	} else if (IS_CANNONLAKE(i915)) {
+		if ((devid & 0x0004) == 0x0004)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_PORTF);
+	} else if (IS_ICELAKE(i915)) {
+		if (devid != 0x8A51)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_PORTF);
+	}
+}
+
  /**
   * intel_device_info_runtime_init - initialize runtime info
   * @dev_priv: the i915 device
drivers/gpu/drm/i915/intel_device_info.h +2 -2
index 047d10bdd455..b03fbd2e451a 100644
@@ -44,7 +44,7 @@ enum intel_platform {
  	INTEL_I915G,
  	INTEL_I915GM,
  	INTEL_I945G,
-	INTEL_I945GM,
+	INTEL_I945GM = 8,
  	INTEL_G33,
  	INTEL_PINEVIEW,
  	/* gen4 */
@@ -55,7 +55,7 @@ enum intel_platform {
  	/* gen5 */
  	INTEL_IRONLAKE,
  	/* gen6 */
-	INTEL_SANDYBRIDGE,
+	INTEL_SANDYBRIDGE = 16,
  	/* gen7 */
  	INTEL_IVYBRIDGE,
  	INTEL_VALLEYVIEW,
Quoted 8 lines

drivers/gpu/drm/i915/intel_device_info.h enum intel_platform { · line 69

Quoted 6 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -1
@@ -66,7 +66,7 @@ enum intel_platform {
  	/* gen9 */
  	INTEL_SKYLAKE,
  	INTEL_BROXTON,
-	INTEL_KABYLAKE,
+	INTEL_KABYLAKE = 24,

Too much magic. Looks rather fragile.

Imagine these hunks gone. This is not required for this patch at all, or for anything for that matter. What do you think is magic and fragile?

Regards,

Tvrtko

Quoted 57 lines
Quoted 57 lines
drivers/gpu/drm/i915/intel_device_info.h +21 -1
  	INTEL_GEMINILAKE,
  	INTEL_COFFEELAKE,
  	/* gen10 */
@@ -76,6 +76,24 @@ enum intel_platform {
  	INTEL_MAX_PLATFORMS
  };
 
+/*
+ * Subplatform bits share the same namespace per parent platform. In other words
+ * it is fine for the same bit to be used on multiple parent platforms.
+ */
+
+#define INTEL_SUBPLATFORM_BITS (3)
+
+#define INTEL_SUBPLATFORM_IRONLAKE_M (0)
+
+#define INTEL_SUBPLATFORM_PINEVIEW_G (0)
+#define INTEL_SUBPLATFORM_PINEVIEW_M (1)
+
+#define INTEL_SUBPLATFORM_ULT	  (0)
+#define INTEL_SUBPLATFORM_ULX	  (1)
+#define INTEL_SUBPLATFORM_AML_ULX (2)
+
+#define INTEL_SUBPLATFORM_PORTF (0)
+
  enum intel_ppgtt {
  	INTEL_PPGTT_NONE = I915_GEM_PPGTT_NONE,
  	INTEL_PPGTT_ALIASING = I915_GEM_PPGTT_ALIASING,
@@ -160,7 +178,6 @@ struct intel_device_info {
  	intel_engine_mask_t engine_mask; /* Engines supported by the HW */
 
  	enum intel_platform platform;
-	u32 platform_mask;
 
  	enum intel_ppgtt ppgtt;
  	unsigned int page_sizes; /* page sizes supported by the HW */
@@ -195,6 +212,8 @@ struct intel_device_info {
  };
 
  struct intel_runtime_info {
+	u32 platform_mask[1];
+
  	u16 device_id;
 
  	u8 num_sprites[I915_MAX_PIPES];
@@ -269,6 +288,7 @@ static inline void sseu_set_eus(struct sseu_dev_info *sseu,
 
  const char *intel_platform_name(enum intel_platform platform);
 
+void intel_device_info_subplatform_init(struct drm_i915_private *dev_priv);
  void intel_device_info_runtime_init(struct drm_i915_private *dev_priv);
  void intel_device_info_dump_flags(const struct intel_device_info *info,
  				  struct drm_printer *p);
Signature · 1 line
2.19.1
Quoted 5 lines
Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw
Quoted 156 lines · Tvrtko Ursulin
Quoted 146 lines · Ville Syrjälä
Quoted 131 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>
---
  drivers/gpu/drm/i915/i915_drv.c          |   7 +-
  drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
  drivers/gpu/drm/i915/i915_pci.c          |   2 +-
  drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
  drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
  5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +4 -3
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv)
  	if (i915_inject_load_failure())
  		return -ENODEV;
 
+	intel_device_info_subplatform_init(dev_priv);
+
  	spin_lock_init(&dev_priv->irq_lock);
  	spin_lock_init(&dev_priv->gpu_error.lock);
  	mutex_init(&dev_priv->backlight_lock);
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
  	if (drm_debug & DRM_UT_DRIVER) {
  		struct drm_printer p = drm_debug_printer("i915 device info:");
 
-		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) gen=%i\n",
  			   INTEL_DEVID(dev_priv),
  			   INTEL_REVID(dev_priv),
  			   intel_platform_name(INTEL_INFO(dev_priv)->platform),
+			   RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],
  			   INTEL_GEN(dev_priv));
 
  		intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
  	memcpy(device_info, match_info, sizeof(*device_info));
  	RUNTIME_INFO(i915)->device_id = pdev->device;
 
-	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-		     BITS_PER_TYPE(device_info->platform_mask));
  	BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 
  	return i915;
drivers/gpu/drm/i915/i915_drv.h +40 -1
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int i915_sg_segment_size(void)
  #define IS_REVID(p, since, until) \
  	(INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) (INTEL_INFO(dev_priv)->platform_mask & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \
+({ \
+	const unsigned int pbits__ = \
+		BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+		INTEL_SUBPLATFORM_BITS; \
+	const unsigned int pi__ = (p) / pbits__; \
+	const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+	BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+	(RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \
+})
+
+#define __IS_SUBPLATFORM(dev_priv, p, s) \
+({ \
+	const unsigned int pbits__ = \
+		BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+		INTEL_SUBPLATFORM_BITS; \
+	const unsigned int pi__ = (p) / pbits__; \
+	const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+	BUILD_BUG_ON(!__builtin_constant_p(p)); \
+	BUILD_BUG_ON(!__builtin_constant_p(s)); \
+	BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS); \
+\
+	(RUNTIME_INFO(dev_priv)->platform_mask[pi__] & (BIT(pb__) | BIT(s))); \
+})
+
+static inline bool
+IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p)
+{
+	return __IS_PLATFORM(i915, p);
+}
+
+static inline bool
+IS_SUBPLATFORM(const struct drm_i915_private *i915,
+	       enum intel_platform p, unsigned int s)
+{
+	return __IS_SUBPLATFORM(i915, p, s);
+}
 
  #define IS_I830(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I830)
  #define IS_I845G(dev_priv)	IS_PLATFORM(dev_priv, INTEL_I845G)

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2342

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +4 -2
@@ -2296,11 +2335,15 @@ static inline unsigned int i915_sg_segment_size(void)
  #define IS_G45(dev_priv)	IS_PLATFORM(dev_priv, INTEL_G45)
  #define IS_GM45(dev_priv)	IS_PLATFORM(dev_priv, INTEL_GM45)
  #define IS_G4X(dev_priv)	(IS_G45(dev_priv) || IS_GM45(dev_priv))
-#define IS_PINEVIEW_G(dev_priv)	(INTEL_DEVID(dev_priv) == 0xa001)
-#define IS_PINEVIEW_M(dev_priv)	(INTEL_DEVID(dev_priv) == 0xa011)
+#define IS_PINEVIEW_G(dev_priv)	\
+	IS_SUBPLATFORM(dev_priv, INTEL_PINEVIEW, INTEL_SUBPLATFORM_PINEVIEW_G)
+#define IS_PINEVIEW_M(dev_priv)	\
+	IS_SUBPLATFORM(dev_priv, INTEL_PINEVIEW, INTEL_SUBPLATFORM_PINEVIEW_M)
  #define IS_PINEVIEW(dev_priv)	IS_PLATFORM(dev_priv, INTEL_PINEVIEW)

I have a feeling we should just use the normal IS_MOBILE() thing here. But untangling that mess might be a bit of work.

Quoted 7 lines

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2346

Quoted 5 lines
drivers/gpu/drm/i915/i915_drv.h +3 -1
  #define IS_G33(dev_priv)	IS_PLATFORM(dev_priv, INTEL_G33)
-#define IS_IRONLAKE_M(dev_priv)	(INTEL_DEVID(dev_priv) == 0x0046)
+#define IS_IRONLAKE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_IRONLAKE)
+#define IS_IRONLAKE_M(dev_priv)	\
+	IS_SUBPLATFORM(dev_priv, INTEL_IRONLAKE, INTEL_SUBPLATFORM_IRONLAKE_M)

This is clearly just IS_MOBILE().

Quoted 6 lines

Ok.

Quoted 2 lines

Or we just keep the current pci id checks. Frankly I see no benefit in abstracting these few exceptions.

Are you referring to Ironlake only or in general?

pnv and ilk.

Quoted 66 lines
Quoted 57 lines
Quoted 57 lines
drivers/gpu/drm/i915/i915_drv.h +12 -29
  #define IS_IVYBRIDGE(dev_priv)	IS_PLATFORM(dev_priv, INTEL_IVYBRIDGE)
  #define IS_IVB_GT1(dev_priv)	(IS_IVYBRIDGE(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 1)
@@ -2318,42 +2361,31 @@ static inline unsigned int i915_sg_segment_size(void)
  #define IS_MOBILE(dev_priv)	(INTEL_INFO(dev_priv)->is_mobile)
  #define IS_HSW_EARLY_SDV(dev_priv) (IS_HASWELL(dev_priv) && \
  				    (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0C00)
-#define IS_BDW_ULT(dev_priv)	(IS_BROADWELL(dev_priv) && \
-				 ((INTEL_DEVID(dev_priv) & 0xf) == 0x6 ||	\
-				 (INTEL_DEVID(dev_priv) & 0xf) == 0xb ||	\
-				 (INTEL_DEVID(dev_priv) & 0xf) == 0xe))
-/* ULX machines are also considered ULT. */
-#define IS_BDW_ULX(dev_priv)	(IS_BROADWELL(dev_priv) && \
-				 (INTEL_DEVID(dev_priv) & 0xf) == 0xe)
+#define IS_BDW_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULT)
+#define IS_BDW_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_BROADWELL, INTEL_SUBPLATFORM_ULX)
  #define IS_BDW_GT3(dev_priv)	(IS_BROADWELL(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 3)
-#define IS_HSW_ULT(dev_priv)	(IS_HASWELL(dev_priv) && \
-				 (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0A00)
+#define IS_HSW_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULT)
  #define IS_HSW_GT3(dev_priv)	(IS_HASWELL(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 3)
  #define IS_HSW_GT1(dev_priv)	(IS_HASWELL(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 1)
  /* ULX machines are also considered ULT. */
-#define IS_HSW_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x0A0E || \
-				 INTEL_DEVID(dev_priv) == 0x0A1E)
-#define IS_SKL_ULT(dev_priv)	(INTEL_DEVID(dev_priv) == 0x1906 || \
-				 INTEL_DEVID(dev_priv) == 0x1913 || \
-				 INTEL_DEVID(dev_priv) == 0x1916 || \
-				 INTEL_DEVID(dev_priv) == 0x1921 || \
-				 INTEL_DEVID(dev_priv) == 0x1926)
-#define IS_SKL_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x190E || \
-				 INTEL_DEVID(dev_priv) == 0x1915 || \
-				 INTEL_DEVID(dev_priv) == 0x191E)
-#define IS_KBL_ULT(dev_priv)	(INTEL_DEVID(dev_priv) == 0x5906 || \
-				 INTEL_DEVID(dev_priv) == 0x5913 || \
-				 INTEL_DEVID(dev_priv) == 0x5916 || \
-				 INTEL_DEVID(dev_priv) == 0x5921 || \
-				 INTEL_DEVID(dev_priv) == 0x5926)
-#define IS_KBL_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x590E || \
-				 INTEL_DEVID(dev_priv) == 0x5915 || \
-				 INTEL_DEVID(dev_priv) == 0x591E)
-#define IS_AML_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x591C || \
-				 INTEL_DEVID(dev_priv) == 0x87C0)
+#define IS_HSW_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULX)
+#define IS_SKL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULT)
+#define IS_SKL_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULX)
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2388

Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.h +6 -0
+#define IS_KBL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULT)
+#define IS_KBL_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULX)
+#define IS_AML_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_AML_ULX)

Why is AML_ULX different from normal ULX?

Quoted 6 lines

As far as I could it is a different devid which we officially call Amberlake, but did not add it as separate platform.

Given how this macro is used, which is always in conjuction with IS_KBL_ULX, I considered just removing it and adding the devid to KBL_ULX, but did not want to interferre with other people's ideas.

This whole AML_ULX makes no sense. The "non-ULX" AML is also docucemented to be a Y SKU, so AFAICS it should use the exact same codepaths as KBL Y (aka. KBL_ULX). Cc:ing Jose who added this second AML variant...

I'm really tempted to just go and nuke all CFL,AML,etc. from the code to make it actually match the spec.

Quoted 175 lines
Quoted 29 lines
Quoted 15 lines
drivers/gpu/drm/i915/i915_drv.h +2 -2
  #define IS_SKL_GT2(dev_priv)	(IS_SKYLAKE(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 2)
  #define IS_SKL_GT3(dev_priv)	(IS_SKYLAKE(dev_priv) && \
@@ -2364,16 +2396,16 @@ static inline unsigned int i915_sg_segment_size(void)
  				 INTEL_INFO(dev_priv)->gt == 2)
  #define IS_KBL_GT3(dev_priv)	(IS_KABYLAKE(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 3)
-#define IS_CFL_ULT(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
-				 (INTEL_DEVID(dev_priv) & 0x00F0) == 0x00A0)
+#define IS_CFL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_COFFEELAKE, INTEL_SUBPLATFORM_ULT)
  #define IS_CFL_GT2(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 2)

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2408

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +4 -4
  #define IS_CFL_GT3(dev_priv)	(IS_COFFEELAKE(dev_priv) && \
  				 INTEL_INFO(dev_priv)->gt == 3)
-#define IS_CNL_WITH_PORT_F(dev_priv)   (IS_CANNONLAKE(dev_priv) && \
-					(INTEL_DEVID(dev_priv) & 0x0004) == 0x0004)
-#define IS_ICL_WITH_PORT_F(dev_priv)   (IS_ICELAKE(dev_priv) && \
-					INTEL_DEVID(dev_priv) != 0x8A51)
+#define IS_CNL_WITH_PORT_F(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_CANNONLAKE, INTEL_SUBPLATFORM_PORTF)
+#define IS_ICL_WITH_PORT_F(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_ICELAKE, INTEL_SUBPLATFORM_PORTF)

God that PORTF thing is ugly. I would suggest we just add port_mask or something along those lines into the device info.

Quoted 4 lines

Then we could perhaps even avoid adding more and more branches to intel_setup_outputs(). Although I'm not sure we need anything for that since we'll look at the VBT anyway (which *maybe* doesn't advertize ports that aren't present?).

No idea, sounds like a question for you display folks to decide separately of this proposal probably?

Quoted 129 lines
Quoted 129 lines
drivers/gpu/drm/i915/i915_drv.h +0 -0
  #define IS_ALPHA_SUPPORT(intel_info) ((intel_info)->is_alpha_support)
 
drivers/gpu/drm/i915/i915_pci.c +1 -1
index 3cf697e8f1fa..2b042618e3ca 100644
@@ -32,7 +32,7 @@
  #include "i915_globals.h"
  #include "i915_selftest.h"
 
-#define PLATFORM(x) .platform = (x), .platform_mask = BIT(x)
+#define PLATFORM(x) .platform = (x)
  #define GEN(x) .gen = (x), .gen_mask = BIT((x) - 1)
 
  #define I845_PIPE_OFFSETS \
drivers/gpu/drm/i915/intel_device_info.c +79 -0
index aac19b1c419c..b8a7e17cb443 100644
@@ -707,6 +707,85 @@ static u32 read_timestamp_frequency(struct drm_i915_private *dev_priv)
  	return 0;
  }
 
+void intel_device_info_subplatform_init(struct drm_i915_private *i915)
+{
+	const unsigned int pbits =
+		BITS_PER_TYPE(RUNTIME_INFO(i915)->platform_mask[0]) -
+		INTEL_SUBPLATFORM_BITS;
+	const unsigned int pi = INTEL_INFO(i915)->platform / pbits;
+	const unsigned int pb =
+		INTEL_INFO(i915)->platform % pbits + INTEL_SUBPLATFORM_BITS;
+	struct intel_runtime_info *info = RUNTIME_INFO(i915);
+	u16 devid = INTEL_DEVID(i915);
+
+	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
+		     pbits * ARRAY_SIZE(RUNTIME_INFO(i915)->platform_mask));
+
+	info->platform_mask[pi] = BIT(pb);
+
+	if (IS_PINEVIEW(i915)) {
+		if (devid == 0xa001)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_PINEVIEW_G);
+		else if (devid == 0xa011)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_PINEVIEW_M);
+	} else if (IS_IRONLAKE(i915)) {
+		if (devid == 0x0046)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_IRONLAKE_M);
+	} else if (IS_HASWELL(i915)) {
+		if ((devid & 0xFF00) == 0x0A00)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		/* ULX machines are also considered ULT. */
+		if (devid == 0x0A0E || devid == 0x0A1E)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+	} else if (IS_BROADWELL(i915)) {
+		if ((devid & 0xf) == 0x6 ||
+		    (devid & 0xf) == 0xb ||
+		    (devid & 0xf) == 0xe)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		/* ULX machines are also considered ULT. */
+		if ((devid & 0xf) == 0xe)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+	} else if (IS_SKYLAKE(i915)) {
+		if (devid == 0x1906 ||
+		    devid == 0x1913 ||
+		    devid == 0x1916 ||
+		    devid == 0x1921 ||
+		    devid == 0x1926)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		else if (devid == 0x190E ||
+			 devid == 0x1915 ||
+			 devid == 0x191E)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+	} else if (IS_KABYLAKE(i915)) {
+		if (devid == 0x5906 ||
+		    devid == 0x5913 ||
+		    devid == 0x5916 ||
+		    devid == 0x5921 ||
+		    devid  == 0x5926)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+		else if (devid == 0x590E ||
+			 devid == 0x5915 ||
+			 devid == 0x591E)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+		else if (devid == 0x591C ||
+			 devid == 0x87C0)
+			info->platform_mask[pi] |=
+				BIT(INTEL_SUBPLATFORM_AML_ULX);
+	} else if (IS_COFFEELAKE(i915)) {
+		if ((devid & 0x00F0) == 0x00A0)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+	} else if (IS_CANNONLAKE(i915)) {
+		if ((devid & 0x0004) == 0x0004)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_PORTF);
+	} else if (IS_ICELAKE(i915)) {
+		if (devid != 0x8A51)
+			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_PORTF);
+	}
+}
+
  /**
   * intel_device_info_runtime_init - initialize runtime info
   * @dev_priv: the i915 device
drivers/gpu/drm/i915/intel_device_info.h +2 -2
index 047d10bdd455..b03fbd2e451a 100644
@@ -44,7 +44,7 @@ enum intel_platform {
  	INTEL_I915G,
  	INTEL_I915GM,
  	INTEL_I945G,
-	INTEL_I945GM,
+	INTEL_I945GM = 8,
  	INTEL_G33,
  	INTEL_PINEVIEW,
  	/* gen4 */
@@ -55,7 +55,7 @@ enum intel_platform {
  	/* gen5 */
  	INTEL_IRONLAKE,
  	/* gen6 */
-	INTEL_SANDYBRIDGE,
+	INTEL_SANDYBRIDGE = 16,
  	/* gen7 */
  	INTEL_IVYBRIDGE,
  	INTEL_VALLEYVIEW,
Quoted 8 lines

drivers/gpu/drm/i915/intel_device_info.h enum intel_platform { · line 69

Quoted 6 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -1
@@ -66,7 +66,7 @@ enum intel_platform {
  	/* gen9 */
  	INTEL_SKYLAKE,
  	INTEL_BROXTON,
-	INTEL_KABYLAKE,
+	INTEL_KABYLAKE = 24,

Too much magic. Looks rather fragile.

Quoted 2 lines

Imagine these hunks gone. This is not required for this patch at all, or for anything for that matter. What do you think is magic and fragile?

Who is going to remeber to keep adding those magic numbers in the future.

Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw
Quoted 27 lines · Ville Syrjälä
Quoted 26 lines · Tvrtko Ursulin
Quoted 12 lines · Ville Syrjälä
Quoted 11 lines · Tvrtko Ursulin
drivers/gpu/drm/i915/i915_drv.h +6 -5
-#define IS_KBL_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x590E || \
-				 INTEL_DEVID(dev_priv) == 0x5915 || \
-				 INTEL_DEVID(dev_priv) == 0x591E)
-#define IS_AML_ULX(dev_priv)	(INTEL_DEVID(dev_priv) == 0x591C || \
-				 INTEL_DEVID(dev_priv) == 0x87C0)
+#define IS_HSW_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_HASWELL, INTEL_SUBPLATFORM_ULX)
+#define IS_SKL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULT)
+#define IS_SKL_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_SKYLAKE, INTEL_SUBPLATFORM_ULX)
Quoted 8 lines

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2388

Quoted 6 lines
drivers/gpu/drm/i915/i915_drv.h +6 -0
+#define IS_KBL_ULT(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULT)
+#define IS_KBL_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_ULX)
+#define IS_AML_ULX(dev_priv) \
+	IS_SUBPLATFORM(dev_priv, INTEL_KABYLAKE, INTEL_SUBPLATFORM_AML_ULX)

Why is AML_ULX different from normal ULX?

As far as I could it is a different devid which we officially call Amberlake, but did not add it as separate platform.

Quoted 8 lines
Quoted 3 lines

Given how this macro is used, which is always in conjuction with IS_KBL_ULX, I considered just removing it and adding the devid to KBL_ULX, but did not want to interferre with other people's ideas.

This whole AML_ULX makes no sense. The "non-ULX" AML is also docucemented to be a Y SKU, so AFAICS it should use the exact same codepaths as KBL Y (aka. KBL_ULX). Cc:ing Jose who added this second AML variant...

Actually cc this time.

Quoted 4 lines

I'm really tempted to just go and nuke all CFL,AML,etc. from the code to make it actually match the spec.

Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw
In reply to Ville Syrjälä
Quoted 1 line · Ville Syrjälä

On Fri, Mar 15, 2019 at 02:21:57PM +0000, Tvrtko Ursulin wrote:

[snip]

Quoted 31 lines
Quoted 31 lines
Quoted 30 lines
Quoted 23 lines
drivers/gpu/drm/i915/intel_device_info.h +2 -2
index 047d10bdd455..b03fbd2e451a 100644
@@ -44,7 +44,7 @@ enum intel_platform {
   	INTEL_I915G,
   	INTEL_I915GM,
   	INTEL_I945G,
-	INTEL_I945GM,
+	INTEL_I945GM = 8,
   	INTEL_G33,
   	INTEL_PINEVIEW,
   	/* gen4 */
@@ -55,7 +55,7 @@ enum intel_platform {
   	/* gen5 */
   	INTEL_IRONLAKE,
   	/* gen6 */
-	INTEL_SANDYBRIDGE,
+	INTEL_SANDYBRIDGE = 16,
   	/* gen7 */
   	INTEL_IVYBRIDGE,
   	INTEL_VALLEYVIEW,

drivers/gpu/drm/i915/intel_device_info.h enum intel_platform { · line 69

Quoted 5 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -1
@@ -66,7 +66,7 @@ enum intel_platform {
   	/* gen9 */
   	INTEL_SKYLAKE,
   	INTEL_BROXTON,
-	INTEL_KABYLAKE,
+	INTEL_KABYLAKE = 24,

Too much magic. Looks rather fragile.

Quoted 5 lines
Quoted 2 lines

Imagine these hunks gone. This is not required for this patch at all, or for anything for that matter. What do you think is magic and fragile?

Who is going to remeber to keep adding those magic numbers in the future.

They serve no purpose. :) I'll remove them from the next respin. It was just me counting to see how many fit into one u32 of mask bits if I reserve N low bits for the subplatform mask.

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#9 lore raw

✗ Fi.CI.BAT: failure for drm/i915: Introduce concept of a sub-platform

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: drm/i915: Introduce concept of a sub-platform
URL : https://patchwork.freedesktop.org/series/58056/
State : failure

== Summary ==

Applying: drm/i915: Introduce concept of a sub-platform
Using index info to reconstruct a base tree...
M drivers/gpu/drm/i915/i915_drv.c
M drivers/gpu/drm/i915/i915_drv.h
M drivers/gpu/drm/i915/i915_pci.c
M drivers/gpu/drm/i915/intel_device_info.c
M drivers/gpu/drm/i915/intel_device_info.h
Falling back to patching base and 3-way merge...
Auto-merging drivers/gpu/drm/i915/intel_device_info.h
CONFLICT (content): Merge conflict in drivers/gpu/drm/i915/intel_device_info.h Auto-merging drivers/gpu/drm/i915/intel_device_info.c Auto-merging drivers/gpu/drm/i915/i915_pci.c
Auto-merging drivers/gpu/drm/i915/i915_drv.h
Auto-merging drivers/gpu/drm/i915/i915_drv.c
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch' to see the failed patch Patch failed at 0001 drm/i915: Introduce concept of a sub-platform When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#10 lore raw

PATCH v5 1/1 drm/i915: Introduce concept of a sub-platform

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

v5:
* Fix subplatform check.
* Protect against forgetting to expand subplatform bits.
* Remove platform enum tallying.
* Add subplatform to error state. (Chris)
* Drop macros and just use static inlines.
* Remove redundant IRONLAKE_M. (Ville)

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>
Cc Ville Syrjälä <[email protected]>
---
 drivers/gpu/drm/i915/i915_drv.c          |   7 +-
 drivers/gpu/drm/i915/i915_drv.h          | 131 ++++++++++++++++-------
 drivers/gpu/drm/i915/i915_gpu_error.c    |   1 +
 drivers/gpu/drm/i915/i915_pci.c          |   2 +-
 drivers/gpu/drm/i915/intel_device_info.c |  71 ++++++++++++
 drivers/gpu/drm/i915/intel_device_info.h |  20 +++-
 6 files changed, 187 insertions(+), 45 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +4 -3
index a3b00ecc58c9..5551695a1db5 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv)
 	if (i915_inject_load_failure())
 		return -ENODEV;
 
+	intel_device_info_subplatform_init(dev_priv);
+
 	spin_lock_init(&dev_priv->irq_lock);
 	spin_lock_init(&dev_priv->gpu_error.lock);
 	mutex_init(&dev_priv->backlight_lock);
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
 	if (drm_debug & DRM_UT_DRIVER) {
 		struct drm_printer p = drm_debug_printer("i915 device info:");
 
-		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (subplatform=0x%x) gen=%i\n",
 			   INTEL_DEVID(dev_priv),
 			   INTEL_REVID(dev_priv),
 			   intel_platform_name(INTEL_INFO(dev_priv)->platform),
+			   intel_subplatform(dev_priv),
 			   INTEL_GEN(dev_priv));
 
 		intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
 	memcpy(device_info, match_info, sizeof(*device_info));
 	RUNTIME_INFO(i915)->device_id = pdev->device;
 
-	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-		     BITS_PER_TYPE(device_info->platform_mask));
 	BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 
 	return i915;
drivers/gpu/drm/i915/i915_drv.h +91 -40

170 lines not on this page · raw message

drivers/gpu/drm/i915/i915_gpu_error.c +1 -0
index 3d8020888604..e3360a31f8d3 100644
@@ -677,6 +677,7 @@ static void __err_print_to_sgl(struct drm_i915_error_state_buf *m,
 	err_printf(m, "Reset count: %u\n", error->reset_count);
 	err_printf(m, "Suspend count: %u\n", error->suspend_count);
 	err_printf(m, "Platform: %s\n", intel_platform_name(error->device_info.platform));
+	err_printf(m, "Subplatform: 0x%x\n", intel_subplatform(m->i915));
 	err_print_pciid(m, m->i915);
 
 	err_printf(m, "IOMMU enabled?: %d\n", error->iommu);
drivers/gpu/drm/i915/i915_pci.c +1 -1
index ef7410c492fd..1522385d098b 100644
@@ -32,7 +32,7 @@
 #include "i915_globals.h"
 #include "i915_selftest.h"
 
-#define PLATFORM(x) .platform = (x), .platform_mask = BIT(x)
+#define PLATFORM(x) .platform = (x)
 #define GEN(x) .gen = (x), .gen_mask = BIT((x) - 1)
 
 #define I845_PIPE_OFFSETS \
drivers/gpu/drm/i915/intel_device_info.c +71 -0

77 lines not on this page · raw message

drivers/gpu/drm/i915/intel_device_info.h +19 -1
index 6234570a9b17..81d76fffb7b0 100644
@@ -76,6 +76,22 @@ enum intel_platform {
 	INTEL_MAX_PLATFORMS
 };
 
+/*
+ * Subplatform bits share the same namespace per parent platform. In other words
+ * it is fine for the same bit to be used on multiple parent platforms.
+ */
+
+#define INTEL_SUBPLATFORM_BITS (3)
+
+#define INTEL_SUBPLATFORM_PINEVIEW_G (0)
+#define INTEL_SUBPLATFORM_PINEVIEW_M (1)
+
+#define INTEL_SUBPLATFORM_ULT	  (0)
+#define INTEL_SUBPLATFORM_ULX	  (1)
+#define INTEL_SUBPLATFORM_AML_ULX (2)
+
+#define INTEL_SUBPLATFORM_PORTF (0)
+
 enum intel_ppgtt_type {
 	INTEL_PPGTT_NONE = I915_GEM_PPGTT_NONE,
 	INTEL_PPGTT_ALIASING = I915_GEM_PPGTT_ALIASING,
@@ -159,7 +175,6 @@ struct intel_device_info {
 	intel_engine_mask_t engine_mask; /* Engines supported by the HW */
 
 	enum intel_platform platform;
-	u32 platform_mask;
 
 	enum intel_ppgtt_type ppgtt_type;
 	unsigned int ppgtt_size; /* log2, e.g. 31/32/48 bits */
@@ -196,6 +211,8 @@ struct intel_device_info {
 };
 
 struct intel_runtime_info {
+	u32 platform_mask[1];
+
 	u16 device_id;
 
 	u8 num_sprites[I915_MAX_PIPES];
@@ -270,6 +287,7 @@ static inline void sseu_set_eus(struct sseu_dev_info *sseu,
 
 const char *intel_platform_name(enum intel_platform platform);
 
+void intel_device_info_subplatform_init(struct drm_i915_private *dev_priv);
 void intel_device_info_runtime_init(struct drm_i915_private *dev_priv);
 void intel_device_info_dump_flags(const struct intel_device_info *info,
 				  struct drm_printer *p);
Signature · 6 lines
2.19.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw

Quoting Tvrtko Ursulin (2019-03-15 17:09:28)

drivers/gpu/drm/i915/i915_gpu_error.c static void __err_print_to_sgl(struct drm_i915_error_state_buf *m, · line 680

Quoted 9 lines
drivers/gpu/drm/i915/i915_gpu_error.c +1 -0
index 3d8020888604..e3360a31f8d3 100644
@@ -677,6 +677,7 @@ static void __err_print_to_sgl(struct drm_i915_error_state_buf *m,
        err_printf(m, "Reset count: %u\n", error->reset_count);
        err_printf(m, "Suspend count: %u\n", error->suspend_count);
        err_printf(m, "Platform: %s\n", intel_platform_name(error->device_info.platform));
+       err_printf(m, "Subplatform: 0x%x\n", intel_subplatform(m->i915));

We didn't take a copy of the runtime_info? Ww should have done at least, that's even more volatile than device_info.

It'll do for now, but would be nicer if RUNTIME_INFO(i915) wasn't baked so hard into the subplatform :)

Quoted 6 lines
drivers/gpu/drm/i915/i915_gpu_error.c +6 -0
+void intel_device_info_subplatform_init(struct drm_i915_private *i915)
+{
+       const unsigned int pi =
+               __platform_mask_index(i915, INTEL_INFO(i915)->platform);
+       const unsigned int pb =
+               __platform_mask_bit(i915, INTEL_INFO(i915)->platform);

drivers/gpu/drm/i915/i915_gpu_error.c static void __err_print_to_sgl(struct drm_i915_error_state_buf *m,

Quoted 10 lines
drivers/gpu/drm/i915/i915_gpu_error.c +10 -0
+       u16 devid = INTEL_DEVID(i915);
+       u32 mask = 0;
+
+       RUNTIME_INFO(i915)->platform_mask[pi] = BIT(pb);
+
+       if (IS_PINEVIEW(i915)) {
+               if (devid == 0xa001)
+                       mask |= BIT(INTEL_SUBPLATFORM_PINEVIEW_G);
+               else if (devid == 0xa011)
+                       mask |= BIT(INTEL_SUBPLATFORM_PINEVIEW_M);

I take it, leaving is-mobile conversion for the display gurus? -Chris
_______________________________________________
Intel-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#12 lore raw
Quoted 14 lines · Chris Wilson

Quoting Tvrtko Ursulin (2019-03-15 17:09:28)

drivers/gpu/drm/i915/i915_gpu_error.c static void __err_print_to_sgl(struct drm_i915_error_state_buf *m, · line 680

Quoted 9 lines
drivers/gpu/drm/i915/i915_gpu_error.c +1 -0
index 3d8020888604..e3360a31f8d3 100644
@@ -677,6 +677,7 @@ static void __err_print_to_sgl(struct drm_i915_error_state_buf *m,
         err_printf(m, "Reset count: %u\n", error->reset_count);
         err_printf(m, "Suspend count: %u\n", error->suspend_count);
         err_printf(m, "Platform: %s\n", intel_platform_name(error->device_info.platform));
+       err_printf(m, "Subplatform: 0x%x\n", intel_subplatform(m->i915));

We didn't take a copy of the runtime_info? Ww should have done at least, that's even more volatile than device_info.

Quoted 2 lines

It'll do for now, but would be nicer if RUNTIME_INFO(i915) wasn't baked so hard into the subplatform :)

Could do yeah.

Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/i915/i915_gpu_error.c +10 -0
+void intel_device_info_subplatform_init(struct drm_i915_private *i915)
+{
+       const unsigned int pi =
+               __platform_mask_index(i915, INTEL_INFO(i915)->platform);
+       const unsigned int pb =
+               __platform_mask_bit(i915, INTEL_INFO(i915)->platform);
+       u16 devid = INTEL_DEVID(i915);
+       u32 mask = 0;
+
+       RUNTIME_INFO(i915)->platform_mask[pi] = BIT(pb);
Quoted 8 lines

drivers/gpu/drm/i915/i915_gpu_error.c

Quoted 6 lines
drivers/gpu/drm/i915/i915_gpu_error.c +6 -0
+
+       if (IS_PINEVIEW(i915)) {
+               if (devid == 0xa001)
+                       mask |= BIT(INTEL_SUBPLATFORM_PINEVIEW_G);
+               else if (devid == 0xa011)
+                       mask |= BIT(INTEL_SUBPLATFORM_PINEVIEW_M);

I take it, leaving is-mobile conversion for the display gurus?

Ville said it will be hard so I did not even look. :) Okay, it doesn't seem that hard.. but definitely wouldn't stuff it into this patch.

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#13 lore raw
In reply to Tvrtko Ursulin
Quoted 57 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>

---

drivers/gpu/drm/i915/i915_drv.c          |   7 +-
drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
drivers/gpu/drm/i915/i915_pci.c          |   2 +-
drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +2 -0
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv)
 	if (i915_inject_load_failure())
 		return -ENODEV;
 
+	intel_device_info_subplatform_init(dev_priv);
+
 	spin_lock_init(&dev_priv->irq_lock);
 	spin_lock_init(&dev_priv->gpu_error.lock);
 	mutex_init(&dev_priv->backlight_lock);

drivers/gpu/drm/i915/i915_drv.c static void i915_welcome_messages(struct drm_i915_private *dev_priv) · line 1761

Quoted 9 lines
drivers/gpu/drm/i915/i915_drv.c +2 -1
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
 	if (drm_debug & DRM_UT_DRIVER) {
 		struct drm_printer p = drm_debug_printer("i915 device info:");
 
-		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) gen=%i\n",
 			   INTEL_DEVID(dev_priv),
 			   INTEL_REVID(dev_priv),
 			   intel_platform_name(INTEL_INFO(dev_priv)->platform),
+			   RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],

bug here, INTEL_SUBPLATFORM_BITS should be outside of []. Bad things will happen for platform=32 /o\

Quoted 22 lines
drivers/gpu/drm/i915/i915_drv.c +0 -2
 			   INTEL_GEN(dev_priv));
 
 		intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
 	memcpy(device_info, match_info, sizeof(*device_info));
 	RUNTIME_INFO(i915)->device_id = pdev->device;
 
-	BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-		     BITS_PER_TYPE(device_info->platform_mask));
 	BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 
 	return i915;
drivers/gpu/drm/i915/i915_drv.h +1 -1
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int i915_sg_segment_size(void)
 #define IS_REVID(p, since, until) \
 	(INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) (INTEL_INFO(dev_priv)->platform_mask & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int i915_sg_segment_size(void) · line 2294

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +10 -0
+({ \
+	const unsigned int pbits__ = \
+		BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+		INTEL_SUBPLATFORM_BITS; \
+	const unsigned int pi__ = (p) / pbits__; \
+	const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+	BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+	(RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \

Ugh. That double dword fiddling is way too ugly. IMO it is not buying us anything. Just use a u64 rather than the double dword. Your approach may have a small benefit on ARCH=i386, but has the burden of carrying all this forward. The diff below (only build-tested) is on top of yours, which is basically equivalent to "move to u64 and then add the subplatform part".

  text    data     bss     dec     hex filename
1834620   40454    4176 1879250  1cacd2 drivers/gpu/drm/i915/i915.o.yours
1834710   40454    4176 1879340  1cad2c drivers/gpu/drm/i915/i915.o
drivers/gpu/drm/i915/i915_drv.c +0 -0
index 3218350cd225..c8042f4579c6 100644
@@ -1754,11 +1754,11 @@ static void i915_welcome_messages(struct drm_i915_private *dev_priv)
	if (drm_debug & DRM_UT_DRIVER) {
		struct drm_printer p = drm_debug_printer("i915 device info:");

- drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) gen=%i\n",
+ drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%#llx) gen=%i\n",

			   INTEL_DEVID(dev_priv),
			   INTEL_REVID(dev_priv),
			   intel_platform_name(INTEL_INFO(dev_priv)->platform),
-			   RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],
+			   RUNTIME_INFO(dev_priv)->platform_mask,
			   INTEL_GEN(dev_priv));

		intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);
drivers/gpu/drm/i915/i915_drv.h +0 -0
index 34282cf66cb0..bd5d31e07a13 100644
@@ -2283,43 +2283,33 @@ static inline unsigned int i915_sg_segment_size(void)
 

#define __IS_PLATFORM(dev_priv, p) \
({ \
- const unsigned int pbits__ = \
- BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
- INTEL_SUBPLATFORM_BITS; \
- const unsigned int pi__ = (p) / pbits__; \
- const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
-\
- BUILD_BUG_ON(!__builtin_constant_p(p)); \
-\
- (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \
})

#define __IS_SUBPLATFORM(dev_priv, p, s) \
({ \
- const unsigned int pbits__ = \
- BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
- INTEL_SUBPLATFORM_BITS; \
- const unsigned int pi__ = (p) / pbits__; \
- const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
-\
- BUILD_BUG_ON(!__builtin_constant_p(p)); \
- BUILD_BUG_ON(!__builtin_constant_p(s)); \
- BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS); \
-\
- (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & (BIT(pb__) | BIT(s))); \
})

-static inline bool
+__always_inline static inline bool
IS_PLATFORM(const struct drm_i915_private *i915, enum intel_platform p) {
- return __IS_PLATFORM(i915, p);
+ const unsigned int pbit = p + INTEL_SUBPLATFORM_BITS;
+
+ BUILD_BUG_ON(!__builtin_constant_p(p));
+
+ return RUNTIME_INFO(i915)->platform_mask & BIT(pbit);
}

-static inline bool
+__always_inline static inline bool IS_SUBPLATFORM(const struct drm_i915_private *i915,
enum intel_platform p, unsigned int s)
{
- return __IS_SUBPLATFORM(i915, p, s);
+ const unsigned int pbit = p + INTEL_SUBPLATFORM_BITS;
+
+ BUILD_BUG_ON(!__builtin_constant_p(p));
+ BUILD_BUG_ON(!__builtin_constant_p(s));
+ BUILD_BUG_ON((s) >= INTEL_SUBPLATFORM_BITS);
+
+ return RUNTIME_INFO(i915)->platform_mask & (BIT(pbit) | BIT(s));
}

#define IS_I830(dev_priv) IS_PLATFORM(dev_priv, INTEL_I830)

drivers/gpu/drm/i915/intel_device_info.c +0 -0
index b8a7e17cb443..1cdd25486c04 100644
@@ -709,80 +709,76 @@ static u32 read_timestamp_frequency(struct drm_i915_private *dev_priv)
 

void intel_device_info_subplatform_init(struct drm_i915_private *i915) {
- const unsigned int pbits =
- BITS_PER_TYPE(RUNTIME_INFO(i915)->platform_mask[0]) -
- INTEL_SUBPLATFORM_BITS;
- const unsigned int pi = INTEL_INFO(i915)->platform / pbits;
- const unsigned int pb =
- INTEL_INFO(i915)->platform % pbits + INTEL_SUBPLATFORM_BITS;
- struct intel_runtime_info *info = RUNTIME_INFO(i915);
+ struct intel_runtime_info *rinfo = RUNTIME_INFO(i915);
+ const unsigned int pbit = INTEL_INFO(i915)->platform

+		+ INTEL_SUBPLATFORM_BITS;
	u16 devid = INTEL_DEVID(i915);

- BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
- pbits * ARRAY_SIZE(RUNTIME_INFO(i915)->platform_mask));
+ BUILD_BUG_ON(INTEL_MAX_PLATFORMS - INTEL_SUBPLATFORM_BITS >
+ BITS_PER_TYPE(rinfo->platform_mask));

- info->platform_mask[pi] = BIT(pb);
+ rinfo->platform_mask = BIT_ULL(pbit);

	if (IS_PINEVIEW(i915)) {
		if (devid == 0xa001)
-			info->platform_mask[pi] |=
+			rinfo->platform_mask |=
				BIT(INTEL_SUBPLATFORM_PINEVIEW_G);
		else if (devid == 0xa011)
-			info->platform_mask[pi] |=
+			rinfo->platform_mask |=
				BIT(INTEL_SUBPLATFORM_PINEVIEW_M);
	} else if (IS_IRONLAKE(i915)) {
		if (devid == 0x0046)
-			info->platform_mask[pi] |=
+			rinfo->platform_mask |=
				BIT(INTEL_SUBPLATFORM_IRONLAKE_M);
	} else if (IS_HASWELL(i915)) {
		if ((devid & 0xFF00) == 0x0A00)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_ULT);
		/* ULX machines are also considered ULT. */
		if (devid == 0x0A0E || devid == 0x0A1E)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_ULX);
	} else if (IS_BROADWELL(i915)) {
		if ((devid & 0xf) == 0x6 ||
		    (devid & 0xf) == 0xb ||
		    (devid & 0xf) == 0xe)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_ULT);
		/* ULX machines are also considered ULT. */
		if ((devid & 0xf) == 0xe)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_ULX);
	} else if (IS_SKYLAKE(i915)) {
		if (devid == 0x1906 ||
		    devid == 0x1913 ||
		    devid == 0x1916 ||
		    devid == 0x1921 ||
		    devid == 0x1926)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_ULT);
		else if (devid == 0x190E ||
			 devid == 0x1915 ||
			 devid == 0x191E)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_ULX);
	} else if (IS_KABYLAKE(i915)) {
		if (devid == 0x5906 ||
		    devid == 0x5913 ||
		    devid == 0x5916 ||
		    devid == 0x5921 ||
		    devid  == 0x5926)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_ULT);
		else if (devid == 0x590E ||
			 devid == 0x5915 ||
			 devid == 0x591E)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULX);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_ULX);
		else if (devid == 0x591C ||
			 devid == 0x87C0)
-			info->platform_mask[pi] |=
+			rinfo->platform_mask |=
				BIT(INTEL_SUBPLATFORM_AML_ULX);
	} else if (IS_COFFEELAKE(i915)) {
		if ((devid & 0x00F0) == 0x00A0)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_ULT);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_ULT);
	} else if (IS_CANNONLAKE(i915)) {
		if ((devid & 0x0004) == 0x0004)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_PORTF);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_PORTF);
	} else if (IS_ICELAKE(i915)) {
		if (devid != 0x8A51)
-			info->platform_mask[pi] |= BIT(INTEL_SUBPLATFORM_PORTF);
+			rinfo->platform_mask |= BIT(INTEL_SUBPLATFORM_PORTF);
	}
}
drivers/gpu/drm/i915/intel_device_info.h +0 -0
index b03fbd2e451a..12ff04a25b51 100644
@@ -212,7 +212,7 @@ struct intel_device_info {

};

struct intel_runtime_info {
- u32 platform_mask[1];
+ u64 platform_mask;

	u16 device_id;

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#14 lore raw
Quoted 63 lines · Lucas De Marchi
Quoted 62 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>

---

drivers/gpu/drm/i915/i915_drv.c          |   7 +-
drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
drivers/gpu/drm/i915/i915_pci.c          |   2 +-
drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +2 -0
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct 
 drm_i915_private *dev_priv)
     if (i915_inject_load_failure())
         return -ENODEV;
 
+    intel_device_info_subplatform_init(dev_priv);
+
     spin_lock_init(&dev_priv->irq_lock);
     spin_lock_init(&dev_priv->gpu_error.lock);

    mutex_init(&dev_priv->backlight_lock);

drivers/gpu/drm/i915/i915_drv.c +0 -0
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct 
 drm_i915_private *dev_priv)
     if (drm_debug & DRM_UT_DRIVER) {
         struct drm_printer p = drm_debug_printer("i915 device info:");
 
Quoted 11 lines

drivers/gpu/drm/i915/i915_drv.c static void i915_welcome_messages(struct · line 1764

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.c +2 -1
-        drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+        drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) 
 gen=%i\n",
                INTEL_DEVID(dev_priv),
                INTEL_REVID(dev_priv),
                intel_platform_name(INTEL_INFO(dev_priv)->platform),
+               
 RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],

bug here, INTEL_SUBPLATFORM_BITS should be outside of []. Bad things will happen for platform=32 /o\

? [32 / (32 - 3)] = [1], for which there is a BUILD_BUG_ON with a comment saying to increase size of array.

Quoted 45 lines
Quoted 26 lines

               INTEL_GEN(dev_priv));

        intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);

drivers/gpu/drm/i915/i915_drv.c +0 -2
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const 
 struct pci_device_id *ent)
     memcpy(device_info, match_info, sizeof(*device_info));
     RUNTIME_INFO(i915)->device_id = pdev->device;
 
-    BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-             BITS_PER_TYPE(device_info->platform_mask));
     BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 

    return i915;

drivers/gpu/drm/i915/i915_drv.h +1 -1
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int 
 i915_sg_segment_size(void)
 #define IS_REVID(p, since, until) \
     (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) (INTEL_INFO(dev_priv)->platform_mask 
 & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int · line 2296

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +10 -0
+({ \
+    const unsigned int pbits__ = \
+        BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+        INTEL_SUBPLATFORM_BITS; \
+    const unsigned int pi__ = (p) / pbits__; \
+    const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+    BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+    (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \

Ugh. That double dword fiddling is way too ugly. IMO it is not buying us anything. Just use a u64 rather than the double dword. Your approach may have a small benefit on ARCH=i386, but has the burden of carrying all this forward.  The diff below (only build-tested) is on top of yours, which is basically equivalent to "move to u64 and then add the subplatform part".

Quoted 3 lines

  text    data     bss     dec     hex filename
1834620   40454    4176 1879250  1cacd2 drivers/gpu/drm/i915/i915.o.yours 1834710   40454    4176 1879340  1cad2c drivers/gpu/drm/i915/i915.o

The cost of going u64 would be higher than what you saw if bits above were actually used I think. But would have to check the output to be sure. It was at least a year ago I think I last played with this.

Benefit of the u32 array approach is that it avoids that even on 64-bit builds.

As it stands v5 of my patch has minimal positive effect on code size (sub 1k). Maybe a bit better in non-debug builds. But the main point is about the devid checking consolidation.

It is of course open to discussion.

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#15 lore raw
Quoted 77 lines · Tvrtko Ursulin
Quoted 63 lines · Lucas De Marchi
Quoted 62 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>

---

drivers/gpu/drm/i915/i915_drv.c          |   7 +-
drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
drivers/gpu/drm/i915/i915_pci.c          |   2 +-
drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +2 -0
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct 
 drm_i915_private *dev_priv)
     if (i915_inject_load_failure())
         return -ENODEV;
 
+    intel_device_info_subplatform_init(dev_priv);
+
     spin_lock_init(&dev_priv->irq_lock);
     spin_lock_init(&dev_priv->gpu_error.lock);

    mutex_init(&dev_priv->backlight_lock);

drivers/gpu/drm/i915/i915_drv.c +0 -0
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct 
 drm_i915_private *dev_priv)
     if (drm_debug & DRM_UT_DRIVER) {
         struct drm_printer p = drm_debug_printer("i915 device info:");
 
Quoted 11 lines

drivers/gpu/drm/i915/i915_drv.c static void i915_welcome_messages(struct · line 1764

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.c +2 -1
-        drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+        drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) 
 gen=%i\n",
                INTEL_DEVID(dev_priv),
                INTEL_REVID(dev_priv),
                intel_platform_name(INTEL_INFO(dev_priv)->platform),
+               
 RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],

bug here, INTEL_SUBPLATFORM_BITS should be outside of []. Bad things will happen for platform=32 /o\

Quoted 1 line

? [32 / (32 - 3)] = [1], for which there is a BUILD_BUG_ON with a comment saying to increase size of array.

I think I missed a "(" and thought that would be (32 / 32) - 3

anyway, you are printing confusing information here since you only print one u32.

Quoted 46 lines
Quoted 46 lines
Quoted 27 lines

               INTEL_GEN(dev_priv));

        intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);

drivers/gpu/drm/i915/i915_drv.c +0 -2
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, 
 const struct pci_device_id *ent)
     memcpy(device_info, match_info, sizeof(*device_info));
     RUNTIME_INFO(i915)->device_id = pdev->device;
 
-    BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-             BITS_PER_TYPE(device_info->platform_mask));
     BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 

    return i915;

drivers/gpu/drm/i915/i915_drv.h +1 -1
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int 
 i915_sg_segment_size(void)
 #define IS_REVID(p, since, until) \
     (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) 
 (INTEL_INFO(dev_priv)->platform_mask & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int · line 2296

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +10 -0
+({ \
+    const unsigned int pbits__ = \
+        BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+        INTEL_SUBPLATFORM_BITS; \
+    const unsigned int pi__ = (p) / pbits__; \
+    const unsigned int pb__ = (p) % pbits__ + INTEL_SUBPLATFORM_BITS; \
+\
+    BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+    (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \

Ugh. That double dword fiddling is way too ugly. IMO it is not buying us anything. Just use a u64 rather than the double dword. Your approach may have a small benefit on ARCH=i386, but has the burden of carrying all this forward.  The diff below (only build-tested) is on top of yours, which is basically equivalent to "move to u64 and then add the subplatform part".

Quoted 5 lines
Quoted 3 lines

  text    data     bss     dec     hex filename
1834620   40454    4176 1879250  1cacd2 drivers/gpu/drm/i915/i915.o.yours 1834710   40454    4176 1879340  1cad2c drivers/gpu/drm/i915/i915.o

The cost of going u64 would be higher than what you saw if bits above were actually used I think. But would have to check the output to be sure. It was at least a year ago I think I last played with this.

I challenge that. My butt feeling here is pretty strong that's not true.

Quoted 1 line

Benefit of the u32 array approach is that it avoids that even on 64-bit builds.

my point is on 64-bit builds... It may suffer a little on m32.

Lucas De Marchi

Quoted 7 lines

As it stands v5 of my patch has minimal positive effect on code size (sub 1k). Maybe a bit better in non-debug builds. But the main point is about the devid checking consolidation.

It is of course open to discussion.

Regards,

Tvrtko

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#16 lore raw
Quoted 78 lines · Lucas De Marchi
Quoted 77 lines · Tvrtko Ursulin
Quoted 74 lines · Lucas De Marchi
Quoted 60 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>

---

drivers/gpu/drm/i915/i915_drv.c          |   7 +-
drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
drivers/gpu/drm/i915/i915_pci.c          |   2 +-
drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +2 -0
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct 
 drm_i915_private *dev_priv)
     if (i915_inject_load_failure())
         return -ENODEV;
 
+    intel_device_info_subplatform_init(dev_priv);
+
     spin_lock_init(&dev_priv->irq_lock);
     spin_lock_init(&dev_priv->gpu_error.lock);

    mutex_init(&dev_priv->backlight_lock);

drivers/gpu/drm/i915/i915_drv.c +0 -0
@@ -1752,10 +1754,11 @@ static void i915_welcome_messages(struct 
 drm_i915_private *dev_priv)
     if (drm_debug & DRM_UT_DRIVER) {

drivers/gpu/drm/i915/i915_drv.c static void i915_welcome_messages(struct · line 1764

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.c +2 -1
         struct drm_printer p = drm_debug_printer("i915 device info:");
 
-        drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+        drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (%x) 
 gen=%i\n",
                INTEL_DEVID(dev_priv),
                INTEL_REVID(dev_priv),
                intel_platform_name(INTEL_INFO(dev_priv)->platform),
+ 
 RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],

bug here, INTEL_SUBPLATFORM_BITS should be outside of []. Bad things will happen for platform=32 /o\

Quoted 6 lines
Quoted 1 line

? [32 / (32 - 3)] = [1], for which there is a BUILD_BUG_ON with a comment saying to increase size of array.

I think I missed a "(" and thought that would be (32 / 32) - 3

anyway, you are printing confusing information here since you only print one u32.

Confusing how and what is the second u32? You mean when array gets expanded in the future? Here the actual idea (see next version) is to only print the subplatform bits.

Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 28 lines

               INTEL_GEN(dev_priv));

        intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);

drivers/gpu/drm/i915/i915_drv.c +0 -2
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, const 
 struct pci_device_id *ent)
     memcpy(device_info, match_info, sizeof(*device_info));
     RUNTIME_INFO(i915)->device_id = pdev->device;
 
-    BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-             BITS_PER_TYPE(device_info->platform_mask));
     BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 

    return i915;

drivers/gpu/drm/i915/i915_drv.h +2 -1
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int 
 i915_sg_segment_size(void)
 #define IS_REVID(p, since, until) \
     (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) 
 (INTEL_INFO(dev_priv)->platform_mask & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \
+({ \

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int · line 2297

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +9 -0
+    const unsigned int pbits__ = \
+        BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+        INTEL_SUBPLATFORM_BITS; \
+    const unsigned int pi__ = (p) / pbits__; \
+    const unsigned int pb__ = (p) % pbits__ + 
 INTEL_SUBPLATFORM_BITS; \
+\
+    BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+    (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \

Ugh. That double dword fiddling is way too ugly. IMO it is not buying us anything. Just use a u64 rather than the double dword. Your approach may have a small benefit on ARCH=i386, but has the burden of carrying all this forward.  The diff below (only build-tested) is on top of yours, which is basically equivalent to "move to u64 and then add the subplatform part".

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

  text    data     bss     dec     hex filename
1834620   40454    4176 1879250  1cacd2 drivers/gpu/drm/i915/i915.o.yours 1834710   40454    4176 1879340  1cad2c drivers/gpu/drm/i915/i915.o

The cost of going u64 would be higher than what you saw if bits above were actually used I think. But would have to check the output to be sure. It was at least a year ago I think I last played with this.

I challenge that. My butt feeling here is pretty strong that's not true.

I hope you meant gut feeling. Anyways, I said I wasn't 100% sure of the details, right? Having exercised my memory lanes I think the biggest negative effect of the move to u64 was in conjunction with this subplatform idea. This is due the "if (mask & platform) && (mask & subplatform)" expanding to 2 u64 constants per check. I have a remedy for that, but lets not get bogged down and code size which is not the main consideration here. Idea was to consolidate and simplify whilst preserving the two beneficial effects which I already explain.

Quoted 3 lines
Quoted 1 line

Benefit of the u32 array approach is that it avoids that even on 64-bit builds.

my point is on 64-bit builds... It may suffer a little on m32.

Which is why I hinted the u32 array approach does not suffer on either. No increase on 64-bit, no real increase on 32-bit.

Regards,

Tvrtko

Quoted 11 lines

Lucas De Marchi

Quoted 7 lines

As it stands v5 of my patch has minimal positive effect on code size (sub 1k). Maybe a bit better in non-debug builds. But the main point is about the devid checking consolidation.

It is of course open to discussion.

Regards,

Tvrtko

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#17 lore raw
Quoted 80 lines · Tvrtko Ursulin
Quoted 78 lines · Lucas De Marchi
Quoted 77 lines · Tvrtko Ursulin
Quoted 74 lines · Lucas De Marchi
Quoted 60 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Concept of a sub-platform already exist in our code (like ULX and ULT platform variants and similar),implemented via the macros which check a list of device ids to determine a match.

With this patch we consolidate device ids checking into a single function called during early driver load.

A few low bits in the platform mask are reserved for sub-platform identification and defined as a per-platform namespace.

At the same time it future proofs the platform_mask handling by preparing the code for easy extending, and tidies the very verbose WARN strings generated when IS_PLATFORM macros are embedded into a WARN type statements.

The approach is also beneficial to driver size, with an combined shrink of code and strings of around 1.7 kiB.

v2: Fixed IS_SUBPLATFORM. Updated commit msg.
v3: Chris was right, there is an ordering problem.

v4:
* Catch-up with new sub-platforms.
* Rebase for RUNTIME_INFO.
* Drop subplatform mask union tricks and convert platform_mask to an array for extensibility.

Cc Chris Wilson <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Lucas De Marchi <[email protected]>
Cc Jose Souza <[email protected]>

---

drivers/gpu/drm/i915/i915_drv.c          |   7 +-
drivers/gpu/drm/i915/i915_drv.h          | 110 +++++++++++++++--------
drivers/gpu/drm/i915/i915_pci.c          |   2 +-
drivers/gpu/drm/i915/intel_device_info.c |  79 ++++++++++++++++
drivers/gpu/drm/i915/intel_device_info.h |  28 +++++-
5 files changed, 179 insertions(+), 47 deletions(-)
drivers/gpu/drm/i915/i915_drv.c +2 -0
index 0d743907e7bc..3218350cd225 100644
@@ -863,6 +863,8 @@ static int i915_driver_init_early(struct 
 drm_i915_private *dev_priv)
     if (i915_inject_load_failure())
         return -ENODEV;
 
+    intel_device_info_subplatform_init(dev_priv);
+
     spin_lock_init(&dev_priv->irq_lock);
     spin_lock_init(&dev_priv->gpu_error.lock);

    mutex_init(&dev_priv->backlight_lock);

drivers/gpu/drm/i915/i915_drv.c +0 -0
@@ -1752,10 +1754,11 @@ static void 
 i915_welcome_messages(struct drm_i915_private *dev_priv)
     if (drm_debug & DRM_UT_DRIVER) {

drivers/gpu/drm/i915/i915_drv.c static void · line 1764

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.c +2 -1
         struct drm_printer p = drm_debug_printer("i915 device info:");
 
-        drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s gen=%i\n",
+        drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s 
 (%x) gen=%i\n",
                INTEL_DEVID(dev_priv),
                INTEL_REVID(dev_priv),
                intel_platform_name(INTEL_INFO(dev_priv)->platform),
+ RUNTIME_INFO(dev_priv)->platform_mask[INTEL_INFO(dev_priv)->platform 
 / (BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - INTEL_SUBPLATFORM_BITS)],

bug here, INTEL_SUBPLATFORM_BITS should be outside of []. Bad things will happen for platform=32 /o\

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

? [32 / (32 - 3)] = [1], for which there is a BUILD_BUG_ON with a comment saying to increase size of array.

I think I missed a "(" and thought that would be (32 / 32) - 3

anyway, you are printing confusing information here since you only print one u32.

Confusing how and what is the second u32? You mean when array gets

because you are printing here only one u32 and hence this number could be more than one platform.

Quoted 1 line

expanded in the future? Here the actual idea (see next version) is to only print the subplatform bits.

yep, much better there.

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 51 lines
Quoted 29 lines

               INTEL_GEN(dev_priv));

        intel_device_info_dump_flags(INTEL_INFO(dev_priv), &p);

drivers/gpu/drm/i915/i915_drv.c +0 -2
@@ -1798,8 +1801,6 @@ i915_driver_create(struct pci_dev *pdev, 
 const struct pci_device_id *ent)
     memcpy(device_info, match_info, sizeof(*device_info));
     RUNTIME_INFO(i915)->device_id = pdev->device;
 
-    BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
-             BITS_PER_TYPE(device_info->platform_mask));
     BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
 

    return i915;

drivers/gpu/drm/i915/i915_drv.h +2 -1
index dccb6006aabf..34282cf66cb0 100644
@@ -2281,7 +2281,46 @@ static inline unsigned int 
 i915_sg_segment_size(void)
 #define IS_REVID(p, since, until) \
     (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
 
-#define IS_PLATFORM(dev_priv, p) 
 (INTEL_INFO(dev_priv)->platform_mask & BIT(p))
+#define __IS_PLATFORM(dev_priv, p) \
+({ \

drivers/gpu/drm/i915/i915_drv.h static inline unsigned int · line 2297

Quoted 10 lines
drivers/gpu/drm/i915/i915_drv.h +9 -0
+    const unsigned int pbits__ = \
+        BITS_PER_TYPE(RUNTIME_INFO(dev_priv)->platform_mask[0]) - \
+        INTEL_SUBPLATFORM_BITS; \
+    const unsigned int pi__ = (p) / pbits__; \
+    const unsigned int pb__ = (p) % pbits__ + 
 INTEL_SUBPLATFORM_BITS; \
+\
+    BUILD_BUG_ON(!__builtin_constant_p(p)); \
+\
+    (RUNTIME_INFO(dev_priv)->platform_mask[pi__] & BIT(pb__)); \

Ugh. That double dword fiddling is way too ugly. IMO it is not buying us anything. Just use a u64 rather than the double dword. Your approach may have a small benefit on ARCH=i386, but has the burden of carrying all this forward.  The diff below (only build-tested) is on top of yours, which is basically equivalent to "move to u64 and then add the subplatform part".

  text    data     bss     dec     hex filename
1834620   40454    4176 1879250  1cacd2 drivers/gpu/drm/i915/i915.o.yours 1834710   40454    4176 1879340  1cad2c drivers/gpu/drm/i915/i915.o

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

The cost of going u64 would be higher than what you saw if bits above were actually used I think. But would have to check the output to be sure. It was at least a year ago I think I last played with this.

I challenge that. My butt feeling here is pretty strong that's not true.

I hope you meant gut feeling. Anyways, I said I wasn't 100% sure of

yep, of course :-/

Quoted 7 lines

the details, right? Having exercised my memory lanes I think the biggest negative effect of the move to u64 was in conjunction with this subplatform idea. This is due the "if (mask & platform) && (mask & subplatform)" expanding to 2 u64 constants per check. I have a remedy for that, but lets not get bogged down and code size which is not the main consideration here. Idea was to consolidate and simplify whilst preserving the two beneficial effects which I already explain.

Quoted 3 lines
Quoted 1 line

Benefit of the u32 array approach is that it avoids that even on 64-bit builds.

my point is on 64-bit builds... It may suffer a little on m32.

Which is why I hinted the u32 array approach does not suffer on either. No increase on 64-bit, no real increase on 32-bit.

I actually think the main advantage of multiple dwords is to be ready for the next bump when it arrives. So ok. I still don't like open coded bitmask though.

Lucas De Marchi

Quoted 16 lines

Regards,

Tvrtko

Quoted 11 lines

Lucas De Marchi

Quoted 7 lines

As it stands v5 of my patch has minimal positive effect on code size (sub 1k). Maybe a bit better in non-debug builds. But the main point is about the devid checking consolidation.

It is of course open to discussion.

Regards,

Tvrtko

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#18 lore raw

✗ Fi.CI.BAT: failure for drm/i915: Introduce concept of a sub-platform (rev3)

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: drm/i915: Introduce concept of a sub-platform (rev3)
URL : https://patchwork.freedesktop.org/series/58056/
State : failure

== Summary ==

Applying: drm/i915: Introduce concept of a sub-platform
error: corrupt patch at line 199
error: could not build fake ancestor
hint: Use 'git am --show-current-patch' to see the failed patch Patch failed at 0001 drm/i915: Introduce concept of a sub-platform When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx