From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> To: dri-devel@lists.freedesktop.org Cc: linux-sh@vger.kernel.org Subject: [PATCH 06/38] drm: adv7511: Fix nested sleep when reading EDID Date: Wed, 25 Feb 2015 21:54:26 +0000 [thread overview] Message-ID: <1424901298-6829-7-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw) In-Reply-To: <1424901298-6829-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> The EDID read code waits for the read completion interrupt to occur using wait_event_interruptible(). The condition passed to the macro reads I2C registers. This results in sleeping with the task state set to TASK_INTERRUPTIBLE, triggering a WARN_ON() introduced in commit 8eb23b9f35aae ("sched: Debug nested sleeps"). Fix this by reworking the EDID read code. Instead of checking whether the read is complete through I2C reads, handle the interrupt registers in the interrupt handler and update a new edid_read flag accordingly. As a side effect both the IRQ and polling code paths now process the interrupt sources through the same code path, simplifying the code. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> --- drivers/gpu/drm/i2c/adv7511.c | 96 +++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/drivers/gpu/drm/i2c/adv7511.c b/drivers/gpu/drm/i2c/adv7511.c index 5109c215018e..60ab1f75d58e 100644 --- a/drivers/gpu/drm/i2c/adv7511.c +++ b/drivers/gpu/drm/i2c/adv7511.c @@ -33,6 +33,7 @@ struct adv7511 { unsigned int current_edid_segment; uint8_t edid_buf[256]; + bool edid_read; wait_queue_head_t wq; struct drm_encoder *encoder; @@ -379,69 +380,71 @@ static bool adv7511_hpd(struct adv7511 *adv7511) return false; } -static irqreturn_t adv7511_irq_handler(int irq, void *devid) -{ - struct adv7511 *adv7511 = devid; - - if (adv7511_hpd(adv7511)) - drm_helper_hpd_irq_event(adv7511->encoder->dev); - - wake_up_all(&adv7511->wq); - - return IRQ_HANDLED; -} - -static unsigned int adv7511_is_interrupt_pending(struct adv7511 *adv7511, - unsigned int irq) +static int adv7511_irq_process(struct adv7511 *adv7511) { unsigned int irq0, irq1; - unsigned int pending; int ret; ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0); if (ret < 0) - return 0; + return ret; + ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(1), &irq1); if (ret < 0) - return 0; + return ret; + + regmap_write(adv7511->regmap, ADV7511_REG_INT(0), irq0); + regmap_write(adv7511->regmap, ADV7511_REG_INT(1), irq1); + + if (irq0 & ADV7511_INT0_HDP) + drm_helper_hpd_irq_event(adv7511->encoder->dev); + + if (irq0 & ADV7511_INT0_EDID_READY || irq1 & ADV7511_INT1_DDC_ERROR) { + adv7511->edid_read = true; - pending = (irq1 << 8) | irq0; + if (adv7511->i2c_main->irq) + wake_up_all(&adv7511->wq); + } - return pending & irq; + return 0; } -static int adv7511_wait_for_interrupt(struct adv7511 *adv7511, int irq, - int timeout) +static irqreturn_t adv7511_irq_handler(int irq, void *devid) +{ + struct adv7511 *adv7511 = devid; + int ret; + + ret = adv7511_irq_process(adv7511); + return ret < 0 ? IRQ_NONE : IRQ_HANDLED; +} + +/* ----------------------------------------------------------------------------- + * EDID retrieval + */ + +static int adv7511_wait_for_edid(struct adv7511 *adv7511, int timeout) { - unsigned int pending; int ret; if (adv7511->i2c_main->irq) { ret = wait_event_interruptible_timeout(adv7511->wq, - adv7511_is_interrupt_pending(adv7511, irq), - msecs_to_jiffies(timeout)); - if (ret <= 0) - return 0; - pending = adv7511_is_interrupt_pending(adv7511, irq); + adv7511->edid_read, msecs_to_jiffies(timeout)); } else { - if (timeout < 25) - timeout = 25; - do { - pending = adv7511_is_interrupt_pending(adv7511, irq); - if (pending) + for (; timeout > 0; timeout -= 25) { + ret = adv7511_irq_process(adv7511); + if (ret < 0) + break; + + if (adv7511->edid_read) break; + msleep(25); - timeout -= 25; - } while (timeout >= 25); + } } - return pending; + return adv7511->edid_read ? 0 : -EIO; } -/* ----------------------------------------------------------------------------- - * EDID retrieval - */ - static int adv7511_get_edid_block(void *data, u8 *buf, unsigned int block, size_t len) { @@ -463,21 +466,14 @@ static int adv7511_get_edid_block(void *data, u8 *buf, unsigned int block, return ret; if (status != 2) { + adv7511->edid_read = false; regmap_write(adv7511->regmap, ADV7511_REG_EDID_SEGMENT, block); - ret = adv7511_wait_for_interrupt(adv7511, - ADV7511_INT0_EDID_READY | - (ADV7511_INT1_DDC_ERROR << 8), 200); - - if (!(ret & ADV7511_INT0_EDID_READY)) - return -EIO; + ret = adv7511_wait_for_edid(adv7511, 200); + if (ret < 0) + return ret; } - regmap_write(adv7511->regmap, ADV7511_REG_INT(0), - ADV7511_INT0_EDID_READY); - regmap_write(adv7511->regmap, ADV7511_REG_INT(1), - ADV7511_INT1_DDC_ERROR); - /* Break this apart, hopefully more I2C controllers will * support 64 byte transfers than 256 byte transfers */ -- 2.0.5
WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> To: dri-devel@lists.freedesktop.org Cc: linux-sh@vger.kernel.org Subject: [PATCH 06/38] drm: adv7511: Fix nested sleep when reading EDID Date: Wed, 25 Feb 2015 23:54:26 +0200 [thread overview] Message-ID: <1424901298-6829-7-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw) In-Reply-To: <1424901298-6829-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> The EDID read code waits for the read completion interrupt to occur using wait_event_interruptible(). The condition passed to the macro reads I2C registers. This results in sleeping with the task state set to TASK_INTERRUPTIBLE, triggering a WARN_ON() introduced in commit 8eb23b9f35aae ("sched: Debug nested sleeps"). Fix this by reworking the EDID read code. Instead of checking whether the read is complete through I2C reads, handle the interrupt registers in the interrupt handler and update a new edid_read flag accordingly. As a side effect both the IRQ and polling code paths now process the interrupt sources through the same code path, simplifying the code. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> --- drivers/gpu/drm/i2c/adv7511.c | 96 +++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/drivers/gpu/drm/i2c/adv7511.c b/drivers/gpu/drm/i2c/adv7511.c index 5109c215018e..60ab1f75d58e 100644 --- a/drivers/gpu/drm/i2c/adv7511.c +++ b/drivers/gpu/drm/i2c/adv7511.c @@ -33,6 +33,7 @@ struct adv7511 { unsigned int current_edid_segment; uint8_t edid_buf[256]; + bool edid_read; wait_queue_head_t wq; struct drm_encoder *encoder; @@ -379,69 +380,71 @@ static bool adv7511_hpd(struct adv7511 *adv7511) return false; } -static irqreturn_t adv7511_irq_handler(int irq, void *devid) -{ - struct adv7511 *adv7511 = devid; - - if (adv7511_hpd(adv7511)) - drm_helper_hpd_irq_event(adv7511->encoder->dev); - - wake_up_all(&adv7511->wq); - - return IRQ_HANDLED; -} - -static unsigned int adv7511_is_interrupt_pending(struct adv7511 *adv7511, - unsigned int irq) +static int adv7511_irq_process(struct adv7511 *adv7511) { unsigned int irq0, irq1; - unsigned int pending; int ret; ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0); if (ret < 0) - return 0; + return ret; + ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(1), &irq1); if (ret < 0) - return 0; + return ret; + + regmap_write(adv7511->regmap, ADV7511_REG_INT(0), irq0); + regmap_write(adv7511->regmap, ADV7511_REG_INT(1), irq1); + + if (irq0 & ADV7511_INT0_HDP) + drm_helper_hpd_irq_event(adv7511->encoder->dev); + + if (irq0 & ADV7511_INT0_EDID_READY || irq1 & ADV7511_INT1_DDC_ERROR) { + adv7511->edid_read = true; - pending = (irq1 << 8) | irq0; + if (adv7511->i2c_main->irq) + wake_up_all(&adv7511->wq); + } - return pending & irq; + return 0; } -static int adv7511_wait_for_interrupt(struct adv7511 *adv7511, int irq, - int timeout) +static irqreturn_t adv7511_irq_handler(int irq, void *devid) +{ + struct adv7511 *adv7511 = devid; + int ret; + + ret = adv7511_irq_process(adv7511); + return ret < 0 ? IRQ_NONE : IRQ_HANDLED; +} + +/* ----------------------------------------------------------------------------- + * EDID retrieval + */ + +static int adv7511_wait_for_edid(struct adv7511 *adv7511, int timeout) { - unsigned int pending; int ret; if (adv7511->i2c_main->irq) { ret = wait_event_interruptible_timeout(adv7511->wq, - adv7511_is_interrupt_pending(adv7511, irq), - msecs_to_jiffies(timeout)); - if (ret <= 0) - return 0; - pending = adv7511_is_interrupt_pending(adv7511, irq); + adv7511->edid_read, msecs_to_jiffies(timeout)); } else { - if (timeout < 25) - timeout = 25; - do { - pending = adv7511_is_interrupt_pending(adv7511, irq); - if (pending) + for (; timeout > 0; timeout -= 25) { + ret = adv7511_irq_process(adv7511); + if (ret < 0) + break; + + if (adv7511->edid_read) break; + msleep(25); - timeout -= 25; - } while (timeout >= 25); + } } - return pending; + return adv7511->edid_read ? 0 : -EIO; } -/* ----------------------------------------------------------------------------- - * EDID retrieval - */ - static int adv7511_get_edid_block(void *data, u8 *buf, unsigned int block, size_t len) { @@ -463,21 +466,14 @@ static int adv7511_get_edid_block(void *data, u8 *buf, unsigned int block, return ret; if (status != 2) { + adv7511->edid_read = false; regmap_write(adv7511->regmap, ADV7511_REG_EDID_SEGMENT, block); - ret = adv7511_wait_for_interrupt(adv7511, - ADV7511_INT0_EDID_READY | - (ADV7511_INT1_DDC_ERROR << 8), 200); - - if (!(ret & ADV7511_INT0_EDID_READY)) - return -EIO; + ret = adv7511_wait_for_edid(adv7511, 200); + if (ret < 0) + return ret; } - regmap_write(adv7511->regmap, ADV7511_REG_INT(0), - ADV7511_INT0_EDID_READY); - regmap_write(adv7511->regmap, ADV7511_REG_INT(1), - ADV7511_INT1_DDC_ERROR); - /* Break this apart, hopefully more I2C controllers will * support 64 byte transfers than 256 byte transfers */ -- 2.0.5
next prev parent reply other threads:[~2015-02-25 21:54 UTC|newest] Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-02-25 21:54 [PATCH 00/38] Renesas R-Car DU atomic updates support Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 01/38] drm/atomic: Rename drm_atomic_helper_commit_pre_planes() state argument Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 02/38] drm/atomic-helper: Rename commmit_post/pre_planes Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 03/38] drm/atomic-helpers: make mode_set hooks optional Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 04/38] drm/atomic-helpers: Fix documentation typos and wrong copy&paste Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 05/38] drm: adv7511: Fix DDC error interrupt handling Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart [this message] 2015-02-25 21:54 ` [PATCH 06/38] drm: adv7511: Fix nested sleep when reading EDID Laurent Pinchart 2015-02-25 21:54 ` [PATCH 07/38] drm: rcar-du: Don't disable unused functions at init time Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 08/38] drm: rcar-du: Remove drm_fbdev_cma_restore_mode() call " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 09/38] drm: rcar-du: Don't set connector->encoder " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 10/38] drm: rcar-du: Reorder CRTC functions Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 11/38] drm: rcar-du: Wait for page flip completion when turning the CRTC off Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 12/38] drm: rcar-du: Turn vblank on/off when enabling/disabling CRTC Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 13/38] drm: rcar-du: Disable fbdev emulation when no connector is present Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 14/38] drm: rcar-du: Define macros for the max number of groups, CRTCs and LVDS Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 15/38] drm: rcar-du: Implement universal plane support Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 16/38] drm: rcar-du: Fix hardware plane allocation Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 17/38] drm: rcar-du: Implement planes atomic operations Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 18/38] drm: rcar-du: Handle primary plane config through atomic plane ops Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 19/38] drm: rcar-du: Wire up atomic state object scaffolding Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 20/38] drm: rcar-du: Remove private copy of plane size and position Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 21/38] drm: rcar-du: Replace LVDS encoder DPMS by enable/disable Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 22/38] drm: rcar-du: Rework encoder enable/disable for atomic updates Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 23/38] drm: rcar-du: Rework HDMI " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 24/38] drm: rcar-du: Rework CRTC " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 25/38] drm: rcar-du: Switch plane update to atomic helpers Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 26/38] drm: rcar-du: Switch mode config " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 27/38] drm: rcar-du: Switch connector DPMS " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 28/38] drm: rcar-du: Replace encoder mode_fixup with atomic_check Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 29/38] drm: rcar-du: Implement asynchronous commit support Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 30/38] drm: rcar-du: Switch page flip to atomic helpers Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 31/38] drm: rcar-du: Switch plane set_property " Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 32/38] drm: rcar-du: Rework plane setup code Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 33/38] drm: rcar-du: Replace plane crtc and enabled fields by plane state Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 34/38] drm: rcar-du: Remove unneeded rcar_du_crtc plane field Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 35/38] drm: rcar-du: Move plane format to plane state Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 36/38] drm: rcar-du: Move plane commit code from CRTC start to CRTC resume Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 37/38] drm: rcar-du: Move group locking inside rcar_du_crtc_update_planes() Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-25 21:54 ` [PATCH 38/38] drm: rcar-du: Fix race condition in hardware plane allocator Laurent Pinchart 2015-02-25 21:54 ` Laurent Pinchart 2015-02-26 0:43 ` [PATCH 00/38] Renesas R-Car DU atomic updates support Magnus Damm 2015-02-26 0:43 ` Magnus Damm 2015-02-26 9:23 ` Laurent Pinchart 2015-02-26 9:23 ` Laurent Pinchart 2015-02-27 0:14 ` Magnus Damm 2015-02-27 0:14 ` Magnus Damm 2015-02-27 10:43 ` Laurent Pinchart 2015-02-27 10:43 ` Laurent Pinchart
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1424901298-6829-7-git-send-email-laurent.pinchart+renesas@ideasonboard.com \ --to=laurent.pinchart+renesas@ideasonboard.com \ --cc=dri-devel@lists.freedesktop.org \ --cc=linux-sh@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.