MIPS: jump label: Add MIPS support.
authorDavid Daney <ddaney@caviumnetworks.com>
Tue, 28 Dec 2010 21:26:23 +0000 (13:26 -0800)
committerRalf Baechle <ralf@linux-mips.org>
Tue, 18 Jan 2011 18:30:24 +0000 (19:30 +0100)
In order not to be left behind, we add jump label support for MIPS.

Tested on 64-bit big endian (Octeon), and 32-bit little endian
(malta/qemu).

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
To: linux-mips@linux-mips.org
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jason Baron <jbaron@redhat.com>
Patchwork: https://patchwork.linux-mips.org/patch/1923/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/Kconfig
arch/mips/include/asm/jump_label.h [new file with mode: 0644]
arch/mips/kernel/Makefile
arch/mips/kernel/jump_label.c [new file with mode: 0644]
arch/mips/kernel/module.c

index 2106781d7473b1393285ddce2b65dd564844207f..9543040682285d035676298526b8624910c47295 100644 (file)
@@ -21,6 +21,7 @@ config MIPS
        select HAVE_DMA_API_DEBUG
        select HAVE_GENERIC_HARDIRQS
        select GENERIC_IRQ_PROBE
+       select HAVE_ARCH_JUMP_LABEL
 
 menu "Machine selection"
 
diff --git a/arch/mips/include/asm/jump_label.h b/arch/mips/include/asm/jump_label.h
new file mode 100644 (file)
index 0000000..7622ccf
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (c) 2010 Cavium Networks, Inc.
+ */
+#ifndef _ASM_MIPS_JUMP_LABEL_H
+#define _ASM_MIPS_JUMP_LABEL_H
+
+#include <linux/types.h>
+
+#ifdef __KERNEL__
+
+#define JUMP_LABEL_NOP_SIZE 4
+
+#ifdef CONFIG_64BIT
+#define WORD_INSN ".dword"
+#else
+#define WORD_INSN ".word"
+#endif
+
+#define JUMP_LABEL(key, label)                                         \
+       do {                                                            \
+               asm goto("1:\tnop\n\t"                                  \
+                       "nop\n\t"                                       \
+                       ".pushsection __jump_table,  \"a\"\n\t"         \
+                       WORD_INSN " 1b, %l[" #label "], %0\n\t"         \
+                       ".popsection\n\t"                               \
+                       : :  "i" (key) :  : label);                     \
+       } while (0)
+
+
+#endif /* __KERNEL__ */
+
+#ifdef CONFIG_64BIT
+typedef u64 jump_label_t;
+#else
+typedef u32 jump_label_t;
+#endif
+
+struct jump_entry {
+       jump_label_t code;
+       jump_label_t target;
+       jump_label_t key;
+};
+
+#endif /* _ASM_MIPS_JUMP_LABEL_H */
index 39773979ca6d4a5e569eb7634eafdd7d4eff7ae9..cedee2bcbd182c8eab8ad59aadfc0d02e1fdb79d 100644 (file)
@@ -107,4 +107,6 @@ obj-$(CONFIG_MIPS_CPUFREQ)  += cpufreq/
 
 obj-$(CONFIG_HW_PERF_EVENTS)   += perf_event.o
 
+obj-$(CONFIG_JUMP_LABEL)       += jump_label.o
+
 CPPFLAGS_vmlinux.lds           := $(KBUILD_CFLAGS)
diff --git a/arch/mips/kernel/jump_label.c b/arch/mips/kernel/jump_label.c
new file mode 100644 (file)
index 0000000..6001610
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (c) 2010 Cavium Networks, Inc.
+ */
+
+#include <linux/jump_label.h>
+#include <linux/kernel.h>
+#include <linux/memory.h>
+#include <linux/mutex.h>
+#include <linux/types.h>
+#include <linux/cpu.h>
+
+#include <asm/cacheflush.h>
+#include <asm/inst.h>
+
+#ifdef HAVE_JUMP_LABEL
+
+#define J_RANGE_MASK ((1ul << 28) - 1)
+
+void arch_jump_label_transform(struct jump_entry *e,
+                              enum jump_label_type type)
+{
+       union mips_instruction insn;
+       union mips_instruction *insn_p =
+               (union mips_instruction *)(unsigned long)e->code;
+
+       /* Jump only works within a 256MB aligned region. */
+       BUG_ON((e->target & ~J_RANGE_MASK) != (e->code & ~J_RANGE_MASK));
+
+       /* Target must have 4 byte alignment. */
+       BUG_ON((e->target & 3) != 0);
+
+       if (type == JUMP_LABEL_ENABLE) {
+               insn.j_format.opcode = j_op;
+               insn.j_format.target = (e->target & J_RANGE_MASK) >> 2;
+       } else {
+               insn.word = 0; /* nop */
+       }
+
+       get_online_cpus();
+       mutex_lock(&text_mutex);
+       *insn_p = insn;
+
+       flush_icache_range((unsigned long)insn_p,
+                          (unsigned long)insn_p + sizeof(*insn_p));
+
+       mutex_unlock(&text_mutex);
+       put_online_cpus();
+}
+
+#endif /* HAVE_JUMP_LABEL */
index d87a72e9fac714bd2d1f73b564426f7a77e2dcc5..dd940b70196387c5b9f39a026100e0054444a175 100644 (file)
@@ -30,6 +30,8 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/spinlock.h>
+#include <linux/jump_label.h>
+
 #include <asm/pgtable.h>       /* MODULE_START */
 
 struct mips_hi16 {
@@ -382,6 +384,9 @@ int module_finalize(const Elf_Ehdr *hdr,
        const Elf_Shdr *s;
        char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
 
+       /* Make jump label nops. */
+       jump_label_apply_nops(me);
+
        INIT_LIST_HEAD(&me->arch.dbe_list);
        for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
                if (strcmp("__dbe_table", secstrings + s->sh_name) != 0)