From patchwork Tue Jan 4 10:09:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575149 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=1nJSsLyG; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=c1JoVryj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpJl52PBz9t0k for ; Tue, 4 Jan 2022 21:10:12 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ROozzaV88z7h814wrazA5sGg0Ib7W9vZCoqpmZlt0PE=; b=1nJSsLyGkRb4e0 aFg9BxFKXIpufs25zMzVT4djM6c4IFGcmZyVrWR5sc1JCuP2OUlg62Zl755hEFY6Di7tCt1+R+UCz J/d5qLsES5mXU1g//ZrelQ92pVPp/EdeRfiv90Rr8jk9BtuuXUyuAjfJzVWM/QkBh83ZWPqVBsFQv HHV+WtR6HtDrd+eYHM0noY423xg4cJxf8au3SwlfvrxL9sNLpB35JGmgumY/ZOmCWYRQOTkoypJ0O Rx0/NW1Xfpp4aO86z534TgAXL0/S2oClOuQdX3tVaj/wQTQynVntSPMxleKRDZAs6yeNP+UTSzRLK uiPgN3iYPWxkxF56YAiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4glZ-00B6Fi-84; Tue, 04 Jan 2022 10:10:05 +0000 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4glX-00B6EK-BH for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:10:04 +0000 Received: by mail-oi1-x22a.google.com with SMTP id u21so45572741oie.10 for ; Tue, 04 Jan 2022 02:10:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6fBIT+H+/DnyD8eDZabn9YyyeU3mEFbJSYJmIFJcml4=; b=c1JoVryjRr9qOhU5REbMwauW31pjly6VT82TNBO2nBUQ+cisexxOv7Yq8Y6CU1HYQj y7ChsK1fOHxW9wtjU/NINPWAutMfQKk/YQrVuLvxSpnd59P4m7e2zqAFbsKcAGFrKAuk y1GAv8gYbWvfsFBmF6ayqvpiLZ40QL5kNPzMPY8tUWSrVh+9zs4ffMQbIvq8VJVJSpMx ohLdKnwWdJxzNKLvBkAQT2MkICCKerrnH+TsMFiJp2xUI6DT+M4k+EUbdtlFxSNCP/Tv pNfwvQ77ibZQWaDGZWLpSOBhThfN0BDLKji+QJ7Auv3aSeLBzwvkN69x7EAzHnpp4lkw /wMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6fBIT+H+/DnyD8eDZabn9YyyeU3mEFbJSYJmIFJcml4=; b=McmiCFi1EKlsIK1b0k2lypmQdFciPD+/pE1yBqvma7B81W1Q1y6fM5s6CzeCETYBQk nr62BL0GQFMJl2wYpDd9XF98BBORJ4oEZ3vPLHkAFcvg18PVUtepJa82eij2Kk4/UwaU ZxSypKGhRhJdigiU8OjW0FUqDaO1uTGY6ITs9D5LzyVbbMjJbF/QAKrOMS9e7m0ijUnj 2aRrndwyIzr158XUvSdKb6evxELxTQsimvT4biEyu22p+fhk64GBs42MCuDXZHzd+JFG Tek1YtSNsqLU2CI6bE05aQhJLigZsP9z1T/w0po3fBtNB6v7nrVryE3vtqvj8qGURPq6 EmqQ== X-Gm-Message-State: AOAM5331eD/M4G4DQdU2Atc9RDKeVvpG7YZ0AwisNadXh1mgcSJCuA8x UciVbrMI2/X57Yj6nuXfNuss1ZTBtLmMBL1k6fQ= X-Google-Smtp-Source: ABdhPJwsi3A7awf/BYjNf+0i3huX+NiefQjiRYMaLFGXK3U5VKu76cV4mt2Zo+04rmA9UJKAxYDsJQ== X-Received: by 2002:a05:6808:1a2a:: with SMTP id bk42mr39076411oib.118.1641290999628; Tue, 04 Jan 2022 02:09:59 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id r13sm7895264oth.21.2022.01.04.02.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:09:59 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 01/13] include: sbi: Add AIA related CSR defines Date: Tue, 4 Jan 2022 15:39:40 +0530 Message-Id: <20220104100952.127448-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104100952.127448-1-apatel@ventanamicro.com> References: <20220104100952.127448-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021003_417366_E1B763DF X-CRM114-Status: UNSURE ( 9.38 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) 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: The RISC-V AIA specification improves handling of per-HART local interrupts in a backward compatible manner. This patch adds defines for the new RISC-V AIA CSRs. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi/riscv_encoding.h | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 inserti [...] Content analysis details: (-0.2 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:22a 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 The RISC-V AIA specification improves handling of per-HART local interrupts in a backward compatible manner. This patch adds defines for the new RISC-V AIA CSRs. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi/riscv_encoding.h | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 8a29f8e..03f85cb 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -173,6 +173,10 @@ #define HGATP_MODE_SHIFT HGATP32_MODE_SHIFT #endif +#define TOPI_IID_SHIFT 16 +#define TOPI_IID_MASK 0xfff +#define TOPI_IPRIO_MASK 0xff + #if __riscv_xlen == 64 #define MHPMEVENT_OF (_UL(1) << 63) #define MHPMEVENT_MINH (_UL(1) << 62) @@ -303,6 +307,24 @@ /* Supervisor Protection and Translation */ #define CSR_SATP 0x180 +/* Supervisor-Level Window to Indirectly Accessed Registers (AIA) */ +#define CSR_SISELECT 0x150 +#define CSR_SIREG 0x151 + +/* Supervisor-Level Interrupts (AIA) */ +#define CSR_STOPI 0xdb0 + +/* Supervisor-Level IMSIC Interface (AIA) */ +#define CSR_SSETEIPNUM 0x158 +#define CSR_SCLREIPNUM 0x159 +#define CSR_SSETEIENUM 0x15a +#define CSR_SCLREIENUM 0x15b +#define CSR_STOPEI 0x15c + +/* Supervisor-Level High-Half CSRs (AIA) */ +#define CSR_SIEH 0x114 +#define CSR_SIPH 0x154 + /* ===== Hypervisor-level CSRs ===== */ /* Hypervisor Trap Setup (H-extension) */ @@ -338,6 +360,35 @@ #define CSR_VSIP 0x244 #define CSR_VSATP 0x280 +/* Virtual Interrupts and Interrupt Priorities (H-extension with AIA) */ +#define CSR_HVIEN 0x608 +#define CSR_HVICTL 0x609 +#define CSR_HVIPRIO1 0x646 +#define CSR_HVIPRIO2 0x647 + +/* VS-Level Window to Indirectly Accessed Registers (H-extension with AIA) */ +#define CSR_VSISELECT 0x250 +#define CSR_VSIREG 0x251 + +/* VS-Level Interrupts (H-extension with AIA) */ +#define CSR_VSTOPI 0xeb0 + +/* VS-Level IMSIC Interface (H-extension with AIA) */ +#define CSR_VSSETEIPNUM 0x258 +#define CSR_VSCLREIPNUM 0x259 +#define CSR_VSSETEIENUM 0x25a +#define CSR_VSCLREIENUM 0x25b +#define CSR_VSTOPEI 0x25c + +/* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ +#define CSR_HIDELEGH 0x613 +#define CSR_HVIENH 0x618 +#define CSR_HVIPH 0x655 +#define CSR_HVIPRIO1H 0x656 +#define CSR_HVIPRIO2H 0x657 +#define CSR_VSIEH 0x214 +#define CSR_VSIPH 0x254 + /* ===== Machine-level CSRs ===== */ /* Machine Information Registers */ @@ -589,6 +640,31 @@ #define CSR_DSCRATCH0 0x7b2 #define CSR_DSCRATCH1 0x7b3 +/* Machine-Level Window to Indirectly Accessed Registers (AIA) */ +#define CSR_MISELECT 0x350 +#define CSR_MIREG 0x351 + +/* Machine-Level Interrupts (AIA) */ +#define CSR_MTOPI 0xfb0 + +/* Machine-Level IMSIC Interface (AIA) */ +#define CSR_MSETEIPNUM 0x358 +#define CSR_MCLREIPNUM 0x359 +#define CSR_MSETEIENUM 0x35a +#define CSR_MCLREIENUM 0x35b +#define CSR_MTOPEI 0x35c + +/* Virtual Interrupts for Supervisor Level (AIA) */ +#define CSR_MVIEN 0x308 +#define CSR_MVIP 0x309 + +/* Machine-Level High-Half CSRs (AIA) */ +#define CSR_MIDELEGH 0x313 +#define CSR_MIEH 0x314 +#define CSR_MVIENH 0x318 +#define CSR_MVIPH 0x319 +#define CSR_MIPH 0x354 + /* ===== Trap/Exception Causes ===== */ #define CAUSE_MISALIGNED_FETCH 0x0 From patchwork Tue Jan 4 10:09:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575147 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=EUFe4TBJ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=LL/rAPXm; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpJk6MbNz9sXM for ; Tue, 4 Jan 2022 21:10:13 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DwJ3qksRKrgJ+Xjcj3dBFEk2mSvD5aBj9EK9KXPPwIM=; b=EUFe4TBJtheSuN wjVyeDUQVm0BIXLhqThmQG8UUP8V6CNHgof0ZEf5OkL4WsjYnC/RyCAbSa72fQ/LtAGHOweQMl9jH JEGcnWRYIexg+8bvsaJLDN8VTIF2de9YGICJK3eLQZLufVjb60vq0TkUlJJXTN60Fbq+uQVBj6IL0 ULh8oOkOIlDYh075T3mPVAzDCrU5wOLmVZ0udPjNLTuUj+doblLHInwAQfOniD/xL5KlBPTEl/t0q LbsB3gJu4EGdnYzQfud35k3FKn8w2dW0d2kgxMNraf+ckmueRYWMJ26J7WjyMserrszwB4mg3C9zX 6C245eyqlMIEzflfUnvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4glb-00B6G3-Ma; Tue, 04 Jan 2022 10:10:07 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4glY-00B6Eh-M5 for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:10:06 +0000 Received: by mail-oi1-x22e.google.com with SMTP id s73so58826512oie.5 for ; Tue, 04 Jan 2022 02:10:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qA+zvTSDff+wGs0K2SAHyTZag1BIY6JgHRJs+m/CW2k=; b=LL/rAPXm53RZzh4tqIC4v7QYdYHOXhP1ZeLqubYBVMFD7Xn66YsZCrwkzBGUBaNCga j7pUIra6JtVRuguJbuzLUJugq76gahRXJptdm6+5v1rbkimMdnjsQ4Bwi3uWnyZmkDMO 2ZiLdHGDnUkNkf4unSZ7TS34f1HkS/IQ71heDyzlauPvNSKI4BIRf34gTLXZKIChVH8T HidKgurJNQ+g3U8BQj9O9fOEstvlJ2GTDR+XoK1qk2qPQ7ajx/ExKupNqLuZnvDbIuDL eMjIqzNMjYM2oxcCghH8+IbSLfMYxmOCQWIOVCwOBOvsc7I/20IikfWA+n63LE9lBvFJ U0UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qA+zvTSDff+wGs0K2SAHyTZag1BIY6JgHRJs+m/CW2k=; b=2ys19BOidVSxVdyTjZePnRPCXiN3U0n8cruJiQM2/wgUWK05b2yinn5aAFo9QVCzZh wtckmf/TGv3+62DS4hYvuufV7Ff2LqKY27DXktg8aP87DCev/fzhPPe/foX4Y/0roUAu pYqKk5Ng/uo+JwmoBnOKwVAKFZ9Dez86+ShfHpdo9rLhUcUhtOGhDlvadZQ2fX4fIevv X0Cuh6onqFLmJ+hiwjb87RsV2cuP5N9MCOoNOPaHwcEeVqfdamiRIwYYrY6/1Xf6N0zH Od8LTtM1lbBe4xr+P54ebS+FJeVPgypAJ+pxVgLwxZ869zmcU4icC4+mfD0ERyv0b7LQ thHQ== X-Gm-Message-State: AOAM5332v4ySowhggM0DZKF8pytDJnU6DszTxx7AzRC8BZd7mf1Z8GAK 4+XeOyO/gWjfX345MibHrC4/LQ== X-Google-Smtp-Source: ABdhPJwAVSRe7lbLN9x3/17yq7oza4dxqZa87ddM4d5i55eWyjgXB1IJtvuWt4ofzzBBwcND2s5UKg== X-Received: by 2002:aca:4283:: with SMTP id p125mr37088261oia.35.1641291002081; Tue, 04 Jan 2022 02:10:02 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id r13sm7895264oth.21.2022.01.04.02.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:10:01 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 02/13] lib: sbi: Detect AIA CSRs at boot-time Date: Tue, 4 Jan 2022 15:39:41 +0530 Message-Id: <20220104100952.127448-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104100952.127448-1-apatel@ventanamicro.com> References: <20220104100952.127448-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021004_746022_52BDBB0F X-CRM114-Status: GOOD ( 11.80 ) X-Spam-Score: -0.2 (/) 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: We extend HART feature detection to discover AIA CSRs at boot-time. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi/sbi_hart.h | 4 +++- lib/sbi/sbi_hart.c | 23 +++++++++++++++++++++++ 2 files changed, [...] Content analysis details: (-0.2 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:22e 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We extend HART feature detection to discover AIA CSRs at boot-time. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi/sbi_hart.h | 4 +++- lib/sbi/sbi_hart.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index d2db9d6..a83b45b 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -24,9 +24,11 @@ enum sbi_hart_features { SBI_HART_HAS_SSCOFPMF = (1 << 3), /** HART has timer csr implementation in hardware */ SBI_HART_HAS_TIME = (1 << 4), + /** HART has AIA local interrupt CSRs */ + SBI_HART_HAS_AIA = (1 << 5), /** Last index of Hart features*/ - SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_TIME, + SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_AIA, }; struct sbi_scratch; diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index d9a15d9..c16b395 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -283,6 +283,9 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature) case SBI_HART_HAS_TIME: fstr = "time"; break; + case SBI_HART_HAS_AIA: + fstr = "aia"; + break; default: break; } @@ -506,6 +509,26 @@ __mhpm_skip: csr_read_allowed(CSR_TIME, (unsigned long)&trap); if (!trap.cause) hfeatures->features |= SBI_HART_HAS_TIME; + + /* Detect if hart has AIA local interrupt CSRs */ + csr_read_allowed(CSR_MTOPI, (unsigned long)&trap); + if (trap.cause) + goto __aia_skip; + csr_read_allowed(CSR_MISELECT, (unsigned long)&trap); + if (trap.cause) + goto __aia_skip; + csr_write_allowed(CSR_MISELECT, (unsigned long)&trap, 0x30); + if (trap.cause) + goto __aia_skip; + val = csr_read_allowed(CSR_MIREG, (unsigned long)&trap); + if (trap.cause) + goto __aia_skip; + csr_write_allowed(CSR_MIREG, (unsigned long)&trap, val); + if (trap.cause) + goto __aia_skip; + hfeatures->features |= SBI_HART_HAS_AIA; +__aia_skip: + return; } int sbi_hart_reinit(struct sbi_scratch *scratch) From patchwork Tue Jan 4 10:13:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575150 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=m972eQxG; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=jn+ErXMI; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpNg68dkz9sXM for ; Tue, 4 Jan 2022 21:13:39 +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:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=MJt3iCbOxJSAshiXgtFVKie/WM6n2oJ8aAoD4YRhSdE=; b=m972eQxGFSiNCB 80yeUg1bOIXGHz0AxLKQG6UH6ulA4xWLVMrrHa6jd8mRdeeJTrl7GOCcoRnNXJzemhzH/TwFGg3xx 2EY1TFXRBAiz7ZINs3gymF6lg2RtSP6xRNvJ7/pB9Q00f9A49zMtmD4AnKLKsuIKPKIxVF9P4K9Bp wE+/DQ0oz7GSW8bHDtOWvAr70nz4EsqL0Nj6tBAQi4x5xc/eR3YM+CSmnMeRCg7T5MAoBjgBlsG5I XvZbTOdups7ivBYUZwibSy3AANN5XXVsyZPAjGa/jcnk14lHJ34x6c9BLkd0tU5tdv2owpI814YVs EEtc2ILrXi1OWdfJRX8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4got-00B6WR-Nc; Tue, 04 Jan 2022 10:13:31 +0000 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4goq-00B6Vq-TO for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:30 +0000 Received: by mail-ot1-x32b.google.com with SMTP id i5-20020a05683033e500b0057a369ac614so46769208otu.10 for ; Tue, 04 Jan 2022 02:13:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WGu/VjptjZxOlFCFOOf01z8ZxWSTcvoGQ01WceeBn18=; b=jn+ErXMIaJKZELVBky5H1WRG5gom4HxKF/kvazui4TYzIKo1FjX2d5l9ITFo4XkWCg nEMpc7RmazAXutcYI1I+HJDU0tUSut2uj4VN+j1SJvGz2In6yum7B24HFz3umDKUAXRa tiDAvUHrD0Sh+L6bj77swc63HHtOCXUHb6VemaqzGY7dLdpMnT5DD3AXtUdpzX3CTK8c dazPG0TcFVK1ejYR5R95PssSNHb3wphQqDT8+3KNX8gAYt3X2f87aj0slVBH/LroB599 9MVf6H79wcr557RGbTIAg2x5N6C0z9rZEwjVULn9lAgq46cUd37+tJ+gkcIDPYFhZ0oL ljDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WGu/VjptjZxOlFCFOOf01z8ZxWSTcvoGQ01WceeBn18=; b=sO2nIpHWejacMa5kwfJiBLWPLsHDKrKzHUZTRpeqwAK/czB3AWDLrrW49CEdBAnABp Yu5UGemSp9AaiUTaWOyXhWWFGCA+Irz2EWi5nFQOdUV3z0btcwMWtjf0n0A7qCO8p+4t trlN6X5J66UFT2Ixu5XVj46wmZByjFNEwC0wd3M7+V6Jl1zFukjpHgI3qGqZCIKamObI Jt7hIAp+tD5VDQZdUAavtiOoWSvwSSZXzIc/uigmR7BR8kCarVaOoL1I5vmhoTtgW53w epg+Ky9zN1HomVompr6yJFnZLHwpApxRDw4ELZ231jieK4GQBBT3ZKUyO2qzH97LMP4P CAcA== X-Gm-Message-State: AOAM531IuPoo6sp55xmNPQG1zBa/PLKV8XhCAtxn2cVC4PztRwYfFnyS rdkBlm2zuixqMJFnYWO/g04EEA== X-Google-Smtp-Source: ABdhPJyS6isx4FGmjRFRqCHs/GZO8TFu4kM4cbc4ig6HmnxqYKND5Ofsxyvc6vuLvRFUFeiYQ70Nhg== X-Received: by 2002:a05:6830:1107:: with SMTP id w7mr35100191otq.20.1641291207924; Tue, 04 Jan 2022 02:13:27 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:27 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 03/13] lib: sbi: Use AIA CSRs for local interrupts when available Date: Tue, 4 Jan 2022 15:43:13 +0530 Message-Id: <20220104101323.127564-1-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021328_996763_0B544230 X-CRM114-Status: UNSURE ( 9.84 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) 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: We should use AIA CSRs to process local interrupts whenever AIA is available. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- lib/sbi/sbi_trap.c | 57 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 inserti [...] Content analysis details: (-0.2 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:32b 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We should use AIA CSRs to process local interrupts whenever AIA is available. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- lib/sbi/sbi_trap.c | 57 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 8d20e04..bc8961f 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -195,6 +195,44 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, return 0; } +static int sbi_trap_nonaia_irq(struct sbi_trap_regs *regs, ulong mcause) +{ + mcause &= ~(1UL << (__riscv_xlen - 1)); + switch (mcause) { + case IRQ_M_TIMER: + sbi_timer_process(); + break; + case IRQ_M_SOFT: + sbi_ipi_process(); + break; + default: + return SBI_ENOENT; + }; + + return 0; +} + +static int sbi_trap_aia_irq(struct sbi_trap_regs *regs, ulong mcause) +{ + unsigned long mtopi; + + while ((mtopi = csr_read(CSR_MTOPI))) { + mtopi = mtopi >> TOPI_IID_SHIFT; + switch (mtopi) { + case IRQ_M_TIMER: + sbi_timer_process(); + break; + case IRQ_M_SOFT: + sbi_ipi_process(); + break; + default: + return SBI_ENOENT; + } + } + + return 0; +} + /** * Handle trap/interrupt * @@ -225,18 +263,15 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs) } if (mcause & (1UL << (__riscv_xlen - 1))) { - mcause &= ~(1UL << (__riscv_xlen - 1)); - switch (mcause) { - case IRQ_M_TIMER: - sbi_timer_process(); - break; - case IRQ_M_SOFT: - sbi_ipi_process(); - break; - default: - msg = "unhandled external interrupt"; + if (sbi_hart_has_feature(sbi_scratch_thishart_ptr(), + SBI_HART_HAS_AIA)) + rc = sbi_trap_aia_irq(regs, mcause); + else + rc = sbi_trap_nonaia_irq(regs, mcause); + if (rc) { + msg = "unhandled local interrupt"; goto trap_error; - }; + } return regs; } From patchwork Tue Jan 4 10:13:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575151 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=P2cl9qpu; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=TWRENM36; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpNj1wkyz9sXM for ; Tue, 4 Jan 2022 21:13:41 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PcXXeb2ZhnpolCYt3vjdQAHphHe6/SwqAjTKKLKdOZI=; b=P2cl9qpuOnY3eT SMEKIk5nsbsdGM9NUF6zgmlOS/Vo/RJNb7PBLZjhAweQg2EmkE7tifqS0LBJ9dOJW1NWRv+vhkYLr rssURKLwl5JAqv7vTN+XPte69x9Ww4WGfspvgMHwD/eI1FXphdlCH6bPM1piorDzkC1b2M9ldCA5/ nKWKAIBHwDNbYYc/vaXCOR2IJdIJ+yIeSlIJpasKCkf2PdGLFhpc4fZgqo1NTis/yQ9y+xVH4p83q J5ml1Uah4h5K/9OGT10k6PPuCqOQUGMc9JMgTijw9KqIgpoVNBiV078ffrCFNRPd+n3sfAt18oNr6 e3Eq18RQiQffCGIxFyGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gow-00B6XJ-6X; Tue, 04 Jan 2022 10:13:34 +0000 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4got-00B6W9-2M for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:32 +0000 Received: by mail-oi1-x231.google.com with SMTP id w80so20374586oie.9 for ; Tue, 04 Jan 2022 02:13:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kcth6vZ5Q4/p3QAda67G90F3WAW8SOVXFjM/fKUze8w=; b=TWRENM36eA2u8Rjw1Qwnn8PxSD1rXpGMlP5AVFQVEKpFs7HsXr7j6WIgM8BgTOnPNe OqgZd63VGxcsG4L0tSy3uUogqxMivMP8yI5MCUi1MPJRy3jSOuyuleJhzaUcP1MZESLv q5cQ+XYfJWL82vw41hZi85KCqpek2e8FB3vA58HBqqksFOXuFthJZExLom68jz4eriGO pI3DaFe1dL4UK3TnjZyK2cWl6AMBZ2/73OQIXcZc6c+CDRBCgvC87Nu1C3TuLi20aiUf A7k66Lm/d2CJUP1ynmVXm7QxTAwKTEnd2pSQWAGUaGJAgbnSQDw35UJfd3Yc95sN7cOa Z1TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kcth6vZ5Q4/p3QAda67G90F3WAW8SOVXFjM/fKUze8w=; b=A45Xc6q4gjcNunMyQyc7Ym135SZDlSIp96Wl8WFVpQCDcKZvqCetq6iPOTmxMu2laV SVJibTB7VqyYUq1TqcQTGj4ENewZIEg7ZWF78C9g+2n3arSQLqf+vpXGdVGuVs5fLLG4 IiiIqgtBVCFYpnIhL7kY3vT6edaq5QeXzF1VipT4esqyx2gNYu56v5frzEoXegm8ilu9 9T/c5QVG7J1XyKKOkLuQcSckhQJjCwfv/JXjPzILAsafKc27jxAwsi1ieDIy9I+Q6vAa n78nhRZAi7AsCj9FC2vbXqA4QNoueSlp0hoaEeClgi03tDJ9Kq3pxCZrhR+WpfWVTU0C sKkw== X-Gm-Message-State: AOAM533O4YhfFzP9SMC+o8DFIyAwsRxgilXDlrzgLjuOCo5vAFBN+7d6 w1Lywlezw9eJEq1nZnfoR+yppw== X-Google-Smtp-Source: ABdhPJyHvQI/aogdgb7VLZsuyHTSreQg46elcirv3dIifmC89RDQopifOBECu6xRmPUPilDSuyB52Q== X-Received: by 2002:a05:6808:168b:: with SMTP id bb11mr20522442oib.40.1641291210253; Tue, 04 Jan 2022 02:13:30 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:30 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 04/13] lib: sbi: Add sbi_trap_set_external_irqfn() API Date: Tue, 4 Jan 2022 15:43:14 +0530 Message-Id: <20220104101323.127564-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104101323.127564-1-apatel@ventanamicro.com> References: <20220104101323.127564-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021331_132260_08ABFD8B X-CRM114-Status: GOOD ( 13.04 ) X-Spam-Score: -0.2 (/) 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 patch adds sbi_trap_set_external_irqfn() API which can be used by OpenSBI platform code to set a callback function for external interrupts. The RISC-V AIA IMSIC driver will use this API to implem [...] Content analysis details: (-0.2 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:231 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 patch adds sbi_trap_set_external_irqfn() API which can be used by OpenSBI platform code to set a callback function for external interrupts. The RISC-V AIA IMSIC driver will use this API to implement inter-processor interrupts on-top-of MSIs. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi/sbi_trap.h | 2 ++ lib/sbi/sbi_trap.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/sbi/sbi_trap.h b/include/sbi/sbi_trap.h index d205056..4f611fa 100644 --- a/include/sbi/sbi_trap.h +++ b/include/sbi/sbi_trap.h @@ -205,6 +205,8 @@ struct sbi_trap_info { int sbi_trap_redirect(struct sbi_trap_regs *regs, struct sbi_trap_info *trap); +void sbi_trap_set_external_irqfn(int (*fn)(struct sbi_trap_regs *regs)); + struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs); void __noreturn sbi_trap_exit(const struct sbi_trap_regs *regs); diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index bc8961f..faab90a 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -195,6 +195,27 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, return 0; } +static int default_irqfn(struct sbi_trap_regs *regs) +{ + return SBI_ENODEV; +} + +static int (*ext_irqfn)(struct sbi_trap_regs *regs) = default_irqfn; + +/** + * Set external irq handler function + * + * This function is called by OpenSBI platform code to set a handler for + * external interrupts + * + * @param fn function pointer for handling external irqs + */ +void sbi_trap_set_external_irqfn(int (*fn)(struct sbi_trap_regs *regs)) +{ + if (fn) + ext_irqfn = fn; +} + static int sbi_trap_nonaia_irq(struct sbi_trap_regs *regs, ulong mcause) { mcause &= ~(1UL << (__riscv_xlen - 1)); @@ -205,6 +226,8 @@ static int sbi_trap_nonaia_irq(struct sbi_trap_regs *regs, ulong mcause) case IRQ_M_SOFT: sbi_ipi_process(); break; + case IRQ_M_EXT: + return ext_irqfn(regs); default: return SBI_ENOENT; }; @@ -214,6 +237,7 @@ static int sbi_trap_nonaia_irq(struct sbi_trap_regs *regs, ulong mcause) static int sbi_trap_aia_irq(struct sbi_trap_regs *regs, ulong mcause) { + int rc; unsigned long mtopi; while ((mtopi = csr_read(CSR_MTOPI))) { @@ -225,6 +249,11 @@ static int sbi_trap_aia_irq(struct sbi_trap_regs *regs, ulong mcause) case IRQ_M_SOFT: sbi_ipi_process(); break; + case IRQ_M_EXT: + rc = ext_irqfn(regs); + if (rc) + return rc; + break; default: return SBI_ENOENT; } From patchwork Tue Jan 4 10:13:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575152 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=M3xo3pJT; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=VoK+E27a; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpNl1sPJz9t0Z for ; Tue, 4 Jan 2022 21:13:43 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1S85aEEt8iS0BP125L4W16/jMQ4WWT+RRrYQw9FVWko=; b=M3xo3pJT7fvYif Iro/HPW9lSOYHUYz6xEUUzL1CXqq892IUype3t5mJuZrUl2ZG3JXyi+0fi5IcOBkiUzObTbNvwQz+ LHSdEEv05JhMsXaSIbt+/Et8JJEMP9cBQ3MamUk8ugEhbNZ1uXMw683O8jm9MR4Hkw9wa2vzAd1Sw lEX+QN3x3vk6+Jf9PTg0gWR/lJh6hn0a1hJ+ZHBhHKMmZ5F5Nn2xThuZ4mZk6KU6EZl+iAFsuiWWo NRAtE4njRJUgtrZ1C7xs04ysYna03X2H/OGMMhroqnX2iqgL5G7sfRsJVgkNtsZrZLcuE7rjl+tTc eyoztKvvMElHiTcMhmpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gox-00B6Y4-Or; Tue, 04 Jan 2022 10:13:35 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gov-00B6Wf-6X for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:34 +0000 Received: by mail-oi1-x22e.google.com with SMTP id j185so58695661oif.8 for ; Tue, 04 Jan 2022 02:13:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/qSdoGAFeCmplnep9cJTunhMgCqMljcvuMcAmbWLiTI=; b=VoK+E27a4B7r8bdxU12wdAApFkbieg8reKGc0cr9ufRMhseb9zcqvPnAdfK/9jHogc V0FWa+2xwvuTjf9Bj3ScfjZ7/bNrty6ZtK8rEC4yUBgQXcuEmEin/8A3EBZs4mEe9hBb VgHTRrW5e+RV10enSqZA7Rq554MCv3Qfax9SVtenRj0A6An5pRUfB8b11iSM4htDHWGp lOarrS3UefJ9XkhrxKKs2SHmk63NYxeg6b3JWGmdEAdNvbvUS4BtZ5FRSfenQSCEl2oe Aw1cNtlW/G2x/gy0Lfojbe+KTPJbZ4+BuFVGNG9/RFlL2MYrQz+LzarUcB08Q+VEC/3m pJHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/qSdoGAFeCmplnep9cJTunhMgCqMljcvuMcAmbWLiTI=; b=fnVeJ2jMzcNc+UKZzDTu9semvc7GiCyxB6CQ9fSnx5eoAfT8YAPMwjf2iM9tG7Q8uC 5i2FPhKlElQyImXFr2SoQnND2ADJiyhatwWwD1ivl+AtsVM5VRJWFk2bZH2by/+Ft30K l/D2tZEPe3r3imrb6DdwRGK9oBdEEdAnoheSF6zoRg4to5fmBv/0FnCb1p73xUEOqwMH W6X5zPDTD4RpVcauzBtRmaIdBBpgO5wNxsGt2XehVqRZvD4Qwx57Q+JnyJ/gXaU1Mbw0 SGJputV/G2P//wgGWQom9x7fMe2AsgMVZwGsR8IlE4QJ9ubJHQl5vQOMkx2xWHqdC0Oo sOHQ== X-Gm-Message-State: AOAM530F/xJ4hVfPSb85D2BCwRRoBfExjdv1ERqGeBzw1QVTevtpqBTB gSCnRJdi16X5AYvWJT82yCMUeg== X-Google-Smtp-Source: ABdhPJzBKz4MqG+TcOm9Pb6tGXkscVlb+DPPTUJomGES0rPUqmN0hige1v6Pk14fQmamHXJwksY62A== X-Received: by 2002:aca:dbd5:: with SMTP id s204mr39200108oig.41.1641291212653; Tue, 04 Jan 2022 02:13:32 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:32 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 05/13] lib: utils/irqchip: Allow multiple FDT irqchip drivers Date: Tue, 4 Jan 2022 15:43:15 +0530 Message-Id: <20220104101323.127564-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104101323.127564-1-apatel@ventanamicro.com> References: <20220104101323.127564-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021333_261677_8003F17D X-CRM114-Status: GOOD ( 15.53 ) X-Spam-Score: -0.2 (/) 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: We can have multiple FDT irqchip drivers to be probed when a RISC-V system has different types of interrupt controller in a hierarchy. This will be certainely the case when a RISC-V system has both RISC-V AIA IMSIC and RISC-V AIA APLIC implemented. Content analysis details: (-0.2 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:22e 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We can have multiple FDT irqchip drivers to be probed when a RISC-V system has different types of interrupt controller in a hierarchy. This will be certainely the case when a RISC-V system has both RISC-V AIA IMSIC and RISC-V AIA APLIC implemented. We extend simple FDT irqchip framework to allow multiple FDT irqchip drivers to be used for same RISC-V platform. Signed-off-by: Anup Patel Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- lib/utils/irqchip/fdt_irqchip.c | 37 ++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/utils/irqchip/fdt_irqchip.c b/lib/utils/irqchip/fdt_irqchip.c index 8dda661..bf6969a 100644 --- a/lib/utils/irqchip/fdt_irqchip.c +++ b/lib/utils/irqchip/fdt_irqchip.c @@ -18,23 +18,40 @@ static struct fdt_irqchip *irqchip_drivers[] = { &fdt_irqchip_plic }; -static struct fdt_irqchip *current_driver = NULL; +#define FDT_IRQCHIP_MAX_DRIVERS 8 + +static struct fdt_irqchip *current_drivers[FDT_IRQCHIP_MAX_DRIVERS] = {0}; +static int current_drivers_count; void fdt_irqchip_exit(void) { - if (current_driver && current_driver->exit) - current_driver->exit(); + int i; + + for (i = 0; i < current_drivers_count; i++) { + if (!current_drivers[i] || !current_drivers[i]->exit) + continue; + current_drivers[i]->exit(); + } } static int fdt_irqchip_warm_init(void) { - if (current_driver && current_driver->warm_init) - return current_driver->warm_init(); + int i, rc; + + for (i = 0; i < current_drivers_count; i++) { + if (!current_drivers[i] || !current_drivers[i]->warm_init) + continue; + rc = current_drivers[i]->warm_init(); + if (rc) + return rc; + } + return 0; } static int fdt_irqchip_cold_init(void) { + bool drv_added; int pos, noff, rc; struct fdt_irqchip *drv; const struct fdt_match *match; @@ -44,6 +61,7 @@ static int fdt_irqchip_cold_init(void) drv = irqchip_drivers[pos]; noff = -1; + drv_added = false; while ((noff = fdt_find_match(fdt, noff, drv->match_table, &match)) >= 0) { if (drv->cold_init) { @@ -53,10 +71,15 @@ static int fdt_irqchip_cold_init(void) if (rc) return rc; } - current_driver = drv; + + if (drv_added) + continue; + + current_drivers[current_drivers_count++] = drv; + drv_added = true; } - if (current_driver) + if (FDT_IRQCHIP_MAX_DRIVERS <= current_drivers_count) break; } From patchwork Tue Jan 4 10:13:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575153 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=F4HrbrbG; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=hRTLcVjM; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpNv0Lg2z9t0Z for ; Tue, 4 Jan 2022 21:13:51 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FwKCZULP26AVtwWlQAdLLiqHPGDK9r39lW5Mqthu68E=; b=F4HrbrbGkN/41B 6zHC2JOBYe8gsmgNFc2hQysNEVqNKdwpGYNBIYisHNbcmc4N5aVl5uMZKALm6ylLAXRtfg4Di8sDc k/voTGMzBwydPqO1Y7it0e3t3C6fhBvky2rfL4G7k7VRy4RwUVuFr8VnQvpoI22lqo572hninBPCS dRhK9BO2DpKzLMqPGoUfziQpCyzbwf8fDkSBfSxBebcxdN12A7KzE3gCsZqaIKgJeOZxOlng9m069 a6KaWNSSTBmPiNyaOgiMD8/nBUIexrKY5suQ5dcNIPQWv3f39ULKJJzmLKpYSV/38TOJfLwHRADsL sYwJbuFFm6ne2zbjDDYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gp4-00B6bi-97; Tue, 04 Jan 2022 10:13:42 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gp1-00B6Xz-KX for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:40 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id y13-20020a4a624d000000b002daae38b0b5so11380476oog.9 for ; Tue, 04 Jan 2022 02:13:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CqZe7ZBeyKu+2esLtqSUEzt15Rw5K9JK54cGg5u/nC8=; b=hRTLcVjMwXI8h/yUyaUBUNhprjOvD4CGNSL98a2/YNTr8UrgkrYC5FYXGgqViO317j 1N78XCCKvRk+4tnoRI69DatggyTcQ9CPqX0oV8qXpsgA/p8A4qnRjdRDT08Y/mnmfh3o tgW16g3fg8U6ZKI46vlIybZr2ybB3LZ2IcsiJYj86TnxkV+BHKh+vT5bKB4Qa07mCMYb KRo/4dgxMtP2A68wkEDTOAMw6vng4An43GtAdA8UPoYo0/QwEjnAtMO3ReBCbVYPRFUb Bi7Ida3djAQzRe0YtCzu3zriwPSPsZpN+No9O857gTihdmEJtMYTyLiWCLAI/fxcQmSe 77YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CqZe7ZBeyKu+2esLtqSUEzt15Rw5K9JK54cGg5u/nC8=; b=qw84AUuaMbI29We3HkXGPkYNLMQ4LQ7k1J6zh8BcxsFGBPxng1Ic60ZG657dsC3hXt 42hTe2u5nqEdWNe6ph0DFd3QiyCYujbHdVDL3Nweh0rbLqi8btxVPvnfll5dfNCj0+Cw AKNmaQ12Tb/8K+nxEdsEJN+1LQ6OPXfoPYmC1MLMMwrJ+dWxSlBXo17XEchi+N9PkZat MbSBm/LEv2jIJ72p5PgLEBZrhgjVD7dPqivf/luJ272546u3KV5rr7Kqja6wkA/Bm43q FI0fj2pKyxRIFwGrubapSLCn5nxknspwMaXCdYy68wWkyCBhrKDT/zefEmMvrYmIM09w uBLQ== X-Gm-Message-State: AOAM533MFu3DzAY6Ff04etevw3Zxud0fal2trV8llvIGg3AmTvTeydUX G0zH3uvbcSzH4akEAv0V6hVmFA== X-Google-Smtp-Source: ABdhPJxtA3TmUjOP+kTkC8qxMz60Sfnz2V7+ulguf6mHqUwDK/94hyQey7Z5sq4durlTBCGaWPcUcg== X-Received: by 2002:a4a:c57:: with SMTP id n23mr31244185ooe.55.1641291214931; Tue, 04 Jan 2022 02:13:34 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:34 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 06/13] include: sbi: Introduce nascent_init() platform callback Date: Tue, 4 Jan 2022 15:43:16 +0530 Message-Id: <20220104101323.127564-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104101323.127564-1-apatel@ventanamicro.com> References: <20220104101323.127564-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021339_695291_F07AE2BC X-CRM114-Status: GOOD ( 12.20 ) X-Spam-Score: -0.2 (/) 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: We introduce nascent_init() platform callback which will allow platforms to do very early initialization of platform specific per-HART CSRs and per-HART devices. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi/sbi_platform.h | 17 +++++++++++++++++ lib/sbi/sbi_init.c | 8 ++++++++ 2 files changed [...] Content analysis details: (-0.2 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:c2d 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We introduce nascent_init() platform callback which will allow platforms to do very early initialization of platform specific per-HART CSRs and per-HART devices. Signed-off-by: Anup Patel Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi/sbi_platform.h | 17 +++++++++++++++++ lib/sbi/sbi_init.c | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 4d192f2..e097785 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -64,6 +64,9 @@ enum sbi_platform_features { /** Platform functions */ struct sbi_platform_operations { + /* Platform nascent initialization */ + int (*nascent_init)(void); + /** Platform early initialization */ int (*early_init)(bool cold_boot); /** Platform final initialization */ @@ -299,6 +302,20 @@ static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat, return FALSE; } +/** + * Nascent (very early) initialization for current HART + * + * @param plat pointer to struct sbi_platform + * + * @return 0 on success and negative error code on failure + */ +static inline int sbi_platform_nascent_init(const struct sbi_platform *plat) +{ + if (plat && sbi_platform_ops(plat)->nascent_init) + return sbi_platform_ops(plat)->nascent_init(); + return 0; +} + /** * Early initialization for current HART * diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 83043c5..27d03a7 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -494,6 +494,14 @@ void __noreturn sbi_init(struct sbi_scratch *scratch) if (next_mode_supported && atomic_xchg(&coldboot_lottery, 1) == 0) coldboot = TRUE; + /* + * Do platform specific nascent (very early) initialization so + * that platform can initialize platform specific per-HART CSRs + * or per-HART devices. + */ + if (sbi_platform_nascent_init(plat)) + sbi_hart_hang(); + if (coldboot) init_coldboot(scratch, hartid); else From patchwork Tue Jan 4 10:13:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575154 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=vPsQoEkL; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=cmi2mSaL; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpNv0HVfz9sXM for ; Tue, 4 Jan 2022 21:13:51 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W89hHqvZMxKLwsKvKFHel5bHGLd3wF7e6idcTt8DM5A=; b=vPsQoEkLSTt2tY iS929pVcQ2dWWRexXLFQtfCluWdAWeVzRMxKBJ1R2xgNLKm3s8qh1wM6FEHd6nKElricJclDZ3wP6 ITS+mKDV5T5HosYuYI0lAarhaea6Cmy0NQGe5VsEYGzyMXlBd+1NvkVgUtdYc13ry56jnOzFqFFy+ tULgZou7o4P68dg7tanyxl0N/zlc7cAPrV+x2QTmjBL7cA81DOWulOaOf4MjcGh8WK/4C8xBOubI7 9hbUd4NCuDiNtJqzeKH1njmZP9XZsQczq8Sh8i1k/hzfVymnwDAEr6hb0A5kmPKtWO987//GNZ9od ie1VebC9ORkthvIobfTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gp5-00B6ca-Sd; Tue, 04 Jan 2022 10:13:43 +0000 Received: from mail-ot1-x32e.google.com ([2607:f8b0:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gp2-00B6Yh-Ux for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:42 +0000 Received: by mail-ot1-x32e.google.com with SMTP id a23-20020a9d4717000000b0056c15d6d0caso46593414otf.12 for ; Tue, 04 Jan 2022 02:13:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CArqN0XGFwTNPZLj/MgHjToF1aZj0tIrZaXPho0vMJY=; b=cmi2mSaLPN3W9dYrIzzAA+AidUttpAH6D3LVo+62JM9UkDespIxW8BpPEScRwiNhnU 4PcazP0sZBHxDaUXlkceidU42AZtlyGzPYaICaTlj2qSBSzFr8Cd+rbGGrUrIZqnnSIb 7XqUlPl+666IjEN1tdc/c7npXLWgVIzHlgk12O8mi6q/0NEAJ9Lt+iBGUA2RYjjZNWkz fAGCaqtyYzxlDUEZetAaPAI+VXvuJ0MkKFpmQBp79sxTC8SBft/zMkUg0nkXHOumrho2 32yN6XASETTHWBklVZ/zdm8vIBV2hORZEUoJyIJzxlrjo0KItT/AZNcfnbNz3gu/vy1o 2gVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CArqN0XGFwTNPZLj/MgHjToF1aZj0tIrZaXPho0vMJY=; b=5r9pm5nSrds842WaWJjBIiYKQuV3j97PuL1HqJnYwj4N3mDnwZLyPVe4jRb3MOWxrk 4978nAmnzaYqtI8RA5iH4bBpt9Wy/c2vR5SHmLC4fwF83g/cHeLCbwRhXRV0KHwyKA0c oabgUHw3Y/tLyKgA6YcZMBh/SXIc1USJi8axXTrtMgdcQZ0yJdar/amGBVeV4FHkrvqO dtedCXy1rKon24fRt8MYVJIAX5tdd+0pPNINYC0uMD1BBlCS9rAbAbuHlsXWdHrnvHip 37aVn3SmzFKiBi+C1ajCfOghzqUkLXVSWw3hsG+m3391kWbZXT3lDGdFOdG5Vml5Xn+c 5BIg== X-Gm-Message-State: AOAM533hKFZkREeDZYLQKbELLOL/AS1aWKYErSlWH8s4MxkDqtDJjYUA qNa2LNbS6HwHbBBCg9roJnWcpw== X-Google-Smtp-Source: ABdhPJxAyAca6Dc0LhY89OzcJkOKr9UaxIHAP7yv1YOYZ1ob9I9yaenvjBs0OC6zS75ZylWLYRw9YQ== X-Received: by 2002:a05:6830:4d1:: with SMTP id s17mr35240856otd.246.1641291217246; Tue, 04 Jan 2022 02:13:37 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:37 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 07/13] lib: sbi: Enable mie.MEIE bit for IPIs based on external interrupts. Date: Tue, 4 Jan 2022 15:43:17 +0530 Message-Id: <20220104101323.127564-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104101323.127564-1-apatel@ventanamicro.com> References: <20220104101323.127564-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021341_050637_40F5D1AB X-CRM114-Status: GOOD ( 11.84 ) X-Spam-Score: -0.2 (/) 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: We can have IPIs based on external interrupts provided by devices such as AIA IMSIC so we should enable mie.MEIE bit at appropriate places in generic library. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- lib/sbi/sbi_hsm.c | 4 ++-- lib/sbi/sbi_init.c | 9 ++++++--- 2 files changed, 8 insertions(+), 5 [...] Content analysis details: (-0.2 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:32e 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We can have IPIs based on external interrupts provided by devices such as AIA IMSIC so we should enable mie.MEIE bit at appropriate places in generic library. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- lib/sbi/sbi_hsm.c | 4 ++-- lib/sbi/sbi_init.c | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index ecd2e45..c4d2c6d 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -113,8 +113,8 @@ static void sbi_hsm_hart_wait(struct sbi_scratch *scratch, u32 hartid) /* Save MIE CSR */ saved_mie = csr_read(CSR_MIE); - /* Set MSIE bit to receive IPI */ - csr_set(CSR_MIE, MIP_MSIP); + /* Set MSIE and MEIE bits to receive IPI */ + csr_set(CSR_MIE, MIP_MSIP | MIP_MEIP); /* Wait for hart_add call*/ while (atomic_read(&hdata->state) != SBI_HSM_STATE_START_PENDING) { diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 27d03a7..6876eb2 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -165,8 +165,8 @@ static void wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid) /* Save MIE CSR */ saved_mie = csr_read(CSR_MIE); - /* Set MSIE bit to receive IPI */ - csr_set(CSR_MIE, MIP_MSIP); + /* Set MSIE and MEIE bits to receive IPI */ + csr_set(CSR_MIE, MIP_MSIP | MIP_MEIP); /* Acquire coldboot lock */ spin_lock(&coldboot_lock); @@ -182,7 +182,7 @@ static void wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid) do { wfi(); cmip = csr_read(CSR_MIP); - } while (!(cmip & MIP_MSIP)); + } while (!(cmip & (MIP_MSIP | MIP_MEIP))); }; /* Acquire coldboot lock */ @@ -276,6 +276,7 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) __func__, rc); sbi_hart_hang(); } + csr_set(CSR_MIE, MIP_MEIP); rc = sbi_ipi_init(scratch, TRUE); if (rc) { @@ -376,6 +377,7 @@ static void init_warm_startup(struct sbi_scratch *scratch, u32 hartid) rc = sbi_platform_irqchip_init(plat, FALSE); if (rc) sbi_hart_hang(); + csr_set(CSR_MIE, MIP_MEIP); rc = sbi_ipi_init(scratch, FALSE); if (rc) @@ -550,6 +552,7 @@ void __noreturn sbi_exit(struct sbi_scratch *scratch) sbi_ipi_exit(scratch); + csr_clear(CSR_MIE, MIP_MEIP); sbi_platform_irqchip_exit(plat); sbi_platform_final_exit(plat); From patchwork Tue Jan 4 10:13:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575155 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=2Fe9blr1; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=m06y4/Tz; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpNw0QQpz9t0k for ; Tue, 4 Jan 2022 21:13:52 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9ZAPxJVGOhO8bRN17dr1ZlYAo4qdQAGK1c6WBnGiAE0=; b=2Fe9blr14V0Dic M9R47Th8eSp77EcaBTEzcO4WZetT33U0JpWum5rpsd/pFj6k6UOqX8nKXgiHjWPSTNyR/6mLFZLbX PqKey78exc+tnaQqfht1AjtJofElzoWbEqdMPQQ1z/bLkA3R3X377yNtCz9KfJrPGuBRBj19aQpiG JCVTGjQIGLmSmjmAHn0rAL/4FPntftXfWpF3wWw4K5CH9JW9lwbHbMHYA/yAIOjXAyxPn7iJWzQ5b Qu5hFtUKgSzr+Mtj7spP8VzjvgJTLE8CGVTAXV0DVjrlNxvBwKjQzQ4M05fzguFhI30VNnDcuFter ZTz/ILipzKP9lOKY9xXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gp7-00B6dD-CI; Tue, 04 Jan 2022 10:13:45 +0000 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gp3-00B6a7-7G for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:43 +0000 Received: by mail-ot1-x344.google.com with SMTP id j3-20020a056830014300b0058f4f1ef3c2so42786082otp.13 for ; Tue, 04 Jan 2022 02:13:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kfdzuH7vgkcBo716puoDvuEBU5u/scnjNqjBPPyH9K4=; b=m06y4/TzyiIGok8swe/VWCt4gSGP8iogu++8lEYjDrTPZxjZaPPqbmgKYf69PH1XIw c5X7MJj9CuvA6lRHCRm0sQ8RH58q3ZU1WdIS7eItzhMRtbhiBg5MtKmjFVrqjmxXaYLm 84mRrvKQhTg0j8oK3kzN0UKGCejzr++LH+axDdxLgt7J7WcGmLa4fJ0tPIYPlBxu7I0Y ex4cxXX5rfxO4hmpw6q3TNvyHqadrF7OjnnDagTTqaMiJcA/gwLAvShES4hMg7CT/ZWZ bJps+/3gyIcypia3M7KfaYZeBnpUnttXLPI2pR6fahvXOdqDqmXB61S6vp2pjfpvyaCv PoEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kfdzuH7vgkcBo716puoDvuEBU5u/scnjNqjBPPyH9K4=; b=qhfI7VKOxsgnvwR90KTsx6XvzI5FIc2KJZvFkjQVnUH6GDQri5DGEeqOGLJu1Rx7/P 9rM2/eg0u7SpBzdJXScfW+u4cBKoOblVyt6pnWlrVRR6ERfiwX9O1eRXbYYDkq5ehczv 5I87nZI+XFhxfXuWRR9zoWw6Dn5tnBW2g8i1s04NPxQAjSL3LPOuLpxaAj1ACzfLYcMv 5IUSU2gNK4vrooNj6g5XhkI2cNw4XpsguJKyzgoXF4g8vIH9c/L8i+elvcaaW5Cd9+Mm 07MR5OXWSDQrLu3bdqGNugUynbSKLBCfQF4Q3+aCK9p6sgwc4KaJwB7Itlr1oClEX3Q+ cjew== X-Gm-Message-State: AOAM5337FeHIdmcb0RElgbJdnKAzwXFzbAMxce+4gwVCnNuCH6+Ef8C8 nu6QAQkBbkwU2AuMQcpOBOZN7tWn7I3QZKqUzck= X-Google-Smtp-Source: ABdhPJxrvWs6/s/414LKLtVNzVmcJYTfEzkZH7LhpsxWkTKQ2gzYNgn8FNBguGf/1dxsnZ1DMqX0ZQ== X-Received: by 2002:a05:6830:310f:: with SMTP id b15mr35196066ots.31.1641291219939; Tue, 04 Jan 2022 02:13:39 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:39 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 08/13] lib: utils/irqchip: Add IMSIC library Date: Tue, 4 Jan 2022 15:43:18 +0530 Message-Id: <20220104101323.127564-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104101323.127564-1-apatel@ventanamicro.com> References: <20220104101323.127564-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021341_298970_1644D173 X-CRM114-Status: GOOD ( 24.54 ) X-Spam-Score: -0.2 (/) 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: We add simple IMSIC library which is independent of hardware description format (FDT or ACPI). This IMSIC library can be used by custom OpenSBI platform support to setup IMSIC for external interrupts. Content analysis details: (-0.2 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:344 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We add simple IMSIC library which is independent of hardware description format (FDT or ACPI). This IMSIC library can be used by custom OpenSBI platform support to setup IMSIC for external interrupts. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi_utils/irqchip/imsic.h | 50 ++++++ lib/utils/irqchip/imsic.c | 287 ++++++++++++++++++++++++++++++ lib/utils/irqchip/objects.mk | 1 + 3 files changed, 338 insertions(+) create mode 100644 include/sbi_utils/irqchip/imsic.h create mode 100644 lib/utils/irqchip/imsic.c diff --git a/include/sbi_utils/irqchip/imsic.h b/include/sbi_utils/irqchip/imsic.h new file mode 100644 index 0000000..cffcb5a --- /dev/null +++ b/include/sbi_utils/irqchip/imsic.h @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * Copyright (c) 2022 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __IRQCHIP_IMSIC_H__ +#define __IRQCHIP_IMSIC_H__ + +#include + +#define IMSIC_MMIO_PAGE_SHIFT 12 +#define IMSIC_MMIO_PAGE_SZ (1UL << IMSIC_MMIO_PAGE_SHIFT) + +#define IMSIC_MAX_REGS 16 + +struct imsic_regs { + unsigned long addr; + unsigned long size; +}; + +struct imsic_data { + bool targets_mmode; + u32 guest_index_bits; + u32 hart_index_bits; + u32 group_index_bits; + u32 group_index_shift; + unsigned long num_ids; + struct imsic_regs regs[IMSIC_MAX_REGS]; +}; + +int imsic_map_hartid_to_data(u32 hartid, struct imsic_data *imsic, int file); + +struct imsic_data *imsic_get_data(u32 hartid); + +int imsic_get_target_file(u32 hartid); + +void imsic_local_irqchip_init(void); + +int imsic_warm_irqchip_init(void); + +int imsic_data_check(struct imsic_data *imsic); + +int imsic_cold_irqchip_init(struct imsic_data *imsic); + +#endif diff --git a/lib/utils/irqchip/imsic.c b/lib/utils/irqchip/imsic.c new file mode 100644 index 0000000..f87321f --- /dev/null +++ b/lib/utils/irqchip/imsic.c @@ -0,0 +1,287 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * Copyright (c) 2022 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define IMSIC_MMIO_PAGE_LE 0x00 +#define IMSIC_MMIO_PAGE_BE 0x04 + +#define IMSIC_MIN_ID 63 +#define IMSIC_MAX_ID 2047 + +#define IMSIC_EIDELIVERY 0x70 + +#define IMSIC_EITHRESHOLD 0x72 + +#define IMSIC_TOPEI 0x76 +#define IMSIC_TOPEI_ID_SHIFT 16 +#define IMSIC_TOPEI_ID_MASK 0x7ff +#define IMSIC_TOPEI_PRIO_MASK 0x7ff + +#define IMSIC_EIP0 0x80 + +#define IMSIC_EIP63 0xbf + +#define IMSIC_EIE0 0xc0 + +#define IMSIC_EIE63 0xff + +#define IMSIC_DISABLE_EIDELIVERY 0 +#define IMSIC_ENABLE_EIDELIVERY 1 +#define IMSIC_DISABLE_EITHRESHOLD 0 +#define IMSIC_ENABLE_EITHRESHOLD IMSIC_MAX_ID + +#define IMSIC_IPI_ID 1 + +#define imsic_csr_write(__c, __v) \ +do { \ + csr_write(CSR_MISELECT, __c); \ + csr_write(CSR_MIREG, __v); \ +} while (0) + +#define imsic_csr_read(__c) \ +({ \ + unsigned long __v; \ + csr_write(CSR_MISELECT, __c); \ + __v = csr_read(CSR_MIREG); \ + __v; \ +}) + +static struct imsic_data *imsic_hartid2data[SBI_HARTMASK_MAX_BITS]; +static int imsic_hartid2file[SBI_HARTMASK_MAX_BITS]; + +int imsic_map_hartid_to_data(u32 hartid, struct imsic_data *imsic, int file) +{ + if (!imsic || !imsic->targets_mmode || + (SBI_HARTMASK_MAX_BITS <= hartid)) + return SBI_EINVAL; + + imsic_hartid2data[hartid] = imsic; + imsic_hartid2file[hartid] = file; + return 0; +} + +struct imsic_data *imsic_get_data(u32 hartid) +{ + if (SBI_HARTMASK_MAX_BITS <= hartid) + return NULL; + return imsic_hartid2data[hartid]; +} + +int imsic_get_target_file(u32 hartid) +{ + if ((SBI_HARTMASK_MAX_BITS <= hartid) || + !imsic_hartid2data[hartid]) + return SBI_ENOENT; + return imsic_hartid2file[hartid]; +} + +static int imsic_external_irqfn(struct sbi_trap_regs *regs) +{ + ulong mirq; + + while ((mirq = csr_swap(CSR_MTOPEI, 0))) { + mirq = (mirq >> IMSIC_TOPEI_ID_SHIFT); + + switch (mirq) { + case IMSIC_IPI_ID: + sbi_ipi_process(); + break; + default: + sbi_printf("%s: unhandled IRQ%d\n", + __func__, (u32)mirq); + break; + } + } + + return 0; +} + +static void imsic_ipi_send(u32 target_hart) +{ + unsigned long reloff; + struct imsic_regs *regs; + struct imsic_data *data = imsic_hartid2data[target_hart]; + int file = imsic_hartid2file[target_hart]; + + if (!data || !data->targets_mmode) + return; + + regs = &data->regs[0]; + reloff = file * (1UL << data->guest_index_bits) * IMSIC_MMIO_PAGE_SZ; + while (regs->size && (regs->size <= reloff)) { + reloff -= regs->size; + regs++; + } + + if (regs->size && (reloff < regs->size)) + writel(IMSIC_IPI_ID, + (void *)(regs->addr + reloff + IMSIC_MMIO_PAGE_LE)); +} + +static struct sbi_ipi_device imsic_ipi_device = { + .name = "aia-imsic", + .ipi_send = imsic_ipi_send +}; + +void imsic_local_irqchip_init(void) +{ + /* + * This function is expected to be called from: + * 1) nascent_init() platform callback which is called + * very early on each HART in boot-up path and and + * HSM resume path. + * 2) irqchip_init() platform callback which is called + * in boot-up path. + */ + + /* Setup threshold to allow all enabled interrupts */ + imsic_csr_write(IMSIC_EITHRESHOLD, IMSIC_ENABLE_EITHRESHOLD); + + /* Enable interrupt delivery */ + imsic_csr_write(IMSIC_EIDELIVERY, IMSIC_ENABLE_EIDELIVERY); + + /* Enable IPI */ + csr_write(CSR_MSETEIENUM, IMSIC_IPI_ID); +} + +int imsic_warm_irqchip_init(void) +{ + unsigned long i; + struct imsic_data *imsic = imsic_hartid2data[current_hartid()]; + + /* Sanity checks */ + if (!imsic || !imsic->targets_mmode) + return SBI_EINVAL; + + /* Disable all interrupts */ + for (i = 1; i <= imsic->num_ids; i++) + csr_write(CSR_MCLREIENUM, i); + + /* Clear IPI */ + csr_write(CSR_MCLREIPNUM, IMSIC_IPI_ID); + + /* Local IMSIC initialization */ + imsic_local_irqchip_init(); + + return 0; +} + +int imsic_data_check(struct imsic_data *imsic) +{ + u32 i, tmp; + unsigned long base_addr, addr, mask; + + /* Sanity checks */ + if (!imsic || + (imsic->num_ids < IMSIC_MIN_ID) || + (IMSIC_MAX_ID < imsic->num_ids)) + return SBI_EINVAL; + + tmp = BITS_PER_LONG - IMSIC_MMIO_PAGE_SHIFT; + if (tmp < imsic->guest_index_bits) + return SBI_EINVAL; + + tmp = BITS_PER_LONG - IMSIC_MMIO_PAGE_SHIFT - + imsic->guest_index_bits; + if (tmp < imsic->hart_index_bits) + return SBI_EINVAL; + + tmp = BITS_PER_LONG - IMSIC_MMIO_PAGE_SHIFT - + imsic->guest_index_bits - imsic->hart_index_bits; + if (tmp < imsic->group_index_bits) + return SBI_EINVAL; + + tmp = IMSIC_MMIO_PAGE_SHIFT + imsic->guest_index_bits + + imsic->hart_index_bits; + if (imsic->group_index_shift < tmp) + return SBI_EINVAL; + tmp = imsic->group_index_bits + imsic->group_index_shift - 1; + if (tmp >= BITS_PER_LONG) + return SBI_EINVAL; + + /* + * Number of interrupt identities should be 1 less than + * multiple of 63 + */ + if ((imsic->num_ids & IMSIC_MIN_ID) != IMSIC_MIN_ID) + return SBI_EINVAL; + + /* We should have at least one regset */ + if (!imsic->regs[0].size) + return SBI_EINVAL; + + /* Match patter of each regset */ + base_addr = imsic->regs[0].addr; + base_addr &= ~((1UL << (imsic->guest_index_bits + + imsic->hart_index_bits + + IMSIC_MMIO_PAGE_SHIFT)) - 1); + base_addr &= ~(((1UL << imsic->group_index_bits) - 1) << + imsic->group_index_shift); + for (i = 0; i < IMSIC_MAX_REGS && imsic->regs[i].size; i++) { + mask = (1UL << imsic->guest_index_bits) * IMSIC_MMIO_PAGE_SZ; + mask -= 1UL; + if (imsic->regs[i].size & mask) + return SBI_EINVAL; + + addr = imsic->regs[i].addr; + addr &= ~((1UL << (imsic->guest_index_bits + + imsic->hart_index_bits + + IMSIC_MMIO_PAGE_SHIFT)) - 1); + addr &= ~(((1UL << imsic->group_index_bits) - 1) << + imsic->group_index_shift); + if (base_addr != addr) + return SBI_EINVAL; + } + + return 0; +} + +int imsic_cold_irqchip_init(struct imsic_data *imsic) +{ + int i, rc; + struct sbi_domain_memregion reg; + + /* Sanity checks */ + rc = imsic_data_check(imsic); + if (rc) + return rc; + + /* We only initialize M-mode IMSIC */ + if (!imsic->targets_mmode) + return SBI_EINVAL; + + /* Setup external interrupt function for IMSIC */ + sbi_trap_set_external_irqfn(imsic_external_irqfn); + + /* Add IMSIC regions to the root domain */ + for (i = 0; i < IMSIC_MAX_REGS && imsic->regs[i].size; i++) { + sbi_domain_memregion_init(imsic->regs[i].addr, + imsic->regs[i].size, + SBI_DOMAIN_MEMREGION_MMIO, ®); + rc = sbi_domain_root_add_memregion(®); + if (rc) + return rc; + } + + /* Register IPI device */ + sbi_ipi_set_device(&imsic_ipi_device); + + return 0; +} diff --git a/lib/utils/irqchip/objects.mk b/lib/utils/irqchip/objects.mk index 934f706..76a3c94 100644 --- a/lib/utils/irqchip/objects.mk +++ b/lib/utils/irqchip/objects.mk @@ -9,4 +9,5 @@ libsbiutils-objs-y += irqchip/fdt_irqchip.o libsbiutils-objs-y += irqchip/fdt_irqchip_plic.o +libsbiutils-objs-y += irqchip/imsic.o libsbiutils-objs-y += irqchip/plic.o From patchwork Tue Jan 4 10:13:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575156 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=kYHpRa/V; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=cst/ugj/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpNx55Sfz9sXM for ; Tue, 4 Jan 2022 21:13:53 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ba9ieB4Ip540d0GNEKmAFIYatBpkV8R1Vw9qq0uMayU=; b=kYHpRa/VnuGS/Y P2TGAPl5F4O5sy+HwdfZU/dIB4QE0pFg8sjXGrf2XL3NnI9aM7g4y9PxWnlNQWEaVVg7O3g9ehEiV /6SB2VKCylb4vHhipiyxq6T8HphVZjO0nG4nbYpfZnCuO+5kJntdOiH7ohUzUpokg6KGxZKk4b9Ud W5u1SVAHvpBtmg3RsiHV/mXMqP/0JzbyJ6SOYN9FXWYv/kY37G8vy3OD0RimMJremXWBpdOt2DfyR 4AmA9yFvuMQLKnlK0/7oL2/3RlusR1J4uWA5eJoYo/iNVPBEJDyC4wUWVBB3b+PBxdItdShE1/XFB Jj7GUEbNBUK5ZMXw0uGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gp9-00B6ec-1n; Tue, 04 Jan 2022 10:13:47 +0000 Received: from mail-oo1-xc42.google.com ([2607:f8b0:4864:20::c42]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gp5-00B6bx-GH for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:45 +0000 Received: by mail-oo1-xc42.google.com with SMTP id r18-20020a4a7252000000b002c5f52d1834so11468481ooe.0 for ; Tue, 04 Jan 2022 02:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uvA3T+tYWcFAuVF9k0kDa+MXnDB7g92kSvvEG1MJeng=; b=cst/ugj/xj0TQ4C+7YvE7CFRyF3J5ovo/5Q72QSzKSkYuGzHuhrC5RvMjsxdQMnRK3 RZvKjZwDW3wODzDQSaRsL1oBwJq3DwaAa6m+h1ose5ASlQnCfmV9smsCSJB7g5AS+REi kV1kMhuA4pje5UKSnjbKlQ7t3JBuHs0PTEzwjSZHL6EWAFnlDS234vrTTctOG8pH4RuY l471FZ9xlQ6i4aWBpUQ6hNj3r7YrqfkE/fu4RtLau8NteslIVx7KnO/oPQocEzeH+U+v DnZAzEcMFDan0tG3pA7ulzt/zWBVlPOByI1PZdIfH/4FRwpfW1suZGBd+G1pLWaSb01B +lhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uvA3T+tYWcFAuVF9k0kDa+MXnDB7g92kSvvEG1MJeng=; b=cicmOrI/PFbD4BloU0NN8h0v8u+DNSUfyZ/n4x1Jc/ZAKAcx//vYFvrGv7RMGrVNEg R097FE6x5knPpB1viDPpHBljkMQVVL9O7mF1TeZMRblCuPji1Uzn9SwN4Xr/GUOTkPB2 bdXSqhmss/5sON9H80T9DBRriypPW179ABaVXAbhBEsHXtA2MdnwZ+z8LihvhIbtTdbw U5sbDYm0qfvhjQv6WlDL8f1SnUivqV4C2LE0hZK5AnoeycmH1KX6EHsAbAEF2gPcksck DGGze4f1fYoWXAlTdY8t/z5FxYfStMJo6vEO0NMdA/dBI35ZmPN4/aCAdQuEmtm3g7P3 Yekg== X-Gm-Message-State: AOAM533xlvX7ytQWoHdtOYsz6235usfCEIciLu790y8ZfEPAoVJ9UIYe OSgFd4BdrqeGmQruZoAuDDhiAw== X-Google-Smtp-Source: ABdhPJyJMKLEDQmeEnjxqW5daX6jnu6ngn9l6AYW/QjxKKtjpJWUYfo16Q1UTmweDQksYieWodxOwg== X-Received: by 2002:a4a:51c5:: with SMTP id s188mr31666051ooa.44.1641291222275; Tue, 04 Jan 2022 02:13:42 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:42 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 09/13] lib: utils/irqchip: Add FDT based driver for IMSIC Date: Tue, 4 Jan 2022 15:43:19 +0530 Message-Id: <20220104101323.127564-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104101323.127564-1-apatel@ventanamicro.com> References: <20220104101323.127564-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021343_588620_1188ECCB X-CRM114-Status: GOOD ( 24.01 ) X-Spam-Score: -0.2 (/) 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: We add simple FDT irqchip driver for IMSIC so that generic platform (and other FDT based platforms) can utilize common IMIC library. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi_utils/fdt/fdt_helper.h | 6 ++ lib/utils/fdt/fdt_helper.c | 103 ++++++++++++++++++++++ [...] Content analysis details: (-0.2 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:c42 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We add simple FDT irqchip driver for IMSIC so that generic platform (and other FDT based platforms) can utilize common IMIC library. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi_utils/fdt/fdt_helper.h | 6 ++ lib/utils/fdt/fdt_helper.c | 103 +++++++++++++++++++++++++ lib/utils/irqchip/fdt_irqchip.c | 2 + lib/utils/irqchip/fdt_irqchip_imsic.c | 106 ++++++++++++++++++++++++++ lib/utils/irqchip/objects.mk | 1 + platform/generic/platform.c | 12 +++ 6 files changed, 230 insertions(+) create mode 100644 lib/utils/irqchip/fdt_irqchip_imsic.c diff --git a/include/sbi_utils/fdt/fdt_helper.h b/include/sbi_utils/fdt/fdt_helper.h index 24fee7a..4c8d29e 100644 --- a/include/sbi_utils/fdt/fdt_helper.h +++ b/include/sbi_utils/fdt/fdt_helper.h @@ -68,6 +68,12 @@ int fdt_parse_uart8250_node(void *fdt, int nodeoffset, int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart, const char *compatible); +struct imsic_data; + +bool fdt_check_imsic_mlevel(void *fdt); + +int fdt_parse_imsic_node(void *fdt, int nodeoff, struct imsic_data *imsic); + struct plic_data; int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic); diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c index 5bf4021..e2782b6 100644 --- a/lib/utils/fdt/fdt_helper.c +++ b/lib/utils/fdt/fdt_helper.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #define DEFAULT_UART_FREQ 0 @@ -465,6 +466,108 @@ int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart, return fdt_parse_uart8250_node(fdt, nodeoffset, uart); } +bool fdt_check_imsic_mlevel(void *fdt) +{ + const fdt32_t *val; + int i, len, noff = 0; + + if (!fdt) + return false; + + while ((noff = fdt_node_offset_by_compatible(fdt, noff, + "riscv,imsics")) >= 0) { + val = fdt_getprop(fdt, noff, "interrupts-extended", &len); + if (val && len > sizeof(fdt32_t)) { + len = len / sizeof(fdt32_t); + for (i = 0; i < len; i += 2) { + if (fdt32_to_cpu(val[i + 1]) == IRQ_M_EXT) + return true; + } + } + } + + return false; +} + +int fdt_parse_imsic_node(void *fdt, int nodeoff, struct imsic_data *imsic) +{ + const fdt32_t *val; + struct imsic_regs *regs; + uint64_t reg_addr, reg_size; + int i, rc, len, nr_parent_irqs; + + if (nodeoff < 0 || !imsic || !fdt) + return SBI_ENODEV; + + imsic->targets_mmode = false; + val = fdt_getprop(fdt, nodeoff, "interrupts-extended", &len); + if (val && len > sizeof(fdt32_t)) { + len = len / sizeof(fdt32_t); + nr_parent_irqs = len / 2; + for (i = 0; i < len; i += 2) { + if (fdt32_to_cpu(val[i + 1]) == IRQ_M_EXT) { + imsic->targets_mmode = true; + break; + } + } + } else + return SBI_EINVAL; + + val = fdt_getprop(fdt, nodeoff, "riscv,guest-index-bits", &len); + if (val && len > 0) + imsic->guest_index_bits = fdt32_to_cpu(*val); + else + imsic->guest_index_bits = 0; + + val = fdt_getprop(fdt, nodeoff, "riscv,hart-index-bits", &len); + if (val && len > 0) { + imsic->hart_index_bits = fdt32_to_cpu(*val); + } else { + imsic->hart_index_bits = __fls(nr_parent_irqs); + if ((1UL << imsic->hart_index_bits) < nr_parent_irqs) + imsic->hart_index_bits++; + } + + val = fdt_getprop(fdt, nodeoff, "riscv,group-index-bits", &len); + if (val && len > 0) + imsic->group_index_bits = fdt32_to_cpu(*val); + else + imsic->group_index_bits = 0; + + val = fdt_getprop(fdt, nodeoff, "riscv,group-index-shift", &len); + if (val && len > 0) + imsic->group_index_shift = fdt32_to_cpu(*val); + else + imsic->group_index_shift = 2 * IMSIC_MMIO_PAGE_SHIFT; + + val = fdt_getprop(fdt, nodeoff, "riscv,num-ids", &len); + if (val && len > 0) + imsic->num_ids = fdt32_to_cpu(*val); + else + return SBI_EINVAL; + + for (i = 0; i < IMSIC_MAX_REGS; i++) { + regs = &imsic->regs[i]; + regs->addr = 0; + regs->size = 0; + } + + for (i = 0; i < (IMSIC_MAX_REGS - 1); i++) { + regs = &imsic->regs[i]; + + rc = fdt_get_node_addr_size(fdt, nodeoff, i, + ®_addr, ®_size); + if (rc < 0 || !reg_addr || !reg_size) + break; + regs->addr = reg_addr; + regs->size = reg_size; + }; + if (!imsic->regs[0].size) + return SBI_EINVAL; + + return 0; +} + int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic) { int len, rc; diff --git a/lib/utils/irqchip/fdt_irqchip.c b/lib/utils/irqchip/fdt_irqchip.c index bf6969a..cf64a2e 100644 --- a/lib/utils/irqchip/fdt_irqchip.c +++ b/lib/utils/irqchip/fdt_irqchip.c @@ -12,9 +12,11 @@ #include #include +extern struct fdt_irqchip fdt_irqchip_imsic; extern struct fdt_irqchip fdt_irqchip_plic; static struct fdt_irqchip *irqchip_drivers[] = { + &fdt_irqchip_imsic, &fdt_irqchip_plic }; diff --git a/lib/utils/irqchip/fdt_irqchip_imsic.c b/lib/utils/irqchip/fdt_irqchip_imsic.c new file mode 100644 index 0000000..b6962be --- /dev/null +++ b/lib/utils/irqchip/fdt_irqchip_imsic.c @@ -0,0 +1,106 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * Copyright (c) 2022 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include +#include +#include +#include + +#define IMSIC_MAX_NR 16 + +static unsigned long imsic_count = 0; +static struct imsic_data imsic[IMSIC_MAX_NR]; + +static int irqchip_imsic_update_hartid_table(void *fdt, int nodeoff, + struct imsic_data *id) +{ + const fdt32_t *val; + u32 phandle, hwirq, hartid; + int i, err, count, cpu_offset, cpu_intc_offset; + + val = fdt_getprop(fdt, nodeoff, "interrupts-extended", &count); + if (!val || count < sizeof(fdt32_t)) + return SBI_EINVAL; + count = count / sizeof(fdt32_t); + + for (i = 0; i < count; i += 2) { + phandle = fdt32_to_cpu(val[i]); + hwirq = fdt32_to_cpu(val[i + 1]); + + cpu_intc_offset = fdt_node_offset_by_phandle(fdt, phandle); + if (cpu_intc_offset < 0) + continue; + + cpu_offset = fdt_parent_offset(fdt, cpu_intc_offset); + if (cpu_intc_offset < 0) + continue; + + err = fdt_parse_hart_id(fdt, cpu_offset, &hartid); + if (err) + return SBI_EINVAL; + if (SBI_HARTMASK_MAX_BITS <= hartid) + return SBI_EINVAL; + + switch (hwirq) { + case IRQ_M_EXT: + err = imsic_map_hartid_to_data(hartid, id, i / 2); + if (err) + return err; + break; + default: + break; + } + } + + return 0; +} + +static int irqchip_imsic_cold_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + int rc; + struct imsic_data *id; + + if (IMSIC_MAX_NR <= imsic_count) + return SBI_ENOSPC; + id = &imsic[imsic_count]; + + rc = fdt_parse_imsic_node(fdt, nodeoff, id); + if (rc) + return rc; + if (!id->targets_mmode) + return 0; + + rc = irqchip_imsic_update_hartid_table(fdt, nodeoff, id); + if (rc) + return rc; + + rc = imsic_cold_irqchip_init(id); + if (rc) + return rc; + + imsic_count++; + + return 0; +} + +static const struct fdt_match irqchip_imsic_match[] = { + { .compatible = "riscv,imsics" }, + { }, +}; + +struct fdt_irqchip fdt_irqchip_imsic = { + .match_table = irqchip_imsic_match, + .cold_init = irqchip_imsic_cold_init, + .warm_init = imsic_warm_irqchip_init, +}; diff --git a/lib/utils/irqchip/objects.mk b/lib/utils/irqchip/objects.mk index 76a3c94..ae6f255 100644 --- a/lib/utils/irqchip/objects.mk +++ b/lib/utils/irqchip/objects.mk @@ -8,6 +8,7 @@ # libsbiutils-objs-y += irqchip/fdt_irqchip.o +libsbiutils-objs-y += irqchip/fdt_irqchip_imsic.o libsbiutils-objs-y += irqchip/fdt_irqchip_plic.o libsbiutils-objs-y += irqchip/imsic.o libsbiutils-objs-y += irqchip/plic.o diff --git a/platform/generic/platform.c b/platform/generic/platform.c index bc6e761..8a4fb70 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,7 @@ static void fw_platform_lookup_special(void *fdt, int root_offset) } extern struct sbi_platform platform; +static bool platform_has_mlevel_imsic = false; static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 }; /* @@ -110,6 +112,8 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1, platform.hart_count = hart_count; + platform_has_mlevel_imsic = fdt_check_imsic_mlevel(fdt); + /* Return original FDT pointer */ return arg1; @@ -118,6 +122,13 @@ fail: wfi(); } +static int generic_nascent_init(void) +{ + if (platform_has_mlevel_imsic) + imsic_local_irqchip_init(); + return 0; +} + static int generic_early_init(bool cold_boot) { if (!generic_plat || !generic_plat->early_init) @@ -210,6 +221,7 @@ static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx, } const struct sbi_platform_operations platform_ops = { + .nascent_init = generic_nascent_init, .early_init = generic_early_init, .final_init = generic_final_init, .early_exit = generic_early_exit, From patchwork Tue Jan 4 10:13:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=dXBB1gbS; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=TdCJR/FP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpNy5Jxpz9t25 for ; Tue, 4 Jan 2022 21:13:54 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2YcMgG+Bh/l7qoTMwfCcbQlycII/5EyOyoW/uOt7wTo=; b=dXBB1gbSf/4iHJ F6GHcJKPP8+gkq2e4c2WlyP9kIjHWQcfCQZ2AxT06dKFLHt0ipbezg5gdCRqSwQiBypbjs9Wl59bK nykd7+b46S7hC8DILlBurtNH7etKr9Luz0gCG+sEW6LEygDrxiNGRyA/kdJb+UmTfgLlKngN5ff69 jY3zJk6kES9Qf9jZQB5OSHf5bJTLwEEmHRoQF12TMvmSpeTcxx41SVfO+lSHIUx81v5xitA695oXm oKxh7cm5o9tDrfjdFkA/tM8nfXPYdxdyf+2vsAKOwooN6bjnN3vcQFBpxlidkI7iD9uMpaourjpXX VRC064zjCmJHiDHDPOYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gp9-00B6f7-OX; Tue, 04 Jan 2022 10:13:47 +0000 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gp7-00B6d6-QF for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:47 +0000 Received: by mail-oo1-xc2f.google.com with SMTP id t13-20020a4a760d000000b002dab4d502dfso11175505ooc.6 for ; Tue, 04 Jan 2022 02:13:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B9lHKNZ3SlLbT9yNcdGkCHvkBhViWZTHgEpYd+JhD1U=; b=TdCJR/FP+ByVulqRczHrFXDxG5N/SENGCRHc5ZprarEHwRjwSWq9oOg22dmZYJYDG4 xGk/G5xXM95gg0KYtUZq5Evlusa5fI0OwkJ7dA1SpWY4KZcQb7UurNRXCDKMRbcTLTN+ XgGSNiNvRSdWQDiPxChzZqBflox3u5OHpWKPx46MEln/TFK97s4R/gNdwh4u/vBXgFyt z3c3L1Yhd3pCsla91WbdJ2UAz/VD40uO3jf6d/FKXUU0Utu7yeyT72f6+NxDmvOP8BAb RKceEhUX+LRnICOi12pCltohOT2qQU/R+zZKAUTBp4DEdZuDuF6LTOxV1POrn1E6Mwyl KbkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B9lHKNZ3SlLbT9yNcdGkCHvkBhViWZTHgEpYd+JhD1U=; b=5rIwrH51fiwSJy75fM3iEENndxc6SWl2NWM2lvA4qbs9+sH5nNuN3SZ2l2UXsAGRB+ 6+Vl1jNds634WsCRWwP1sRfZQ0CaaFzGW8OI5iIFlQPswa2w0gu02Zh+nBUz0BJtYO9G JxqvTr87en21uI7jnxv3Ad8p7fHoTzWZmRMgJIVgHMgAOUBeT1ZEHpiCYKpJ8VcaOQTj EmIQwRCom1LQFDW1lyB4H48NAy00SxrP0h+5CdH56cOKsh5MYrh4D0CA/J8nu+9btmI3 agvs6e1hMjQBYZrALf/GNi0KMyj/bOu6u3LKQqpjqjq+E+WzKk0Dx5uzk9ZQH+zxxHtn reMg== X-Gm-Message-State: AOAM530rs8KwmuF9sRLOnaLW9o196Tf05Cd9W8/aKNEvBh88D73Wlfqk fGRPOpO9wWZp/cXxTa5XinqXow== X-Google-Smtp-Source: ABdhPJzPbhaodw1mWerMhuO9ZwioNcT1nyrxLN+n0cAucjXA1SX1YPnHEjquhRDF8LvrrH9/kF+62w== X-Received: by 2002:a4a:9612:: with SMTP id q18mr31699588ooi.36.1641291224591; Tue, 04 Jan 2022 02:13:44 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:44 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 10/13] lib: utils: Disable appropriate IMSIC DT nodes in fdt_fixups() Date: Tue, 4 Jan 2022 15:43:20 +0530 Message-Id: <20220104101323.127564-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104101323.127564-1-apatel@ventanamicro.com> References: <20220104101323.127564-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021345_885893_DA23AC9D X-CRM114-Status: GOOD ( 15.74 ) X-Spam-Score: -0.2 (/) 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: We should disable IMSIC DT nodes in fdt_fixups() which are not accessible to the next booting stage based on currently assigned domain. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi_utils/fdt/fdt_fixup.h | 17 ++++++++++++++-- lib/utils/fdt/fdt_fixup.c | 32 ++++++++++ [...] Content analysis details: (-0.2 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:c2f 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We should disable IMSIC DT nodes in fdt_fixups() which are not accessible to the next booting stage based on currently assigned domain. Signed-off-by: Anup Patel Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi_utils/fdt/fdt_fixup.h | 17 ++++++++++++++-- lib/utils/fdt/fdt_fixup.c | 32 +++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/include/sbi_utils/fdt/fdt_fixup.h b/include/sbi_utils/fdt/fdt_fixup.h index c38e5d9..77575bb 100644 --- a/include/sbi_utils/fdt/fdt_fixup.h +++ b/include/sbi_utils/fdt/fdt_fixup.h @@ -21,6 +21,18 @@ */ void fdt_cpu_fixup(void *fdt); +/** + * Fix up the IMSIC nodes in the device tree + * + * This routine disables IMSIC nodes which are not accessible to the next + * booting stage based on currently assigned domain. + * + * It is recommended that platform codes call this helper in their final_init() + * + * @param fdt: device tree blob + */ +void fdt_imsic_fixup(void *fdt); + /** * Fix up the PLIC node in the device tree * @@ -64,8 +76,9 @@ int fdt_reserved_memory_nomap_fixup(void *fdt); * General device tree fix-up * * This routine do all required device tree fix-ups for a typical platform. - * It fixes up the PLIC node and the reserved memory node in the device tree - * by calling the corresponding helper routines to accomplish the task. + * It fixes up the PLIC node, IMSIC nodes, and the reserved memory node in + * the device tree by calling the corresponding helper routines to accomplish + * the task. * * It is recommended that platform codes call this helper in their final_init() * diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c index ac01ba3..c2460b8 100644 --- a/lib/utils/fdt/fdt_fixup.c +++ b/lib/utils/fdt/fdt_fixup.c @@ -52,6 +52,34 @@ void fdt_cpu_fixup(void *fdt) } } +static void fdt_domain_based_fixup_one(void *fdt, int nodeoff) +{ + int rc; + uint64_t reg_addr, reg_size; + struct sbi_domain *dom = sbi_domain_thishart_ptr(); + + rc = fdt_get_node_addr_size(fdt, nodeoff, 0, ®_addr, ®_size); + if (rc < 0 || !reg_addr || !reg_size) + return; + + if (!sbi_domain_check_addr(dom, reg_addr, dom->next_mode, + SBI_DOMAIN_READ | SBI_DOMAIN_WRITE)) { + rc = fdt_open_into(fdt, fdt, fdt_totalsize(fdt) + 32); + if (rc < 0) + return; + fdt_setprop_string(fdt, nodeoff, "status", "disabled"); + } +} + +void fdt_imsic_fixup(void *fdt) +{ + int noff = 0; + + while ((noff = fdt_node_offset_by_compatible(fdt, noff, + "riscv,imsics")) >= 0) + fdt_domain_based_fixup_one(fdt, noff); +} + void fdt_plic_fixup(void *fdt) { u32 *cells; @@ -261,10 +289,10 @@ int fdt_reserved_memory_nomap_fixup(void *fdt) void fdt_fixups(void *fdt) { + fdt_imsic_fixup(fdt); + fdt_plic_fixup(fdt); fdt_reserved_memory_fixup(fdt); fdt_pmu_fixup(fdt); } - - From patchwork Tue Jan 4 10:13:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575158 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=kOaXiFU6; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=Sto0x2a0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpP10mRvz9sXM for ; Tue, 4 Jan 2022 21:13:57 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JGr2gGQBoQ4L1mYKDvXjjLHmmMX9dTmUo4/SnJBfnGo=; b=kOaXiFU6J64+Ks rQtfOlKx4+3fzt2tLcZ+fxjrwCUMGR5W19zWutZK1smjqLcbgZm3DL4dkcBAu81RNsvgt8jtlT8d/ A4YF2xeSN+hklc3DCaXMZgmMPOJbrHsIFs95eloWVvpnneSUdQt+EhHu/XWOy/+B8qu+XbGHWsYeW DoRNJC/740dyRwJ7Y+Q3xndxaBKnUCR0QiLnJyPDW+86iF3qQoT9PcOMovyjQyFALfsSAXpqF8Cml 7ujY8u85uK1k5y5bWDweHr+m/df1vznah7pzVszC3G7c+MrgHGI77Q91/5ESGNvr/P8OJbW6EkJfl 0+PNgfhmawZTJAaDd2ug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gpD-00B6ir-B8; Tue, 04 Jan 2022 10:13:51 +0000 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gpA-00B6eo-7F for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:50 +0000 Received: by mail-ot1-x341.google.com with SMTP id o3-20020a9d4043000000b0058f31f4312fso44563581oti.1 for ; Tue, 04 Jan 2022 02:13:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bORIMO/bfRG3UjKkF1lsRaLM0uOwsGq0hZCVF+tK+jU=; b=Sto0x2a0x6b2ESiPZ5XXMQO7r90VwFtDK1pROYFbYGHrvvJgTzIsTxcDLIoLEiUzb6 dm+gsnQL3qSW7/LwsUovDYYwyajekxzNm+IJnYDpIDMUZ0CfD1Fn6QvQQt/stqG6x6UQ tqKFoSLd+GB2NY2rs4jRD9pszn1yhgv1UuDMVXFMP4OFPDZummLUeUSd3IRP10PJzScZ YvzIs1M0jIKsbDRmmSfMsiTWLGk8X7UWX9rm9JS+0qN/rXshmOeXe/YCbhEigyM7qiIa kUnjtYTOZi3YhBsdZaoChPhGf9ZJ0F2YhajXvjmSyT1UOGkxO8vYF6sU2CnEoZdw+2x0 QOcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bORIMO/bfRG3UjKkF1lsRaLM0uOwsGq0hZCVF+tK+jU=; b=ORqIC8n89SzXQhLZYN0YlDavkkuK83dnCClJGWqYiaIGZFF/ZnTH4H1tRCQ44Gzaj0 0srEKdH18SRMQK1vrreXCNPd9gos40uTw/NT5JBZsYNMFinfZ6A/VYEHeFEcVTFgEWAA WMnqjgDZ2m4MB5Juy1piGn3DNpkhy53S2i6J4lb63fm0rsjRciJncHUe91yR1Cz7tbPd 3+kme/fws7UyHiUyv3KiJMn2nopxv/Zd/XkbxbcGnzOegot3TFXFQZmF/ZmxJFohTZiu OdBgl1/ydNhajOTZPtwPj8fIaRKAmaUglSkYtBH0WIK9m7cZX+TSPBYYd3zu7q+9yw8R Zoug== X-Gm-Message-State: AOAM530axz929jsBk5Vonlsny2vaKLTsyhbcyeUWI/LwniXl3tDWjmaT +V6ZTkrAUtVNT1W8htRtmd5txw== X-Google-Smtp-Source: ABdhPJz6DM1TB+CzWcV4bbfMTwhcY8UyhDJm5R0uxgFvjpvTnda2CGBi02PJONWqH3AFNi5KMezx/Q== X-Received: by 2002:a05:6830:1d7c:: with SMTP id l28mr34772417oti.372.1641291226932; Tue, 04 Jan 2022 02:13:46 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:46 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 11/13] lib: utils/irqchip: Add APLIC initialization library Date: Tue, 4 Jan 2022 15:43:21 +0530 Message-Id: <20220104101323.127564-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104101323.127564-1-apatel@ventanamicro.com> References: <20220104101323.127564-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021348_298393_27DF3ECF X-CRM114-Status: GOOD ( 22.79 ) X-Spam-Score: -0.2 (/) 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: We add simple APLIC initialization library which is independent of hardware description format (FDT or ACPI). This APLIC initialization library can be used by custom OpenSBI platform support to setup [...] Content analysis details: (-0.2 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:341 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We add simple APLIC initialization library which is independent of hardware description format (FDT or ACPI). This APLIC initialization library can be used by custom OpenSBI platform support to setup APLIC domains. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi_utils/irqchip/aplic.h | 47 +++++ lib/utils/irqchip/aplic.c | 279 ++++++++++++++++++++++++++++++ lib/utils/irqchip/objects.mk | 1 + 3 files changed, 327 insertions(+) create mode 100644 include/sbi_utils/irqchip/aplic.h create mode 100644 lib/utils/irqchip/aplic.c diff --git a/include/sbi_utils/irqchip/aplic.h b/include/sbi_utils/irqchip/aplic.h new file mode 100644 index 0000000..82682e8 --- /dev/null +++ b/include/sbi_utils/irqchip/aplic.h @@ -0,0 +1,47 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * Copyright (c) 2022 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#ifndef __IRQCHIP_APLIC_H__ +#define __IRQCHIP_APLIC_H__ + +#include + +#define APLIC_MAX_DELEGATE 16 + +struct aplic_msicfg_data { + unsigned long lhxs; + unsigned long lhxw; + unsigned long hhxs; + unsigned long hhxw; + unsigned long base_addr; +}; + +struct aplic_delegate_data { + u32 first_irq; + u32 last_irq; + u32 child_index; +}; + +struct aplic_data { + unsigned long addr; + unsigned long size; + unsigned long num_idc; + unsigned long num_source; + bool targets_mmode; + bool has_msicfg_mmode; + struct aplic_msicfg_data msicfg_mmode; + bool has_msicfg_smode; + struct aplic_msicfg_data msicfg_smode; + struct aplic_delegate_data delegate[APLIC_MAX_DELEGATE]; +}; + +int aplic_cold_irqchip_init(struct aplic_data *aplic); + +#endif diff --git a/lib/utils/irqchip/aplic.c b/lib/utils/irqchip/aplic.c new file mode 100644 index 0000000..b8741c8 --- /dev/null +++ b/lib/utils/irqchip/aplic.c @@ -0,0 +1,279 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * Copyright (c) 2022 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include +#include + +#define APLIC_MAX_IDC (1UL << 14) +#define APLIC_MAX_SOURCE 1024 + +#define APLIC_DOMAINCFG 0x0000 +#define APLIC_DOMAINCFG_IE (1 << 8) +#define APLIC_DOMAINCFG_DM (1 << 2) +#define APLIC_DOMAINCFG_BE (1 << 0) + +#define APLIC_SOURCECFG_BASE 0x0004 +#define APLIC_SOURCECFG_D (1 << 10) +#define APLIC_SOURCECFG_CHILDIDX_MASK 0x000003ff +#define APLIC_SOURCECFG_SM_MASK 0x00000007 +#define APLIC_SOURCECFG_SM_INACTIVE 0x0 +#define APLIC_SOURCECFG_SM_DETACH 0x1 +#define APLIC_SOURCECFG_SM_EDGE_RISE 0x4 +#define APLIC_SOURCECFG_SM_EDGE_FALL 0x5 +#define APLIC_SOURCECFG_SM_LEVEL_HIGH 0x6 +#define APLIC_SOURCECFG_SM_LEVEL_LOW 0x7 + +#define APLIC_MMSICFGADDR 0x1bc0 +#define APLIC_MMSICFGADDRH 0x1bc4 +#define APLIC_SMSICFGADDR 0x1bc8 +#define APLIC_SMSICFGADDRH 0x1bcc + +#define APLIC_xMSICFGADDRH_L (1UL << 31) +#define APLIC_xMSICFGADDRH_HHXS_MASK 0x1f +#define APLIC_xMSICFGADDRH_HHXS_SHIFT 24 +#define APLIC_xMSICFGADDRH_LHXS_MASK 0x7 +#define APLIC_xMSICFGADDRH_LHXS_SHIFT 20 +#define APLIC_xMSICFGADDRH_HHXW_MASK 0x7 +#define APLIC_xMSICFGADDRH_HHXW_SHIFT 16 +#define APLIC_xMSICFGADDRH_LHXW_MASK 0xf +#define APLIC_xMSICFGADDRH_LHXW_SHIFT 12 +#define APLIC_xMSICFGADDRH_BAPPN_MASK 0xfff + +#define APLIC_xMSICFGADDR_PPN_SHIFT 12 + +#define APLIC_xMSICFGADDR_PPN_HART(__lhxs) \ + ((1UL << (__lhxs)) - 1) + +#define APLIC_xMSICFGADDR_PPN_LHX_MASK(__lhxw) \ + ((1UL << (__lhxw)) - 1) +#define APLIC_xMSICFGADDR_PPN_LHX_SHIFT(__lhxs) \ + ((__lhxs)) +#define APLIC_xMSICFGADDR_PPN_LHX(__lhxw, __lhxs) \ + (APLIC_xMSICFGADDR_PPN_LHX_MASK(__lhxw) << \ + APLIC_xMSICFGADDR_PPN_LHX_SHIFT(__lhxs)) + +#define APLIC_xMSICFGADDR_PPN_HHX_MASK(__hhxw) \ + ((1UL << (__hhxw)) - 1) +#define APLIC_xMSICFGADDR_PPN_HHX_SHIFT(__hhxs) \ + ((__hhxs) + APLIC_xMSICFGADDR_PPN_SHIFT) +#define APLIC_xMSICFGADDR_PPN_HHX(__hhxw, __hhxs) \ + (APLIC_xMSICFGADDR_PPN_HHX_MASK(__hhxw) << \ + APLIC_xMSICFGADDR_PPN_HHX_SHIFT(__hhxs)) + +#define APLIC_SETIP_BASE 0x1c00 +#define APLIC_SETIPNUM 0x1cdc + +#define APLIC_CLRIP_BASE 0x1d00 +#define APLIC_CLRIPNUM 0x1ddc + +#define APLIC_SETIE_BASE 0x1e00 +#define APLIC_SETIENUM 0x1edc + +#define APLIC_CLRIE_BASE 0x1f00 +#define APLIC_CLRIENUM 0x1fdc + +#define APLIC_SETIPNUM_LE 0x2000 +#define APLIC_SETIPNUM_BE 0x2004 + +#define APLIC_TARGET_BASE 0x3004 +#define APLIC_TARGET_HART_IDX_SHIFT 18 +#define APLIC_TARGET_HART_IDX_MASK 0x3fff +#define APLIC_TARGET_GUEST_IDX_SHIFT 12 +#define APLIC_TARGET_GUEST_IDX_MASK 0x3f +#define APLIC_TARGET_IPRIO_MASK 0xff +#define APLIC_TARGET_EIID_MASK 0x7ff + +#define APLIC_IDC_BASE 0x4000 +#define APLIC_IDC_SIZE 32 + +#define APLIC_IDC_IDELIVERY 0x00 + +#define APLIC_IDC_IFORCE 0x04 + +#define APLIC_IDC_ITHRESHOLD 0x08 + +#define APLIC_IDC_TOPI 0x18 +#define APLIC_IDC_TOPI_ID_SHIFT 16 +#define APLIC_IDC_TOPI_ID_MASK 0x3ff +#define APLIC_IDC_TOPI_PRIO_MASK 0xff + +#define APLIC_IDC_CLAIMI 0x1c + +#define APLIC_DEFAULT_PRIORITY 0 +#define APLIC_DISABLE_IDELIVERY 0 +#define APLIC_ENABLE_IDELIVERY 1 +#define APLIC_DISABLE_ITHRESHOLD APLIC_DEFAULT_PRIORITY +#define APLIC_ENABLE_ITHRESHOLD (APLIC_DEFAULT_PRIORITY + 1) + +static void aplic_writel_msicfg(struct aplic_msicfg_data *msicfg, + void *msicfgaddr, void *msicfgaddrH) +{ + u32 val; + unsigned long base_ppn; + + /* Check if MSI config is already locked */ + if (readl(msicfgaddrH) & APLIC_xMSICFGADDRH_L) + return; + + /* Compute the MSI base PPN */ + base_ppn = msicfg->base_addr >> APLIC_xMSICFGADDR_PPN_SHIFT; + base_ppn &= ~APLIC_xMSICFGADDR_PPN_HART(msicfg->lhxs); + base_ppn &= ~APLIC_xMSICFGADDR_PPN_LHX(msicfg->lhxw, msicfg->lhxs); + base_ppn &= ~APLIC_xMSICFGADDR_PPN_HHX(msicfg->hhxw, msicfg->hhxs); + + /* Write the lower MSI config register */ + writel((u32)base_ppn, msicfgaddr); + + /* Write the upper MSI config register */ + val = (((u64)base_ppn) >> 32) & + APLIC_xMSICFGADDRH_BAPPN_MASK; + val |= (msicfg->lhxw & APLIC_xMSICFGADDRH_LHXW_MASK) + << APLIC_xMSICFGADDRH_LHXW_SHIFT; + val |= (msicfg->hhxw & APLIC_xMSICFGADDRH_HHXW_MASK) + << APLIC_xMSICFGADDRH_HHXW_SHIFT; + val |= (msicfg->lhxs & APLIC_xMSICFGADDRH_LHXS_MASK) + << APLIC_xMSICFGADDRH_LHXS_SHIFT; + val |= (msicfg->hhxs & APLIC_xMSICFGADDRH_HHXS_MASK) + << APLIC_xMSICFGADDRH_HHXS_SHIFT; + writel(val, msicfgaddrH); +} + +static int aplic_check_msicfg(struct aplic_msicfg_data *msicfg) +{ + if (APLIC_xMSICFGADDRH_LHXS_MASK < msicfg->lhxs) + return SBI_EINVAL; + + if (APLIC_xMSICFGADDRH_LHXW_MASK < msicfg->lhxw) + return SBI_EINVAL; + + if (APLIC_xMSICFGADDRH_HHXS_MASK < msicfg->hhxs) + return SBI_EINVAL; + + if (APLIC_xMSICFGADDRH_HHXW_MASK < msicfg->hhxw) + return SBI_EINVAL; + + return 0; +} + +int aplic_cold_irqchip_init(struct aplic_data *aplic) +{ + int rc; + u32 i, j, tmp; + struct sbi_domain_memregion reg; + struct aplic_delegate_data *deleg; + u32 first_deleg_irq, last_deleg_irq; + + /* Sanity checks */ + if (!aplic || + !aplic->num_source || APLIC_MAX_SOURCE <= aplic->num_source || + APLIC_MAX_IDC <= aplic->num_idc) + return SBI_EINVAL; + if (aplic->targets_mmode && aplic->has_msicfg_mmode) { + rc = aplic_check_msicfg(&aplic->msicfg_mmode); + if (rc) + return rc; + } + if (aplic->targets_mmode && aplic->has_msicfg_smode) { + rc = aplic_check_msicfg(&aplic->msicfg_smode); + if (rc) + return rc; + } + + /* Set domain configuration to 0 */ + writel(0, (void *)(aplic->addr + APLIC_DOMAINCFG)); + + /* Disable all interrupts */ + for (i = 0; i <= aplic->num_source; i++) + writel(-1U, (void *)(aplic->addr + APLIC_CLRIE_BASE + + (i / 32) * sizeof(u32))); + + /* Set interrupt type and priority for all interrupts */ + for (i = 1; i <= aplic->num_source; i++) { + /* Set IRQ source configuration to 0 */ + writel(0, (void *)(aplic->addr + APLIC_SOURCECFG_BASE + + (i - 1) * sizeof(u32))); + /* Set IRQ target hart index and priority to 1 */ + writel(APLIC_DEFAULT_PRIORITY, (void *)(aplic->addr + + APLIC_TARGET_BASE + + (i - 1) * sizeof(u32))); + } + + /* Configure IRQ delegation */ + first_deleg_irq = -1U; + last_deleg_irq = 0; + for (i = 0; i < APLIC_MAX_DELEGATE; i++) { + deleg = &aplic->delegate[i]; + if (!deleg->first_irq || !deleg->last_irq) + continue; + if (aplic->num_source < deleg->first_irq || + aplic->num_source < deleg->last_irq) + continue; + if (APLIC_SOURCECFG_CHILDIDX_MASK < deleg->child_index) + continue; + if (deleg->first_irq > deleg->last_irq) { + tmp = deleg->first_irq; + deleg->first_irq = deleg->last_irq; + deleg->last_irq = tmp; + } + if (deleg->first_irq < first_deleg_irq) + first_deleg_irq = deleg->first_irq; + if (last_deleg_irq < deleg->last_irq) + last_deleg_irq = deleg->last_irq; + for (j = deleg->first_irq; j <= deleg->last_irq; j++) + writel(APLIC_SOURCECFG_D | deleg->child_index, + (void *)(aplic->addr + APLIC_SOURCECFG_BASE + + (j - 1) * sizeof(u32))); + } + + /* Default initialization of IDC structures */ + for (i = 0; i < aplic->num_idc; i++) { + writel(0, (void *)(aplic->addr + APLIC_IDC_BASE + + i * APLIC_IDC_SIZE + APLIC_IDC_IDELIVERY)); + writel(0, (void *)(aplic->addr + APLIC_IDC_BASE + + i * APLIC_IDC_SIZE + APLIC_IDC_IFORCE)); + writel(APLIC_DISABLE_ITHRESHOLD, (void *)(aplic->addr + + APLIC_IDC_BASE + + (i * APLIC_IDC_SIZE) + + APLIC_IDC_ITHRESHOLD)); + } + + /* MSI configuration */ + if (aplic->targets_mmode && aplic->has_msicfg_mmode) { + aplic_writel_msicfg(&aplic->msicfg_mmode, + (void *)(aplic->addr + APLIC_MMSICFGADDR), + (void *)(aplic->addr + APLIC_MMSICFGADDRH)); + } + if (aplic->targets_mmode && aplic->has_msicfg_smode) { + aplic_writel_msicfg(&aplic->msicfg_smode, + (void *)(aplic->addr + APLIC_SMSICFGADDR), + (void *)(aplic->addr + APLIC_SMSICFGADDRH)); + } + + /* + * Add APLIC region to the root domain if: + * 1) It targets M-mode of any HART directly or via MSIs + * 2) All interrupts are delegated to some child APLIC + */ + if (aplic->targets_mmode || + ((first_deleg_irq < last_deleg_irq) && + (last_deleg_irq == aplic->num_source) && + (first_deleg_irq == 1))) { + sbi_domain_memregion_init(aplic->addr, aplic->size, + SBI_DOMAIN_MEMREGION_MMIO, ®); + rc = sbi_domain_root_add_memregion(®); + if (rc) + return rc; + } + + return 0; +} diff --git a/lib/utils/irqchip/objects.mk b/lib/utils/irqchip/objects.mk index ae6f255..b2b3f79 100644 --- a/lib/utils/irqchip/objects.mk +++ b/lib/utils/irqchip/objects.mk @@ -10,5 +10,6 @@ libsbiutils-objs-y += irqchip/fdt_irqchip.o libsbiutils-objs-y += irqchip/fdt_irqchip_imsic.o libsbiutils-objs-y += irqchip/fdt_irqchip_plic.o +libsbiutils-objs-y += irqchip/aplic.o libsbiutils-objs-y += irqchip/imsic.o libsbiutils-objs-y += irqchip/plic.o From patchwork Tue Jan 4 10:13:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575159 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=QAfJbccf; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=h6zU/WR4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpP53blkz9sXM for ; Tue, 4 Jan 2022 21:14:01 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=To76n2d24pQ/Dh8xPo7oA6DkeuwHdKc4E8hIVru0os8=; b=QAfJbccfLd/Fl/ e35LfJm9W4I0sBlPzEdgDjURoqnjvuWLPCoN2wAYn6UDFCxToVN5onr6veTfvV8M1C7hFqKkIFk58 +wKHImz88cNO1wJnR95Tw6o332lSi+SXPBkQRNWMtUPSys/MW7d4bC+WO8Iil9HYlAZH8/5PBLbLP dJ2ghmDMmsjncm/oBftPzNCH61KcxFhlYxACxW6+2UA110Z/Bbos3G900lexNmHQUCiph9xkgFT0D NpdkEH3OeuHEJFtDBUtm2c6CI6r9JDdFkDNC/Yv6+drs9RoneUqwju+WspLPHGMFH+/c9VcwWs4th RvD6Pjxr/JTzSbztC5nw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gpF-00B6kg-4w; Tue, 04 Jan 2022 10:13:53 +0000 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gpB-00B6hU-RD for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:52 +0000 Received: by mail-ot1-x344.google.com with SMTP id r10-20020a056830080a00b0055c8fd2cebdso46700347ots.6 for ; Tue, 04 Jan 2022 02:13:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZiMI0p2aGk3k/Wme3wU6ziVxlWJm04RhQ1ZkyNrsdmE=; b=h6zU/WR4cYhKNC22iyY0ZbXIVAl09qjDI1c+/SXWNP0GAUYeACCtw/kVo1aEz/BxDE LiiqI8hHcDqhHtgReEkXZix/0TdCQdrRYTPsUcr0jGEfXMi7Br+B6De/mFt1ZD+N8QvS BMW0jKmBEEp2H8qR2gzgKKzQMiYV59+QDz99A3ThEdxlDOOzGOpKJhmAN1S3ZdPvkMlm mZEhu2wWxLaSBFjCFwihSxdJrFnPcedBUorJ1lhccFs8rxzVEkqNdjRWZMX0lbN6ifqJ JdCCkzR6x502P9NSrwGuqK7MtcMJFvAAW2DQoSx4UktAy284UGx7k472Qjs4MaOQMLCI yAjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZiMI0p2aGk3k/Wme3wU6ziVxlWJm04RhQ1ZkyNrsdmE=; b=IbQ447BtM9bLh7wRjiRKICn6Cm2HQvLbjmDkfTXIA4ToX4afCdkZI6Yn5AMiuXniLe CX8hPZyhQkAfQQO5hRMI1l/T6SRvbVHTQB3sknHrtSafvG16EL9Z0+mZVsVCHIqxIxBP lc5t9u7Rq0uCI9kP+0IKKqFPEEpEQF3EAz7Lhxl5MtByA9ZATWmy9C7gfTc7QS/3GNwA wPFrNBq6oA/DUf9i0O7bWqKHUMnlXss8pUyqz9Bv5gFLNyUMeI0CHCCfIWE6kGCrBoNA GJnuNXvtR+QdY+RAUnQ6zS79b2ClTIk47Hu4u7xiFOfxxbdioiFVzOe0fcOBXbKJE2o2 wsnw== X-Gm-Message-State: AOAM531cCsrtn1IEFG3UNRd6qAir7r6hdHUwfS5O4of0JSpzU41qo+lA tEWd+19JjJ3sP7xIKfaX832Myg== X-Google-Smtp-Source: ABdhPJw5UzLUU3u/Yrw2IPJXmKuTcSqAwteDP9YK0WvSfHXFT+6/Pc8UvKsYc9kODElyg4v41Hc8NQ== X-Received: by 2002:a05:6830:25d6:: with SMTP id d22mr36145502otu.87.1641291229275; Tue, 04 Jan 2022 02:13:49 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:49 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 12/13] lib: utils/irqchip: Add FDT based driver for APLIC Date: Tue, 4 Jan 2022 15:43:22 +0530 Message-Id: <20220104101323.127564-10-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104101323.127564-1-apatel@ventanamicro.com> References: <20220104101323.127564-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021349_913994_9BF96A54 X-CRM114-Status: GOOD ( 23.38 ) X-Spam-Score: -0.2 (/) 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: We add simple FDT irqchip driver for APLIC so that generic platform (and other FDT based platforms) can utilize common APLIC initialization library. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi_utils/fdt/fdt_helper.h | 4 + lib/utils/fdt/fdt_helper.c | 159 +++++++++++++++++++++++ [...] Content analysis details: (-0.2 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:344 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We add simple FDT irqchip driver for APLIC so that generic platform (and other FDT based platforms) can utilize common APLIC initialization library. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi_utils/fdt/fdt_helper.h | 4 + lib/utils/fdt/fdt_helper.c | 159 ++++++++++++++++++++++++++ lib/utils/irqchip/fdt_irqchip.c | 2 + lib/utils/irqchip/fdt_irqchip_aplic.c | 56 +++++++++ lib/utils/irqchip/objects.mk | 1 + 5 files changed, 222 insertions(+) create mode 100644 lib/utils/irqchip/fdt_irqchip_aplic.c diff --git a/include/sbi_utils/fdt/fdt_helper.h b/include/sbi_utils/fdt/fdt_helper.h index 4c8d29e..1232b26 100644 --- a/include/sbi_utils/fdt/fdt_helper.h +++ b/include/sbi_utils/fdt/fdt_helper.h @@ -68,6 +68,10 @@ int fdt_parse_uart8250_node(void *fdt, int nodeoffset, int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart, const char *compatible); +struct aplic_data; + +int fdt_parse_aplic_node(void *fdt, int nodeoff, struct aplic_data *aplic); + struct imsic_data; bool fdt_check_imsic_mlevel(void *fdt); diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c index e2782b6..2f5ebc8 100644 --- a/lib/utils/fdt/fdt_helper.c +++ b/lib/utils/fdt/fdt_helper.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -466,6 +467,164 @@ int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart, return fdt_parse_uart8250_node(fdt, nodeoffset, uart); } +int fdt_parse_aplic_node(void *fdt, int nodeoff, struct aplic_data *aplic) +{ + bool child_found; + const fdt32_t *val; + const fdt32_t *del; + struct imsic_data imsic; + int i, j, d, dcnt, len, noff, rc; + uint64_t reg_addr, reg_size; + struct aplic_delegate_data *deleg; + + if (nodeoff < 0 || !aplic || !fdt) + return SBI_ENODEV; + memset(aplic, 0, sizeof(*aplic)); + + rc = fdt_get_node_addr_size(fdt, nodeoff, 0, ®_addr, ®_size); + if (rc < 0 || !reg_addr || !reg_size) + return SBI_ENODEV; + aplic->addr = reg_addr; + aplic->size = reg_size; + + val = fdt_getprop(fdt, nodeoff, "riscv,num-sources", &len); + if (len > 0) + aplic->num_source = fdt32_to_cpu(*val); + + val = fdt_getprop(fdt, nodeoff, "interrupts-extended", &len); + if (val && len > sizeof(fdt32_t)) { + len = len / sizeof(fdt32_t); + for (i = 0; i < len; i += 2) { + if (fdt32_to_cpu(val[i + 1]) == IRQ_M_EXT) { + aplic->targets_mmode = true; + break; + } + } + aplic->num_idc = len / 2; + goto aplic_msi_parent_done; + } + + val = fdt_getprop(fdt, nodeoff, "msi-parent", &len); + if (val && len >= sizeof(fdt32_t)) { + noff = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*val)); + if (noff < 0) + return noff; + + rc = fdt_parse_imsic_node(fdt, noff, &imsic); + if (rc) + return rc; + + rc = imsic_data_check(&imsic); + if (rc) + return rc; + + aplic->targets_mmode = imsic.targets_mmode; + + if (imsic.targets_mmode) { + aplic->has_msicfg_mmode = true; + aplic->msicfg_mmode.lhxs = imsic.guest_index_bits; + aplic->msicfg_mmode.lhxw = imsic.hart_index_bits; + aplic->msicfg_mmode.hhxw = imsic.group_index_bits; + aplic->msicfg_mmode.hhxs = imsic.group_index_shift; + if (aplic->msicfg_mmode.hhxs < + (2 * IMSIC_MMIO_PAGE_SHIFT)) + return SBI_EINVAL; + aplic->msicfg_mmode.hhxs -= 24; + aplic->msicfg_mmode.base_addr = imsic.regs[0].addr; + } else { + goto aplic_msi_parent_done; + } + + val = fdt_getprop(fdt, nodeoff, "riscv,children", &len); + if (!val || len < sizeof(fdt32_t)) + goto aplic_msi_parent_done; + + noff = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*val)); + if (noff < 0) + return noff; + + val = fdt_getprop(fdt, noff, "msi-parent", &len); + if (!val || len < sizeof(fdt32_t)) + goto aplic_msi_parent_done; + + noff = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*val)); + if (noff < 0) + return noff; + + rc = fdt_parse_imsic_node(fdt, noff, &imsic); + if (rc) + return rc; + + rc = imsic_data_check(&imsic); + if (rc) + return rc; + + if (!imsic.targets_mmode) { + aplic->has_msicfg_smode = true; + aplic->msicfg_smode.lhxs = imsic.guest_index_bits; + aplic->msicfg_smode.lhxw = imsic.hart_index_bits; + aplic->msicfg_smode.hhxw = imsic.group_index_bits; + aplic->msicfg_smode.hhxs = imsic.group_index_shift; + if (aplic->msicfg_smode.hhxs < + (2 * IMSIC_MMIO_PAGE_SHIFT)) + return SBI_EINVAL; + aplic->msicfg_smode.hhxs -= 24; + aplic->msicfg_smode.base_addr = imsic.regs[0].addr; + } + } +aplic_msi_parent_done: + + for (d = 0; d < APLIC_MAX_DELEGATE; d++) { + deleg = &aplic->delegate[d]; + deleg->first_irq = 0; + deleg->last_irq = 0; + deleg->child_index = 0; + } + + del = fdt_getprop(fdt, nodeoff, "riscv,delegate", &len); + if (!del || len < (3 * sizeof(fdt32_t))) + goto skip_delegate_parse; + d = 0; + dcnt = len / sizeof(fdt32_t); + for (i = 0; i < dcnt; i += 3) { + if (d >= APLIC_MAX_DELEGATE) + break; + deleg = &aplic->delegate[d]; + + deleg->first_irq = fdt32_to_cpu(del[i + 1]); + deleg->last_irq = fdt32_to_cpu(del[i + 2]); + deleg->child_index = 0; + + child_found = false; + val = fdt_getprop(fdt, nodeoff, "riscv,children", &len); + if (!val || len < sizeof(fdt32_t)) { + deleg->first_irq = 0; + deleg->last_irq = 0; + deleg->child_index = 0; + continue; + } + len = len / sizeof(fdt32_t); + for (j = 0; j < len; j++) { + if (del[i] != val[j]) + continue; + deleg->child_index = j; + child_found = true; + break; + } + + if (child_found) { + d++; + } else { + deleg->first_irq = 0; + deleg->last_irq = 0; + deleg->child_index = 0; + } + } +skip_delegate_parse: + + return 0; +} + bool fdt_check_imsic_mlevel(void *fdt) { const fdt32_t *val; diff --git a/lib/utils/irqchip/fdt_irqchip.c b/lib/utils/irqchip/fdt_irqchip.c index cf64a2e..6007755 100644 --- a/lib/utils/irqchip/fdt_irqchip.c +++ b/lib/utils/irqchip/fdt_irqchip.c @@ -12,10 +12,12 @@ #include #include +extern struct fdt_irqchip fdt_irqchip_aplic; extern struct fdt_irqchip fdt_irqchip_imsic; extern struct fdt_irqchip fdt_irqchip_plic; static struct fdt_irqchip *irqchip_drivers[] = { + &fdt_irqchip_aplic, &fdt_irqchip_imsic, &fdt_irqchip_plic }; diff --git a/lib/utils/irqchip/fdt_irqchip_aplic.c b/lib/utils/irqchip/fdt_irqchip_aplic.c new file mode 100644 index 0000000..965f023 --- /dev/null +++ b/lib/utils/irqchip/fdt_irqchip_aplic.c @@ -0,0 +1,56 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * Copyright (c) 2022 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include +#include +#include + +#define APLIC_MAX_NR 16 + +static unsigned long aplic_count = 0; +static struct aplic_data aplic[APLIC_MAX_NR]; + +static int irqchip_aplic_warm_init(void) +{ + /* Nothing to do here. */ + return 0; +} + +static int irqchip_aplic_cold_init(void *fdt, int nodeoff, + const struct fdt_match *match) +{ + int rc; + struct aplic_data *pd; + + if (APLIC_MAX_NR <= aplic_count) + return SBI_ENOSPC; + pd = &aplic[aplic_count++]; + + rc = fdt_parse_aplic_node(fdt, nodeoff, pd); + if (rc) + return rc; + + return aplic_cold_irqchip_init(pd); +} + +static const struct fdt_match irqchip_aplic_match[] = { + { .compatible = "riscv,aplic" }, + { }, +}; + +struct fdt_irqchip fdt_irqchip_aplic = { + .match_table = irqchip_aplic_match, + .cold_init = irqchip_aplic_cold_init, + .warm_init = irqchip_aplic_warm_init, + .exit = NULL, +}; diff --git a/lib/utils/irqchip/objects.mk b/lib/utils/irqchip/objects.mk index b2b3f79..fad4344 100644 --- a/lib/utils/irqchip/objects.mk +++ b/lib/utils/irqchip/objects.mk @@ -8,6 +8,7 @@ # libsbiutils-objs-y += irqchip/fdt_irqchip.o +libsbiutils-objs-y += irqchip/fdt_irqchip_aplic.o libsbiutils-objs-y += irqchip/fdt_irqchip_imsic.o libsbiutils-objs-y += irqchip/fdt_irqchip_plic.o libsbiutils-objs-y += irqchip/aplic.o From patchwork Tue Jan 4 10:13:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1575160 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=XjpbyPNu; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=a9mA+MdH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSpP80lqBz9sXM for ; Tue, 4 Jan 2022 21:14:04 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pywnw/WRP35+eZVxP5tESFzkpmkT0sfVg0tpfQPZf/g=; b=XjpbyPNuNtlcch osqtAjyJ9FuIqPIhJbsn50HnvjgYHWw5uKfRDehKufi6KrmgBXNf6prZsEOzYkLToXeskOdwJTUrc hpWMsBvxsfd0iIp27Yf2+Wo5YFaq6ia8/FNmqULy0bMm6nhm2/xaw8/u4LoGgArEPhf2F9Qs1lpk9 ezMFhp0W922LsblOTUHSrg9jZ/I+rV+28mc1ea8p3kx5upVeji99xYjMLdFEvoAjccbHmMkks9ujj Ctn2AYQYcszUoimgV2bMCs5NEgSCIN9I4K3LcG+SjrLFxVBpMElWuVVkSgd7N0y0ZqGf1+sEs6Ala mp3Eo+FoyfzKNoxHlsXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gpH-00B6mm-4T; Tue, 04 Jan 2022 10:13:55 +0000 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4gpE-00B6jZ-6e for opensbi@lists.infradead.org; Tue, 04 Jan 2022 10:13:53 +0000 Received: by mail-oo1-xc2f.google.com with SMTP id c18-20020a4a3812000000b002da81004c1cso11457037ooa.13 for ; Tue, 04 Jan 2022 02:13:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yWT+darl12nq2uUBIYXqMH3RYY1RPQfYYYQU3kYeoGk=; b=a9mA+MdHW9J6Nis3rTeh4hmJLxTZvkf/qzC4612XTUqSMdfVHBuBh8ecCbPAqxqBC4 ttYW/8/yH7o0wIIMDZOr2VRIeJfLIuUeiBQ7byvvPExRoZHFVDQOGuzEdS4OQbYG4xhB A+17wA84/EojybfltXPIzI4/1z+PW7k2iF5n71SxK4nuIFeSWlNaJOFlAdk2/aoL5Xag PJ3TaU1xErG6+o+apDMtmfGyeHr5wrGPz524qKrkeJbuKAZtyNMn+jKKEFXDdb2XK3yO KmJBzeOa85ALQp/DITcXKH57g4Fh764XIotlhx0qhDWJHSfnd27mLy+61gdE952wuf7k L+tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yWT+darl12nq2uUBIYXqMH3RYY1RPQfYYYQU3kYeoGk=; b=FNcn0Ww/AiQZzd5XTw/uix/m7GbnZcqBktzucQ+7FeFVCKlbkJBJB+DwI5gnPfNIxf UYkYK6gn/65HfFb0wtr5KZGQTcSXYROgcsSFXPWgE+MdeONR42uxpZ7IcraUipdNTdrO UMsjyVsGBRIW25yR1MHzndPqUpDBB4dj8AzzeNE41rgDp+8Nf+if9YL75CGR03sIyZRQ fw8Hxl/8IEUz46sPX3KLV3CAV7swzzPu4Vw2jF4aiNv+RhMweCvLqk5nWYq5yDoVl7df AyBWefXi5mqZYMQjIcZEdbttUcTiS0AH6uRVpZkEsPACRNhYEBvLPv82uPH5QDqYVN2u Bwyw== X-Gm-Message-State: AOAM532l/iyW54XyUCXSGPY+xjPhLQrqy7hpwT7c6bkyOyh4aR+Sgi3L XWB8pNdpaliL+r6OLM+xXKMY4jqp03SeJBNVISM= X-Google-Smtp-Source: ABdhPJzoo6/V9jX8BisPQOdsxcnVFNO04UNQ5/cLN6FN2bzh5EPfZjkAPUVj6LNfZglPN502kYyNdA== X-Received: by 2002:a4a:a5cf:: with SMTP id k15mr31288930oom.70.1641291231572; Tue, 04 Jan 2022 02:13:51 -0800 (PST) Received: from localhost.localdomain ([223.182.251.2]) by smtp.gmail.com with ESMTPSA id s196sm8715469oie.7.2022.01.04.02.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 02:13:51 -0800 (PST) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 13/13] lib: utils: Disable appropriate APLIC DT nodes in fdt_fixups() Date: Tue, 4 Jan 2022 15:43:23 +0530 Message-Id: <20220104101323.127564-11-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220104101323.127564-1-apatel@ventanamicro.com> References: <20220104101323.127564-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220104_021352_274626_5C8629FF X-CRM114-Status: GOOD ( 14.81 ) X-Spam-Score: -0.2 (/) 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: We should disable APLIC DT nodes in fdt_fixups() which are not accessible to the next booting stage based on currently assigned domain. Signed-off-by: Anup Patel Signed-off-by: Anup Patel --- include/sbi_utils/fdt/fdt_fixup.h | 18 +++++++++++++++--- lib/utils/fdt/fdt_fixup.c | 11 ++++++++ [...] Content analysis details: (-0.2 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:c2f 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 We should disable APLIC DT nodes in fdt_fixups() which are not accessible to the next booting stage based on currently assigned domain. Signed-off-by: Anup Patel Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi_utils/fdt/fdt_fixup.h | 18 +++++++++++++++--- lib/utils/fdt/fdt_fixup.c | 11 +++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/sbi_utils/fdt/fdt_fixup.h b/include/sbi_utils/fdt/fdt_fixup.h index 77575bb..fb076ba 100644 --- a/include/sbi_utils/fdt/fdt_fixup.h +++ b/include/sbi_utils/fdt/fdt_fixup.h @@ -21,6 +21,18 @@ */ void fdt_cpu_fixup(void *fdt); +/** + * Fix up the APLIC nodes in the device tree + * + * This routine disables APLIC nodes which are not accessible to the next + * booting stage based on currently assigned domain. + * + * It is recommended that platform codes call this helper in their final_init() + * + * @param fdt: device tree blob + */ +void fdt_aplic_fixup(void *fdt); + /** * Fix up the IMSIC nodes in the device tree * @@ -76,9 +88,9 @@ int fdt_reserved_memory_nomap_fixup(void *fdt); * General device tree fix-up * * This routine do all required device tree fix-ups for a typical platform. - * It fixes up the PLIC node, IMSIC nodes, and the reserved memory node in - * the device tree by calling the corresponding helper routines to accomplish - * the task. + * It fixes up the PLIC node, IMSIC nodes, APLIC nodes, and the reserved + * memory node in the device tree by calling the corresponding helper + * routines to accomplish the task. * * It is recommended that platform codes call this helper in their final_init() * diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c index c2460b8..a80bd82 100644 --- a/lib/utils/fdt/fdt_fixup.c +++ b/lib/utils/fdt/fdt_fixup.c @@ -71,6 +71,15 @@ static void fdt_domain_based_fixup_one(void *fdt, int nodeoff) } } +void fdt_aplic_fixup(void *fdt) +{ + int noff = 0; + + while ((noff = fdt_node_offset_by_compatible(fdt, noff, + "riscv,aplic")) >= 0) + fdt_domain_based_fixup_one(fdt, noff); +} + void fdt_imsic_fixup(void *fdt) { int noff = 0; @@ -289,6 +298,8 @@ int fdt_reserved_memory_nomap_fixup(void *fdt) void fdt_fixups(void *fdt) { + fdt_aplic_fixup(fdt); + fdt_imsic_fixup(fdt); fdt_plic_fixup(fdt);