Changes in / [c6cb76d:7dfc06fa] in mainline


Ignore:
Files:
17 deleted
23 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/amd64/Makefile.inc

    rc6cb76d r7dfc06fa  
    5050        usbhub \
    5151        usbkbd \
    52         usbhid \
    5352        usbmid \
    5453        usbmouse \
  • uspace/Makefile

    rc6cb76d r7dfc06fa  
    123123                drv/usbflbk \
    124124                drv/usbkbd \
    125                 drv/usbhid \
    126125                drv/usbhub \
    127126                drv/usbmid \
     
    144143                drv/usbflbk \
    145144                drv/usbkbd \
    146                 drv/usbhid \
    147145                drv/usbhub \
    148146                drv/usbmid \
  • uspace/drv/ohci/root_hub.c

    rc6cb76d r7dfc06fa  
    4747 *      standart device descriptor for ohci root hub
    4848 */
    49 static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = {
    50         .configuration_count = 1,
    51         .descriptor_type = USB_DESCTYPE_DEVICE,
    52         .device_class = USB_CLASS_HUB,
    53         .device_protocol = 0,
    54         .device_subclass = 0,
    55         .device_version = 0,
    56         .length = sizeof (usb_standard_device_descriptor_t),
    57         /// \TODO this value is guessed
    58         .max_packet_size = 8,
    59         .vendor_id = 0x16db,
    60         .product_id = 0x0001,
    61         /// \TODO these values migt be different
    62         .str_serial_number = 0,
    63         .usb_spec_version = 0x110,
     49static const usb_standard_device_descriptor_t ohci_rh_device_descriptor =
     50{
     51                .configuration_count = 1,
     52                .descriptor_type = USB_DESCTYPE_DEVICE,
     53                .device_class = USB_CLASS_HUB,
     54                .device_protocol = 0,
     55                .device_subclass = 0,
     56                .device_version = 0,
     57                .length = sizeof(usb_standard_device_descriptor_t),
     58                /// \TODO this value is guessed
     59                .max_packet_size = 8,
     60                .vendor_id = 0x16db,
     61                .product_id = 0x0001,
     62                /// \TODO these values migt be different
     63                .str_serial_number = 0,
     64                .usb_spec_version = 0x110,
    6465};
    6566
     
    6869 * for ohci root hubs
    6970 */
    70 static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = {
     71static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor =
     72{
    7173        /// \TODO some values are default or guessed
    72         .attributes = 1 << 7,
     74        .attributes = 1<<7,
    7375        .configuration_number = 1,
    7476        .descriptor_type = USB_DESCTYPE_CONFIGURATION,
    7577        .interface_count = 1,
    76         .length = sizeof (usb_standard_configuration_descriptor_t),
     78        .length = sizeof(usb_standard_configuration_descriptor_t),
    7779        .max_power = 100,
    7880        .str_configuration = 0,
     
    8284 * standart ohci root hub interface descriptor
    8385 */
    84 static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor = {
     86static const usb_standard_interface_descriptor_t ohci_rh_iface_descriptor =
     87{
    8588        .alternate_setting = 0,
    8689        .descriptor_type = USB_DESCTYPE_INTERFACE,
     
    9194        .interface_protocol = 0,
    9295        .interface_subclass = 0,
    93         .length = sizeof (usb_standard_interface_descriptor_t),
     96        .length = sizeof(usb_standard_interface_descriptor_t),
    9497        .str_interface = 0,
    9598};
     
    98101 * standart ohci root hub endpoint descriptor
    99102 */
    100 static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor = {
     103static const usb_standard_endpoint_descriptor_t ohci_rh_ep_descriptor =
     104{
    101105        .attributes = USB_TRANSFER_INTERRUPT,
    102106        .descriptor_type = USB_DESCTYPE_ENDPOINT,
    103         .endpoint_address = 1 + (1 << 7),
    104         .length = sizeof (usb_standard_endpoint_descriptor_t),
     107        .endpoint_address = 1 + (1<<7),
     108        .length = sizeof(usb_standard_endpoint_descriptor_t),
    105109        .max_packet_size = 8,
    106110        .poll_interval = 255,
     
    108112
    109113static const uint32_t hub_clear_feature_valid_mask =
    110         (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) |
    111 (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     114        (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) +
     115        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    112116
    113117static const uint32_t hub_clear_feature_by_writing_one_mask =
     
    117121        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    118122
    119 
     123       
    120124static const uint32_t hub_set_feature_direct_mask =
    121125        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    122126
    123127static const uint32_t port_set_feature_valid_mask =
    124         (1 << USB_HUB_FEATURE_PORT_ENABLE) |
    125 (1 << USB_HUB_FEATURE_PORT_SUSPEND) |
    126 (1 << USB_HUB_FEATURE_PORT_RESET) |
    127 (1 << USB_HUB_FEATURE_PORT_POWER);
     128        (1 << USB_HUB_FEATURE_PORT_ENABLE) +
     129        (1 << USB_HUB_FEATURE_PORT_SUSPEND) +
     130        (1 << USB_HUB_FEATURE_PORT_RESET) +
     131        (1 << USB_HUB_FEATURE_PORT_POWER);
    128132
    129133static const uint32_t port_clear_feature_valid_mask =
    130         (1 << USB_HUB_FEATURE_PORT_CONNECTION) |
    131 (1 << USB_HUB_FEATURE_PORT_SUSPEND) |
    132 (1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) |
    133 (1 << USB_HUB_FEATURE_PORT_POWER) |
    134 (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) |
    135 (1 << USB_HUB_FEATURE_C_PORT_ENABLE) |
    136 (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) |
    137 (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
    138 (1 << USB_HUB_FEATURE_C_PORT_RESET);
    139 //note that USB_HUB_FEATURE_PORT_POWER bit is translated into
    140 //USB_HUB_FEATURE_PORT_LOW_SPEED
    141 
    142 static const uint32_t port_status_change_mask =
    143 (1<< USB_HUB_FEATURE_C_PORT_CONNECTION) |
    144 (1<< USB_HUB_FEATURE_C_PORT_ENABLE) |
    145 (1<< USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
    146 (1<< USB_HUB_FEATURE_C_PORT_RESET) |
    147 (1<< USB_HUB_FEATURE_C_PORT_SUSPEND);
    148 
    149 
    150 static void usb_create_serialized_hub_descriptor(rh_t *instance,
    151         uint8_t ** out_result,
    152         size_t * out_size);
    153 
    154 static void rh_init_descriptors(rh_t *instance);
    155 
    156 static int process_get_port_status_request(rh_t *instance, uint16_t port,
    157         usb_transfer_batch_t * request);
    158 
    159 static int process_get_hub_status_request(rh_t *instance,
    160         usb_transfer_batch_t * request);
    161 
    162 static int process_get_status_request(rh_t *instance,
    163         usb_transfer_batch_t * request);
    164 
    165 static void create_interrupt_mask(rh_t *instance, void ** buffer,
    166         size_t * buffer_size);
    167 
    168 static int process_get_descriptor_request(rh_t *instance,
    169         usb_transfer_batch_t *request);
    170 
    171 static int process_get_configuration_request(rh_t *instance,
    172         usb_transfer_batch_t *request);
    173 
    174 static int process_hub_feature_set_request(rh_t *instance, uint16_t feature);
    175 
    176 static int process_hub_feature_clear_request(rh_t *instance,
    177         uint16_t feature);
    178 
    179 static int process_port_feature_set_request(rh_t *instance,
    180         uint16_t feature, uint16_t port);
    181 
    182 static int process_port_feature_clear_request(rh_t *instance,
    183         uint16_t feature, uint16_t port);
    184 
    185 static int process_address_set_request(rh_t *instance,
    186         uint16_t address);
    187 
    188 static int process_request_with_output(rh_t *instance,
    189         usb_transfer_batch_t *request);
    190 
    191 static int process_request_with_input(rh_t *instance,
    192         usb_transfer_batch_t *request);
    193 
    194 static int process_request_without_data(rh_t *instance,
    195         usb_transfer_batch_t *request);
    196 
    197 static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request);
    198 
    199 
    200 
    201 
    202 
    203 /** Root hub initialization
    204  * @return Error code.
    205  */
    206 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs) {
    207         assert(instance);
    208         //instance->address = -1;
    209         instance->registers = regs;
    210         instance->device = dev;
    211         instance->port_count = instance->registers->rh_desc_a & 0xff;
    212         rh_init_descriptors(instance);
    213         // set port power mode to no-power-switching
    214         instance->registers->rh_desc_a =
    215                 instance->registers->rh_desc_a | (1<<9);
    216 
    217         usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
    218 
    219         //start generic usb hub driver
    220 
    221         /* TODO: implement */
    222         return EOK;
    223 }
    224 /*----------------------------------------------------------------------------*/
    225 
    226 /**
    227  * process root hub request
    228  *
    229  * @param instance root hub instance
    230  * @param request structure containing both request and response information
    231  * @return error code
    232  */
    233 int rh_request(rh_t *instance, usb_transfer_batch_t *request) {
    234         assert(instance);
    235         assert(request);
    236         int opResult;
    237         if (request->transfer_type == USB_TRANSFER_CONTROL) {
    238                 usb_log_info("Root hub got CONTROL packet\n");
    239                 opResult = process_ctrl_request(instance, request);
    240         } else if (request->transfer_type == USB_TRANSFER_INTERRUPT) {
    241                 usb_log_info("Root hub got INTERRUPT packet\n");
    242                 void * buffer;
    243                 create_interrupt_mask(instance, &buffer,
    244                         &(request->transfered_size));
    245                 memcpy(request->transport_buffer, buffer,
    246                         request->transfered_size);
    247                 opResult = EOK;
    248         } else {
    249                 opResult = EINVAL;
    250         }
    251         usb_transfer_batch_finish_error(request, opResult);
    252         return EOK;
    253 }
    254 
    255 /*----------------------------------------------------------------------------*/
    256 
    257 
    258 void rh_interrupt(rh_t *instance) {
    259         usb_log_info("Whoa whoa wait, I`m not supposed to receive any "
    260                 "interrupts, am I?\n");
    261         /* TODO: implement? */
    262 }
    263 /*----------------------------------------------------------------------------*/
     134        (1 << USB_HUB_FEATURE_PORT_CONNECTION) +
     135        (1 << USB_HUB_FEATURE_PORT_SUSPEND) +
     136        (1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) +
     137        (1 << USB_HUB_FEATURE_PORT_POWER) +
     138        (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) +
     139        (1 << USB_HUB_FEATURE_C_PORT_ENABLE) +
     140        (1 << USB_HUB_FEATURE_C_PORT_SUSPEND) +
     141        (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) +
     142        (1 << USB_HUB_FEATURE_C_PORT_RESET);
     143//note that USB_HUB_FEATURE_PORT_POWER bit is translated into USB_HUB_FEATURE_PORT_LOW_SPEED
     144
     145
     146
    264147
    265148/**
     
    274157 */
    275158static void usb_create_serialized_hub_descriptor(rh_t *instance,
    276         uint8_t ** out_result,
    277         size_t * out_size) {
     159                uint8_t ** out_result,
     160                size_t * out_size) {
    278161        //base size
    279162        size_t size = 7;
    280163        //variable size according to port count
    281164        size_t var_size = instance->port_count / 8 +
    282                 ((instance->port_count % 8 > 0) ? 1 : 0);
     165                        ((instance->port_count % 8 > 0) ? 1 : 0);
    283166        size += 2 * var_size;
    284167        uint8_t * result = (uint8_t*) malloc(size);
    285         bzero(result, size);
     168        bzero(result,size);
    286169        //size
    287170        result[0] = size;
     
    291174        uint32_t hub_desc_reg = instance->registers->rh_desc_a;
    292175        result[3] =
    293                 ((hub_desc_reg >> 8) % 2) +
    294                 (((hub_desc_reg >> 9) % 2) << 1) +
    295                 (((hub_desc_reg >> 10) % 2) << 2) +
    296                 (((hub_desc_reg >> 11) % 2) << 3) +
    297                 (((hub_desc_reg >> 12) % 2) << 4);
     176                        ((hub_desc_reg >> 8) %2) +
     177                        (((hub_desc_reg >> 9) %2) << 1) +
     178                        (((hub_desc_reg >> 10) %2) << 2) +
     179                        (((hub_desc_reg >> 11) %2) << 3) +
     180                        (((hub_desc_reg >> 12) %2) << 4);
    298181        result[4] = 0;
    299182        result[5] = /*descriptor->pwr_on_2_good_time*/ 50;
     
    302185        int port;
    303186        for (port = 1; port <= instance->port_count; ++port) {
    304                 uint8_t is_non_removable =
    305                         instance->registers->rh_desc_b >> port % 2;
    306                 result[7 + port / 8] +=
    307                         is_non_removable << (port % 8);
     187                result[7 + port/8] +=
     188                                ((instance->registers->rh_desc_b >> port)%2) << (port%8);
    308189        }
    309190        size_t i;
     
    314195        (*out_size) = size;
    315196}
    316 /*----------------------------------------------------------------------------*/
     197
    317198
    318199/** initialize hub descriptors
     
    322203 * @instance root hub instance
    323204 */
    324 static void rh_init_descriptors(rh_t *instance) {
     205static void rh_init_descriptors(rh_t *instance){
    325206        memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
    326                 sizeof (ohci_rh_device_descriptor)
    327                 );
     207                sizeof(ohci_rh_device_descriptor)
     208        );
    328209        usb_standard_configuration_descriptor_t descriptor;
    329         memcpy(&descriptor, &ohci_rh_conf_descriptor,
    330                 sizeof (ohci_rh_conf_descriptor));
     210        memcpy(&descriptor,&ohci_rh_conf_descriptor,
     211                        sizeof(ohci_rh_conf_descriptor));
    331212        uint8_t * hub_descriptor;
    332213        size_t hub_desc_size;
    333214        usb_create_serialized_hub_descriptor(instance, &hub_descriptor,
    334                 &hub_desc_size);
     215                        &hub_desc_size);
    335216
    336217        descriptor.total_length =
    337                 sizeof (usb_standard_configuration_descriptor_t) +
    338                 sizeof (usb_standard_endpoint_descriptor_t) +
    339                 sizeof (usb_standard_interface_descriptor_t) +
    340                 hub_desc_size;
    341 
     218                        sizeof(usb_standard_configuration_descriptor_t)+
     219                        sizeof(usb_standard_endpoint_descriptor_t)+
     220                        sizeof(usb_standard_interface_descriptor_t)+
     221                        hub_desc_size;
     222       
    342223        uint8_t * full_config_descriptor =
    343                 (uint8_t*) malloc(descriptor.total_length);
    344         memcpy(full_config_descriptor, &descriptor, sizeof (descriptor));
    345         memcpy(full_config_descriptor + sizeof (descriptor),
    346                 &ohci_rh_iface_descriptor, sizeof (ohci_rh_iface_descriptor));
    347         memcpy(full_config_descriptor + sizeof (descriptor) +
    348                 sizeof (ohci_rh_iface_descriptor),
    349                 &ohci_rh_ep_descriptor, sizeof (ohci_rh_ep_descriptor));
    350         memcpy(full_config_descriptor + sizeof (descriptor) +
    351                 sizeof (ohci_rh_iface_descriptor) +
    352                 sizeof (ohci_rh_ep_descriptor),
    353                 hub_descriptor, hub_desc_size);
    354 
     224                        (uint8_t*) malloc(descriptor.total_length);
     225        memcpy(full_config_descriptor, &descriptor, sizeof(descriptor));
     226        memcpy(full_config_descriptor + sizeof(descriptor),
     227                        &ohci_rh_iface_descriptor, sizeof(ohci_rh_iface_descriptor));
     228        memcpy(full_config_descriptor + sizeof(descriptor) +
     229                                sizeof(ohci_rh_iface_descriptor),
     230                        &ohci_rh_ep_descriptor, sizeof(ohci_rh_ep_descriptor));
     231        memcpy(full_config_descriptor + sizeof(descriptor) +
     232                                sizeof(ohci_rh_iface_descriptor) +
     233                                sizeof(ohci_rh_ep_descriptor),
     234                        hub_descriptor, hub_desc_size);
     235       
    355236        instance->descriptors.configuration = full_config_descriptor;
    356237        instance->descriptors.configuration_size = descriptor.total_length;
    357238}
     239
     240/** Root hub initialization
     241 * @return Error code.
     242 */
     243int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs)
     244{
     245        assert(instance);
     246        instance->address = -1;
     247        instance->registers = regs;
     248        instance->device = dev;
     249        instance->port_count = instance->registers->rh_desc_a & 0xff;
     250        rh_init_descriptors(instance);
     251        /// \TODO set port power mode
     252
     253
     254        usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
     255
     256        //start generic usb hub driver
     257       
     258        /* TODO: implement */
     259        return EOK;
     260}
    358261/*----------------------------------------------------------------------------*/
    359262
     
    369272 */
    370273static int process_get_port_status_request(rh_t *instance, uint16_t port,
    371         usb_transfer_batch_t * request) {
    372         if (port < 1 || port > instance->port_count)
    373                 return EINVAL;
    374         uint32_t * uint32_buffer = (uint32_t*) request->transport_buffer;
     274                usb_transfer_batch_t * request){
     275        if(port<1 || port>instance->port_count)
     276                return EINVAL;
     277        uint32_t * uint32_buffer = (uint32_t*)request->transport_buffer;
    375278        request->transfered_size = 4;
    376         uint32_buffer[0] = instance->registers->rh_port_status[port - 1];
    377 #if 0
    378         int i;
    379         for (i = 0; i < instance->port_count; ++i) {
    380                 usb_log_debug("port status %d,x%x\n",
    381                         instance->registers->rh_port_status[i],
    382                         instance->registers->rh_port_status[i]);
    383         }
    384 #endif
    385         return EOK;
    386 }
    387 /*----------------------------------------------------------------------------*/
     279        uint32_buffer[0] = instance->registers->rh_port_status[port -1];
     280        return EOK;
     281}
    388282
    389283/**
     
    397291 */
    398292static int process_get_hub_status_request(rh_t *instance,
    399         usb_transfer_batch_t * request) {
    400         uint32_t * uint32_buffer = (uint32_t*) request->transport_buffer;
     293                usb_transfer_batch_t * request){
     294        uint32_t * uint32_buffer = (uint32_t*)request->transport_buffer;
     295        //bits, 0,1,16,17
    401296        request->transfered_size = 4;
    402         //bits, 0,1,16,17
    403         uint32_t mask = 1 | (1 << 1) | (1 << 16) | (1 << 17);
     297        uint32_t mask = 1 & (1<<1) & (1<<16) & (1<<17);
    404298        uint32_buffer[0] = mask & instance->registers->rh_status;
    405299        return EOK;
    406 }
    407 /*----------------------------------------------------------------------------*/
     300
     301}
     302
     303
    408304
    409305/**
     
    417313 */
    418314static int process_get_status_request(rh_t *instance,
    419         usb_transfer_batch_t * request) {
     315                usb_transfer_batch_t * request)
     316{
    420317        size_t buffer_size = request->buffer_size;
    421318        usb_device_request_setup_packet_t * request_packet =
    422                 (usb_device_request_setup_packet_t*)
    423                 request->setup_buffer;
     319                        (usb_device_request_setup_packet_t*)
     320                        request->setup_buffer;
    424321
    425322        usb_hub_bm_request_type_t request_type = request_packet->request_type;
    426         if (buffer_size < 4/*request_packet->length*/) {///\TODO
     323        if(buffer_size<4/*request_packet->length*/){///\TODO
    427324                usb_log_warning("requested more data than buffer size\n");
    428325                return EINVAL;
    429326        }
    430327
    431         if (request_type == USB_HUB_REQ_TYPE_GET_HUB_STATUS)
     328        if(request_type == USB_HUB_REQ_TYPE_GET_HUB_STATUS)
    432329                return process_get_hub_status_request(instance, request);
    433         if (request_type == USB_HUB_REQ_TYPE_GET_PORT_STATUS)
    434                 return process_get_port_status_request(instance,
    435                 request_packet->index,
    436                 request);
     330        if(request_type == USB_HUB_REQ_TYPE_GET_PORT_STATUS)
     331                return process_get_port_status_request(instance, request_packet->index,
     332                                request);
    437333        return ENOTSUP;
    438334}
    439 /*----------------------------------------------------------------------------*/
    440335
    441336/**
     
    444339 * Result contains bitmap where bit 0 indicates change on hub and
    445340 * bit i indicates change on i`th port (i>0). For more info see
    446  * Hub and Port status bitmap specification in USB specification
    447  * (chapter 11.13.4)
     341 * Hub and Port status bitmap specification in USB specification.
    448342 * @param instance root hub instance
    449343 * @param@out buffer pointer to created interrupt mas
     
    451345 */
    452346static void create_interrupt_mask(rh_t *instance, void ** buffer,
    453         size_t * buffer_size) {
     347                size_t * buffer_size){
    454348        int bit_count = instance->port_count + 1;
    455         (*buffer_size) = (bit_count / 8) + ((bit_count % 8 == 0) ? 0 : 1);
    456 
     349        (*buffer_size) = (bit_count / 8) + (bit_count%8==0)?0:1;
    457350        (*buffer) = malloc(*buffer_size);
    458         uint8_t * bitmap = (uint8_t*) (*buffer);
    459         uint32_t mask = (1 << (USB_HUB_FEATURE_C_HUB_LOCAL_POWER + 16))
    460                 | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16));
    461         bzero(bitmap, (*buffer_size));
    462         if (instance->registers->rh_status & mask) {
     351        uint8_t * bitmap = (uint8_t*)(*buffer);
     352        uint32_t mask = (1<<16) + (1<<17);
     353        bzero(bitmap,(*buffer_size));
     354        if(instance->registers->rh_status & mask){
    463355                bitmap[0] = 1;
    464356        }
    465357        int port;
    466         mask = port_status_change_mask;
    467         for (port = 1; port <= instance->port_count; ++port) {
    468                 if (mask & instance->registers->rh_port_status[port - 1]) {
    469                         bitmap[(port) / 8] += 1 << (port % 8);
    470                 }
    471         }
    472 }
    473 /*----------------------------------------------------------------------------*/
    474 
     358        mask = 0;
     359        int i;
     360        for(i=16;i<=20;++i)
     361                mask += 1<<i;
     362        for(port = 1; port<=instance->port_count;++port){
     363                if(mask & instance->registers->rh_port_status[port-1]){
     364                        bitmap[(port+1)/8] += 1<<(port%8);
     365                }
     366        }
     367}
     368 
    475369/**
    476370 * create answer to a descriptor request
     
    483377 */
    484378static int process_get_descriptor_request(rh_t *instance,
    485         usb_transfer_batch_t *request) {
     379                usb_transfer_batch_t *request){
    486380        usb_device_request_setup_packet_t * setup_request =
    487                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     381                        (usb_device_request_setup_packet_t*)request->setup_buffer;
    488382        size_t size;
    489383        const void * result_descriptor = NULL;
    490384        const uint16_t setup_request_value = setup_request->value_high;
    491         //(setup_request->value_low << 8);
     385                        //(setup_request->value_low << 8);
    492386        bool del = false;
    493         switch (setup_request_value) {
    494                 case USB_DESCTYPE_HUB:
    495                 {
     387        switch (setup_request_value)
     388        {
     389                case USB_DESCTYPE_HUB: {
    496390                        uint8_t * descriptor;
    497391                        usb_create_serialized_hub_descriptor(
    498392                                instance, &descriptor, &size);
    499393                        result_descriptor = descriptor;
    500                         if (result_descriptor) del = true;
     394                        if(result_descriptor) del = true;
    501395                        break;
    502396                }
    503                 case USB_DESCTYPE_DEVICE:
    504                 {
     397                case USB_DESCTYPE_DEVICE: {
    505398                        usb_log_debug("USB_DESCTYPE_DEVICE\n");
    506399                        result_descriptor = &ohci_rh_device_descriptor;
    507                         size = sizeof (ohci_rh_device_descriptor);
     400                        size = sizeof(ohci_rh_device_descriptor);
    508401                        break;
    509402                }
    510                 case USB_DESCTYPE_CONFIGURATION:
    511                 {
     403                case USB_DESCTYPE_CONFIGURATION: {
    512404                        usb_log_debug("USB_DESCTYPE_CONFIGURATION\n");
    513405                        result_descriptor = instance->descriptors.configuration;
     
    515407                        break;
    516408                }
    517                 case USB_DESCTYPE_INTERFACE:
    518                 {
     409                case USB_DESCTYPE_INTERFACE: {
    519410                        usb_log_debug("USB_DESCTYPE_INTERFACE\n");
    520411                        result_descriptor = &ohci_rh_iface_descriptor;
    521                         size = sizeof (ohci_rh_iface_descriptor);
     412                        size = sizeof(ohci_rh_iface_descriptor);
    522413                        break;
    523414                }
    524                 case USB_DESCTYPE_ENDPOINT:
    525                 {
     415                case USB_DESCTYPE_ENDPOINT: {
    526416                        usb_log_debug("USB_DESCTYPE_ENDPOINT\n");
    527417                        result_descriptor = &ohci_rh_ep_descriptor;
    528                         size = sizeof (ohci_rh_ep_descriptor);
     418                        size = sizeof(ohci_rh_ep_descriptor);
    529419                        break;
    530420                }
    531                 default:
    532                 {
    533                         usb_log_debug("USB_DESCTYPE_EINVAL %d \n",
    534                                 setup_request->value);
    535                         usb_log_debug("\ttype %d\n\trequest %d\n\tvalue "
    536                                 "%d\n\tindex %d\n\tlen %d\n ",
    537                                 setup_request->request_type,
    538                                 setup_request->request,
    539                                 setup_request_value,
    540                                 setup_request->index,
    541                                 setup_request->length
    542                                 );
     421                default: {
     422                        usb_log_debug("USB_DESCTYPE_EINVAL %d \n",setup_request->value);
     423                        usb_log_debug("\ttype %d\n\trequest %d\n\tvalue %d\n\tindex %d\n\tlen %d\n ",
     424                                        setup_request->request_type,
     425                                        setup_request->request,
     426                                        setup_request_value,
     427                                        setup_request->index,
     428                                        setup_request->length
     429                                        );
    543430                        return EINVAL;
    544431                }
    545432        }
    546         if (request->buffer_size < size) {
     433        if(request->buffer_size < size){
    547434                size = request->buffer_size;
    548435        }
    549436        request->transfered_size = size;
    550         memcpy(request->transport_buffer, result_descriptor, size);
     437        memcpy(request->transport_buffer,result_descriptor,size);
     438        usb_log_debug("sent desctiptor: %s\n",
     439                        usb_debug_str_buffer((uint8_t*)request->transport_buffer,size,size));
    551440        if (del)
    552441                free(result_descriptor);
    553442        return EOK;
    554443}
    555 /*----------------------------------------------------------------------------*/
    556444
    557445/**
     
    563451 * @return error code
    564452 */
    565 static int process_get_configuration_request(rh_t *instance,
    566         usb_transfer_batch_t *request) {
     453static int process_get_configuration_request(rh_t *instance, 
     454                usb_transfer_batch_t *request){
    567455        //set and get configuration requests do not have any meaning, only dummy
    568456        //values are returned
    569         if (request->buffer_size != 1)
     457        if(request->buffer_size != 1)
    570458                return EINVAL;
    571459        request->transport_buffer[0] = 1;
     
    573461        return EOK;
    574462}
    575 /*----------------------------------------------------------------------------*/
    576463
    577464/**
    578465 * process feature-enabling request on hub
    579  *
     466 * 
    580467 * @param instance root hub instance
    581468 * @param feature feature selector
     
    583470 */
    584471static int process_hub_feature_set_request(rh_t *instance,
    585         uint16_t feature) {
    586         if (!((1 << feature) & hub_set_feature_valid_mask))
     472                uint16_t feature){
     473        if(! ((1<<feature) & hub_set_feature_valid_mask))
    587474                return EINVAL;
    588475        instance->registers->rh_status =
    589                 (instance->registers->rh_status | (1 << feature))
    590                 & (~hub_clear_feature_by_writing_one_mask);
    591         return EOK;
    592 }
    593 /*----------------------------------------------------------------------------*/
     476                        (instance->registers->rh_status | (1<<feature))
     477                        & (~ hub_clear_feature_by_writing_one_mask);
     478        return EOK;
     479}
    594480
    595481/**
     
    601487 */
    602488static int process_hub_feature_clear_request(rh_t *instance,
    603         uint16_t feature) {
    604         if (!((1 << feature) & hub_clear_feature_valid_mask))
     489                uint16_t feature){
     490        if(! ((1<<feature) & hub_clear_feature_valid_mask))
    605491                return EINVAL;
    606492        //is the feature cleared directly?
    607         if ((1 << feature) & hub_set_feature_direct_mask) {
     493        if ((1<<feature) & hub_set_feature_direct_mask){
    608494                instance->registers->rh_status =
    609                         (instance->registers->rh_status & (~(1 << feature)))
    610                         & (~hub_clear_feature_by_writing_one_mask);
    611         } else {//the feature is cleared by writing '1'
     495                        (instance->registers->rh_status & (~(1<<feature)))
     496                        & (~ hub_clear_feature_by_writing_one_mask);
     497        }else{//the feature is cleared by writing '1'
    612498                instance->registers->rh_status =
    613                         (instance->registers->rh_status
    614                         & (~hub_clear_feature_by_writing_one_mask))
    615                         | (1 << feature);
    616         }
    617         return EOK;
    618 }
    619 /*----------------------------------------------------------------------------*/
     499                                (instance->registers->rh_status
     500                                & (~ hub_clear_feature_by_writing_one_mask))
     501                                | (1<<feature);
     502        }
     503        return EOK;
     504}
     505
     506
    620507
    621508/**
    622509 * process feature-enabling request on hub
    623  *
     510 * 
    624511 * @param instance root hub instance
    625512 * @param feature feature selector
     
    629516 */
    630517static int process_port_feature_set_request(rh_t *instance,
    631         uint16_t feature, uint16_t port) {
    632         if (!((1 << feature) & port_set_feature_valid_mask))
    633                 return EINVAL;
    634         if (port < 1 || port > instance->port_count)
     518                uint16_t feature, uint16_t port){
     519        if(!((1<<feature) & port_set_feature_valid_mask))
     520                return EINVAL;
     521        if(port<1 || port>instance->port_count)
    635522                return EINVAL;
    636523        instance->registers->rh_port_status[port - 1] =
    637                 (instance->registers->rh_port_status[port - 1] | (1 << feature))
    638                 & (~port_clear_feature_valid_mask);
     524                        (instance->registers->rh_port_status[port - 1] | (1<<feature))
     525                        & (~port_clear_feature_valid_mask);
    639526        /// \TODO any error?
    640527        return EOK;
    641528}
    642 /*----------------------------------------------------------------------------*/
    643529
    644530/**
     
    652538 */
    653539static int process_port_feature_clear_request(rh_t *instance,
    654         uint16_t feature, uint16_t port) {
    655         if (!((1 << feature) & port_clear_feature_valid_mask))
    656                 return EINVAL;
    657         if (port < 1 || port > instance->port_count)
    658                 return EINVAL;
    659         if (feature == USB_HUB_FEATURE_PORT_POWER)
     540                uint16_t feature, uint16_t port){
     541        if(!((1<<feature) & port_clear_feature_valid_mask))
     542                return EINVAL;
     543        if(port<1 || port>instance->port_count)
     544                return EINVAL;
     545        if(feature == USB_HUB_FEATURE_PORT_POWER)
    660546                feature = USB_HUB_FEATURE_PORT_LOW_SPEED;
    661         if (feature == USB_HUB_FEATURE_PORT_SUSPEND)
     547        if(feature == USB_HUB_FEATURE_PORT_SUSPEND)
    662548                feature = USB_HUB_FEATURE_PORT_OVER_CURRENT;
    663549        instance->registers->rh_port_status[port - 1] =
    664                 (instance->registers->rh_port_status[port - 1]
    665                 & (~port_clear_feature_valid_mask))
    666                 | (1 << feature);
     550                        (instance->registers->rh_port_status[port - 1]
     551                        & (~port_clear_feature_valid_mask))
     552                        | (1<<feature);
    667553        /// \TODO any error?
    668554        return EOK;
    669555}
    670 /*----------------------------------------------------------------------------*/
     556
    671557
    672558/**
    673559 * register address to this device
    674  *
     560 * 
    675561 * @param instance root hub instance
    676562 * @param address new address
     
    678564 */
    679565static int process_address_set_request(rh_t *instance,
    680         uint16_t address) {
     566                uint16_t address){
    681567        instance->address = address;
    682568        return EOK;
    683569}
    684 /*----------------------------------------------------------------------------*/
    685570
    686571/**
     
    694579 */
    695580static int process_request_with_output(rh_t *instance,
    696         usb_transfer_batch_t *request) {
     581                usb_transfer_batch_t *request){
    697582        usb_device_request_setup_packet_t * setup_request =
    698                 (usb_device_request_setup_packet_t*) request->setup_buffer;
    699         if (setup_request->request == USB_DEVREQ_GET_STATUS) {
     583                        (usb_device_request_setup_packet_t*)request->setup_buffer;
     584        if(setup_request->request == USB_DEVREQ_GET_STATUS){
    700585                usb_log_debug("USB_DEVREQ_GET_STATUS\n");
    701586                return process_get_status_request(instance, request);
    702587        }
    703         if (setup_request->request == USB_DEVREQ_GET_DESCRIPTOR) {
     588        if(setup_request->request == USB_DEVREQ_GET_DESCRIPTOR){
    704589                usb_log_debug("USB_DEVREQ_GET_DESCRIPTOR\n");
    705590                return process_get_descriptor_request(instance, request);
    706591        }
    707         if (setup_request->request == USB_DEVREQ_GET_CONFIGURATION) {
     592        if(setup_request->request == USB_DEVREQ_GET_CONFIGURATION){
    708593                usb_log_debug("USB_DEVREQ_GET_CONFIGURATION\n");
    709594                return process_get_configuration_request(instance, request);
     
    711596        return ENOTSUP;
    712597}
    713 /*----------------------------------------------------------------------------*/
    714598
    715599/**
     
    723607 */
    724608static int process_request_with_input(rh_t *instance,
    725         usb_transfer_batch_t *request) {
     609                usb_transfer_batch_t *request){
    726610        usb_device_request_setup_packet_t * setup_request =
    727                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     611                        (usb_device_request_setup_packet_t*)request->setup_buffer;
    728612        request->transfered_size = 0;
    729         if (setup_request->request == USB_DEVREQ_SET_DESCRIPTOR) {
     613        if(setup_request->request == USB_DEVREQ_SET_DESCRIPTOR){
    730614                return ENOTSUP;
    731615        }
    732         if (setup_request->request == USB_DEVREQ_SET_CONFIGURATION) {
     616        if(setup_request->request == USB_DEVREQ_SET_CONFIGURATION){
    733617                //set and get configuration requests do not have any meaning,
    734618                //only dummy values are returned
     
    737621        return ENOTSUP;
    738622}
    739 /*----------------------------------------------------------------------------*/
    740623
    741624/**
     
    749632 */
    750633static int process_request_without_data(rh_t *instance,
    751         usb_transfer_batch_t *request) {
     634                usb_transfer_batch_t *request){
    752635        usb_device_request_setup_packet_t * setup_request =
    753                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     636                        (usb_device_request_setup_packet_t*)request->setup_buffer;
    754637        request->transfered_size = 0;
    755         if (setup_request->request == USB_DEVREQ_CLEAR_FEATURE) {
    756                 if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE) {
     638        if(setup_request->request == USB_DEVREQ_CLEAR_FEATURE){
     639                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){
    757640                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    758641                        return process_hub_feature_clear_request(instance,
    759                                 setup_request->value);
    760                 }
    761                 if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
     642                                        setup_request->value);
     643                }
     644                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){
    762645                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    763646                        return process_port_feature_clear_request(instance,
    764                                 setup_request->value,
    765                                 setup_request->index);
     647                                        setup_request->value,
     648                                        setup_request->index);
    766649                }
    767650                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
    768                         setup_request->request_type);
    769                 return EINVAL;
    770         }
    771         if (setup_request->request == USB_DEVREQ_SET_FEATURE) {
    772                 if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE) {
     651                                setup_request->request_type);
     652                return EINVAL;
     653        }
     654        if(setup_request->request == USB_DEVREQ_SET_FEATURE){
     655                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_HUB_FEATURE){
    773656                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    774657                        return process_hub_feature_set_request(instance,
    775                                 setup_request->value);
    776                 }
    777                 if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
     658                                        setup_request->value);
     659                }
     660                if(setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE){
    778661                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    779662                        return process_port_feature_set_request(instance,
    780                                 setup_request->value,
    781                                 setup_request->index);
    782                 }
    783                 usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
    784                         setup_request->request_type);
    785                 return EINVAL;
    786         }
    787         if (setup_request->request == USB_DEVREQ_SET_ADDRESS) {
     663                                        setup_request->value,
     664                                        setup_request->index);
     665                }
     666                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",setup_request->request_type);
     667                return EINVAL;
     668        }
     669        if(setup_request->request == USB_DEVREQ_SET_ADDRESS){
    788670                usb_log_debug("USB_DEVREQ_SET_ADDRESS\n");
    789                 return process_address_set_request(instance,
    790                         setup_request->value);
    791         }
    792         usb_log_debug("USB_DEVREQ_SET_ENOTSUP %d\n",
    793                 setup_request->request_type);
     671                return process_address_set_request(instance, setup_request->value);
     672        }
     673        usb_log_debug("USB_DEVREQ_SET_ENOTSUP %d\n",setup_request->request_type);
    794674        return ENOTSUP;
    795675}
    796 /*----------------------------------------------------------------------------*/
    797676
    798677/**
     
    814693 * @return error code
    815694 */
    816 static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request) {
    817         if (!request->setup_buffer) {
     695static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request){
     696        int opResult;
     697        if (request->setup_buffer) {
     698                if(sizeof(usb_device_request_setup_packet_t)>request->setup_size){
     699                        usb_log_error("setup packet too small\n");
     700                        return EINVAL;
     701                }
     702                usb_log_info("CTRL packet: %s.\n",
     703                        usb_debug_str_buffer((const uint8_t *)request->setup_buffer, 8, 8));
     704                usb_device_request_setup_packet_t * setup_request =
     705                                (usb_device_request_setup_packet_t*)request->setup_buffer;
     706                if(
     707                        setup_request->request == USB_DEVREQ_GET_STATUS
     708                        || setup_request->request == USB_DEVREQ_GET_DESCRIPTOR
     709                        || setup_request->request == USB_DEVREQ_GET_CONFIGURATION
     710                ){
     711                        usb_log_debug("processing request with output\n");
     712                        opResult = process_request_with_output(instance,request);
     713                }else if(
     714                        setup_request->request == USB_DEVREQ_CLEAR_FEATURE
     715                        || setup_request->request == USB_DEVREQ_SET_FEATURE
     716                        || setup_request->request == USB_DEVREQ_SET_ADDRESS
     717                ){
     718                        usb_log_debug("processing request without additional data\n");
     719                        opResult = process_request_without_data(instance,request);
     720                }else if(setup_request->request == USB_DEVREQ_SET_DESCRIPTOR
     721                                || setup_request->request == USB_DEVREQ_SET_CONFIGURATION
     722                ){
     723                        usb_log_debug("processing request with input\n");
     724                        opResult = process_request_with_input(instance,request);
     725                }else{
     726                        usb_log_warning("received unsuported request: %d\n",
     727                                        setup_request->request
     728                                        );
     729                        opResult = ENOTSUP;
     730                }
     731        }else{
    818732                usb_log_error("root hub received empty transaction?");
    819                 return EINVAL;
    820         }
     733                opResult = EINVAL;
     734        }
     735        return opResult;
     736}
     737
     738/**
     739 * process root hub request
     740 *
     741 * @param instance root hub instance
     742 * @param request structure containing both request and response information
     743 * @return error code
     744 */
     745int rh_request(rh_t *instance, usb_transfer_batch_t *request)
     746{
     747        assert(instance);
     748        assert(request);
    821749        int opResult;
    822         if (sizeof (usb_device_request_setup_packet_t) > request->setup_size) {
    823                 usb_log_error("setup packet too small\n");
    824                 return EINVAL;
    825         }
    826         usb_log_info("CTRL packet: %s.\n",
    827                 usb_debug_str_buffer(
    828                 (const uint8_t *) request->setup_buffer, 8, 8));
    829         usb_device_request_setup_packet_t * setup_request =
    830                 (usb_device_request_setup_packet_t*)
    831                 request->setup_buffer;
    832         switch (setup_request->request) {
    833                 case USB_DEVREQ_GET_STATUS:
    834                 case USB_DEVREQ_GET_DESCRIPTOR:
    835                 case USB_DEVREQ_GET_CONFIGURATION:
    836                         usb_log_debug("processing request with output\n");
    837                         opResult = process_request_with_output(
    838                                 instance, request);
    839                         break;
    840                 case USB_DEVREQ_CLEAR_FEATURE:
    841                 case USB_DEVREQ_SET_FEATURE:
    842                 case USB_DEVREQ_SET_ADDRESS:
    843                         usb_log_debug("processing request without "
    844                                 "additional data\n");
    845                         opResult = process_request_without_data(
    846                                 instance, request);
    847                         break;
    848                 case USB_DEVREQ_SET_DESCRIPTOR:
    849                 case USB_DEVREQ_SET_CONFIGURATION:
    850                         usb_log_debug("processing request with "
    851                                 "input\n");
    852                         opResult = process_request_with_input(
    853                                 instance, request);
    854                         break;
    855                 default:
    856                         usb_log_warning("received unsuported request: "
    857                                 "%d\n",
    858                                 setup_request->request
    859                                 );
    860                         opResult = ENOTSUP;
    861         }
    862         return opResult;
    863 }
    864 
     750        if(request->transfer_type == USB_TRANSFER_CONTROL){
     751                usb_log_info("Root hub got CONTROL packet\n");
     752                opResult = process_ctrl_request(instance,request);
     753        }else if(request->transfer_type == USB_TRANSFER_INTERRUPT){
     754                usb_log_info("Root hub got INTERRUPT packet\n");
     755                void * buffer;
     756                create_interrupt_mask(instance, &buffer,
     757                        &(request->transfered_size));
     758                memcpy(request->transport_buffer,buffer, request->transfered_size);
     759                opResult = EOK;
     760        }else{
     761                opResult = EINVAL;
     762        }
     763        usb_transfer_batch_finish(request, opResult);
     764        return EOK;
     765}
     766/*----------------------------------------------------------------------------*/
     767
     768
     769void rh_interrupt(rh_t *instance)
     770{
     771        usb_log_info("Whoa whoa wait, I`m not supposed to receive any interrupts, am I?\n");
     772        /* TODO: implement? */
     773}
    865774/**
    866775 * @}
  • uspace/drv/uhci-hcd/batch.c

    rc6cb76d r7dfc06fa  
    8080 * transaction and callback.
    8181 */
    82 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,
    83     char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size,
     82usb_transfer_batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
     83    usb_transfer_type_t transfer_type, size_t max_packet_size,
     84    usb_speed_t speed, char *buffer, size_t buffer_size,
     85    char* setup_buffer, size_t setup_size,
    8486    usbhc_iface_transfer_in_callback_t func_in,
    85     usbhc_iface_transfer_out_callback_t func_out, void *arg)
    86 {
    87         assert(ep);
     87    usbhc_iface_transfer_out_callback_t func_out, void *arg, endpoint_t *ep
     88    )
     89{
    8890        assert(func_in == NULL || func_out == NULL);
    8991        assert(func_in != NULL || func_out != NULL);
     
    101103        CHECK_NULL_DISPOSE_RETURN(instance,
    102104            "Failed to allocate batch instance.\n");
    103         usb_target_t target =
    104             { .address = ep->address, .endpoint = ep->endpoint };
    105105        usb_transfer_batch_init(instance, target,
    106             ep->transfer_type, ep->speed, ep->max_packet_size,
     106            transfer_type, speed, max_packet_size,
    107107            buffer, NULL, buffer_size, NULL, setup_size, func_in,
    108108            func_out, arg, fun, ep, NULL);
     
    115115        instance->private_data = data;
    116116
    117         data->transfers =
    118             (buffer_size + ep->max_packet_size - 1) / ep->max_packet_size;
    119         if (ep->transfer_type == USB_TRANSFER_CONTROL) {
     117        data->transfers = (buffer_size + max_packet_size - 1) / max_packet_size;
     118        if (transfer_type == USB_TRANSFER_CONTROL) {
    120119                data->transfers += 2;
    121120        }
     
    179178                            instance, i, data->tds[i].status);
    180179                        td_print_status(&data->tds[i]);
    181                         assert(instance->ep != NULL);
    182 
    183                         endpoint_toggle_set(instance->ep,
    184                             td_toggle(&data->tds[i]));
     180                        if (instance->ep != NULL)
     181                                endpoint_toggle_set(instance->ep,
     182                                    td_toggle(&data->tds[i]));
    185183                        if (i > 0)
    186184                                goto substract_ret;
  • uspace/drv/uhci-hcd/batch.h

    rc6cb76d r7dfc06fa  
    4444
    4545usb_transfer_batch_t * batch_get(
    46     ddf_fun_t *fun, endpoint_t *ep, char *buffer, size_t size,
    47     char *setup_buffer, size_t setup_size,
     46    ddf_fun_t *fun,
     47                usb_target_t target,
     48    usb_transfer_type_t transfer_type,
     49                size_t max_packet_size,
     50    usb_speed_t speed,
     51                char *buffer,
     52                size_t size,
     53                char *setup_buffer,
     54                size_t setup_size,
    4855    usbhc_iface_transfer_in_callback_t func_in,
    4956    usbhc_iface_transfer_out_callback_t func_out,
    50     void *arg);
     57                void *arg,
     58                endpoint_t *ep
     59                );
    5160
    5261void batch_dispose(usb_transfer_batch_t *instance);
  • uspace/drv/uhci-hcd/hc.c

    rc6cb76d r7dfc06fa  
    332332            instance->transfers[batch->speed][batch->transfer_type];
    333333        assert(list);
     334        if (batch->transfer_type == USB_TRANSFER_CONTROL) {
     335                usb_device_keeper_use_control(
     336                    &instance->manager, batch->target);
     337        }
    334338        transfer_list_add_batch(list, batch);
    335339
     
    369373                        usb_transfer_batch_t *batch =
    370374                            list_get_instance(item, usb_transfer_batch_t, link);
    371                         usb_transfer_batch_finish(batch);
     375                        switch (batch->transfer_type)
     376                        {
     377                        case USB_TRANSFER_CONTROL:
     378                                usb_device_keeper_release_control(
     379                                    &instance->manager, batch->target);
     380                                break;
     381                        case USB_TRANSFER_INTERRUPT:
     382                        case USB_TRANSFER_ISOCHRONOUS: {
     383/*
     384                                int ret = bandwidth_free(&instance->bandwidth,
     385                                    batch->target.address,
     386                                    batch->target.endpoint,
     387                                    batch->direction);
     388                                if (ret != EOK)
     389                                        usb_log_warning("Failed(%d) to free "
     390                                            "reserved bw: %s.\n", ret,
     391                                            str_error(ret));
     392*/
     393                                }
     394                        default:
     395                                break;
     396                        }
     397                        batch->next_step(batch);
    372398                }
    373399        }
  • uspace/drv/uhci-hcd/iface.c

    rc6cb76d r7dfc06fa  
    4141#include "hc.h"
    4242
    43 static inline int setup_batch(
    44     ddf_fun_t *fun, usb_target_t target, usb_direction_t direction,
    45     void *data, size_t size, void * setup_data, size_t setup_size,
    46     usbhc_iface_transfer_in_callback_t in,
    47     usbhc_iface_transfer_out_callback_t out, void *arg, const char* name,
    48     hc_t **hc, usb_transfer_batch_t **batch)
    49 {
    50         assert(hc);
    51         assert(batch);
    52         assert(fun);
    53         *hc = fun_to_hc(fun);
    54         assert(*hc);
    55 
    56         size_t res_bw;
    57         endpoint_t *ep = usb_endpoint_manager_get_ep(&(*hc)->ep_manager,
    58             target.address, target.endpoint, direction, &res_bw);
    59         if (ep == NULL) {
    60                 usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
    61                     target.address, target.endpoint, name);
    62                 return ENOENT;
    63         }
    64 
    65         const size_t bw = bandwidth_count_usb11(
    66             ep->speed, ep->transfer_type, size, ep->max_packet_size);
    67         if (res_bw < bw) {
    68                 usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
    69                     "but only %zu is reserved.\n",
    70                     name, target.address, target.endpoint, bw, res_bw);
    71                 return ENOSPC;
    72         }
    73         usb_log_debug("%s %d:%d %zu(%zu).\n",
    74             name, target.address, target.endpoint, size, ep->max_packet_size);
    75 
    76         assert(ep->speed ==
    77             usb_device_keeper_get_speed(&(*hc)->manager, target.address));
    78 //      assert(ep->max_packet_size == max_packet_size);
    79 //      assert(ep->transfer_type == USB_TRANSFER_CONTROL);
    80 
    81         *batch =
    82             batch_get(fun, ep, data, size, setup_data, setup_size,
    83                 in, out, arg);
    84         if (!batch)
    85                 return ENOMEM;
    86         return EOK;
    87 }
    88 
    89 
    9043/** Reserve default address interface function
    9144 *
     
    261214    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
    262215{
    263         usb_transfer_batch_t *batch = NULL;
    264         hc_t *hc = NULL;
    265         int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
    266             NULL, 0, NULL, callback, arg, "Interrupt OUT", &hc, &batch);
    267         if (ret != EOK)
    268                 return ret;
     216        assert(fun);
     217        hc_t *hc = fun_to_hc(fun);
     218        assert(hc);
     219
     220        usb_log_debug("Interrupt OUT %d:%d %zu.\n",
     221            target.address, target.endpoint, size);
     222
     223        size_t res_bw;
     224        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     225            target.address, target.endpoint, USB_DIRECTION_OUT, &res_bw);
     226        if (ep == NULL) {
     227                usb_log_error("Endpoint(%d:%d) not registered for INT OUT.\n",
     228                        target.address, target.endpoint);
     229                return ENOENT;
     230        }
     231        const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
     232            size, ep->max_packet_size);
     233        if (res_bw < bw)
     234        {
     235                usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw "
     236                    "but only %zu is reserved.\n",
     237                    target.address, target.endpoint, bw, res_bw);
     238                return ENOENT;
     239        }
     240        assert(ep->speed ==
     241            usb_device_keeper_get_speed(&hc->manager, target.address));
     242        assert(ep->transfer_type == USB_TRANSFER_INTERRUPT);
     243
     244        usb_transfer_batch_t *batch =
     245            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     246                ep->speed, data, size, NULL, 0, NULL, callback, arg, ep);
     247        if (!batch)
     248                return ENOMEM;
    269249        batch_interrupt_out(batch);
    270         ret = hc_schedule(hc, batch);
     250        const int ret = hc_schedule(hc, batch);
    271251        if (ret != EOK) {
    272252                batch_dispose(batch);
     
    289269    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
    290270{
    291         usb_transfer_batch_t *batch = NULL;
    292         hc_t *hc = NULL;
    293         int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
    294             NULL, 0, callback, NULL, arg, "Interrupt IN", &hc, &batch);
    295         if (ret != EOK)
    296                 return ret;
     271        assert(fun);
     272        hc_t *hc = fun_to_hc(fun);
     273        assert(hc);
     274
     275        usb_log_debug("Interrupt IN %d:%d %zu.\n",
     276            target.address, target.endpoint, size);
     277
     278        size_t res_bw;
     279        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     280            target.address, target.endpoint, USB_DIRECTION_IN, &res_bw);
     281        if (ep == NULL) {
     282                usb_log_error("Endpoint(%d:%d) not registered for INT IN.\n",
     283                    target.address, target.endpoint);
     284                return ENOENT;
     285        }
     286        const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
     287            size, ep->max_packet_size);
     288        if (res_bw < bw)
     289        {
     290                usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw "
     291                    "but only %zu bw is reserved.\n",
     292                    target.address, target.endpoint, bw, res_bw);
     293                return ENOENT;
     294        }
     295
     296        assert(ep->speed ==
     297            usb_device_keeper_get_speed(&hc->manager, target.address));
     298        assert(ep->transfer_type == USB_TRANSFER_INTERRUPT);
     299
     300        usb_transfer_batch_t *batch =
     301            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     302                ep->speed, data, size, NULL, 0, callback, NULL, arg, ep);
     303        if (!batch)
     304                return ENOMEM;
    297305        batch_interrupt_in(batch);
    298         ret = hc_schedule(hc, batch);
     306        const int ret = hc_schedule(hc, batch);
    299307        if (ret != EOK) {
    300308                batch_dispose(batch);
     
    317325    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
    318326{
    319         usb_transfer_batch_t *batch = NULL;
    320         hc_t *hc = NULL;
    321         int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
    322             NULL, 0, NULL, callback, arg, "Bulk OUT", &hc, &batch);
    323         if (ret != EOK)
    324                 return ret;
     327        assert(fun);
     328        hc_t *hc = fun_to_hc(fun);
     329        assert(hc);
     330
     331        usb_log_debug("Bulk OUT %d:%d %zu.\n",
     332            target.address, target.endpoint, size);
     333
     334        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     335            target.address, target.endpoint, USB_DIRECTION_OUT, NULL);
     336        if (ep == NULL) {
     337                usb_log_error("Endpoint(%d:%d) not registered for BULK OUT.\n",
     338                        target.address, target.endpoint);
     339                return ENOENT;
     340        }
     341        assert(ep->speed ==
     342            usb_device_keeper_get_speed(&hc->manager, target.address));
     343        assert(ep->transfer_type == USB_TRANSFER_BULK);
     344
     345        usb_transfer_batch_t *batch =
     346            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     347                ep->speed, data, size, NULL, 0, NULL, callback, arg, ep);
     348        if (!batch)
     349                return ENOMEM;
    325350        batch_bulk_out(batch);
    326         ret = hc_schedule(hc, batch);
     351        const int ret = hc_schedule(hc, batch);
    327352        if (ret != EOK) {
    328353                batch_dispose(batch);
     
    345370    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
    346371{
    347         usb_transfer_batch_t *batch = NULL;
    348         hc_t *hc = NULL;
    349         int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
    350             NULL, 0, callback, NULL, arg, "Bulk IN", &hc, &batch);
    351         if (ret != EOK)
    352                 return ret;
     372        assert(fun);
     373        hc_t *hc = fun_to_hc(fun);
     374        assert(hc);
     375        usb_log_debug("Bulk IN %d:%d %zu.\n",
     376            target.address, target.endpoint, size);
     377
     378        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     379            target.address, target.endpoint, USB_DIRECTION_IN, NULL);
     380        if (ep == NULL) {
     381                usb_log_error("Endpoint(%d:%d) not registered for BULK IN.\n",
     382                        target.address, target.endpoint);
     383                return ENOENT;
     384        }
     385        assert(ep->speed ==
     386            usb_device_keeper_get_speed(&hc->manager, target.address));
     387        assert(ep->transfer_type == USB_TRANSFER_BULK);
     388
     389        usb_transfer_batch_t *batch =
     390            batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
     391                ep->speed, data, size, NULL, 0, callback, NULL, arg, ep);
     392        if (!batch)
     393                return ENOMEM;
    353394        batch_bulk_in(batch);
    354         ret = hc_schedule(hc, batch);
     395        const int ret = hc_schedule(hc, batch);
    355396        if (ret != EOK) {
    356397                batch_dispose(batch);
     
    376417    usbhc_iface_transfer_out_callback_t callback, void *arg)
    377418{
    378         usb_transfer_batch_t *batch = NULL;
    379         hc_t *hc = NULL;
    380         int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
    381             setup_data, setup_size, NULL, callback, arg, "Control WRITE",
    382             &hc, &batch);
    383         if (ret != EOK)
    384                 return ret;
     419        assert(fun);
     420        hc_t *hc = fun_to_hc(fun);
     421        assert(hc);
     422        usb_speed_t speed =
     423            usb_device_keeper_get_speed(&hc->manager, target.address);
     424        usb_log_debug("Control WRITE (%d) %d:%d %zu.\n",
     425            speed, target.address, target.endpoint, size);
     426        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     427            target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
     428        if (ep == NULL) {
     429                usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n",
     430                        target.address, target.endpoint);
     431        }
     432
     433        if (setup_size != 8)
     434                return EINVAL;
     435
     436        usb_transfer_batch_t *batch =
     437            batch_get(fun, target, USB_TRANSFER_CONTROL, ep->max_packet_size, speed,
     438                data, size, setup_data, setup_size, NULL, callback, arg, ep);
     439        if (!batch)
     440                return ENOMEM;
    385441        usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
    386442        batch_control_write(batch);
    387         ret = hc_schedule(hc, batch);
     443        const int ret = hc_schedule(hc, batch);
    388444        if (ret != EOK) {
    389445                batch_dispose(batch);
     
    409465    usbhc_iface_transfer_in_callback_t callback, void *arg)
    410466{
    411         usb_transfer_batch_t *batch = NULL;
    412         hc_t *hc = NULL;
    413         int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
    414             setup_data, setup_size, callback, NULL, arg, "Control READ",
    415             &hc, &batch);
    416         if (ret != EOK)
    417                 return ret;
     467        assert(fun);
     468        hc_t *hc = fun_to_hc(fun);
     469        assert(hc);
     470        usb_speed_t speed =
     471            usb_device_keeper_get_speed(&hc->manager, target.address);
     472
     473        usb_log_debug("Control READ(%d) %d:%d %zu.\n",
     474            speed, target.address, target.endpoint, size);
     475        endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
     476            target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
     477        if (ep == NULL) {
     478                usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n",
     479                        target.address, target.endpoint);
     480        }
     481        usb_transfer_batch_t *batch =
     482            batch_get(fun, target, USB_TRANSFER_CONTROL, ep->max_packet_size, speed,
     483                data, size, setup_data, setup_size, callback, NULL, arg, ep);
     484        if (!batch)
     485                return ENOMEM;
    418486        batch_control_read(batch);
    419         ret = hc_schedule(hc, batch);
     487        const int ret = hc_schedule(hc, batch);
    420488        if (ret != EOK) {
    421489                batch_dispose(batch);
  • uspace/drv/uhci-hcd/transfer_list.c

    rc6cb76d r7dfc06fa  
    132132}
    133133/*----------------------------------------------------------------------------*/
    134 /** Create list for finished batches.
    135  *
    136  * @param[in] instance List to use.
    137  * @param[in] done list to fill
     134/** Check list for finished batches.
     135 *
     136 * @param[in] instance List to use.
     137 * @return Error code
     138 *
     139 * Creates a local list of finished batches and calls next_step on each and
     140 * every one. This is safer because next_step may theoretically access
     141 * this transfer list leading to the deadlock if its done inline.
    138142 */
    139143void transfer_list_remove_finished(transfer_list_t *instance, link_t *done)
     
    157161        }
    158162        fibril_mutex_unlock(&instance->guard);
     163
    159164}
    160165/*----------------------------------------------------------------------------*/
     
    171176                    list_get_instance(current, usb_transfer_batch_t, link);
    172177                transfer_list_remove_batch(instance, batch);
    173                 usb_transfer_batch_finish_error(batch, EIO);
     178                usb_transfer_batch_finish(batch, EIO);
    174179        }
    175180        fibril_mutex_unlock(&instance->guard);
  • uspace/drv/uhci-rhd/root_hub.h

    rc6cb76d r7dfc06fa  
    4040
    4141#define UHCI_ROOT_HUB_PORT_COUNT 2
    42 #define ROOT_HUB_WAIT_USEC 250000 /* 250 miliseconds */
     42#define ROOT_HUB_WAIT_USEC 5000000 /* 5 seconds */
    4343
    4444typedef struct root_hub {
  • uspace/drv/usbkbd/kbddev.c

    rc6cb76d r7dfc06fa  
    265265static void usb_kbd_set_led(usb_kbd_t *kbd_dev)
    266266{
    267         if (kbd_dev->output_size == 0) {
    268                 return;
    269         }
    270        
    271267        unsigned i = 0;
    272268       
     
    292288       
    293289        int rc = usb_hid_report_output_translate(kbd_dev->parser,
    294             kbd_dev->led_path,
    295             USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    296             kbd_dev->output_buffer,
     290            kbd_dev->led_path, USB_HID_PATH_COMPARE_END, kbd_dev->output_buffer,
    297291            kbd_dev->output_size, kbd_dev->led_data, kbd_dev->led_output_size);
    298292       
     
    545539 *                  according to HID Usage Tables.
    546540 * @param count Number of key codes in report (size of the report).
    547  * @param report_id
     541 * @param modifiers Bitmap of modifiers (Ctrl, Alt, Shift, GUI).
    548542 * @param arg User-specified argument. Expects pointer to the keyboard device
    549543 *            structure representing the keyboard.
     
    552546 */
    553547static void usb_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
    554     uint8_t report_id, void *arg)
     548    uint8_t modifiers, void *arg)
    555549{
    556550        if (arg == NULL) {
     
    563557        assert(kbd_dev != NULL);
    564558
    565         usb_log_debug("Got keys from parser (report id: %u): %s\n",
    566             report_id, usb_debug_str_buffer(key_codes, count, 0));
     559        usb_log_debug("Got keys from parser: %s\n",
     560            usb_debug_str_buffer(key_codes, count, 0));
    567561       
    568562        if (count != kbd_dev->key_count) {
     
    614608        usb_hid_report_path_t *path = usb_hid_report_path();
    615609        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    616         usb_hid_report_path_set_report_id(path, 0);
    617610       
    618611        int rc = usb_hid_parse_report(kbd_dev->parser, buffer,
    619             actual_size, path,
    620             USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    621             callbacks, kbd_dev);
     612            actual_size, path, USB_HID_PATH_COMPARE_STRICT, callbacks, kbd_dev);
    622613
    623614        usb_hid_report_path_free (path);
     
    767758        usb_hid_report_path_t *path = usb_hid_report_path();
    768759        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    769        
    770         usb_hid_report_path_set_report_id(path, 0);
    771        
    772760        kbd_dev->key_count = usb_hid_report_input_length(
    773             kbd_dev->parser, path,
    774             USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
     761            kbd_dev->parser, path, USB_HID_PATH_COMPARE_STRICT);
    775762        usb_hid_report_path_free (path);
    776763       
     
    790777        kbd_dev->output_buffer = usb_hid_report_output(kbd_dev->parser,
    791778            &kbd_dev->output_size);
    792         if (kbd_dev->output_buffer == NULL && kbd_dev->output_size != 0) {
     779        if (kbd_dev->output_buffer == NULL) {
    793780                usb_log_warning("Error creating output report buffer.\n");
    794781                free(kbd_dev->keys);
     
    803790       
    804791        kbd_dev->led_output_size = usb_hid_report_output_size(kbd_dev->parser,
    805             kbd_dev->led_path,
    806             USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
     792            kbd_dev->led_path, USB_HID_PATH_COMPARE_END);
    807793       
    808794        usb_log_debug("Output report size (in items): %zu\n",
  • uspace/drv/usbkbd/main.c

    rc6cb76d r7dfc06fa  
    3333/**
    3434 * @file
    35  * Main routines of USB KBD driver.
     35 * Main routines of USB HID driver.
    3636 */
    3737
     
    7575 * @sa usb_kbd_fibril(), usb_kbd_repeat_fibril()
    7676 */
    77 static int usb_kbd_try_add_device(usb_device_t *dev)
     77static int usbhid_try_add_device(usb_device_t *dev)
    7878{
    7979        /* Create the function exposed under /dev/devices. */
     
    105105                usb_kbd_free(&kbd_dev);
    106106                return rc;
    107         }
     107        }       
    108108       
    109109        usb_log_debug("USB/HID KBD device structure initialized.\n");
     
    195195 * @retval EREFUSED if the device is not supported.
    196196 */
    197 static int usb_kbd_add_device(usb_device_t *dev)
     197static int usbhid_add_device(usb_device_t *dev)
    198198{
    199         usb_log_debug("usb_kbd_add_device()\n");
     199        usb_log_debug("usbhid_add_device()\n");
    200200       
    201201        if (dev->interface_no < 0) {
    202202                usb_log_warning("Device is not a supported keyboard.\n");
    203                 usb_log_error("Failed to add USB KBD device: endpoint not "
    204                     "found.\n");
     203                usb_log_error("Failed to add HID device: endpoint not found."
     204                    "\n");
    205205                return ENOTSUP;
    206206        }
    207207       
    208         int rc = usb_kbd_try_add_device(dev);
     208        int rc = usbhid_try_add_device(dev);
    209209       
    210210        if (rc != EOK) {
    211211                usb_log_warning("Device is not a supported keyboard.\n");
    212                 usb_log_error("Failed to add KBD device: %s.\n",
     212                usb_log_error("Failed to add HID device: %s.\n",
    213213                    str_error(rc));
    214214                return rc;
     
    224224/* Currently, the framework supports only device adding. Once the framework
    225225 * supports unplug, more callbacks will be added. */
    226 static usb_driver_ops_t usb_kbd_driver_ops = {
    227         .add_device = usb_kbd_add_device,
     226static usb_driver_ops_t usbhid_driver_ops = {
     227        .add_device = usbhid_add_device,
    228228};
    229229
    230230
    231231/* The driver itself. */
    232 static usb_driver_t usb_kbd_driver = {
     232static usb_driver_t usbhid_driver = {
    233233        .name = NAME,
    234         .ops = &usb_kbd_driver_ops,
     234        .ops = &usbhid_driver_ops,
    235235        .endpoints = usb_kbd_endpoints
    236236};
     
    238238/*----------------------------------------------------------------------------*/
    239239
     240//static driver_ops_t kbd_driver_ops = {
     241//      .add_device = usbhid_add_device,
     242//};
     243
     244///*----------------------------------------------------------------------------*/
     245
     246//static driver_t kbd_driver = {
     247//      .name = NAME,
     248//      .driver_ops = &kbd_driver_ops
     249//};
     250
     251/*----------------------------------------------------------------------------*/
     252
    240253int main(int argc, char *argv[])
    241254{
    242         printf(NAME ": HelenOS USB KBD driver.\n");
     255        printf(NAME ": HelenOS USB HID driver.\n");
    243256
    244257        usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
    245258
    246         return usb_driver_main(&usb_kbd_driver);
     259        return usb_driver_main(&usbhid_driver);
    247260}
    248261
  • uspace/drv/usbkbd/usbkbd.ma

    rc6cb76d r7dfc06fa  
    1 10 usb&interface&class=HID&subclass=0x01&protocol=0x01
     1100 usb&interface&class=HID&subclass=0x01&protocol=0x01
     210 usb&interface&class=HID
  • uspace/lib/usb/include/usb/classes/hidparser.h

    rc6cb76d r7dfc06fa  
    8888        /** */ 
    8989        int depth;     
    90         uint8_t report_id;
    9190       
    9291        /** */ 
    9392        link_t link;
    94 
    9593} usb_hid_report_path_t;
    9694
     
    157155        /** */ 
    158156        link_t feature;
    159        
    160         int use_report_id;
    161 
    162         /** */
    163         link_t stack;
    164157} usb_hid_report_parser_t;     
    165158
     
    173166         * @param arg Custom argument.
    174167         */
    175         void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t report_id, void *arg);
     168        void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t modifiers, void *arg);
    176169} usb_hid_report_in_callbacks_t;
    177170
     
    276269
    277270/** */
    278 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path, uint8_t report_id);
    279 
    280 /** */
    281271int usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, int32_t usage_page, int32_t usage);
    282272
  • uspace/lib/usb/include/usb/host/batch.h

    rc6cb76d r7dfc06fa  
    9292void usb_transfer_batch_call_in(usb_transfer_batch_t *instance);
    9393void usb_transfer_batch_call_out(usb_transfer_batch_t *instance);
    94 void usb_transfer_batch_finish(usb_transfer_batch_t *instance);
    95 
    96 static inline void usb_transfer_batch_finish_error(
    97     usb_transfer_batch_t *instance, int error)
    98 {
    99         assert(instance);
    100         instance->error = error;
    101         usb_transfer_batch_finish(instance);
    102 }
     94void usb_transfer_batch_finish(usb_transfer_batch_t *instance, int error);
    10395
    10496#endif
  • uspace/lib/usb/include/usb/host/device_keeper.h

    rc6cb76d r7dfc06fa  
    9696usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance,
    9797    usb_address_t address);
     98
     99void usb_device_keeper_use_control(usb_device_keeper_t *instance,
     100    usb_target_t target);
     101
     102void usb_device_keeper_release_control(usb_device_keeper_t *instance,
     103    usb_target_t target);
     104
    98105#endif
    99106/**
  • uspace/lib/usb/include/usb/host/endpoint.h

    rc6cb76d r7dfc06fa  
    3939#include <bool.h>
    4040#include <adt/list.h>
    41 #include <fibril_synch.h>
    42 
    4341#include <usb/usb.h>
    4442
     
    5048        usb_speed_t speed;
    5149        size_t max_packet_size;
     50        bool active;
    5251        unsigned toggle:1;
    53         fibril_mutex_t guard;
    54         fibril_condvar_t avail;
    55         volatile bool active;
    5652        link_t same_device_eps;
    5753} endpoint_t;
     
    6258
    6359void endpoint_destroy(endpoint_t *instance);
    64 
    65 void endpoint_use(endpoint_t *instance);
    66 
    67 void endpoint_release(endpoint_t *instance);
    6860
    6961int endpoint_toggle_get(endpoint_t *instance);
  • uspace/lib/usb/src/devpoll.c

    rc6cb76d r7dfc06fa  
    6666        usb_pipe_t *pipe
    6767            = polling_data->dev->pipes[polling_data->pipe_index].pipe;
    68        
    69         usb_log_debug("Pipe interface number: %d, protocol: %d, subclass: %d, max packet size: %d\n",
    70             polling_data->dev->pipes[polling_data->pipe_index].interface_no,
    71             polling_data->dev->pipes[polling_data->pipe_index].description->interface_protocol,
    72             polling_data->dev->pipes[polling_data->pipe_index].description->interface_subclass,
    73             pipe->max_packet_size);
    7468
    7569        size_t failed_attempts = 0;
     
    8983                /* Quit the session regardless of errors. */
    9084                usb_pipe_end_session(pipe);
    91                
    92 //              if (rc == ESTALL) {
    93 //                      usb_log_debug("Seding clear feature...\n");
    94 //                      usb_request_clear_feature(pipe, USB_REQUEST_TYPE_STANDARD,
    95 //                        USB_REQUEST_RECIPIENT_ENDPOINT, 0, pipe->endpoint_no);
    96 //                      continue;
    97 //              }
    9885
    9986                if (rc != EOK) {
  • uspace/lib/usb/src/hidparser.c

    rc6cb76d r7dfc06fa  
    6464int usb_hid_report_reset_local_items();
    6565void usb_hid_free_report_list(link_t *head);
    66 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item);
     66
    6767/*
    6868 * Data translation private functions
     
    106106    list_initialize(&(parser->feature));
    107107
    108         list_initialize(&(parser->stack));
    109 
    110         parser->use_report_id = 0;
    111108    return EOK;   
    112109}
     
    189186                                        tmp_usage_path = NULL;
    190187
    191                                         usb_hid_report_path_set_report_id(report_item->usage_path, report_item->id);   
    192                                         if(report_item->id != 0){
    193                                                 parser->use_report_id = 1;
    194                                         }
    195188                                       
    196189                                        switch(tag) {
     
    222215                                        if(!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) {
    223216                                                return ENOMEM;
    224                                         }                                       
     217                                        }
    225218                                        memcpy(new_report_item,report_item, sizeof(usb_hid_report_item_t));
    226                                         link_initialize(&(new_report_item->link));
    227                                        
    228219                                        /* reset local items */
    229220                                        new_report_item->usage_minimum = 0;
    230221                                        new_report_item->usage_maximum = 0;
    231                                         new_report_item->designator_index = 0;
    232                                         new_report_item->designator_minimum = 0;
    233                                         new_report_item->designator_maximum = 0;
    234                                         new_report_item->string_index = 0;
    235                                         new_report_item->string_minimum = 0;
    236                                         new_report_item->string_maximum = 0;
    237 
    238                                         /* reset usage from current usage path */
    239                                         usb_hid_report_usage_path_t *path = list_get_instance(&usage_path->link, usb_hid_report_usage_path_t, link);
    240                                         path->usage = 0;
    241222                                       
     223                                        link_initialize(&(new_report_item->link));
    242224                                        report_item = new_report_item;
    243225                                                                               
     
    245227                                case USB_HID_REPORT_TAG_PUSH:
    246228                                        // push current state to stack
    247                                         new_report_item = usb_hid_report_item_clone(report_item);
    248                                         list_prepend (&parser->stack, &new_report_item->link);
    249                                        
     229                                        // not yet implemented
    250230                                        break;
    251231                                case USB_HID_REPORT_TAG_POP:
    252232                                        // restore current state from stack
    253                                         if(list_empty (&parser->stack)) {
    254                                                 return EINVAL;
    255                                         }
    256                                        
    257                                         report_item = list_get_instance(&parser->stack, usb_hid_report_item_t, link);
    258                                         list_remove (parser->stack.next);
    259                                        
     233                                        // not yet implemented                                             
    260234                                        break;
    261235                                       
     
    673647        }
    674648
    675         parser->use_report_id = 0;
    676 
    677649        usb_hid_free_report_list(&parser->input);
    678650        usb_hid_free_report_list(&parser->output);
     
    704676        size_t i=0;
    705677        size_t j=0;
    706         uint8_t report_id = 0;
    707678
    708679        if(parser == NULL) {
     
    715686        if(!(keys = malloc(sizeof(uint8_t) * key_count))){
    716687                return ENOMEM;
    717         }
    718 
    719         if(parser->use_report_id != 0) {
    720                 report_id = data[0];
    721                 usb_hid_report_path_set_report_id(path, report_id);
    722688        }
    723689
     
    727693
    728694                item = list_get_instance(list_item, usb_hid_report_item_t, link);
    729 
    730695                if(!USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) &&
    731696                   (usb_hid_report_compare_usage_path(item->usage_path, path, flags) == EOK)) {
     
    750715        }
    751716
    752         callbacks->keyboard(keys, key_count, report_id, arg);
     717        callbacks->keyboard(keys, key_count, 0, arg);
    753718           
    754719        free(keys);     
     
    774739        int32_t mask;
    775740        const uint8_t *foo;
    776 
     741       
    777742        // now only common numbers llowed
    778743        if(item->size > 32) {
     
    793758                (usb_pow(10,(item->unit_exponent))));
    794759        }
    795 
    796760        offset = item->offset + (j * item->size);
    797         if(item->id != 0) {
    798                 offset += 8;
    799                 usb_log_debug("MOVED OFFSET BY 1Byte, REPORT_ID(%d)\n", item->id);
    800         }
    801761       
    802762        // FIXME
     
    982942
    983943        int only_page;
    984 
    985         if(report_path->report_id != path->report_id) {
    986                 return 1;
    987         }
    988944
    989945        if(path->depth == 0){
     
    10821038        else {
    10831039                path->depth = 0;
    1084                 path->report_id = 0;
    10851040                list_initialize(&path->link);
    10861041                return path;
     
    12001155                return 0;
    12011156        }
    1202 
     1157       
    12031158        item = parser->output.next;
    12041159        while(&parser->output != item) {
     
    12401195        int length;
    12411196        int32_t tmp_value;
    1242         size_t offset_prefix = 0;
    12431197       
    12441198        if(parser == NULL) {
    12451199                return EINVAL;
    1246         }
    1247 
    1248         if(parser->use_report_id != 0) {
    1249                 buffer[0] = path->report_id;
    1250                 offset_prefix = 8;
    12511200        }
    12521201
     
    12691218//                              // variable item
    12701219                                value = usb_hid_translate_data_reverse(report_item, data[idx++]);
    1271                                 offset = report_item->offset + (i * report_item->size) + offset_prefix;
     1220                                offset = report_item->offset + (i * report_item->size);
    12721221                                length = report_item->size;
    12731222                        }
     
    12751224                                //bitmap
    12761225                                value += usb_hid_translate_data_reverse(report_item, data[idx++]);
    1277                                 offset = report_item->offset + offset_prefix;
     1226                                offset = report_item->offset;
    12781227                                length = report_item->size * report_item->count;
    12791228                        }
     
    13741323
    13751324
    1376 int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id)
    1377 {
    1378         if(path == NULL){
    1379                 return EINVAL;
    1380         }
    1381 
    1382         path->report_id = report_id;
    1383         return EOK;
    1384 }
    1385 
    1386 
    1387 usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item)
    1388 {
    1389         usb_hid_report_item_t *new_report_item;
    1390        
    1391         if(!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) {
    1392                 return NULL;
    1393         }                                       
    1394         memcpy(new_report_item,item, sizeof(usb_hid_report_item_t));
    1395         link_initialize(&(new_report_item->link));
    1396 
    1397         return new_report_item;
    1398 }
    1399 
    14001325/**
    14011326 * @}
  • uspace/lib/usb/src/hidreport.c

    rc6cb76d r7dfc06fa  
    8080                d = usb_dp_get_sibling_descriptor(&parser, &parser_data,
    8181                    dev->descriptors.configuration, d);
    82                 ++i;
    8382        }
    8483       
  • uspace/lib/usb/src/host/batch.c

    rc6cb76d r7dfc06fa  
    7979        instance->error = EOK;
    8080        instance->ep = ep;
    81         endpoint_use(instance->ep);
    8281}
    8382/*----------------------------------------------------------------------------*/
     
    8786 *
    8887 */
    89 void usb_transfer_batch_finish(usb_transfer_batch_t *instance)
     88void usb_transfer_batch_finish(usb_transfer_batch_t *instance, int error)
    9089{
    9190        assert(instance);
    92         assert(instance->ep);
    93         endpoint_release(instance->ep);
     91        instance->error = error;
    9492        instance->next_step(instance);
    9593}
  • uspace/lib/usb/src/host/device_keeper.c

    rc6cb76d r7dfc06fa  
    264264        return instance->devices[address].speed;
    265265}
     266/*----------------------------------------------------------------------------*/
     267void usb_device_keeper_use_control(
     268    usb_device_keeper_t *instance, usb_target_t target)
     269{
     270        assert(instance);
     271        const uint16_t ep = 1 << target.endpoint;
     272        fibril_mutex_lock(&instance->guard);
     273        while (instance->devices[target.address].control_used & ep) {
     274                fibril_condvar_wait(&instance->change, &instance->guard);
     275        }
     276        instance->devices[target.address].control_used |= ep;
     277        fibril_mutex_unlock(&instance->guard);
     278}
     279/*----------------------------------------------------------------------------*/
     280void usb_device_keeper_release_control(
     281    usb_device_keeper_t *instance, usb_target_t target)
     282{
     283        assert(instance);
     284        const uint16_t ep = 1 << target.endpoint;
     285        fibril_mutex_lock(&instance->guard);
     286        assert((instance->devices[target.address].control_used & ep) != 0);
     287        instance->devices[target.address].control_used &= ~ep;
     288        fibril_mutex_unlock(&instance->guard);
     289        fibril_condvar_signal(&instance->change);
     290}
    266291/**
    267292 * @}
  • uspace/lib/usb/src/host/endpoint.c

    rc6cb76d r7dfc06fa  
    3434 */
    3535
    36 #include <assert.h>
    3736#include <errno.h>
    3837#include <usb/host/endpoint.h>
     
    5049        instance->max_packet_size = max_packet_size;
    5150        instance->toggle = 0;
    52         instance->active = false;
    53         fibril_mutex_initialize(&instance->guard);
    54         fibril_condvar_initialize(&instance->avail);
    5551        link_initialize(&instance->same_device_eps);
    5652        return EOK;
     
    6056{
    6157        assert(instance);
    62         assert(!instance->active);
    6358        list_remove(&instance->same_device_eps);
    6459        free(instance);
    65 }
    66 /*----------------------------------------------------------------------------*/
    67 void endpoint_use(endpoint_t *instance)
    68 {
    69         assert(instance);
    70         fibril_mutex_lock(&instance->guard);
    71         while (instance->active)
    72                 fibril_condvar_wait(&instance->avail, &instance->guard);
    73         instance->active = true;
    74         fibril_mutex_unlock(&instance->guard);
    75 }
    76 /*----------------------------------------------------------------------------*/
    77 void endpoint_release(endpoint_t *instance)
    78 {
    79         assert(instance);
    80         fibril_mutex_lock(&instance->guard);
    81         instance->active = false;
    82         fibril_mutex_unlock(&instance->guard);
    83         fibril_condvar_signal(&instance->avail);
    8460}
    8561/*----------------------------------------------------------------------------*/
  • uspace/lib/usb/src/hub.c

    rc6cb76d r7dfc06fa  
    178178 * error codes than those listed as return codes by this function itself).
    179179 *
    180  * The @p connection representing connection with host controller does not
    181  * need to be started.
    182  * This function duplicates the connection to allow simultaneous calls of
    183  * this function (i.e. from different fibrils).
    184  *
    185180 * @param[in] parent Parent device (i.e. the hub device).
    186  * @param[in] connection Connection to host controller.
     181 * @param[in] connection Opened connection to host controller.
    187182 * @param[in] dev_speed New device speed.
    188183 * @param[in] enable_port Function for enabling signaling through the port the
     
    211206    ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun)
    212207{
    213         assert(connection != NULL);
    214         // FIXME: this is awful, we are accessing directly the structure.
    215         usb_hc_connection_t hc_conn = {
    216                 .hc_handle = connection->hc_handle,
    217                 .hc_phone = -1
    218         };
     208        CHECK_CONNECTION(connection);
     209
     210        /*
     211         * Request new address.
     212         */
     213        usb_address_t dev_addr = usb_hc_request_address(connection, dev_speed);
     214        if (dev_addr < 0) {
     215                return EADDRNOTAVAIL;
     216        }
    219217
    220218        int rc;
    221219
    222         rc = usb_hc_connection_open(&hc_conn);
    223         if (rc != EOK) {
    224                 return rc;
    225         }
    226 
    227 
    228         /*
    229          * Request new address.
    230          */
    231         usb_address_t dev_addr = usb_hc_request_address(&hc_conn, dev_speed);
    232         if (dev_addr < 0) {
    233                 usb_hc_connection_close(&hc_conn);
    234                 return EADDRNOTAVAIL;
    235         }
    236 
    237 
    238220        /*
    239221         * Reserve the default address.
    240222         */
    241         rc = usb_hc_reserve_default_address(&hc_conn, dev_speed);
     223        rc = usb_hc_reserve_default_address(connection, dev_speed);
    242224        if (rc != EOK) {
    243225                rc = EBUSY;
     
    259241        usb_device_connection_t dev_conn;
    260242        rc = usb_device_connection_initialize_on_default_address(&dev_conn,
    261             &hc_conn);
     243            connection);
    262244        if (rc != EOK) {
    263245                rc = ENOTCONN;
     
    276258         * endpoint.
    277259         */
    278         rc = usb_pipe_register(&ctrl_pipe, 0, &hc_conn);
     260        rc = usb_pipe_register(&ctrl_pipe, 0, connection);
    279261        if (rc != EOK) {
    280262                rc = EREFUSED;
     
    304286         * Register the control endpoint for the new device.
    305287         */
    306         rc = usb_pipe_register(&ctrl_pipe, 0, &hc_conn);
     288        rc = usb_pipe_register(&ctrl_pipe, 0, connection);
    307289        if (rc != EOK) {
    308290                rc = EREFUSED;
     
    313295         * Release the original endpoint.
    314296         */
    315         unregister_control_endpoint_on_default_address(&hc_conn);
     297        unregister_control_endpoint_on_default_address(connection);
    316298
    317299        /*
    318300         * Once the address is changed, we can return the default address.
    319301         */
    320         usb_hc_release_default_address(&hc_conn);
     302        usb_hc_release_default_address(connection);
    321303
    322304
     
    343325                .handle = child_handle
    344326        };
    345         rc = usb_hc_register_device(&hc_conn, &new_device);
     327        rc = usb_hc_register_device(connection, &new_device);
    346328        if (rc != EOK) {
    347329                rc = EDESTADDRREQ;
     
    372354
    373355leave_unregister_endpoint:
    374         usb_pipe_unregister(&ctrl_pipe, &hc_conn);
     356        usb_pipe_unregister(&ctrl_pipe, connection);
    375357
    376358leave_release_default_address:
    377         usb_hc_release_default_address(&hc_conn);
     359        usb_hc_release_default_address(connection);
    378360
    379361leave_release_free_address:
    380         usb_hc_unregister_device(&hc_conn, dev_addr);
    381 
    382         usb_hc_connection_close(&hc_conn);
     362        usb_hc_unregister_device(connection, dev_addr);
    383363
    384364        return rc;
Note: See TracChangeset for help on using the changeset viewer.