dma-debug.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. /*
  2. * Copyright (C) 2008 Advanced Micro Devices, Inc.
  3. *
  4. * Author: Joerg Roedel <joerg.roedel@amd.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/scatterlist.h>
  20. #include <linux/dma-mapping.h>
  21. #include <linux/stacktrace.h>
  22. #include <linux/dma-debug.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/debugfs.h>
  25. #include <linux/uaccess.h>
  26. #include <linux/export.h>
  27. #include <linux/device.h>
  28. #include <linux/types.h>
  29. #include <linux/sched.h>
  30. #include <linux/ctype.h>
  31. #include <linux/list.h>
  32. #include <linux/slab.h>
  33. #include <asm/sections.h>
  34. #define HASH_SIZE 1024ULL
  35. #define HASH_FN_SHIFT 13
  36. #define HASH_FN_MASK (HASH_SIZE - 1)
  37. enum {
  38. dma_debug_single,
  39. dma_debug_page,
  40. dma_debug_sg,
  41. dma_debug_coherent,
  42. };
  43. enum map_err_types {
  44. MAP_ERR_CHECK_NOT_APPLICABLE,
  45. MAP_ERR_NOT_CHECKED,
  46. MAP_ERR_CHECKED,
  47. };
  48. #define DMA_DEBUG_STACKTRACE_ENTRIES 5
  49. struct dma_debug_entry {
  50. struct list_head list;
  51. struct device *dev;
  52. int type;
  53. phys_addr_t paddr;
  54. u64 dev_addr;
  55. u64 size;
  56. int direction;
  57. int sg_call_ents;
  58. int sg_mapped_ents;
  59. enum map_err_types map_err_type;
  60. #ifdef CONFIG_STACKTRACE
  61. struct stack_trace stacktrace;
  62. unsigned long st_entries[DMA_DEBUG_STACKTRACE_ENTRIES];
  63. #endif
  64. };
  65. typedef bool (*match_fn)(struct dma_debug_entry *, struct dma_debug_entry *);
  66. struct hash_bucket {
  67. struct list_head list;
  68. spinlock_t lock;
  69. } ____cacheline_aligned_in_smp;
  70. /* Hash list to save the allocated dma addresses */
  71. static struct hash_bucket dma_entry_hash[HASH_SIZE];
  72. /* List of pre-allocated dma_debug_entry's */
  73. static LIST_HEAD(free_entries);
  74. /* Lock for the list above */
  75. static DEFINE_SPINLOCK(free_entries_lock);
  76. /* Global disable flag - will be set in case of an error */
  77. static u32 global_disable __read_mostly;
  78. /* Global error count */
  79. static u32 error_count;
  80. /* Global error show enable*/
  81. static u32 show_all_errors __read_mostly;
  82. /* Number of errors to show */
  83. static u32 show_num_errors = 1;
  84. static u32 num_free_entries;
  85. static u32 min_free_entries;
  86. static u32 nr_total_entries;
  87. /* number of preallocated entries requested by kernel cmdline */
  88. static u32 req_entries;
  89. /* debugfs dentry's for the stuff above */
  90. static struct dentry *dma_debug_dent __read_mostly;
  91. static struct dentry *global_disable_dent __read_mostly;
  92. static struct dentry *error_count_dent __read_mostly;
  93. static struct dentry *show_all_errors_dent __read_mostly;
  94. static struct dentry *show_num_errors_dent __read_mostly;
  95. static struct dentry *num_free_entries_dent __read_mostly;
  96. static struct dentry *min_free_entries_dent __read_mostly;
  97. static struct dentry *filter_dent __read_mostly;
  98. /* per-driver filter related state */
  99. #define NAME_MAX_LEN 64
  100. static char current_driver_name[NAME_MAX_LEN] __read_mostly;
  101. static struct device_driver *current_driver __read_mostly;
  102. static DEFINE_RWLOCK(driver_name_lock);
  103. static const char *const maperr2str[] = {
  104. [MAP_ERR_CHECK_NOT_APPLICABLE] = "dma map error check not applicable",
  105. [MAP_ERR_NOT_CHECKED] = "dma map error not checked",
  106. [MAP_ERR_CHECKED] = "dma map error checked",
  107. };
  108. static const char *type2name[4] = { "single", "page",
  109. "scather-gather", "coherent" };
  110. static const char *dir2name[4] = { "DMA_BIDIRECTIONAL", "DMA_TO_DEVICE",
  111. "DMA_FROM_DEVICE", "DMA_NONE" };
  112. /*
  113. * The access to some variables in this macro is racy. We can't use atomic_t
  114. * here because all these variables are exported to debugfs. Some of them even
  115. * writeable. This is also the reason why a lock won't help much. But anyway,
  116. * the races are no big deal. Here is why:
  117. *
  118. * error_count: the addition is racy, but the worst thing that can happen is
  119. * that we don't count some errors
  120. * show_num_errors: the subtraction is racy. Also no big deal because in
  121. * worst case this will result in one warning more in the
  122. * system log than the user configured. This variable is
  123. * writeable via debugfs.
  124. */
  125. static inline void dump_entry_trace(struct dma_debug_entry *entry)
  126. {
  127. #ifdef CONFIG_STACKTRACE
  128. if (entry) {
  129. pr_warning("Mapped at:\n");
  130. print_stack_trace(&entry->stacktrace, 0);
  131. }
  132. #endif
  133. }
  134. static bool driver_filter(struct device *dev)
  135. {
  136. struct device_driver *drv;
  137. unsigned long flags;
  138. bool ret;
  139. /* driver filter off */
  140. if (likely(!current_driver_name[0]))
  141. return true;
  142. /* driver filter on and initialized */
  143. if (current_driver && dev && dev->driver == current_driver)
  144. return true;
  145. /* driver filter on, but we can't filter on a NULL device... */
  146. if (!dev)
  147. return false;
  148. if (current_driver || !current_driver_name[0])
  149. return false;
  150. /* driver filter on but not yet initialized */
  151. drv = dev->driver;
  152. if (!drv)
  153. return false;
  154. /* lock to protect against change of current_driver_name */
  155. read_lock_irqsave(&driver_name_lock, flags);
  156. ret = false;
  157. if (drv->name &&
  158. strncmp(current_driver_name, drv->name, NAME_MAX_LEN - 1) == 0) {
  159. current_driver = drv;
  160. ret = true;
  161. }
  162. read_unlock_irqrestore(&driver_name_lock, flags);
  163. return ret;
  164. }
  165. #define err_printk(dev, entry, format, arg...) do { \
  166. error_count += 1; \
  167. if (driver_filter(dev) && \
  168. (show_all_errors || show_num_errors > 0)) { \
  169. WARN(1, "%s %s: " format, \
  170. dev ? dev_driver_string(dev) : "NULL", \
  171. dev ? dev_name(dev) : "NULL", ## arg); \
  172. dump_entry_trace(entry); \
  173. } \
  174. if (!show_all_errors && show_num_errors > 0) \
  175. show_num_errors -= 1; \
  176. } while (0);
  177. /*
  178. * Hash related functions
  179. *
  180. * Every DMA-API request is saved into a struct dma_debug_entry. To
  181. * have quick access to these structs they are stored into a hash.
  182. */
  183. static int hash_fn(struct dma_debug_entry *entry)
  184. {
  185. /*
  186. * Hash function is based on the dma address.
  187. * We use bits 20-27 here as the index into the hash
  188. */
  189. return (entry->dev_addr >> HASH_FN_SHIFT) & HASH_FN_MASK;
  190. }
  191. /*
  192. * Request exclusive access to a hash bucket for a given dma_debug_entry.
  193. */
  194. static struct hash_bucket *get_hash_bucket(struct dma_debug_entry *entry,
  195. unsigned long *flags)
  196. {
  197. int idx = hash_fn(entry);
  198. unsigned long __flags;
  199. spin_lock_irqsave(&dma_entry_hash[idx].lock, __flags);
  200. *flags = __flags;
  201. return &dma_entry_hash[idx];
  202. }
  203. /*
  204. * Give up exclusive access to the hash bucket
  205. */
  206. static void put_hash_bucket(struct hash_bucket *bucket,
  207. unsigned long *flags)
  208. {
  209. unsigned long __flags = *flags;
  210. spin_unlock_irqrestore(&bucket->lock, __flags);
  211. }
  212. static bool exact_match(struct dma_debug_entry *a, struct dma_debug_entry *b)
  213. {
  214. return ((a->dev_addr == b->dev_addr) &&
  215. (a->dev == b->dev)) ? true : false;
  216. }
  217. static bool containing_match(struct dma_debug_entry *a,
  218. struct dma_debug_entry *b)
  219. {
  220. if (a->dev != b->dev)
  221. return false;
  222. if ((b->dev_addr <= a->dev_addr) &&
  223. ((b->dev_addr + b->size) >= (a->dev_addr + a->size)))
  224. return true;
  225. return false;
  226. }
  227. /*
  228. * Search a given entry in the hash bucket list
  229. */
  230. static struct dma_debug_entry *__hash_bucket_find(struct hash_bucket *bucket,
  231. struct dma_debug_entry *ref,
  232. match_fn match)
  233. {
  234. struct dma_debug_entry *entry, *ret = NULL;
  235. int matches = 0, match_lvl, last_lvl = -1;
  236. list_for_each_entry(entry, &bucket->list, list) {
  237. if (!match(ref, entry))
  238. continue;
  239. /*
  240. * Some drivers map the same physical address multiple
  241. * times. Without a hardware IOMMU this results in the
  242. * same device addresses being put into the dma-debug
  243. * hash multiple times too. This can result in false
  244. * positives being reported. Therefore we implement a
  245. * best-fit algorithm here which returns the entry from
  246. * the hash which fits best to the reference value
  247. * instead of the first-fit.
  248. */
  249. matches += 1;
  250. match_lvl = 0;
  251. entry->size == ref->size ? ++match_lvl : 0;
  252. entry->type == ref->type ? ++match_lvl : 0;
  253. entry->direction == ref->direction ? ++match_lvl : 0;
  254. entry->sg_call_ents == ref->sg_call_ents ? ++match_lvl : 0;
  255. if (match_lvl == 4) {
  256. /* perfect-fit - return the result */
  257. return entry;
  258. } else if (match_lvl > last_lvl) {
  259. /*
  260. * We found an entry that fits better then the
  261. * previous one or it is the 1st match.
  262. */
  263. last_lvl = match_lvl;
  264. ret = entry;
  265. }
  266. }
  267. /*
  268. * If we have multiple matches but no perfect-fit, just return
  269. * NULL.
  270. */
  271. ret = (matches == 1) ? ret : NULL;
  272. return ret;
  273. }
  274. static struct dma_debug_entry *bucket_find_exact(struct hash_bucket *bucket,
  275. struct dma_debug_entry *ref)
  276. {
  277. return __hash_bucket_find(bucket, ref, exact_match);
  278. }
  279. static struct dma_debug_entry *bucket_find_contain(struct hash_bucket **bucket,
  280. struct dma_debug_entry *ref,
  281. unsigned long *flags)
  282. {
  283. unsigned int max_range = dma_get_max_seg_size(ref->dev);
  284. struct dma_debug_entry *entry, index = *ref;
  285. unsigned int range = 0;
  286. while (range <= max_range) {
  287. entry = __hash_bucket_find(*bucket, &index, containing_match);
  288. if (entry)
  289. return entry;
  290. /*
  291. * Nothing found, go back a hash bucket
  292. */
  293. put_hash_bucket(*bucket, flags);
  294. range += (1 << HASH_FN_SHIFT);
  295. index.dev_addr -= (1 << HASH_FN_SHIFT);
  296. *bucket = get_hash_bucket(&index, flags);
  297. }
  298. return NULL;
  299. }
  300. /*
  301. * Add an entry to a hash bucket
  302. */
  303. static void hash_bucket_add(struct hash_bucket *bucket,
  304. struct dma_debug_entry *entry)
  305. {
  306. list_add_tail(&entry->list, &bucket->list);
  307. }
  308. /*
  309. * Remove entry from a hash bucket list
  310. */
  311. static void hash_bucket_del(struct dma_debug_entry *entry)
  312. {
  313. list_del(&entry->list);
  314. }
  315. /*
  316. * Dump mapping entries for debugging purposes
  317. */
  318. void debug_dma_dump_mappings(struct device *dev)
  319. {
  320. int idx;
  321. for (idx = 0; idx < HASH_SIZE; idx++) {
  322. struct hash_bucket *bucket = &dma_entry_hash[idx];
  323. struct dma_debug_entry *entry;
  324. unsigned long flags;
  325. spin_lock_irqsave(&bucket->lock, flags);
  326. list_for_each_entry(entry, &bucket->list, list) {
  327. if (!dev || dev == entry->dev) {
  328. dev_info(entry->dev,
  329. "%s idx %d P=%Lx D=%Lx L=%Lx %s %s\n",
  330. type2name[entry->type], idx,
  331. (unsigned long long)entry->paddr,
  332. entry->dev_addr, entry->size,
  333. dir2name[entry->direction],
  334. maperr2str[entry->map_err_type]);
  335. }
  336. }
  337. spin_unlock_irqrestore(&bucket->lock, flags);
  338. }
  339. }
  340. EXPORT_SYMBOL(debug_dma_dump_mappings);
  341. /*
  342. * Wrapper function for adding an entry to the hash.
  343. * This function takes care of locking itself.
  344. */
  345. static void add_dma_entry(struct dma_debug_entry *entry)
  346. {
  347. struct hash_bucket *bucket;
  348. unsigned long flags;
  349. bucket = get_hash_bucket(entry, &flags);
  350. hash_bucket_add(bucket, entry);
  351. put_hash_bucket(bucket, &flags);
  352. }
  353. static struct dma_debug_entry *__dma_entry_alloc(void)
  354. {
  355. struct dma_debug_entry *entry;
  356. entry = list_entry(free_entries.next, struct dma_debug_entry, list);
  357. list_del(&entry->list);
  358. memset(entry, 0, sizeof(*entry));
  359. num_free_entries -= 1;
  360. if (num_free_entries < min_free_entries)
  361. min_free_entries = num_free_entries;
  362. return entry;
  363. }
  364. /* struct dma_entry allocator
  365. *
  366. * The next two functions implement the allocator for
  367. * struct dma_debug_entries.
  368. */
  369. static struct dma_debug_entry *dma_entry_alloc(void)
  370. {
  371. struct dma_debug_entry *entry;
  372. unsigned long flags;
  373. spin_lock_irqsave(&free_entries_lock, flags);
  374. if (list_empty(&free_entries)) {
  375. pr_err("DMA-API: debugging out of memory - disabling\n");
  376. global_disable = true;
  377. spin_unlock_irqrestore(&free_entries_lock, flags);
  378. return NULL;
  379. }
  380. entry = __dma_entry_alloc();
  381. spin_unlock_irqrestore(&free_entries_lock, flags);
  382. #ifdef CONFIG_STACKTRACE
  383. entry->stacktrace.max_entries = DMA_DEBUG_STACKTRACE_ENTRIES;
  384. entry->stacktrace.entries = entry->st_entries;
  385. entry->stacktrace.skip = 2;
  386. save_stack_trace(&entry->stacktrace);
  387. #endif
  388. return entry;
  389. }
  390. static void dma_entry_free(struct dma_debug_entry *entry)
  391. {
  392. unsigned long flags;
  393. /*
  394. * add to beginning of the list - this way the entries are
  395. * more likely cache hot when they are reallocated.
  396. */
  397. spin_lock_irqsave(&free_entries_lock, flags);
  398. list_add(&entry->list, &free_entries);
  399. num_free_entries += 1;
  400. spin_unlock_irqrestore(&free_entries_lock, flags);
  401. }
  402. int dma_debug_resize_entries(u32 num_entries)
  403. {
  404. int i, delta, ret = 0;
  405. unsigned long flags;
  406. struct dma_debug_entry *entry;
  407. LIST_HEAD(tmp);
  408. spin_lock_irqsave(&free_entries_lock, flags);
  409. if (nr_total_entries < num_entries) {
  410. delta = num_entries - nr_total_entries;
  411. spin_unlock_irqrestore(&free_entries_lock, flags);
  412. for (i = 0; i < delta; i++) {
  413. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  414. if (!entry)
  415. break;
  416. list_add_tail(&entry->list, &tmp);
  417. }
  418. spin_lock_irqsave(&free_entries_lock, flags);
  419. list_splice(&tmp, &free_entries);
  420. nr_total_entries += i;
  421. num_free_entries += i;
  422. } else {
  423. delta = nr_total_entries - num_entries;
  424. for (i = 0; i < delta && !list_empty(&free_entries); i++) {
  425. entry = __dma_entry_alloc();
  426. kfree(entry);
  427. }
  428. nr_total_entries -= i;
  429. }
  430. if (nr_total_entries != num_entries)
  431. ret = 1;
  432. spin_unlock_irqrestore(&free_entries_lock, flags);
  433. return ret;
  434. }
  435. EXPORT_SYMBOL(dma_debug_resize_entries);
  436. /*
  437. * DMA-API debugging init code
  438. *
  439. * The init code does two things:
  440. * 1. Initialize core data structures
  441. * 2. Preallocate a given number of dma_debug_entry structs
  442. */
  443. static int prealloc_memory(u32 num_entries)
  444. {
  445. struct dma_debug_entry *entry, *next_entry;
  446. int i;
  447. for (i = 0; i < num_entries; ++i) {
  448. entry = kzalloc(sizeof(*entry), GFP_KERNEL);
  449. if (!entry)
  450. goto out_err;
  451. list_add_tail(&entry->list, &free_entries);
  452. }
  453. num_free_entries = num_entries;
  454. min_free_entries = num_entries;
  455. pr_info("DMA-API: preallocated %d debug entries\n", num_entries);
  456. return 0;
  457. out_err:
  458. list_for_each_entry_safe(entry, next_entry, &free_entries, list) {
  459. list_del(&entry->list);
  460. kfree(entry);
  461. }
  462. return -ENOMEM;
  463. }
  464. static ssize_t filter_read(struct file *file, char __user *user_buf,
  465. size_t count, loff_t *ppos)
  466. {
  467. char buf[NAME_MAX_LEN + 1];
  468. unsigned long flags;
  469. int len;
  470. if (!current_driver_name[0])
  471. return 0;
  472. /*
  473. * We can't copy to userspace directly because current_driver_name can
  474. * only be read under the driver_name_lock with irqs disabled. So
  475. * create a temporary copy first.
  476. */
  477. read_lock_irqsave(&driver_name_lock, flags);
  478. len = scnprintf(buf, NAME_MAX_LEN + 1, "%s\n", current_driver_name);
  479. read_unlock_irqrestore(&driver_name_lock, flags);
  480. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  481. }
  482. static ssize_t filter_write(struct file *file, const char __user *userbuf,
  483. size_t count, loff_t *ppos)
  484. {
  485. char buf[NAME_MAX_LEN];
  486. unsigned long flags;
  487. size_t len;
  488. int i;
  489. /*
  490. * We can't copy from userspace directly. Access to
  491. * current_driver_name is protected with a write_lock with irqs
  492. * disabled. Since copy_from_user can fault and may sleep we
  493. * need to copy to temporary buffer first
  494. */
  495. len = min(count, (size_t)(NAME_MAX_LEN - 1));
  496. if (copy_from_user(buf, userbuf, len))
  497. return -EFAULT;
  498. buf[len] = 0;
  499. write_lock_irqsave(&driver_name_lock, flags);
  500. /*
  501. * Now handle the string we got from userspace very carefully.
  502. * The rules are:
  503. * - only use the first token we got
  504. * - token delimiter is everything looking like a space
  505. * character (' ', '\n', '\t' ...)
  506. *
  507. */
  508. if (!isalnum(buf[0])) {
  509. /*
  510. * If the first character userspace gave us is not
  511. * alphanumerical then assume the filter should be
  512. * switched off.
  513. */
  514. if (current_driver_name[0])
  515. pr_info("DMA-API: switching off dma-debug driver filter\n");
  516. current_driver_name[0] = 0;
  517. current_driver = NULL;
  518. goto out_unlock;
  519. }
  520. /*
  521. * Now parse out the first token and use it as the name for the
  522. * driver to filter for.
  523. */
  524. for (i = 0; i < NAME_MAX_LEN - 1; ++i) {
  525. current_driver_name[i] = buf[i];
  526. if (isspace(buf[i]) || buf[i] == ' ' || buf[i] == 0)
  527. break;
  528. }
  529. current_driver_name[i] = 0;
  530. current_driver = NULL;
  531. pr_info("DMA-API: enable driver filter for driver [%s]\n",
  532. current_driver_name);
  533. out_unlock:
  534. write_unlock_irqrestore(&driver_name_lock, flags);
  535. return count;
  536. }
  537. static const struct file_operations filter_fops = {
  538. .read = filter_read,
  539. .write = filter_write,
  540. .llseek = default_llseek,
  541. };
  542. static int dma_debug_fs_init(void)
  543. {
  544. dma_debug_dent = debugfs_create_dir("dma-api", NULL);
  545. if (!dma_debug_dent) {
  546. pr_err("DMA-API: can not create debugfs directory\n");
  547. return -ENOMEM;
  548. }
  549. global_disable_dent = debugfs_create_bool("disabled", 0444,
  550. dma_debug_dent,
  551. &global_disable);
  552. if (!global_disable_dent)
  553. goto out_err;
  554. error_count_dent = debugfs_create_u32("error_count", 0444,
  555. dma_debug_dent, &error_count);
  556. if (!error_count_dent)
  557. goto out_err;
  558. show_all_errors_dent = debugfs_create_u32("all_errors", 0644,
  559. dma_debug_dent,
  560. &show_all_errors);
  561. if (!show_all_errors_dent)
  562. goto out_err;
  563. show_num_errors_dent = debugfs_create_u32("num_errors", 0644,
  564. dma_debug_dent,
  565. &show_num_errors);
  566. if (!show_num_errors_dent)
  567. goto out_err;
  568. num_free_entries_dent = debugfs_create_u32("num_free_entries", 0444,
  569. dma_debug_dent,
  570. &num_free_entries);
  571. if (!num_free_entries_dent)
  572. goto out_err;
  573. min_free_entries_dent = debugfs_create_u32("min_free_entries", 0444,
  574. dma_debug_dent,
  575. &min_free_entries);
  576. if (!min_free_entries_dent)
  577. goto out_err;
  578. filter_dent = debugfs_create_file("driver_filter", 0644,
  579. dma_debug_dent, NULL, &filter_fops);
  580. if (!filter_dent)
  581. goto out_err;
  582. return 0;
  583. out_err:
  584. debugfs_remove_recursive(dma_debug_dent);
  585. return -ENOMEM;
  586. }
  587. static int device_dma_allocations(struct device *dev, struct dma_debug_entry **out_entry)
  588. {
  589. struct dma_debug_entry *entry;
  590. unsigned long flags;
  591. int count = 0, i;
  592. local_irq_save(flags);
  593. for (i = 0; i < HASH_SIZE; ++i) {
  594. spin_lock(&dma_entry_hash[i].lock);
  595. list_for_each_entry(entry, &dma_entry_hash[i].list, list) {
  596. if (entry->dev == dev) {
  597. count += 1;
  598. *out_entry = entry;
  599. }
  600. }
  601. spin_unlock(&dma_entry_hash[i].lock);
  602. }
  603. local_irq_restore(flags);
  604. return count;
  605. }
  606. static int dma_debug_device_change(struct notifier_block *nb, unsigned long action, void *data)
  607. {
  608. struct device *dev = data;
  609. struct dma_debug_entry *uninitialized_var(entry);
  610. int count;
  611. if (global_disable)
  612. return 0;
  613. switch (action) {
  614. case BUS_NOTIFY_UNBOUND_DRIVER:
  615. count = device_dma_allocations(dev, &entry);
  616. if (count == 0)
  617. break;
  618. err_printk(dev, entry, "DMA-API: device driver has pending "
  619. "DMA allocations while released from device "
  620. "[count=%d]\n"
  621. "One of leaked entries details: "
  622. "[device address=0x%016llx] [size=%llu bytes] "
  623. "[mapped with %s] [mapped as %s]\n",
  624. count, entry->dev_addr, entry->size,
  625. dir2name[entry->direction], type2name[entry->type]);
  626. break;
  627. default:
  628. break;
  629. }
  630. return 0;
  631. }
  632. void dma_debug_add_bus(struct bus_type *bus)
  633. {
  634. struct notifier_block *nb;
  635. if (global_disable)
  636. return;
  637. nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL);
  638. if (nb == NULL) {
  639. pr_err("dma_debug_add_bus: out of memory\n");
  640. return;
  641. }
  642. nb->notifier_call = dma_debug_device_change;
  643. bus_register_notifier(bus, nb);
  644. }
  645. /*
  646. * Let the architectures decide how many entries should be preallocated.
  647. */
  648. void dma_debug_init(u32 num_entries)
  649. {
  650. int i;
  651. if (global_disable)
  652. return;
  653. for (i = 0; i < HASH_SIZE; ++i) {
  654. INIT_LIST_HEAD(&dma_entry_hash[i].list);
  655. spin_lock_init(&dma_entry_hash[i].lock);
  656. }
  657. if (dma_debug_fs_init() != 0) {
  658. pr_err("DMA-API: error creating debugfs entries - disabling\n");
  659. global_disable = true;
  660. return;
  661. }
  662. if (req_entries)
  663. num_entries = req_entries;
  664. if (prealloc_memory(num_entries) != 0) {
  665. pr_err("DMA-API: debugging out of memory error - disabled\n");
  666. global_disable = true;
  667. return;
  668. }
  669. nr_total_entries = num_free_entries;
  670. pr_info("DMA-API: debugging enabled by kernel config\n");
  671. }
  672. static __init int dma_debug_cmdline(char *str)
  673. {
  674. if (!str)
  675. return -EINVAL;
  676. if (strncmp(str, "off", 3) == 0) {
  677. pr_info("DMA-API: debugging disabled on kernel command line\n");
  678. global_disable = true;
  679. }
  680. return 0;
  681. }
  682. static __init int dma_debug_entries_cmdline(char *str)
  683. {
  684. int res;
  685. if (!str)
  686. return -EINVAL;
  687. res = get_option(&str, &req_entries);
  688. if (!res)
  689. req_entries = 0;
  690. return 0;
  691. }
  692. __setup("dma_debug=", dma_debug_cmdline);
  693. __setup("dma_debug_entries=", dma_debug_entries_cmdline);
  694. static void check_unmap(struct dma_debug_entry *ref)
  695. {
  696. struct dma_debug_entry *entry;
  697. struct hash_bucket *bucket;
  698. unsigned long flags;
  699. bucket = get_hash_bucket(ref, &flags);
  700. entry = bucket_find_exact(bucket, ref);
  701. if (!entry) {
  702. if (dma_mapping_error(ref->dev, ref->dev_addr)) {
  703. err_printk(ref->dev, NULL,
  704. "DMA-API: device driver tries "
  705. "to free an invalid DMA memory address\n");
  706. return;
  707. }
  708. err_printk(ref->dev, NULL, "DMA-API: device driver tries "
  709. "to free DMA memory it has not allocated "
  710. "[device address=0x%016llx] [size=%llu bytes]\n",
  711. ref->dev_addr, ref->size);
  712. goto out;
  713. }
  714. if (ref->size != entry->size) {
  715. err_printk(ref->dev, entry, "DMA-API: device driver frees "
  716. "DMA memory with different size "
  717. "[device address=0x%016llx] [map size=%llu bytes] "
  718. "[unmap size=%llu bytes]\n",
  719. ref->dev_addr, entry->size, ref->size);
  720. }
  721. if (ref->type != entry->type) {
  722. err_printk(ref->dev, entry, "DMA-API: device driver frees "
  723. "DMA memory with wrong function "
  724. "[device address=0x%016llx] [size=%llu bytes] "
  725. "[mapped as %s] [unmapped as %s]\n",
  726. ref->dev_addr, ref->size,
  727. type2name[entry->type], type2name[ref->type]);
  728. } else if ((entry->type == dma_debug_coherent) &&
  729. (ref->paddr != entry->paddr)) {
  730. err_printk(ref->dev, entry, "DMA-API: device driver frees "
  731. "DMA memory with different CPU address "
  732. "[device address=0x%016llx] [size=%llu bytes] "
  733. "[cpu alloc address=0x%016llx] "
  734. "[cpu free address=0x%016llx]",
  735. ref->dev_addr, ref->size,
  736. (unsigned long long)entry->paddr,
  737. (unsigned long long)ref->paddr);
  738. }
  739. if (ref->sg_call_ents && ref->type == dma_debug_sg &&
  740. ref->sg_call_ents != entry->sg_call_ents) {
  741. err_printk(ref->dev, entry, "DMA-API: device driver frees "
  742. "DMA sg list with different entry count "
  743. "[map count=%d] [unmap count=%d]\n",
  744. entry->sg_call_ents, ref->sg_call_ents);
  745. }
  746. /*
  747. * This may be no bug in reality - but most implementations of the
  748. * DMA API don't handle this properly, so check for it here
  749. */
  750. if (ref->direction != entry->direction) {
  751. err_printk(ref->dev, entry, "DMA-API: device driver frees "
  752. "DMA memory with different direction "
  753. "[device address=0x%016llx] [size=%llu bytes] "
  754. "[mapped with %s] [unmapped with %s]\n",
  755. ref->dev_addr, ref->size,
  756. dir2name[entry->direction],
  757. dir2name[ref->direction]);
  758. }
  759. if (entry->map_err_type == MAP_ERR_NOT_CHECKED) {
  760. err_printk(ref->dev, entry,
  761. "DMA-API: device driver failed to check map error"
  762. "[device address=0x%016llx] [size=%llu bytes] "
  763. "[mapped as %s]",
  764. ref->dev_addr, ref->size,
  765. type2name[entry->type]);
  766. }
  767. hash_bucket_del(entry);
  768. dma_entry_free(entry);
  769. out:
  770. put_hash_bucket(bucket, &flags);
  771. }
  772. static void check_for_stack(struct device *dev, void *addr)
  773. {
  774. if (object_is_on_stack(addr))
  775. err_printk(dev, NULL, "DMA-API: device driver maps memory from"
  776. "stack [addr=%p]\n", addr);
  777. }
  778. static inline bool overlap(void *addr, unsigned long len, void *start, void *end)
  779. {
  780. unsigned long a1 = (unsigned long)addr;
  781. unsigned long b1 = a1 + len;
  782. unsigned long a2 = (unsigned long)start;
  783. unsigned long b2 = (unsigned long)end;
  784. return !(b1 <= a2 || a1 >= b2);
  785. }
  786. static void check_for_illegal_area(struct device *dev, void *addr, unsigned long len)
  787. {
  788. if (overlap(addr, len, _text, _etext) ||
  789. overlap(addr, len, __start_rodata, __end_rodata))
  790. err_printk(dev, NULL, "DMA-API: device driver maps memory from kernel text or rodata [addr=%p] [len=%lu]\n", addr, len);
  791. }
  792. static void check_sync(struct device *dev,
  793. struct dma_debug_entry *ref,
  794. bool to_cpu)
  795. {
  796. struct dma_debug_entry *entry;
  797. struct hash_bucket *bucket;
  798. unsigned long flags;
  799. bucket = get_hash_bucket(ref, &flags);
  800. entry = bucket_find_contain(&bucket, ref, &flags);
  801. if (!entry) {
  802. err_printk(dev, NULL, "DMA-API: device driver tries "
  803. "to sync DMA memory it has not allocated "
  804. "[device address=0x%016llx] [size=%llu bytes]\n",
  805. (unsigned long long)ref->dev_addr, ref->size);
  806. goto out;
  807. }
  808. if (ref->size > entry->size) {
  809. err_printk(dev, entry, "DMA-API: device driver syncs"
  810. " DMA memory outside allocated range "
  811. "[device address=0x%016llx] "
  812. "[allocation size=%llu bytes] "
  813. "[sync offset+size=%llu]\n",
  814. entry->dev_addr, entry->size,
  815. ref->size);
  816. }
  817. if (entry->direction == DMA_BIDIRECTIONAL)
  818. goto out;
  819. if (ref->direction != entry->direction) {
  820. err_printk(dev, entry, "DMA-API: device driver syncs "
  821. "DMA memory with different direction "
  822. "[device address=0x%016llx] [size=%llu bytes] "
  823. "[mapped with %s] [synced with %s]\n",
  824. (unsigned long long)ref->dev_addr, entry->size,
  825. dir2name[entry->direction],
  826. dir2name[ref->direction]);
  827. }
  828. if (to_cpu && !(entry->direction == DMA_FROM_DEVICE) &&
  829. !(ref->direction == DMA_TO_DEVICE))
  830. err_printk(dev, entry, "DMA-API: device driver syncs "
  831. "device read-only DMA memory for cpu "
  832. "[device address=0x%016llx] [size=%llu bytes] "
  833. "[mapped with %s] [synced with %s]\n",
  834. (unsigned long long)ref->dev_addr, entry->size,
  835. dir2name[entry->direction],
  836. dir2name[ref->direction]);
  837. if (!to_cpu && !(entry->direction == DMA_TO_DEVICE) &&
  838. !(ref->direction == DMA_FROM_DEVICE))
  839. err_printk(dev, entry, "DMA-API: device driver syncs "
  840. "device write-only DMA memory to device "
  841. "[device address=0x%016llx] [size=%llu bytes] "
  842. "[mapped with %s] [synced with %s]\n",
  843. (unsigned long long)ref->dev_addr, entry->size,
  844. dir2name[entry->direction],
  845. dir2name[ref->direction]);
  846. out:
  847. put_hash_bucket(bucket, &flags);
  848. }
  849. void debug_dma_map_page(struct device *dev, struct page *page, size_t offset,
  850. size_t size, int direction, dma_addr_t dma_addr,
  851. bool map_single)
  852. {
  853. struct dma_debug_entry *entry;
  854. if (unlikely(global_disable))
  855. return;
  856. if (dma_mapping_error(dev, dma_addr))
  857. return;
  858. entry = dma_entry_alloc();
  859. if (!entry)
  860. return;
  861. entry->dev = dev;
  862. entry->type = dma_debug_page;
  863. entry->paddr = page_to_phys(page) + offset;
  864. entry->dev_addr = dma_addr;
  865. entry->size = size;
  866. entry->direction = direction;
  867. entry->map_err_type = MAP_ERR_NOT_CHECKED;
  868. if (map_single)
  869. entry->type = dma_debug_single;
  870. if (!PageHighMem(page)) {
  871. void *addr = page_address(page) + offset;
  872. check_for_stack(dev, addr);
  873. check_for_illegal_area(dev, addr, size);
  874. }
  875. add_dma_entry(entry);
  876. }
  877. EXPORT_SYMBOL(debug_dma_map_page);
  878. void debug_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  879. {
  880. struct dma_debug_entry ref;
  881. struct dma_debug_entry *entry;
  882. struct hash_bucket *bucket;
  883. unsigned long flags;
  884. if (unlikely(global_disable))
  885. return;
  886. ref.dev = dev;
  887. ref.dev_addr = dma_addr;
  888. bucket = get_hash_bucket(&ref, &flags);
  889. entry = bucket_find_exact(bucket, &ref);
  890. if (!entry)
  891. goto out;
  892. entry->map_err_type = MAP_ERR_CHECKED;
  893. out:
  894. put_hash_bucket(bucket, &flags);
  895. }
  896. EXPORT_SYMBOL(debug_dma_mapping_error);
  897. void debug_dma_unmap_page(struct device *dev, dma_addr_t addr,
  898. size_t size, int direction, bool map_single)
  899. {
  900. struct dma_debug_entry ref = {
  901. .type = dma_debug_page,
  902. .dev = dev,
  903. .dev_addr = addr,
  904. .size = size,
  905. .direction = direction,
  906. };
  907. if (unlikely(global_disable))
  908. return;
  909. if (map_single)
  910. ref.type = dma_debug_single;
  911. check_unmap(&ref);
  912. }
  913. EXPORT_SYMBOL(debug_dma_unmap_page);
  914. void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
  915. int nents, int mapped_ents, int direction)
  916. {
  917. struct dma_debug_entry *entry;
  918. struct scatterlist *s;
  919. int i;
  920. if (unlikely(global_disable))
  921. return;
  922. for_each_sg(sg, s, mapped_ents, i) {
  923. entry = dma_entry_alloc();
  924. if (!entry)
  925. return;
  926. entry->type = dma_debug_sg;
  927. entry->dev = dev;
  928. entry->paddr = sg_phys(s);
  929. entry->size = sg_dma_len(s);
  930. entry->dev_addr = sg_dma_address(s);
  931. entry->direction = direction;
  932. entry->sg_call_ents = nents;
  933. entry->sg_mapped_ents = mapped_ents;
  934. if (!PageHighMem(sg_page(s))) {
  935. check_for_stack(dev, sg_virt(s));
  936. check_for_illegal_area(dev, sg_virt(s), sg_dma_len(s));
  937. }
  938. add_dma_entry(entry);
  939. }
  940. }
  941. EXPORT_SYMBOL(debug_dma_map_sg);
  942. static int get_nr_mapped_entries(struct device *dev,
  943. struct dma_debug_entry *ref)
  944. {
  945. struct dma_debug_entry *entry;
  946. struct hash_bucket *bucket;
  947. unsigned long flags;
  948. int mapped_ents;
  949. bucket = get_hash_bucket(ref, &flags);
  950. entry = bucket_find_exact(bucket, ref);
  951. mapped_ents = 0;
  952. if (entry)
  953. mapped_ents = entry->sg_mapped_ents;
  954. put_hash_bucket(bucket, &flags);
  955. return mapped_ents;
  956. }
  957. void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
  958. int nelems, int dir)
  959. {
  960. struct scatterlist *s;
  961. int mapped_ents = 0, i;
  962. if (unlikely(global_disable))
  963. return;
  964. for_each_sg(sglist, s, nelems, i) {
  965. struct dma_debug_entry ref = {
  966. .type = dma_debug_sg,
  967. .dev = dev,
  968. .paddr = sg_phys(s),
  969. .dev_addr = sg_dma_address(s),
  970. .size = sg_dma_len(s),
  971. .direction = dir,
  972. .sg_call_ents = nelems,
  973. };
  974. if (mapped_ents && i >= mapped_ents)
  975. break;
  976. if (!i)
  977. mapped_ents = get_nr_mapped_entries(dev, &ref);
  978. check_unmap(&ref);
  979. }
  980. }
  981. EXPORT_SYMBOL(debug_dma_unmap_sg);
  982. void debug_dma_alloc_coherent(struct device *dev, size_t size,
  983. dma_addr_t dma_addr, void *virt)
  984. {
  985. struct dma_debug_entry *entry;
  986. if (unlikely(global_disable))
  987. return;
  988. if (unlikely(virt == NULL))
  989. return;
  990. entry = dma_entry_alloc();
  991. if (!entry)
  992. return;
  993. entry->type = dma_debug_coherent;
  994. entry->dev = dev;
  995. entry->paddr = virt_to_phys(virt);
  996. entry->size = size;
  997. entry->dev_addr = dma_addr;
  998. entry->direction = DMA_BIDIRECTIONAL;
  999. add_dma_entry(entry);
  1000. }
  1001. EXPORT_SYMBOL(debug_dma_alloc_coherent);
  1002. void debug_dma_free_coherent(struct device *dev, size_t size,
  1003. void *virt, dma_addr_t addr)
  1004. {
  1005. struct dma_debug_entry ref = {
  1006. .type = dma_debug_coherent,
  1007. .dev = dev,
  1008. .paddr = virt_to_phys(virt),
  1009. .dev_addr = addr,
  1010. .size = size,
  1011. .direction = DMA_BIDIRECTIONAL,
  1012. };
  1013. if (unlikely(global_disable))
  1014. return;
  1015. check_unmap(&ref);
  1016. }
  1017. EXPORT_SYMBOL(debug_dma_free_coherent);
  1018. void debug_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
  1019. size_t size, int direction)
  1020. {
  1021. struct dma_debug_entry ref;
  1022. if (unlikely(global_disable))
  1023. return;
  1024. ref.type = dma_debug_single;
  1025. ref.dev = dev;
  1026. ref.dev_addr = dma_handle;
  1027. ref.size = size;
  1028. ref.direction = direction;
  1029. ref.sg_call_ents = 0;
  1030. check_sync(dev, &ref, true);
  1031. }
  1032. EXPORT_SYMBOL(debug_dma_sync_single_for_cpu);
  1033. void debug_dma_sync_single_for_device(struct device *dev,
  1034. dma_addr_t dma_handle, size_t size,
  1035. int direction)
  1036. {
  1037. struct dma_debug_entry ref;
  1038. if (unlikely(global_disable))
  1039. return;
  1040. ref.type = dma_debug_single;
  1041. ref.dev = dev;
  1042. ref.dev_addr = dma_handle;
  1043. ref.size = size;
  1044. ref.direction = direction;
  1045. ref.sg_call_ents = 0;
  1046. check_sync(dev, &ref, false);
  1047. }
  1048. EXPORT_SYMBOL(debug_dma_sync_single_for_device);
  1049. void debug_dma_sync_single_range_for_cpu(struct device *dev,
  1050. dma_addr_t dma_handle,
  1051. unsigned long offset, size_t size,
  1052. int direction)
  1053. {
  1054. struct dma_debug_entry ref;
  1055. if (unlikely(global_disable))
  1056. return;
  1057. ref.type = dma_debug_single;
  1058. ref.dev = dev;
  1059. ref.dev_addr = dma_handle;
  1060. ref.size = offset + size;
  1061. ref.direction = direction;
  1062. ref.sg_call_ents = 0;
  1063. check_sync(dev, &ref, true);
  1064. }
  1065. EXPORT_SYMBOL(debug_dma_sync_single_range_for_cpu);
  1066. void debug_dma_sync_single_range_for_device(struct device *dev,
  1067. dma_addr_t dma_handle,
  1068. unsigned long offset,
  1069. size_t size, int direction)
  1070. {
  1071. struct dma_debug_entry ref;
  1072. if (unlikely(global_disable))
  1073. return;
  1074. ref.type = dma_debug_single;
  1075. ref.dev = dev;
  1076. ref.dev_addr = dma_handle;
  1077. ref.size = offset + size;
  1078. ref.direction = direction;
  1079. ref.sg_call_ents = 0;
  1080. check_sync(dev, &ref, false);
  1081. }
  1082. EXPORT_SYMBOL(debug_dma_sync_single_range_for_device);
  1083. void debug_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
  1084. int nelems, int direction)
  1085. {
  1086. struct scatterlist *s;
  1087. int mapped_ents = 0, i;
  1088. if (unlikely(global_disable))
  1089. return;
  1090. for_each_sg(sg, s, nelems, i) {
  1091. struct dma_debug_entry ref = {
  1092. .type = dma_debug_sg,
  1093. .dev = dev,
  1094. .paddr = sg_phys(s),
  1095. .dev_addr = sg_dma_address(s),
  1096. .size = sg_dma_len(s),
  1097. .direction = direction,
  1098. .sg_call_ents = nelems,
  1099. };
  1100. if (!i)
  1101. mapped_ents = get_nr_mapped_entries(dev, &ref);
  1102. if (i >= mapped_ents)
  1103. break;
  1104. check_sync(dev, &ref, true);
  1105. }
  1106. }
  1107. EXPORT_SYMBOL(debug_dma_sync_sg_for_cpu);
  1108. void debug_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
  1109. int nelems, int direction)
  1110. {
  1111. struct scatterlist *s;
  1112. int mapped_ents = 0, i;
  1113. if (unlikely(global_disable))
  1114. return;
  1115. for_each_sg(sg, s, nelems, i) {
  1116. struct dma_debug_entry ref = {
  1117. .type = dma_debug_sg,
  1118. .dev = dev,
  1119. .paddr = sg_phys(s),
  1120. .dev_addr = sg_dma_address(s),
  1121. .size = sg_dma_len(s),
  1122. .direction = direction,
  1123. .sg_call_ents = nelems,
  1124. };
  1125. if (!i)
  1126. mapped_ents = get_nr_mapped_entries(dev, &ref);
  1127. if (i >= mapped_ents)
  1128. break;
  1129. check_sync(dev, &ref, false);
  1130. }
  1131. }
  1132. EXPORT_SYMBOL(debug_dma_sync_sg_for_device);
  1133. static int __init dma_debug_driver_setup(char *str)
  1134. {
  1135. int i;
  1136. for (i = 0; i < NAME_MAX_LEN - 1; ++i, ++str) {
  1137. current_driver_name[i] = *str;
  1138. if (*str == 0)
  1139. break;
  1140. }
  1141. if (current_driver_name[0])
  1142. pr_info("DMA-API: enable driver filter for driver [%s]\n",
  1143. current_driver_name);
  1144. return 1;
  1145. }
  1146. __setup("dma_debug_driver=", dma_debug_driver_setup);