Changeset cb0ab9e in mainline


Ignore:
Timestamp:
2011-05-07T14:40:46Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6985b4e
Parents:
df0bbe1 (diff), 7205209 (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
Files:
8 edited

Legend:

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

    rdf0bbe1 rcb0ab9e  
    4949static int interrupt_emulator(hc_t *instance);
    5050static void hc_gain_control(hc_t *instance);
    51 static void hc_init_hw(hc_t *instance);
    5251static int hc_init_transfer_lists(hc_t *instance);
    5352static int hc_init_memory(hc_t *instance);
     
    9291                usb_log_error("Failed add root hub match-id.\n");
    9392        }
     93        ret = ddf_fun_bind(hub_fun);
    9494        return ret;
    9595}
     
    111111            ret, str_error(ret));
    112112
     113        list_initialize(&instance->pending_batches);
    113114        usb_device_keeper_init(&instance->manager);
    114115        ret = usb_endpoint_manager_init(&instance->ep_manager,
     
    117118            str_error(ret));
    118119
    119         hc_gain_control(instance);
    120120        ret = hc_init_memory(instance);
    121121        CHECK_RET_RETURN(ret, "Failed to create OHCI memory structures: %s.\n",
    122122            str_error(ret));
    123         hc_init_hw(instance);
     123#undef CHECK_RET_RETURN
     124
     125
     126//      hc_init_hw(instance);
     127        hc_gain_control(instance);
    124128        fibril_mutex_initialize(&instance->guard);
    125129
     
    132136        }
    133137
    134         list_initialize(&instance->pending_batches);
    135 #undef CHECK_RET_RETURN
    136138        return EOK;
    137139}
     
    287289{
    288290        assert(instance);
    289         usb_log_debug("OHCI interrupt: %x.\n", status);
     291        usb_log_debug("OHCI(%p) interrupt: %x.\n", instance, status);
    290292        if ((status & ~I_SF) == 0) /* ignore sof status */
    291293                return;
     
    339341            (uint32_t*)((char*)instance->registers + 0x100);
    340342        usb_log_debug("OHCI legacy register %p: %x.\n",
    341                 ohci_emulation_reg, *ohci_emulation_reg);
    342         *ohci_emulation_reg &= ~0x1;
     343            ohci_emulation_reg, *ohci_emulation_reg);
     344        /* Do not change A20 state */
     345        *ohci_emulation_reg &= 0x100;
     346        usb_log_debug("OHCI legacy register %p: %x.\n",
     347            ohci_emulation_reg, *ohci_emulation_reg);
    343348
    344349        /* Interrupt routing enabled => smm driver is active */
     
    350355                }
    351356                usb_log_info("SMM driver: Ownership taken.\n");
     357                instance->registers->control &= (C_HCFS_RESET << C_HCFS_SHIFT);
     358                async_usleep(50000);
    352359                return;
    353360        }
     
    375382}
    376383/*----------------------------------------------------------------------------*/
    377 void hc_init_hw(hc_t *instance)
     384void hc_start_hw(hc_t *instance)
    378385{
    379386        /* OHCI guide page 42 */
     
    474481{
    475482        assert(instance);
     483
     484        bzero(&instance->rh, sizeof(instance->rh));
    476485        /* Init queues */
    477486        hc_init_transfer_lists(instance);
  • uspace/drv/ohci/hc.h

    rdf0bbe1 rcb0ab9e  
    8080     uintptr_t regs, size_t reg_size, bool interrupts);
    8181
     82void hc_start_hw(hc_t *instance);
     83
    8284/** Safely dispose host controller internal structures
    8385 *
  • uspace/drv/ohci/main.c

    rdf0bbe1 rcb0ab9e  
    7575                return ret;
    7676        }
    77         device->driver_data = ohci;
     77//      device->driver_data = ohci;
     78        hc_register_hub(&ohci->hc, ohci->rh_fun);
    7879
    7980        usb_log_info("Controlling new OHCI device `%s'.\n", device->name);
     
    9394{
    9495        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    95         sleep(5);
    9696        return ddf_driver_main(&ohci_driver);
    9797}
  • uspace/drv/ohci/ohci.c

    rdf0bbe1 rcb0ab9e  
    5454{
    5555        assert(dev);
     56        assert(dev->driver_data);
    5657        hc_t *hc = &((ohci_t*)dev->driver_data)->hc;
    5758        uint16_t status = IPC_GET_ARG1(*call);
     
    152153        usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n",
    153154            (void *) mem_reg_base, mem_reg_size, irq);
    154 
    155         ret = pci_disable_legacy(device);
    156         CHECK_RET_DEST_FUN_RETURN(ret,
    157             "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
    158155
    159156        bool interrupts = false;
     
    216213            "Failed(%d) to create root hub function.\n", ret);
    217214
    218         hc_register_hub(&instance->hc, instance->rh_fun);
    219215
    220216        instance->rh_fun->ops = &rh_ops;
    221217        instance->rh_fun->driver_data = NULL;
    222         ret = ddf_fun_bind(instance->rh_fun);
    223         CHECK_RET_FINI_RETURN(ret,
    224             "Failed(%d) to register OHCI root hub.\n", ret);
    225 
     218       
     219        device->driver_data = instance;
     220
     221        hc_start_hw(&instance->hc);
    226222        return EOK;
    227223#undef CHECK_RET_FINI_RETURN
  • uspace/drv/ohci/pci.c

    rdf0bbe1 rcb0ab9e  
    136136        return enabled ? EOK : EIO;
    137137}
    138 /*----------------------------------------------------------------------------*/
    139 /** Implements BIOS handoff routine as decribed in OHCI spec
    140  *
    141  * @param[in] device Device asking for interrupts
    142  * @return Error code.
    143  */
    144 int pci_disable_legacy(ddf_dev_t *device)
    145 {
    146         /* TODO: implement */
    147         return EOK;
    148 }
    149 /*----------------------------------------------------------------------------*/
    150138/**
    151139 * @}
  • uspace/drv/ohci/root_hub.c

    rdf0bbe1 rcb0ab9e  
    4545
    4646/**
    47  *      standart device descriptor for ohci root hub
     47 * standart device descriptor for ohci root hub
    4848 */
    4949static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = {
     
    6969 */
    7070static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = {
    71         /// \TODO some values are default or guessed
    7271        .attributes = 1 << 7,
    7372        .configuration_number = 1,
     
    8786        .endpoint_count = 1,
    8887        .interface_class = USB_CLASS_HUB,
    89         /// \TODO is this correct?
    9088        .interface_number = 1,
    9189        .interface_protocol = 0,
     
    107105};
    108106
     107/**
     108 * bitmask of hub features that are valid to be cleared
     109 */
    109110static const uint32_t hub_clear_feature_valid_mask =
    110         (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) |
     111    (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) |
    111112(1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    112113
     114/**
     115 * bitmask of hub features that are cleared by writing 1 (and not 0)
     116 */
    113117static const uint32_t hub_clear_feature_by_writing_one_mask =
    114         1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
    115 
     118    1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
     119
     120/**
     121 * bitmask of hub features that are valid to be set
     122 */
    116123static const uint32_t hub_set_feature_valid_mask =
    117         (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) |
     124    (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) |
    118125(1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
    119126
    120 
     127/**
     128 * bitmask of hub features that are set by writing 1 and cleared by writing 0
     129 */
    121130static const uint32_t hub_set_feature_direct_mask =
    122         (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    123 
     131    (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     132
     133/**
     134 * bitmask of port features that are valid to be set
     135 */
    124136static const uint32_t port_set_feature_valid_mask =
    125         (1 << USB_HUB_FEATURE_PORT_ENABLE) |
     137    (1 << USB_HUB_FEATURE_PORT_ENABLE) |
    126138(1 << USB_HUB_FEATURE_PORT_SUSPEND) |
    127139(1 << USB_HUB_FEATURE_PORT_RESET) |
    128140(1 << USB_HUB_FEATURE_PORT_POWER);
    129141
     142/**
     143 * bitmask of port features that can be cleared
     144 */
    130145static const uint32_t port_clear_feature_valid_mask =
    131         (1 << USB_HUB_FEATURE_PORT_CONNECTION) |
     146    (1 << USB_HUB_FEATURE_PORT_CONNECTION) |
    132147(1 << USB_HUB_FEATURE_PORT_SUSPEND) |
    133148(1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) |
     
    141156//USB_HUB_FEATURE_PORT_LOW_SPEED
    142157
     158/**
     159 * bitmask with port status changes
     160 */
    143161static const uint32_t port_status_change_mask =
    144 (1<< USB_HUB_FEATURE_C_PORT_CONNECTION) |
    145 (1<< USB_HUB_FEATURE_C_PORT_ENABLE) |
    146 (1<< USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
    147 (1<< USB_HUB_FEATURE_C_PORT_RESET) |
    148 (1<< USB_HUB_FEATURE_C_PORT_SUSPEND);
     162    (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) |
     163(1 << USB_HUB_FEATURE_C_PORT_ENABLE) |
     164(1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
     165(1 << USB_HUB_FEATURE_C_PORT_RESET) |
     166(1 << USB_HUB_FEATURE_C_PORT_SUSPEND);
    149167
    150168
     
    154172
    155173static int process_get_port_status_request(rh_t *instance, uint16_t port,
    156         usb_transfer_batch_t * request);
     174    usb_transfer_batch_t * request);
    157175
    158176static int process_get_hub_status_request(rh_t *instance,
    159         usb_transfer_batch_t * request);
     177    usb_transfer_batch_t * request);
    160178
    161179static int process_get_status_request(rh_t *instance,
    162         usb_transfer_batch_t * request);
     180    usb_transfer_batch_t * request);
    163181
    164182static void create_interrupt_mask_in_instance(rh_t *instance);
    165183
    166184static int process_get_descriptor_request(rh_t *instance,
    167         usb_transfer_batch_t *request);
     185    usb_transfer_batch_t *request);
    168186
    169187static int process_get_configuration_request(rh_t *instance,
    170         usb_transfer_batch_t *request);
     188    usb_transfer_batch_t *request);
    171189
    172190static int process_hub_feature_set_request(rh_t *instance, uint16_t feature);
    173191
    174192static int process_hub_feature_clear_request(rh_t *instance,
    175         uint16_t feature);
     193    uint16_t feature);
    176194
    177195static int process_port_feature_set_request(rh_t *instance,
    178         uint16_t feature, uint16_t port);
     196    uint16_t feature, uint16_t port);
    179197
    180198static int process_port_feature_clear_request(rh_t *instance,
    181         uint16_t feature, uint16_t port);
     199    uint16_t feature, uint16_t port);
    182200
    183201static int process_address_set_request(rh_t *instance,
    184         uint16_t address);
     202    uint16_t address);
    185203
    186204static int process_request_with_output(rh_t *instance,
    187         usb_transfer_batch_t *request);
     205    usb_transfer_batch_t *request);
    188206
    189207static int process_request_with_input(rh_t *instance,
    190         usb_transfer_batch_t *request);
     208    usb_transfer_batch_t *request);
    191209
    192210static int process_request_without_data(rh_t *instance,
    193         usb_transfer_batch_t *request);
     211    usb_transfer_batch_t *request);
    194212
    195213static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request);
     
    198216
    199217static bool is_zeros(void * buffer, size_t size);
    200 
    201 
    202218
    203219/** Root hub initialization
     
    210226            (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK;
    211227        int opResult = rh_init_descriptors(instance);
    212         if(opResult != EOK){
     228        if (opResult != EOK) {
    213229                return opResult;
    214230        }
     
    216232        instance->registers->rh_desc_a |= RHDA_NPS_FLAG;
    217233        instance->unfinished_interrupt_transfer = NULL;
    218         instance->interrupt_mask_size = (instance->port_count + 8)/8;
     234        instance->interrupt_mask_size = (instance->port_count + 8) / 8;
    219235        instance->interrupt_buffer = malloc(instance->interrupt_mask_size);
    220         if(!instance->interrupt_buffer)
     236        if (!instance->interrupt_buffer)
    221237                return ENOMEM;
    222        
    223 
    224         usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
     238
     239        usb_log_info("OHCI root hub with %d ports initialized.\n",
     240            instance->port_count);
     241
    225242        return EOK;
    226243}
     
    245262                usb_log_info("Root hub got INTERRUPT packet\n");
    246263                create_interrupt_mask_in_instance(instance);
    247                 if(is_zeros(instance->interrupt_buffer,
    248                     instance->interrupt_mask_size)){
     264                if (is_zeros(instance->interrupt_buffer,
     265                    instance->interrupt_mask_size)) {
    249266                        usb_log_debug("no changes..\n");
    250267                        instance->unfinished_interrupt_transfer = request;
    251268                        //will be finished later
    252                 }else{
     269                } else {
    253270                        usb_log_debug("processing changes..\n");
    254271                        process_interrupt_mask_in_instance(instance, request);
     
    256273                opResult = EOK;
    257274        } else {
     275
    258276                opResult = EINVAL;
    259277                usb_transfer_batch_finish_error(request, opResult);
     
    271289 */
    272290void rh_interrupt(rh_t *instance) {
    273         if(!instance->unfinished_interrupt_transfer){
     291        if (!instance->unfinished_interrupt_transfer) {
    274292                return;
    275293        }
     
    292310static int create_serialized_hub_descriptor(rh_t *instance) {
    293311        size_t size = 7 +
    294             ((instance->port_count +7 )/ 8) * 2;
    295         size_t var_size = (instance->port_count +7 )/ 8;
     312            ((instance->port_count + 7) / 8) * 2;
     313        size_t var_size = (instance->port_count + 7) / 8;
    296314        uint8_t * result = (uint8_t*) malloc(size);
    297         if(!result) return ENOMEM;
     315        if (!result) return ENOMEM;
    298316
    299317        bzero(result, size);
     
    305323        uint32_t hub_desc_reg = instance->registers->rh_desc_a;
    306324        result[3] =
    307                 ((hub_desc_reg >> 8) % 2) +
    308                 (((hub_desc_reg >> 9) % 2) << 1) +
    309                 (((hub_desc_reg >> 10) % 2) << 2) +
    310                 (((hub_desc_reg >> 11) % 2) << 3) +
    311                 (((hub_desc_reg >> 12) % 2) << 4);
     325            ((hub_desc_reg >> 8) % 2) +
     326            (((hub_desc_reg >> 9) % 2) << 1) +
     327            (((hub_desc_reg >> 10) % 2) << 2) +
     328            (((hub_desc_reg >> 11) % 2) << 3) +
     329            (((hub_desc_reg >> 12) % 2) << 4);
    312330        result[4] = 0;
    313331        result[5] = /*descriptor->pwr_on_2_good_time*/ 50;
    314332        result[6] = 50;
    315333
    316         int port;
     334        size_t port;
    317335        for (port = 1; port <= instance->port_count; ++port) {
    318336                uint8_t is_non_removable =
    319                         instance->registers->rh_desc_b >> port % 2;
     337                    instance->registers->rh_desc_b >> port % 2;
    320338                result[7 + port / 8] +=
    321                         is_non_removable << (port % 8);
     339                    is_non_removable << (port % 8);
    322340        }
    323341        size_t i;
     
    327345        instance->hub_descriptor = result;
    328346        instance->descriptor_size = size;
     347
    329348        return EOK;
    330349}
     
    340359static int rh_init_descriptors(rh_t *instance) {
    341360        memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
    342                 sizeof (ohci_rh_device_descriptor)
    343                 );
     361            sizeof (ohci_rh_device_descriptor)
     362            );
    344363        usb_standard_configuration_descriptor_t descriptor;
    345364        memcpy(&descriptor, &ohci_rh_conf_descriptor,
    346                 sizeof (ohci_rh_conf_descriptor));
     365            sizeof (ohci_rh_conf_descriptor));
    347366
    348367        int opResult = create_serialized_hub_descriptor(instance);
    349         if(opResult != EOK){
     368        if (opResult != EOK) {
    350369                return opResult;
    351370        }
    352371        descriptor.total_length =
    353                 sizeof (usb_standard_configuration_descriptor_t) +
    354                 sizeof (usb_standard_endpoint_descriptor_t) +
    355                 sizeof (usb_standard_interface_descriptor_t) +
    356                 instance->descriptor_size;
     372            sizeof (usb_standard_configuration_descriptor_t) +
     373            sizeof (usb_standard_endpoint_descriptor_t) +
     374            sizeof (usb_standard_interface_descriptor_t) +
     375            instance->descriptor_size;
    357376
    358377        uint8_t * full_config_descriptor =
    359                 (uint8_t*) malloc(descriptor.total_length);
    360         if(!full_config_descriptor){
     378            (uint8_t*) malloc(descriptor.total_length);
     379        if (!full_config_descriptor) {
    361380                return ENOMEM;
    362381        }
    363382        memcpy(full_config_descriptor, &descriptor, sizeof (descriptor));
    364383        memcpy(full_config_descriptor + sizeof (descriptor),
    365                 &ohci_rh_iface_descriptor, sizeof (ohci_rh_iface_descriptor));
     384            &ohci_rh_iface_descriptor, sizeof (ohci_rh_iface_descriptor));
    366385        memcpy(full_config_descriptor + sizeof (descriptor) +
    367                 sizeof (ohci_rh_iface_descriptor),
    368                 &ohci_rh_ep_descriptor, sizeof (ohci_rh_ep_descriptor));
     386            sizeof (ohci_rh_iface_descriptor),
     387            &ohci_rh_ep_descriptor, sizeof (ohci_rh_ep_descriptor));
    369388        memcpy(full_config_descriptor + sizeof (descriptor) +
    370                 sizeof (ohci_rh_iface_descriptor) +
    371                 sizeof (ohci_rh_ep_descriptor),
    372                 instance->hub_descriptor, instance->descriptor_size);
    373        
     389            sizeof (ohci_rh_iface_descriptor) +
     390            sizeof (ohci_rh_ep_descriptor),
     391            instance->hub_descriptor, instance->descriptor_size);
     392
    374393        instance->descriptors.configuration = full_config_descriptor;
    375394        instance->descriptors.configuration_size = descriptor.total_length;
     395
    376396        return EOK;
    377397}
     
    389409 */
    390410static int process_get_port_status_request(rh_t *instance, uint16_t port,
    391         usb_transfer_batch_t * request) {
     411    usb_transfer_batch_t * request) {
    392412        if (port < 1 || port > instance->port_count)
    393413                return EINVAL;
     
    398418        int i;
    399419        for (i = 0; i < instance->port_count; ++i) {
     420
    400421                usb_log_debug("port status %d,x%x\n",
    401                         instance->registers->rh_port_status[i],
    402                         instance->registers->rh_port_status[i]);
     422                    instance->registers->rh_port_status[i],
     423                    instance->registers->rh_port_status[i]);
    403424        }
    404425#endif
     
    417438 */
    418439static int process_get_hub_status_request(rh_t *instance,
    419         usb_transfer_batch_t * request) {
     440    usb_transfer_batch_t * request) {
    420441        uint32_t * uint32_buffer = (uint32_t*) request->data_buffer;
    421442        request->transfered_size = 4;
     
    423444        uint32_t mask = 1 | (1 << 1) | (1 << 16) | (1 << 17);
    424445        uint32_buffer[0] = mask & instance->registers->rh_status;
     446
    425447        return EOK;
    426448}
     
    437459 */
    438460static int process_get_status_request(rh_t *instance,
    439         usb_transfer_batch_t * request) {
     461    usb_transfer_batch_t * request) {
    440462        size_t buffer_size = request->buffer_size;
    441463        usb_device_request_setup_packet_t * request_packet =
    442                 (usb_device_request_setup_packet_t*)
    443                 request->setup_buffer;
     464            (usb_device_request_setup_packet_t*)
     465            request->setup_buffer;
    444466
    445467        usb_hub_bm_request_type_t request_type = request_packet->request_type;
     
    453475        if (request_type == USB_HUB_REQ_TYPE_GET_PORT_STATUS)
    454476                return process_get_port_status_request(instance,
    455                 request_packet->index,
    456                 request);
     477            request_packet->index,
     478            request);
     479
    457480        return ENOTSUP;
    458481}
     
    472495        uint8_t * bitmap = (uint8_t*) (instance->interrupt_buffer);
    473496        uint32_t mask = (1 << (USB_HUB_FEATURE_C_HUB_LOCAL_POWER + 16))
    474                 | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16));
     497            | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16));
    475498        bzero(bitmap, instance->interrupt_mask_size);
    476499        if (instance->registers->rh_status & mask) {
    477500                bitmap[0] = 1;
    478501        }
    479         int port;
     502        size_t port;
    480503        mask = port_status_change_mask;
    481504        for (port = 1; port <= instance->port_count; ++port) {
    482505                if (mask & instance->registers->rh_port_status[port - 1]) {
     506
    483507                        bitmap[(port) / 8] += 1 << (port % 8);
    484508                }
     
    497521 */
    498522static int process_get_descriptor_request(rh_t *instance,
    499         usb_transfer_batch_t *request) {
     523    usb_transfer_batch_t *request) {
    500524        usb_device_request_setup_packet_t * setup_request =
    501                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     525            (usb_device_request_setup_packet_t*) request->setup_buffer;
    502526        size_t size;
    503527        const void * result_descriptor = NULL;
     
    543567                {
    544568                        usb_log_debug("USB_DESCTYPE_EINVAL %d \n",
    545                                 setup_request->value);
     569                            setup_request->value);
    546570                        usb_log_debug("\ttype %d\n\trequest %d\n\tvalue "
    547                                 "%d\n\tindex %d\n\tlen %d\n ",
    548                                 setup_request->request_type,
    549                                 setup_request->request,
    550                                 setup_request_value,
    551                                 setup_request->index,
    552                                 setup_request->length
    553                                 );
     571                            "%d\n\tindex %d\n\tlen %d\n ",
     572                            setup_request->request_type,
     573                            setup_request->request,
     574                            setup_request_value,
     575                            setup_request->index,
     576                            setup_request->length
     577                            );
    554578                        return EINVAL;
    555579                }
     
    560584        request->transfered_size = size;
    561585        memcpy(request->data_buffer, result_descriptor, size);
     586
    562587        return EOK;
    563588}
     
    573598 */
    574599static int process_get_configuration_request(rh_t *instance,
    575         usb_transfer_batch_t *request) {
     600    usb_transfer_batch_t *request) {
    576601        //set and get configuration requests do not have any meaning, only dummy
    577602        //values are returned
     
    580605        request->data_buffer[0] = 1;
    581606        request->transfered_size = 1;
     607
    582608        return EOK;
    583609}
     
    592618 */
    593619static int process_hub_feature_set_request(rh_t *instance,
    594         uint16_t feature) {
     620    uint16_t feature) {
    595621        if (!((1 << feature) & hub_set_feature_valid_mask))
    596622                return EINVAL;
    597         if(feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER)
     623        if (feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER)
    598624                feature = USB_HUB_FEATURE_C_HUB_LOCAL_POWER << 16;
    599625        instance->registers->rh_status =
    600                 (instance->registers->rh_status | (1 << feature))
    601                 & (~hub_clear_feature_by_writing_one_mask);
     626            (instance->registers->rh_status | (1 << feature))
     627            & (~hub_clear_feature_by_writing_one_mask);
     628
    602629        return EOK;
    603630}
     
    612639 */
    613640static int process_hub_feature_clear_request(rh_t *instance,
    614         uint16_t feature) {
     641    uint16_t feature) {
    615642        if (!((1 << feature) & hub_clear_feature_valid_mask))
    616643                return EINVAL;
     
    618645        if ((1 << feature) & hub_set_feature_direct_mask) {
    619646                instance->registers->rh_status =
    620                         (instance->registers->rh_status & (~(1 << feature)))
    621                         & (~hub_clear_feature_by_writing_one_mask);
     647                    (instance->registers->rh_status & (~(1 << feature)))
     648                    & (~hub_clear_feature_by_writing_one_mask);
    622649        } else {//the feature is cleared by writing '1'
     650
    623651                instance->registers->rh_status =
    624                         (instance->registers->rh_status
    625                         & (~hub_clear_feature_by_writing_one_mask))
    626                         | (1 << feature);
     652                    (instance->registers->rh_status
     653                    & (~hub_clear_feature_by_writing_one_mask))
     654                    | (1 << feature);
    627655        }
    628656        return EOK;
     
    640668 */
    641669static int process_port_feature_set_request(rh_t *instance,
    642         uint16_t feature, uint16_t port) {
     670    uint16_t feature, uint16_t port) {
    643671        if (!((1 << feature) & port_set_feature_valid_mask))
    644672                return EINVAL;
     
    646674                return EINVAL;
    647675        instance->registers->rh_port_status[port - 1] =
    648                 (instance->registers->rh_port_status[port - 1] | (1 << feature))
    649                 & (~port_clear_feature_valid_mask);
     676            (instance->registers->rh_port_status[port - 1] | (1 << feature))
     677            & (~port_clear_feature_valid_mask);
    650678        /// \TODO any error?
     679
    651680        return EOK;
    652681}
     
    663692 */
    664693static int process_port_feature_clear_request(rh_t *instance,
    665         uint16_t feature, uint16_t port) {
     694    uint16_t feature, uint16_t port) {
    666695        if (!((1 << feature) & port_clear_feature_valid_mask))
    667696                return EINVAL;
     
    673702                feature = USB_HUB_FEATURE_PORT_OVER_CURRENT;
    674703        instance->registers->rh_port_status[port - 1] =
    675                 (instance->registers->rh_port_status[port - 1]
    676                 & (~port_clear_feature_valid_mask))
    677                 | (1 << feature);
     704            (instance->registers->rh_port_status[port - 1]
     705            & (~port_clear_feature_valid_mask))
     706            | (1 << feature);
    678707        /// \TODO any error?
     708
    679709        return EOK;
    680710}
     
    689719 */
    690720static int process_address_set_request(rh_t *instance,
    691         uint16_t address) {
     721    uint16_t address) {
    692722        instance->address = address;
     723
    693724        return EOK;
    694725}
     
    705736 */
    706737static int process_request_with_output(rh_t *instance,
    707         usb_transfer_batch_t *request) {
     738    usb_transfer_batch_t *request) {
    708739        usb_device_request_setup_packet_t * setup_request =
    709                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     740            (usb_device_request_setup_packet_t*) request->setup_buffer;
    710741        if (setup_request->request == USB_DEVREQ_GET_STATUS) {
    711742                usb_log_debug("USB_DEVREQ_GET_STATUS\n");
     
    718749        if (setup_request->request == USB_DEVREQ_GET_CONFIGURATION) {
    719750                usb_log_debug("USB_DEVREQ_GET_CONFIGURATION\n");
     751
    720752                return process_get_configuration_request(instance, request);
    721753        }
     
    734766 */
    735767static int process_request_with_input(rh_t *instance,
    736         usb_transfer_batch_t *request) {
     768    usb_transfer_batch_t *request) {
    737769        usb_device_request_setup_packet_t * setup_request =
    738                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     770            (usb_device_request_setup_packet_t*) request->setup_buffer;
    739771        request->transfered_size = 0;
    740772        if (setup_request->request == USB_DEVREQ_SET_DESCRIPTOR) {
     
    744776                //set and get configuration requests do not have any meaning,
    745777                //only dummy values are returned
     778
    746779                return EOK;
    747780        }
     
    760793 */
    761794static int process_request_without_data(rh_t *instance,
    762         usb_transfer_batch_t *request) {
     795    usb_transfer_batch_t *request) {
    763796        usb_device_request_setup_packet_t * setup_request =
    764                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     797            (usb_device_request_setup_packet_t*) request->setup_buffer;
    765798        request->transfered_size = 0;
    766799        if (setup_request->request == USB_DEVREQ_CLEAR_FEATURE) {
     
    768801                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    769802                        return process_hub_feature_clear_request(instance,
    770                                 setup_request->value);
     803                            setup_request->value);
    771804                }
    772805                if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
    773806                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    774807                        return process_port_feature_clear_request(instance,
    775                                 setup_request->value,
    776                                 setup_request->index);
     808                            setup_request->value,
     809                            setup_request->index);
    777810                }
    778811                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
    779                         setup_request->request_type);
     812                    setup_request->request_type);
    780813                return EINVAL;
    781814        }
     
    784817                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    785818                        return process_hub_feature_set_request(instance,
    786                                 setup_request->value);
     819                            setup_request->value);
    787820                }
    788821                if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
    789822                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    790823                        return process_port_feature_set_request(instance,
    791                                 setup_request->value,
    792                                 setup_request->index);
     824                            setup_request->value,
     825                            setup_request->index);
    793826                }
    794827                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
    795                         setup_request->request_type);
     828                    setup_request->request_type);
    796829                return EINVAL;
    797830        }
     
    799832                usb_log_debug("USB_DEVREQ_SET_ADDRESS\n");
    800833                return process_address_set_request(instance,
    801                         setup_request->value);
     834                    setup_request->value);
    802835        }
    803836        usb_log_debug("USB_DEVREQ_SET_ENOTSUP %d\n",
    804                 setup_request->request_type);
     837            setup_request->request_type);
     838
    805839        return ENOTSUP;
    806840}
     
    836870        }
    837871        usb_log_info("CTRL packet: %s.\n",
    838                 usb_debug_str_buffer(
    839                 (const uint8_t *) request->setup_buffer, 8, 8));
     872            usb_debug_str_buffer(
     873            (const uint8_t *) request->setup_buffer, 8, 8));
    840874        usb_device_request_setup_packet_t * setup_request =
    841                 (usb_device_request_setup_packet_t*)
    842                 request->setup_buffer;
     875            (usb_device_request_setup_packet_t*)
     876            request->setup_buffer;
    843877        switch (setup_request->request) {
    844878                case USB_DEVREQ_GET_STATUS:
     
    847881                        usb_log_debug("processing request with output\n");
    848882                        opResult = process_request_with_output(
    849                                 instance, request);
     883                            instance, request);
    850884                        break;
    851885                case USB_DEVREQ_CLEAR_FEATURE:
     
    853887                case USB_DEVREQ_SET_ADDRESS:
    854888                        usb_log_debug("processing request without "
    855                                 "additional data\n");
     889                            "additional data\n");
    856890                        opResult = process_request_without_data(
    857                                 instance, request);
     891                            instance, request);
    858892                        break;
    859893                case USB_DEVREQ_SET_DESCRIPTOR:
    860894                case USB_DEVREQ_SET_CONFIGURATION:
    861895                        usb_log_debug("processing request with "
    862                                 "input\n");
     896                            "input\n");
    863897                        opResult = process_request_with_input(
    864                                 instance, request);
     898                            instance, request);
     899
    865900                        break;
    866901                default:
    867902                        usb_log_warning("received unsuported request: "
    868                                 "%d\n",
    869                                 setup_request->request
    870                                 );
     903                            "%d\n",
     904                            setup_request->request
     905                            );
    871906                        opResult = ENOTSUP;
    872907        }
     
    888923 * @return
    889924 */
    890 static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request){
     925static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request) {
    891926        memcpy(request->data_buffer, instance->interrupt_buffer,
    892927            instance->interrupt_mask_size);
     
    894929        instance->unfinished_interrupt_transfer = NULL;
    895930        usb_transfer_batch_finish_error(request, EOK);
     931
    896932        return EOK;
    897933}
     
    907943 * @return
    908944 */
    909 static bool is_zeros(void * buffer, size_t size){
    910         if(!buffer) return true;
    911         if(!size) return true;
     945static bool is_zeros(void * buffer, size_t size) {
     946        if (!buffer) return true;
     947        if (!size) return true;
    912948        size_t i;
    913         for(i=0;i<size;++i){
    914                 if(((char*)buffer)[i])
     949        for (i = 0; i < size; ++i) {
     950                if (((char*) buffer)[i])
    915951                        return false;
    916952        }
  • uspace/drv/ohci/root_hub.h

    rdf0bbe1 rcb0ab9e  
    5151        usb_address_t address;
    5252        /** hub port count */
    53         int port_count;
     53        size_t port_count;
    5454        /** hubs descriptors */
    5555        usb_device_descriptors_t descriptors;
  • uspace/drv/usbhub/ports.c

    rdf0bbe1 rcb0ab9e  
    5353        size_t port;
    5454        usb_speed_t speed;
     55};
     56
     57/**
     58 * count of port status changes that are not explicitly handled by
     59 * any function here and must be cleared by hand
     60 */
     61static const unsigned int non_handled_changes_count = 2;
     62
     63/**
     64 * port status changes that are not explicitly handled by
     65 * any function here and must be cleared by hand
     66 */
     67static const int non_handled_changes[] =  {
     68        USB_HUB_FEATURE_C_PORT_ENABLE,
     69        USB_HUB_FEATURE_C_PORT_SUSPEND
    5570};
    5671
     
    131146            &status, USB_HUB_FEATURE_C_PORT_CONNECTION,false);
    132147        usb_port_status_set_bit(
    133             &status, USB_HUB_FEATURE_PORT_RESET,false);
    134         usb_port_status_set_bit(
    135148            &status, USB_HUB_FEATURE_C_PORT_RESET,false);
    136149        usb_port_status_set_bit(
    137150            &status, USB_HUB_FEATURE_C_PORT_OVER_CURRENT,false);
    138         /// \TODO what about port power change?
    139         if (status >> 16) {
    140                 usb_log_info("there was unsupported change on port %d: %X\n",
    141                         port, status);
    142 
     151       
     152        //clearing not yet handled changes     
     153        unsigned int feature_idx;
     154        for(feature_idx = 0;feature_idx<non_handled_changes_count;
     155            ++feature_idx){
     156                unsigned int bit_idx = non_handled_changes[feature_idx];
     157                if(status & (1<<bit_idx)){
     158                        usb_log_info(
     159                            "there was not yet handled change on port %d: %d"
     160                            ";clearing it\n",
     161                        port, bit_idx);
     162                        int opResult = usb_hub_clear_port_feature(
     163                            hub->control_pipe,
     164                            port, bit_idx);
     165                        if (opResult != EOK) {
     166                                usb_log_warning(
     167                                    "could not clear port flag %d: %d\n",
     168                                    bit_idx, opResult
     169                                    );
     170                        }
     171                        usb_port_status_set_bit(
     172                            &status, bit_idx,false);
     173                }
     174        }
     175        if(status>>16){
     176                usb_log_info("there is still some unhandled change %X\n",
     177                    status);
    143178        }
    144179}
     
    222257                    "Port %zu reset complete but port not enabled.\n",
    223258                    (size_t) port);
     259        }
     260        /* Clear the port reset change. */
     261        int rc = usb_hub_clear_port_feature(hub->control_pipe,
     262            port, USB_HUB_FEATURE_C_PORT_RESET);
     263        if (rc != EOK) {
     264                usb_log_error("Failed to clear port %d reset feature: %s.\n",
     265                    port, str_error(rc));
    224266        }
    225267}
     
    319361        fibril_mutex_unlock(&my_port->reset_mutex);
    320362
    321         /* Clear the port reset change. */
    322         rc = usb_hub_clear_port_feature(hub->control_pipe,
    323             port_no, USB_HUB_FEATURE_C_PORT_RESET);
    324         if (rc != EOK) {
    325                 usb_log_error("Failed to clear port %d reset feature: %s.\n",
    326                     port_no, str_error(rc));
    327                 return rc;
    328         }
    329 
    330363        if (my_port->reset_okay) {
    331364                return EOK;
Note: See TracChangeset for help on using the changeset viewer.