Ignore:
Timestamp:
2011-02-02T00:57:32Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1537ba6, 3597dab
Parents:
2cea1045 (diff), 2f4438f5 (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:

Merged pipe API

The pipe API shall eventually replace USB device drivers API explicitly
using phones. This API uses extra abstraction level by introducing
device connection (the wire) and endpoint pipe.

The USB HID driver uses the new API, hub driver does not.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/remote_usbhc.c

    r2cea1045 rb00849e  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2010-2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    5252static void remote_usbhc_control_read_data(device_t *, void *, ipc_callid_t, ipc_call_t *);
    5353static void remote_usbhc_control_read_status(device_t *, void *, ipc_callid_t, ipc_call_t *);
     54static void remote_usbhc_control_write(device_t *, void *, ipc_callid_t, ipc_call_t *);
     55static void remote_usbhc_control_read(device_t *, void *, ipc_callid_t, ipc_call_t *);
    5456static void remote_usbhc_reserve_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
    5557static void remote_usbhc_release_default_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
     
    8183        remote_usbhc_control_read_setup,
    8284        remote_usbhc_control_read_data,
    83         remote_usbhc_control_read_status
     85        remote_usbhc_control_read_status,
     86
     87        remote_usbhc_control_write,
     88        remote_usbhc_control_read
    8489};
    8590
     
    95100        ipc_callid_t caller;
    96101        void *buffer;
     102        void *setup_packet;
    97103        size_t size;
    98104} async_transaction_t;
     
    297303        trans->caller = callid;
    298304        trans->buffer = buffer;
     305        trans->setup_packet = NULL;
    299306        trans->size = len;
    300307
     
    336343        trans->caller = callid;
    337344        trans->buffer = malloc(len);
     345        trans->setup_packet = NULL;
    338346        trans->size = len;
    339347
     
    391399        trans->caller = callid;
    392400        trans->buffer = NULL;
     401        trans->setup_packet = NULL;
    393402        trans->size = 0;
    394403
     
    496505}
    497506
     507void remote_usbhc_control_write(device_t *device, void *iface,
     508ipc_callid_t callid, ipc_call_t *call)
     509{
     510        usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     511        assert(usb_iface != NULL);
     512
     513        if (!usb_iface->control_write) {
     514                ipc_answer_0(callid, ENOTSUP);
     515                return;
     516        }
     517
     518        usb_target_t target = {
     519                .address = DEV_IPC_GET_ARG1(*call),
     520                .endpoint = DEV_IPC_GET_ARG2(*call)
     521        };
     522
     523        int rc;
     524
     525        void *setup_packet = NULL;
     526        void *data_buffer = NULL;
     527        size_t setup_packet_len = 0;
     528        size_t data_buffer_len = 0;
     529
     530        rc = async_data_write_accept(&setup_packet, false,
     531            1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
     532        if (rc != EOK) {
     533                ipc_answer_0(callid, rc);
     534                return;
     535        }
     536        rc = async_data_write_accept(&data_buffer, false,
     537            1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);
     538        if (rc != EOK) {
     539                free(setup_packet);
     540                ipc_answer_0(callid, rc);
     541                return;
     542        }
     543
     544        async_transaction_t *trans = malloc(sizeof(async_transaction_t));
     545        trans->caller = callid;
     546        trans->setup_packet = setup_packet;
     547        trans->buffer = data_buffer;
     548        trans->size = data_buffer_len;
     549
     550        rc = usb_iface->control_write(device, target,
     551            setup_packet, setup_packet_len,
     552            data_buffer, data_buffer_len,
     553            callback_out, trans);
     554
     555        if (rc != EOK) {
     556                ipc_answer_0(callid, rc);
     557                free(setup_packet);
     558                free(data_buffer);
     559                free(trans);
     560        }
     561}
     562
     563
     564void remote_usbhc_control_read(device_t *device, void *iface,
     565ipc_callid_t callid, ipc_call_t *call)
     566{
     567        usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     568        assert(usb_iface != NULL);
     569
     570        if (!usb_iface->control_read) {
     571                ipc_answer_0(callid, ENOTSUP);
     572                return;
     573        }
     574
     575        size_t data_len = DEV_IPC_GET_ARG3(*call);
     576        usb_target_t target = {
     577                .address = DEV_IPC_GET_ARG1(*call),
     578                .endpoint = DEV_IPC_GET_ARG2(*call)
     579        };
     580
     581        int rc;
     582
     583        void *setup_packet = NULL;
     584        size_t setup_packet_len = 0;
     585
     586        rc = async_data_write_accept(&setup_packet, false,
     587            1, USB_MAX_PAYLOAD_SIZE, 0, &setup_packet_len);
     588        if (rc != EOK) {
     589                ipc_answer_0(callid, rc);
     590                return;
     591        }
     592
     593        async_transaction_t *trans = malloc(sizeof(async_transaction_t));
     594        trans->caller = callid;
     595        trans->setup_packet = setup_packet;
     596        trans->buffer = malloc(data_len);
     597        trans->size = data_len;
     598
     599        rc = usb_iface->control_read(device, target,
     600            setup_packet, setup_packet_len,
     601            trans->buffer, trans->size,
     602            callback_in, trans);
     603
     604        if (rc != EOK) {
     605                ipc_answer_0(callid, rc);
     606                free(setup_packet);
     607                free(trans->buffer);
     608                free(trans);
     609        }
     610}
     611
    498612
    499613
Note: See TracChangeset for help on using the changeset viewer.