Changeset 1e32a63 in mainline for uspace/drv/vhc/hubops.c


Ignore:
Timestamp:
2010-12-13T00:30:09Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f9a0cef
Parents:
f8597ca
Message:

Guarding port changes by mutex in VHC

The individual ports in virtual host controller are guarded by mutex.

Also added ClearPortFeature(C_PORT_RESET) callback.

File:
1 edited

Legend:

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

    rf8597ca r1e32a63  
    6767    void *buffer, size_t size, size_t *actual_size);
    6868static 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);
    6971
    7072/** Standard USB requests. */
     
    135137        async_usleep(change->delay);
    136138       
     139        fibril_mutex_lock(&change->port->guard);
    137140        if (change->port->state == change->old_state) {
    138                 set_port_state(change->port, change->new_state);
    139         }
     141                set_port_state_nl(change->port, change->new_state);
     142        }
     143        fibril_mutex_unlock(&change->port->guard);
    140144       
    141145        free(change);
     
    166170void set_port_state(hub_port_t *port, hub_port_state_t state)
    167171{
    168         dprintf(1, "setting port %d state to %d (%c)", port->index,
    169             state, hub_port_state_as_char(state));
     172        fibril_mutex_lock(&port->guard);
     173        set_port_state_nl(port, state);
     174        fibril_mutex_unlock(&port->guard);
     175}
     176
     177void set_port_state_nl(hub_port_t *port, hub_port_state_t state)
     178{
     179
     180        dprintf(2, "setting port %d state to %d (%c) from %c (change=%u)",
     181            port->index,
     182            state, hub_port_state_as_char(state),
     183            hub_port_state_as_char(port->state),
     184            (unsigned int) port->status_change);
    170185       
    171186        if (state == HUB_PORT_STATE_POWERED_OFF) {
    172                 clear_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
    173                 clear_port_status_change(port, HUB_STATUS_C_PORT_ENABLE);
    174                 clear_port_status_change(port, HUB_STATUS_C_PORT_RESET);
     187                clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION);
     188                clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE);
     189                clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET);
    175190        }
    176191        if (state == HUB_PORT_STATE_RESUMING) {
     
    184199        if ((port->state == HUB_PORT_STATE_RESETTING)
    185200            && (state == HUB_PORT_STATE_ENABLED)) {
    186                 set_port_status_change(port, HUB_STATUS_C_PORT_RESET);
     201                set_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET);
    187202        }
    188203       
     
    212227        _GET_PORT(port, portindex);
    213228       
     229        fibril_mutex_lock(&port->guard);
     230        int rc = ENOTSUP;
     231
    214232        switch (feature) {
    215233                case USB_HUB_FEATURE_PORT_ENABLE:
    216234                        if ((port->state != HUB_PORT_STATE_NOT_CONFIGURED)
    217235                            && (port->state != HUB_PORT_STATE_POWERED_OFF)) {
    218                                 set_port_state(port, HUB_PORT_STATE_DISABLED);
    219                         }
    220                         return EOK;
     236                                set_port_state_nl(port, HUB_PORT_STATE_DISABLED);
     237                        }
     238                        rc = EOK;
     239                        break;
    221240               
    222241                case USB_HUB_FEATURE_PORT_SUSPEND:
    223242                        if (port->state != HUB_PORT_STATE_SUSPENDED) {
    224                                 return EOK;
    225                         }
    226                         set_port_state(port, HUB_PORT_STATE_RESUMING);
    227                         return EOK;
     243                                rc = EOK;
     244                                break;
     245                        }
     246                        set_port_state_nl(port, HUB_PORT_STATE_RESUMING);
     247                        rc = EOK;
     248                        break;
    228249                       
    229250                case USB_HUB_FEATURE_PORT_POWER:
    230251                        if (port->state != HUB_PORT_STATE_NOT_CONFIGURED) {
    231                                 set_port_state(port, HUB_PORT_STATE_POWERED_OFF);
    232                         }
    233                         return EOK;
     252                                set_port_state_nl(port, HUB_PORT_STATE_POWERED_OFF);
     253                        }
     254                        rc = EOK;
     255                        break;
    234256               
    235257                case USB_HUB_FEATURE_C_PORT_CONNECTION:
    236                         clear_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION);
    237                         return EOK;
     258                        clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION);
     259                        rc = EOK;
     260                        break;
    238261               
    239262                case USB_HUB_FEATURE_C_PORT_ENABLE:
    240                         clear_port_status_change(port, HUB_STATUS_C_PORT_ENABLE);
    241                         return EOK;
     263                        clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE);
     264                        rc = EOK;
     265                        break;
    242266               
    243267                case USB_HUB_FEATURE_C_PORT_SUSPEND:
    244                         clear_port_status_change(port, HUB_STATUS_C_PORT_SUSPEND);
    245                         return EOK;
     268                        clear_port_status_change_nl(port, HUB_STATUS_C_PORT_SUSPEND);
     269                        rc = EOK;
     270                        break;
    246271                       
    247272                case USB_HUB_FEATURE_C_PORT_OVER_CURRENT:
    248                         clear_port_status_change(port, HUB_STATUS_C_PORT_OVER_CURRENT);
    249                         return EOK;
    250         }
    251        
    252         return ENOTSUP;
     273                        clear_port_status_change_nl(port, HUB_STATUS_C_PORT_OVER_CURRENT);
     274                        rc = EOK;
     275                        break;
     276
     277                case USB_HUB_FEATURE_C_PORT_RESET:
     278                        clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET);
     279                        rc = EOK;
     280                        break;
     281        }
     282       
     283        fibril_mutex_unlock(&port->guard);
     284
     285        return rc;
    253286}
    254287
     
    285318        _GET_PORT(port, portindex);
    286319       
     320        fibril_mutex_lock(&port->guard);
     321
    287322        uint32_t status;
    288323        status = MAKE_BYTE(
     
    312347        status |= (port->status_change << 16);
    313348       
     349        fibril_mutex_unlock(&port->guard);
     350
    314351        dprintf(2, "GetPortStatus(port=%d, status=%u)\n", (int)portindex,
    315352            (unsigned int) status);
     
    327364        _GET_PORT(port, portindex);
    328365       
     366        fibril_mutex_lock(&port->guard);
     367
     368        int rc = ENOTSUP;
     369
    329370        switch (feature) {
    330371                case USB_HUB_FEATURE_PORT_RESET:
    331372                        if (port->state != HUB_PORT_STATE_POWERED_OFF) {
    332                                 set_port_state(port, HUB_PORT_STATE_RESETTING);
    333                         }
    334                         return EOK;
     373                                set_port_state_nl(port, HUB_PORT_STATE_RESETTING);
     374                        }
     375                        rc = EOK;
     376                        break;
    335377               
    336378                case USB_HUB_FEATURE_PORT_SUSPEND:
    337379                        if (port->state == HUB_PORT_STATE_ENABLED) {
    338                                 set_port_state(port, HUB_PORT_STATE_SUSPENDED);
    339                         }
    340                         return EOK;
     380                                set_port_state_nl(port, HUB_PORT_STATE_SUSPENDED);
     381                        }
     382                        rc = EOK;
     383                        break;
    341384               
    342385                case USB_HUB_FEATURE_PORT_POWER:
    343386                        if (port->state == HUB_PORT_STATE_POWERED_OFF) {
    344                                 set_port_state(port, HUB_PORT_STATE_DISCONNECTED);
    345                         }
    346                         return EOK;
    347         }
    348         return ENOTSUP;
     387                                set_port_state_nl(port, HUB_PORT_STATE_DISCONNECTED);
     388                        }
     389                        rc = EOK;
     390                        break;
     391        }
     392
     393        fibril_mutex_unlock(&port->guard);
     394        return rc;
    349395}
    350396
     
    416462}
    417463
     464void clear_port_status_change_nl(hub_port_t *port, uint16_t change)
     465{
     466        port->status_change &= (~change);
     467        dprintf(2, "cleared port %d status change %d (%u)", port->index,
     468            (int)change, (unsigned int) port->status_change);
     469}
     470
     471void set_port_status_change_nl(hub_port_t *port, uint16_t change)
     472{
     473        port->status_change |= change;
     474        dprintf(2, "set port %d status change %d (%u)", port->index,
     475            (int)change, (unsigned int) port->status_change);
     476
     477}
     478
    418479void clear_port_status_change(hub_port_t *port, uint16_t change)
    419480{
    420         port->status_change &= (~change);
     481        fibril_mutex_lock(&port->guard);
     482        clear_port_status_change_nl(port, change);
     483        fibril_mutex_unlock(&port->guard);
    421484}
    422485
    423486void set_port_status_change(hub_port_t *port, uint16_t change)
    424487{
    425         port->status_change |= change;
     488        fibril_mutex_lock(&port->guard);
     489        set_port_status_change_nl(port, change);
     490        fibril_mutex_unlock(&port->guard);
    426491}
    427492
     
    441506                hub_port_t *port = &hub_dev.ports[i];
    442507               
     508                fibril_mutex_lock(&port->guard);
    443509                if (port->status_change != 0) {
    444510                        change_map |= (1 << (i + 1));
    445511                }
     512                fibril_mutex_unlock(&port->guard);
    446513        }
    447514       
Note: See TracChangeset for help on using the changeset viewer.