module.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/module.h>
  17. #include <linux/elf.h>
  18. #include <linux/moduleloader.h>
  19. #include <linux/err.h>
  20. #include <linux/vmalloc.h>
  21. #include <linux/bug.h>
  22. #include <asm/module.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/firmware.h>
  25. #include <linux/sort.h>
  26. #include "setup.h"
  27. LIST_HEAD(module_bug_list);
  28. static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
  29. const Elf_Shdr *sechdrs,
  30. const char *name)
  31. {
  32. char *secstrings;
  33. unsigned int i;
  34. secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
  35. for (i = 1; i < hdr->e_shnum; i++)
  36. if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
  37. return &sechdrs[i];
  38. return NULL;
  39. }
  40. int module_finalize(const Elf_Ehdr *hdr,
  41. const Elf_Shdr *sechdrs, struct module *me)
  42. {
  43. const Elf_Shdr *sect;
  44. /* Apply feature fixups */
  45. sect = find_section(hdr, sechdrs, "__ftr_fixup");
  46. if (sect != NULL)
  47. do_feature_fixups(cur_cpu_spec->cpu_features,
  48. (void *)sect->sh_addr,
  49. (void *)sect->sh_addr + sect->sh_size);
  50. sect = find_section(hdr, sechdrs, "__mmu_ftr_fixup");
  51. if (sect != NULL)
  52. do_feature_fixups(cur_cpu_spec->mmu_features,
  53. (void *)sect->sh_addr,
  54. (void *)sect->sh_addr + sect->sh_size);
  55. #ifdef CONFIG_PPC64
  56. sect = find_section(hdr, sechdrs, "__fw_ftr_fixup");
  57. if (sect != NULL)
  58. do_feature_fixups(powerpc_firmware_features,
  59. (void *)sect->sh_addr,
  60. (void *)sect->sh_addr + sect->sh_size);
  61. #endif
  62. sect = find_section(hdr, sechdrs, "__lwsync_fixup");
  63. if (sect != NULL)
  64. do_lwsync_fixups(cur_cpu_spec->cpu_features,
  65. (void *)sect->sh_addr,
  66. (void *)sect->sh_addr + sect->sh_size);
  67. return 0;
  68. }