Merge branch 'perfcounters-core-for-linus' of git://git.kernel.org/pub/scm/linux...
[safe/jmp/linux-2.6] / arch / powerpc / kernel / module_64.c
index 3a82b02..8fbb125 100644 (file)
 #include <linux/moduleloader.h>
 #include <linux/err.h>
 #include <linux/vmalloc.h>
+#include <linux/ftrace.h>
 #include <linux/bug.h>
 #include <asm/module.h>
-#include <asm/uaccess.h>
 #include <asm/firmware.h>
+#include <asm/code-patching.h>
 #include <linux/sort.h>
 
 #include "setup.h"
 #define DEBUGP(fmt , ...)
 #endif
 
-/* There's actually a third entry here, but it's unused */
-struct ppc64_opd_entry
-{
-       unsigned long funcaddr;
-       unsigned long r2;
-};
-
 /* Like PPC32, we need little trampolines to do > 24-bit jumps (into
    the kernel itself).  But on PPC64, these need to be used for every
    jump, actually, to reset r2 (TOC+0x8000). */
@@ -101,22 +95,6 @@ static unsigned int count_relocs(const Elf64_Rela *rela, unsigned int num)
        return _count_relocs;
 }
 
-void *module_alloc(unsigned long size)
-{
-       if (size == 0)
-               return NULL;
-
-       return vmalloc_exec(size);
-}
-
-/* Free memory returned from module_alloc */
-void module_free(struct module *mod, void *module_region)
-{
-       vfree(module_region);
-       /* FIXME: If module_region == mod->init_region, trim exception
-           table entries. */
-}
-
 static int relacmp(const void *_x, const void *_y)
 {
        const Elf64_Rela *x, *y;
@@ -186,6 +164,11 @@ static unsigned long get_stubs_size(const Elf64_Ehdr *hdr,
                }
        }
 
+#ifdef CONFIG_DYNAMIC_FTRACE
+       /* make the trampoline to the ftrace_caller */
+       relocs++;
+#endif
+
        DEBUGP("Looks like a total of %lu stubs, max\n", relocs);
        return relocs * sizeof(struct ppc64_stub_entry);
 }
@@ -346,7 +329,7 @@ static unsigned long stub_for_addr(Elf64_Shdr *sechdrs,
    restore r2. */
 static int restore_r2(u32 *instruction, struct module *me)
 {
-       if (*instruction != 0x60000000) {
+       if (*instruction != PPC_INST_NOP) {
                printk("%s: Expect noop after relocate, got %08x\n",
                       me->name, *instruction);
                return 0;
@@ -464,67 +447,12 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
                }
        }
 
-       return 0;
-}
-
-LIST_HEAD(module_bug_list);
-
-static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
-                                   const Elf_Shdr *sechdrs,
-                                   const char *name)
-{
-       char *secstrings;
-       unsigned int i;
-
-       secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
-       for (i = 1; i < hdr->e_shnum; i++)
-               if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
-                       return &sechdrs[i];
-       return NULL;
-}
-
-int module_finalize(const Elf_Ehdr *hdr,
-               const Elf_Shdr *sechdrs, struct module *me)
-{
-       const Elf_Shdr *sect;
-       int err;
-
-       err = module_bug_finalize(hdr, sechdrs, me);
-       if (err)
-               return err;
-
-       /* Apply feature fixups */
-       sect = find_section(hdr, sechdrs, "__ftr_fixup");
-       if (sect != NULL)
-               do_feature_fixups(cur_cpu_spec->cpu_features,
-                                 (void *)sect->sh_addr,
-                                 (void *)sect->sh_addr + sect->sh_size);
-
-       sect = find_section(hdr, sechdrs, "__fw_ftr_fixup");
-       if (sect != NULL)
-               do_feature_fixups(powerpc_firmware_features,
-                                 (void *)sect->sh_addr,
-                                 (void *)sect->sh_addr + sect->sh_size);
+#ifdef CONFIG_DYNAMIC_FTRACE
+       me->arch.toc = my_r2(sechdrs, me);
+       me->arch.tramp = stub_for_addr(sechdrs,
+                                      (unsigned long)ftrace_caller,
+                                      me);
+#endif
 
        return 0;
 }
-
-void module_arch_cleanup(struct module *mod)
-{
-       module_bug_cleanup(mod);
-}
-
-struct bug_entry *module_find_bug(unsigned long bugaddr)
-{
-       struct mod_arch_specific *mod;
-       unsigned int i;
-       struct bug_entry *bug;
-
-       list_for_each_entry(mod, &module_bug_list, bug_list) {
-               bug = mod->bug_table;
-               for (i = 0; i < mod->num_bugs; ++i, ++bug)
-                       if (bugaddr == bug->bug_addr)
-                               return bug;
-       }
-       return NULL;
-}