From patchwork Thu Oct 7 12:36:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12541759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CEFEC433FE for ; Thu, 7 Oct 2021 12:38:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CBACC61075 for ; Thu, 7 Oct 2021 12:38:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CBACC61075 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=pv9s5rEPquEZCFBaEXNgs9R8CxfAtkRV5ODMvLOD9tM=; b=tMP2AjG+nusSFB c4jNOGs09Uf4cP/aC692WpRskXno+/vUiVCoIZsUC3sghYpuTcDIutyru5p9p5Yll/x0th3izvod7 SAx7+YAhChDqhOicpvez55gQuA6HEfRyagfQKfsOrZ+8+QrLQjB91vEzTXKADJ6mjzwsTdAziAb7c TVd74c4YFw4AicjhHNYU/m7xzlUOTriNp26zrGpOHezrJRciAcMj2570rD/6uFHT/P5+xVjyguA6M O4eGntXu2/s2YGz6DUqRae7PtHqzX/YC1+XjNjGm3RnDjHDbFzFsEH9sHkrjB9kx42HHSqma7vkN3 op/Bm1f0am69k67SprmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYSeo-00HIQe-CD; Thu, 07 Oct 2021 12:37:54 +0000 Received: from esa3.hgst.iphmx.com ([216.71.153.141]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYSeX-00HI4w-Sv for linux-riscv@lists.infradead.org; Thu, 07 Oct 2021 12:37:39 +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=1633610257; x=1665146257; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=YI6W+/n9aAzWP4LzqzPEHrZxCONtaCdEtKPj+E5HvVI=; b=jC7KiDUMilZ9J4jHbHn8JDXVQPEqB4xNaT66Hp/0vTlV9qMJ4wpQ7QCW WSzsVtxud5esS5h1b0whD4GNjW99WbTydmNHhEKdcrvRRIJitH5PJalDS Fpnq0+5Q+pXgBhdjP7R6rg8j8ihUeaowOO20pQ/hOq4fqAPCgTpg/zt1d C6/tIbUB5NAgH924tOa8KH3hHNOh5e6a+s+8AK665LqKUnd6L2gDyC+NA c3qyy86XRErJ4UHEAv5gf7zj6aXYs7DpLLAjFHX7rN8pmW4DFKXSzmGEd 7jLjWY9RKWOXP1zY7I7kH3CSpU8trhsH70ox+Smfy6USlNhISIL3JKAGR A==; X-IronPort-AV: E=Sophos;i="5.85,354,1624291200"; d="scan'208";a="186926274" Received: from mail-bn8nam12lp2170.outbound.protection.outlook.com (HELO NAM12-BN8-obe.outbound.protection.outlook.com) ([104.47.55.170]) by ob1.hgst.iphmx.com with ESMTP; 07 Oct 2021 20:37:35 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SAicOrwxGWcHSzKol4F0euGjGPEAdzSU4O4BOucK5DJni88lqexxeleuYaXsN6WvpcfCFuvR+nthdQavHDrENpXJPaewdjYad82pMrQfCusA5kGs+moudb+9kO+owk0JNAUJgBNA1ursWjCEuRIsu9gxEhbeOzxy/mVOwq7U08bFnFVj5cXObAAKYpWy9/8K7z1K5osnq7GBv4b+Zap1JrNnIP3PwibHBo/M1l/KlE7bgiZ8tTeT3dX9uqeYhnwq1k4hyxs4hAbV3RlHGoZ2x29rqkw18vcmI+hNpVE99/Y14mjVxU5Xsej4tHLp5Oq9BPvDzHaaF3BT5abCGFkqYQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EEv5oCfdSg/2nOVTlC7u6t7+ljXv5IBn9INTVEpyUxc=; b=ZFs3E87bihOo+6JCyDoWvDu43qt8uBQXuATpoHpB0xAnhFJRY6At4LlWpJmmBA0DlXmtCS09GLwIBP8WEjlBP6HnWFt7PzDD0xCemdydYAXWg/8wVwbTR2EVeT7mYlGwIV+Ti2sovt9cVxDV9u1KS4hkSl2hcOSj2rzlJnFfvmkTMF7OqcjpAy3gsqzwxmUogdPZTv4VMdx8kgLT2JyCTBb0c+Rfqr6Uv0XmplOEI6TE+ALsJf9JtgrZFhjz/Tz85gYW8+0u+9rNQ0mA0wQ3ldfrOzMZc0xQtoGviL1tjBwuTV8A/1xlTPxlnntiS/otNyxerewT3ExYv9GzITYHJA== 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=EEv5oCfdSg/2nOVTlC7u6t7+ljXv5IBn9INTVEpyUxc=; b=sk77PDGIw/JcY93KfyjxaayZeadZL423wLl2iNq6YZZChyGYvJRWN0b9QhcZ5as0wKNOp0uVq+RiW0qzFNfNfIiGAzUqIyDdRvlZFrLvAfPvu4rpbDUoBGRywM5nwxyP6WBbC3DCPPDIu4DEgGAd2TVgsEd3X1T7arClBxiftJU= Authentication-Results: dabbelt.com; dkim=none (message not signed) header.d=none;dabbelt.com; dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB7892.namprd04.prod.outlook.com (2603:10b6:303:13a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18; Thu, 7 Oct 2021 12:37:34 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4587.020; Thu, 7 Oct 2021 12:37:34 +0000 From: Anup Patel To: Palmer Dabbelt , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Marc Zyngier , Daniel Lezcano , Rob Herring Cc: Atish Patra , Alistair Francis , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Anup Patel , Bin Meng Subject: [RFC PATCH v4 09/10] clocksource: clint: Add support for ACLINT MTIMER device Date: Thu, 7 Oct 2021 18:06:31 +0530 Message-Id: <20211007123632.697666-10-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211007123632.697666-1-anup.patel@wdc.com> References: <20211007123632.697666-1-anup.patel@wdc.com> X-ClientProxiedBy: MAXPR0101CA0045.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (171.61.64.222) by MAXPR0101CA0045.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18 via Frontend Transport; Thu, 7 Oct 2021 12:37:31 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a3b128a6-2954-48d7-6268-08d9898f3cf4 X-MS-TrafficTypeDiagnostic: CO6PR04MB7892: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:632; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZwI8PB7wPyoNzkySgRx7XX9UIcm/tXGyav7ivhMV6ilKcAPfSH71LQfSrrvBB0DZQS5OygvAGayE7Eid0e0j6qFjYqu0X1x0d0gQZvk6xO5hGnZ/GX1vB1cy4mEIf07D8cLuONt0JIzXOlGFoID3hacDk6r0uKSO1JoIh5Z8KA7L83cyOLNeMUcfHGvfMjKiSpcdDIWoyvqQD7GQZSsYrDH3xAalWMvFy2Fby+j0bavleUdNHVA0RdVNSonTH9cSbWxEt5FKkQQJUL2HygQJ56Ko4HXihSK6D7VLc4iSH2YxV8Uv8CtjM5UajT3BBz5cYE/VFRbMGowJJ24nWAro8tnPkFkWGv3/lYG5dhRjr8avMYAHqmzywkpb8bU/RPFOdWk1SXo2uRva5mbqCKhkmU+IGVKkjax9/9YkxqO9SK/NElgP26ZvR3hdugXkBVsmV04bqAQs0H+K2Ot+Mw8n8Cdqb8/5JAVx4zZCle5rA/7He8U+x/IHM7LGWe9rlbrEBXtF31+4HqgQVr9qV+VgWQYQxr0FDk7tjKoDpqCL+MD5ar0vR7PhmO8yzxU15ZbdambIG2NJPD0HMdT2ysiTwiRM0cgY/kQqo3cmKnLFgbG2hqi0hXz/f9T69wXEoOCPPW0nXErJJshsGyH+2XlnMtz9rvsNpA37+aTzYVmt2LSAMuOCB6GBnSxGzlI62oheGjwrPCBD40TUq8TMA4EWAQ== 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)(54906003)(5660300002)(8676002)(110136005)(316002)(8936002)(508600001)(8886007)(4326008)(36756003)(186003)(26005)(2906002)(38100700002)(66946007)(44832011)(1076003)(55016002)(956004)(2616005)(52116002)(66476007)(66556008)(7696005)(83380400001)(7416002)(86362001)(38350700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XNGiyyP1h5bEmdMxOB0mxI+zGM6GwG/6iIBKLu65KORRQwxu8Cz3u0UosqvJBmluJADH0NyZ84e6pmpkGK68o+2vGHK5wjjjbMk7V2JDDWrvFw7YGxAuMLkQUetfyZP3WhokiMXANUG+4mNKy3Qj5XF1bxxMTqADWKmd35qRwhry0vh+1jKX2dl0MvYeyEn53hfuwbnOzsRWToyXuNmmju32WZ8QZabBGhY8YRhntWp1dKK7R5wOlI+TXkxwpa+V0ubJl+Wync3PvtTmGK5V4mAq8c7umbL03GfkeLsJPtv5kwaSJS7iY55ap0GlJleHrzkh7RMPoO3KSxB07WggrTTRf/RgXwlYYEoSBQjnsUSJfXLBMxXELG5EDnDKz7UjvcPAKoQ4mWofuDBmDdiOjy5YUbJh83kwVX3lpE3eH/BCvaEy6Zrbid1GKcKexVnHXTF0oV+tDZaVcdys8iLNE6cO28TgSAzOGZjrlcANrpSOJa48SLtDr8D1daIF4LiCjDKH2+WYvxNUJJI2r5poGU1z5CjMZStrnCbhU9itoNOWAqcd1n7r2BU3bk/bn2zz+n18YYdiAhMuaGEeqF9mYQBaTmIkuQwJ5Zl2gu82U1TQHlTusaBCL7jTSHne4D1G1CEImkn67xmnkAC7mQ5NqemyFHF4dho1iGuVL7mpbypoO+wjOhbUtK4KtsgaP9d3q+49QCR8uwQA52CvLeYfCejsgu7acW3NxvP8WxYRpaVKDyX2tA3ABmFknpJTJF9yEaskay/qDT7Lb7GCOM9Vea2AgQxt/9IE99zoTwc1NQI3a9xYchOe05OL8BIhbGwxnJ3Lz64TOAWQGanlbrVgYpkfmCHMe6gleahKXZRV0IdeeEPdUKfjfjwoykOPZk2nem9tvigYx0pWWz/my/VchO1cqGxxm4msdrnTP0q957cx7wfo0hsUCgpZEhr7ufhLnpd6RvykDr5qIKlkkZiFd0fH5e+swuwb6ISIQU98EaE680lr4ci0yVmhZpQGFfX6izun8/K8hV5gek/N77t6qmO8Gb5CcAeHEwIhX00m7GbjUa9vFYPBmbBbWl66iJ8z4LU+PkY6rOoY+iZjCwiGf2Rdu7kR7frf6n44hyzmB76IWBC0CLLGgqOVG3hg8kOGS3ZN2PYe/JcN0WxnwA+VeiEGrwDSdIO6od0B4fqKIkdT8q0uCZKZPgt2K5T/d2tMazBTq+1h150eLgaprVhpi2CQrSaUbixXotoJu26LVyezGQCkTdcLvuAzn+A/RZOkbmIdkh5OZ6aspF6mw0zjThnJrETbl2dda3WziYiRTmo2ftJT/kCtL+Ybo1vXL9nv X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3b128a6-2954-48d7-6268-08d9898f3cf4 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2021 12:37:34.6589 (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: u/0sOhnm1cvHQMKKN4K0BwYA1lAmY6vVk09GHQTnK8GgDOH7SqkVajW4z2eLPUH7xdSMMlIEDt4Mlb9S+lJVCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7892 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211007_053737_993131_DE03450C X-CRM114-Status: GOOD ( 21.75 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The RISC-V ACLINT specification is a modular specification and the ACLINT MTIMER device is backward compatible with the M-mode timer functionality of the CLINT device. This patch extends the CLINT timer driver to support both CLINT device and ACLINT MTIMER device. Signed-off-by: Anup Patel Reviewed-by: Bin Meng --- drivers/clocksource/timer-clint.c | 59 ++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/drivers/clocksource/timer-clint.c b/drivers/clocksource/timer-clint.c index 3b68ed53fe4a..9d38dfce374e 100644 --- a/drivers/clocksource/timer-clint.c +++ b/drivers/clocksource/timer-clint.c @@ -2,8 +2,16 @@ /* * Copyright (C) 2020 Western Digital Corporation or its affiliates. * - * Most of the M-mode (i.e. NoMMU) RISC-V systems usually have a - * CLINT MMIO timer device. + * Most of the M-mode (i.e. NoMMU) RISC-V systems usually have a CLINT + * MMIO device which is a composite device capable of injecting M-mode + * software interrupts and M-mode timer interrupts. + * + * The RISC-V ACLINT specification is modular in nature and defines + * separate devices for M-mode software interrupt (MSWI), M-mode timer + * (MTIMER) and S-mode software interrupt (SSWI). + * + * This is a common timer driver for the CLINT device and the ACLINT + * MTIMER device. */ #define pr_fmt(fmt) "clint: " fmt @@ -17,12 +25,16 @@ #include #include #include +#include #include #include #include -#ifndef CONFIG_RISCV_M_MODE +#ifdef CONFIG_RISCV_M_MODE #include + +u64 __iomem *clint_time_val; +EXPORT_SYMBOL(clint_time_val); #endif #define CLINT_IPI_OFF 0 @@ -35,11 +47,6 @@ static u64 __iomem *clint_timer_val; static unsigned long clint_timer_freq; static unsigned int clint_timer_irq; -#ifdef CONFIG_RISCV_M_MODE -u64 __iomem *clint_time_val; -EXPORT_SYMBOL(clint_time_val); -#endif - #ifdef CONFIG_64BIT #define clint_get_cycles() readq_relaxed(clint_timer_val) #else @@ -129,8 +136,10 @@ static int __init clint_timer_init_dt(struct device_node *np) { int rc; u32 i, nr_irqs; - void __iomem *base; + void __iomem *base = NULL; + void __iomem *base1 = NULL; struct of_phandle_args oirq; + bool is_aclint = of_device_is_compatible(np, "riscv,aclint-mtimer"); /* * Ensure that CLINT device interrupts are either RV_IRQ_TIMER or @@ -170,8 +179,19 @@ static int __init clint_timer_init_dt(struct device_node *np) return -ENODEV; } - clint_timer_cmp = base + CLINT_TIMER_CMP_OFF; - clint_timer_val = base + CLINT_TIMER_VAL_OFF; + if (is_aclint) { + clint_timer_val = base; + base1 = of_iomap(np, 1); + if (!base1) { + rc = -ENODEV; + pr_err("%pOFP: could not map registers\n", np); + goto fail_iounmap; + } + clint_timer_cmp = base1; + } else { + clint_timer_cmp = base + CLINT_TIMER_CMP_OFF; + clint_timer_val = base + CLINT_TIMER_VAL_OFF; + } clint_timer_freq = riscv_timebase; #ifdef CONFIG_RISCV_M_MODE @@ -208,14 +228,29 @@ static int __init clint_timer_init_dt(struct device_node *np) goto fail_free_irq; } + if (!is_aclint) { + rc = aclint_swi_init(np, base + CLINT_IPI_OFF); + if (rc) { + pr_err("%pOFP: aclint swi init failed [%d]\n", + np, rc); + goto fail_remove_cpuhp; + } + } + return 0; +fail_remove_cpuhp: + cpuhp_remove_state(CPUHP_AP_CLINT_TIMER_STARTING); fail_free_irq: free_irq(clint_timer_irq, &clint_clock_event); fail_iounmap: - iounmap(base); + if (base1) + iounmap(base1); + if (base) + iounmap(base); return rc; } TIMER_OF_DECLARE(clint_timer, "riscv,clint0", clint_timer_init_dt); TIMER_OF_DECLARE(clint_timer1, "sifive,clint0", clint_timer_init_dt); +TIMER_OF_DECLARE(clint_timer2, "riscv,aclint-mtimer", clint_timer_init_dt);