module.c 2.9 KB

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