From patchwork Tue Sep 3 04:06:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 1979809 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=F2Hkb8KY; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=SeJzqsgg; 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 4WyXDM4nPkz1yh2 for ; Tue, 3 Sep 2024 14:08:34 +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:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GqZs083zM1Y1m2N8QYjhMKmLS9MJBvrrMXfFyJITkTI=; b=F2Hkb8KYMlNRX6 AJUvcbzAchRNBoV0fef9VDyMiIbBf6T+TqiyTD3jLfDI08H/ywGPMJ/9dzGSf/yf778HqJ/9WiHrS syv5jcAcspniGHPNHEQJkVZS3YWtpbefboTRHgxkaynQIdKHTfypKPNK79p/k61yO9K/muSb+Ktzt RcQl6YgDmJORrezXwYWNlX1Gi7om1cpMDPRTyE3cIUI8AgiTpCZEUS4Eu661+gEBVE+Uk/lM5GNzs S55k85DgmC2Y8/NOUIISZT6WTo7jXHxq6nY/+fhhdTTXqu+VjhncP0kJIDnRH3wGWvwUZq5M8B/0t 4d+58OhgZBDu7YhKmRMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slKq5-0000000GFVk-2MLb; Tue, 03 Sep 2024 04:08:21 +0000 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slKq2-0000000GFUj-49Q1 for opensbi@lists.infradead.org; Tue, 03 Sep 2024 04:08:20 +0000 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-7091558067eso1768782a34.3 for ; Mon, 02 Sep 2024 21:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1725336497; x=1725941297; 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=BfsxyeLdQPd9h/hla5CZCPbqCM14lfs1Kp4GhUN+hxc=; b=SeJzqsgg1xOZwr7aDxRIKiHYH6fpX6XpND4gPGTkBekGcI7jPu1Aq2sUJwtTMBh5YP b8Eihj4ieJvk+0bdCedxjkhMUimYEf1bSRZFDHwnXY2rhC/C8lRIEtfQjswZVa6yzgkK kd5yQkHEJ5dueRYsW1jOCNG15SjkpD3vWDCqFh9urcq+33uYXT+2SeF76Z5DlaBqDm2K PP/dubnX1JpsVfhLc086/R/9j0G6HI6wIQTecIv5R5kCDoYnx7/KDwg2Jlrutp3uD0e8 4tl99oSOWqu2jowa/nZ1qk6Bx39vShzTBNhIBi5nt9/JKp+2UIJkvP/wq376ZCRHpZAl de+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725336497; x=1725941297; 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=BfsxyeLdQPd9h/hla5CZCPbqCM14lfs1Kp4GhUN+hxc=; b=aw/Ef81pPYaxo4fu8NCTi4UEa2Y29KtRRVdFLdeTu1v/3Ct1WNrKFHkya9PoplsmmQ e1mqZS5qKmfbBzorZfcfVg2vREu9mnYGILyxQa2K/++90BWv1+qXIy2yRYsWggkjwRIP jNDBmZ1fyMyfqbdor8XjiU8fDfVvvyKnzTxfflo7pamPmd6zehPsZJUd3CJq8WkHfOGY DU731yhKtMgTjHE0fUIi+RYtJHGfhF1ErOR4eE0tk7+GLwnwqvWJxj9z2bkSFqWk/yXf ZtG2vvoBA/IkpWPjKj+x9IPrSDQ32JLFHcWo2CX7Syfi2aEW9+Oq4hBo6jKNpV4BSW8X T1Mw== X-Gm-Message-State: AOJu0Yz+M2VJBlcTW63D2TJ6lMc5tMYSs0whT2rSHqHC6LflgAXkXDc6 mHAogza2j2FT8ht5va91S5r/2N4KTd6JbFKdG954QoQwuXq8MIvhIYpJnzgh4zxTOB+dn/LhMNj VwqxDfeYkiZoMgWhHVhm2H/mZGTW66xuhV1z53Uxak++fV1DAtfxnyS+69Hy0/TdutZpxJB6VZC cEVsFkbeyAXYI87QvN5k9hUxgYvYwwvbvO6bFPhFPfzRSnQWoxfuo= X-Google-Smtp-Source: AGHT+IF0Bn5j0XxzzbVq6KjYp++Qmeuvmy+DDrFo61TAJjx/PgOiD2V9XVa9BikQnTZ7zN4p23wPWw== X-Received: by 2002:a05:6358:9107:b0:1ac:ef2e:5316 with SMTP id e5c5f4694b2df-1b603cd4fdfmr1971877155d.26.1725336497274; Mon, 02 Sep 2024 21:08:17 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-715e557723fsm7570563b3a.42.2024.09.02.21.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 21:08:16 -0700 (PDT) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 1/2] lib: sbi_timer: Call driver warm_init from SBI core Date: Mon, 2 Sep 2024 21:06:49 -0700 Message-ID: <20240903040814.622145-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240903040814.622145-1-samuel.holland@sifive.com> References: <20240903040814.622145-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240902_210819_053416_44168E18 X-CRM114-Status: GOOD ( 21.56 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Currently, the platform's timer device is tracked in two places: the core SBI implementation has `timer_dev`, and the FDT timer layer has `current_driver`. The latter is used for warm initialization o [...] Content analysis details: (-2.1 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:335 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 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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 Currently, the platform's timer device is tracked in two places: the core SBI implementation has `timer_dev`, and the FDT timer layer has `current_driver`. The latter is used for warm initialization of the timer device. However, this warm init is not specific to FDT-based platforms; other platforms call exactly the same functions from the same point in the boot sequence. The code is simplified and made common across platforms by treating warm init and exit as properties of the driver, not the platform. Then the platform's only role is to select and prepare a driver during cold boot. For now, only add a .warm_init hook, since none of the existing drivers need an .exit hook. It could be added in the future if needed. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- include/sbi/sbi_timer.h | 3 +++ include/sbi_utils/timer/aclint_mtimer.h | 2 -- include/sbi_utils/timer/andes_plmt.h | 1 - lib/sbi/sbi_timer.c | 13 ++++++++++++- lib/utils/timer/aclint_mtimer.c | 3 ++- lib/utils/timer/andes_plmt.c | 23 ++++++++++++----------- lib/utils/timer/fdt_timer_mtimer.c | 2 +- lib/utils/timer/fdt_timer_plmt.c | 2 +- platform/fpga/ariane/platform.c | 2 +- platform/fpga/openpiton/platform.c | 2 +- platform/kendryte/k210/platform.c | 2 +- platform/nuclei/ux600/platform.c | 2 +- platform/template/platform.c | 2 +- 13 files changed, 36 insertions(+), 23 deletions(-) diff --git a/include/sbi/sbi_timer.h b/include/sbi/sbi_timer.h index ac48e2b8..64df9dfa 100644 --- a/include/sbi/sbi_timer.h +++ b/include/sbi/sbi_timer.h @@ -28,6 +28,9 @@ struct sbi_timer_device { /** Stop timer event for current HART */ void (*timer_event_stop)(void); + + /** Initialize timer device for current HART */ + int (*warm_init)(void); }; struct sbi_scratch; diff --git a/include/sbi_utils/timer/aclint_mtimer.h b/include/sbi_utils/timer/aclint_mtimer.h index 6ab8799c..a245e13e 100644 --- a/include/sbi_utils/timer/aclint_mtimer.h +++ b/include/sbi_utils/timer/aclint_mtimer.h @@ -47,8 +47,6 @@ void aclint_mtimer_sync(struct aclint_mtimer_data *mt); void aclint_mtimer_set_reference(struct aclint_mtimer_data *mt, struct aclint_mtimer_data *ref); -int aclint_mtimer_warm_init(void); - int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt, struct aclint_mtimer_data *reference); diff --git a/include/sbi_utils/timer/andes_plmt.h b/include/sbi_utils/timer/andes_plmt.h index 08bce332..119f1b44 100644 --- a/include/sbi_utils/timer/andes_plmt.h +++ b/include/sbi_utils/timer/andes_plmt.h @@ -24,6 +24,5 @@ struct plmt_data { }; int plmt_cold_timer_init(struct plmt_data *plmt); -int plmt_warm_timer_init(void); #endif /* __TIMER_ANDES_PLMT_H__ */ diff --git a/lib/sbi/sbi_timer.c b/lib/sbi/sbi_timer.c index 7b618de1..466e81e5 100644 --- a/lib/sbi/sbi_timer.c +++ b/lib/sbi/sbi_timer.c @@ -182,6 +182,7 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot) { u64 *time_delta; const struct sbi_platform *plat = sbi_platform_ptr(scratch); + int ret; if (cold_boot) { time_delta_off = sbi_scratch_alloc_offset(sizeof(*time_delta)); @@ -198,7 +199,17 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot) time_delta = sbi_scratch_offset_ptr(scratch, time_delta_off); *time_delta = 0; - return sbi_platform_timer_init(plat, cold_boot); + ret = sbi_platform_timer_init(plat, cold_boot); + if (ret) + return ret; + + if (timer_dev && timer_dev->warm_init) { + ret = timer_dev->warm_init(); + if (ret) + return ret; + } + + return 0; } void sbi_timer_exit(struct sbi_scratch *scratch) diff --git a/lib/utils/timer/aclint_mtimer.c b/lib/utils/timer/aclint_mtimer.c index 9acb26eb..3db3c3be 100644 --- a/lib/utils/timer/aclint_mtimer.c +++ b/lib/utils/timer/aclint_mtimer.c @@ -143,7 +143,7 @@ void aclint_mtimer_set_reference(struct aclint_mtimer_data *mt, mt->time_delta_computed = 0; } -int aclint_mtimer_warm_init(void) +static int aclint_mtimer_warm_init(void) { u64 *mt_time_cmp; u32 target_hart = current_hartid(); @@ -260,6 +260,7 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt, } mtimer.timer_freq = mt->mtime_freq; + mtimer.warm_init = aclint_mtimer_warm_init; sbi_timer_set_device(&mtimer); return 0; diff --git a/lib/utils/timer/andes_plmt.c b/lib/utils/timer/andes_plmt.c index 6e4bfafe..d034feb9 100644 --- a/lib/utils/timer/andes_plmt.c +++ b/lib/utils/timer/andes_plmt.c @@ -67,12 +67,23 @@ static void plmt_timer_event_start(u64 next_event) #endif } +static int plmt_warm_timer_init(void) +{ + if (!plmt.time_val) + return SBI_ENODEV; + + plmt_timer_event_stop(); + + return 0; +} + static struct sbi_timer_device plmt_timer = { .name = "andes_plmt", .timer_freq = DEFAULT_AE350_PLMT_FREQ, .timer_value = plmt_timer_value, .timer_event_start = plmt_timer_event_start, - .timer_event_stop = plmt_timer_event_stop + .timer_event_stop = plmt_timer_event_stop, + .warm_init = plmt_warm_timer_init, }; int plmt_cold_timer_init(struct plmt_data *plmt) @@ -95,13 +106,3 @@ int plmt_cold_timer_init(struct plmt_data *plmt) return 0; } - -int plmt_warm_timer_init(void) -{ - if (!plmt.time_val) - return SBI_ENODEV; - - plmt_timer_event_stop(); - - return 0; -} diff --git a/lib/utils/timer/fdt_timer_mtimer.c b/lib/utils/timer/fdt_timer_mtimer.c index 458e8881..eff50417 100644 --- a/lib/utils/timer/fdt_timer_mtimer.c +++ b/lib/utils/timer/fdt_timer_mtimer.c @@ -165,6 +165,6 @@ static const struct fdt_match timer_mtimer_match[] = { struct fdt_timer fdt_timer_mtimer = { .match_table = timer_mtimer_match, .cold_init = timer_mtimer_cold_init, - .warm_init = aclint_mtimer_warm_init, + .warm_init = NULL, .exit = NULL, }; diff --git a/lib/utils/timer/fdt_timer_plmt.c b/lib/utils/timer/fdt_timer_plmt.c index 88a42e2a..87e634bd 100644 --- a/lib/utils/timer/fdt_timer_plmt.c +++ b/lib/utils/timer/fdt_timer_plmt.c @@ -46,6 +46,6 @@ static const struct fdt_match timer_plmt_match[] = { struct fdt_timer fdt_timer_plmt = { .match_table = timer_plmt_match, .cold_init = fdt_plmt_cold_timer_init, - .warm_init = plmt_warm_timer_init, + .warm_init = NULL, .exit = NULL, }; diff --git a/platform/fpga/ariane/platform.c b/platform/fpga/ariane/platform.c index ec0584ab..c895cb47 100644 --- a/platform/fpga/ariane/platform.c +++ b/platform/fpga/ariane/platform.c @@ -159,7 +159,7 @@ static int ariane_timer_init(bool cold_boot) return ret; } - return aclint_mtimer_warm_init(); + return 0; } /* diff --git a/platform/fpga/openpiton/platform.c b/platform/fpga/openpiton/platform.c index 81cc48f4..ea0a4799 100644 --- a/platform/fpga/openpiton/platform.c +++ b/platform/fpga/openpiton/platform.c @@ -190,7 +190,7 @@ static int openpiton_timer_init(bool cold_boot) return ret; } - return aclint_mtimer_warm_init(); + return 0; } /* diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 2f3f7079..82dd0809 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -169,7 +169,7 @@ static int k210_timer_init(bool cold_boot) return rc; } - return aclint_mtimer_warm_init(); + return 0; } const struct sbi_platform_operations platform_ops = { diff --git a/platform/nuclei/ux600/platform.c b/platform/nuclei/ux600/platform.c index 5610e7c7..b17c1df2 100644 --- a/platform/nuclei/ux600/platform.c +++ b/platform/nuclei/ux600/platform.c @@ -225,7 +225,7 @@ static int ux600_timer_init(bool cold_boot) return rc; } - return aclint_mtimer_warm_init(); + return 0; } const struct sbi_platform_operations platform_ops = { diff --git a/platform/template/platform.c b/platform/template/platform.c index b4d30a57..1238a8d6 100644 --- a/platform/template/platform.c +++ b/platform/template/platform.c @@ -129,7 +129,7 @@ static int platform_timer_init(bool cold_boot) return ret; } - return aclint_mtimer_warm_init(); + return 0; } /*