Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2025029lqb; Mon, 27 May 2024 05:42:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX2uoCgr4lSy1lzGSxF++D2DpbKkeLkhU+C1BhvAmZ14v1Q4M1nfNH6juWVxEctNNAgQrMPM6ls47pUCIHFu2hnonQYwBEOaPrixjdHAQ== X-Google-Smtp-Source: AGHT+IFc0J2qJz/qv4eDk50hyKI+ErzvuHgYz56k898PNEHXg9kHIrKZQlu1Xh60X48/AwKFbQfh X-Received: by 2002:a17:903:41ce:b0:1f2:fa51:6edb with SMTP id d9443c01a7336-1f4486fd3f8mr98350215ad.9.1716813730827; Mon, 27 May 2024 05:42:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716813730; cv=pass; d=google.com; s=arc-20160816; b=siGelX1WCo5UXus63L1uMu9K8HkQZsl4D4URR8DGYLvgiF4Gb5uguS55VJOl1e+pHL aV9OjjMyKMd9shQczQrBnCYnof583zNuK+TCSVa+hufgObzgoMB9mg8pXj3AVgVETmGI It3dvvCvB3Z+7/5691mxoieYPWdP917Ij172L8hTSaoUG1b/Mtdy+3kIYy6nQBkp8O6L Sja1qECBJ2bh3Q1aTS2+YjBVUt/NXtP+X+5jAkLhpTJfpiFzUZfDVdQnxLLNjNR0X/dZ kFF9eun28ixgHTd3IEzftwWQwjwwX+nz72iQwQj5jQdlyrNTkn6dqvewHhQAK48YlT2e x/nw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=2ZHeacqx7h9OIfULCl9v9Wa5T8h0YZ8Yzt/NYUCDVOE=; fh=JhTdWYFZ8w88n/94sqvWELMCujglPo7hfkIbZpbglA4=; b=uC5xoJt9F8qerXmyka68KRa34+U1u+6XdKWZMD8M8IQZX2YaAh4GQOwSVFtWF43dFR /Dlc8PmBWuQSnj5fenQBmimTUyYcTGalhjAqjml06ItQFU8MlbNLksSNfEH9Jr6vZiut V+8biDhFMN+NwT1WpwXOtd3wXqMACOCWkol9pZAL0MI7TvAKqS9hzIwWe0RaydXAgBrA nJDYueP1EHmD7GwGdd+ZdX8AK6dHJHDvjBwGOZKdU3M0ZUdH4g4KIEv9uUjcWSiMFmsL 4ctHI7QQeBfEmpCMwWCOZTqzbIuNHv+1X7MP9pgM+Ouvfht2A7pUJeO6O8dkXLeDwW25 SwGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-190595-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190595-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f44c971246si60581235ad.228.2024.05.27.05.42.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 05:42:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190595-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-190595-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190595-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C7CA628508F for ; Mon, 27 May 2024 12:41:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6BD015ECC6; Mon, 27 May 2024 12:41:31 +0000 (UTC) Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [195.130.132.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 A2DFD15E5DD for ; Mon, 27 May 2024 12:41:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.130.132.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716813691; cv=none; b=CH62pgjPCt8vQR8NEh2ayKgsj9ibB2AGENBpIUQGmhNz8b7Rbb6Q9XlUqfwmgr3f/WKyqhGYa2XoSdSdSb5o28Uj9iW17hIiAcggTvjVxyaMy+X3PsdTLOnoerCVaZEEE4aESNQv89wCuGlPML4+wAvtbL36guipfYrlI63nF/I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716813691; c=relaxed/simple; bh=DKPGT9zCwjT97JfwUeLGsvdXWvcfL2iqAGQFqV9g4PU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dSX71/170EM6vZGzf626Icb+hObGwpanDpEInB1GNXb5YFw3zScSEadGGNV0788tL5uxSu5o5UPUg10bWIOc+dmJUYN6h0VvOPHDlM93ifFlgdA2DnpttKjsXTnQXfQgNAY+hFXJgbZXIEHpu5hsXRQU5HqOoF6Fvx0hMJGOUz8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=glider.be; spf=none smtp.mailfrom=linux-m68k.org; arc=none smtp.client-ip=195.130.132.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=glider.be Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux-m68k.org Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed80:c993:5573:f894:7353]) by xavier.telenet-ops.be with bizsmtp id UChF2C0052nC7mg01ChFB4; Mon, 27 May 2024 14:41:25 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1sBZeD-00CfTf-5D; Mon, 27 May 2024 14:41:14 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1sBZf8-003hdc-TN; Mon, 27 May 2024 14:41:14 +0200 From: Geert Uytterhoeven To: Ulf Hansson , Greg Kroah-Hartman , Jiri Slaby , "Rafael J . Wysocki" , Rob Herring , Saravana Kannan Cc: Claudiu Beznea , Peng Fan , linux-pm@vger.kernel.org, linux-serial@vger.kernel.org, linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH/RFC 2/3] pmdomain: core: Avoid earlycon power-down Date: Mon, 27 May 2024 14:41:12 +0200 Message-Id: <7c5c0c8a10b8f755e5a75c7836b43cac63762eec.1716811405.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If the earlycon serial port's PM Domain is shared with another device, and that other device is runtime-suspended before the full serial driver has overtaken earlycon, the serial port's PM Domain will be disabled inadvertently. Any subsequent serial console output will cause a crash or system lock-up. Avoid this by introducing a new flag to handle a PM domain that must be kept powered-on during early boot, and by setting this flag if the PM Domain contains the serial console. Note that the PM Domain can still be powered off later, when the serial port's power state agrees, e.g. during s2ram without no_console_suspend. Signed-off-by: Geert Uytterhoeven --- drivers/pmdomain/core.c | 24 ++++++++++++++++++++++-- include/linux/pm_domain.h | 4 ++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index 342779464c0d7e84..97b9b50257eb354c 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -22,6 +22,7 @@ #include #include #include +#include #define GENPD_RETRY_MAX_MS 250 /* Approximate */ @@ -129,6 +130,7 @@ static const struct genpd_lock_ops genpd_spin_ops = { #define genpd_is_cpu_domain(genpd) (genpd->flags & GENPD_FLAG_CPU_DOMAIN) #define genpd_is_rpm_always_on(genpd) (genpd->flags & GENPD_FLAG_RPM_ALWAYS_ON) #define genpd_is_opp_table_fw(genpd) (genpd->flags & GENPD_FLAG_OPP_TABLE_FW) +#define genpd_is_early_on(genpd) (genpd->flags & GENPD_FLAG_EARLY_ON) static inline bool irq_safe_dev_in_sleep_domain(struct device *dev, const struct generic_pm_domain *genpd) @@ -725,8 +727,9 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, * (2) When the domain has a subdomain being powered on. */ if (genpd_is_always_on(genpd) || - genpd_is_rpm_always_on(genpd) || - atomic_read(&genpd->sd_count) > 0) + (genpd_is_early_on(genpd) && system_state < SYSTEM_RUNNING) || + genpd_is_rpm_always_on(genpd) || + atomic_read(&genpd->sd_count) > 0) return -EBUSY; /* @@ -2367,6 +2370,10 @@ int of_genpd_add_provider_simple(struct device_node *np, genpd->dev.of_node = np; + if (earlycon_power_domains && + np->phandle == be32_to_cpup(earlycon_power_domains)) + genpd->flags |= GENPD_FLAG_EARLY_ON; + /* Parse genpd OPP table */ if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) { ret = dev_pm_opp_of_add_table(&genpd->dev); @@ -2447,6 +2454,19 @@ int of_genpd_add_provider_onecell(struct device_node *np, genpd->has_provider = true; } + if (earlycon_power_domains && earlycon_power_domains_ncells == 2 && + np->phandle == be32_to_cpup(earlycon_power_domains)) { + struct of_phandle_args genpdspec = { + .np = np, + .args_count = 1, + .args[0] = be32_to_cpup(earlycon_power_domains + 1), + }; + + genpd = data->xlate(&genpdspec, data); + if (!IS_ERR(genpd)) + genpd->flags |= GENPD_FLAG_EARLY_ON; + } + ret = genpd_add_provider(np, data->xlate, data); if (ret < 0) goto error; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 772d3280d35fafa2..012d58ffc7059e0d 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -92,6 +92,9 @@ struct dev_pm_domain_list { * GENPD_FLAG_OPP_TABLE_FW: The genpd provider supports performance states, * but its corresponding OPP tables are not * described in DT, but are given directly by FW. + * + * GENPD_FLAG_EARLY_ON: Instructs genpd to keep the PM domain powered + * on during early boot. */ #define GENPD_FLAG_PM_CLK (1U << 0) #define GENPD_FLAG_IRQ_SAFE (1U << 1) @@ -101,6 +104,7 @@ struct dev_pm_domain_list { #define GENPD_FLAG_RPM_ALWAYS_ON (1U << 5) #define GENPD_FLAG_MIN_RESIDENCY (1U << 6) #define GENPD_FLAG_OPP_TABLE_FW (1U << 7) +#define GENPD_FLAG_EARLY_ON (1U << 8) enum gpd_status { GENPD_STATE_ON = 0, /* PM domain is on */ -- 2.34.1