Lines Matching refs:pipe
215 static int goldfish_pipe_cmd_locked(struct goldfish_pipe *pipe, enum PipeCmdCode cmd) in goldfish_pipe_cmd_locked() argument
217 pipe->command_buffer->cmd = cmd; in goldfish_pipe_cmd_locked()
218 pipe->command_buffer->status = PIPE_ERROR_INVAL; /* failure by default */ in goldfish_pipe_cmd_locked()
219 writel(pipe->id, pipe->dev->base + PIPE_REG_CMD); in goldfish_pipe_cmd_locked()
220 return pipe->command_buffer->status; in goldfish_pipe_cmd_locked()
223 static int goldfish_pipe_cmd(struct goldfish_pipe *pipe, enum PipeCmdCode cmd) in goldfish_pipe_cmd() argument
226 if (mutex_lock_interruptible(&pipe->lock)) in goldfish_pipe_cmd()
228 status = goldfish_pipe_cmd_locked(pipe, cmd); in goldfish_pipe_cmd()
229 mutex_unlock(&pipe->lock); in goldfish_pipe_cmd()
322 static int transfer_max_buffers(struct goldfish_pipe *pipe, in transfer_max_buffers() argument
337 if (mutex_lock_interruptible(&pipe->lock)) in transfer_max_buffers()
342 pipe->command_buffer); in transfer_max_buffers()
345 *status = goldfish_pipe_cmd_locked(pipe, in transfer_max_buffers()
348 *consumed_size = pipe->command_buffer->rw_params.consumed_size; in transfer_max_buffers()
350 mutex_unlock(&pipe->lock); in transfer_max_buffers()
357 static int goldfish_pipe_wait_event(u32 wakeBit, struct goldfish_pipe *pipe) { in goldfish_pipe_wait_event() argument
358 while (test_bit(wakeBit, &pipe->flags)) { in goldfish_pipe_wait_event()
360 pipe->wake_queue, in goldfish_pipe_wait_event()
361 !test_bit(wakeBit, &pipe->flags))) in goldfish_pipe_wait_event()
364 if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) in goldfish_pipe_wait_event()
370 static int wait_for_host_signal(struct goldfish_pipe *pipe, int is_write) in wait_for_host_signal() argument
373 set_bit(wakeBit, &pipe->flags); in wait_for_host_signal()
376 (void)goldfish_pipe_cmd(pipe, in wait_for_host_signal()
379 return goldfish_pipe_wait_event(wakeBit, pipe); in wait_for_host_signal()
385 struct goldfish_pipe *pipe = filp->private_data; in goldfish_pipe_read_write() local
391 if (unlikely(test_bit(BIT_CLOSED_ON_HOST, &pipe->flags))) in goldfish_pipe_read_write()
409 ret = transfer_max_buffers(pipe, address, address_end, is_write, in goldfish_pipe_read_write()
448 status = wait_for_host_signal(pipe, is_write); in goldfish_pipe_read_write()
475 struct goldfish_pipe *pipe = filp->private_data; in goldfish_pipe_poll() local
479 poll_wait(filp, &pipe->wake_queue, wait); in goldfish_pipe_poll()
481 status = goldfish_pipe_cmd(pipe, PIPE_CMD_POLL); in goldfish_pipe_poll()
492 if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags)) in goldfish_pipe_poll()
501 struct goldfish_pipe *pipe; in signalled_pipes_add_locked() local
505 pipe = dev->pipes[id]; in signalled_pipes_add_locked()
506 if (!pipe) in signalled_pipes_add_locked()
508 pipe->signalled_flags |= flags; in signalled_pipes_add_locked()
510 if (pipe->prev_signalled || pipe->next_signalled in signalled_pipes_add_locked()
511 || dev->first_signalled_pipe == pipe) in signalled_pipes_add_locked()
513 pipe->next_signalled = dev->first_signalled_pipe; in signalled_pipes_add_locked()
515 dev->first_signalled_pipe->prev_signalled = pipe; in signalled_pipes_add_locked()
517 dev->first_signalled_pipe = pipe; in signalled_pipes_add_locked()
521 struct goldfish_pipe *pipe) { in signalled_pipes_remove_locked() argument
522 if (pipe->prev_signalled) in signalled_pipes_remove_locked()
523 pipe->prev_signalled->next_signalled = pipe->next_signalled; in signalled_pipes_remove_locked()
524 if (pipe->next_signalled) in signalled_pipes_remove_locked()
525 pipe->next_signalled->prev_signalled = pipe->prev_signalled; in signalled_pipes_remove_locked()
526 if (pipe == dev->first_signalled_pipe) in signalled_pipes_remove_locked()
527 dev->first_signalled_pipe = pipe->next_signalled; in signalled_pipes_remove_locked()
528 pipe->prev_signalled = NULL; in signalled_pipes_remove_locked()
529 pipe->next_signalled = NULL; in signalled_pipes_remove_locked()
535 struct goldfish_pipe *pipe; in signalled_pipes_pop_front() local
539 pipe = dev->first_signalled_pipe; in signalled_pipes_pop_front()
540 if (pipe) { in signalled_pipes_pop_front()
541 *wakes = pipe->signalled_flags; in signalled_pipes_pop_front()
542 pipe->signalled_flags = 0; in signalled_pipes_pop_front()
548 dev->first_signalled_pipe = pipe->next_signalled; in signalled_pipes_pop_front()
551 pipe->next_signalled = NULL; in signalled_pipes_pop_front()
555 return pipe; in signalled_pipes_pop_front()
558 static void goldfish_pipe_dma_clear_lock(struct goldfish_pipe *pipe) { in goldfish_pipe_dma_clear_lock() argument
559 DPRINT("PIPE_WAKE_UNLOCK_DMA: unlock pipe dma for pipe 0x%p\n", pipe); in goldfish_pipe_dma_clear_lock()
560 if (pipe->dma) { in goldfish_pipe_dma_clear_lock()
561 WARN_ON(!pipe->dma->locked); in goldfish_pipe_dma_clear_lock()
562 clear_bit(BIT_WAKE_ON_UNLOCK_DMA, &pipe->flags); in goldfish_pipe_dma_clear_lock()
563 pipe->dma->locked = false; in goldfish_pipe_dma_clear_lock()
572 struct goldfish_pipe *pipe; in goldfish_interrupt_task() local
574 while ((pipe = signalled_pipes_pop_front(goldfish_pipe_dev, &wakes)) != in goldfish_interrupt_task()
577 pipe->flags = 1 << BIT_CLOSED_ON_HOST; in goldfish_interrupt_task()
580 goldfish_pipe_dma_clear_lock(pipe); in goldfish_interrupt_task()
582 clear_bit(BIT_WAKE_ON_READ, &pipe->flags); in goldfish_interrupt_task()
584 clear_bit(BIT_WAKE_ON_WRITE, &pipe->flags); in goldfish_interrupt_task()
590 wake_up_interruptible(&pipe->wake_queue); in goldfish_interrupt_task()
681 struct goldfish_pipe *pipe = kzalloc(sizeof(*pipe), GFP_KERNEL); in goldfish_pipe_open() local
682 if (pipe == NULL) { in goldfish_pipe_open()
687 pipe->dev = dev; in goldfish_pipe_open()
688 mutex_init(&pipe->lock); in goldfish_pipe_open()
689 init_waitqueue_head(&pipe->wake_queue); in goldfish_pipe_open()
695 pipe->command_buffer = in goldfish_pipe_open()
697 if (!pipe->command_buffer) { in goldfish_pipe_open()
712 dev->pipes[id] = pipe; in goldfish_pipe_open()
713 pipe->id = id; in goldfish_pipe_open()
714 pipe->command_buffer->id = id; in goldfish_pipe_open()
720 (u64)(unsigned long)__pa(pipe->command_buffer); in goldfish_pipe_open()
721 status = goldfish_pipe_cmd_locked(pipe, PIPE_CMD_OPEN); in goldfish_pipe_open()
728 pipe->dma = NULL; in goldfish_pipe_open()
731 file->private_data = pipe; in goldfish_pipe_open()
732 DPRINT("%s on 0x%p\n", __FUNCTION__, pipe); in goldfish_pipe_open()
740 free_page((unsigned long)pipe->command_buffer); in goldfish_pipe_open()
742 kfree(pipe); in goldfish_pipe_open()
746 static void goldfish_pipe_dma_release(struct goldfish_pipe *pipe) { in goldfish_pipe_dma_release() argument
747 struct goldfish_dma_context *dma = pipe->dma; in goldfish_pipe_dma_release()
753 pipe->command_buffer->dma_maphost_params.dma_paddr = dma->phys_begin; in goldfish_pipe_dma_release()
754 pipe->command_buffer->dma_maphost_params.sz = dma->dma_size; in goldfish_pipe_dma_release()
755 goldfish_pipe_cmd(pipe, PIPE_CMD_DMA_HOST_UNMAP); in goldfish_pipe_dma_release()
762 pipe->dev->dma_alloc_total -= dma->dma_size; in goldfish_pipe_dma_release()
765 dma->phys_begin, pipe->dev->dma_alloc_total); in goldfish_pipe_dma_release()
769 pipe->dma = NULL; in goldfish_pipe_dma_release()
775 struct goldfish_pipe *pipe = filp->private_data; in goldfish_pipe_release() local
776 struct goldfish_pipe_dev *dev = pipe->dev; in goldfish_pipe_release()
778 DPRINT("%s on 0x%p\n", __FUNCTION__, pipe); in goldfish_pipe_release()
783 goldfish_pipe_dma_release(pipe); in goldfish_pipe_release()
786 (void)goldfish_pipe_cmd(pipe, PIPE_CMD_CLOSE); in goldfish_pipe_release()
789 dev->pipes[pipe->id] = NULL; in goldfish_pipe_release()
790 signalled_pipes_remove_locked(dev, pipe); in goldfish_pipe_release()
795 free_page((unsigned long)pipe->command_buffer); in goldfish_pipe_release()
796 kfree(pipe); in goldfish_pipe_release()
833 static void goldfish_pipe_dma_alloc_locked(struct goldfish_pipe *pipe) { in goldfish_pipe_dma_alloc_locked() argument
837 __FUNCTION__, pipe); in goldfish_pipe_dma_alloc_locked()
839 dma = pipe->dma; in goldfish_pipe_dma_alloc_locked()
858 pipe->dev->dma_alloc_total += dma->dma_size; in goldfish_pipe_dma_alloc_locked()
866 pipe->dev->dma_alloc_total); in goldfish_pipe_dma_alloc_locked()
867 pipe->command_buffer->dma_maphost_params.dma_paddr = dma->phys_begin; in goldfish_pipe_dma_alloc_locked()
868 pipe->command_buffer->dma_maphost_params.sz = dma->dma_size; in goldfish_pipe_dma_alloc_locked()
869 goldfish_pipe_cmd(pipe, PIPE_CMD_DMA_HOST_MAP); in goldfish_pipe_dma_alloc_locked()
877 struct goldfish_pipe *pipe = (struct goldfish_pipe *)(filp->private_data); in goldfish_dma_mmap() local
878 struct goldfish_dma_context *dma = pipe->dma; in goldfish_dma_mmap()
892 goldfish_pipe_dma_alloc_locked(pipe); in goldfish_dma_mmap()
917 struct goldfish_pipe *pipe, in goldfish_pipe_dma_create_region() argument
929 mutex_lock(&pipe->lock); in goldfish_pipe_dma_create_region()
930 pipe->dma = dma; in goldfish_pipe_dma_create_region()
931 pipe->dma->pdev_dev = pipe->dev->pdev_dev; in goldfish_pipe_dma_create_region()
932 mutex_unlock(&pipe->lock); in goldfish_pipe_dma_create_region()
935 static int goldfish_pipe_dma_acquire_lock(struct goldfish_pipe *pipe) { in goldfish_pipe_dma_acquire_lock() argument
937 if (pipe->dma && pipe->dma->locked) { in goldfish_pipe_dma_acquire_lock()
938 set_bit(BIT_WAKE_ON_UNLOCK_DMA, &pipe->flags); in goldfish_pipe_dma_acquire_lock()
939 return goldfish_pipe_wait_event(BIT_WAKE_ON_UNLOCK_DMA, pipe); in goldfish_pipe_dma_acquire_lock()
940 } else if (pipe->dma) { in goldfish_pipe_dma_acquire_lock()
941 pipe->dma->locked = true; in goldfish_pipe_dma_acquire_lock()
953 struct goldfish_pipe *pipe; in goldfish_dma_ioctl() local
959 pipe = (struct goldfish_pipe *)(file->private_data); in goldfish_dma_ioctl()
961 dma = pipe->dma; in goldfish_dma_ioctl()
972 DPRINT("LOCK_DMA for pipe 0x%p\n", pipe); in goldfish_dma_ioctl()
973 ret = goldfish_pipe_dma_acquire_lock(pipe); in goldfish_dma_ioctl()
975 DPRINT("acquired lock, proceeding for pipe 0x%p\n", pipe); in goldfish_dma_ioctl()
979 DPRINT("UNLOCK_DMA for pipe 0x%p\n", pipe); in goldfish_dma_ioctl()
980 goldfish_pipe_dma_clear_lock(pipe); in goldfish_dma_ioctl()
981 wake_up_interruptible(&pipe->wake_queue); in goldfish_dma_ioctl()
984 DPRINT("DMA_GETOFF for pipe 0x%p\n", pipe); in goldfish_dma_ioctl()
992 DPRINT("DMA_CREATE_REGION for pipe 0x%p\n", pipe); in goldfish_dma_ioctl()
998 goldfish_pipe_dma_create_region(pipe, ioctl_data.size); in goldfish_dma_ioctl()