| 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 libusb
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * General communication with host controller.
|
|---|
| 34 | */
|
|---|
| 35 | #ifndef LIBUSB_HC_H_
|
|---|
| 36 | #define LIBUSB_HC_H_
|
|---|
| 37 |
|
|---|
| 38 | #include <async.h>
|
|---|
| 39 | #include <devman.h>
|
|---|
| 40 | #include <ddf/driver.h>
|
|---|
| 41 | #include <stdbool.h>
|
|---|
| 42 | #include <fibril_synch.h>
|
|---|
| 43 | #include <usb/usb.h>
|
|---|
| 44 |
|
|---|
| 45 | /** Connection to the host controller driver.
|
|---|
| 46 | *
|
|---|
| 47 | * This is a high level IPC communication wrapper. After the structure has been
|
|---|
| 48 | * initialized using devman handle of an USB host controller, it
|
|---|
| 49 | * will manage all communication to that host controller, including session
|
|---|
| 50 | * creation/destruction and proper IPC protocol.
|
|---|
| 51 | */
|
|---|
| 52 | typedef struct {
|
|---|
| 53 | /** Devman handle of the host controller. */
|
|---|
| 54 | devman_handle_t hc_handle;
|
|---|
| 55 | /** Session to the host controller. */
|
|---|
| 56 | async_sess_t *hc_sess;
|
|---|
| 57 | /** Session guard. */
|
|---|
| 58 | fibril_mutex_t guard;
|
|---|
| 59 | /** Use counter. */
|
|---|
| 60 | unsigned ref_count;
|
|---|
| 61 | } usb_hc_connection_t;
|
|---|
| 62 |
|
|---|
| 63 | /** Initialize connection to USB host controller.
|
|---|
| 64 | *
|
|---|
| 65 | * @param connection Connection to be initialized.
|
|---|
| 66 | * @param hc_handle Devman handle of the host controller.
|
|---|
| 67 | * @return Error code.
|
|---|
| 68 | */
|
|---|
| 69 | static inline void usb_hc_connection_initialize(usb_hc_connection_t *connection,
|
|---|
| 70 | devman_handle_t hc_handle)
|
|---|
| 71 | {
|
|---|
| 72 | assert(connection);
|
|---|
| 73 | connection->hc_handle = hc_handle;
|
|---|
| 74 | connection->hc_sess = NULL;
|
|---|
| 75 | connection->ref_count = 0;
|
|---|
| 76 | fibril_mutex_initialize(&connection->guard);
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | int usb_hc_connection_initialize_from_device(usb_hc_connection_t *, ddf_dev_t *);
|
|---|
| 80 |
|
|---|
| 81 | void usb_hc_connection_deinitialize(usb_hc_connection_t *);
|
|---|
| 82 |
|
|---|
| 83 | int usb_hc_connection_open(usb_hc_connection_t *);
|
|---|
| 84 | int usb_hc_connection_close(usb_hc_connection_t *);
|
|---|
| 85 |
|
|---|
| 86 | int usb_hc_get_handle_by_address(usb_hc_connection_t *, usb_address_t,
|
|---|
| 87 | devman_handle_t *);
|
|---|
| 88 |
|
|---|
| 89 | int usb_hc_read(usb_hc_connection_t *, usb_address_t, usb_endpoint_t,
|
|---|
| 90 | uint64_t, void *, size_t, size_t *);
|
|---|
| 91 | int usb_hc_write(usb_hc_connection_t *, usb_address_t, usb_endpoint_t,
|
|---|
| 92 | uint64_t, const void *, size_t);
|
|---|
| 93 |
|
|---|
| 94 | /** Get host controller handle by its class index.
|
|---|
| 95 | *
|
|---|
| 96 | * @param sid Service ID of the HC function.
|
|---|
| 97 | * @param hc_handle Where to store the HC handle
|
|---|
| 98 | * (can be NULL for existence test only).
|
|---|
| 99 | * @return Error code.
|
|---|
| 100 | */
|
|---|
| 101 | static inline int usb_ddf_get_hc_handle_by_sid(
|
|---|
| 102 | service_id_t sid, devman_handle_t *handle)
|
|---|
| 103 | {
|
|---|
| 104 | devman_handle_t h;
|
|---|
| 105 | return devman_fun_sid_to_handle(sid, handle ? handle : &h);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | #endif
|
|---|
| 109 | /**
|
|---|
| 110 | * @}
|
|---|
| 111 | */
|
|---|