From patchwork Wed Dec 4 15:58:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13893983 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99A442144AA for ; Wed, 4 Dec 2024 15:58:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327899; cv=none; b=Ix9Kp+1PPw9ILOMGxhfZRCoarr4IqqFnkPvdqF4Iu31BKAJ1cIjm4ZCWE1gud1KVMWn7KH/6rtJj35Ld5agKi2euTlo2q+IAOyE+pByl8aiMiYYYJI8Ky8cplPJs+maHesC3xStc0eYLULflklsPN9bjGhNOqq559S6sgeBxqL0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327899; c=relaxed/simple; bh=eKmGJN/hdldvnD2ziuy0kMEX3JoK/YzfUj6m/JU908Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qNCxuas/Z56iL4kxzE04eWg90r/jYjhjbnSy7Cu57K8k1XDXc98xZUHEwm/XBY5c6LdGQbyDkw21whNI0RQfo5staSAnDHgS7EEq7+loW8UoRCo2QaDmrbHguNZV3fGJIivA1qLJtujpIiESWLqdfNQrcUAlmeBmf4rX6FQC8hE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=V7zFlQL5; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="V7zFlQL5" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-432d86a3085so58889105e9.2 for ; Wed, 04 Dec 2024 07:58:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1733327896; x=1733932696; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k67t0AHTbgurPxTOX/jkHsLw2xGkhWr4QjypFy+JQHs=; b=V7zFlQL5FJq6uN8jU5zMVEdkrePPmTG+cYAYFvmUhUzgYsZmhjNsfrp6buvM1qi3JW sPRuRAqEOl+8fe/tYO71zZl2pETtqn0yBKyM6Y66r94zD66ImyNXRSt3aY1eYVSN9ivm h/nEo0PRRUu0/APpwfrSKjekcxdOerdYomnbzIDVDmiTkXyrLhGb5vtW6fPj4pEAPVje iePQ0BoopIn9F+uJ2ntBGA63sJMsl0pacOfzlAHVTgMebAp7JUxSWeEiX/bXOJi2I9lI WDLcQoHJTHlcrPWFeIOvkT3xCsCbMVFKuUildSTdLeVPxuKLEUtIY6Og32/hAFcCIRHp 70EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733327896; x=1733932696; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k67t0AHTbgurPxTOX/jkHsLw2xGkhWr4QjypFy+JQHs=; b=Kr7e2/XSd/+0ES+wsT7guvYiIUCrGwMlW/yeryk0cN6JKhxWtl6rGn6AcxO8MXfNxn n1MMHgZaTm9RZQ04+hZTegoFE3q4KDI+DV7Pc445T8A7bkUG0zseU6+1tR82mFOamkl7 IBK5GPW8QIzWipYD7juB6dUnnx5nsafOAz3eMkOXpIJrHbr3DIf6mTx5mM2ezoBxC0kA LeTillLQJrWhiTkp+n799/7BHXTkkW1EiNt2QtT56CZXrxkC6ZvhD47QoY+s1NsO1jw9 wzrDY2raEA3AW5jiKTLEFbD2W0ZPIFOcG6zBJZ5n6YMi5Y/5RbloNIBY8SuRtDPTSOxB 9fjA== X-Forwarded-Encrypted: i=1; AJvYcCXDBZ9Yy92exWySzmlqKk5rwTGkAQ4eORzMAGUYWWgeM5WFMZ7b4mNaTkPUeXZfmsb6Ga14YahVfgpsPvjrKVbkQA==@vger.kernel.org X-Gm-Message-State: AOJu0Yw7sOMxYUsEwmefVL2GD//TY+NEGpuH1JQ9j83+V+0ZQnBXyL9j ileIDhD37iAKPP1qYObjtwq8fxyE6LISPamd9Z55iAhMK9zzqyBf3lk+bfFvaY8= X-Gm-Gg: ASbGncsg++GdqnP+aJTGSFNEnS//8KPzHHyOy1n1C2jQXIkepUmsqQGwbhecc/Hjc6U diI5/3q7//6AsgeFMtHe/tPPCre1ucFPy+ZjCg5aWl1dtM8ulxW3aIXtpI4LrXr5p9im/F10tD7 ZJQvwVWqSduii4t21GC/tUf+ZTLWACm9YUokukbXS8gOqHpJ1rBIqOfnbUB5yDvEwXM5vJUN5Zx Iu7kOrkZQA2sc5RHC9zmlO4uxLYBekyH/ebQzdunfyyxR9KRPy6mH5O8u3iIhlJxzbi/Pt2AO7Z zOw5 X-Google-Smtp-Source: AGHT+IGXCyAtkFpwaTBfcYQVs6ode3X2km7CTocnfjtuPAOGNzHHc8ilh09JcBMny1fNIazaj2zftQ== X-Received: by 2002:a05:600c:1f8f:b0:434:a396:9474 with SMTP id 5b1f17b1804b1-434d09cbe39mr63094175e9.18.1733327895803; Wed, 04 Dec 2024 07:58:15 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.161]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52b5677sm29043695e9.37.2024.12.04.07.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 07:58:15 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, wsa+renesas@sang-engineering.com, geert+renesas@glider.be, prabhakar.mahadev-lad.rj@bp.renesas.com, lethal@linux-sh.org, g.liakhovetski@gmx.de, groeck@chromium.org, mka@chromium.org, ulrich.hecht+renesas@gmail.com, ysato@users.sourceforge.jp Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH RFT 1/6] serial: sh-sci: Check if TX data was written to device in .tx_empty() Date: Wed, 4 Dec 2024 17:58:01 +0200 Message-Id: <20241204155806.3781200-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> References: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Claudiu Beznea On the Renesas RZ/G3S, when doing suspend to RAM, the uart_suspend_port() is called. The uart_suspend_port() calls 3 times the struct uart_port::ops::tx_empty() before shutting down the port. According to the documentation, the struct uart_port::ops::tx_empty() API tests whether the transmitter FIFO and shifter for the port is empty. The Renesas RZ/G3S SCIFA IP reports the number of data units stored in the transmit FIFO through the FDR (FIFO Data Count Register). The data units in the FIFOs are written in the shift register and transmitted from there. The TEND bit in the Serial Status Register reports if the data was transmitted from the shift register. In the previous code, in the tx_empty() API implemented by the sh-sci driver, it is considered that the TX is empty if the hardware reports the TEND bit set and the number of data units in the FIFO is zero. According to the HW manual, the TEND bit has the following meaning: 0: Transmission is in the waiting state or in progress. 1: Transmission is completed. It has been noticed that when opening the serial device w/o using it and then switch to a power saving mode, the tx_empty() call in the uart_port_suspend() function fails, leading to the "Unable to drain transmitter" message being printed on the console. This is because the TEND=0 if nothing has been transmitted and the FIFOs are empty. As the TEND=0 has double meaning (waiting state, in progress) we can't determined the scenario described above. Add a software workaround for this. This sets a variable if any data has been sent on the serial console (when using PIO) or if the DMA callback has been called (meaning something has been transmitted). In the tx_empty() API the status of the DMA transaction is also checked and if it is completed or in progress the code falls back in checking the hardware registers instead of relying on the software variable. Fixes: 73a19e4c0301 ("serial: sh-sci: Add DMA support.") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- drivers/tty/serial/sh-sci.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index df523c744423..924b803af440 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -157,6 +157,7 @@ struct sci_port { bool has_rtscts; bool autorts; + bool tx_occurred; }; #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS @@ -850,6 +851,7 @@ static void sci_transmit_chars(struct uart_port *port) { struct tty_port *tport = &port->state->port; unsigned int stopped = uart_tx_stopped(port); + struct sci_port *s = to_sci_port(port); unsigned short status; unsigned short ctrl; int count; @@ -885,6 +887,7 @@ static void sci_transmit_chars(struct uart_port *port) } sci_serial_out(port, SCxTDR, c); + s->tx_occurred = true; port->icount.tx++; } while (--count > 0); @@ -1241,6 +1244,8 @@ static void sci_dma_tx_complete(void *arg) if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) uart_write_wakeup(port); + s->tx_occurred = true; + if (!kfifo_is_empty(&tport->xmit_fifo)) { s->cookie_tx = 0; schedule_work(&s->work_tx); @@ -1731,6 +1736,19 @@ static void sci_flush_buffer(struct uart_port *port) s->cookie_tx = -EINVAL; } } + +static void sci_dma_check_tx_occurred(struct sci_port *s) +{ + struct dma_tx_state state; + enum dma_status status; + + if (!s->chan_tx) + return; + + status = dmaengine_tx_status(s->chan_tx, s->cookie_tx, &state); + if (status == DMA_COMPLETE || status == DMA_IN_PROGRESS) + s->tx_occurred = true; +} #else /* !CONFIG_SERIAL_SH_SCI_DMA */ static inline void sci_request_dma(struct uart_port *port) { @@ -1740,6 +1758,10 @@ static inline void sci_free_dma(struct uart_port *port) { } +static void sci_dma_check_tx_occurred(struct sci_port *s) +{ +} + #define sci_flush_buffer NULL #endif /* !CONFIG_SERIAL_SH_SCI_DMA */ @@ -2076,6 +2098,12 @@ static unsigned int sci_tx_empty(struct uart_port *port) { unsigned short status = sci_serial_in(port, SCxSR); unsigned short in_tx_fifo = sci_txfill(port); + struct sci_port *s = to_sci_port(port); + + sci_dma_check_tx_occurred(s); + + if (!s->tx_occurred) + return TIOCSER_TEMT; return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0; } @@ -2247,6 +2275,7 @@ static int sci_startup(struct uart_port *port) dev_dbg(port->dev, "%s(%d)\n", __func__, port->line); + s->tx_occurred = false; sci_request_dma(port); ret = sci_request_irq(s); From patchwork Wed Dec 4 15:58:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13893984 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D9E12144B5 for ; Wed, 4 Dec 2024 15:58:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327900; cv=none; b=UHSK0qJyT2qi5oIYZgcovQdRmER/6QDF82a7qsnDVDN9vTCBLLfWyc+ATVOXnPkn7zrC9AfNk5WfJLxeilKT1AFsLK1ytwalDrulcGtc6deT8QMMAvrUAJ07y4B5uClHwV97VaRDnaw5/gd6rzhwHub2QXgrzQEs57a1TtBFXjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327900; c=relaxed/simple; bh=vd24ELPUpzIEthODLFQ5qLWi9e3qKvukCK4lkf0j1CA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pyPgbRS5rLyCH5k0CiM3Wwv0WU9lEClalWPxD3a74Z98ZHmU7ME2NTtYvW9PMP+uEalFCRdVR52Tlh57qaHTPGJNKoRtN805IusW47Z1WfuT5gMKBgmB8Ticr6WIMALZkX5JyYsPrBXP8DXYItQngfrmHrOXjpz6fM3bQf8ovzs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=ESSoFeqg; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="ESSoFeqg" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-434a2f3bae4so64774135e9.3 for ; Wed, 04 Dec 2024 07:58:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1733327897; x=1733932697; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YI/FcgkOifwXXzXlvk8zo5YFKecagbmROLu06ZFniA0=; b=ESSoFeqgAkRcjblLHxccnALnvO5s38lf9FD0kZkU+b5gom6Rt3ekj1uZHNpyf1eJUn ycfokj0PQ9TKic9L7JNu9vIZWevcIxJe6L2XHCzvBJtxTk+3XNBERDmrRObL9rAVKyK3 jqdRsmJ/cOuXrn2QlwpHPZnvKnlYzwMNhbL0ysUOBtIn2sFZAtn9KaLzNtmyO30ERFqU Ma1rM/JWZkL6XgY+ocSkMMdeXFzmkIiibxO1JUT1bvetJaczP8jw0Dr7e2zWmge8IpmY W8PG0t4FaV81W/RwsZUHVv1HoExjum8ND+0Qx3shNXKhTGNK/tBQLacc6szeTRwMqP1R R9EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733327897; x=1733932697; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YI/FcgkOifwXXzXlvk8zo5YFKecagbmROLu06ZFniA0=; b=aMx4zD4L+xAv/hEPtlZYZ/p77JCoCtmb52cYmFg8NnXOF5d7sWvLBMx5PFJBIPrnj5 yqVHnBAI4FC7hVMPNfrQHpgaDVPaCirl4o0IknA9lqU3fLBV3NuIghNOc2xbgNPPcsBQ mysP2/srq4y/Cpkv8oluLnYPUsO2ZtvLHejieoTDpmVXbGp6DHzpXLfEfu9NKtuVyMh6 yRzWyr2cgJOQDtUd+haveo9+qbu7zmzkhb7Eg4wxbC5cmvrh8CanCjZlEAk5HF5wZi6e 6yMDkkH2j7tGNZdNMUymaEsK4ROMSxRKeaS2iT8KwiEYAIzlIzZ6TMz7xw35fufzTDtT T4vw== X-Forwarded-Encrypted: i=1; AJvYcCXuJC5YVuW4hddIf6Qse4gbdB4tscHrV5oPkWAwuk8cMS8/liJ4IYXkjkeCkompjlF03bu/za5E346yJR5ii7mehw==@vger.kernel.org X-Gm-Message-State: AOJu0Yw0BgZ9977SNmZzeSdJDf/0v+f6LeL2qBBTINXCOVW5u760q9MN TPHuYYvgoOnYLEUBDKRCIUVbCjF6HnxpA2GtUA9UdhgVjJ03cypN8v63k6Jbci0= X-Gm-Gg: ASbGncsZ12rMYgXRNVOnXf330sI6pFUMG1D5uJoGFK1gjSX29JUEzlMpCGpVXDTNTj6 vLhSVe8UWOlnSTr10aP50T/SjMpINB83vwwyptJdLxtGpJkJL8hdITwuW1DTFwajuErdbmX5f/r IQrT4E4eaGdVN+duCIM5IA0bcA9r4dxNLhRjBHllUVyvsHQl6ZFjJyFkNK1p/hklvGwwHO5sxzH 5m75cb9O22rnE5h4avw7zGs0b587s3LF7uLUGM4sCSQmcRZeHWc1lBcYGkV7vbytHHDO7wlqp11 AnV2 X-Google-Smtp-Source: AGHT+IGPLwKQh57Ead8RRrh1gxEVt29W9QxQJZdC/e01yLZTzadTaRF9r6H13On42Alm4HnNGJ6b+A== X-Received: by 2002:a05:600c:19d1:b0:434:a765:7f9c with SMTP id 5b1f17b1804b1-434d09acf91mr62725955e9.6.1733327897506; Wed, 04 Dec 2024 07:58:17 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.161]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52b5677sm29043695e9.37.2024.12.04.07.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 07:58:16 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, wsa+renesas@sang-engineering.com, geert+renesas@glider.be, prabhakar.mahadev-lad.rj@bp.renesas.com, lethal@linux-sh.org, g.liakhovetski@gmx.de, groeck@chromium.org, mka@chromium.org, ulrich.hecht+renesas@gmail.com, ysato@users.sourceforge.jp Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH RFT 2/6] serial: sh-sci: Drop __initdata macro for port_cfg Date: Wed, 4 Dec 2024 17:58:02 +0200 Message-Id: <20241204155806.3781200-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> References: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Claudiu Beznea The port_cfg object is used by serial_console_write(), which serves as the write function for the earlycon device. Marking port_cfg as __initdata causes it to be freed after kernel initialization, resulting in earlycon becoming unavailable thereafter. Remove the __initdata macro from port_cfg to resolve this issue. Fixes: dd076cffb8cd ("serial: sh-sci: Fix init data attribute for struct 'port_cfg'") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- drivers/tty/serial/sh-sci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 924b803af440..4f5da3254420 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3562,7 +3562,7 @@ sh_early_platform_init_buffer("earlyprintk", &sci_driver, early_serial_buf, ARRAY_SIZE(early_serial_buf)); #endif #ifdef CONFIG_SERIAL_SH_SCI_EARLYCON -static struct plat_sci_port port_cfg __initdata; +static struct plat_sci_port port_cfg; static int __init early_console_setup(struct earlycon_device *device, int type) From patchwork Wed Dec 4 15:58:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13893985 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9BDC2144C3 for ; Wed, 4 Dec 2024 15:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327902; cv=none; b=plUaczS5Hq9dLLnlKuUktT8IxSKSTOhAH8Vw3jFuKh3rQp8O0u/UGUTOdxj1l+7TeMV5IyHzqizT5hFcT+V4gU18g9ImWFNWRusMbsvr/WFN3+np75NGGM76LDnL4F+gdLAHFxxNGFn/a6nvWL2Nr2+fKgwtzW+U9xrAh0V2QLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327902; c=relaxed/simple; bh=ZT/xdjFLeWNNlsrj3Ue+9kz2Tfvcw+jWnO0VG76SBPI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BP+jIvP5UKOuxp6JR5lZ9E5NqFj6Pfk+vu6Fc+z5dC9q2I3thO+eiTpR46wktJvx5lJYUaM6/cFjAlhYCNTGkYJy48S9kvOFk6iFLOjr9ImcI8ed8mkFoN4iecVw4JBJPMJLMsPrCuxaKHiwV4D+8iR2tBmDUJjERZoklec55Ds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=jsPFp6Cw; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="jsPFp6Cw" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-434a45f05feso85299485e9.3 for ; Wed, 04 Dec 2024 07:58:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1733327899; x=1733932699; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iw97V1HkeTfD3TObMHDloJkcKAuf8zzJLrBo8Fp9hAs=; b=jsPFp6CwqnKs6uCZj8RfZB4mh0xEeb//7c9XjOdsA1BDzN9VodpgLMN2ZosSzFum0/ Zh/lGILkVfTCf8WCcNyqAlTQRsUJjQVbkCcpVhQCfNwudGaX3SE+7ux+3iICm8I6YkyD 60U9RE/5CsWtjqsN0xQH+vevlKffzMMRlww0M47K0rdI4CVaT/erh/imD7V7XhqjqZci XKXSPM995v3aVclBenxpH88qx9REPXjU3UI5o/WKYMDQBMWl2uL+l5nRQKoO8IeCYocl bOUGPLtPDr5KC8pF2TPZXcK8VLeOzczMMfpO5AwuIvPzr49Y5tOVuVx2smAp99f4vKIG lEHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733327899; x=1733932699; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iw97V1HkeTfD3TObMHDloJkcKAuf8zzJLrBo8Fp9hAs=; b=SmjCsq3NLywkLHFGkQd4tpJNxo6ZvQ3XPxeVg4qnE6aWWlmQFgTSlOebDFBetFFDBO hD0cFVAdaD531TyoG0eKI3hGBMeUpobHUUrNP5HY9TILrQoubHmxE3F2LuB2VpuHCOuo uzPgyUDgsBO+vlslCpN7k1ug5Ckbhvo1M1FX8E+WppMOfES4qVjGWmtaJGimSbE0scSN 0t3nFYnWzpMX95laLj1G037Krk8Yj4vhkzeesvtuyia+Q9qwa9kCgnBU2YIMncKXYcz6 NCqQqfqPb2PD8cn8Qi6h+ydieozCm7pyGBzRKeLiW/VCccb1CzGCHYcjvt4s62JTRFmk KImg== X-Forwarded-Encrypted: i=1; AJvYcCVqDJK4LPe1BB1FYTelgZ74ISwWEgMtsPOc1v9DBCtIE+DuoADa+s+3USL+LW+rAhDHdkX46mGseo+ZfRyxV5PWtQ==@vger.kernel.org X-Gm-Message-State: AOJu0YwGozZzjC/1uUICsgc0p6ZKDX0FzZ1+H66cNul7f2hHs/Ib3PS5 LTVST6EjxwAYJOJZASiYSjZtXHjtbrANzANq6K+90gcoKrk7JccOE+Xb06rEwxk= X-Gm-Gg: ASbGncvGT4vQQHgs3wleRJHwf/CHi9oQgOZS9i5AlPNb3SpxaQ+BMnQMTAMM+4mq8HJ JQSOfJSi7WEHfqlXc3VRaoyA4IgLqnxpeRpECXVL/PXydW3Lr32vojvNeWDyGFx+gjv0LrSdta0 aSZuWf5QUiO701+JRrvfazhHnQWCrz4pTIB/myqtLyEomvoJsaEPYfb3iMVm0gfDsE8Ox9NEmMn 5laxAlqUcjJ+8qof7w9gYRK09De2lXB9+xxLe+16FErVxCECZOsBtmhTm2B0RQ55CQBCiF3qYa4 Hz0v X-Google-Smtp-Source: AGHT+IEdO01rXNTKKymFk0tOKPPstS1yxCCBYj396aNVH1MZSrtaciEZJPkmPj7/r7/fpuguB+UslA== X-Received: by 2002:a05:600c:4593:b0:434:9ec0:9e4e with SMTP id 5b1f17b1804b1-434d0a28531mr77312675e9.30.1733327899104; Wed, 04 Dec 2024 07:58:19 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.161]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52b5677sm29043695e9.37.2024.12.04.07.58.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 07:58:18 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, wsa+renesas@sang-engineering.com, geert+renesas@glider.be, prabhakar.mahadev-lad.rj@bp.renesas.com, lethal@linux-sh.org, g.liakhovetski@gmx.de, groeck@chromium.org, mka@chromium.org, ulrich.hecht+renesas@gmail.com, ysato@users.sourceforge.jp Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH RFT 3/6] serial: sh-sci: Move runtime PM enable to sci_probe_single() Date: Wed, 4 Dec 2024 17:58:03 +0200 Message-Id: <20241204155806.3781200-4-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> References: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Claudiu Beznea Relocate the runtime PM enable operation to sci_probe_single(). This change prepares the codebase for upcoming fixes. While at it, replace the existing logic with a direct call to devm_pm_runtime_enable() and remove sci_cleanup_single(). The devm_pm_runtime_enable() function automatically handles disabling runtime PM during driver removal. Signed-off-by: Claudiu Beznea --- drivers/tty/serial/sh-sci.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 4f5da3254420..373195995d3b 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3056,10 +3056,6 @@ static int sci_init_single(struct platform_device *dev, ret = sci_init_clocks(sci_port, &dev->dev); if (ret < 0) return ret; - - port->dev = &dev->dev; - - pm_runtime_enable(&dev->dev); } port->type = p->type; @@ -3086,11 +3082,6 @@ static int sci_init_single(struct platform_device *dev, return 0; } -static void sci_cleanup_single(struct sci_port *port) -{ - pm_runtime_disable(port->port.dev); -} - #if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) || \ defined(CONFIG_SERIAL_SH_SCI_EARLYCON) static void serial_console_putchar(struct uart_port *port, unsigned char ch) @@ -3260,8 +3251,6 @@ static void sci_remove(struct platform_device *dev) sci_ports_in_use &= ~BIT(port->port.line); uart_remove_one_port(&sci_uart_driver, &port->port); - sci_cleanup_single(port); - if (port->port.fifosize > 1) device_remove_file(&dev->dev, &dev_attr_rx_fifo_trigger); if (type == PORT_SCIFA || type == PORT_SCIFB || type == PORT_HSCIF) @@ -3425,6 +3414,11 @@ static int sci_probe_single(struct platform_device *dev, if (ret) return ret; + sciport->port.dev = &dev->dev; + ret = devm_pm_runtime_enable(&dev->dev); + if (ret) + return ret; + sciport->gpios = mctrl_gpio_init(&sciport->port, 0); if (IS_ERR(sciport->gpios)) return PTR_ERR(sciport->gpios); @@ -3440,7 +3434,6 @@ static int sci_probe_single(struct platform_device *dev, ret = uart_add_one_port(&sci_uart_driver, &sciport->port); if (ret) { - sci_cleanup_single(sciport); return ret; } From patchwork Wed Dec 4 15:58:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13893986 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42DA4215F40 for ; Wed, 4 Dec 2024 15:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327904; cv=none; b=UzzdJ+m7hTqbuOqbw+9za674OAy53X1Hr7mYjy90jxzeGrzIw5tayXY+UppRNhacNdBftgWQ3i6MeBGyqWlNQ9qJrOEZns1/P8CkgAMaq+/NzHqPKy0Ot37moSuBtqHFHUpMA0tTvykqMUO2u/aZez+cB4HAhMWd8V3vmJBjfU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327904; c=relaxed/simple; bh=hNvsm/KT1uK/VLwkIurCBjMDay2qykQ05TtUGaANs+M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U/lgcNJiQCJOUltrN2DHmhPCuxG4ZhIcwQyhs6PkYizUZ9sc+a8Qz0+hLSzPSKDfsLPXoIY3q6XQQ4uSG8V3hgKRUL4K1NwTzHPcgyKIk4iwgis1vhHWlIcOQk+dRtvqnZSsEnGQ4iYr97qlaE7EgdxYNyzgyg9WqUqVGAP/nds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=fiIZOhJ7; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="fiIZOhJ7" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-434a1833367so6813005e9.1 for ; Wed, 04 Dec 2024 07:58:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1733327901; x=1733932701; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=msXpgYS9tLSNaLykc7vmvtR+isPm7EdibA54ABrXSEE=; b=fiIZOhJ7KmDtdtTA+WeVKNQVv1bsOOBhNYD1GChO0mqb6pTVjfOaPRXxiW7Hcg8q8Q i+zukxqcqaX0bEMOrTZRfUW1XOzhyjOPZHzzNFVe+DAmsn9LppsHGynV6EvfDQhov4vQ r6dzIxFbg2gQR23phrY1Ea0GDOyg5WbbMjbVPNfaXupA3Z6XIVL4arH7rrYQch4A5JP+ iS7LHfV0Rayz0/ef2VSIEbEc19be9OdF7+auwTz8aFjXS+sI1WNor4YM//Ya7sDwfPWM edfxmf15ig6gmXz70C9k1BmEqWAJ2xvWzslRgdRAR7h1ntiBWbum4InWFIk7jkx3+bhy TngA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733327901; x=1733932701; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=msXpgYS9tLSNaLykc7vmvtR+isPm7EdibA54ABrXSEE=; b=rblrDz4gkknt5ly1Sg0YmGyLzF1unWSMkk4bIs/+ZU+GVuSS8EfW1Mz9Spyo4VUnjT VI8qW0De4OHm/JOa2ii22Naz3e72EYjJdIik4Lied1Ya3bE7aK//HoqGWhezitD+zcyS +vgjmlUR9DrFr1PVMheoDRujyz9p2LttQ8hRb664J8CXFSK34uSK6a3wCEMWR9hHXmxc jJ8S+E5TexoVvLwHqVed/AVYhM8YY9lWQ1eKu5RUHEpVWe7oPRKsGvwN14yhdXIn46iz fDI2KKi6CjAC/n8eJfB9oySS4SPxzdGLMiBccLEbaUzhHFB5EdtswmYw+mbAr2R8FzzL aMnA== X-Forwarded-Encrypted: i=1; AJvYcCVEATlta/mMiJvG9n+8LGFxygiMIfYiceJNVLwtIRHVlpNyEdPKRl2E4NIqMrdzdEvRY/AnlstSw631oMO3Fallew==@vger.kernel.org X-Gm-Message-State: AOJu0Yz1E8ycTiE/Co7jHggfhPfeQdfwZK1pepbdr6SrIabeCrZg/DGO HksKQ2zUjrZRgOh4JDxRB5lzaLhZ1NOUd+anfnGx3qgdp9t0ELtJd8f3Ojyexmg= X-Gm-Gg: ASbGnctZw6VKqYVsz8fJhb0SBWbALd6l197rCPSsrrNjnfpRt7H5t/GGoSiQiF8GoKG T1FKEGyBPyJriHF/vPpumjDuFsejR9MUcChO8bD50BejX5f02QODq0EZQkFrCwUy6kfziejclvO eLXb044JOj/NINK5cAKdBheb5cI0RrlFEV1PC8mQ3r0bQbJ5k0lOA08KmcHxA7dxC5kaiigQF+W /ZUBRq/UtpgkyHYPZMWPk8Wgo0kdxwnzzYCKk0a8jU1kXaDeyZZNunQ7PeeRL7PP3OQNSXKgHzJ dikS X-Google-Smtp-Source: AGHT+IFwVNe09WNHkBY2H/LBD9xqPexC52/hSNnEpjHiB9kAbrM0T8XCJhvLvde3Ex8EWBQKVsNWLw== X-Received: by 2002:a05:600c:1989:b0:434:9e17:190c with SMTP id 5b1f17b1804b1-434d0cb158dmr52971695e9.0.1733327900709; Wed, 04 Dec 2024 07:58:20 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.161]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52b5677sm29043695e9.37.2024.12.04.07.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 07:58:20 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, wsa+renesas@sang-engineering.com, geert+renesas@glider.be, prabhakar.mahadev-lad.rj@bp.renesas.com, lethal@linux-sh.org, g.liakhovetski@gmx.de, groeck@chromium.org, mka@chromium.org, ulrich.hecht+renesas@gmail.com, ysato@users.sourceforge.jp Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH RFT 4/6] serial: sh-sci: Do not probe the serial port if its slot in sci_ports[] is in use Date: Wed, 4 Dec 2024 17:58:04 +0200 Message-Id: <20241204155806.3781200-5-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> References: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Claudiu Beznea In the sh-sci driver, sci_ports[0] is used by earlycon. If the earlycon is still active when sci_probe() is called and the new serial port is supposed to map to sci_ports[0], return -EBUSY to prevent breaking the earlycon. This situation should occurs in debug scenarios, and users should be aware of the potential conflict. Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- drivers/tty/serial/sh-sci.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 373195995d3b..e12fbc71082a 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -158,6 +158,7 @@ struct sci_port { bool has_rtscts; bool autorts; bool tx_occurred; + bool earlycon; }; #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS @@ -3443,6 +3444,7 @@ static int sci_probe_single(struct platform_device *dev, static int sci_probe(struct platform_device *dev) { struct plat_sci_port *p; + struct resource *res; struct sci_port *sp; unsigned int dev_id; int ret; @@ -3472,6 +3474,26 @@ static int sci_probe(struct platform_device *dev) } sp = &sci_ports[dev_id]; + + /* + * In case: + * - the probed port alias is zero (as the one used by earlycon), and + * - the earlycon is still active (e.g., "earlycon keep_bootcon" in + * bootargs) + * + * defer the probe of this serial. This is a debug scenario and the user + * must be aware of it. + * + * Except when the probed port is the same as the earlycon port. + */ + + res = platform_get_resource(dev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; + + if (sp->earlycon && res->start != sp->port.mapbase) + return dev_err_probe(&dev->dev, -EBUSY, "sci_port[0] is used by earlycon!\n"); + platform_set_drvdata(dev, sp); ret = sci_probe_single(dev, dev_id, p, sp); @@ -3568,6 +3590,7 @@ static int __init early_console_setup(struct earlycon_device *device, port_cfg.type = type; sci_ports[0].cfg = &port_cfg; sci_ports[0].params = sci_probe_regmap(&port_cfg); + sci_ports[0].earlycon = true; port_cfg.scscr = sci_serial_in(&sci_ports[0].port, SCSCR); sci_serial_out(&sci_ports[0].port, SCSCR, SCSCR_RE | SCSCR_TE | port_cfg.scscr); From patchwork Wed Dec 4 15:58:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13893987 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CF8C215F64 for ; Wed, 4 Dec 2024 15:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327906; cv=none; b=iXDjqiabW8h7AUafbX5SfSrJkeUiggGCb0zP6HS66hQGNLegppgfWJvu+sbYaRaYl3m1bvSZOFunCDBQJKX10VbXztNfOfErtbQ8NzYsQE++wxHCFE/kmDrqDlXiF3Xkxq7/0eFfFIujrTIA5QXeGqQDAwjvahrRE1SzPpHENJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327906; c=relaxed/simple; bh=MxMaPltCgRW13FZnasc8Tq7kHIMdsrQSwKvFTxmIPUI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=flDh4hJbHvIJsy6GlMg7LCqvI9yIelQfP74q/lxj7aEazTNx5wucm7R6FmJcPdzoVhz2mJN310RZB2R/mZmroKtCreqcrza1cpAa6MFM15GFeqbtoj1TBDp3xs1T7DRc+5Mo9NV1ZId8ji0YvDRYDcECXqugaGaSCHtDkWVn3E4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=iU0RE5p9; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="iU0RE5p9" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-434aabd688fso45683515e9.3 for ; Wed, 04 Dec 2024 07:58:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1733327902; x=1733932702; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/rlI7Qx26yf6aFN47ni90xhGkPbc5gZWYXhldcxWmyE=; b=iU0RE5p9qa0LrI95cZg5ZxC3Afi8ZeqyNDm+G4AqCeNXWNOgSmdgK40LM+1sxDP2+9 EFqzNAgc524OmngAKAHVLkK9YNY+MifE4F9GCbNtDL+2Wnv87fb7tA7/YhVqKHuzP3Xw SuX0i0d8p3muSMfRyEdcVLEQO/njMziGv+VFOo54xRK0RH6FvvyKRPKLWE3glp91qsCa GhUg4X+KpnXlR4SbP4O1x6DMNrpv/o+cNAmssO2JDngawur4N31H1x8DeyGVFqoXrcBi +R5NLZdxM2gD60D0N/uE0ZXKN0mPlYdQdrSwPeEe+r/icdoUwD9UKqNfCSGnS9jOMg5T J9MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733327902; x=1733932702; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/rlI7Qx26yf6aFN47ni90xhGkPbc5gZWYXhldcxWmyE=; b=nmj5TRbOy9UgKyVFO9vzhvNNE6SVaVAUjOHtipImW1rhBJ+xgyi4nqsnoNFGISxLxE FXEavFa+v1YeGNSlcTQH/v8vP/SPAid0Tlz9HYxezH4Gx8NiAqENk8AIm1iG42a4qRmn 8GWQ9Y4cR8CoREs6sq4Xs04xGw4pKkgsHCrawG6DueNT284NsVKa/s7iOu7a1e8HOBNR v9ZCGUXdbDiKzUqBUIM6utOIIFkGLho0+USEgbkFeDcuEWgXNu1WYSbGu4NYAq+TK3EM Hro8qS5pAMJwQh8fAh6oMA+mWSK2trWaXZHfhsykIzotMBoXNgWYB8FsgKv0I9KA5nNJ /VRA== X-Forwarded-Encrypted: i=1; AJvYcCXLTHNYKAakeOjJARoWgKdqMmj88FYIFncyRZT9vpl6UlxIOYW9jKRLV7T3/OfAkKJjxni2M3N8zoc8IebE+8zI8w==@vger.kernel.org X-Gm-Message-State: AOJu0YwX7HTGSZUOeQAduoxEVaQgarxDnq2CgLxH5MzfCT4LxbLPpj3k rW2pco4A5cFRMNUmMyRsndjwyHavFBJqN/Wv+l2JC4XCDkDXTBEKdgBwDKcoOcw= X-Gm-Gg: ASbGncsZzygRyG0HFTA5UgezRb5okRJfg+MlNVB/qr2NnXFiYoxEVyNFkghwYLFVtdU Xy8YPVGM7zy8FcP1U+wkou1xQAVynK+ueC7ONKrz85+zkNfA3xSu6u2EopEfjeI7IYj/m1XWIOy fmu8UduWM7SPXkQCSaP3sLD1mDk97GaqwY4hs7EtwiB9pR5YN59+/t1vr1HAT1+AxOwMwWjMWk/ fgMA516O3C8x7JDeoD++7pMUHkHQ8oJStfOAuS7jYOKknlFYmiIe0fgcAdnAGStYdMWThUphO3q sMFS X-Google-Smtp-Source: AGHT+IF+1o32TF0lWbqkhxRtE212Vnx1K8CfTxGY1M11SpSR8N/1jY5uC9iZqH3b8pu7L9xs+zxDJA== X-Received: by 2002:a05:600c:19ce:b0:431:5871:6c5d with SMTP id 5b1f17b1804b1-434d3f8e454mr48344175e9.3.1733327902370; Wed, 04 Dec 2024 07:58:22 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.161]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52b5677sm29043695e9.37.2024.12.04.07.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 07:58:21 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, wsa+renesas@sang-engineering.com, geert+renesas@glider.be, prabhakar.mahadev-lad.rj@bp.renesas.com, lethal@linux-sh.org, g.liakhovetski@gmx.de, groeck@chromium.org, mka@chromium.org, ulrich.hecht+renesas@gmail.com, ysato@users.sourceforge.jp Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH RFT 5/6] serial: sh-sci: Clean sci_ports[0] after at earlycon exit Date: Wed, 4 Dec 2024 17:58:05 +0200 Message-Id: <20241204155806.3781200-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> References: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Claudiu Beznea The early_console_setup() function initializes sci_ports[0].port with an object of type struct uart_port obtained from the struct earlycon_device passed as an argument to early_console_setup(). Later, during serial port probing, the serial port used as earlycon (e.g., port A) might be remapped to a different position in the sci_ports[] array, and a different serial port (e.g., port B) might be assigned to slot 0. For example: sci_ports[0] = port B sci_ports[X] = port A In this scenario, the new port mapped at index zero (port B) retains the data associated with the earlycon configuration. Consequently, after the Linux boot process, any access to the serial port now mapped to sci_ports[0] (port B) will block the original earlycon port (port A). To address this, introduce an early_console_exit() function to clean up sci_ports[0] when earlycon is exited. To prevent the cleanup of sci_ports[0] while the serial device is still being used by earlycon, introduce the struct sci_port::probing flag and account for it in early_console_exit(). Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- Changes since the integrated patch: - adjust the commit message to address Geert comments at [1] - Introduce the struct sci_port::probing flag to prevent the cleanup of sci_ports[0] while the serial device is still being used by earlycon [1] https://lore.kernel.org/all/CAMuHMdX57_AEYC_6CbrJn-+B+ivU8oFiXR0FXF7Lrqv5dWZWYA@mail.gmail.com/ drivers/tty/serial/sh-sci.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index e12fbc71082a..f74eb68774ca 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -159,6 +159,7 @@ struct sci_port { bool autorts; bool tx_occurred; bool earlycon; + bool probing; }; #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS @@ -3386,7 +3387,8 @@ static struct plat_sci_port *sci_parse_dt(struct platform_device *pdev, static int sci_probe_single(struct platform_device *dev, unsigned int index, struct plat_sci_port *p, - struct sci_port *sciport) + struct sci_port *sciport, + struct resource *sci_res) { int ret; @@ -3433,12 +3435,15 @@ static int sci_probe_single(struct platform_device *dev, sciport->port.flags |= UPF_HARD_FLOW; } - ret = uart_add_one_port(&sci_uart_driver, &sciport->port); - if (ret) { - return ret; + if (sci_ports[0].earlycon && sci_ports[0].port.mapbase == sci_res->start) { + /* + * Skip cleanup up the sci_port[0] in early_console_exit(), this + * port is the same as the earlycon one. + */ + sci_ports[0].probing = true; } - return 0; + return uart_add_one_port(&sci_uart_driver, &sciport->port); } static int sci_probe(struct platform_device *dev) @@ -3496,7 +3501,7 @@ static int sci_probe(struct platform_device *dev) platform_set_drvdata(dev, sp); - ret = sci_probe_single(dev, dev_id, p, sp); + ret = sci_probe_single(dev, dev_id, p, sp, res); if (ret) return ret; @@ -3579,6 +3584,20 @@ sh_early_platform_init_buffer("earlyprintk", &sci_driver, #ifdef CONFIG_SERIAL_SH_SCI_EARLYCON static struct plat_sci_port port_cfg; +static int early_console_exit(struct console *co) +{ + struct sci_port *sci_port = &sci_ports[0]; + + /* + * Clean the slot used by earlycon. A new SCI device might + * map to this slot. + */ + if (sci_port->earlycon && !sci_port->probing) + memset(sci_port, 0, sizeof(*sci_port)); + + return 0; +} + static int __init early_console_setup(struct earlycon_device *device, int type) { @@ -3596,6 +3615,8 @@ static int __init early_console_setup(struct earlycon_device *device, SCSCR_RE | SCSCR_TE | port_cfg.scscr); device->con->write = serial_console_write; + device->con->exit = early_console_exit; + return 0; } static int __init sci_early_console_setup(struct earlycon_device *device, From patchwork Wed Dec 4 15:58:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13893988 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD170217649 for ; Wed, 4 Dec 2024 15:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327907; cv=none; b=lhp5gpvNFDcyqoCJnI4mzVWiH9m1RB9WzpaHG3x1OaOL7W1z7cD1m62pRoFlF4d7nXz2jZC2RmijuDPWS2u0lmoHV9m4EiqazX65hM2bIhPmF62105bC3SlNBTeL6xHVBzt+galol63uk5yoJ+S7d9Hl3Sy2WR2Yr3e52JSTngc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327907; c=relaxed/simple; bh=fnmIuQ3AC6S2Pd91eCPrbiQeWsPvWcflJGps7V3hZSw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X1H9HtO1aXIglsg0zX34R7GvNdA7fcRZ4dpPgjVmvV34vOxIVmTjzRhrdmnq8W+LzBWYv/3n/bNhAoqR/ojRYtcbQDaE2OsC/cfV4davkskuTEAbAT6FfYxgK60rm5dBmA5vMwabn2CYJ0qSxx37thso2Kr/1XBj9BXdLWFwv2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=PUWJhPhh; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="PUWJhPhh" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-434a752140eso58880085e9.3 for ; Wed, 04 Dec 2024 07:58:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1733327904; x=1733932704; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hIgexULd80z2MjCqhWRkmxhXY4y89/FFLZbXUxSS9MA=; b=PUWJhPhhST9iGelcZq0AP77BmiT5SOZDHhxomGLaPic/OLfvRo7VXUhagBoc8a2QWF XprvNiAYIrw1Zrj5uot8RTazjOpdjooSYC3On9Yl8deLKNe9XAub86opHhhiQkghuqgL 0IjG66vWcopFmIPVdKkkW88TQDpSM4yavW6ruQiSzme1LkeTHvJJ1S1rVd8dBinZ+lhQ aK1QY+3HduznV8cTtJOaWY2dRICsllcaedwSbleTYPWLZwRv5uKQV9YnFcJRqs2GqzF4 2mS5nzHtpYJnLwqqq6eDcEr9rREaybS6nBRZj9kSZDylXDBh7vDOBgYycbBkRP/3Nf8L NKEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733327904; x=1733932704; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hIgexULd80z2MjCqhWRkmxhXY4y89/FFLZbXUxSS9MA=; b=Omiv+RdFdAmfOXbzR7KIAHxhW2sUIfcTsY46CPD+98IyFhASfh2LBK1uurACXIolE4 Fb5/u6Bwaam0x/u4LzUtjEv/9mW45B+2qohlGsxvUAFXccEWZnlPxtTV+Ll9sodjSUr3 0GwiGAe84pNytgZ7JBt2MYHU7y2aWX+HSExZq9OX2nQ4aFLHYJCObOK5SUbMYmYzUnTn TnRnfHq9Kp4WQ+x+masZxnRR3/ubExgJcC1jEPCNxsxHlVsHuWti82Ls9kGGkleqapbB 9Wq+JySuNsioE7K2TJToTLctbXxJeB+FVLq21OY/dHC/dkuACpYH/+YMu1JcfQAHjMv9 WX4A== X-Forwarded-Encrypted: i=1; AJvYcCWYYUSX2smDtZGiG5TppjquOinug+dbmkY3vajhF37pwHQyh5GYRKU4l4Me+dOAPBLpAnf++6aFDSJYvY8H27SoFg==@vger.kernel.org X-Gm-Message-State: AOJu0Yyajq2ZNMwoNhqGBMcJEe7mPgrgkHGwmrWIaOUB9WTWPv1+ABIS 15NNRFrcjJISZohz1EHcXDUKjjqaA2R54l6xT9Blu10d4ZHxBGSnUPbWd7Nuau4= X-Gm-Gg: ASbGncsnjf7wkAu9XC+8vdD90oxfax2GQPrxyQ5tug0lQdrezoJ7AWsqkuZCSZmXLfe khzC8ALuwwOYV4c7WPQlEL5ig3919wtdOWlhqpAKsgGdytd91YpcfE/h3UR5U7PirsAtDx5fqd0 4DskMoN7M7ZPnpr7/Rpz72YabH8Wvq6lsORHTMVj/8W3LdeknE+YAoirTk599sqw7caYHeAPvHr 8wjVQSWY907ZTEDCTWhTZ8sidQiwBWvqvbUU5S67tX5T7n6ZXJXQITi90zS+jbY9u+e5aOrPWbu Im+X X-Google-Smtp-Source: AGHT+IFbwxrksVk/MTeFkTAjIssqvXFYbv9NCxbCkjPtRUqUluTZ9LIe0N58I+leYtxliC1iMWLK8g== X-Received: by 2002:a05:600c:46cd:b0:434:882c:f746 with SMTP id 5b1f17b1804b1-434d09c8e42mr68216715e9.17.1733327904095; Wed, 04 Dec 2024 07:58:24 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.161]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-434d52b5677sm29043695e9.37.2024.12.04.07.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 07:58:23 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: gregkh@linuxfoundation.org, jirislaby@kernel.org, wsa+renesas@sang-engineering.com, geert+renesas@glider.be, prabhakar.mahadev-lad.rj@bp.renesas.com, lethal@linux-sh.org, g.liakhovetski@gmx.de, groeck@chromium.org, mka@chromium.org, ulrich.hecht+renesas@gmail.com, ysato@users.sourceforge.jp Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea , stable@vger.kernel.org Subject: [PATCH RFT 6/6] serial: sh-sci: Increment the runtime usage counter for the earlycon device Date: Wed, 4 Dec 2024 17:58:06 +0200 Message-Id: <20241204155806.3781200-7-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> References: <20241204155806.3781200-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Claudiu Beznea In the sh-sci driver, serial ports are mapped to the sci_ports[] array, with earlycon mapped at index zero. The uart_add_one_port() function eventually calls __device_attach(), which, in turn, calls pm_request_idle(). The identified code path is as follows: uart_add_one_port() -> serial_ctrl_register_port() -> serial_core_register_port() -> serial_core_port_device_add() -> serial_base_port_add() -> device_add() -> bus_probe_device() -> device_initial_probe() -> __device_attach() -> // ... if (dev->p->dead) { // ... } else if (dev->driver) { // ... } else { // ... pm_request_idle(dev); // ... } The earlycon device clocks are enabled by the bootloader. However, the pm_request_idle() call in __device_attach() disables the SCI port clocks while earlycon is still active. The earlycon write function, serial_console_write(), calls sci_poll_put_char() via serial_console_putchar(). If the SCI port clocks are disabled, writing to earlycon may sometimes cause the SR.TDFE bit to remain unset indefinitely, causing the while loop in sci_poll_put_char() to never exit. On single-core SoCs, this can result in the system being blocked during boot when this issue occurs. To resolve this, increment the runtime PM usage counter for the earlycon SCI device before registering the UART port. Fixes: 0b0cced19ab1 ("serial: sh-sci: Add CONFIG_SERIAL_EARLYCON support") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea --- drivers/tty/serial/sh-sci.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index f74eb68774ca..6acdc8588d2d 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -3435,7 +3435,24 @@ static int sci_probe_single(struct platform_device *dev, sciport->port.flags |= UPF_HARD_FLOW; } + /* + * In case: + * - this is the earlycon port (mapped on index 0 in sci_ports[]) and + * - it now maps to an alias other than zero and + * - the earlycon is still alive (e.g., "earlycon keep_bootcon" is + * available in bootargs) + * + * we need to avoid disabling clocks and PM domains through the runtime + * PM APIs called in __device_attach(). For this, increment the runtime + * PM reference counter (the clocks and PM domains were already enabled + * by the bootloader). Otherwise the earlycon may access the HW when it + * has no clocks enabled leading to failures (infinite loop in + * sci_poll_put_char()). + */ + if (sci_ports[0].earlycon && sci_ports[0].port.mapbase == sci_res->start) { + pm_runtime_get_noresume(&dev->dev); + /* * Skip cleanup up the sci_port[0] in early_console_exit(), this * port is the same as the earlycon one.