From patchwork Thu Jul 6 10:49:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himanshu Chauhan X-Patchwork-Id: 1804282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=RTMcq95n; 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=Rhh1lyqz; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QxYFw02Xwz20c5 for ; Thu, 6 Jul 2023 20:50:11 +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: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=kocHjpnNYkGcgLiH/DS4KnUFKnkObg/iAvTYsvx9JRM=; b=RTMcq95npJv0Gx gbVBb7SSfnSwNkHMjNllSJImd7ihWQZgK9gn+o4H0Z7x76cxFPDPY9xWDS3tONCotlqbQd7y/kAdR LGFVVFoJ9DuQ4Imx0zXiXGP3d0g/vidYAup7ivCQqaKhm8wqlHQgF9W6UGlC449kRe+rarGk9hI5J ueUh1VVC+6D1Kwjwk6HCSUB4xfsnY8cBQHO+Zh1CONxkqAVyshODYR5sh5popuxlNcSugYRdOGHf1 H7ei9YKxAT9MICw1hl8z48ySOTu/+XP/vefZ1WNOmmT+C0Zbim7uxo5i08QaTTLNTHCGDsF3PARkg d/4Ze43bTYXFjb37GN7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHMYX-001Ghb-0p; Thu, 06 Jul 2023 10:49:49 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qHMYT-001Gdk-1t for opensbi@lists.infradead.org; Thu, 06 Jul 2023 10:49:47 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-263315da33cso141933a91.0 for ; Thu, 06 Jul 2023 03:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1688640585; x=1691232585; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+HcxmJSroGdSS4K7FIOlab0DXMvs8k0uHXMU41GV/RI=; b=Rhh1lyqzMdweSs9i5nP0V2tbae9yhKLhL6NM3QpS7TBH4xm/JMhIB0k5AIGhBRHa+r 7sDJ8EUy0z4CBwtRCkwQGp8TABhMMe4zgQ55/4j9KB57TRRKFhHyES57T52g8JqwWae6 RNm9frulkSlEfNRLhEYrwuZQlvEU8JwJjfA35VHqTZDytOKIyvHXUHbjldi3bdmolT+S +95azSOv3d4DnohnYk7jrDx1fS/mmqhzq8E0Ug94ckXU4CAcWomR4IbBMPpc8dfGPmRn cUkGFzFMld48Ub3Riku/Xc9vqsetKAnoPURmu6YdHFtZCZy6dtI6k3/ZBanxF2cP89tx daTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688640585; x=1691232585; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+HcxmJSroGdSS4K7FIOlab0DXMvs8k0uHXMU41GV/RI=; b=Og1/BrNnqGpd6dZZvfB6ofdHNGpIsToBG03LJlattmn+Cac/l2Y5XoQJWjoRDKOuGn 6b1vYCtjuk9JrsokbHddKpp8viAZ3FkuqGuWXWMmKYjfy6X6a9Ke4oUvm9R1/MOJGG5L FJFmpLcVsR2DRQUxDSOE5KbC82H9lEHHF6Vfjo3n/YpJE00Sn6bUqpeOn0wXlO7KYiVF W/R34SW5WPIrtvoi9DtaR01NHD52hB40Ld1Xc2ARjSNZ6B4K39WB6BLLEotqUKD90H5r 1OHGzKTliiAUCD7wHIgdqw14/YyhJhC69aMBTwNHGiY321vOHAJKeJYTet2qArH0BYhg +0DQ== X-Gm-Message-State: ABy/qLYfowslZih5KlBr7Ov1CwTH4aDkuj7Pm67YSajWei1jyqRQRyiI jPXc0nePeql1/nH3eQ2HR0MoUfxAI/bg+2W9nt7f9c1C X-Google-Smtp-Source: APBJJlHamARyUJGRHvG6K4MsQNdGG9roPHRvkPVa9paW8pgXtIz4WXnsXlYt2iFVcYGzUIpXk+kbSA== X-Received: by 2002:a17:90a:fb49:b0:263:a5b5:c538 with SMTP id iq9-20020a17090afb4900b00263a5b5c538mr1376178pjb.4.1688640584679; Thu, 06 Jul 2023 03:49:44 -0700 (PDT) Received: from saptrishi.. ([2405:201:d019:cbd3:9126:16c2:7e:c7e5]) by smtp.gmail.com with ESMTPSA id gn20-20020a17090ac79400b002635341a7e8sm3670746pjb.3.2023.07.06.03.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 03:49:44 -0700 (PDT) From: Himanshu Chauhan To: opensbi@lists.infradead.org Cc: Himanshu Chauhan Subject: [PATCH v2 5/8] lib: utils: Add detection of Smepmp from ISA string in FDT Date: Thu, 6 Jul 2023 16:19:25 +0530 Message-Id: <20230706104928.3391947-6-hchauhan@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230706104928.3391947-1-hchauhan@ventanamicro.com> References: <20230620143212.2701598-1-hchauhan@ventanamicro.com> <20230706104928.3391947-1-hchauhan@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230706_034945_625178_62B8F92C X-CRM114-Status: GOOD ( 16.23 ) 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: - Add function to parse ISA string in FDT. - Set Smepmp feature bit in extensions if "smepmp" string is found in ISA string. Signed-off-by: Himanshu Chauhan --- include/sbi_utils/fdt/fdt_helper.h | 3 + lib/utils/fdt/fdt_helper.c | 111 +++++++++++++++++++++++++++++ platform/generic/platform.c | 9 [...] 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:102c 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 - Add function to parse ISA string in FDT. - Set Smepmp feature bit in extensions if "smepmp" string is found in ISA string. Signed-off-by: Himanshu Chauhan Reviewed-by: Anup Patel --- include/sbi_utils/fdt/fdt_helper.h | 3 + lib/utils/fdt/fdt_helper.c | 111 +++++++++++++++++++++++++++++ platform/generic/platform.c | 9 +++ 3 files changed, 123 insertions(+) diff --git a/include/sbi_utils/fdt/fdt_helper.h b/include/sbi_utils/fdt/fdt_helper.h index 39d7f3a..5c928ff 100644 --- a/include/sbi_utils/fdt/fdt_helper.h +++ b/include/sbi_utils/fdt/fdt_helper.h @@ -56,6 +56,9 @@ int fdt_parse_max_enabled_hart_id(void *fdt, u32 *max_hartid); int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq); +int fdt_parse_isa_extensions(void *fdt, unsigned int hard_id, + unsigned long *extensions); + int fdt_parse_gaisler_uart_node(void *fdt, int nodeoffset, struct platform_uart_data *uart); diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c index a88a4ba..61a4100 100644 --- a/lib/utils/fdt/fdt_helper.c +++ b/lib/utils/fdt/fdt_helper.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -313,6 +314,116 @@ int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq) return 0; } +static int fdt_get_isa_string(void *fdt, unsigned int hartid, + const char **isa_string) +{ + int err, cpu_offset, cpus_offset, len; + u32 c_hartid; + const fdt32_t *val; + + if (!fdt) + return SBI_EINVAL; + + cpus_offset = fdt_path_offset(fdt, "/cpus"); + if (cpus_offset < 0) + return cpus_offset; + + fdt_for_each_subnode(cpu_offset, fdt, cpus_offset) { + err = fdt_parse_hart_id(fdt, cpu_offset, &c_hartid); + if (err) + continue; + + if (!fdt_node_is_enabled(fdt, cpu_offset)) + continue; + + if (c_hartid == hartid) { + val = fdt_getprop(fdt, cpu_offset, "riscv,isa", &len); + if (val && len > 0) { + *isa_string = (const char *)val; + return 0; + } + } + } + + return SBI_EINVAL; +} + +#define RISCV_ISA_EXT_NAME_LEN_MAX 32 + +int fdt_parse_isa_extensions(void *fdt, unsigned int hartid, + unsigned long *extensions) +{ + size_t i, j, isa_len; + char mstr[RISCV_ISA_EXT_NAME_LEN_MAX]; + const char *isa = NULL; + + if (fdt_get_isa_string(fdt, hartid, &isa)) + return SBI_EINVAL; + + if (!isa) + return SBI_EINVAL; + + i = 0; + isa_len = strlen(isa); + + if (isa[i] == 'r' || isa[i] == 'R') + i++; + else + return SBI_EINVAL; + + if (isa[i] == 'v' || isa[i] == 'V') + i++; + else + return SBI_EINVAL; + + if (isa[i] == '3' || isa[i+1] == '2') + i += 2; + else if (isa[i] == '6' || isa[i+1] == '4') + i += 2; + else + return SBI_EINVAL; + + /* Skip base ISA extensions */ + for (; i < isa_len; i++) { + if (isa[i] == '_') + break; + } + + while (i < isa_len) { + if (isa[i] != '_') { + i++; + continue; + } + + /* Skip the '_' character */ + i++; + + /* Extract the multi-letter extension name */ + j = 0; + while ((i < isa_len) && (isa[i] != '_') && + (j < (sizeof(mstr) - 1))) + mstr[j++] = isa[i++]; + mstr[j] = '\0'; + + /* Skip empty multi-letter extension name */ + if (!j) + continue; + +#define SET_ISA_EXT_MAP(name, bit) \ + do { \ + if (!strcmp(mstr, name)) { \ + __set_bit(bit, extensions); \ + continue; \ + } \ + } while (false) \ + + SET_ISA_EXT_MAP("smepmp", SBI_HART_EXT_SMEPMP); +#undef SET_ISA_EXT_MAP + } + + return 0; +} + static int fdt_parse_uart_node_common(void *fdt, int nodeoffset, struct platform_uart_data *uart, unsigned long default_freq, diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 86811e6..34b87f7 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -211,6 +211,15 @@ static void generic_final_exit(void) static int generic_extensions_init(struct sbi_hart_features *hfeatures) { + int rc; + + /* Parse the ISA string from FDT and enable the listed extensions */ + rc = fdt_parse_isa_extensions(fdt_get_address(), current_hartid(), + &hfeatures->extensions); + + if (rc) + return rc; + if (generic_plat && generic_plat->extensions_init) return generic_plat->extensions_init(generic_plat_match, hfeatures);