pci-iommu_table.c 2.0 KB

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