Skip to contentSkip to conversation

drm: zynqmp_dp: Misc. patches and debugfs support

PATCH In review Sean Anderson 3 participants 36 messages Mar 19, 2024 – Mar 23, 2024

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

v2 cover drm: zynqmp_dp: Misc. patches and debugfs support

This series adds debugfs support for the zynqmp_dp driver. The intent is to enable compliance testing or to help debug signal-integrity issues.

The first four patches are general improvements (and could be applied independently), while the last four add debugfs support.

Changes in v2:
- Fix kerneldoc
- Rearrange zynqmp_dp for better padding
- Document hpd_irq_work
- Split off the HPD IRQ work into another commit
- Expand the commit message
- Document debugfs files
- Add ignore_aux_errors and ignore_hpd debugfs files to replace earlier implicit functionality
- Attempt to fix unreproducable, spurious build warning
- Drop "Optionally ignore DPCD errors" in favor of a debugfs file directly affecting zynqmp_dp_aux_transfer.

Sean Anderson (8):
drm: xlnx: Fix kerneldoc
drm: zynqmp_dp: Downgrade log level for aux retries message
drm: zynqmp_dp: Adjust training values per-lane
drm: zynqmp_dp: Rearrange zynqmp_dp for better padding
drm: zynqmp_dp: Don't retrain the link in our IRQ
drm: zynqmp_dp: Add locking
drm: zynqmp_dp: Split off several helper functions
drm: zynqmp_dp: Add debugfs interface for compliance testing

 Documentation/gpu/drivers.rst       |   1 +
 Documentation/gpu/zynqmp.rst        | 149 +++++
 MAINTAINERS                         |   1 +
 drivers/gpu/drm/xlnx/zynqmp_disp.c  |   6 +-
 drivers/gpu/drm/xlnx/zynqmp_dp.c    | 836 +++++++++++++++++++++++++---
 drivers/gpu/drm/xlnx/zynqmp_dpsub.h |   1 +
 drivers/gpu/drm/xlnx/zynqmp_kms.h   |   4 +-
 7 files changed, 931 insertions(+), 67 deletions(-)
 create mode 100644 Documentation/gpu/zynqmp.rst
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#1 lore raw

PATCH v2 1/8 drm: xlnx: Fix kerneldoc

Fix a few errors in the kerneldoc. Mostly this addresses missing/renamed members.

---

Changes in v2:
- New

 drivers/gpu/drm/xlnx/zynqmp_disp.c  | 6 +++---
 drivers/gpu/drm/xlnx/zynqmp_dpsub.h | 1 +
 drivers/gpu/drm/xlnx/zynqmp_kms.h   | 4 ++--
 3 files changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_disp.c +3 -3
index 407bc07cec69..f79bf3fb8110 100644
@@ -128,9 +128,9 @@ struct zynqmp_disp_layer {
  * struct zynqmp_disp - Display controller
  * @dev: Device structure
  * @dpsub: Display subsystem
- * @blend.base: Register I/O base address for the blender
- * @avbuf.base: Register I/O base address for the audio/video buffer manager
- * @audio.base: Registers I/O base address for the audio mixer
+ * @blend: Register I/O base address for the blender
+ * @avbuf: Register I/O base address for the audio/video buffer manager
+ * @audio: Registers I/O base address for the audio mixer
  * @layers: Layers (planes)
  */
 struct zynqmp_disp {
drivers/gpu/drm/xlnx/zynqmp_dpsub.h +1 -0
index 09ea01878f2a..b18554467e9c 100644
@@ -53,6 +53,7 @@ enum zynqmp_dpsub_format {
  * @drm: The DRM/KMS device data
  * @bridge: The DP encoder bridge
  * @disp: The display controller
+ * @layers: Video and graphics layers
  * @dp: The DisplayPort controller
  * @dma_align: DMA alignment constraint (must be a power of 2)
  */
drivers/gpu/drm/xlnx/zynqmp_kms.h +2 -2
index 01be96b00e3f..cb13c6b8008e 100644
@@ -22,9 +22,9 @@
 struct zynqmp_dpsub;
 
 /**
- * struct zynqmp_dpsub - ZynqMP DisplayPort Subsystem DRM/KMS data
+ * struct zynqmp_dpsub_drm - ZynqMP DisplayPort Subsystem DRM/KMS data
  * @dpsub: Backpointer to the DisplayPort subsystem
- * @drm: The DRM/KMS device
+ * @dev: The DRM/KMS device
  * @planes: The DRM planes
  * @crtc: The DRM CRTC
  * @encoder: The dummy DRM encoder
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#7 lore raw

PATCH v2 2/8 drm: zynqmp_dp: Downgrade log level for aux retries message

In reply to Sean Anderson

Enable this message for verbose debugging only as it is otherwise printed after every AUX message, quickly filling the log buffer.

---

(no changes since v1)

 drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +1 -1
index a0606fab0e22..98a32e6a0459 100644
@@ -1006,7 +1006,7 @@ zynqmp_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
 					       msg->buffer, msg->size,
 					       &msg->reply);
 		if (!ret) {
-			dev_dbg(dp->dev, "aux %d retries\n", i);
+			dev_vdbg(dp->dev, "aux %d retries\n", i);
 			return msg->size;
 		}
 
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#9 lore raw

PATCH v2 3/8 drm: zynqmp_dp: Adjust training values per-lane

In reply to Sean Anderson

The feedback we get from the DPRX is per-lane. Make changes using this information, instead of picking the maximum values from all lanes. This results in more-consistent training on marginal links.

---

(no changes since v1)

 drivers/gpu/drm/xlnx/zynqmp_dp.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +8 -15
index 98a32e6a0459..8635b5673386 100644
@@ -605,28 +605,21 @@ static void zynqmp_dp_adjust_train(struct zynqmp_dp *dp,
 				   u8 link_status[DP_LINK_STATUS_SIZE])
 {
 	u8 *train_set = dp->train_set;
-	u8 voltage = 0, preemphasis = 0;
 	u8 i;
 
 	for (i = 0; i < dp->mode.lane_cnt; i++) {
-		u8 v = drm_dp_get_adjust_request_voltage(link_status, i);
-		u8 p = drm_dp_get_adjust_request_pre_emphasis(link_status, i);
+		u8 voltage = drm_dp_get_adjust_request_voltage(link_status, i);
+		u8 preemphasis =
+			drm_dp_get_adjust_request_pre_emphasis(link_status, i);
 
-		if (v > voltage)
-			voltage = v;
+		if (voltage >= DP_TRAIN_VOLTAGE_SWING_LEVEL_3)
+			voltage |= DP_TRAIN_MAX_SWING_REACHED;
 
-		if (p > preemphasis)
-			preemphasis = p;
-	}
+		if (preemphasis >= DP_TRAIN_PRE_EMPH_LEVEL_2)
+			preemphasis |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
 
-	if (voltage >= DP_TRAIN_VOLTAGE_SWING_LEVEL_3)
-		voltage |= DP_TRAIN_MAX_SWING_REACHED;
-
-	if (preemphasis >= DP_TRAIN_PRE_EMPH_LEVEL_2)
-		preemphasis |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
-
-	for (i = 0; i < dp->mode.lane_cnt; i++)
 		train_set[i] = voltage | preemphasis;
+	}
 }
 
 /**
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#12 lore raw

PATCH v2 4/8 drm: zynqmp_dp: Rearrange zynqmp_dp for better padding

In reply to Sean Anderson

Sort the members of struct zynqmp_dp to reduce padding necessary for alignment.

---

Changes in v2:
- New

 drivers/gpu/drm/xlnx/zynqmp_dp.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +14 -14
index 8635b5673386..f1834c8e3c02 100644
@@ -255,10 +255,10 @@ struct zynqmp_dp_link_config {
  * @fmt: format identifier string
  */
 struct zynqmp_dp_mode {
-	u8 bw_code;
-	u8 lane_cnt;
-	int pclock;
 	const char *fmt;
+	int pclock;
+	u8 bw_code;
+	u8 lane_cnt;
 };
 
 /**
@@ -295,27 +295,27 @@ struct zynqmp_dp_config {
  * @train_set: set of training data
  */
 struct zynqmp_dp {
+	struct drm_dp_aux aux;
+	struct drm_bridge bridge;
+	struct delayed_work hpd_work;
+
+	struct drm_bridge *next_bridge;
 	struct device *dev;
 	struct zynqmp_dpsub *dpsub;
 	void __iomem *iomem;
 	struct reset_control *reset;
-	int irq;
-
-	struct drm_bridge bridge;
-	struct drm_bridge *next_bridge;
-
-	struct zynqmp_dp_config config;
-	struct drm_dp_aux aux;
 	struct phy *phy[ZYNQMP_DP_MAX_LANES];
-	u8 num_lanes;
-	struct delayed_work hpd_work;
+
 	enum drm_connector_status status;
+	int irq;
 	bool enabled;
 
-	u8 dpcd[DP_RECEIVER_CAP_SIZE];
-	struct zynqmp_dp_link_config link_config;
 	struct zynqmp_dp_mode mode;
+	struct zynqmp_dp_link_config link_config;
+	struct zynqmp_dp_config config;
+	u8 dpcd[DP_RECEIVER_CAP_SIZE];
 	u8 train_set[ZYNQMP_DP_MAX_LANES];
+	u8 num_lanes;
 };
 
 static inline struct zynqmp_dp *bridge_to_dp(struct drm_bridge *bridge)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#15 lore raw

PATCH v2 5/8 drm: zynqmp_dp: Don't retrain the link in our IRQ

In reply to Sean Anderson

Retraining the link can take a while, and might involve waiting for DPCD reads/writes to complete. This is inappropriate for an IRQ handler. Just schedule this work for later completion. This is racy, but will be fixed in the next commit.

---
Actually, on second look this IRQ is threaded. So why do we have a workqueue for HPD events? Maybe we should make it unthreaded?

Changes in v2:
- Document hpd_irq_work
- Split this off from the lcoking changes

 drivers/gpu/drm/xlnx/zynqmp_dp.c | 43 ++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 16 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +27 -16
index f1834c8e3c02..f3fcdbf662fa 100644
@@ -287,6 +287,7 @@ struct zynqmp_dp_config {
  * @phy: PHY handles for DP lanes
  * @num_lanes: number of enabled phy lanes
  * @hpd_work: hot plug detection worker
+ * @hpd_irq_work: hot plug detection IRQ worker
  * @status: connection status
  * @enabled: flag to indicate if the device is enabled
  * @dpcd: DP configuration data from currently connected sink device
@@ -298,6 +299,7 @@ struct zynqmp_dp {
 	struct drm_dp_aux aux;
 	struct drm_bridge bridge;
 	struct delayed_work hpd_work;
+	struct delayed_work hpd_irq_work;
 
 	struct drm_bridge *next_bridge;
 	struct device *dev;
@@ -1611,6 +1613,27 @@ static void zynqmp_dp_hpd_work_func(struct work_struct *work)
 	drm_bridge_hpd_notify(&dp->bridge, status);
 }
 
+static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work)
+{
+	struct zynqmp_dp *dp = container_of(work, struct zynqmp_dp,
+					    hpd_irq_work.work);
+	u8 status[DP_LINK_STATUS_SIZE + 2];
+	int err;
+
+	err = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, status,
+			       DP_LINK_STATUS_SIZE + 2);
+	if (err < 0) {
+		dev_dbg_ratelimited(dp->dev,
+				    "could not read sink status: %d\n", err);
+	} else {
+		if (status[4] & DP_LINK_STATUS_UPDATED ||
+		    !drm_dp_clock_recovery_ok(&status[2], dp->mode.lane_cnt) ||
+		    !drm_dp_channel_eq_ok(&status[2], dp->mode.lane_cnt)) {
+			zynqmp_dp_train_loop(dp);
+		}
+	}
+}
+
 static irqreturn_t zynqmp_dp_irq_handler(int irq, void *data)
 {
 	struct zynqmp_dp *dp = (struct zynqmp_dp *)data;
@@ -1635,23 +1658,9 @@ static irqreturn_t zynqmp_dp_irq_handler(int irq, void *data)
 	if (status & ZYNQMP_DP_INT_HPD_EVENT)
 		schedule_delayed_work(&dp->hpd_work, 0);
 
-	if (status & ZYNQMP_DP_INT_HPD_IRQ) {
-		int ret;
-		u8 status[DP_LINK_STATUS_SIZE + 2];
+	if (status & ZYNQMP_DP_INT_HPD_IRQ)
+		schedule_delayed_work(&dp->hpd_irq_work, 0);
 
-		ret = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, status,
-				       DP_LINK_STATUS_SIZE + 2);
-		if (ret < 0)
-			goto handled;
-
-		if (status[4] & DP_LINK_STATUS_UPDATED ||
-		    !drm_dp_clock_recovery_ok(&status[2], dp->mode.lane_cnt) ||
-		    !drm_dp_channel_eq_ok(&status[2], dp->mode.lane_cnt)) {
-			zynqmp_dp_train_loop(dp);
-		}
-	}
-
-handled:
 	return IRQ_HANDLED;
 }
 
@@ -1676,6 +1685,7 @@ int zynqmp_dp_probe(struct zynqmp_dpsub *dpsub)
 	dp->status = connector_status_disconnected;
 
 	INIT_DELAYED_WORK(&dp->hpd_work, zynqmp_dp_hpd_work_func);
+	INIT_DELAYED_WORK(&dp->hpd_irq_work, zynqmp_dp_hpd_irq_work_func);
 
 	/* Acquire all resources (IOMEM, IRQ and PHYs). */
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dp");
@@ -1775,6 +1785,7 @@ void zynqmp_dp_remove(struct zynqmp_dpsub *dpsub)
 	zynqmp_dp_write(dp, ZYNQMP_DP_INT_DS, ZYNQMP_DP_INT_ALL);
 	disable_irq(dp->irq);
 
+	cancel_delayed_work_sync(&dp->hpd_irq_work);
 	cancel_delayed_work_sync(&dp->hpd_work);
 
 	zynqmp_dp_write(dp, ZYNQMP_DP_TRANSMITTER_ENABLE, 0);
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#27 lore raw

PATCH v2 6/8 drm: zynqmp_dp: Add locking

In reply to Sean Anderson

Add some locking to prevent the IRQ/workers/bridge API calls from stepping on each other's toes. This lock protects:

- Non-atomic registers configuring the link. That is, everything but the IRQ registers (since these are accessed in an atomic fashion), and the DP AUX registers (since these don't affect the link). We also access AUX while holding this lock, so it would be very tricky to support.
- Link configuration. This is effectively everything in zynqmp_dp which isn't read-only after probe time. So from next_bridge onward.

This lock is designed to protect configuration changes so we don't have to do anything tricky. Configuration should never be in the hot path, so I'm not worried about performance.

---

Changes in v2:
- Split off the HPD IRQ work into another commit
- Expand the commit message

 drivers/gpu/drm/xlnx/zynqmp_dp.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/gpu/drm/xlnx/zynqmp_dp.c +20 -0
index f3fcdbf662fa..a90ab5c0f5cf 100644
@@ -279,6 +279,7 @@ struct zynqmp_dp_config {
  * @dpsub: Display subsystem
  * @iomem: device I/O memory for register access
  * @reset: reset controller
+ * @lock: Mutex protecting this struct and register access (but not AUX)
  * @irq: irq
  * @bridge: DRM bridge for the DP encoder
  * @next_bridge: The downstream bridge
@@ -294,12 +295,17 @@ struct zynqmp_dp_config {
  * @link_config: common link configuration between IP core and sink device
  * @mode: current mode between IP core and sink device
  * @train_set: set of training data
+ *
+ * @lock covers the link configuration in this struct and the device's
+ * registers. It does not cover @aux. It is not strictly required for any of
+ * the members which are only modified at probe/remove time (e.g. @dev).
  */
 struct zynqmp_dp {
 	struct drm_dp_aux aux;
 	struct drm_bridge bridge;
 	struct delayed_work hpd_work;
 	struct delayed_work hpd_irq_work;
+	struct mutex lock;
 
 	struct drm_bridge *next_bridge;
 	struct device *dev;
@@ -1373,8 +1379,10 @@ zynqmp_dp_bridge_mode_valid(struct drm_bridge *bridge,
 	}
 
 	/* Check with link rate and lane count */
+	mutex_lock(&dp->lock);
 	rate = zynqmp_dp_max_rate(dp->link_config.max_rate,
 				  dp->link_config.max_lanes, dp->config.bpp);
+	mutex_unlock(&dp->lock);
 	if (mode->clock > rate) {
 		dev_dbg(dp->dev, "filtered mode %s for high pixel rate\n",
 			mode->name);
@@ -1401,6 +1409,7 @@ static void zynqmp_dp_bridge_atomic_enable(struct drm_bridge *bridge,
 
 	pm_runtime_get_sync(dp->dev);
 
+	mutex_lock(&dp->lock);
 	zynqmp_dp_disp_enable(dp, old_bridge_state);
 
 	/*
@@ -1461,6 +1470,7 @@ static void zynqmp_dp_bridge_atomic_enable(struct drm_bridge *bridge,
 	zynqmp_dp_write(dp, ZYNQMP_DP_SOFTWARE_RESET,
 			ZYNQMP_DP_SOFTWARE_RESET_ALL);
 	zynqmp_dp_write(dp, ZYNQMP_DP_MAIN_STREAM_ENABLE, 1);
+	mutex_unlock(&dp->lock);
 }
 
 static void zynqmp_dp_bridge_atomic_disable(struct drm_bridge *bridge,
@@ -1468,6 +1478,7 @@ static void zynqmp_dp_bridge_atomic_disable(struct drm_bridge *bridge,
 {
 	struct zynqmp_dp *dp = bridge_to_dp(bridge);
 
+	mutex_lock(&dp->lock);
 	dp->enabled = false;
 	cancel_delayed_work(&dp->hpd_work);
 	zynqmp_dp_write(dp, ZYNQMP_DP_MAIN_STREAM_ENABLE, 0);
@@ -1478,6 +1489,7 @@ static void zynqmp_dp_bridge_atomic_disable(struct drm_bridge *bridge,
 		zynqmp_dp_write(dp, ZYNQMP_DP_TX_AUDIO_CONTROL, 0);
 
 	zynqmp_dp_disp_disable(dp, old_bridge_state);
+	mutex_unlock(&dp->lock);
 
 	pm_runtime_put_sync(dp->dev);
 }
@@ -1520,6 +1532,8 @@ static enum drm_connector_status zynqmp_dp_bridge_detect(struct drm_bridge *brid
 	u32 state, i;
 	int ret;
 
+	mutex_lock(&dp->lock);
+
 	/*
 	 * This is from heuristic. It takes some delay (ex, 100 ~ 500 msec) to
 	 * get the HPD signal with some monitors.
@@ -1547,11 +1561,13 @@ static enum drm_connector_status zynqmp_dp_bridge_detect(struct drm_bridge *brid
 					       dp->num_lanes);
 
 		dp->status = connector_status_connected;
+		mutex_unlock(&dp->lock);
 		return connector_status_connected;
 	}
 
 disconnected:
 	dp->status = connector_status_disconnected;
+	mutex_unlock(&dp->lock);
 	return connector_status_disconnected;
 }
 
@@ -1620,6 +1636,7 @@ static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work)
 	u8 status[DP_LINK_STATUS_SIZE + 2];
 	int err;
 
+	mutex_lock(&dp->lock);
 	err = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, status,
 			       DP_LINK_STATUS_SIZE + 2);
 	if (err < 0) {
@@ -1632,6 +1649,7 @@ static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work)
 			zynqmp_dp_train_loop(dp);
 		}
 	}
+	mutex_unlock(&dp->lock);
 }
 
 static irqreturn_t zynqmp_dp_irq_handler(int irq, void *data)
@@ -1683,6 +1701,7 @@ int zynqmp_dp_probe(struct zynqmp_dpsub *dpsub)
 	dp->dev = &pdev->dev;
 	dp->dpsub = dpsub;
 	dp->status = connector_status_disconnected;
+	mutex_init(&dp->lock);
 
 	INIT_DELAYED_WORK(&dp->hpd_work, zynqmp_dp_hpd_work_func);
 	INIT_DELAYED_WORK(&dp->hpd_irq_work, zynqmp_dp_hpd_irq_work_func);
@@ -1793,4 +1812,5 @@ void zynqmp_dp_remove(struct zynqmp_dpsub *dpsub)
 
 	zynqmp_dp_phy_exit(dp);
 	zynqmp_dp_reset(dp, true);
+	mutex_destroy(&dp->lock);
 }
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#28 lore raw

PATCH v2 7/8 drm: zynqmp_dp: Split off several helper functions

In reply to Sean Anderson

In preparation for supporting compliance testing, split off several helper functions. No functional change intended.

---

(no changes since v1)

 drivers/gpu/drm/xlnx/zynqmp_dp.c | 49 ++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 15 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +34 -15
index a90ab5c0f5cf..6e04dcf61e19 100644
@@ -633,6 +633,7 @@ static void zynqmp_dp_adjust_train(struct zynqmp_dp *dp,
 /**
  * zynqmp_dp_update_vs_emph - Update the training values
  * @dp: DisplayPort IP core structure
+ * @train_set: A set of training values
  *
  * Update the training values based on the request from sink. The mapped values
  * are predefined, and values(vs, pe, pc) are from the device manual.
@@ -640,12 +641,12 @@ static void zynqmp_dp_adjust_train(struct zynqmp_dp *dp,
  * Return: 0 if vs and emph are updated successfully, or the error code returned
  * by drm_dp_dpcd_write().
  */
-static int zynqmp_dp_update_vs_emph(struct zynqmp_dp *dp)
+static int zynqmp_dp_update_vs_emph(struct zynqmp_dp *dp, u8 *train_set)
 {
 	unsigned int i;
 	int ret;
 
-	ret = drm_dp_dpcd_write(&dp->aux, DP_TRAINING_LANE0_SET, dp->train_set,
+	ret = drm_dp_dpcd_write(&dp->aux, DP_TRAINING_LANE0_SET, train_set,
 				dp->mode.lane_cnt);
 	if (ret < 0)
 		return ret;
@@ -653,7 +654,7 @@ static int zynqmp_dp_update_vs_emph(struct zynqmp_dp *dp)
 	for (i = 0; i < dp->mode.lane_cnt; i++) {
 		u32 reg = ZYNQMP_DP_SUB_TX_PHY_PRECURSOR_LANE_0 + i * 4;
 		union phy_configure_opts opts = { 0 };
-		u8 train = dp->train_set[i];
+		u8 train = train_set[i];
 
 		opts.dp.voltage[0] = (train & DP_TRAIN_VOLTAGE_SWING_MASK)
 				   >> DP_TRAIN_VOLTAGE_SWING_SHIFT;
@@ -697,7 +698,7 @@ static int zynqmp_dp_link_train_cr(struct zynqmp_dp *dp)
 	 * So, This loop should exit before 512 iterations
 	 */
 	for (max_tries = 0; max_tries < 512; max_tries++) {
-		ret = zynqmp_dp_update_vs_emph(dp);
+		ret = zynqmp_dp_update_vs_emph(dp, dp->train_set);
 		if (ret)
 			return ret;
 
@@ -762,7 +763,7 @@ static int zynqmp_dp_link_train_ce(struct zynqmp_dp *dp)
 		return ret;
 
 	for (tries = 0; tries < DP_MAX_TRAINING_TRIES; tries++) {
-		ret = zynqmp_dp_update_vs_emph(dp);
+		ret = zynqmp_dp_update_vs_emph(dp, dp->train_set);
 		if (ret)
 			return ret;
 
@@ -785,28 +786,29 @@ static int zynqmp_dp_link_train_ce(struct zynqmp_dp *dp)
 }
 
 /**
- * zynqmp_dp_train - Train the link
+ * zynqmp_dp_setup() - Set up major link parameters
  * @dp: DisplayPort IP core structure
+ * @bw_code: The link bandwidth as a multiple of 270 MHz
+ * @lane_cnt: The number of lanes to use
+ * @enhanced: Use enhanced framing
+ * @downspread: Enable spread-spectrum clocking
  *
- * Return: 0 if all trains are done successfully, or corresponding error code.
+ * Return: 0 on success, or -errno on failure
  */
-static int zynqmp_dp_train(struct zynqmp_dp *dp)
+static int zynqmp_dp_setup(struct zynqmp_dp *dp, u8 bw_code, u8 lane_cnt,
+			   bool enhanced, bool downspread)
 {
 	u32 reg;
-	u8 bw_code = dp->mode.bw_code;
-	u8 lane_cnt = dp->mode.lane_cnt;
 	u8 aux_lane_cnt = lane_cnt;
-	bool enhanced;
 	int ret;
 
 	zynqmp_dp_write(dp, ZYNQMP_DP_LANE_COUNT_SET, lane_cnt);
-	enhanced = drm_dp_enhanced_frame_cap(dp->dpcd);
 	if (enhanced) {
 		zynqmp_dp_write(dp, ZYNQMP_DP_ENHANCED_FRAME_EN, 1);
 		aux_lane_cnt |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
 	}
 
-	if (dp->dpcd[3] & 0x1) {
+	if (downspread) {
 		zynqmp_dp_write(dp, ZYNQMP_DP_DOWNSPREAD_CTL, 1);
 		drm_dp_dpcd_writeb(&dp->aux, DP_DOWNSPREAD_CTRL,
 				   DP_SPREAD_AMP_0_5);
@@ -849,8 +851,25 @@ static int zynqmp_dp_train(struct zynqmp_dp *dp)
 	}
 
 	zynqmp_dp_write(dp, ZYNQMP_DP_PHY_CLOCK_SELECT, reg);
-	ret = zynqmp_dp_phy_ready(dp);
-	if (ret < 0)
+	return zynqmp_dp_phy_ready(dp);
+}
+
+
+/**
+ * zynqmp_dp_train - Train the link
+ * @dp: DisplayPort IP core structure
+ *
+ * Return: 0 if all trains are done successfully, or corresponding error code.
+ */
+static int zynqmp_dp_train(struct zynqmp_dp *dp)
+{
+	int ret;
+
+	ret = zynqmp_dp_setup(dp, dp->mode.bw_code, dp->mode.lane_cnt,
+			      drm_dp_enhanced_frame_cap(dp->dpcd),
+			      dp->dpcd[DP_MAX_DOWNSPREAD] &
+			      DP_MAX_DOWNSPREAD_0_5);
+	if (ret)
 		return ret;
 
 	zynqmp_dp_write(dp, ZYNQMP_DP_SCRAMBLING_DISABLE, 1);
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#30 lore raw

PATCH v2 8/8 drm: zynqmp_dp: Add debugfs interface for compliance testing

In reply to Sean Anderson

Add a debugfs interface for exercising the various test modes supported by the DisplayPort controller. This allows performing compliance testing, or performing signal integrity measurements on a failing link. At the moment, we do not support sink-driven link quality testing, although such support would be fairly easy to add.

Additionally, add some debugfs files for ignoring AUX errors and HPD events, as this can allow testing with equipment that cannot emulate a DPRX.

---

Changes in v2:
- Document debugfs files
- Add ignore_aux_errors and ignore_hpd debugfs files to replace earlier implicit functionality
- Attempt to fix unreproducable, spurious build warning

 Documentation/gpu/drivers.rst    |   1 +
 Documentation/gpu/zynqmp.rst     | 149 +++++++
 MAINTAINERS                      |   1 +
 drivers/gpu/drm/xlnx/zynqmp_dp.c | 675 ++++++++++++++++++++++++++++++-
 4 files changed, 823 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/gpu/zynqmp.rst
Documentation/gpu/drivers.rst +1 -0
index b899cbc5c2b4..187201aedbe5 100644
@@ -22,6 +22,7 @@ GPU Driver Documentation
    afbc
    komeda-kms
    panfrost
+   zynqmp
 
 .. only::  subproject and html
 
Documentation/gpu/zynqmp.rst new file +149 -0

149 lines not on this page · raw message

MAINTAINERS +1 -0
index 8d1052fa6a69..78680180aefc 100644
@@ -7305,6 +7305,7 @@ L:	[email protected]
 S:	Maintained
 T:	git git://anongit.freedesktop.org/drm/drm-misc
 F:	Documentation/devicetree/bindings/display/xlnx/
+F:	Documentation/gpu/zynqmp.rst
 F:	drivers/gpu/drm/xlnx/
 
 DRM GPU SCHEDULER
drivers/gpu/drm/xlnx/zynqmp_dp.c +672 -3

771 lines not on this page · raw message

Signature · 1 line
2.35.1.1320.gc452695387.dirty
#35 lore raw
In reply to Sean Anderson
Quoted 29 lines · Sean Anderson

This series adds debugfs support for the zynqmp_dp driver. The intent is to enable compliance testing or to help debug signal-integrity issues.

The first four patches are general improvements (and could be applied independently), while the last four add debugfs support.

Changes in v2:
- Fix kerneldoc
- Rearrange zynqmp_dp for better padding
- Document hpd_irq_work
- Split off the HPD IRQ work into another commit
- Expand the commit message
- Document debugfs files
- Add ignore_aux_errors and ignore_hpd debugfs files to replace earlier implicit functionality
- Attempt to fix unreproducable, spurious build warning
- Drop "Optionally ignore DPCD errors" in favor of a debugfs file directly affecting zynqmp_dp_aux_transfer.

Sean Anderson (8):
drm: xlnx: Fix kerneldoc
drm: zynqmp_dp: Downgrade log level for aux retries message
drm: zynqmp_dp: Adjust training values per-lane
drm: zynqmp_dp: Rearrange zynqmp_dp for better padding
drm: zynqmp_dp: Don't retrain the link in our IRQ
drm: zynqmp_dp: Add locking
drm: zynqmp_dp: Split off several helper functions
drm: zynqmp_dp: Add debugfs interface for compliance testing

Quoted 10 lines
 Documentation/gpu/drivers.rst       |   1 +
 Documentation/gpu/zynqmp.rst        | 149 +++++
 MAINTAINERS                         |   1 +
 drivers/gpu/drm/xlnx/zynqmp_disp.c  |   6 +-
 drivers/gpu/drm/xlnx/zynqmp_dp.c    | 836 +++++++++++++++++++++++++---
 drivers/gpu/drm/xlnx/zynqmp_dpsub.h |   1 +
 drivers/gpu/drm/xlnx/zynqmp_kms.h   |   4 +-
 7 files changed, 931 insertions(+), 67 deletions(-)
 create mode 100644 Documentation/gpu/zynqmp.rst

+CC Dmitry, Tomi, and Anatoliy who I forgot to CC

Let me know if you want to be taken off CC for future revisions

--Sean

maintainer
#2 lore raw

Re: [PATCH v2 1/8] drm: xlnx: Fix kerneldoc

In reply to Sean Anderson
Quoted 19 lines · Sean Anderson

Fix a few errors in the kerneldoc. Mostly this addresses missing/renamed members.

---

Changes in v2:
- New

  drivers/gpu/drm/xlnx/zynqmp_disp.c  | 6 +++---
  drivers/gpu/drm/xlnx/zynqmp_dpsub.h | 1 +
  drivers/gpu/drm/xlnx/zynqmp_kms.h   | 4 ++--
  3 files changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_disp.c +0 -0
index 407bc07cec69..f79bf3fb8110 100644

drivers/gpu/drm/xlnx/zynqmp_disp.c struct zynqmp_disp_layer { · line 133

Quoted 9 lines
drivers/gpu/drm/xlnx/zynqmp_disp.c +3 -3
@@ -128,9 +128,9 @@ struct zynqmp_disp_layer {
   * struct zynqmp_disp - Display controller
   * @dev: Device structure
   * @dpsub: Display subsystem
- * @blend.base: Register I/O base address for the blender
- * @avbuf.base: Register I/O base address for the audio/video buffer manager
- * @audio.base: Registers I/O base address for the audio mixer
+ * @blend: Register I/O base address for the blender
+ * @avbuf: Register I/O base address for the audio/video buffer manager
+ * @audio: Registers I/O base address for the audio mixer

Afaics, the kernel doc guide:

https://docs.kernel.org/doc-guide/kernel-doc.html#nested-structs-unions

says that the current version is correct. Or is the issue that while, say, 'base' is documented, 'blend' was not?

Tomi

maintainer Reviewed-by on v2 2/8
#8 lore raw

Re: [PATCH v2 2/8] drm: zynqmp_dp: Downgrade log level for aux retries message

In reply to Sean Anderson
Quoted 17 lines · Sean Anderson

Enable this message for verbose debugging only as it is otherwise printed after every AUX message, quickly filling the log buffer.

---

(no changes since v1)

  drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +0 -0
index a0606fab0e22..98a32e6a0459 100644

drivers/gpu/drm/xlnx/zynqmp_dp.c zynqmp_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) · line 1012

Quoted 8 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +1 -1
@@ -1006,7 +1006,7 @@ zynqmp_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
  					       msg->buffer, msg->size,
  					       &msg->reply);
  		if (!ret) {
-			dev_dbg(dp->dev, "aux %d retries\n", i);
+			dev_vdbg(dp->dev, "aux %d retries\n", i);
  			return msg->size;
  		}
 

Yes, these are annoying... In my work branch I had added "if (i)" there, so that this is only printed if there actually are retries.

But this is fine too (or even dropping the print totally), so:

Tomi

maintainer Reviewed-by on v2 3/8
#10 lore raw

Re: [PATCH v2 3/8] drm: zynqmp_dp: Adjust training values per-lane

In reply to Sean Anderson
Quoted 43 lines · Sean Anderson

The feedback we get from the DPRX is per-lane. Make changes using this information, instead of picking the maximum values from all lanes. This results in more-consistent training on marginal links.

---

(no changes since v1)

  drivers/gpu/drm/xlnx/zynqmp_dp.c | 23 ++++++++---------------
  1 file changed, 8 insertions(+), 15 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +7 -10
index 98a32e6a0459..8635b5673386 100644
@@ -605,28 +605,21 @@ static void zynqmp_dp_adjust_train(struct zynqmp_dp *dp,
  				   u8 link_status[DP_LINK_STATUS_SIZE])
  {
  	u8 *train_set = dp->train_set;
-	u8 voltage = 0, preemphasis = 0;
  	u8 i;
 
  	for (i = 0; i < dp->mode.lane_cnt; i++) {
-		u8 v = drm_dp_get_adjust_request_voltage(link_status, i);
-		u8 p = drm_dp_get_adjust_request_pre_emphasis(link_status, i);
+		u8 voltage = drm_dp_get_adjust_request_voltage(link_status, i);
+		u8 preemphasis =
+			drm_dp_get_adjust_request_pre_emphasis(link_status, i);
 
-		if (v > voltage)
-			voltage = v;
+		if (voltage >= DP_TRAIN_VOLTAGE_SWING_LEVEL_3)
+			voltage |= DP_TRAIN_MAX_SWING_REACHED;
 
-		if (p > preemphasis)
-			preemphasis = p;
-	}
+		if (preemphasis >= DP_TRAIN_PRE_EMPH_LEVEL_2)
+			preemphasis |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
 
-	if (voltage >= DP_TRAIN_VOLTAGE_SWING_LEVEL_3)
-		voltage |= DP_TRAIN_MAX_SWING_REACHED;

drivers/gpu/drm/xlnx/zynqmp_dp.c static void zynqmp_dp_adjust_train(struct zynqmp_dp *dp, · line 625

Quoted 10 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +1 -5
-
-	if (preemphasis >= DP_TRAIN_PRE_EMPH_LEVEL_2)
-		preemphasis |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
-
-	for (i = 0; i < dp->mode.lane_cnt; i++)
  		train_set[i] = voltage | preemphasis;
+	}
  }
 
  /**

Looks fine to me, but a few cosmetic suggestions, feel free to ignore if not to your liking:

1)

u8 voltage, preemphasis;

voltage = drm_dp_get_adjust_request_voltage(link_status, i); preemphasis = drm_dp_get_adjust_request_pre_emphasis(link_status, i);

2)

for (unsigned int i = 0; i < dp->mode.lane_cnt; i++)

3)

dp->train_set[i] = voltage | preemphasis;

Tomi

reviewer
#3 lore raw

Re: [PATCH v2 1/8] drm: xlnx: Fix kerneldoc

In reply to Tomi Valkeinen
Quoted 32 lines · Tomi Valkeinen
Quoted 19 lines · Sean Anderson

Fix a few errors in the kerneldoc. Mostly this addresses missing/renamed members.

---

Changes in v2:
- New

  drivers/gpu/drm/xlnx/zynqmp_disp.c  | 6 +++---
  drivers/gpu/drm/xlnx/zynqmp_dpsub.h | 1 +
  drivers/gpu/drm/xlnx/zynqmp_kms.h   | 4 ++--

  3 files changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_disp.c +0 -0
index 407bc07cec69..f79bf3fb8110 100644

drivers/gpu/drm/xlnx/zynqmp_disp.c struct zynqmp_disp_layer { · line 133

Quoted 9 lines
drivers/gpu/drm/xlnx/zynqmp_disp.c +3 -3
@@ -128,9 +128,9 @@ struct zynqmp_disp_layer {
    * struct zynqmp_disp - Display controller
    * @dev: Device structure
    * @dpsub: Display subsystem
- * @blend.base: Register I/O base address for the blender
- * @avbuf.base: Register I/O base address for the audio/video buffer manager
- * @audio.base: Registers I/O base address for the audio mixer
+ * @blend: Register I/O base address for the blender
+ * @avbuf: Register I/O base address for the audio/video buffer manager
+ * @audio: Registers I/O base address for the audio mixer

Afaics, the kernel doc guide:

Quoted 3 lines

https://docs.kernel.org/doc-guide/kernel-doc.html#nested-structs-unions

says that the current version is correct. Or is the issue that while, say, 'base' is documented, 'blend' was not?

Hi,

I would do it more like so:

---
 drivers/gpu/drm/xlnx/zynqmp_disp.c |    3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/xlnx/zynqmp_disp.c +3 -0
diff -- a/drivers/gpu/drm/xlnx/zynqmp_disp.c b/drivers/gpu/drm/xlnx/zynqmp_disp.c
@@ -128,8 +128,11 @@ struct zynqmp_disp_layer {
  * struct zynqmp_disp - Display controller
  * @dev: Device structure
  * @dpsub: Display subsystem
+ * @blend: blender iomem info
  * @blend.base: Register I/O base address for the blender
+ * @avbuf: audio/video buffer iomem info
  * @avbuf.base: Register I/O base address for the audio/video buffer manager
+ * @audio: audio mixer iomem info
  * @audio.base: Registers I/O base address for the audio mixer
  * @layers: Layers (planes)
  */

but in my testing, Sean's way or my way result in no warning/errors.

Signature · 1 line
#Randy
maintainer
#13 lore raw

Re: [PATCH v2 4/8] drm: zynqmp_dp: Rearrange zynqmp_dp for better padding

In reply to Sean Anderson
Quoted 59 lines · Sean Anderson

Sort the members of struct zynqmp_dp to reduce padding necessary for alignment.

---

Changes in v2:
- New

  drivers/gpu/drm/xlnx/zynqmp_dp.c | 28 ++++++++++++++--------------
  1 file changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +10 -13
index 8635b5673386..f1834c8e3c02 100644
@@ -255,10 +255,10 @@ struct zynqmp_dp_link_config {
   * @fmt: format identifier string
   */
  struct zynqmp_dp_mode {
-	u8 bw_code;
-	u8 lane_cnt;
-	int pclock;
  	const char *fmt;
+	int pclock;
+	u8 bw_code;
+	u8 lane_cnt;
  };
 
  /**
@@ -295,27 +295,27 @@ struct zynqmp_dp_config {
   * @train_set: set of training data
   */
  struct zynqmp_dp {
+	struct drm_dp_aux aux;
+	struct drm_bridge bridge;
+	struct delayed_work hpd_work;
+
+	struct drm_bridge *next_bridge;
  	struct device *dev;
  	struct zynqmp_dpsub *dpsub;
  	void __iomem *iomem;
  	struct reset_control *reset;
-	int irq;
-
-	struct drm_bridge bridge;
-	struct drm_bridge *next_bridge;
-
-	struct zynqmp_dp_config config;
-	struct drm_dp_aux aux;
  	struct phy *phy[ZYNQMP_DP_MAX_LANES];
-	u8 num_lanes;
-	struct delayed_work hpd_work;
+
  	enum drm_connector_status status;
+	int irq;
  	bool enabled;
 
-	u8 dpcd[DP_RECEIVER_CAP_SIZE];

drivers/gpu/drm/xlnx/zynqmp_dp.c struct zynqmp_dp_config { · line 321

Quoted 10 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +4 -1
-	struct zynqmp_dp_link_config link_config;
  	struct zynqmp_dp_mode mode;
+	struct zynqmp_dp_link_config link_config;
+	struct zynqmp_dp_config config;
+	u8 dpcd[DP_RECEIVER_CAP_SIZE];
  	u8 train_set[ZYNQMP_DP_MAX_LANES];
+	u8 num_lanes;
  };
 
  static inline struct zynqmp_dp *bridge_to_dp(struct drm_bridge *bridge)

If you change the order of the fields, you should change the order in the kernel doc accordingly.

To be honest, I'm not sure if I like this patch. We have usually one instance of these structs allocated. How many bytes do we save?

I'm fine with getting easy savings by changing the field order in some cases, but I think the "human" side of the order is important too: usually the fields are grouped in some way, and ordered so that the more base or generic ones are first, and fields for some specific feature are later. And fields protected by a lock should be grouped together, with their lock being first/last in that group.

Looking at the zynqmp_dp struct with this patch, I get an urge to start moving things around: dev, dpsub, iomem, etc first, hpd somewhere later. Base config fields like config, num_lanes, irq would be grouped together. Etc.

Tomi

maintainer
#16 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

In reply to Sean Anderson
Quoted 4 lines · Sean Anderson

Retraining the link can take a while, and might involve waiting for DPCD reads/writes to complete. This is inappropriate for an IRQ handler. Just schedule this work for later completion. This is racy, but will be fixed in the next commit.

You should add the locks first, and use them here, rather than first adding a buggy commit and fixing it in the next one.

Quoted 4 lines

---
Actually, on second look this IRQ is threaded. So why do we have a workqueue for HPD events? Maybe we should make it unthreaded?

Indeed, there's not much work being done in the IRQ handler. I don't know why it's threaded.

We could move the queued work to be inside the threaded irq handler, but with a quick look, the HPD work has lines like "msleep(100)" (and that's inside a for loop...), which is probably not a good thing to do even in threaded irq handler.

Although I'm not sure if that code is good to have anywhere. Why do we even have such code in the HPD work path... We already got the HPD interrupt. What does "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" even mean...

Would it be possible to clean up the work funcs a bit (I haven't looked a the new work func yet), to remove the worst extra sleeps, and just do all that inside the threaded irq handler?

Do we need to handle interrupts while either delayed work is being done?

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Tomi

maintainer Reviewed-by on v2 7/8
#29 lore raw

Re: [PATCH v2 7/8] drm: zynqmp_dp: Split off several helper functions

In reply to Sean Anderson
Quoted 12 lines · Sean Anderson

In preparation for supporting compliance testing, split off several helper functions. No functional change intended.

---

(no changes since v1)

  drivers/gpu/drm/xlnx/zynqmp_dp.c | 49 ++++++++++++++++++++++----------
  1 file changed, 34 insertions(+), 15 deletions(-)

Tomi

maintainer
#31 lore raw

Re: [PATCH v2 8/8] drm: zynqmp_dp: Add debugfs interface for compliance testing

In reply to Sean Anderson
Quoted 2 lines · Sean Anderson

+/**
+ * enum test_pattern - Test patterns for test testing

"for test testing"? =)

drivers/gpu/drm/xlnx/zynqmp_dp.c static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work) · line 2329

Quoted 10 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +3 -0
@@ -1655,6 +2321,9 @@ static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work)
  	u8 status[DP_LINK_STATUS_SIZE + 2];
  	int err;
 
+	if (READ_ONCE(dp->ignore_hpd))
+		return;
+
  	mutex_lock(&dp->lock);
  	err = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, status,
  			       DP_LINK_STATUS_SIZE + 2);

Why do you need READ/WRITE_ONCE() for ignore_hpd?

Tomi

#4 lore raw

Re: [PATCH v2 1/8] drm: xlnx: Fix kerneldoc

In reply to Randy Dunlap
Quoted 64 lines · Randy Dunlap
Quoted 32 lines · Tomi Valkeinen
Quoted 19 lines · Sean Anderson

Fix a few errors in the kerneldoc. Mostly this addresses missing/renamed members.

---

Changes in v2:
- New

  drivers/gpu/drm/xlnx/zynqmp_disp.c  | 6 +++---
  drivers/gpu/drm/xlnx/zynqmp_dpsub.h | 1 +
  drivers/gpu/drm/xlnx/zynqmp_kms.h   | 4 ++--
  3 files changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_disp.c +0 -0
index 407bc07cec69..f79bf3fb8110 100644

drivers/gpu/drm/xlnx/zynqmp_disp.c struct zynqmp_disp_layer { · line 133

Quoted 9 lines
drivers/gpu/drm/xlnx/zynqmp_disp.c +3 -3
@@ -128,9 +128,9 @@ struct zynqmp_disp_layer {
   * struct zynqmp_disp - Display controller
   * @dev: Device structure
   * @dpsub: Display subsystem
- * @blend.base: Register I/O base address for the blender
- * @avbuf.base: Register I/O base address for the audio/video buffer manager
- * @audio.base: Registers I/O base address for the audio mixer
+ * @blend: Register I/O base address for the blender
+ * @avbuf: Register I/O base address for the audio/video buffer manager
+ * @audio: Registers I/O base address for the audio mixer

Afaics, the kernel doc guide:

Quoted 3 lines

https://docs.kernel.org/doc-guide/kernel-doc.html#nested-structs-unions

says that the current version is correct. Or is the issue that while, say, 'base' is documented, 'blend' was not?

Hi,

I would do it more like so:

---
 drivers/gpu/drm/xlnx/zynqmp_disp.c |    3 +++
 1 file changed, 3 insertions(+)

diff -- a/drivers/gpu/drm/xlnx/zynqmp_disp.c b/drivers/gpu/drm/xlnx/zynqmp_disp.c

drivers/gpu/drm/xlnx/zynqmp_disp.c +3 -0
@@ -128,8 +128,11 @@ struct zynqmp_disp_layer {
  * struct zynqmp_disp - Display controller
  * @dev: Device structure
  * @dpsub: Display subsystem
+ * @blend: blender iomem info
  * @blend.base: Register I/O base address for the blender
+ * @avbuf: audio/video buffer iomem info
  * @avbuf.base: Register I/O base address for the audio/video buffer manager
+ * @audio: audio mixer iomem info
  * @audio.base: Registers I/O base address for the audio mixer
  * @layers: Layers (planes)
  */
Quoted 2 lines

but in my testing, Sean's way or my way result in no warning/errors.

The specific errors are:

../drivers/gpu/drm/xlnx/zynqmp_disp.c:151: warning: Function parameter or struct member 'blend' not described in 'zynqmp_disp' ../drivers/gpu/drm/xlnx/zynqmp_disp.c:151: warning: Function parameter or struct member 'avbuf' not described in 'zynqmp_disp' ../drivers/gpu/drm/xlnx/zynqmp_disp.c:151: warning: Function parameter or struct member 'audio' not described in 'zynqmp_disp'

I don't see the need to document a single-member struct twice. Actually, maybe it would be better to just lift the .base member to live in zynqmp_disp. But I think that would be better in another series.

--Sean

#11 lore raw

Re: [PATCH v2 3/8] drm: zynqmp_dp: Adjust training values per-lane

In reply to Tomi Valkeinen
Quoted 52 lines · Tomi Valkeinen
Quoted 38 lines · Sean Anderson

The feedback we get from the DPRX is per-lane. Make changes using this information, instead of picking the maximum values from all lanes. This results in more-consistent training on marginal links.

---

(no changes since v1)

  drivers/gpu/drm/xlnx/zynqmp_dp.c | 23 ++++++++---------------
  1 file changed, 8 insertions(+), 15 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +7 -6
index 98a32e6a0459..8635b5673386 100644
@@ -605,28 +605,21 @@ static void zynqmp_dp_adjust_train(struct zynqmp_dp *dp,
                     u8 link_status[DP_LINK_STATUS_SIZE])
  {
      u8 *train_set = dp->train_set;
-    u8 voltage = 0, preemphasis = 0;
      u8 i;
        for (i = 0; i < dp->mode.lane_cnt; i++) {
-        u8 v = drm_dp_get_adjust_request_voltage(link_status, i);
-        u8 p = drm_dp_get_adjust_request_pre_emphasis(link_status, i);
+        u8 voltage = drm_dp_get_adjust_request_voltage(link_status, i);
+        u8 preemphasis =
+            drm_dp_get_adjust_request_pre_emphasis(link_status, i);
  -        if (v > voltage)
-            voltage = v;
+        if (voltage >= DP_TRAIN_VOLTAGE_SWING_LEVEL_3)
+            voltage |= DP_TRAIN_MAX_SWING_REACHED;
  -        if (p > preemphasis)
-            preemphasis = p;
-    }
+        if (preemphasis >= DP_TRAIN_PRE_EMPH_LEVEL_2)
+            preemphasis |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
  -    if (voltage >= DP_TRAIN_VOLTAGE_SWING_LEVEL_3)

drivers/gpu/drm/xlnx/zynqmp_dp.c static void zynqmp_dp_adjust_train(struct zynqmp_dp *dp, · line 623

Quoted 10 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +1 -6
-        voltage |= DP_TRAIN_MAX_SWING_REACHED;
-
-    if (preemphasis >= DP_TRAIN_PRE_EMPH_LEVEL_2)
-        preemphasis |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
-
-    for (i = 0; i < dp->mode.lane_cnt; i++)
          train_set[i] = voltage | preemphasis;
+    }
  }
    /**

Looks fine to me, but a few cosmetic suggestions, feel free to ignore if not to your liking:

Quoted 6 lines

1)

u8 voltage, preemphasis;

voltage = drm_dp_get_adjust_request_voltage(link_status, i); preemphasis = drm_dp_get_adjust_request_pre_emphasis(link_status, i);

If the comment here is about the line break, I agree that this looks better but the second line is over 80 characters.

Quoted 3 lines

2)

for (unsigned int i = 0; i < dp->mode.lane_cnt; i++)

Is this allowed now?

Quoted 3 lines

3)

dp->train_set[i] = voltage | preemphasis;

This would be undone in patch 7/8.

--Sean

Quoted 4 lines

Tomi

#14 lore raw

Re: [PATCH v2 4/8] drm: zynqmp_dp: Rearrange zynqmp_dp for better padding

In reply to Tomi Valkeinen
Quoted 61 lines · Tomi Valkeinen
Quoted 60 lines · Sean Anderson

Sort the members of struct zynqmp_dp to reduce padding necessary for alignment.

---

Changes in v2:
- New

  drivers/gpu/drm/xlnx/zynqmp_dp.c | 28 ++++++++++++++--------------
  1 file changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +11 -13
index 8635b5673386..f1834c8e3c02 100644
@@ -255,10 +255,10 @@ struct zynqmp_dp_link_config {
   * @fmt: format identifier string
   */
  struct zynqmp_dp_mode {
-    u8 bw_code;
-    u8 lane_cnt;
-    int pclock;
      const char *fmt;
+    int pclock;
+    u8 bw_code;
+    u8 lane_cnt;
  };
    /**
@@ -295,27 +295,27 @@ struct zynqmp_dp_config {
   * @train_set: set of training data
   */
  struct zynqmp_dp {
+    struct drm_dp_aux aux;
+    struct drm_bridge bridge;
+    struct delayed_work hpd_work;
+
+    struct drm_bridge *next_bridge;
      struct device *dev;
      struct zynqmp_dpsub *dpsub;
      void __iomem *iomem;
      struct reset_control *reset;
-    int irq;
-
-    struct drm_bridge bridge;
-    struct drm_bridge *next_bridge;
-
-    struct zynqmp_dp_config config;
-    struct drm_dp_aux aux;
      struct phy *phy[ZYNQMP_DP_MAX_LANES];
-    u8 num_lanes;
-    struct delayed_work hpd_work;
+
      enum drm_connector_status status;
+    int irq;
      bool enabled;
  -    u8 dpcd[DP_RECEIVER_CAP_SIZE];
-    struct zynqmp_dp_link_config link_config;
      struct zynqmp_dp_mode mode;
+    struct zynqmp_dp_link_config link_config;
Quoted 8 lines

drivers/gpu/drm/xlnx/zynqmp_dp.c struct zynqmp_dp_config { · line 321

Quoted 6 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +3 -0
+    struct zynqmp_dp_config config;
+    u8 dpcd[DP_RECEIVER_CAP_SIZE];
      u8 train_set[ZYNQMP_DP_MAX_LANES];
+    u8 num_lanes;
  };
    static inline struct zynqmp_dp *bridge_to_dp(struct drm_bridge *bridge)

If you change the order of the fields, you should change the order in the kernel doc accordingly.

The kernel doc is documentation, so it should continue to group similar functionality together.

Quoted 1 line

To be honest, I'm not sure if I like this patch. We have usually one instance of these structs allocated. How many bytes do we save?

Actually, the main reason is to make it easy to determine where to insert new members. Stick the pointers with the pointers, u8s with u8s, etc.

Quoted 3 lines

I'm fine with getting easy savings by changing the field order in some cases, but I think the "human" side of the order is important too: usually the fields are grouped in some way, and ordered so that the more base or generic ones are first, and fields for some specific feature are later. And fields protected by a lock should be grouped together, with their lock being first/last in that group.

Looking at the zynqmp_dp struct with this patch, I get an urge to start moving things around: dev, dpsub, iomem, etc first, hpd somewhere later. Base config fields like config, num_lanes, irq would be grouped together. Etc.

--Sean

#17 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

In reply to Tomi Valkeinen
Quoted 8 lines · Tomi Valkeinen
Quoted 4 lines · Sean Anderson

Retraining the link can take a while, and might involve waiting for DPCD reads/writes to complete. This is inappropriate for an IRQ handler. Just schedule this work for later completion. This is racy, but will be fixed in the next commit.

You should add the locks first, and use them here, rather than first adding a buggy commit and fixing it in the next one.

I didn't think I could add the locks first since I only noticed the IRQ was threaded right before sending out this series. So yeah, we could add locking, add the workqueue, and then unthread the IRQ.

Quoted 12 lines
Quoted 4 lines

---
Actually, on second look this IRQ is threaded. So why do we have a workqueue for HPD events? Maybe we should make it unthreaded?

Indeed, there's not much work being done in the IRQ handler. I don't know why it's threaded.

We could move the queued work to be inside the threaded irq handler, but with a quick look, the HPD work has lines like "msleep(100)" (and that's inside a for loop...), which is probably not a good thing to do even in threaded irq handler.

Quoted 4 lines

Although I'm not sure if that code is good to have anywhere. Why do we even have such code in the HPD work path... We already got the HPD interrupt. What does "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" even mean...

The documentation for this bit is

| HPD_STATE 0 ro 0x0 Contains the raw state of the HPD pin on the DisplayPort connector.

So I think the idea is to perform some debouncing.

Quoted 3 lines

Would it be possible to clean up the work funcs a bit (I haven't looked a the new work func yet), to remove the worst extra sleeps, and just do all that inside the threaded irq handler?

Probably not, since a HPD IRQ results in link retraining, which can take a while.

Quoted 1 line

Do we need to handle interrupts while either delayed work is being done?

Probably not.

Quoted 2 lines

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Maybe, but then we need to determine which pending events we need to handle. I think since we have only two events it will be easier to just have separate workqueues.

--Sean

#32 lore raw

Re: [PATCH v2 8/8] drm: zynqmp_dp: Add debugfs interface for compliance testing

In reply to Tomi Valkeinen
Quoted 7 lines · Tomi Valkeinen
Quoted 2 lines · Sean Anderson

+/**
+ * enum test_pattern - Test patterns for test testing

"for test testing"? =)

Quoted 11 lines

drivers/gpu/drm/xlnx/zynqmp_dp.c static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work) · line 2328

Quoted 9 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +2 -0
@@ -1655,6 +2321,9 @@ static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work)
      u8 status[DP_LINK_STATUS_SIZE + 2];
      int err;
  +    if (READ_ONCE(dp->ignore_hpd))
+        return;
+
      mutex_lock(&dp->lock);
      err = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, status,
                     DP_LINK_STATUS_SIZE + 2);

Why do you need READ/WRITE_ONCE() for ignore_hpd?

It's not protected by dp->lock so we don't have to take it for zynqmp_dp_hpd_work_func. Although maybe we should make a version of zynqmp_dp_bridge_detect which assumes we already hold the lock.

--Sean

maintainer
#33 lore raw

Re: [PATCH v2 8/8] drm: zynqmp_dp: Add debugfs interface for compliance testing

Quoted 20 lines · Sean Anderson
Quoted 7 lines · Tomi Valkeinen
Quoted 2 lines · Sean Anderson

+/**
+ * enum test_pattern - Test patterns for test testing

"for test testing"? =)

Quoted 11 lines

drivers/gpu/drm/xlnx/zynqmp_dp.c static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work) · line 2328

Quoted 9 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +2 -0
@@ -1655,6 +2321,9 @@ static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work)
       u8 status[DP_LINK_STATUS_SIZE + 2];
       int err;
   +    if (READ_ONCE(dp->ignore_hpd))
+        return;
+
       mutex_lock(&dp->lock);
       err = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, status,
                      DP_LINK_STATUS_SIZE + 2);

Why do you need READ/WRITE_ONCE() for ignore_hpd?

Quoted 3 lines

It's not protected by dp->lock so we don't have to take it for zynqmp_dp_hpd_work_func. Although maybe we should make a version of zynqmp_dp_bridge_detect which assumes we already hold the lock.

Does using the macros solve some potential issue, or is it just for documenting that this variable is accessed without lock?

Tomi

#34 lore raw

Re: [PATCH v2 8/8] drm: zynqmp_dp: Add debugfs interface for compliance testing

Quoted 21 lines · Tomi Valkeinen
Quoted 20 lines · Sean Anderson
Quoted 18 lines · Tomi Valkeinen
Quoted 2 lines · Sean Anderson

+/**
+ * enum test_pattern - Test patterns for test testing

"for test testing"? =)

drivers/gpu/drm/xlnx/zynqmp_dp.c static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work) · line 2328

Quoted 9 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +2 -0
@@ -1655,6 +2321,9 @@ static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work)
        u8 status[DP_LINK_STATUS_SIZE + 2];
        int err;
    +    if (READ_ONCE(dp->ignore_hpd))
+        return;
+
        mutex_lock(&dp->lock);
        err = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, status,
                       DP_LINK_STATUS_SIZE + 2);

Why do you need READ/WRITE_ONCE() for ignore_hpd?

Quoted 5 lines
Quoted 3 lines

It's not protected by dp->lock so we don't have to take it for zynqmp_dp_hpd_work_func. Although maybe we should make a version of zynqmp_dp_bridge_detect which assumes we already hold the lock.

Does using the macros solve some potential issue, or is it just for documenting that this variable is accessed without lock?

Without this the compiler is free to issue multiple loads for this variable, which could be incorrect.

--Sean

maintainer
#18 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

In reply to Sean Anderson
Quoted 31 lines · Sean Anderson
Quoted 8 lines · Tomi Valkeinen
Quoted 4 lines · Sean Anderson

Retraining the link can take a while, and might involve waiting for DPCD reads/writes to complete. This is inappropriate for an IRQ handler. Just schedule this work for later completion. This is racy, but will be fixed in the next commit.

You should add the locks first, and use them here, rather than first adding a buggy commit and fixing it in the next one.

I didn't think I could add the locks first since I only noticed the IRQ was threaded right before sending out this series. So yeah, we could add locking, add the workqueue, and then unthread the IRQ.

Quoted 12 lines
Quoted 4 lines

---
Actually, on second look this IRQ is threaded. So why do we have a workqueue for HPD events? Maybe we should make it unthreaded?

Indeed, there's not much work being done in the IRQ handler. I don't know why it's threaded.

We could move the queued work to be inside the threaded irq handler, but with a quick look, the HPD work has lines like "msleep(100)" (and that's inside a for loop...), which is probably not a good thing to do even in threaded irq handler.

Quoted 4 lines

Although I'm not sure if that code is good to have anywhere. Why do we even have such code in the HPD work path... We already got the HPD interrupt. What does "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" even mean...

Quoted 5 lines

The documentation for this bit is

| HPD_STATE 0 ro 0x0 Contains the raw state of the HPD pin on the DisplayPort connector.

So I think the idea is to perform some debouncing.

Hmm, it just looks a bit odd to me. It can sleep for a second. And the wording "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" makes it sound like some kind of a hack...

The docs mention debounce once:

https://docs.amd.com/r/en-US/pg299-v-dp-txss1/Hot-Plug-Detection

But it's not immediately obvious what the SW must do and what's done by the HW. Debounce is not mentioned later, e.g. in the HPD Event Handling. But if debounce is needed, wouldn't it be perhaps in a few milliseconds, instead of hundreds of milliseconds...

zynqmp_dp_bridge_detect() is used for drm_bridge_funcs.detect(), and if the cable is not connected, it'll sleep for 1 second (probably more) until returning not connected. It just doesn't sound correct to me.

Well, it's not part of this patch as such, but related to the amount of time we spend in the interrupt handler (and also the detect()).

Quoted 5 lines
Quoted 3 lines

Would it be possible to clean up the work funcs a bit (I haven't looked a the new work func yet), to remove the worst extra sleeps, and just do all that inside the threaded irq handler?

Probably not, since a HPD IRQ results in link retraining, which can take a while.

But is it any different if you have a workqueue? Isn't a threaded interrupt handler basically the same thing?

Probably at least the zynqmp_dp_hpd_work_func() could be done in the threaded irq just fine, if the insane 1s sleep can be dropped.

Quoted 10 lines
Quoted 1 line

Do we need to handle interrupts while either delayed work is being done?

Probably not.

Quoted 2 lines

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Maybe, but then we need to determine which pending events we need to handle. I think since we have only two events it will be easier to just have separate workqueues.

The less concurrency, the better...Which is why it would be nice to do it all in the threaded irq.

Tomi

#19 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

Quoted 36 lines · Tomi Valkeinen
Quoted 35 lines · Sean Anderson
Quoted 8 lines · Tomi Valkeinen
Quoted 4 lines · Sean Anderson

Retraining the link can take a while, and might involve waiting for DPCD reads/writes to complete. This is inappropriate for an IRQ handler. Just schedule this work for later completion. This is racy, but will be fixed in the next commit.

You should add the locks first, and use them here, rather than first adding a buggy commit and fixing it in the next one.

I didn't think I could add the locks first since I only noticed the IRQ was threaded right before sending out this series. So yeah, we could add locking, add the workqueue, and then unthread the IRQ.

Quoted 12 lines
Quoted 4 lines

---
Actually, on second look this IRQ is threaded. So why do we have a workqueue for HPD events? Maybe we should make it unthreaded?

Indeed, there's not much work being done in the IRQ handler. I don't know why it's threaded.

We could move the queued work to be inside the threaded irq handler, but with a quick look, the HPD work has lines like "msleep(100)" (and that's inside a for loop...), which is probably not a good thing to do even in threaded irq handler.

Quoted 4 lines

Although I'm not sure if that code is good to have anywhere. Why do we even have such code in the HPD work path... We already got the HPD interrupt. What does "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" even mean...

The documentation for this bit is

| HPD_STATE 0 ro 0x0 Contains the raw state of the HPD pin on the DisplayPort connector.

Quoted 7 lines
Quoted 1 line

So I think the idea is to perform some debouncing.

Hmm, it just looks a bit odd to me. It can sleep for a second. And the wording "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" makes it sound like some kind of a hack...

The docs mention debounce once:

https://docs.amd.com/r/en-US/pg299-v-dp-txss1/Hot-Plug-Detection

Are you sure this is the right document? This seems to be documentation for [1]. Is that instantiated as a hard block on the ZynqMP?

[1] https://www.xilinx.com/products/intellectual-property/ef-di-displayport.html

Quoted 1 line

But it's not immediately obvious what the SW must do and what's done by the HW. Debounce is not mentioned later, e.g. in the HPD Event Handling. But if debounce is needed, wouldn't it be perhaps in a few milliseconds, instead of hundreds of milliseconds...

Well, the DP spec says

| If the HPD is the result of a new device being connected, either
| directly to the Source device (signaled by a long HPD), –or– downstream
| of a Branch device (indicated by incrementing the DFP_COUNT field value
| in the DOWN_STREAM_PORT_COUNT register (DPCD 00007h[3:0]) and signaled
| by an IRQ_HPD pulse), the Source device shall read the new DisplayID or
| legacy EDID that has been made available to it to ensure that content
| being transmitted over the link is able to be properly received and
| rendered.
|
| Informative Note: If the HPD signal toggling (or bouncing) is the
|                   result of the Hot Unplug followed by Hot Plug of a
|                   cable-connector assembly, the HPD signal is likely
|                   to remain unstable during the de-bouncing period,
|                   which is in the order of tens of milliseconds. The
|                   Source device may either check the HPD signal’s
|                   stability before initiating an AUX read transaction,
|                   –or– immediately initiate the AUX read transaction
|                   after each HPD rising edge.

So a 100 ms delay seems plausible for some monitors.

That said, maybe we can just skip this and always read the DPCD.

Quoted 8 lines

zynqmp_dp_bridge_detect() is used for drm_bridge_funcs.detect(), and if the cable is not connected, it'll sleep for 1 second (probably more) until returning not connected. It just doesn't sound correct to me.

Well, it's not part of this patch as such, but related to the amount of time we spend in the interrupt handler (and also the detect()).

Quoted 4 lines
Quoted 3 lines

Would it be possible to clean up the work funcs a bit (I haven't looked a the new work func yet), to remove the worst extra sleeps, and just do all that inside the threaded irq handler?

Quoted 5 lines
Quoted 1 line

Probably not, since a HPD IRQ results in link retraining, which can take a while.

But is it any different if you have a workqueue? Isn't a threaded interrupt handler basically the same thing?

Probably at least the zynqmp_dp_hpd_work_func() could be done in the threaded irq just fine, if the insane 1s sleep can be dropped.

Anything involving AUX shouldn't been in an IRQ, since zynqmp_dp_aux_transfer will retry for up to 50ms by default.

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

Do we need to handle interrupts while either delayed work is being done?

Probably not.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Maybe, but then we need to determine which pending events we need to handle. I think since we have only two events it will be easier to just have separate workqueues.

The less concurrency, the better...Which is why it would be nice to do it all in the threaded irq.

Yeah, but we can use a mutex for this which means there is not too much interesting going on.

--Sean

maintainer
#20 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

Quoted 41 lines · Sean Anderson
Quoted 40 lines · Tomi Valkeinen
Quoted 31 lines · Sean Anderson
Quoted 8 lines · Tomi Valkeinen
Quoted 4 lines · Sean Anderson

Retraining the link can take a while, and might involve waiting for DPCD reads/writes to complete. This is inappropriate for an IRQ handler. Just schedule this work for later completion. This is racy, but will be fixed in the next commit.

You should add the locks first, and use them here, rather than first adding a buggy commit and fixing it in the next one.

I didn't think I could add the locks first since I only noticed the IRQ was threaded right before sending out this series. So yeah, we could add locking, add the workqueue, and then unthread the IRQ.

Quoted 12 lines
Quoted 4 lines

---
Actually, on second look this IRQ is threaded. So why do we have a workqueue for HPD events? Maybe we should make it unthreaded?

Indeed, there's not much work being done in the IRQ handler. I don't know why it's threaded.

We could move the queued work to be inside the threaded irq handler, but with a quick look, the HPD work has lines like "msleep(100)" (and that's inside a for loop...), which is probably not a good thing to do even in threaded irq handler.

Quoted 4 lines

Although I'm not sure if that code is good to have anywhere. Why do we even have such code in the HPD work path... We already got the HPD interrupt. What does "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" even mean...

Quoted 5 lines

The documentation for this bit is

| HPD_STATE 0 ro 0x0 Contains the raw state of the HPD pin on the DisplayPort connector.

So I think the idea is to perform some debouncing.

Hmm, it just looks a bit odd to me. It can sleep for a second. And the wording "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" makes it sound like some kind of a hack...

Quoted 7 lines
Quoted 3 lines

The docs mention debounce once:

https://docs.amd.com/r/en-US/pg299-v-dp-txss1/Hot-Plug-Detection

Are you sure this is the right document? This seems to be documentation for [1]. Is that instantiated as a hard block on the ZynqMP?

[1] https://www.xilinx.com/products/intellectual-property/ef-di-displayport.html

You're right, wrong document. The registers and bitfield names I looked at just matched, so I didn't think it through...

The right doc says even less:

https://docs.amd.com/r/en-US/ug1085-zynq-ultrascale-trm/Upon-HPD-Assertion

Quoted 23 lines
Quoted 1 line

But it's not immediately obvious what the SW must do and what's done by the HW. Debounce is not mentioned later, e.g. in the HPD Event Handling. But if debounce is needed, wouldn't it be perhaps in a few milliseconds, instead of hundreds of milliseconds...

Well, the DP spec says

| If the HPD is the result of a new device being connected, either
| directly to the Source device (signaled by a long HPD), –or– downstream
| of a Branch device (indicated by incrementing the DFP_COUNT field value
| in the DOWN_STREAM_PORT_COUNT register (DPCD 00007h[3:0]) and signaled
| by an IRQ_HPD pulse), the Source device shall read the new DisplayID or
| legacy EDID that has been made available to it to ensure that content
| being transmitted over the link is able to be properly received and
| rendered.
|
| Informative Note: If the HPD signal toggling (or bouncing) is the
|                   result of the Hot Unplug followed by Hot Plug of a
|                   cable-connector assembly, the HPD signal is likely
|                   to remain unstable during the de-bouncing period,
|                   which is in the order of tens of milliseconds. The
|                   Source device may either check the HPD signal’s
|                   stability before initiating an AUX read transaction,
|                   –or– immediately initiate the AUX read transaction
|                   after each HPD rising edge.
Quoted 1 line

So a 100 ms delay seems plausible for some monitors.

I read the text above as "it may take tens of milliseconds for HPD to stabilize". So polling it for total of 100ms sounds fine, but we're polling it for 1000ms.

And I think checking for stability is fine, but for detect() I think it goes overboard: if the cable is disconnected, every detect call spends a second checking for HPD, even if we haven't seen any sign of an HPD =).

And if we're checking the HPD stability, wouldn't we, say, poll the HPD for some time, and see if it stays the same? At the moment the code proceeds right away if HPD is high, but keeps polling if HPD is low.

Quoted 1 line

That said, maybe we can just skip this and always read the DPCD.

If the HPD is bouncing, is the AUX line also unstable?

I don't mind a HPD stability check, I think it makes sense as (I think) the HW doesn't handle de-bouncing here. I think think it could be much much shorter than what it is now, and that it would make sense to observe the HPD for a period, instead of just waiting for the HPD to go high.

But this could also be left for later, I don't think it matters in the context of this series.

Quoted 8 lines
Quoted 8 lines

zynqmp_dp_bridge_detect() is used for drm_bridge_funcs.detect(), and if the cable is not connected, it'll sleep for 1 second (probably more) until returning not connected. It just doesn't sound correct to me.

Well, it's not part of this patch as such, but related to the amount of time we spend in the interrupt handler (and also the detect()).

Quoted 4 lines
Quoted 3 lines

Would it be possible to clean up the work funcs a bit (I haven't looked a the new work func yet), to remove the worst extra sleeps, and just do all that inside the threaded irq handler?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Probably not, since a HPD IRQ results in link retraining, which can take a while.

But is it any different if you have a workqueue? Isn't a threaded interrupt handler basically the same thing?

Probably at least the zynqmp_dp_hpd_work_func() could be done in the threaded irq just fine, if the insane 1s sleep can be dropped.

Anything involving AUX shouldn't been in an IRQ, since zynqmp_dp_aux_transfer will retry for up to 50ms by default.

Perhaps. I'm still not sure if that's a problem. If a threaded irq is essentially a workqueue dedicated for this device, and we don't need to handle other irqs while the work is being done, then... What's the difference with a threaded irq and a workqueue?

Oh, but we do need to handle irqs, we have the vblank irq in there. We don't want the vblanks to stop if there's a HPD IRQ.

Btw, looks like zynqmp_dpsub_drm_handle_vblank() can sleep, so we can't move to non-threaded irq.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

Do we need to handle interrupts while either delayed work is being done?

Probably not.

Quoted 2 lines

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Maybe, but then we need to determine which pending events we need to handle. I think since we have only two events it will be easier to just have separate workqueues.

The less concurrency, the better...Which is why it would be nice to do it all in the threaded irq.

Yeah, but we can use a mutex for this which means there is not too much interesting going on.

Ok. Yep, if we get (hopefully) a single mutex with clearly defined fields that it protects, I'm ok with workqueues.

I'd still prefer just one workqueue, though...

Tomi

#21 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

Quoted 109 lines · Tomi Valkeinen
Quoted 41 lines · Sean Anderson
Quoted 40 lines · Tomi Valkeinen
Quoted 31 lines · Sean Anderson
Quoted 8 lines · Tomi Valkeinen
Quoted 4 lines · Sean Anderson

Retraining the link can take a while, and might involve waiting for DPCD reads/writes to complete. This is inappropriate for an IRQ handler. Just schedule this work for later completion. This is racy, but will be fixed in the next commit.

You should add the locks first, and use them here, rather than first adding a buggy commit and fixing it in the next one.

I didn't think I could add the locks first since I only noticed the IRQ was threaded right before sending out this series. So yeah, we could add locking, add the workqueue, and then unthread the IRQ.

Quoted 12 lines
Quoted 4 lines

---
Actually, on second look this IRQ is threaded. So why do we have a workqueue for HPD events? Maybe we should make it unthreaded?

Indeed, there's not much work being done in the IRQ handler. I don't know why it's threaded.

We could move the queued work to be inside the threaded irq handler, but with a quick look, the HPD work has lines like "msleep(100)" (and that's inside a for loop...), which is probably not a good thing to do even in threaded irq handler.

Quoted 4 lines

Although I'm not sure if that code is good to have anywhere. Why do we even have such code in the HPD work path... We already got the HPD interrupt. What does "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" even mean...

Quoted 5 lines

The documentation for this bit is

| HPD_STATE    0    ro    0x0    Contains the raw state of the HPD pin on the DisplayPort connector.

So I think the idea is to perform some debouncing.

Hmm, it just looks a bit odd to me. It can sleep for a second. And the wording "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" makes it sound like some kind of a hack...

Quoted 7 lines
Quoted 3 lines

The docs mention debounce once:

https://docs.amd.com/r/en-US/pg299-v-dp-txss1/Hot-Plug-Detection

Are you sure this is the right document? This seems to be documentation for [1]. Is that instantiated as a hard block on the ZynqMP?

[1] https://www.xilinx.com/products/intellectual-property/ef-di-displayport.html

You're right, wrong document. The registers and bitfield names I looked at just matched, so I didn't think it through...

The right doc says even less:

https://docs.amd.com/r/en-US/ug1085-zynq-ultrascale-trm/Upon-HPD-Assertion

Quoted 23 lines
Quoted 1 line

But it's not immediately obvious what the SW must do and what's done by the HW. Debounce is not mentioned later, e.g. in the HPD Event Handling. But if debounce is needed, wouldn't it be perhaps in a few milliseconds, instead of hundreds of milliseconds...

Well, the DP spec says

| If the HPD is the result of a new device being connected, either
| directly to the Source device (signaled by a long HPD), –or– downstream
| of a Branch device (indicated by incrementing the DFP_COUNT field value
| in the DOWN_STREAM_PORT_COUNT register (DPCD 00007h[3:0]) and signaled
| by an IRQ_HPD pulse), the Source device shall read the new DisplayID or
| legacy EDID that has been made available to it to ensure that content
| being transmitted over the link is able to be properly received and
| rendered.
|
| Informative Note: If the HPD signal toggling (or bouncing) is the
|                   result of the Hot Unplug followed by Hot Plug of a
|                   cable-connector assembly, the HPD signal is likely
|                   to remain unstable during the de-bouncing period,
|                   which is in the order of tens of milliseconds. The
|                   Source device may either check the HPD signal’s
|                   stability before initiating an AUX read transaction,
|                   –or– immediately initiate the AUX read transaction
|                   after each HPD rising edge.
Quoted 1 line

So a 100 ms delay seems plausible for some monitors.

I read the text above as "it may take tens of milliseconds for HPD to stabilize". So polling it for total of 100ms sounds fine, but we're polling it for 1000ms.

And I think checking for stability is fine, but for detect() I think it goes overboard: if the cable is disconnected, every detect call spends a second checking for HPD, even if we haven't seen any sign of an HPD =).

And if we're checking the HPD stability, wouldn't we, say, poll the HPD for some time, and see if it stays the same? At the moment the code proceeds right away if HPD is high, but keeps polling if HPD is low.

Quoted 1 line

That said, maybe we can just skip this and always read the DPCD.

If the HPD is bouncing, is the AUX line also unstable?

I don't mind a HPD stability check, I think it makes sense as (I think) the HW doesn't handle de-bouncing here. I think think it could be much much shorter than what it is now, and that it would make sense to observe the HPD for a period, instead of just waiting for the HPD to go high.

But this could also be left for later, I don't think it matters in the context of this series.

Quoted 14 lines
Quoted 13 lines

zynqmp_dp_bridge_detect() is used for drm_bridge_funcs.detect(), and if the cable is not connected, it'll sleep for 1 second (probably more) until returning not connected. It just doesn't sound correct to me.

Well, it's not part of this patch as such, but related to the amount of time we spend in the interrupt handler (and also the detect()).

Quoted 5 lines
Quoted 3 lines

Would it be possible to clean up the work funcs a bit (I haven't looked a the new work func yet), to remove the worst extra sleeps, and just do all that inside the threaded irq handler?

Probably not, since a HPD IRQ results in link retraining, which can take a while.

But is it any different if you have a workqueue? Isn't a threaded interrupt handler basically the same thing?

Probably at least the zynqmp_dp_hpd_work_func() could be done in the threaded irq just fine, if the insane 1s sleep can be dropped.

Quoted 8 lines
Quoted 2 lines

Anything involving AUX shouldn't been in an IRQ, since zynqmp_dp_aux_transfer will retry for up to 50ms by default.

Perhaps. I'm still not sure if that's a problem. If a threaded irq is essentially a workqueue dedicated for this device, and we don't need to handle other irqs while the work is being done, then... What's the difference with a threaded irq and a workqueue?

Oh, but we do need to handle irqs, we have the vblank irq in there. We don't want the vblanks to stop if there's a HPD IRQ.

Btw, looks like zynqmp_dpsub_drm_handle_vblank() can sleep, so we can't move to non-threaded irq.

I don't see that. We have

zynqmp_dpsub_drm_handle_vblank
drm_crtc_handle_vblank

    drm_handle_vblank
      spin_lock_irqsave(...)
      ...
      spin_lock_irqsave(...)
      vblank_disable_fn(...)
        spin_lock_irqsave(...)
        ...
        spin_lock_irqrestore(...)

so no sleeping AFAICT.

--Sean

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 1 line

Do we need to handle interrupts while either delayed work is being done?

Probably not.

Quoted 2 lines

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Maybe, but then we need to determine which pending events we need to handle. I think since we have only two events it will be easier to just have separate workqueues.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

The less concurrency, the better...Which is why it would be nice to do it all in the threaded irq.

Yeah, but we can use a mutex for this which means there is not too much interesting going on.

Ok. Yep, if we get (hopefully) a single mutex with clearly defined fields that it protects, I'm ok with workqueues.

I'd still prefer just one workqueue, though...

Yeah, but then we need a spinlock or something to tell the workqueue what it should do.

--Sean

maintainer
#22 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

Quoted 132 lines · Sean Anderson
Quoted 109 lines · Tomi Valkeinen
Quoted 41 lines · Sean Anderson
Quoted 40 lines · Tomi Valkeinen
Quoted 31 lines · Sean Anderson
Quoted 8 lines · Tomi Valkeinen
Quoted 4 lines · Sean Anderson

Retraining the link can take a while, and might involve waiting for DPCD reads/writes to complete. This is inappropriate for an IRQ handler. Just schedule this work for later completion. This is racy, but will be fixed in the next commit.

You should add the locks first, and use them here, rather than first adding a buggy commit and fixing it in the next one.

I didn't think I could add the locks first since I only noticed the IRQ was threaded right before sending out this series. So yeah, we could add locking, add the workqueue, and then unthread the IRQ.

Quoted 12 lines
Quoted 4 lines

---
Actually, on second look this IRQ is threaded. So why do we have a workqueue for HPD events? Maybe we should make it unthreaded?

Indeed, there's not much work being done in the IRQ handler. I don't know why it's threaded.

We could move the queued work to be inside the threaded irq handler, but with a quick look, the HPD work has lines like "msleep(100)" (and that's inside a for loop...), which is probably not a good thing to do even in threaded irq handler.

Quoted 4 lines

Although I'm not sure if that code is good to have anywhere. Why do we even have such code in the HPD work path... We already got the HPD interrupt. What does "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" even mean...

Quoted 5 lines

The documentation for this bit is

| HPD_STATE    0    ro    0x0    Contains the raw state of the HPD pin on the DisplayPort connector.

So I think the idea is to perform some debouncing.

Hmm, it just looks a bit odd to me. It can sleep for a second. And the wording "It takes some delay (ex, 100 ~ 500 msec) to get the HPD signal with some monitors" makes it sound like some kind of a hack...

Quoted 7 lines
Quoted 3 lines

The docs mention debounce once:

https://docs.amd.com/r/en-US/pg299-v-dp-txss1/Hot-Plug-Detection

Are you sure this is the right document? This seems to be documentation for [1]. Is that instantiated as a hard block on the ZynqMP?

[1] https://www.xilinx.com/products/intellectual-property/ef-di-displayport.html

You're right, wrong document. The registers and bitfield names I looked at just matched, so I didn't think it through...

The right doc says even less:

https://docs.amd.com/r/en-US/ug1085-zynq-ultrascale-trm/Upon-HPD-Assertion

Quoted 23 lines
Quoted 1 line

But it's not immediately obvious what the SW must do and what's done by the HW. Debounce is not mentioned later, e.g. in the HPD Event Handling. But if debounce is needed, wouldn't it be perhaps in a few milliseconds, instead of hundreds of milliseconds...

Well, the DP spec says

| If the HPD is the result of a new device being connected, either
| directly to the Source device (signaled by a long HPD), –or– downstream
| of a Branch device (indicated by incrementing the DFP_COUNT field value
| in the DOWN_STREAM_PORT_COUNT register (DPCD 00007h[3:0]) and signaled
| by an IRQ_HPD pulse), the Source device shall read the new DisplayID or
| legacy EDID that has been made available to it to ensure that content
| being transmitted over the link is able to be properly received and
| rendered.
|
| Informative Note: If the HPD signal toggling (or bouncing) is the
|                   result of the Hot Unplug followed by Hot Plug of a
|                   cable-connector assembly, the HPD signal is likely
|                   to remain unstable during the de-bouncing period,
|                   which is in the order of tens of milliseconds. The
|                   Source device may either check the HPD signal’s
|                   stability before initiating an AUX read transaction,
|                   –or– immediately initiate the AUX read transaction
|                   after each HPD rising edge.
Quoted 1 line

So a 100 ms delay seems plausible for some monitors.

I read the text above as "it may take tens of milliseconds for HPD to stabilize". So polling it for total of 100ms sounds fine, but we're polling it for 1000ms.

And I think checking for stability is fine, but for detect() I think it goes overboard: if the cable is disconnected, every detect call spends a second checking for HPD, even if we haven't seen any sign of an HPD =).

And if we're checking the HPD stability, wouldn't we, say, poll the HPD for some time, and see if it stays the same? At the moment the code proceeds right away if HPD is high, but keeps polling if HPD is low.

Quoted 1 line

That said, maybe we can just skip this and always read the DPCD.

If the HPD is bouncing, is the AUX line also unstable?

I don't mind a HPD stability check, I think it makes sense as (I think) the HW doesn't handle de-bouncing here. I think think it could be much much shorter than what it is now, and that it would make sense to observe the HPD for a period, instead of just waiting for the HPD to go high.

But this could also be left for later, I don't think it matters in the context of this series.

Quoted 14 lines
Quoted 13 lines

zynqmp_dp_bridge_detect() is used for drm_bridge_funcs.detect(), and if the cable is not connected, it'll sleep for 1 second (probably more) until returning not connected. It just doesn't sound correct to me.

Well, it's not part of this patch as such, but related to the amount of time we spend in the interrupt handler (and also the detect()).

Quoted 5 lines
Quoted 3 lines

Would it be possible to clean up the work funcs a bit (I haven't looked a the new work func yet), to remove the worst extra sleeps, and just do all that inside the threaded irq handler?

Probably not, since a HPD IRQ results in link retraining, which can take a while.

But is it any different if you have a workqueue? Isn't a threaded interrupt handler basically the same thing?

Probably at least the zynqmp_dp_hpd_work_func() could be done in the threaded irq just fine, if the insane 1s sleep can be dropped.

Quoted 8 lines
Quoted 2 lines

Anything involving AUX shouldn't been in an IRQ, since zynqmp_dp_aux_transfer will retry for up to 50ms by default.

Perhaps. I'm still not sure if that's a problem. If a threaded irq is essentially a workqueue dedicated for this device, and we don't need to handle other irqs while the work is being done, then... What's the difference with a threaded irq and a workqueue?

Oh, but we do need to handle irqs, we have the vblank irq in there. We don't want the vblanks to stop if there's a HPD IRQ.

Btw, looks like zynqmp_dpsub_drm_handle_vblank() can sleep, so we can't move to non-threaded irq.

I don't see that. We have

zynqmp_dpsub_drm_handle_vblank
drm_crtc_handle_vblank

     drm_handle_vblank
       spin_lock_irqsave(...)
       ...
       spin_lock_irqsave(...)
       vblank_disable_fn(...)
         spin_lock_irqsave(...)
         ...
         spin_lock_irqrestore(...)
Quoted 1 line

so no sleeping AFAICT.

Sorry, I don't know what code-path I was following where I saw mutexes. I shouldn't look at code so late at night...

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 1 line

Do we need to handle interrupts while either delayed work is being done?

Probably not.

Quoted 2 lines

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Maybe, but then we need to determine which pending events we need to handle. I think since we have only two events it will be easier to just have separate workqueues.

The less concurrency, the better...Which is why it would be nice to do it all in the threaded irq.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Yeah, but we can use a mutex for this which means there is not too much interesting going on.

Ok. Yep, if we get (hopefully) a single mutex with clearly defined fields that it protects, I'm ok with workqueues.

I'd still prefer just one workqueue, though...

Yeah, but then we need a spinlock or something to tell the workqueue what it should do.

Yep. We could also always look at the HPD (if we drop the big sleeps) in the wq, and have a flag for the HPD IRQ, which would reduce the state to a single bit.

Tomi

maintainer
#5 lore raw

Re: [PATCH v2 1/8] drm: xlnx: Fix kerneldoc

In reply to Sean Anderson
Quoted 70 lines · Sean Anderson
Quoted 64 lines · Randy Dunlap
Quoted 32 lines · Tomi Valkeinen
Quoted 19 lines · Sean Anderson

Fix a few errors in the kerneldoc. Mostly this addresses missing/renamed members.

---

Changes in v2:
- New

   drivers/gpu/drm/xlnx/zynqmp_disp.c  | 6 +++---
   drivers/gpu/drm/xlnx/zynqmp_dpsub.h | 1 +
   drivers/gpu/drm/xlnx/zynqmp_kms.h   | 4 ++--
   3 files changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_disp.c +0 -0
index 407bc07cec69..f79bf3fb8110 100644

drivers/gpu/drm/xlnx/zynqmp_disp.c struct zynqmp_disp_layer { · line 133

Quoted 9 lines
drivers/gpu/drm/xlnx/zynqmp_disp.c +3 -3
@@ -128,9 +128,9 @@ struct zynqmp_disp_layer {
    * struct zynqmp_disp - Display controller
    * @dev: Device structure
    * @dpsub: Display subsystem
- * @blend.base: Register I/O base address for the blender
- * @avbuf.base: Register I/O base address for the audio/video buffer manager
- * @audio.base: Registers I/O base address for the audio mixer
+ * @blend: Register I/O base address for the blender
+ * @avbuf: Register I/O base address for the audio/video buffer manager
+ * @audio: Registers I/O base address for the audio mixer

Afaics, the kernel doc guide:

Quoted 3 lines

https://docs.kernel.org/doc-guide/kernel-doc.html#nested-structs-unions

says that the current version is correct. Or is the issue that while, say, 'base' is documented, 'blend' was not?

Hi,

I would do it more like so:

---
  drivers/gpu/drm/xlnx/zynqmp_disp.c |    3 +++
  1 file changed, 3 insertions(+)

diff -- a/drivers/gpu/drm/xlnx/zynqmp_disp.c b/drivers/gpu/drm/xlnx/zynqmp_disp.c

drivers/gpu/drm/xlnx/zynqmp_disp.c +3 -0
@@ -128,8 +128,11 @@ struct zynqmp_disp_layer {
   * struct zynqmp_disp - Display controller
   * @dev: Device structure
   * @dpsub: Display subsystem
+ * @blend: blender iomem info
   * @blend.base: Register I/O base address for the blender
+ * @avbuf: audio/video buffer iomem info
   * @avbuf.base: Register I/O base address for the audio/video buffer manager
+ * @audio: audio mixer iomem info
   * @audio.base: Registers I/O base address for the audio mixer
   * @layers: Layers (planes)
   */
Quoted 2 lines

but in my testing, Sean's way or my way result in no warning/errors.

The specific errors are:

Quoted 5 lines

../drivers/gpu/drm/xlnx/zynqmp_disp.c:151: warning: Function parameter or struct member 'blend' not described in 'zynqmp_disp' ../drivers/gpu/drm/xlnx/zynqmp_disp.c:151: warning: Function parameter or struct member 'avbuf' not described in 'zynqmp_disp' ../drivers/gpu/drm/xlnx/zynqmp_disp.c:151: warning: Function parameter or struct member 'audio' not described in 'zynqmp_disp'

I don't see the need to document a single-member struct twice. Actually,

But if only the struct is documented, then we're documenting the wrong thing. A tool showing to the user what blend.base is would miss that documentation.

Quoted 2 lines

maybe it would be better to just lift the .base member to live in zynqmp_disp. But I think that would be better in another series.

Yes, there's not much point with the structs.

Tomi

#6 lore raw

Re: [PATCH v2 1/8] drm: xlnx: Fix kerneldoc

Quoted 71 lines · Tomi Valkeinen
Quoted 70 lines · Sean Anderson
Quoted 64 lines · Randy Dunlap
Quoted 32 lines · Tomi Valkeinen
Quoted 19 lines · Sean Anderson

Fix a few errors in the kerneldoc. Mostly this addresses missing/renamed members.

---

Changes in v2:
- New

   drivers/gpu/drm/xlnx/zynqmp_disp.c  | 6 +++---
   drivers/gpu/drm/xlnx/zynqmp_dpsub.h | 1 +
   drivers/gpu/drm/xlnx/zynqmp_kms.h   | 4 ++--
   3 files changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_disp.c +0 -0
index 407bc07cec69..f79bf3fb8110 100644

drivers/gpu/drm/xlnx/zynqmp_disp.c struct zynqmp_disp_layer { · line 133

Quoted 9 lines
drivers/gpu/drm/xlnx/zynqmp_disp.c +3 -3
@@ -128,9 +128,9 @@ struct zynqmp_disp_layer {
    * struct zynqmp_disp - Display controller
    * @dev: Device structure
    * @dpsub: Display subsystem
- * @blend.base: Register I/O base address for the blender
- * @avbuf.base: Register I/O base address for the audio/video buffer manager
- * @audio.base: Registers I/O base address for the audio mixer
+ * @blend: Register I/O base address for the blender
+ * @avbuf: Register I/O base address for the audio/video buffer manager
+ * @audio: Registers I/O base address for the audio mixer

Afaics, the kernel doc guide:

Quoted 3 lines

https://docs.kernel.org/doc-guide/kernel-doc.html#nested-structs-unions

says that the current version is correct. Or is the issue that while, say, 'base' is documented, 'blend' was not?

Hi,

I would do it more like so:

---
  drivers/gpu/drm/xlnx/zynqmp_disp.c |    3 +++
  1 file changed, 3 insertions(+)

diff -- a/drivers/gpu/drm/xlnx/zynqmp_disp.c b/drivers/gpu/drm/xlnx/zynqmp_disp.c

drivers/gpu/drm/xlnx/zynqmp_disp.c +3 -0
@@ -128,8 +128,11 @@ struct zynqmp_disp_layer {
   * struct zynqmp_disp - Display controller
   * @dev: Device structure
   * @dpsub: Display subsystem
+ * @blend: blender iomem info
   * @blend.base: Register I/O base address for the blender
+ * @avbuf: audio/video buffer iomem info
   * @avbuf.base: Register I/O base address for the audio/video buffer manager
+ * @audio: audio mixer iomem info
   * @audio.base: Registers I/O base address for the audio mixer
   * @layers: Layers (planes)
   */
Quoted 2 lines

but in my testing, Sean's way or my way result in no warning/errors.

The specific errors are:

Quoted 7 lines
Quoted 5 lines

../drivers/gpu/drm/xlnx/zynqmp_disp.c:151: warning: Function parameter or struct member 'blend' not described in 'zynqmp_disp' ../drivers/gpu/drm/xlnx/zynqmp_disp.c:151: warning: Function parameter or struct member 'avbuf' not described in 'zynqmp_disp' ../drivers/gpu/drm/xlnx/zynqmp_disp.c:151: warning: Function parameter or struct member 'audio' not described in 'zynqmp_disp'

I don't see the need to document a single-member struct twice. Actually,

But if only the struct is documented, then we're documenting the wrong thing. A tool showing to the user what blend.base is would miss that documentation.

Are there any such tools? kerneldoc e.g. just prints the definition and then a list of members with documentation. So from the user's perspective the only thing which changes is the name.

--Sean

Quoted 7 lines
Quoted 2 lines

maybe it would be better to just lift the .base member to live in zynqmp_disp. But I think that would be better in another series.

Yes, there's not much point with the structs.

Tomi

#23 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

In reply to Tomi Valkeinen
Quoted 23 lines · Tomi Valkeinen
Quoted 22 lines · Sean Anderson
Quoted 21 lines · Tomi Valkeinen
Quoted 19 lines · Sean Anderson
Quoted 7 lines · Tomi Valkeinen
Quoted 6 lines · Sean Anderson
Quoted 2 lines · Tomi Valkeinen

On 20/03/2024 00:51, Sean Anderson wrote:
Do we need to handle interrupts while either delayed work is being done?

Probably not.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Maybe, but then we need to determine which pending events we need to handle. I think since we have only two events it will be easier to just have separate workqueues.

The less concurrency, the better...Which is why it would be nice to do it all in the threaded irq.

Yeah, but we can use a mutex for this which means there is not too much interesting going on.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Ok. Yep, if we get (hopefully) a single mutex with clearly defined fields that it protects, I'm ok with workqueues.

I'd still prefer just one workqueue, though...

Yeah, but then we need a spinlock or something to tell the workqueue what it should do.

Yep. We could also always look at the HPD (if we drop the big sleeps) in the wq, and have a flag for the HPD IRQ, which would reduce the state to a single bit.

How about something like

zynqmp_dp_irq_handler(...)

{
	/* Read status and handle underflow/overflow/vblank */

	status &= ZYNQMP_DP_INT_HPD_EVENT | ZYNQMP_DP_INT_HPD_IRQ;
	if (status) {
		atomic_or(status, &dp->status);
		return IRQ_WAKE_THREAD;
	}

	return IRQ_HANDLED;
}

zynqmp_dp_thread_handler(...)

{
	status = atomic_xchg(&dp->status, 0);
	/* process HPD stuff */
}

which gets rid of the workqueue too.

--Sean

maintainer
#24 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

Quoted 47 lines · Sean Anderson
Quoted 23 lines · Tomi Valkeinen
Quoted 22 lines · Sean Anderson
Quoted 21 lines · Tomi Valkeinen
Quoted 19 lines · Sean Anderson
Quoted 7 lines · Tomi Valkeinen
Quoted 6 lines · Sean Anderson
Quoted 2 lines · Tomi Valkeinen

On 20/03/2024 00:51, Sean Anderson wrote:
Do we need to handle interrupts while either delayed work is being done?

Probably not.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Maybe, but then we need to determine which pending events we need to handle. I think since we have only two events it will be easier to just have separate workqueues.

The less concurrency, the better...Which is why it would be nice to do it all in the threaded irq.

Yeah, but we can use a mutex for this which means there is not too much interesting going on.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Ok. Yep, if we get (hopefully) a single mutex with clearly defined fields that it protects, I'm ok with workqueues.

I'd still prefer just one workqueue, though...

Yeah, but then we need a spinlock or something to tell the workqueue what it should do.

Yep. We could also always look at the HPD (if we drop the big sleeps) in the wq, and have a flag for the HPD IRQ, which would reduce the state to a single bit.

How about something like

zynqmp_dp_irq_handler(...)

{
	/* Read status and handle underflow/overflow/vblank */

	status &= ZYNQMP_DP_INT_HPD_EVENT | ZYNQMP_DP_INT_HPD_IRQ;
	if (status) {
		atomic_or(status, &dp->status);
		return IRQ_WAKE_THREAD;
	}

	return IRQ_HANDLED;
}
Quoted 7 lines

zynqmp_dp_thread_handler(...)

{
	status = atomic_xchg(&dp->status, 0);
	/* process HPD stuff */
}

which gets rid of the workqueue too.

I like it. We can't use IRQF_ONESHOT, as that would keep the irq masked while the threaded handler is being ran. I don't think that's a problem, but just something to keep in mind that both handlers can run concurrently.

Tomi

#25 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

Quoted 54 lines · Tomi Valkeinen
Quoted 53 lines · Sean Anderson
Quoted 23 lines · Tomi Valkeinen
Quoted 22 lines · Sean Anderson
Quoted 21 lines · Tomi Valkeinen
Quoted 19 lines · Sean Anderson
Quoted 7 lines · Tomi Valkeinen
Quoted 6 lines · Sean Anderson
Quoted 2 lines · Tomi Valkeinen

On 20/03/2024 00:51, Sean Anderson wrote:
Do we need to handle interrupts while either delayed work is being done?

Probably not.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Maybe, but then we need to determine which pending events we need to handle. I think since we have only two events it will be easier to just have separate workqueues.

The less concurrency, the better...Which is why it would be nice to do it all in the threaded irq.

Yeah, but we can use a mutex for this which means there is not too much interesting going on.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Ok. Yep, if we get (hopefully) a single mutex with clearly defined fields that it protects, I'm ok with workqueues.

I'd still prefer just one workqueue, though...

Yeah, but then we need a spinlock or something to tell the workqueue what it should do.

Yep. We could also always look at the HPD (if we drop the big sleeps) in the wq, and have a flag for the HPD IRQ, which would reduce the state to a single bit.

How about something like

zynqmp_dp_irq_handler(...)

{
    /* Read status and handle underflow/overflow/vblank */

    status &= ZYNQMP_DP_INT_HPD_EVENT | ZYNQMP_DP_INT_HPD_IRQ;
    if (status) {
        atomic_or(status, &dp->status);
        return IRQ_WAKE_THREAD;
    }

    return IRQ_HANDLED;
}

zynqmp_dp_thread_handler(...)

{
    status = atomic_xchg(&dp->status, 0);
    /* process HPD stuff */
}
Quoted 3 lines
Quoted 1 line

which gets rid of the workqueue too.

I like it. We can't use IRQF_ONESHOT, as that would keep the irq masked while the threaded handler is being ran. I don't think that's a problem, but just something to keep in mind that both handlers can run concurrently.

Actually, I'm not sure we can do it like this. Imagine we have something like

CPU 0 CPU 1
zynqmp_dp_thread_handler()
atomic_xchg()

			   __handle_irq_event_percpu 
                             zynqmp_dp_irq_handler()
                               atomic_or()
                               return IRQ_WAIT_THREAD
                             __irq_wake_thread()
                               test_and_set_bit(IRQTF_RUNTHREAD, ...)
                               return

return IRQ_HANDLED

and whoops we now have bits set in dp->status but the thread isn't running. I don't think there's a way to fix this without locking (or two works). TBH I am leaning towards just having two works; it is a clean implementation. We can also convert to use work_struct instead of delayed_work, since we never set a delay.

--Sean

maintainer
#26 lore raw

Re: [PATCH v2 5/8] drm: zynqmp_dp: Don't retrain the link in our IRQ

Quoted 72 lines · Sean Anderson
Quoted 54 lines · Tomi Valkeinen
Quoted 53 lines · Sean Anderson
Quoted 23 lines · Tomi Valkeinen
Quoted 22 lines · Sean Anderson
Quoted 21 lines · Tomi Valkeinen
Quoted 19 lines · Sean Anderson
Quoted 7 lines · Tomi Valkeinen
Quoted 6 lines · Sean Anderson
Quoted 2 lines · Tomi Valkeinen

On 20/03/2024 00:51, Sean Anderson wrote:
Do we need to handle interrupts while either delayed work is being done?

Probably not.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

If we do need a delayed work, would just one work be enough which handles both HPD_EVENT and HPD_IRQ, instead of two?

Maybe, but then we need to determine which pending events we need to handle. I think since we have only two events it will be easier to just have separate workqueues.

The less concurrency, the better...Which is why it would be nice to do it all in the threaded irq.

Yeah, but we can use a mutex for this which means there is not too much interesting going on.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Ok. Yep, if we get (hopefully) a single mutex with clearly defined fields that it protects, I'm ok with workqueues.

I'd still prefer just one workqueue, though...

Yeah, but then we need a spinlock or something to tell the workqueue what it should do.

Yep. We could also always look at the HPD (if we drop the big sleeps) in the wq, and have a flag for the HPD IRQ, which would reduce the state to a single bit.

How about something like

zynqmp_dp_irq_handler(...)

{
     /* Read status and handle underflow/overflow/vblank */

     status &= ZYNQMP_DP_INT_HPD_EVENT | ZYNQMP_DP_INT_HPD_IRQ;
     if (status) {
         atomic_or(status, &dp->status);
         return IRQ_WAKE_THREAD;
     }

     return IRQ_HANDLED;
}

zynqmp_dp_thread_handler(...)

{
     status = atomic_xchg(&dp->status, 0);
     /* process HPD stuff */
}
Quoted 3 lines
Quoted 1 line

which gets rid of the workqueue too.

I like it. We can't use IRQF_ONESHOT, as that would keep the irq masked while the threaded handler is being ran. I don't think that's a problem, but just something to keep in mind that both handlers can run concurrently.

Actually, I'm not sure we can do it like this. Imagine we have something like

CPU 0 CPU 1
zynqmp_dp_thread_handler()
atomic_xchg()

			   __handle_irq_event_percpu
                              zynqmp_dp_irq_handler()
                                atomic_or()
                                return IRQ_WAIT_THREAD
                              __irq_wake_thread()
                                test_and_set_bit(IRQTF_RUNTHREAD, ...)
                                return
Quoted 4 lines

return IRQ_HANDLED

and whoops we now have bits set in dp->status but the thread isn't running. I don't think there's a way to fix this without locking (or two

In your example above, the IRQTF_RUNTHREAD has been cleared by the threaded-irq before calling zynqmp_dp_thread_handler. So the hard-irq will set that flag before the zynqmp_dp_thread_handler() returns.

When zynqmp_dp_thread_handler() returns, the execution will go to irq_wait_for_interrupt(). That function will notice the IRQTF_RUNTHREAD flag (and clear it), and run the zynqmp_dp_thread_handler() again.

So if I'm not mistaken, when the hard-irq function returns IRQ_WAKE_THREAD, it's always guaranteed that a "fresh" run of the threaded handler will be ran.

I think that makes sense, as I'm not sure how threaded handlers without IRQF_ONESHOT could be used if that were not the case. I hope I'm right in my analysis =).

Tomi