diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-01-30 21:37:27 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-01-30 21:37:27 -0500 |
commit | 8af03e782cae1e0a0f530ddd22301cdd12cf9dc0 (patch) | |
tree | c4af13a38bd3cc1a811a37f2358491f171052070 /arch/powerpc/kernel/module_64.c | |
parent | 6232665040f9a23fafd9d94d4ae8d5a2dc850f65 (diff) | |
parent | 99e139126ab2e84be67969650f92eb37c12ab5cd (diff) |
Merge branch 'for-2.6.25' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
* 'for-2.6.25' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc: (454 commits)
[POWERPC] Cell IOMMU fixed mapping support
[POWERPC] Split out the ioid fetching/checking logic
[POWERPC] Add support to cell_iommu_setup_page_tables() for multiple windows
[POWERPC] Split out the IOMMU logic from cell_dma_dev_setup()
[POWERPC] Split cell_iommu_setup_hardware() into two parts
[POWERPC] Split out the logic that allocates struct iommus
[POWERPC] Allocate the hash table under 1G on cell
[POWERPC] Add set_dma_ops() to match get_dma_ops()
[POWERPC] 83xx: Clean up / convert mpc83xx board DTS files to v1 format.
[POWERPC] 85xx: Only invalidate TLB0 and TLB1
[POWERPC] 83xx: Fix typo in mpc837x compatible entries
[POWERPC] 85xx: convert sbc85* boards to use machine_device_initcall
[POWERPC] 83xx: rework platform Kconfig
[POWERPC] 85xx: rework platform Kconfig
[POWERPC] 86xx: Remove unused IRQ defines
[POWERPC] QE: Explicitly set address-cells and size cells for muram
[POWERPC] Convert StorCenter DTS file to /dts-v1/ format.
[POWERPC] 86xx: Convert all 86xx DTS files to /dts-v1/ format.
[PPC] Remove 85xx from arch/ppc
[PPC] Remove 83xx from arch/ppc
...
Diffstat (limited to 'arch/powerpc/kernel/module_64.c')
-rw-r--r-- | arch/powerpc/kernel/module_64.c | 81 |
1 files changed, 64 insertions, 17 deletions
diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index 75c7c4f19280..3a82b02b784b 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <asm/module.h> | 24 | #include <asm/module.h> |
25 | #include <asm/uaccess.h> | 25 | #include <asm/uaccess.h> |
26 | #include <asm/firmware.h> | 26 | #include <asm/firmware.h> |
27 | #include <linux/sort.h> | ||
27 | 28 | ||
28 | #include "setup.h" | 29 | #include "setup.h" |
29 | 30 | ||
@@ -81,25 +82,23 @@ static struct ppc64_stub_entry ppc64_stub = | |||
81 | different addend) */ | 82 | different addend) */ |
82 | static unsigned int count_relocs(const Elf64_Rela *rela, unsigned int num) | 83 | static unsigned int count_relocs(const Elf64_Rela *rela, unsigned int num) |
83 | { | 84 | { |
84 | unsigned int i, j, ret = 0; | 85 | unsigned int i, r_info, r_addend, _count_relocs; |
85 | 86 | ||
86 | /* FIXME: Only count external ones --RR */ | 87 | /* FIXME: Only count external ones --RR */ |
87 | /* Sure, this is order(n^2), but it's usually short, and not | 88 | _count_relocs = 0; |
88 | time critical */ | 89 | r_info = 0; |
89 | for (i = 0; i < num; i++) { | 90 | r_addend = 0; |
91 | for (i = 0; i < num; i++) | ||
90 | /* Only count 24-bit relocs, others don't need stubs */ | 92 | /* Only count 24-bit relocs, others don't need stubs */ |
91 | if (ELF64_R_TYPE(rela[i].r_info) != R_PPC_REL24) | 93 | if (ELF64_R_TYPE(rela[i].r_info) == R_PPC_REL24 && |
92 | continue; | 94 | (r_info != ELF64_R_SYM(rela[i].r_info) || |
93 | for (j = 0; j < i; j++) { | 95 | r_addend != rela[i].r_addend)) { |
94 | /* If this addend appeared before, it's | 96 | _count_relocs++; |
95 | already been counted */ | 97 | r_info = ELF64_R_SYM(rela[i].r_info); |
96 | if (rela[i].r_info == rela[j].r_info | 98 | r_addend = rela[i].r_addend; |
97 | && rela[i].r_addend == rela[j].r_addend) | ||
98 | break; | ||
99 | } | 99 | } |
100 | if (j == i) ret++; | 100 | |
101 | } | 101 | return _count_relocs; |
102 | return ret; | ||
103 | } | 102 | } |
104 | 103 | ||
105 | void *module_alloc(unsigned long size) | 104 | void *module_alloc(unsigned long size) |
@@ -118,6 +117,44 @@ void module_free(struct module *mod, void *module_region) | |||
118 | table entries. */ | 117 | table entries. */ |
119 | } | 118 | } |
120 | 119 | ||
120 | static int relacmp(const void *_x, const void *_y) | ||
121 | { | ||
122 | const Elf64_Rela *x, *y; | ||
123 | |||
124 | y = (Elf64_Rela *)_x; | ||
125 | x = (Elf64_Rela *)_y; | ||
126 | |||
127 | /* Compare the entire r_info (as opposed to ELF64_R_SYM(r_info) only) to | ||
128 | * make the comparison cheaper/faster. It won't affect the sorting or | ||
129 | * the counting algorithms' performance | ||
130 | */ | ||
131 | if (x->r_info < y->r_info) | ||
132 | return -1; | ||
133 | else if (x->r_info > y->r_info) | ||
134 | return 1; | ||
135 | else if (x->r_addend < y->r_addend) | ||
136 | return -1; | ||
137 | else if (x->r_addend > y->r_addend) | ||
138 | return 1; | ||
139 | else | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | static void relaswap(void *_x, void *_y, int size) | ||
144 | { | ||
145 | uint64_t *x, *y, tmp; | ||
146 | int i; | ||
147 | |||
148 | y = (uint64_t *)_x; | ||
149 | x = (uint64_t *)_y; | ||
150 | |||
151 | for (i = 0; i < sizeof(Elf64_Rela) / sizeof(uint64_t); i++) { | ||
152 | tmp = x[i]; | ||
153 | x[i] = y[i]; | ||
154 | y[i] = tmp; | ||
155 | } | ||
156 | } | ||
157 | |||
121 | /* Get size of potential trampolines required. */ | 158 | /* Get size of potential trampolines required. */ |
122 | static unsigned long get_stubs_size(const Elf64_Ehdr *hdr, | 159 | static unsigned long get_stubs_size(const Elf64_Ehdr *hdr, |
123 | const Elf64_Shdr *sechdrs) | 160 | const Elf64_Shdr *sechdrs) |
@@ -133,6 +170,16 @@ static unsigned long get_stubs_size(const Elf64_Ehdr *hdr, | |||
133 | DEBUGP("Ptr: %p. Number: %lu\n", | 170 | DEBUGP("Ptr: %p. Number: %lu\n", |
134 | (void *)sechdrs[i].sh_addr, | 171 | (void *)sechdrs[i].sh_addr, |
135 | sechdrs[i].sh_size / sizeof(Elf64_Rela)); | 172 | sechdrs[i].sh_size / sizeof(Elf64_Rela)); |
173 | |||
174 | /* Sort the relocation information based on a symbol and | ||
175 | * addend key. This is a stable O(n*log n) complexity | ||
176 | * alogrithm but it will reduce the complexity of | ||
177 | * count_relocs() to linear complexity O(n) | ||
178 | */ | ||
179 | sort((void *)sechdrs[i].sh_addr, | ||
180 | sechdrs[i].sh_size / sizeof(Elf64_Rela), | ||
181 | sizeof(Elf64_Rela), relacmp, relaswap); | ||
182 | |||
136 | relocs += count_relocs((void *)sechdrs[i].sh_addr, | 183 | relocs += count_relocs((void *)sechdrs[i].sh_addr, |
137 | sechdrs[i].sh_size | 184 | sechdrs[i].sh_size |
138 | / sizeof(Elf64_Rela)); | 185 | / sizeof(Elf64_Rela)); |
@@ -343,7 +390,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, | |||
343 | /* Simply set it */ | 390 | /* Simply set it */ |
344 | *(u32 *)location = value; | 391 | *(u32 *)location = value; |
345 | break; | 392 | break; |
346 | 393 | ||
347 | case R_PPC64_ADDR64: | 394 | case R_PPC64_ADDR64: |
348 | /* Simply set it */ | 395 | /* Simply set it */ |
349 | *(unsigned long *)location = value; | 396 | *(unsigned long *)location = value; |
@@ -399,7 +446,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, | |||
399 | } | 446 | } |
400 | 447 | ||
401 | /* Only replace bits 2 through 26 */ | 448 | /* Only replace bits 2 through 26 */ |
402 | *(uint32_t *)location | 449 | *(uint32_t *)location |
403 | = (*(uint32_t *)location & ~0x03fffffc) | 450 | = (*(uint32_t *)location & ~0x03fffffc) |
404 | | (value & 0x03fffffc); | 451 | | (value & 0x03fffffc); |
405 | break; | 452 | break; |