[6865243c] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Vojtech Horky
|
---|
[bd575647] | 3 | * Copyright (c) 2011 Jan Vesely
|
---|
[6865243c] | 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 | */
|
---|
[160b75e] | 29 | /** @addtogroup libusbdev
|
---|
[6865243c] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
[dc04868] | 33 | * USB endpoint pipes miscellaneous functions.
|
---|
[6865243c] | 34 | */
|
---|
[357a302] | 35 | #include <usb_iface.h>
|
---|
[bd575647] | 36 | #include <usb/dev/pipes.h>
|
---|
| 37 | #include <usb/dev.h>
|
---|
[6865243c] | 38 | #include <errno.h>
|
---|
[43f698b] | 39 | #include <assert.h>
|
---|
[a546687] | 40 | #include "pipepriv.h"
|
---|
[563fb40] | 41 |
|
---|
[27a0012] | 42 | /** Tell USB interface assigned to given device.
|
---|
| 43 | *
|
---|
| 44 | * @param device Device in question.
|
---|
[56bdd9a4] | 45 | * @return Error code (ENOTSUP means any).
|
---|
[27a0012] | 46 | */
|
---|
[8e5ce07] | 47 | int usb_device_get_assigned_interface(const ddf_dev_t *device)
|
---|
[27a0012] | 48 | {
|
---|
[7fc260ff] | 49 | assert(device);
|
---|
[79ae36dd] | 50 | async_sess_t *parent_sess =
|
---|
[9f7276d] | 51 | devman_parent_device_connect(EXCHANGE_ATOMIC, device->handle,
|
---|
[27a0012] | 52 | IPC_FLAG_BLOCKING);
|
---|
[79ae36dd] | 53 | if (!parent_sess)
|
---|
[56bdd9a4] | 54 | return ENOMEM;
|
---|
| 55 |
|
---|
[79ae36dd] | 56 | async_exch_t *exch = async_exchange_begin(parent_sess);
|
---|
[56bdd9a4] | 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;
|
---|
[27a0012] | 66 | }
|
---|
| 67 |
|
---|
[e9ce696] | 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 | */
|
---|
[2c2cbcf] | 78 | void usb_pipe_start_long_transfer(usb_pipe_t *pipe)
|
---|
[e9ce696] | 79 | {
|
---|
[2c2cbcf] | 80 | (void) pipe_add_ref(pipe, true);
|
---|
[e9ce696] | 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 |
|
---|
[6865243c] | 94 | /**
|
---|
| 95 | * @}
|
---|
| 96 | */
|
---|