Commit | Line | Data |
---|---|---|
5bef80a4 KRW |
1 | #include <linux/dma-mapping.h> |
2 | #include <asm/iommu_table.h> | |
3 | #include <linux/string.h> | |
4 | #include <linux/kallsyms.h> | |
5 | ||
6 | ||
7 | #define DEBUG 1 | |
8 | ||
9 | static struct iommu_table_entry * __init | |
10 | find_dependents_of(struct iommu_table_entry *start, | |
11 | struct iommu_table_entry *finish, | |
12 | struct iommu_table_entry *q) | |
13 | { | |
14 | struct iommu_table_entry *p; | |
15 | ||
16 | if (!q) | |
17 | return NULL; | |
18 | ||
19 | for (p = start; p < finish; p++) | |
20 | if (p->detect == q->depend) | |
21 | return p; | |
22 | ||
23 | return NULL; | |
24 | } | |
25 | ||
26 | ||
27 | void __init sort_iommu_table(struct iommu_table_entry *start, | |
28 | struct iommu_table_entry *finish) { | |
29 | ||
30 | struct iommu_table_entry *p, *q, tmp; | |
31 | ||
32 | for (p = start; p < finish; p++) { | |
33 | again: | |
34 | q = find_dependents_of(start, finish, p); | |
35 | /* We are bit sneaky here. We use the memory address to figure | |
36 | * out if the node we depend on is past our point, if so, swap. | |
37 | */ | |
38 | if (q > p) { | |
39 | tmp = *p; | |
40 | memmove(p, q, sizeof(*p)); | |
41 | *q = tmp; | |
42 | goto again; | |
43 | } | |
44 | } | |
45 | ||
46 | } | |
47 | ||
48 | #ifdef DEBUG | |
49 | void __init check_iommu_entries(struct iommu_table_entry *start, | |
50 | struct iommu_table_entry *finish) | |
51 | { | |
52 | struct iommu_table_entry *p, *q, *x; | |
53 | char sym_p[KSYM_SYMBOL_LEN]; | |
54 | char sym_q[KSYM_SYMBOL_LEN]; | |
55 | ||
56 | /* Simple cyclic dependency checker. */ | |
57 | for (p = start; p < finish; p++) { | |
58 | q = find_dependents_of(start, finish, p); | |
59 | x = find_dependents_of(start, finish, q); | |
60 | if (p == x) { | |
61 | sprint_symbol(sym_p, (unsigned long)p->detect); | |
62 | sprint_symbol(sym_q, (unsigned long)q->detect); | |
63 | ||
64 | printk(KERN_ERR "CYCLIC DEPENDENCY FOUND! %s depends" \ | |
65 | " on %s and vice-versa. BREAKING IT.\n", | |
66 | sym_p, sym_q); | |
67 | /* Heavy handed way..*/ | |
68 | x->depend = 0; | |
69 | } | |
70 | } | |
71 | ||
72 | for (p = start; p < finish; p++) { | |
73 | q = find_dependents_of(p, finish, p); | |
74 | if (q && q > p) { | |
75 | sprint_symbol(sym_p, (unsigned long)p->detect); | |
76 | sprint_symbol(sym_q, (unsigned long)q->detect); | |
77 | ||
78 | printk(KERN_ERR "EXECUTION ORDER INVALID! %s "\ | |
79 | "should be called before %s!\n", | |
80 | sym_p, sym_q); | |
81 | } | |
82 | } | |
83 | } | |
84 | #else | |
85 | inline void check_iommu_entries(struct iommu_table_entry *start, | |
86 | struct iommu_table_entry *finish) | |
87 | { | |
88 | } | |
89 | #endif |