Joerg Roedel | f2f45e5 | 2009-01-09 12:19:52 +0100 | [diff] [blame] | 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 | |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 20 | #include <linux/scatterlist.h> |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 21 | #include <linux/dma-mapping.h> |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 22 | #include <linux/stacktrace.h> |
Joerg Roedel | f2f45e5 | 2009-01-09 12:19:52 +0100 | [diff] [blame] | 23 | #include <linux/dma-debug.h> |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 24 | #include <linux/spinlock.h> |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 25 | #include <linux/debugfs.h> |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 26 | #include <linux/uaccess.h> |
Paul Gortmaker | 23a7bfa | 2011-07-01 16:23:59 -0400 | [diff] [blame] | 27 | #include <linux/export.h> |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 28 | #include <linux/device.h> |
Joerg Roedel | f2f45e5 | 2009-01-09 12:19:52 +0100 | [diff] [blame] | 29 | #include <linux/types.h> |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 30 | #include <linux/sched.h> |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 31 | #include <linux/ctype.h> |
Joerg Roedel | f2f45e5 | 2009-01-09 12:19:52 +0100 | [diff] [blame] | 32 | #include <linux/list.h> |
Joerg Roedel | 6bf0787 | 2009-01-09 12:54:42 +0100 | [diff] [blame] | 33 | #include <linux/slab.h> |
Joerg Roedel | f2f45e5 | 2009-01-09 12:19:52 +0100 | [diff] [blame] | 34 | |
Joerg Roedel | 2e34bde | 2009-03-16 16:51:55 +0100 | [diff] [blame] | 35 | #include <asm/sections.h> |
| 36 | |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 37 | #define HASH_SIZE 1024ULL |
| 38 | #define HASH_FN_SHIFT 13 |
| 39 | #define HASH_FN_MASK (HASH_SIZE - 1) |
| 40 | |
Joerg Roedel | f2f45e5 | 2009-01-09 12:19:52 +0100 | [diff] [blame] | 41 | enum { |
| 42 | dma_debug_single, |
| 43 | dma_debug_page, |
| 44 | dma_debug_sg, |
| 45 | dma_debug_coherent, |
| 46 | }; |
| 47 | |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 48 | enum map_err_types { |
| 49 | MAP_ERR_CHECK_NOT_APPLICABLE, |
| 50 | MAP_ERR_NOT_CHECKED, |
| 51 | MAP_ERR_CHECKED, |
| 52 | }; |
| 53 | |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 54 | #define DMA_DEBUG_STACKTRACE_ENTRIES 5 |
| 55 | |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 56 | /** |
| 57 | * struct dma_debug_entry - track a dma_map* or dma_alloc_coherent mapping |
| 58 | * @list: node on pre-allocated free_entries list |
| 59 | * @dev: 'dev' argument to dma_map_{page|single|sg} or dma_alloc_coherent |
| 60 | * @type: single, page, sg, coherent |
| 61 | * @pfn: page frame of the start address |
| 62 | * @offset: offset of mapping relative to pfn |
| 63 | * @size: length of the mapping |
| 64 | * @direction: enum dma_data_direction |
| 65 | * @sg_call_ents: 'nents' from dma_map_sg |
| 66 | * @sg_mapped_ents: 'mapped_ents' from dma_map_sg |
| 67 | * @map_err_type: track whether dma_mapping_error() was checked |
| 68 | * @stacktrace: support backtraces when a violation is detected |
| 69 | */ |
Joerg Roedel | f2f45e5 | 2009-01-09 12:19:52 +0100 | [diff] [blame] | 70 | struct dma_debug_entry { |
| 71 | struct list_head list; |
| 72 | struct device *dev; |
| 73 | int type; |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 74 | unsigned long pfn; |
| 75 | size_t offset; |
Joerg Roedel | f2f45e5 | 2009-01-09 12:19:52 +0100 | [diff] [blame] | 76 | u64 dev_addr; |
| 77 | u64 size; |
| 78 | int direction; |
| 79 | int sg_call_ents; |
| 80 | int sg_mapped_ents; |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 81 | enum map_err_types map_err_type; |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 82 | #ifdef CONFIG_STACKTRACE |
| 83 | struct stack_trace stacktrace; |
| 84 | unsigned long st_entries[DMA_DEBUG_STACKTRACE_ENTRIES]; |
| 85 | #endif |
Joerg Roedel | f2f45e5 | 2009-01-09 12:19:52 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
Neil Horman | c6a21d0 | 2011-08-08 15:13:54 -0400 | [diff] [blame] | 88 | typedef bool (*match_fn)(struct dma_debug_entry *, struct dma_debug_entry *); |
| 89 | |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 90 | struct hash_bucket { |
| 91 | struct list_head list; |
| 92 | spinlock_t lock; |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 93 | } ____cacheline_aligned_in_smp; |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 94 | |
| 95 | /* Hash list to save the allocated dma addresses */ |
| 96 | static struct hash_bucket dma_entry_hash[HASH_SIZE]; |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 97 | /* List of pre-allocated dma_debug_entry's */ |
| 98 | static LIST_HEAD(free_entries); |
| 99 | /* Lock for the list above */ |
| 100 | static DEFINE_SPINLOCK(free_entries_lock); |
| 101 | |
| 102 | /* Global disable flag - will be set in case of an error */ |
Dan Carpenter | 68ee6d2 | 2012-06-27 12:08:55 +0300 | [diff] [blame] | 103 | static u32 global_disable __read_mostly; |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 104 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 105 | static inline bool dma_debug_disabled(void) |
| 106 | { |
| 107 | return global_disable; |
| 108 | } |
| 109 | |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 110 | /* Global error count */ |
| 111 | static u32 error_count; |
| 112 | |
| 113 | /* Global error show enable*/ |
| 114 | static u32 show_all_errors __read_mostly; |
| 115 | /* Number of errors to show */ |
| 116 | static u32 show_num_errors = 1; |
| 117 | |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 118 | static u32 num_free_entries; |
| 119 | static u32 min_free_entries; |
FUJITA Tomonori | e6a1a89 | 2009-04-15 18:22:41 +0900 | [diff] [blame] | 120 | static u32 nr_total_entries; |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 121 | |
Joerg Roedel | 59d3daa | 2009-01-09 13:01:56 +0100 | [diff] [blame] | 122 | /* number of preallocated entries requested by kernel cmdline */ |
| 123 | static u32 req_entries; |
| 124 | |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 125 | /* debugfs dentry's for the stuff above */ |
| 126 | static struct dentry *dma_debug_dent __read_mostly; |
| 127 | static struct dentry *global_disable_dent __read_mostly; |
| 128 | static struct dentry *error_count_dent __read_mostly; |
| 129 | static struct dentry *show_all_errors_dent __read_mostly; |
| 130 | static struct dentry *show_num_errors_dent __read_mostly; |
| 131 | static struct dentry *num_free_entries_dent __read_mostly; |
| 132 | static struct dentry *min_free_entries_dent __read_mostly; |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 133 | static struct dentry *filter_dent __read_mostly; |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 134 | |
Joerg Roedel | 2e507d8 | 2009-05-22 18:24:20 +0200 | [diff] [blame] | 135 | /* per-driver filter related state */ |
| 136 | |
| 137 | #define NAME_MAX_LEN 64 |
| 138 | |
| 139 | static char current_driver_name[NAME_MAX_LEN] __read_mostly; |
| 140 | static struct device_driver *current_driver __read_mostly; |
| 141 | |
| 142 | static DEFINE_RWLOCK(driver_name_lock); |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 143 | |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 144 | static const char *const maperr2str[] = { |
| 145 | [MAP_ERR_CHECK_NOT_APPLICABLE] = "dma map error check not applicable", |
| 146 | [MAP_ERR_NOT_CHECKED] = "dma map error not checked", |
| 147 | [MAP_ERR_CHECKED] = "dma map error checked", |
| 148 | }; |
| 149 | |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 150 | static const char *type2name[4] = { "single", "page", |
| 151 | "scather-gather", "coherent" }; |
| 152 | |
| 153 | static const char *dir2name[4] = { "DMA_BIDIRECTIONAL", "DMA_TO_DEVICE", |
| 154 | "DMA_FROM_DEVICE", "DMA_NONE" }; |
| 155 | |
| 156 | /* |
| 157 | * The access to some variables in this macro is racy. We can't use atomic_t |
| 158 | * here because all these variables are exported to debugfs. Some of them even |
| 159 | * writeable. This is also the reason why a lock won't help much. But anyway, |
| 160 | * the races are no big deal. Here is why: |
| 161 | * |
| 162 | * error_count: the addition is racy, but the worst thing that can happen is |
| 163 | * that we don't count some errors |
| 164 | * show_num_errors: the subtraction is racy. Also no big deal because in |
| 165 | * worst case this will result in one warning more in the |
| 166 | * system log than the user configured. This variable is |
| 167 | * writeable via debugfs. |
| 168 | */ |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 169 | static inline void dump_entry_trace(struct dma_debug_entry *entry) |
| 170 | { |
| 171 | #ifdef CONFIG_STACKTRACE |
| 172 | if (entry) { |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 173 | pr_warning("Mapped at:\n"); |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 174 | print_stack_trace(&entry->stacktrace, 0); |
| 175 | } |
| 176 | #endif |
| 177 | } |
| 178 | |
Joerg Roedel | 2e507d8 | 2009-05-22 18:24:20 +0200 | [diff] [blame] | 179 | static bool driver_filter(struct device *dev) |
| 180 | { |
Joerg Roedel | 0bf8412 | 2009-06-08 15:53:46 +0200 | [diff] [blame] | 181 | struct device_driver *drv; |
| 182 | unsigned long flags; |
| 183 | bool ret; |
| 184 | |
Joerg Roedel | 2e507d8 | 2009-05-22 18:24:20 +0200 | [diff] [blame] | 185 | /* driver filter off */ |
| 186 | if (likely(!current_driver_name[0])) |
| 187 | return true; |
| 188 | |
| 189 | /* driver filter on and initialized */ |
Kyle McMartin | ec9c96e | 2009-08-19 21:17:08 -0400 | [diff] [blame] | 190 | if (current_driver && dev && dev->driver == current_driver) |
Joerg Roedel | 2e507d8 | 2009-05-22 18:24:20 +0200 | [diff] [blame] | 191 | return true; |
| 192 | |
Kyle McMartin | ec9c96e | 2009-08-19 21:17:08 -0400 | [diff] [blame] | 193 | /* driver filter on, but we can't filter on a NULL device... */ |
| 194 | if (!dev) |
| 195 | return false; |
| 196 | |
Joerg Roedel | 0bf8412 | 2009-06-08 15:53:46 +0200 | [diff] [blame] | 197 | if (current_driver || !current_driver_name[0]) |
| 198 | return false; |
| 199 | |
Joerg Roedel | 2e507d8 | 2009-05-22 18:24:20 +0200 | [diff] [blame] | 200 | /* driver filter on but not yet initialized */ |
Alan Stern | f3ff924 | 2012-01-24 13:35:24 -0500 | [diff] [blame] | 201 | drv = dev->driver; |
Joerg Roedel | 0bf8412 | 2009-06-08 15:53:46 +0200 | [diff] [blame] | 202 | if (!drv) |
| 203 | return false; |
Joerg Roedel | 2e507d8 | 2009-05-22 18:24:20 +0200 | [diff] [blame] | 204 | |
Joerg Roedel | 0bf8412 | 2009-06-08 15:53:46 +0200 | [diff] [blame] | 205 | /* lock to protect against change of current_driver_name */ |
| 206 | read_lock_irqsave(&driver_name_lock, flags); |
Joerg Roedel | 2e507d8 | 2009-05-22 18:24:20 +0200 | [diff] [blame] | 207 | |
Joerg Roedel | 0bf8412 | 2009-06-08 15:53:46 +0200 | [diff] [blame] | 208 | ret = false; |
| 209 | if (drv->name && |
| 210 | strncmp(current_driver_name, drv->name, NAME_MAX_LEN - 1) == 0) { |
| 211 | current_driver = drv; |
| 212 | ret = true; |
Joerg Roedel | 2e507d8 | 2009-05-22 18:24:20 +0200 | [diff] [blame] | 213 | } |
| 214 | |
Joerg Roedel | 0bf8412 | 2009-06-08 15:53:46 +0200 | [diff] [blame] | 215 | read_unlock_irqrestore(&driver_name_lock, flags); |
Joerg Roedel | 0bf8412 | 2009-06-08 15:53:46 +0200 | [diff] [blame] | 216 | |
| 217 | return ret; |
Joerg Roedel | 2e507d8 | 2009-05-22 18:24:20 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Kyle McMartin | ec9c96e | 2009-08-19 21:17:08 -0400 | [diff] [blame] | 220 | #define err_printk(dev, entry, format, arg...) do { \ |
| 221 | error_count += 1; \ |
| 222 | if (driver_filter(dev) && \ |
| 223 | (show_all_errors || show_num_errors > 0)) { \ |
| 224 | WARN(1, "%s %s: " format, \ |
| 225 | dev ? dev_driver_string(dev) : "NULL", \ |
| 226 | dev ? dev_name(dev) : "NULL", ## arg); \ |
| 227 | dump_entry_trace(entry); \ |
| 228 | } \ |
| 229 | if (!show_all_errors && show_num_errors > 0) \ |
| 230 | show_num_errors -= 1; \ |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 231 | } while (0); |
| 232 | |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 233 | /* |
| 234 | * Hash related functions |
| 235 | * |
| 236 | * Every DMA-API request is saved into a struct dma_debug_entry. To |
| 237 | * have quick access to these structs they are stored into a hash. |
| 238 | */ |
| 239 | static int hash_fn(struct dma_debug_entry *entry) |
| 240 | { |
| 241 | /* |
| 242 | * Hash function is based on the dma address. |
| 243 | * We use bits 20-27 here as the index into the hash |
| 244 | */ |
| 245 | return (entry->dev_addr >> HASH_FN_SHIFT) & HASH_FN_MASK; |
| 246 | } |
| 247 | |
| 248 | /* |
| 249 | * Request exclusive access to a hash bucket for a given dma_debug_entry. |
| 250 | */ |
| 251 | static struct hash_bucket *get_hash_bucket(struct dma_debug_entry *entry, |
| 252 | unsigned long *flags) |
| 253 | { |
| 254 | int idx = hash_fn(entry); |
| 255 | unsigned long __flags; |
| 256 | |
| 257 | spin_lock_irqsave(&dma_entry_hash[idx].lock, __flags); |
| 258 | *flags = __flags; |
| 259 | return &dma_entry_hash[idx]; |
| 260 | } |
| 261 | |
| 262 | /* |
| 263 | * Give up exclusive access to the hash bucket |
| 264 | */ |
| 265 | static void put_hash_bucket(struct hash_bucket *bucket, |
| 266 | unsigned long *flags) |
| 267 | { |
| 268 | unsigned long __flags = *flags; |
| 269 | |
| 270 | spin_unlock_irqrestore(&bucket->lock, __flags); |
| 271 | } |
| 272 | |
Neil Horman | c6a21d0 | 2011-08-08 15:13:54 -0400 | [diff] [blame] | 273 | static bool exact_match(struct dma_debug_entry *a, struct dma_debug_entry *b) |
| 274 | { |
Thomas Jarosch | 91ec37c | 2011-11-17 20:31:02 +0100 | [diff] [blame] | 275 | return ((a->dev_addr == b->dev_addr) && |
Neil Horman | c6a21d0 | 2011-08-08 15:13:54 -0400 | [diff] [blame] | 276 | (a->dev == b->dev)) ? true : false; |
| 277 | } |
| 278 | |
| 279 | static bool containing_match(struct dma_debug_entry *a, |
| 280 | struct dma_debug_entry *b) |
| 281 | { |
| 282 | if (a->dev != b->dev) |
| 283 | return false; |
| 284 | |
| 285 | if ((b->dev_addr <= a->dev_addr) && |
| 286 | ((b->dev_addr + b->size) >= (a->dev_addr + a->size))) |
| 287 | return true; |
| 288 | |
| 289 | return false; |
| 290 | } |
| 291 | |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 292 | /* |
| 293 | * Search a given entry in the hash bucket list |
| 294 | */ |
Neil Horman | c6a21d0 | 2011-08-08 15:13:54 -0400 | [diff] [blame] | 295 | static struct dma_debug_entry *__hash_bucket_find(struct hash_bucket *bucket, |
| 296 | struct dma_debug_entry *ref, |
| 297 | match_fn match) |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 298 | { |
Joerg Roedel | 7caf6a4 | 2009-06-05 12:01:35 +0200 | [diff] [blame] | 299 | struct dma_debug_entry *entry, *ret = NULL; |
Ming Lei | fe73fbe | 2012-10-19 13:57:01 -0700 | [diff] [blame] | 300 | int matches = 0, match_lvl, last_lvl = -1; |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 301 | |
| 302 | list_for_each_entry(entry, &bucket->list, list) { |
Neil Horman | c6a21d0 | 2011-08-08 15:13:54 -0400 | [diff] [blame] | 303 | if (!match(ref, entry)) |
Joerg Roedel | 7caf6a4 | 2009-06-05 12:01:35 +0200 | [diff] [blame] | 304 | continue; |
| 305 | |
| 306 | /* |
| 307 | * Some drivers map the same physical address multiple |
| 308 | * times. Without a hardware IOMMU this results in the |
| 309 | * same device addresses being put into the dma-debug |
| 310 | * hash multiple times too. This can result in false |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 311 | * positives being reported. Therefore we implement a |
Joerg Roedel | 7caf6a4 | 2009-06-05 12:01:35 +0200 | [diff] [blame] | 312 | * best-fit algorithm here which returns the entry from |
| 313 | * the hash which fits best to the reference value |
| 314 | * instead of the first-fit. |
| 315 | */ |
| 316 | matches += 1; |
| 317 | match_lvl = 0; |
Joerg Roedel | e5e8c5b | 2009-06-11 10:03:42 +0200 | [diff] [blame] | 318 | entry->size == ref->size ? ++match_lvl : 0; |
| 319 | entry->type == ref->type ? ++match_lvl : 0; |
| 320 | entry->direction == ref->direction ? ++match_lvl : 0; |
| 321 | entry->sg_call_ents == ref->sg_call_ents ? ++match_lvl : 0; |
Joerg Roedel | 7caf6a4 | 2009-06-05 12:01:35 +0200 | [diff] [blame] | 322 | |
Joerg Roedel | e5e8c5b | 2009-06-11 10:03:42 +0200 | [diff] [blame] | 323 | if (match_lvl == 4) { |
Joerg Roedel | 7caf6a4 | 2009-06-05 12:01:35 +0200 | [diff] [blame] | 324 | /* perfect-fit - return the result */ |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 325 | return entry; |
Joerg Roedel | 7caf6a4 | 2009-06-05 12:01:35 +0200 | [diff] [blame] | 326 | } else if (match_lvl > last_lvl) { |
| 327 | /* |
| 328 | * We found an entry that fits better then the |
Ming Lei | fe73fbe | 2012-10-19 13:57:01 -0700 | [diff] [blame] | 329 | * previous one or it is the 1st match. |
Joerg Roedel | 7caf6a4 | 2009-06-05 12:01:35 +0200 | [diff] [blame] | 330 | */ |
| 331 | last_lvl = match_lvl; |
| 332 | ret = entry; |
| 333 | } |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 334 | } |
| 335 | |
Joerg Roedel | 7caf6a4 | 2009-06-05 12:01:35 +0200 | [diff] [blame] | 336 | /* |
| 337 | * If we have multiple matches but no perfect-fit, just return |
| 338 | * NULL. |
| 339 | */ |
| 340 | ret = (matches == 1) ? ret : NULL; |
| 341 | |
| 342 | return ret; |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Neil Horman | c6a21d0 | 2011-08-08 15:13:54 -0400 | [diff] [blame] | 345 | static struct dma_debug_entry *bucket_find_exact(struct hash_bucket *bucket, |
| 346 | struct dma_debug_entry *ref) |
| 347 | { |
| 348 | return __hash_bucket_find(bucket, ref, exact_match); |
| 349 | } |
| 350 | |
| 351 | static struct dma_debug_entry *bucket_find_contain(struct hash_bucket **bucket, |
| 352 | struct dma_debug_entry *ref, |
| 353 | unsigned long *flags) |
| 354 | { |
| 355 | |
| 356 | unsigned int max_range = dma_get_max_seg_size(ref->dev); |
| 357 | struct dma_debug_entry *entry, index = *ref; |
| 358 | unsigned int range = 0; |
| 359 | |
| 360 | while (range <= max_range) { |
| 361 | entry = __hash_bucket_find(*bucket, &index, containing_match); |
| 362 | |
| 363 | if (entry) |
| 364 | return entry; |
| 365 | |
| 366 | /* |
| 367 | * Nothing found, go back a hash bucket |
| 368 | */ |
| 369 | put_hash_bucket(*bucket, flags); |
| 370 | range += (1 << HASH_FN_SHIFT); |
| 371 | index.dev_addr -= (1 << HASH_FN_SHIFT); |
| 372 | *bucket = get_hash_bucket(&index, flags); |
| 373 | } |
| 374 | |
| 375 | return NULL; |
| 376 | } |
| 377 | |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 378 | /* |
| 379 | * Add an entry to a hash bucket |
| 380 | */ |
| 381 | static void hash_bucket_add(struct hash_bucket *bucket, |
| 382 | struct dma_debug_entry *entry) |
| 383 | { |
| 384 | list_add_tail(&entry->list, &bucket->list); |
| 385 | } |
| 386 | |
| 387 | /* |
| 388 | * Remove entry from a hash bucket list |
| 389 | */ |
| 390 | static void hash_bucket_del(struct dma_debug_entry *entry) |
| 391 | { |
| 392 | list_del(&entry->list); |
| 393 | } |
| 394 | |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 395 | static unsigned long long phys_addr(struct dma_debug_entry *entry) |
| 396 | { |
| 397 | return page_to_phys(pfn_to_page(entry->pfn)) + entry->offset; |
| 398 | } |
| 399 | |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 400 | /* |
David Woodhouse | ac26c18 | 2009-02-12 16:19:13 +0100 | [diff] [blame] | 401 | * Dump mapping entries for debugging purposes |
| 402 | */ |
| 403 | void debug_dma_dump_mappings(struct device *dev) |
| 404 | { |
| 405 | int idx; |
| 406 | |
| 407 | for (idx = 0; idx < HASH_SIZE; idx++) { |
| 408 | struct hash_bucket *bucket = &dma_entry_hash[idx]; |
| 409 | struct dma_debug_entry *entry; |
| 410 | unsigned long flags; |
| 411 | |
| 412 | spin_lock_irqsave(&bucket->lock, flags); |
| 413 | |
| 414 | list_for_each_entry(entry, &bucket->list, list) { |
| 415 | if (!dev || dev == entry->dev) { |
| 416 | dev_info(entry->dev, |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 417 | "%s idx %d P=%Lx N=%lx D=%Lx L=%Lx %s %s\n", |
David Woodhouse | ac26c18 | 2009-02-12 16:19:13 +0100 | [diff] [blame] | 418 | type2name[entry->type], idx, |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 419 | phys_addr(entry), entry->pfn, |
David Woodhouse | ac26c18 | 2009-02-12 16:19:13 +0100 | [diff] [blame] | 420 | entry->dev_addr, entry->size, |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 421 | dir2name[entry->direction], |
| 422 | maperr2str[entry->map_err_type]); |
David Woodhouse | ac26c18 | 2009-02-12 16:19:13 +0100 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | spin_unlock_irqrestore(&bucket->lock, flags); |
| 427 | } |
| 428 | } |
| 429 | EXPORT_SYMBOL(debug_dma_dump_mappings); |
| 430 | |
| 431 | /* |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 432 | * For each mapping (initial cacheline in the case of |
| 433 | * dma_alloc_coherent/dma_map_page, initial cacheline in each page of a |
| 434 | * scatterlist, or the cacheline specified in dma_map_single) insert |
| 435 | * into this tree using the cacheline as the key. At |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 436 | * dma_unmap_{single|sg|page} or dma_free_coherent delete the entry. If |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 437 | * the entry already exists at insertion time add a tag as a reference |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 438 | * count for the overlapping mappings. For now, the overlap tracking |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 439 | * just ensures that 'unmaps' balance 'maps' before marking the |
| 440 | * cacheline idle, but we should also be flagging overlaps as an API |
| 441 | * violation. |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 442 | * |
| 443 | * Memory usage is mostly constrained by the maximum number of available |
| 444 | * dma-debug entries in that we need a free dma_debug_entry before |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 445 | * inserting into the tree. In the case of dma_map_page and |
| 446 | * dma_alloc_coherent there is only one dma_debug_entry and one |
| 447 | * dma_active_cacheline entry to track per event. dma_map_sg(), on the |
| 448 | * other hand, consumes a single dma_debug_entry, but inserts 'nents' |
| 449 | * entries into the tree. |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 450 | * |
| 451 | * At any time debug_dma_assert_idle() can be called to trigger a |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 452 | * warning if any cachelines in the given page are in the active set. |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 453 | */ |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 454 | static RADIX_TREE(dma_active_cacheline, GFP_NOWAIT); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 455 | static DEFINE_SPINLOCK(radix_lock); |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 456 | #define ACTIVE_CACHELINE_MAX_OVERLAP ((1 << RADIX_TREE_MAX_TAGS) - 1) |
| 457 | #define CACHELINE_PER_PAGE_SHIFT (PAGE_SHIFT - L1_CACHE_SHIFT) |
| 458 | #define CACHELINES_PER_PAGE (1 << CACHELINE_PER_PAGE_SHIFT) |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 459 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 460 | static phys_addr_t to_cacheline_number(struct dma_debug_entry *entry) |
| 461 | { |
| 462 | return (entry->pfn << CACHELINE_PER_PAGE_SHIFT) + |
| 463 | (entry->offset >> L1_CACHE_SHIFT); |
| 464 | } |
| 465 | |
| 466 | static int active_cacheline_read_overlap(phys_addr_t cln) |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 467 | { |
| 468 | int overlap = 0, i; |
| 469 | |
| 470 | for (i = RADIX_TREE_MAX_TAGS - 1; i >= 0; i--) |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 471 | if (radix_tree_tag_get(&dma_active_cacheline, cln, i)) |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 472 | overlap |= 1 << i; |
| 473 | return overlap; |
| 474 | } |
| 475 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 476 | static int active_cacheline_set_overlap(phys_addr_t cln, int overlap) |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 477 | { |
| 478 | int i; |
| 479 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 480 | if (overlap > ACTIVE_CACHELINE_MAX_OVERLAP || overlap < 0) |
Dan Williams | 59f2e7d | 2014-01-29 14:05:53 -0800 | [diff] [blame] | 481 | return overlap; |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 482 | |
| 483 | for (i = RADIX_TREE_MAX_TAGS - 1; i >= 0; i--) |
| 484 | if (overlap & 1 << i) |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 485 | radix_tree_tag_set(&dma_active_cacheline, cln, i); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 486 | else |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 487 | radix_tree_tag_clear(&dma_active_cacheline, cln, i); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 488 | |
| 489 | return overlap; |
| 490 | } |
| 491 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 492 | static void active_cacheline_inc_overlap(phys_addr_t cln) |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 493 | { |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 494 | int overlap = active_cacheline_read_overlap(cln); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 495 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 496 | overlap = active_cacheline_set_overlap(cln, ++overlap); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 497 | |
| 498 | /* If we overflowed the overlap counter then we're potentially |
| 499 | * leaking dma-mappings. Otherwise, if maps and unmaps are |
| 500 | * balanced then this overflow may cause false negatives in |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 501 | * debug_dma_assert_idle() as the cacheline may be marked idle |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 502 | * prematurely. |
| 503 | */ |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 504 | WARN_ONCE(overlap > ACTIVE_CACHELINE_MAX_OVERLAP, |
| 505 | "DMA-API: exceeded %d overlapping mappings of cacheline %pa\n", |
| 506 | ACTIVE_CACHELINE_MAX_OVERLAP, &cln); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 509 | static int active_cacheline_dec_overlap(phys_addr_t cln) |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 510 | { |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 511 | int overlap = active_cacheline_read_overlap(cln); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 512 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 513 | return active_cacheline_set_overlap(cln, --overlap); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 516 | static int active_cacheline_insert(struct dma_debug_entry *entry) |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 517 | { |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 518 | phys_addr_t cln = to_cacheline_number(entry); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 519 | unsigned long flags; |
| 520 | int rc; |
| 521 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 522 | /* If the device is not writing memory then we don't have any |
| 523 | * concerns about the cpu consuming stale data. This mitigates |
| 524 | * legitimate usages of overlapping mappings. |
| 525 | */ |
| 526 | if (entry->direction == DMA_TO_DEVICE) |
| 527 | return 0; |
| 528 | |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 529 | spin_lock_irqsave(&radix_lock, flags); |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 530 | rc = radix_tree_insert(&dma_active_cacheline, cln, entry); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 531 | if (rc == -EEXIST) |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 532 | active_cacheline_inc_overlap(cln); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 533 | spin_unlock_irqrestore(&radix_lock, flags); |
| 534 | |
| 535 | return rc; |
| 536 | } |
| 537 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 538 | static void active_cacheline_remove(struct dma_debug_entry *entry) |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 539 | { |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 540 | phys_addr_t cln = to_cacheline_number(entry); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 541 | unsigned long flags; |
| 542 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 543 | /* ...mirror the insert case */ |
| 544 | if (entry->direction == DMA_TO_DEVICE) |
| 545 | return; |
| 546 | |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 547 | spin_lock_irqsave(&radix_lock, flags); |
Dan Williams | 59f2e7d | 2014-01-29 14:05:53 -0800 | [diff] [blame] | 548 | /* since we are counting overlaps the final put of the |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 549 | * cacheline will occur when the overlap count is 0. |
| 550 | * active_cacheline_dec_overlap() returns -1 in that case |
Dan Williams | 59f2e7d | 2014-01-29 14:05:53 -0800 | [diff] [blame] | 551 | */ |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 552 | if (active_cacheline_dec_overlap(cln) < 0) |
| 553 | radix_tree_delete(&dma_active_cacheline, cln); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 554 | spin_unlock_irqrestore(&radix_lock, flags); |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * debug_dma_assert_idle() - assert that a page is not undergoing dma |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 559 | * @page: page to lookup in the dma_active_cacheline tree |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 560 | * |
| 561 | * Place a call to this routine in cases where the cpu touching the page |
| 562 | * before the dma completes (page is dma_unmapped) will lead to data |
| 563 | * corruption. |
| 564 | */ |
| 565 | void debug_dma_assert_idle(struct page *page) |
| 566 | { |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 567 | static struct dma_debug_entry *ents[CACHELINES_PER_PAGE]; |
| 568 | struct dma_debug_entry *entry = NULL; |
| 569 | void **results = (void **) &ents; |
| 570 | unsigned int nents, i; |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 571 | unsigned long flags; |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 572 | phys_addr_t cln; |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 573 | |
| 574 | if (!page) |
| 575 | return; |
| 576 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 577 | cln = (phys_addr_t) page_to_pfn(page) << CACHELINE_PER_PAGE_SHIFT; |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 578 | spin_lock_irqsave(&radix_lock, flags); |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 579 | nents = radix_tree_gang_lookup(&dma_active_cacheline, results, cln, |
| 580 | CACHELINES_PER_PAGE); |
| 581 | for (i = 0; i < nents; i++) { |
| 582 | phys_addr_t ent_cln = to_cacheline_number(ents[i]); |
| 583 | |
| 584 | if (ent_cln == cln) { |
| 585 | entry = ents[i]; |
| 586 | break; |
| 587 | } else if (ent_cln >= cln + CACHELINES_PER_PAGE) |
| 588 | break; |
| 589 | } |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 590 | spin_unlock_irqrestore(&radix_lock, flags); |
| 591 | |
| 592 | if (!entry) |
| 593 | return; |
| 594 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 595 | cln = to_cacheline_number(entry); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 596 | err_printk(entry->dev, entry, |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 597 | "DMA-API: cpu touching an active dma mapped cacheline [cln=%pa]\n", |
| 598 | &cln); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /* |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 602 | * Wrapper function for adding an entry to the hash. |
| 603 | * This function takes care of locking itself. |
| 604 | */ |
| 605 | static void add_dma_entry(struct dma_debug_entry *entry) |
| 606 | { |
| 607 | struct hash_bucket *bucket; |
| 608 | unsigned long flags; |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 609 | int rc; |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 610 | |
| 611 | bucket = get_hash_bucket(entry, &flags); |
| 612 | hash_bucket_add(bucket, entry); |
| 613 | put_hash_bucket(bucket, &flags); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 614 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 615 | rc = active_cacheline_insert(entry); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 616 | if (rc == -ENOMEM) { |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 617 | pr_err("DMA-API: cacheline tracking ENOMEM, dma-debug disabled\n"); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 618 | global_disable = true; |
| 619 | } |
| 620 | |
| 621 | /* TODO: report -EEXIST errors here as overlapping mappings are |
| 622 | * not supported by the DMA API |
| 623 | */ |
Joerg Roedel | 30dfa90 | 2009-01-09 12:34:49 +0100 | [diff] [blame] | 624 | } |
| 625 | |
FUJITA Tomonori | e6a1a89 | 2009-04-15 18:22:41 +0900 | [diff] [blame] | 626 | static struct dma_debug_entry *__dma_entry_alloc(void) |
| 627 | { |
| 628 | struct dma_debug_entry *entry; |
| 629 | |
| 630 | entry = list_entry(free_entries.next, struct dma_debug_entry, list); |
| 631 | list_del(&entry->list); |
| 632 | memset(entry, 0, sizeof(*entry)); |
| 633 | |
| 634 | num_free_entries -= 1; |
| 635 | if (num_free_entries < min_free_entries) |
| 636 | min_free_entries = num_free_entries; |
| 637 | |
| 638 | return entry; |
| 639 | } |
| 640 | |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 641 | /* struct dma_entry allocator |
| 642 | * |
| 643 | * The next two functions implement the allocator for |
| 644 | * struct dma_debug_entries. |
| 645 | */ |
| 646 | static struct dma_debug_entry *dma_entry_alloc(void) |
| 647 | { |
Jakub Kicinski | 29cdd4e | 2012-04-04 03:19:10 +0200 | [diff] [blame] | 648 | struct dma_debug_entry *entry; |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 649 | unsigned long flags; |
| 650 | |
| 651 | spin_lock_irqsave(&free_entries_lock, flags); |
| 652 | |
| 653 | if (list_empty(&free_entries)) { |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 654 | pr_err("DMA-API: debugging out of memory - disabling\n"); |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 655 | global_disable = true; |
Jakub Kicinski | 29cdd4e | 2012-04-04 03:19:10 +0200 | [diff] [blame] | 656 | spin_unlock_irqrestore(&free_entries_lock, flags); |
| 657 | return NULL; |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 658 | } |
| 659 | |
FUJITA Tomonori | e6a1a89 | 2009-04-15 18:22:41 +0900 | [diff] [blame] | 660 | entry = __dma_entry_alloc(); |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 661 | |
Jakub Kicinski | 29cdd4e | 2012-04-04 03:19:10 +0200 | [diff] [blame] | 662 | spin_unlock_irqrestore(&free_entries_lock, flags); |
| 663 | |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 664 | #ifdef CONFIG_STACKTRACE |
| 665 | entry->stacktrace.max_entries = DMA_DEBUG_STACKTRACE_ENTRIES; |
| 666 | entry->stacktrace.entries = entry->st_entries; |
| 667 | entry->stacktrace.skip = 2; |
| 668 | save_stack_trace(&entry->stacktrace); |
| 669 | #endif |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 670 | |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 671 | return entry; |
| 672 | } |
| 673 | |
| 674 | static void dma_entry_free(struct dma_debug_entry *entry) |
| 675 | { |
| 676 | unsigned long flags; |
| 677 | |
Dan Williams | 3b7a641 | 2014-03-03 15:38:21 -0800 | [diff] [blame] | 678 | active_cacheline_remove(entry); |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 679 | |
Joerg Roedel | 3b1e79e | 2009-01-09 12:42:46 +0100 | [diff] [blame] | 680 | /* |
| 681 | * add to beginning of the list - this way the entries are |
| 682 | * more likely cache hot when they are reallocated. |
| 683 | */ |
| 684 | spin_lock_irqsave(&free_entries_lock, flags); |
| 685 | list_add(&entry->list, &free_entries); |
| 686 | num_free_entries += 1; |
| 687 | spin_unlock_irqrestore(&free_entries_lock, flags); |
| 688 | } |
| 689 | |
FUJITA Tomonori | e6a1a89 | 2009-04-15 18:22:41 +0900 | [diff] [blame] | 690 | int dma_debug_resize_entries(u32 num_entries) |
| 691 | { |
| 692 | int i, delta, ret = 0; |
| 693 | unsigned long flags; |
| 694 | struct dma_debug_entry *entry; |
| 695 | LIST_HEAD(tmp); |
| 696 | |
| 697 | spin_lock_irqsave(&free_entries_lock, flags); |
| 698 | |
| 699 | if (nr_total_entries < num_entries) { |
| 700 | delta = num_entries - nr_total_entries; |
| 701 | |
| 702 | spin_unlock_irqrestore(&free_entries_lock, flags); |
| 703 | |
| 704 | for (i = 0; i < delta; i++) { |
| 705 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
| 706 | if (!entry) |
| 707 | break; |
| 708 | |
| 709 | list_add_tail(&entry->list, &tmp); |
| 710 | } |
| 711 | |
| 712 | spin_lock_irqsave(&free_entries_lock, flags); |
| 713 | |
| 714 | list_splice(&tmp, &free_entries); |
| 715 | nr_total_entries += i; |
| 716 | num_free_entries += i; |
| 717 | } else { |
| 718 | delta = nr_total_entries - num_entries; |
| 719 | |
| 720 | for (i = 0; i < delta && !list_empty(&free_entries); i++) { |
| 721 | entry = __dma_entry_alloc(); |
| 722 | kfree(entry); |
| 723 | } |
| 724 | |
| 725 | nr_total_entries -= i; |
| 726 | } |
| 727 | |
| 728 | if (nr_total_entries != num_entries) |
| 729 | ret = 1; |
| 730 | |
| 731 | spin_unlock_irqrestore(&free_entries_lock, flags); |
| 732 | |
| 733 | return ret; |
| 734 | } |
| 735 | EXPORT_SYMBOL(dma_debug_resize_entries); |
| 736 | |
Joerg Roedel | 6bf0787 | 2009-01-09 12:54:42 +0100 | [diff] [blame] | 737 | /* |
| 738 | * DMA-API debugging init code |
| 739 | * |
| 740 | * The init code does two things: |
| 741 | * 1. Initialize core data structures |
| 742 | * 2. Preallocate a given number of dma_debug_entry structs |
| 743 | */ |
| 744 | |
| 745 | static int prealloc_memory(u32 num_entries) |
| 746 | { |
| 747 | struct dma_debug_entry *entry, *next_entry; |
| 748 | int i; |
| 749 | |
| 750 | for (i = 0; i < num_entries; ++i) { |
| 751 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
| 752 | if (!entry) |
| 753 | goto out_err; |
| 754 | |
| 755 | list_add_tail(&entry->list, &free_entries); |
| 756 | } |
| 757 | |
| 758 | num_free_entries = num_entries; |
| 759 | min_free_entries = num_entries; |
| 760 | |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 761 | pr_info("DMA-API: preallocated %d debug entries\n", num_entries); |
Joerg Roedel | 6bf0787 | 2009-01-09 12:54:42 +0100 | [diff] [blame] | 762 | |
| 763 | return 0; |
| 764 | |
| 765 | out_err: |
| 766 | |
| 767 | list_for_each_entry_safe(entry, next_entry, &free_entries, list) { |
| 768 | list_del(&entry->list); |
| 769 | kfree(entry); |
| 770 | } |
| 771 | |
| 772 | return -ENOMEM; |
| 773 | } |
| 774 | |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 775 | static ssize_t filter_read(struct file *file, char __user *user_buf, |
| 776 | size_t count, loff_t *ppos) |
| 777 | { |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 778 | char buf[NAME_MAX_LEN + 1]; |
Joerg Roedel | c17e2cf | 2009-06-08 15:19:29 +0200 | [diff] [blame] | 779 | unsigned long flags; |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 780 | int len; |
| 781 | |
| 782 | if (!current_driver_name[0]) |
| 783 | return 0; |
| 784 | |
| 785 | /* |
| 786 | * We can't copy to userspace directly because current_driver_name can |
| 787 | * only be read under the driver_name_lock with irqs disabled. So |
| 788 | * create a temporary copy first. |
| 789 | */ |
| 790 | read_lock_irqsave(&driver_name_lock, flags); |
| 791 | len = scnprintf(buf, NAME_MAX_LEN + 1, "%s\n", current_driver_name); |
| 792 | read_unlock_irqrestore(&driver_name_lock, flags); |
| 793 | |
| 794 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 795 | } |
| 796 | |
| 797 | static ssize_t filter_write(struct file *file, const char __user *userbuf, |
| 798 | size_t count, loff_t *ppos) |
| 799 | { |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 800 | char buf[NAME_MAX_LEN]; |
Joerg Roedel | c17e2cf | 2009-06-08 15:19:29 +0200 | [diff] [blame] | 801 | unsigned long flags; |
| 802 | size_t len; |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 803 | int i; |
| 804 | |
| 805 | /* |
| 806 | * We can't copy from userspace directly. Access to |
| 807 | * current_driver_name is protected with a write_lock with irqs |
| 808 | * disabled. Since copy_from_user can fault and may sleep we |
| 809 | * need to copy to temporary buffer first |
| 810 | */ |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 811 | len = min(count, (size_t)(NAME_MAX_LEN - 1)); |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 812 | if (copy_from_user(buf, userbuf, len)) |
| 813 | return -EFAULT; |
| 814 | |
| 815 | buf[len] = 0; |
| 816 | |
| 817 | write_lock_irqsave(&driver_name_lock, flags); |
| 818 | |
Joerg Roedel | 31232509 | 2009-06-08 15:07:08 +0200 | [diff] [blame] | 819 | /* |
| 820 | * Now handle the string we got from userspace very carefully. |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 821 | * The rules are: |
| 822 | * - only use the first token we got |
| 823 | * - token delimiter is everything looking like a space |
| 824 | * character (' ', '\n', '\t' ...) |
| 825 | * |
| 826 | */ |
| 827 | if (!isalnum(buf[0])) { |
| 828 | /* |
Joerg Roedel | 31232509 | 2009-06-08 15:07:08 +0200 | [diff] [blame] | 829 | * If the first character userspace gave us is not |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 830 | * alphanumerical then assume the filter should be |
| 831 | * switched off. |
| 832 | */ |
| 833 | if (current_driver_name[0]) |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 834 | pr_info("DMA-API: switching off dma-debug driver filter\n"); |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 835 | current_driver_name[0] = 0; |
| 836 | current_driver = NULL; |
| 837 | goto out_unlock; |
| 838 | } |
| 839 | |
| 840 | /* |
| 841 | * Now parse out the first token and use it as the name for the |
| 842 | * driver to filter for. |
| 843 | */ |
Dan Carpenter | 39a37ce | 2010-04-06 19:45:12 +0300 | [diff] [blame] | 844 | for (i = 0; i < NAME_MAX_LEN - 1; ++i) { |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 845 | current_driver_name[i] = buf[i]; |
| 846 | if (isspace(buf[i]) || buf[i] == ' ' || buf[i] == 0) |
| 847 | break; |
| 848 | } |
| 849 | current_driver_name[i] = 0; |
| 850 | current_driver = NULL; |
| 851 | |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 852 | pr_info("DMA-API: enable driver filter for driver [%s]\n", |
| 853 | current_driver_name); |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 854 | |
| 855 | out_unlock: |
| 856 | write_unlock_irqrestore(&driver_name_lock, flags); |
| 857 | |
| 858 | return count; |
| 859 | } |
| 860 | |
Thiago Farina | aeb583d | 2010-01-18 18:57:33 -0500 | [diff] [blame] | 861 | static const struct file_operations filter_fops = { |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 862 | .read = filter_read, |
| 863 | .write = filter_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 864 | .llseek = default_llseek, |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 865 | }; |
| 866 | |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 867 | static int dma_debug_fs_init(void) |
| 868 | { |
| 869 | dma_debug_dent = debugfs_create_dir("dma-api", NULL); |
| 870 | if (!dma_debug_dent) { |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 871 | pr_err("DMA-API: can not create debugfs directory\n"); |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 872 | return -ENOMEM; |
| 873 | } |
| 874 | |
| 875 | global_disable_dent = debugfs_create_bool("disabled", 0444, |
| 876 | dma_debug_dent, |
Dan Carpenter | 68ee6d2 | 2012-06-27 12:08:55 +0300 | [diff] [blame] | 877 | &global_disable); |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 878 | if (!global_disable_dent) |
| 879 | goto out_err; |
| 880 | |
| 881 | error_count_dent = debugfs_create_u32("error_count", 0444, |
| 882 | dma_debug_dent, &error_count); |
| 883 | if (!error_count_dent) |
| 884 | goto out_err; |
| 885 | |
| 886 | show_all_errors_dent = debugfs_create_u32("all_errors", 0644, |
| 887 | dma_debug_dent, |
| 888 | &show_all_errors); |
| 889 | if (!show_all_errors_dent) |
| 890 | goto out_err; |
| 891 | |
| 892 | show_num_errors_dent = debugfs_create_u32("num_errors", 0644, |
| 893 | dma_debug_dent, |
| 894 | &show_num_errors); |
| 895 | if (!show_num_errors_dent) |
| 896 | goto out_err; |
| 897 | |
| 898 | num_free_entries_dent = debugfs_create_u32("num_free_entries", 0444, |
| 899 | dma_debug_dent, |
| 900 | &num_free_entries); |
| 901 | if (!num_free_entries_dent) |
| 902 | goto out_err; |
| 903 | |
| 904 | min_free_entries_dent = debugfs_create_u32("min_free_entries", 0444, |
| 905 | dma_debug_dent, |
| 906 | &min_free_entries); |
| 907 | if (!min_free_entries_dent) |
| 908 | goto out_err; |
| 909 | |
Joerg Roedel | 8a6fc70 | 2009-05-22 21:23:13 +0200 | [diff] [blame] | 910 | filter_dent = debugfs_create_file("driver_filter", 0644, |
| 911 | dma_debug_dent, NULL, &filter_fops); |
| 912 | if (!filter_dent) |
| 913 | goto out_err; |
| 914 | |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 915 | return 0; |
| 916 | |
| 917 | out_err: |
| 918 | debugfs_remove_recursive(dma_debug_dent); |
| 919 | |
| 920 | return -ENOMEM; |
| 921 | } |
| 922 | |
Stanislaw Gruszka | ba4b87ad | 2011-03-31 08:08:09 -0400 | [diff] [blame] | 923 | static int device_dma_allocations(struct device *dev, struct dma_debug_entry **out_entry) |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 924 | { |
| 925 | struct dma_debug_entry *entry; |
| 926 | unsigned long flags; |
| 927 | int count = 0, i; |
| 928 | |
Joerg Roedel | be81c6e | 2009-06-08 15:46:19 +0200 | [diff] [blame] | 929 | local_irq_save(flags); |
| 930 | |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 931 | for (i = 0; i < HASH_SIZE; ++i) { |
Joerg Roedel | be81c6e | 2009-06-08 15:46:19 +0200 | [diff] [blame] | 932 | spin_lock(&dma_entry_hash[i].lock); |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 933 | list_for_each_entry(entry, &dma_entry_hash[i].list, list) { |
Stanislaw Gruszka | ba4b87ad | 2011-03-31 08:08:09 -0400 | [diff] [blame] | 934 | if (entry->dev == dev) { |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 935 | count += 1; |
Stanislaw Gruszka | ba4b87ad | 2011-03-31 08:08:09 -0400 | [diff] [blame] | 936 | *out_entry = entry; |
| 937 | } |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 938 | } |
Joerg Roedel | be81c6e | 2009-06-08 15:46:19 +0200 | [diff] [blame] | 939 | spin_unlock(&dma_entry_hash[i].lock); |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 940 | } |
| 941 | |
Joerg Roedel | be81c6e | 2009-06-08 15:46:19 +0200 | [diff] [blame] | 942 | local_irq_restore(flags); |
| 943 | |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 944 | return count; |
| 945 | } |
| 946 | |
Ingo Molnar | a8fe9ea | 2009-12-31 15:16:23 +0100 | [diff] [blame] | 947 | static int dma_debug_device_change(struct notifier_block *nb, unsigned long action, void *data) |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 948 | { |
| 949 | struct device *dev = data; |
Stanislaw Gruszka | ba4b87ad | 2011-03-31 08:08:09 -0400 | [diff] [blame] | 950 | struct dma_debug_entry *uninitialized_var(entry); |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 951 | int count; |
| 952 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 953 | if (dma_debug_disabled()) |
Ingo Molnar | a8fe9ea | 2009-12-31 15:16:23 +0100 | [diff] [blame] | 954 | return 0; |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 955 | |
| 956 | switch (action) { |
| 957 | case BUS_NOTIFY_UNBOUND_DRIVER: |
Stanislaw Gruszka | ba4b87ad | 2011-03-31 08:08:09 -0400 | [diff] [blame] | 958 | count = device_dma_allocations(dev, &entry); |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 959 | if (count == 0) |
| 960 | break; |
Stanislaw Gruszka | ba4b87ad | 2011-03-31 08:08:09 -0400 | [diff] [blame] | 961 | err_printk(dev, entry, "DMA-API: device driver has pending " |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 962 | "DMA allocations while released from device " |
Stanislaw Gruszka | ba4b87ad | 2011-03-31 08:08:09 -0400 | [diff] [blame] | 963 | "[count=%d]\n" |
| 964 | "One of leaked entries details: " |
| 965 | "[device address=0x%016llx] [size=%llu bytes] " |
| 966 | "[mapped with %s] [mapped as %s]\n", |
| 967 | count, entry->dev_addr, entry->size, |
| 968 | dir2name[entry->direction], type2name[entry->type]); |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 969 | break; |
| 970 | default: |
| 971 | break; |
| 972 | } |
| 973 | |
| 974 | return 0; |
| 975 | } |
| 976 | |
Joerg Roedel | 41531c8 | 2009-03-16 17:32:14 +0100 | [diff] [blame] | 977 | void dma_debug_add_bus(struct bus_type *bus) |
| 978 | { |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 979 | struct notifier_block *nb; |
| 980 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 981 | if (dma_debug_disabled()) |
Shaun Ruffell | f797d98 | 2009-12-17 18:00:36 -0600 | [diff] [blame] | 982 | return; |
| 983 | |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 984 | nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL); |
| 985 | if (nb == NULL) { |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 986 | pr_err("dma_debug_add_bus: out of memory\n"); |
Joerg Roedel | ed888ae | 2009-05-22 17:16:04 +0200 | [diff] [blame] | 987 | return; |
| 988 | } |
| 989 | |
| 990 | nb->notifier_call = dma_debug_device_change; |
| 991 | |
| 992 | bus_register_notifier(bus, nb); |
Joerg Roedel | 41531c8 | 2009-03-16 17:32:14 +0100 | [diff] [blame] | 993 | } |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 994 | |
Joerg Roedel | 6bf0787 | 2009-01-09 12:54:42 +0100 | [diff] [blame] | 995 | /* |
| 996 | * Let the architectures decide how many entries should be preallocated. |
| 997 | */ |
| 998 | void dma_debug_init(u32 num_entries) |
| 999 | { |
| 1000 | int i; |
| 1001 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1002 | if (dma_debug_disabled()) |
Joerg Roedel | 6bf0787 | 2009-01-09 12:54:42 +0100 | [diff] [blame] | 1003 | return; |
| 1004 | |
| 1005 | for (i = 0; i < HASH_SIZE; ++i) { |
| 1006 | INIT_LIST_HEAD(&dma_entry_hash[i].list); |
Ingo Molnar | b0a5b83 | 2009-06-16 16:11:14 +0200 | [diff] [blame] | 1007 | spin_lock_init(&dma_entry_hash[i].lock); |
Joerg Roedel | 6bf0787 | 2009-01-09 12:54:42 +0100 | [diff] [blame] | 1008 | } |
| 1009 | |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 1010 | if (dma_debug_fs_init() != 0) { |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 1011 | pr_err("DMA-API: error creating debugfs entries - disabling\n"); |
Joerg Roedel | 788dcfa | 2009-01-09 13:13:27 +0100 | [diff] [blame] | 1012 | global_disable = true; |
| 1013 | |
| 1014 | return; |
| 1015 | } |
| 1016 | |
Joerg Roedel | 59d3daa | 2009-01-09 13:01:56 +0100 | [diff] [blame] | 1017 | if (req_entries) |
| 1018 | num_entries = req_entries; |
| 1019 | |
Joerg Roedel | 6bf0787 | 2009-01-09 12:54:42 +0100 | [diff] [blame] | 1020 | if (prealloc_memory(num_entries) != 0) { |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 1021 | pr_err("DMA-API: debugging out of memory error - disabled\n"); |
Joerg Roedel | 6bf0787 | 2009-01-09 12:54:42 +0100 | [diff] [blame] | 1022 | global_disable = true; |
| 1023 | |
| 1024 | return; |
| 1025 | } |
| 1026 | |
FUJITA Tomonori | e6a1a89 | 2009-04-15 18:22:41 +0900 | [diff] [blame] | 1027 | nr_total_entries = num_free_entries; |
| 1028 | |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 1029 | pr_info("DMA-API: debugging enabled by kernel config\n"); |
Joerg Roedel | 6bf0787 | 2009-01-09 12:54:42 +0100 | [diff] [blame] | 1030 | } |
| 1031 | |
Joerg Roedel | 59d3daa | 2009-01-09 13:01:56 +0100 | [diff] [blame] | 1032 | static __init int dma_debug_cmdline(char *str) |
| 1033 | { |
| 1034 | if (!str) |
| 1035 | return -EINVAL; |
| 1036 | |
| 1037 | if (strncmp(str, "off", 3) == 0) { |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 1038 | pr_info("DMA-API: debugging disabled on kernel command line\n"); |
Joerg Roedel | 59d3daa | 2009-01-09 13:01:56 +0100 | [diff] [blame] | 1039 | global_disable = true; |
| 1040 | } |
| 1041 | |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | static __init int dma_debug_entries_cmdline(char *str) |
| 1046 | { |
| 1047 | int res; |
| 1048 | |
| 1049 | if (!str) |
| 1050 | return -EINVAL; |
| 1051 | |
| 1052 | res = get_option(&str, &req_entries); |
| 1053 | |
| 1054 | if (!res) |
| 1055 | req_entries = 0; |
| 1056 | |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | __setup("dma_debug=", dma_debug_cmdline); |
| 1061 | __setup("dma_debug_entries=", dma_debug_entries_cmdline); |
| 1062 | |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1063 | static void check_unmap(struct dma_debug_entry *ref) |
| 1064 | { |
| 1065 | struct dma_debug_entry *entry; |
| 1066 | struct hash_bucket *bucket; |
| 1067 | unsigned long flags; |
| 1068 | |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1069 | bucket = get_hash_bucket(ref, &flags); |
Neil Horman | c6a21d0 | 2011-08-08 15:13:54 -0400 | [diff] [blame] | 1070 | entry = bucket_find_exact(bucket, ref); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1071 | |
| 1072 | if (!entry) { |
Alexander Duyck | 8d640a5 | 2013-03-22 15:04:48 -0700 | [diff] [blame] | 1073 | /* must drop lock before calling dma_mapping_error */ |
| 1074 | put_hash_bucket(bucket, &flags); |
| 1075 | |
Shuah Khan | bfe0fb0 | 2012-11-03 17:00:07 -0600 | [diff] [blame] | 1076 | if (dma_mapping_error(ref->dev, ref->dev_addr)) { |
| 1077 | err_printk(ref->dev, NULL, |
Alexander Duyck | 8d640a5 | 2013-03-22 15:04:48 -0700 | [diff] [blame] | 1078 | "DMA-API: device driver tries to free an " |
| 1079 | "invalid DMA memory address\n"); |
| 1080 | } else { |
| 1081 | err_printk(ref->dev, NULL, |
| 1082 | "DMA-API: device driver tries to free DMA " |
| 1083 | "memory it has not allocated [device " |
| 1084 | "address=0x%016llx] [size=%llu bytes]\n", |
| 1085 | ref->dev_addr, ref->size); |
Shuah Khan | bfe0fb0 | 2012-11-03 17:00:07 -0600 | [diff] [blame] | 1086 | } |
Alexander Duyck | 8d640a5 | 2013-03-22 15:04:48 -0700 | [diff] [blame] | 1087 | return; |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | if (ref->size != entry->size) { |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1091 | err_printk(ref->dev, entry, "DMA-API: device driver frees " |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1092 | "DMA memory with different size " |
| 1093 | "[device address=0x%016llx] [map size=%llu bytes] " |
| 1094 | "[unmap size=%llu bytes]\n", |
| 1095 | ref->dev_addr, entry->size, ref->size); |
| 1096 | } |
| 1097 | |
| 1098 | if (ref->type != entry->type) { |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1099 | err_printk(ref->dev, entry, "DMA-API: device driver frees " |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1100 | "DMA memory with wrong function " |
| 1101 | "[device address=0x%016llx] [size=%llu bytes] " |
| 1102 | "[mapped as %s] [unmapped as %s]\n", |
| 1103 | ref->dev_addr, ref->size, |
| 1104 | type2name[entry->type], type2name[ref->type]); |
| 1105 | } else if ((entry->type == dma_debug_coherent) && |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 1106 | (phys_addr(ref) != phys_addr(entry))) { |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1107 | err_printk(ref->dev, entry, "DMA-API: device driver frees " |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1108 | "DMA memory with different CPU address " |
| 1109 | "[device address=0x%016llx] [size=%llu bytes] " |
Joerg Roedel | 59a40e70 | 2009-10-29 16:25:50 +0100 | [diff] [blame] | 1110 | "[cpu alloc address=0x%016llx] " |
| 1111 | "[cpu free address=0x%016llx]", |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1112 | ref->dev_addr, ref->size, |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 1113 | phys_addr(entry), |
| 1114 | phys_addr(ref)); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | if (ref->sg_call_ents && ref->type == dma_debug_sg && |
| 1118 | ref->sg_call_ents != entry->sg_call_ents) { |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1119 | err_printk(ref->dev, entry, "DMA-API: device driver frees " |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1120 | "DMA sg list with different entry count " |
| 1121 | "[map count=%d] [unmap count=%d]\n", |
| 1122 | entry->sg_call_ents, ref->sg_call_ents); |
| 1123 | } |
| 1124 | |
| 1125 | /* |
| 1126 | * This may be no bug in reality - but most implementations of the |
| 1127 | * DMA API don't handle this properly, so check for it here |
| 1128 | */ |
| 1129 | if (ref->direction != entry->direction) { |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1130 | err_printk(ref->dev, entry, "DMA-API: device driver frees " |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1131 | "DMA memory with different direction " |
| 1132 | "[device address=0x%016llx] [size=%llu bytes] " |
| 1133 | "[mapped with %s] [unmapped with %s]\n", |
| 1134 | ref->dev_addr, ref->size, |
| 1135 | dir2name[entry->direction], |
| 1136 | dir2name[ref->direction]); |
| 1137 | } |
| 1138 | |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 1139 | if (entry->map_err_type == MAP_ERR_NOT_CHECKED) { |
| 1140 | err_printk(ref->dev, entry, |
| 1141 | "DMA-API: device driver failed to check map error" |
| 1142 | "[device address=0x%016llx] [size=%llu bytes] " |
| 1143 | "[mapped as %s]", |
| 1144 | ref->dev_addr, ref->size, |
| 1145 | type2name[entry->type]); |
| 1146 | } |
| 1147 | |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1148 | hash_bucket_del(entry); |
| 1149 | dma_entry_free(entry); |
| 1150 | |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1151 | put_hash_bucket(bucket, &flags); |
| 1152 | } |
| 1153 | |
| 1154 | static void check_for_stack(struct device *dev, void *addr) |
| 1155 | { |
| 1156 | if (object_is_on_stack(addr)) |
Horia Geanta | f9134be | 2014-09-02 14:28:14 +0300 | [diff] [blame] | 1157 | err_printk(dev, NULL, "DMA-API: device driver maps memory from " |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1158 | "stack [addr=%p]\n", addr); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1159 | } |
| 1160 | |
Ingo Molnar | f39d1b9 | 2009-07-10 21:38:02 +0200 | [diff] [blame] | 1161 | static inline bool overlap(void *addr, unsigned long len, void *start, void *end) |
Joerg Roedel | 2e34bde | 2009-03-16 16:51:55 +0100 | [diff] [blame] | 1162 | { |
Ingo Molnar | f39d1b9 | 2009-07-10 21:38:02 +0200 | [diff] [blame] | 1163 | unsigned long a1 = (unsigned long)addr; |
| 1164 | unsigned long b1 = a1 + len; |
| 1165 | unsigned long a2 = (unsigned long)start; |
| 1166 | unsigned long b2 = (unsigned long)end; |
Joerg Roedel | 2e34bde | 2009-03-16 16:51:55 +0100 | [diff] [blame] | 1167 | |
Ingo Molnar | f39d1b9 | 2009-07-10 21:38:02 +0200 | [diff] [blame] | 1168 | return !(b1 <= a2 || a1 >= b2); |
Joerg Roedel | 2e34bde | 2009-03-16 16:51:55 +0100 | [diff] [blame] | 1169 | } |
| 1170 | |
Ingo Molnar | f39d1b9 | 2009-07-10 21:38:02 +0200 | [diff] [blame] | 1171 | static void check_for_illegal_area(struct device *dev, void *addr, unsigned long len) |
Joerg Roedel | 2e34bde | 2009-03-16 16:51:55 +0100 | [diff] [blame] | 1172 | { |
Ingo Molnar | f39d1b9 | 2009-07-10 21:38:02 +0200 | [diff] [blame] | 1173 | if (overlap(addr, len, _text, _etext) || |
| 1174 | overlap(addr, len, __start_rodata, __end_rodata)) |
| 1175 | err_printk(dev, NULL, "DMA-API: device driver maps memory from kernel text or rodata [addr=%p] [len=%lu]\n", addr, len); |
Joerg Roedel | 2e34bde | 2009-03-16 16:51:55 +0100 | [diff] [blame] | 1176 | } |
| 1177 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1178 | static void check_sync(struct device *dev, |
| 1179 | struct dma_debug_entry *ref, |
| 1180 | bool to_cpu) |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1181 | { |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1182 | struct dma_debug_entry *entry; |
| 1183 | struct hash_bucket *bucket; |
| 1184 | unsigned long flags; |
| 1185 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1186 | bucket = get_hash_bucket(ref, &flags); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1187 | |
Neil Horman | c6a21d0 | 2011-08-08 15:13:54 -0400 | [diff] [blame] | 1188 | entry = bucket_find_contain(&bucket, ref, &flags); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1189 | |
| 1190 | if (!entry) { |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1191 | err_printk(dev, NULL, "DMA-API: device driver tries " |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1192 | "to sync DMA memory it has not allocated " |
| 1193 | "[device address=0x%016llx] [size=%llu bytes]\n", |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1194 | (unsigned long long)ref->dev_addr, ref->size); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1195 | goto out; |
| 1196 | } |
| 1197 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1198 | if (ref->size > entry->size) { |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1199 | err_printk(dev, entry, "DMA-API: device driver syncs" |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1200 | " DMA memory outside allocated range " |
| 1201 | "[device address=0x%016llx] " |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1202 | "[allocation size=%llu bytes] " |
| 1203 | "[sync offset+size=%llu]\n", |
| 1204 | entry->dev_addr, entry->size, |
| 1205 | ref->size); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1206 | } |
| 1207 | |
Krzysztof Halasa | 42d53b4 | 2010-01-08 14:42:36 -0800 | [diff] [blame] | 1208 | if (entry->direction == DMA_BIDIRECTIONAL) |
| 1209 | goto out; |
| 1210 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1211 | if (ref->direction != entry->direction) { |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1212 | err_printk(dev, entry, "DMA-API: device driver syncs " |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1213 | "DMA memory with different direction " |
| 1214 | "[device address=0x%016llx] [size=%llu bytes] " |
| 1215 | "[mapped with %s] [synced with %s]\n", |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1216 | (unsigned long long)ref->dev_addr, entry->size, |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1217 | dir2name[entry->direction], |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1218 | dir2name[ref->direction]); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1221 | if (to_cpu && !(entry->direction == DMA_FROM_DEVICE) && |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1222 | !(ref->direction == DMA_TO_DEVICE)) |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1223 | err_printk(dev, entry, "DMA-API: device driver syncs " |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1224 | "device read-only DMA memory for cpu " |
| 1225 | "[device address=0x%016llx] [size=%llu bytes] " |
| 1226 | "[mapped with %s] [synced with %s]\n", |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1227 | (unsigned long long)ref->dev_addr, entry->size, |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1228 | dir2name[entry->direction], |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1229 | dir2name[ref->direction]); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1230 | |
| 1231 | if (!to_cpu && !(entry->direction == DMA_TO_DEVICE) && |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1232 | !(ref->direction == DMA_FROM_DEVICE)) |
David Woodhouse | 6c132d1 | 2009-01-19 16:52:39 +0100 | [diff] [blame] | 1233 | err_printk(dev, entry, "DMA-API: device driver syncs " |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1234 | "device write-only DMA memory to device " |
| 1235 | "[device address=0x%016llx] [size=%llu bytes] " |
| 1236 | "[mapped with %s] [synced with %s]\n", |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1237 | (unsigned long long)ref->dev_addr, entry->size, |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1238 | dir2name[entry->direction], |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1239 | dir2name[ref->direction]); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1240 | |
| 1241 | out: |
| 1242 | put_hash_bucket(bucket, &flags); |
Joerg Roedel | 2d62ece | 2009-01-09 14:10:26 +0100 | [diff] [blame] | 1243 | } |
| 1244 | |
Joerg Roedel | f62bc98 | 2009-01-09 14:14:49 +0100 | [diff] [blame] | 1245 | void debug_dma_map_page(struct device *dev, struct page *page, size_t offset, |
| 1246 | size_t size, int direction, dma_addr_t dma_addr, |
| 1247 | bool map_single) |
| 1248 | { |
| 1249 | struct dma_debug_entry *entry; |
| 1250 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1251 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | f62bc98 | 2009-01-09 14:14:49 +0100 | [diff] [blame] | 1252 | return; |
| 1253 | |
Shuah Khan | bfe0fb0 | 2012-11-03 17:00:07 -0600 | [diff] [blame] | 1254 | if (dma_mapping_error(dev, dma_addr)) |
Joerg Roedel | f62bc98 | 2009-01-09 14:14:49 +0100 | [diff] [blame] | 1255 | return; |
| 1256 | |
| 1257 | entry = dma_entry_alloc(); |
| 1258 | if (!entry) |
| 1259 | return; |
| 1260 | |
| 1261 | entry->dev = dev; |
| 1262 | entry->type = dma_debug_page; |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 1263 | entry->pfn = page_to_pfn(page); |
| 1264 | entry->offset = offset, |
Joerg Roedel | f62bc98 | 2009-01-09 14:14:49 +0100 | [diff] [blame] | 1265 | entry->dev_addr = dma_addr; |
| 1266 | entry->size = size; |
| 1267 | entry->direction = direction; |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 1268 | entry->map_err_type = MAP_ERR_NOT_CHECKED; |
Joerg Roedel | f62bc98 | 2009-01-09 14:14:49 +0100 | [diff] [blame] | 1269 | |
Joerg Roedel | 9537a48 | 2009-03-23 15:35:08 +0100 | [diff] [blame] | 1270 | if (map_single) |
Joerg Roedel | f62bc98 | 2009-01-09 14:14:49 +0100 | [diff] [blame] | 1271 | entry->type = dma_debug_single; |
Joerg Roedel | 9537a48 | 2009-03-23 15:35:08 +0100 | [diff] [blame] | 1272 | |
| 1273 | if (!PageHighMem(page)) { |
Ingo Molnar | f39d1b9 | 2009-07-10 21:38:02 +0200 | [diff] [blame] | 1274 | void *addr = page_address(page) + offset; |
| 1275 | |
Joerg Roedel | 2e34bde | 2009-03-16 16:51:55 +0100 | [diff] [blame] | 1276 | check_for_stack(dev, addr); |
| 1277 | check_for_illegal_area(dev, addr, size); |
Joerg Roedel | f62bc98 | 2009-01-09 14:14:49 +0100 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | add_dma_entry(entry); |
| 1281 | } |
| 1282 | EXPORT_SYMBOL(debug_dma_map_page); |
| 1283 | |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 1284 | void debug_dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
| 1285 | { |
| 1286 | struct dma_debug_entry ref; |
| 1287 | struct dma_debug_entry *entry; |
| 1288 | struct hash_bucket *bucket; |
| 1289 | unsigned long flags; |
| 1290 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1291 | if (unlikely(dma_debug_disabled())) |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 1292 | return; |
| 1293 | |
| 1294 | ref.dev = dev; |
| 1295 | ref.dev_addr = dma_addr; |
| 1296 | bucket = get_hash_bucket(&ref, &flags); |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 1297 | |
Alexander Duyck | 96e7d7a | 2013-03-22 15:04:49 -0700 | [diff] [blame] | 1298 | list_for_each_entry(entry, &bucket->list, list) { |
| 1299 | if (!exact_match(&ref, entry)) |
| 1300 | continue; |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 1301 | |
Alexander Duyck | 96e7d7a | 2013-03-22 15:04:49 -0700 | [diff] [blame] | 1302 | /* |
| 1303 | * The same physical address can be mapped multiple |
| 1304 | * times. Without a hardware IOMMU this results in the |
| 1305 | * same device addresses being put into the dma-debug |
| 1306 | * hash multiple times too. This can result in false |
| 1307 | * positives being reported. Therefore we implement a |
| 1308 | * best-fit algorithm here which updates the first entry |
| 1309 | * from the hash which fits the reference value and is |
| 1310 | * not currently listed as being checked. |
| 1311 | */ |
| 1312 | if (entry->map_err_type == MAP_ERR_NOT_CHECKED) { |
| 1313 | entry->map_err_type = MAP_ERR_CHECKED; |
| 1314 | break; |
| 1315 | } |
| 1316 | } |
| 1317 | |
Shuah Khan | 6c9c6d6 | 2012-10-08 11:08:06 -0600 | [diff] [blame] | 1318 | put_hash_bucket(bucket, &flags); |
| 1319 | } |
| 1320 | EXPORT_SYMBOL(debug_dma_mapping_error); |
| 1321 | |
Joerg Roedel | f62bc98 | 2009-01-09 14:14:49 +0100 | [diff] [blame] | 1322 | void debug_dma_unmap_page(struct device *dev, dma_addr_t addr, |
| 1323 | size_t size, int direction, bool map_single) |
| 1324 | { |
| 1325 | struct dma_debug_entry ref = { |
| 1326 | .type = dma_debug_page, |
| 1327 | .dev = dev, |
| 1328 | .dev_addr = addr, |
| 1329 | .size = size, |
| 1330 | .direction = direction, |
| 1331 | }; |
| 1332 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1333 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | f62bc98 | 2009-01-09 14:14:49 +0100 | [diff] [blame] | 1334 | return; |
| 1335 | |
| 1336 | if (map_single) |
| 1337 | ref.type = dma_debug_single; |
| 1338 | |
| 1339 | check_unmap(&ref); |
| 1340 | } |
| 1341 | EXPORT_SYMBOL(debug_dma_unmap_page); |
| 1342 | |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1343 | void debug_dma_map_sg(struct device *dev, struct scatterlist *sg, |
| 1344 | int nents, int mapped_ents, int direction) |
| 1345 | { |
| 1346 | struct dma_debug_entry *entry; |
| 1347 | struct scatterlist *s; |
| 1348 | int i; |
| 1349 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1350 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1351 | return; |
| 1352 | |
| 1353 | for_each_sg(sg, s, mapped_ents, i) { |
| 1354 | entry = dma_entry_alloc(); |
| 1355 | if (!entry) |
| 1356 | return; |
| 1357 | |
| 1358 | entry->type = dma_debug_sg; |
| 1359 | entry->dev = dev; |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 1360 | entry->pfn = page_to_pfn(sg_page(s)); |
| 1361 | entry->offset = s->offset, |
FUJITA Tomonori | 884d059 | 2009-05-27 09:43:02 +0900 | [diff] [blame] | 1362 | entry->size = sg_dma_len(s); |
FUJITA Tomonori | 15aedea | 2009-05-27 09:43:01 +0900 | [diff] [blame] | 1363 | entry->dev_addr = sg_dma_address(s); |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1364 | entry->direction = direction; |
| 1365 | entry->sg_call_ents = nents; |
| 1366 | entry->sg_mapped_ents = mapped_ents; |
| 1367 | |
Joerg Roedel | 9537a48 | 2009-03-23 15:35:08 +0100 | [diff] [blame] | 1368 | if (!PageHighMem(sg_page(s))) { |
| 1369 | check_for_stack(dev, sg_virt(s)); |
FUJITA Tomonori | 884d059 | 2009-05-27 09:43:02 +0900 | [diff] [blame] | 1370 | check_for_illegal_area(dev, sg_virt(s), sg_dma_len(s)); |
Joerg Roedel | 9537a48 | 2009-03-23 15:35:08 +0100 | [diff] [blame] | 1371 | } |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1372 | |
| 1373 | add_dma_entry(entry); |
| 1374 | } |
| 1375 | } |
| 1376 | EXPORT_SYMBOL(debug_dma_map_sg); |
| 1377 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1378 | static int get_nr_mapped_entries(struct device *dev, |
| 1379 | struct dma_debug_entry *ref) |
FUJITA Tomonori | 88f3907 | 2009-05-27 09:43:03 +0900 | [diff] [blame] | 1380 | { |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1381 | struct dma_debug_entry *entry; |
FUJITA Tomonori | 88f3907 | 2009-05-27 09:43:03 +0900 | [diff] [blame] | 1382 | struct hash_bucket *bucket; |
| 1383 | unsigned long flags; |
Joerg Roedel | c17e2cf | 2009-06-08 15:19:29 +0200 | [diff] [blame] | 1384 | int mapped_ents; |
FUJITA Tomonori | 88f3907 | 2009-05-27 09:43:03 +0900 | [diff] [blame] | 1385 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1386 | bucket = get_hash_bucket(ref, &flags); |
Neil Horman | c6a21d0 | 2011-08-08 15:13:54 -0400 | [diff] [blame] | 1387 | entry = bucket_find_exact(bucket, ref); |
Joerg Roedel | c17e2cf | 2009-06-08 15:19:29 +0200 | [diff] [blame] | 1388 | mapped_ents = 0; |
| 1389 | |
FUJITA Tomonori | 88f3907 | 2009-05-27 09:43:03 +0900 | [diff] [blame] | 1390 | if (entry) |
| 1391 | mapped_ents = entry->sg_mapped_ents; |
| 1392 | put_hash_bucket(bucket, &flags); |
| 1393 | |
| 1394 | return mapped_ents; |
| 1395 | } |
| 1396 | |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1397 | void debug_dma_unmap_sg(struct device *dev, struct scatterlist *sglist, |
| 1398 | int nelems, int dir) |
| 1399 | { |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1400 | struct scatterlist *s; |
| 1401 | int mapped_ents = 0, i; |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1402 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1403 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1404 | return; |
| 1405 | |
| 1406 | for_each_sg(sglist, s, nelems, i) { |
| 1407 | |
| 1408 | struct dma_debug_entry ref = { |
| 1409 | .type = dma_debug_sg, |
| 1410 | .dev = dev, |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 1411 | .pfn = page_to_pfn(sg_page(s)), |
| 1412 | .offset = s->offset, |
FUJITA Tomonori | 15aedea | 2009-05-27 09:43:01 +0900 | [diff] [blame] | 1413 | .dev_addr = sg_dma_address(s), |
FUJITA Tomonori | 884d059 | 2009-05-27 09:43:02 +0900 | [diff] [blame] | 1414 | .size = sg_dma_len(s), |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1415 | .direction = dir, |
Joerg Roedel | e5e8c5b | 2009-06-11 10:03:42 +0200 | [diff] [blame] | 1416 | .sg_call_ents = nelems, |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1417 | }; |
| 1418 | |
| 1419 | if (mapped_ents && i >= mapped_ents) |
| 1420 | break; |
| 1421 | |
Joerg Roedel | e5e8c5b | 2009-06-11 10:03:42 +0200 | [diff] [blame] | 1422 | if (!i) |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1423 | mapped_ents = get_nr_mapped_entries(dev, &ref); |
Joerg Roedel | 972aa45 | 2009-01-09 14:19:54 +0100 | [diff] [blame] | 1424 | |
| 1425 | check_unmap(&ref); |
| 1426 | } |
| 1427 | } |
| 1428 | EXPORT_SYMBOL(debug_dma_unmap_sg); |
| 1429 | |
Joerg Roedel | 6bfd449 | 2009-01-09 14:38:50 +0100 | [diff] [blame] | 1430 | void debug_dma_alloc_coherent(struct device *dev, size_t size, |
| 1431 | dma_addr_t dma_addr, void *virt) |
| 1432 | { |
| 1433 | struct dma_debug_entry *entry; |
| 1434 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1435 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | 6bfd449 | 2009-01-09 14:38:50 +0100 | [diff] [blame] | 1436 | return; |
| 1437 | |
| 1438 | if (unlikely(virt == NULL)) |
| 1439 | return; |
| 1440 | |
| 1441 | entry = dma_entry_alloc(); |
| 1442 | if (!entry) |
| 1443 | return; |
| 1444 | |
| 1445 | entry->type = dma_debug_coherent; |
| 1446 | entry->dev = dev; |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 1447 | entry->pfn = page_to_pfn(virt_to_page(virt)); |
| 1448 | entry->offset = (size_t) virt & PAGE_MASK; |
Joerg Roedel | 6bfd449 | 2009-01-09 14:38:50 +0100 | [diff] [blame] | 1449 | entry->size = size; |
| 1450 | entry->dev_addr = dma_addr; |
| 1451 | entry->direction = DMA_BIDIRECTIONAL; |
| 1452 | |
| 1453 | add_dma_entry(entry); |
| 1454 | } |
| 1455 | EXPORT_SYMBOL(debug_dma_alloc_coherent); |
| 1456 | |
| 1457 | void debug_dma_free_coherent(struct device *dev, size_t size, |
| 1458 | void *virt, dma_addr_t addr) |
| 1459 | { |
| 1460 | struct dma_debug_entry ref = { |
| 1461 | .type = dma_debug_coherent, |
| 1462 | .dev = dev, |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 1463 | .pfn = page_to_pfn(virt_to_page(virt)), |
| 1464 | .offset = (size_t) virt & PAGE_MASK, |
Joerg Roedel | 6bfd449 | 2009-01-09 14:38:50 +0100 | [diff] [blame] | 1465 | .dev_addr = addr, |
| 1466 | .size = size, |
| 1467 | .direction = DMA_BIDIRECTIONAL, |
| 1468 | }; |
| 1469 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1470 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | 6bfd449 | 2009-01-09 14:38:50 +0100 | [diff] [blame] | 1471 | return; |
| 1472 | |
| 1473 | check_unmap(&ref); |
| 1474 | } |
| 1475 | EXPORT_SYMBOL(debug_dma_free_coherent); |
| 1476 | |
Joerg Roedel | b9d2317 | 2009-01-09 14:43:04 +0100 | [diff] [blame] | 1477 | void debug_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, |
| 1478 | size_t size, int direction) |
| 1479 | { |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1480 | struct dma_debug_entry ref; |
| 1481 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1482 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | b9d2317 | 2009-01-09 14:43:04 +0100 | [diff] [blame] | 1483 | return; |
| 1484 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1485 | ref.type = dma_debug_single; |
| 1486 | ref.dev = dev; |
| 1487 | ref.dev_addr = dma_handle; |
| 1488 | ref.size = size; |
| 1489 | ref.direction = direction; |
| 1490 | ref.sg_call_ents = 0; |
| 1491 | |
| 1492 | check_sync(dev, &ref, true); |
Joerg Roedel | b9d2317 | 2009-01-09 14:43:04 +0100 | [diff] [blame] | 1493 | } |
| 1494 | EXPORT_SYMBOL(debug_dma_sync_single_for_cpu); |
| 1495 | |
| 1496 | void debug_dma_sync_single_for_device(struct device *dev, |
| 1497 | dma_addr_t dma_handle, size_t size, |
| 1498 | int direction) |
| 1499 | { |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1500 | struct dma_debug_entry ref; |
| 1501 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1502 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | b9d2317 | 2009-01-09 14:43:04 +0100 | [diff] [blame] | 1503 | return; |
| 1504 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1505 | ref.type = dma_debug_single; |
| 1506 | ref.dev = dev; |
| 1507 | ref.dev_addr = dma_handle; |
| 1508 | ref.size = size; |
| 1509 | ref.direction = direction; |
| 1510 | ref.sg_call_ents = 0; |
| 1511 | |
| 1512 | check_sync(dev, &ref, false); |
Joerg Roedel | b9d2317 | 2009-01-09 14:43:04 +0100 | [diff] [blame] | 1513 | } |
| 1514 | EXPORT_SYMBOL(debug_dma_sync_single_for_device); |
| 1515 | |
Joerg Roedel | 948408b | 2009-01-09 14:55:38 +0100 | [diff] [blame] | 1516 | void debug_dma_sync_single_range_for_cpu(struct device *dev, |
| 1517 | dma_addr_t dma_handle, |
| 1518 | unsigned long offset, size_t size, |
| 1519 | int direction) |
| 1520 | { |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1521 | struct dma_debug_entry ref; |
| 1522 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1523 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | 948408b | 2009-01-09 14:55:38 +0100 | [diff] [blame] | 1524 | return; |
| 1525 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1526 | ref.type = dma_debug_single; |
| 1527 | ref.dev = dev; |
| 1528 | ref.dev_addr = dma_handle; |
| 1529 | ref.size = offset + size; |
| 1530 | ref.direction = direction; |
| 1531 | ref.sg_call_ents = 0; |
| 1532 | |
| 1533 | check_sync(dev, &ref, true); |
Joerg Roedel | 948408b | 2009-01-09 14:55:38 +0100 | [diff] [blame] | 1534 | } |
| 1535 | EXPORT_SYMBOL(debug_dma_sync_single_range_for_cpu); |
| 1536 | |
| 1537 | void debug_dma_sync_single_range_for_device(struct device *dev, |
| 1538 | dma_addr_t dma_handle, |
| 1539 | unsigned long offset, |
| 1540 | size_t size, int direction) |
| 1541 | { |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1542 | struct dma_debug_entry ref; |
| 1543 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1544 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | 948408b | 2009-01-09 14:55:38 +0100 | [diff] [blame] | 1545 | return; |
| 1546 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1547 | ref.type = dma_debug_single; |
| 1548 | ref.dev = dev; |
| 1549 | ref.dev_addr = dma_handle; |
| 1550 | ref.size = offset + size; |
| 1551 | ref.direction = direction; |
| 1552 | ref.sg_call_ents = 0; |
| 1553 | |
| 1554 | check_sync(dev, &ref, false); |
Joerg Roedel | 948408b | 2009-01-09 14:55:38 +0100 | [diff] [blame] | 1555 | } |
| 1556 | EXPORT_SYMBOL(debug_dma_sync_single_range_for_device); |
| 1557 | |
Joerg Roedel | a31fba5 | 2009-01-09 15:01:12 +0100 | [diff] [blame] | 1558 | void debug_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, |
| 1559 | int nelems, int direction) |
| 1560 | { |
| 1561 | struct scatterlist *s; |
FUJITA Tomonori | 88f3907 | 2009-05-27 09:43:03 +0900 | [diff] [blame] | 1562 | int mapped_ents = 0, i; |
Joerg Roedel | a31fba5 | 2009-01-09 15:01:12 +0100 | [diff] [blame] | 1563 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1564 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | a31fba5 | 2009-01-09 15:01:12 +0100 | [diff] [blame] | 1565 | return; |
| 1566 | |
| 1567 | for_each_sg(sg, s, nelems, i) { |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1568 | |
| 1569 | struct dma_debug_entry ref = { |
| 1570 | .type = dma_debug_sg, |
| 1571 | .dev = dev, |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 1572 | .pfn = page_to_pfn(sg_page(s)), |
| 1573 | .offset = s->offset, |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1574 | .dev_addr = sg_dma_address(s), |
| 1575 | .size = sg_dma_len(s), |
| 1576 | .direction = direction, |
| 1577 | .sg_call_ents = nelems, |
| 1578 | }; |
| 1579 | |
FUJITA Tomonori | 88f3907 | 2009-05-27 09:43:03 +0900 | [diff] [blame] | 1580 | if (!i) |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1581 | mapped_ents = get_nr_mapped_entries(dev, &ref); |
FUJITA Tomonori | 88f3907 | 2009-05-27 09:43:03 +0900 | [diff] [blame] | 1582 | |
| 1583 | if (i >= mapped_ents) |
| 1584 | break; |
| 1585 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1586 | check_sync(dev, &ref, true); |
Joerg Roedel | a31fba5 | 2009-01-09 15:01:12 +0100 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | EXPORT_SYMBOL(debug_dma_sync_sg_for_cpu); |
| 1590 | |
| 1591 | void debug_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, |
| 1592 | int nelems, int direction) |
| 1593 | { |
| 1594 | struct scatterlist *s; |
FUJITA Tomonori | 88f3907 | 2009-05-27 09:43:03 +0900 | [diff] [blame] | 1595 | int mapped_ents = 0, i; |
Joerg Roedel | a31fba5 | 2009-01-09 15:01:12 +0100 | [diff] [blame] | 1596 | |
Florian Fainelli | 01ce18b | 2014-12-10 15:41:23 -0800 | [diff] [blame^] | 1597 | if (unlikely(dma_debug_disabled())) |
Joerg Roedel | a31fba5 | 2009-01-09 15:01:12 +0100 | [diff] [blame] | 1598 | return; |
| 1599 | |
| 1600 | for_each_sg(sg, s, nelems, i) { |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1601 | |
| 1602 | struct dma_debug_entry ref = { |
| 1603 | .type = dma_debug_sg, |
| 1604 | .dev = dev, |
Dan Williams | 0abdd7a | 2014-01-21 15:48:12 -0800 | [diff] [blame] | 1605 | .pfn = page_to_pfn(sg_page(s)), |
| 1606 | .offset = s->offset, |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1607 | .dev_addr = sg_dma_address(s), |
| 1608 | .size = sg_dma_len(s), |
| 1609 | .direction = direction, |
| 1610 | .sg_call_ents = nelems, |
| 1611 | }; |
FUJITA Tomonori | 88f3907 | 2009-05-27 09:43:03 +0900 | [diff] [blame] | 1612 | if (!i) |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1613 | mapped_ents = get_nr_mapped_entries(dev, &ref); |
FUJITA Tomonori | 88f3907 | 2009-05-27 09:43:03 +0900 | [diff] [blame] | 1614 | |
| 1615 | if (i >= mapped_ents) |
| 1616 | break; |
| 1617 | |
Joerg Roedel | aa010ef | 2009-06-12 15:25:06 +0200 | [diff] [blame] | 1618 | check_sync(dev, &ref, false); |
Joerg Roedel | a31fba5 | 2009-01-09 15:01:12 +0100 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | EXPORT_SYMBOL(debug_dma_sync_sg_for_device); |
| 1622 | |
Joerg Roedel | 1745de5 | 2009-05-22 21:49:51 +0200 | [diff] [blame] | 1623 | static int __init dma_debug_driver_setup(char *str) |
| 1624 | { |
| 1625 | int i; |
| 1626 | |
| 1627 | for (i = 0; i < NAME_MAX_LEN - 1; ++i, ++str) { |
| 1628 | current_driver_name[i] = *str; |
| 1629 | if (*str == 0) |
| 1630 | break; |
| 1631 | } |
| 1632 | |
| 1633 | if (current_driver_name[0]) |
Joerg Roedel | e7ed70e | 2009-06-08 15:39:24 +0200 | [diff] [blame] | 1634 | pr_info("DMA-API: enable driver filter for driver [%s]\n", |
| 1635 | current_driver_name); |
Joerg Roedel | 1745de5 | 2009-05-22 21:49:51 +0200 | [diff] [blame] | 1636 | |
| 1637 | |
| 1638 | return 1; |
| 1639 | } |
| 1640 | __setup("dma_debug_driver=", dma_debug_driver_setup); |