Skip to contentSkip to conversation

drm/i915/registers: use standard bits.h and bitfield.h macros

RFC In review Jani Nikula 6 participants 15 messages Sep 27, 2018 – Sep 28, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover drm/i915/registers: use standard bits.h and bitfield.h macros

This is an RFC to get input on how people feel about moving towards using <linux/bits.h> and <linux/bitfield.h> macros for register field definitions and manipulation:

* BIT()
* GENMASK()
* FIELD_GET()
* FIELD_PREP()

I'm not necessarily proposing pushing the patches in this series; they're more of a piece-by-piece transformation of the power sequencer macros and code to use the above macros, to give an idea what the end result would look like.

I'm also not proposing mass conversions that are error prone and cause unnecessary conflicts. At least not outside of i915_reg.h.

I'd like to figure out the *direction* where we'd like to go with what we're adding in the future.

BR,
Jani.

Jani Nikula (4):
drm/i915/registers: prefer GENMASK() over hand rolled masks drm/i915/registers: prefer BIT() for single bits drm/i915/registers: deprecate _SHIFT in favor of FIELD_GET() and _MASK drm/i915/registers: define field values using FIELD_PREP()

 drivers/gpu/drm/i915/i915_reg.h   | 82 +++++++++++++++++----------------------
 drivers/gpu/drm/i915/intel_dp.c   | 43 +++++++++-----------
 drivers/gpu/drm/i915/intel_lvds.c | 41 +++++++++-----------
 3 files changed, 73 insertions(+), 93 deletions(-)
Signature · 6 lines
2.11.0

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

RFC 1/4 drm/i915/registers: prefer GENMASK() over hand rolled masks

GENMASK() is much easier to get right and review against the specs than hand rolled masks.

---
 drivers/gpu/drm/i915/i915_reg.h | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +11 -11
index 27e650fe591b..25efce1eded7 100644
@@ -4621,13 +4621,13 @@ enum {
  * - LVDS/DVOB/DVOC on
  */
 #define   PP_READY			(1 << 30)
+#define   PP_SEQUENCE_MASK		GENMASK(29, 28)
 #define   PP_SEQUENCE_NONE		(0 << 28)
 #define   PP_SEQUENCE_POWER_UP		(1 << 28)
 #define   PP_SEQUENCE_POWER_DOWN	(2 << 28)
-#define   PP_SEQUENCE_MASK		(3 << 28)
 #define   PP_SEQUENCE_SHIFT		28
 #define   PP_CYCLE_DELAY_ACTIVE		(1 << 27)
-#define   PP_SEQUENCE_STATE_MASK	0x0000000f
+#define   PP_SEQUENCE_STATE_MASK	GENMASK(3, 0)
 #define   PP_SEQUENCE_STATE_OFF_IDLE	(0x0 << 0)
 #define   PP_SEQUENCE_STATE_OFF_S0_1	(0x1 << 0)
 #define   PP_SEQUENCE_STATE_OFF_S0_2	(0x2 << 0)
@@ -4640,9 +4640,9 @@ enum {
 
 #define _PP_CONTROL			0x61204
 #define PP_CONTROL(pps_idx)		_MMIO_PPS(pps_idx, _PP_CONTROL)
+#define  PANEL_UNLOCK_MASK		GENMASK(31, 16)
 #define  PANEL_UNLOCK_REGS		(0xabcd << 16)
-#define  PANEL_UNLOCK_MASK		(0xffff << 16)
-#define  BXT_POWER_CYCLE_DELAY_MASK	0x1f0
+#define  BXT_POWER_CYCLE_DELAY_MASK	GENMASK(8, 4)
 #define  BXT_POWER_CYCLE_DELAY_SHIFT	4
 #define  EDP_FORCE_VDD			(1 << 3)
 #define  EDP_BLC_ENABLE			(1 << 2)
@@ -4653,29 +4653,29 @@ enum {
 #define _PP_ON_DELAYS			0x61208
 #define PP_ON_DELAYS(pps_idx)		_MMIO_PPS(pps_idx, _PP_ON_DELAYS)
 #define  PANEL_PORT_SELECT_SHIFT	30
-#define  PANEL_PORT_SELECT_MASK		(3 << 30)
+#define  PANEL_PORT_SELECT_MASK		GENMASK(31, 30)
 #define  PANEL_PORT_SELECT_LVDS		(0 << 30)
 #define  PANEL_PORT_SELECT_DPA		(1 << 30)
 #define  PANEL_PORT_SELECT_DPC		(2 << 30)
 #define  PANEL_PORT_SELECT_DPD		(3 << 30)
 #define  PANEL_PORT_SELECT_VLV(port)	((port) << 30)
-#define  PANEL_POWER_UP_DELAY_MASK	0x1fff0000
+#define  PANEL_POWER_UP_DELAY_MASK	GENMASK(28, 16)
 #define  PANEL_POWER_UP_DELAY_SHIFT	16
-#define  PANEL_LIGHT_ON_DELAY_MASK	0x1fff
+#define  PANEL_LIGHT_ON_DELAY_MASK	GENMASK(12, 0)
 #define  PANEL_LIGHT_ON_DELAY_SHIFT	0
 
 #define _PP_OFF_DELAYS			0x6120C
 #define PP_OFF_DELAYS(pps_idx)		_MMIO_PPS(pps_idx, _PP_OFF_DELAYS)
-#define  PANEL_POWER_DOWN_DELAY_MASK	0x1fff0000
+#define  PANEL_POWER_DOWN_DELAY_MASK	GENMASK(28, 16)
 #define  PANEL_POWER_DOWN_DELAY_SHIFT	16
-#define  PANEL_LIGHT_OFF_DELAY_MASK	0x1fff
+#define  PANEL_LIGHT_OFF_DELAY_MASK	GENMASK(12, 0)
 #define  PANEL_LIGHT_OFF_DELAY_SHIFT	0
 
 #define _PP_DIVISOR			0x61210
 #define PP_DIVISOR(pps_idx)		_MMIO_PPS(pps_idx, _PP_DIVISOR)
-#define  PP_REFERENCE_DIVIDER_MASK	0xffffff00
+#define  PP_REFERENCE_DIVIDER_MASK	GENMASK(31, 8)
 #define  PP_REFERENCE_DIVIDER_SHIFT	8
-#define  PANEL_POWER_CYCLE_DELAY_MASK	0x1f
+#define  PANEL_POWER_CYCLE_DELAY_MASK	GENMASK(4, 0)
 #define  PANEL_POWER_CYCLE_DELAY_SHIFT	0
 
 /* Panel fitting */
Signature · 6 lines
2.11.0

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

RFC 2/4 drm/i915/registers: prefer BIT() for single bits

In reply to Jani Nikula

BIT() is the preferred way of defining bits in the kernel.

---
 drivers/gpu/drm/i915/i915_reg.h | 15 +++++++--------
 drivers/gpu/drm/i915/intel_dp.c |  2 +-
 2 files changed, 8 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +7 -8
index 25efce1eded7..893628c86a8d 100644
@@ -4612,7 +4612,7 @@ enum {
 
 #define _PP_STATUS			0x61200
 #define PP_STATUS(pps_idx)		_MMIO_PPS(pps_idx, _PP_STATUS)
-#define   PP_ON				(1 << 31)
+#define   PP_ON				BIT(31)
 /*
  * Indicates that all dependencies of the panel are on:
  *
@@ -4620,13 +4620,13 @@ enum {
  * - pipe enabled
  * - LVDS/DVOB/DVOC on
  */
-#define   PP_READY			(1 << 30)
+#define   PP_READY			BIT(30)
 #define   PP_SEQUENCE_MASK		GENMASK(29, 28)
 #define   PP_SEQUENCE_NONE		(0 << 28)
 #define   PP_SEQUENCE_POWER_UP		(1 << 28)
 #define   PP_SEQUENCE_POWER_DOWN	(2 << 28)
 #define   PP_SEQUENCE_SHIFT		28
-#define   PP_CYCLE_DELAY_ACTIVE		(1 << 27)
+#define   PP_CYCLE_DELAY_ACTIVE		BIT(27)
 #define   PP_SEQUENCE_STATE_MASK	GENMASK(3, 0)
 #define   PP_SEQUENCE_STATE_OFF_IDLE	(0x0 << 0)
 #define   PP_SEQUENCE_STATE_OFF_S0_1	(0x1 << 0)
@@ -4644,11 +4644,10 @@ enum {
 #define  PANEL_UNLOCK_REGS		(0xabcd << 16)
 #define  BXT_POWER_CYCLE_DELAY_MASK	GENMASK(8, 4)
 #define  BXT_POWER_CYCLE_DELAY_SHIFT	4
-#define  EDP_FORCE_VDD			(1 << 3)
-#define  EDP_BLC_ENABLE			(1 << 2)
-#define  PANEL_POWER_RESET		(1 << 1)
-#define  PANEL_POWER_OFF		(0 << 0)
-#define  PANEL_POWER_ON			(1 << 0)
+#define  EDP_FORCE_VDD			BIT(3)
+#define  EDP_BLC_ENABLE			BIT(2)
+#define  PANEL_POWER_RESET		BIT(1)
+#define  PANEL_POWER_ON			BIT(0)
 
 #define _PP_ON_DELAYS			0x61208
 #define PP_ON_DELAYS(pps_idx)		_MMIO_PPS(pps_idx, _PP_ON_DELAYS)
drivers/gpu/drm/i915/intel_dp.c +1 -1
index 6b4c19123f2a..ed06876457b7 100644
@@ -1040,7 +1040,7 @@ static int edp_notify_handler(struct notifier_block *this, unsigned long code,
 
 		/* 0x1F write to PP_DIV_REG sets max cycle delay */
 		I915_WRITE(pp_div_reg, pp_div | 0x1F);
-		I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
+		I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS);
 		msleep(intel_dp->panel_power_cycle_delay);
 	}
 
Signature · 6 lines
2.11.0

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

RFC 3/4 drm/i915/registers: deprecate _SHIFT in favor of FIELD_GET() and _MASK

In reply to Jani Nikula

bitfield.h defines FIELD_GET() and FIELD_PREP() macros to access bitfields using the mask alone, with no need for separate shift. Indeed, the shift is redundant.

For the most part, FIELD_GET() is shorter than masking followed by shift, and arguably has more clarity.

FIELD_PREP() can get more verbose than simply shifting in place, but it does provide masking to ensure we don't overflow the mask, something we usually don't bother with currently. For build time constants there's a build error for this.

---
 drivers/gpu/drm/i915/i915_reg.h   |  9 ---------
 drivers/gpu/drm/i915/intel_dp.c   | 41 ++++++++++++++++-----------------------
 drivers/gpu/drm/i915/intel_lvds.c | 41 ++++++++++++++++++---------------------
 3 files changed, 36 insertions(+), 55 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +0 -9
index 893628c86a8d..52aa007c54c5 100644
@@ -4625,7 +4625,6 @@ enum {
 #define   PP_SEQUENCE_NONE		(0 << 28)
 #define   PP_SEQUENCE_POWER_UP		(1 << 28)
 #define   PP_SEQUENCE_POWER_DOWN	(2 << 28)
-#define   PP_SEQUENCE_SHIFT		28
 #define   PP_CYCLE_DELAY_ACTIVE		BIT(27)
 #define   PP_SEQUENCE_STATE_MASK	GENMASK(3, 0)
 #define   PP_SEQUENCE_STATE_OFF_IDLE	(0x0 << 0)
@@ -4643,7 +4642,6 @@ enum {
 #define  PANEL_UNLOCK_MASK		GENMASK(31, 16)
 #define  PANEL_UNLOCK_REGS		(0xabcd << 16)
 #define  BXT_POWER_CYCLE_DELAY_MASK	GENMASK(8, 4)
-#define  BXT_POWER_CYCLE_DELAY_SHIFT	4
 #define  EDP_FORCE_VDD			BIT(3)
 #define  EDP_BLC_ENABLE			BIT(2)
 #define  PANEL_POWER_RESET		BIT(1)
@@ -4651,7 +4649,6 @@ enum {
 
 #define _PP_ON_DELAYS			0x61208
 #define PP_ON_DELAYS(pps_idx)		_MMIO_PPS(pps_idx, _PP_ON_DELAYS)
-#define  PANEL_PORT_SELECT_SHIFT	30
 #define  PANEL_PORT_SELECT_MASK		GENMASK(31, 30)
 #define  PANEL_PORT_SELECT_LVDS		(0 << 30)
 #define  PANEL_PORT_SELECT_DPA		(1 << 30)
@@ -4659,23 +4656,17 @@ enum {
 #define  PANEL_PORT_SELECT_DPD		(3 << 30)
 #define  PANEL_PORT_SELECT_VLV(port)	((port) << 30)
 #define  PANEL_POWER_UP_DELAY_MASK	GENMASK(28, 16)
-#define  PANEL_POWER_UP_DELAY_SHIFT	16
 #define  PANEL_LIGHT_ON_DELAY_MASK	GENMASK(12, 0)
-#define  PANEL_LIGHT_ON_DELAY_SHIFT	0
 
 #define _PP_OFF_DELAYS			0x6120C
 #define PP_OFF_DELAYS(pps_idx)		_MMIO_PPS(pps_idx, _PP_OFF_DELAYS)
 #define  PANEL_POWER_DOWN_DELAY_MASK	GENMASK(28, 16)
-#define  PANEL_POWER_DOWN_DELAY_SHIFT	16
 #define  PANEL_LIGHT_OFF_DELAY_MASK	GENMASK(12, 0)
-#define  PANEL_LIGHT_OFF_DELAY_SHIFT	0
 
 #define _PP_DIVISOR			0x61210
 #define PP_DIVISOR(pps_idx)		_MMIO_PPS(pps_idx, _PP_DIVISOR)
 #define  PP_REFERENCE_DIVIDER_MASK	GENMASK(31, 8)
-#define  PP_REFERENCE_DIVIDER_SHIFT	8
 #define  PANEL_POWER_CYCLE_DELAY_MASK	GENMASK(4, 0)
-#define  PANEL_POWER_CYCLE_DELAY_SHIFT	0
 
 /* Panel fitting */
 #define PFIT_CONTROL	_MMIO(dev_priv->info.display_mmio_offset + 0x61230)
drivers/gpu/drm/i915/intel_dp.c +17 -24

70 lines not on this page · raw message

drivers/gpu/drm/i915/intel_lvds.c +19 -22

64 lines not on this page · raw message

Signature · 6 lines
2.11.0

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

RFC 4/4 drm/i915/registers: define field values using FIELD_PREP()

In reply to Jani Nikula

Slightly verbose, but does away with hand rolled shifts and provides static checking that the values fit the mask.

---
 drivers/gpu/drm/i915/i915_reg.h | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +18 -18
index 52aa007c54c5..d1fc08038e54 100644
@@ -4622,25 +4622,25 @@ enum {
  */
 #define   PP_READY			BIT(30)
 #define   PP_SEQUENCE_MASK		GENMASK(29, 28)
-#define   PP_SEQUENCE_NONE		(0 << 28)
-#define   PP_SEQUENCE_POWER_UP		(1 << 28)
-#define   PP_SEQUENCE_POWER_DOWN	(2 << 28)
+#define   PP_SEQUENCE_NONE		FIELD_PREP(PP_SEQUENCE_MASK, 0)
+#define   PP_SEQUENCE_POWER_UP		FIELD_PREP(PP_SEQUENCE_MASK, 1)
+#define   PP_SEQUENCE_POWER_DOWN	FIELD_PREP(PP_SEQUENCE_MASK, 2)
 #define   PP_CYCLE_DELAY_ACTIVE		BIT(27)
 #define   PP_SEQUENCE_STATE_MASK	GENMASK(3, 0)
-#define   PP_SEQUENCE_STATE_OFF_IDLE	(0x0 << 0)
-#define   PP_SEQUENCE_STATE_OFF_S0_1	(0x1 << 0)
-#define   PP_SEQUENCE_STATE_OFF_S0_2	(0x2 << 0)
-#define   PP_SEQUENCE_STATE_OFF_S0_3	(0x3 << 0)
-#define   PP_SEQUENCE_STATE_ON_IDLE	(0x8 << 0)
-#define   PP_SEQUENCE_STATE_ON_S1_0	(0x9 << 0)
-#define   PP_SEQUENCE_STATE_ON_S1_2	(0xa << 0)
-#define   PP_SEQUENCE_STATE_ON_S1_3	(0xb << 0)
-#define   PP_SEQUENCE_STATE_RESET	(0xf << 0)
+#define   PP_SEQUENCE_STATE_OFF_IDLE	FIELD_PREP(PP_SEQUENCE_STATE_MASK, 0x0)
+#define   PP_SEQUENCE_STATE_OFF_S0_1	FIELD_PREP(PP_SEQUENCE_STATE_MASK, 0x1)
+#define   PP_SEQUENCE_STATE_OFF_S0_2	FIELD_PREP(PP_SEQUENCE_STATE_MASK, 0x2)
+#define   PP_SEQUENCE_STATE_OFF_S0_3	FIELD_PREP(PP_SEQUENCE_STATE_MASK, 0x3)
+#define   PP_SEQUENCE_STATE_ON_IDLE	FIELD_PREP(PP_SEQUENCE_STATE_MASK, 0x8)
+#define   PP_SEQUENCE_STATE_ON_S1_0	FIELD_PREP(PP_SEQUENCE_STATE_MASK, 0x9)
+#define   PP_SEQUENCE_STATE_ON_S1_2	FIELD_PREP(PP_SEQUENCE_STATE_MASK, 0xa)
+#define   PP_SEQUENCE_STATE_ON_S1_3	FIELD_PREP(PP_SEQUENCE_STATE_MASK, 0xb)
+#define   PP_SEQUENCE_STATE_RESET	FIELD_PREP(PP_SEQUENCE_STATE_MASK, 0xf)
 
 #define _PP_CONTROL			0x61204
 #define PP_CONTROL(pps_idx)		_MMIO_PPS(pps_idx, _PP_CONTROL)
 #define  PANEL_UNLOCK_MASK		GENMASK(31, 16)
-#define  PANEL_UNLOCK_REGS		(0xabcd << 16)
+#define  PANEL_UNLOCK_REGS		FIELD_PREP(PANEL_UNLOCK_MASK, 0xabcd)
 #define  BXT_POWER_CYCLE_DELAY_MASK	GENMASK(8, 4)
 #define  EDP_FORCE_VDD			BIT(3)
 #define  EDP_BLC_ENABLE			BIT(2)
@@ -4650,11 +4650,11 @@ enum {
 #define _PP_ON_DELAYS			0x61208
 #define PP_ON_DELAYS(pps_idx)		_MMIO_PPS(pps_idx, _PP_ON_DELAYS)
 #define  PANEL_PORT_SELECT_MASK		GENMASK(31, 30)
-#define  PANEL_PORT_SELECT_LVDS		(0 << 30)
-#define  PANEL_PORT_SELECT_DPA		(1 << 30)
-#define  PANEL_PORT_SELECT_DPC		(2 << 30)
-#define  PANEL_PORT_SELECT_DPD		(3 << 30)
-#define  PANEL_PORT_SELECT_VLV(port)	((port) << 30)
+#define  PANEL_PORT_SELECT_LVDS		FIELD_PREP(PANEL_PORT_SELECT_MASK, 0)
+#define  PANEL_PORT_SELECT_DPA		FIELD_PREP(PANEL_PORT_SELECT_MASK, 1)
+#define  PANEL_PORT_SELECT_DPC		FIELD_PREP(PANEL_PORT_SELECT_MASK, 2)
+#define  PANEL_PORT_SELECT_DPD		FIELD_PREP(PANEL_PORT_SELECT_MASK, 3)
+#define  PANEL_PORT_SELECT_VLV(port)	FIELD_PREP(PANEL_PORT_SELECT_MASK, port)
 #define  PANEL_POWER_UP_DELAY_MASK	GENMASK(28, 16)
 #define  PANEL_LIGHT_ON_DELAY_MASK	GENMASK(12, 0)
 
Signature · 6 lines
2.11.0

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

Re: [RFC 4/4] drm/i915/registers: define field values using FIELD_PREP()

Quoting Jani Nikula (2018-09-27 10:40:23)

Quoted 9 lines

Slightly verbose, but does away with hand rolled shifts and provides static checking that the values fit the mask.

---

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -4650,11 +4650,11 @@ enum {
 #define _PP_ON_DELAYS                  0x61208
 #define PP_ON_DELAYS(pps_idx)          _MMIO_PPS(pps_idx, _PP_ON_DELAYS)
 #define  PANEL_PORT_SELECT_MASK                GENMASK(31, 30)

drivers/gpu/drm/i915/i915_reg.h enum { · line 4657

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +5 -5
-#define  PANEL_PORT_SELECT_LVDS                (0 << 30)
-#define  PANEL_PORT_SELECT_DPA         (1 << 30)
-#define  PANEL_PORT_SELECT_DPC         (2 << 30)
-#define  PANEL_PORT_SELECT_DPD         (3 << 30)
-#define  PANEL_PORT_SELECT_VLV(port)   ((port) << 30)
+#define  PANEL_PORT_SELECT_LVDS                FIELD_PREP(PANEL_PORT_SELECT_MASK, 0)
+#define  PANEL_PORT_SELECT_DPA         FIELD_PREP(PANEL_PORT_SELECT_MASK, 1)
+#define  PANEL_PORT_SELECT_DPC         FIELD_PREP(PANEL_PORT_SELECT_MASK, 2)
+#define  PANEL_PORT_SELECT_DPD         FIELD_PREP(PANEL_PORT_SELECT_MASK, 3)
+#define  PANEL_PORT_SELECT_VLV(port)   FIELD_PREP(PANEL_PORT_SELECT_MASK, port)

Maybe verbose, but it reads far better as giving each field a distinct name ties together all the individual options.

Before seeing this I was sceptical about FIELD_PREP, no longer.

Under this construct we aren't using masks per se, but giving a name to a group of bits within the register (a field). So I think

#define PANEL_PORT_SELECT GENMASK(31, 30)
#define PANEL_PORT_SELECT_LVDS FIELD_PREP(PANEL_PORT_SELECT, 0)

is intuitive. Did you do a quick bloatometer to see if gcc code generation is affected?
-Chris
_______________________________________________
Intel-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

Re: [RFC 4/4] drm/i915/registers: define field values using FIELD_PREP()

Quoted 24 lines · Chris Wilson

Quoting Jani Nikula (2018-09-27 10:40:23)

Quoted 9 lines

Slightly verbose, but does away with hand rolled shifts and provides static checking that the values fit the mask.

---

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -4650,11 +4650,11 @@ enum {
 #define _PP_ON_DELAYS                  0x61208
 #define PP_ON_DELAYS(pps_idx)          _MMIO_PPS(pps_idx, _PP_ON_DELAYS)
 #define  PANEL_PORT_SELECT_MASK                GENMASK(31, 30)

drivers/gpu/drm/i915/i915_reg.h enum { · line 4657

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +5 -5
-#define  PANEL_PORT_SELECT_LVDS                (0 << 30)
-#define  PANEL_PORT_SELECT_DPA         (1 << 30)
-#define  PANEL_PORT_SELECT_DPC         (2 << 30)
-#define  PANEL_PORT_SELECT_DPD         (3 << 30)
-#define  PANEL_PORT_SELECT_VLV(port)   ((port) << 30)
+#define  PANEL_PORT_SELECT_LVDS                FIELD_PREP(PANEL_PORT_SELECT_MASK, 0)
+#define  PANEL_PORT_SELECT_DPA         FIELD_PREP(PANEL_PORT_SELECT_MASK, 1)
+#define  PANEL_PORT_SELECT_DPC         FIELD_PREP(PANEL_PORT_SELECT_MASK, 2)
+#define  PANEL_PORT_SELECT_DPD         FIELD_PREP(PANEL_PORT_SELECT_MASK, 3)
+#define  PANEL_PORT_SELECT_VLV(port)   FIELD_PREP(PANEL_PORT_SELECT_MASK, port)

Maybe verbose, but it reads far better as giving each field a distinct name ties together all the individual options.

Quoted 7 lines

Before seeing this I was sceptical about FIELD_PREP, no longer.

Under this construct we aren't using masks per se, but giving a name to a group of bits within the register (a field). So I think

#define PANEL_PORT_SELECT GENMASK(31, 30)
#define PANEL_PORT_SELECT_LVDS FIELD_PREP(PANEL_PORT_SELECT, 0)

Argh, I've screwed up. I must have failed to build after adding the last patch. You know, RFC and all. This results in:

drivers/gpu/drm/i915/intel_display.c: In function ‘assert_panel_unlocked’:
drivers/gpu/drm/i915/intel_display.c:1219:3: error: case label does not reduce to an integer constant
case PANEL_PORT_SELECT_LVDS:

Fail.

However, taking just the mask&shift part from FIELD_PREP works:

	(((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask))

But then we'll lose the static checks, unless we come up with something ingenious ourselves.

BR,
Jani.

Quoted 4 lines

is intuitive. Did you do a quick bloatometer to see if gcc code generation is affected?
-Chris

Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw

Re: [RFC 4/4] drm/i915/registers: define field values using FIELD_PREP()

Quoted 40 lines · Jani Nikula
Quoted 24 lines · Chris Wilson

Quoting Jani Nikula (2018-09-27 10:40:23)

Quoted 9 lines

Slightly verbose, but does away with hand rolled shifts and provides static checking that the values fit the mask.

---

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -4650,11 +4650,11 @@ enum {
 #define _PP_ON_DELAYS                  0x61208
 #define PP_ON_DELAYS(pps_idx)          _MMIO_PPS(pps_idx, _PP_ON_DELAYS)
 #define  PANEL_PORT_SELECT_MASK                GENMASK(31, 30)

drivers/gpu/drm/i915/i915_reg.h enum { · line 4657

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +5 -5
-#define  PANEL_PORT_SELECT_LVDS                (0 << 30)
-#define  PANEL_PORT_SELECT_DPA         (1 << 30)
-#define  PANEL_PORT_SELECT_DPC         (2 << 30)
-#define  PANEL_PORT_SELECT_DPD         (3 << 30)
-#define  PANEL_PORT_SELECT_VLV(port)   ((port) << 30)
+#define  PANEL_PORT_SELECT_LVDS                FIELD_PREP(PANEL_PORT_SELECT_MASK, 0)
+#define  PANEL_PORT_SELECT_DPA         FIELD_PREP(PANEL_PORT_SELECT_MASK, 1)
+#define  PANEL_PORT_SELECT_DPC         FIELD_PREP(PANEL_PORT_SELECT_MASK, 2)
+#define  PANEL_PORT_SELECT_DPD         FIELD_PREP(PANEL_PORT_SELECT_MASK, 3)
+#define  PANEL_PORT_SELECT_VLV(port)   FIELD_PREP(PANEL_PORT_SELECT_MASK, port)

Maybe verbose, but it reads far better as giving each field a distinct name ties together all the individual options.

Quoted 7 lines

Before seeing this I was sceptical about FIELD_PREP, no longer.

Under this construct we aren't using masks per se, but giving a name to a group of bits within the register (a field). So I think

#define PANEL_PORT_SELECT GENMASK(31, 30)
#define PANEL_PORT_SELECT_LVDS FIELD_PREP(PANEL_PORT_SELECT, 0)

Argh, I've screwed up. I must have failed to build after adding the last patch. You know, RFC and all. This results in:

drivers/gpu/drm/i915/intel_display.c: In function ‘assert_panel_unlocked’:
drivers/gpu/drm/i915/intel_display.c:1219:3: error: case label does not reduce to an integer constant
case PANEL_PORT_SELECT_LVDS:

Quoted 8 lines

Fail.

However, taking just the mask&shift part from FIELD_PREP works:

	(((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask))

But then we'll lose the static checks, unless we come up with something ingenious ourselves.

If my grep-fu serves me right, we have 186 macros defined in i915_reg.h that are used as case labels, and almost all of them would be candidates for FIELD_PREP().

Is an alternative FIELD_PREP() worth it without the static checks?

BR,
Jani.

Quoted 9 lines

BR,
Jani.

Quoted 4 lines

is intuitive. Did you do a quick bloatometer to see if gcc code generation is affected?
-Chris

Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer
#9 lore raw

Re: [RFC 4/4] drm/i915/registers: define field values using FIELD_PREP()

In reply to Chris Wilson

Quoting Chris Wilson (2018-09-27 13:35:47)

Quoted 26 lines

Quoting Jani Nikula (2018-09-27 10:40:23)

Quoted 9 lines

Slightly verbose, but does away with hand rolled shifts and provides static checking that the values fit the mask.

---

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -4650,11 +4650,11 @@ enum {
 #define _PP_ON_DELAYS                  0x61208
 #define PP_ON_DELAYS(pps_idx)          _MMIO_PPS(pps_idx, _PP_ON_DELAYS)
 #define  PANEL_PORT_SELECT_MASK                GENMASK(31, 30)

drivers/gpu/drm/i915/i915_reg.h enum { · line 4657

Quoted 10 lines
drivers/gpu/drm/i915/i915_reg.h +5 -5
-#define  PANEL_PORT_SELECT_LVDS                (0 << 30)
-#define  PANEL_PORT_SELECT_DPA         (1 << 30)
-#define  PANEL_PORT_SELECT_DPC         (2 << 30)
-#define  PANEL_PORT_SELECT_DPD         (3 << 30)
-#define  PANEL_PORT_SELECT_VLV(port)   ((port) << 30)
+#define  PANEL_PORT_SELECT_LVDS                FIELD_PREP(PANEL_PORT_SELECT_MASK, 0)
+#define  PANEL_PORT_SELECT_DPA         FIELD_PREP(PANEL_PORT_SELECT_MASK, 1)
+#define  PANEL_PORT_SELECT_DPC         FIELD_PREP(PANEL_PORT_SELECT_MASK, 2)
+#define  PANEL_PORT_SELECT_DPD         FIELD_PREP(PANEL_PORT_SELECT_MASK, 3)
+#define  PANEL_PORT_SELECT_VLV(port)   FIELD_PREP(PANEL_PORT_SELECT_MASK, port)

Maybe verbose, but it reads far better as giving each field a distinct name ties together all the individual options.

Before seeing this I was sceptical about FIELD_PREP, no longer.

Quoted 8 lines

Under this construct we aren't using masks per se, but giving a name to a group of bits within the register (a field). So I think

#define PANEL_PORT_SELECT GENMASK(31, 30)
#define PANEL_PORT_SELECT_LVDS FIELD_PREP(PANEL_PORT_SELECT, 0)

is intuitive. Did you do a quick bloatometer to see if gcc code generation is affected?

+1 from me for the change as big and for the above detail suggested by Chris.

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

#10 lore raw
In reply to Jani Nikula
Quoted 4 lines · Jani Nikula

I'm not necessarily proposing pushing the patches in this series; they're more of a piece-by-piece transformation of the power sequencer macros and code to use the above macros, to give an idea what the end result would look like.

And if it isn't clear from the above, I'm *not* soliciting detailed patch review on the series. More like meta review, what worries do you have for wider usage, etc.

BR,
Jani.

Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw
In reply to Jani Nikula
Quoted 6 lines · Jani Nikula

This is an RFC to get input on how people feel about moving towards using <linux/bits.h> and <linux/bitfield.h> macros for register field definitions and manipulation:

* BIT()
* GENMASK()

BIT/GENMASK macros assumes 'unsigned long' type (64b) while our registers (and some of our temporary variables) are 'unsigned int' (32b).

It was reported [1] that use of plain BIT(0) may cause compilation issues.

Michal

[1] https://lists.freedesktop.org/archives/intel-gfx/2018-September/176704.html

Quoted 2 lines

* FIELD_GET()
* FIELD_PREP()

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

#12 lore raw
Quoted 7 lines · Michal Wajdeczko
Quoted 4 lines · Jani Nikula

This is an RFC to get input on how people feel about moving towards using <linux/bits.h> and <linux/bitfield.h> macros for register field definitions and manipulation:

Quoted 5 lines
Quoted 2 lines

* BIT()
* GENMASK()

BIT/GENMASK macros assumes 'unsigned long' type (64b) while our registers (and some of our temporary variables) are 'unsigned int' (32b).

I don't see a problem with that as long as we stick to unsigned types.

Quoted 1 line

It was reported [1] that use of plain BIT(0) may cause compilation issues.

That mixes signed and unsigned types.

BR,
Jani.

Quoted 10 lines

Michal

[1]
https://lists.freedesktop.org/archives/intel-gfx/2018-September/176704.html

Quoted 2 lines

* FIELD_GET()
* FIELD_PREP()

Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#13 lore raw
Quoted 8 lines · Jani Nikula
Quoted 7 lines · Michal Wajdeczko
Quoted 4 lines · Jani Nikula

This is an RFC to get input on how people feel about moving towards using <linux/bits.h> and <linux/bitfield.h> macros for register field definitions and manipulation:

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

* BIT()
* GENMASK()

BIT/GENMASK macros assumes 'unsigned long' type (64b) while our registers (and some of our temporary variables) are 'unsigned int' (32b).

I don't see a problem with that as long as we stick to unsigned types.

Okay, there's a problem with mixing (1 << n) with GENMASK, as the former is signed. Using BIT() and GENMASK() together works better.

Another slight annoyance is printf formats, which are currently written for unsigned ints, and passing GENMASK or BIT to prints will make them require unsigned longs. I don't think we use that a whole lot, but it's a consideration.

If all else fails, we can write our own wrappers for u32, though it's a bit meh.

BR,
Jani.

Quoted 19 lines
Quoted 2 lines

It was reported [1] that use of plain BIT(0) may cause compilation issues.

That mixes signed and unsigned types.

BR,
Jani.

Quoted 10 lines

Michal

[1]
https://lists.freedesktop.org/archives/intel-gfx/2018-September/176704.html

Quoted 2 lines

* FIELD_GET()
* FIELD_PREP()

Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#14 lore raw

✗ Fi.CI.BAT: failure for drm/i915/registers: use standard bits.h and bitfield.h macros

In reply to Jani Nikula
== Series Details ==

== Series Details ==

Series: drm/i915/registers: use standard bits.h and bitfield.h macros
URL : https://patchwork.freedesktop.org/series/50267/
State : failure

== Summary ==

CALL scripts/checksyscalls.sh
DESCEND objtool
CHK include/generated/compile.h
CC [M] drivers/gpu/drm/i915/intel_display.o
In file included from drivers/gpu/drm/i915/i915_drv.h:58:0,

                 from drivers/gpu/drm/i915/intel_drv.h:33,
                 from drivers/gpu/drm/i915/intel_display.c:36:
drivers/gpu/drm/i915/intel_display.c: In function ‘assert_panel_unlocked’:
drivers/gpu/drm/i915/i915_reg.h:4653:34: error: implicit declaration of function ‘FIELD_PREP’; did you mean ‘CLK_PRE’? [-Werror=implicit-function-declaration]
 #define  PANEL_PORT_SELECT_LVDS  FIELD_PREP(PANEL_PORT_SELECT_MASK, 0)
                                  ^
drivers/gpu/drm/i915/intel_display.c:1219:8: note: in expansion of macro ‘PANEL_PORT_SELECT_LVDS’
   case PANEL_PORT_SELECT_LVDS:
        ^~~~~~~~~~~~~~~~~~~~~~

drivers/gpu/drm/i915/intel_display.c:1219:3: error: case label does not reduce to an integer constant
case PANEL_PORT_SELECT_LVDS:
^~~~
drivers/gpu/drm/i915/intel_display.c:1222:3: error: case label does not reduce to an integer constant
case PANEL_PORT_SELECT_DPA:
^~~~
drivers/gpu/drm/i915/intel_display.c:1225:3: error: case label does not reduce to an integer constant
case PANEL_PORT_SELECT_DPC:
^~~~
drivers/gpu/drm/i915/intel_display.c:1228:3: error: case label does not reduce to an integer constant
case PANEL_PORT_SELECT_DPD:
^~~~
cc1: all warnings being treated as errors
scripts/Makefile.build:305: recipe for target 'drivers/gpu/drm/i915/intel_display.o' failed make[4]: *** [drivers/gpu/drm/i915/intel_display.o] Error 1 scripts/Makefile.build:546: recipe for target 'drivers/gpu/drm/i915' failed
make[3]: *** [drivers/gpu/drm/i915] Error 2
scripts/Makefile.build:546: recipe for target 'drivers/gpu/drm' failed
make[2]: *** [drivers/gpu/drm] Error 2
scripts/Makefile.build:546: recipe for target 'drivers/gpu' failed
make[1]: *** [drivers/gpu] Error 2
Makefile:1050: recipe for target 'drivers' failed
make: *** [drivers] Error 2

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