module.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Kernel module help for powerpc.
  2. Copyright (C) 2001, 2003 Rusty Russell IBM Corporation.
  3. Copyright (C) 2008 Freescale Semiconductor, Inc.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. #include <linux/elf.h>
  17. #include <linux/moduleloader.h>
  18. #include <linux/err.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/bug.h>
  21. #include <asm/module.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/firmware.h>
  24. #include <linux/sort.h>
  25. #include <asm/setup.h>
  26. static LIST_HEAD(module_bug_list);
  27. static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
  28. const Elf_Shdr *sechdrs,
  29. const char *name)
  30. {
  31. char *secstrings;
  32. unsigned int i;
  33. secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
  34. for (i = 1; i < hdr->e_shnum; i++)
  35. if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
  36. return &sechdrs[i];
  37. return NULL;
  38. }
  39. int module_finalize(const Elf_Ehdr *hdr,
  40. const Elf_Shdr *sechdrs, struct module *me)
  41. {
  42. const Elf_Shdr *sect;
  43. int rc;
  44. rc = module_finalize_ftrace(me, sechdrs);
  45. if (rc)
  46. return rc;
  47. /* Apply feature fixups */
  48. sect = find_section(hdr, sechdrs, "__ftr_fixup");
  49. if (sect != NULL)
  50. do_feature_fixups(cur_cpu_spec->cpu_features,
  51. (void *)sect->sh_addr,
  52. (void *)sect->sh_addr + sect->sh_size);
  53. sect = find_section(hdr, sechdrs, "__mmu_ftr_fixup");
  54. if (sect != NULL)
  55. do_feature_fixups(cur_cpu_spec->mmu_features,
  56. (void *)sect->sh_addr,
  57. (void *)sect->sh_addr + sect->sh_size);
  58. #ifdef CONFIG_PPC64
  59. sect = find_section(hdr, sechdrs, "__fw_ftr_fixup");
  60. if (sect != NULL)
  61. do_feature_fixups(powerpc_firmware_features,
  62. (void *)sect->sh_addr,
  63. (void *)sect->sh_addr + sect->sh_size);
  64. #endif
  65. sect = find_section(hdr, sechdrs, "__lwsync_fixup");
  66. if (sect != NULL)
  67. do_lwsync_fixups(cur_cpu_spec->cpu_features,
  68. (void *)sect->sh_addr,
  69. (void *)sect->sh_addr + sect->sh_size);
  70. return 0;
  71. }