[PATCH 1/2] asm-generic: Add a generic set_handle_irq
From: Palmer Dabbelt
Date: Thu Jan 18 2018 - 11:10:37 EST
From: Palmer Dabbelt <palmer@xxxxxxxxxxx>
I've copied this from arm64, but it appears to be the same code that's
in arm and openrisc. I wanted to use it for RISC-V's interrupt handler
as well, so despite this only being a handful of lines of code it seems
worth having a generic version -- if it existed when we created our
interrupt controller then maybe we would have just started with the
generic version.
This patch alone is just dead code, further patches actually use this
infrastructure.
Signed-off-by: Palmer Dabbelt <palmer@xxxxxxxxxxx>
---
include/asm-generic/handle_irq.h | 28 ++++++++++++++++++++++++++++
lib/Kconfig | 3 +++
lib/Makefile | 2 ++
lib/handle_irq.c | 26 ++++++++++++++++++++++++++
4 files changed, 59 insertions(+)
create mode 100644 include/asm-generic/handle_irq.h
create mode 100644 lib/handle_irq.c
diff --git a/include/asm-generic/handle_irq.h b/include/asm-generic/handle_irq.h
new file mode 100644
index 000000000000..2865fa12993a
--- /dev/null
+++ b/include/asm-generic/handle_irq.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 1992 Linus Torvalds
+ * Modifications for ARM processor Copyright (C) 1995-2000 Russell King.
+ * Support for Dynamic Tick Timer Copyright (C) 2004-2005 Nokia Corporation.
+ * Dynamic Tick Timer written by Tony Lindgren <tony@xxxxxxxxxxx> and
+ * Tuukka Tikkanen <tuukka.tikkanen@xxxxxxxxxxxxxx>.
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2017 SiFive, Inc
+ */
+
+#ifndef __ASM_GENERIC_IRQ_HANDLER_H
+#define __ASM_GENERIC_IRQ_HANDLER_H
+
+#include <asm/ptrace.h>
+#include <linux/module.h>
+
+/*
+ * Registers a generic IRQ handling function as the top-level IRQ handler in
+ * the system, which is generally the first C code called from an assembly
+ * architecture-specific interrupt handler.
+ *
+ * Returns 0 on success, or -EBUSY if an IRQ handler has already been
+ * registered.
+ */
+int __init set_handle_irq(void (*handle_irq)(struct pt_regs *));
+
+#endif
diff --git a/lib/Kconfig b/lib/Kconfig
index c5e84fbcb30b..c74469d44fdc 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -601,3 +601,6 @@ config GENERIC_CMPDI2
config GENERIC_UCMPDI2
bool
+
+config GENERIC_HANDLE_IRQ
+ bool
diff --git a/lib/Makefile b/lib/Makefile
index d11c48ec8ffd..57ae58fde821 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -258,3 +258,5 @@ obj-$(CONFIG_GENERIC_LSHRDI3) += lshrdi3.o
obj-$(CONFIG_GENERIC_MULDI3) += muldi3.o
obj-$(CONFIG_GENERIC_CMPDI2) += cmpdi2.o
obj-$(CONFIG_GENERIC_UCMPDI2) += ucmpdi2.o
+
+obj-$(CONFIG_GENERIC_HANDLE_IRQ) += handle_irq.o
diff --git a/lib/handle_irq.c b/lib/handle_irq.c
new file mode 100644
index 000000000000..e732147537f4
--- /dev/null
+++ b/lib/handle_irq.c
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 1992 Linus Torvalds
+ * Modifications for ARM processor Copyright (C) 1995-2000 Russell King.
+ * Support for Dynamic Tick Timer Copyright (C) 2004-2005 Nokia Corporation.
+ * Dynamic Tick Timer written by Tony Lindgren <tony@xxxxxxxxxxx> and
+ * Tuukka Tikkanen <tuukka.tikkanen@xxxxxxxxxxxxxx>.
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2017 SiFive, Inc
+ */
+
+#include <asm-generic/handle_irq.h>
+
+void (*handle_arch_irq)(struct pt_regs *) = NULL;
+
+int __init set_handle_irq(void (*handle_irq)(struct pt_regs *))
+{
+ if (!handle_arch_irq)
+ handle_arch_irq = handle_irq;
+
+ if (handle_arch_irq != handle_irq)
+ return -EBUSY;
+
+ return 0;
+}
+
--
2.13.6