Thomas Gleixner | 3b20eb2 | 2019-05-29 16:57:35 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 2 | /* |
David Woodhouse | a15a519 | 2009-07-01 18:49:06 +0100 | [diff] [blame] | 3 | * Copyright © 2006-2009, Intel Corporation. |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 4 | * |
mark gross | 98bcef5 | 2008-02-23 15:23:35 -0800 | [diff] [blame] | 5 | * Author: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Kay, Allen M | 3871794 | 2008-09-09 18:37:29 +0300 | [diff] [blame] | 8 | #include <linux/iova.h> |
Sakari Ailus | 15bbdec | 2015-07-13 14:31:30 +0300 | [diff] [blame] | 9 | #include <linux/module.h> |
Robin Murphy | 85b4545 | 2015-01-12 17:51:14 +0000 | [diff] [blame] | 10 | #include <linux/slab.h> |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 11 | #include <linux/smp.h> |
| 12 | #include <linux/bitops.h> |
Sebastian Andrzej Siewior | aaffaa8 | 2017-06-27 18:16:47 +0200 | [diff] [blame] | 13 | #include <linux/cpu.h> |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 14 | |
Robin Murphy | bb68b2f | 2017-09-21 16:52:46 +0100 | [diff] [blame] | 15 | /* The anchor node sits above the top of the usable address space */ |
| 16 | #define IOVA_ANCHOR ~0UL |
| 17 | |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 18 | static bool iova_rcache_insert(struct iova_domain *iovad, |
| 19 | unsigned long pfn, |
| 20 | unsigned long size); |
| 21 | static unsigned long iova_rcache_get(struct iova_domain *iovad, |
| 22 | unsigned long size, |
| 23 | unsigned long limit_pfn); |
| 24 | static void init_iova_rcaches(struct iova_domain *iovad); |
| 25 | static void free_iova_rcaches(struct iova_domain *iovad); |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 26 | static void fq_destroy_all_entries(struct iova_domain *iovad); |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 27 | static void fq_flush_timeout(struct timer_list *t); |
Robin Murphy | 85b4545 | 2015-01-12 17:51:14 +0000 | [diff] [blame] | 28 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 29 | void |
Robin Murphy | 0fb5fe8 | 2015-01-12 17:51:16 +0000 | [diff] [blame] | 30 | init_iova_domain(struct iova_domain *iovad, unsigned long granule, |
Zhen Lei | aa3ac94 | 2017-09-21 16:52:45 +0100 | [diff] [blame] | 31 | unsigned long start_pfn) |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 32 | { |
Robin Murphy | 0fb5fe8 | 2015-01-12 17:51:16 +0000 | [diff] [blame] | 33 | /* |
| 34 | * IOVA granularity will normally be equal to the smallest |
| 35 | * supported IOMMU page size; both *must* be capable of |
| 36 | * representing individual CPU pages exactly. |
| 37 | */ |
| 38 | BUG_ON((granule > PAGE_SIZE) || !is_power_of_2(granule)); |
| 39 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 40 | spin_lock_init(&iovad->iova_rbtree_lock); |
| 41 | iovad->rbroot = RB_ROOT; |
Robin Murphy | 973f5fb | 2017-09-21 16:52:47 +0100 | [diff] [blame] | 42 | iovad->cached_node = &iovad->anchor.node; |
| 43 | iovad->cached32_node = &iovad->anchor.node; |
Robin Murphy | 0fb5fe8 | 2015-01-12 17:51:16 +0000 | [diff] [blame] | 44 | iovad->granule = granule; |
Robin Murphy | 1b72250 | 2015-01-12 17:51:15 +0000 | [diff] [blame] | 45 | iovad->start_pfn = start_pfn; |
Zhen Lei | aa3ac94 | 2017-09-21 16:52:45 +0100 | [diff] [blame] | 46 | iovad->dma_32bit_pfn = 1UL << (32 - iova_shift(iovad)); |
Ganapatrao Kulkarni | bee60e9 | 2018-09-05 09:57:36 +0530 | [diff] [blame] | 47 | iovad->max32_alloc_size = iovad->dma_32bit_pfn; |
Joerg Roedel | 42f87e7 | 2017-08-10 14:44:28 +0200 | [diff] [blame] | 48 | iovad->flush_cb = NULL; |
| 49 | iovad->fq = NULL; |
Robin Murphy | bb68b2f | 2017-09-21 16:52:46 +0100 | [diff] [blame] | 50 | iovad->anchor.pfn_lo = iovad->anchor.pfn_hi = IOVA_ANCHOR; |
| 51 | rb_link_node(&iovad->anchor.node, NULL, &iovad->rbroot.rb_node); |
| 52 | rb_insert_color(&iovad->anchor.node, &iovad->rbroot); |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 53 | init_iova_rcaches(iovad); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 54 | } |
Sakari Ailus | 9b41760 | 2015-07-13 14:31:29 +0300 | [diff] [blame] | 55 | EXPORT_SYMBOL_GPL(init_iova_domain); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 56 | |
Joerg Roedel | 42f87e7 | 2017-08-10 14:44:28 +0200 | [diff] [blame] | 57 | static void free_iova_flush_queue(struct iova_domain *iovad) |
| 58 | { |
| 59 | if (!iovad->fq) |
| 60 | return; |
| 61 | |
Joerg Roedel | 9a005a8 | 2017-08-10 16:58:18 +0200 | [diff] [blame] | 62 | if (timer_pending(&iovad->fq_timer)) |
| 63 | del_timer(&iovad->fq_timer); |
| 64 | |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 65 | fq_destroy_all_entries(iovad); |
Joerg Roedel | 9a005a8 | 2017-08-10 16:58:18 +0200 | [diff] [blame] | 66 | |
Joerg Roedel | 42f87e7 | 2017-08-10 14:44:28 +0200 | [diff] [blame] | 67 | free_percpu(iovad->fq); |
| 68 | |
| 69 | iovad->fq = NULL; |
| 70 | iovad->flush_cb = NULL; |
| 71 | iovad->entry_dtor = NULL; |
| 72 | } |
| 73 | |
| 74 | int init_iova_flush_queue(struct iova_domain *iovad, |
| 75 | iova_flush_cb flush_cb, iova_entry_dtor entry_dtor) |
| 76 | { |
| 77 | int cpu; |
| 78 | |
Joerg Roedel | fb418da | 2017-08-10 16:14:59 +0200 | [diff] [blame] | 79 | atomic64_set(&iovad->fq_flush_start_cnt, 0); |
| 80 | atomic64_set(&iovad->fq_flush_finish_cnt, 0); |
| 81 | |
Joerg Roedel | 42f87e7 | 2017-08-10 14:44:28 +0200 | [diff] [blame] | 82 | iovad->fq = alloc_percpu(struct iova_fq); |
| 83 | if (!iovad->fq) |
| 84 | return -ENOMEM; |
| 85 | |
| 86 | iovad->flush_cb = flush_cb; |
| 87 | iovad->entry_dtor = entry_dtor; |
| 88 | |
| 89 | for_each_possible_cpu(cpu) { |
| 90 | struct iova_fq *fq; |
| 91 | |
| 92 | fq = per_cpu_ptr(iovad->fq, cpu); |
| 93 | fq->head = 0; |
| 94 | fq->tail = 0; |
Joerg Roedel | 8109c2a | 2017-08-10 16:31:17 +0200 | [diff] [blame] | 95 | |
| 96 | spin_lock_init(&fq->lock); |
Joerg Roedel | 42f87e7 | 2017-08-10 14:44:28 +0200 | [diff] [blame] | 97 | } |
| 98 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 99 | timer_setup(&iovad->fq_timer, fq_flush_timeout, 0); |
Joerg Roedel | 9a005a8 | 2017-08-10 16:58:18 +0200 | [diff] [blame] | 100 | atomic_set(&iovad->fq_timer_on, 0); |
| 101 | |
Joerg Roedel | 42f87e7 | 2017-08-10 14:44:28 +0200 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | EXPORT_SYMBOL_GPL(init_iova_flush_queue); |
| 105 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 106 | static struct rb_node * |
Robin Murphy | 973f5fb | 2017-09-21 16:52:47 +0100 | [diff] [blame] | 107 | __get_cached_rbnode(struct iova_domain *iovad, unsigned long limit_pfn) |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 108 | { |
Robin Murphy | 973f5fb | 2017-09-21 16:52:47 +0100 | [diff] [blame] | 109 | if (limit_pfn <= iovad->dma_32bit_pfn) |
| 110 | return iovad->cached32_node; |
Robin Murphy | e60aa7b | 2017-09-21 16:52:44 +0100 | [diff] [blame] | 111 | |
Robin Murphy | 973f5fb | 2017-09-21 16:52:47 +0100 | [diff] [blame] | 112 | return iovad->cached_node; |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static void |
Robin Murphy | e60aa7b | 2017-09-21 16:52:44 +0100 | [diff] [blame] | 116 | __cached_rbnode_insert_update(struct iova_domain *iovad, struct iova *new) |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 117 | { |
Robin Murphy | e60aa7b | 2017-09-21 16:52:44 +0100 | [diff] [blame] | 118 | if (new->pfn_hi < iovad->dma_32bit_pfn) |
| 119 | iovad->cached32_node = &new->node; |
| 120 | else |
| 121 | iovad->cached_node = &new->node; |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static void |
| 125 | __cached_rbnode_delete_update(struct iova_domain *iovad, struct iova *free) |
| 126 | { |
| 127 | struct iova *cached_iova; |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 128 | |
Robin Murphy | e60aa7b | 2017-09-21 16:52:44 +0100 | [diff] [blame] | 129 | cached_iova = rb_entry(iovad->cached32_node, struct iova, node); |
| 130 | if (free->pfn_hi < iovad->dma_32bit_pfn && |
Ganapatrao Kulkarni | bee60e9 | 2018-09-05 09:57:36 +0530 | [diff] [blame] | 131 | free->pfn_lo >= cached_iova->pfn_lo) { |
Robin Murphy | e60aa7b | 2017-09-21 16:52:44 +0100 | [diff] [blame] | 132 | iovad->cached32_node = rb_next(&free->node); |
Ganapatrao Kulkarni | bee60e9 | 2018-09-05 09:57:36 +0530 | [diff] [blame] | 133 | iovad->max32_alloc_size = iovad->dma_32bit_pfn; |
| 134 | } |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 135 | |
Robin Murphy | e60aa7b | 2017-09-21 16:52:44 +0100 | [diff] [blame] | 136 | cached_iova = rb_entry(iovad->cached_node, struct iova, node); |
Robin Murphy | 973f5fb | 2017-09-21 16:52:47 +0100 | [diff] [blame] | 137 | if (free->pfn_lo >= cached_iova->pfn_lo) |
Robin Murphy | e60aa7b | 2017-09-21 16:52:44 +0100 | [diff] [blame] | 138 | iovad->cached_node = rb_next(&free->node); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Marek Szyprowski | d751751 | 2017-02-24 12:13:37 +0100 | [diff] [blame] | 141 | /* Insert the iova into domain rbtree by holding writer lock */ |
| 142 | static void |
| 143 | iova_insert_rbtree(struct rb_root *root, struct iova *iova, |
| 144 | struct rb_node *start) |
| 145 | { |
| 146 | struct rb_node **new, *parent = NULL; |
| 147 | |
| 148 | new = (start) ? &start : &(root->rb_node); |
| 149 | /* Figure out where to put new node */ |
| 150 | while (*new) { |
| 151 | struct iova *this = rb_entry(*new, struct iova, node); |
| 152 | |
| 153 | parent = *new; |
| 154 | |
| 155 | if (iova->pfn_lo < this->pfn_lo) |
| 156 | new = &((*new)->rb_left); |
| 157 | else if (iova->pfn_lo > this->pfn_lo) |
| 158 | new = &((*new)->rb_right); |
| 159 | else { |
| 160 | WARN_ON(1); /* this should not happen */ |
| 161 | return; |
| 162 | } |
| 163 | } |
| 164 | /* Add new node and rebalance tree. */ |
| 165 | rb_link_node(&iova->node, parent, new); |
| 166 | rb_insert_color(&iova->node, root); |
| 167 | } |
| 168 | |
mark gross | ddf0288 | 2008-03-04 15:22:04 -0800 | [diff] [blame] | 169 | static int __alloc_and_insert_iova_range(struct iova_domain *iovad, |
| 170 | unsigned long size, unsigned long limit_pfn, |
| 171 | struct iova *new, bool size_aligned) |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 172 | { |
Robin Murphy | 973f5fb | 2017-09-21 16:52:47 +0100 | [diff] [blame] | 173 | struct rb_node *curr, *prev; |
| 174 | struct iova *curr_iova; |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 175 | unsigned long flags; |
Robin Murphy | e60aa7b | 2017-09-21 16:52:44 +0100 | [diff] [blame] | 176 | unsigned long new_pfn; |
Zhen Lei | 086c83a | 2017-09-21 16:52:43 +0100 | [diff] [blame] | 177 | unsigned long align_mask = ~0UL; |
| 178 | |
| 179 | if (size_aligned) |
| 180 | align_mask <<= fls_long(size - 1); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 181 | |
| 182 | /* Walk the tree backwards */ |
| 183 | spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); |
Ganapatrao Kulkarni | bee60e9 | 2018-09-05 09:57:36 +0530 | [diff] [blame] | 184 | if (limit_pfn <= iovad->dma_32bit_pfn && |
| 185 | size >= iovad->max32_alloc_size) |
| 186 | goto iova32_full; |
| 187 | |
Robin Murphy | 973f5fb | 2017-09-21 16:52:47 +0100 | [diff] [blame] | 188 | curr = __get_cached_rbnode(iovad, limit_pfn); |
| 189 | curr_iova = rb_entry(curr, struct iova, node); |
| 190 | do { |
| 191 | limit_pfn = min(limit_pfn, curr_iova->pfn_lo); |
| 192 | new_pfn = (limit_pfn - size) & align_mask; |
mark gross | ddf0288 | 2008-03-04 15:22:04 -0800 | [diff] [blame] | 193 | prev = curr; |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 194 | curr = rb_prev(curr); |
Robin Murphy | 973f5fb | 2017-09-21 16:52:47 +0100 | [diff] [blame] | 195 | curr_iova = rb_entry(curr, struct iova, node); |
| 196 | } while (curr && new_pfn <= curr_iova->pfn_hi); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 197 | |
Robert Richter | 80ef446 | 2019-03-20 18:57:23 +0000 | [diff] [blame] | 198 | if (limit_pfn < size || new_pfn < iovad->start_pfn) { |
| 199 | iovad->max32_alloc_size = size; |
Ganapatrao Kulkarni | bee60e9 | 2018-09-05 09:57:36 +0530 | [diff] [blame] | 200 | goto iova32_full; |
Robert Richter | 80ef446 | 2019-03-20 18:57:23 +0000 | [diff] [blame] | 201 | } |
Keshavamurthy, Anil S | f76aec7 | 2007-10-21 16:41:58 -0700 | [diff] [blame] | 202 | |
| 203 | /* pfn_lo will point to size aligned address if size_aligned is set */ |
Zhen Lei | 086c83a | 2017-09-21 16:52:43 +0100 | [diff] [blame] | 204 | new->pfn_lo = new_pfn; |
Keshavamurthy, Anil S | f76aec7 | 2007-10-21 16:41:58 -0700 | [diff] [blame] | 205 | new->pfn_hi = new->pfn_lo + size - 1; |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 206 | |
Marek Szyprowski | d751751 | 2017-02-24 12:13:37 +0100 | [diff] [blame] | 207 | /* If we have 'prev', it's a valid place to start the insertion. */ |
| 208 | iova_insert_rbtree(&iovad->rbroot, new, prev); |
Robin Murphy | e60aa7b | 2017-09-21 16:52:44 +0100 | [diff] [blame] | 209 | __cached_rbnode_insert_update(iovad, new); |
mark gross | ddf0288 | 2008-03-04 15:22:04 -0800 | [diff] [blame] | 210 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 211 | spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); |
| 212 | return 0; |
Ganapatrao Kulkarni | bee60e9 | 2018-09-05 09:57:36 +0530 | [diff] [blame] | 213 | |
| 214 | iova32_full: |
Ganapatrao Kulkarni | bee60e9 | 2018-09-05 09:57:36 +0530 | [diff] [blame] | 215 | spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); |
| 216 | return -ENOMEM; |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Sakari Ailus | ae1ff3d | 2015-07-13 14:31:28 +0300 | [diff] [blame] | 219 | static struct kmem_cache *iova_cache; |
| 220 | static unsigned int iova_cache_users; |
| 221 | static DEFINE_MUTEX(iova_cache_mutex); |
| 222 | |
| 223 | struct iova *alloc_iova_mem(void) |
| 224 | { |
| 225 | return kmem_cache_alloc(iova_cache, GFP_ATOMIC); |
| 226 | } |
| 227 | EXPORT_SYMBOL(alloc_iova_mem); |
| 228 | |
| 229 | void free_iova_mem(struct iova *iova) |
| 230 | { |
Robin Murphy | bb68b2f | 2017-09-21 16:52:46 +0100 | [diff] [blame] | 231 | if (iova->pfn_lo != IOVA_ANCHOR) |
| 232 | kmem_cache_free(iova_cache, iova); |
Sakari Ailus | ae1ff3d | 2015-07-13 14:31:28 +0300 | [diff] [blame] | 233 | } |
| 234 | EXPORT_SYMBOL(free_iova_mem); |
| 235 | |
| 236 | int iova_cache_get(void) |
| 237 | { |
| 238 | mutex_lock(&iova_cache_mutex); |
| 239 | if (!iova_cache_users) { |
| 240 | iova_cache = kmem_cache_create( |
| 241 | "iommu_iova", sizeof(struct iova), 0, |
| 242 | SLAB_HWCACHE_ALIGN, NULL); |
| 243 | if (!iova_cache) { |
| 244 | mutex_unlock(&iova_cache_mutex); |
| 245 | printk(KERN_ERR "Couldn't create iova cache\n"); |
| 246 | return -ENOMEM; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | iova_cache_users++; |
| 251 | mutex_unlock(&iova_cache_mutex); |
| 252 | |
| 253 | return 0; |
| 254 | } |
Sakari Ailus | 9b41760 | 2015-07-13 14:31:29 +0300 | [diff] [blame] | 255 | EXPORT_SYMBOL_GPL(iova_cache_get); |
Sakari Ailus | ae1ff3d | 2015-07-13 14:31:28 +0300 | [diff] [blame] | 256 | |
| 257 | void iova_cache_put(void) |
| 258 | { |
| 259 | mutex_lock(&iova_cache_mutex); |
| 260 | if (WARN_ON(!iova_cache_users)) { |
| 261 | mutex_unlock(&iova_cache_mutex); |
| 262 | return; |
| 263 | } |
| 264 | iova_cache_users--; |
| 265 | if (!iova_cache_users) |
| 266 | kmem_cache_destroy(iova_cache); |
| 267 | mutex_unlock(&iova_cache_mutex); |
| 268 | } |
Sakari Ailus | 9b41760 | 2015-07-13 14:31:29 +0300 | [diff] [blame] | 269 | EXPORT_SYMBOL_GPL(iova_cache_put); |
Sakari Ailus | ae1ff3d | 2015-07-13 14:31:28 +0300 | [diff] [blame] | 270 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 271 | /** |
| 272 | * alloc_iova - allocates an iova |
Masanari Iida | 07db040 | 2012-07-22 02:21:32 +0900 | [diff] [blame] | 273 | * @iovad: - iova domain in question |
| 274 | * @size: - size of page frames to allocate |
| 275 | * @limit_pfn: - max limit address |
| 276 | * @size_aligned: - set if size_aligned address range is required |
Robin Murphy | 1b72250 | 2015-01-12 17:51:15 +0000 | [diff] [blame] | 277 | * This function allocates an iova in the range iovad->start_pfn to limit_pfn, |
| 278 | * searching top-down from limit_pfn to iovad->start_pfn. If the size_aligned |
Keshavamurthy, Anil S | f76aec7 | 2007-10-21 16:41:58 -0700 | [diff] [blame] | 279 | * flag is set then the allocated address iova->pfn_lo will be naturally |
| 280 | * aligned on roundup_power_of_two(size). |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 281 | */ |
| 282 | struct iova * |
| 283 | alloc_iova(struct iova_domain *iovad, unsigned long size, |
Keshavamurthy, Anil S | f76aec7 | 2007-10-21 16:41:58 -0700 | [diff] [blame] | 284 | unsigned long limit_pfn, |
| 285 | bool size_aligned) |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 286 | { |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 287 | struct iova *new_iova; |
| 288 | int ret; |
| 289 | |
| 290 | new_iova = alloc_iova_mem(); |
| 291 | if (!new_iova) |
| 292 | return NULL; |
| 293 | |
Robin Murphy | 757c370 | 2017-05-16 12:26:48 +0100 | [diff] [blame] | 294 | ret = __alloc_and_insert_iova_range(iovad, size, limit_pfn + 1, |
mark gross | ddf0288 | 2008-03-04 15:22:04 -0800 | [diff] [blame] | 295 | new_iova, size_aligned); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 296 | |
| 297 | if (ret) { |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 298 | free_iova_mem(new_iova); |
| 299 | return NULL; |
| 300 | } |
| 301 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 302 | return new_iova; |
| 303 | } |
Sakari Ailus | 9b41760 | 2015-07-13 14:31:29 +0300 | [diff] [blame] | 304 | EXPORT_SYMBOL_GPL(alloc_iova); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 305 | |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 306 | static struct iova * |
| 307 | private_find_iova(struct iova_domain *iovad, unsigned long pfn) |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 308 | { |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 309 | struct rb_node *node = iovad->rbroot.rb_node; |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 310 | |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 311 | assert_spin_locked(&iovad->iova_rbtree_lock); |
| 312 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 313 | while (node) { |
Geliang Tang | eba484b | 2016-12-19 22:46:58 +0800 | [diff] [blame] | 314 | struct iova *iova = rb_entry(node, struct iova, node); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 315 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 316 | if (pfn < iova->pfn_lo) |
| 317 | node = node->rb_left; |
Zhen Lei | 2070f94 | 2017-09-21 16:52:42 +0100 | [diff] [blame] | 318 | else if (pfn > iova->pfn_hi) |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 319 | node = node->rb_right; |
Zhen Lei | 2070f94 | 2017-09-21 16:52:42 +0100 | [diff] [blame] | 320 | else |
| 321 | return iova; /* pfn falls within iova's range */ |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 324 | return NULL; |
| 325 | } |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 326 | |
| 327 | static void private_free_iova(struct iova_domain *iovad, struct iova *iova) |
| 328 | { |
| 329 | assert_spin_locked(&iovad->iova_rbtree_lock); |
| 330 | __cached_rbnode_delete_update(iovad, iova); |
| 331 | rb_erase(&iova->node, &iovad->rbroot); |
| 332 | free_iova_mem(iova); |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * find_iova - finds an iova for a given pfn |
| 337 | * @iovad: - iova domain in question. |
| 338 | * @pfn: - page frame number |
| 339 | * This function finds and returns an iova belonging to the |
| 340 | * given doamin which matches the given pfn. |
| 341 | */ |
| 342 | struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn) |
| 343 | { |
| 344 | unsigned long flags; |
| 345 | struct iova *iova; |
| 346 | |
| 347 | /* Take the lock so that no other thread is manipulating the rbtree */ |
| 348 | spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); |
| 349 | iova = private_find_iova(iovad, pfn); |
| 350 | spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); |
| 351 | return iova; |
| 352 | } |
Sakari Ailus | 9b41760 | 2015-07-13 14:31:29 +0300 | [diff] [blame] | 353 | EXPORT_SYMBOL_GPL(find_iova); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 354 | |
| 355 | /** |
| 356 | * __free_iova - frees the given iova |
| 357 | * @iovad: iova domain in question. |
| 358 | * @iova: iova in question. |
| 359 | * Frees the given iova belonging to the giving domain |
| 360 | */ |
| 361 | void |
| 362 | __free_iova(struct iova_domain *iovad, struct iova *iova) |
| 363 | { |
| 364 | unsigned long flags; |
| 365 | |
| 366 | spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 367 | private_free_iova(iovad, iova); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 368 | spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 369 | } |
Sakari Ailus | 9b41760 | 2015-07-13 14:31:29 +0300 | [diff] [blame] | 370 | EXPORT_SYMBOL_GPL(__free_iova); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 371 | |
| 372 | /** |
| 373 | * free_iova - finds and frees the iova for a given pfn |
| 374 | * @iovad: - iova domain in question. |
| 375 | * @pfn: - pfn that is allocated previously |
| 376 | * This functions finds an iova for a given pfn and then |
| 377 | * frees the iova from that domain. |
| 378 | */ |
| 379 | void |
| 380 | free_iova(struct iova_domain *iovad, unsigned long pfn) |
| 381 | { |
| 382 | struct iova *iova = find_iova(iovad, pfn); |
Robert Callicotte | 733cac2 | 2015-04-16 23:32:47 -0500 | [diff] [blame] | 383 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 384 | if (iova) |
| 385 | __free_iova(iovad, iova); |
| 386 | |
| 387 | } |
Sakari Ailus | 9b41760 | 2015-07-13 14:31:29 +0300 | [diff] [blame] | 388 | EXPORT_SYMBOL_GPL(free_iova); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 389 | |
| 390 | /** |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 391 | * alloc_iova_fast - allocates an iova from rcache |
| 392 | * @iovad: - iova domain in question |
| 393 | * @size: - size of page frames to allocate |
| 394 | * @limit_pfn: - max limit address |
Tomasz Nowicki | 538d5b3 | 2017-09-20 10:52:02 +0200 | [diff] [blame] | 395 | * @flush_rcache: - set to flush rcache on regular allocation failure |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 396 | * This function tries to satisfy an iova allocation from the rcache, |
Tomasz Nowicki | 538d5b3 | 2017-09-20 10:52:02 +0200 | [diff] [blame] | 397 | * and falls back to regular allocation on failure. If regular allocation |
| 398 | * fails too and the flush_rcache flag is set then the rcache will be flushed. |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 399 | */ |
| 400 | unsigned long |
| 401 | alloc_iova_fast(struct iova_domain *iovad, unsigned long size, |
Tomasz Nowicki | 538d5b3 | 2017-09-20 10:52:02 +0200 | [diff] [blame] | 402 | unsigned long limit_pfn, bool flush_rcache) |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 403 | { |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 404 | unsigned long iova_pfn; |
| 405 | struct iova *new_iova; |
| 406 | |
Robin Murphy | b826ee9 | 2017-09-19 14:48:40 +0100 | [diff] [blame] | 407 | iova_pfn = iova_rcache_get(iovad, size, limit_pfn + 1); |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 408 | if (iova_pfn) |
| 409 | return iova_pfn; |
| 410 | |
| 411 | retry: |
| 412 | new_iova = alloc_iova(iovad, size, limit_pfn, true); |
| 413 | if (!new_iova) { |
| 414 | unsigned int cpu; |
| 415 | |
Tomasz Nowicki | 538d5b3 | 2017-09-20 10:52:02 +0200 | [diff] [blame] | 416 | if (!flush_rcache) |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 417 | return 0; |
| 418 | |
| 419 | /* Try replenishing IOVAs by flushing rcache. */ |
Tomasz Nowicki | 538d5b3 | 2017-09-20 10:52:02 +0200 | [diff] [blame] | 420 | flush_rcache = false; |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 421 | for_each_online_cpu(cpu) |
| 422 | free_cpu_cached_iovas(cpu, iovad); |
| 423 | goto retry; |
| 424 | } |
| 425 | |
| 426 | return new_iova->pfn_lo; |
| 427 | } |
| 428 | EXPORT_SYMBOL_GPL(alloc_iova_fast); |
| 429 | |
| 430 | /** |
| 431 | * free_iova_fast - free iova pfn range into rcache |
| 432 | * @iovad: - iova domain in question. |
| 433 | * @pfn: - pfn that is allocated previously |
| 434 | * @size: - # of pages in range |
| 435 | * This functions frees an iova range by trying to put it into the rcache, |
| 436 | * falling back to regular iova deallocation via free_iova() if this fails. |
| 437 | */ |
| 438 | void |
| 439 | free_iova_fast(struct iova_domain *iovad, unsigned long pfn, unsigned long size) |
| 440 | { |
| 441 | if (iova_rcache_insert(iovad, pfn, size)) |
| 442 | return; |
| 443 | |
| 444 | free_iova(iovad, pfn); |
| 445 | } |
| 446 | EXPORT_SYMBOL_GPL(free_iova_fast); |
| 447 | |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 448 | #define fq_ring_for_each(i, fq) \ |
| 449 | for ((i) = (fq)->head; (i) != (fq)->tail; (i) = ((i) + 1) % IOVA_FQ_SIZE) |
| 450 | |
| 451 | static inline bool fq_full(struct iova_fq *fq) |
| 452 | { |
Joerg Roedel | 8109c2a | 2017-08-10 16:31:17 +0200 | [diff] [blame] | 453 | assert_spin_locked(&fq->lock); |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 454 | return (((fq->tail + 1) % IOVA_FQ_SIZE) == fq->head); |
| 455 | } |
| 456 | |
| 457 | static inline unsigned fq_ring_add(struct iova_fq *fq) |
| 458 | { |
| 459 | unsigned idx = fq->tail; |
| 460 | |
Joerg Roedel | 8109c2a | 2017-08-10 16:31:17 +0200 | [diff] [blame] | 461 | assert_spin_locked(&fq->lock); |
| 462 | |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 463 | fq->tail = (idx + 1) % IOVA_FQ_SIZE; |
| 464 | |
| 465 | return idx; |
| 466 | } |
| 467 | |
| 468 | static void fq_ring_free(struct iova_domain *iovad, struct iova_fq *fq) |
| 469 | { |
Joerg Roedel | fb418da | 2017-08-10 16:14:59 +0200 | [diff] [blame] | 470 | u64 counter = atomic64_read(&iovad->fq_flush_finish_cnt); |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 471 | unsigned idx; |
| 472 | |
Joerg Roedel | 8109c2a | 2017-08-10 16:31:17 +0200 | [diff] [blame] | 473 | assert_spin_locked(&fq->lock); |
| 474 | |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 475 | fq_ring_for_each(idx, fq) { |
| 476 | |
Joerg Roedel | fb418da | 2017-08-10 16:14:59 +0200 | [diff] [blame] | 477 | if (fq->entries[idx].counter >= counter) |
| 478 | break; |
| 479 | |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 480 | if (iovad->entry_dtor) |
| 481 | iovad->entry_dtor(fq->entries[idx].data); |
| 482 | |
| 483 | free_iova_fast(iovad, |
| 484 | fq->entries[idx].iova_pfn, |
| 485 | fq->entries[idx].pages); |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 486 | |
Joerg Roedel | fb418da | 2017-08-10 16:14:59 +0200 | [diff] [blame] | 487 | fq->head = (fq->head + 1) % IOVA_FQ_SIZE; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | static void iova_domain_flush(struct iova_domain *iovad) |
| 492 | { |
| 493 | atomic64_inc(&iovad->fq_flush_start_cnt); |
| 494 | iovad->flush_cb(iovad); |
| 495 | atomic64_inc(&iovad->fq_flush_finish_cnt); |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static void fq_destroy_all_entries(struct iova_domain *iovad) |
| 499 | { |
| 500 | int cpu; |
| 501 | |
| 502 | /* |
| 503 | * This code runs when the iova_domain is being detroyed, so don't |
| 504 | * bother to free iovas, just call the entry_dtor on all remaining |
| 505 | * entries. |
| 506 | */ |
| 507 | if (!iovad->entry_dtor) |
| 508 | return; |
| 509 | |
| 510 | for_each_possible_cpu(cpu) { |
| 511 | struct iova_fq *fq = per_cpu_ptr(iovad->fq, cpu); |
| 512 | int idx; |
| 513 | |
| 514 | fq_ring_for_each(idx, fq) |
| 515 | iovad->entry_dtor(fq->entries[idx].data); |
| 516 | } |
| 517 | } |
| 518 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 519 | static void fq_flush_timeout(struct timer_list *t) |
Joerg Roedel | 9a005a8 | 2017-08-10 16:58:18 +0200 | [diff] [blame] | 520 | { |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 521 | struct iova_domain *iovad = from_timer(iovad, t, fq_timer); |
Joerg Roedel | 9a005a8 | 2017-08-10 16:58:18 +0200 | [diff] [blame] | 522 | int cpu; |
| 523 | |
| 524 | atomic_set(&iovad->fq_timer_on, 0); |
| 525 | iova_domain_flush(iovad); |
| 526 | |
| 527 | for_each_possible_cpu(cpu) { |
| 528 | unsigned long flags; |
| 529 | struct iova_fq *fq; |
| 530 | |
| 531 | fq = per_cpu_ptr(iovad->fq, cpu); |
| 532 | spin_lock_irqsave(&fq->lock, flags); |
| 533 | fq_ring_free(iovad, fq); |
| 534 | spin_unlock_irqrestore(&fq->lock, flags); |
| 535 | } |
| 536 | } |
| 537 | |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 538 | void queue_iova(struct iova_domain *iovad, |
| 539 | unsigned long pfn, unsigned long pages, |
| 540 | unsigned long data) |
| 541 | { |
Sebastian Andrzej Siewior | 94e2cc4 | 2017-09-21 17:21:40 +0200 | [diff] [blame] | 542 | struct iova_fq *fq = raw_cpu_ptr(iovad->fq); |
Joerg Roedel | 8109c2a | 2017-08-10 16:31:17 +0200 | [diff] [blame] | 543 | unsigned long flags; |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 544 | unsigned idx; |
| 545 | |
Joerg Roedel | 8109c2a | 2017-08-10 16:31:17 +0200 | [diff] [blame] | 546 | spin_lock_irqsave(&fq->lock, flags); |
| 547 | |
Joerg Roedel | fb418da | 2017-08-10 16:14:59 +0200 | [diff] [blame] | 548 | /* |
| 549 | * First remove all entries from the flush queue that have already been |
| 550 | * flushed out on another CPU. This makes the fq_full() check below less |
| 551 | * likely to be true. |
| 552 | */ |
| 553 | fq_ring_free(iovad, fq); |
| 554 | |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 555 | if (fq_full(fq)) { |
Joerg Roedel | fb418da | 2017-08-10 16:14:59 +0200 | [diff] [blame] | 556 | iova_domain_flush(iovad); |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 557 | fq_ring_free(iovad, fq); |
| 558 | } |
| 559 | |
| 560 | idx = fq_ring_add(fq); |
| 561 | |
| 562 | fq->entries[idx].iova_pfn = pfn; |
| 563 | fq->entries[idx].pages = pages; |
| 564 | fq->entries[idx].data = data; |
Joerg Roedel | fb418da | 2017-08-10 16:14:59 +0200 | [diff] [blame] | 565 | fq->entries[idx].counter = atomic64_read(&iovad->fq_flush_start_cnt); |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 566 | |
Joerg Roedel | 8109c2a | 2017-08-10 16:31:17 +0200 | [diff] [blame] | 567 | spin_unlock_irqrestore(&fq->lock, flags); |
Joerg Roedel | 9a005a8 | 2017-08-10 16:58:18 +0200 | [diff] [blame] | 568 | |
| 569 | if (atomic_cmpxchg(&iovad->fq_timer_on, 0, 1) == 0) |
| 570 | mod_timer(&iovad->fq_timer, |
| 571 | jiffies + msecs_to_jiffies(IOVA_FQ_TIMEOUT)); |
Joerg Roedel | 1928210 | 2017-08-10 15:49:44 +0200 | [diff] [blame] | 572 | } |
| 573 | EXPORT_SYMBOL_GPL(queue_iova); |
| 574 | |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 575 | /** |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 576 | * put_iova_domain - destroys the iova doamin |
| 577 | * @iovad: - iova domain in question. |
| 578 | * All the iova's in that domain are destroyed. |
| 579 | */ |
| 580 | void put_iova_domain(struct iova_domain *iovad) |
| 581 | { |
Robin Murphy | 7595dc5 | 2017-09-19 14:48:39 +0100 | [diff] [blame] | 582 | struct iova *iova, *tmp; |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 583 | |
Joerg Roedel | 42f87e7 | 2017-08-10 14:44:28 +0200 | [diff] [blame] | 584 | free_iova_flush_queue(iovad); |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 585 | free_iova_rcaches(iovad); |
Robin Murphy | 7595dc5 | 2017-09-19 14:48:39 +0100 | [diff] [blame] | 586 | rbtree_postorder_for_each_entry_safe(iova, tmp, &iovad->rbroot, node) |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 587 | free_iova_mem(iova); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 588 | } |
Sakari Ailus | 9b41760 | 2015-07-13 14:31:29 +0300 | [diff] [blame] | 589 | EXPORT_SYMBOL_GPL(put_iova_domain); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 590 | |
| 591 | static int |
| 592 | __is_range_overlap(struct rb_node *node, |
| 593 | unsigned long pfn_lo, unsigned long pfn_hi) |
| 594 | { |
Geliang Tang | eba484b | 2016-12-19 22:46:58 +0800 | [diff] [blame] | 595 | struct iova *iova = rb_entry(node, struct iova, node); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 596 | |
| 597 | if ((pfn_lo <= iova->pfn_hi) && (pfn_hi >= iova->pfn_lo)) |
| 598 | return 1; |
| 599 | return 0; |
| 600 | } |
| 601 | |
Jiang Liu | 75f0556 | 2014-02-19 14:07:37 +0800 | [diff] [blame] | 602 | static inline struct iova * |
| 603 | alloc_and_init_iova(unsigned long pfn_lo, unsigned long pfn_hi) |
| 604 | { |
| 605 | struct iova *iova; |
| 606 | |
| 607 | iova = alloc_iova_mem(); |
| 608 | if (iova) { |
| 609 | iova->pfn_lo = pfn_lo; |
| 610 | iova->pfn_hi = pfn_hi; |
| 611 | } |
| 612 | |
| 613 | return iova; |
| 614 | } |
| 615 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 616 | static struct iova * |
| 617 | __insert_new_range(struct iova_domain *iovad, |
| 618 | unsigned long pfn_lo, unsigned long pfn_hi) |
| 619 | { |
| 620 | struct iova *iova; |
| 621 | |
Jiang Liu | 75f0556 | 2014-02-19 14:07:37 +0800 | [diff] [blame] | 622 | iova = alloc_and_init_iova(pfn_lo, pfn_hi); |
| 623 | if (iova) |
Marek Szyprowski | d751751 | 2017-02-24 12:13:37 +0100 | [diff] [blame] | 624 | iova_insert_rbtree(&iovad->rbroot, iova, NULL); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 625 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 626 | return iova; |
| 627 | } |
| 628 | |
| 629 | static void |
| 630 | __adjust_overlap_range(struct iova *iova, |
| 631 | unsigned long *pfn_lo, unsigned long *pfn_hi) |
| 632 | { |
| 633 | if (*pfn_lo < iova->pfn_lo) |
| 634 | iova->pfn_lo = *pfn_lo; |
| 635 | if (*pfn_hi > iova->pfn_hi) |
| 636 | *pfn_lo = iova->pfn_hi + 1; |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * reserve_iova - reserves an iova in the given range |
| 641 | * @iovad: - iova domain pointer |
| 642 | * @pfn_lo: - lower page frame address |
| 643 | * @pfn_hi:- higher pfn adderss |
| 644 | * This function allocates reserves the address range from pfn_lo to pfn_hi so |
| 645 | * that this address is not dished out as part of alloc_iova. |
| 646 | */ |
| 647 | struct iova * |
| 648 | reserve_iova(struct iova_domain *iovad, |
| 649 | unsigned long pfn_lo, unsigned long pfn_hi) |
| 650 | { |
| 651 | struct rb_node *node; |
| 652 | unsigned long flags; |
| 653 | struct iova *iova; |
| 654 | unsigned int overlap = 0; |
| 655 | |
Robin Murphy | bb68b2f | 2017-09-21 16:52:46 +0100 | [diff] [blame] | 656 | /* Don't allow nonsensical pfns */ |
| 657 | if (WARN_ON((pfn_hi | pfn_lo) > (ULLONG_MAX >> iova_shift(iovad)))) |
| 658 | return NULL; |
| 659 | |
David Woodhouse | 3d39cec | 2009-07-08 15:23:30 +0100 | [diff] [blame] | 660 | spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 661 | for (node = rb_first(&iovad->rbroot); node; node = rb_next(node)) { |
| 662 | if (__is_range_overlap(node, pfn_lo, pfn_hi)) { |
Geliang Tang | eba484b | 2016-12-19 22:46:58 +0800 | [diff] [blame] | 663 | iova = rb_entry(node, struct iova, node); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 664 | __adjust_overlap_range(iova, &pfn_lo, &pfn_hi); |
| 665 | if ((pfn_lo >= iova->pfn_lo) && |
| 666 | (pfn_hi <= iova->pfn_hi)) |
| 667 | goto finish; |
| 668 | overlap = 1; |
| 669 | |
| 670 | } else if (overlap) |
| 671 | break; |
| 672 | } |
| 673 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 674 | /* We are here either because this is the first reserver node |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 675 | * or need to insert remaining non overlap addr range |
| 676 | */ |
| 677 | iova = __insert_new_range(iovad, pfn_lo, pfn_hi); |
| 678 | finish: |
| 679 | |
David Woodhouse | 3d39cec | 2009-07-08 15:23:30 +0100 | [diff] [blame] | 680 | spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 681 | return iova; |
| 682 | } |
Sakari Ailus | 9b41760 | 2015-07-13 14:31:29 +0300 | [diff] [blame] | 683 | EXPORT_SYMBOL_GPL(reserve_iova); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 684 | |
| 685 | /** |
| 686 | * copy_reserved_iova - copies the reserved between domains |
| 687 | * @from: - source doamin from where to copy |
| 688 | * @to: - destination domin where to copy |
| 689 | * This function copies reserved iova's from one doamin to |
| 690 | * other. |
| 691 | */ |
| 692 | void |
| 693 | copy_reserved_iova(struct iova_domain *from, struct iova_domain *to) |
| 694 | { |
| 695 | unsigned long flags; |
| 696 | struct rb_node *node; |
| 697 | |
David Woodhouse | 3d39cec | 2009-07-08 15:23:30 +0100 | [diff] [blame] | 698 | spin_lock_irqsave(&from->iova_rbtree_lock, flags); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 699 | for (node = rb_first(&from->rbroot); node; node = rb_next(node)) { |
Geliang Tang | eba484b | 2016-12-19 22:46:58 +0800 | [diff] [blame] | 700 | struct iova *iova = rb_entry(node, struct iova, node); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 701 | struct iova *new_iova; |
Robert Callicotte | 733cac2 | 2015-04-16 23:32:47 -0500 | [diff] [blame] | 702 | |
Robin Murphy | abbb8a0 | 2017-10-02 11:53:31 +0100 | [diff] [blame] | 703 | if (iova->pfn_lo == IOVA_ANCHOR) |
| 704 | continue; |
| 705 | |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 706 | new_iova = reserve_iova(to, iova->pfn_lo, iova->pfn_hi); |
| 707 | if (!new_iova) |
| 708 | printk(KERN_ERR "Reserve iova range %lx@%lx failed\n", |
| 709 | iova->pfn_lo, iova->pfn_lo); |
| 710 | } |
David Woodhouse | 3d39cec | 2009-07-08 15:23:30 +0100 | [diff] [blame] | 711 | spin_unlock_irqrestore(&from->iova_rbtree_lock, flags); |
Keshavamurthy, Anil S | f8de50e | 2007-10-21 16:41:48 -0700 | [diff] [blame] | 712 | } |
Sakari Ailus | 9b41760 | 2015-07-13 14:31:29 +0300 | [diff] [blame] | 713 | EXPORT_SYMBOL_GPL(copy_reserved_iova); |
Jiang Liu | 75f0556 | 2014-02-19 14:07:37 +0800 | [diff] [blame] | 714 | |
| 715 | struct iova * |
| 716 | split_and_remove_iova(struct iova_domain *iovad, struct iova *iova, |
| 717 | unsigned long pfn_lo, unsigned long pfn_hi) |
| 718 | { |
| 719 | unsigned long flags; |
| 720 | struct iova *prev = NULL, *next = NULL; |
| 721 | |
| 722 | spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); |
| 723 | if (iova->pfn_lo < pfn_lo) { |
| 724 | prev = alloc_and_init_iova(iova->pfn_lo, pfn_lo - 1); |
| 725 | if (prev == NULL) |
| 726 | goto error; |
| 727 | } |
| 728 | if (iova->pfn_hi > pfn_hi) { |
| 729 | next = alloc_and_init_iova(pfn_hi + 1, iova->pfn_hi); |
| 730 | if (next == NULL) |
| 731 | goto error; |
| 732 | } |
| 733 | |
| 734 | __cached_rbnode_delete_update(iovad, iova); |
| 735 | rb_erase(&iova->node, &iovad->rbroot); |
| 736 | |
| 737 | if (prev) { |
Marek Szyprowski | d751751 | 2017-02-24 12:13:37 +0100 | [diff] [blame] | 738 | iova_insert_rbtree(&iovad->rbroot, prev, NULL); |
Jiang Liu | 75f0556 | 2014-02-19 14:07:37 +0800 | [diff] [blame] | 739 | iova->pfn_lo = pfn_lo; |
| 740 | } |
| 741 | if (next) { |
Marek Szyprowski | d751751 | 2017-02-24 12:13:37 +0100 | [diff] [blame] | 742 | iova_insert_rbtree(&iovad->rbroot, next, NULL); |
Jiang Liu | 75f0556 | 2014-02-19 14:07:37 +0800 | [diff] [blame] | 743 | iova->pfn_hi = pfn_hi; |
| 744 | } |
| 745 | spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); |
| 746 | |
| 747 | return iova; |
| 748 | |
| 749 | error: |
| 750 | spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); |
| 751 | if (prev) |
| 752 | free_iova_mem(prev); |
| 753 | return NULL; |
| 754 | } |
Sakari Ailus | 15bbdec | 2015-07-13 14:31:30 +0300 | [diff] [blame] | 755 | |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 756 | /* |
| 757 | * Magazine caches for IOVA ranges. For an introduction to magazines, |
| 758 | * see the USENIX 2001 paper "Magazines and Vmem: Extending the Slab |
| 759 | * Allocator to Many CPUs and Arbitrary Resources" by Bonwick and Adams. |
| 760 | * For simplicity, we use a static magazine size and don't implement the |
| 761 | * dynamic size tuning described in the paper. |
| 762 | */ |
| 763 | |
| 764 | #define IOVA_MAG_SIZE 128 |
| 765 | |
| 766 | struct iova_magazine { |
| 767 | unsigned long size; |
| 768 | unsigned long pfns[IOVA_MAG_SIZE]; |
| 769 | }; |
| 770 | |
| 771 | struct iova_cpu_rcache { |
| 772 | spinlock_t lock; |
| 773 | struct iova_magazine *loaded; |
| 774 | struct iova_magazine *prev; |
| 775 | }; |
| 776 | |
| 777 | static struct iova_magazine *iova_magazine_alloc(gfp_t flags) |
| 778 | { |
| 779 | return kzalloc(sizeof(struct iova_magazine), flags); |
| 780 | } |
| 781 | |
| 782 | static void iova_magazine_free(struct iova_magazine *mag) |
| 783 | { |
| 784 | kfree(mag); |
| 785 | } |
| 786 | |
| 787 | static void |
| 788 | iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad) |
| 789 | { |
| 790 | unsigned long flags; |
| 791 | int i; |
| 792 | |
| 793 | if (!mag) |
| 794 | return; |
| 795 | |
| 796 | spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); |
| 797 | |
| 798 | for (i = 0 ; i < mag->size; ++i) { |
| 799 | struct iova *iova = private_find_iova(iovad, mag->pfns[i]); |
| 800 | |
| 801 | BUG_ON(!iova); |
| 802 | private_free_iova(iovad, iova); |
| 803 | } |
| 804 | |
| 805 | spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); |
| 806 | |
| 807 | mag->size = 0; |
| 808 | } |
| 809 | |
| 810 | static bool iova_magazine_full(struct iova_magazine *mag) |
| 811 | { |
| 812 | return (mag && mag->size == IOVA_MAG_SIZE); |
| 813 | } |
| 814 | |
| 815 | static bool iova_magazine_empty(struct iova_magazine *mag) |
| 816 | { |
| 817 | return (!mag || mag->size == 0); |
| 818 | } |
| 819 | |
| 820 | static unsigned long iova_magazine_pop(struct iova_magazine *mag, |
| 821 | unsigned long limit_pfn) |
| 822 | { |
Robin Murphy | e8b1984 | 2017-09-28 11:31:23 +0100 | [diff] [blame] | 823 | int i; |
| 824 | unsigned long pfn; |
| 825 | |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 826 | BUG_ON(iova_magazine_empty(mag)); |
| 827 | |
Robin Murphy | e8b1984 | 2017-09-28 11:31:23 +0100 | [diff] [blame] | 828 | /* Only fall back to the rbtree if we have no suitable pfns at all */ |
| 829 | for (i = mag->size - 1; mag->pfns[i] > limit_pfn; i--) |
| 830 | if (i == 0) |
| 831 | return 0; |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 832 | |
Robin Murphy | e8b1984 | 2017-09-28 11:31:23 +0100 | [diff] [blame] | 833 | /* Swap it to pop it */ |
| 834 | pfn = mag->pfns[i]; |
| 835 | mag->pfns[i] = mag->pfns[--mag->size]; |
| 836 | |
| 837 | return pfn; |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | static void iova_magazine_push(struct iova_magazine *mag, unsigned long pfn) |
| 841 | { |
| 842 | BUG_ON(iova_magazine_full(mag)); |
| 843 | |
| 844 | mag->pfns[mag->size++] = pfn; |
| 845 | } |
| 846 | |
| 847 | static void init_iova_rcaches(struct iova_domain *iovad) |
| 848 | { |
| 849 | struct iova_cpu_rcache *cpu_rcache; |
| 850 | struct iova_rcache *rcache; |
| 851 | unsigned int cpu; |
| 852 | int i; |
| 853 | |
| 854 | for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { |
| 855 | rcache = &iovad->rcaches[i]; |
| 856 | spin_lock_init(&rcache->lock); |
| 857 | rcache->depot_size = 0; |
| 858 | rcache->cpu_rcaches = __alloc_percpu(sizeof(*cpu_rcache), cache_line_size()); |
| 859 | if (WARN_ON(!rcache->cpu_rcaches)) |
| 860 | continue; |
| 861 | for_each_possible_cpu(cpu) { |
| 862 | cpu_rcache = per_cpu_ptr(rcache->cpu_rcaches, cpu); |
| 863 | spin_lock_init(&cpu_rcache->lock); |
| 864 | cpu_rcache->loaded = iova_magazine_alloc(GFP_KERNEL); |
| 865 | cpu_rcache->prev = iova_magazine_alloc(GFP_KERNEL); |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /* |
| 871 | * Try inserting IOVA range starting with 'iova_pfn' into 'rcache', and |
| 872 | * return true on success. Can fail if rcache is full and we can't free |
| 873 | * space, and free_iova() (our only caller) will then return the IOVA |
| 874 | * range to the rbtree instead. |
| 875 | */ |
| 876 | static bool __iova_rcache_insert(struct iova_domain *iovad, |
| 877 | struct iova_rcache *rcache, |
| 878 | unsigned long iova_pfn) |
| 879 | { |
| 880 | struct iova_magazine *mag_to_free = NULL; |
| 881 | struct iova_cpu_rcache *cpu_rcache; |
| 882 | bool can_insert = false; |
| 883 | unsigned long flags; |
| 884 | |
Sebastian Andrzej Siewior | aaffaa8 | 2017-06-27 18:16:47 +0200 | [diff] [blame] | 885 | cpu_rcache = raw_cpu_ptr(rcache->cpu_rcaches); |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 886 | spin_lock_irqsave(&cpu_rcache->lock, flags); |
| 887 | |
| 888 | if (!iova_magazine_full(cpu_rcache->loaded)) { |
| 889 | can_insert = true; |
| 890 | } else if (!iova_magazine_full(cpu_rcache->prev)) { |
| 891 | swap(cpu_rcache->prev, cpu_rcache->loaded); |
| 892 | can_insert = true; |
| 893 | } else { |
| 894 | struct iova_magazine *new_mag = iova_magazine_alloc(GFP_ATOMIC); |
| 895 | |
| 896 | if (new_mag) { |
| 897 | spin_lock(&rcache->lock); |
| 898 | if (rcache->depot_size < MAX_GLOBAL_MAGS) { |
| 899 | rcache->depot[rcache->depot_size++] = |
| 900 | cpu_rcache->loaded; |
| 901 | } else { |
| 902 | mag_to_free = cpu_rcache->loaded; |
| 903 | } |
| 904 | spin_unlock(&rcache->lock); |
| 905 | |
| 906 | cpu_rcache->loaded = new_mag; |
| 907 | can_insert = true; |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | if (can_insert) |
| 912 | iova_magazine_push(cpu_rcache->loaded, iova_pfn); |
| 913 | |
| 914 | spin_unlock_irqrestore(&cpu_rcache->lock, flags); |
| 915 | |
| 916 | if (mag_to_free) { |
| 917 | iova_magazine_free_pfns(mag_to_free, iovad); |
| 918 | iova_magazine_free(mag_to_free); |
| 919 | } |
| 920 | |
| 921 | return can_insert; |
| 922 | } |
| 923 | |
| 924 | static bool iova_rcache_insert(struct iova_domain *iovad, unsigned long pfn, |
| 925 | unsigned long size) |
| 926 | { |
| 927 | unsigned int log_size = order_base_2(size); |
| 928 | |
| 929 | if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE) |
| 930 | return false; |
| 931 | |
| 932 | return __iova_rcache_insert(iovad, &iovad->rcaches[log_size], pfn); |
| 933 | } |
| 934 | |
| 935 | /* |
| 936 | * Caller wants to allocate a new IOVA range from 'rcache'. If we can |
| 937 | * satisfy the request, return a matching non-NULL range and remove |
| 938 | * it from the 'rcache'. |
| 939 | */ |
| 940 | static unsigned long __iova_rcache_get(struct iova_rcache *rcache, |
| 941 | unsigned long limit_pfn) |
| 942 | { |
| 943 | struct iova_cpu_rcache *cpu_rcache; |
| 944 | unsigned long iova_pfn = 0; |
| 945 | bool has_pfn = false; |
| 946 | unsigned long flags; |
| 947 | |
Sebastian Andrzej Siewior | aaffaa8 | 2017-06-27 18:16:47 +0200 | [diff] [blame] | 948 | cpu_rcache = raw_cpu_ptr(rcache->cpu_rcaches); |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 949 | spin_lock_irqsave(&cpu_rcache->lock, flags); |
| 950 | |
| 951 | if (!iova_magazine_empty(cpu_rcache->loaded)) { |
| 952 | has_pfn = true; |
| 953 | } else if (!iova_magazine_empty(cpu_rcache->prev)) { |
| 954 | swap(cpu_rcache->prev, cpu_rcache->loaded); |
| 955 | has_pfn = true; |
| 956 | } else { |
| 957 | spin_lock(&rcache->lock); |
| 958 | if (rcache->depot_size > 0) { |
| 959 | iova_magazine_free(cpu_rcache->loaded); |
| 960 | cpu_rcache->loaded = rcache->depot[--rcache->depot_size]; |
| 961 | has_pfn = true; |
| 962 | } |
| 963 | spin_unlock(&rcache->lock); |
| 964 | } |
| 965 | |
| 966 | if (has_pfn) |
| 967 | iova_pfn = iova_magazine_pop(cpu_rcache->loaded, limit_pfn); |
| 968 | |
| 969 | spin_unlock_irqrestore(&cpu_rcache->lock, flags); |
| 970 | |
| 971 | return iova_pfn; |
| 972 | } |
| 973 | |
| 974 | /* |
| 975 | * Try to satisfy IOVA allocation range from rcache. Fail if requested |
| 976 | * size is too big or the DMA limit we are given isn't satisfied by the |
| 977 | * top element in the magazine. |
| 978 | */ |
| 979 | static unsigned long iova_rcache_get(struct iova_domain *iovad, |
| 980 | unsigned long size, |
| 981 | unsigned long limit_pfn) |
| 982 | { |
| 983 | unsigned int log_size = order_base_2(size); |
| 984 | |
| 985 | if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE) |
| 986 | return 0; |
| 987 | |
Robin Murphy | b826ee9 | 2017-09-19 14:48:40 +0100 | [diff] [blame] | 988 | return __iova_rcache_get(&iovad->rcaches[log_size], limit_pfn - size); |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | /* |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 992 | * free rcache data structures. |
| 993 | */ |
| 994 | static void free_iova_rcaches(struct iova_domain *iovad) |
| 995 | { |
| 996 | struct iova_rcache *rcache; |
Robin Murphy | 7595dc5 | 2017-09-19 14:48:39 +0100 | [diff] [blame] | 997 | struct iova_cpu_rcache *cpu_rcache; |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 998 | unsigned int cpu; |
| 999 | int i, j; |
| 1000 | |
| 1001 | for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { |
| 1002 | rcache = &iovad->rcaches[i]; |
Robin Murphy | 7595dc5 | 2017-09-19 14:48:39 +0100 | [diff] [blame] | 1003 | for_each_possible_cpu(cpu) { |
| 1004 | cpu_rcache = per_cpu_ptr(rcache->cpu_rcaches, cpu); |
| 1005 | iova_magazine_free(cpu_rcache->loaded); |
| 1006 | iova_magazine_free(cpu_rcache->prev); |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 1007 | } |
Robin Murphy | 7595dc5 | 2017-09-19 14:48:39 +0100 | [diff] [blame] | 1008 | free_percpu(rcache->cpu_rcaches); |
| 1009 | for (j = 0; j < rcache->depot_size; ++j) |
| 1010 | iova_magazine_free(rcache->depot[j]); |
Omer Peleg | 9257b4a | 2016-04-20 11:34:11 +0300 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | * free all the IOVA ranges cached by a cpu (used when cpu is unplugged) |
| 1016 | */ |
| 1017 | void free_cpu_cached_iovas(unsigned int cpu, struct iova_domain *iovad) |
| 1018 | { |
| 1019 | struct iova_cpu_rcache *cpu_rcache; |
| 1020 | struct iova_rcache *rcache; |
| 1021 | unsigned long flags; |
| 1022 | int i; |
| 1023 | |
| 1024 | for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { |
| 1025 | rcache = &iovad->rcaches[i]; |
| 1026 | cpu_rcache = per_cpu_ptr(rcache->cpu_rcaches, cpu); |
| 1027 | spin_lock_irqsave(&cpu_rcache->lock, flags); |
| 1028 | iova_magazine_free_pfns(cpu_rcache->loaded, iovad); |
| 1029 | iova_magazine_free_pfns(cpu_rcache->prev, iovad); |
| 1030 | spin_unlock_irqrestore(&cpu_rcache->lock, flags); |
| 1031 | } |
| 1032 | } |
| 1033 | |
Sakari Ailus | 15bbdec | 2015-07-13 14:31:30 +0300 | [diff] [blame] | 1034 | MODULE_AUTHOR("Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>"); |
| 1035 | MODULE_LICENSE("GPL"); |