Lines Matching full:area

25 	struct iopt_area *area;  member
40 iter->area = iopt_area_iter_first(iopt, iova, iova); in iopt_area_contig_init()
41 if (!iter->area) in iopt_area_contig_init()
43 if (!iter->area->pages) { in iopt_area_contig_init()
44 iter->area = NULL; in iopt_area_contig_init()
47 return iter->area; in iopt_area_contig_init()
54 if (!iter->area) in iopt_area_contig_next()
56 last_iova = iopt_area_last_iova(iter->area); in iopt_area_contig_next()
61 iter->area = iopt_area_iter_next(iter->area, iter->cur_iova, in iopt_area_contig_next()
63 if (!iter->area) in iopt_area_contig_next()
65 if (iter->cur_iova != iopt_area_iova(iter->area) || in iopt_area_contig_next()
66 !iter->area->pages) { in iopt_area_contig_next()
67 iter->area = NULL; in iopt_area_contig_next()
70 return iter->area; in iopt_area_contig_next()
196 * The area takes a slice of the pages from start_bytes to start_byte + length
198 static int iopt_insert_area(struct io_pagetable *iopt, struct iopt_area *area, in iopt_insert_area() argument
208 area->iommu_prot = iommu_prot; in iopt_insert_area()
209 area->page_offset = start_byte % PAGE_SIZE; in iopt_insert_area()
210 if (area->page_offset & (iopt->iova_alignment - 1)) in iopt_insert_area()
213 area->node.start = iova; in iopt_insert_area()
214 if (check_add_overflow(iova, length - 1, &area->node.last)) in iopt_insert_area()
217 area->pages_node.start = start_byte / PAGE_SIZE; in iopt_insert_area()
218 if (check_add_overflow(start_byte, length - 1, &area->pages_node.last)) in iopt_insert_area()
220 area->pages_node.last = area->pages_node.last / PAGE_SIZE; in iopt_insert_area()
221 if (WARN_ON(area->pages_node.last >= pages->npages)) in iopt_insert_area()
225 * The area is inserted with a NULL pages indicating it is not fully in iopt_insert_area()
228 area->iopt = iopt; in iopt_insert_area()
229 interval_tree_insert(&area->node, &iopt->area_itree); in iopt_insert_area()
235 struct iopt_area *area; in iopt_area_alloc() local
237 area = kzalloc(sizeof(*area), GFP_KERNEL_ACCOUNT); in iopt_area_alloc()
238 if (!area) in iopt_area_alloc()
240 RB_CLEAR_NODE(&area->node.rb); in iopt_area_alloc()
241 RB_CLEAR_NODE(&area->pages_node.rb); in iopt_area_alloc()
242 return area; in iopt_area_alloc()
255 elm->area = iopt_area_alloc(); in iopt_alloc_area_pages()
256 if (!elm->area) in iopt_alloc_area_pages()
292 rc = iopt_insert_area(iopt, elm->area, elm->pages, iova, in iopt_alloc_area_pages()
304 static void iopt_abort_area(struct iopt_area *area) in iopt_abort_area() argument
307 WARN_ON(area->pages); in iopt_abort_area()
308 if (area->iopt) { in iopt_abort_area()
309 down_write(&area->iopt->iova_rwsem); in iopt_abort_area()
310 interval_tree_remove(&area->node, &area->iopt->area_itree); in iopt_abort_area()
311 up_write(&area->iopt->iova_rwsem); in iopt_abort_area()
313 kfree(area); in iopt_abort_area()
322 if (elm->area) in iopt_free_pages_list()
323 iopt_abort_area(elm->area); in iopt_free_pages_list()
338 rc = iopt_area_fill_domains(elm->area, elm->pages); in iopt_fill_domains_pages()
348 iopt_area_unfill_domains(undo_elm->area, undo_elm->pages); in iopt_fill_domains_pages()
373 * area->pages must be set inside the domains_rwsem to ensure in iopt_map_pages()
377 elm->area->pages = elm->pages; in iopt_map_pages()
379 elm->area = NULL; in iopt_map_pages()
427 if (elm.area) in iopt_map_user_pages()
428 iopt_abort_area(elm.area); in iopt_map_user_pages()
447 struct iopt_area *area; in __iommu_read_and_clear_dirty() local
457 iopt_for_each_contig_area(&iter, area, arg->iopt, iova, last_iova) { in __iommu_read_and_clear_dirty()
458 unsigned long last = min(last_iova, iopt_area_last_iova(area)); in __iommu_read_and_clear_dirty()
559 struct iopt_area *area; in iopt_clear_dirty_data() local
566 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area; in iopt_clear_dirty_data()
567 area = iopt_area_iter_next(area, 0, ULONG_MAX)) { in iopt_clear_dirty_data()
568 if (!area->pages) in iopt_clear_dirty_data()
571 ret = ops->read_and_clear_dirty(domain, iopt_area_iova(area), in iopt_clear_dirty_data()
572 iopt_area_length(area), 0, in iopt_clear_dirty_data()
612 struct iopt_area *area; in iopt_get_pages() local
621 iopt_for_each_contig_area(&iter, area, iopt, iova, last_iova) { in iopt_get_pages()
623 unsigned long last = min(last_iova, iopt_area_last_iova(area)); in iopt_get_pages()
630 elm->start_byte = iopt_area_start_byte(area, iter.cur_iova); in iopt_get_pages()
631 elm->pages = area->pages; in iopt_get_pages()
651 struct iopt_area *area; in iopt_unmap_iova_range() local
657 * The domains_rwsem must be held in read mode any time any area->pages in iopt_unmap_iova_range()
659 * concurrently with cleaning up the area. in iopt_unmap_iova_range()
664 while ((area = iopt_area_iter_first(iopt, start, last))) { in iopt_unmap_iova_range()
665 unsigned long area_last = iopt_area_last_iova(area); in iopt_unmap_iova_range()
666 unsigned long area_first = iopt_area_iova(area); in iopt_unmap_iova_range()
669 /* Userspace should not race map/unmap's of the same area */ in iopt_unmap_iova_range()
670 if (!area->pages) { in iopt_unmap_iova_range()
688 if (area->num_accesses) { in iopt_unmap_iova_range()
689 size_t length = iopt_area_length(area); in iopt_unmap_iova_range()
692 area->prevent_access = true; in iopt_unmap_iova_range()
704 pages = area->pages; in iopt_unmap_iova_range()
705 area->pages = NULL; in iopt_unmap_iova_range()
708 iopt_area_unfill_domains(area, pages); in iopt_unmap_iova_range()
709 iopt_abort_area(area); in iopt_unmap_iova_range()
872 * This is used when removing a domain from the iopt. Every area in the iopt
879 struct iopt_area *area; in iopt_unfill_domain() local
893 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area; in iopt_unfill_domain()
894 area = iopt_area_iter_next(area, 0, ULONG_MAX)) { in iopt_unfill_domain()
895 struct iopt_pages *pages = area->pages; in iopt_unfill_domain()
902 WARN_ON(!area->storage_domain); in iopt_unfill_domain()
903 if (area->storage_domain == domain) in iopt_unfill_domain()
904 area->storage_domain = storage_domain; in iopt_unfill_domain()
907 iopt_area_unmap_domain(area, domain); in iopt_unfill_domain()
912 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area; in iopt_unfill_domain()
913 area = iopt_area_iter_next(area, 0, ULONG_MAX)) { in iopt_unfill_domain()
914 struct iopt_pages *pages = area->pages; in iopt_unfill_domain()
920 interval_tree_remove(&area->pages_node, &pages->domains_itree); in iopt_unfill_domain()
921 WARN_ON(area->storage_domain != domain); in iopt_unfill_domain()
922 area->storage_domain = NULL; in iopt_unfill_domain()
923 iopt_area_unfill_domain(area, pages, domain); in iopt_unfill_domain()
933 * Fill the domain with PFNs from every area in the iopt. On failure the domain
940 struct iopt_area *area; in iopt_fill_domain() local
946 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area; in iopt_fill_domain()
947 area = iopt_area_iter_next(area, 0, ULONG_MAX)) { in iopt_fill_domain()
948 struct iopt_pages *pages = area->pages; in iopt_fill_domain()
954 rc = iopt_area_fill_domain(area, domain); in iopt_fill_domain()
959 if (!area->storage_domain) { in iopt_fill_domain()
961 area->storage_domain = domain; in iopt_fill_domain()
962 interval_tree_insert(&area->pages_node, in iopt_fill_domain()
970 end_area = area; in iopt_fill_domain()
971 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area; in iopt_fill_domain()
972 area = iopt_area_iter_next(area, 0, ULONG_MAX)) { in iopt_fill_domain()
973 struct iopt_pages *pages = area->pages; in iopt_fill_domain()
975 if (area == end_area) in iopt_fill_domain()
981 interval_tree_remove(&area->pages_node, in iopt_fill_domain()
983 area->storage_domain = NULL; in iopt_fill_domain()
985 iopt_area_unfill_domain(area, pages, domain); in iopt_fill_domain()
991 /* All existing area's conform to an increased page size */
996 struct iopt_area *area; in iopt_check_iova_alignment() local
1001 for (area = iopt_area_iter_first(iopt, 0, ULONG_MAX); area; in iopt_check_iova_alignment()
1002 area = iopt_area_iter_next(area, 0, ULONG_MAX)) in iopt_check_iova_alignment()
1003 if ((iopt_area_iova(area) & align_mask) || in iopt_check_iova_alignment()
1004 (iopt_area_length(area) & align_mask) || in iopt_check_iova_alignment()
1005 (area->page_offset & align_mask)) in iopt_check_iova_alignment()
1060 /* No area exists that is outside the allowed domain aperture */ in iopt_table_add_domain()
1168 * iopt_area_split - Split an area into two parts at iova
1169 * @area: The area to split
1170 * @iova: Becomes the last of a new area
1172 * This splits an area into two. It is part of the VFIO compatibility to allow
1176 static int iopt_area_split(struct iopt_area *area, unsigned long iova) in iopt_area_split() argument
1178 unsigned long alignment = area->iopt->iova_alignment; in iopt_area_split()
1179 unsigned long last_iova = iopt_area_last_iova(area); in iopt_area_split()
1180 unsigned long start_iova = iopt_area_iova(area); in iopt_area_split()
1182 struct io_pagetable *iopt = area->iopt; in iopt_area_split()
1183 struct iopt_pages *pages = area->pages; in iopt_area_split()
1193 if (!pages || area->prevent_access) in iopt_area_split()
1197 iopt_area_start_byte(area, new_start) & (alignment - 1)) in iopt_area_split()
1215 if (area->num_accesses) { in iopt_area_split()
1224 if (area->storage_domain && !iopt->disable_large_pages) { in iopt_area_split()
1229 interval_tree_remove(&area->node, &iopt->area_itree); in iopt_area_split()
1230 rc = iopt_insert_area(iopt, lhs, area->pages, start_iova, in iopt_area_split()
1231 iopt_area_start_byte(area, start_iova), in iopt_area_split()
1233 area->iommu_prot); in iopt_area_split()
1237 rc = iopt_insert_area(iopt, rhs, area->pages, new_start, in iopt_area_split()
1238 iopt_area_start_byte(area, new_start), in iopt_area_split()
1239 last_iova - new_start + 1, area->iommu_prot); in iopt_area_split()
1244 * If the original area has filled a domain, domains_itree has to be in iopt_area_split()
1247 if (area->storage_domain) { in iopt_area_split()
1248 interval_tree_remove(&area->pages_node, &pages->domains_itree); in iopt_area_split()
1253 lhs->storage_domain = area->storage_domain; in iopt_area_split()
1254 lhs->pages = area->pages; in iopt_area_split()
1255 rhs->storage_domain = area->storage_domain; in iopt_area_split()
1256 rhs->pages = area->pages; in iopt_area_split()
1258 kfree(area); in iopt_area_split()
1270 interval_tree_insert(&area->node, &iopt->area_itree); in iopt_area_split()
1287 struct iopt_area *area; in iopt_cut_iova() local
1289 area = iopt_area_iter_first(iopt, iovas[i], iovas[i]); in iopt_cut_iova()
1290 if (!area) in iopt_cut_iova()
1292 rc = iopt_area_split(area, iovas[i]); in iopt_cut_iova()