Changes in / [f6309b6:53338bda] in mainline


Ignore:
Location:
uspace
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/main.c

    rf6309b6 r53338bda  
    8181{
    8282        int rc;
    83 
    84         if (str_cmp(path, "uhci") == 0) {
    85                 path = "/hw/pci0/00:01.2";
    86         }
    8783
    8884        devman_handle_t handle;
  • uspace/drv/usbhid/hid.h

    rf6309b6 r53338bda  
    6969        device_t *device;
    7070        usb_hid_configuration_t *conf;
     71        usb_address_t address;
    7172        usb_hid_report_parser_t *parser;
    7273
    7374        usb_device_connection_t wire;
    74         usb_endpoint_pipe_t ctrl_pipe;
    7575        usb_endpoint_pipe_t poll_pipe;
    7676} usb_hid_dev_kbd_t;
  • uspace/drv/usbhid/main.c

    rf6309b6 r53338bda  
    4747#include <usb/classes/hid.h>
    4848#include <usb/classes/hidparser.h>
    49 #include <usb/request.h>
     49#include <usb/devreq.h>
    5050#include <usb/descriptor.h>
    5151#include <io/console.h>
     
    262262}
    263263
     264# if 0
    264265/*
    265266 * Kbd functions
     
    280281               
    281282                // get the descriptor from the device
    282                 int rc = usb_request_get_descriptor(&kbd_dev->ctrl_pipe,
    283                     USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
    284                     i, 0,
    285                     kbd_dev->conf->interfaces[i].report_desc, length,
     283                int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone,
     284                    kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
     285                    0, i, kbd_dev->conf->interfaces[i].report_desc, length,
    286286                    &actual_size);
    287287
     
    303303        usb_standard_configuration_descriptor_t config_desc;
    304304       
    305         int rc;
    306         rc = usb_request_get_bare_configuration_descriptor(&kbd_dev->ctrl_pipe,
    307             0, &config_desc);
     305        int rc = usb_drv_req_get_bare_configuration_descriptor(
     306            kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc);
    308307       
    309308        if (rc != EOK) {
     
    319318        size_t transferred = 0;
    320319        // get full configuration descriptor
    321         rc = usb_request_get_full_configuration_descriptor(&kbd_dev->ctrl_pipe,
    322             0, descriptors,
     320        rc = usb_drv_req_get_full_configuration_descriptor(
     321            kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors,
    323322            config_desc.total_length, &transferred);
    324323       
     
    364363        return EOK;
    365364}
    366 
     365#endif
    367366static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    368367{
    369         int rc;
    370 
    371368        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
    372369            sizeof(usb_hid_dev_kbd_t));
     
    379376        kbd_dev->device = dev;
    380377
     378        // get phone to my HC and save it as my parent's phone
     379        // TODO: maybe not a good idea if DDF will use parent_phone
     380        int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
     381        if (rc < 0) {
     382                printf("Problem setting phone to HC.\n");
     383                goto error_leave;
     384        }
     385
     386        rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
     387        if (rc < 0) {
     388                printf("Problem getting address of the device.\n");
     389                goto error_leave;
     390        }
     391
     392        // doesn't matter now that we have no address
     393//      if (kbd_dev->address < 0) {
     394//              fprintf(stderr, NAME ": No device address!\n");
     395//              free(kbd_dev);
     396//              return NULL;
     397//      }
     398
     399        /*
     400         * will need all descriptors:
     401         * 1) choose one configuration from configuration descriptors
     402         *    (set it to the device)
     403         * 2) set endpoints from endpoint descriptors
     404         */
     405
     406
     407        // TODO: get descriptors, parse descriptors and save endpoints
     408        //usbkbd_process_descriptors(kbd_dev);
     409        usb_drv_req_set_configuration(
     410          kbd_dev->device->parent_phone, kbd_dev->address, 1);
     411
     412
     413
    381414        /*
    382415         * Initialize the backing connection to the host controller.
     
    392425         * Initialize device pipes.
    393426         */
    394         rc = usb_endpoint_pipe_initialize_default_control(&kbd_dev->ctrl_pipe,
    395             &kbd_dev->wire);
    396         if (rc != EOK) {
    397                 printf("Failed to initialize default control pipe: %s.\n",
    398                     str_error(rc));
    399                 goto error_leave;
    400         }
    401 
    402427        rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire,
    403428            GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);
     
    408433        }
    409434
    410         /*
    411          * will need all descriptors:
    412          * 1) choose one configuration from configuration descriptors
    413          *    (set it to the device)
    414          * 2) set endpoints from endpoint descriptors
    415          */
    416 
    417         // TODO: get descriptors, parse descriptors and save endpoints
    418         usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
    419         //usb_request_set_configuration(&kbd_dev->ctrl_pipe, 1);
    420         usbkbd_process_descriptors(kbd_dev);
    421         usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
    422435
    423436        return kbd_dev;
  • uspace/lib/c/generic/async.c

    rf6309b6 r53338bda  
    15671567}
    15681568
    1569 /** Start IPC_M_DATA_READ using the async framework.
    1570  *
    1571  * @param phoneid Phone that will be used to contact the receiving side.
    1572  * @param dst Address of the beginning of the destination buffer.
    1573  * @param size Size of the destination buffer (in bytes).
    1574  * @param dataptr Storage of call data (arg 2 holds actual data size).
    1575  * @return Hash of the sent message or 0 on error.
    1576  */
    1577 aid_t async_data_read(int phoneid, void *dst, size_t size, ipc_call_t *dataptr)
    1578 {
    1579         return async_send_2(phoneid, IPC_M_DATA_READ, (sysarg_t) dst,
    1580             (sysarg_t) size, dataptr);
    1581 }
    1582 
    15831569/** Wrapper for IPC_M_DATA_READ calls using the async framework.
    15841570 *
  • uspace/lib/c/include/async.h

    rf6309b6 r53338bda  
    340340            (arg4), (answer))
    341341
    342 extern aid_t async_data_read(int, void *, size_t, ipc_call_t *);
    343342extern int async_data_read_start(int, void *, size_t);
    344343extern bool async_data_read_receive(ipc_callid_t *, size_t *);
  • uspace/lib/drv/generic/remote_usbhc.c

    rf6309b6 r53338bda  
    4242
    4343static void remote_usbhc_get_address(device_t *, void *, ipc_callid_t, ipc_call_t *);
     44static void remote_usbhc_get_buffer(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4445static void remote_usbhc_interrupt_out(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4546static void remote_usbhc_interrupt_in(device_t *, void *, ipc_callid_t, ipc_call_t *);
     
    6364        remote_usbhc_get_address,
    6465
     66        remote_usbhc_get_buffer,
     67
    6568        remote_usbhc_reserve_default_address,
    6669        remote_usbhc_release_default_address,
     
    9598typedef struct {
    9699        ipc_callid_t caller;
    97         ipc_callid_t data_caller;
    98100        void *buffer;
    99101        void *setup_packet;
     
    125127
    126128        trans->caller = caller;
    127         trans->data_caller = 0;
    128129        trans->buffer = NULL;
    129130        trans->setup_packet = NULL;
     
    154155}
    155156
     157void remote_usbhc_get_buffer(device_t *device, void *iface,
     158    ipc_callid_t callid, ipc_call_t *call)
     159{
     160        sysarg_t buffer_hash = DEV_IPC_GET_ARG1(*call);
     161        async_transaction_t * trans = (async_transaction_t *)buffer_hash;
     162        if (trans == NULL) {
     163                async_answer_0(callid, ENOENT);
     164                return;
     165        }
     166        if (trans->buffer == NULL) {
     167                async_answer_0(callid, EINVAL);
     168                async_transaction_destroy(trans);
     169                return;
     170        }
     171
     172        ipc_callid_t cid;
     173        size_t accepted_size;
     174        if (!async_data_read_receive(&cid, &accepted_size)) {
     175                async_answer_0(callid, EINVAL);
     176                async_transaction_destroy(trans);
     177                return;
     178        }
     179
     180        if (accepted_size > trans->size) {
     181                accepted_size = trans->size;
     182        }
     183        async_data_read_finalize(cid, trans->buffer, accepted_size);
     184
     185        async_answer_1(callid, EOK, accepted_size);
     186
     187        async_transaction_destroy(trans);
     188}
     189
    156190void remote_usbhc_reserve_default_address(device_t *device, void *iface,
    157191    ipc_callid_t callid, ipc_call_t *call)
     
    256290        if (outcome != USB_OUTCOME_OK) {
    257291                async_answer_0(trans->caller, outcome);
    258                 if (trans->data_caller) {
    259                         async_answer_0(trans->data_caller, EINTR);
    260                 }
    261292                async_transaction_destroy(trans);
    262293                return;
     
    264295
    265296        trans->size = actual_size;
    266 
    267         if (trans->data_caller) {
    268                 async_data_read_finalize(trans->data_caller,
    269                     trans->buffer, actual_size);
    270         }
    271 
    272         async_answer_0(trans->caller, USB_OUTCOME_OK);
    273 
    274         async_transaction_destroy(trans);
     297        async_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans);
    275298}
    276299
     
    353376        };
    354377
    355         ipc_callid_t data_callid;
    356         if (!async_data_read_receive(&data_callid, &len)) {
    357                 async_answer_0(callid, EPARTY);
    358                 return;
    359         }
    360 
    361378        async_transaction_t *trans = async_transaction_create(callid);
    362379        if (trans == NULL) {
     
    364381                return;
    365382        }
    366         trans->data_caller = data_callid;
    367383        trans->buffer = malloc(len);
    368384        trans->size = len;
     
    614630        }
    615631
    616         ipc_callid_t data_callid;
    617         if (!async_data_read_receive(&data_callid, &data_len)) {
    618                 async_answer_0(callid, EPARTY);
    619                 free(setup_packet);
    620                 return;
    621         }
    622 
    623632        async_transaction_t *trans = async_transaction_create(callid);
    624633        if (trans == NULL) {
     
    627636                return;
    628637        }
    629         trans->data_caller = data_callid;
    630638        trans->setup_packet = setup_packet;
    631639        trans->size = data_len;
  • uspace/lib/drv/include/usbhc_iface.h

    rf6309b6 r53338bda  
    6666 *   - argument #2 is target endpoint
    6767 *   - argument #3 is buffer size
    68  * - this call is immediately followed by IPC data read (async version)
    6968 * - the call is not answered until the device returns some data (or until
    7069 *   error occurs)
     70 * - if the call is answered with EOK, first argument of the answer is buffer
     71 *   hash that could be used to retrieve the actual data
    7172 *
    7273 * Some special methods (NO-DATA transactions) do not send any data. These
    7374 * might behave as both OUT or IN transactions because communication parts
    7475 * where actual buffers are exchanged are omitted.
    75  **
     76 *
     77 * The mentioned data retrieval can be done any time after receiving EOK
     78 * answer to IN method.
     79 * This retrieval is done using the IPC_M_USBHC_GET_BUFFER where
     80 * the first argument is buffer hash from call answer.
     81 * This call must be immediately followed by data read-in and after the
     82 * data are transferred, the initial call (IPC_M_USBHC_GET_BUFFER)
     83 * is answered. Each buffer can be retrieved only once.
     84 *
    7685 * For all these methods, wrap functions exists. Important rule: functions
    7786 * for IN transactions have (as parameters) buffers where retrieved data
     
    95104        IPC_M_USBHC_GET_ADDRESS,
    96105
     106        /** Asks for data buffer.
     107         * See explanation at usb_iface_funcs_t.
     108         * This function does not have counter part in functional interface
     109         * as it is handled by the remote part itself.
     110         */
     111        IPC_M_USBHC_GET_BUFFER,
     112
    97113
    98114        /** Reserve usage of default address.
  • uspace/lib/usb/src/usbdrv.c

    rf6309b6 r53338bda  
    4949        /** Storage for actual number of bytes transferred. */
    5050        size_t *size_transferred;
    51         /** Initial call reply data. */
     51        /** Initial call replay data. */
    5252        ipc_call_t reply;
    5353        /** Initial call identifier. */
    5454        aid_t request;
    55         /** Reply data for data read call. */
    56         ipc_call_t read_reply;
    57         /** Data read call identifier. */
    58         aid_t read_request;
    5955} transfer_info_t;
    6056
     
    144140
    145141        if (rc != EOK) {
     142                printf("usb_drv_get_my_address over %d failed: %s\n", phone, str_error(rc));
    146143                return rc;
    147144        }
     
    253250        }
    254251
    255         transfer->read_request = 0;
    256252        transfer->size_transferred = NULL;
    257253        transfer->buffer = NULL;
     
    319315        }
    320316
    321         transfer->read_request = 0;
    322317        transfer->size_transferred = actual_size;
    323318        transfer->buffer = buffer;
     
    332327            &transfer->reply);
    333328
    334         if (buffer != NULL) {
    335                 transfer->read_request = async_data_read(phone, buffer, size,
    336                     &transfer->read_reply);
    337         }
    338 
    339329        *handle = (usb_handle_t) transfer;
    340330
     
    342332}
    343333
     334/** Read buffer from HCD.
     335 *
     336 * @param phone Opened phone to HCD.
     337 * @param hash Buffer hash (obtained after completing IN transaction).
     338 * @param buffer Buffer where to store data data.
     339 * @param size Buffer size.
     340 * @param actual_size Storage where actual number of bytes transferred will
     341 *      be stored.
     342 * @return Error status.
     343 */
     344static int read_buffer_in(int phone, sysarg_t hash,
     345    void *buffer, size_t size, size_t *actual_size)
     346{
     347        ipc_call_t answer_data;
     348        sysarg_t answer_rc;
     349        aid_t req;
     350        int rc;
     351
     352        req = async_send_2(phone,
     353            DEV_IFACE_ID(USBHC_DEV_IFACE),
     354            IPC_M_USBHC_GET_BUFFER,
     355            hash,
     356            &answer_data);
     357
     358        rc = async_data_read_start(phone, buffer, size);
     359        if (rc != EOK) {
     360                async_wait_for(req, NULL);
     361                return EINVAL;
     362        }
     363
     364        async_wait_for(req, &answer_rc);
     365        rc = (int)answer_rc;
     366
     367        if (rc != EOK) {
     368                return rc;
     369        }
     370
     371        *actual_size = IPC_GET_ARG1(answer_data);
     372
     373        return EOK;
     374}
    344375
    345376/** Blocks caller until given USB transaction is finished.
     
    364395
    365396        sysarg_t answer_rc;
     397        async_wait_for(transfer->request, &answer_rc);
     398
     399        if (answer_rc != EOK) {
     400                rc = (int) answer_rc;
     401                goto leave;
     402        }
    366403
    367404        /*
     
    369406         */
    370407        if ((transfer->buffer != NULL) && (transfer->size > 0)) {
    371                 async_wait_for(transfer->read_request, &answer_rc);
    372 
    373                 if (answer_rc != EOK) {
    374                         rc = (int) answer_rc;
     408                /*
     409                 * The buffer hash identifies the data on the server
     410                 * side.
     411                 * We will use it when actually reading-in the data.
     412                 */
     413                sysarg_t buffer_hash = IPC_GET_ARG1(transfer->reply);
     414                if (buffer_hash == 0) {
     415                        rc = ENOENT;
    375416                        goto leave;
    376417                }
    377418
    378                 if (transfer->size_transferred != NULL) {
    379                         *(transfer->size_transferred)
    380                             = IPC_GET_ARG2(transfer->read_reply);
     419                size_t actual_size;
     420                rc = read_buffer_in(transfer->phone, buffer_hash,
     421                    transfer->buffer, transfer->size, &actual_size);
     422
     423                if (rc != EOK) {
     424                        goto leave;
    381425                }
    382         }
    383 
    384         async_wait_for(transfer->request, &answer_rc);
    385 
    386         if (answer_rc != EOK) {
    387                 rc = (int) answer_rc;
    388                 goto leave;
     426
     427                if (transfer->size_transferred) {
     428                        *(transfer->size_transferred) = actual_size;
     429                }
    389430        }
    390431
     
    474515        }
    475516
    476         transfer->read_request = 0;
    477517        transfer->size_transferred = NULL;
    478518        transfer->buffer = NULL;
     
    580620        }
    581621
    582         transfer->read_request = async_data_read(phone, buffer, buffer_size,
    583             &transfer->read_reply);
    584 
    585622        *handle = (usb_handle_t) transfer;
    586623
Note: See TracChangeset for help on using the changeset viewer.