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

Changeset f35b294 in mainline


Ignore:
Timestamp:
2011-04-09T17:50:15Z (11 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial
Children:
a43f1d18
Parents:
1e1b1a9
Message:

codelifting

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/root_hub.c

    r1e1b1a9 rf35b294  
    115115
    116116static const uint32_t hub_set_feature_valid_mask =
    117         (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     117        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) |
     118(1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
    118119
    119120
     
    586587        if (!((1 << feature) & hub_set_feature_valid_mask))
    587588                return EINVAL;
     589        if(feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER)
     590                feature = USB_HUB_FEATURE_C_HUB_LOCAL_POWER << 16;
    588591        instance->registers->rh_status =
    589592                (instance->registers->rh_status | (1 << feature))
  • uspace/drv/usbhub/port_status.h

    r1e1b1a9 rf35b294  
    9696usb_hub_create_port_status_request(uint16_t port) {
    9797        usb_device_request_setup_packet_t * result =
    98                 usb_new(usb_device_request_setup_packet_t);
     98                malloc(sizeof(usb_device_request_setup_packet_t));
    9999        usb_hub_set_port_status_request(result, port);
    100100        return result;
     
    158158usb_hub_create_enable_port_request(uint16_t port) {
    159159        usb_device_request_setup_packet_t * result =
    160                 usb_new(usb_device_request_setup_packet_t);
     160                malloc(sizeof(usb_device_request_setup_packet_t));
    161161        usb_hub_set_enable_port_request(result, port);
    162162        return result;
     
    186186usb_hub_create_disable_port_request(uint16_t port) {
    187187        usb_device_request_setup_packet_t * result =
    188                 usb_new(usb_device_request_setup_packet_t);
     188                malloc(sizeof(usb_device_request_setup_packet_t));
    189189        usb_hub_set_disable_port_request(result, port);
    190190        return result;
     
    214214usb_hub_create_reset_port_request(uint16_t port) {
    215215        usb_device_request_setup_packet_t * result =
    216                 usb_new(usb_device_request_setup_packet_t);
     216                malloc(sizeof(usb_device_request_setup_packet_t));
    217217        usb_hub_set_reset_port_request(result, port);
    218218        return result;
     
    256256 * @return
    257257 */
    258 static inline bool usb_port_get_bit(usb_port_status_t * status, int idx) {
    259         return ((*status)&(1 << idx))!=0;
     258static inline bool usb_port_is_status(usb_port_status_t status, int idx) {
     259        return (status&(1 << idx))!=0;
    260260}
    261261
     
    267267 * @param value
    268268 */
    269 static inline void usb_port_set_bit(
     269static inline void usb_port_status_set_bit(
    270270        usb_port_status_t * status, int idx, bool value) {
    271271        (*status) = value ?
     
    281281 * @return
    282282 */
    283 static inline bool usb_hub_get_bit(usb_hub_status_t * status, int idx) {
    284         return ((*status)&(1 << idx))!=0;
     283static inline bool usb_hub_is_status(usb_hub_status_t status, int idx) {
     284        return (status&(1 << idx))!=0;
    285285}
    286286
     
    292292 * @param value
    293293 */
    294 static inline void usb_hub_set_bit(
     294static inline void usb_hub_status_set_bit(
    295295        usb_hub_status_t * status, int idx, bool value) {
    296296        (*status) = value ?
     
    299299}
    300300
     301
     302#if 0
    301303/**
    302304 * connection status geter for port status
     
    425427}
    426428
     429#endif
     430
    427431//low speed device attached
    428432/**
     
    432436 * @return true if low speed device is attached
    433437 */
    434 static inline bool usb_port_low_speed(usb_port_status_t * status) {
    435         return usb_port_get_bit(status, 9);
    436 }
    437 
    438 /**
    439  * set device connected bit in port status
     438static inline bool usb_port_low_speed(usb_port_status_t status) {
     439        return usb_port_is_status(status, 9);
     440}
     441
     442/**
     443 * set low speed device connected bit in port status
    440444 *
    441445 * @param status
     
    443447 */
    444448static inline void usb_port_set_low_speed(usb_port_status_t * status, bool low_speed) {
    445         usb_port_set_bit(status, 9, low_speed);
     449        usb_port_status_set_bit(status, 9, low_speed);
    446450}
    447451
     
    453457 * @return true if high speed device is on port
    454458 */
    455 static inline bool usb_port_high_speed(usb_port_status_t * status) {
    456         return usb_port_get_bit(status, 10);
     459static inline bool usb_port_high_speed(usb_port_status_t status) {
     460        return usb_port_is_status(status, 10);
    457461}
    458462
     
    464468 */
    465469static inline void usb_port_set_high_speed(usb_port_status_t * status, bool high_speed) {
    466         usb_port_set_bit(status, 10, high_speed);
     470        usb_port_status_set_bit(status, 10, high_speed);
    467471}
    468472
     
    473477 * @return speed of usb device (for more see usb specification)
    474478 */
    475 static inline usb_speed_t usb_port_speed(usb_port_status_t * status) {
     479static inline usb_speed_t usb_port_speed(usb_port_status_t status) {
    476480        if (usb_port_low_speed(status))
    477481                return USB_SPEED_LOW;
     
    481485}
    482486
    483 
     487#if 0
    484488//connect change
    485489/**
     
    673677        usb_hub_set_bit(status, 17, change);
    674678}
     679#endif
    675680
    676681
  • uspace/drv/usbhub/usbhub.c

    r1e1b1a9 rf35b294  
    6161static int usb_hub_set_configuration(usb_hub_info_t * hub_info);
    6262
    63 //static int usb_hub_check_hub_changes(usb_hub_info_t * hub_info_param);
     63static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info);
    6464
    6565static int usb_process_hub_over_current(usb_hub_info_t * hub_info,
    66         usb_hub_status_t status);
     66    usb_hub_status_t status);
    6767
    6868static int usb_process_hub_power_change(usb_hub_info_t * hub_info,
    69         usb_hub_status_t status);
     69    usb_hub_status_t status);
    7070
    7171static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info);
     
    7979//
    8080//*********************************************
    81 
    82 
    8381
    8482/**
     
    9694        usb_log_debug("Initializing USB wire abstraction.\n");
    9795        int opResult = usb_hc_connection_initialize_from_device(
    98                 &hub_info->connection,
    99                 hub_info->usb_device->ddf_dev);
     96            &hub_info->connection,
     97            hub_info->usb_device->ddf_dev);
    10098        if (opResult != EOK) {
    10199                usb_log_error("could not initialize connection to device, "
    102                         "errno %d\n",
    103                         opResult);
     100                    "errno %d\n",
     101                    opResult);
    104102                free(hub_info);
    105103                return opResult;
     
    111109        if (opResult != EOK) {
    112110                usb_log_error("could not set hub configuration, errno %d\n",
    113                         opResult);
     111                    opResult);
    114112                free(hub_info);
    115113                return opResult;
     
    118116        opResult = usb_hub_process_hub_specific_info(hub_info);
    119117        if (opResult != EOK) {
    120                 usb_log_error("could not set hub configuration, errno %d\n",
    121                         opResult);
     118                usb_log_error("could process hub specific info, errno %d\n",
     119                    opResult);
    122120                free(hub_info);
    123121                return opResult;
    124122        }
    125123        usb_pipe_end_session(hub_info->control_pipe);
    126 
    127124
    128125        /// \TODO what is this?
    129126        usb_log_debug("Creating `hub' function.\n");
    130127        ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,
    131                 fun_exposed, "hub");
     128            fun_exposed, "hub");
    132129        assert(hub_fun != NULL);
    133130        hub_fun->ops = NULL;
    134131
    135         int rc = ddf_fun_bind(hub_fun);
    136         assert(rc == EOK);
    137         rc = ddf_fun_add_to_class(hub_fun, "hub");
    138         assert(rc == EOK);
    139 
     132        opResult = ddf_fun_bind(hub_fun);
     133        assert(opResult == EOK);
     134        opResult = ddf_fun_add_to_class(hub_fun, "hub");
     135        assert(opResult == EOK);
     136
     137        opResult = usb_hub_start_hub_fibril(hub_info);
     138        if(opResult!=EOK)
     139                free(hub_info);
     140        return opResult;
     141}
     142
     143
     144/** Callback for polling hub for changes.
     145 *
     146 * @param dev Device where the change occured.
     147 * @param change_bitmap Bitmap of changed ports.
     148 * @param change_bitmap_size Size of the bitmap in bytes.
     149 * @param arg Custom argument, points to @c usb_hub_info_t.
     150 * @return Whether to continue polling.
     151 */
     152bool hub_port_changes_callback(usb_device_t *dev,
     153    uint8_t *change_bitmap, size_t change_bitmap_size, void *arg) {
     154        usb_hub_info_t *hub = (usb_hub_info_t *) arg;
     155
     156        /* FIXME: check that we received enough bytes. */
     157        if (change_bitmap_size == 0) {
     158                goto leave;
     159        }
     160
     161        bool change;
     162        change = ((uint8_t*) change_bitmap)[0] & 1;
     163        if (change) {
     164                usb_hub_process_global_interrupt(hub);
     165        }
     166
     167        size_t port;
     168        for (port = 1; port < hub->port_count + 1; port++) {
     169                bool change = (change_bitmap[port / 8] >> (port % 8)) % 2;
     170                if (change) {
     171                        usb_hub_process_interrupt(hub, port);
     172                }
     173        }
     174leave:
     175        /* FIXME: proper interval. */
     176        async_usleep(1000 * 1000 * 10);
     177
     178        return true;
     179}
     180
     181/**
     182 * release default address used by given hub
     183 *
     184 * Also unsets hub->is_default_address_used. Convenience wrapper function.
     185 * @note hub->connection MUST be open for communication
     186 * @param hub hub representation
     187 * @return error code
     188 */
     189int usb_hub_release_default_address(usb_hub_info_t * hub) {
     190        int opResult = usb_hc_release_default_address(&hub->connection);
     191        if (opResult != EOK) {
     192                usb_log_error("could not release default address, errno %d\n",
     193                    opResult);
     194                return opResult;
     195        }
     196        hub->is_default_address_used = false;
     197        return EOK;
     198}
     199
     200
     201//*********************************************
     202//
     203//  support functions
     204//
     205//*********************************************
     206
     207/**
     208 * create usb_hub_info_t structure
     209 *
     210 * Does only basic copying of known information into new structure.
     211 * @param usb_dev usb device structure
     212 * @return basic usb_hub_info_t structure
     213 */
     214static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) {
     215        usb_hub_info_t * result = malloc(sizeof(usb_hub_info_t));
     216        if (!result) return NULL;
     217        result->usb_device = usb_dev;
     218        result->status_change_pipe = usb_dev->pipes[0].pipe;
     219        result->control_pipe = &usb_dev->ctrl_pipe;
     220        result->is_default_address_used = false;
     221        return result;
     222}
     223
     224/**
     225 * Load hub-specific information into hub_info structure and process if needed
     226 *
     227 * Particularly read port count and initialize structure holding port
     228 * information. If there are non-removable devices, start initializing them.
     229 * This function is hub-specific and should be run only after the hub is
     230 * configured using usb_hub_set_configuration function.
     231 * @param hub_info hub representation
     232 * @return error code
     233 */
     234static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info) {
     235        // get hub descriptor
     236        usb_log_debug("creating serialized descriptor\n");
     237        void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
     238        usb_hub_descriptor_t * descriptor;
     239        int opResult;
     240
     241        size_t received_size;
     242        opResult = usb_request_get_descriptor(hub_info->control_pipe,
     243            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE,
     244            USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
     245            USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
     246
     247        if (opResult != EOK) {
     248                usb_log_error("failed when receiving hub descriptor, "
     249                    "badcode = %d\n",
     250                    opResult);
     251                free(serialized_descriptor);
     252                return opResult;
     253        }
     254        usb_log_debug2("deserializing descriptor\n");
     255        descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
     256        if (descriptor == NULL) {
     257                usb_log_warning("could not deserialize descriptor \n");
     258                return opResult;
     259        }
     260        usb_log_debug("setting port count to %d\n", descriptor->ports_count);
     261        hub_info->port_count = descriptor->ports_count;
     262        /// \TODO this is not semantically correct
     263        hub_info->ports = malloc(
     264            sizeof (usb_hub_port_t) * (hub_info->port_count + 1));
     265        size_t port;
     266        for (port = 0; port < hub_info->port_count + 1; port++) {
     267                usb_hub_port_init(&hub_info->ports[port]);
     268        }
     269        usb_log_debug2("freeing data\n");
     270        free(serialized_descriptor);
     271        free(descriptor->devices_removable);
     272        free(descriptor);
     273        return EOK;
     274}
     275
     276/**
     277 * Set configuration of hub
     278 *
     279 * Check whether there is at least one configuration and sets the first one.
     280 * This function should be run prior to running any hub-specific action.
     281 * @param hub_info hub representation
     282 * @return error code
     283 */
     284static int usb_hub_set_configuration(usb_hub_info_t * hub_info) {
     285        //device descriptor
     286        usb_standard_device_descriptor_t *std_descriptor
     287            = &hub_info->usb_device->descriptors.device;
     288        usb_log_debug("hub has %d configurations\n",
     289            std_descriptor->configuration_count);
     290        if (std_descriptor->configuration_count < 1) {
     291                usb_log_error("there are no configurations available\n");
     292                return EINVAL;
     293        }
     294
     295        usb_standard_configuration_descriptor_t *config_descriptor
     296            = (usb_standard_configuration_descriptor_t *)
     297            hub_info->usb_device->descriptors.configuration;
     298
     299        /* Set configuration. */
     300        int opResult = usb_request_set_configuration(
     301            &hub_info->usb_device->ctrl_pipe,
     302            config_descriptor->configuration_number);
     303
     304        if (opResult != EOK) {
     305                usb_log_error("Failed to set hub configuration: %s.\n",
     306                    str_error(opResult));
     307                return opResult;
     308        }
     309        usb_log_debug("\tused configuration %d\n",
     310            config_descriptor->configuration_number);
     311
     312        return EOK;
     313}
     314
     315/**
     316 * create and start fibril with hub control loop
     317 *
     318 * Before the fibril is started, the control pipe and host controller
     319 * connection of the hub is open.
     320 *
     321 * @param hub_info hub representing structure
     322 * @return error code
     323 */
     324static int usb_hub_start_hub_fibril(usb_hub_info_t * hub_info){
    140325        /*
    141326         * The processing will require opened control pipe and connection
     
    146331         * auto destruction, this could work better.
    147332         */
    148         rc = usb_pipe_start_session(&usb_dev->ctrl_pipe);
     333        int rc = usb_pipe_start_session(hub_info->control_pipe);
    149334        if (rc != EOK) {
    150335                usb_log_error("Failed to start session on control pipe: %s.\n",
    151336                    str_error(rc));
    152                 goto leave;
     337                return rc;
    153338        }
    154339        rc = usb_hc_connection_open(&hub_info->connection);
    155340        if (rc != EOK) {
    156                 usb_pipe_end_session(&usb_dev->ctrl_pipe);
     341                usb_pipe_end_session(hub_info->control_pipe);
    157342                usb_log_error("Failed to open connection to HC: %s.\n",
    158343                    str_error(rc));
    159                 goto leave;
     344                return rc;
    160345        }
    161346
    162347        rc = usb_device_auto_poll(hub_info->usb_device, 0,
    163             hub_port_changes_callback, ((hub_info->port_count+1) / 8) + 1,
     348            hub_port_changes_callback, ((hub_info->port_count + 1) / 8) + 1,
    164349            NULL, hub_info);
    165350        if (rc != EOK) {
     
    171356
    172357        usb_log_info("Controlling hub `%s' (%d ports).\n",
    173                 hub_info->usb_device->ddf_dev->name, hub_info->port_count);
     358            hub_info->usb_device->ddf_dev->name, hub_info->port_count);
    174359        return EOK;
    175 leave:
    176         free(hub_info);
    177 
    178         return rc;
    179 }
    180 
    181 
    182 //*********************************************
    183 //
    184 //  hub driver code, main loop and port handling
    185 //
    186 //*********************************************
    187 
    188 
    189 /** Callback for polling hub for changes.
    190  *
    191  * @param dev Device where the change occured.
    192  * @param change_bitmap Bitmap of changed ports.
    193  * @param change_bitmap_size Size of the bitmap in bytes.
    194  * @param arg Custom argument, points to @c usb_hub_info_t.
    195  * @return Whether to continue polling.
    196  */
    197 bool hub_port_changes_callback(usb_device_t *dev,
    198     uint8_t *change_bitmap, size_t change_bitmap_size, void *arg)
    199 {
    200         usb_hub_info_t *hub = (usb_hub_info_t *) arg;
    201 
    202         /* FIXME: check that we received enough bytes. */
    203         if (change_bitmap_size == 0) {
    204                 goto leave;
    205         }
    206 
    207         bool change;
    208         change = ((uint8_t*)change_bitmap)[0] & 1;
    209         if(change){
    210                 usb_hub_process_global_interrupt(hub);
    211         }
    212 
    213         size_t port;
    214         for (port = 1; port < hub->port_count + 1; port++) {
    215                 bool change = (change_bitmap[port / 8] >> (port % 8)) % 2;
    216                 if (change) {
    217                         usb_hub_process_interrupt(hub, port);
    218                 }
    219         }
    220 
    221 
    222 
    223 
    224 
    225 leave:
    226         /* FIXME: proper interval. */
    227         async_usleep(1000 * 1000 * 10 );
    228 
    229         return true;
    230 }
    231 
    232 
    233 /**
    234  * release default address used by given hub
    235  *
    236  * Also unsets hub->is_default_address_used. Convenience wrapper function.
    237  * @note hub->connection MUST be open for communication
    238  * @param hub hub representation
    239  * @return error code
    240  */
    241 int usb_hub_release_default_address(usb_hub_info_t * hub) {
    242         int opResult = usb_hc_release_default_address(&hub->connection);
    243         if (opResult != EOK) {
    244                 usb_log_error("could not release default address, errno %d\n",
    245                         opResult);
    246                 return opResult;
    247         }
    248         hub->is_default_address_used = false;
    249         return EOK;
    250 }
    251 
    252 
    253 //*********************************************
    254 //
    255 //  support functions
    256 //
    257 //*********************************************
    258 
    259 /**
    260  * create usb_hub_info_t structure
    261  *
    262  * Does only basic copying of known information into new structure.
    263  * @param usb_dev usb device structure
    264  * @return basic usb_hub_info_t structure
    265  */
    266 static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) {
    267         usb_hub_info_t * result = usb_new(usb_hub_info_t);
    268         if (!result) return NULL;
    269         result->usb_device = usb_dev;
    270         result->status_change_pipe = usb_dev->pipes[0].pipe;
    271         result->control_pipe = &usb_dev->ctrl_pipe;
    272         result->is_default_address_used = false;
    273         return result;
    274 }
    275 
    276 
    277 /**
    278  * Load hub-specific information into hub_info structure and process if needed
    279  *
    280  * Particularly read port count and initialize structure holding port
    281  * information. If there are non-removable devices, start initializing them.
    282  * This function is hub-specific and should be run only after the hub is
    283  * configured using usb_hub_set_configuration function.
    284  * @param hub_info hub representation
    285  * @return error code
    286  */
    287 static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info) {
    288         // get hub descriptor
    289         usb_log_debug("creating serialized descriptor\n");
    290         void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
    291         usb_hub_descriptor_t * descriptor;
    292         int opResult;
    293 
    294         size_t received_size;
    295         opResult = usb_request_get_descriptor(hub_info->control_pipe,
    296                 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE,
    297                 USB_DESCTYPE_HUB,
    298                 0, 0, serialized_descriptor,
    299                 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
    300 
    301         if (opResult != EOK) {
    302                 usb_log_error("failed when receiving hub descriptor, "
    303                         "badcode = %d\n",
    304                         opResult);
    305                 free(serialized_descriptor);
    306                 return opResult;
    307         }
    308         usb_log_debug2("deserializing descriptor\n");
    309         descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
    310         if (descriptor == NULL) {
    311                 usb_log_warning("could not deserialize descriptor \n");
    312                 return opResult;
    313         }
    314         usb_log_debug("setting port count to %d\n", descriptor->ports_count);
    315         hub_info->port_count = descriptor->ports_count;
    316         /// \TODO this is not semantically correct
    317         hub_info->ports = malloc(sizeof(usb_hub_port_t) * (hub_info->port_count+1));
    318         size_t port;
    319         for (port = 0; port < hub_info->port_count + 1; port++) {
    320                 usb_hub_port_init(&hub_info->ports[port]);
    321         }
    322         usb_log_debug2("freeing data\n");
    323         free(serialized_descriptor);
    324         free(descriptor->devices_removable);
    325         free(descriptor);
    326         return EOK;
    327 }
    328 
    329 /**
    330  * Set configuration of hub
    331  *
    332  * Check whether there is at least one configuration and sets the first one.
    333  * This function should be run prior to running any hub-specific action.
    334  * @param hub_info hub representation
    335  * @return error code
    336  */
    337 static int usb_hub_set_configuration(usb_hub_info_t * hub_info) {
    338         //device descriptor
    339         usb_standard_device_descriptor_t *std_descriptor
    340                 = &hub_info->usb_device->descriptors.device;
    341         usb_log_debug("hub has %d configurations\n",
    342                 std_descriptor->configuration_count);
    343         if (std_descriptor->configuration_count < 1) {
    344                 usb_log_error("there are no configurations available\n");
    345                 return EINVAL;
    346         }
    347 
    348         usb_standard_configuration_descriptor_t *config_descriptor
    349                 = (usb_standard_configuration_descriptor_t *)
    350                 hub_info->usb_device->descriptors.configuration;
    351 
    352         /* Set configuration. */
    353         int opResult = usb_request_set_configuration(
    354                 &hub_info->usb_device->ctrl_pipe,
    355                 config_descriptor->configuration_number);
    356 
    357         if (opResult != EOK) {
    358                 usb_log_error("Failed to set hub configuration: %s.\n",
    359                         str_error(opResult));
    360                 return opResult;
    361         }
    362         usb_log_debug("\tused configuration %d\n",
    363                 config_descriptor->configuration_number);
    364 
    365         return EOK;
    366 }
    367 
    368 #if 0
    369 /**
    370  * check changes on hub
    371  *
    372  * Handles changes on each port with a status change.
    373  * @param hub_info hub representation
    374  * @return error code
    375  */
    376 static int usb_hub_check_hub_changes(usb_hub_info_t * hub_info) {
    377         int opResult;
    378         opResult = usb_pipe_start_session(
    379                 hub_info->status_change_pipe);
    380         //this might not be necessary - if all non-removables are ok, it is
    381         //not needed here
    382         opResult = usb_pipe_start_session(hub_info->control_pipe);
    383         if (opResult != EOK) {
    384                 usb_log_error("could not initialize communication for hub; %d\n",
    385                         opResult);
    386                 return opResult;
    387         }
    388 
    389         size_t port_count = hub_info->port_count;
    390         size_t byte_length = ((port_count + 1) / 8) + 1;
    391         void *change_bitmap = malloc(byte_length);
    392         size_t actual_size;
    393 
    394         /*
    395          * Send the request.
    396          */
    397         opResult = usb_pipe_read(
    398                 hub_info->status_change_pipe,
    399                 change_bitmap, byte_length, &actual_size
    400                 );
    401 
    402         if (opResult != EOK) {
    403                 free(change_bitmap);
    404                 usb_log_warning("something went wrong while getting the"
    405                         "status of hub\n");
    406                 usb_pipe_end_session(hub_info->status_change_pipe);
    407                 return opResult;
    408         }
    409         unsigned int port;
    410 
    411         if (opResult != EOK) {
    412                 usb_log_error("could not start control pipe session %d\n",
    413                         opResult);
    414                 usb_pipe_end_session(hub_info->status_change_pipe);
    415                 return opResult;
    416         }
    417         opResult = usb_hc_connection_open(&hub_info->connection);
    418         if (opResult != EOK) {
    419                 usb_log_error("could not start host controller session %d\n",
    420                         opResult);
    421                 usb_pipe_end_session(hub_info->control_pipe);
    422                 usb_pipe_end_session(hub_info->status_change_pipe);
    423                 return opResult;
    424         }
    425 
    426         ///todo, opresult check, pre obe konekce
    427         bool interrupt;
    428         interrupt = ((uint8_t*)change_bitmap)[0] & 1;
    429         if(interrupt){
    430                 usb_hub_process_global_interrupt(hub_info);
    431         }
    432         for (port = 1; port < port_count + 1; ++port) {
    433                 interrupt =
    434                         ((uint8_t*) change_bitmap)[port / 8] & (1<<(port % 8));
    435                 if (interrupt) {
    436                         usb_hub_process_interrupt(
    437                                 hub_info, port);
    438                 }
    439         }
    440         /// \todo check hub status
    441         usb_hc_connection_close(&hub_info->connection);
    442         usb_pipe_end_session(hub_info->control_pipe);
    443         usb_pipe_end_session(hub_info->status_change_pipe);
    444         free(change_bitmap);
    445         return EOK;
    446 }
    447 
    448 #endif
     360}
     361
     362//*********************************************
     363//
     364//  change handling functions
     365//
     366//*********************************************
     367
    449368
    450369/**
     
    457376 */
    458377static int usb_process_hub_over_current(usb_hub_info_t * hub_info,
    459         usb_hub_status_t status)
    460 {
     378    usb_hub_status_t status) {
    461379        int opResult;
    462         if(usb_hub_over_current(&status)){
     380        if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_OVER_CURRENT)){
    463381                opResult = usb_hub_clear_feature(hub_info->control_pipe,
    464                         USB_HUB_FEATURE_PORT_POWER);
     382                    USB_HUB_FEATURE_HUB_LOCAL_POWER);
    465383                if (opResult != EOK) {
    466384                        usb_log_error("cannot power off hub: %d\n",
    467                                 opResult);
     385                            opResult);
    468386                }
    469         }else{
     387        } else {
    470388                opResult = usb_hub_set_feature(hub_info->control_pipe,
    471                         USB_HUB_FEATURE_PORT_POWER);
     389                    USB_HUB_FEATURE_HUB_LOCAL_POWER);
    472390                if (opResult != EOK) {
    473391                        usb_log_error("cannot power on hub: %d\n",
    474                                 opResult);
     392                            opResult);
    475393                }
    476394        }
     
    488406 */
    489407static int usb_process_hub_power_change(usb_hub_info_t * hub_info,
    490         usb_hub_status_t status)
    491 {
     408    usb_hub_status_t status) {
    492409        int opResult;
    493         if(usb_hub_local_power_lost(&status)){
     410        if (usb_hub_is_status(status,USB_HUB_FEATURE_HUB_LOCAL_POWER)) {
    494411                //restart power on hub
    495412                opResult = usb_hub_set_feature(hub_info->control_pipe,
    496                         USB_HUB_FEATURE_PORT_POWER);
     413                    USB_HUB_FEATURE_HUB_LOCAL_POWER);
    497414                if (opResult != EOK) {
    498415                        usb_log_error("cannot power on hub: %d\n",
    499                                 opResult);
     416                            opResult);
    500417                }
    501         }else{//power reestablished on hub- restart ports
     418        } else {//power reestablished on hub- restart ports
    502419                size_t port;
    503                 for(port=0;port<hub_info->port_count;++port){
     420                for (port = 0; port < hub_info->port_count; ++port) {
    504421                        opResult = usb_hub_set_port_feature(
    505                                 hub_info->control_pipe,
    506                                 port, USB_HUB_FEATURE_PORT_POWER);
     422                            hub_info->control_pipe,
     423                            port, USB_HUB_FEATURE_PORT_POWER);
    507424                        if (opResult != EOK) {
    508425                                usb_log_error("cannot power on port %d;  %d\n",
    509                                         port, opResult);
     426                                    port, opResult);
    510427                        }
    511428                }
     
    521438 * @param hub_info hub instance
    522439 */
    523 static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info){
     440static void usb_hub_process_global_interrupt(usb_hub_info_t * hub_info) {
    524441        usb_log_debug("global interrupt on a hub\n");
    525442        usb_pipe_t *pipe = hub_info->control_pipe;
     
    534451
    535452        opResult = usb_pipe_control_read(
    536                 pipe,
    537                 &request, sizeof (usb_device_request_setup_packet_t),
    538                 &status, 4, &rcvd_size
    539                 );
     453            pipe,
     454            &request, sizeof (usb_device_request_setup_packet_t),
     455            &status, 4, &rcvd_size
     456            );
    540457        if (opResult != EOK) {
    541458                usb_log_error("could not get hub status\n");
     
    547464        }
    548465        //port reset
    549         if (usb_hub_over_current_change(&status)) {
    550                 usb_process_hub_over_current(hub_info,status);
    551         }
    552         if (usb_hub_local_power_change(&status)) {
    553                 usb_process_hub_power_change(hub_info,status);
    554         }
    555 }
    556 
    557 
     466        if (
     467            usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {
     468                usb_process_hub_over_current(hub_info, status);
     469        }
     470        if (
     471            usb_hub_is_status(status,16+USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
     472                usb_process_hub_power_change(hub_info, status);
     473        }
     474}
    558475
    559476/**
  • uspace/drv/usbhub/usbhub_private.h

    r1e1b1a9 rf35b294  
    5454//
    5555//************
    56 #define usb_new(type) (type*)malloc(sizeof(type))
    5756
    5857
    59 /**
    60  * Create hub structure instance
    61  *
    62  * Set the address and port count information most importantly.
    63  *
    64  * @param device
    65  * @param hc host controller phone
    66  * @return
    67  */
    6858usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device);
    6959
  • uspace/drv/usbhub/utils.c

    r1e1b1a9 rf35b294  
    6060        size_t size = 7;
    6161        //variable size according to port count
    62         size_t var_size = descriptor->ports_count / 8 + ((descriptor->ports_count % 8 > 0) ? 1 : 0);
     62        size_t var_size = (descriptor->ports_count+7)/8;
    6363        size += 2 * var_size;
    64         uint8_t * result = (uint8_t*) malloc(size);
     64        uint8_t * result = malloc(size);
    6565        //size
    6666        result[0] = size;
     
    8484}
    8585
    86 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * serialized_descriptor) {
    87         uint8_t * sdescriptor = (uint8_t*) serialized_descriptor;
     86usb_hub_descriptor_t * usb_deserialize_hub_desriptor(
     87void * serialized_descriptor) {
     88        uint8_t * sdescriptor = serialized_descriptor;
    8889
    8990        if (sdescriptor[1] != USB_DESCTYPE_HUB) {
    90                 usb_log_warning("trying to deserialize wrong descriptor %x\n",sdescriptor[1]);
     91                usb_log_warning("trying to deserialize wrong descriptor %x\n",
     92                    sdescriptor[1]);
    9193                return NULL;
    9294        }
    9395
    94         usb_hub_descriptor_t * result = usb_new(usb_hub_descriptor_t);
     96        usb_hub_descriptor_t * result = malloc(sizeof(usb_hub_descriptor_t));
    9597       
    9698
     
    100102        result->pwr_on_2_good_time = sdescriptor[5];
    101103        result->current_requirement = sdescriptor[6];
    102         size_t var_size = result->ports_count / 8 + ((result->ports_count % 8 > 0)
    103                         ? 1 : 0);
     104        size_t var_size = (result->ports_count+7) / 8;
    104105        result->devices_removable = (uint8_t*) malloc(var_size);
    105106
  • uspace/lib/usb/include/usb/classes/hub.h

    r1e1b1a9 rf35b294  
    4343 */
    4444typedef enum {
     45        USB_HUB_FEATURE_HUB_LOCAL_POWER = 0,
     46        USB_HUB_FEATURE_HUB_OVER_CURRENT = 1,
    4547        USB_HUB_FEATURE_C_HUB_LOCAL_POWER = 0,
    4648        USB_HUB_FEATURE_C_HUB_OVER_CURRENT = 1,
     
    5961        /* USB_HUB_FEATURE_ = , */
    6062} usb_hub_class_feature_t;
     63
    6164
    6265/** Header of standard hub descriptor without the "variadic" part. */
Note: See TracChangeset for help on using the changeset viewer.