[a045ab1] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jan Vesely
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #include <usb/dev.h>
|
---|
| 30 | #include <errno.h>
|
---|
| 31 | #include <usb_iface.h>
|
---|
| 32 |
|
---|
| 33 | /** Tell USB address assigned to device with given handle.
|
---|
| 34 | *
|
---|
| 35 | * @param dev_handle Devman handle of the USB device in question.
|
---|
| 36 | * @return USB address or negative error code.
|
---|
| 37 | */
|
---|
| 38 | usb_address_t usb_get_address_by_handle(devman_handle_t dev_handle)
|
---|
| 39 | {
|
---|
| 40 | async_sess_t *parent_sess =
|
---|
| 41 | devman_parent_device_connect(EXCHANGE_ATOMIC, dev_handle,
|
---|
| 42 | IPC_FLAG_BLOCKING);
|
---|
| 43 | if (!parent_sess)
|
---|
| 44 | return ENOMEM;
|
---|
| 45 |
|
---|
| 46 | async_exch_t *exch = async_exchange_begin(parent_sess);
|
---|
| 47 | if (!exch) {
|
---|
| 48 | async_hangup(parent_sess);
|
---|
| 49 | return ENOMEM;
|
---|
| 50 | }
|
---|
| 51 | usb_address_t address;
|
---|
| 52 | const int ret = usb_get_my_address(exch, &address);
|
---|
| 53 |
|
---|
| 54 | async_exchange_end(exch);
|
---|
| 55 | async_hangup(parent_sess);
|
---|
| 56 |
|
---|
| 57 | if (ret != EOK)
|
---|
| 58 | return ret;
|
---|
| 59 |
|
---|
| 60 | return address;
|
---|
| 61 | }
|
---|
| 62 | /*----------------------------------------------------------------------------*/
|
---|
| 63 | /** Find host controller handle for the device.
|
---|
| 64 | *
|
---|
| 65 | * @param[in] device_handle Device devman handle.
|
---|
| 66 | * @param[out] hc_handle Where to store handle of host controller
|
---|
| 67 | * controlling device with @p device_handle handle.
|
---|
| 68 | * @return Error code.
|
---|
| 69 | */
|
---|
| 70 | int usb_find_hc(devman_handle_t device_handle, devman_handle_t *hc_handle)
|
---|
| 71 | {
|
---|
| 72 | async_sess_t *parent_sess =
|
---|
| 73 | devman_parent_device_connect(EXCHANGE_ATOMIC, device_handle,
|
---|
| 74 | IPC_FLAG_BLOCKING);
|
---|
| 75 | if (!parent_sess)
|
---|
| 76 | return ENOMEM;
|
---|
| 77 |
|
---|
| 78 | async_exch_t *exch = async_exchange_begin(parent_sess);
|
---|
| 79 | if (!exch) {
|
---|
| 80 | async_hangup(parent_sess);
|
---|
| 81 | return ENOMEM;
|
---|
| 82 | }
|
---|
| 83 | const int ret = usb_get_hc_handle(exch, hc_handle);
|
---|
| 84 |
|
---|
| 85 | async_exchange_end(exch);
|
---|
| 86 | async_hangup(parent_sess);
|
---|
| 87 |
|
---|
| 88 | return ret;
|
---|
| 89 | }
|
---|