00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <usb/usb.h>
00036 #include <usb/dev/pipes.h>
00037 #include <usb/debug.h>
00038 #include <usb/hc.h>
00039 #include <usbhc_iface.h>
00040 #include <usb_iface.h>
00041 #include <devman.h>
00042 #include <errno.h>
00043 #include <assert.h>
00044 #include "pipepriv.h"
00045
00046 #define IPC_AGAIN_DELAY (1000 * 2)
00047
00054 static usb_address_t get_my_address(int phone, ddf_dev_t *dev)
00055 {
00056 sysarg_t address;
00057
00058
00059
00060
00061
00062
00063 int rc = async_req_2_1(phone, DEV_IFACE_ID(USB_DEV_IFACE),
00064 IPC_M_USB_GET_ADDRESS,
00065 0, &address);
00066
00067 if (rc != EOK) {
00068 return rc;
00069 }
00070
00071 return (usb_address_t) address;
00072 }
00073
00079 int usb_device_get_assigned_interface(ddf_dev_t *device)
00080 {
00081 int parent_phone = devman_parent_device_connect(device->handle,
00082 IPC_FLAG_BLOCKING);
00083 if (parent_phone < 0) {
00084 return -1;
00085 }
00086
00087 sysarg_t iface_no;
00088 int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
00089 IPC_M_USB_GET_INTERFACE,
00090 device->handle, &iface_no);
00091
00092 async_hangup(parent_phone);
00093
00094 if (rc != EOK) {
00095 return -1;
00096 }
00097
00098 return (int) iface_no;
00099 }
00100
00107 int usb_device_connection_initialize_from_device(
00108 usb_device_connection_t *connection, ddf_dev_t *dev)
00109 {
00110 assert(connection);
00111 assert(dev);
00112
00113 int rc;
00114 devman_handle_t hc_handle;
00115 usb_address_t my_address;
00116
00117 rc = usb_hc_find(dev->handle, &hc_handle);
00118 if (rc != EOK) {
00119 return rc;
00120 }
00121
00122 int parent_phone = devman_parent_device_connect(dev->handle,
00123 IPC_FLAG_BLOCKING);
00124 if (parent_phone < 0) {
00125 return parent_phone;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 do {
00140 my_address = get_my_address(parent_phone, dev);
00141
00142 if (my_address == ENOENT) {
00143
00144 async_usleep(IPC_AGAIN_DELAY);
00145 } else if (my_address < 0) {
00146
00147 rc = my_address;
00148 goto leave;
00149 }
00150
00151 } while (my_address < 0);
00152
00153 rc = usb_device_connection_initialize(connection,
00154 hc_handle, my_address);
00155
00156 leave:
00157 async_hangup(parent_phone);
00158 return rc;
00159 }
00160
00169 int usb_device_connection_initialize(usb_device_connection_t *connection,
00170 devman_handle_t host_controller_handle, usb_address_t device_address)
00171 {
00172 assert(connection);
00173
00174 if ((device_address < 0) || (device_address >= USB11_ADDRESS_MAX)) {
00175 return EINVAL;
00176 }
00177
00178 connection->hc_handle = host_controller_handle;
00179 connection->address = device_address;
00180
00181 return EOK;
00182 }
00183
00190 int usb_device_connection_initialize_on_default_address(
00191 usb_device_connection_t *dev_connection,
00192 usb_hc_connection_t *hc_connection)
00193 {
00194 assert(dev_connection);
00195
00196 if (hc_connection == NULL) {
00197 return EBADMEM;
00198 }
00199
00200 return usb_device_connection_initialize(dev_connection,
00201 hc_connection->hc_handle, (usb_address_t) 0);
00202 }
00203
00214 void usb_pipe_start_long_transfer(usb_pipe_t *pipe)
00215 {
00216 (void) pipe_add_ref(pipe, true);
00217 }
00218
00225 void usb_pipe_end_long_transfer(usb_pipe_t *pipe)
00226 {
00227 pipe_drop_ref(pipe);
00228 }
00229