From patchwork Sat Jul 24 12:24:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1509484 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: 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=iBJyK6QH; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=KEah9MJ+; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=uo7CopYO; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GX54h4tg0z9sXJ for ; Sat, 24 Jul 2021 22:25:40 +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=25vq9H64TJ6/NLd9+OPi4iXJV89CA4p52lXqri4SJVA=; b=iBJyK6QHDtvIxL kIN3m5R7p/HNIyq0i4w2Cfp9XqPX2Oxer/4uPn4XgxQx/MM2IkUcUqx1m8jZ7322cGs5wUlRLpx4T MhBi/KstKIDq6eAB8hnBaKttNPovMmm/u19K67nkmmTHbAQRcfKvHRCTet+wH/fPwvSJgCPVmfO0/ WnDS9K+Vr7ye85BsetcJGWfTcHvV1vlGHlRsg80utpS0laXlC9CnWY8lC8agtE/K/JVT+PI5GAGNU mKkCq0Mwr5lOTWEuMuuRrYKL9vgqpCBxzY1fIsUA9S+ZjX41GIlGdsdy4IMvndK17QwT/nJAYd9DR O8hp9rObliSZwMSTfv6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7Gii-007AXS-Fu; Sat, 24 Jul 2021 12:25:32 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7Gie-007AW7-Vu for opensbi@lists.infradead.org; Sat, 24 Jul 2021 12:25:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1627129528; x=1658665528; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=8ssYtHmDzb7oW076g9AnVBUm7r/li70clzZ72GlSm/M=; b=KEah9MJ+wrIuzlh//6bZfkwS04dZVz1c2B/6E2DtBBhkXtCheFSIIcqm eM3Y6Dp6K44xWZOZ8w96R+mrMJ7cKVPp77kNnDq0Hg8l/5HwM/2iBEyjp lFkxWXh6ZFSxSPOR50TlbfzIrphojsjq5fj/8qj1GhC8aw2n3+0b6NGgc a+fVyUjG8cBRc5QJGTIdffx3tzzadkm2+5u/5FdegqPJqCmBgwz+vClNo hxjxu3FuPZJCmmX7Eqh7IIR7LibcQxdyEjEsq1/yavMlC9HAycedhNn0u YjON4y/ME7S5mlZl5r01qTRla06zhNTKfAKs+4hibaA5ocqw9m8jAosNt Q==; X-IronPort-AV: E=Sophos;i="5.84,266,1620662400"; d="scan'208";a="286959715" Received: from mail-dm6nam08lp2040.outbound.protection.outlook.com (HELO NAM04-DM6-obe.outbound.protection.outlook.com) ([104.47.73.40]) by ob1.hgst.iphmx.com with ESMTP; 24 Jul 2021 20:25:26 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fkQtpbh6LMDEMCsIZYMCgc6o1qkSNpTh2ZFLtxo1ewLE9Apfn1NgcrcLTDQSBVO1d6yzpCJ77gUmKmpI4mROQkhD8KaCkcsoMGf0xu4iagwXMzG6BFGDWB2/PIb0LdOQN1FwvFy2EMiyGRaeoVIcMpgtOVXOPNXRnDftfVerEJ/XNl7XkSPler8BaU0EEtN86i4NXI0eCJCps0+qgb3bKfMojPBLObSphhXXNVckoVnCVL5ktAnSPbPvlnSHqGPBQrFSHbghQgz2CxP5/wxJXzcf5ZeABaBhfYyf2xB0Dt+u9CuSVKpFHuqg7hMxeWFbn0NmV7JJWzv1e0Fl86vsww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3K2OE3at4tWkG5x5HvoUC/D8ddQyJVGP24v2GMh+YXM=; b=Okyeih+2iNr0g1fQjTuA5nmEaD+cqDXEIA4V+uULKBDOOradeWO0YMAtToHsvitDPYwEUPTlPEKd7z21XEI2gSEmdHLbw0dkB+zA6EmN8UqasZg+l5SDaOUb4JQD4WulkRT6WLhEI4usGfJ3l2B81zNQaNW/bpB+jjz5bOCVSt/YWzbXJZezQqeA6t8qStXui9G9BZWsl2rmIhjr605pPqRqQ3HYSF7ncGOuGcDaeE4Cnmmo5dmT16uAclNgFWUb/+ENkGwY6NnXSH21LW2xQTB4Yi1WIVZLxVXGPBq/McPwBI4FLMi7YgeILzsFgto4MXKLSBXde+JTrGxZaroZWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3K2OE3at4tWkG5x5HvoUC/D8ddQyJVGP24v2GMh+YXM=; b=uo7CopYO9dHADQ4FwdSxkqfjrS6TuHopHylHkS/6BTTs4fZSzi+JGgz2gpO9bupBW/p76sMI4LxxqWNGJJIYQMlluSJhYG3ooqsoNv3lW4sKyWG1wlcGJtD23C1DW5xqfALarJLQydcrOCVIFhuSwVNm7pnJ7xb4T/YC5ckKJFM= Authentication-Results: wdc.com; dkim=none (message not signed) header.d=none;wdc.com; dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB7764.namprd04.prod.outlook.com (2603:10b6:303:138::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.25; Sat, 24 Jul 2021 12:25:26 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::a153:b7f8:c87f:89f8]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::a153:b7f8:c87f:89f8%8]) with mapi id 15.20.4352.029; Sat, 24 Jul 2021 12:25:26 +0000 From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 1/5] lib: utils/timer: Allow separate base addresses for MTIME and MTIMECMP Date: Sat, 24 Jul 2021 17:54:59 +0530 Message-Id: <20210724122503.2486624-2-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210724122503.2486624-1-anup.patel@wdc.com> References: <20210724122503.2486624-1-anup.patel@wdc.com> X-ClientProxiedBy: MAXPR0101CA0006.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:c::16) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.61.225) by MAXPR0101CA0006.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.24 via Frontend Transport; Sat, 24 Jul 2021 12:25:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1911f3e0-9c4b-4acd-694c-08d94e9e1d9a X-MS-TrafficTypeDiagnostic: CO6PR04MB7764: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:663; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6oqce2zwVTwDi8e1OQWlWiKYUS4iLqL/h8D6zhOXXonN7hJwd4j84TlcOkhxZB3vZ1thCEFH1x+uKs9ZE9mhitqaZMxhE5X6AHsMe3dPzYfFUWPNAoKZ9XXQ/A+970VrabEBsAwlQltXGc06cZ2NEFOQ0OESNUZS1HvUvR1otWkb/Lg2dlMV3C6EezWuTbSNbAZA9yeOx4RrlvaPeMvi2BUURRpSRmxhLA1PCheSGySigoYNgce2b1dssOkUs/hzMFUfS3Bx9WGjOuIfZ0y+8e/Fho0Szd4ly4FtHAh2rXhjDXq/sIM3o8xbNg1d2PDd6mEDcOkHbTjlVEysSrG3EmRQ89ZGk+3q7vLycWS2xhwGZFa3SAdHXcabceWvWjK5MOC+ZbE6o9JzTW068cS0j1IUdC4/+IGmrW9XyHSAa3k2jCbct0ffQXHYsUZGTGhYzrdwF5f5vA7aNCDYD1IzuWCH5mMqttljIDpFW5IBrj3oOV40k/5ICxfz/waOprCzAHqY67SlBOU5Uv5agohEFdEevrWjaucbGid+ZPoMT65rYZ5yZxLwpRb6exQrwztyKKJou25ahz9aMOtFmzjadYWs7GNhW6TC5GQb43JlNei/9hh16ZTX1uz/8eksujMuY27gyCalg2E2z6A5wDN4qf8bRqiOplqgB8WLmApyfIdlcKf+pxiPmCg+cPUnpXizIXBb9mCB84/i/ahHVjoH+Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(956004)(44832011)(2616005)(38350700002)(36756003)(1076003)(8676002)(38100700002)(4326008)(508600001)(5660300002)(55016002)(110136005)(8936002)(66476007)(66556008)(66946007)(316002)(6636002)(8886007)(6666004)(54906003)(52116002)(7696005)(83380400001)(86362001)(2906002)(26005)(186003)(30864003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IyjYkXDQqvu79+jab0LQt2Ft2kIssgNL/46uOnwHUxNqdiLGC19lKTkO2ms+J55oW5zn0Ts17OQn0jMhtXBsEkxxkMy2SdoDgpsafuCZmr8Xzi7NZQVx6qnQ+bjInZhsSVjrCBS3pfcvDA2x2bnEo5MSRLuPcXrAft4WKJ4xnBsRFuxzyMr11/TnERassDKs+sbPDCjp6eK2lDtkLskkDUBeASwRwOCPHtGuHujnNCINg0bfimR8+tJQ4mv36C6BQegYp7ejE0nLHQLo2qKWcsL55wvdt53ameJtTUesnrZCFG2PRuePA16fm85HrJZ7GffIxW0OFMoSgn+FPfSaXkpzEBIo+O2eoRP/obgIqr8W4Dc3TnxR3D34309z6mGSyq8Bu0/y1iWiT4EB+UPe8yzrASYa8hwl+MzrdczThjUtvi5iLeerXHwmtW1kuYL/i6IFwFOwd8DWGl9T/7lxL8zKr1e/siEYY4QtsswLnjjWIr1Uy8/wrALgh+sZpaZm96gQyrV0W0l0tFwc/jsUQWj0wY+egU4aIVwgrQ0T5Pq5fFklUDNhXUQK3PTE+IVxebfc+Qi1HoRuuYDY8fv/2pOJl+Uvk25ICtX4+x/xlNYS3gQbY2TEKuMEtICqQ3HdZ/d/owNXgo/JVWteXxjgHYBDQjyKkFQdHq9rmZwypXm+NVNiAkdhnqyzANhRMXYHkGNspfPHCQupSAUKmJ5dhzyWG+yZbgTep66GRVIg2HoKTlFXuAQPbf/kwlOMWbR5hN4iTJ8BLcZGdPBbOu9FqHB4tMJMmvd4QbYPGigpPiCo4iGh9XoCPivy5Ppe6a18r+qLxVsdcf84ri2jmVzP1pQMfijGQcDNsCTVQGEp38HmdemhkrJLZAfnNYxcZkCtsTFtf1x4Q9dECcrOrozFNsdyVqABfvWAx1ZcPFujqSNa4m1gxrnN3JL/O2yz3xkr1f2A/Ax7xXYvAm8WT6n7V+ixCurZ+2KkIJPpmItXHDJ/ujyB2lvLGhjEJ9xzGJ40JFtzYNWiYtGd+daFHphE3LpO4o83BRylmpgp1PmLMm39aHcB9WBqW0ARbEI/1jUgbpZj9wly+WCxvCW49ALiOFo67FgJOWCyXBg5+8AAHMENrXVcELBYudZvjRPCpeSjJgtc63YlrwiDE3LH/l3Vi3cSaSJMGcbaqmILJiCyk1U9BQOrt6hWpHNlKfnsqXPmS3hc7BJv5R59MxCjT1HKPATlxXf30sbAOlaEUrDpCs/muLl7HTzORFZmS1nI63eyJMPgS6AHYa3yAB7sEmfEfTjdSmr8E655oH8Bi3O4wjz2Wl8yKV0EIusqkNHPmpsK X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1911f3e0-9c4b-4acd-694c-08d94e9e1d9a X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2021 12:25:25.9507 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KW7Pl2phSfKBAZGblTEvWw4PBwjTWfnJv3AZeYdCU+i253aaInvGL2ORI24mWiNCW3EMP74Guoo4i9cl8nQsQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7764 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210724_052529_090680_5D9AA80B X-CRM114-Status: GOOD ( 19.11 ) X-Spam-Score: -2.5 (--) 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 the ACLINT library to support separate base addresses for MTIME and MTIMECMP registers. Signed-off-by: Anup Patel --- include/sbi_utils/timer/aclint_mtimer.h | 19 ++++-- lib/utils/timer/aclint_mtimer.c | 77 +++++++++++++++++++------ lib/utils/timer/fdt_timer_mtimer.c [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.141.245 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches 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 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay 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 the ACLINT library to support separate base addresses for MTIME and MTIMECMP registers. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi_utils/timer/aclint_mtimer.h | 19 ++++-- lib/utils/timer/aclint_mtimer.c | 77 +++++++++++++++++++------ lib/utils/timer/fdt_timer_mtimer.c | 16 +++-- platform/fpga/ariane/platform.c | 8 ++- platform/fpga/openpiton/platform.c | 13 ++++- platform/kendryte/k210/platform.c | 8 ++- platform/nuclei/ux600/platform.c | 8 ++- platform/template/platform.c | 8 ++- 8 files changed, 116 insertions(+), 41 deletions(-) diff --git a/include/sbi_utils/timer/aclint_mtimer.h b/include/sbi_utils/timer/aclint_mtimer.h index 62aa086..54eb238 100644 --- a/include/sbi_utils/timer/aclint_mtimer.h +++ b/include/sbi_utils/timer/aclint_mtimer.h @@ -12,16 +12,25 @@ #include -#define ACLINT_MTIMER_ALIGN 0x1000 -#define ACLINT_MTIMER_SIZE 0x8000 -#define ACLINT_MTIMER_MAX_HARTS 4095 +#define ACLINT_MTIME_ALIGN 0x8 +#define ACLINT_MTIMECMP_ALIGN 0x8 +#define ACLINT_MTIMER_MAX_HARTS 4095 + +#define ACLINT_DEFAULT_MTIME_OFFSET 0x7ff8 +#define ACLINT_DEFAULT_MTIME_SIZE 0x8 +#define ACLINT_DEFAULT_MTIMECMP_OFFSET 0x0000 +#define ACLINT_DEFAULT_MTIMECMP_SIZE 0x7ff8 +#define ACLINT_DEFAULT_MTIMER_SIZE 0x8000 +#define ACLINT_DEFAULT_MTIMER_ALIGN 0x1000 #define CLINT_MTIMER_OFFSET 0x4000 struct aclint_mtimer_data { /* Public details */ - unsigned long addr; - unsigned long size; + unsigned long mtime_addr; + unsigned long mtime_size; + unsigned long mtimecmp_addr; + unsigned long mtimecmp_size; u32 first_hartid; u32 hart_count; bool has_64bit_mmio; diff --git a/lib/utils/timer/aclint_mtimer.c b/lib/utils/timer/aclint_mtimer.c index 41b0290..ebc9300 100644 --- a/lib/utils/timer/aclint_mtimer.c +++ b/lib/utils/timer/aclint_mtimer.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -17,9 +18,6 @@ #include #include -#define MTIMER_CMP_OFF 0x0000 -#define MTIMER_VAL_OFF 0x7ff8 - static struct aclint_mtimer_data *mtimer_hartid2data[SBI_HARTMASK_MAX_BITS]; #if __riscv_xlen != 32 @@ -56,7 +54,7 @@ static void mtimer_time_wr32(bool timecmp, u64 value, volatile u64 *addr) static u64 mtimer_value(void) { struct aclint_mtimer_data *mt = mtimer_hartid2data[current_hartid()]; - u64 *time_val = ((void *)mt->addr) + MTIMER_VAL_OFF; + u64 *time_val = (void *)mt->mtime_addr; /* Read MTIMER Time Value */ return mt->time_rd(time_val) + mt->time_delta; @@ -66,7 +64,7 @@ static void mtimer_event_stop(void) { u32 target_hart = current_hartid(); struct aclint_mtimer_data *mt = mtimer_hartid2data[target_hart]; - u64 *time_cmp = (void *)mt->addr + MTIMER_CMP_OFF; + u64 *time_cmp = (void *)mt->mtimecmp_addr; /* Clear MTIMER Time Compare */ mt->time_wr(true, -1ULL, &time_cmp[target_hart - mt->first_hartid]); @@ -76,7 +74,7 @@ static void mtimer_event_start(u64 next_event) { u32 target_hart = current_hartid(); struct aclint_mtimer_data *mt = mtimer_hartid2data[target_hart]; - u64 *time_cmp = (void *)mt->addr + MTIMER_CMP_OFF; + u64 *time_cmp = (void *)mt->mtimecmp_addr; /* Program MTIMER Time Compare */ mt->time_wr(true, next_event - mt->time_delta, @@ -111,8 +109,8 @@ int aclint_mtimer_warm_init(void) */ if (mt->time_delta_reference) { reference = mt->time_delta_reference; - mt_time_val = (void *)mt->addr + MTIMER_VAL_OFF; - ref_time_val = (void *)reference->addr + MTIMER_VAL_OFF; + mt_time_val = (void *)mt->mtime_addr; + ref_time_val = (void *)reference->mtime_addr; if (!atomic_raw_xchg_ulong(&mt->time_delta_computed, 1)) { v1 = mt->time_rd(mt_time_val); mv = reference->time_rd(ref_time_val); @@ -122,24 +120,53 @@ int aclint_mtimer_warm_init(void) } /* Clear Time Compare */ - mt_time_cmp = (void *)mt->addr + MTIMER_CMP_OFF; + mt_time_cmp = (void *)mt->mtimecmp_addr; mt->time_wr(true, -1ULL, &mt_time_cmp[target_hart - mt->first_hartid]); return 0; } +static int aclint_mtimer_add_regions(unsigned long addr, unsigned long size) +{ + int rc; + unsigned long pos, end, rsize; + struct sbi_domain_memregion reg; + + pos = addr; + end = addr + size; + while (pos < end) { + rsize = pos & (ACLINT_DEFAULT_MTIMER_ALIGN - 1); + if (rsize) + rsize = 1UL << __ffs(pos); + else + rsize = ((end - pos) < ACLINT_DEFAULT_MTIMER_ALIGN) ? + (end - pos) : ACLINT_DEFAULT_MTIMER_ALIGN; + + sbi_domain_memregion_init(pos, rsize, + SBI_DOMAIN_MEMREGION_MMIO, ®); + rc = sbi_domain_root_add_memregion(®); + if (rc) + return rc; + pos += rsize; + } + + return 0; +} + int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt, struct aclint_mtimer_data *reference) { u32 i; int rc; - unsigned long pos, region_size; - struct sbi_domain_memregion reg; /* Sanity checks */ - if (!mt || (mt->addr & (ACLINT_MTIMER_ALIGN - 1)) || - (mt->size < ACLINT_MTIMER_SIZE) || + if (!mt || !mt->mtime_size || + (mt->hart_count && !mt->mtimecmp_size) || + (mt->mtime_addr & (ACLINT_MTIME_ALIGN - 1)) || + (mt->mtime_size & (ACLINT_MTIME_ALIGN - 1)) || + (mt->mtimecmp_addr & (ACLINT_MTIMECMP_ALIGN - 1)) || + (mt->mtimecmp_size & (ACLINT_MTIMECMP_ALIGN - 1)) || (mt->first_hartid >= SBI_HARTMASK_MAX_BITS) || (mt->hart_count > ACLINT_MTIMER_MAX_HARTS)) return SBI_EINVAL; @@ -164,12 +191,24 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt, mtimer_hartid2data[mt->first_hartid + i] = mt; /* Add MTIMER regions to the root domain */ - for (pos = 0; pos < mt->size; pos += ACLINT_MTIMER_ALIGN) { - region_size = ((mt->size - pos) < ACLINT_MTIMER_ALIGN) ? - (mt->size - pos) : ACLINT_MTIMER_ALIGN; - sbi_domain_memregion_init(mt->addr + pos, region_size, - SBI_DOMAIN_MEMREGION_MMIO, ®); - rc = sbi_domain_root_add_memregion(®); + if (mt->mtime_addr == (mt->mtimecmp_addr + mt->mtimecmp_size)) { + rc = aclint_mtimer_add_regions(mt->mtimecmp_addr, + mt->mtime_size + mt->mtimecmp_size); + if (rc) + return rc; + } else if (mt->mtimecmp_addr == (mt->mtime_addr + mt->mtime_size)) { + rc = aclint_mtimer_add_regions(mt->mtime_addr, + mt->mtime_size + mt->mtimecmp_size); + if (rc) + return rc; + } else { + rc = aclint_mtimer_add_regions(mt->mtime_addr, + mt->mtime_size); + if (rc) + return rc; + + rc = aclint_mtimer_add_regions(mt->mtimecmp_addr, + mt->mtimecmp_size); if (rc) return rc; } diff --git a/lib/utils/timer/fdt_timer_mtimer.c b/lib/utils/timer/fdt_timer_mtimer.c index 4907428..3f830ad 100644 --- a/lib/utils/timer/fdt_timer_mtimer.c +++ b/lib/utils/timer/fdt_timer_mtimer.c @@ -22,7 +22,7 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff, const struct fdt_match *match) { int rc; - unsigned long offset; + unsigned long offset, addr, size; struct aclint_mtimer_data *mt, *mtmaster = NULL; if (MTIMER_MAX_NR <= mtimer_count) @@ -31,19 +31,23 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff, if (0 < mtimer_count) mtmaster = &mtimer[0]; - rc = fdt_parse_aclint_node(fdt, nodeoff, true, &mt->addr, &mt->size, + rc = fdt_parse_aclint_node(fdt, nodeoff, true, &addr, &size, &mt->first_hartid, &mt->hart_count); if (rc) return rc; mt->has_64bit_mmio = true; + mt->mtimecmp_addr = addr + ACLINT_DEFAULT_MTIMECMP_OFFSET; + mt->mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE; + mt->mtime_addr = addr + ACLINT_DEFAULT_MTIME_OFFSET; + mt->mtime_size = size - mt->mtimecmp_size; + if (match->data) { /* Adjust MTIMER address and size for CLINT device */ offset = *((unsigned long *)match->data); - mt->addr += offset; - if ((mt->size - offset) < ACLINT_MTIMER_SIZE) - return SBI_EINVAL; - mt->size -= offset; + mt->mtime_addr += offset; + mt->mtimecmp_addr += offset; + mt->mtime_size -= offset; /* Parse additional CLINT properties */ if (fdt_getprop(fdt, nodeoff, "clint,has-no-64bit-mmio", &rc)) mt->has_64bit_mmio = false; diff --git a/platform/fpga/ariane/platform.c b/platform/fpga/ariane/platform.c index 0b47aa0..58a46c0 100644 --- a/platform/fpga/ariane/platform.c +++ b/platform/fpga/ariane/platform.c @@ -44,8 +44,12 @@ static struct aclint_mswi_data mswi = { }; static struct aclint_mtimer_data mtimer = { - .addr = ARIANE_ACLINT_MTIMER_ADDR, - .size = ACLINT_MTIMER_SIZE, + .mtime_addr = ARIANE_ACLINT_MTIMER_ADDR + + ACLINT_DEFAULT_MTIME_OFFSET, + .mtime_size = ACLINT_DEFAULT_MTIME_SIZE, + .mtimecmp_addr = ARIANE_ACLINT_MTIMER_ADDR + + ACLINT_DEFAULT_MTIMECMP_OFFSET, + .mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE, .first_hartid = 0, .hart_count = ARIANE_HART_COUNT, .has_64bit_mmio = TRUE, diff --git a/platform/fpga/openpiton/platform.c b/platform/fpga/openpiton/platform.c index 57ec21b..bcfe7eb 100644 --- a/platform/fpga/openpiton/platform.c +++ b/platform/fpga/openpiton/platform.c @@ -49,8 +49,12 @@ static struct aclint_mswi_data mswi = { }; static struct aclint_mtimer_data mtimer = { - .addr = OPENPITON_DEFAULT_ACLINT_MTIMER_ADDR, - .size = ACLINT_MTIMER_SIZE, + .mtime_addr = OPENPITON_DEFAULT_ACLINT_MTIMER_ADDR + + ACLINT_DEFAULT_MTIME_OFFSET, + .mtime_size = ACLINT_DEFAULT_MTIME_SIZE, + .mtimecmp_addr = OPENPITON_DEFAULT_ACLINT_MTIMER_ADDR + + ACLINT_DEFAULT_MTIMECMP_OFFSET, + .mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE, .first_hartid = 0, .hart_count = OPENPITON_DEFAULT_HART_COUNT, .has_64bit_mmio = TRUE, @@ -82,7 +86,10 @@ static int openpiton_early_init(bool cold_boot) rc = fdt_parse_compat_addr(fdt, &clint_addr, "riscv,clint0"); if (!rc) { mswi.addr = clint_addr; - mtimer.addr = clint_addr + CLINT_MTIMER_OFFSET; + mtimer.mtime_addr = clint_addr + CLINT_MTIMER_OFFSET + + ACLINT_DEFAULT_MTIME_OFFSET; + mtimer.mtimecmp_addr = clint_addr + CLINT_MTIMER_OFFSET + + ACLINT_DEFAULT_MTIMECMP_OFFSET; } return 0; diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 55c4b1e..ee4c223 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -42,8 +42,12 @@ static struct aclint_mswi_data mswi = { }; static struct aclint_mtimer_data mtimer = { - .addr = K210_ACLINT_MTIMER_ADDR, - .size = ACLINT_MTIMER_SIZE, + .mtime_addr = K210_ACLINT_MTIMER_ADDR + + ACLINT_DEFAULT_MTIME_OFFSET, + .mtime_size = ACLINT_DEFAULT_MTIME_SIZE, + .mtimecmp_addr = K210_ACLINT_MTIMER_ADDR + + ACLINT_DEFAULT_MTIMECMP_OFFSET, + .mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE, .first_hartid = 0, .hart_count = K210_HART_COUNT, .has_64bit_mmio = TRUE, diff --git a/platform/nuclei/ux600/platform.c b/platform/nuclei/ux600/platform.c index 22ca4c9..ab0becc 100644 --- a/platform/nuclei/ux600/platform.c +++ b/platform/nuclei/ux600/platform.c @@ -74,8 +74,12 @@ static struct aclint_mswi_data mswi = { }; static struct aclint_mtimer_data mtimer = { - .addr = UX600_ACLINT_MTIMER_ADDR, - .size = ACLINT_MTIMER_SIZE, + .mtime_addr = UX600_ACLINT_MTIMER_ADDR + + ACLINT_DEFAULT_MTIME_OFFSET, + .mtime_size = ACLINT_DEFAULT_MTIME_SIZE, + .mtimecmp_addr = UX600_ACLINT_MTIMER_ADDR + + ACLINT_DEFAULT_MTIMECMP_OFFSET, + .mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE, .first_hartid = 0, .hart_count = UX600_HART_COUNT, .has_64bit_mmio = TRUE, diff --git a/platform/template/platform.c b/platform/template/platform.c index 3f09d98..4528822 100644 --- a/platform/template/platform.c +++ b/platform/template/platform.c @@ -43,8 +43,12 @@ static struct aclint_mswi_data mswi = { }; static struct aclint_mtimer_data mtimer = { - .addr = PLATFORM_ACLINT_MTIMER_ADDR, - .size = ACLINT_MTIMER_SIZE, + .mtime_addr = PLATFORM_ACLINT_MTIMER_ADDR + + ACLINT_DEFAULT_MTIME_OFFSET, + .mtime_size = ACLINT_DEFAULT_MTIME_SIZE, + .mtimecmp_addr = PLATFORM_ACLINT_MTIMER_ADDR + + ACLINT_DEFAULT_MTIMECMP_OFFSET, + .mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE, .first_hartid = 0, .hart_count = PLATFORM_HART_COUNT, .has_64bit_mmio = TRUE,