From patchwork Tue Nov 5 04:10:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 2006629 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=HX3Xwqg/; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=aZ8XWsHn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XjFHb3JZ4z1xyR for ; Tue, 5 Nov 2024 15:10:34 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Jj2bIYZW5jUOvO9gFTfEZgMiRlQbSLHW3gYyLOEtack=; b=HX3Xwqg/rkX3EF qnjB9zwgQ9HmF8lFuW48bT1bFTyyVJjkWRRza0K1y9klwoQFfhzp2p1WDoz8w9rXuHJfJBzlNqmRv px85F4VpBq7myCUH4qhXT7FGOTRK5TQzuoEOYLncDAR6h/0bdttw4Dy2MTTyUQjecOToq5tdPs+6p GTgLztJb7W3EslURY7UZzUs+G90TrdOqYkxaNEJZaquXqRHtkEIYxj3uQmw7YsMruLvgD+z6MTTUp 4RHJhYx2J/R7SxIZGfs717kw5gceinum66pc2y28CZ09EDfbIkOrlYV1gZZoB2/aY9XYC6LGfFFwX MBtJKfX+kDfE9fCekbrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8Atb-0000000Fpnb-40qH; Tue, 05 Nov 2024 04:10:23 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8AtY-0000000Fpld-2FCR for opensbi@lists.infradead.org; Tue, 05 Nov 2024 04:10:22 +0000 Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2e2a999b287so4106739a91.0 for ; Mon, 04 Nov 2024 20:10:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1730779819; x=1731384619; darn=lists.infradead.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=hvP0nBn9Pd2xbRF/sGrzXTATg/4wU7eYIrojgqYv0Vs=; b=aZ8XWsHnz6bixficM04gl6sJGyeG5YffqsRTs5MuTzAR7Bj+Nvwcc1mfeBdNaYTp7d 6pdqzi8fds6Pw4iWd1FriwhtB0OQwk0zd1ooG9icLLY1OGolIL0ODbcqUda3eERSAtjp WXBY0eyZa+G1wCDQnsiAoCS9k0mAu5CBVR2+LDKZHsz5XJiZfjNPX7dUnh2kV8HAvVFn N6Sy9t35q6tdlw6IX/eqjpqOblLFBfzCjUS8Nu+OvPEv3bAFLeDSoLq/WrGB+rk2MjND bDOOLr9mALqHOS4UHnMAZUyN0rsZIzil+paqUOw5GIzr66opp1GtZFdCOSwNvZa4c4ML Vo3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730779819; x=1731384619; 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=hvP0nBn9Pd2xbRF/sGrzXTATg/4wU7eYIrojgqYv0Vs=; b=sX8WFf/oRgcXUQawyJKhWLrmYrLKzxATcZk3aIRNWQ0QzmBniCDT/u+JtUZADSLWcH CSdwrWdPOZUg+ltTa4fMgaG3jO2VqWnx5WgZHRUT2Tn7BlND3rvcAVJ1dHhaPzAs+zud 4kIaGUV120iodmGOO1HB/bXuJbVswrASC1NR+wf8SzpcLXydJbp3X/oJMpmT0kgNzQix ZT8pI1C6h236g3ePkJEoM/5IAhYORzf0RjKskqtl55D7TfbeKb5z/es/k30empWC639d P0BHNchp9UEsiB49nuMAkR4Eq6QnnRiM7WdFCG4BK2VYPfCi+SOmfe6nHunhyqn0yxNr t6Rg== X-Gm-Message-State: AOJu0YxvWnF7l+nqGkl6XAzHhS+QwBGdi8EDNxYgXQD4B5B8mKl23DMy C6/sH595UUX+QgIvpirK36IPK+5MQNKKW3sTD8CjMwWisbOZa+L5MpVNRZFKVHvaNi/pDKx87uC pEBXCuk2wz3Kn1Miy3SirP8hvD8jpDJCTkLAfrToBwn0NpLOoW4dzFHrTNY+M2FMsdqhcJQwWTo 2AM8LmxNw/oc1AzFIFMAKCw+QeOGFQs40TNdHyESgBi/YOmzKCJaI= X-Google-Smtp-Source: AGHT+IEh3YE20MbWYQvPLao4Sp7x/PEmDY2/GoTdw4zc/yGcigeSghqIuS4JMM7+U3CgarJKHt//Jg== X-Received: by 2002:a17:90b:4d0c:b0:2e2:b44d:119d with SMTP id 98e67ed59e1d1-2e93c300855mr24096770a91.39.1730779819223; Mon, 04 Nov 2024 20:10:19 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e92fa0ea9bsm10759120a91.10.2024.11.04.20.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 20:10:18 -0800 (PST) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 2/9] lib: utils/irqchip: plic: Move delegation to base PLIC driver Date: Mon, 4 Nov 2024 20:10:03 -0800 Message-ID: <20241105041015.2949808-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241105041015.2949808-1-samuel.holland@sifive.com> References: <20241105041015.2949808-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_201021_003801_9681C9BA X-CRM114-Status: GOOD ( 17.16 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This needs to be in the base PLIC driver as part of the power management save/restore flow. This is also in preparation for moving the PLIC information in the scratch area to the base PLIC driver. After that change, the FDT PLIC layer will be unable to look up the `struct plic_data` after co [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1036 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This needs to be in the base PLIC driver as part of the power management save/restore flow. This is also in preparation for moving the PLIC information in the scratch area to the base PLIC driver. After that change, the FDT PLIC layer will be unable to look up the `struct plic_data` after cold boot. Signed-off-by: Samuel Holland --- include/sbi_utils/irqchip/plic.h | 4 ++++ lib/utils/irqchip/fdt_irqchip_plic.c | 16 +++------------- lib/utils/irqchip/plic.c | 11 +++++++++++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/sbi_utils/irqchip/plic.h b/include/sbi_utils/irqchip/plic.h index 5da09055..cbe66761 100644 --- a/include/sbi_utils/irqchip/plic.h +++ b/include/sbi_utils/irqchip/plic.h @@ -21,6 +21,8 @@ struct plic_data { /** Work around a bug on Ariane that requires enabling interrupts at boot */ #define PLIC_FLAG_ARIANE_BUG BIT(0) +/** PLIC must be delegated to S-mode like T-HEAD C906 and C910 */ +#define PLIC_FLAG_THEAD_DELEGATION BIT(1) /* So far, priorities on all consumers of these functions fit in 8 bits. */ void plic_priority_save(const struct plic_data *plic, u8 *priority, u32 num); @@ -28,6 +30,8 @@ void plic_priority_save(const struct plic_data *plic, u8 *priority, u32 num); void plic_priority_restore(const struct plic_data *plic, const u8 *priority, u32 num); +void plic_delegate(const struct plic_data *plic); + void plic_context_save(const struct plic_data *plic, int context_id, u32 *enable, u32 *threshold, u32 num); diff --git a/lib/utils/irqchip/fdt_irqchip_plic.c b/lib/utils/irqchip/fdt_irqchip_plic.c index a8aa4fcd..3c57a0f5 100644 --- a/lib/utils/irqchip/fdt_irqchip_plic.c +++ b/lib/utils/irqchip/fdt_irqchip_plic.c @@ -164,10 +164,7 @@ static int irqchip_plic_cold_init(const void *fdt, int nodeoff, if (rc) goto fail_free_data; - if (match->data) { - void (*plic_plat_init)(struct plic_data *) = match->data; - plic_plat_init(pd); - } + pd->flags = (unsigned long)match->data; rc = plic_cold_irqchip_init(pd); if (rc) @@ -184,19 +181,12 @@ fail_free_data: return rc; } -#define THEAD_PLIC_CTRL_REG 0x1ffffc - -static void thead_plic_plat_init(struct plic_data *pd) -{ - writel_relaxed(BIT(0), (char *)pd->addr + THEAD_PLIC_CTRL_REG); -} - void thead_plic_restore(void) { struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); struct plic_data *plic = plic_get_hart_data_ptr(scratch); - thead_plic_plat_init(plic); + plic_delegate(plic); } static const struct fdt_match irqchip_plic_match[] = { @@ -204,7 +194,7 @@ static const struct fdt_match irqchip_plic_match[] = { { .compatible = "riscv,plic0" }, { .compatible = "sifive,plic-1.0.0" }, { .compatible = "thead,c900-plic", - .data = thead_plic_plat_init }, + .data = (void *)PLIC_FLAG_THEAD_DELEGATION }, { /* sentinel */ } }; diff --git a/lib/utils/irqchip/plic.c b/lib/utils/irqchip/plic.c index c66a6886..a432a8c4 100644 --- a/lib/utils/irqchip/plic.c +++ b/lib/utils/irqchip/plic.c @@ -24,6 +24,8 @@ #define PLIC_CONTEXT_BASE 0x200000 #define PLIC_CONTEXT_STRIDE 0x1000 +#define THEAD_PLIC_CTRL_REG 0x1ffffc + static u32 plic_get_priority(const struct plic_data *plic, u32 source) { volatile void *plic_priority = (char *)plic->addr + @@ -93,6 +95,13 @@ static void plic_set_ie(const struct plic_data *plic, u32 cntxid, writel(val, plic_ie); } +void plic_delegate(const struct plic_data *plic) +{ + /* If this is a T-HEAD PLIC, delegate access to S-mode */ + if (plic->flags & PLIC_FLAG_THEAD_DELEGATION) + writel_relaxed(BIT(0), (char *)plic->addr + THEAD_PLIC_CTRL_REG); +} + void plic_context_save(const struct plic_data *plic, int context_id, u32 *enable, u32 *threshold, u32 num) { @@ -178,6 +187,8 @@ int plic_cold_irqchip_init(const struct plic_data *plic) for (i = 1; i <= plic->num_src; i++) plic_set_priority(plic, i, 0); + plic_delegate(plic); + return sbi_domain_root_add_memrange(plic->addr, plic->size, BIT(20), (SBI_DOMAIN_MEMREGION_MMIO | SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW));