dma-debug.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  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. /* must drop lock before calling dma_mapping_error */
  703. put_hash_bucket(bucket, &flags);
  704. if (dma_mapping_error(ref->dev, ref->dev_addr)) {
  705. err_printk(ref->dev, NULL,
  706. "DMA-API: device driver tries to free an "
  707. "invalid DMA memory address\n");
  708. } else {
  709. err_printk(ref->dev, NULL,
  710. "DMA-API: device driver tries to free DMA "
  711. "memory it has not allocated [device "
  712. "address=0x%016llx] [size=%llu bytes]\n",
  713. ref->dev_addr, ref->size);
  714. }
  715. return;
  716. }
  717. if (ref->size != entry->size) {
  718. err_printk(ref->dev, entry, "DMA-API: device driver frees "
  719. "DMA memory with different size "
  720. "[device address=0x%016llx] [map size=%llu bytes] "
  721. "[unmap size=%llu bytes]\n",
  722. ref->dev_addr, entry->size, ref->size);
  723. }
  724. if (ref->type != entry->type) {
  725. err_printk(ref->dev, entry, "DMA-API: device driver frees "
  726. "DMA memory with wrong function "
  727. "[device address=0x%016llx] [size=%llu bytes] "
  728. "[mapped as %s] [unmapped as %s]\n",
  729. ref->dev_addr, ref->size,
  730. type2name[entry->type], type2name[ref->type]);
  731. } else if ((entry->type == dma_debug_coherent) &&
  732. (ref->paddr != entry->paddr)) {
  733. err_printk(ref->dev, entry, "DMA-API: device driver frees "
  734. "DMA memory with different CPU address "
  735. "[device address=0x%016llx] [size=%llu bytes] "
  736. "[cpu alloc address=0x%016llx] "
  737. "[cpu free address=0x%016llx]",
  738. ref->dev_addr, ref->size,
  739. (unsigned long long)entry->paddr,
  740. (unsigned long long)ref->paddr);
  741. }
  742. if (ref->sg_call_ents && ref->type == dma_debug_sg &&
  743. ref->sg_call_ents != entry->sg_call_ents) {
  744. err_printk(ref->dev, entry, "DMA-API: device driver frees "
  745. "DMA sg list with different entry count "
  746. "[map count=%d] [unmap count=%d]\n",
  747. entry->sg_call_ents, ref->sg_call_ents);
  748. }
  749. /*
  750. * This may be no bug in reality - but most implementations of the
  751. * DMA API don't handle this properly, so check for it here
  752. */
  753. if (ref->direction != entry->direction) {
  754. err_printk(ref->dev, entry, "DMA-API: device driver frees "
  755. "DMA memory with different direction "
  756. "[device address=0x%016llx] [size=%llu bytes] "
  757. "[mapped with %s] [unmapped with %s]\n",
  758. ref->dev_addr, ref->size,
  759. dir2name[entry->direction],
  760. dir2name[ref->direction]);
  761. }
  762. if (entry->map_err_type == MAP_ERR_NOT_CHECKED) {
  763. err_printk(ref->dev, entry,
  764. "DMA-API: device driver failed to check map error"
  765. "[device address=0x%016llx] [size=%llu bytes] "
  766. "[mapped as %s]",
  767. ref->dev_addr, ref->size,
  768. type2name[entry->type]);
  769. }
  770. hash_bucket_del(entry);
  771. dma_entry_free(entry);
  772. put_hash_bucket(bucket, &flags);
  773. }
  774. static void check_for_stack(struct device *dev, void *addr)
  775. {
  776. if (object_is_on_stack(addr))
  777. err_printk(dev, NULL, "DMA-API: device driver maps memory from"
  778. "stack [addr=%p]\n", addr);
  779. }
  780. static inline bool overlap(void *addr, unsigned long len, void *start, void *end)
  781. {
  782. unsigned long a1 = (unsigned long)addr;
  783. unsigned long b1 = a1 + len;
  784. unsigned long a2 = (unsigned long)start;
  785. unsigned long b2 = (unsigned long)end;
  786. return !(b1 <= a2 || a1 >= b2);
  787. }
  788. static void check_for_illegal_area(struct device *dev, void *addr, unsigned long len)
  789. {
  790. if (overlap(addr, len, _text, _etext) ||
  791. overlap(addr, len, __start_rodata, __end_rodata))
  792. err_printk(dev, NULL, "DMA-API: device driver maps memory from kernel text or rodata [addr=%p] [len=%lu]\n", addr, len);
  793. }
  794. static void check_sync(struct device *dev,
  795. struct dma_debug_entry *ref,
  796. bool to_cpu)
  797. {
  798. struct dma_debug_entry *entry;
  799. struct hash_bucket *bucket;
  800. unsigned long flags;
  801. bucket = get_hash_bucket(ref, &flags);
  802. entry = bucket_find_contain(&bucket, ref, &flags);
  803. if (!entry) {
  804. err_printk(dev, NULL, "DMA-API: device driver tries "
  805. "to sync DMA memory it has not allocated "
  806. "[device address=0x%016llx] [size=%llu bytes]\n",
  807. (unsigned long long)ref->dev_addr, ref->size);
  808. goto out;
  809. }
  810. if (ref->size > entry->size) {
  811. err_printk(dev, entry, "DMA-API: device driver syncs"
  812. " DMA memory outside allocated range "
  813. "[device address=0x%016llx] "
  814. "[allocation size=%llu bytes] "
  815. "[sync offset+size=%llu]\n",
  816. entry->dev_addr, entry->size,
  817. ref->size);
  818. }
  819. if (entry->direction == DMA_BIDIRECTIONAL)
  820. goto out;
  821. if (ref->direction != entry->direction) {
  822. err_printk(dev, entry, "DMA-API: device driver syncs "
  823. "DMA memory with different direction "
  824. "[device address=0x%016llx] [size=%llu bytes] "
  825. "[mapped with %s] [synced with %s]\n",
  826. (unsigned long long)ref->dev_addr, entry->size,
  827. dir2name[entry->direction],
  828. dir2name[ref->direction]);
  829. }
  830. if (to_cpu && !(entry->direction == DMA_FROM_DEVICE) &&
  831. !(ref->direction == DMA_TO_DEVICE))
  832. err_printk(dev, entry, "DMA-API: device driver syncs "
  833. "device read-only DMA memory for cpu "
  834. "[device address=0x%016llx] [size=%llu bytes] "
  835. "[mapped with %s] [synced with %s]\n",
  836. (unsigned long long)ref->dev_addr, entry->size,
  837. dir2name[entry->direction],
  838. dir2name[ref->direction]);
  839. if (!to_cpu && !(entry->direction == DMA_TO_DEVICE) &&
  840. !(ref->direction == DMA_FROM_DEVICE))
  841. err_printk(dev, entry, "DMA-API: device driver syncs "
  842. "device write-only DMA memory to device "
  843. "[device address=0x%016llx] [size=%llu bytes] "
  844. "[mapped with %s] [synced with %s]\n",
  845. (unsigned long long)ref->dev_addr, entry->size,
  846. dir2name[entry->direction],
  847. dir2name[ref->direction]);
  848. out:
  849. put_hash_bucket(bucket, &flags);
  850. }
  851. void debug_dma_map_page(struct device *dev, struct page *page, size_t offset,
  852. size_t size, int direction, dma_addr_t dma_addr,
  853. bool map_single)
  854. {
  855. struct dma_debug_entry *entry;
  856. if (unlikely(global_disable))
  857. return;
  858. if (dma_mapping_error(dev, dma_addr))
  859. return;
  860. entry = dma_entry_alloc();
  861. if (!entry)
  862. return;
  863. entry->dev = dev;
  864. entry->type = dma_debug_page;
  865. entry->paddr = page_to_phys(page) + offset;
  866. entry->dev_addr = dma_addr;
  867. entry->size = size;
  868. entry->direction = direction;
  869. entry->map_err_type = MAP_ERR_NOT_CHECKED;
  870. if (map_single)
  871. entry->type = dma_debug_single;
  872. if (!PageHighMem(page)) {
  873. void *addr = page_address(page) + offset;
  874. check_for_stack(dev, addr);
  875. check_for_illegal_area(dev, addr, size);
  876. }
  877. add_dma_entry(entry);
  878. }
  879. EXPORT_SYMBOL(debug_dma_map_page);
  880. void debug_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
  881. {
  882. struct dma_debug_entry ref;
  883. struct dma_debug_entry *entry;
  884. struct hash_bucket *bucket;
  885. unsigned long flags;
  886. if (unlikely(global_disable))
  887. return;
  888. ref.dev = dev;
  889. ref.dev_addr = dma_addr;
  890. bucket = get_hash_bucket(&ref, &flags);
  891. entry = bucket_find_exact(bucket, &ref);
  892. if (!entry)
  893. goto out;
  894. entry->map_err_type = MAP_ERR_CHECKED;
  895. out:
  896. put_hash_bucket(bucket, &flags);
  897. }
  898. EXPORT_SYMBOL(debug_dma_mapping_error);
  899. void debug_dma_unmap_page(struct device *dev, dma_addr_t addr,
  900. size_t size, int direction, bool map_single)
  901. {
  902. struct dma_debug_entry ref = {
  903. .type = dma_debug_page,
  904. .dev = dev,
  905. .dev_addr = addr,
  906. .size = size,
  907. .direction = direction,
  908. };
  909. if (unlikely(global_disable))
  910. return;
  911. if (map_single)
  912. ref.type = dma_debug_single;
  913. check_unmap(&ref);
  914. }
  915. EXPORT_SYMBOL(debug_dma_unmap_page);
  916. void debug_dma_map_sg(struct device *dev, struct scatterlist *sg,
  917. int nents, int mapped_ents, int direction)
  918. {
  919. struct dma_debug_entry *entry;
  920. struct scatterlist *s;
  921. int i;
  922. if (unlikely(global_disable))
  923. return;
  924. for_each_sg(sg, s, mapped_ents, i) {
  925. entry = dma_entry_alloc();
  926. if (!entry)
  927. return;
  928. entry->type = dma_debug_sg;
  929. entry->dev = dev;
  930. entry->paddr = sg_phys(s);
  931. entry->size = sg_dma_len(s);
  932. entry->dev_addr = sg_dma_address(s);
  933. entry->direction = direction;
  934. entry->sg_call_ents = nents;
  935. entry->sg_mapped_ents = mapped_ents;
  936. if (!PageHighMem(sg_page(s))) {
  937. check_for_stack(dev, sg_virt(s));
  938. check_for_illegal_area(dev, sg_virt(s), sg_dma_len(s));
  939. }
  940. add_dma_entry(entry);
  941. }
  942. }
  943. EXPORT_SYMBOL(debug_dma_map_sg);
  944. static int get_nr_mapped_entries(struct device *dev,
  945. struct dma_debug_entry *ref)
  946. {
  947. struct dma_debug_entry *entry;
  948. struct hash_bucket *bucket;
  949. unsigned long flags;
  950. int mapped_ents;
  951. bucket = get_hash_bucket(ref, &flags);
  952. entry = bucket_find_exact(bucket, ref);
  953. mapped_ents = 0;
  954. if (entry)
  955. mapped_ents = entry->sg_mapped_ents;
  956. put_hash_bucket(bucket, &flags);
  957. return mapped_ents;
  958. }
  959. void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
  960. int nelems, int dir)
  961. {
  962. struct scatterlist *s;
  963. int mapped_ents = 0, i;
  964. if (unlikely(global_disable))
  965. return;
  966. for_each_sg(sglist, s, nelems, i) {
  967. struct dma_debug_entry ref = {
  968. .type = dma_debug_sg,
  969. .dev = dev,
  970. .paddr = sg_phys(s),
  971. .dev_addr = sg_dma_address(s),
  972. .size = sg_dma_len(s),
  973. .direction = dir,
  974. .sg_call_ents = nelems,
  975. };
  976. if (mapped_ents && i >= mapped_ents)
  977. break;
  978. if (!i)
  979. mapped_ents = get_nr_mapped_entries(dev, &ref);
  980. check_unmap(&ref);
  981. }
  982. }
  983. EXPORT_SYMBOL(debug_dma_unmap_sg);
  984. void debug_dma_alloc_coherent(struct device *dev, size_t size,
  985. dma_addr_t dma_addr, void *virt)
  986. {
  987. struct dma_debug_entry *entry;
  988. if (unlikely(global_disable))
  989. return;
  990. if (unlikely(virt == NULL))
  991. return;
  992. entry = dma_entry_alloc();
  993. if (!entry)
  994. return;
  995. entry->type = dma_debug_coherent;
  996. entry->dev = dev;
  997. entry->paddr = virt_to_phys(virt);
  998. entry->size = size;
  999. entry->dev_addr = dma_addr;
  1000. entry->direction = DMA_BIDIRECTIONAL;
  1001. add_dma_entry(entry);
  1002. }
  1003. EXPORT_SYMBOL(debug_dma_alloc_coherent);
  1004. void debug_dma_free_coherent(struct device *dev, size_t size,
  1005. void *virt, dma_addr_t addr)
  1006. {
  1007. struct dma_debug_entry ref = {
  1008. .type = dma_debug_coherent,
  1009. .dev = dev,
  1010. .paddr = virt_to_phys(virt),
  1011. .dev_addr = addr,
  1012. .size = size,
  1013. .direction = DMA_BIDIRECTIONAL,
  1014. };
  1015. if (unlikely(global_disable))
  1016. return;
  1017. check_unmap(&ref);
  1018. }
  1019. EXPORT_SYMBOL(debug_dma_free_coherent);
  1020. void debug_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
  1021. size_t size, int direction)
  1022. {
  1023. struct dma_debug_entry ref;
  1024. if (unlikely(global_disable))
  1025. return;
  1026. ref.type = dma_debug_single;
  1027. ref.dev = dev;
  1028. ref.dev_addr = dma_handle;
  1029. ref.size = size;
  1030. ref.direction = direction;
  1031. ref.sg_call_ents = 0;
  1032. check_sync(dev, &ref, true);
  1033. }
  1034. EXPORT_SYMBOL(debug_dma_sync_single_for_cpu);
  1035. void debug_dma_sync_single_for_device(struct device *dev,
  1036. dma_addr_t dma_handle, size_t size,
  1037. int direction)
  1038. {
  1039. struct dma_debug_entry ref;
  1040. if (unlikely(global_disable))
  1041. return;
  1042. ref.type = dma_debug_single;
  1043. ref.dev = dev;
  1044. ref.dev_addr = dma_handle;
  1045. ref.size = size;
  1046. ref.direction = direction;
  1047. ref.sg_call_ents = 0;
  1048. check_sync(dev, &ref, false);
  1049. }
  1050. EXPORT_SYMBOL(debug_dma_sync_single_for_device);
  1051. void debug_dma_sync_single_range_for_cpu(struct device *dev,
  1052. dma_addr_t dma_handle,
  1053. unsigned long offset, size_t size,
  1054. int direction)
  1055. {
  1056. struct dma_debug_entry ref;
  1057. if (unlikely(global_disable))
  1058. return;
  1059. ref.type = dma_debug_single;
  1060. ref.dev = dev;
  1061. ref.dev_addr = dma_handle;
  1062. ref.size = offset + size;
  1063. ref.direction = direction;
  1064. ref.sg_call_ents = 0;
  1065. check_sync(dev, &ref, true);
  1066. }
  1067. EXPORT_SYMBOL(debug_dma_sync_single_range_for_cpu);
  1068. void debug_dma_sync_single_range_for_device(struct device *dev,
  1069. dma_addr_t dma_handle,
  1070. unsigned long offset,
  1071. size_t size, int direction)
  1072. {
  1073. struct dma_debug_entry ref;
  1074. if (unlikely(global_disable))
  1075. return;
  1076. ref.type = dma_debug_single;
  1077. ref.dev = dev;
  1078. ref.dev_addr = dma_handle;
  1079. ref.size = offset + size;
  1080. ref.direction = direction;
  1081. ref.sg_call_ents = 0;
  1082. check_sync(dev, &ref, false);
  1083. }
  1084. EXPORT_SYMBOL(debug_dma_sync_single_range_for_device);
  1085. void debug_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
  1086. int nelems, int direction)
  1087. {
  1088. struct scatterlist *s;
  1089. int mapped_ents = 0, i;
  1090. if (unlikely(global_disable))
  1091. return;
  1092. for_each_sg(sg, s, nelems, i) {
  1093. struct dma_debug_entry ref = {
  1094. .type = dma_debug_sg,
  1095. .dev = dev,
  1096. .paddr = sg_phys(s),
  1097. .dev_addr = sg_dma_address(s),
  1098. .size = sg_dma_len(s),
  1099. .direction = direction,
  1100. .sg_call_ents = nelems,
  1101. };
  1102. if (!i)
  1103. mapped_ents = get_nr_mapped_entries(dev, &ref);
  1104. if (i >= mapped_ents)
  1105. break;
  1106. check_sync(dev, &ref, true);
  1107. }
  1108. }
  1109. EXPORT_SYMBOL(debug_dma_sync_sg_for_cpu);
  1110. void debug_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
  1111. int nelems, int direction)
  1112. {
  1113. struct scatterlist *s;
  1114. int mapped_ents = 0, i;
  1115. if (unlikely(global_disable))
  1116. return;
  1117. for_each_sg(sg, s, nelems, i) {
  1118. struct dma_debug_entry ref = {
  1119. .type = dma_debug_sg,
  1120. .dev = dev,
  1121. .paddr = sg_phys(s),
  1122. .dev_addr = sg_dma_address(s),
  1123. .size = sg_dma_len(s),
  1124. .direction = direction,
  1125. .sg_call_ents = nelems,
  1126. };
  1127. if (!i)
  1128. mapped_ents = get_nr_mapped_entries(dev, &ref);
  1129. if (i >= mapped_ents)
  1130. break;
  1131. check_sync(dev, &ref, false);
  1132. }
  1133. }
  1134. EXPORT_SYMBOL(debug_dma_sync_sg_for_device);
  1135. static int __init dma_debug_driver_setup(char *str)
  1136. {
  1137. int i;
  1138. for (i = 0; i < NAME_MAX_LEN - 1; ++i, ++str) {
  1139. current_driver_name[i] = *str;
  1140. if (*str == 0)
  1141. break;
  1142. }
  1143. if (current_driver_name[0])
  1144. pr_info("DMA-API: enable driver filter for driver [%s]\n",
  1145. current_driver_name);
  1146. return 1;
  1147. }
  1148. __setup("dma_debug_driver=", dma_debug_driver_setup);