• Home
  • Raw
  • Download

Lines Matching full:window

84  * @nr_pages: number of pages in window
144 * @temp: true if a temporary window is being created
146 * Allocate and prepare a self registration window.
151 struct scif_window *window; in scif_create_window() local
154 window = scif_zalloc(sizeof(*window)); in scif_create_window()
155 if (!window) in scif_create_window()
158 window->dma_addr = scif_zalloc(nr_pages * sizeof(*window->dma_addr)); in scif_create_window()
159 if (!window->dma_addr) in scif_create_window()
162 window->num_pages = scif_zalloc(nr_pages * sizeof(*window->num_pages)); in scif_create_window()
163 if (!window->num_pages) in scif_create_window()
166 window->offset = offset; in scif_create_window()
167 window->ep = (u64)ep; in scif_create_window()
168 window->magic = SCIFEP_MAGIC; in scif_create_window()
169 window->reg_state = OP_IDLE; in scif_create_window()
170 init_waitqueue_head(&window->regwq); in scif_create_window()
171 window->unreg_state = OP_IDLE; in scif_create_window()
172 init_waitqueue_head(&window->unregwq); in scif_create_window()
173 INIT_LIST_HEAD(&window->list); in scif_create_window()
174 window->type = SCIF_WINDOW_SELF; in scif_create_window()
175 window->temp = temp; in scif_create_window()
176 return window; in scif_create_window()
179 scif_free(window->dma_addr, in scif_create_window()
180 nr_pages * sizeof(*window->dma_addr)); in scif_create_window()
181 scif_free(window, sizeof(*window)); in scif_create_window()
189 * @window: registration window
191 * Deallocate resources for self window.
194 struct scif_window *window) in scif_destroy_incomplete_window() argument
197 int nr_pages = window->nr_pages; in scif_destroy_incomplete_window()
198 struct scif_allocmsg *alloc = &window->alloc_handle; in scif_destroy_incomplete_window()
214 msg.payload[1] = window->alloc_handle.vaddr; in scif_destroy_incomplete_window()
215 msg.payload[2] = (u64)window; in scif_destroy_incomplete_window()
221 scif_free_window_offset(ep, window, window->offset); in scif_destroy_incomplete_window()
222 scif_free(window->dma_addr, nr_pages * sizeof(*window->dma_addr)); in scif_destroy_incomplete_window()
223 scif_free(window->num_pages, nr_pages * sizeof(*window->num_pages)); in scif_destroy_incomplete_window()
224 scif_free(window, sizeof(*window)); in scif_destroy_incomplete_window()
230 * @window: registration window
232 * Delete any DMA mappings created for a registered self window
234 void scif_unmap_window(struct scif_dev *remote_dev, struct scif_window *window) in scif_unmap_window() argument
239 if (window->st) { in scif_unmap_window()
241 window->st->sgl, window->st->nents, in scif_unmap_window()
243 sg_free_table(window->st); in scif_unmap_window()
244 kfree(window->st); in scif_unmap_window()
245 window->st = NULL; in scif_unmap_window()
248 for (j = 0; j < window->nr_contig_chunks; j++) { in scif_unmap_window()
249 if (window->dma_addr[j]) { in scif_unmap_window()
250 scif_unmap_single(window->dma_addr[j], in scif_unmap_window()
252 window->num_pages[j] << in scif_unmap_window()
254 window->dma_addr[j] = 0x0; in scif_unmap_window()
317 * @window: registration window
319 * Deallocate resources for self window.
321 int scif_destroy_window(struct scif_endpt *ep, struct scif_window *window) in scif_destroy_window() argument
324 struct scif_pinned_pages *pinned_pages = window->pinned_pages; in scif_destroy_window()
325 int nr_pages = window->nr_pages; in scif_destroy_window()
328 if (!window->temp && window->mm) { in scif_destroy_window()
329 __scif_dec_pinned_vm_lock(window->mm, window->nr_pages, 0); in scif_destroy_window()
330 __scif_release_mm(window->mm); in scif_destroy_window()
331 window->mm = NULL; in scif_destroy_window()
334 scif_free_window_offset(ep, window, window->offset); in scif_destroy_window()
335 scif_unmap_window(ep->remote_dev, window); in scif_destroy_window()
338 * this window. in scif_destroy_window()
351 scif_destroy_pinned_pages(window->pinned_pages); in scif_destroy_window()
352 scif_free(window->dma_addr, nr_pages * sizeof(*window->dma_addr)); in scif_destroy_window()
353 scif_free(window->num_pages, nr_pages * sizeof(*window->num_pages)); in scif_destroy_window()
354 window->magic = 0; in scif_destroy_window()
355 scif_free(window, sizeof(*window)); in scif_destroy_window()
362 * @window: remote window
369 struct scif_window *window) in scif_create_remote_lookup() argument
372 int nr_pages = window->nr_pages; in scif_create_remote_lookup()
376 /* Map window */ in scif_create_remote_lookup()
377 err = scif_map_single(&window->mapped_offset, in scif_create_remote_lookup()
378 window, remote_dev, sizeof(*window)); in scif_create_remote_lookup()
383 window->nr_lookup = ALIGN(nr_pages * PAGE_SIZE, in scif_create_remote_lookup()
386 window->dma_addr_lookup.lookup = in scif_create_remote_lookup()
387 scif_alloc_coherent(&window->dma_addr_lookup.offset, in scif_create_remote_lookup()
388 remote_dev, window->nr_lookup * in scif_create_remote_lookup()
389 sizeof(*window->dma_addr_lookup.lookup), in scif_create_remote_lookup()
391 if (!window->dma_addr_lookup.lookup) { in scif_create_remote_lookup()
396 window->num_pages_lookup.lookup = in scif_create_remote_lookup()
397 scif_alloc_coherent(&window->num_pages_lookup.offset, in scif_create_remote_lookup()
398 remote_dev, window->nr_lookup * in scif_create_remote_lookup()
399 sizeof(*window->num_pages_lookup.lookup), in scif_create_remote_lookup()
401 if (!window->num_pages_lookup.lookup) { in scif_create_remote_lookup()
406 vmalloc_dma_phys = is_vmalloc_addr(&window->dma_addr[0]); in scif_create_remote_lookup()
407 vmalloc_num_pages = is_vmalloc_addr(&window->num_pages[0]); in scif_create_remote_lookup()
411 err = scif_map_page(&window->dma_addr_lookup.lookup[j], in scif_create_remote_lookup()
413 vmalloc_to_page(&window->dma_addr[i]) : in scif_create_remote_lookup()
414 virt_to_page(&window->dma_addr[i]), in scif_create_remote_lookup()
418 err = scif_map_page(&window->num_pages_lookup.lookup[j], in scif_create_remote_lookup()
420 vmalloc_to_page(&window->num_pages[i]) : in scif_create_remote_lookup()
421 virt_to_page(&window->num_pages[i]), in scif_create_remote_lookup()
434 * @window: remote window
440 struct scif_window *window) in scif_destroy_remote_lookup() argument
444 if (window->nr_lookup) { in scif_destroy_remote_lookup()
445 struct scif_rma_lookup *lup = &window->dma_addr_lookup; in scif_destroy_remote_lookup()
446 struct scif_rma_lookup *npup = &window->num_pages_lookup; in scif_destroy_remote_lookup()
448 for (i = 0, j = 0; i < window->nr_pages; in scif_destroy_remote_lookup()
461 remote_dev, window->nr_lookup * in scif_destroy_remote_lookup()
465 remote_dev, window->nr_lookup * in scif_destroy_remote_lookup()
467 if (window->mapped_offset) in scif_destroy_remote_lookup()
468 scif_unmap_single(window->mapped_offset, in scif_destroy_remote_lookup()
469 remote_dev, sizeof(*window)); in scif_destroy_remote_lookup()
470 window->nr_lookup = 0; in scif_destroy_remote_lookup()
477 * @nr_pages: number of pages in window
479 * Allocate and prepare a remote registration window.
484 struct scif_window *window; in scif_create_remote_window() local
487 window = scif_zalloc(sizeof(*window)); in scif_create_remote_window()
488 if (!window) in scif_create_remote_window()
491 window->magic = SCIFEP_MAGIC; in scif_create_remote_window()
492 window->nr_pages = nr_pages; in scif_create_remote_window()
494 window->dma_addr = scif_zalloc(nr_pages * sizeof(*window->dma_addr)); in scif_create_remote_window()
495 if (!window->dma_addr) in scif_create_remote_window()
498 window->num_pages = scif_zalloc(nr_pages * in scif_create_remote_window()
499 sizeof(*window->num_pages)); in scif_create_remote_window()
500 if (!window->num_pages) in scif_create_remote_window()
503 if (scif_create_remote_lookup(scifdev, window)) in scif_create_remote_window()
506 window->type = SCIF_WINDOW_PEER; in scif_create_remote_window()
507 window->unreg_state = OP_IDLE; in scif_create_remote_window()
508 INIT_LIST_HEAD(&window->list); in scif_create_remote_window()
509 return window; in scif_create_remote_window()
511 scif_destroy_remote_window(window); in scif_create_remote_window()
519 * @window: remote registration window
521 * Deallocate resources for remote window.
524 scif_destroy_remote_window(struct scif_window *window) in scif_destroy_remote_window() argument
526 scif_free(window->dma_addr, window->nr_pages * in scif_destroy_remote_window()
527 sizeof(*window->dma_addr)); in scif_destroy_remote_window()
528 scif_free(window->num_pages, window->nr_pages * in scif_destroy_remote_window()
529 sizeof(*window->num_pages)); in scif_destroy_remote_window()
530 window->magic = 0; in scif_destroy_remote_window()
531 scif_free(window, sizeof(*window)); in scif_destroy_remote_window()
537 * @window: remote registration window
543 struct scif_window *window) in scif_iommu_map() argument
547 scif_pinned_pages_t pin = window->pinned_pages; in scif_iommu_map()
549 window->st = kzalloc(sizeof(*window->st), GFP_KERNEL); in scif_iommu_map()
550 if (!window->st) in scif_iommu_map()
553 err = sg_alloc_table(window->st, window->nr_pages, GFP_KERNEL); in scif_iommu_map()
557 for_each_sg(window->st->sgl, sg, window->st->nents, i) in scif_iommu_map()
560 err = dma_map_sg(&remote_dev->sdev->dev, window->st->sgl, in scif_iommu_map()
561 window->st->nents, DMA_BIDIRECTIONAL); in scif_iommu_map()
565 sg = window->st->sgl; in scif_iommu_map()
569 window->dma_addr[i] = sg_dma_address(sg); in scif_iommu_map()
570 window->num_pages[i] = sg_dma_len(sg) >> PAGE_SHIFT; in scif_iommu_map()
573 window->num_pages[i] += in scif_iommu_map()
575 last_da = window->dma_addr[i] + in scif_iommu_map()
578 window->nr_contig_chunks++; in scif_iommu_map()
586 * @window: self registration window
588 * Map pages of a window into the aperture/PCI.
592 scif_map_window(struct scif_dev *remote_dev, struct scif_window *window) in scif_map_window() argument
600 pin = window->pinned_pages; in scif_map_window()
603 return scif_iommu_map(remote_dev, window); in scif_map_window()
605 for (i = 0, j = 0; i < window->nr_pages; i += nr_contig_pages, j++) { in scif_map_window()
610 for (k = i + 1; k < window->nr_pages; k++) { in scif_map_window()
617 window->num_pages[j] = nr_contig_pages; in scif_map_window()
618 window->nr_contig_chunks++; in scif_map_window()
624 err = scif_map_single(&window->dma_addr[j], in scif_map_window()
632 window->dma_addr[j] = page_to_phys(pin->pages[i]); in scif_map_window()
641 * @window: self registration window
646 struct scif_window *window) in scif_send_scif_unregister() argument
652 msg.payload[0] = window->alloc_handle.vaddr; in scif_send_scif_unregister()
653 msg.payload[1] = (u64)window; in scif_send_scif_unregister()
659 * @window: self registration window
663 int scif_unregister_window(struct scif_window *window) in scif_unregister_window() argument
666 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_unregister_window()
670 switch (window->unreg_state) { in scif_unregister_window()
673 window->unreg_state = OP_IN_PROGRESS; in scif_unregister_window()
679 scif_get_window(window, 1); in scif_unregister_window()
682 err = scif_send_scif_unregister(ep, window); in scif_unregister_window()
684 window->unreg_state = OP_COMPLETED; in scif_unregister_window()
694 err = wait_event_timeout(window->unregwq, in scif_unregister_window()
695 window->unreg_state != OP_IN_PROGRESS, in scif_unregister_window()
701 window->unreg_state = OP_COMPLETED; in scif_unregister_window()
709 scif_put_window(window, 1); in scif_unregister_window()
716 window->unreg_state = OP_COMPLETED; in scif_unregister_window()
726 if (window->unreg_state == OP_COMPLETED && window->ref_count) in scif_unregister_window()
727 scif_put_window(window, window->nr_pages); in scif_unregister_window()
729 if (!window->ref_count) { in scif_unregister_window()
731 list_del_init(&window->list); in scif_unregister_window()
732 scif_free_window_offset(ep, window, window->offset); in scif_unregister_window()
734 if ((!!(window->pinned_pages->map_flags & SCIF_MAP_KERNEL)) && in scif_unregister_window()
739 if (!__scif_dec_pinned_vm_lock(window->mm, in scif_unregister_window()
740 window->nr_pages, 1)) { in scif_unregister_window()
741 __scif_release_mm(window->mm); in scif_unregister_window()
742 window->mm = NULL; in scif_unregister_window()
745 scif_queue_for_cleanup(window, &scif_info.rma); in scif_unregister_window()
754 * @window: self registration window
756 * Send a remote window allocation request
759 struct scif_window *window) in scif_send_alloc_request() argument
762 struct scif_allocmsg *alloc = &window->alloc_handle; in scif_send_alloc_request()
770 msg.payload[1] = window->nr_pages; in scif_send_alloc_request()
771 msg.payload[2] = (u64)&window->alloc_handle; in scif_send_alloc_request()
778 * @window: self registration window
780 * Send a remote window allocation request, wait for an allocation response,
781 * and prepares the remote window by copying over the page lists
784 struct scif_window *window) in scif_prep_remote_window() argument
788 struct scif_allocmsg *alloc = &window->alloc_handle; in scif_prep_remote_window()
795 map_err = scif_map_window(ep->remote_dev, window); in scif_prep_remote_window()
799 remaining_nr_contig_chunks = window->nr_contig_chunks; in scif_prep_remote_window()
800 nr_contig_chunks = window->nr_contig_chunks; in scif_prep_remote_window()
830 msg.payload[1] = window->alloc_handle.vaddr; in scif_prep_remote_window()
831 msg.payload[2] = (u64)window; in scif_prep_remote_window()
842 remote_window = scif_ioremap(alloc->phys_addr, sizeof(*window), in scif_prep_remote_window()
873 sizeof(*window->dma_addr), in scif_prep_remote_window()
877 sizeof(*window->num_pages), in scif_prep_remote_window()
881 &window->dma_addr[i], loop_nr_contig_chunks in scif_prep_remote_window()
882 * sizeof(*window->dma_addr)); in scif_prep_remote_window()
884 &window->num_pages[i], loop_nr_contig_chunks in scif_prep_remote_window()
885 * sizeof(*window->num_pages)); in scif_prep_remote_window()
896 dma_addr = window->dma_addr[i + m] + in scif_prep_remote_window()
902 &window->num_pages[i], in scif_prep_remote_window()
904 * sizeof(*window->num_pages)); in scif_prep_remote_window()
914 &window->dma_addr[i], in scif_prep_remote_window()
916 sizeof(*window->dma_addr)); in scif_prep_remote_window()
918 &window->num_pages[i], in scif_prep_remote_window()
920 sizeof(*window->num_pages)); in scif_prep_remote_window()
927 sizeof(*window->dma_addr), ep->remote_dev); in scif_prep_remote_window()
929 sizeof(*window->num_pages), ep->remote_dev); in scif_prep_remote_window()
932 /* Prepare the remote window for the peer */ in scif_prep_remote_window()
933 remote_window->peer_window = (u64)window; in scif_prep_remote_window()
934 remote_window->offset = window->offset; in scif_prep_remote_window()
935 remote_window->prot = window->prot; in scif_prep_remote_window()
947 window->peer_window = alloc->vaddr; in scif_prep_remote_window()
954 * @window: self registration window
958 * message so that the peer can free its remote window allocated earlier.
961 struct scif_window *window) in scif_send_scif_register() argument
968 msg.payload[1] = window->alloc_handle.vaddr; in scif_send_scif_register()
969 msg.payload[2] = (u64)window; in scif_send_scif_register()
973 window->reg_state = OP_IN_PROGRESS; in scif_send_scif_register()
979 err = wait_event_timeout(window->regwq, in scif_send_scif_register()
980 window->reg_state != in scif_send_scif_register()
986 if (window->reg_state == OP_FAILED) in scif_send_scif_register()
1037 * @window: registration window
1044 struct scif_window *window, s64 offset) in scif_free_window_offset() argument
1046 if ((window && !window->offset_freed) || !window) { in scif_free_window_offset()
1048 if (window) in scif_free_window_offset()
1049 window->offset_freed = true; in scif_free_window_offset()
1062 struct scif_window *window = NULL; in scif_alloc_req() local
1065 window = scif_create_remote_window(scifdev, nr_pages); in scif_alloc_req()
1066 if (!window) { in scif_alloc_req()
1073 msg->payload[0] = (u64)window; in scif_alloc_req()
1074 msg->payload[1] = window->mapped_offset; in scif_alloc_req()
1077 scif_destroy_remote_window(window); in scif_alloc_req()
1083 __func__, __LINE__, err, window, nr_pages); in scif_alloc_req()
1097 struct scif_window *window = container_of(handle, struct scif_window, in scif_alloc_gnt_rej() local
1099 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_alloc_gnt_rej()
1120 struct scif_window *window = (struct scif_window *)msg->payload[1]; in scif_free_virt() local
1122 scif_destroy_remote_window(window); in scif_free_virt()
1126 scif_fixup_aper_base(struct scif_dev *dev, struct scif_window *window) in scif_fixup_aper_base() argument
1136 if (!scifdev_self(dev) && window->type == SCIF_WINDOW_PEER && in scif_fixup_aper_base()
1142 for (j = 0; j < window->nr_contig_chunks; j++) { in scif_fixup_aper_base()
1143 if (window->num_pages[j]) in scif_fixup_aper_base()
1144 window->dma_addr[j] += apt_base; in scif_fixup_aper_base()
1154 * Update remote window list with a new registered window.
1159 struct scif_window *window = in scif_recv_reg() local
1167 scif_fixup_aper_base(ep->remote_dev, window); in scif_recv_reg()
1168 /* No further failures expected. Insert new window */ in scif_recv_reg()
1169 scif_insert_window(window, &ep->rma_info.remote_reg_list); in scif_recv_reg()
1177 scif_destroy_remote_lookup(ep->remote_dev, window); in scif_recv_reg()
1179 * We could not insert the window but we need to in scif_recv_reg()
1180 * destroy the window. in scif_recv_reg()
1183 scif_destroy_remote_window(window); in scif_recv_reg()
1190 * Remove window from remote registration list;
1195 struct scif_window *window = NULL; in scif_recv_unreg() local
1202 req.out_window = &window; in scif_recv_unreg()
1211 /* Does a valid window exist? */ in scif_recv_unreg()
1218 if (window) { in scif_recv_unreg()
1219 if (window->ref_count) in scif_recv_unreg()
1220 scif_put_window(window, window->nr_pages); in scif_recv_unreg()
1225 window->unreg_state = OP_COMPLETED; in scif_recv_unreg()
1226 if (!window->ref_count) { in scif_recv_unreg()
1230 list_del_init(&window->list); in scif_recv_unreg()
1233 /* NACK! There are valid references to this window */ in scif_recv_unreg()
1237 /* The window did not make its way to the list at all. ACK */ in scif_recv_unreg()
1248 scif_queue_for_cleanup(window, &scif_info.rma); in scif_recv_unreg()
1255 * Wake up the window waiting to complete registration.
1259 struct scif_window *window = in scif_recv_reg_ack() local
1261 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_recv_reg_ack()
1264 window->reg_state = OP_COMPLETED; in scif_recv_reg_ack()
1265 wake_up(&window->regwq); in scif_recv_reg_ack()
1273 * Wake up the window waiting to inform it that registration
1278 struct scif_window *window = in scif_recv_reg_nack() local
1280 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_recv_reg_nack()
1283 window->reg_state = OP_FAILED; in scif_recv_reg_nack()
1284 wake_up(&window->regwq); in scif_recv_reg_nack()
1292 * Wake up the window waiting to complete unregistration.
1296 struct scif_window *window = in scif_recv_unreg_ack() local
1298 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_recv_unreg_ack()
1301 window->unreg_state = OP_COMPLETED; in scif_recv_unreg_ack()
1302 wake_up(&window->unregwq); in scif_recv_unreg_ack()
1310 * Wake up the window waiting to inform it that unregistration
1315 struct scif_window *window = in scif_recv_unreg_nack() local
1317 struct scif_endpt *ep = (struct scif_endpt *)window->ep; in scif_recv_unreg_nack()
1320 window->unreg_state = OP_FAILED; in scif_recv_unreg_nack()
1321 wake_up(&window->unregwq); in scif_recv_unreg_nack()
1469 * Destroy the window if the ref count for this set of pinned in scif_unpin_pages()
1471 * a valid registered window which is backed by these pages and in scif_unpin_pages()
1482 scif_insert_local_window(struct scif_window *window, struct scif_endpt *ep) in scif_insert_local_window() argument
1485 scif_insert_window(window, &ep->rma_info.reg_list); in scif_insert_local_window()
1495 struct scif_window *window; in scif_register_pinned_pages() local
1536 /* Allocate and prepare self registration window */ in scif_register_pinned_pages()
1537 window = scif_create_window(ep, pinned_pages->nr_pages, in scif_register_pinned_pages()
1539 if (!window) { in scif_register_pinned_pages()
1545 window->pinned_pages = pinned_pages; in scif_register_pinned_pages()
1546 window->nr_pages = pinned_pages->nr_pages; in scif_register_pinned_pages()
1547 window->prot = pinned_pages->prot; in scif_register_pinned_pages()
1552 scif_destroy_window(ep, window); in scif_register_pinned_pages()
1555 err = scif_send_alloc_request(ep, window); in scif_register_pinned_pages()
1562 /* Prepare the remote registration window */ in scif_register_pinned_pages()
1563 err = scif_prep_remote_window(ep, window); in scif_register_pinned_pages()
1570 /* Tell the peer about the new window */ in scif_register_pinned_pages()
1571 err = scif_send_scif_register(ep, window); in scif_register_pinned_pages()
1579 /* No further failures expected. Insert new window */ in scif_register_pinned_pages()
1580 scif_insert_local_window(window, ep); in scif_register_pinned_pages()
1583 scif_destroy_window(ep, window); in scif_register_pinned_pages()
1598 struct scif_window *window; in scif_register() local
1646 /* Allocate and prepare self registration window */ in scif_register()
1647 window = scif_create_window(ep, len >> PAGE_SHIFT, in scif_register()
1649 if (!window) { in scif_register()
1655 window->nr_pages = len >> PAGE_SHIFT; in scif_register()
1657 err = scif_send_alloc_request(ep, window); in scif_register()
1659 scif_destroy_incomplete_window(ep, window); in scif_register()
1673 scif_destroy_incomplete_window(ep, window); in scif_register()
1678 window->pinned_pages = pinned_pages; in scif_register()
1679 window->prot = pinned_pages->prot; in scif_register()
1680 window->mm = mm; in scif_register()
1682 /* Prepare the remote registration window */ in scif_register()
1683 err = scif_prep_remote_window(ep, window); in scif_register()
1690 /* Tell the peer about the new window */ in scif_register()
1691 err = scif_send_scif_register(ep, window); in scif_register()
1699 /* No further failures expected. Insert new window */ in scif_register()
1700 scif_insert_local_window(window, ep); in scif_register()
1706 scif_destroy_window(ep, window); in scif_register()
1719 struct scif_window *window = NULL; in scif_unregister() local
1745 req.out_window = &window; in scif_unregister()
1758 /* Does a valid window exist? */ in scif_unregister()
1766 err = scif_rma_list_unregister(window, offset, nr_pages); in scif_unregister()