Changeset 00aece0 in mainline for uspace/drv/bus/usb/vhc/connhost.c


Ignore:
Timestamp:
2012-02-18T16:47:38Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4449c6c
Parents:
bd5f3b7 (diff), f943dd3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/vhc/connhost.c

    rbd5f3b7 r00aece0  
    5757 * @return Error code.
    5858 */
    59 static int request_address(ddf_fun_t *fun, usb_speed_t speed,
    60     usb_address_t *address)
    61 {
    62         VHC_DATA(vhc, fun);
    63 
    64         usb_address_t addr = device_keeper_get_free_address(&vhc->dev_keeper,
    65             USB_SPEED_HIGH);
    66         if (addr < 0) {
    67                 return addr;
    68         }
    69 
    70         if (address != NULL) {
    71                 *address = addr;
    72         }
    73 
    74         return EOK;
     59static int request_address(ddf_fun_t *fun, usb_address_t *address, bool strict,
     60    usb_speed_t speed)
     61{
     62        VHC_DATA(vhc, fun);
     63
     64        assert(address);
     65        return usb_device_manager_request_address(
     66            &vhc->dev_manager, address, strict, speed);
    7567}
    7668
     
    8880        usb_log_debug("Binding handle %" PRIun " to address %d.\n",
    8981            handle, address);
    90         usb_device_keeper_bind(&vhc->dev_keeper, address, handle);
     82        usb_device_manager_bind_address(&vhc->dev_manager, address, handle);
    9183
    9284        return EOK;
     
    10496{
    10597        VHC_DATA(vhc, fun);
    106         bool found =
    107             usb_device_keeper_find_by_address(&vhc->dev_keeper, address, handle);
    108         return found ? EOK : ENOENT;
     98        return usb_device_manager_get_info_by_address(
     99            &vhc->dev_manager, address, handle, NULL);
    109100}
    110101
     
    119110        VHC_DATA(vhc, fun);
    120111        usb_log_debug("Releasing address %d...\n", address);
    121         usb_device_keeper_release(&vhc->dev_keeper, address);
     112        usb_device_manager_release_address(&vhc->dev_manager, address);
    122113
    123114        return ENOTSUP;
     
    137128 */
    138129static int register_endpoint(ddf_fun_t *fun,
    139     usb_address_t address, usb_speed_t speed, usb_endpoint_t endpoint,
     130    usb_address_t address, usb_endpoint_t endpoint,
    140131    usb_transfer_type_t transfer_type, usb_direction_t direction,
    141132    size_t max_packet_size, unsigned int interval)
    142133{
    143         /* TODO: Use usb_endpoint_manager_add_ep */
    144         VHC_DATA(vhc, fun);
    145 
    146         endpoint_t *ep = endpoint_get(
    147             address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1);
    148         if (ep == NULL) {
    149                 return ENOMEM;
    150         }
    151 
    152         int rc = usb_endpoint_manager_register_ep(&vhc->ep_manager, ep, 1);
    153         if (rc != EOK) {
    154                 endpoint_destroy(ep);
    155                 return rc;
    156         }
    157 
    158         return EOK;
     134        VHC_DATA(vhc, fun);
     135
     136        return usb_endpoint_manager_add_ep(&vhc->ep_manager,
     137            address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1, 0,
     138            NULL, NULL);
     139
    159140}
    160141
     
    172153        VHC_DATA(vhc, fun);
    173154
    174         endpoint_t *ep = usb_endpoint_manager_get_ep(&vhc->ep_manager,
    175             address, endpoint, direction, NULL);
    176         if (ep == NULL) {
    177                 return ENOENT;
    178         }
    179 
    180         int rc = usb_endpoint_manager_unregister_ep(&vhc->ep_manager,
    181             address, endpoint, direction);
     155        int rc = usb_endpoint_manager_remove_ep(&vhc->ep_manager,
     156            address, endpoint, direction, NULL, NULL);
    182157
    183158        return rc;
    184159}
    185 
     160#if 0
    186161/** Schedule interrupt out transfer.
    187162 *
     
    413388        return EOK;
    414389}
    415 
    416 static int tell_address(ddf_fun_t *fun, devman_handle_t handle,
    417     usb_address_t *address)
     390#endif
     391static int usb_read(ddf_fun_t *fun, usb_target_t target, uint64_t setup_buffer,
     392    uint8_t *data_buffer, size_t data_buffer_size,
     393    usbhc_iface_transfer_in_callback_t callback, void *arg)
     394{
     395        VHC_DATA(vhc, fun);
     396
     397        endpoint_t *ep = usb_endpoint_manager_find_ep(&vhc->ep_manager,
     398            target.address, target.endpoint, USB_DIRECTION_IN);
     399        if (ep == NULL) {
     400                return ENOENT;
     401        }
     402        const usb_transfer_type_t transfer_type = ep->transfer_type;
     403
     404
     405        vhc_transfer_t *transfer = vhc_transfer_create(target.address,
     406            target.endpoint, USB_DIRECTION_IN, transfer_type,
     407            fun, arg);
     408        if (transfer == NULL) {
     409                return ENOMEM;
     410        }
     411        if (transfer_type == USB_TRANSFER_CONTROL) {
     412                transfer->setup_buffer = malloc(sizeof(uint64_t));
     413                assert(transfer->setup_buffer);
     414                memcpy(transfer->setup_buffer, &setup_buffer, sizeof(uint64_t));
     415                transfer->setup_buffer_size = sizeof(uint64_t);
     416        }
     417        transfer->data_buffer = data_buffer;
     418        transfer->data_buffer_size = data_buffer_size;
     419        transfer->callback_in = callback;
     420
     421        int rc = vhc_virtdev_add_transfer(vhc, transfer);
     422        if (rc != EOK) {
     423                if (transfer->setup_buffer != NULL) {
     424                        free(transfer->setup_buffer);
     425                }
     426                free(transfer);
     427                return rc;
     428        }
     429
     430        return EOK;
     431}
     432
     433static int usb_write(ddf_fun_t *fun, usb_target_t target, uint64_t setup_buffer,
     434    const uint8_t *data_buffer, size_t data_buffer_size,
     435    usbhc_iface_transfer_out_callback_t callback, void *arg)
     436{
     437        VHC_DATA(vhc, fun);
     438
     439        endpoint_t *ep = usb_endpoint_manager_find_ep(&vhc->ep_manager,
     440            target.address, target.endpoint, USB_DIRECTION_OUT);
     441        if (ep == NULL) {
     442                return ENOENT;
     443        }
     444        const usb_transfer_type_t transfer_type = ep->transfer_type;
     445
     446
     447        vhc_transfer_t *transfer = vhc_transfer_create(target.address,
     448            target.endpoint, USB_DIRECTION_OUT, transfer_type,
     449            fun, arg);
     450        if (transfer == NULL) {
     451                return ENOMEM;
     452        }
     453        if (transfer_type == USB_TRANSFER_CONTROL) {
     454                transfer->setup_buffer = malloc(sizeof(uint64_t));
     455                assert(transfer->setup_buffer);
     456                memcpy(transfer->setup_buffer, &setup_buffer, sizeof(uint64_t));
     457                transfer->setup_buffer_size = sizeof(uint64_t);
     458        }
     459        transfer->data_buffer = (void*)data_buffer;
     460        transfer->data_buffer_size = data_buffer_size;
     461        transfer->callback_out = callback;
     462
     463        int rc = vhc_virtdev_add_transfer(vhc, transfer);
     464        if (rc != EOK) {
     465                free(transfer->setup_buffer);
     466                free(transfer);
     467                return rc;
     468        }
     469
     470        return EOK;
     471}
     472
     473static int tell_address(ddf_fun_t *fun, usb_address_t *address)
    418474{
    419475        UNSUPPORTED("tell_address");
     
    432488}
    433489
    434 static int tell_address_rh(ddf_fun_t *root_hub_fun, devman_handle_t handle,
    435     usb_address_t *address)
     490static int tell_address_rh(ddf_fun_t *root_hub_fun, usb_address_t *address)
    436491{
    437492        VHC_DATA(vhc, root_hub_fun);
    438493
    439         if (handle == 0) {
    440                 handle = root_hub_fun->handle;
    441         }
     494        devman_handle_t handle = root_hub_fun->handle;
    442495
    443496        usb_log_debug("tell_address_rh(handle=%" PRIun ")\n", handle);
    444         usb_address_t addr = usb_device_keeper_find(&vhc->dev_keeper, handle);
     497        const usb_address_t addr =
     498            usb_device_manager_find_address(&vhc->dev_manager, handle);
    445499        if (addr < 0) {
    446500                return addr;
     
    454508        .request_address = request_address,
    455509        .bind_address = bind_address,
    456         .find_by_address = find_by_address,
     510        .get_handle = find_by_address,
    457511        .release_address = release_address,
    458512
     
    460514        .unregister_endpoint = unregister_endpoint,
    461515
    462         .interrupt_out = interrupt_out,
    463         .interrupt_in = interrupt_in,
    464 
    465         .bulk_in = bulk_in,
    466         .bulk_out = bulk_out,
    467 
    468         .control_write = control_write,
    469         .control_read = control_read
     516        .write = usb_write,
     517        .read = usb_read,
    470518};
    471519
    472520usb_iface_t vhc_usb_iface = {
    473521        .get_hc_handle = usb_iface_get_hc_handle_hc_impl,
    474         .get_address = tell_address
     522        .get_my_address = tell_address
    475523};
    476524
    477525usb_iface_t rh_usb_iface = {
    478526        .get_hc_handle = usb_iface_get_hc_handle_rh_impl,
    479         .get_address = tell_address_rh
     527        .get_my_address = tell_address_rh
    480528};
    481529
Note: See TracChangeset for help on using the changeset viewer.