sparc: remove several unnecessary module.h include instances
[firefly-linux-kernel-4.4.55.git] / arch / sparc / mm / extable.c
1 /*
2  * linux/arch/sparc/mm/extable.c
3  */
4
5 #include <asm/uaccess.h>
6
7 void sort_extable(struct exception_table_entry *start,
8                   struct exception_table_entry *finish)
9 {
10 }
11
12 /* Caller knows they are in a range if ret->fixup == 0 */
13 const struct exception_table_entry *
14 search_extable(const struct exception_table_entry *start,
15                const struct exception_table_entry *last,
16                unsigned long value)
17 {
18         const struct exception_table_entry *walk;
19
20         /* Single insn entries are encoded as:
21          *      word 1: insn address
22          *      word 2: fixup code address
23          *
24          * Range entries are encoded as:
25          *      word 1: first insn address
26          *      word 2: 0
27          *      word 3: last insn address + 4 bytes
28          *      word 4: fixup code address
29          *
30          * Deleted entries are encoded as:
31          *      word 1: unused
32          *      word 2: -1
33          *
34          * See asm/uaccess.h for more details.
35          */
36
37         /* 1. Try to find an exact match. */
38         for (walk = start; walk <= last; walk++) {
39                 if (walk->fixup == 0) {
40                         /* A range entry, skip both parts. */
41                         walk++;
42                         continue;
43                 }
44
45                 /* A deleted entry; see trim_init_extable */
46                 if (walk->fixup == -1)
47                         continue;
48
49                 if (walk->insn == value)
50                         return walk;
51         }
52
53         /* 2. Try to find a range match. */
54         for (walk = start; walk <= (last - 1); walk++) {
55                 if (walk->fixup)
56                         continue;
57
58                 if (walk[0].insn <= value && walk[1].insn > value)
59                         return walk;
60
61                 walk++;
62         }
63
64         return NULL;
65 }
66
67 #ifdef CONFIG_MODULES
68 /* We could memmove them around; easier to mark the trimmed ones. */
69 void trim_init_extable(struct module *m)
70 {
71         unsigned int i;
72         bool range;
73
74         for (i = 0; i < m->num_exentries; i += range ? 2 : 1) {
75                 range = m->extable[i].fixup == 0;
76
77                 if (within_module_init(m->extable[i].insn, m)) {
78                         m->extable[i].fixup = -1;
79                         if (range)
80                                 m->extable[i+1].fixup = -1;
81                 }
82                 if (range)
83                         i++;
84         }
85 }
86 #endif /* CONFIG_MODULES */
87
88 /* Special extable search, which handles ranges.  Returns fixup */
89 unsigned long search_extables_range(unsigned long addr, unsigned long *g2)
90 {
91         const struct exception_table_entry *entry;
92
93         entry = search_exception_tables(addr);
94         if (!entry)
95                 return 0;
96
97         /* Inside range?  Fix g2 and return correct fixup */
98         if (!entry->fixup) {
99                 *g2 = (addr - entry->insn) / 4;
100                 return (entry + 1)->fixup;
101         }
102
103         return entry->fixup;
104 }