ddfiface.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Vojtech Horky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #include <ipc/devman.h>
00036 #include <devman.h>
00037 #include <async.h>
00038 #include <usb/ddfiface.h>
00039 #include <usb/hc.h>
00040 #include <usb/debug.h>
00041 #include <errno.h>
00042 #include <assert.h>
00043 
00045 usb_iface_t  usb_iface_hub_impl = {
00046         .get_hc_handle = usb_iface_get_hc_handle_hub_impl,
00047         .get_address = usb_iface_get_address_hub_impl
00048 };
00049 
00051 usb_iface_t  usb_iface_hub_child_impl = {
00052         .get_hc_handle = usb_iface_get_hc_handle_hub_child_impl,
00053         .get_address = usb_iface_get_address_hub_child_impl
00054 };
00055 
00056 
00063 int usb_iface_get_hc_handle_hub_impl(ddf_fun_t *fun, devman_handle_t *handle)
00064 {
00065         assert(fun);
00066         return usb_hc_find(fun->handle, handle);
00067 }
00068 
00076 int usb_iface_get_hc_handle_hub_child_impl(ddf_fun_t *fun,
00077     devman_handle_t *handle)
00078 {
00079         assert(fun != NULL);
00080 
00081         int parent_phone = devman_parent_device_connect(fun->handle,
00082             IPC_FLAG_BLOCKING);
00083         if (parent_phone < 0) {
00084                 return parent_phone;
00085         }
00086 
00087         sysarg_t hc_handle;
00088         int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
00089             IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &hc_handle);
00090 
00091         async_hangup(parent_phone);
00092 
00093         if (rc != EOK) {
00094                 return rc;
00095         }
00096 
00097         *handle = hc_handle;
00098 
00099         return EOK;
00100 }
00101 
00108 int usb_iface_get_hc_handle_hc_impl(ddf_fun_t *fun, devman_handle_t *handle)
00109 {
00110         assert(fun);
00111 
00112         if (handle != NULL) {
00113                 *handle = fun->handle;
00114         }
00115 
00116         return EOK;
00117 }
00118 
00126 int usb_iface_get_address_hub_impl(ddf_fun_t *fun, devman_handle_t handle,
00127     usb_address_t *address)
00128 {
00129         assert(fun);
00130         int parent_phone = devman_parent_device_connect(fun->handle,
00131             IPC_FLAG_BLOCKING);
00132         if (parent_phone < 0) {
00133                 return parent_phone;
00134         }
00135 
00136         sysarg_t addr;
00137         int rc = async_req_2_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
00138             IPC_M_USB_GET_ADDRESS, handle, &addr);
00139 
00140         async_hangup(parent_phone);
00141 
00142         if (rc != EOK) {
00143                 return rc;
00144         }
00145 
00146         if (address != NULL) {
00147                 *address = (usb_address_t) addr;
00148         }
00149 
00150         return EOK;
00151 }
00152 
00161 int usb_iface_get_address_hub_child_impl(ddf_fun_t *fun,
00162     devman_handle_t handle, usb_address_t *address)
00163 {
00164         if (handle == 0) {
00165                 handle = fun->handle;
00166         }
00167         return usb_iface_get_address_hub_impl(fun, handle, address);
00168 }
00169 

Generated on Thu Jun 2 07:45:48 2011 for HelenOS/USB by  doxygen 1.4.7