module.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. 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. /* Apply feature fixups */
  44. sect = find_section(hdr, sechdrs, "__ftr_fixup");
  45. if (sect != NULL)
  46. do_feature_fixups(cur_cpu_spec->cpu_features,
  47. (void *)sect->sh_addr,
  48. (void *)sect->sh_addr + sect->sh_size);
  49. sect = find_section(hdr, sechdrs, "__mmu_ftr_fixup");
  50. if (sect != NULL)
  51. do_feature_fixups(cur_cpu_spec->mmu_features,
  52. (void *)sect->sh_addr,
  53. (void *)sect->sh_addr + sect->sh_size);
  54. #ifdef CONFIG_PPC64
  55. sect = find_section(hdr, sechdrs, "__fw_ftr_fixup");
  56. if (sect != NULL)
  57. do_feature_fixups(powerpc_firmware_features,
  58. (void *)sect->sh_addr,
  59. (void *)sect->sh_addr + sect->sh_size);
  60. #endif
  61. sect = find_section(hdr, sechdrs, "__lwsync_fixup");
  62. if (sect != NULL)
  63. do_lwsync_fixups(cur_cpu_spec->cpu_features,
  64. (void *)sect->sh_addr,
  65. (void *)sect->sh_addr + sect->sh_size);
  66. return 0;
  67. }