module.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /* Apply feature fixups */
  56. sect = find_section(hdr, sechdrs, "__ftr_fixup");
  57. if (sect != NULL)
  58. do_feature_fixups(cur_cpu_spec->cpu_features,
  59. (void *)sect->sh_addr,
  60. (void *)sect->sh_addr + sect->sh_size);
  61. sect = find_section(hdr, sechdrs, "__mmu_ftr_fixup");
  62. if (sect != NULL)
  63. do_feature_fixups(cur_cpu_spec->mmu_features,
  64. (void *)sect->sh_addr,
  65. (void *)sect->sh_addr + sect->sh_size);
  66. #ifdef CONFIG_PPC64
  67. sect = find_section(hdr, sechdrs, "__fw_ftr_fixup");
  68. if (sect != NULL)
  69. do_feature_fixups(powerpc_firmware_features,
  70. (void *)sect->sh_addr,
  71. (void *)sect->sh_addr + sect->sh_size);
  72. #endif
  73. sect = find_section(hdr, sechdrs, "__lwsync_fixup");
  74. if (sect != NULL)
  75. do_lwsync_fixups(cur_cpu_spec->cpu_features,
  76. (void *)sect->sh_addr,
  77. (void *)sect->sh_addr + sect->sh_size);
  78. return 0;
  79. }
  80. void module_arch_cleanup(struct module *mod)
  81. {
  82. }