Changeset e27595b in mainline


Ignore:
Timestamp:
2010-11-20T13:04:15Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0e126be7
Parents:
7034be15
Message:

Virtual USB devices can connect to VHC

Fixed and bypassed problems introduced by using DDF.

Location:
uspace
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/virtusbkbd/virtusbkbd.c

    r7034be15 re27595b  
    5858#define NAME "virt-usb-kbd"
    5959
    60 #define DEV_HCD_NAME "hcd-virt-dev"
    6160
    6261#define __QUOTEME(x) #x
     
    216215       
    217216       
    218         int rc = usbvirt_connect(&keyboard_dev, DEV_HCD_NAME);
     217        int rc = usbvirt_connect(&keyboard_dev);
    219218        if (rc != EOK) {
    220                 printf("%s: Unable to start comunication with VHCD at usb://%s (%s).\n",
    221                     NAME, DEV_HCD_NAME, str_error(rc));
     219                printf("%s: Unable to start communication with VHCD (%s).\n",
     220                    NAME, str_error(rc));
    222221                return rc;
    223222        }
  • uspace/drv/vhc/conn.h

    r7034be15 re27595b  
    4242
    4343void connection_handler_host(ipcarg_t);
    44 void connection_handler_device(ipcarg_t, virtdev_connection_t *);
     44
    4545usb_hcd_transfer_ops_t vhc_transfer_ops;
     46
     47void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
     48
    4649
    4750#endif
  • uspace/drv/vhc/conndev.c

    r7034be15 re27595b  
    7474}
    7575
    76 /** Connection handler for communcation with virtual device.
     76/** Default handler for IPC methods not handled by DDF.
    7777 *
    78  * This function also takes care of proper phone hung-up.
    79  *
    80  * @param phone_hash Incoming phone hash.
    81  * @param dev Virtual device handle.
     78 * @param dev Device handling the call.
     79 * @param icallid Call id.
     80 * @param icall Call data.
    8281 */
    83 void connection_handler_device(ipcarg_t phone_hash, virtdev_connection_t *dev)
     82void default_connection_handler(device_t *dev,
     83    ipc_callid_t icallid, ipc_call_t *icall)
    8484{
    85         assert(dev != NULL);
    86        
    87         char devname[DEVICE_NAME_MAXLENGTH + 1];
    88         int rc = get_device_name(dev->phone, devname, DEVICE_NAME_MAXLENGTH);
    89        
    90         dprintf(0, "virtual device connected (phone: %#x, name: %s)",
    91             phone_hash, rc == EOK ? devname : "<unknown>");
    92        
    93        
    94         while (true) {
    95                 ipc_callid_t callid;
    96                 ipc_call_t call;
    97                
    98                 callid = async_get_call(&call);
    99                
    100                 switch (IPC_GET_METHOD(call)) {
    101                         case IPC_M_PHONE_HUNGUP:
    102                                 ipc_hangup(dev->phone);
    103                                 ipc_answer_0(callid, EOK);
    104                                 dprintf(0, "phone%#x: device hung-up",
    105                                     phone_hash);
    106                                 return;
    107                        
    108                         case IPC_M_CONNECT_TO_ME:
    109                                 ipc_answer_0(callid, ELIMIT);
    110                                 break;
    111                        
    112                         default:
    113                                 dprintf_inval_call(2, call, phone_hash);
    114                                 ipc_answer_0(callid, EINVAL);
    115                                 break;
     85        ipcarg_t method = IPC_GET_METHOD(*icall);
     86
     87        if (method == IPC_M_CONNECT_TO_ME) {
     88                int callback = IPC_GET_ARG5(*icall);
     89                virtdev_connection_t *dev
     90                    = virtdev_add_device(callback);
     91                if (!dev) {
     92                        ipc_answer_0(icallid, EEXISTS);
     93                        ipc_hangup(callback);
     94                        return;
    11695                }
     96                ipc_answer_0(icallid, EOK);
     97
     98                char devname[DEVICE_NAME_MAXLENGTH + 1];
     99                int rc = get_device_name(callback, devname, DEVICE_NAME_MAXLENGTH);
     100
     101                dprintf(0, "virtual device connected (name: %s)",
     102                    rc == EOK ? devname : "<unknown>");
     103
     104                /* FIXME: destroy the device when the client disconnects. */
     105
     106                return;
    117107        }
     108
     109        ipc_answer_0(icallid, EINVAL);
    118110}
     111
    119112
    120113/**
  • uspace/drv/vhc/devices.h

    r7034be15 re27595b  
    5050
    5151virtdev_connection_t *virtdev_add_device(int);
     52virtdev_connection_t *virtdev_get_mine(void);
    5253void virtdev_destroy_device(virtdev_connection_t *);
    5354usb_transaction_outcome_t virtdev_send_to_all(transaction_t *);
  • uspace/drv/vhc/hcd.c

    r7034be15 re27595b  
    5252#include "conn.h"
    5353
     54
    5455static int vhc_count = 0;
    5556static int vhc_add_device(usb_hc_device_t *dev)
    5657{
    57         printf("%s: new device registered.\n", NAME);
    5858        /*
    5959         * Currently, we know how to simulate only single HC.
     
    6666
    6767        dev->transfer_ops = &vhc_transfer_ops;
     68        dev->generic->ops->default_handler = default_connection_handler;
    6869
    6970        /*
     
    7172         */
    7273        usb_hcd_add_root_hub(dev);
     74
     75        printf("%s: virtual USB host controller ready.\n", NAME);
    7376
    7477        return EOK;
     
    8487        printf("%s: virtual USB host controller driver.\n", NAME);
    8588
     89        debug_level = 5;
     90
    8691        return usb_hcd_main(&vhc_driver);
    8792}
  • uspace/lib/usb/hcdhubd.c

    r7034be15 re27595b  
    7676
    7777                hc_dev->generic = dev;
     78                dev->ops = &usb_device_ops;
     79                hc_dev->generic->driver_data = hc_dev;
     80
    7881                int rc = hc_driver->add_hc(hc_dev);
    7982                if (rc != EOK) {
     
    8184                        return rc;
    8285                }
    83 
    84                 /*
    85                  * Finish initialization of dev and hc_dev structures.
    86                  */
    87                 hc_dev->generic->driver_data = hc_dev;
    88                 dev->ops = &usb_device_ops;
    8986
    9087                /*
  • uspace/lib/usbvirt/hub.h

    r7034be15 re27595b  
    5959} usbvirt_device_method_t;
    6060
    61 int usbvirt_connect(usbvirt_device_t *, const char *);
     61int usbvirt_connect(usbvirt_device_t *);
    6262int usbvirt_connect_local(usbvirt_device_t *);
    6363int usbvirt_disconnect(usbvirt_device_t *dev);
  • uspace/lib/usbvirt/main.c

    r7034be15 re27595b  
    3333 * @brief Device registration with virtual USB framework.
    3434 */
    35 #include <devmap.h>
    36 #include <fcntl.h>
    37 #include <vfs/vfs.h>
     35#include <devman.h>
    3836#include <errno.h>
    3937#include <stdlib.h>
     
    181179                return;
    182180        }
    183        
     181
    184182        device_callback_connection(dev->device, iid, icall);
    185183}
     
    187185/** Create necessary phones for comunication with virtual HCD.
    188186 * This function wraps following calls:
    189  * -# open <code>/dev/usb/<i>hcd_path</i></code> for reading
     187 * -# open <code>/dev/devices/\\vhc for reading
    190188 * -# access phone of file opened in previous step
    191189 * -# create callback through just opened phone
     
    202200 * @return EOK on success or error code from errno.h.
    203201 */
    204 int usbvirt_connect(usbvirt_device_t *dev, const char *hcd_path)
     202int usbvirt_connect(usbvirt_device_t *dev)
    205203{
    206204        virtual_device_t *virtual_device = find_device(dev);
     
    209207        }
    210208       
    211         char dev_path[DEVMAP_NAME_MAXLEN + 1];
    212         snprintf(dev_path, DEVMAP_NAME_MAXLEN,
    213             "/dev/%s/%s", NAMESPACE, hcd_path);
    214        
    215         int fd = open(dev_path, O_RDONLY);
    216         if (fd < 0) {
    217                 return fd;
    218         }
    219        
    220         int hcd_phone = fd_phone(fd);
     209        const char *vhc_path = "/vhc";
     210        int rc;
     211        devman_handle_t handle;
     212
     213        rc = devman_device_get_handle(vhc_path, &handle, 0);
     214        if (rc != EOK) {
     215                printf("devman_device_get_handle() failed\n");
     216                return rc;
     217        }
     218       
     219        int hcd_phone = devman_device_connect(handle, 0);
    221220       
    222221        if (hcd_phone < 0) {
     222                printf("devman_device_connect() failed\n");
    223223                return hcd_phone;
    224224        }
    225225       
    226226        ipcarg_t phonehash;
    227         int rc = ipc_connect_to_me(hcd_phone, 0, 0, 0, &phonehash);
     227        rc = ipc_connect_to_me(hcd_phone, 0, 0, 0, &phonehash);
    228228        if (rc != EOK) {
     229                printf("ipc_connect_to_me() failed\n");
    229230                return rc;
    230231        }
Note: See TracChangeset for help on using the changeset viewer.