From patchwork Fri Jul 5 07:14:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1957137 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=vGyiipLE; 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=DsMb3N4x; 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 4WFlCf6vqqz1xr0 for ; Fri, 5 Jul 2024 17:15:26 +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=//5Xdijd4S1KVe4jWeFqbIB/sIdUgjxa0lPlbJ+Teco=; b=vGyiipLEKuD3zJ yK5KmEJ3uSpdRy5ouxZShSFE6dq/8ZhpcSHE2zKYv60mXfRe1fmxv4eIU65P3cFpKqrM3XohV6Zuz LrMmGDfX8DSTbNVycVu91DU5rKapUy+i/hb2J/JpwZB8OY01f+lK+32gC9f36V4LjbWlJ2Jb+o6/l +274OKYAMjaycbj+jQmWMDZDVHRL/FRclHYeFp6IB/vvPTwwcRyTHOqAmPQkWRWoPDJ6erQJGxJaO Tll9eyPiK1zsPBbMjPg4B2EyYUdUFr2evwA/FN7xjIGQsWx8lvcdUtt2+I6I9UjPU0xpGGwWNbS3n kOYC4DoHmPGTB4kSVPmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdA6-0000000F7zO-2NEL; Fri, 05 Jul 2024 07:15:18 +0000 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdA3-0000000F7y5-2td7 for opensbi@lists.infradead.org; Fri, 05 Jul 2024 07:15:17 +0000 Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-3815eaa136eso5630315ab.0 for ; Fri, 05 Jul 2024 00:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1720163713; x=1720768513; darn=lists.infradead.org; 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=vVwBKq3MnwSxY0FSucTSRJ4UjeXzBR+4AhmepmJLRAg=; b=DsMb3N4xIKePtoxIQNO8qsBbi3aKZO+HBZg+ZWGliKn4Df+9bnCqg2MvBT9FfBf+EA +Rrlj4bmz6PwYG+cny2ovgH5vNKIl8BsUTmqQQrX0s03NLeXmwII1Ojov1BUDaA80hqQ P8yWyo1sZtuUFwbgZ0oOSebBiJSS8sVmtY+mGtyEUIKKmJlmTzm/ceUYpQH/nec9MZGF HV5w9GqTSvZJtx4ht3MGp8Yv5fZbd21zWLl5mzZJHi9FMEYKnDgnInatTFahiDM15vYf QIrbTDbgMaX0HeoQp6lYmIE3nezuYKDx2lpxLkRuVbTRhmGLfGj9X7sWRhk5IqvqAji4 fE1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720163713; x=1720768513; 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=vVwBKq3MnwSxY0FSucTSRJ4UjeXzBR+4AhmepmJLRAg=; b=VWBbWtgwuRy5IS4Y5NXZri8gn+ycMEswREvcNLLiggBcMvDFzGIrSTIPrzNxHf9JG0 oJARfFO3oXZ9hgtAsFdb5fbZkharrlVCzhtjghu0Y+DlMIfyyl2yZXtsrJb2O5pYFjSK AsoNgz43St8KIb7+yY4iTsfNLNX1jUjYVrI1LlhjpGRy5OlbbV/7doYtB/ZIKoO3Qq2b kxnbBp9Co2Yqg75WrERemLf6VeDleRUN/WlImasP95CMNrofyTBb2LvwET/9TFFvuiAm Sa1N0POQlEVwJyZqCyr5phfcW0BBM4YKjzEnuw60133afY9dS1M3OiQBPghmkLR18dmh S0DA== X-Forwarded-Encrypted: i=1; AJvYcCU9w2WZeORlkbBaktRUoc35eQkdXnoKPmsS6xkbS7PUFGoSJV1qxdrY/XHHaO0Ak/Iwi2SkppyoNNu5+XO2dHo5v8gAavliNkG4eaA= X-Gm-Message-State: AOJu0Yztai38+PMN6u/EAY30Uu7vIuU3FVdrcytHCNKVOlQUnOQ/76Ts k9BpGdNzXcFWKAqFkrM6RRHenOpu/U4/bEMTw6GfzxRwWuQHAwBaMX4jwgNkqoA= X-Google-Smtp-Source: AGHT+IEePs4Tb7pFe4ctlQGgmrcTrMFxDnqkII7wrIN+4o6JTiNjY6USXeeMiDWWigQJidzCMTREVA== X-Received: by 2002:a92:ca4a:0:b0:381:fa54:fb33 with SMTP id e9e14a558f8ab-38399874d75mr41197125ab.17.1720163713376; Fri, 05 Jul 2024 00:15:13 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.133.57]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-75e51aaf3f2sm2262658a12.15.2024.07.05.00.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 00:15:12 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 1/6] platform: Setup serial console device in early_init() Date: Fri, 5 Jul 2024 12:44:59 +0530 Message-Id: <20240705071504.50988-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240705071504.50988-1-apatel@ventanamicro.com> References: <20240705071504.50988-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240705_001515_773341_BB24604A X-CRM114-Status: GOOD ( 15.66 ) 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 sbi_console_init() does not do any special initialization so setup serial console device in early_init() so that console prints work as early as possible. Signed-off-by: Anup Patel --- platform/fpga/ariane/platform.c | 26 +++++++++ platform/fpga/openpiton/platform.c | 20 ++++ platform/generic/pl [...] 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:12d listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 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 sbi_console_init() does not do any special initialization so setup serial console device in early_init() so that console prints work as early as possible. Signed-off-by: Anup Patel Reviewed-By: Himanshu Chauhan --- platform/fpga/ariane/platform.c | 26 +++++++++----------------- platform/fpga/openpiton/platform.c | 20 ++++---------------- platform/generic/platform.c | 21 +++++++++++---------- platform/kendryte/k210/platform.c | 18 ++++++------------ platform/nuclei/ux600/platform.c | 18 +++++++----------- platform/template/platform.c | 18 ++++++------------ 6 files changed, 43 insertions(+), 78 deletions(-) diff --git a/platform/fpga/ariane/platform.c b/platform/fpga/ariane/platform.c index 8be5e6c..8d46d88 100644 --- a/platform/fpga/ariane/platform.c +++ b/platform/fpga/ariane/platform.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -67,8 +66,15 @@ static struct aclint_mtimer_data mtimer = { */ static int ariane_early_init(bool cold_boot) { - /* For now nothing to do. */ - return 0; + if (!cold_boot) + return 0; + + return uart8250_init(ARIANE_UART_ADDR, + ARIANE_UART_FREQ, + ARIANE_UART_BAUDRATE, + ARIANE_UART_REG_SHIFT, + ARIANE_UART_REG_WIDTH, + ARIANE_UART_REG_OFFSET); } /* @@ -87,19 +93,6 @@ static int ariane_final_init(bool cold_boot) return 0; } -/* - * Initialize the ariane console. - */ -static int ariane_console_init(void) -{ - return uart8250_init(ARIANE_UART_ADDR, - ARIANE_UART_FREQ, - ARIANE_UART_BAUDRATE, - ARIANE_UART_REG_SHIFT, - ARIANE_UART_REG_WIDTH, - ARIANE_UART_REG_OFFSET); -} - static int plic_ariane_warm_irqchip_init(int m_cntx_id, int s_cntx_id) { int ret; @@ -175,7 +168,6 @@ static int ariane_timer_init(bool cold_boot) const struct sbi_platform_operations platform_ops = { .early_init = ariane_early_init, .final_init = ariane_final_init, - .console_init = ariane_console_init, .irqchip_init = ariane_irqchip_init, .ipi_init = ariane_ipi_init, .timer_init = ariane_timer_init, diff --git a/platform/fpga/openpiton/platform.c b/platform/fpga/openpiton/platform.c index 2317a89..dd74a0c 100644 --- a/platform/fpga/openpiton/platform.c +++ b/platform/fpga/openpiton/platform.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -103,7 +102,10 @@ static int openpiton_early_init(bool cold_boot) ACLINT_DEFAULT_MTIMECMP_OFFSET; } - return 0; + return uart8250_init(uart.addr, uart.freq, uart.baud, + OPENPITON_DEFAULT_UART_REG_SHIFT, + OPENPITON_DEFAULT_UART_REG_WIDTH, + OPENPITON_DEFAULT_UART_REG_OFFSET); } /* @@ -122,19 +124,6 @@ static int openpiton_final_init(bool cold_boot) return 0; } -/* - * Initialize the openpiton console. - */ -static int openpiton_console_init(void) -{ - return uart8250_init(uart.addr, - uart.freq, - uart.baud, - OPENPITON_DEFAULT_UART_REG_SHIFT, - OPENPITON_DEFAULT_UART_REG_WIDTH, - OPENPITON_DEFAULT_UART_REG_OFFSET); -} - static int plic_openpiton_warm_irqchip_init(int m_cntx_id, int s_cntx_id) { int ret; @@ -210,7 +199,6 @@ static int openpiton_timer_init(bool cold_boot) const struct sbi_platform_operations platform_ops = { .early_init = openpiton_early_init, .final_init = openpiton_final_init, - .console_init = openpiton_console_init, .irqchip_init = openpiton_irqchip_init, .ipi_init = openpiton_ipi_init, .timer_init = openpiton_timer_init, diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 1f46b76..3470474 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -221,9 +221,19 @@ static int generic_nascent_init(void) static int generic_early_init(bool cold_boot) { - if (cold_boot) + int rc; + + if (cold_boot) { fdt_reset_init(); + if (semihosting_enabled()) + rc = semihosting_init(); + else + rc = fdt_serial_init(); + if (rc) + return rc; + } + if (!generic_plat || !generic_plat->early_init) return 0; @@ -378,14 +388,6 @@ static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx, return evt_val; } -static int generic_console_init(void) -{ - if (semihosting_enabled()) - return semihosting_init(); - else - return fdt_serial_init(); -} - const struct sbi_platform_operations platform_ops = { .cold_boot_allowed = generic_cold_boot_allowed, .nascent_init = generic_nascent_init, @@ -395,7 +397,6 @@ const struct sbi_platform_operations platform_ops = { .final_exit = generic_final_exit, .extensions_init = generic_extensions_init, .domains_init = generic_domains_init, - .console_init = generic_console_init, .irqchip_init = fdt_irqchip_init, .irqchip_exit = fdt_irqchip_exit, .ipi_init = fdt_ipi_init, diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 27b23f7..531adcd 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -109,10 +108,13 @@ static struct sbi_system_reset_device k210_reset = { static int k210_early_init(bool cold_boot) { - if (cold_boot) - sbi_system_reset_add_device(&k210_reset); + if (!cold_boot) + return 0; - return 0; + sbi_system_reset_add_device(&k210_reset); + + return sifive_uart_init(K210_UART_BASE_ADDR, k210_get_clk_freq(), + K210_UART_BAUDRATE); } static int k210_final_init(bool cold_boot) @@ -130,12 +132,6 @@ static int k210_final_init(bool cold_boot) return 0; } -static int k210_console_init(void) -{ - return sifive_uart_init(K210_UART_BASE_ADDR, k210_get_clk_freq(), - K210_UART_BAUDRATE); -} - static int k210_irqchip_init(bool cold_boot) { int rc; @@ -181,8 +177,6 @@ const struct sbi_platform_operations platform_ops = { .final_init = k210_final_init, - .console_init = k210_console_init, - .irqchip_init = k210_irqchip_init, .ipi_init = k210_ipi_init, diff --git a/platform/nuclei/ux600/platform.c b/platform/nuclei/ux600/platform.c index f688b50..2289366 100644 --- a/platform/nuclei/ux600/platform.c +++ b/platform/nuclei/ux600/platform.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -150,8 +149,10 @@ static int ux600_early_init(bool cold_boot) { u32 regval; - if (cold_boot) - sbi_system_reset_add_device(&ux600_reset); + if (!cold_boot) + return 0; + + sbi_system_reset_add_device(&ux600_reset); /* Measure CPU Frequency using Timer */ ux600_clk_freq = ux600_get_clk_freq(); @@ -163,7 +164,9 @@ static int ux600_early_init(bool cold_boot) regval = readl((void *)(UX600_GPIO_ADDR + UX600_GPIO_IOF_EN_OFS)) | UX600_GPIO_IOF_UART0_MASK; writel(regval, (void *)(UX600_GPIO_ADDR + UX600_GPIO_IOF_EN_OFS)); - return 0; + + return sifive_uart_init(UX600_DEBUG_UART, ux600_clk_freq, + UX600_UART_BAUDRATE); } static void ux600_modify_dt(void *fdt) @@ -184,12 +187,6 @@ static int ux600_final_init(bool cold_boot) return 0; } -static int ux600_console_init(void) -{ - return sifive_uart_init(UX600_DEBUG_UART, ux600_clk_freq, - UX600_UART_BAUDRATE); -} - static int ux600_irqchip_init(bool cold_boot) { int rc; @@ -234,7 +231,6 @@ static int ux600_timer_init(bool cold_boot) const struct sbi_platform_operations platform_ops = { .early_init = ux600_early_init, .final_init = ux600_final_init, - .console_init = ux600_console_init, .irqchip_init = ux600_irqchip_init, .ipi_init = ux600_ipi_init, .timer_init = ux600_timer_init, diff --git a/platform/template/platform.c b/platform/template/platform.c index 4b3f2ac..b4d30a5 100644 --- a/platform/template/platform.c +++ b/platform/template/platform.c @@ -64,7 +64,12 @@ static struct aclint_mtimer_data mtimer = { */ static int platform_early_init(bool cold_boot) { - return 0; + if (!cold_boot) + return 0; + + /* Example if the generic UART8250 driver is used */ + return uart8250_init(PLATFORM_UART_ADDR, PLATFORM_UART_INPUT_FREQ, + PLATFORM_UART_BAUDRATE, 0, 1, 0); } /* @@ -75,16 +80,6 @@ static int platform_final_init(bool cold_boot) return 0; } -/* - * Initialize the platform console. - */ -static int platform_console_init(void) -{ - /* Example if the generic UART8250 driver is used */ - return uart8250_init(PLATFORM_UART_ADDR, PLATFORM_UART_INPUT_FREQ, - PLATFORM_UART_BAUDRATE, 0, 1, 0); -} - /* * Initialize the platform interrupt controller for current HART. */ @@ -143,7 +138,6 @@ static int platform_timer_init(bool cold_boot) const struct sbi_platform_operations platform_ops = { .early_init = platform_early_init, .final_init = platform_final_init, - .console_init = platform_console_init, .irqchip_init = platform_irqchip_init, .ipi_init = platform_ipi_init, .timer_init = platform_timer_init From patchwork Fri Jul 5 07:15:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1957136 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=crgu/EiJ; 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=e2Nr961L; 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 4WFlCf57jTz1xpP for ; Fri, 5 Jul 2024 17:15:26 +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=wNzaOIoe8eL3p1lq+iXTh7mWnDyOm/wTG1ykvOerEIw=; b=crgu/EiJxjqEJl IZUNZ7aPEK/plrBjQVa5zFwY7EgEqrPUoACcH/yq8xm0mGvMnDSjK5WJHtsBXwUD+INqQWvus8E3C fzUre8pmVRhoeZYOH4SheMGpCVvDZ9kWJl9PG5YXwqJs8tPeqY5S76LG3MXvxuwKOjLHKBSfr+TpD kK1w9CZFBG7OENt0lz+CChUELPB3G89FfjA1CZKKT5DOKYoOSwQ+slOi91X9kUYDxPafOfc+utt4e zMZROTj972N+7whP8wDkEHi905S4hHKccWAAGjtVPbmjav4v97FKRsyVVVRW2g77ng4oB+J5F64Ma XWLDPHzO941O2SF9P8+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdA8-0000000F80Q-1p81; Fri, 05 Jul 2024 07:15:20 +0000 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdA5-0000000F7yt-0xZW for opensbi@lists.infradead.org; Fri, 05 Jul 2024 07:15:18 +0000 Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-5c2284616f7so748035eaf.1 for ; Fri, 05 Jul 2024 00:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1720163716; x=1720768516; darn=lists.infradead.org; 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=IP+/VfT2u5rQikDZCOqH7APd6Am3O86O90TlMtL4ZFg=; b=e2Nr961LRDWGggcEAfyTRoCFOtM+3TllPe1h80D/mPAYguE4BYCrcl40kX9yvlvAOQ pOE41VH/l7irSpP6ITT1GjRybUhf571v2r1JYW5L8E3/ukKTZZr8vLJvhCwV3dnuiP2E zdPyMNqk0myLiOfdfB7GjBoo8mvuBEu1SCVomxGb4yct59KSMFtE5KaemjBGQq/BqEBJ C+p4HlPne2t7fP/BBQ+THsjCYUhmOUw07Sxq+wrNq0EQhj6UwJYuim/kzcuJYptdLoq5 3JJQal8VGUQYYRfz2B/h0OMkRavKjr5svy4zS0bLnpfo+xYyDg1QeTz8dFhqMFXHVoMQ DyQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720163716; x=1720768516; 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=IP+/VfT2u5rQikDZCOqH7APd6Am3O86O90TlMtL4ZFg=; b=Y6JLcKZ2WK4S1HKvGkIu1rN21Ozo6PV99I0OOSkgV547NHBCCD71/UqxI/4QGSeaFC eVUdmyA7pBPNZjtxaeWOrvrGrP2LXz+scrEZMxdE7nV9NaToQD2y+Eii/AsnaGvhzKiD dgwHAKCiGl9elwf59XAyNQBiIOByNebwgy3WWOUvxTA9NK8aWfJcwSfFwpagJ6u5fEM1 olWQbVMRqA1exEoE515SaGagsR7t2Z6EU68xDfjL5Dinns37TprssqhtfAD7RXMXddY4 pxVzWkI+zCl4/kg4SGDwqETxLNQK9Bf1e/5pvn3y0IOXa62aloc12GR0xSgIGa62K+AX myrw== X-Forwarded-Encrypted: i=1; AJvYcCVPVNJWOy0vVYQBfXawTwonuEHUBytOj/wlgEvDqT7Jj2ZfSYzijQIqOi4kVxit6iNHI0aorNnxZvkkUKedWiXa8lTQ08lxD3sEssY= X-Gm-Message-State: AOJu0Yy0l0nWpfmu7Ou4DismWEWhbFAA5I7dKjuZfmIK/rpiYhEKiZRF Icw74WPqASBt6tcduxvstKI0zE5JJEifHVL3p/aYk26YFzyS4TOnyqnDsxartNM= X-Google-Smtp-Source: AGHT+IFLCPr3cMn3sx7rrxQx1SdFAn4UhKIkUXhPYxTkiTcABL9Jdg9oQS9MccVO0WmC+ZzzEymf+w== X-Received: by 2002:a05:6358:9386:b0:1a2:5c3b:cf86 with SMTP id e5c5f4694b2df-1aa98c81984mr283718355d.31.1720163715849; Fri, 05 Jul 2024 00:15:15 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.133.57]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-75e51aaf3f2sm2262658a12.15.2024.07.05.00.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 00:15:15 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 2/6] lib: sbi: Remove sbi_console_init() and console_init() platform callback Date: Fri, 5 Jul 2024 12:45:00 +0530 Message-Id: <20240705071504.50988-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240705071504.50988-1-apatel@ventanamicro.com> References: <20240705071504.50988-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240705_001517_294351_542B9D12 X-CRM114-Status: GOOD ( 12.48 ) 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: Now that all platforms have been updated to initialize serial console device in early_init(), the sbi_console_init() and console_init() platform callback are redundant hence remove them. Signed-off-by: Anup Patel --- include/sbi/sbi_console.h | 2 -- include/sbi/sbi_platform.h | 17 lib/sbi/sbi_console.c | 11 lib/sbi/sbi_init.c | 4 [...] 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_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 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 Now that all platforms have been updated to initialize serial console device in early_init(), the sbi_console_init() and console_init() platform callback are redundant hence remove them. Signed-off-by: Anup Patel Reviewed-By: Himanshu Chauhan --- include/sbi/sbi_console.h | 2 -- include/sbi/sbi_platform.h | 17 ----------------- lib/sbi/sbi_console.c | 11 ----------- lib/sbi/sbi_init.c | 4 ---- 4 files changed, 34 deletions(-) diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h index 0979765..3097db1 100644 --- a/include/sbi/sbi_console.h +++ b/include/sbi/sbi_console.h @@ -58,8 +58,6 @@ void sbi_console_set_device(const struct sbi_console_device *dev); struct sbi_scratch; -int sbi_console_init(struct sbi_scratch *scratch); - #define SBI_ASSERT(cond, args) do { \ if (unlikely(!(cond))) \ sbi_panic args; \ diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 581935a..7b3ac4b 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -111,9 +111,6 @@ struct sbi_platform_operations { /** Get platform specific mhpmevent value */ uint64_t (*pmu_xlate_to_mhpmevent)(uint32_t event_idx, uint64_t data); - /** Initialize the platform console */ - int (*console_init)(void); - /** Initialize the platform interrupt controller for current HART */ int (*irqchip_init)(bool cold_boot); /** Exit the platform interrupt controller for current HART */ @@ -549,20 +546,6 @@ static inline uint64_t sbi_platform_pmu_xlate_to_mhpmevent(const struct sbi_plat return 0; } -/** - * Initialize the platform console - * - * @param plat pointer to struct sbi_platform - * - * @return 0 on success and negative error code on failure - */ -static inline int sbi_platform_console_init(const struct sbi_platform *plat) -{ - if (plat && sbi_platform_ops(plat)->console_init) - return sbi_platform_ops(plat)->console_init(); - return 0; -} - /** * Initialize the platform interrupt controller for current HART * diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index d3ec461..194529d 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -477,14 +477,3 @@ void sbi_console_set_device(const struct sbi_console_device *dev) console_dev = dev; } - -int sbi_console_init(struct sbi_scratch *scratch) -{ - int rc = sbi_platform_console_init(sbi_platform_ptr(scratch)); - - /* console is not a necessary device */ - if (rc == SBI_ENODEV) - return 0; - - return rc; -} diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 0f9e14c..d80efe9 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -261,10 +261,6 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) if (rc) sbi_hart_hang(); - rc = sbi_console_init(scratch); - if (rc) - sbi_hart_hang(); - rc = sbi_sse_init(scratch, true); if (rc) { sbi_printf("%s: sse init failed (error %d)\n", __func__, rc); From patchwork Fri Jul 5 07:15:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1957138 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=hNp6HzpU; 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=ele+Rt0r; 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 4WFlCh34cRz1xpP for ; Fri, 5 Jul 2024 17:15:28 +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=zQIblk/OPjdAtvr3P3ha7An/DiRNxGRAUzYgj/czcfo=; b=hNp6HzpU8kgeqp JzD2bO+hFnLUDoYEWTIU3zr8WIigVjaqT/41zQVJlmLpwB2fHNdoy7j8bjneFU+p/Fyj3wAJGPmrJ EDxXF2a06+rgV1dRWcg85Y/49LC3BMoeZR75Hu71EvWSTYzKh6z6fK18xCG57RB7mWKSKaacZE+cb Yk8sAah//M9JCA7d6RaK8IQkUf8cHB8qyDuxAqPk8fV5Y9AHk3jTKGqT5PdaGQGTjhg4x72/kLLFl E5/6siVppKGqIXg6haG5EUOYBHRvw3ZIn5o6sKW0df/wlRyCrnLZEIoyqkuNlj5c7jP9nQsF0zmUy KfYqRdNkvofIsvgdfBdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdAA-0000000F81R-0EYv; Fri, 05 Jul 2024 07:15:22 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdA7-0000000F7zo-2EVL for opensbi@lists.infradead.org; Fri, 05 Jul 2024 07:15:20 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-70b07bdbfbcso537798b3a.0 for ; Fri, 05 Jul 2024 00:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1720163718; x=1720768518; darn=lists.infradead.org; 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=n0qXM7rcZ0FLoMAZcHAoGZKUEAWaxYXTxtvoo7TbKwE=; b=ele+Rt0rVTTbqArBTbrCEmIEgbg9lOggozeFQQ5iXm6EmR/5FNr+B8gzWM2Xa0/yUR tLi6tRfAWPzUeWulJ2I90BKA981HpbxO7Wh1KyFHISr6ZCEwAP6YlqDIROditJgRedAn ZC6UagIgGbryx24NSyjCGduHwSHcr3KAKT87wzPefvqCUMVY0z7/c2b4X2P3mknptRt5 yRSzhcM24VSR5llTNGgz66U7JXy2a7tgIkS0gl0yZd9W61iHVGN6sn42aq3TPPAqZKmF NMkVsGhdH0hJtDYPp44gpju9pZ0c1XHty1shtZmmawGTd8vBXOrQRdFdGsOZ2aZQ7DQb 5IWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720163718; x=1720768518; 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=n0qXM7rcZ0FLoMAZcHAoGZKUEAWaxYXTxtvoo7TbKwE=; b=WQ+Wl8g1aGACe8veUyPKtdiDotZMkAbGW/n2Dr0i4MLb88IhZez9pjXd9sNyKI8e9R x9qygiU0oy2QWTDSJTuxyrKyd5vbOXwxfHYD5NPfTlUnHQotLJQ59Q9wp1Ot9GRediC9 nEIKeLt08dKdNaB2SaYT2OAc2vZxHx1TTm5z6ZmKP1q9UTxJmpCM95Oql/iklODWqCjI ATbYsIGaZJS5jZ9W8LD83to0uSG8tHT4WxeiWRQ0dri4+aRq47SWN9KfiIitLrusAsi0 fpkW5ujpikzLNnF3l/1HNSEZUF6u0csW/wqc0k3m4yOD+iSwYKrcz2xihcTP/uXNO9oi 6sJA== X-Forwarded-Encrypted: i=1; AJvYcCXDW7YFyyeQGTPS6wr6PY1R+lTG1LdE1PS4vx2N6YWCyBLycAtwrxCcJmXcHhJxbYBX50uQfXaWo2+b+Igi9UghI+xvf8I2IahWEEM= X-Gm-Message-State: AOJu0YzB1LBp1Jq3VRbQObAsHFEyqBuIRoc4w4HgeX58PqO3naQ1egsI vzBzKEqshYdXz/xfR3QnzOkq6SBbmX6EoyvWoliZMYquL4Ebu1A1oa14dN+fLOc51ysGZJdckOU l X-Google-Smtp-Source: AGHT+IHHBbpT30iQ08OR56MfGPC/8jxwnnJVhEw0ErnkoaKYf51wW29WWgbxICRyROPEhZzSUdrwsQ== X-Received: by 2002:a05:6a20:9718:b0:1af:f50f:cbe5 with SMTP id adf61e73a8af0-1c0cd194c0bmr4153053637.8.1720163718284; Fri, 05 Jul 2024 00:15:18 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.133.57]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-75e51aaf3f2sm2262658a12.15.2024.07.05.00.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 00:15:17 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 3/6] lib: sbi: Optimize fifo enqueue/dequeue for basic data types Date: Fri, 5 Jul 2024 12:45:01 +0530 Message-Id: <20240705071504.50988-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240705071504.50988-1-apatel@ventanamicro.com> References: <20240705071504.50988-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240705_001519_601244_C3EEEFAE X-CRM114-Status: UNSURE ( 8.96 ) 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: Don't use sbi_memcpy() for basic data types in fifo enqueue/dequeue instead use direct type-cast and assignment. Signed-off-by: Anup Patel --- lib/sbi/sbi_fifo.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) 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:434 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 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 Don't use sbi_memcpy() for basic data types in fifo enqueue/dequeue instead use direct type-cast and assignment. Signed-off-by: Anup Patel Reviewed-By: Himanshu Chauhan --- lib/sbi/sbi_fifo.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_fifo.c b/lib/sbi/sbi_fifo.c index 72c6d39..9199a30 100644 --- a/lib/sbi/sbi_fifo.c +++ b/lib/sbi/sbi_fifo.c @@ -66,7 +66,26 @@ static inline void __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data) if (head >= fifo->num_entries) head = head - fifo->num_entries; - sbi_memcpy((char *)fifo->queue + head * fifo->entry_size, data, fifo->entry_size); + switch (fifo->entry_size) { + case 1: + *(char *)(fifo->queue + head * fifo->entry_size) = *(char *)data; + break; + case 2: + *(u16 *)(fifo->queue + head * fifo->entry_size) = *(u16 *)data; + break; + case 4: + *(u32 *)(fifo->queue + head * fifo->entry_size) = *(u32 *)data; + break; +#if __riscv_xlen > 32 + case 8: + *(u64 *)(fifo->queue + head * fifo->entry_size) = *(u64 *)data; + break; +#endif + default: + sbi_memcpy(fifo->queue + head * fifo->entry_size, + data, fifo->entry_size); + break; + } fifo->avail++; } @@ -184,8 +203,26 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data) return SBI_ENOENT; } - sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo->entry_size, - fifo->entry_size); + switch (fifo->entry_size) { + case 1: + *(char *)data = *(char *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; + case 2: + *(u16 *)data = *(u16 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; + case 4: + *(u32 *)data = *(u32 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; +#if __riscv_xlen > 32 + case 8: + *(u64 *)data = *(u64 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; +#endif + default: + sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo->entry_size, + fifo->entry_size); + break; + } fifo->avail--; fifo->tail++; From patchwork Fri Jul 5 07:15:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1957139 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=nWE/Ryy5; 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=RgMj/Zhe; 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 4WFlCl6l7vz1xpP for ; Fri, 5 Jul 2024 17:15: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: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=b6WDwllGD1Hm7CGYBk2LOv0ZY4FSZa4Dq2llzpkvpiQ=; b=nWE/Ryy5yYKEeO a86lOldGEufXoOidVIMqkY+3YujJvZzRH2nULnhSdiuf/X0bRcU0R81dnGlM46IWpaTqgA4SGn1Xq i39H/JnWjBCxKJi/e40U5Mr5YoCIpEeWaLFCpVqveReUKKrNBy62tfo+N4mwnpIgQ67AkSZ1APo9d oSuw/A0/P6e0+jUGrdzrrQ7rtDkYbcMAqv5i1iS0OTcT2IahohrtQLtgNKPjq9PwwYa0EzTdJRcNi xozTtzgXZ2QODNSEFB/Tx6Bk43q1GqD0vZwLZ0CcFSyus1jhJSl3gAikeTWeot7CJ2d+Zx7oCpXX4 mL+dWc8LEW0+qAms57bg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdAD-0000000F84O-3jci; Fri, 05 Jul 2024 07:15:25 +0000 Received: from mail-ot1-x329.google.com ([2607:f8b0:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdAA-0000000F81N-1J9h for opensbi@lists.infradead.org; Fri, 05 Jul 2024 07:15:23 +0000 Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-70226277bc0so815880a34.0 for ; Fri, 05 Jul 2024 00:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1720163721; x=1720768521; darn=lists.infradead.org; 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=jbNZ6YcFH+cAkRAzhnR3l6ePr/oQTMCGesInNN5d8cI=; b=RgMj/ZhebYyqWjPS9QWI3c5+kMWTcfnhJVZfoeghbP4Thxj7dFy1ODRuxegXR+88Tx rVbtVIA3KGlnagGKTJcVbBVT150+xXL1ndqd8S2RMKEAZ/QJyUet1loVLX0058u5TRSM LyLqgK6NUDdnqF1qr0QMLIOEOJPih/EAt8qjFNLpwD3DZL6BrAxIKC/xhqiJ0vPxeyxw pSkaM8OfYLEmRJJGFMjnuA9jlMB9rdfRLfjr1bw7hcI3/Da80ydKqV4gsCJa4gjs56TH EI4uBP6r7QqrLOxbZq42udMGdHd6l/iFyTQdnjC8gV6ykHJgu//wuG0jQOWlDOGhuLIr 8nAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720163721; x=1720768521; 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=jbNZ6YcFH+cAkRAzhnR3l6ePr/oQTMCGesInNN5d8cI=; b=kLKzshi3LfBrSD0hbvuXrBOB742vMyPNaXCAPiq01VL5SAGcsuS8moCDzhZ1CjP27y 8TglVIdX1dxx930ka9TA44qtROQQaLoUe+c3p8SzSV3LhZOhY5Q4+THb+NIXwNz6AVSB 22VO1f5CpKl1xy0fXjt+tgu93a2mbP+vO2k/GqnfxuiJAh4NJEpSI2OtWB7vZapvh/cu KDf2SyBwlpN5Qfg2f28Z7m8NGHXBkuSA9QPA7yTGhbntgOoIQJdp9h5EeZICB60ybHS4 fdswTxMuPsA7WWT386yoGi9iua8xCjhTBlp0e9xJnGFkkpKUPDUq+W3EoElP7QhBf3rY sj/w== X-Forwarded-Encrypted: i=1; AJvYcCWM+h6+FEIqvm+lg2vggTWmGJLDLhl1ZSkYlu9u+4d09qX9BlFrp+mQSnklPHba5tslrRx8MYUaJKdrAzbmSKTv4XbfJ/Kwm/I1B5g= X-Gm-Message-State: AOJu0YxAVDSiP2acdHihFpqdbgs+NFBc1amlgrGotCKrJi8GefUW2H1h KlqHDUo0Kj/ze6BNmRuiw8WRH2JZLc86VG0xz/VaCMbgdwDQUmyuisB9I0EDLjA= X-Google-Smtp-Source: AGHT+IFtBqwRDZa93JTYLyyBr8jbtLoavHfCxadkCgcY/kR7CJD4Uy1ZkBdGBU5/ywf1FJA2wUqHRA== X-Received: by 2002:a05:6870:1596:b0:254:a917:cb3a with SMTP id 586e51a60fabf-25e2bb896d4mr3191851fac.28.1720163720810; Fri, 05 Jul 2024 00:15:20 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.133.57]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-75e51aaf3f2sm2262658a12.15.2024.07.05.00.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 00:15:20 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 4/6] lib: sbi: Allow forceful queueing of data in sbi_fifo_enqueue() Date: Fri, 5 Jul 2024 12:45:02 +0530 Message-Id: <20240705071504.50988-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240705071504.50988-1-apatel@ventanamicro.com> References: <20240705071504.50988-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240705_001522_415873_50782442 X-CRM114-Status: GOOD ( 14.15 ) 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: Extend sbi_fifo_enqueue() to allow forceful queueing by droping data from the tail. Signed-off-by: Anup Patel --- include/sbi/sbi_fifo.h | 2 +- lib/sbi/sbi_fifo.c | 69 +++++++++++++++++++++++++ lib/sbi/sbi_sse.c | 2 +- lib/sbi/sbi_tlb.c | 3 [...] 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:329 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 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 Extend sbi_fifo_enqueue() to allow forceful queueing by droping data from the tail. Signed-off-by: Anup Patel Reviewed-By: Himanshu Chauhan --- include/sbi/sbi_fifo.h | 2 +- lib/sbi/sbi_fifo.c | 69 +++++++++++++++++++++++++----------------- lib/sbi/sbi_sse.c | 2 +- lib/sbi/sbi_tlb.c | 3 +- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/include/sbi/sbi_fifo.h b/include/sbi/sbi_fifo.h index 1a85f07..af1632a 100644 --- a/include/sbi/sbi_fifo.h +++ b/include/sbi/sbi_fifo.h @@ -30,7 +30,7 @@ enum sbi_fifo_inplace_update_types { }; int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data); -int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data); +int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data, bool force); void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries, u16 entry_size); int sbi_fifo_is_empty(struct sbi_fifo *fifo); diff --git a/lib/sbi/sbi_fifo.c b/lib/sbi/sbi_fifo.c index 9199a30..d07ebff 100644 --- a/lib/sbi/sbi_fifo.c +++ b/lib/sbi/sbi_fifo.c @@ -90,6 +90,39 @@ static inline void __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data) fifo->avail++; } +/* Note: must be called with fifo->qlock held */ +static inline void __sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data) +{ + if (!data) + goto skip_data_copy; + + switch (fifo->entry_size) { + case 1: + *(char *)data = *(char *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; + case 2: + *(u16 *)data = *(u16 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; + case 4: + *(u32 *)data = *(u32 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; +#if __riscv_xlen > 32 + case 8: + *(u64 *)data = *(u64 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; +#endif + default: + sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo->entry_size, + fifo->entry_size); + break; + } + +skip_data_copy: + fifo->avail--; + fifo->tail++; + if (fifo->tail >= fifo->num_entries) + fifo->tail = 0; +} /* Note: must be called with fifo->qlock held */ static inline bool __sbi_fifo_is_empty(struct sbi_fifo *fifo) @@ -173,7 +206,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in, return ret; } -int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data) +int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data, bool force) { if (!fifo || !data) return SBI_EINVAL; @@ -181,9 +214,13 @@ int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data) spin_lock(&fifo->qlock); if (__sbi_fifo_is_full(fifo)) { - spin_unlock(&fifo->qlock); - return SBI_ENOSPC; + if (!force) { + spin_unlock(&fifo->qlock); + return SBI_ENOSPC; + } + __sbi_fifo_dequeue(fifo, NULL); } + __sbi_fifo_enqueue(fifo, data); spin_unlock(&fifo->qlock); @@ -203,31 +240,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data) return SBI_ENOENT; } - switch (fifo->entry_size) { - case 1: - *(char *)data = *(char *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); - break; - case 2: - *(u16 *)data = *(u16 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); - break; - case 4: - *(u32 *)data = *(u32 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); - break; -#if __riscv_xlen > 32 - case 8: - *(u64 *)data = *(u64 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); - break; -#endif - default: - sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo->entry_size, - fifo->entry_size); - break; - } - - fifo->avail--; - fifo->tail++; - if (fifo->tail >= fifo->num_entries) - fifo->tail = 0; + __sbi_fifo_dequeue(fifo, data); spin_unlock(&fifo->qlock); diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c index e39963f..fe36a64 100644 --- a/lib/sbi/sbi_sse.c +++ b/lib/sbi/sbi_sse.c @@ -667,7 +667,7 @@ static int sse_ipi_inject_send(unsigned long hartid, uint32_t event_id) sse_inject_fifo_r = sbi_scratch_offset_ptr(remote_scratch, sse_inject_fifo_off); - ret = sbi_fifo_enqueue(sse_inject_fifo_r, &evt); + ret = sbi_fifo_enqueue(sse_inject_fifo_r, &evt, false); if (ret) return SBI_EFAIL; diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index cca319f..01b31f4 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -351,7 +351,8 @@ static int tlb_update(struct sbi_scratch *scratch, ret = sbi_fifo_inplace_update(tlb_fifo_r, data, tlb_update_cb); - if (ret == SBI_FIFO_UNCHANGED && sbi_fifo_enqueue(tlb_fifo_r, data) < 0) { + if (ret == SBI_FIFO_UNCHANGED && + sbi_fifo_enqueue(tlb_fifo_r, data, false) < 0) { /** * For now, Busy loop until there is space in the fifo. * There may be case where target hart is also From patchwork Fri Jul 5 07:15:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1957140 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=J3Uf0lTh; 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=Uhnr74HJ; 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 4WFlCn6lSBz1xpP for ; Fri, 5 Jul 2024 17:15:33 +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=KAqvWS8tmNzgv9Zp7QQeCtLVJ4h+lYD9lU5GsSqwVww=; b=J3Uf0lThkvHG3Z 3zvmgPI7WhpuZQD7wCOcopWNZ7s5qSZvcNcAkT0soy1/fFe/9+tJ8teYkJCxYOzVrnNDlnF7tHs4T s59h/rwUw1yc1s42AhZfRaIdWZlkbgNhGXVUOP7nVntYuTAtcBZnOnvFCjy2HEYS+qqJ9kHk7V93Y WlIzAuF4b9rakPXOXrylGkWIuxLGzwrLpHRyUsZwQJa0o32e9gquhYU/VOT9DEOW5e6yhvr0sWuMS Rr0Lua6V+s4ABhK/18gYoDJca4wr390g5ITtsHZu6PIPlZrIAOIHUndfleMkWuN2EuzI5Gv0pZuwb ukSbCT7H8NjAR+ai9qjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdAF-0000000F85t-3P2f; Fri, 05 Jul 2024 07:15:27 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdAC-0000000F83A-2UPS for opensbi@lists.infradead.org; Fri, 05 Jul 2024 07:15:26 +0000 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3c9cc681e4fso631759b6e.0 for ; Fri, 05 Jul 2024 00:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1720163723; x=1720768523; darn=lists.infradead.org; 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=vWGGS3A/QO6ZdlbwySw9w2zcAWzVI3jC1aI3HIAl5WM=; b=Uhnr74HJW81GHW+8x/V0Q149XB0C8d1PCNcMDq/8U6OxyM/RKr/PbzrqkqjinY0awr XJ5aG/2RfYcE6M6yewmOxVe1+h+I1EtEghepB8Hxn9A9GeC0h4RZrwgFn0ljOaPKAF6l q1tGFEa3m9TaCmPAoiEgPb74GOSIJ84b+TaoBwVC6NKEybCgLJox70X+pY9A8oFFShIT fEF8v7QS4QTPN9euxGmY9wexRIImH6sYZ1YVot9Q0fERPd5qFxjh+7nTKAwvsi7w1kjB RCIWvAq8CKkjNz06Iy6AHXdeRYKrBgb34UlPodDiOBDwnYomz9k23Nc7zWyy5Aq6WD0f /LaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720163723; x=1720768523; 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=vWGGS3A/QO6ZdlbwySw9w2zcAWzVI3jC1aI3HIAl5WM=; b=PdscAp6DGQHMhGWmOSrJfrVU6S3ZZjIB7ue99jz168CAj8aLq1lt7lnzuGRDe2o+TB AjiNJi16o1nQW4DIQD+Ar9ZWEopmG8gYG31yOEHBwuAUeOFXQwEyz8d3AXQbrl+19Q2y Zml8vahqtSRssrNd96Hn+PSQos/xhwt2qV5mhw56i9Tl7866y3zHHtC8IB6vVR47rY9I PhbbrwQr7/pHXcAMBLEe9w5FYefOTsGikL5UcKccHCUaYGZVZ8Q4k41y+4pf5VmYq+LC Zs4yfr4NFg+6rgFS3f8oKZArkXXyVgRVPhm8YY88PA3W5SkhoxTTer1aGAHgwX2EAodx GgOw== X-Forwarded-Encrypted: i=1; AJvYcCVXpMXioML/4FEUgiEB143gnxJvjyLgGWSdthYAAW402JRqrafk1e05gC0llaKEkc47BePIerFJ+C0rVhulIy8u4cbk7iQAPkWcC/w= X-Gm-Message-State: AOJu0Yx6L29VNXzIjIn8OXnBLUB6kw+lx/sGlYT8ZLDtbID/Vv2ySikK XeU+TvaYNIdVEYxFL8c/tbCPeZCZS4vC1iefPBTItb5M3uq8PQN9AQj/zYnM31E= X-Google-Smtp-Source: AGHT+IEWtJdU4koy4uHZ6PcexFZ3zSDXGUaNOkt15c6+a+zJu4+3fc0BjxhpsfwRYhA2b89jXYH1eg== X-Received: by 2002:a05:6808:21a1:b0:3d6:2dc9:3b3 with SMTP id 5614622812f47-3d914cadfcdmr4337896b6e.37.1720163723253; Fri, 05 Jul 2024 00:15:23 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.133.57]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-75e51aaf3f2sm2262658a12.15.2024.07.05.00.15.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 00:15:22 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 5/6] include: sbi: Add macros to create FIFO as local or global variable Date: Fri, 5 Jul 2024 12:45:03 +0530 Message-Id: <20240705071504.50988-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240705071504.50988-1-apatel@ventanamicro.com> References: <20240705071504.50988-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240705_001524_696867_9E229605 X-CRM114-Status: UNSURE ( 7.13 ) 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 FIFO data structure is quite handy of variety of use-case so add SBI_FIFO_INITIALIZER() and SBI_FIFO_DEFINE() helper macros to create FIFO as local or global variable. Signed-off-by: Anup Patel --- include/sbi/sbi_fifo.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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:230 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 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 FIFO data structure is quite handy of variety of use-case so add SBI_FIFO_INITIALIZER() and SBI_FIFO_DEFINE() helper macros to create FIFO as local or global variable. Signed-off-by: Anup Patel Reviewed-By: Himanshu Chauhan --- include/sbi/sbi_fifo.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/sbi/sbi_fifo.h b/include/sbi/sbi_fifo.h index af1632a..89a2ea2 100644 --- a/include/sbi/sbi_fifo.h +++ b/include/sbi/sbi_fifo.h @@ -23,6 +23,18 @@ struct sbi_fifo { u16 tail; }; +#define SBI_FIFO_INITIALIZER(__queue_mem, __entries, __entry_size) \ +{ .queue = __queue_mem, \ + .qlock = SPIN_LOCK_INITIALIZER, \ + .num_entries = __entries, \ + .entry_size = __entry_size, \ + .avail = 0, \ + .tail = 0, \ +} + +#define SBI_FIFO_DEFINE(__name, __queue_mem, __entries, __entry_size) \ +struct sbi_fifo __name = SBI_FIFO_INITIALIZER(__queue_mem, __entries, __entry_size) + enum sbi_fifo_inplace_update_types { SBI_FIFO_SKIP, SBI_FIFO_UPDATED, From patchwork Fri Jul 5 07:15:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1957141 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=Dvg90T9m; 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=MRCl8Cuk; 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 4WFlCr3Tw5z1xpP for ; Fri, 5 Jul 2024 17:15:36 +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=Hb5PHIpn57xLPd6qFDh7MJpvvoNjE8KQz03kyWWa75E=; b=Dvg90T9mM9wOw6 kD1r5lNfUxA0swWvW8E0OsA5GNa5VRafpWywb9SDbAx+dxSrCNvpG8bs6+1ufter3f1QzuhWf0pJQ r35ID5rqH5wibGw9VRHlJKcDMt0IBKs8QO2xmbGJs9m/WIs/Fwqi9z7/QDSl2Z4zO80pa//FBGR2d OFJZHf4dHnpZ1jUq2WIDgc949tJNfzHNI78t9XaYCAZgn/oU9wNeIwz/xfB0u1TDP1NQET8yYW77g VwJzymfqNGwNHSNZugRfE06llZvBL+Z/7almmtLSxuw6554imtOPMVMNtQ+Y3+X/80xpLumLhBmmW NlBmDAM+1DGiYM0//q1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdAI-0000000F88M-3gbP; Fri, 05 Jul 2024 07:15:30 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdAF-0000000F84s-1VFj for opensbi@lists.infradead.org; Fri, 05 Jul 2024 07:15:29 +0000 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3d846f4360cso869519b6e.0 for ; Fri, 05 Jul 2024 00:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1720163726; x=1720768526; darn=lists.infradead.org; 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=TyfUbLuTMQOnvdfsxtWoWsDI0RgDyf8zDWL0glUHy3o=; b=MRCl8CukivxLmty6iA2aqyJI8RsUzwwO5+iRWBPFHIYfjs6YkWUC2h+Ob5xPOnaQf6 x2bfC4MsyML8z2/JD4Xbd1Lr4jT7sreIl0hXmF7ESL6ZfQnKYkwvrZj/fOoFFGqew0Q1 mupCS1AEg5l+XIIvKhajN9TerIaEWkp/4DJ0HrRp+CjskKucVTK0Hrf666LEEBVkKKNP LfAoDNiwnHkCjcrBzwK6qTTStSso1jK/tob/S0WSSe4I4x44M7w47xTzdD7ubx1Z+VOf uWhBUqV5es8W1V44Wvrv11ILJqGlDCpxZvoEYJvFDdcIKBrw4M/34F0sCvB9sZi3bJO/ kPmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720163726; x=1720768526; 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=TyfUbLuTMQOnvdfsxtWoWsDI0RgDyf8zDWL0glUHy3o=; b=YjA7RBXfBeWNFGHH7Br3DYdjvESYmBuBEN9TnvHJFps5YV3xX9ssnGTVvT2+FZXGgX sb3BF4o0E7Rtph6QG1tv5evOsNcZdxpAfJ+qe+1z7CxBDUJKlVcFo1LFVGFqoemGvkhR FVH0lU3Zk/KD+3tJquTpbM5yj/ZKQzgJmQ+zqYa8n0Fzk4NDYpzm9L7jP5Ra1rBxCaiR eEnP3S5537Sm233fnpN5dmK8F75avU3IbDMkA50M4Rygdj03ltgRTkHmWTCpFFGvDEpQ PXu1gYG8IJrLW0Nf2qi7W/GOlwlsnlpgl+vrbdiaJpQHqUwyGTZ2j9EazZu6dwrZ/wd7 +hHQ== X-Forwarded-Encrypted: i=1; AJvYcCVV9c2vAu5d9vVy7e1iAORn5w1IEwcm84p1Z5X4Jaz6BxU7GhPXq2AL7u0Io/ew5ZO7Ss9HW1KCOBSdXieiIxNu7LbO1YcNRF/l8Dc= X-Gm-Message-State: AOJu0YxUtqB/YVllqlyZCO1cJKQpoDPDHENXDGBu9vdpuCjuuZ91q6sC tviIv+mxhoueyk9WuPDyrMmXyhtYYZsMg4AL6/nHLtWDY3T0w4YDggeyHa7BkLQ= X-Google-Smtp-Source: AGHT+IEvddMKH/sQBABKzKZfKboYp4Pxidi9aCoZHcdo+TFYpuYNDqED2aGB0g6PmiP++if6HKtLNQ== X-Received: by 2002:a05:6808:10c7:b0:3d5:6410:7dd8 with SMTP id 5614622812f47-3d914c50154mr4976165b6e.12.1720163725660; Fri, 05 Jul 2024 00:15:25 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.133.57]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-75e51aaf3f2sm2262658a12.15.2024.07.05.00.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 00:15:25 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 6/6] lib: sbi: Introduce an early console buffer for caching early prints Date: Fri, 5 Jul 2024 12:45:04 +0530 Message-Id: <20240705071504.50988-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240705071504.50988-1-apatel@ventanamicro.com> References: <20240705071504.50988-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240705_001527_455642_07881AED X-CRM114-Status: GOOD ( 14.26 ) 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 console device is registered by platform only in early_init() callback so any prints before this point will be lost. Introduce an early console buffer for caching prints before platform early_init [...] 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:235 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 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 console device is registered by platform only in early_init() callback so any prints before this point will be lost. Introduce an early console buffer for caching prints before platform early_init(). For crashes before platform early_init(), users can simply dump the contents of the console_early_buffer[] string using a debugger. The relative address of the console_early_buffer[] string can be found using following two commands: CONSOLE_EARLY_FIFO_ADDR=`${CROSS_COMPILE}objdump -D \ build/platform/generic/firmware/fw_dynamic.elf | \ grep ":" | awk '{print $1}'` ${CROSS_COMPILE}objdump -R build/platform/generic/firmware/fw_dynamic.elf | \ grep $CONSOLE_EARLY_FIFO_ADDR | awk '{print $3}' Signed-off-by: Anup Patel Reviewed-By: Himanshu Chauhan --- lib/sbi/Kconfig | 6 +++++- lib/sbi/sbi_console.c | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig index 6cf54ce..bd8ba2b 100644 --- a/lib/sbi/Kconfig +++ b/lib/sbi/Kconfig @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-2-Clause -menu "SBI Extension Support" +menu "Generic SBI Support" + +config CONSOLE_EARLY_BUFFER_SIZE + int "Early console buffer size (bytes)" + default 256 config SBI_ECALL_TIME bool "Timer extension" diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 194529d..d760885 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -21,6 +22,15 @@ static char console_tbuf[CONSOLE_TBUF_MAX]; static u32 console_tbuf_len; static spinlock_t console_out_lock = SPIN_LOCK_INITIALIZER; +#ifdef CONFIG_CONSOLE_EARLY_BUFFER_SIZE +#define CONSOLE_EARLY_BUFFER_SIZE CONFIG_CONSOLE_EARLY_BUFFER_SIZE +#else +#define CONSOLE_EARLY_BUFFER_SIZE 256 +#endif +static char console_early_buffer[CONSOLE_EARLY_BUFFER_SIZE] = { 0 }; +static SBI_FIFO_DEFINE(console_early_fifo, console_early_buffer, \ + CONSOLE_EARLY_BUFFER_SIZE, sizeof(char)); + bool sbi_isprintable(char c) { if (((31 < c) && (c < 127)) || (c == '\f') || (c == '\r') || @@ -39,6 +49,7 @@ int sbi_getc(void) static unsigned long nputs(const char *str, unsigned long len) { + char ch; unsigned long i; if (console_dev) { @@ -51,6 +62,11 @@ static unsigned long nputs(const char *str, unsigned long len) console_dev->console_putc(str[i]); } } + } else { + for (i = 0; i < len; i++) { + ch = str[i]; + sbi_fifo_enqueue(&console_early_fifo, &ch, true); + } } return len; } @@ -472,8 +488,19 @@ const struct sbi_console_device *sbi_console_get_device(void) void sbi_console_set_device(const struct sbi_console_device *dev) { + char ch; + bool flush_early_fifo = false; + if (!dev) return; + if (!console_dev) + flush_early_fifo = true; + console_dev = dev; + + if (flush_early_fifo) { + while (!sbi_fifo_dequeue(&console_early_fifo, &ch)) + sbi_putc(ch); + } }