get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.1/patches/2230817/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2230817,
    "url": "http://patchwork.ozlabs.org/api/1.1/patches/2230817/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/opensbi/patch/20260430045528.420437-9-npiggin@gmail.com/",
    "project": {
        "id": 67,
        "url": "http://patchwork.ozlabs.org/api/1.1/projects/67/?format=api",
        "name": "OpenSBI development",
        "link_name": "opensbi",
        "list_id": "opensbi.lists.infradead.org",
        "list_email": "opensbi@lists.infradead.org",
        "web_url": "https://github.com/riscv/opensbi",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20260430045528.420437-9-npiggin@gmail.com>",
    "date": "2026-04-30T04:55:25",
    "name": "[7/7] lib: sbi: Move hart PMP functions to sbi_hart_pmp.c",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "bd5e7552653cdc022aeb1afeedf1fb3b3ad3cb31",
    "submitter": {
        "id": 69518,
        "url": "http://patchwork.ozlabs.org/api/1.1/people/69518/?format=api",
        "name": "Nicholas Piggin",
        "email": "npiggin@gmail.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/opensbi/patch/20260430045528.420437-9-npiggin@gmail.com/mbox/",
    "series": [
        {
            "id": 502193,
            "url": "http://patchwork.ozlabs.org/api/1.1/series/502193/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/opensbi/list/?series=502193",
            "date": "2026-04-30T04:55:18",
            "name": "Make PMP encoding usable for non-hart PMPs",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/502193/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2230817/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2230817/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "\n <opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=renor2CM;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256\n header.s=desiato.20200630 header.b=bkUzbbvv;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=lNihaMrk;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"
        ],
        "Received": [
            "from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g5hhp5DSHz1yGq\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 30 Apr 2026 14:56:26 +1000 (AEST)",
            "from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wIJRl-00000004gIt-3Gp0;\n\tThu, 30 Apr 2026 04:56:21 +0000",
            "from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wIJRl-00000004gIR-0Sqh\n\tfor opensbi@bombadil.infradead.org;\n\tThu, 30 Apr 2026 04:56:21 +0000",
            "from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f])\n\tby desiato.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wIJRi-00000006deE-0619\n\tfor opensbi@lists.infradead.org;\n\tThu, 30 Apr 2026 04:56:19 +0000",
            "by mail-pl1-x62f.google.com with SMTP id\n d9443c01a7336-2b458ca2296so3212105ad.0\n        for <opensbi@lists.infradead.org>;\n Wed, 29 Apr 2026 21:56:17 -0700 (PDT)",
            "from localhost ([124.158.97.178])\n        by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b98893f0b7sm42259725ad.40.2026.04.29.21.56.13\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Wed, 29 Apr 2026 21:56:14 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:\n\tMessage-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=aACMbQZhbF0UB7gRnYxKVkNOlyZHIG5h17nFxZJAsuc=; b=renor2CMz4Nf0L\n\tFy4NMyc886IW1JgR9KQxP0dX+32ZlDDYw8+j1CafwUXJ77FliDDio0uE8W1ujTcHR9SZphEU+qfWy\n\txbhKNTZc8dtpY/+oyx5Dke9GJxqpBUcXoTnK6M/yHM0QU6YpMmBkOgmCh/Fd+N8Q3324IXvJmkBXw\n\t/w+/InbNNNGRXHolbqfZiIILqfMn1TcLJJoenzmSMg4/vTbLvIRWFHslGe8uEM6u+4E8GiaL7ve2T\n\tdIvegtPGJmPC1cWZjnNWOk0u1gFXa2bHzV2sbUmwEag77cwkFT4DdZpkYNxkzbK65SnyfvZoGylzc\n\td1wJ4kgtMuH4jcw2S9bw==;",
            "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version\n\t:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:\n\tContent-Type:Content-ID:Content-Description;\n\tbh=LkDous2/iMCynyzTMJFz68Dw24FI8Z3E+U3aZWla2As=; b=bkUzbbvvUah2EQnGvBkwSmHLbV\n\th9JkjjEQQnVawbf8zuLPZPDE/Ep505ug4OtW1mQh46IVMvsugv3tiP+Kj8VxY/ontNPyOxpLqsK24\n\tjhgJtQORYjzV3HQEngTnbjmiLFzZtEpTVw8xKOWxSkCc0cvL+CP7+QGxezkTkEfjWFob8SunHRumb\n\tcNf7vCKxhMiEUgwl9cP8/9HBGyKKcd/dc19ZtYvm6kWefPanlfWMYXX1637/BcPMYzjeS23Kb0D5H\n\tIsHKYX+dWjVza6hfOSY1bp0QsnbCJA/qYLPzv4ECEbH+0/lFCdt7Tu8BrXd/5b8C0hpBDYcbWe9R2\n\tyb5RaAxQ==;",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777524975; x=1778129775;\n darn=lists.infradead.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=LkDous2/iMCynyzTMJFz68Dw24FI8Z3E+U3aZWla2As=;\n        b=lNihaMrk2v1rhBrSWfOSAzL6jB+7QFXSdVek4qjqEJNXZfVk89yWBrOWMJ+HUktd0G\n         ScZDbNTmqf0/Aczz09QNjvc/iaB0dnOFsoHBjOXok0fvrGh/SCqgt/YqvD3G2QUWN0bf\n         4TQ/Cmabe9JZH6JuR8eyVmoqKYN8Q3Gl0vi90n4z3QMiTJ+M9GHVl0BaX8feTXfOo5Uv\n         Nmj15URvjSqibRDNobzsKCCyPW+ckYkyaH6aUkdinFcoVnCcKkHikBr2xpJYIdeLl+KS\n         1FVbTic/Tz04rfhMMyN+oYyR4YmObbIUmLslne0b+bxa6pjnUMx2ZzP4ZderJ5UITFSS\n         I9Xg=="
        ],
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777524975; x=1778129775;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=LkDous2/iMCynyzTMJFz68Dw24FI8Z3E+U3aZWla2As=;\n        b=S4kgbFLUPstBM0jg8Y93BG9QKFRw8hLsps+TyrznFE6vmQ0xnAL48+roE6YwAXA1Uw\n         HF1nSSvwKrKa/f6w2vehWUW/R953vW6KW10rUW3Hm4Cp+p/R5rCVyv4XWf4OAL3dwYV9\n         3zV0ZxUvjfERsfMQXXg+eOhGsKMB+vFrik/qPMhV/siExFZu87Rj2QqRy6571QMtm/GB\n         x6EZbWDA8lOzXFiAkrEQ4Hk99zP79KKufIVSDBa0JxwTbdrTTDoFn7AT8Tw8senaFw0P\n         QvsHOg2lYXMePFvYwwx5NGTm9NxJ0Y4KzgcWuG6KblOm9L9n22IRDVLdGvGxBdiuiAxg\n         l5CA==",
        "X-Gm-Message-State": "AOJu0YytbYXYqh3rOEZ7DN5opwmvghjXmMmEapBN+9LykWb0PDT/pPhs\n\tXu6K5Cr6bVlnz2VwebNDgduoIFLrJ0/l744491mMJVAe76OpwEZXjVW7fXqW3Q==",
        "X-Gm-Gg": "AeBDiet25QninFVMAS2Np5Go39c1Ie6mq/CEegWUT8ZK+yaQnyC7vBi/k9aXNM8rHdF\n\tBuFD2BM5jT50AmgkEyYja25e/hczD+U0Po2pTFHU7pvQVW6sU1WxqhZdoSlGR3SbbKzOlhbnWOB\n\tFhI/THdXfZ99+miabfBsaZPO+bG2r5h0r0+M19k+yaUgJDHcv0cfP3UM9aArt0AJST3gqPzgEx/\n\tSn6ezI9hamvc4bLW0r2rCvHVGIvpxr9wqELh9iMJtJwv4GuAadRCbhbwRtf5N5ISJFK5KB17tjh\n\tbuG0Ih74IkdfmklElBfzfOiNfWKj9P9R5yI1cdAWcAGoEGKO3LYcLcmug1eekj4zv9Tua1bYy94\n\tT8QeZrlIPLkB6r65Q5SKFUyz390SvHVlfPG8E8F+uVdl5E01MQK1CZ1F864Fk3DXXi7bCF+Y5gL\n\tA3cDGEqDBi3GKZy9eyWvL8FIt0zEPH4aR/GtZpnDAAfFA=",
        "X-Received": "by 2002:a17:902:ef10:b0:2b9:4941:7f6e with SMTP id\n d9443c01a7336-2b9a2319b9cmr13498535ad.2.1777524975003;\n        Wed, 29 Apr 2026 21:56:15 -0700 (PDT)",
        "From": "Nicholas Piggin <npiggin@gmail.com>",
        "To": "opensbi@lists.infradead.org",
        "Cc": "Nicholas Piggin <npiggin@gmail.com>",
        "Subject": "[PATCH 7/7] lib: sbi: Move hart PMP functions to sbi_hart_pmp.c",
        "Date": "Thu, 30 Apr 2026 14:55:25 +1000",
        "Message-ID": "<20260430045528.420437-9-npiggin@gmail.com>",
        "X-Mailer": "git-send-email 2.53.0",
        "In-Reply-To": "<20260430045528.420437-1-npiggin@gmail.com>",
        "References": "<20260430045528.420437-1-npiggin@gmail.com>",
        "MIME-Version": "1.0",
        "X-CRM114-Version": "20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ",
        "X-CRM114-CacheID": "sfid-20260430_055618_412770_A169EEE6 ",
        "X-CRM114-Status": "GOOD (  14.77  )",
        "X-Spam-Score": "-0.2 (/)",
        "X-Spam-Report": "Spam detection software,\n running on the system \"desiato.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  The sbi_hart_pmp.c looks like a good place for the hart PMP\n    CSR access functions. Signed-off-by: Nicholas Piggin ---\n include/sbi/riscv_asm.h\n    | 14 ----- include/sbi/sbi_hart_pmp.h | 12 ++++ lib/sbi/riscv_asm.c | 109\n    lib/sbi/sbi_hart_pmp.c | 110 [...]\n Content analysis details:   (-0.2 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.0 SPF_PASS               SPF: sender matches SPF record\n -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/, no\n                             trust\n                             [2607:f8b0:4864:20:0:0:0:62f listed in]\n                             [list.dnswl.org]\n  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record\n -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from\n author's\n                             domain\n  0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n not necessarily valid\n -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from\n                             envelope-from domain\n -0.1 DKIM_VALID             Message has at least one valid DKIM or DK\n signature\n  0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail\n provider\n                             [npiggin(at)gmail.com]",
        "X-BeenThere": "opensbi@lists.infradead.org",
        "X-Mailman-Version": "2.1.34",
        "Precedence": "list",
        "List-Id": "<opensbi.lists.infradead.org>",
        "List-Unsubscribe": "<http://lists.infradead.org/mailman/options/opensbi>,\n <mailto:opensbi-request@lists.infradead.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.infradead.org/pipermail/opensbi/>",
        "List-Post": "<mailto:opensbi@lists.infradead.org>",
        "List-Help": "<mailto:opensbi-request@lists.infradead.org?subject=help>",
        "List-Subscribe": "<http://lists.infradead.org/mailman/listinfo/opensbi>,\n <mailto:opensbi-request@lists.infradead.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Sender": "\"opensbi\" <opensbi-bounces@lists.infradead.org>",
        "Errors-To": "opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"
    },
    "content": "The sbi_hart_pmp.c looks like a good place for the hart PMP CSR\naccess functions.\n\nSigned-off-by: Nicholas Piggin <npiggin@gmail.com>\n---\n include/sbi/riscv_asm.h    |  14 -----\n include/sbi/sbi_hart_pmp.h |  12 ++++\n lib/sbi/riscv_asm.c        | 109 ------------------------------------\n lib/sbi/sbi_hart_pmp.c     | 110 +++++++++++++++++++++++++++++++++++++\n 4 files changed, 122 insertions(+), 123 deletions(-)",
    "diff": "diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h\nindex f845320b..7765edb7 100644\n--- a/include/sbi/riscv_asm.h\n+++ b/include/sbi/riscv_asm.h\n@@ -81,8 +81,6 @@\n \n #ifndef __ASSEMBLER__\n \n-#include <sbi/sbi_types.h>\n-\n #define csr_swap(csr, val)                                              \\\n \t({                                                              \\\n \t\tregister unsigned long __v = (unsigned long)(val);      \\\n@@ -211,18 +209,6 @@ int misa_xlen(void);\n /* Get RISC-V ISA string representation */\n void misa_string(int xlen, char *out, unsigned int out_sz);\n \n-/* Disable pmp entry at a given index */\n-int hart_pmp_disable(unsigned int n);\n-\n-/* Check if the matching field is set */\n-bool hart_is_pmp_enabled(unsigned int n);\n-\n-int hart_pmp_set(unsigned int n, unsigned long prot, unsigned long addr,\n-\t    unsigned long log2len);\n-\n-int hart_pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,\n-\t    unsigned long *log2len);\n-\n #endif /* !__ASSEMBLER__ */\n \n #endif\ndiff --git a/include/sbi/sbi_hart_pmp.h b/include/sbi/sbi_hart_pmp.h\nindex a7765d17..3e0219ac 100644\n--- a/include/sbi/sbi_hart_pmp.h\n+++ b/include/sbi/sbi_hart_pmp.h\n@@ -9,6 +9,18 @@\n \n #include <sbi/sbi_types.h>\n \n+/* Disable pmp entry at a given index */\n+int hart_pmp_disable(unsigned int n);\n+\n+/* Check if the matching field is set */\n+bool hart_is_pmp_enabled(unsigned int n);\n+\n+int hart_pmp_set(unsigned int n, unsigned long prot,\n+\t\t unsigned long addr, unsigned long log2len);\n+\n+int hart_pmp_get(unsigned int n, unsigned long *prot_out,\n+\t\t unsigned long *addr_out, unsigned long *log2len);\n+\n struct sbi_scratch;\n \n unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch);\ndiff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c\nindex 98a93462..a1e0f2f8 100644\n--- a/lib/sbi/riscv_asm.c\n+++ b/lib/sbi/riscv_asm.c\n@@ -272,112 +272,3 @@ void csr_write_num(int csr_num, unsigned long val)\n #undef switchcase_csr_write_2\n #undef switchcase_csr_write\n }\n-\n-static int hart_pmp_read(pmp_t *pmp, unsigned int n)\n-{\n-\tint pmpcfg_csr, pmpcfg_shift, pmpaddr_csr;\n-\tunsigned long cfgmask;\n-\n-\t/* check parameters */\n-\tif (n >= PMP_COUNT)\n-\t\treturn SBI_EINVAL;\n-\n-\t/* calculate PMP register and offset */\n-#if __riscv_xlen == 32\n-\tpmpcfg_csr   = CSR_PMPCFG0 + (n >> 2);\n-\tpmpcfg_shift = (n & 3) << 3;\n-#elif __riscv_xlen == 64\n-\tpmpcfg_csr   = (CSR_PMPCFG0 + (n >> 2)) & ~1;\n-\tpmpcfg_shift = (n & 7) << 3;\n-#else\n-# error \"Unexpected __riscv_xlen\"\n-#endif\n-\tpmpaddr_csr = CSR_PMPADDR0 + n;\n-\n-\tcfgmask = (0xffUL << pmpcfg_shift);\n-\tpmp->cfg = (csr_read_num(pmpcfg_csr) & cfgmask) >> pmpcfg_shift;\n-\tpmp->addr = csr_read_num(pmpaddr_csr);\n-\n-\treturn SBI_OK;\n-}\n-\n-static int hart_pmp_write(pmp_t *pmp, unsigned int n)\n-{\n-\tint pmpcfg_csr, pmpcfg_shift, pmpaddr_csr;\n-\tunsigned long cfgmask, pmpcfg;\n-\n-\t/* check parameters */\n-\tif (n >= PMP_COUNT)\n-\t\treturn SBI_EINVAL;\n-\n-\t/* calculate PMP register and offset */\n-#if __riscv_xlen == 32\n-\tpmpcfg_csr   = CSR_PMPCFG0 + (n >> 2);\n-\tpmpcfg_shift = (n & 3) << 3;\n-#elif __riscv_xlen == 64\n-\tpmpcfg_csr   = (CSR_PMPCFG0 + (n >> 2)) & ~1;\n-\tpmpcfg_shift = (n & 7) << 3;\n-#else\n-# error \"Unexpected __riscv_xlen\"\n-#endif\n-\tpmpaddr_csr = CSR_PMPADDR0 + n;\n-\n-\t/* write csrs */\n-\tcsr_write_num(pmpaddr_csr, pmp->addr);\n-\tcfgmask = ~(0xffUL << pmpcfg_shift);\n-\tpmpcfg  = (csr_read_num(pmpcfg_csr) & cfgmask);\n-\tpmpcfg |= (((unsigned long)pmp->cfg << pmpcfg_shift) & ~cfgmask);\n-\tcsr_write_num(pmpcfg_csr, pmpcfg);\n-\n-\treturn SBI_OK;\n-}\n-\n-int hart_pmp_disable(unsigned int n)\n-{\n-\tpmp_t pmp;\n-\tint rc;\n-\n-\trc = hart_pmp_read(&pmp, n);\n-\tif (rc)\n-\t\treturn rc;\n-\n-\tpmp.cfg = 0;\n-\n-\treturn hart_pmp_write(&pmp, n);\n-}\n-\n-bool hart_is_pmp_enabled(unsigned int n)\n-{\n-\tpmp_t pmp;\n-\n-\tif (hart_pmp_read(&pmp, n) != SBI_OK)\n-\t\treturn false;\n-\n-\treturn pmp_is_enabled(&pmp);\n-}\n-\n-int hart_pmp_set(unsigned int n, unsigned long prot, unsigned long addr,\n-\t    unsigned long log2len)\n-{\n-\tpmp_t pmp;\n-\tint rc;\n-\n-\trc = pmp_encode(&pmp, prot, addr, log2len);\n-\tif (rc)\n-\t\treturn rc;\n-\n-\treturn hart_pmp_write(&pmp, n);\n-}\n-\n-int hart_pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,\n-\t    unsigned long *log2len)\n-{\n-\tpmp_t pmp;\n-\tint rc;\n-\n-\trc = hart_pmp_read(&pmp, n);\n-\tif (rc)\n-\t\treturn rc;\n-\n-\treturn pmp_decode(&pmp, prot_out, addr_out, log2len);\n-}\ndiff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c\nindex 8b7b091c..54cfd0cb 100644\n--- a/lib/sbi/sbi_hart_pmp.c\n+++ b/lib/sbi/sbi_hart_pmp.c\n@@ -12,9 +12,119 @@\n #include <sbi/sbi_hfence.h>\n #include <sbi/sbi_math.h>\n #include <sbi/sbi_platform.h>\n+#include <sbi/sbi_pmp.h>\n #include <sbi/sbi_tlb.h>\n #include <sbi/riscv_asm.h>\n \n+static int hart_pmp_read(pmp_t *pmp, unsigned int n)\n+{\n+\tint pmpcfg_csr, pmpcfg_shift, pmpaddr_csr;\n+\tunsigned long cfgmask;\n+\n+\t/* check parameters */\n+\tif (n >= PMP_COUNT)\n+\t\treturn SBI_EINVAL;\n+\n+\t/* calculate PMP register and offset */\n+#if __riscv_xlen == 32\n+\tpmpcfg_csr   = CSR_PMPCFG0 + (n >> 2);\n+\tpmpcfg_shift = (n & 3) << 3;\n+#elif __riscv_xlen == 64\n+\tpmpcfg_csr   = (CSR_PMPCFG0 + (n >> 2)) & ~1;\n+\tpmpcfg_shift = (n & 7) << 3;\n+#else\n+# error \"Unexpected __riscv_xlen\"\n+#endif\n+\tpmpaddr_csr = CSR_PMPADDR0 + n;\n+\n+\tcfgmask = (0xffUL << pmpcfg_shift);\n+\tpmp->cfg = (csr_read_num(pmpcfg_csr) & cfgmask) >> pmpcfg_shift;\n+\tpmp->addr = csr_read_num(pmpaddr_csr);\n+\n+\treturn SBI_OK;\n+}\n+\n+static int hart_pmp_write(pmp_t *pmp, unsigned int n)\n+{\n+\tint pmpcfg_csr, pmpcfg_shift, pmpaddr_csr;\n+\tunsigned long cfgmask, pmpcfg;\n+\n+\t/* check parameters */\n+\tif (n >= PMP_COUNT)\n+\t\treturn SBI_EINVAL;\n+\n+\t/* calculate PMP register and offset */\n+#if __riscv_xlen == 32\n+\tpmpcfg_csr   = CSR_PMPCFG0 + (n >> 2);\n+\tpmpcfg_shift = (n & 3) << 3;\n+#elif __riscv_xlen == 64\n+\tpmpcfg_csr   = (CSR_PMPCFG0 + (n >> 2)) & ~1;\n+\tpmpcfg_shift = (n & 7) << 3;\n+#else\n+# error \"Unexpected __riscv_xlen\"\n+#endif\n+\tpmpaddr_csr = CSR_PMPADDR0 + n;\n+\n+\t/* write csrs */\n+\tcsr_write_num(pmpaddr_csr, pmp->addr);\n+\tcfgmask = ~(0xffUL << pmpcfg_shift);\n+\tpmpcfg  = (csr_read_num(pmpcfg_csr) & cfgmask);\n+\tpmpcfg |= (((unsigned long)pmp->cfg << pmpcfg_shift) & ~cfgmask);\n+\tcsr_write_num(pmpcfg_csr, pmpcfg);\n+\n+\treturn SBI_OK;\n+}\n+\n+int hart_pmp_disable(unsigned int n)\n+{\n+\tpmp_t pmp;\n+\tint rc;\n+\n+\trc = hart_pmp_read(&pmp, n);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\tpmp.cfg = 0;\n+\n+\treturn hart_pmp_write(&pmp, n);\n+}\n+\n+bool hart_is_pmp_enabled(unsigned int n)\n+{\n+\tpmp_t pmp;\n+\n+\tif (hart_pmp_read(&pmp, n) != SBI_OK)\n+\t\treturn false;\n+\n+\treturn pmp_is_enabled(&pmp);\n+}\n+\n+int hart_pmp_set(unsigned int n, unsigned long prot, unsigned long addr,\n+\t    unsigned long log2len)\n+{\n+\tpmp_t pmp;\n+\tint rc;\n+\n+\trc = pmp_encode(&pmp, prot, addr, log2len);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\treturn hart_pmp_write(&pmp, n);\n+}\n+\n+int hart_pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,\n+\t    unsigned long *log2len)\n+{\n+\tpmp_t pmp;\n+\tint rc;\n+\n+\trc = hart_pmp_read(&pmp, n);\n+\tif (rc)\n+\t\treturn rc;\n+\n+\treturn pmp_decode(&pmp, prot_out, addr_out, log2len);\n+}\n+\n /*\n  * Smepmp enforces access boundaries between M-mode and\n  * S/U-mode. When it is enabled, the PMPs are programmed\n",
    "prefixes": [
        "7/7"
    ]
}