Lines Matching refs:window

149 	struct scif_window *window;  in scif_create_window()  local
152 window = scif_zalloc(sizeof(*window)); in scif_create_window()
153 if (!window) in scif_create_window()
156 window->dma_addr = scif_zalloc(nr_pages * sizeof(*window->dma_addr)); in scif_create_window()
157 if (!window->dma_addr) in scif_create_window()
160 window->num_pages = scif_zalloc(nr_pages * sizeof(*window->num_pages)); in scif_create_window()
161 if (!window->num_pages) in scif_create_window()
164 window->offset = offset; in scif_create_window()
165 window->ep = (u64)ep; in scif_create_window()
166 window->magic = SCIFEP_MAGIC; in scif_create_window()
167 window->reg_state = OP_IDLE; in scif_create_window()
168 init_waitqueue_head(&window->regwq); in scif_create_window()
169 window->unreg_state = OP_IDLE; in scif_create_window()
170 init_waitqueue_head(&window->unregwq); in scif_create_window()
171 INIT_LIST_HEAD(&window->list); in scif_create_window()
172 window->type = SCIF_WINDOW_SELF; in scif_create_window()
173 window->temp = temp; in scif_create_window()
174 return window; in scif_create_window()
177 scif_free(window->dma_addr, in scif_create_window()
178 nr_pages * sizeof(*window->dma_addr)); in scif_create_window()
179 scif_free(window, sizeof(*window)); in scif_create_window()
192 struct scif_window *window) in scif_destroy_incomplete_window() argument
195 int nr_pages = window->nr_pages; in scif_destroy_incomplete_window()
196 struct scif_allocmsg *alloc = &window->alloc_handle; in scif_destroy_incomplete_window()
212 msg.payload[1] = window->alloc_handle.vaddr; in scif_destroy_incomplete_window()
213 msg.payload[2] = (u64)window; in scif_destroy_incomplete_window()
219 scif_free_window_offset(ep, window, window->offset); in scif_destroy_incomplete_window()
220 scif_free(window->dma_addr, nr_pages * sizeof(*window->dma_addr)); in scif_destroy_incomplete_window()
221 scif_free(window->num_pages, nr_pages * sizeof(*window->num_pages)); in scif_destroy_incomplete_window()
222 scif_free(window, sizeof(*window)); in scif_destroy_incomplete_window()
232 void scif_unmap_window(struct scif_dev *remote_dev, struct scif_window *window) in scif_unmap_window() argument
237 if (window->st) { in scif_unmap_window()
239 window->st->sgl, window->st->nents, in scif_unmap_window()
241 sg_free_table(window->st); in scif_unmap_window()
242 kfree(window->st); in scif_unmap_window()
243 window->st = NULL; in scif_unmap_window()
246 for (j = 0; j < window->nr_contig_chunks; j++) { in scif_unmap_window()
247 if (window->dma_addr[j]) { in scif_unmap_window()
248 scif_unmap_single(window->dma_addr[j], in scif_unmap_window()
250 window->num_pages[j] << in scif_unmap_window()
252 window->dma_addr[j] = 0x0; in scif_unmap_window()
319 int scif_destroy_window(struct scif_endpt *ep, struct scif_window *window) in scif_destroy_window() argument
322 struct scif_pinned_pages *pinned_pages = window->pinned_pages; in scif_destroy_window()
323 int nr_pages = window->nr_pages; in scif_destroy_window()
326 if (!window->temp && window->mm) { in scif_destroy_window()
327 __scif_dec_pinned_vm_lock(window->mm, window->nr_pages, 0); in scif_destroy_window()
328 __scif_release_mm(window->mm); in scif_destroy_window()
329 window->mm = NULL; in scif_destroy_window()
332 scif_free_window_offset(ep, window, window->offset); in scif_destroy_window()
333 scif_unmap_window(ep->remote_dev, window); in scif_destroy_window()
349 scif_destroy_pinned_pages(window->pinned_pages); in scif_destroy_window()
350 scif_free(window->dma_addr, nr_pages * sizeof(*window->dma_addr)); in scif_destroy_window()
351 scif_free(window->num_pages, nr_pages * sizeof(*window->num_pages)); in scif_destroy_window()
352 window->magic = 0; in scif_destroy_window()
353 scif_free(window, sizeof(*window)); in scif_destroy_window()
367 struct scif_window *window) in scif_create_remote_lookup() argument
370 int nr_pages = window->nr_pages; in scif_create_remote_lookup()
375 err = scif_map_single(&window->mapped_offset, in scif_create_remote_lookup()
376 window, remote_dev, sizeof(*window)); in scif_create_remote_lookup()
381 window->nr_lookup = ALIGN(nr_pages * PAGE_SIZE, in scif_create_remote_lookup()
384 window->dma_addr_lookup.lookup = in scif_create_remote_lookup()
385 scif_alloc_coherent(&window->dma_addr_lookup.offset, in scif_create_remote_lookup()
386 remote_dev, window->nr_lookup * in scif_create_remote_lookup()
387 sizeof(*window->dma_addr_lookup.lookup), in scif_create_remote_lookup()
389 if (!window->dma_addr_lookup.lookup) { in scif_create_remote_lookup()
394 window->num_pages_lookup.lookup = in scif_create_remote_lookup()
395 scif_alloc_coherent(&window->num_pages_lookup.offset, in scif_create_remote_lookup()
396 remote_dev, window->nr_lookup * in scif_create_remote_lookup()
397 sizeof(*window->num_pages_lookup.lookup), in scif_create_remote_lookup()
399 if (!window->num_pages_lookup.lookup) { in scif_create_remote_lookup()
404 vmalloc_dma_phys = is_vmalloc_addr(&window->dma_addr[0]); in scif_create_remote_lookup()
405 vmalloc_num_pages = is_vmalloc_addr(&window->num_pages[0]); in scif_create_remote_lookup()
409 err = scif_map_page(&window->dma_addr_lookup.lookup[j], in scif_create_remote_lookup()
411 vmalloc_to_page(&window->dma_addr[i]) : in scif_create_remote_lookup()
412 virt_to_page(&window->dma_addr[i]), in scif_create_remote_lookup()
416 err = scif_map_page(&window->num_pages_lookup.lookup[j], in scif_create_remote_lookup()
418 vmalloc_to_page(&window->num_pages[i]) : in scif_create_remote_lookup()
419 virt_to_page(&window->num_pages[i]), in scif_create_remote_lookup()
438 struct scif_window *window) in scif_destroy_remote_lookup() argument
442 if (window->nr_lookup) { in scif_destroy_remote_lookup()
443 struct scif_rma_lookup *lup = &window->dma_addr_lookup; in scif_destroy_remote_lookup()
444 struct scif_rma_lookup *npup = &window->num_pages_lookup; in scif_destroy_remote_lookup()
446 for (i = 0, j = 0; i < window->nr_pages; in scif_destroy_remote_lookup()
459 remote_dev, window->nr_lookup * in scif_destroy_remote_lookup()
463 remote_dev, window->nr_lookup * in scif_destroy_remote_lookup()
465 if (window->mapped_offset) in scif_destroy_remote_lookup()
466 scif_unmap_single(window->mapped_offset, in scif_destroy_remote_lookup()
467 remote_dev, sizeof(*window)); in scif_destroy_remote_lookup()
468 window->nr_lookup = 0; in scif_destroy_remote_lookup()
482 struct scif_window *window; in scif_create_remote_window() local
485 window = scif_zalloc(sizeof(*window)); in scif_create_remote_window()
486 if (!window) in scif_create_remote_window()
489 window->magic = SCIFEP_MAGIC; in scif_create_remote_window()
490 window->nr_pages = nr_pages; in scif_create_remote_window()
492 window->dma_addr = scif_zalloc(nr_pages * sizeof(*window->dma_addr)); in scif_create_remote_window()
493 if (!window->dma_addr) in scif_create_remote_window()
496 window->num_pages = scif_zalloc(nr_pages * in scif_create_remote_window()
497 sizeof(*window->num_pages)); in scif_create_remote_window()
498 if (!window->num_pages) in scif_create_remote_window()
501 if (scif_create_remote_lookup(scifdev, window)) in scif_create_remote_window()
504 window->type = SCIF_WINDOW_PEER; in scif_create_remote_window()
505 window->unreg_state = OP_IDLE; in scif_create_remote_window()
506 INIT_LIST_HEAD(&window->list); in scif_create_remote_window()
507 return window; in scif_create_remote_window()
509 scif_destroy_remote_window(window); in scif_create_remote_window()
522 scif_destroy_remote_window(struct scif_window *window) in scif_destroy_remote_window() argument
524 scif_free(window->dma_addr, window->nr_pages * in scif_destroy_remote_window()
525 sizeof(*window->dma_addr)); in scif_destroy_remote_window()
526 scif_free(window->num_pages, window->nr_pages * in scif_destroy_remote_window()
527 sizeof(*window->num_pages)); in scif_destroy_remote_window()
528 window->magic = 0; in scif_destroy_remote_window()
529 scif_free(window, sizeof(*window)); in scif_destroy_remote_window()
541 struct scif_window *window) in scif_iommu_map() argument
545 scif_pinned_pages_t pin = window->pinned_pages; in scif_iommu_map()
547 window->st = kzalloc(sizeof(*window->st), GFP_KERNEL); in scif_iommu_map()
548 if (!window->st) in scif_iommu_map()
551 err = sg_alloc_table(window->st, window->nr_pages, GFP_KERNEL); in scif_iommu_map()
555 for_each_sg(window->st->sgl, sg, window->st->nents, i) in scif_iommu_map()
558 err = dma_map_sg(&remote_dev->sdev->dev, window->st->sgl, in scif_iommu_map()
559 window->st->nents, DMA_BIDIRECTIONAL); in scif_iommu_map()
563 sg = window->st->sgl; in scif_iommu_map()
567 window->dma_addr[i] = sg_dma_address(sg); in scif_iommu_map()
568 window->num_pages[i] = sg_dma_len(sg) >> PAGE_SHIFT; in scif_iommu_map()
571 window->num_pages[i] += in scif_iommu_map()
573 last_da = window->dma_addr[i] + in scif_iommu_map()
576 window->nr_contig_chunks++; in scif_iommu_map()
590 scif_map_window(struct scif_dev *remote_dev, struct scif_window *window) in scif_map_window() argument
598 pin = window->pinned_pages; in scif_map_window()
601 return scif_iommu_map(remote_dev, window); in scif_map_window()
603 for (i = 0, j = 0; i < window->nr_pages; i += nr_contig_pages, j++) { in scif_map_window()
608 for (k = i + 1; k < window->nr_pages; k++) { in scif_map_window()
615 window->num_pages[j] = nr_contig_pages; in scif_map_window()
616 window->nr_contig_chunks++; in scif_map_window()
622 err = scif_map_single(&window->dma_addr[j], in scif_map_window()
630 window->dma_addr[j] = page_to_phys(pin->pages[i]); in scif_map_window()
644 struct scif_window *window) in scif_send_scif_unregister() argument
650 msg.payload[0] = window->alloc_handle.vaddr; in scif_send_scif_unregister()
651 msg.payload[1] = (u64)window; in scif_send_scif_unregister()
661 int scif_unregister_window(struct scif_window *window) in scif_unregister_window() argument
664 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_unregister_window()
668 switch (window->unreg_state) { in scif_unregister_window()
671 window->unreg_state = OP_IN_PROGRESS; in scif_unregister_window()
677 scif_get_window(window, 1); in scif_unregister_window()
680 err = scif_send_scif_unregister(ep, window); in scif_unregister_window()
682 window->unreg_state = OP_COMPLETED; in scif_unregister_window()
692 err = wait_event_timeout(window->unregwq, in scif_unregister_window()
693 window->unreg_state != OP_IN_PROGRESS, in scif_unregister_window()
699 window->unreg_state = OP_COMPLETED; in scif_unregister_window()
707 scif_put_window(window, 1); in scif_unregister_window()
714 window->unreg_state = OP_COMPLETED; in scif_unregister_window()
724 if (window->unreg_state == OP_COMPLETED && window->ref_count) in scif_unregister_window()
725 scif_put_window(window, window->nr_pages); in scif_unregister_window()
727 if (!window->ref_count) { in scif_unregister_window()
729 list_del_init(&window->list); in scif_unregister_window()
730 scif_free_window_offset(ep, window, window->offset); in scif_unregister_window()
732 if ((!!(window->pinned_pages->map_flags & SCIF_MAP_KERNEL)) && in scif_unregister_window()
737 if (!__scif_dec_pinned_vm_lock(window->mm, in scif_unregister_window()
738 window->nr_pages, 1)) { in scif_unregister_window()
739 __scif_release_mm(window->mm); in scif_unregister_window()
740 window->mm = NULL; in scif_unregister_window()
743 scif_queue_for_cleanup(window, &scif_info.rma); in scif_unregister_window()
757 struct scif_window *window) in scif_send_alloc_request() argument
760 struct scif_allocmsg *alloc = &window->alloc_handle; in scif_send_alloc_request()
768 msg.payload[1] = window->nr_pages; in scif_send_alloc_request()
769 msg.payload[2] = (u64)&window->alloc_handle; in scif_send_alloc_request()
782 struct scif_window *window) in scif_prep_remote_window() argument
786 struct scif_allocmsg *alloc = &window->alloc_handle; in scif_prep_remote_window()
793 map_err = scif_map_window(ep->remote_dev, window); in scif_prep_remote_window()
797 remaining_nr_contig_chunks = window->nr_contig_chunks; in scif_prep_remote_window()
798 nr_contig_chunks = window->nr_contig_chunks; in scif_prep_remote_window()
828 msg.payload[1] = window->alloc_handle.vaddr; in scif_prep_remote_window()
829 msg.payload[2] = (u64)window; in scif_prep_remote_window()
840 remote_window = scif_ioremap(alloc->phys_addr, sizeof(*window), in scif_prep_remote_window()
871 sizeof(*window->dma_addr), in scif_prep_remote_window()
875 sizeof(*window->num_pages), in scif_prep_remote_window()
879 &window->dma_addr[i], loop_nr_contig_chunks in scif_prep_remote_window()
880 * sizeof(*window->dma_addr)); in scif_prep_remote_window()
882 &window->num_pages[i], loop_nr_contig_chunks in scif_prep_remote_window()
883 * sizeof(*window->num_pages)); in scif_prep_remote_window()
894 dma_addr = window->dma_addr[i + m] + in scif_prep_remote_window()
900 &window->num_pages[i], in scif_prep_remote_window()
902 * sizeof(*window->num_pages)); in scif_prep_remote_window()
912 &window->dma_addr[i], in scif_prep_remote_window()
914 sizeof(*window->dma_addr)); in scif_prep_remote_window()
916 &window->num_pages[i], in scif_prep_remote_window()
918 sizeof(*window->num_pages)); in scif_prep_remote_window()
925 sizeof(*window->dma_addr), ep->remote_dev); in scif_prep_remote_window()
927 sizeof(*window->num_pages), ep->remote_dev); in scif_prep_remote_window()
931 remote_window->peer_window = (u64)window; in scif_prep_remote_window()
932 remote_window->offset = window->offset; in scif_prep_remote_window()
933 remote_window->prot = window->prot; in scif_prep_remote_window()
945 window->peer_window = alloc->vaddr; in scif_prep_remote_window()
959 struct scif_window *window) in scif_send_scif_register() argument
966 msg.payload[1] = window->alloc_handle.vaddr; in scif_send_scif_register()
967 msg.payload[2] = (u64)window; in scif_send_scif_register()
971 window->reg_state = OP_IN_PROGRESS; in scif_send_scif_register()
977 err = wait_event_timeout(window->regwq, in scif_send_scif_register()
978 window->reg_state != in scif_send_scif_register()
984 if (window->reg_state == OP_FAILED) in scif_send_scif_register()
1042 struct scif_window *window, s64 offset) in scif_free_window_offset() argument
1044 if ((window && !window->offset_freed) || !window) { in scif_free_window_offset()
1046 if (window) in scif_free_window_offset()
1047 window->offset_freed = true; in scif_free_window_offset()
1060 struct scif_window *window = NULL; in scif_alloc_req() local
1063 window = scif_create_remote_window(scifdev, nr_pages); in scif_alloc_req()
1064 if (!window) { in scif_alloc_req()
1071 msg->payload[0] = (u64)window; in scif_alloc_req()
1072 msg->payload[1] = window->mapped_offset; in scif_alloc_req()
1075 scif_destroy_remote_window(window); in scif_alloc_req()
1081 __func__, __LINE__, err, window, nr_pages); in scif_alloc_req()
1095 struct scif_window *window = container_of(handle, struct scif_window, in scif_alloc_gnt_rej() local
1097 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_alloc_gnt_rej()
1118 struct scif_window *window = (struct scif_window *)msg->payload[1]; in scif_free_virt() local
1120 scif_destroy_remote_window(window); in scif_free_virt()
1124 scif_fixup_aper_base(struct scif_dev *dev, struct scif_window *window) in scif_fixup_aper_base() argument
1134 if (!scifdev_self(dev) && window->type == SCIF_WINDOW_PEER && in scif_fixup_aper_base()
1140 for (j = 0; j < window->nr_contig_chunks; j++) { in scif_fixup_aper_base()
1141 if (window->num_pages[j]) in scif_fixup_aper_base()
1142 window->dma_addr[j] += apt_base; in scif_fixup_aper_base()
1157 struct scif_window *window = in scif_recv_reg() local
1165 scif_fixup_aper_base(ep->remote_dev, window); in scif_recv_reg()
1167 scif_insert_window(window, &ep->rma_info.remote_reg_list); in scif_recv_reg()
1175 scif_destroy_remote_lookup(ep->remote_dev, window); in scif_recv_reg()
1181 scif_destroy_remote_window(window); in scif_recv_reg()
1193 struct scif_window *window = NULL; in scif_recv_unreg() local
1200 req.out_window = &window; in scif_recv_unreg()
1216 if (window) { in scif_recv_unreg()
1217 if (window->ref_count) in scif_recv_unreg()
1218 scif_put_window(window, window->nr_pages); in scif_recv_unreg()
1223 window->unreg_state = OP_COMPLETED; in scif_recv_unreg()
1224 if (!window->ref_count) { in scif_recv_unreg()
1228 list_del_init(&window->list); in scif_recv_unreg()
1246 scif_queue_for_cleanup(window, &scif_info.rma); in scif_recv_unreg()
1257 struct scif_window *window = in scif_recv_reg_ack() local
1259 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_recv_reg_ack()
1262 window->reg_state = OP_COMPLETED; in scif_recv_reg_ack()
1263 wake_up(&window->regwq); in scif_recv_reg_ack()
1276 struct scif_window *window = in scif_recv_reg_nack() local
1278 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_recv_reg_nack()
1281 window->reg_state = OP_FAILED; in scif_recv_reg_nack()
1282 wake_up(&window->regwq); in scif_recv_reg_nack()
1294 struct scif_window *window = in scif_recv_unreg_ack() local
1296 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_recv_unreg_ack()
1299 window->unreg_state = OP_COMPLETED; in scif_recv_unreg_ack()
1300 wake_up(&window->unregwq); in scif_recv_unreg_ack()
1313 struct scif_window *window = in scif_recv_unreg_nack() local
1315 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_recv_unreg_nack()
1318 window->unreg_state = OP_FAILED; in scif_recv_unreg_nack()
1319 wake_up(&window->unregwq); in scif_recv_unreg_nack()
1483 scif_insert_local_window(struct scif_window *window, struct scif_endpt *ep) in scif_insert_local_window() argument
1486 scif_insert_window(window, &ep->rma_info.reg_list); in scif_insert_local_window()
1496 struct scif_window *window; in scif_register_pinned_pages() local
1538 window = scif_create_window(ep, pinned_pages->nr_pages, in scif_register_pinned_pages()
1540 if (!window) { in scif_register_pinned_pages()
1546 window->pinned_pages = pinned_pages; in scif_register_pinned_pages()
1547 window->nr_pages = pinned_pages->nr_pages; in scif_register_pinned_pages()
1548 window->prot = pinned_pages->prot; in scif_register_pinned_pages()
1553 scif_destroy_window(ep, window); in scif_register_pinned_pages()
1556 err = scif_send_alloc_request(ep, window); in scif_register_pinned_pages()
1564 err = scif_prep_remote_window(ep, window); in scif_register_pinned_pages()
1572 err = scif_send_scif_register(ep, window); in scif_register_pinned_pages()
1581 scif_insert_local_window(window, ep); in scif_register_pinned_pages()
1584 scif_destroy_window(ep, window); in scif_register_pinned_pages()
1599 struct scif_window *window; in scif_register() local
1648 window = scif_create_window(ep, len >> PAGE_SHIFT, in scif_register()
1650 if (!window) { in scif_register()
1656 window->nr_pages = len >> PAGE_SHIFT; in scif_register()
1658 err = scif_send_alloc_request(ep, window); in scif_register()
1660 scif_destroy_incomplete_window(ep, window); in scif_register()
1674 scif_destroy_incomplete_window(ep, window); in scif_register()
1679 window->pinned_pages = pinned_pages; in scif_register()
1680 window->prot = pinned_pages->prot; in scif_register()
1681 window->mm = mm; in scif_register()
1684 err = scif_prep_remote_window(ep, window); in scif_register()
1692 err = scif_send_scif_register(ep, window); in scif_register()
1701 scif_insert_local_window(window, ep); in scif_register()
1707 scif_destroy_window(ep, window); in scif_register()
1720 struct scif_window *window = NULL; in scif_unregister() local
1746 req.out_window = &window; in scif_unregister()
1767 err = scif_rma_list_unregister(window, offset, nr_pages); in scif_unregister()