Lines Matching refs:iova

8 #include <linux/iova.h>
125 __cached_rbnode_insert_update(struct iova_domain *iovad, struct iova *new)
134 __cached_rbnode_delete_update(struct iova_domain *iovad, struct iova *free)
136 struct iova *cached_iova;
138 cached_iova = rb_entry(iovad->cached32_node, struct iova, node);
147 cached_iova = rb_entry(iovad->cached_node, struct iova, node);
152 /* Insert the iova into domain rbtree by holding writer lock */
154 iova_insert_rbtree(struct rb_root *root, struct iova *iova,
162 struct iova *this = rb_entry(*new, struct iova, node);
166 if (iova->pfn_lo < this->pfn_lo)
168 else if (iova->pfn_lo > this->pfn_lo)
176 rb_link_node(&iova->node, parent, new);
177 rb_insert_color(&iova->node, root);
182 struct iova *new, bool size_aligned)
185 struct iova *curr_iova;
200 curr_iova = rb_entry(curr, struct iova, node);
206 curr_iova = rb_entry(curr, struct iova, node);
234 struct iova *alloc_iova_mem(void)
240 void free_iova_mem(struct iova *iova)
242 if (iova->pfn_lo != IOVA_ANCHOR)
243 kmem_cache_free(iova_cache, iova);
252 "iommu_iova", sizeof(struct iova), 0,
256 pr_err("Couldn't create iova cache\n");
283 * alloc_iova - allocates an iova
284 * @iovad: - iova domain in question
288 * This function allocates an iova in the range iovad->start_pfn to limit_pfn,
290 * flag is set then the allocated address iova->pfn_lo will be naturally
293 struct iova *
298 struct iova *new_iova;
317 static struct iova *
325 struct iova *iova = rb_entry(node, struct iova, node);
327 if (pfn < iova->pfn_lo)
329 else if (pfn > iova->pfn_hi)
332 return iova; /* pfn falls within iova's range */
338 static void private_free_iova(struct iova_domain *iovad, struct iova *iova)
341 __cached_rbnode_delete_update(iovad, iova);
342 rb_erase(&iova->node, &iovad->rbroot);
343 free_iova_mem(iova);
347 * find_iova - finds an iova for a given pfn
348 * @iovad: - iova domain in question.
350 * This function finds and returns an iova belonging to the
353 struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn)
356 struct iova *iova;
360 iova = private_find_iova(iovad, pfn);
362 return iova;
367 * __free_iova - frees the given iova
368 * @iovad: iova domain in question.
369 * @iova: iova in question.
370 * Frees the given iova belonging to the giving domain
373 __free_iova(struct iova_domain *iovad, struct iova *iova)
378 private_free_iova(iovad, iova);
384 * free_iova - finds and frees the iova for a given pfn
385 * @iovad: - iova domain in question.
387 * This functions finds an iova for a given pfn and then
388 * frees the iova from that domain.
393 struct iova *iova = find_iova(iovad, pfn);
395 if (iova)
396 __free_iova(iovad, iova);
402 * alloc_iova_fast - allocates an iova from rcache
403 * @iovad: - iova domain in question
407 * This function tries to satisfy an iova allocation from the rcache,
416 struct iova *new_iova;
442 * free_iova_fast - free iova pfn range into rcache
443 * @iovad: - iova domain in question.
446 * This functions frees an iova range by trying to put it into the rcache,
447 * falling back to regular iova deallocation via free_iova() if this fails.
589 * put_iova_domain - destroys the iova doamin
590 * @iovad: - iova domain in question.
591 * All the iova's in that domain are destroyed.
595 struct iova *iova, *tmp;
599 rbtree_postorder_for_each_entry_safe(iova, tmp, &iovad->rbroot, node)
600 free_iova_mem(iova);
608 struct iova *iova = rb_entry(node, struct iova, node);
610 if ((pfn_lo <= iova->pfn_hi) && (pfn_hi >= iova->pfn_lo))
615 static inline struct iova *
618 struct iova *iova;
620 iova = alloc_iova_mem();
621 if (iova) {
622 iova->pfn_lo = pfn_lo;
623 iova->pfn_hi = pfn_hi;
626 return iova;
629 static struct iova *
633 struct iova *iova;
635 iova = alloc_and_init_iova(pfn_lo, pfn_hi);
636 if (iova)
637 iova_insert_rbtree(&iovad->rbroot, iova, NULL);
639 return iova;
643 __adjust_overlap_range(struct iova *iova,
646 if (*pfn_lo < iova->pfn_lo)
647 iova->pfn_lo = *pfn_lo;
648 if (*pfn_hi > iova->pfn_hi)
649 *pfn_lo = iova->pfn_hi + 1;
653 * reserve_iova - reserves an iova in the given range
654 * @iovad: - iova domain pointer
660 struct iova *
666 struct iova *iova;
676 iova = rb_entry(node, struct iova, node);
677 __adjust_overlap_range(iova, &pfn_lo, &pfn_hi);
678 if ((pfn_lo >= iova->pfn_lo) &&
679 (pfn_hi <= iova->pfn_hi))
690 iova = __insert_new_range(iovad, pfn_lo, pfn_hi);
694 return iova;
702 * This function copies reserved iova's from one doamin to
713 struct iova *iova = rb_entry(node, struct iova, node);
714 struct iova *new_iova;
716 if (iova->pfn_lo == IOVA_ANCHOR)
719 new_iova = reserve_iova(to, iova->pfn_lo, iova->pfn_hi);
721 pr_err("Reserve iova range %lx@%lx failed\n",
722 iova->pfn_lo, iova->pfn_lo);
728 struct iova *
729 split_and_remove_iova(struct iova_domain *iovad, struct iova *iova,
733 struct iova *prev = NULL, *next = NULL;
736 if (iova->pfn_lo < pfn_lo) {
737 prev = alloc_and_init_iova(iova->pfn_lo, pfn_lo - 1);
741 if (iova->pfn_hi > pfn_hi) {
742 next = alloc_and_init_iova(pfn_hi + 1, iova->pfn_hi);
747 __cached_rbnode_delete_update(iovad, iova);
748 rb_erase(&iova->node, &iovad->rbroot);
752 iova->pfn_lo = pfn_lo;
756 iova->pfn_hi = pfn_hi;
760 return iova;
812 struct iova *iova = private_find_iova(iovad, mag->pfns[i]);
814 if (WARN_ON(!iova))
817 private_free_iova(iovad, iova);