Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp522833imm; Thu, 26 Jul 2018 07:39:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcVR52e/ymNPZgrZdnqnBy440hN2VZ4utNDYV+Qab+/NIHJdioUoUTB71NL1MDf8YBO3f3F X-Received: by 2002:a17:902:d90f:: with SMTP id c15-v6mr2203753plz.65.1532615941056; Thu, 26 Jul 2018 07:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532615941; cv=none; d=google.com; s=arc-20160816; b=mPDx2bLGM12gxx0si2H+6ixHqXtWjjmUu6qkNq7WQK44Uh8eoOaRkCFM1ia7QgrPXW qTbSbYuTx3K5YezukBi+dL/RwJGNjvavXLpIhV1rh9//Yl2aZZvFGJVWZvzrOyow10j1 5RAo1gthcLMaPlfNdBviv8S9tqSYz6Vx3uNNC04qykJNte+PWnYeYYeCS0ef67ifDqZQ V/cdFIwwoAL9od6D7uZhFacCTfdvCoCpzLmJmmTmkpaBUixEZDyW49Nqh8o2yd0cK3ZT 2so01p40RhFIMBth8UYhy6UeYKacOyYI76cZM+QAZBsyGLlFUhPdZ43Fw75Z8FcyIleb 17PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Y9L6sVyCND3pCUBTkFzMbfyGpy1+MFBmetZ8xMn3P9k=; b=S0ivwzVQV6EddwmH3O3Af22PxCOeNjLC5WgmeDqmEJHZTCIaCkPgzyIQDgODhmUhGu ZJYsLl692ycN8SADm6HkpVflXoCEYhmwZ9Ocq/id+KzyPk1tVbqe3kbBKOeGkDmRpmZ0 26dgeHRG6L5qRlO61aHePZ1KMRpZqQUEgNK82cIiVEMW7JMBUBNCKsju8CXQDRZ8ce49 p4iWmL1nw1H9cAdgby0oQz6TdiS7cZHG6ik1659qeKhQNRTWRRLmqiYpU7EYBJDDj/XJ 4NpR8D6JCeIUbOVsOsY9ILhZdf5CG1/MFWU5OJ7nUqpg6QjpgTzyxHs/qS2RHpxSFKI4 ew6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PSTCLHHa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o19-v6si1524476pgl.212.2018.07.26.07.38.46; Thu, 26 Jul 2018 07:39:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PSTCLHHa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731563AbeGZPy6 (ORCPT + 99 others); Thu, 26 Jul 2018 11:54:58 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:57760 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729506AbeGZPy5 (ORCPT ); Thu, 26 Jul 2018 11:54:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Y9L6sVyCND3pCUBTkFzMbfyGpy1+MFBmetZ8xMn3P9k=; b=PSTCLHHat97cO2Pkyn3kKwypV F8xZus8U/PDiAYtMGPn1wAFbRfBD1vo9uNeJhCiH5EmQNyXsI6qUE4RysGu/GaEAys2MTs27P6CzN 5BYZwEhsncOSQh3NSSz6lBYo5+RyPOUHp2c9DNkSUZRSjKYfAVnZJfsxkwUbzXEAzcwP0QTBnsLrk qNTpqG1pRMCospGex3jb6hNuIB5ZdIQBg0PdX5L1ZeLYFQE0pmKinjgbVKjQg0rP/tbkJCohp14d3 iY7EBrs9mmMpKrahARInm6BPiI6lYnTLhKdn7lrrO69sqB8vyPvNmDGFJ9cel2Z9pF3XZDv/lrWV3 utW8bXAPQ==; Received: from 213-225-8-157.nat.highway.a1.net ([213.225.8.157] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fihOi-0005mO-5N; Thu, 26 Jul 2018 14:37:44 +0000 From: Christoph Hellwig To: tglx@linutronix.de, palmer@sifive.com, jason@lakedaemon.net, marc.zyngier@arm.com, robh+dt@kernel.org, mark.rutland@arm.com Cc: anup@brainfault.org, atish.patra@wdc.com, devicetree@vger.kernel.org, aou@eecs.berkeley.edu, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, shorne@gmail.com Subject: [PATCH 5/9] RISC-V: implement low-level interrupt handling Date: Thu, 26 Jul 2018 16:37:19 +0200 Message-Id: <20180726143723.16585-6-hch@lst.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180726143723.16585-1-hch@lst.de> References: <20180726143723.16585-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for a routine that dispatches exceptions with the interrupt flags set to either the IPI or irqdomain code (and the clock source in the future). Loosely based on the irq-riscv-int.c irqchip driver from the RISC-V tree. Signed-off-by: Christoph Hellwig --- arch/riscv/kernel/entry.S | 4 +-- arch/riscv/kernel/irq.c | 52 ++++++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 9aaf6c986771..fa2c08e3c05e 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -168,8 +168,8 @@ ENTRY(handle_exception) /* Handle interrupts */ move a0, sp /* pt_regs */ - REG_L a1, handle_arch_irq - jr a1 + move a1, s4 /* scause */ + tail do_IRQ 1: /* Exceptions run with interrupts enabled */ csrs sstatus, SR_SIE diff --git a/arch/riscv/kernel/irq.c b/arch/riscv/kernel/irq.c index 7bcdaed15703..ab5f3e22c7cc 100644 --- a/arch/riscv/kernel/irq.c +++ b/arch/riscv/kernel/irq.c @@ -1,21 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2012 Regents of the University of California * Copyright (C) 2017 SiFive - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Copyright (C) 2018 Christoph Hellwig */ #include #include #include +/* + * Possible interrupt causes: + */ +#define INTERRUPT_CAUSE_SOFTWARE 1 +#define INTERRUPT_CAUSE_TIMER 5 +#define INTERRUPT_CAUSE_EXTERNAL 9 + +/* + * The high order bit of the trap cause register is always set for + * interrupts, which allows us to differentiate them from exceptions + * quickly. The INTERRUPT_CAUSE_* macros don't contain that bit, so we + * need to mask it off. + */ +#define INTERRUPT_CAUSE_FLAG (1UL << (__riscv_xlen - 1)) + +asmlinkage void __irq_entry do_IRQ(struct pt_regs *regs, unsigned long cause) +{ + struct pt_regs *old_regs = set_irq_regs(regs); + + irq_enter(); + switch (cause & ~INTERRUPT_CAUSE_FLAG) { +#ifdef CONFIG_SMP + case INTERRUPT_CAUSE_SOFTWARE: + /* + * We only use software interrupts to pass IPIs, so if a non-SMP + * system gets one, then we don't know what to do. + */ + riscv_software_interrupt(); + break; +#endif + case INTERRUPT_CAUSE_EXTERNAL: + handle_arch_irq(regs); + break; + default: + panic("unexpected interrupt cause"); + } + irq_exit(); + + set_irq_regs(old_regs); +} + void __init init_IRQ(void) { irqchip_init(); -- 2.18.0