Changeset 75732da in mainline for uspace/drv/vhc


Ignore:
Timestamp:
2010-12-13T07:20:20Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
309dea52
Parents:
84439d7 (diff), 37f7cfe (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 development/ changes

Location:
uspace/drv/vhc
Files:
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/vhc/Makefile

    r84439d7 r75732da  
    3939
    4040SOURCES = \
    41         addrmgm.c \
    4241        conndev.c \
    4342        connhost.c \
  • uspace/drv/vhc/conn.h

    r84439d7 r75732da  
    4848
    4949void address_init(void);
    50 int reserve_default_address(device_t *);
    51 int release_default_address(device_t *);
    52 int request_address(device_t *, usb_address_t *);
    53 int release_address(device_t *, usb_address_t);
    54 int bind_address(device_t *, usb_address_t, devman_handle_t);
    5550
    56 int tell_address(device_t *, devman_handle_t, usb_address_t *);
    5751
    5852void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
  • uspace/drv/vhc/connhost.c

    r84439d7 r75732da  
    3636#include <errno.h>
    3737#include <usb/usb.h>
     38#include <usb/hcd.h>
    3839
    3940#include "vhcd.h"
     
    5758                case USB_DIRECTION_IN:
    5859                        transfer->in_callback(transfer->dev,
    59                             size, outcome,
     60                            outcome, size,
    6061                            transfer->arg);
    6162                        break;
     
    9293    usbhc_iface_transfer_out_callback_t callback, void *arg)
    9394{
    94         printf(NAME ": transfer OUT [%d.%d (%s); %u]\n",
     95        dprintf(3, "transfer OUT [%d.%d (%s); %zu]",
    9596            target.address, target.endpoint,
    9697            usb_str_transfer_type(transfer_type),
     
    112113    usbhc_iface_transfer_out_callback_t callback, void *arg)
    113114{
    114         printf(NAME ": transfer SETUP [%d.%d (%s); %u]\n",
     115        dprintf(3, "transfer SETUP [%d.%d (%s); %zu]",
    115116            target.address, target.endpoint,
    116117            usb_str_transfer_type(transfer_type),
     
    132133    usbhc_iface_transfer_in_callback_t callback, void *arg)
    133134{
    134         printf(NAME ": transfer IN [%d.%d (%s); %u]\n",
     135        dprintf(3, "transfer IN [%d.%d (%s); %zu]",
    135136            target.address, target.endpoint,
    136137            usb_str_transfer_type(transfer_type),
     
    218219}
    219220
     221static usb_address_keeping_t addresses;
     222
     223
     224static int reserve_default_address(device_t *dev)
     225{
     226        usb_address_keeping_reserve_default(&addresses);
     227        return EOK;
     228}
     229
     230static int release_default_address(device_t *dev)
     231{
     232        usb_address_keeping_release_default(&addresses);
     233        return EOK;
     234}
     235
     236static int request_address(device_t *dev, usb_address_t *address)
     237{
     238        usb_address_t addr = usb_address_keeping_request(&addresses);
     239        if (addr < 0) {
     240                return (int)addr;
     241        }
     242
     243        *address = addr;
     244        return EOK;
     245}
     246
     247static int release_address(device_t *dev, usb_address_t address)
     248{
     249        return usb_address_keeping_release(&addresses, address);
     250}
     251
     252static int bind_address(device_t *dev, usb_address_t address,
     253    devman_handle_t handle)
     254{
     255        usb_address_keeping_devman_bind(&addresses, address, handle);
     256        return EOK;
     257}
     258
     259static int tell_address(device_t *dev, devman_handle_t handle,
     260    usb_address_t *address)
     261{
     262        usb_address_t addr = usb_address_keeping_find(&addresses, handle);
     263        if (addr < 0) {
     264                return addr;
     265        }
     266
     267        *address = addr;
     268        return EOK;
     269}
     270
     271void address_init(void)
     272{
     273        usb_address_keeping_init(&addresses, 50);
     274}
    220275
    221276usbhc_iface_t vhc_iface = {
  • uspace/drv/vhc/debug.c

    r84439d7 r75732da  
    3535#include <stdio.h>
    3636#include <ipc/ipc.h>
     37#include <usb/debug.h>
    3738
    3839#include "vhcd.h"
    3940
    40 /** Current debug level. */
    41 int debug_level = 0;
    42 
    43 /** Debugging printf.
    44  * This function is intended for single-line messages as it
    45  * automatically prints debugging prefix at the beginning of the
    46  * line.
    47  *
    48  * @see printf
    49  * @param level Debugging level.
    50  */
    51 void dprintf(int level, const char *format, ...)
    52 {
    53         if (level > debug_level) {
    54                 return;
    55         }
    56        
    57         printf("%s(%d): ", NAME, level);
    58         va_list args;
    59         va_start(args, format);
    60         vprintf(format, args);
    61         va_end(args);
    62         printf("\n");
    63 }
    6441
    6542/** Debug print informing of invalid call.
  • uspace/drv/vhc/devices.c

    r84439d7 r75732da  
    147147        if (virthub_dev.address == transaction->target.address) {
    148148                size_t tmp;
    149                 dprintf(3, "sending `%s' transaction to hub",
     149                dprintf(1, "sending `%s' transaction to hub",
    150150                    usbvirt_str_transaction_type(transaction->type));
    151151                switch (transaction->type) {
  • uspace/drv/vhc/hc.c

    r84439d7 r75732da  
    5050#include "hub.h"
    5151
    52 #define USLEEP_BASE (500 * 1000)
     52#define USLEEP_BASE (0 * 5 * 1000)
    5353
    54 #define USLEEP_VAR 5000
     54#define USLEEP_VAR 50
    5555
    5656#define SHORTENING_VAR 15
     
    8989    usb_transaction_outcome_t outcome)
    9090{
    91         dprintf(3, "processing transaction " TRANSACTION_FORMAT ", outcome: %s",
     91        dprintf(3, "transaction " TRANSACTION_FORMAT " done, outcome: %s",
    9292            TRANSACTION_PRINTF(*transaction),
    9393            usb_str_transaction_outcome(outcome));
     
    116116                char ports[HUB_PORT_COUNT + 2];
    117117                hub_get_port_statuses(ports, HUB_PORT_COUNT + 1);
    118                 dprintf(3, "virtual hub: addr=%d ports=%s",
     118                dprintf(4, "virtual hub: addr=%d ports=%s",
    119119                    virthub_dev.address, ports);
    120120               
     
    124124                list_remove(first_transaction_link);
    125125               
     126
     127                dprintf(0, "about to process " TRANSACTION_FORMAT " (vhub:%s)",
     128                    TRANSACTION_PRINTF(*transaction), ports);
     129
    126130                dprintf(3, "processing transaction " TRANSACTION_FORMAT "",
    127131                    TRANSACTION_PRINTF(*transaction));
     
    153157        transaction->callback_arg = arg;
    154158       
    155         dprintf(1, "creating transaction " TRANSACTION_FORMAT,
     159        dprintf(3, "creating transaction " TRANSACTION_FORMAT,
    156160            TRANSACTION_PRINTF(*transaction));
    157161       
  • uspace/drv/vhc/hcd.c

    r84439d7 r75732da  
    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);
     
    111110        printf("%s: virtual USB host controller driver.\n", NAME);
    112111
    113         debug_level = 10;
     112        usb_dprintf_enable(NAME, 0);
    114113
    115114        fid_t fid = fibril_create(hc_manager_fibril, NULL);
  • uspace/drv/vhc/hub.c

    r84439d7 r75732da  
    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
     
    141144        .ops = &hub_ops,
    142145        .descriptors = &descriptors,
    143         .lib_debug_level = 4,
     146        .lib_debug_level = 0,
    144147        .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL
    145148};
     
    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)
    152 {
    153         size_t i;
     176void hub_init(device_t *hc_dev)
     177{
     178        size_t i;
     179       
    154180        for (i = 0; i < HUB_PORT_COUNT; i++) {
    155181                hub_port_t *port = &hub_dev.ports[i];
    156182               
     183                port->index = (int) i + 1;
    157184                port->device = NULL;
    158185                port->state = HUB_PORT_STATE_NOT_CONFIGURED;
    159186                port->status_change = 0;
     187                fibril_mutex_initialize(&port->guard);
    160188        }
    161189       
     
    163191       
    164192        dprintf(1, "virtual hub (%d ports) created", HUB_PORT_COUNT);
     193
     194        usb_address_t hub_address = hub_set_address(&virthub_dev);
     195        if (hub_address < 0) {
     196                dprintf(1, "problem changing hub address (%s)",
     197                    str_error(hub_address));
     198        }
     199
     200        dprintf(2, "virtual hub address changed to %d", hub_address);
     201
     202        char *id;
     203        int rc = asprintf(&id, "usb&hub");
     204        if (rc <= 0) {
     205                return;
     206        }
     207        devman_handle_t hub_handle;
     208        rc = child_device_register_wrapper(hc_dev, "hub", id, 10, &hub_handle);
     209        if (rc != EOK) {
     210                free(id);
     211        }
     212
     213        vhc_iface.bind_address(NULL, hub_address, hub_handle); 
     214
     215        dprintf(2, "virtual hub has devman handle %d", (int) hub_handle);
    165216}
    166217
     
    175226        for (i = 0; i < HUB_PORT_COUNT; i++) {
    176227                hub_port_t *port = &hub_dev.ports[i];
     228                fibril_mutex_lock(&port->guard);
    177229               
    178230                if (port->device != NULL) {
     231                        fibril_mutex_unlock(&port->guard);
    179232                        continue;
    180233                }
     
    191244                //if (port->state == HUB_PORT_STATE_DISCONNECTED) {
    192245                        port->state = HUB_PORT_STATE_DISABLED;
    193                         set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
     246                        set_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION);
    194247                //}
    195248               
     249                fibril_mutex_unlock(&port->guard);
     250
    196251                return i;
    197252        }
  • uspace/drv/vhc/hub.h

    r84439d7 r75732da  
    3737
    3838#include <usbvirt/device.h>
     39#include <driver.h>
    3940
    4041#include "devices.h"
    4142
    42 #define HUB_PORT_COUNT 6
     43#define HUB_PORT_COUNT 2
    4344
    4445#define BITS2BYTES(bits) \
     
    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 *);
  • uspace/drv/vhc/hubintern.h

    r84439d7 r75732da  
    3737
    3838#include "hub.h"
     39#include <fibril_synch.h>
    3940
    4041/** Endpoint number for status change pipe. */
     
    121122typedef struct {
    122123        virtdev_connection_t *device;
     124        int index;
    123125        hub_port_state_t state;
    124126        uint16_t status_change;
     127        fibril_mutex_t guard;
    125128} hub_port_t;
    126129
     
    138141void clear_port_status_change(hub_port_t *, uint16_t);
    139142void set_port_status_change(hub_port_t *, uint16_t);
     143void set_port_status_change_nl(hub_port_t *, uint16_t);
    140144
    141145
  • uspace/drv/vhc/hubops.c

    r84439d7 r75732da  
    5959static int on_get_descriptor(struct usbvirt_device *dev,
    6060    usb_device_request_setup_packet_t *request, uint8_t *data);
     61static int on_set_configuration(struct usbvirt_device *dev,
     62    usb_device_request_setup_packet_t *request, uint8_t *data);
    6163static int on_class_request(struct usbvirt_device *dev,
    6264    usb_device_request_setup_packet_t *request, uint8_t *data);
     
    6466    usb_endpoint_t endpoint,
    6567    void *buffer, size_t size, size_t *actual_size);
     68static void set_port_state(hub_port_t *, hub_port_state_t);
     69static void clear_port_status_change_nl(hub_port_t *, uint16_t);
     70static void set_port_state_nl(hub_port_t *, hub_port_state_t);
    6671
    6772/** Hub operations. */
    6873usbvirt_device_ops_t hub_ops = {
    6974        .on_standard_request[USB_DEVREQ_GET_DESCRIPTOR] = on_get_descriptor,
     75        .on_standard_request[USB_DEVREQ_SET_CONFIGURATION] = on_set_configuration,
    7076        .on_class_device_request = on_class_request,
    7177        .on_data = NULL,
     
    8793}
    8894
     95/** Callback for SET_CONFIGURATION request. */
     96int on_set_configuration(struct usbvirt_device *dev,
     97    usb_device_request_setup_packet_t *request, uint8_t *data)
     98{
     99        /* We must suspend power source to all ports. */
     100        size_t i;
     101        for (i = 0; i < HUB_PORT_COUNT; i++) {
     102                hub_port_t *port = &hub_dev.ports[i];
     103               
     104                set_port_state(port, HUB_PORT_STATE_POWERED_OFF);
     105        }
     106       
     107        /* Let the framework handle the rest of the job. */
     108        return EFORWARD;
     109}
     110
     111struct delay_port_state_change {
     112        suseconds_t delay;
     113        hub_port_state_t old_state;
     114        hub_port_state_t new_state;
     115        hub_port_t *port;
     116};
     117
     118static int set_port_state_delayed_fibril(void *arg)
     119{
     120        struct delay_port_state_change *change
     121            = (struct delay_port_state_change *) arg;
     122       
     123        async_usleep(change->delay);
     124       
     125        fibril_mutex_lock(&change->port->guard);
     126        if (change->port->state == change->old_state) {
     127                set_port_state_nl(change->port, change->new_state);
     128        }
     129        fibril_mutex_unlock(&change->port->guard);
     130       
     131        free(change);
     132       
     133        return EOK;
     134}
     135
     136static void set_port_state_delayed(hub_port_t *port,
     137    suseconds_t delay_time,
     138    hub_port_state_t old_state, hub_port_state_t new_state)
     139{
     140        struct delay_port_state_change *change
     141            = malloc(sizeof(struct delay_port_state_change));
     142        change->port = port;
     143        change->delay = delay_time;
     144        change->old_state = old_state;
     145        change->new_state = new_state;
     146        fid_t fibril = fibril_create(set_port_state_delayed_fibril, change);
     147        if (fibril == 0) {
     148                printf("Failed to create fibril\n");
     149                return;
     150        }
     151        fibril_add_ready(fibril);
     152}
     153
    89154/** Change port status and updates status change status fields.
    90155 */
    91 static void set_port_state(hub_port_t *port, hub_port_state_t state)
    92 {
     156void set_port_state(hub_port_t *port, hub_port_state_t state)
     157{
     158        fibril_mutex_lock(&port->guard);
     159        set_port_state_nl(port, state);
     160        fibril_mutex_unlock(&port->guard);
     161}
     162
     163void set_port_state_nl(hub_port_t *port, hub_port_state_t state)
     164{
     165
     166        dprintf(2, "setting port %d state to %d (%c) from %c (change=%u)",
     167            port->index,
     168            state, hub_port_state_as_char(state),
     169            hub_port_state_as_char(port->state),
     170            (unsigned int) port->status_change);
     171       
     172        if (state == HUB_PORT_STATE_POWERED_OFF) {
     173                clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION);
     174                clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE);
     175                clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET);
     176        }
     177        if (state == HUB_PORT_STATE_RESUMING) {
     178                set_port_state_delayed(port, 10*1000,
     179                    HUB_PORT_STATE_RESUMING, HUB_PORT_STATE_ENABLED);
     180        }
     181        if (state == HUB_PORT_STATE_RESETTING) {
     182                set_port_state_delayed(port, 10*1000,
     183                    HUB_PORT_STATE_RESETTING, HUB_PORT_STATE_ENABLED);
     184        }
     185        if ((port->state == HUB_PORT_STATE_RESETTING)
     186            && (state == HUB_PORT_STATE_ENABLED)) {
     187                set_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET);
     188        }
     189       
    93190        port->state = state;
    94         if (state == HUB_PORT_STATE_POWERED_OFF) {
    95                 clear_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
    96                 clear_port_status_change(port, HUB_STATUS_C_PORT_ENABLE);
    97                 clear_port_status_change(port, HUB_STATUS_C_PORT_RESET);
    98         }
    99         if (state == HUB_PORT_STATE_RESUMING) {
    100                 async_usleep(10*1000);
    101                 if (port->state == state) {
    102                         set_port_state(port, HUB_PORT_STATE_ENABLED);
    103                 }
    104         }
    105         if (state == HUB_PORT_STATE_RESETTING) {
    106                 async_usleep(10*1000);
    107                 if (port->state == state) {
    108                         set_port_status_change(port, HUB_STATUS_C_PORT_RESET);
    109                         set_port_state(port, HUB_PORT_STATE_ENABLED);
    110                 }
    111         }
    112191}
    113192
     
    122201                } \
    123202        } while (false); \
    124         hub_port_t *portvar = &hub_dev.ports[index]
     203        hub_port_t *portvar = &hub_dev.ports[index-1]
    125204
    126205
     
    134213        _GET_PORT(port, portindex);
    135214       
     215        fibril_mutex_lock(&port->guard);
     216        int rc = ENOTSUP;
     217
    136218        switch (feature) {
    137219                case USB_HUB_FEATURE_PORT_ENABLE:
    138220                        if ((port->state != HUB_PORT_STATE_NOT_CONFIGURED)
    139221                            && (port->state != HUB_PORT_STATE_POWERED_OFF)) {
    140                                 set_port_state(port, HUB_PORT_STATE_DISABLED);
    141                         }
    142                         return EOK;
     222                                set_port_state_nl(port, HUB_PORT_STATE_DISABLED);
     223                        }
     224                        rc = EOK;
     225                        break;
    143226               
    144227                case USB_HUB_FEATURE_PORT_SUSPEND:
    145228                        if (port->state != HUB_PORT_STATE_SUSPENDED) {
    146                                 return EOK;
    147                         }
    148                         set_port_state(port, HUB_PORT_STATE_RESUMING);
    149                         return EOK;
     229                                rc = EOK;
     230                                break;
     231                        }
     232                        set_port_state_nl(port, HUB_PORT_STATE_RESUMING);
     233                        rc = EOK;
     234                        break;
    150235                       
    151236                case USB_HUB_FEATURE_PORT_POWER:
    152237                        if (port->state != HUB_PORT_STATE_NOT_CONFIGURED) {
    153                                 set_port_state(port, HUB_PORT_STATE_POWERED_OFF);
    154                         }
    155                         return EOK;
     238                                set_port_state_nl(port, HUB_PORT_STATE_POWERED_OFF);
     239                        }
     240                        rc = EOK;
     241                        break;
    156242               
    157243                case USB_HUB_FEATURE_C_PORT_CONNECTION:
    158                         clear_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
    159                         return EOK;
     244                        clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION);
     245                        rc = EOK;
     246                        break;
    160247               
    161248                case USB_HUB_FEATURE_C_PORT_ENABLE:
    162                         clear_port_status_change(port, HUB_STATUS_C_PORT_ENABLE);
    163                         return EOK;
     249                        clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE);
     250                        rc = EOK;
     251                        break;
    164252               
    165253                case USB_HUB_FEATURE_C_PORT_SUSPEND:
    166                         clear_port_status_change(port, HUB_STATUS_C_PORT_SUSPEND);
    167                         return EOK;
     254                        clear_port_status_change_nl(port, HUB_STATUS_C_PORT_SUSPEND);
     255                        rc = EOK;
     256                        break;
    168257                       
    169258                case USB_HUB_FEATURE_C_PORT_OVER_CURRENT:
    170                         clear_port_status_change(port, HUB_STATUS_C_PORT_OVER_CURRENT);
    171                         return EOK;
    172         }
    173        
     259                        clear_port_status_change_nl(port, HUB_STATUS_C_PORT_OVER_CURRENT);
     260                        rc = EOK;
     261                        break;
     262
     263                case USB_HUB_FEATURE_C_PORT_RESET:
     264                        clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET);
     265                        rc = EOK;
     266                        break;
     267        }
     268       
     269        fibril_mutex_unlock(&port->guard);
     270
     271        return rc;
     272}
     273
     274static int get_bus_state(uint16_t portindex)
     275{
    174276        return ENOTSUP;
    175277}
    176278
    177 static int get_bus_state(uint16_t portindex)
    178 {
    179         return ENOTSUP;
    180 }
    181 
    182 static int get_hub_descriptor(uint8_t descriptor_type,
    183     uint8_t descriptor_index, uint16_t length)
    184 {
     279static int get_hub_descriptor(struct usbvirt_device *dev,
     280    uint8_t descriptor_index,
     281    uint8_t descriptor_type, uint16_t length)
     282{
     283        if (descriptor_type == USB_DESCTYPE_HUB) {
     284                int rc = dev->control_transfer_reply(dev, 0,
     285                    &hub_descriptor, hub_descriptor.length);
     286
     287                return rc;
     288
     289        }
     290
    185291        return ENOTSUP;
    186292}
     
    198304        _GET_PORT(port, portindex);
    199305       
     306        fibril_mutex_lock(&port->guard);
     307
    200308        uint32_t status;
    201309        status = MAKE_BYTE(
     
    225333        status |= (port->status_change << 16);
    226334       
     335        fibril_mutex_unlock(&port->guard);
     336
     337        dprintf(2, "GetPortStatus(port=%d, status=%u)\n", (int)portindex,
     338            (unsigned int) status);
    227339        return virthub_dev.control_transfer_reply(&virthub_dev, 0, &status, 4);
    228340}
     
    238350        _GET_PORT(port, portindex);
    239351       
     352        fibril_mutex_lock(&port->guard);
     353
     354        int rc = ENOTSUP;
     355
    240356        switch (feature) {
    241357                case USB_HUB_FEATURE_PORT_RESET:
    242358                        if (port->state != HUB_PORT_STATE_POWERED_OFF) {
    243                                 set_port_state(port, HUB_PORT_STATE_RESETTING);
    244                         }
    245                         return EOK;
     359                                set_port_state_nl(port, HUB_PORT_STATE_RESETTING);
     360                        }
     361                        rc = EOK;
     362                        break;
    246363               
    247364                case USB_HUB_FEATURE_PORT_SUSPEND:
    248365                        if (port->state == HUB_PORT_STATE_ENABLED) {
    249                                 set_port_state(port, HUB_PORT_STATE_SUSPENDED);
    250                         }
    251                         return EOK;
     366                                set_port_state_nl(port, HUB_PORT_STATE_SUSPENDED);
     367                        }
     368                        rc = EOK;
     369                        break;
    252370               
    253371                case USB_HUB_FEATURE_PORT_POWER:
    254372                        if (port->state == HUB_PORT_STATE_POWERED_OFF) {
    255                                 set_port_state(port, HUB_PORT_STATE_DISCONNECTED);
    256                         }
    257                         return EOK;
    258         }
    259         return ENOTSUP;
     373                                set_port_state_nl(port, HUB_PORT_STATE_DISCONNECTED);
     374                        }
     375                        rc = EOK;
     376                        break;
     377        }
     378
     379        fibril_mutex_unlock(&port->guard);
     380        return rc;
    260381}
    261382
     
    267388    usb_device_request_setup_packet_t *request, uint8_t *data)
    268389{       
    269         dprintf(2, "hub class request (%d)\n", (int) request->request);
     390        dprintf(2, "hub class request (%d)", (int) request->request);
    270391       
    271392        uint8_t recipient = request->request_type & 31;
     
    298419                       
    299420                case USB_HUB_REQUEST_GET_DESCRIPTOR:
    300                         return get_hub_descriptor(request->value_low,
     421                        return get_hub_descriptor(dev, request->value_low,
    301422                            request->value_high, request->length);
    302423                       
     
    316437                       
    317438                default:
     439                        dprintf(0, "WARN: unknown request (%d)!\n",
     440                            request->request);
    318441                        break;
    319442        }
     
    325448}
    326449
     450void clear_port_status_change_nl(hub_port_t *port, uint16_t change)
     451{
     452        port->status_change &= (~change);
     453        dprintf(2, "cleared port %d status change %d (%u)", port->index,
     454            (int)change, (unsigned int) port->status_change);
     455}
     456
     457void set_port_status_change_nl(hub_port_t *port, uint16_t change)
     458{
     459        port->status_change |= change;
     460        dprintf(2, "set port %d status change %d (%u)", port->index,
     461            (int)change, (unsigned int) port->status_change);
     462
     463}
     464
    327465void clear_port_status_change(hub_port_t *port, uint16_t change)
    328466{
    329         port->status_change &= (~change);
     467        fibril_mutex_lock(&port->guard);
     468        clear_port_status_change_nl(port, change);
     469        fibril_mutex_unlock(&port->guard);
    330470}
    331471
    332472void set_port_status_change(hub_port_t *port, uint16_t change)
    333473{
    334         port->status_change |= change;
     474        fibril_mutex_lock(&port->guard);
     475        set_port_status_change_nl(port, change);
     476        fibril_mutex_unlock(&port->guard);
    335477}
    336478
     
    350492                hub_port_t *port = &hub_dev.ports[i];
    351493               
     494                fibril_mutex_lock(&port->guard);
    352495                if (port->status_change != 0) {
    353496                        change_map |= (1 << (i + 1));
    354497                }
     498                fibril_mutex_unlock(&port->guard);
    355499        }
    356500       
  • uspace/drv/vhc/vhcd.h

    r84439d7 r75732da  
    3636#define VHCD_VHCD_H_
    3737
     38#include <usb/debug.h>
     39
    3840#define NAME "vhc"
    3941#define NAME_DEV "hcd-virt-dev"
     
    4345#define DEVMAP_PATH_DEV NAMESPACE "/" NAME_DEV
    4446
    45 extern int debug_level;
    46 void dprintf(int, const char *, ...);
     47#define dprintf(level, format, ...) \
     48        usb_dprintf(NAME, (level), format "\n", ##__VA_ARGS__)
    4749void dprintf_inval_call(int, ipc_call_t, ipcarg_t);
    4850
Note: See TracChangeset for help on using the changeset viewer.