iommu/msm: Add iommu_group support
[linux/fpc-iii.git] / arch / sparc / mm / extable.c
blob2422511dc8c5f16a7db7d205cb824b3a463e02c5
1 /*
2 * linux/arch/sparc/mm/extable.c
3 */
5 #include <linux/module.h>
6 #include <linux/extable.h>
7 #include <linux/uaccess.h>
9 void sort_extable(struct exception_table_entry *start,
10 struct exception_table_entry *finish)
14 /* Caller knows they are in a range if ret->fixup == 0 */
15 const struct exception_table_entry *
16 search_extable(const struct exception_table_entry *base,
17 const size_t num,
18 unsigned long value)
20 int i;
22 /* Single insn entries are encoded as:
23 * word 1: insn address
24 * word 2: fixup code address
26 * Range entries are encoded as:
27 * word 1: first insn address
28 * word 2: 0
29 * word 3: last insn address + 4 bytes
30 * word 4: fixup code address
32 * Deleted entries are encoded as:
33 * word 1: unused
34 * word 2: -1
36 * See asm/uaccess.h for more details.
39 /* 1. Try to find an exact match. */
40 for (i = 0; i < num; i++) {
41 if (base[i].fixup == 0) {
42 /* A range entry, skip both parts. */
43 i++;
44 continue;
47 /* A deleted entry; see trim_init_extable */
48 if (base[i].fixup == -1)
49 continue;
51 if (base[i].insn == value)
52 return &base[i];
55 /* 2. Try to find a range match. */
56 for (i = 0; i < (num - 1); i++) {
57 if (base[i].fixup)
58 continue;
60 if (base[i].insn <= value && base[i + 1].insn > value)
61 return &base[i];
63 i++;
66 return NULL;
69 #ifdef CONFIG_MODULES
70 /* We could memmove them around; easier to mark the trimmed ones. */
71 void trim_init_extable(struct module *m)
73 unsigned int i;
74 bool range;
76 for (i = 0; i < m->num_exentries; i += range ? 2 : 1) {
77 range = m->extable[i].fixup == 0;
79 if (within_module_init(m->extable[i].insn, m)) {
80 m->extable[i].fixup = -1;
81 if (range)
82 m->extable[i+1].fixup = -1;
84 if (range)
85 i++;
88 #endif /* CONFIG_MODULES */
90 /* Special extable search, which handles ranges. Returns fixup */
91 unsigned long search_extables_range(unsigned long addr, unsigned long *g2)
93 const struct exception_table_entry *entry;
95 entry = search_exception_tables(addr);
96 if (!entry)
97 return 0;
99 /* Inside range? Fix g2 and return correct fixup */
100 if (!entry->fixup) {
101 *g2 = (addr - entry->insn) / 4;
102 return (entry + 1)->fixup;
105 return entry->fixup;