module.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. void *module_alloc(unsigned long size)
  29. {
  30. if (size == 0)
  31. return NULL;
  32. return vmalloc_exec(size);
  33. }
  34. /* Free memory returned from module_alloc */
  35. void module_free(struct module *mod, void *module_region)
  36. {
  37. vfree(module_region);
  38. }
  39. static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
  40. const Elf_Shdr *sechdrs,
  41. const char *name)
  42. {
  43. char *secstrings;
  44. unsigned int i;
  45. secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
  46. for (i = 1; i < hdr->e_shnum; i++)
  47. if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
  48. return &sechdrs[i];
  49. return NULL;
  50. }
  51. int module_finalize(const Elf_Ehdr *hdr,
  52. const Elf_Shdr *sechdrs, struct module *me)
  53. {
  54. const Elf_Shdr *sect;
  55. int err;
  56. err = module_bug_finalize(hdr, sechdrs, me);
  57. if (err)
  58. return err;
  59. /* Apply feature fixups */
  60. sect = find_section(hdr, sechdrs, "__ftr_fixup");
  61. if (sect != NULL)
  62. do_feature_fixups(cur_cpu_spec->cpu_features,
  63. (void *)sect->sh_addr,
  64. (void *)sect->sh_addr + sect->sh_size);
  65. sect = find_section(hdr, sechdrs, "__mmu_ftr_fixup");
  66. if (sect != NULL)
  67. do_feature_fixups(cur_cpu_spec->mmu_features,
  68. (void *)sect->sh_addr,
  69. (void *)sect->sh_addr + sect->sh_size);
  70. #ifdef CONFIG_PPC64
  71. sect = find_section(hdr, sechdrs, "__fw_ftr_fixup");
  72. if (sect != NULL)
  73. do_feature_fixups(powerpc_firmware_features,
  74. (void *)sect->sh_addr,
  75. (void *)sect->sh_addr + sect->sh_size);
  76. #endif
  77. sect = find_section(hdr, sechdrs, "__lwsync_fixup");
  78. if (sect != NULL)
  79. do_lwsync_fixups(cur_cpu_spec->cpu_features,
  80. (void *)sect->sh_addr,
  81. (void *)sect->sh_addr + sect->sh_size);
  82. return 0;
  83. }
  84. void module_arch_cleanup(struct module *mod)
  85. {
  86. module_bug_cleanup(mod);
  87. }