Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 0995cd6 in mainline


Ignore:
Timestamp:
2010-12-10T16:15:44Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
cf978f2
Parents:
9f6c5ef0
Message:

Virtual HC root hub sets its own address

Location:
uspace/drv/vhc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/vhc/hcd.c

    r9f6c5ef0 r0995cd6  
    7979         * Initialize our hub and announce its presence.
    8080         */
    81         hub_init();
    82         usb_hcd_add_root_hub(dev);
     81        hub_init(dev);
    8382
    8483        printf("%s: virtual USB host controller ready.\n", NAME);
  • uspace/drv/vhc/hub.c

    r9f6c5ef0 r0995cd6  
    3737#include <usbvirt/device.h>
    3838#include <errno.h>
     39#include <str_error.h>
    3940#include <stdlib.h>
     41#include <driver.h>
    4042
    4143#include "vhcd.h"
    4244#include "hub.h"
    4345#include "hubintern.h"
     46#include "conn.h"
    4447
    4548
     
    148151hub_device_t hub_dev;
    149152
     153static usb_address_t hub_set_address(usbvirt_device_t *hub)
     154{
     155        usb_address_t new_address;
     156        int rc = vhc_iface.request_address(NULL, &new_address);
     157        if (rc != EOK) {
     158                return rc;
     159        }
     160       
     161        usb_device_request_setup_packet_t setup_packet = {
     162                .request_type = 0,
     163                .request = USB_DEVREQ_SET_ADDRESS,
     164                .index = 0,
     165                .length = 0,
     166        };
     167        setup_packet.value = new_address;
     168
     169        hub->transaction_setup(hub, 0, &setup_packet, sizeof(setup_packet));
     170        hub->transaction_in(hub, 0, NULL, 0, NULL);
     171       
     172        return new_address;
     173}
     174
    150175/** Initialize virtual hub. */
    151 void hub_init(void)
     176void hub_init(device_t *hc_dev)
    152177{
    153178        size_t i;
     
    163188       
    164189        dprintf(1, "virtual hub (%d ports) created", HUB_PORT_COUNT);
     190
     191        usb_address_t hub_address = hub_set_address(&virthub_dev);
     192        if (hub_address < 0) {
     193                dprintf(1, "problem changing hub address (%s)",
     194                    str_error(hub_address));
     195        }
     196
     197        dprintf(2, "virtual hub address changed to %d", hub_address);
     198
     199        char *id;
     200        int rc = asprintf(&id, "usb&hub");
     201        if (rc <= 0) {
     202                return;
     203        }
     204        devman_handle_t hub_handle;
     205        rc = child_device_register_wrapper(hc_dev, "hub", id, 10, &hub_handle);
     206        if (rc != EOK) {
     207                free(id);
     208        }
     209
     210        vhc_iface.bind_address(NULL, hub_address, hub_handle); 
     211
     212        dprintf(2, "virtual hub has devman handle %d", (int) hub_handle);
    165213}
    166214
  • uspace/drv/vhc/hub.h

    r9f6c5ef0 r0995cd6  
    3737
    3838#include <usbvirt/device.h>
     39#include <driver.h>
    3940
    4041#include "devices.h"
     
    4748extern usbvirt_device_t virthub_dev;
    4849
    49 void hub_init(void);
     50void hub_init(device_t *);
    5051size_t hub_add_device(virtdev_connection_t *);
    5152void hub_remove_device(virtdev_connection_t *);
Note: See TracChangeset for help on using the changeset viewer.