| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Vojtech Horky
|
|---|
| 3 | * Copyright (c) 2011 Jan Vesely
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 | /** @addtogroup libusbdev
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * USB endpoint pipes miscellaneous functions.
|
|---|
| 34 | */
|
|---|
| 35 | #include <usb_iface.h>
|
|---|
| 36 | #include <usb/dev/pipes.h>
|
|---|
| 37 | #include <usb/dev.h>
|
|---|
| 38 | #include <errno.h>
|
|---|
| 39 | #include <assert.h>
|
|---|
| 40 | #include "pipepriv.h"
|
|---|
| 41 |
|
|---|
| 42 | /** Tell USB interface assigned to given device.
|
|---|
| 43 | *
|
|---|
| 44 | * @param device Device in question.
|
|---|
| 45 | * @return Error code (ENOTSUP means any).
|
|---|
| 46 | */
|
|---|
| 47 | int usb_device_get_assigned_interface(const ddf_dev_t *device)
|
|---|
| 48 | {
|
|---|
| 49 | assert(device);
|
|---|
| 50 | async_sess_t *parent_sess =
|
|---|
| 51 | devman_parent_device_connect(EXCHANGE_ATOMIC, device->handle,
|
|---|
| 52 | IPC_FLAG_BLOCKING);
|
|---|
| 53 | if (!parent_sess)
|
|---|
| 54 | return ENOMEM;
|
|---|
| 55 |
|
|---|
| 56 | async_exch_t *exch = async_exchange_begin(parent_sess);
|
|---|
| 57 | if (!exch) {
|
|---|
| 58 | async_hangup(parent_sess);
|
|---|
| 59 | return ENOMEM;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | int iface_no;
|
|---|
| 63 | const int ret = usb_get_my_interface(exch, &iface_no);
|
|---|
| 64 |
|
|---|
| 65 | return ret == EOK ? iface_no : ret;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | /** Prepare pipe for a long transfer.
|
|---|
| 69 | *
|
|---|
| 70 | * By a long transfer is mean transfer consisting of several
|
|---|
| 71 | * requests to the HC.
|
|---|
| 72 | * Calling such function is optional and it has positive effect of
|
|---|
| 73 | * improved performance because IPC session is initiated only once.
|
|---|
| 74 | *
|
|---|
| 75 | * @param pipe Pipe over which the transfer will happen.
|
|---|
| 76 | * @return Error code.
|
|---|
| 77 | */
|
|---|
| 78 | void usb_pipe_start_long_transfer(usb_pipe_t *pipe)
|
|---|
| 79 | {
|
|---|
| 80 | (void) pipe_add_ref(pipe, true);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | /** Terminate a long transfer on a pipe.
|
|---|
| 84 | *
|
|---|
| 85 | * @see usb_pipe_start_long_transfer
|
|---|
| 86 | *
|
|---|
| 87 | * @param pipe Pipe where to end the long transfer.
|
|---|
| 88 | */
|
|---|
| 89 | void usb_pipe_end_long_transfer(usb_pipe_t *pipe)
|
|---|
| 90 | {
|
|---|
| 91 | pipe_drop_ref(pipe);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | /**
|
|---|
| 95 | * @}
|
|---|
| 96 | */
|
|---|