Changeset 71ed4849 in mainline


Ignore:
Timestamp:
2010-12-28T14:00:36Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8f8a0cd6
Parents:
de2c901
Message:

Connecting to "parent" host controller

USB drivers can now connect to host controller drivers they physically
belong to (so far, everything connected to VHC).

Each USB device must implement the USB interface of libdrv to allow
this (it is absolutely neccesary for hubs).

USB drivers can use usb_drv_hc_connect() to connect to "their" host
controller.

Child devices created with usb_drv_register_child_in_devman()are set
to handle this connection automatically.

UHCI and VHC drivers were updated.

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/main.c

    rde2c901 r71ed4849  
    2727 */
    2828#include <usb/hcdhubd.h>
     29#include <usb_iface.h>
    2930#include <usb/debug.h>
    3031#include <errno.h>
     
    3233#include "uhci.h"
    3334
     35static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
     36{
     37        /* This shall be called only for the UHCI itself. */
     38        assert(dev->parent == NULL);
     39
     40        *handle = dev->handle;
     41        return EOK;
     42}
     43
     44static usb_iface_t hc_usb_iface = {
     45        .get_hc_handle = usb_iface_get_hc_handle
     46};
     47
    3448static device_ops_t uhci_ops = {
    35         .interfaces[USBHC_DEV_IFACE] = &uhci_iface,
     49        .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
     50        .interfaces[USBHC_DEV_IFACE] = &uhci_iface
    3651};
    3752
  • uspace/drv/usbhub/usbhub.c

    rde2c901 r71ed4849  
    3737#include <errno.h>
    3838
    39 #include <usbhc_iface.h>
     39#include <usb_iface.h>
    4040#include <usb/usbdrv.h>
    4141#include <usb/descriptor.h>
     
    4646#include "usbhub_private.h"
    4747#include "port_status.h"
     48
     49static usb_iface_t hub_usb_iface = {
     50        .get_hc_handle = usb_drv_find_hc
     51};
     52
     53static device_ops_t hub_device_ops = {
     54        .interfaces[USB_DEV_IFACE] = &hub_usb_iface
     55};
    4856
    4957//*********************************************
     
    135143         * connected devices.
    136144         */
     145        dev->ops = &hub_device_ops;
    137146
    138147        //create the hub structure
    139148        //get hc connection
    140         int hc = usb_drv_hc_connect(dev, 0);
     149        int hc = usb_drv_hc_connect_auto(dev, 0);
     150        if (hc < 0) {
     151                return hc;
     152        }
    141153
    142154        usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc);
     
    464476                 * Connect to respective HC.
    465477                 */
    466                 int hc = usb_drv_hc_connect(hub_info->device, 0);
     478                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    467479                if (hc < 0) {
    468480                        continue;
  • uspace/drv/usbkbd/main.c

    rde2c901 r71ed4849  
    190190        // get phone to my HC and save it as my parent's phone
    191191        // TODO: maybe not a good idea if DDF will use parent_phone
    192         kbd_dev->device->parent_phone = usb_drv_hc_connect(dev, 0);
     192        kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
    193193
    194194        kbd_dev->address = usb_drv_get_my_address(dev->parent_phone,
     
    325325         * Not supported yet, skip..
    326326         */
    327 //      int phone = usb_drv_hc_connect(dev, 0);
     327//      int phone = usb_drv_hc_connect_auto(dev, 0);
    328328//      if (phone < 0) {
    329329//              /*
  • uspace/drv/vhc/hcd.c

    rde2c901 r71ed4849  
    4646
    4747#include <usb/usb.h>
     48#include <usb_iface.h>
    4849#include "vhcd.h"
    4950#include "hc.h"
     
    5253#include "conn.h"
    5354
     55static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
     56{
     57        /* This shall be called only for VHC device. */
     58        assert(dev->parent == NULL);
     59
     60        *handle = dev->handle;
     61        return EOK;
     62}
     63
     64static usb_iface_t hc_usb_iface = {
     65        .get_hc_handle = usb_iface_get_hc_handle
     66};
     67
    5468static device_ops_t vhc_ops = {
    5569        .interfaces[USBHC_DEV_IFACE] = &vhc_iface,
     70        .interfaces[USB_DEV_IFACE] = &hc_usb_iface,
    5671        .default_handler = default_connection_handler
    5772};
  • uspace/drv/vhc/hub.c

    rde2c901 r71ed4849  
    7979        device_t *hc_dev = (device_t *) arg;
    8080
    81         int hc = usb_drv_hc_connect(hc_dev, IPC_FLAG_BLOCKING);
     81        int hc = usb_drv_hc_connect(hc_dev, hc_dev->handle, IPC_FLAG_BLOCKING);
    8282        if (hc < 0) {
    8383                printf(NAME ": failed to register root hub\n");
  • uspace/lib/usb/include/usb/usbdrv.h

    rde2c901 r71ed4849  
    4242
    4343int usb_drv_find_hc(device_t *, devman_handle_t *);
    44 int usb_drv_hc_connect(device_t *, unsigned int);
     44int usb_drv_hc_connect(device_t *, devman_handle_t, unsigned int);
     45int usb_drv_hc_connect_auto(device_t *, unsigned int);
    4546
    4647int usb_drv_reserve_default_address(int);
  • uspace/lib/usb/src/hcdhubd.c

    rde2c901 r71ed4849  
    3636#include <usb/devreq.h>
    3737#include <usbhc_iface.h>
     38#include <usb_iface.h>
    3839#include <usb/descriptor.h>
    3940#include <driver.h>
     
    4546#include "hcdhubd_private.h"
    4647
     48
     49static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
     50{
     51        assert(dev);
     52        assert(dev->parent != NULL);
     53
     54        device_t *parent = dev->parent;
     55
     56        if (parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
     57                usb_iface_t *usb_iface
     58                    = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
     59                assert(usb_iface != NULL);
     60                if (usb_iface->get_hc_handle) {
     61                        int rc = usb_iface->get_hc_handle(parent, handle);
     62                        return rc;
     63                }
     64        }
     65
     66        return ENOTSUP;
     67}
     68
     69static usb_iface_t usb_iface = {
     70        .get_hc_handle = usb_iface_get_hc_handle
     71};
     72
     73static device_ops_t child_ops = {
     74        .interfaces[USB_DEV_IFACE] = &usb_iface
     75};
     76
    4777/** Callback when new device is detected and must be handled by this driver.
    4878 *
     
    129159        }
    130160        child->name = child_info->name;
     161        child->parent = child_info->parent;
     162        child->ops = &child_ops;
    131163
    132164        match_id = create_match_id();
  • uspace/lib/usb/src/recognise.c

    rde2c901 r71ed4849  
    3333 * @brief Functions for recognising kind of attached devices.
    3434 */
     35#include <usb_iface.h>
    3536#include <usb/usbdrv.h>
    3637#include <usb/classes/classes.h>
     
    3839#include <errno.h>
    3940
     41static int usb_iface_get_hc_handle(device_t *dev, devman_handle_t *handle)
     42{
     43        assert(dev);
     44        assert(dev->parent != NULL);
     45
     46        device_t *parent = dev->parent;
     47
     48        if (parent->ops && parent->ops->interfaces[USB_DEV_IFACE]) {
     49                usb_iface_t *usb_iface
     50                    = (usb_iface_t *) parent->ops->interfaces[USB_DEV_IFACE];
     51                assert(usb_iface != NULL);
     52                if (usb_iface->get_hc_handle) {
     53                        int rc = usb_iface->get_hc_handle(parent, handle);
     54                        return rc;
     55                }
     56        }
     57
     58        return ENOTSUP;
     59}
     60
     61static usb_iface_t usb_iface = {
     62        .get_hc_handle = usb_iface_get_hc_handle
     63};
     64
     65static device_ops_t child_ops = {
     66        .interfaces[USB_DEV_IFACE] = &usb_iface
     67};
    4068
    4169#define BCD_INT(a) (((unsigned int)(a)) / 256)
     
    285313                goto failure;
    286314        }
     315        child->parent = parent;
    287316        child->name = child_name;
     317        child->ops = &child_ops;
    288318       
    289319        rc = usb_drv_create_device_match_ids(hc, &child->match_ids, address);
  • uspace/lib/usb/src/usbdrv.c

    rde2c901 r71ed4849  
    7070        }
    7171
    72         int parent_phone = devman_parent_device_connect(dev->handle, 0);
     72        int parent_phone = devman_parent_device_connect(dev->handle,
     73            IPC_FLAG_BLOCKING);
    7374        if (parent_phone < 0) {
    7475                return parent_phone;
     
    7879        int rc = async_req_1_1(parent_phone, DEV_IFACE_ID(USB_DEV_IFACE),
    7980            IPC_M_USB_GET_HOST_CONTROLLER_HANDLE, &h);
     81
     82        ipc_hangup(parent_phone);
     83
    8084        if (rc != EOK) {
    8185                return rc;
     
    8589
    8690        return EOK;
     91}
     92
     93/** Connect to host controller the device is physically attached to.
     94 *
     95 * @param dev Device asking for connection.
     96 * @param hc_handle Devman handle of the host controller.
     97 * @param flags Connection flags (blocking connection).
     98 * @return Phone to the HC or error code.
     99 */
     100int usb_drv_hc_connect(device_t *dev, devman_handle_t hc_handle,
     101    unsigned int flags)
     102{
     103        return devman_device_connect(hc_handle, flags);
    87104}
    88105
     
    93110 * @return Phone to corresponding HC or error code.
    94111 */
    95 int usb_drv_hc_connect(device_t *dev, unsigned int flags)
    96 {
     112int usb_drv_hc_connect_auto(device_t *dev, unsigned int flags)
     113{
     114        int rc;
     115        devman_handle_t hc_handle;
     116
    97117        /*
    98118         * Call parent hub to obtain device handle of respective HC.
    99119         */
    100 
    101         /*
    102          * FIXME: currently we connect always to virtual host controller.
    103          */
    104         int rc;
    105         devman_handle_t handle;
    106 
    107         rc = devman_device_get_handle("/virt/usbhc", &handle, flags);
     120        rc = usb_drv_find_hc(dev, &hc_handle);
    108121        if (rc != EOK) {
    109122                return rc;
    110123        }
    111124       
    112         int phone = devman_device_connect(handle, flags);
    113 
    114         return phone;
     125        return usb_drv_hc_connect(dev, hc_handle, flags);
    115126}
    116127
Note: See TracChangeset for help on using the changeset viewer.