From nobody Thu Dec 18 09:49:04 2025 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 999C22144A9 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=1733327900; cv=none; b=oww9CujfF/1K8dV1jN3dfUMzgR7Yvbd4zxc1YRqKI0Vi92ZSrrY8b7wp1NesBllEnrcqYKeuDAZnKuHKgIEiKqOIblLiGo5HnVQ1hjk400f33XXCicdV1RUOeCFE6RqNsNQK48u8/YcN/EPO5HF+vw3WuR78fOE91r6XTOmNlao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327900; c=relaxed/simple; bh=eKmGJN/hdldvnD2ziuy0kMEX3JoK/YzfUj6m/JU908Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j7ioOrX1UYB2aub9jQ+/vbUHNCfJgG5to7dWV86BaxSpdDQ+QKvINAopkAAGmoGE+FouWSmYUR7ugtEQq0iuETIw5mE1ZCTujqir8rYiPWJgFMaVLeHGHQperWNzduamtTQCEWr0mj2z/VJWV1bHUokoW+SiBj2SP9V+chnLAGo= 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-434ab114753so59033345e9.0 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=G8GB3WRKGbwbjbYknRT35UQi1RgF1x/ytVwG1qW7zsliCXYz9FiX4hQx8VpvhsZ8FA 8/FRSsWtc+MYZr/RRt6jVBVAPMgEvrEt8KCW4zgENCQgExKFkJtdIfs3ifUWbWARmZ/A teLCxuzMWMCNyi0dSXaaI57v9S4GjQl7uRPxT7Be8r3hQlPYZl34+P+yw98qtdu7PdXs VIopxBkwyO4OZYKpp1/e8o9XPf36c5fMqt/LGg+QQiz/MFzdeDhsNUfQUnNoWI1BDoq+ j5hhmuMHQCdD5HZ/w7ex2GCBoa2aLXI5u2+y673TCmCKPKGnOOOVCT8XgAPTFEpBlJWE V+mg== X-Forwarded-Encrypted: i=1; AJvYcCVnnVE3Uhk0UQ4XvRHBzP9kHsxkq7pIe2BQLOrW5CS4+llg0+F0FgtI4Hg1/dqZzfDxWe8XEO2li0ROlj0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0Ld9dZCB5heVWyVlB/7W6PM2fFtAwzUnIZFWeYDNjf4sRE8Sn 8gKIfj5Vz0HNII8BZR/t+DoLJafD9GN8gvWS5NT/Arw7aSVumJx+QmMW0qb4awY= X-Gm-Gg: ASbGnctItKVWqQA4yNymy8+Uem2YFqShUZZJcpAeZ3VIkfa3Oq7K2/00VCWfODlKLAx B0pXul1HoC3pyfbI5MQ2HRCaBeEKtkCLiUHz/HBq2JO7vQo1BVwpymwOGjlfu5yiM3+fP2BhrRE 8aZ9b43cRjs1pmEr642k6mJ14tFLjCOCIKruONuib31TsKcbtTay4JKg6Dd9hwrOr/w5RmGyTbq buWh/Zhxsw6lihKZ36yWyysDD0jw+GvCFYKYFpgoF1pQ/lftXP7pumgf5ETu6BM80B0RU0c5kOZ 2tPY 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D0 if nothing has been transmitted and the FIFOs are empty. As the TEND=3D0 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 { =20 bool has_rtscts; bool autorts; + bool tx_occurred; }; =20 #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 =3D &port->state->port; unsigned int stopped =3D uart_tx_stopped(port); + struct sci_port *s =3D 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) } =20 sci_serial_out(port, SCxTDR, c); + s->tx_occurred =3D true; =20 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); =20 + s->tx_occurred =3D true; + if (!kfifo_is_empty(&tport->xmit_fifo)) { s->cookie_tx =3D 0; schedule_work(&s->work_tx); @@ -1731,6 +1736,19 @@ static void sci_flush_buffer(struct uart_port *port) s->cookie_tx =3D -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 =3D dmaengine_tx_status(s->chan_tx, s->cookie_tx, &state); + if (status =3D=3D DMA_COMPLETE || status =3D=3D DMA_IN_PROGRESS) + s->tx_occurred =3D 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 *po= rt) { } =20 +static void sci_dma_check_tx_occurred(struct sci_port *s) +{ +} + #define sci_flush_buffer NULL #endif /* !CONFIG_SERIAL_SH_SCI_DMA */ =20 @@ -2076,6 +2098,12 @@ static unsigned int sci_tx_empty(struct uart_port *p= ort) { unsigned short status =3D sci_serial_in(port, SCxSR); unsigned short in_tx_fifo =3D sci_txfill(port); + struct sci_port *s =3D to_sci_port(port); + + sci_dma_check_tx_occurred(s); + + if (!s->tx_occurred) + return TIOCSER_TEMT; =20 return (status & SCxSR_TEND(port)) && !in_tx_fifo ? TIOCSER_TEMT : 0; } @@ -2247,6 +2275,7 @@ static int sci_startup(struct uart_port *port) =20 dev_dbg(port->dev, "%s(%d)\n", __func__, port->line); =20 + s->tx_occurred =3D false; sci_request_dma(port); =20 ret =3D sci_request_irq(s); --=20 2.39.2 From nobody Thu Dec 18 09:49:04 2025 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 376122144B6 for ; Wed, 4 Dec 2024 15:58:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327900; cv=none; b=MdrAfaUiQUKt5FM0RfjhHHVuJ8dahoJgL7KetpOmI5qdcEHzO34mpvDl7QBd6biXi+cOVlF9cBcNJ0SJNx52vqBvq47WQglA2OIOFfTyORTl3LiHJAsTMLQItZhamssPibTRFg3V+2LomYONIxezWbpLclDEwslKi5fsOvXUo3I= 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.53 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-f53.google.com with SMTP id 5b1f17b1804b1-4349e4e252dso64926555e9.0 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=d318KgHUllY6Uk32IvxhPntEQHrVpcoKcVCcoEW6qVkYv/33URbJdzdMdhv7e5dtLo fwfWnRfxqIHr1g9euR3dKYkM48/U+BhOHAANtzKUEtKJ9hyEHl5sKc8FdiVfLz4hWfyB whK2TwpevUnnI4BvJl3INl+lU02+9SnigeQVAnCirgtwG/1kJ8p+5onmpfbOi/wplSDT JnaS5hE928Z09A7gM2qfCplhD3D8zQUGSKtoZrh9+Qc1Ne+3ZnDKqZs/sEw5zZ0ZucT5 +O7zhK+5IWjiDSs86zHZOWQhXNwgI0B4cQzUgxOQdrVfpoUFdu+qQvT8ytMrc0NtQHUc wbHw== X-Forwarded-Encrypted: i=1; AJvYcCX3/2dfhDkp9tATS/a5Fb/BDSar3/4ifN+kAWrLHmEmId1YQqEnyMGxzl8mMsrp0xoCe145s+M3hv8icK8=@vger.kernel.org X-Gm-Message-State: AOJu0YzKi5qgDRXGyVP+Z0bwpx+/0Q2EaOc8cqie6WdGsxkXkoxI1s14 p8ht8SF03yX4UTLplMz5iUhfORqDuLRO2s9WhHsLM/aCn4rGpYKY+T2XaN2nwyY= X-Gm-Gg: ASbGncvxZvZylkhQ0dCFztxweS1qc8lOHME0DkpRgguPSr1RugbXuG11JTmM1nEFpDv drDzF+qZfy58xwzdCH/uGvBHJJqQSFfRHlrPa7TYNppiJqaBxNgv8uI/5FYkcSoEHebKHSF1c0R aeV+WwoJ60vv1UkijxhzGvaf9YcK3FgPnmp4sFjXuw2ZJMgbofk3Bkd8mSHBYFIikL195Woflze wLvIQ4ZYAdxXs0G3zWmxKPSwPFNOSazrmuxFPzesvqZw9uOGw2BwPZQW91F7adEkZ7VPVJiAPe9 Wr6v 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 'p= ort_cfg'") Cc: stable@vger.kernel.org Signed-off-by: Claudiu Beznea Reviewed-by: Geert Uytterhoeven --- 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_dri= ver, 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; =20 static int __init early_console_setup(struct earlycon_device *device, int type) --=20 2.39.2 From nobody Thu Dec 18 09:49:04 2025 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 C3B152144C6 for ; Wed, 4 Dec 2024 15:58:20 +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=1733327902; cv=none; b=e2fuD34YdGm5jyGEqzU3ux2QqqLkpiff0dI5VQgSRFduesfw6XX4yJWnJDdqxqAEo5hWrwG2/hqyUWoGo7IKMhAl2JlWSJIDusDmXnkdVPiCHjC9yWA/oQahKkx7+tjcl5qdEqbTLoWn7oQEsYHEh6hFczAd1kw3KFCxZNHrBTE= 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.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="jsPFp6Cw" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-434a044dce2so85314225e9.2 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=dJxINtPSAOCjFEqvrElr83cPveV9nP/jtQVHGmSboMQM1D5sNM1PTifmKvXSkq1RFS X+kzs4LvXkpIzCGm08Uti+P6daICViHopqEtvaO0ZURoAQSDn1xC8ZCIM0JxrygL4xtX iH2+a1+mTpFpboqKfOAM1GTvF1kCCSkPxgTsaWOAaG95aotXeCl8p7XKha02ND5wy+Uw f0K0sYQ31J9Q/lpHNM0EPJ+RuB557n4ig1GjMiq46B38Ar34F6vya6vIBqcKrt2gcebl Dl8FMBSxgFgCSgUGYn8aPzPBsMyw0J/ExqdvKv7hTKCLAclMf5p4X+qfg7sXx7ES1pBB fHkg== X-Forwarded-Encrypted: i=1; AJvYcCX8gDiUlT5pG9ZR2Ky7foH/EPuMfMR3+7VwGpFDMP2UBGbx1I9g6ednUw/DS0p/OwUvRasKOHzHLs455fg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw74Cz4AysRcVO1a8J5jiE57seJ9YIWAue/kw5sJDRTxq6/tdzt a+X4ZzUxrt1uEcbIrZweUXm3kwlhl5W5v7k2jpyS/BomvdfOY4pMg3euasaIRG8= X-Gm-Gg: ASbGncs6mGR++YfJmYanBfXTmfD3p1fcuQ7eGD19itn5fJRq5QDfCB87aKAzWt5UI/1 y1aTRHEl7nBrKnYSswR9e9q0XsCszG9RNOkn3bcUSYOmsV7jUAtyqUuSNmpFTvrowtWxJXXPirK jGhjTEZjX5QW3OIyHoPVjZ23ef3AUM+BheSXocVIeDZm5iHs7ET+DfUPVaLg1zhGN2U/gKUMIvC xxfxsbSqVF2nrkUGdkNQKlm328cvehbPxii8x9sQnEgsKYszSaHFG3FSJxsiSyAsvNLwLvi9fm7 oi4O 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Geert Uytterhoeven --- 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 *d= ev, ret =3D sci_init_clocks(sci_port, &dev->dev); if (ret < 0) return ret; - - port->dev =3D &dev->dev; - - pm_runtime_enable(&dev->dev); } =20 port->type =3D p->type; @@ -3086,11 +3082,6 @@ static int sci_init_single(struct platform_device *d= ev, return 0; } =20 -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 c= h) @@ -3260,8 +3251,6 @@ static void sci_remove(struct platform_device *dev) sci_ports_in_use &=3D ~BIT(port->port.line); uart_remove_one_port(&sci_uart_driver, &port->port); =20 - sci_cleanup_single(port); - if (port->port.fifosize > 1) device_remove_file(&dev->dev, &dev_attr_rx_fifo_trigger); if (type =3D=3D PORT_SCIFA || type =3D=3D PORT_SCIFB || type =3D=3D PORT_= HSCIF) @@ -3425,6 +3414,11 @@ static int sci_probe_single(struct platform_device *= dev, if (ret) return ret; =20 + sciport->port.dev =3D &dev->dev; + ret =3D devm_pm_runtime_enable(&dev->dev); + if (ret) + return ret; + sciport->gpios =3D 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 *d= ev, =20 ret =3D uart_add_one_port(&sci_uart_driver, &sciport->port); if (ret) { - sci_cleanup_single(sciport); return ret; } =20 --=20 2.39.2 From nobody Thu Dec 18 09:49:04 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 94AC620FA95 for ; Wed, 4 Dec 2024 15:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327905; cv=none; b=P1bCKNXJmUJLOXPMGAMEdhTJe43PEpD0pFu9zLmYF0q1amdQRD+hRREgq3j55nWvIcAtmkNGIvYfFxwr/0qgsf2ChQ77uAAjWfWIui45tid7mYg2ThkbjYzV5CzZym63IhYa27Gw6QuX0LP4AJcwgxvXo/S+dY5QATDu2z80ak8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327905; c=relaxed/simple; bh=hNvsm/KT1uK/VLwkIurCBjMDay2qykQ05TtUGaANs+M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pvJzsfX8krGbm4Wz/PcVtxzCIqlgj8VazMu1etk9z/oDuGsEb3kzQ36Rt3hUWG2gSTZgemA8r9clB/MFbNb1rzywnY6qe1+70HWtLx9oyVh7IMo1lxQyxr/IW4Qo8Un1SRlNznwea1jomCuINEQfvWaVT3QoyKg05Y79m8+D6Cc= 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.52 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-f52.google.com with SMTP id 5b1f17b1804b1-434a8b94fb5so6916045e9.0 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=C5K/4XTWnZQ7rEWXfYn60anPTbjknew3mt9raGAHXWXatCNdvV+YFcwa22cEldjxf1 vJciEbQftwd7U3QwShhAlgzocSVDfsdBzyM6gGiPAhOLkPZr1UG4yOVjDR4u45l/HWJh MFHkPr4wwPZvx6T6Q2B0l5ISWOowI5yl/lSyiwaqBi77J8N5wSszBsQs2rh6b0AUt5AU iY5aSgSWrsArWbC+AN6lPGbar6rH5jGeZLqdihlt4FRXT1HIMISMr6J6K498wf/xV6Ea P3SzRX+0BG+ZGyATnmsa2ZRq9nSt5+Rx0F5DgEprIGkUJ12ol3ePdjeP3/hCPZiwf21x iiKA== X-Forwarded-Encrypted: i=1; AJvYcCU/6FCiat5Tx5T7B/YKOwXPuxYB1kD2Hkgs4Xtf8jJqy2rFC1hTgVhrKhkHhkjY4Gb6fM2FCdTTFfu8IOQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxwiyZclyCgBX/DJLR+Pfzvrb0YFNWd/LipzUqFoOiaIz5rfau8 XNKtnmZ4rco5GnSRfS36OhuwjrUjBAPu8Zh/3WdxAP/Jzuszkj3ZJnP2OaX4H0U= X-Gm-Gg: ASbGnctMWtxNnR3teWTnUtxTJfRtv/qxNc0/l3DKqvq01VbnLuXdlDpaHVtudVT8wRw mME9J+tkf0IDohDZcucjVHqyPFUxy7wqqfd6sXkppGNJiMZoRVS0dWL/71WibKrCEzfT53cPD9O oiP74AX4MmIb4gghtatNmhlQTHKhPtDKNADFXrY/f1RCyVD+e2DdYW1mEVaAeOiyPoPQxq6pL8M jA61q1DW1VmPiTxKyVNyzSQWegogCgsYb8oeDlhTYLHwIv5Ea990WBUvsSRNn4i6NytPVj71nSB i1zD 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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; }; =20 #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS @@ -3443,6 +3444,7 @@ static int sci_probe_single(struct platform_device *d= ev, 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) } =20 sp =3D &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 =3D platform_get_resource(dev, IORESOURCE_MEM, 0); + if (!res) + return -ENODEV; + + if (sp->earlycon && res->start !=3D sp->port.mapbase) + return dev_err_probe(&dev->dev, -EBUSY, "sci_port[0] is used by earlycon= !\n"); + platform_set_drvdata(dev, sp); =20 ret =3D 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 =3D type; sci_ports[0].cfg =3D &port_cfg; sci_ports[0].params =3D sci_probe_regmap(&port_cfg); + sci_ports[0].earlycon =3D true; port_cfg.scscr =3D sci_serial_in(&sci_ports[0].port, SCSCR); sci_serial_out(&sci_ports[0].port, SCSCR, SCSCR_RE | SCSCR_TE | port_cfg.scscr); --=20 2.39.2 From nobody Thu Dec 18 09:49:04 2025 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 24088215F68 for ; Wed, 4 Dec 2024 15:58:23 +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=1733327906; cv=none; b=oL7haXyg4pxV7NUzFJPHkw+HyoNETZdNRitQB5WPdx2aARTXX2HzmHF4Hd7OT2ugTBBWM1se6HaE9W8vSSCjHAJKBP5JTOH+FJ+q5J7kV1m1qZZesD4ZbVLYa9Gwi2h97NNoTkiHbcfFBop4rSGH5SZiwTsAaqOX5fLI1VmHXvI= 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.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="iU0RE5p9" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-434a10588f3so45734155e9.1 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=JC9z720wCTQfkL2itWCsSkAfa0ShaeAe/cJfCWZJAm/ipFhGujEuUfTEefRYgTJRMZ PCF1Vias0rclhf9aIKCIxo8alDoo8ayhuFDf7oq5MjJa7WLHuY2SC5Cna8IyQm5wAEqJ MZ0L8sSZzJMswiGRzdppFbFmGa+8Nr+OFOT/kNpp4Bh14nA1K9qIm0QjMgi7DHKil0w+ FFly9gpMNtPOOSVTc2IDkFDwRkSdW9RJcwDAqW8suFk5CiyEVax9lDhh0TKGNXIRfUdD hx3bxCRQ1GbIvzvOKLmG2uurXXRcoPqpOrxH9P8jSLpMnOhLuOaxS72kpSNeKSLQ3GBR vGZw== X-Forwarded-Encrypted: i=1; AJvYcCXGsB0agthDadBAW5Ud4ZPzP6kxzN0dgwHetwQ+fQiMCGMpxxEODRkMIT2Tz6f4NnldolAF0FF13/E5i0g=@vger.kernel.org X-Gm-Message-State: AOJu0YwKXKHXkGCEFoiyg8kdrS4zqemfQqy435MQT1gqj+Pb+Y8Acaxc wo1/cZLztTKALOXePWt9WzhcyRrup9BWZQZdTnK+WnRDLrGKFa0sBDwNNgb96zU= X-Gm-Gg: ASbGnctWRWhrtY88X842HS5amghhnClSx8fVXHUqN5D/1EbEPc7LEjRt9qaPwhxNmta 7r1PxBiaOUImgmYmknlB/VhEQS+FeOOZWy5Wrjdb+YkBR2LK8WBo4ePjnrjdTCgZd6cbpNRye5J 0C06mZLlGRQB706GjqccFCFBfyquj90XT+9jGGdr3ubR1874zuQGjFcYyyHflAAqCVdlnGamqQJ Uv9sFwLhpeZVmF/vI9Qio+z2sZ0YFbOjOyVyI/mLxhKzRvk9SH1fu8FbuxjObnHdCZ8HxCVfcYm J1ZE 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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] =3D port B sci_ports[X] =3D 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+ivU8oFiXR0FXF7Lrq= v5dWZWYA@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; }; =20 #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS @@ -3386,7 +3387,8 @@ static struct plat_sci_port *sci_parse_dt(struct plat= form_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; =20 @@ -3433,12 +3435,15 @@ static int sci_probe_single(struct platform_device = *dev, sciport->port.flags |=3D UPF_HARD_FLOW; } =20 - ret =3D uart_add_one_port(&sci_uart_driver, &sciport->port); - if (ret) { - return ret; + if (sci_ports[0].earlycon && sci_ports[0].port.mapbase =3D=3D sci_res->st= art) { + /* + * Skip cleanup up the sci_port[0] in early_console_exit(), this + * port is the same as the earlycon one. + */ + sci_ports[0].probing =3D true; } =20 - return 0; + return uart_add_one_port(&sci_uart_driver, &sciport->port); } =20 static int sci_probe(struct platform_device *dev) @@ -3496,7 +3501,7 @@ static int sci_probe(struct platform_device *dev) =20 platform_set_drvdata(dev, sp); =20 - ret =3D sci_probe_single(dev, dev_id, p, sp); + ret =3D sci_probe_single(dev, dev_id, p, sp, res); if (ret) return ret; =20 @@ -3579,6 +3584,20 @@ sh_early_platform_init_buffer("earlyprintk", &sci_dr= iver, #ifdef CONFIG_SERIAL_SH_SCI_EARLYCON static struct plat_sci_port port_cfg; =20 +static int early_console_exit(struct console *co) +{ + struct sci_port *sci_port =3D &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); =20 device->con->write =3D serial_console_write; + device->con->exit =3D early_console_exit; + return 0; } static int __init sci_early_console_setup(struct earlycon_device *device, --=20 2.39.2 From nobody Thu Dec 18 09:49:04 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 F249921764E for ; Wed, 4 Dec 2024 15:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327907; cv=none; b=RbHw29fwHuLxoqB2nlS0Q8137vj8444am4WZPYv7LmeBOvOijDvYP4dPrF2tIXL62XCw7tOa1uyO7K8LGbSoVpW6/Ta1gQ13JHB+G8pY9i6YHA+WvNGz7IBKZJI27y8igFEQLA04jkC+f/xUzJ/OJjhTZnWfs0pl9H39eKLqT/E= 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.41 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-f41.google.com with SMTP id 5b1f17b1804b1-434a752140eso58880075e9.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=VXJhRoT3pmsp9XiTSN0yTvP3528faToE0hTBhYo1vALQM+C7ENZXUcmmEni8xo+uKb 831D5BC8Od0AtRbD3ui5W6L7iV07+PZC3AmAA0ic6hncaMlAKjJ0YYpPieJL9e3crhkx PNVbKThbI7vmxwJ5itxMdvWyL0CYViUr89VQJJDP6tf4/uDN9OYz27mWAVTxd+zju365 vuA6TuLI/Sx3/jNHpSq2j2f8LpHOkxL3Q6i86nYX3kuinClmbhsZSBKMbINBT7YdTcVl YCZi2y6kzqH0pLJ5gUShaJ0NIPeG2CYbECPYUcgSSWP+GLEE6uQYT0Roxkm/EDyNoA2q JaHw== X-Forwarded-Encrypted: i=1; AJvYcCU68fqdkZVNToxgnNl8gcZIz0oHCKCGjod7ulUNd7xKPNaxG0nN4cuqZmqcTe0bHd4HYm3gwAsc1Ej5GGM=@vger.kernel.org X-Gm-Message-State: AOJu0YwZbXKwhB7GLJDUNrhYuhgCRGKhjsNi1m6EvjvUuxcwea1mcH5S zAewO1ZB78dlaP/zblLs2+7hQOhM9QzdjxZB6hmPpkk/+uJemmV0vu/1col0xvU= X-Gm-Gg: ASbGncsoiDEIbBaswV/wU57KxasoLhZuZBZpNyFl7GqElozmWbJyWfvXXUTWeLZ3C72 4+/MN8Rqqqd1VfsHZ7u8WP9RmHaluN3ZWI8lWcIB0tFDCc4ZselXcWQD8WiNeN8TtsGUjjL9Duf nHA5fatMX14lhBYXVPB4+k9TtuiftP0vy8cxrm6JV5LyoVIrhVc1/9cnb62J0YjsytedgJmLKag GgUpzYevOsjueG+siPIFGyrzZe0Q7RgoUL+19rP5fBm4FqSiWNChBc6++Teb85OX0kMKIXDkXC9 +pSy 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 |=3D UPF_HARD_FLOW; } =20 + /* + * 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 =3D=3D sci_res->st= art) { + 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. --=20 2.39.2