From patchwork Thu Sep 26 13:16:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pope B.Lei" X-Patchwork-Id: 1989831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=YHwMYKeg; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WS2cNIQ5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XDvK71Ybwz1xt6 for ; Thu, 26 Sep 2024 23:17:31 +1000 (AEST) 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=zdDl4MxmUnFmQs4CV01ZprpM8Ujw9zE/j16dUg/oCM8=; b=YHwMYKegrZYzvo lal4SdrxjVazMJBlKI2rT57KNn2DIWeOfgV2OM26aWg2jcXQOdpcRLHzKhi1do1qamavoDm+hR0Za UaTinwrJje7KRW2/IC+gyMsjArCB7iW22z5KlgGRmCZEu689UpxYxqIpqTpP2IUqxLDOmwBJWZkqd KdncnnmmJONkbRXUS8T1k84Ro+LOg3qEPFqqch5NNiNAqO/33vJSub1FZGT+Bi5A0FjgtAe11ctnI p4GzYlAXYaFk4piR6ostlTDklKWDqhFlLbIwRdK68uxjxA4zAGFm6xRRlT47PEgh6InTV65HWEHVN Un/BH5YdPXqgkEj+d8KQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stoN2-00000008RkQ-0GHP; Thu, 26 Sep 2024 13:17:24 +0000 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stoMz-00000008Rij-0Zo6 for opensbi@lists.infradead.org; Thu, 26 Sep 2024 13:17:22 +0000 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-7d4f85766f0so743412a12.2 for ; Thu, 26 Sep 2024 06:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727356639; x=1727961439; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=rOgRWnZ79A9NkHZmQHdg08ci7OlXw1mXxm9QvKsirmI=; b=WS2cNIQ5QtBYDi6rnnUNw0u9W4ukc/7IEq2Preg8PfoC8DihwWKUF9oXKV7Bea6SW8 jKTwCPqUgn/PWp2wC+Qw3R9QOSbahZe0tpZ8QCOB+bYQZTRefi+4q1HhGpDJiHNvNT3P vbC9vhOtc6cxSE2MyMOw2AKKDDS24PzLQvyeVF/+g9TTmrRY5zCJ8JcrAG6ezcYS0Gnr BF9fW8GSWsyO4ho/69oG8qG60JwkMBb2WekZblZ4tUfrxxwZKzG7SErjiCzcG16USDEV uqL1B2MwEXi6nQy0qISfr4jNatgjnIiNJ44pyW1v601XXNeyqo93OCmAVEg6kmZr30Jq xp1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727356639; x=1727961439; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rOgRWnZ79A9NkHZmQHdg08ci7OlXw1mXxm9QvKsirmI=; b=Wjdupf2g73EHkJKS/6uhNMmpfeUK5TiMmpEu566h9ksEa1LETtV8QJZRQ1EpWcBdPQ alFg/a2KVWcvRRhFVq2WOuElyUImqM5E5oBTQAVgReJMeriXgQ5xDVLTvhKebz8XtURX CzeZy40NfGQ1a9oKL14AUQSsaCjZlFZW3ZzsgdgthrOnDsKr4GdAjT0fAbl/zV4jQn4G XvYt525IdYNEb62kIFE6T1X9dkvgJLRrwSlNscW+NBXrQAouUziqWE/UEghMrGou12GV zHNDfJ2T5Visi7f9NBBpfxw10Fo5OKGQmKaOvXcooCpGBWJ+1jUizV9W1Dv84Iw7sw7k EoHQ== X-Gm-Message-State: AOJu0Yyin9ipytI5v4lnau18mIlpsOT7NcVZGnA2XOCIeZ58ZPDf+1Xw yPSygw5OcKPVk3o+Zuu16o2Vc+U+sEpyug5oSJJ/AmmYsnLZ6PjRiRP1wZ80 X-Google-Smtp-Source: AGHT+IEy7Df5Gv9I/iJjrJgvSMzURn8Fb7sPj9wPCJBWl2lxju74yTQxdbr2tHKmarFkGO5H6+VKJA== X-Received: by 2002:a05:6a21:9201:b0:1cc:e43e:3a01 with SMTP id adf61e73a8af0-1d4d4b8601cmr10265485637.33.1727356639303; Thu, 26 Sep 2024 06:17:19 -0700 (PDT) Received: from smtp.qq.com ([110.185.172.244]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71afc92ca2dsm4297156b3a.101.2024.09.26.06.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 06:17:18 -0700 (PDT) From: "Pope B.Lei" To: opensbi@lists.infradead.org Cc: "Pope B.Lei" Subject: [PATCH] Support TOR mode in pmp_set Date: Thu, 26 Sep 2024 21:16:59 +0800 Message-Id: <20240926131659.1477-1-popeblei@gmail.com> X-Mailer: git-send-email 2.35.2.windows.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_061721_199329_3A1990CA X-CRM114-Status: GOOD ( 10.64 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Signed-off-by: Pope B.Lei --- include/sbi/riscv_encoding.h | 2 ++ lib/sbi/riscv_asm.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 980abdb..387c011 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -154,6 +154,8 @@ #define [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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_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 -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 -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [popeblei(at)gmail.com] 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 Signed-off-by: Pope B.Lei --- include/sbi/riscv_encoding.h | 2 ++ lib/sbi/riscv_asm.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 980abdb..387c011 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -154,6 +154,8 @@ #define PMP_A_NAPOT _UL(0x18) #define PMP_L _UL(0x80) +#define PMP_USE_TOR _UL(0x00) + #define PMP_SHIFT 2 #define PMP_COUNT 64 #if __riscv_xlen == 64 diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c index c7d75ac..4518b2c 100644 --- a/lib/sbi/riscv_asm.c +++ b/lib/sbi/riscv_asm.c @@ -309,7 +309,7 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, unsigned long addrmask, pmpaddr; /* check parameters */ - if (n >= PMP_COUNT || log2len > __riscv_xlen || log2len < PMP_SHIFT) + if (n >= PMP_COUNT || log2len > __riscv_xlen || (log2len < PMP_SHIFT && log2len != PMP_USE_TOR )) return SBI_EINVAL; /* calculate PMP register and offset */ @@ -326,13 +326,26 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, /* encode PMP config */ prot &= ~PMP_A; - prot |= (log2len == PMP_SHIFT) ? PMP_A_NA4 : PMP_A_NAPOT; + + switch(log2len){ + case PMP_USE_TOR:{ + prot |= PMP_A_TOR; + break; + } + case PMP_SHIFT:{ + prot |= PMP_A_NA4; + break; + } + default: + prot |= PMP_A_NAPOT; + } + cfgmask = ~(0xffUL << pmpcfg_shift); pmpcfg = (csr_read_num(pmpcfg_csr) & cfgmask); pmpcfg |= ((prot << pmpcfg_shift) & ~cfgmask); /* encode PMP address */ - if (log2len == PMP_SHIFT) { + if (log2len == PMP_SHIFT || log2len == PMP_USE_TOR) { pmpaddr = (addr >> PMP_SHIFT); } else { if (log2len == __riscv_xlen) {