Changeset 944f8fdd in mainline


Ignore:
Timestamp:
2018-01-19T17:38:22Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2833bb4
Parents:
861b5d6
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-19 17:06:40)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-19 17:38:22)
Message:

libusbhost: move utility functions to new header utility.h

Location:
uspace
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ehci/main.c

    r861b5d6 r944f8fdd  
    3737#include <io/logctl.h>
    3838#include <usb/host/hcd.h>
    39 #include <usb/host/ddf_helpers.h>
     39#include <usb/host/utility.h>
    4040
    4141#include "res.h"
     
    5252        .claim = disable_legacy,
    5353        .start = hc_start,
    54         .setup_root_hub = hcd_setup_virtual_root_hub,
     54        .setup_root_hub = hc_setup_virtual_root_hub,
    5555        .hc_gone = hc_gone,
    5656};
  • uspace/drv/bus/usb/ohci/main.c

    r861b5d6 r944f8fdd  
    4343
    4444#include <usb/debug.h>
    45 #include <usb/host/ddf_helpers.h>
     45#include <usb/host/utility.h>
    4646
    4747#include "hc.h"
     
    5858        .claim = hc_gain_control,
    5959        .start = hc_start,
    60         .setup_root_hub = hcd_setup_virtual_root_hub,
     60        .setup_root_hub = hc_setup_virtual_root_hub,
    6161        .hc_gone = hc_gone,
    6262};
  • uspace/drv/bus/usb/uhci/main.c

    r861b5d6 r944f8fdd  
    4343#include <str_error.h>
    4444#include <usb/debug.h>
    45 #include <usb/host/ddf_helpers.h>
     45#include <usb/host/utility.h>
    4646
    4747#include "hc.h"
     
    5858        .hc_add = hc_add,
    5959        .start = hc_start,
    60         .setup_root_hub = hcd_setup_virtual_root_hub,
     60        .setup_root_hub = hc_setup_virtual_root_hub,
    6161        .hc_gone = hc_gone,
    6262};
  • uspace/drv/bus/usb/vhc/main.c

    r861b5d6 r944f8fdd  
    4040
    4141#include <usb/host/ddf_helpers.h>
     42#include <usb/host/utility.h>
    4243
    4344#include <usb/debug.h>
     
    106107         * needs to be ready at this time.
    107108         */
    108         ret = hcd_setup_virtual_root_hub(&vhc->base);
     109        ret = hc_setup_virtual_root_hub(&vhc->base);
    109110        if (ret != EOK) {
    110111                usb_log_error("Failed to init VHC root hub: %s",
  • uspace/drv/bus/usb/xhci/bus.c

    r861b5d6 r944f8fdd  
    3636#include <usb/host/endpoint.h>
    3737#include <usb/host/hcd.h>
     38#include <usb/host/utility.h>
    3839#include <usb/descriptor.h>
    3940#include <usb/debug.h>
     
    113114
    114115        uint16_t max_packet_size;
    115         if ((err = hcd_get_ep0_max_packet_size(&max_packet_size, (bus_t *) &hc->bus, &dev->base)))
     116        if ((err = hc_get_ep0_max_packet_size(&max_packet_size, (bus_t *) &hc->bus, &dev->base)))
    116117                return err;
    117118
     
    184185
    185186        /* Read the device descriptor, derive the match ids */
    186         if ((err = hcd_device_explore(dev))) {
     187        if ((err = hc_device_explore(dev))) {
    187188                usb_log_error("Device(%d): Failed to explore device: %s", dev->address, str_error(err));
    188189                goto err_address;
  • uspace/lib/usbhost/Makefile

    r861b5d6 r944f8fdd  
    4141        src/bandwidth.c \
    4242        src/dma_buffer.c \
     43        src/utility.c \
    4344        src/usb_transfer_batch.c
    4445
  • uspace/lib/usbhost/include/usb/host/ddf_helpers.h

    r861b5d6 r944f8fdd  
    4848void hcd_ddf_clean_hc(hc_device_t *);
    4949
    50 int hcd_setup_virtual_root_hub(hc_device_t *);
    5150
    5251device_t *hcd_ddf_fun_create(hc_device_t *, usb_speed_t);
    5352void hcd_ddf_fun_destroy(device_t *);
    5453
    55 int hcd_get_device_desc(device_t *, usb_standard_device_descriptor_t *);
    56 int hcd_setup_match_ids(device_t *, usb_standard_device_descriptor_t *);
    57 int hcd_device_explore(device_t *);
     54int hcd_ddf_setup_match_ids(device_t *, usb_standard_device_descriptor_t *);
    5855
    5956int hcd_ddf_enable_interrupt(hc_device_t *hcd, int);
  • uspace/lib/usbhost/include/usb/host/hcd.h

    r861b5d6 r944f8fdd  
    110110int hc_driver_main(const hc_driver_t *);
    111111
    112 /* TODO: These are a kind of utility functions, they should probably go
    113  * somewhere else.
    114  */
    115 extern int hcd_get_ep0_max_packet_size(uint16_t *, bus_t *, device_t *);
    116 
    117 /** How many toggles need to be reset */
    118 typedef enum {
    119         RESET_NONE,
    120         RESET_EP,
    121         RESET_ALL
    122 } toggle_reset_mode_t;
    123 
    124 extern toggle_reset_mode_t hcd_get_request_toggle_reset_mode(
    125     const usb_device_request_setup_packet_t *request);
    126 
    127112#endif
    128113
  • uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h

    r861b5d6 r944f8fdd  
    5151typedef struct endpoint endpoint_t;
    5252typedef struct bus bus_t;
     53
     54/** How many toggles need to be reset */
     55typedef enum {
     56        RESET_NONE,
     57        RESET_EP,
     58        RESET_ALL
     59} toggle_reset_mode_t;
    5360
    5461/** Structure stores additional data needed for communication with EP */
  • uspace/lib/usbhost/src/ddf_helpers.c

    r861b5d6 r944f8fdd  
    393393}
    394394
    395 int hcd_get_device_desc(device_t *device, usb_standard_device_descriptor_t *desc)
    396 {
    397         const usb_target_t control_ep = {{
    398                 .address = device->address,
    399                 .endpoint = 0,
    400         }};
    401 
    402         /* Get std device descriptor */
    403         const usb_device_request_setup_packet_t get_device_desc =
    404             GET_DEVICE_DESC(sizeof(*desc));
    405 
    406         usb_log_debug("Device(%d): Requesting full device descriptor.",
    407             device->address);
    408         ssize_t got = bus_device_send_batch_sync(device, control_ep, USB_DIRECTION_IN,
    409             (char *) desc, sizeof(*desc), *(uint64_t *)&get_device_desc,
    410             "read device descriptor");
    411 
    412         if (got < 0)
    413                 return got;
    414 
    415         return got == sizeof(*desc) ? EOK : EOVERFLOW;
    416 }
    417 
    418 int hcd_setup_match_ids(device_t *device, usb_standard_device_descriptor_t *desc)
     395int hcd_ddf_setup_match_ids(device_t *device, usb_standard_device_descriptor_t *desc)
    419396{
    420397        int err;
     
    434411
    435412        return EOK;
    436 }
    437 
    438 
    439 int hcd_device_explore(device_t *device)
    440 {
    441         int err;
    442         usb_standard_device_descriptor_t desc = { 0 };
    443 
    444         if ((err = hcd_get_device_desc(device, &desc))) {
    445                 usb_log_error("Device(%d): Failed to get dev descriptor: %s",
    446                     device->address, str_error(err));
    447                 return err;
    448         }
    449 
    450         if ((err = hcd_setup_match_ids(device, &desc))) {
    451                 usb_log_error("Device(%d): Failed to setup match ids: %s", device->address, str_error(err));
    452                 return err;
    453         }
    454 
    455         return EOK;
    456 }
    457 
    458 /** Announce root hub to the DDF
    459  *
    460  * @param[in] device Host controller ddf device
    461  * @return Error code
    462  */
    463 int hcd_setup_virtual_root_hub(hc_device_t *hcd)
    464 {
    465         int err;
    466 
    467         assert(hcd);
    468 
    469         device_t *dev = hcd_ddf_fun_create(hcd, USB_SPEED_MAX);
    470         if (!dev) {
    471                 usb_log_error("Failed to create function for the root hub.");
    472                 return ENOMEM;
    473         }
    474 
    475         ddf_fun_set_name(dev->fun, "roothub");
    476 
    477         /* Assign an address to the device */
    478         if ((err = bus_device_enumerate(dev))) {
    479                 usb_log_error("Failed to enumerate roothub device: %s", str_error(err));
    480                 goto err_usb_dev;
    481         }
    482 
    483         if ((err = ddf_fun_bind(dev->fun))) {
    484                 usb_log_error("Failed to register roothub: %s.", str_error(err));
    485                 goto err_enumerated;
    486         }
    487 
    488         return EOK;
    489 
    490 err_enumerated:
    491         bus_device_gone(dev);
    492 err_usb_dev:
    493         hcd_ddf_fun_destroy(dev);
    494         return err;
    495413}
    496414
  • uspace/lib/usbhost/src/endpoint.c

    r861b5d6 r944f8fdd  
    4343#include <usb/descriptor.h>
    4444#include <usb/host/hcd.h>
     45#include <usb/host/utility.h>
    4546
    4647#include "usb_transfer_batch.h"
     
    284285        if (ep->transfer_type == USB_TRANSFER_CONTROL)
    285286                batch->toggle_reset_mode
    286                         = hcd_get_request_toggle_reset_mode(&batch->setup.packet);
     287                        = hc_get_request_toggle_reset_mode(&batch->setup.packet);
    287288
    288289        const int ret = ops->batch_schedule(batch);
  • uspace/lib/usbhost/src/hcd.c

    r861b5d6 r944f8fdd  
    370370}
    371371
    372 /** Get max packet size for the control endpoint 0.
    373  *
    374  * For LS, HS, and SS devices this value is fixed. For FS devices we must fetch
    375  * the first 8B of the device descriptor to determine it.
    376  *
    377  * @return Max packet size for EP 0
    378  */
    379 int hcd_get_ep0_max_packet_size(uint16_t *mps, bus_t *bus, device_t *dev)
    380 {
    381         assert(mps);
    382 
    383         static const uint16_t mps_fixed [] = {
    384                 [USB_SPEED_LOW] = 8,
    385                 [USB_SPEED_HIGH] = 64,
    386                 [USB_SPEED_SUPER] = 512,
    387         };
    388 
    389         if (dev->speed < ARRAY_SIZE(mps_fixed) && mps_fixed[dev->speed] != 0) {
    390                 *mps = mps_fixed[dev->speed];
    391                 return EOK;
    392         }
    393 
    394         const usb_target_t control_ep = {{
    395                 .address = dev->address,
    396                 .endpoint = 0,
    397         }};
    398 
    399         usb_standard_device_descriptor_t desc = { 0 };
    400         const usb_device_request_setup_packet_t get_device_desc_8 =
    401             GET_DEVICE_DESC(CTRL_PIPE_MIN_PACKET_SIZE);
    402 
    403         usb_log_debug("Requesting first 8B of device descriptor to determine MPS.");
    404         ssize_t got = bus_device_send_batch_sync(dev, control_ep, USB_DIRECTION_IN,
    405             (char *) &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8,
    406             "read first 8 bytes of dev descriptor");
    407 
    408         if (got != CTRL_PIPE_MIN_PACKET_SIZE) {
    409                 const int err = got < 0 ? got : EOVERFLOW;
    410                 usb_log_error("Failed to get 8B of dev descr: %s.", str_error(err));
    411                 return err;
    412         }
    413 
    414         if (desc.descriptor_type != USB_DESCTYPE_DEVICE) {
    415                 usb_log_error("The device responded with wrong device descriptor.");
    416                 return EIO;
    417         }
    418 
    419         uint16_t version = uint16_usb2host(desc.usb_spec_version);
    420         if (version < 0x0300) {
    421                 /* USB 2 and below have MPS raw in the field */
    422                 *mps = desc.max_packet_size;
    423         } else {
    424                 /* USB 3 have MPS as an 2-based exponent */
    425                 *mps = (1 << desc.max_packet_size);
    426         }
    427         return EOK;
    428 }
    429 
    430 /** Check setup packet data for signs of toggle reset.
    431  *
    432  * @param[in] requst Setup requst data.
    433  *
    434  * @retval -1 No endpoints need reset.
    435  * @retval 0 All endpoints need reset.
    436  * @retval >0 Specified endpoint needs reset.
    437  *
    438  */
    439 toggle_reset_mode_t hcd_get_request_toggle_reset_mode(
    440     const usb_device_request_setup_packet_t *request)
    441 {
    442         assert(request);
    443         switch (request->request)
    444         {
    445         /* Clear Feature ENPOINT_STALL */
    446         case USB_DEVREQ_CLEAR_FEATURE: /*resets only cleared ep */
    447                 /* 0x2 ( HOST to device | STANDART | TO ENPOINT) */
    448                 if ((request->request_type == 0x2) &&
    449                     (request->value == USB_FEATURE_ENDPOINT_HALT))
    450                         return RESET_EP;
    451                 break;
    452         case USB_DEVREQ_SET_CONFIGURATION:
    453         case USB_DEVREQ_SET_INTERFACE:
    454                 /* Recipient must be device, this resets all endpoints,
    455                  * In fact there should be no endpoints but EP 0 registered
    456                  * as different interfaces use different endpoints,
    457                  * unless you're changing configuration or alternative
    458                  * interface of an already setup device. */
    459                 if (!(request->request_type & SETUP_REQUEST_TYPE_DEVICE_TO_HOST))
    460                         return RESET_ALL;
    461                 break;
    462         default:
    463                 break;
    464         }
    465 
    466         return RESET_NONE;
    467 }
    468 
    469372
    470373/**
  • uspace/lib/usbhost/src/usb2_bus.c

    r861b5d6 r944f8fdd  
    4545#include <usb/descriptor.h>
    4646#include <usb/request.h>
     47#include <usb/host/utility.h>
    4748#include <usb/usb.h>
    4849
     
    140141        }
    141142
    142         if ((err = hcd_get_ep0_max_packet_size(&ep0_desc.endpoint.max_packet_size, &bus->base, dev)))
     143        if ((err = hc_get_ep0_max_packet_size(&ep0_desc.endpoint.max_packet_size, &bus->base, dev)))
    143144                goto err_address;
    144145
     
    199200
    200201        /* Read the device descriptor, derive the match ids */
    201         if ((err = hcd_device_explore(dev))) {
     202        if ((err = hc_device_explore(dev))) {
    202203                usb_log_error("Device(%d): Failed to explore device: %s", dev->address, str_error(err));
    203204                release_address(bus, dev->address);
Note: See TracChangeset for help on using the changeset viewer.