From patchwork Tue Apr 25 12:32:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1773378 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=qMLA7nnp; 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=c0v+p5tB; 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 4Q5Lxq2YqKz23s0 for ; Tue, 25 Apr 2023 22:33:03 +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=qWiGcGiiPLrhN6d2ggdiTwMbGatrhJnbd5vkk3ebIYo=; b=qMLA7nnpNFPVeD b+LTGmcWAkyRnXZzvFP107B2KfL7QLbq67Pok89F9BwhhsTD8wzaqx+TXInSSaY0zoaj91xudW1Zr hyI/Iim4eF31rGVYvLojbRm7L/F7AEHrDAzhLhX+FBWldyzb8r9oryPyr/IZe5lA5EbCzqRTDlmRB FDG3q8c6fpeXhEmAeh0ctARaBZQ4EEd4U3n8ByIfPaZE+ywiOnU8ARPVkSxny0saRI2eU7WNBmyNL D7YMAZqTDe61XbpjsZs6rNpjDM2Z2o8PgoyjKuH+rGCQFvLRU6Vr6HuptDTQN+a9gigjp9m9EBJyE I8e96qdSl6rNqQcvcSWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1prHqj-0015IJ-2Y; Tue, 25 Apr 2023 12:32:49 +0000 Received: from mail-oo1-xc2e.google.com ([2607:f8b0:4864:20::c2e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1prHqg-0015FX-14 for opensbi@lists.infradead.org; Tue, 25 Apr 2023 12:32:48 +0000 Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-5475e0147c9so1491868eaf.1 for ; Tue, 25 Apr 2023 05:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682425963; x=1685017963; 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=bUDUUK64WNvyga/uGQozaODPJLPWybUGcvSAoUVN/nM=; b=c0v+p5tBy267tKX+GAGZd33AyOcaaHqzqoqT73cwZPqlPfVZuZlwejyLn9SJfUuj1L tHwi0eA+yfIC/80sc8k0yA+urDoP57CNXHEGby+Ev6gLwvET9dMfDZDDWD3t0vcIrjOY jLzz9/cHDbsKbzmz2aEaBIEgdOpidL+1OjeL9xwcbe6E2tMlF41HLkmGi5LZ5wUWoqJj w0WsNQVZyNEPImbUygycnndqWkkm6GhBbAVuxVOviKOoRZTl1hBJ6uySp59NCIOurk4H n8xFg0Mk5uOuw3hpAQe6v7naEiN+lb4NVVkyI7SVGoxs0H741ekEC0s/YXDM2T/fBZC6 7Ahw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682425963; x=1685017963; 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=bUDUUK64WNvyga/uGQozaODPJLPWybUGcvSAoUVN/nM=; b=b9gf9gNpoHoMFpWWFNJDChh/WUxI4S5vwYBZY2aM0mbeaCMIRGsPRzPJMleiSfGlIk CvqfVRYxUbnTfxlE9Zdn6pq9RK5bxEufERkijVxk8CCiFRYcXXFuT0RKC+j3Mr1D+qad A8MIMNIcVa9XlD+6CJa5qg6QP7v+r2T9KiXRWeJvQmiKgxkvIXGmN6QduPMQtGLyvIW9 uLTbg2n9dT+PKSSPA1Y37KkzkVGvoAgxthInw8U6TbZf4NPSLq+E9KYNcd8a9a5+nXRZ oF7Feb23prqnx8L/AkDrY5wvGHGC90c2H3jo+1FV4Qups6TglpR8MYb2tI/TXLfa8so7 +uBQ== X-Gm-Message-State: AAQBX9fyseEp0Gqn98xbr4z8gsJKCES++eHV0yH7wjMuoBNxw3F02Rsk +Zb8gVWlr+dLutfWw+BRl/FKtA== X-Google-Smtp-Source: AKy350YHgft+eSxwN1BA1xjaPM5JrZKgmCl8nuWr1cbhTkPTWOys71kdMbTb+cdDDAU5ssLsvFGaaQ== X-Received: by 2002:aca:bad7:0:b0:38e:62ee:ee96 with SMTP id k206-20020acabad7000000b0038e62eeee96mr7688707oif.58.1682425963238; Tue, 25 Apr 2023 05:32:43 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.165.210]) by smtp.gmail.com with ESMTPSA id s132-20020acaa98a000000b0038de3f4e375sm5511001oie.23.2023.04.25.05.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Apr 2023 05:32:43 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 01/17] platform: Allow platforms to specify heap size Date: Tue, 25 Apr 2023 18:02:14 +0530 Message-Id: <20230425123230.3943447-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230425123230.3943447-1-apatel@ventanamicro.com> References: <20230425123230.3943447-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230425_053246_379036_C73FCC3A X-CRM114-Status: GOOD ( 15.22 ) 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 struct sbi_platform and struct sbi_scratch to allow platforms specify the heap size to the OpenSBI firmwares. The OpenSBI firmwares will use this information to determine the location of hea [...] 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:c2e 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 struct sbi_platform and struct sbi_scratch to allow platforms specify the heap size to the OpenSBI firmwares. The OpenSBI firmwares will use this information to determine the location of heap and provide heap base address in per-HART scratch space. Signed-off-by: Anup Patel Reviewed-by: Andrew Jones --- firmware/fw_base.S | 15 +++++++++++++++ include/sbi/sbi_platform.h | 18 +++++++++++++++--- include/sbi/sbi_scratch.h | 28 ++++++++++++++++++---------- platform/fpga/ariane/platform.c | 1 + platform/fpga/openpiton/platform.c | 2 ++ platform/generic/platform.c | 3 ++- platform/kendryte/k210/platform.c | 2 ++ platform/nuclei/ux600/platform.c | 2 ++ platform/template/platform.c | 1 + 9 files changed, 58 insertions(+), 14 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index e37df09..fff09e1 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -255,20 +255,28 @@ _bss_zero: /* Preload HART details * s7 -> HART Count * s8 -> HART Stack Size + * s9 -> Heap Size + * s10 -> Heap Offset */ lla a4, platform #if __riscv_xlen > 32 lwu s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4) lwu s8, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(a4) + lwu s9, SBI_PLATFORM_HEAP_SIZE_OFFSET(a4) #else lw s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4) lw s8, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(a4) + lw s9, SBI_PLATFORM_HEAP_SIZE_OFFSET(a4) #endif /* Setup scratch space for all the HARTs*/ lla tp, _fw_end mul a5, s7, s8 add tp, tp, a5 + /* Setup heap base address */ + lla s10, _fw_start + sub s10, tp, s10 + add tp, tp, s9 /* Keep a copy of tp */ add t3, tp, zero /* Counter */ @@ -283,8 +291,11 @@ _scratch_init: * t3 -> the firmware end address * s7 -> HART count * s8 -> HART stack size + * s9 -> Heap Size + * s10 -> Heap Offset */ add tp, t3, zero + sub tp, tp, s9 mul a5, s8, t1 sub tp, tp, a5 li a5, SBI_SCRATCH_SIZE @@ -302,6 +313,10 @@ _scratch_init: REG_L a5, 0(a4) REG_S a5, SBI_SCRATCH_FW_RW_OFFSET(tp) + /* Store fw_heap_offset and fw_heap_size in scratch space */ + REG_S s10, SBI_SCRATCH_FW_HEAP_OFFSET(tp) + REG_S s9, SBI_SCRATCH_FW_HEAP_SIZE_OFFSET(tp) + /* Store next arg1 in scratch space */ MOV_3R s0, a0, s1, a1, s2, a2 call fw_next_arg1 diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 546c0a6..3e9616f 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -29,12 +29,16 @@ #define SBI_PLATFORM_HART_COUNT_OFFSET (0x50) /** Offset of hart_stack_size in struct sbi_platform */ #define SBI_PLATFORM_HART_STACK_SIZE_OFFSET (0x54) +/** Offset of heap_size in struct sbi_platform */ +#define SBI_PLATFORM_HEAP_SIZE_OFFSET (0x58) +/** Offset of reserved in struct sbi_platform */ +#define SBI_PLATFORM_RESERVED_OFFSET (0x5c) /** Offset of platform_ops_addr in struct sbi_platform */ -#define SBI_PLATFORM_OPS_OFFSET (0x58) +#define SBI_PLATFORM_OPS_OFFSET (0x60) /** Offset of firmware_context in struct sbi_platform */ -#define SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET (0x58 + __SIZEOF_POINTER__) +#define SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET (0x60 + __SIZEOF_POINTER__) /** Offset of hart_index2id in struct sbi_platform */ -#define SBI_PLATFORM_HART_INDEX2ID_OFFSET (0x58 + (__SIZEOF_POINTER__ * 2)) +#define SBI_PLATFORM_HART_INDEX2ID_OFFSET (0x60 + (__SIZEOF_POINTER__ * 2)) #define SBI_PLATFORM_TLB_RANGE_FLUSH_LIMIT_DEFAULT (1UL << 12) @@ -138,6 +142,10 @@ struct sbi_platform_operations { /** Platform default per-HART stack size for exception/interrupt handling */ #define SBI_PLATFORM_DEFAULT_HART_STACK_SIZE 8192 +/** Platform default heap size */ +#define SBI_PLATFORM_DEFAULT_HEAP_SIZE(__num_hart) \ + (0x8000 + 0x800 * (__num_hart)) + /** Representation of a platform */ struct sbi_platform { /** @@ -160,6 +168,10 @@ struct sbi_platform { u32 hart_count; /** Per-HART stack size for exception/interrupt handling */ u32 hart_stack_size; + /** Size of heap shared by all HARTs */ + u32 heap_size; + /** Reserved for future use */ + u32 reserved; /** Pointer to sbi platform operations */ unsigned long platform_ops_addr; /** Pointer to system firmware specific context */ diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index 2966188..2376995 100644 --- a/include/sbi/sbi_scratch.h +++ b/include/sbi/sbi_scratch.h @@ -20,26 +20,30 @@ #define SBI_SCRATCH_FW_SIZE_OFFSET (1 * __SIZEOF_POINTER__) /** Offset (in sbi_scratch) of the R/W Offset */ #define SBI_SCRATCH_FW_RW_OFFSET (2 * __SIZEOF_POINTER__) +/** Offset of fw_heap_offset member in sbi_scratch */ +#define SBI_SCRATCH_FW_HEAP_OFFSET (3 * __SIZEOF_POINTER__) +/** Offset of fw_heap_size_offset member in sbi_scratch */ +#define SBI_SCRATCH_FW_HEAP_SIZE_OFFSET (4 * __SIZEOF_POINTER__) /** Offset of next_arg1 member in sbi_scratch */ -#define SBI_SCRATCH_NEXT_ARG1_OFFSET (3 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_NEXT_ARG1_OFFSET (5 * __SIZEOF_POINTER__) /** Offset of next_addr member in sbi_scratch */ -#define SBI_SCRATCH_NEXT_ADDR_OFFSET (4 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_NEXT_ADDR_OFFSET (6 * __SIZEOF_POINTER__) /** Offset of next_mode member in sbi_scratch */ -#define SBI_SCRATCH_NEXT_MODE_OFFSET (5 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_NEXT_MODE_OFFSET (7 * __SIZEOF_POINTER__) /** Offset of warmboot_addr member in sbi_scratch */ -#define SBI_SCRATCH_WARMBOOT_ADDR_OFFSET (6 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_WARMBOOT_ADDR_OFFSET (8 * __SIZEOF_POINTER__) /** Offset of platform_addr member in sbi_scratch */ -#define SBI_SCRATCH_PLATFORM_ADDR_OFFSET (7 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_PLATFORM_ADDR_OFFSET (9 * __SIZEOF_POINTER__) /** Offset of hartid_to_scratch member in sbi_scratch */ -#define SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET (8 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET (10 * __SIZEOF_POINTER__) /** Offset of trap_exit member in sbi_scratch */ -#define SBI_SCRATCH_TRAP_EXIT_OFFSET (9 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_TRAP_EXIT_OFFSET (11 * __SIZEOF_POINTER__) /** Offset of tmp0 member in sbi_scratch */ -#define SBI_SCRATCH_TMP0_OFFSET (10 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_TMP0_OFFSET (12 * __SIZEOF_POINTER__) /** Offset of options member in sbi_scratch */ -#define SBI_SCRATCH_OPTIONS_OFFSET (11 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_OPTIONS_OFFSET (13 * __SIZEOF_POINTER__) /** Offset of extra space in sbi_scratch */ -#define SBI_SCRATCH_EXTRA_SPACE_OFFSET (12 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_EXTRA_SPACE_OFFSET (14 * __SIZEOF_POINTER__) /** Maximum size of sbi_scratch (4KB) */ #define SBI_SCRATCH_SIZE (0x1000) @@ -57,6 +61,10 @@ struct sbi_scratch { unsigned long fw_size; /** Offset (in bytes) of the R/W section */ unsigned long fw_rw_offset; + /** Offset (in bytes) of the heap area */ + unsigned long fw_heap_offset; + /** Size (in bytes) of the heap area */ + unsigned long fw_heap_size; /** Arg1 (or 'a1' register) of next booting stage for this HART */ unsigned long next_arg1; /** Address of next booting stage for this HART */ diff --git a/platform/fpga/ariane/platform.c b/platform/fpga/ariane/platform.c index 1e341c2..975528f 100644 --- a/platform/fpga/ariane/platform.c +++ b/platform/fpga/ariane/platform.c @@ -185,5 +185,6 @@ const struct sbi_platform platform = { .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = ARIANE_HART_COUNT, .hart_stack_size = SBI_PLATFORM_DEFAULT_HART_STACK_SIZE, + .heap_size = SBI_PLATFORM_DEFAULT_HEAP_SIZE(ARIANE_HART_COUNT), .platform_ops_addr = (unsigned long)&platform_ops }; diff --git a/platform/fpga/openpiton/platform.c b/platform/fpga/openpiton/platform.c index 57ae698..e59dc99 100644 --- a/platform/fpga/openpiton/platform.c +++ b/platform/fpga/openpiton/platform.c @@ -220,5 +220,7 @@ const struct sbi_platform platform = { .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = OPENPITON_DEFAULT_HART_COUNT, .hart_stack_size = SBI_PLATFORM_DEFAULT_HART_STACK_SIZE, + .heap_size = + SBI_PLATFORM_DEFAULT_HEAP_SIZE(OPENPITON_DEFAULT_HART_COUNT), .platform_ops_addr = (unsigned long)&platform_ops }; diff --git a/platform/generic/platform.c b/platform/generic/platform.c index eeefef4..0c9cd95 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -115,7 +115,7 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1, } platform.hart_count = hart_count; - + platform.heap_size = SBI_PLATFORM_DEFAULT_HEAP_SIZE(hart_count); platform_has_mlevel_imsic = fdt_check_imsic_mlevel(fdt); /* Return original FDT pointer */ @@ -315,5 +315,6 @@ struct sbi_platform platform = { .hart_count = SBI_HARTMASK_MAX_BITS, .hart_index2id = generic_hart_index2id, .hart_stack_size = SBI_PLATFORM_DEFAULT_HART_STACK_SIZE, + .heap_size = SBI_PLATFORM_DEFAULT_HEAP_SIZE(0), .platform_ops_addr = (unsigned long)&platform_ops }; diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 7eb9015..637a217 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -196,5 +196,7 @@ const struct sbi_platform platform = { .features = 0, .hart_count = K210_HART_COUNT, .hart_stack_size = SBI_PLATFORM_DEFAULT_HART_STACK_SIZE, + .heap_size = + SBI_PLATFORM_DEFAULT_HEAP_SIZE(K210_HART_COUNT), .platform_ops_addr = (unsigned long)&platform_ops }; diff --git a/platform/nuclei/ux600/platform.c b/platform/nuclei/ux600/platform.c index 4eccff1..6fd6cd7 100644 --- a/platform/nuclei/ux600/platform.c +++ b/platform/nuclei/ux600/platform.c @@ -244,5 +244,7 @@ const struct sbi_platform platform = { .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = UX600_HART_COUNT, .hart_stack_size = SBI_PLATFORM_DEFAULT_HART_STACK_SIZE, + .heap_size = + SBI_PLATFORM_DEFAULT_HEAP_SIZE(UX600_HART_COUNT), .platform_ops_addr = (unsigned long)&platform_ops }; diff --git a/platform/template/platform.c b/platform/template/platform.c index 8adc431..86381ca 100644 --- a/platform/template/platform.c +++ b/platform/template/platform.c @@ -152,5 +152,6 @@ const struct sbi_platform platform = { .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = 1, .hart_stack_size = SBI_PLATFORM_DEFAULT_HART_STACK_SIZE, + .heap_size = SBI_PLATFORM_DEFAULT_HEAP_SIZE(1), .platform_ops_addr = (unsigned long)&platform_ops };