Lines Matching refs:iova
8 #include <linux/iova.h>
46 static struct iova *to_iova(struct rb_node *node)
48 return rb_entry(node, struct iova, node);
86 __cached_rbnode_insert_update(struct iova_domain *iovad, struct iova *new)
95 __cached_rbnode_delete_update(struct iova_domain *iovad, struct iova *free)
97 struct iova *cached_iova;
150 /* Insert the iova into domain rbtree by holding writer lock */
152 iova_insert_rbtree(struct rb_root *root, struct iova *iova,
160 struct iova *this = to_iova(*new);
164 if (iova->pfn_lo < this->pfn_lo)
166 else if (iova->pfn_lo > this->pfn_lo)
174 rb_link_node(&iova->node, parent, new);
175 rb_insert_color(&iova->node, root);
180 struct iova *new, bool size_aligned)
183 struct iova *curr_iova;
243 static struct iova *alloc_iova_mem(void)
248 static void free_iova_mem(struct iova *iova)
250 if (iova->pfn_lo != IOVA_ANCHOR)
251 kmem_cache_free(iova_cache, iova);
260 ret = cpuhp_setup_state_multi(CPUHP_IOMMU_IOVA_DEAD, "iommu/iova:dead", NULL,
269 "iommu_iova", sizeof(struct iova), 0,
274 pr_err("Couldn't create iova cache\n");
303 * alloc_iova - allocates an iova
304 * @iovad: - iova domain in question
308 * This function allocates an iova in the range iovad->start_pfn to limit_pfn,
310 * flag is set then the allocated address iova->pfn_lo will be naturally
313 struct iova *
318 struct iova *new_iova;
337 static struct iova *
345 struct iova *iova = to_iova(node);
347 if (pfn < iova->pfn_lo)
349 else if (pfn > iova->pfn_hi)
352 return iova; /* pfn falls within iova's range */
358 static void remove_iova(struct iova_domain *iovad, struct iova *iova)
361 __cached_rbnode_delete_update(iovad, iova);
362 rb_erase(&iova->node, &iovad->rbroot);
366 * find_iova - finds an iova for a given pfn
367 * @iovad: - iova domain in question.
369 * This function finds and returns an iova belonging to the
372 struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn)
375 struct iova *iova;
379 iova = private_find_iova(iovad, pfn);
381 return iova;
386 * __free_iova - frees the given iova
387 * @iovad: iova domain in question.
388 * @iova: iova in question.
389 * Frees the given iova belonging to the giving domain
392 __free_iova(struct iova_domain *iovad, struct iova *iova)
397 remove_iova(iovad, iova);
399 free_iova_mem(iova);
404 * free_iova - finds and frees the iova for a given pfn
405 * @iovad: - iova domain in question.
407 * This functions finds an iova for a given pfn and then
408 * frees the iova from that domain.
414 struct iova *iova;
417 iova = private_find_iova(iovad, pfn);
418 if (!iova) {
422 remove_iova(iovad, iova);
424 free_iova_mem(iova);
429 * alloc_iova_fast - allocates an iova from rcache
430 * @iovad: - iova domain in question
434 * This function tries to satisfy an iova allocation from the rcache,
443 struct iova *new_iova;
479 * free_iova_fast - free iova pfn range into rcache
480 * @iovad: - iova domain in question.
483 * This functions frees an iova range by trying to put it into the rcache,
484 * falling back to regular iova deallocation via free_iova() if this fails.
504 * put_iova_domain - destroys the iova domain
505 * @iovad: - iova domain in question.
506 * All the iova's in that domain are destroyed.
510 struct iova *iova, *tmp;
515 rbtree_postorder_for_each_entry_safe(iova, tmp, &iovad->rbroot, node)
516 free_iova_mem(iova);
524 struct iova *iova = to_iova(node);
526 if ((pfn_lo <= iova->pfn_hi) && (pfn_hi >= iova->pfn_lo))
531 static inline struct iova *
534 struct iova *iova;
536 iova = alloc_iova_mem();
537 if (iova) {
538 iova->pfn_lo = pfn_lo;
539 iova->pfn_hi = pfn_hi;
542 return iova;
545 static struct iova *
549 struct iova *iova;
551 iova = alloc_and_init_iova(pfn_lo, pfn_hi);
552 if (iova)
553 iova_insert_rbtree(&iovad->rbroot, iova, NULL);
555 return iova;
559 __adjust_overlap_range(struct iova *iova,
562 if (*pfn_lo < iova->pfn_lo)
563 iova->pfn_lo = *pfn_lo;
564 if (*pfn_hi > iova->pfn_hi)
565 *pfn_lo = iova->pfn_hi + 1;
569 * reserve_iova - reserves an iova in the given range
570 * @iovad: - iova domain pointer
576 struct iova *
582 struct iova *iova;
592 iova = to_iova(node);
593 __adjust_overlap_range(iova, &pfn_lo, &pfn_hi);
594 if ((pfn_lo >= iova->pfn_lo) &&
595 (pfn_hi <= iova->pfn_hi))
606 iova = __insert_new_range(iovad, pfn_lo, pfn_hi);
610 return iova;
673 struct iova *iova = private_find_iova(iovad, mag->pfns[i]);
675 if (WARN_ON(!iova))
678 remove_iova(iovad, iova);
679 free_iova_mem(iova);