Changeset f2962621 in mainline for uspace/drv


Ignore:
Timestamp:
2010-12-17T10:14:01Z (15 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6e5dc07
Parents:
9223dc5c (diff), 11658b64 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge with usb/development

Location:
uspace/drv
Files:
4 added
1 deleted
17 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/ns8250/ns8250.c

    r9223dc5c rf2962621  
    887887    ipc_call_t *call)
    888888{
    889         ipcarg_t method = IPC_GET_METHOD(*call);
     889        sysarg_t method = IPC_GET_IMETHOD(*call);
    890890        int ret;
    891891        unsigned int baud_rate, parity, word_length, stop_bits;
  • uspace/drv/usbhub/main.c

    r9223dc5c rf2962621  
    5050        while(true){
    5151                usb_hub_check_hub_changes();
    52                 async_usleep(10000000);
     52                async_usleep(1000 * 1000);
    5353        }
    5454        return 0;
  • uspace/drv/usbhub/usbhub_private.h

    r9223dc5c rf2962621  
    182182}
    183183
     184static inline int usb_hub_clear_port_feature(int hc, usb_address_t address,
     185    int port_index,
     186    usb_hub_class_feature_t feature) {
     187        usb_target_t target = {
     188                .address = address,
     189                .endpoint = 0
     190        };
     191        usb_device_request_setup_packet_t clear_request = {
     192                .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
     193                .request = USB_DEVREQ_CLEAR_FEATURE,
     194                .length = 0,
     195                .index = port_index
     196        };
     197        clear_request.value = feature;
     198        return usb_drv_psync_control_write(hc, target, &clear_request,
     199            sizeof(clear_request), NULL, 0);
     200}
     201
    184202
    185203
  • uspace/drv/usbhub/utils.c

    r9223dc5c rf2962621  
    506506                int hc, uint16_t port, usb_target_t target) {
    507507
    508         usb_device_request_setup_packet_t request;
    509508        int opResult;
    510509        printf("[usb_hub] finalizing add device\n");
    511         usb_address_t new_device_address =
    512                         usb_drv_request_address(hc);
    513         usb_hub_set_set_address_request
    514                         (&request, new_device_address);
    515         opResult = usb_drv_sync_control_write(
    516                         hc, target,
    517                         &request,
    518                         NULL, 0
    519                         );
     510        opResult = usb_hub_clear_port_feature(hc, target.address,
     511            port, USB_HUB_FEATURE_C_PORT_RESET);
     512        if (opResult != EOK) {
     513                goto release;
     514        }
     515
     516        /* Request address at from host controller. */
     517        usb_address_t new_device_address = usb_drv_request_address(hc);
     518        if (new_device_address < 0) {
     519                printf("[usb_hub] failed to get free USB address\n");
     520                opResult = new_device_address;
     521                goto release;
     522        }
     523        printf("[usb_hub] setting new address\n");
     524        opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
     525            new_device_address);
     526
    520527        if (opResult != EOK) {
    521528                printf("[usb_hub] could not set address for new device\n");
    522                 //will retry later...
    523                 return;
    524         }
    525 
     529                goto release;
     530        }
     531
     532release:
     533        printf("[usb_hub] releasing default address\n");
    526534        usb_drv_release_default_address(hc);
     535        if (opResult != EOK) {
     536                return;
     537        }
    527538
    528539        devman_handle_t child_handle;
    529540        opResult = usb_drv_register_child_in_devman(hc, hub->device,
    530         new_device_address, &child_handle);
     541            new_device_address, &child_handle);
    531542        if (opResult != EOK) {
    532543                printf("[usb_hub] could not start driver for new device \n");
     
    541552                return;
    542553        }
    543         printf("[usb_hub] new device address %d, handle %d\n",
     554        printf("[usb_hub] new device address %d, handle %zu\n",
    544555            new_device_address, child_handle);
    545         sleep(60);
    546556       
    547557}
     
    620630        //something connected/disconnected
    621631        if (usb_port_connect_change(&status)) {
     632                opResult = usb_hub_clear_port_feature(hc, target.address,
     633                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
     634                // TODO: check opResult
    622635                if (usb_port_dev_connected(&status)) {
    623636                        printf("[usb_hub] some connection changed\n");
     
    629642        //port reset
    630643        if (usb_port_reset_completed(&status)) {
    631                 printf("[usb_hub] finalizing add device\n");
     644                printf("[usb_hub] port reset complete\n");
    632645                if (usb_port_enabled(&status)) {
    633646                        usb_hub_finalize_add_device(hub, hc, port, target);
     
    670683                        lst_item != &usb_hub_list;
    671684                        lst_item = lst_item->next) {
    672                 printf("[usb_hub] checking hub changes\n");
    673685                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
    674686                /*
     
    679691                target.address = hub_info->usb_device->address;
    680692                target.endpoint = 1;/// \TODO get from endpoint descriptor
    681                 printf("checking changes for hub at addr %d \n",target.address);
     693                printf("[usb_hub] checking changes for hub at addr %d\n",
     694                    target.address);
    682695
    683696                size_t port_count = hub_info->port_count;
  • uspace/drv/usbkbd/main.c

    r9223dc5c rf2962621  
    3939#define NAME "usbkbd"
    4040
    41 static const usb_endpoint_t CONTROL_EP = 0;
     41#define GUESSED_POLL_ENDPOINT 1
    4242
    4343/*
     
    155155
    156156        // default endpoint
    157         kbd_dev->default_ep = CONTROL_EP;
     157        kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT;
    158158       
    159159        /*
     
    204204        usb_target_t poll_target = {
    205205                .address = kbd_dev->address,
    206                 .endpoint = kbd_dev->default_ep
     206                .endpoint = kbd_dev->poll_endpoint
    207207        };
    208208
    209209        while (true) {
     210                async_usleep(1000 * 1000);
    210211                rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
    211212                    poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
  • uspace/drv/vhc/Makefile

    r9223dc5c rf2962621  
    3333        $(LIBDRV_PREFIX)/libdrv.a
    3434EXTRA_CFLAGS += \
    35         -I$(LIB_PREFIX) \
     35        -I$(LIBUSBVIRT_PREFIX)/include \
    3636        -I$(LIBUSB_PREFIX)/include \
    3737        -I$(LIBDRV_PREFIX)/include
     
    3939
    4040SOURCES = \
     41        hub/hub.c \
     42        hub/virthub.c \
     43        hub/virthubops.c \
    4144        conndev.c \
    4245        connhost.c \
     
    4548        hc.c \
    4649        hcd.c \
    47         hub.c \
    48         hubops.c
     50        hub.c
    4951
    5052include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/vhc/conn.h

    r9223dc5c rf2962621  
    4242#include "devices.h"
    4343
    44 void connection_handler_host(ipcarg_t);
     44void connection_handler_host(sysarg_t);
    4545
    4646usb_hcd_transfer_ops_t vhc_transfer_ops;
  • uspace/drv/vhc/conndev.c

    r9223dc5c rf2962621  
    4747{
    4848        ipc_call_t answer_data;
    49         ipcarg_t answer_rc;
     49        sysarg_t answer_rc;
    5050        aid_t req;
    5151        int rc;
     
    8383    ipc_callid_t icallid, ipc_call_t *icall)
    8484{
    85         ipcarg_t method = IPC_GET_METHOD(*icall);
     85        sysarg_t method = IPC_GET_IMETHOD(*icall);
    8686
    8787        if (method == IPC_M_CONNECT_TO_ME) {
  • uspace/drv/vhc/connhost.c

    r9223dc5c rf2962621  
    102102        transfer->out_callback = callback;
    103103
    104         hc_add_transaction_to_device(false, target, buffer, size,
     104        hc_add_transaction_to_device(false, target, transfer_type, buffer, size,
    105105            universal_callback, transfer);
    106106
     
    122122        transfer->out_callback = callback;
    123123
    124         hc_add_transaction_to_device(true, target, buffer, size,
     124        hc_add_transaction_to_device(true, target, transfer_type, buffer, size,
    125125            universal_callback, transfer);
    126126
     
    142142        transfer->in_callback = callback;
    143143
    144         hc_add_transaction_from_device(target, buffer, size,
     144        hc_add_transaction_from_device(target, transfer_type, buffer, size,
    145145            universal_callback, transfer);
    146146
  • uspace/drv/vhc/debug.c

    r9223dc5c rf2962621  
    4242/** Debug print informing of invalid call.
    4343 */
    44 void dprintf_inval_call(int level, ipc_call_t call, ipcarg_t phone_hash)
     44void dprintf_inval_call(int level, ipc_call_t call, sysarg_t phone_hash)
    4545{
    4646        dprintf(level, "phone%#x: invalid call [%u (%u, %u, %u, %u, %u)]",
    4747            phone_hash,
    48             IPC_GET_METHOD(call),
     48            IPC_GET_IMETHOD(call),
    4949            IPC_GET_ARG1(call), IPC_GET_ARG2(call), IPC_GET_ARG3(call),
    5050            IPC_GET_ARG4(call), IPC_GET_ARG5(call));
  • uspace/drv/vhc/devices.c

    r9223dc5c rf2962621  
    4747#include "devices.h"
    4848#include "hub.h"
     49#include "hub/virthub.h"
    4950#include "vhcd.h"
    5051
     
    6970        list_append(&dev->link, &devices);
    7071       
    71         hub_add_device(dev);
     72        virthub_connect_device(&virtual_hub_device, dev);
    7273       
    7374        return dev;
     
    7879void virtdev_destroy_device(virtdev_connection_t *dev)
    7980{
    80         hub_remove_device(dev);
     81        virthub_disconnect_device(&virtual_hub_device, dev);
    8182        list_remove(&dev->link);
    8283        free(dev);
     
    9495                    = list_get_instance(pos, virtdev_connection_t, link);
    9596               
    96                 if (!hub_can_device_signal(dev)) {
     97                if (!virthub_is_device_enabled(&virtual_hub_device, dev)) {
    9798                        continue;
    9899                }
    99100               
    100101                ipc_call_t answer_data;
    101                 ipcarg_t answer_rc;
     102                sysarg_t answer_rc;
    102103                aid_t req;
    103104                int rc = EOK;
     
    145146         * (if the address matches).
    146147         */
    147         if (virthub_dev.address == transaction->target.address) {
     148        if (virtual_hub_device.address == transaction->target.address) {
    148149                size_t tmp;
    149150                dprintf(1, "sending `%s' transaction to hub",
     
    151152                switch (transaction->type) {
    152153                        case USBVIRT_TRANSACTION_SETUP:
    153                                 virthub_dev.transaction_setup(&virthub_dev,
     154                                virtual_hub_device.transaction_setup(
     155                                    &virtual_hub_device,
    154156                                    transaction->target.endpoint,
    155157                                    transaction->buffer, transaction->len);
     
    157159                               
    158160                        case USBVIRT_TRANSACTION_IN:
    159                                 virthub_dev.transaction_in(&virthub_dev,
     161                                virtual_hub_device.transaction_in(
     162                                    &virtual_hub_device,
    160163                                    transaction->target.endpoint,
    161164                                    transaction->buffer, transaction->len,
     
    167170                               
    168171                        case USBVIRT_TRANSACTION_OUT:
    169                                 virthub_dev.transaction_out(&virthub_dev,
     172                                virtual_hub_device.transaction_out(
     173                                    &virtual_hub_device,
    170174                                    transaction->target.endpoint,
    171175                                    transaction->buffer, transaction->len);
  • uspace/drv/vhc/hc.c

    r9223dc5c rf2962621  
    5050#include "hub.h"
    5151
    52 #define USLEEP_BASE (0 * 500 * 1000)
    53 
    54 #define USLEEP_VAR 5000
     52#define USLEEP_BASE (0 * 5 * 1000)
     53
     54#define USLEEP_VAR 50
    5555
    5656#define SHORTENING_VAR 15
     
    6868static link_t transaction_list;
    6969
    70 #define TRANSACTION_FORMAT "T[%d:%d %s (%d)]"
     70#define TRANSACTION_FORMAT "T[%d.%d %s/%s (%d)]"
    7171#define TRANSACTION_PRINTF(t) \
    7272        (t).target.address, (t).target.endpoint, \
     73        usb_str_transfer_type((t).transfer_type), \
    7374        usbvirt_str_transaction_type((t).type), \
    7475        (int)(t).len
     
    7778        list_get_instance(lnk, transaction_t, link)
    7879
     80#define HUB_STATUS_MAX_LEN (HUB_PORT_COUNT + 64)
     81
    7982static inline unsigned int pseudo_random(unsigned int *seed)
    8083{
     
    8992    usb_transaction_outcome_t outcome)
    9093{
    91         dprintf(3, "processing transaction " TRANSACTION_FORMAT ", outcome: %s",
     94        dprintf(3, "transaction " TRANSACTION_FORMAT " done, outcome: %s",
    9295            TRANSACTION_PRINTF(*transaction),
    9396            usb_str_transaction_outcome(outcome));
     
    99102/** Host controller manager main function.
    100103 */
    101 void hc_manager(void)
     104static int hc_manager_fibril(void *arg)
    102105{
    103106        list_initialize(&transaction_list);
     
    114117                }
    115118               
    116                 char ports[HUB_PORT_COUNT + 2];
    117                 hub_get_port_statuses(ports, HUB_PORT_COUNT + 1);
    118                 dprintf(0, "virtual hub: addr=%d ports=%s",
    119                     virthub_dev.address, ports);
     119                char ports[HUB_STATUS_MAX_LEN + 1];
     120                virthub_get_status(&virtual_hub_device, ports, HUB_STATUS_MAX_LEN);
    120121               
    121122                link_t *first_transaction_link = transaction_list.next;
     
    124125                list_remove(first_transaction_link);
    125126               
     127
     128                dprintf(0, "about to process " TRANSACTION_FORMAT " [%s]",
     129                    TRANSACTION_PRINTF(*transaction), ports);
     130
    126131                dprintf(3, "processing transaction " TRANSACTION_FORMAT "",
    127132                    TRANSACTION_PRINTF(*transaction));
     
    134139                free(transaction);
    135140        }
     141
     142        assert(false && "unreachable");
     143        return EOK;
     144}
     145
     146void hc_manager(void)
     147{
     148        fid_t fid = fibril_create(hc_manager_fibril, NULL);
     149        if (fid == 0) {
     150                printf(NAME ": failed to start HC manager fibril\n");
     151                return;
     152        }
     153        fibril_add_ready(fid);
    136154}
    137155
     
    139157 */
    140158static transaction_t *transaction_create(usbvirt_transaction_type_t type,
    141     usb_target_t target,
     159    usb_target_t target, usb_transfer_type_t transfer_type,
    142160    void * buffer, size_t len,
    143161    hc_transaction_done_callback_t callback, void * arg)
     
    147165        list_initialize(&transaction->link);
    148166        transaction->type = type;
     167        transaction->transfer_type = transfer_type;
    149168        transaction->target = target;
    150169        transaction->buffer = buffer;
     
    162181 */
    163182void hc_add_transaction_to_device(bool setup, usb_target_t target,
     183    usb_transfer_type_t transfer_type,
    164184    void * buffer, size_t len,
    165185    hc_transaction_done_callback_t callback, void * arg)
    166186{
    167187        transaction_t *transaction = transaction_create(
    168             setup ? USBVIRT_TRANSACTION_SETUP : USBVIRT_TRANSACTION_OUT, target,
     188            setup ? USBVIRT_TRANSACTION_SETUP : USBVIRT_TRANSACTION_OUT,
     189            target, transfer_type,
    169190            buffer, len, callback, arg);
    170191        list_append(&transaction->link, &transaction_list);
     
    174195 */
    175196void hc_add_transaction_from_device(usb_target_t target,
     197    usb_transfer_type_t transfer_type,
    176198    void * buffer, size_t len,
    177199    hc_transaction_done_callback_t callback, void * arg)
    178200{
    179201        transaction_t *transaction = transaction_create(USBVIRT_TRANSACTION_IN,
    180             target, buffer, len, callback, arg);
     202            target, transfer_type,
     203            buffer, len, callback, arg);
    181204        list_append(&transaction->link, &transaction_list);
    182205}
  • uspace/drv/vhc/hc.h

    r9223dc5c rf2962621  
    5555        /** Transaction type. */
    5656        usbvirt_transaction_type_t type;
     57        /** Transfer type. */
     58        usb_transfer_type_t transfer_type;
    5759        /** Device address. */
    5860        usb_target_t target;
     
    7173void hc_manager(void);
    7274
    73 void hc_add_transaction_to_device(bool setup, usb_target_t target,
     75void hc_add_transaction_to_device(bool setup,
     76    usb_target_t target, usb_transfer_type_t transfer_type,
    7477    void * buffer, size_t len,
    7578    hc_transaction_done_callback_t callback, void * arg);
    7679
    77 void hc_add_transaction_from_device(usb_target_t target,
     80void hc_add_transaction_from_device(
     81    usb_target_t target, usb_transfer_type_t transfer_type,
    7882    void * buffer, size_t len,
    7983    hc_transaction_done_callback_t callback, void * arg);
  • uspace/drv/vhc/hcd.c

    r9223dc5c rf2962621  
    7979         * Initialize our hub and announce its presence.
    8080         */
    81         hub_init(dev);
     81        virtual_hub_device_init(dev);
    8282
    8383        printf("%s: virtual USB host controller ready.\n", NAME);
     
    9595};
    9696
    97 /** Fibril wrapper for HC transaction manager.
    98  *
    99  * @param arg Not used.
    100  * @return Nothing, return argument is unreachable.
    101  */
    102 static int hc_manager_fibril(void *arg)
    103 {
    104         hc_manager();
    105         return EOK;
    106 }
    10797
    10898int main(int argc, char * argv[])
    10999{       
    110         printf("%s: virtual USB host controller driver.\n", NAME);
    111 
    112         usb_dprintf_enable(NAME, 2);
    113 
    114         fid_t fid = fibril_create(hc_manager_fibril, NULL);
    115         if (fid == 0) {
    116                 printf("%s: failed to start HC manager fibril\n", NAME);
    117                 return ENOMEM;
    118         }
    119         fibril_add_ready(fid);
    120 
    121100        /*
    122101         * Temporary workaround. Wait a little bit to be the last driver
    123102         * in devman output.
    124103         */
    125         sleep(4);
     104        sleep(5);
     105
     106        usb_dprintf_enable(NAME, 0);
     107
     108        printf(NAME ": virtual USB host controller driver.\n");
     109
     110        hc_manager();
    126111
    127112        return driver_main(&vhc_driver);
  • uspace/drv/vhc/hub.c

    r9223dc5c rf2962621  
    4040#include <stdlib.h>
    4141#include <driver.h>
     42#include <usb/usbdrv.h>
    4243
     44#include "hub.h"
     45#include "hub/virthub.h"
    4346#include "vhcd.h"
    44 #include "hub.h"
    45 #include "hubintern.h"
    46 #include "conn.h"
    4747
     48usbvirt_device_t virtual_hub_device;
    4849
    49 /** Standard device descriptor. */
    50 usb_standard_device_descriptor_t std_device_descriptor = {
    51         .length = sizeof(usb_standard_device_descriptor_t),
    52         .descriptor_type = USB_DESCTYPE_DEVICE,
    53         .usb_spec_version = 0x110,
    54         .device_class = USB_CLASS_HUB,
    55         .device_subclass = 0,
    56         .device_protocol = 0,
    57         .max_packet_size = 64,
    58         .configuration_count = 1
    59 };
     50static int hub_register_in_devman_fibril(void *arg);
    6051
    61 /** Standard interface descriptor. */
    62 usb_standard_interface_descriptor_t std_interface_descriptor = {
    63         .length = sizeof(usb_standard_interface_descriptor_t),
    64         .descriptor_type = USB_DESCTYPE_INTERFACE,
    65         .interface_number = 0,
    66         .alternate_setting = 0,
    67         .endpoint_count = 1,
    68         .interface_class = USB_CLASS_HUB,
    69         .interface_subclass = 0,
    70         .interface_protocol = 0,
    71         .str_interface = 0
    72 };
     52void virtual_hub_device_init(device_t *hc_dev)
     53{
     54        virthub_init(&virtual_hub_device);
    7355
    74 hub_descriptor_t hub_descriptor = {
    75         .length = sizeof(hub_descriptor_t),
    76         .type = USB_DESCTYPE_HUB,
    77         .port_count = HUB_PORT_COUNT,
    78         .characteristics = 0,
    79         .power_on_warm_up = 50, /* Huh? */
    80         .max_current = 100, /* Huh again. */
    81         .removable_device = { 0 },
    82         .port_power = { 0xFF }
    83 };
     56        /*
     57         * We need to register the root hub.
     58         * This must be done in separate fibril because the device
     59         * we are connecting to are ourselves and we cannot connect
     60         * before leaving the add_device() function.
     61         */
     62        fid_t root_hub_registration
     63            = fibril_create(hub_register_in_devman_fibril, hc_dev);
     64        if (root_hub_registration == 0) {
     65                printf(NAME ": failed to register root hub\n");
     66                return;
     67        }
    8468
    85 /** Endpoint descriptor. */
    86 usb_standard_endpoint_descriptor_t endpoint_descriptor = {
    87         .length = sizeof(usb_standard_endpoint_descriptor_t),
    88         .descriptor_type = USB_DESCTYPE_ENDPOINT,
    89         .endpoint_address = HUB_STATUS_CHANGE_PIPE | 128,
    90         .attributes = USB_TRANSFER_INTERRUPT,
    91         .max_packet_size = 8,
    92         .poll_interval = 0xFF
    93 };
    94 
    95 /** Standard configuration descriptor. */
    96 usb_standard_configuration_descriptor_t std_configuration_descriptor = {
    97         .length = sizeof(usb_standard_configuration_descriptor_t),
    98         .descriptor_type = USB_DESCTYPE_CONFIGURATION,
    99         .total_length =
    100                 sizeof(usb_standard_configuration_descriptor_t)
    101                 + sizeof(std_interface_descriptor)
    102                 + sizeof(hub_descriptor)
    103                 + sizeof(endpoint_descriptor)
    104                 ,
    105         .interface_count = 1,
    106         .configuration_number = HUB_CONFIGURATION_ID,
    107         .str_configuration = 0,
    108         .attributes = 128, /* denotes bus-powered device */
    109         .max_power = 50
    110 };
    111 
    112 /** All hub configuration descriptors. */
    113 static usbvirt_device_configuration_extras_t extra_descriptors[] = {
    114         {
    115                 .data = (uint8_t *) &std_interface_descriptor,
    116                 .length = sizeof(std_interface_descriptor)
    117         },
    118         {
    119                 .data = (uint8_t *) &hub_descriptor,
    120                 .length = sizeof(hub_descriptor)
    121         },
    122         {
    123                 .data = (uint8_t *) &endpoint_descriptor,
    124                 .length = sizeof(endpoint_descriptor)
    125         }
    126 };
    127 
    128 /** Hub configuration. */
    129 usbvirt_device_configuration_t configuration = {
    130         .descriptor = &std_configuration_descriptor,
    131         .extra = extra_descriptors,
    132         .extra_count = sizeof(extra_descriptors)/sizeof(extra_descriptors[0])
    133 };
    134 
    135 /** Hub standard descriptors. */
    136 usbvirt_descriptors_t descriptors = {
    137         .device = &std_device_descriptor,
    138         .configuration = &configuration,
    139         .configuration_count = 1,
    140 };
    141 
    142 /** Hub as a virtual device. */
    143 usbvirt_device_t virthub_dev = {
    144         .ops = &hub_ops,
    145         .descriptors = &descriptors,
    146         .lib_debug_level = 1,
    147         .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL
    148 };
    149 
    150 /** Hub device. */
    151 hub_device_t hub_dev;
    152 
    153 static 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;
     69        fibril_add_ready(root_hub_registration);
    17370}
    17471
    175 /** Initialize virtual hub. */
    176 void hub_init(device_t *hc_dev)
     72/** Register root hub in devman.
     73 *
     74 * @param arg Host controller device (type <code>device_t *</code>).
     75 * @return Error code.
     76 */
     77int hub_register_in_devman_fibril(void *arg)
    17778{
    178         size_t i;
    179        
    180         for (i = 0; i < HUB_PORT_COUNT; i++) {
    181                 hub_port_t *port = &hub_dev.ports[i];
    182                
    183                 port->index = (int) i;
    184                 port->device = NULL;
    185                 port->state = HUB_PORT_STATE_NOT_CONFIGURED;
    186                 port->status_change = 0;
    187         }
    188        
    189         usbvirt_connect_local(&virthub_dev);
    190        
    191         dprintf(1, "virtual hub (%d ports) created", HUB_PORT_COUNT);
     79        device_t *hc_dev = (device_t *) arg;
    19280
    193         usb_address_t hub_address = hub_set_address(&virthub_dev);
    194         if (hub_address < 0) {
    195                 dprintf(1, "problem changing hub address (%s)",
    196                     str_error(hub_address));
     81        int hc = usb_drv_hc_connect(hc_dev, IPC_FLAG_BLOCKING);
     82        if (hc < 0) {
     83                printf(NAME ": failed to register root hub\n");
     84                return hc;
    19785        }
    19886
    199         dprintf(2, "virtual hub address changed to %d", hub_address);
     87        usb_drv_reserve_default_address(hc);
    20088
    201         char *id;
    202         int rc = asprintf(&id, "usb&hub");
    203         if (rc <= 0) {
    204                 return;
    205         }
     89        usb_address_t hub_address = usb_drv_request_address(hc);
     90        usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, hub_address);
     91
     92        usb_drv_release_default_address(hc);
     93
    20694        devman_handle_t hub_handle;
    207         rc = child_device_register_wrapper(hc_dev, "hub", id, 10, &hub_handle);
    208         if (rc != EOK) {
    209                 free(id);
    210         }
     95        usb_drv_register_child_in_devman(hc, hc_dev, hub_address, &hub_handle);
     96        usb_drv_bind_address(hc, hub_address, hub_handle);
    21197
    212         vhc_iface.bind_address(NULL, hub_address, hub_handle); 
    213 
    214         dprintf(2, "virtual hub has devman handle %d", (int) hub_handle);
     98        return EOK;
    21599}
    216 
    217 /** Connect device to the hub.
    218  *
    219  * @param device Device to be connected.
    220  * @return Port where the device was connected to.
    221  */
    222 size_t hub_add_device(virtdev_connection_t *device)
    223 {
    224         size_t i;
    225         for (i = 0; i < HUB_PORT_COUNT; i++) {
    226                 hub_port_t *port = &hub_dev.ports[i];
    227                
    228                 if (port->device != NULL) {
    229                         continue;
    230                 }
    231                
    232                 port->device = device;
    233                
    234                 /*
    235                  * TODO:
    236                  * If the hub was configured, we can normally
    237                  * announce the plug-in.
    238                  * Otherwise, we will wait until hub is configured
    239                  * and announce changes in single burst.
    240                  */
    241                 //if (port->state == HUB_PORT_STATE_DISCONNECTED) {
    242                         port->state = HUB_PORT_STATE_DISABLED;
    243                         set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
    244                 //}
    245                
    246                 return i;
    247         }
    248100       
    249         return (size_t)-1;
    250 }
    251 
    252 /** Disconnect device from the hub. */
    253 void hub_remove_device(virtdev_connection_t *device)
    254 {
    255         size_t i;
    256         for (i = 0; i < HUB_PORT_COUNT; i++) {
    257                 hub_port_t *port = &hub_dev.ports[i];
    258                
    259                 if (port->device != device) {
    260                         continue;
    261                 }
    262                
    263                 port->device = NULL;
    264                 port->state = HUB_PORT_STATE_DISCONNECTED;
    265                
    266                 set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
    267         }
    268 }
    269 
    270 /** Tell whether device port is open.
    271  *
    272  * @return Whether communication to and from the device can go through the hub.
    273  */
    274 bool hub_can_device_signal(virtdev_connection_t * device)
    275 {
    276         size_t i;
    277         for (i = 0; i < HUB_PORT_COUNT; i++) {
    278                 if (hub_dev.ports[i].device == device) {
    279                         return hub_dev.ports[i].state == HUB_PORT_STATE_ENABLED;
    280                 }
    281         }
    282        
    283         return false;
    284 }
    285 
    286 /** Format hub port status.
    287  *
    288  * @param result Buffer where to store status string.
    289  * @param len Number of characters that is possible to store in @p result
    290  *      (excluding trailing zero).
    291  */
    292 void hub_get_port_statuses(char *result, size_t len)
    293 {
    294         if (len > HUB_PORT_COUNT) {
    295                 len = HUB_PORT_COUNT;
    296         }
    297         size_t i;
    298         for (i = 0; i < len; i++) {
    299                 result[i] = hub_port_state_as_char(hub_dev.ports[i].state);
    300         }
    301         result[len] = 0;
    302 }
    303101
    304102/**
  • uspace/drv/vhc/hub.h

    r9223dc5c rf2962621  
    4040
    4141#include "devices.h"
     42#include "hub/hub.h"
     43#include "hub/virthub.h"
    4244
    43 #define HUB_PORT_COUNT 2
     45extern usbvirt_device_t virtual_hub_device;
    4446
    45 #define BITS2BYTES(bits) \
    46     (bits ? ((((bits)-1)>>3)+1) : 0)
    47 
    48 extern usbvirt_device_t virthub_dev;
    49 
    50 void hub_init(device_t *);
    51 size_t hub_add_device(virtdev_connection_t *);
    52 void hub_remove_device(virtdev_connection_t *);
    53 bool hub_can_device_signal(virtdev_connection_t *);
    54 void hub_get_port_statuses(char *result, size_t len);
     47void virtual_hub_device_init(device_t *);
    5548
    5649#endif
  • uspace/drv/vhc/hub/virthub.h

    r9223dc5c rf2962621  
    3131 */
    3232/** @file
    33  * @brief
     33 * @brief USB hub as a virtual USB device.
    3434 */
    35 #ifndef VHCD_HUBINTERN_H_
    36 #define VHCD_HUBINTERN_H_
     35#ifndef VHC_HUB_VIRTHUB_H_
     36#define VHC_HUB_VIRTHUB_H_
    3737
     38#include <usbvirt/device.h>
     39#include "../devices.h"
    3840#include "hub.h"
    3941
     
    4244/** Configuration value for hub configuration. */
    4345#define HUB_CONFIGURATION_ID 1
     46
    4447
    4548/** Hub descriptor.
     
    6871} __attribute__ ((packed)) hub_descriptor_t;
    6972
    70 /** Hub port internal state.
    71  * Some states (e.g. port over current) are not covered as they are not
    72  * simulated at all.
    73  */
    74 typedef enum {
    75         HUB_PORT_STATE_NOT_CONFIGURED,
    76         HUB_PORT_STATE_POWERED_OFF,
    77         HUB_PORT_STATE_DISCONNECTED,
    78         HUB_PORT_STATE_DISABLED,
    79         HUB_PORT_STATE_RESETTING,
    80         HUB_PORT_STATE_ENABLED,
    81         HUB_PORT_STATE_SUSPENDED,
    82         HUB_PORT_STATE_RESUMING,
    83         /* HUB_PORT_STATE_, */
    84 } hub_port_state_t;
    85 
    86 /** Convert hub port state to a char. */
    87 static inline char hub_port_state_as_char(hub_port_state_t state) {
    88         switch (state) {
    89                 case HUB_PORT_STATE_NOT_CONFIGURED:
    90                         return '-';
    91                 case HUB_PORT_STATE_POWERED_OFF:
    92                         return 'O';
    93                 case HUB_PORT_STATE_DISCONNECTED:
    94                         return 'X';
    95                 case HUB_PORT_STATE_DISABLED:
    96                         return 'D';
    97                 case HUB_PORT_STATE_RESETTING:
    98                         return 'R';
    99                 case HUB_PORT_STATE_ENABLED:
    100                         return 'E';
    101                 case HUB_PORT_STATE_SUSPENDED:
    102                         return 'S';
    103                 case HUB_PORT_STATE_RESUMING:
    104                         return 'F';
    105                 default:
    106                         return '?';
    107         }
    108 }
    109 
    110 /** Hub status change mask bits. */
    111 typedef enum {
    112         HUB_STATUS_C_PORT_CONNECTION = (1 << 0),
    113         HUB_STATUS_C_PORT_ENABLE = (1 << 1),
    114         HUB_STATUS_C_PORT_SUSPEND = (1 << 2),
    115         HUB_STATUS_C_PORT_OVER_CURRENT = (1 << 3),
    116         HUB_STATUS_C_PORT_RESET = (1 << 4),
    117         /* HUB_STATUS_C_ = (1 << ), */
    118 } hub_status_change_t;
    119 
    120 /** Hub port information. */
    121 typedef struct {
    122         virtdev_connection_t *device;
    123         int index;
    124         hub_port_state_t state;
    125         uint16_t status_change;
    126 } hub_port_t;
    127 
    128 /** Hub device type. */
    129 typedef struct {
    130         hub_port_t ports[HUB_PORT_COUNT];
    131 } hub_device_t;
    132 
    133 extern hub_device_t hub_dev;
    134 
     73extern usbvirt_device_ops_t hub_ops;
    13574extern hub_descriptor_t hub_descriptor;
    13675
    137 extern usbvirt_device_ops_t hub_ops;
    138 
    139 void clear_port_status_change(hub_port_t *, uint16_t);
    140 void set_port_status_change(hub_port_t *, uint16_t);
    141 
     76int virthub_init(usbvirt_device_t *);
     77int virthub_connect_device(usbvirt_device_t *, virtdev_connection_t *);
     78int virthub_disconnect_device(usbvirt_device_t *, virtdev_connection_t *);
     79bool virthub_is_device_enabled(usbvirt_device_t *, virtdev_connection_t *);
     80void virthub_get_status(usbvirt_device_t *, char *, size_t);
    14281
    14382#endif
  • uspace/drv/vhc/vhcd.h

    r9223dc5c rf2962621  
    4747#define dprintf(level, format, ...) \
    4848        usb_dprintf(NAME, (level), format "\n", ##__VA_ARGS__)
    49 void dprintf_inval_call(int, ipc_call_t, ipcarg_t);
     49void dprintf_inval_call(int, ipc_call_t, sysarg_t);
    5050
    5151#endif
Note: See TracChangeset for help on using the changeset viewer.