Changes in / [a146aa33:cd4ae1e] in mainline


Ignore:
Location:
uspace/drv
Files:
5 edited

Legend:

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

    ra146aa33 rcd4ae1e  
    149149
    150150
    151 static int create_serialized_hub_descriptor(rh_t *instance);
    152 
    153 static int rh_init_descriptors(rh_t *instance);
     151static void usb_create_serialized_hub_descriptor(rh_t *instance,
     152        uint8_t ** out_result,
     153        size_t * out_size);
     154
     155static void rh_init_descriptors(rh_t *instance);
    154156
    155157static int process_get_port_status_request(rh_t *instance, uint16_t port,
     
    162164        usb_transfer_batch_t * request);
    163165
    164 static void create_interrupt_mask_in_instance(rh_t *instance);
     166static void create_interrupt_mask(rh_t *instance, void ** buffer,
     167        size_t * buffer_size);
    165168
    166169static int process_get_descriptor_request(rh_t *instance,
     
    195198static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request);
    196199
    197 static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request);
     200static int process_interrupt(rh_t *instance, usb_transfer_batch_t * request,
     201    void * change_buffer, size_t buffe_size);
    198202
    199203static bool is_zeros(void * buffer, size_t size);
     
    209213        instance->port_count =
    210214            (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK;
    211         int opResult = rh_init_descriptors(instance);
    212         if(opResult != EOK){
    213                 return opResult;
    214         }
     215        rh_init_descriptors(instance);
    215216        // set port power mode to no-power-switching
    216217        instance->registers->rh_desc_a |= RHDA_NPS_FLAG;
    217218        instance->unfinished_interrupt_transfer = NULL;
    218         instance->interrupt_mask_size = (instance->port_count + 8)/8;
    219         instance->interrupt_buffer = malloc(instance->interrupt_mask_size);
    220         if(!instance->interrupt_buffer)
    221                 return ENOMEM;
    222        
    223 
     219        instance->interrupt_buffer = malloc((instance->port_count + 8)/8);
    224220        usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
    225221        return EOK;
     
    244240        } else if (request->ep->transfer_type == USB_TRANSFER_INTERRUPT) {
    245241                usb_log_info("Root hub got INTERRUPT packet\n");
    246                 create_interrupt_mask_in_instance(instance);
    247                 if(is_zeros(instance->interrupt_buffer,
    248                     instance->interrupt_mask_size)){
    249                         usb_log_debug("no changes..\n");
    250                         instance->unfinished_interrupt_transfer = request;
     242                void * buffer;
     243                size_t buffer_size;
     244                create_interrupt_mask(instance, &buffer,
     245                        &buffer_size);
     246                if(is_zeros(buffer,buffer_size)){
     247                        usb_log_debug("no changes..");
     248                        instance->unfinished_interrupt_transfer=
     249                            request;
    251250                        //will be finished later
    252251                }else{
    253                         usb_log_debug("processing changes..\n");
    254                         process_interrupt_mask_in_instance(instance, request);
    255                 }
     252                        usb_log_debug("processing changes..");
     253                        process_interrupt(instance, request,
     254                            buffer, buffer_size);
     255                }
     256                free(buffer);
    256257                opResult = EOK;
    257258        } else {
     
    264265/*----------------------------------------------------------------------------*/
    265266
    266 /**
    267  * process interrupt on a hub
    268  *
    269  * If there is no pending interrupt transfer, nothing happens.
    270  * @param instance
    271  */
     267
    272268void rh_interrupt(rh_t *instance) {
     269        //usb_log_info("Whoa whoa wait, I`m not supposed to receive any "
     270        //      "interrupts, am I?\n");
    273271        if(!instance->unfinished_interrupt_transfer){
    274272                return;
    275273        }
    276         usb_log_debug("finalizing interrupt transfer\n");
    277         create_interrupt_mask_in_instance(instance);
    278         process_interrupt_mask_in_instance(instance,
    279             instance->unfinished_interrupt_transfer);
     274        size_t size;
     275        void * buffer;
     276        create_interrupt_mask(instance, &buffer,
     277                        &size);
     278        process_interrupt(instance,instance->unfinished_interrupt_transfer,
     279            buffer,size);
     280        free(buffer);
    280281}
    281282/*----------------------------------------------------------------------------*/
     
    288289 *
    289290 * @param instance root hub instance
    290  * @return error code
    291  */
    292 static int create_serialized_hub_descriptor(rh_t *instance) {
    293         size_t size = 7 +
    294             ((instance->port_count +7 )/ 8) * 2;
    295         size_t var_size = (instance->port_count +7 )/ 8;
     291 * @param@out out_result pointer to resultant serialized descriptor
     292 * @param@out out_size size of serialized descriptor
     293 */
     294static void usb_create_serialized_hub_descriptor(rh_t *instance,
     295        uint8_t ** out_result,
     296        size_t * out_size) {
     297        //base size
     298        size_t size = 7;
     299        //variable size according to port count
     300        size_t var_size = instance->port_count / 8 +
     301                ((instance->port_count % 8 > 0) ? 1 : 0);
     302        size += 2 * var_size;
    296303        uint8_t * result = (uint8_t*) malloc(size);
    297         if(!result) return ENOMEM;
    298 
    299304        bzero(result, size);
    300305        //size
     
    325330                result[7 + var_size + i] = 255;
    326331        }
    327         instance->hub_descriptor = result;
    328         instance->descriptor_size = size;
    329         return EOK;
     332        (*out_result) = result;
     333        (*out_size) = size;
    330334}
    331335/*----------------------------------------------------------------------------*/
     
    336340 * be initialized only once per hub.
    337341 * @instance root hub instance
    338  * @return error code
    339  */
    340 static int rh_init_descriptors(rh_t *instance) {
     342 */
     343static void rh_init_descriptors(rh_t *instance) {
    341344        memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
    342345                sizeof (ohci_rh_device_descriptor)
     
    345348        memcpy(&descriptor, &ohci_rh_conf_descriptor,
    346349                sizeof (ohci_rh_conf_descriptor));
    347 
    348         int opResult = create_serialized_hub_descriptor(instance);
    349         if(opResult != EOK){
    350                 return opResult;
    351         }
     350        uint8_t * hub_descriptor;
     351        size_t hub_desc_size;
     352        usb_create_serialized_hub_descriptor(instance, &hub_descriptor,
     353                &hub_desc_size);
     354
    352355        descriptor.total_length =
    353356                sizeof (usb_standard_configuration_descriptor_t) +
    354357                sizeof (usb_standard_endpoint_descriptor_t) +
    355358                sizeof (usb_standard_interface_descriptor_t) +
    356                 instance->descriptor_size;
     359                hub_desc_size;
    357360
    358361        uint8_t * full_config_descriptor =
    359362                (uint8_t*) malloc(descriptor.total_length);
    360         if(!full_config_descriptor){
    361                 return ENOMEM;
    362         }
    363363        memcpy(full_config_descriptor, &descriptor, sizeof (descriptor));
    364364        memcpy(full_config_descriptor + sizeof (descriptor),
     
    370370                sizeof (ohci_rh_iface_descriptor) +
    371371                sizeof (ohci_rh_ep_descriptor),
    372                 instance->hub_descriptor, instance->descriptor_size);
    373        
     372                hub_descriptor, hub_desc_size);
     373
    374374        instance->descriptors.configuration = full_config_descriptor;
    375375        instance->descriptors.configuration_size = descriptor.total_length;
    376         return EOK;
    377376}
    378377/*----------------------------------------------------------------------------*/
     
    465464 * bit i indicates change on i`th port (i>0). For more info see
    466465 * Hub and Port status bitmap specification in USB specification
    467  * (chapter 11.13.4).
    468  * Uses instance`s interrupt buffer to store the interrupt information.
    469  * @param instance root hub instance
    470  */
    471 static void create_interrupt_mask_in_instance(rh_t * instance) {
    472         uint8_t * bitmap = (uint8_t*) (instance->interrupt_buffer);
     466 * (chapter 11.13.4)
     467 * @param instance root hub instance
     468 * @param@out buffer pointer to created interrupt mas
     469 * @param@out buffer_size size of created interrupt mask
     470 */
     471static void create_interrupt_mask(rh_t *instance, void ** buffer,
     472        size_t * buffer_size) {
     473        int bit_count = instance->port_count + 1;
     474        (*buffer_size) = (bit_count+7 / 8);
     475
     476        (*buffer) = instance->interrupt_buffer;//malloc(*buffer_size);
     477        uint8_t * bitmap = (uint8_t*) (*buffer);
    473478        uint32_t mask = (1 << (USB_HUB_FEATURE_C_HUB_LOCAL_POWER + 16))
    474479                | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16));
    475         bzero(bitmap, instance->interrupt_mask_size);
     480        bzero(bitmap, (*buffer_size));
    476481        if (instance->registers->rh_status & mask) {
    477482                bitmap[0] = 1;
     
    504509        const uint16_t setup_request_value = setup_request->value_high;
    505510        //(setup_request->value_low << 8);
     511        bool del = false;
    506512        switch (setup_request_value) {
    507513                case USB_DESCTYPE_HUB:
    508514                {
    509                         usb_log_debug("USB_DESCTYPE_HUB\n");
    510                         result_descriptor = instance->hub_descriptor;
    511                         size = instance->descriptor_size;
     515                        uint8_t * descriptor;
     516                        usb_create_serialized_hub_descriptor(
     517                                instance, &descriptor, &size);
     518                        result_descriptor = descriptor;
     519                        if (result_descriptor) del = true;
    512520                        break;
    513521                }
     
    560568        request->transfered_size = size;
    561569        memcpy(request->data_buffer, result_descriptor, size);
     570        if (del)
     571                free(result_descriptor);
    562572        return EOK;
    563573}
     
    885895 * @param instance hub instance
    886896 * @param request batch request to be processed
     897 * @param change_buffer chages on hub
     898 * @param buffer_size size of change buffer
    887899 *
    888900 * @return
    889901 */
    890 static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request){
    891         memcpy(request->data_buffer, instance->interrupt_buffer,
    892             instance->interrupt_mask_size);
    893         request->transfered_size = instance->interrupt_mask_size;
     902static int process_interrupt(rh_t *instance, usb_transfer_batch_t * request,
     903    void * change_buffer, size_t buffe_size){
     904        create_interrupt_mask(instance, &change_buffer,
     905            &(request->transfered_size));
     906        memcpy(request->data_buffer, change_buffer,request->transfered_size);
    894907        instance->unfinished_interrupt_transfer = NULL;
    895908        usb_transfer_batch_finish_error(request, EOK);
  • uspace/drv/ohci/root_hub.h

    ra146aa33 rcd4ae1e  
    5959         *
    6060         * This is allocated when initializing instance, so that memory
    61          * allocation is not needed when processing request. Buffer is used for
    62          * interrupt bitmask.
     61         * allocation is not needed when processing request.
    6362         */
    6463        uint8_t * interrupt_buffer;
    65         /** size of interrupt buffer */
    66         size_t interrupt_mask_size;
    67         /** instance`s descriptor*/
    68         uint8_t * hub_descriptor;
    69         /** size of hub descriptor */
    70         size_t descriptor_size;
    71 
    72 
    7364} rh_t;
    7465
  • uspace/drv/usbhub/main.c

    ra146aa33 rcd4ae1e  
    5555};
    5656
    57 /**
    58  * usb hub driver operations
    59  *
    60  * The most important one is add_device, which is set to usb_hub_add_device.
    61  */
     57
    6258static usb_driver_ops_t usb_hub_driver_ops = {
    6359        .add_device = usb_hub_add_device
    6460};
    6561
    66 /**
    67  * hub endpoints, excluding control endpoint
    68  */
    6962static usb_endpoint_description_t *usb_hub_endpoints[] = {
    7063        &hub_status_change_endpoint_description,
     
    7265};
    7366
    74 /**
    75  * static usb hub driver information
    76  */
    7767static usb_driver_t usb_hub_driver = {
    7868        .name = NAME,
  • uspace/drv/usbhub/ports.c

    ra146aa33 rcd4ae1e  
    167167
    168168        //close address
     169        //if (hub->attached_devs[port].address != 0) {
    169170        if(hub->ports[port].attached_device.address >= 0){
    170171                /*uncomment this code to use it when DDF allows device removal
     
    181182                 */
    182183        } else {
     184                // TODO: is this really reason to print a warning?
    183185                usb_log_warning("Device removed before being registered.\n");
    184186
  • uspace/drv/usbhub/usbhub.c

    ra146aa33 rcd4ae1e  
    7373
    7474
     75/// \TODO malloc checking
     76
    7577//*********************************************
    7678//
     
    246248        hub_info->ports = malloc(
    247249            sizeof (usb_hub_port_t) * (hub_info->port_count + 1));
    248         if(!hub_info->ports){
    249                 return ENOMEM;
    250         }
    251250        size_t port;
    252251        for (port = 0; port < hub_info->port_count + 1; ++port) {
     
    256255                usb_log_debug("is_power_switched\n");
    257256               
     257                for (port = 1; port <= hub_info->port_count; ++port) {
     258                        usb_log_debug("Powering port %zu.\n",port);
     259                        opResult = usb_hub_set_port_feature(hub_info->control_pipe,
     260                            port, USB_HUB_FEATURE_PORT_POWER);
     261                        if (opResult != EOK) {
     262                                usb_log_error("cannot power on port %zu: %s.\n",
     263                                    port, str_error(opResult));
     264                        }
     265                }
    258266                if(!has_individual_port_powering){
    259267                        usb_log_debug("!has_individual_port_powering\n");
     
    265273                        }
    266274                }
    267 
    268                 for (port = 1; port <= hub_info->port_count; ++port) {
    269                         usb_log_debug("Powering port %zu.\n",port);
    270                         opResult = usb_hub_set_port_feature(hub_info->control_pipe,
    271                             port, USB_HUB_FEATURE_PORT_POWER);
    272                         if (opResult != EOK) {
    273                                 usb_log_error("cannot power on port %zu: %s.\n",
    274                                     port, str_error(opResult));
    275                         }
    276                 }
    277                
    278275        }else{
    279                 usb_log_debug("!is_power_switched, not going to be powered\n");
     276                usb_log_debug("!is_power_switched\n");
    280277        }
    281278        usb_log_debug2("freeing data\n");
Note: See TracChangeset for help on using the changeset viewer.