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: 847783 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 A31AB2144AD for ; Wed, 4 Dec 2024 15:58:17 +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=1733327900; cv=none; b=XMnobjLyn5XgKseHoj2bF7cldW5qQxIAZM56ADFq3RA2Jf5FkhXI6bPwehJpwslK4vCa8h/Mp6THSW35PjBvmefcr2LvzaCLxZgHusol72dXdiqds3PMeM2AwcN/7AVt5uDC7rhG8BFNxnJMVhi36j5lMv5Ne5enb1KG5W7lI2g= 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.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="V7zFlQL5" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-432d86a3085so58889115e9.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=Wg82wDxkJCFeyxwvBwmPajkEo+7bt0vkH2i2NDKzC+pKpCEtJmom5J/lLaTPCh5c4h 0KNgWhkPJKR7wv0v3M8fEu/LnjJLGNq+G1FM6UPObyyQCEBiGn4zCpn8b4L0vfbvZ/py /MM1FOHb9OePTWbYu+BlLTJZ7ZUavI58qVUz+Vv+ogE0aUbTdp6OC3E6dOtOrLWA/1LD BoJESDxpdmt58mWrR1Wfeu0xY133xdqC33WhKm3A1ZDVXG67djQhwEcFcOxaJtlO1PyC kK/WHGUTk68m5K/pFHb9ZSne+FlyDI2LLQfwK6q3ACIwoldBp3Swv2Qaahu/FO1c/Lhr RGHQ== X-Forwarded-Encrypted: i=1; AJvYcCU/DnoaEyLI7N1z8rNzVjxPuio5HKiCLodKrZ+jPI0l2ayvfN9L3H5XjIOAPjCoGzaD4Uq+LKlfJxEZ/Z8=@vger.kernel.org X-Gm-Message-State: AOJu0YxRRNSWjiThT8Zx55rE4DPVFWRE9l0tmyHY2PM6fE1Pq/0HiEpp dra0hCcTUsgdiyBF/emRAc/6X3n7CU5+lARmeP0XyFj2Yv93LhWjBcph7PNcECw= X-Gm-Gg: ASbGnct/SAPJdyw9HbsVypPu7aJSM4GKJMyX1n5QHdrj8I4YLd/uRyxg0140B/ThXAM J5KcSvfteAMEMr+PcI0gePSyvjbhZKZCy1DkobnZMeoi763pw1dFhz+L5i2MzLJeO3lsmRDdg9H BNHINtO+a8MrsRO4u9jSYI7fTWYPnucOdmYvNNUD4ORdMNjEhlgHxqzR8E4U6xi8LCmM4j01S1j t7Om7pITdtQqe4mRqWrPdCT9eoVQaN/zwV5gaDHkqJj3RCHKoV1s5i1avgpNvb/pwBXsDyrP1yM xZ/s 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-serial@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: 847550 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 285FA2144B0 for ; Wed, 4 Dec 2024 15:58:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327900; cv=none; b=tUp525Ekb4CDGed895JlMAMxjv9Nx876RUfNBm6djjFBanen/dIAvgN/7zANT376SWJbFE+jVN9JT+CzNRXqL4WeoLWtFY7+vx40rpEjDNcrh2VSAXKnLr7l/nwvN6fDptmjU3iL3qnGchFtwgofgXyqPsW8ukhyfom526eRYeQ= 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.44 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-f44.google.com with SMTP id 5b1f17b1804b1-434a1639637so64836405e9.1 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=pO2n7VPqRcX2MnbXcIkBa/QjVB6W7sj9Ons/pjq0JRrvdZ3ax+mhZT9XWHW1haIuc3 4Ct6M8E1I+xa5lGzGy4PSStnVqIs6kDsZ4xlNE6FhNM824z5INuKrOaRN7qXliDH7XaM TpZgtrDU9r1Lgz9oAtmbzVPRrYEPbufIOLIadEuLqRhgf6C6w0a9xI4w/IXaaEXIzY6G +qkmJ/D9pHn+QX+ln1BcnOf/qllO9Bhnj2O2lzL26CgU11j2DIpPFyPOozsrLqEQbozR dsYcuf4yI3U4Hf6ya7irqrob8FNJbmCrJAB6ajk+zxfilHnznXKvaGZl7d7CHdkSsubb AlNw== X-Forwarded-Encrypted: i=1; AJvYcCVzr0BSk7TFJNDnRWrhysH0WNbapaChDyvYBdjfqyDkep/jtCSqDtRn/Y5KontQRS2Ca/8zcX1QTyavGv0=@vger.kernel.org X-Gm-Message-State: AOJu0YxlL1v5+EO6WG7lflfWRE8vYLbFX1To5YxYvA1Hl1JPWkB66jTA cN64SDAD++1oquhcqFray8Z1k9ZvtnOOVqkAk1BXoyN+cJrILYYBDhDMod1/hvQ= X-Gm-Gg: ASbGncvqy96/nNuCgMNRwrUfcKJHvAisNvpduXcMSvG82yFuSGO/1OQz9BkRYzeb6vv CC+VEhthAo4k3dPWY7pqsGdON24vEd9UFdZLSGG0YMpup8cjvbF92sfYfpJlNy3YQltuBMLMJ7H +lWXLirgLNCdxXkwhnrdh9BITNYeZOC4QWTdSUU5p/zaC/tN3Zx8stdkIJ8l36F96zu6ZzFSSK4 0PuRGNMoq9fF/coVOoT7BefAiWbpjzB8llEVM/1FdWi7FUJs3PCWBt5nuh65LLxie52RQY6jnSX SrB+ 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-serial@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: 847782 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 B83C62144C2 for ; Wed, 4 Dec 2024 15:58:20 +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=1733327902; cv=none; b=SaRR3LhRrnFSyocbomDrJDewnUBapM0WMPDx4gbSeELQSV1WcNbEjvMs5ksT/3OHaBEP+4YV0zmAiG58mHbdIazIw2zIztgDJh8SbDMelN2AVTikNt09j3rNtFzY1frwtQ5cGVbNWJ+ZvUykc81GtmVAqU5k7S0wgNde4z7ws3Q= 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.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="jsPFp6Cw" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-434aa222d96so85488715e9.0 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=ND45eo3himreu7NalZ1mYwVbhc8SCUdh2xZN5+qQp2gf/9srh0PLQkHniXDLLlvk23 fy1XqOCF3Xy3X6NJxK4KrnO6H3sxDK1xJUCKAQBJp1X3Fp+M6TgJhCRBPtJB3ZtyUkaq +123us43oFVJPx7PScvfv7EeZuhlGFyHw00quSmBbB/jbcMSpAvxdciv480l07fxbF/P 8OwWdYEZbcSIfbO42RcQiXORe6kZZHR/qRoGpqunt6ZJ+vPLRO4WrwZYnuw413VwVoda 6pLNp+9JK3W0T27/MzxngGFJtb9xno190Me7lwoMCr1zh+rSUjn10QD6Y2l4a4TFQF6M 89PA== X-Forwarded-Encrypted: i=1; AJvYcCVLe9VjzJ0gGoKKNFIv2BkI2WzoB1akTdecXuPMpo47TyVLlhTtF+TGfL0bgZ0zOjbSip9cpehDxDyaMIQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyIdMRHEJORxRAvVoCSypZF/BAXSitN/s5Sxrrh/JXHbfLJqm7N ZhmxgyhhZWmEHw5hcYvib4ru9HgBgagykni8HjzES8+lDI5dVXfRXQgIbrm3B3U= X-Gm-Gg: ASbGncsRQigOaZAK8E6jc1DVxYtIqqNeHx/W0elzNU+7PiiewgLsZed/l9kzXKiFrvg hZwn8l7QFZipTYj51EW6KzYzOPIbgrbyUk8OoJT7QIi2ycpxtQ4dDAjPoKr+v1i2TU+T/ZnhKTy mVXV+ojk43GBaNKJkvoKkfNBkgfz3Kd3DbmfqFkNDFiaKTRH30OBjAwJqGfFXHBq0BACwUqSOMO 3oq5ic07BYP04MmEMVELmANhJbghkeC38k8scqg5VLigN26Rmg3vCDJH30gjkBJrRI6xZCmWxGS zjVg 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-serial@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: 847549 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 6A7C6215F46 for ; Wed, 4 Dec 2024 15:58:22 +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=1733327904; cv=none; b=ohct4O0wit9oe4aOV1vAFojQW7LofSd2kBnF7lp9LY40gbxC7sr61YU6rNrTU5+LE9yAVzG/RGbvHQtRshfQd56h7SPdIksMH9oDoRnnsOIgvLTtSXZZnJQmpWrAIUHT3HeiqcGTnbPEyeldJBrhwqxoMcrjYg0kcXu9EiMQgww= 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.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="fiIZOhJ7" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-434a1833367so6813055e9.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=Y3FoepnJzfN1EWiMFwXU/aH3RNNxHDzMOfzuVEUX3h4kHSWy6ySuqS//1NURFI33zD iHdSBXN+xxw5+KfZXewQjpHTkvpCJLMX+L2u2PZ4MJxSv9uder0CjvJexP520FWXJJ8/ 46kKBsAdyOeFePS0a+J5OKu7tNafy1VM94aEb6cqQUpyxL5zB3e3Sa8h7s0v+Nq4Z/Au b4cfC6eDDxAJlYygE/CTGMZy/n36AMEbPjQc/fPBpl7cjXaOf56hySnNGV9S8fWoWghP v8EUsG60VdPj8WDXiaXFOzqrv/EgjQOvkAPj1XD1Mi+V4e53FbwH00t1NyPPqP7CSxfy ezUw== X-Forwarded-Encrypted: i=1; AJvYcCWJGLWK5jRGNRWxUPMHSfNyRlccjLPUviq2heuFul5apTOi1t5Z+/cquT2zmIVNjZ4StofZ1zkejly+tq4=@vger.kernel.org X-Gm-Message-State: AOJu0YwFNvX0caZGMDl8Q+5+hrN/0VnV+rAphv5/RCLd45vzNy47GCPm 9fzsFIsMDgXP6xBL0a/q9RGVBCeB04Q9P7P5aNDoieIsTUAl3JGTSwX5ufV4F4w= X-Gm-Gg: ASbGncsfaqTswe/3ZRswwiz0JsfpSFB/svYoXF/S14r+ArtumKD+nVUVvfvS4DEyamB nFBMvGt35JsOu+31ufx8JFJKEEjVQueun7smSQvifE/We8yDXgViYGFGQ/L875w2hn3eq4YXPPz jI0bzmTPIJPDQNdwt++laX8Dj32rUsRwf/Cdvh93oV4JsbI1RiAgDJsSlIH4JOjuiH1jI5j6TRv PpEp0At5P9NqIaBg8YnKlCoi49R437h2soDgeHn5tIVb5OrYR9lAijZ9eA9GjZriqmcvttKzuQO Yirm 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-serial@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: 847781 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 2186A215F66 for ; Wed, 4 Dec 2024 15:58:23 +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=1733327906; cv=none; b=OPBYr3bHYdR6viHQP8uvKJ2rfNGxvbdiHnVHLAJKs0Fhnv4z0Mv9FFgOxMDZbGNeJtnrnZFeVXjV9HIgWtL+u1H2khiBOFT6IyO5qEOLnWdCusTnkCgNCUkRtIewPgdfOuSsrcer/TjySic6WvVP99l1lY9l+q/mCPUazWIBst0= 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.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="iU0RE5p9" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-43497839b80so45690845e9.2 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=kWPRnDh8V5zj5yknMhKqrcoMga0qr0SIPGPJS+bVfzOBWQ05XZQKVQcE9h//8ofhmY FTtadD4Zi6bpXDSj+C5MFeFPd6GzkzZPEwoR/rOIdu67b8rwVUdsomGQpiNstzaZRkkv KBgrhL75pcqKLfXrOH18hdcvC997eAMbSYTO+OvuwLLPj4JycAX0fnUWdYtUkxkD2fgI li4WmF+akIL9Z2gBonSRL/neI0hIa7Ky+8aDVYX7qVWZ3NIV9weWVitpVY0iYtbDP9T7 nQaq2meN7zMYwJYE52FzqdMMWpGFshX7eAgNGVxiLjPPSfJAfZoL7IL8Vf0CvM1zrXzQ 19Iw== X-Forwarded-Encrypted: i=1; AJvYcCUWe6sgGVrRLBwXMDkU5rmZTcht2MhdEZNgGPHgUrv+iNftPWB07c5d/hp5HXCuyk0LNjVvkk2bv2KzZ8M=@vger.kernel.org X-Gm-Message-State: AOJu0YxQuPkGCMTYnbCCb+g8qhf3oNH4eQpr31Fdm/IczLKW+5l2bi3K t286j0dUlwvp+VWOxhZUx98YirtwM2fgzHUCbIY3QtZIo9lXsbZFf8xI9Cxxzqw= X-Gm-Gg: ASbGncvi9fLqZRjGiHyx0KQSNf6/q3/ugBONSIuYDaUJ8mlICVh3GygF7E4hhfw+5YB dT3y+4AmcMYnTnu4XKdZ/RCtkkXK77em08WwkispYhmdjLhl2BU3W9qJAyhF5RXnZlGcXz8H3CI XPhWf6jRgzKkV/Tm8E1FRr03dgBptEYvlKY7MXU4I9HqbLaq+iOZN3KIakjs5fi/ACWOqYGZkLv cTepf2d10HdbE4oc9OYOliYRO/oMJYRp662NlP1/l0Noq0esYSqwANvHyiZtP4vIZTCIx/7Iy7H BCxK 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-serial@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: 847548 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 DD98521764C for ; Wed, 4 Dec 2024 15:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327908; cv=none; b=lirgENK/ZG2EXnr4jvaiaSaYEL3CtUIzWY3GAWrCnAfUU8cZmsevdBgo78w43xoDYZ7G5M14o+C2Qf1lMX2EDH9yLaf8khjhXcVLJ9REoZaNF2wmF7C5syL951DX1Tumdv0cBjBlygZTyYzNDRMsojBR5DkSoI1h+JQi3OXMOWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733327908; c=relaxed/simple; bh=fnmIuQ3AC6S2Pd91eCPrbiQeWsPvWcflJGps7V3hZSw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eEIphE4Bp85S13aPvy9tz2pmSWVBOFYgPBhZB/z3fEL3mZQYjYz4ciX0YCXVUtv51FV61kVTqtsHkWTLgbidGG4cNDj8m9VJcSdHjZl7J/VVpa07Rehn32/oSZikofTChxAGyTqe2hEKGKr55E6n5XHcWMBlCjaLYP343f0AEaI= 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.46 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-f46.google.com with SMTP id 5b1f17b1804b1-434ab114753so59034645e9.0 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=WajD4aaynw4sF8bBNm0xi+esgtuF69yhGgZDhEb7+4KOaHa3NEuSjdK+y3nHXUvlpd heeUS7SNeWpmEwUKp5YPk4YaH4Vhc3g9K30JgbZvTOOzSdIIH5EfTdAhxSj0UfcmYKqu NMHP9nkLecfDZeAXKZqhUqZpTwzk7Ir7tAe2eb+whNR5AMcwHeYl6p8feKGgvIF9JHoE 91TFUPqsPv1Ysoa/4imBqi/zNdCaA6OTiITcxShVlstiOHsyhY5VO597b33wghiLWmpJ YGu5clAA5Bhw2J8x5/PkUZPCEnT70PwwgNAfV1nZq8NyMPTsZVyAOVcsuHJ//85pgrTc MMpA== X-Forwarded-Encrypted: i=1; AJvYcCXyorK3mMjAUd/j50DY4niMQEtrEovpGMXA2sjGiC2kj81K3INmzHGNAsa2srK9sCQzX7xajFMU4TUAFyk=@vger.kernel.org X-Gm-Message-State: AOJu0YwefiyyaSewr5c1z9tVs1NxruA3qcVrS+XxUG4/cHyOrwJT/lPm VFM/yHSV5EdVvNVL6t7CoNjZ/+RPK61IwaKx4p3ja6MqDfPy31vy8wcOaR1fiPQ= X-Gm-Gg: ASbGnctSNmL8LXoV3nQlyMzX65m9cjuPdZOHB63UC3esAHFgIkVtCpgVYFqsaq8Z3jL JPeMVaoPPwvSVkZopuxZxHJGr057iAOhaNfqilH9MYCTTR4kbh8qVSbJAVZkL2I6MMxus6Rqy/u 5l5c9tQcL0CFlfDV8/RSRgwvgDJZY27Jmdtw3XIC5ENyEAzzgD1Pi7/aw4E098IjXJoN6WvisWN C+aBK8S4l+MGlUT8xZ85vRY2xohQeHW3+acrviMwCUXeniFndkPx92Dwui0lVnjZXuOzjz2pXNQ SfIS 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-serial@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.