Changeset e099f26 in mainline


Ignore:
Timestamp:
2011-03-21T20:22:50Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c56c5b5b
Parents:
4fb6d9ee (diff), 31b568e (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:

Development branch changes (including OHCI)

Files:
22 added
60 edited
2 moved

Legend:

Unmodified
Added
Removed
  • .bzrignore

    r4fb6d9ee re099f26  
    99_link.ld
    1010./*.iso
     11
     12./tools/__pycache__/
    1113
    1214./Makefile.common
     
    8486./uspace/drv/test1/test1
    8587./uspace/drv/test2/test2
     88./uspace/drv/ohci/ohci
    8689./uspace/drv/ehci-hcd/ehci-hcd
    8790./uspace/drv/uhci-hcd/uhci-hcd
    8891./uspace/drv/uhci-rhd/uhci-rhd
     92./uspace/drv/usbflbk/usbflbk
    8993./uspace/drv/usbhub/usbhub
    9094./uspace/drv/usbhid/usbhid
     
    137141.cproject
    138142.project
     143.settings
     144.pydevproject
     145
  • boot/arch/amd64/Makefile.inc

    r4fb6d9ee re099f26  
    4444        ns8250 \
    4545        ehci-hcd \
     46        ohci \
    4647        uhci-hcd \
    4748        uhci-rhd \
     49        usbflbk \
    4850        usbhub \
    4951        usbhid \
  • kernel/tools/genmap.py

    r4fb6d9ee re099f26  
    100100                        for addr, symbol in symbols:
    101101                                value = fname + ':' + symbol
    102                                 data = struct.pack(symtabfmt, addr + offset, value[:MAXSTRING])
     102                                value_bytes = value.encode('ascii')
     103                                data = struct.pack(symtabfmt, addr + offset, value_bytes[:MAXSTRING])
    103104                                out.write(data)
    104105                       
    105         out.write(struct.pack(symtabfmt, 0, ''))
     106        out.write(struct.pack(symtabfmt, 0, b''))
    106107
    107108def main():
  • tools/mkfat.py

    r4fb6d9ee re099f26  
    211211        dir_entry = xstruct.create(DIR_ENTRY)
    212212       
    213         dir_entry.name = mangle_fname(name)
    214         dir_entry.ext = mangle_ext(name)
     213        dir_entry.name = mangle_fname(name).encode('ascii')
     214        dir_entry.ext = mangle_ext(name).encode('ascii')
    215215       
    216216        if (directory):
     
    239239       
    240240        dir_entry.signature = 0x2e
    241         dir_entry.name = '       '
    242         dir_entry.ext = '   '
     241        dir_entry.name = b'       '
     242        dir_entry.ext = b'   '
    243243        dir_entry.attr = 0x10
    244244       
     
    258258       
    259259        dir_entry.signature = [0x2e, 0x2e]
    260         dir_entry.name = '      '
    261         dir_entry.ext = '   '
     260        dir_entry.name = b'      '
     261        dir_entry.ext = b'   '
    262262        dir_entry.attr = 0x10
    263263       
  • tools/mkhord.py

    r4fb6d9ee re099f26  
    8484        payload_size_aligned = align_up(payload_size, align)
    8585       
    86         header.tag = "HORD"
     86        header.tag = b"HORD"
    8787        header.version = 1
    8888        header.encoding = HORD_LSB
  • tools/mktmpfs.py

    r4fb6d9ee re099f26  
    8080                        dentry.kind = TMPFS_FILE
    8181                        dentry.fname_len = len(name)
    82                         dentry.fname = name
     82                        dentry.fname = name.encode('ascii')
    8383                        dentry.flen = size
    8484                       
     
    9797                        dentry.kind = TMPFS_DIRECTORY
    9898                        dentry.fname_len = len(name)
    99                         dentry.fname = name
     99                        dentry.fname = name.encode('ascii')
    100100                       
    101101                        outf.write(dentry.pack())
     
    122122       
    123123        header = xstruct.create(HEADER)
    124         header.tag = "TMPFS"
     124        header.tag = b"TMPFS"
    125125       
    126126        outf.write(header.pack())
  • uspace/Makefile

    r4fb6d9ee re099f26  
    118118                srv/hw/irc/i8259 \
    119119                drv/ehci-hcd \
     120                drv/ohci \
    120121                drv/uhci-hcd \
    121122                drv/uhci-rhd \
     123                drv/usbflbk \
    122124                drv/usbhid \
    123125                drv/usbhub \
     
    136138                srv/hw/irc/i8259 \
    137139                drv/ehci-hcd \
     140                drv/ohci \
    138141                drv/uhci-hcd \
    139142                drv/uhci-rhd \
     143                drv/usbflbk \
    140144                drv/usbhid \
    141145                drv/usbhub \
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    r4fb6d9ee re099f26  
    7070        unsigned int i, j;
    7171        devmap_handle_t handle;
     72        aoff64_t offset;
    7273        uint8_t *blk;
    7374        size_t size, bytes, rows;
     
    120121        }
    121122
     123        offset = ba * block_size;
     124
    122125        while (size > 0) {
    123126                rc = block_read_direct(handle, ba, 1, blk);
     
    133136
    134137                for (j = 0; j < rows; j++) {
     138                        printf("[%06" PRIxOFF64 "] ", offset);
    135139                        for (i = 0; i < BPR; i++) {
    136140                                if (j * BPR + i < bytes)
     
    152156                                }
    153157                        }
     158                        offset += BPR;
    154159                        putchar('\n');
    155160                }
  • uspace/app/usbinfo/dev.c

    r4fb6d9ee re099f26  
    5959        }
    6060
    61         rc = usb_endpoint_pipe_initialize_default_control(&dev->ctrl_pipe,
     61        rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe,
    6262            &dev->wire);
    6363        if (rc != EOK) {
     
    6868        }
    6969
    70         rc = usb_endpoint_pipe_probe_default_control(&dev->ctrl_pipe);
     70        rc = usb_pipe_probe_default_control(&dev->ctrl_pipe);
    7171        if (rc != EOK) {
    7272                fprintf(stderr,
     
    7676        }
    7777
    78         rc = usb_endpoint_pipe_start_session(&dev->ctrl_pipe);
     78        rc = usb_pipe_start_session(&dev->ctrl_pipe);
    7979        if (rc != EOK) {
    8080                fprintf(stderr,
     
    107107
    108108leave:
    109         if (usb_endpoint_pipe_is_session_started(&dev->ctrl_pipe)) {
    110                 usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
     109        if (usb_pipe_is_session_started(&dev->ctrl_pipe)) {
     110                usb_pipe_end_session(&dev->ctrl_pipe);
    111111        }
    112112
     
    118118void destroy_device(usbinfo_device_t *dev)
    119119{
    120         usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
     120        usb_pipe_end_session(&dev->ctrl_pipe);
    121121        free(dev);
    122122}
  • uspace/app/usbinfo/info.c

    r4fb6d9ee re099f26  
    4242#include <usb/classes/classes.h>
    4343#include <usb/classes/hid.h>
     44#include <usb/classes/hub.h>
    4445#include "usbinfo.h"
    4546
     
    109110    usb_standard_device_descriptor_t *descriptor)
    110111{
    111         printf("%sDevice (0x%04x by 0x%04x, %s)\n", prefix,
     112        printf("%sDevice (0x%04x by 0x%04x, %s, %zu configurations)\n", prefix,
    112113            (int) descriptor->product_id,
    113114            (int) descriptor->vendor_id,
    114             usb_str_class(descriptor->device_class));
     115            usb_str_class(descriptor->device_class),
     116            (size_t) descriptor->configuration_count);
    115117}
    116118
     
    118120    usb_standard_configuration_descriptor_t *descriptor)
    119121{
    120         printf("%sConfiguration #%d\n", prefix,
    121             (int) descriptor->configuration_number);
     122        printf("%sConfiguration #%d (%zu interfaces, total %zuB)\n", prefix,
     123            (int) descriptor->configuration_number,
     124            (size_t) descriptor->interface_count,
     125            (size_t) descriptor->total_length);
    122126}
    123127
     
    125129    usb_standard_interface_descriptor_t *descriptor)
    126130{
    127         printf("%sInterface #%d (%s, 0x%02x, 0x%02x)\n", prefix,
     131        printf("%sInterface #%d (%s, 0x%02x, 0x%02x), alternate %d\n", prefix,
    128132            (int) descriptor->interface_number,
    129133            usb_str_class(descriptor->interface_class),
    130134            (int) descriptor->interface_subclass,
    131             (int) descriptor->interface_protocol);
     135            (int) descriptor->interface_protocol,
     136            (int) descriptor->alternate_setting);
    132137}
    133138
     
    153158}
    154159
    155 
    156 static void dump_descriptor_tree_brief_callback(uint8_t *descriptor,
     160static void dump_descriptor_tree_brief_hub(const char *prefix,
     161    usb_hub_descriptor_header_t *descriptor)
     162{
     163        printf("%shub (%d ports)\n", prefix,
     164            (int) descriptor->port_count);
     165}
     166
     167
     168static void dump_descriptor_tree_callback(uint8_t *descriptor,
    157169    size_t depth, void *arg)
    158170{
     
    171183                if (descr_size >= sizeof(descriptor_type)) { \
    172184                        callback(indent, (descriptor_type *) descriptor); \
     185                        if (arg != NULL) { \
     186                                usb_dump_standard_descriptor(stdout, \
     187                                    get_indent(depth +2), "\n", \
     188                                    descriptor, descr_size); \
     189                        } \
    173190                } else { \
    174191                        descr_type = -1; \
     
    191208                    usb_standard_hid_descriptor_t,
    192209                    dump_descriptor_tree_brief_hid);
     210                /*
     211                 * Probably useless, hub descriptor shall not be part of
     212                 * configuration descriptor.
     213                 */
     214                _BRANCH(USB_DESCTYPE_HUB,
     215                    usb_hub_descriptor_header_t,
     216                    dump_descriptor_tree_brief_hub);
    193217
    194218                default:
     
    203227void dump_descriptor_tree_brief(usbinfo_device_t *dev)
    204228{
    205         dump_descriptor_tree_brief_callback((uint8_t *)&dev->device_descriptor,
     229        dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
    206230            (size_t) -1, NULL);
    207231        usb_dp_walk_simple(dev->full_configuration_descriptor,
    208232            dev->full_configuration_descriptor_size,
    209233            usb_dp_standard_descriptor_nesting,
    210             dump_descriptor_tree_brief_callback,
     234            dump_descriptor_tree_callback,
    211235            NULL);
    212236}
     237
     238void dump_descriptor_tree_full(usbinfo_device_t *dev)
     239{
     240        dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
     241            (size_t) -1, dev);
     242        usb_dp_walk_simple(dev->full_configuration_descriptor,
     243            dev->full_configuration_descriptor_size,
     244            usb_dp_standard_descriptor_nesting,
     245            dump_descriptor_tree_callback,
     246            dev);
     247}
     248
    213249
    214250void dump_strings(usbinfo_device_t *dev)
  • uspace/app/usbinfo/main.c

    r4fb6d9ee re099f26  
    134134        _OPTION("-m --match-ids", "Print match ids generated for the device.");
    135135        _OPTION("-t --descriptor-tree", "Print descriptor tree.");
     136        _OPTION("-T --descriptor-tree-full", "Print detailed descriptor tree");
    136137        _OPTION("-s --strings", "Try to print all string descriptors.");
    137138
     
    149150        {"match-ids", no_argument, NULL, 'm'},
    150151        {"descriptor-tree", no_argument, NULL, 't'},
     152        {"descriptor-tree-full", no_argument, NULL, 'T'},
    151153        {"strings", no_argument, NULL, 's'},
    152154        {0, 0, NULL, 0}
    153155};
    154 static const char *short_options = "himts";
     156static const char *short_options = "himtTs";
    155157
    156158static usbinfo_action_t actions[] = {
     
    168170                .opt = 't',
    169171                .action = dump_descriptor_tree_brief,
     172                .active = false
     173        },
     174        {
     175                .opt = 'T',
     176                .action = dump_descriptor_tree_full,
    170177                .active = false
    171178        },
  • uspace/app/usbinfo/usbinfo.h

    r4fb6d9ee re099f26  
    4444
    4545typedef struct {
    46         usb_endpoint_pipe_t ctrl_pipe;
     46        usb_pipe_t ctrl_pipe;
    4747        usb_device_connection_t wire;
    4848        usb_standard_device_descriptor_t device_descriptor;
     
    8282void dump_device_match_ids(usbinfo_device_t *);
    8383void dump_descriptor_tree_brief(usbinfo_device_t *);
     84void dump_descriptor_tree_full(usbinfo_device_t *);
    8485void dump_strings(usbinfo_device_t *);
    8586
  • uspace/doc/doxygroups.h

    r4fb6d9ee re099f26  
    274274         */
    275275
    276 
     276        /**
     277         * @defgroup drvusbfallback USB fallback driver.
     278         * @ingroup usb
     279         * @brief Fallback driver for any USB device.
     280         * @details
     281         * The purpose of this driver is to simplify querying of unknown
     282         * devices from within HelenOS (without a driver, no node at all
     283         * may appear under /dev/devices).
     284         */
     285
     286
  • uspace/drv/ehci-hcd/Makefile

    r4fb6d9ee re099f26  
    3333
    3434SOURCES = \
     35        hc_iface.c \
    3536        main.c \
    3637        pci.c
  • uspace/drv/ehci-hcd/main.c

    r4fb6d9ee re099f26  
    4444
    4545#include "pci.h"
    46 
    47 #define NAME "ehci-hcd"
     46#include "ehci.h"
    4847
    4948static int ehci_add_device(ddf_dev_t *device);
     
    5756        .driver_ops = &ehci_driver_ops
    5857};
     58static ddf_dev_ops_t hc_ops = {
     59        .interfaces[USBHC_DEV_IFACE] = &ehci_hc_iface,
     60};
     61
    5962/*----------------------------------------------------------------------------*/
    6063/** Initializes a new ddf driver instance of EHCI hcd.
     
    7174        return ret; \
    7275}
    73 
    74         usb_log_info("uhci_add_device() called\n");
    7576
    7677        uintptr_t mem_reg_base = 0;
     
    8990            "Failed(%d) disable legacy USB: %s.\n", ret, str_error(ret));
    9091
     92        ddf_fun_t *hc_fun = ddf_fun_create(device, fun_exposed, "ehci-hc");
     93        if (hc_fun == NULL) {
     94                usb_log_error("Failed to create EHCI function.\n");
     95                return ENOMEM;
     96        }
     97        hc_fun->ops = &hc_ops;
     98        ret = ddf_fun_bind(hc_fun);
     99
     100        CHECK_RET_RETURN(ret,
     101            "Failed to bind EHCI function: %s.\n",
     102            str_error(ret));
     103
     104        usb_log_info("Controlling new EHCI device `%s' (handle %llu).\n",
     105            device->name, device->handle);
     106
    91107        return EOK;
    92108#undef CHECK_RET_RETURN
     
    103119int main(int argc, char *argv[])
    104120{
    105         usb_log_enable(USB_LOG_LEVEL_ERROR, NAME);
     121        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    106122        return ddf_driver_main(&ehci_driver);
    107123}
  • uspace/drv/ohci/hc.h

    r4fb6d9ee re099f26  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 
    29 /** @addtogroup drvusbuhcihc
     28/** @addtogroup drvusbohci
    3029 * @{
    3130 */
    3231/** @file
    33  * @brief UHCI driver
     32 * @brief OHCI host controller driver structure
    3433 */
    35 #ifndef UTILS_DEVICE_KEEPER_H
    36 #define UTILS_DEVICE_KEEPER_H
    37 #include <devman.h>
     34#ifndef DRV_OHCI_HC_H
     35#define DRV_OHCI_HC_H
     36
     37#include <fibril.h>
    3838#include <fibril_synch.h>
     39#include <adt/list.h>
     40#include <ddi.h>
     41
    3942#include <usb/usb.h>
     43#include <usb/host/device_keeper.h>
     44#include <usbhc_iface.h>
    4045
    41 #define USB_ADDRESS_COUNT (USB11_ADDRESS_MAX + 1)
     46#include "batch.h"
     47#include "ohci_regs.h"
     48#include "root_hub.h"
    4249
    43 struct usb_device_info {
    44         usb_speed_t speed;
    45         bool occupied;
    46         uint16_t toggle_status;
    47         devman_handle_t handle;
    48 };
     50typedef struct hc {
     51        ohci_regs_t *registers;
     52        usb_address_t rh_address;
     53        rh_t rh;
     54        ddf_fun_t *ddf_instance;
     55        usb_device_keeper_t manager;
     56        fid_t interrupt_emulator;
     57} hc_t;
    4958
    50 typedef struct device_keeper {
    51         struct usb_device_info devices[USB_ADDRESS_COUNT];
    52         fibril_mutex_t guard;
    53         fibril_condvar_t default_address_occupied;
    54         usb_address_t last_address;
    55 } device_keeper_t;
     59int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
     60     uintptr_t regs, size_t reg_size, bool interrupts);
    5661
    57 void device_keeper_init(device_keeper_t *instance);
     62int hc_register_hub(hc_t *instance);
    5863
    59 void device_keeper_reserve_default(
    60     device_keeper_t *instance, usb_speed_t speed);
     64int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch);
    6165
    62 void device_keeper_release_default(device_keeper_t *instance);
     66void hc_interrupt(hc_t *instance, uint32_t status);
    6367
    64 void device_keeper_reset_if_need(
    65     device_keeper_t *instance, usb_target_t target, const unsigned char *setup_data);
     68/** Safely dispose host controller internal structures
     69 *
     70 * @param[in] instance Host controller structure to use.
     71 */
     72static inline void hc_fini(hc_t *instance) { /* TODO: implement*/ };
    6673
    67 int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target);
    68 
    69 int device_keeper_set_toggle(
    70     device_keeper_t *instance, usb_target_t target, bool toggle);
    71 
    72 usb_address_t device_keeper_request(
    73     device_keeper_t *instance, usb_speed_t speed);
    74 
    75 void device_keeper_bind(
    76     device_keeper_t *instance, usb_address_t address, devman_handle_t handle);
    77 
    78 void device_keeper_release(device_keeper_t *instance, usb_address_t address);
    79 
    80 usb_address_t device_keeper_find(
    81     device_keeper_t *instance, devman_handle_t handle);
    82 
    83 usb_speed_t device_keeper_speed(
    84     device_keeper_t *instance, usb_address_t address);
     74/** Get and cast pointer to the driver data
     75 *
     76 * @param[in] fun DDF function pointer
     77 * @return cast pointer to driver_data
     78 */
     79static inline hc_t * fun_to_hc(ddf_fun_t *fun)
     80        { return (hc_t*)fun->driver_data; }
    8581#endif
    8682/**
  • uspace/drv/uhci-hcd/Makefile

    r4fb6d9ee re099f26  
    4040        uhci_rh.c \
    4141        uhci_struct/transfer_descriptor.c \
    42         utils/device_keeper.c \
    4342        pci.c \
    4443        batch.c
  • uspace/drv/uhci-hcd/batch.c

    r4fb6d9ee re099f26  
    4242#include "uhci_hc.h"
    4343#include "utils/malloc32.h"
     44#include "uhci_struct/transfer_descriptor.h"
    4445
    4546#define DEFAULT_ERROR_COUNT 3
    4647
    47 static void batch_control(batch_t *instance,
     48typedef struct uhci_batch {
     49        qh_t *qh;
     50        td_t *tds;
     51        size_t packets;
     52        usb_device_keeper_t *manager;
     53} uhci_batch_t;
     54
     55static void batch_control(usb_transfer_batch_t *instance,
    4856    usb_packet_id data_stage, usb_packet_id status_stage);
    49 static void batch_data(batch_t *instance, usb_packet_id pid);
    50 static void batch_call_in(batch_t *instance);
    51 static void batch_call_out(batch_t *instance);
    52 static void batch_call_in_and_dispose(batch_t *instance);
    53 static void batch_call_out_and_dispose(batch_t *instance);
     57static void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid);
     58static void batch_call_in_and_dispose(usb_transfer_batch_t *instance);
     59static void batch_call_out_and_dispose(usb_transfer_batch_t *instance);
    5460
    5561
     
    7682 * transaction and callback.
    7783 */
    78 batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
     84usb_transfer_batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
    7985    usb_transfer_type_t transfer_type, size_t max_packet_size,
    80     usb_speed_t speed, char *buffer, size_t size,
     86    usb_speed_t speed, char *buffer, size_t buffer_size,
    8187    char* setup_buffer, size_t setup_size,
    8288    usbhc_iface_transfer_in_callback_t func_in,
    8389    usbhc_iface_transfer_out_callback_t func_out, void *arg,
    84     device_keeper_t *manager
     90    usb_device_keeper_t *manager
    8591    )
    8692{
     
    97103        } else (void)0
    98104
    99         batch_t *instance = malloc(sizeof(batch_t));
     105        usb_transfer_batch_t *instance = malloc(sizeof(usb_transfer_batch_t));
    100106        CHECK_NULL_DISPOSE_RETURN(instance,
    101107            "Failed to allocate batch instance.\n");
    102         bzero(instance, sizeof(batch_t));
    103 
    104         instance->qh = malloc32(sizeof(qh_t));
    105         CHECK_NULL_DISPOSE_RETURN(instance->qh,
     108        usb_transfer_batch_init(instance, target, transfer_type, speed, max_packet_size,
     109            buffer, NULL, buffer_size, NULL, setup_size, func_in,
     110            func_out, arg, fun, NULL);
     111
     112
     113        uhci_batch_t *data = malloc(sizeof(uhci_batch_t));
     114        CHECK_NULL_DISPOSE_RETURN(instance,
     115            "Failed to allocate batch instance.\n");
     116        bzero(data, sizeof(uhci_batch_t));
     117        data->manager = manager;
     118        instance->private_data = data;
     119
     120        data->packets = (buffer_size + max_packet_size - 1) / max_packet_size;
     121        if (transfer_type == USB_TRANSFER_CONTROL) {
     122                data->packets += 2;
     123        }
     124
     125        data->tds = malloc32(sizeof(td_t) * data->packets);
     126        CHECK_NULL_DISPOSE_RETURN(
     127            data->tds, "Failed to allocate transfer descriptors.\n");
     128        bzero(data->tds, sizeof(td_t) * data->packets);
     129
     130        data->qh = malloc32(sizeof(qh_t));
     131        CHECK_NULL_DISPOSE_RETURN(data->qh,
    106132            "Failed to allocate batch queue head.\n");
    107         qh_init(instance->qh);
    108 
    109         instance->packets = (size + max_packet_size - 1) / max_packet_size;
    110         if (transfer_type == USB_TRANSFER_CONTROL) {
    111                 instance->packets += 2;
    112         }
    113 
    114         instance->tds = malloc32(sizeof(td_t) * instance->packets);
    115         CHECK_NULL_DISPOSE_RETURN(
    116             instance->tds, "Failed to allocate transfer descriptors.\n");
    117         bzero(instance->tds, sizeof(td_t) * instance->packets);
    118 
    119         if (size > 0) {
    120                 instance->transport_buffer = malloc32(size);
     133        qh_init(data->qh);
     134        qh_set_element_td(data->qh, addr_to_phys(data->tds));
     135
     136        if (buffer_size > 0) {
     137                instance->transport_buffer = malloc32(buffer_size);
    121138                CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
    122139                    "Failed to allocate device accessible buffer.\n");
     
    130147        }
    131148
    132 
    133         link_initialize(&instance->link);
    134 
    135         instance->max_packet_size = max_packet_size;
    136         instance->target = target;
    137         instance->transfer_type = transfer_type;
    138         instance->buffer = buffer;
    139         instance->buffer_size = size;
    140         instance->setup_size = setup_size;
    141         instance->fun = fun;
    142         instance->arg = arg;
    143         instance->speed = speed;
    144         instance->manager = manager;
    145         instance->callback_out = func_out;
    146         instance->callback_in = func_in;
    147 
    148         qh_set_element_td(instance->qh, addr_to_phys(instance->tds));
    149 
    150149        usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
    151150            instance, target.address, target.endpoint);
     
    153152}
    154153/*----------------------------------------------------------------------------*/
    155 /** Mark batch as failed and continue with next step.
    156  *
    157  * @param[in] instance Batch structure to use.
    158  *
    159  */
    160 void batch_abort(batch_t *instance)
    161 {
    162         assert(instance);
    163         instance->error = EIO;
    164         instance->next_step(instance);
    165 }
    166 /*----------------------------------------------------------------------------*/
    167154/** Check batch TDs for activity.
    168155 *
     
    174161 * is reached.
    175162 */
    176 bool batch_is_complete(batch_t *instance)
    177 {
    178         assert(instance);
     163bool batch_is_complete(usb_transfer_batch_t *instance)
     164{
     165        assert(instance);
     166        uhci_batch_t *data = instance->private_data;
     167        assert(data);
     168
    179169        usb_log_debug2("Batch(%p) checking %d packet(s) for completion.\n",
    180             instance, instance->packets);
     170            instance, data->packets);
    181171        instance->transfered_size = 0;
    182172        size_t i = 0;
    183         for (;i < instance->packets; ++i) {
    184                 if (td_is_active(&instance->tds[i])) {
     173        for (;i < data->packets; ++i) {
     174                if (td_is_active(&data->tds[i])) {
    185175                        return false;
    186176                }
    187177
    188                 instance->error = td_status(&instance->tds[i]);
     178                instance->error = td_status(&data->tds[i]);
    189179                if (instance->error != EOK) {
    190180                        usb_log_debug("Batch(%p) found error TD(%d):%x.\n",
    191                             instance, i, instance->tds[i].status);
    192                         td_print_status(&instance->tds[i]);
    193 
    194                         device_keeper_set_toggle(instance->manager,
    195                             instance->target, td_toggle(&instance->tds[i]));
     181                            instance, i, data->tds[i].status);
     182                        td_print_status(&data->tds[i]);
     183
     184                        usb_device_keeper_set_toggle(data->manager,
     185                            instance->target, instance->direction,
     186                            td_toggle(&data->tds[i]));
    196187                        if (i > 0)
    197188                                goto substract_ret;
     
    199190                }
    200191
    201                 instance->transfered_size += td_act_size(&instance->tds[i]);
    202                 if (td_is_short(&instance->tds[i]))
     192                instance->transfered_size += td_act_size(&data->tds[i]);
     193                if (td_is_short(&data->tds[i]))
    203194                        goto substract_ret;
    204195        }
     
    214205 * Uses genercir control function with pids OUT and IN.
    215206 */
    216 void batch_control_write(batch_t *instance)
     207void batch_control_write(usb_transfer_batch_t *instance)
    217208{
    218209        assert(instance);
     
    231222 * Uses generic control with pids IN and OUT.
    232223 */
    233 void batch_control_read(batch_t *instance)
     224void batch_control_read(usb_transfer_batch_t *instance)
    234225{
    235226        assert(instance);
     
    245236 * Data transaction with PID_IN.
    246237 */
    247 void batch_interrupt_in(batch_t *instance)
    248 {
    249         assert(instance);
     238void batch_interrupt_in(usb_transfer_batch_t *instance)
     239{
     240        assert(instance);
     241        instance->direction = USB_DIRECTION_IN;
    250242        batch_data(instance, USB_PID_IN);
    251243        instance->next_step = batch_call_in_and_dispose;
     
    259251 * Data transaction with PID_OUT.
    260252 */
    261 void batch_interrupt_out(batch_t *instance)
    262 {
    263         assert(instance);
     253void batch_interrupt_out(usb_transfer_batch_t *instance)
     254{
     255        assert(instance);
     256        instance->direction = USB_DIRECTION_OUT;
    264257        /* We are data out, we are supposed to provide data */
    265258        memcpy(instance->transport_buffer, instance->buffer,
     
    276269 * Data transaction with PID_IN.
    277270 */
    278 void batch_bulk_in(batch_t *instance)
     271void batch_bulk_in(usb_transfer_batch_t *instance)
    279272{
    280273        assert(instance);
    281274        batch_data(instance, USB_PID_IN);
     275        instance->direction = USB_DIRECTION_IN;
    282276        instance->next_step = batch_call_in_and_dispose;
    283277        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
     
    290284 * Data transaction with PID_OUT.
    291285 */
    292 void batch_bulk_out(batch_t *instance)
    293 {
    294         assert(instance);
     286void batch_bulk_out(usb_transfer_batch_t *instance)
     287{
     288        assert(instance);
     289        instance->direction = USB_DIRECTION_OUT;
    295290        /* We are data out, we are supposed to provide data */
    296291        memcpy(instance->transport_buffer, instance->buffer,
     
    309304 * The last packet is marked with IOC flag.
    310305 */
    311 void batch_data(batch_t *instance, usb_packet_id pid)
    312 {
    313         assert(instance);
     306void batch_data(usb_transfer_batch_t *instance, usb_packet_id pid)
     307{
     308        assert(instance);
     309        uhci_batch_t *data = instance->private_data;
     310        assert(data);
     311
    314312        const bool low_speed = instance->speed == USB_SPEED_LOW;
    315         int toggle =
    316             device_keeper_get_toggle(instance->manager, instance->target);
     313        int toggle = usb_device_keeper_get_toggle(
     314            data->manager, instance->target, instance->direction);
    317315        assert(toggle == 0 || toggle == 1);
    318316
     
    320318        size_t remain_size = instance->buffer_size;
    321319        while (remain_size > 0) {
    322                 char *data =
     320                char *trans_data =
    323321                    instance->transport_buffer + instance->buffer_size
    324322                    - remain_size;
     
    328326                    remain_size : instance->max_packet_size;
    329327
    330                 td_t *next_packet = (packet + 1 < instance->packets)
    331                     ? &instance->tds[packet + 1] : NULL;
    332 
    333                 assert(packet < instance->packets);
     328                td_t *next_packet = (packet + 1 < data->packets)
     329                    ? &data->tds[packet + 1] : NULL;
     330
     331                assert(packet < data->packets);
    334332                assert(packet_size <= remain_size);
    335333
    336334                td_init(
    337                     &instance->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
    338                     toggle, false, low_speed, instance->target, pid, data,
     335                    &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
     336                    toggle, false, low_speed, instance->target, pid, trans_data,
    339337                    next_packet);
    340338
     
    344342                ++packet;
    345343        }
    346         td_set_ioc(&instance->tds[packet - 1]);
    347         device_keeper_set_toggle(instance->manager, instance->target, toggle);
     344        td_set_ioc(&data->tds[packet - 1]);
     345        usb_device_keeper_set_toggle(data->manager, instance->target,
     346            instance->direction, toggle);
    348347}
    349348/*----------------------------------------------------------------------------*/
     
    359358 * The last packet is marked with IOC.
    360359 */
    361 void batch_control(batch_t *instance,
     360void batch_control(usb_transfer_batch_t *instance,
    362361   usb_packet_id data_stage, usb_packet_id status_stage)
    363362{
    364363        assert(instance);
     364        uhci_batch_t *data = instance->private_data;
     365        assert(data);
     366        assert(data->packets >= 2);
    365367
    366368        const bool low_speed = instance->speed == USB_SPEED_LOW;
    367369        int toggle = 0;
    368370        /* setup stage */
    369         td_init(instance->tds, DEFAULT_ERROR_COUNT,
    370             instance->setup_size, toggle, false, low_speed, instance->target,
    371             USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]);
     371        td_init(
     372            data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, toggle, false,
     373            low_speed, instance->target, USB_PID_SETUP, instance->setup_buffer,
     374            &data->tds[1]);
    372375
    373376        /* data stage */
     
    375378        size_t remain_size = instance->buffer_size;
    376379        while (remain_size > 0) {
    377                 char *data =
     380                char *control_data =
    378381                    instance->transport_buffer + instance->buffer_size
    379382                    - remain_size;
     
    386389
    387390                td_init(
    388                     &instance->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
     391                    &data->tds[packet], DEFAULT_ERROR_COUNT, packet_size,
    389392                    toggle, false, low_speed, instance->target, data_stage,
    390                     data, &instance->tds[packet + 1]);
     393                    control_data, &data->tds[packet + 1]);
    391394
    392395                ++packet;
    393                 assert(packet < instance->packets);
     396                assert(packet < data->packets);
    394397                assert(packet_size <= remain_size);
    395398                remain_size -= packet_size;
     
    397400
    398401        /* status stage */
    399         assert(packet == instance->packets - 1);
    400         td_init(&instance->tds[packet], DEFAULT_ERROR_COUNT,
    401             0, 1, false, low_speed, instance->target, status_stage, NULL, NULL);
    402 
    403         td_set_ioc(&instance->tds[packet]);
     402        assert(packet == data->packets - 1);
     403
     404        td_init(
     405            &data->tds[packet], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed,
     406            instance->target, status_stage, NULL, NULL);
     407        td_set_ioc(&data->tds[packet]);
     408
    404409        usb_log_debug2("Control last TD status: %x.\n",
    405             instance->tds[packet].status);
    406 }
    407 /*----------------------------------------------------------------------------*/
    408 /** Prepare data, get error status and call callback in.
    409  *
    410  * @param[in] instance Batch structure to use.
    411  * Copies data from transport buffer, and calls callback with appropriate
    412  * parameters.
    413  */
    414 void batch_call_in(batch_t *instance)
    415 {
    416         assert(instance);
    417         assert(instance->callback_in);
    418 
    419         /* We are data in, we need data */
    420         memcpy(instance->buffer, instance->transport_buffer,
    421             instance->buffer_size);
    422 
    423         int err = instance->error;
    424         usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n",
    425             instance, instance->transfer_type, str_error(err), err,
    426             instance->transfered_size);
    427 
    428         instance->callback_in(
    429             instance->fun, err, instance->transfered_size, instance->arg);
    430 }
    431 /*----------------------------------------------------------------------------*/
    432 /** Get error status and call callback out.
    433  *
    434  * @param[in] instance Batch structure to use.
    435  */
    436 void batch_call_out(batch_t *instance)
    437 {
    438         assert(instance);
    439         assert(instance->callback_out);
    440 
    441         int err = instance->error;
    442         usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n",
    443             instance, instance->transfer_type, str_error(err), err);
    444         instance->callback_out(instance->fun,
    445             err, instance->arg);
     410            data->tds[packet].status);
     411}
     412/*----------------------------------------------------------------------------*/
     413qh_t * batch_qh(usb_transfer_batch_t *instance)
     414{
     415        assert(instance);
     416        uhci_batch_t *data = instance->private_data;
     417        assert(data);
     418        return data->qh;
    446419}
    447420/*----------------------------------------------------------------------------*/
     
    450423 * @param[in] instance Batch structure to use.
    451424 */
    452 void batch_call_in_and_dispose(batch_t *instance)
    453 {
    454         assert(instance);
    455         batch_call_in(instance);
     425void batch_call_in_and_dispose(usb_transfer_batch_t *instance)
     426{
     427        assert(instance);
     428        usb_transfer_batch_call_in(instance);
    456429        batch_dispose(instance);
    457430}
     
    461434 * @param[in] instance Batch structure to use.
    462435 */
    463 void batch_call_out_and_dispose(batch_t *instance)
    464 {
    465         assert(instance);
    466         batch_call_out(instance);
     436void batch_call_out_and_dispose(usb_transfer_batch_t *instance)
     437{
     438        assert(instance);
     439        usb_transfer_batch_call_out(instance);
    467440        batch_dispose(instance);
    468441}
     
    472445 * @param[in] instance Batch structure to use.
    473446 */
    474 void batch_dispose(batch_t *instance)
    475 {
    476         assert(instance);
     447void batch_dispose(usb_transfer_batch_t *instance)
     448{
     449        assert(instance);
     450        uhci_batch_t *data = instance->private_data;
     451        assert(data);
    477452        usb_log_debug("Batch(%p) disposing.\n", instance);
    478453        /* free32 is NULL safe */
    479         free32(instance->tds);
    480         free32(instance->qh);
     454        free32(data->tds);
     455        free32(data->qh);
    481456        free32(instance->setup_buffer);
    482457        free32(instance->transport_buffer);
     458        free(data);
    483459        free(instance);
    484460}
  • uspace/drv/uhci-hcd/batch.h

    r4fb6d9ee re099f26  
    3939#include <usbhc_iface.h>
    4040#include <usb/usb.h>
     41#include <usb/host/device_keeper.h>
     42#include <usb/host/batch.h>
    4143
    42 #include "uhci_struct/transfer_descriptor.h"
    4344#include "uhci_struct/queue_head.h"
    44 #include "utils/device_keeper.h"
    4545
    46 typedef struct batch
    47 {
    48         link_t link;
    49         usb_speed_t speed;
    50         usb_target_t target;
    51         usb_transfer_type_t transfer_type;
    52         usbhc_iface_transfer_in_callback_t callback_in;
    53         usbhc_iface_transfer_out_callback_t callback_out;
    54         void *arg;
    55         char *transport_buffer;
    56         char *setup_buffer;
    57         size_t setup_size;
    58         char *buffer;
    59         size_t buffer_size;
    60         size_t max_packet_size;
    61         size_t packets;
    62         size_t transfered_size;
    63         int error;
    64         ddf_fun_t *fun;
    65         qh_t *qh;
    66         td_t *tds;
    67         void (*next_step)(struct batch*);
    68         device_keeper_t *manager;
    69 } batch_t;
    70 
    71 batch_t * batch_get(
     46usb_transfer_batch_t * batch_get(
    7247    ddf_fun_t *fun,
    7348                usb_target_t target,
     
    8257    usbhc_iface_transfer_out_callback_t func_out,
    8358                void *arg,
    84                 device_keeper_t *manager
     59                usb_device_keeper_t *manager
    8560                );
    8661
    87 void batch_dispose(batch_t *instance);
     62void batch_dispose(usb_transfer_batch_t *instance);
    8863
    89 void batch_abort(batch_t *instance);
     64bool batch_is_complete(usb_transfer_batch_t *instance);
    9065
    91 bool batch_is_complete(batch_t *instance);
     66void batch_control_write(usb_transfer_batch_t *instance);
    9267
    93 void batch_control_write(batch_t *instance);
     68void batch_control_read(usb_transfer_batch_t *instance);
    9469
    95 void batch_control_read(batch_t *instance);
     70void batch_interrupt_in(usb_transfer_batch_t *instance);
    9671
    97 void batch_interrupt_in(batch_t *instance);
     72void batch_interrupt_out(usb_transfer_batch_t *instance);
    9873
    99 void batch_interrupt_out(batch_t *instance);
     74void batch_bulk_in(usb_transfer_batch_t *instance);
    10075
    101 void batch_bulk_in(batch_t *instance);
     76void batch_bulk_out(usb_transfer_batch_t *instance);
    10277
    103 void batch_bulk_out(batch_t *instance);
     78qh_t * batch_qh(usb_transfer_batch_t *instance);
    10479#endif
    10580/**
  • uspace/drv/uhci-hcd/iface.c

    r4fb6d9ee re099f26  
    4141#include "iface.h"
    4242#include "uhci_hc.h"
    43 #include "utils/device_keeper.h"
    4443
    4544/** Reserve default address interface function
     
    5655        assert(hc);
    5756        usb_log_debug("Default address request with speed %d.\n", speed);
    58         device_keeper_reserve_default(&hc->device_manager, speed);
     57        usb_device_keeper_reserve_default_address(&hc->device_manager, speed);
    5958        return EOK;
    6059}
     
    7170        assert(hc);
    7271        usb_log_debug("Default address release.\n");
    73         device_keeper_release_default(&hc->device_manager);
     72        usb_device_keeper_release_default_address(&hc->device_manager);
    7473        return EOK;
    7574}
     
    9190
    9291        usb_log_debug("Address request with speed %d.\n", speed);
    93         *address = device_keeper_request(&hc->device_manager, speed);
     92        *address = device_keeper_get_free_address(&hc->device_manager, speed);
    9493        usb_log_debug("Address request with result: %d.\n", *address);
    9594        if (*address <= 0)
     
    112111        assert(hc);
    113112        usb_log_debug("Address bind %d-%d.\n", address, handle);
    114         device_keeper_bind(&hc->device_manager, address, handle);
     113        usb_device_keeper_bind(&hc->device_manager, address, handle);
    115114        return EOK;
    116115}
     
    128127        assert(hc);
    129128        usb_log_debug("Address release %d.\n", address);
    130         device_keeper_release(&hc->device_manager, address);
     129        usb_device_keeper_release(&hc->device_manager, address);
    131130        return EOK;
    132131}
     
    150149        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    151150        assert(hc);
    152         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     151        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    153152
    154153        usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
    155154            target.address, target.endpoint, size, max_packet_size);
    156155
    157         batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
     156        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    158157            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    159158            &hc->device_manager);
     
    187186        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    188187        assert(hc);
    189         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     188        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    190189        usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
    191190            target.address, target.endpoint, size, max_packet_size);
    192191
    193         batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
     192        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_INTERRUPT,
    194193            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    195194                        &hc->device_manager);
     
    223222        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    224223        assert(hc);
    225         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     224        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    226225
    227226        usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
    228227            target.address, target.endpoint, size, max_packet_size);
    229228
    230         batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
     229        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    231230            max_packet_size, speed, data, size, NULL, 0, NULL, callback, arg,
    232231            &hc->device_manager);
     
    260259        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    261260        assert(hc);
    262         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     261        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    263262        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
    264263            target.address, target.endpoint, size, max_packet_size);
    265264
    266         batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
     265        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_BULK,
    267266            max_packet_size, speed, data, size, NULL, 0, callback, NULL, arg,
    268267            &hc->device_manager);
     
    299298        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    300299        assert(hc);
    301         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     300        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    302301        usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n",
    303302            speed, target.address, target.endpoint, size, max_packet_size);
     
    306305                return EINVAL;
    307306
    308         batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
     307        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    309308            max_packet_size, speed, data, size, setup_data, setup_size,
    310309            NULL, callback, arg, &hc->device_manager);
    311310        if (!batch)
    312311                return ENOMEM;
    313         device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
     312        usb_device_keeper_reset_if_need(&hc->device_manager, target, setup_data);
    314313        batch_control_write(batch);
    315314        const int ret = uhci_hc_schedule(hc, batch);
     
    342341        uhci_hc_t *hc = fun_to_uhci_hc(fun);
    343342        assert(hc);
    344         usb_speed_t speed = device_keeper_speed(&hc->device_manager, target.address);
     343        usb_speed_t speed = usb_device_keeper_get_speed(&hc->device_manager, target.address);
    345344
    346345        usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n",
    347346            speed, target.address, target.endpoint, size, max_packet_size);
    348         batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
     347        usb_transfer_batch_t *batch = batch_get(fun, target, USB_TRANSFER_CONTROL,
    349348            max_packet_size, speed, data, size, setup_data, setup_size, callback,
    350349            NULL, arg, &hc->device_manager);
  • uspace/drv/uhci-hcd/main.c

    r4fb6d9ee re099f26  
    6262int uhci_add_device(ddf_dev_t *device)
    6363{
    64         usb_log_info("uhci_add_device() called\n");
     64        usb_log_debug("uhci_add_device() called\n");
    6565        assert(device);
    6666        uhci_t *uhci = malloc(sizeof(uhci_t));
     
    7272        int ret = uhci_init(uhci, device);
    7373        if (ret != EOK) {
    74                 usb_log_error("Failed to initialzie UHCI driver.\n");
     74                usb_log_error("Failed to initialize UHCI driver: %s.\n",
     75                    str_error(ret));
    7576                return ret;
    7677        }
    7778        device->driver_data = uhci;
     79
     80        usb_log_info("Controlling new UHCI device `%s'.\n", device->name);
     81
    7882        return EOK;
    7983}
     
    8993int main(int argc, char *argv[])
    9094{
     95        printf(NAME ": HelenOS UHCI driver.\n");
     96
    9197        sleep(3); /* TODO: remove in final version */
    92         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     98        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    9399
    94100        return ddf_driver_main(&uhci_driver);
  • uspace/drv/uhci-hcd/transfer_list.c

    r4fb6d9ee re099f26  
    3838
    3939static void transfer_list_remove_batch(
    40     transfer_list_t *instance, batch_t *batch);
     40    transfer_list_t *instance, usb_transfer_batch_t *batch);
    4141/*----------------------------------------------------------------------------*/
    4242/** Initialize transfer list structures.
     
    9191 * The batch is added to the end of the list and queue.
    9292 */
    93 void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch)
     93void transfer_list_add_batch(transfer_list_t *instance, usb_transfer_batch_t *batch)
    9494{
    9595        assert(instance);
    9696        assert(batch);
    9797        usb_log_debug2("Queue %s: Adding batch(%p).\n", instance->name, batch);
    98 
    9998
    10099        fibril_mutex_lock(&instance->guard);
     
    107106        } else {
    108107                /* There is something scheduled */
    109                 batch_t *last = list_get_instance(
    110                     instance->batch_list.prev, batch_t, link);
    111                 last_qh = last->qh;
     108                usb_transfer_batch_t *last = list_get_instance(
     109                    instance->batch_list.prev, usb_transfer_batch_t, link);
     110                last_qh = batch_qh(last);
    112111        }
    113112        const uint32_t pa = addr_to_phys(batch->qh);
    114113        assert((pa & LINK_POINTER_ADDRESS_MASK) == pa);
    115114
    116         batch->qh->next = last_qh->next;
     115        /* keep link */
     116        batch_qh(batch)->next = last_qh->next;
    117117        qh_set_next_qh(last_qh, pa);
    118118
     
    120120        list_append(&batch->link, &instance->batch_list);
    121121
    122         batch_t *first = list_get_instance(
    123             instance->batch_list.next, batch_t, link);
     122        usb_transfer_batch_t *first = list_get_instance(
     123            instance->batch_list.next, usb_transfer_batch_t, link);
    124124        usb_log_debug("Batch(%p) added to queue %s, first is %p.\n",
    125125                batch, instance->name, first);
     
    146146        while (current != &instance->batch_list) {
    147147                link_t *next = current->next;
    148                 batch_t *batch = list_get_instance(current, batch_t, link);
     148                usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link);
    149149
    150150                if (batch_is_complete(batch)) {
     
    160160                link_t *item = done.next;
    161161                list_remove(item);
    162                 batch_t *batch = list_get_instance(item, batch_t, link);
     162                usb_transfer_batch_t *batch = list_get_instance(item, usb_transfer_batch_t, link);
    163163                batch->next_step(batch);
    164164        }
     
    174174        while (!list_empty(&instance->batch_list)) {
    175175                link_t *current = instance->batch_list.next;
    176                 batch_t *batch = list_get_instance(current, batch_t, link);
     176                usb_transfer_batch_t *batch = list_get_instance(current, usb_transfer_batch_t, link);
    177177                transfer_list_remove_batch(instance, batch);
    178                 batch_abort(batch);
     178                usb_transfer_batch_finish(batch, EIO);
    179179        }
    180180        fibril_mutex_unlock(&instance->guard);
     
    189189 * Does not lock the transfer list, caller is responsible for that.
    190190 */
    191 void transfer_list_remove_batch(transfer_list_t *instance, batch_t *batch)
    192 {
    193         assert(instance);
     191void transfer_list_remove_batch(transfer_list_t *instance, usb_transfer_batch_t *batch)
     192{
     193        assert(instance);
     194        assert(instance->queue_head);
    194195        assert(batch);
    195         assert(instance->queue_head);
    196         assert(batch->qh);
     196        assert(batch_qh(batch));
    197197        assert(fibril_mutex_is_locked(&instance->guard));
    198198
     
    205205                /* I'm the first one here */
    206206                assert((instance->queue_head->next & LINK_POINTER_ADDRESS_MASK)
    207                     == addr_to_phys(batch->qh));
    208                 instance->queue_head->next = batch->qh->next;
     207                    == addr_to_phys(bathc_qh(batch)));
     208                instance->queue_head->next = batch_qh(batch)->next;
    209209                qpos = "FIRST";
    210210        } else {
    211                 batch_t *prev =
    212                     list_get_instance(batch->link.prev, batch_t, link);
    213                 assert((prev->qh->next & LINK_POINTER_ADDRESS_MASK)
    214                     == addr_to_phys(batch->qh));
    215                 prev->qh->next = batch->qh->next;
     211                usb_transfer_batch_t *prev =
     212                    list_get_instance(batch->link.prev, usb_transfer_batch_t, link);
     213                assert((batch_qh(prev)->next & LINK_POINTER_ADDRESS_MASK)
     214                    == addr_to_phys(batch_qh(batch)));
     215                batch_qh(prev)->next = batch_qh(batch)->next;
    216216                qpos = "NOT FIRST";
    217217        }
     
    219219        list_remove(&batch->link);
    220220        usb_log_debug("Batch(%p) removed (%s) from %s, next %x.\n",
    221             batch, qpos, instance->name, batch->qh->next);
     221            batch, pos, instance->name, batch_qh(batch)->next);
    222222}
    223223/**
  • uspace/drv/uhci-hcd/transfer_list.h

    r4fb6d9ee re099f26  
    6666void transfer_list_set_next(transfer_list_t *instance, transfer_list_t *next);
    6767
    68 void transfer_list_add_batch(transfer_list_t *instance, batch_t *batch);
     68void transfer_list_add_batch(transfer_list_t *instance, usb_transfer_batch_t *batch);
    6969
    7070void transfer_list_remove_finished(transfer_list_t *instance);
  • uspace/drv/uhci-hcd/uhci.c

    r4fb6d9ee re099f26  
    7070{
    7171        assert(fun);
    72         device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.device_manager;
    73 
    74         usb_address_t addr = device_keeper_find(manager, handle);
     72        usb_device_keeper_t *manager = &((uhci_t*)fun->dev->driver_data)->hc.device_manager;
     73
     74        usb_address_t addr = usb_device_keeper_find(manager, handle);
    7575        if (addr < 0) {
    7676                return addr;
     
    167167        CHECK_RET_DEST_FUN_RETURN(ret,
    168168            "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
    169         usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
     169        usb_log_debug("I/O regs at 0x%X (size %zu), IRQ %d.\n",
    170170            io_reg_base, io_reg_size, irq);
    171171
  • uspace/drv/uhci-hcd/uhci_hc.c

    r4fb6d9ee re099f26  
    121121                    fibril_create(uhci_hc_interrupt_emulator, instance);
    122122                fibril_add_ready(instance->cleaner);
     123        } else {
     124                /* TODO: enable interrupts here */
    123125        }
    124126
     
    127129//      fibril_add_ready(instance->debug_checker);
    128130
    129         usb_log_info("Started UHCI driver.\n");
    130131        return EOK;
    131132#undef CHECK_RET_DEST_FUN_RETURN
     
    235236
    236237        /* Init device keeper*/
    237         device_keeper_init(&instance->device_manager);
     238        usb_device_keeper_init(&instance->device_manager);
    238239        usb_log_debug("Initialized device manager.\n");
    239240
     
    317318 * Checks for bandwidth availability and appends the batch to the proper queue.
    318319 */
    319 int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch)
     320int uhci_hc_schedule(uhci_hc_t *instance, usb_transfer_batch_t *batch)
    320321{
    321322        assert(instance);
  • uspace/drv/uhci-hcd/uhci_hc.h

    r4fb6d9ee re099f26  
    4242
    4343#include <usbhc_iface.h>
     44#include <usb/host/device_keeper.h>
    4445
    4546#include "batch.h"
    4647#include "transfer_list.h"
    47 #include "utils/device_keeper.h"
    4848
    4949typedef struct uhci_regs {
     
    8383
    8484typedef struct uhci_hc {
    85         device_keeper_t device_manager;
     85        usb_device_keeper_t device_manager;
    8686
    8787        regs_t *registers;
     
    109109    void *regs, size_t reg_size, bool interupts);
    110110
    111 int uhci_hc_schedule(uhci_hc_t *instance, batch_t *batch);
     111int uhci_hc_schedule(uhci_hc_t *instance, usb_transfer_batch_t *batch);
    112112
    113113void uhci_hc_interrupt(uhci_hc_t *instance, uint16_t status);
  • uspace/drv/uhci-rhd/main.c

    r4fb6d9ee re099f26  
    3636#include <device/hw_res.h>
    3737#include <errno.h>
     38#include <str_error.h>
    3839#include <usb_iface.h>
    3940#include <usb/ddfiface.h>
     
    8687        int ret = hc_get_my_registers(device, &io_regs, &io_size);
    8788        if (ret != EOK) {
    88                 usb_log_error("Failed(%d) to get registers from parent hc.",
    89                     ret);
    90         }
    91         usb_log_info("I/O regs at %#X (size %zu).\n", io_regs, io_size);
     89                usb_log_error("Failed to get registers from parent HC: %s.\n",
     90                    str_error(ret));
     91        }
     92        usb_log_debug("I/O regs at %#X (size %zu).\n", io_regs, io_size);
    9293
    9394        uhci_root_hub_t *rh = malloc(sizeof(uhci_root_hub_t));
     
    99100        ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
    100101        if (ret != EOK) {
    101                 usb_log_error("Failed(%d) to initialize driver instance.\n", ret);
     102                usb_log_error("Failed to initialize driver instance: %s.\n",
     103                    str_error(ret));
    102104                free(rh);
    103105                return ret;
     
    105107
    106108        device->driver_data = rh;
    107         usb_log_info("Sucessfully initialized driver instance for device:%d.\n",
    108             device->handle);
     109        usb_log_info("Controlling root hub `%s' (%llu).\n",
     110            device->name, device->handle);
    109111        return EOK;
    110112}
     
    129131int main(int argc, char *argv[])
    130132{
    131         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     133        printf(NAME ": HelenOS UHCI root hub driver.\n");
     134
     135        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
     136
    132137        return ddf_driver_main(&uhci_rh_driver);
    133138}
  • uspace/drv/uhci-rhd/port.c

    r4fb6d9ee re099f26  
    256256        assert(usb_hc_connection_is_opened(&port->hc_connection));
    257257
    258         usb_log_info("%s: Detected new device.\n", port->id_string);
     258        usb_log_debug("%s: Detected new device.\n", port->id_string);
    259259
    260260        usb_address_t dev_addr;
     
    270270        }
    271271
    272         usb_log_info("%s: New device has address %d (handle %zu).\n",
    273             port->id_string, dev_addr, port->attached_device);
     272        usb_log_info("New device at port %u, address %d (handle %llu).\n",
     273            port->number, dev_addr, port->attached_device);
    274274
    275275        return EOK;
     
    315315        uhci_port_write_status(port, port_status);
    316316
    317         usb_log_info("%s: %sabled port.\n",
     317        usb_log_debug("%s: %sabled port.\n",
    318318                port->id_string, enabled ? "En" : "Dis");
    319319        return EOK;
  • uspace/drv/usbhid/hiddev.c

    r4fb6d9ee re099f26  
    184184 *                     successfuly initialize the structure.
    185185 *
    186  * @sa usb_endpoint_pipe_initialize_from_configuration(),
     186 * @sa usb_pipe_initialize_from_configuration(),
    187187 *     usbhid_dev_get_report_descriptor()
    188188 */
     
    192192        assert(hid_dev != NULL);
    193193       
    194         usb_log_info("Processing descriptors...\n");
     194        usb_log_debug("Processing descriptors...\n");
    195195       
    196196        int rc;
     
    218218        };
    219219       
    220         rc = usb_endpoint_pipe_initialize_from_configuration(
     220        rc = usb_pipe_initialize_from_configuration(
    221221            endpoint_mapping, 1, descriptors, descriptors_size,
    222222            &hid_dev->wire);
     
    359359 * @return Other value inherited from one of functions
    360360 *         usb_device_connection_initialize_from_device(),
    361  *         usb_endpoint_pipe_initialize_default_control(),
    362  *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     361 *         usb_pipe_initialize_default_control(),
     362 *         usb_pipe_start_session(), usb_pipe_end_session(),
    363363 *         usbhid_dev_process_descriptors().
    364364 *
     
    368368    usb_endpoint_description_t *poll_ep_desc)
    369369{
    370         usb_log_info("Initializing HID device structure.\n");
     370        usb_log_debug("Initializing HID device structure.\n");
    371371       
    372372        if (hid_dev == NULL) {
     
    404404         * Initialize device pipes.
    405405         */
    406         rc = usb_endpoint_pipe_initialize_default_control(&hid_dev->ctrl_pipe,
     406        rc = usb_pipe_initialize_default_control(&hid_dev->ctrl_pipe,
    407407            &hid_dev->wire);
    408408        if (rc != EOK) {
     
    411411                return rc;
    412412        }
    413         rc = usb_endpoint_pipe_probe_default_control(&hid_dev->ctrl_pipe);
     413        rc = usb_pipe_probe_default_control(&hid_dev->ctrl_pipe);
    414414        if (rc != EOK) {
    415415                usb_log_error("Probing default control pipe failed: %s.\n",
     
    430430         * Get descriptors, parse descriptors and save endpoints.
    431431         */
    432         rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     432        rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
    433433        if (rc != EOK) {
    434434                usb_log_error("Failed to start session on the control pipe: %s"
     
    440440        if (rc != EOK) {
    441441                /* TODO: end session?? */
    442                 usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     442                usb_pipe_end_session(&hid_dev->ctrl_pipe);
    443443                usb_log_error("Failed to process descriptors: %s.\n",
    444444                    str_error(rc));
     
    446446        }
    447447       
    448         rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     448        rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
    449449        if (rc != EOK) {
    450450                usb_log_warning("Failed to start session on the control pipe: "
     
    454454       
    455455        hid_dev->initialized = 1;
    456         usb_log_info("HID device structure initialized.\n");
     456        usb_log_debug("HID device structure initialized.\n");
    457457       
    458458        return EOK;
  • uspace/drv/usbhid/hiddev.h

    r4fb6d9ee re099f26  
    6868        usb_device_connection_t wire;
    6969        /** USB pipe corresponding to the default Control endpoint. */
    70         usb_endpoint_pipe_t ctrl_pipe;
     70        usb_pipe_t ctrl_pipe;
    7171        /** USB pipe corresponding to the Interrupt In (polling) pipe. */
    72         usb_endpoint_pipe_t poll_pipe;
     72        usb_pipe_t poll_pipe;
    7373       
    7474        /** Polling interval retreived from the Interface descriptor. */
  • uspace/drv/usbhid/hidreq.c

    r4fb6d9ee re099f26  
    5757 * @retval EINVAL if no HID device is given.
    5858 * @return Other value inherited from one of functions
    59  *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     59 *         usb_pipe_start_session(), usb_pipe_end_session(),
    6060 *         usb_control_request_set().
    6161 */
     
    7676        int rc, sess_rc;
    7777       
    78         sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     78        sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
    7979        if (sess_rc != EOK) {
    8080                usb_log_warning("Failed to start a session: %s.\n",
     
    9292            USB_HIDREQ_SET_REPORT, value, hid_dev->iface, buffer, buf_size);
    9393
    94         sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     94        sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
    9595
    9696        if (rc != EOK) {
     
    119119 * @retval EINVAL if no HID device is given.
    120120 * @return Other value inherited from one of functions
    121  *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     121 *         usb_pipe_start_session(), usb_pipe_end_session(),
    122122 *         usb_control_request_set().
    123123 */
     
    137137        int rc, sess_rc;
    138138       
    139         sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     139        sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
    140140        if (sess_rc != EOK) {
    141141                usb_log_warning("Failed to start a session: %s.\n",
     
    151151            USB_HIDREQ_SET_PROTOCOL, protocol, hid_dev->iface, NULL, 0);
    152152
    153         sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     153        sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
    154154
    155155        if (rc != EOK) {
     
    179179 * @retval EINVAL if no HID device is given.
    180180 * @return Other value inherited from one of functions
    181  *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     181 *         usb_pipe_start_session(), usb_pipe_end_session(),
    182182 *         usb_control_request_set().
    183183 */
     
    197197        int rc, sess_rc;
    198198       
    199         sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     199        sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
    200200        if (sess_rc != EOK) {
    201201                usb_log_warning("Failed to start a session: %s.\n",
     
    213213            USB_HIDREQ_SET_IDLE, value, hid_dev->iface, NULL, 0);
    214214
    215         sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     215        sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
    216216
    217217        if (rc != EOK) {
     
    244244 * @retval EINVAL if no HID device is given.
    245245 * @return Other value inherited from one of functions
    246  *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     246 *         usb_pipe_start_session(), usb_pipe_end_session(),
    247247 *         usb_control_request_set().
    248248 */
     
    263263        int rc, sess_rc;
    264264       
    265         sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     265        sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
    266266        if (sess_rc != EOK) {
    267267                usb_log_warning("Failed to start a session: %s.\n",
     
    280280            actual_size);
    281281
    282         sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     282        sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
    283283
    284284        if (rc != EOK) {
     
    307307 * @retval EINVAL if no HID device is given.
    308308 * @return Other value inherited from one of functions
    309  *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     309 *         usb_pipe_start_session(), usb_pipe_end_session(),
    310310 *         usb_control_request_set().
    311311 */
     
    325325        int rc, sess_rc;
    326326       
    327         sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     327        sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
    328328        if (sess_rc != EOK) {
    329329                usb_log_warning("Failed to start a session: %s.\n",
     
    342342            USB_HIDREQ_GET_PROTOCOL, 0, hid_dev->iface, buffer, 1, &actual_size);
    343343
    344         sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     344        sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
    345345
    346346        if (rc != EOK) {
     
    378378 * @retval EINVAL if no HID device is given.
    379379 * @return Other value inherited from one of functions
    380  *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     380 *         usb_pipe_start_session(), usb_pipe_end_session(),
    381381 *         usb_control_request_set().
    382382 */
     
    396396        int rc, sess_rc;
    397397       
    398         sess_rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     398        sess_rc = usb_pipe_start_session(&hid_dev->ctrl_pipe);
    399399        if (sess_rc != EOK) {
    400400                usb_log_warning("Failed to start a session: %s.\n",
     
    415415            &actual_size);
    416416
    417         sess_rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     417        sess_rc = usb_pipe_end_session(&hid_dev->ctrl_pipe);
    418418
    419419        if (rc != EOK) {
  • uspace/drv/usbhid/kbddev.c

    r4fb6d9ee re099f26  
    662662        int rc;
    663663       
    664         usb_log_info("Initializing HID/KBD structure...\n");
     664        usb_log_debug("Initializing HID/KBD structure...\n");
    665665       
    666666        if (kbd_dev == NULL) {
     
    742742       
    743743        kbd_dev->initialized = USBHID_KBD_STATUS_INITIALIZED;
    744         usb_log_info("HID/KBD device structure initialized.\n");
     744        usb_log_debug("HID/KBD device structure initialized.\n");
    745745       
    746746        return EOK;
     
    769769        size_t actual_size;
    770770       
    771         usb_log_info("Polling keyboard...\n");
     771        usb_log_debug("Polling keyboard...\n");
    772772       
    773773        if (!kbd_dev->initialized) {
     
    780780
    781781        while (true) {
    782                 sess_rc = usb_endpoint_pipe_start_session(
     782                sess_rc = usb_pipe_start_session(
    783783                    &kbd_dev->hid_dev->poll_pipe);
    784784                if (sess_rc != EOK) {
     
    788788                }
    789789
    790                 rc = usb_endpoint_pipe_read(&kbd_dev->hid_dev->poll_pipe,
     790                rc = usb_pipe_read(&kbd_dev->hid_dev->poll_pipe,
    791791                    buffer, BOOTP_BUFFER_SIZE, &actual_size);
    792792               
    793                 sess_rc = usb_endpoint_pipe_end_session(
     793                sess_rc = usb_pipe_end_session(
    794794                    &kbd_dev->hid_dev->poll_pipe);
    795795
     
    907907         * Initialize device (get and process descriptors, get address, etc.)
    908908         */
    909         usb_log_info("Initializing USB/HID KBD device...\n");
     909        usb_log_debug("Initializing USB/HID KBD device...\n");
    910910       
    911911        usbhid_kbd_t *kbd_dev = usbhid_kbd_new();
     
    926926        }       
    927927       
    928         usb_log_info("USB/HID KBD device structure initialized.\n");
     928        usb_log_debug("USB/HID KBD device structure initialized.\n");
    929929       
    930930        /*
     
    937937        rc = ddf_fun_bind(kbd_fun);
    938938        if (rc != EOK) {
    939                 usb_log_error("Could not bind DDF function.\n");
     939                usb_log_error("Could not bind DDF function: %s.\n",
     940                    str_error(rc));
    940941                // TODO: Can / should I destroy the DDF function?
    941942                ddf_fun_destroy(kbd_fun);
     
    946947        rc = ddf_fun_add_to_class(kbd_fun, "keyboard");
    947948        if (rc != EOK) {
    948                 usb_log_error("Could not add DDF function to class 'keyboard'"
    949                     "\n");
     949                usb_log_error(
     950                    "Could not add DDF function to class 'keyboard': %s.\n",
     951                    str_error(rc));
    950952                // TODO: Can / should I destroy the DDF function?
    951953                ddf_fun_destroy(kbd_fun);
     
    959961        fid_t fid = fibril_create(usbhid_kbd_fibril, kbd_dev);
    960962        if (fid == 0) {
    961                 usb_log_error("Failed to start fibril for KBD device\n");
     963                usb_log_error("Failed to start fibril for `%s' device.\n",
     964                    dev->name);
    962965                return ENOMEM;
    963966        }
  • uspace/drv/usbhid/main.c

    r4fb6d9ee re099f26  
    3939#include <usb/debug.h>
    4040#include <errno.h>
     41#include <str_error.h>
    4142
    4243#include "kbddev.h"
     
    6465       
    6566        if (rc != EOK) {
    66                 usb_log_info("Device is not a supported keyboard.\n");
    67                 usb_log_error("Failed to add HID device.\n");
    68                 return EREFUSED;
     67                usb_log_warning("Device is not a supported keyboard.\n");
     68                usb_log_error("Failed to add HID device: %s.\n",
     69                    str_error(rc));
     70                return rc;
    6971        }
    7072       
     73        usb_log_info("Keyboard `%s' ready to use.\n", dev->name);
     74
    7175        return EOK;
    7276}
     
    8993int main(int argc, char *argv[])
    9094{
    91         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     95        printf(NAME ": HelenOS USB HID driver.\n");
     96
     97        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
     98
    9299        return ddf_driver_main(&kbd_driver);
    93100}
  • uspace/drv/usbhub/main.c

    r4fb6d9ee re099f26  
    3636#include <stdio.h>
    3737
     38#include <usb/devdrv.h>
     39#include <usb/classes/classes.h>
     40
    3841#include "usbhub.h"
    3942#include "usbhub_private.h"
    4043
    41 
    42 usb_general_list_t usb_hub_list;
    43 fibril_mutex_t usb_hub_list_lock;
    44 
    45 static driver_ops_t hub_driver_ops = {
    46         .add_device = usb_add_hub_device,
     44/** Hub status-change endpoint description.
     45 *
     46 * For more information see section 11.15.1 of USB 1.1 specification.
     47 */
     48static usb_endpoint_description_t hub_status_change_endpoint_description = {
     49        .transfer_type = USB_TRANSFER_INTERRUPT,
     50        .direction = USB_DIRECTION_IN,
     51        .interface_class = USB_CLASS_HUB,
     52        .interface_subclass = 0,
     53        .interface_protocol = 0,
     54        .flags = 0
    4755};
    4856
    49 static driver_t hub_driver = {
    50         .name = "usbhub",
    51         .driver_ops = &hub_driver_ops
     57
     58static usb_driver_ops_t usb_hub_driver_ops = {
     59        .add_device = usb_hub_add_device
    5260};
     61
     62static usb_endpoint_description_t *usb_hub_endpoints[] = {
     63        &hub_status_change_endpoint_description,
     64        NULL
     65};
     66
     67static usb_driver_t usb_hub_driver = {
     68        .name = NAME,
     69        .ops = &usb_hub_driver_ops,
     70        .endpoints = usb_hub_endpoints
     71};
     72
    5373
    5474int main(int argc, char *argv[])
    5575{
    56         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
    57         dprintf(USB_LOG_LEVEL_INFO, "starting hub driver");
     76        printf(NAME ": HelenOS USB hub driver.\n");
    5877
    59         //this is probably not needed anymore
    60         fibril_mutex_initialize(&usb_hub_list_lock);
    61         fibril_mutex_lock(&usb_hub_list_lock);
    62         usb_lst_init(&usb_hub_list);
    63         fibril_mutex_unlock(&usb_hub_list_lock);
     78        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    6479       
    65         return ddf_driver_main(&hub_driver);
     80        return usb_driver_main(&usb_hub_driver);
    6681}
    6782
  • uspace/drv/usbhub/usbhub.c

    r4fb6d9ee re099f26  
    5353#include "usb/classes/classes.h"
    5454
    55 static ddf_dev_ops_t hub_device_ops = {
    56         .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
    57 };
    58 
    59 /** Hub status-change endpoint description
    60  *
    61  * For more see usb hub specification in 11.15.1 of
    62  */
    63 static usb_endpoint_description_t status_change_endpoint_description = {
    64         .transfer_type = USB_TRANSFER_INTERRUPT,
    65         .direction = USB_DIRECTION_IN,
    66         .interface_class = USB_CLASS_HUB,
    67         .interface_subclass = 0,
    68         .interface_protocol = 0,
    69         .flags = 0
    70 };
    71 
    7255int usb_hub_control_loop(void * hub_info_param){
    7356        usb_hub_info_t * hub_info = (usb_hub_info_t*)hub_info_param;
     
    7861                async_usleep(1000 * 1000 );/// \TODO proper number once
    7962        }
    80         usb_log_error("something in ctrl loop went wrong, errno %d",errorCode);
     63        usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode);
    8164
    8265        return 0;
     
    9174
    9275/**
    93  * Initialize connnections to host controller, device, and device
    94  * control endpoint
    95  * @param hub
    96  * @param device
    97  * @return
    98  */
    99 static int usb_hub_init_communication(usb_hub_info_t * hub){
    100         usb_log_debug("Initializing hub USB communication (hub->device->handle=%zu).\n", hub->device->handle);
    101         int opResult;
    102         opResult = usb_device_connection_initialize_from_device(
    103                         &hub->device_connection,
    104                         hub->device);
    105         if(opResult != EOK){
    106                 usb_log_error("could not initialize connection to hc, errno %d",opResult);
    107                 return opResult;
    108         }
    109         usb_log_debug("Initializing USB wire abstraction.\n");
    110         opResult = usb_hc_connection_initialize_from_device(&hub->connection,
    111                         hub->device);
    112         if(opResult != EOK){
    113                 usb_log_error("could not initialize connection to device, errno %d",
    114                                 opResult);
    115                 return opResult;
    116         }
    117         usb_log_debug("Initializing default control pipe.\n");
    118         opResult = usb_endpoint_pipe_initialize_default_control(&hub->endpoints.control,
    119             &hub->device_connection);
    120         if(opResult != EOK){
    121                 usb_log_error("could not initialize connection to device endpoint, errno %d",
    122                                 opResult);
    123                 return opResult;
    124         }
    125 
    126         opResult = usb_endpoint_pipe_probe_default_control(&hub->endpoints.control);
    127         if (opResult != EOK) {
    128                 usb_log_error("failed probing endpoint 0, %d", opResult);
    129                 return opResult;
    130         }
    131 
    132         return EOK;
    133 }
    134 
    135 /**
    136  * When entering this function, hub->endpoints.control should be active.
    137  * @param hub
    138  * @return
    139  */
    140 static int usb_hub_process_configuration_descriptors(
    141         usb_hub_info_t * hub){
    142         if(hub==NULL) {
    143                 return EINVAL;
    144         }
    145         int opResult;
    146        
    147         //device descriptor
    148         usb_standard_device_descriptor_t std_descriptor;
    149         opResult = usb_request_get_device_descriptor(&hub->endpoints.control,
    150             &std_descriptor);
    151         if(opResult!=EOK){
    152                 usb_log_error("could not get device descriptor, %d",opResult);
    153                 return opResult;
    154         }
    155         usb_log_info("hub has %d configurations",
    156                         std_descriptor.configuration_count);
    157         if(std_descriptor.configuration_count<1){
    158                 usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE");
    159                 //shouldn`t I return?
    160         }
    161 
    162         /* Retrieve full configuration descriptor. */
    163         uint8_t *descriptors = NULL;
    164         size_t descriptors_size = 0;
    165         opResult = usb_request_get_full_configuration_descriptor_alloc(
    166             &hub->endpoints.control, 0,
    167             (void **) &descriptors, &descriptors_size);
    168         if (opResult != EOK) {
    169                 usb_log_error("Could not get configuration descriptor: %s.\n",
    170                     str_error(opResult));
    171                 return opResult;
    172         }
    173         usb_standard_configuration_descriptor_t *config_descriptor
    174             = (usb_standard_configuration_descriptor_t *) descriptors;
    175 
    176         /* Set configuration. */
    177         opResult = usb_request_set_configuration(&hub->endpoints.control,
    178             config_descriptor->configuration_number);
    179 
    180         if (opResult != EOK) {
    181                 usb_log_error("Failed to set hub configuration: %s.\n",
    182                     str_error(opResult));
    183                 return opResult;
    184         }
    185         usb_log_debug("\tused configuration %d",
    186                         config_descriptor->configuration_number);
    187 
    188         usb_endpoint_mapping_t endpoint_mapping[1] = {
    189                 {
    190                         .pipe = &hub->endpoints.status_change,
    191                         .description = &status_change_endpoint_description,
    192                         .interface_no =
    193                             usb_device_get_assigned_interface(hub->device)
    194                 }
    195         };
    196         opResult = usb_endpoint_pipe_initialize_from_configuration(
    197             endpoint_mapping, 1,
    198             descriptors, descriptors_size,
    199             &hub->device_connection);
    200         if (opResult != EOK) {
    201                 usb_log_error("Failed to initialize status change pipe: %s",
    202                     str_error(opResult));
    203                 return opResult;
    204         }
    205         if (!endpoint_mapping[0].present) {
    206                 usb_log_error("Not accepting device, " \
    207                     "cannot understand what is happenning");
    208                 return EREFUSED;
    209         }
    210 
    211         free(descriptors);
    212         return EOK;
    213        
    214 }
    215 
    216 
    217 /**
    218  * Create hub representation from device information.
    219  * @param device
    220  * @return pointer to created structure or NULL in case of error
    221  */
    222 usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device) {
    223         usb_hub_info_t* result = usb_new(usb_hub_info_t);
    224         result->device = device;
    225         int opResult;
    226         opResult = usb_hub_init_communication(result);
    227         if(opResult != EOK){
    228                 free(result);
    229                 return NULL;
    230         }
    231 
    232         //result->device = device;
    233         result->port_count = -1;
    234         result->device = device;
     76 * create usb_hub_info_t structure
     77 *
     78 * Does only basic copying of known information into new structure.
     79 * @param usb_dev usb device structure
     80 * @return basic usb_hub_info_t structure
     81 */
     82static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) {
     83        usb_hub_info_t * result = usb_new(usb_hub_info_t);
     84        if(!result) return NULL;
     85        result->usb_device = usb_dev;
     86        result->status_change_pipe = usb_dev->pipes[0].pipe;
     87        result->control_pipe = &usb_dev->ctrl_pipe;
    23588        result->is_default_address_used = false;
    236 
    237         //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
    238         size_t received_size;
    239 
     89        return result;
     90}
     91
     92/**
     93 * Load hub-specific information into hub_info structure.
     94 *
     95 * Particularly read port count and initialize structure holding port
     96 * information.
     97 * This function is hub-specific and should be run only after the hub is
     98 * configured using usb_hub_set_configuration function.
     99 * @param hub_info pointer to structure with usb hub data
     100 * @return error code
     101 */
     102static int usb_hub_get_hub_specific_info(usb_hub_info_t * hub_info){
    240103        // get hub descriptor
    241         usb_log_debug("creating serialized descripton");
     104        usb_log_debug("creating serialized descriptor\n");
    242105        void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
    243106        usb_hub_descriptor_t * descriptor;
    244         usb_log_debug("starting control transaction");
    245         usb_endpoint_pipe_start_session(&result->endpoints.control);
    246         opResult = usb_request_set_configuration(&result->endpoints.control, 1);
    247         assert(opResult == EOK);
    248 
    249         opResult = usb_request_get_descriptor(&result->endpoints.control,
     107
     108        /* this was one fix of some bug, should not be needed anymore
     109        int opResult = usb_request_set_configuration(&result->endpoints.control, 1);
     110        if(opResult!=EOK){
     111                usb_log_error("could not set default configuration, errno %d",opResult);
     112                return opResult;
     113        }
     114         */
     115        size_t received_size;
     116        int opResult = usb_request_get_descriptor(&hub_info->usb_device->ctrl_pipe,
    250117                        USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE,
    251118                        USB_DESCTYPE_HUB,
    252119                        0, 0, serialized_descriptor,
    253120                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
    254         usb_endpoint_pipe_end_session(&result->endpoints.control);
    255 
    256         if (opResult != EOK) {
    257                 usb_log_error("failed when receiving hub descriptor, badcode = %d",
     121
     122        if (opResult != EOK) {
     123                usb_log_error("failed when receiving hub descriptor, badcode = %d\n",
    258124                                opResult);
    259125                free(serialized_descriptor);
    260                 free(result);
    261                 return NULL;
    262         }
    263         usb_log_debug2("deserializing descriptor");
     126                return opResult;
     127        }
     128        usb_log_debug2("deserializing descriptor\n");
    264129        descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
    265130        if(descriptor==NULL){
    266                 usb_log_warning("could not deserialize descriptor ");
    267                 free(result);
    268                 return NULL;
    269         }
    270 
    271         usb_log_info("setting port count to %d",descriptor->ports_count);
    272         result->port_count = descriptor->ports_count;
    273         result->attached_devs = (usb_hc_attached_device_t*)
    274             malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t));
     131                usb_log_warning("could not deserialize descriptor \n");
     132                return opResult;
     133        }
     134        usb_log_debug("setting port count to %d\n",descriptor->ports_count);
     135        hub_info->port_count = descriptor->ports_count;
     136        hub_info->attached_devs = (usb_hc_attached_device_t*)
     137            malloc((hub_info->port_count+1) * sizeof(usb_hc_attached_device_t));
    275138        int i;
    276         for(i=0;i<result->port_count+1;++i){
    277                 result->attached_devs[i].handle=0;
    278                 result->attached_devs[i].address=0;
    279         }
    280         usb_log_debug2("freeing data");
     139        for(i=0;i<hub_info->port_count+1;++i){
     140                hub_info->attached_devs[i].handle=0;
     141                hub_info->attached_devs[i].address=0;
     142        }
     143        usb_log_debug2("freeing data\n");
    281144        free(serialized_descriptor);
    282145        free(descriptor->devices_removable);
    283146        free(descriptor);
    284 
    285         //finish
    286 
    287         usb_log_info("hub info created");
    288 
    289         return result;
    290 }
    291 
    292 /**
    293  * Create hub representation and add it into hub list
    294  * @param dev
     147        return EOK;
     148}
     149/**
     150 * Set configuration of hub
     151 *
     152 * Check whether there is at least one configuration and sets the first one.
     153 * This function should be run prior to running any hub-specific action.
     154 * @param hub_info
    295155 * @return
    296156 */
    297 int usb_add_hub_device(ddf_dev_t *dev) {
    298         usb_log_info("add_hub_device(handle=%d)", (int) dev->handle);
    299 
    300         //dev->ops = &hub_device_ops;
    301         (void) hub_device_ops;
    302 
    303         usb_hub_info_t * hub_info = usb_create_hub_info(dev);
    304         if(!hub_info){
    305                 return EINTR;
    306         }
    307 
    308         int opResult;
    309 
    310         //perform final configurations
    311         usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
    312         // process descriptors
    313         opResult = usb_hub_process_configuration_descriptors(hub_info);
     157static int usb_hub_set_configuration(usb_hub_info_t * hub_info){
     158        //device descriptor
     159        usb_standard_device_descriptor_t *std_descriptor
     160            = &hub_info->usb_device->descriptors.device;
     161        usb_log_debug("hub has %d configurations\n",
     162            std_descriptor->configuration_count);
     163        if(std_descriptor->configuration_count<1){
     164                usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE\n");
     165                //shouldn`t I return?
     166                //definitely
     167                return EINVAL;
     168        }
     169
     170        usb_standard_configuration_descriptor_t *config_descriptor
     171            = (usb_standard_configuration_descriptor_t *)
     172            hub_info->usb_device->descriptors.configuration;
     173
     174        /* Set configuration. */
     175        int opResult = usb_request_set_configuration(
     176            &hub_info->usb_device->ctrl_pipe,
     177            config_descriptor->configuration_number);
     178
     179        if (opResult != EOK) {
     180                usb_log_error("Failed to set hub configuration: %s.\n",
     181                    str_error(opResult));
     182                return opResult;
     183        }
     184        usb_log_debug("\tused configuration %d\n",
     185                        config_descriptor->configuration_number);
     186
     187        return EOK;
     188}
     189
     190/**
     191 * Initialize hub device driver fibril
     192 *
     193 * Creates hub representation and fibril that periodically checks hub`s status.
     194 * Hub representation is passed to the fibril.
     195 * @param usb_dev generic usb device information
     196 * @return error code
     197 */
     198int usb_hub_add_device(usb_device_t * usb_dev){
     199        if(!usb_dev) return EINVAL;
     200        usb_hub_info_t * hub_info = usb_hub_info_create(usb_dev);
     201        //create hc connection
     202        usb_log_debug("Initializing USB wire abstraction.\n");
     203        int opResult = usb_hc_connection_initialize_from_device(
     204                        &hub_info->connection,
     205                        hub_info->usb_device->ddf_dev);
    314206        if(opResult != EOK){
    315                 usb_log_error("could not get configuration descriptors, %d",
     207                usb_log_error("could not initialize connection to device, errno %d\n",
    316208                                opResult);
    317                 return opResult;
    318         }
    319         //power ports
    320         usb_device_request_setup_packet_t request;
    321         int port;
    322         for (port = 1; port < hub_info->port_count+1; ++port) {
    323                 usb_hub_set_power_port_request(&request, port);
    324                 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
    325                                 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
    326                 usb_log_info("powering port %d",port);
    327                 if (opResult != EOK) {
    328                         usb_log_warning("something went wrong when setting hub`s %dth port", port);
    329                 }
    330         }
    331         //ports powered, hub seems to be enabled
    332         usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
    333 
    334         //add the hub to list
    335         //is this needed now?
    336         fibril_mutex_lock(&usb_hub_list_lock);
    337         usb_lst_append(&usb_hub_list, hub_info);
    338         fibril_mutex_unlock(&usb_hub_list_lock);
    339         usb_log_debug("hub info added to list");
    340 
    341         usb_log_debug("adding to ddf");
    342         ddf_fun_t *hub_fun = ddf_fun_create(dev, fun_exposed, "hub");
     209                free(hub_info);
     210                return opResult;
     211        }
     212       
     213        usb_pipe_start_session(hub_info->control_pipe);
     214        //set hub configuration
     215        opResult = usb_hub_set_configuration(hub_info);
     216        if(opResult!=EOK){
     217                usb_log_error("could not set hub configuration, errno %d\n",opResult);
     218                free(hub_info);
     219                return opResult;
     220        }
     221        //get port count and create attached_devs
     222        opResult = usb_hub_get_hub_specific_info(hub_info);
     223        if(opResult!=EOK){
     224                usb_log_error("could not set hub configuration, errno %d\n",opResult);
     225                free(hub_info);
     226                return opResult;
     227        }
     228        usb_pipe_end_session(hub_info->control_pipe);
     229
     230
     231        /// \TODO what is this?
     232        usb_log_debug("Creating `hub' function.\n");
     233        ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,
     234                        fun_exposed, "hub");
    343235        assert(hub_fun != NULL);
    344236        hub_fun->ops = NULL;
     
    349241        assert(rc == EOK);
    350242
     243        //create fibril for the hub control loop
    351244        fid_t fid = fibril_create(usb_hub_control_loop, hub_info);
    352245        if (fid == 0) {
    353                 usb_log_error("failed to start monitoring fibril for new hub");
     246                usb_log_error("failed to start monitoring fibril for new hub.\n");
    354247                return ENOMEM;
    355248        }
    356249        fibril_add_ready(fid);
    357 
    358         usb_log_debug("hub fibril created");
    359         //(void)hub_info;
    360         //usb_hub_check_hub_changes();
    361        
    362         usb_log_info("hub dev added");
    363         //address is lost...
    364         usb_log_debug("\taddress %d, has %d ports ",
    365                         //hub_info->endpoints.control.,
    366                         hub_info->port_count);
    367 
     250        usb_log_debug("Hub fibril created.\n");
     251
     252        usb_log_info("Controlling hub `%s' (%d ports).\n",
     253            hub_info->usb_device->ddf_dev->name, hub_info->port_count);
    368254        return EOK;
    369         //return ENOTSUP;
    370255}
    371256
     
    388273        int opResult = usb_hc_release_default_address(&hub->connection);
    389274        if(opResult!=EOK){
    390                 usb_log_error("could not release default address, errno %d",opResult);
     275                usb_log_error("could not release default address, errno %d\n",opResult);
    391276                return opResult;
    392277        }
     
    405290        //if this hub already uses default address, it cannot request it once more
    406291        if(hub->is_default_address_used) return;
    407         int opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     292        usb_log_debug("some connection changed\n");
     293        assert(hub->control_pipe->hc_phone);
     294        int opResult = usb_hub_clear_port_feature(hub->control_pipe,
    408295                                port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    409296        if(opResult != EOK){
    410                 usb_log_warning("could not clear port-change-connection flag");
    411         }
    412 
     297                usb_log_warning("could not clear port-change-connection flag\n");
     298        }
    413299        usb_device_request_setup_packet_t request;
    414         usb_log_info("some connection changed");
    415         assert(hub->endpoints.control.hc_phone);
     300       
    416301        //get default address
    417302        opResult = usb_hc_reserve_default_address(&hub->connection, speed);
    418303       
    419304        if (opResult != EOK) {
    420                 usb_log_warning("cannot assign default address, it is probably used %d",
     305                usb_log_warning("cannot assign default address, it is probably used %d\n",
    421306                                opResult);
    422307                return;
     
    425310        //reset port
    426311        usb_hub_set_reset_port_request(&request, port);
    427         opResult = usb_endpoint_pipe_control_write(
    428                         &hub->endpoints.control,
     312        opResult = usb_pipe_control_write(
     313                        hub->control_pipe,
    429314                        &request,sizeof(usb_device_request_setup_packet_t),
    430315                        NULL, 0
    431316                        );
    432317        if (opResult != EOK) {
    433                 usb_log_error("something went wrong when reseting a port %d",opResult);
     318                usb_log_error("something went wrong when reseting a port %d\n",opResult);
    434319                //usb_hub_release_default_address(hc);
    435320                usb_hub_release_default_address(hub);
     
    445330 */
    446331static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    447                 uint16_t port, bool isLowSpeed) {
     332                uint16_t port, usb_speed_t speed) {
    448333
    449334        int opResult;
    450         usb_log_info("finalizing add device");
    451         opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     335        usb_log_debug("finalizing add device\n");
     336        opResult = usb_hub_clear_port_feature(hub->control_pipe,
    452337            port, USB_HUB_FEATURE_C_PORT_RESET);
    453338
    454339        if (opResult != EOK) {
    455                 usb_log_error("failed to clear port reset feature");
     340                usb_log_error("failed to clear port reset feature\n");
    456341                usb_hub_release_default_address(hub);
    457342                return;
    458343        }
    459344        //create connection to device
    460         usb_endpoint_pipe_t new_device_pipe;
     345        usb_pipe_t new_device_pipe;
    461346        usb_device_connection_t new_device_connection;
    462347        usb_device_connection_initialize_on_default_address(
     
    464349                        &hub->connection
    465350                        );
    466         usb_endpoint_pipe_initialize_default_control(
     351        usb_pipe_initialize_default_control(
    467352                        &new_device_pipe,
    468353                        &new_device_connection);
    469         usb_endpoint_pipe_probe_default_control(&new_device_pipe);
    470         /// \TODO get highspeed info
    471         usb_speed_t speed = isLowSpeed?USB_SPEED_LOW:USB_SPEED_FULL;
    472 
     354        usb_pipe_probe_default_control(&new_device_pipe);
    473355
    474356        /* Request address from host controller. */
     
    478360                        );
    479361        if (new_device_address < 0) {
    480                 usb_log_error("failed to get free USB address");
     362                usb_log_error("failed to get free USB address\n");
    481363                opResult = new_device_address;
    482364                usb_hub_release_default_address(hub);
    483365                return;
    484366        }
    485         usb_log_info("setting new address %d",new_device_address);
     367        usb_log_debug("setting new address %d\n",new_device_address);
    486368        //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    487369        //    new_device_address);
    488         usb_endpoint_pipe_start_session(&new_device_pipe);
     370        usb_pipe_start_session(&new_device_pipe);
    489371        opResult = usb_request_set_address(&new_device_pipe,new_device_address);
    490         usb_endpoint_pipe_end_session(&new_device_pipe);
    491         if (opResult != EOK) {
    492                 usb_log_error("could not set address for new device %d",opResult);
     372        usb_pipe_end_session(&new_device_pipe);
     373        if (opResult != EOK) {
     374                usb_log_error("could not set address for new device %d\n",opResult);
    493375                usb_hub_release_default_address(hub);
    494376                return;
     
    505387        //??
    506388    opResult = usb_device_register_child_in_devman(new_device_address,
    507             hub->connection.hc_handle, hub->device, &child_handle,
     389            hub->connection.hc_handle, hub->usb_device->ddf_dev, &child_handle,
    508390            NULL, NULL, NULL);
    509391
    510392        if (opResult != EOK) {
    511                 usb_log_error("could not start driver for new device %d",opResult);
     393                usb_log_error("could not start driver for new device %d\n",opResult);
    512394                return;
    513395        }
     
    520402                        &hub->attached_devs[port]);
    521403        if (opResult != EOK) {
    522                 usb_log_error("could not assign address of device in hcd %d",opResult);
    523                 return;
    524         }
    525         usb_log_info("new device address %d, handle %zu",
     404                usb_log_error("could not assign address of device in hcd %d\n",opResult);
     405                return;
     406        }
     407        usb_log_info("Detected new device on `%s' (port %d), " \
     408            "address %d (handle %llu).\n",
     409            hub->usb_device->ddf_dev->name, (int) port,
    526410            new_device_address, child_handle);
    527 
    528411}
    529412
     
    537420    usb_hub_info_t * hub,uint16_t port) {
    538421
    539         int opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     422        int opResult = usb_hub_clear_port_feature(hub->control_pipe,
    540423                                port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    541424        if(opResult != EOK){
    542                 usb_log_warning("could not clear port-change-connection flag");
     425                usb_log_warning("could not clear port-change-connection flag\n");
    543426        }
    544427        /** \TODO remove device from device manager - not yet implemented in
     
    559442                 */
    560443        }else{
    561                 usb_log_warning("this is strange, disconnected device had no address");
     444                usb_log_warning("this is strange, disconnected device had no address\n");
    562445                //device was disconnected before it`s port was reset - return default address
    563446                usb_hub_release_default_address(hub);
     
    577460                uint16_t port){
    578461        int opResult;
    579         opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     462        opResult = usb_hub_clear_port_feature(hub->control_pipe,
    580463            port, USB_HUB_FEATURE_PORT_POWER);
    581464        if(opResult!=EOK){
    582                 usb_log_error("cannot power off port %d;  %d",
     465                usb_log_error("cannot power off port %d;  %d\n",
    583466                                port, opResult);
    584467        }
     
    593476static void usb_hub_process_interrupt(usb_hub_info_t * hub,
    594477        uint16_t port) {
    595         usb_log_debug("interrupt at port %d", port);
     478        usb_log_debug("interrupt at port %d\n", port);
    596479        //determine type of change
    597         usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
     480        usb_pipe_t *pipe = hub->control_pipe;
    598481       
    599482        int opResult;
     
    606489        //endpoint 0
    607490
    608         opResult = usb_endpoint_pipe_control_read(
     491        opResult = usb_pipe_control_read(
    609492                        pipe,
    610493                        &request, sizeof(usb_device_request_setup_packet_t),
     
    612495                        );
    613496        if (opResult != EOK) {
    614                 usb_log_error("could not get port status");
     497                usb_log_error("could not get port status\n");
    615498                return;
    616499        }
    617500        if (rcvd_size != sizeof (usb_port_status_t)) {
    618                 usb_log_error("received status has incorrect size");
     501                usb_log_error("received status has incorrect size\n");
    619502                return;
    620503        }
     
    622505        if (usb_port_connect_change(&status)) {
    623506                if (usb_port_dev_connected(&status)) {
    624                         usb_log_info("some connection changed");
     507                        usb_log_debug("some connection changed\n");
    625508                        usb_hub_init_add_device(hub, port, usb_port_speed(&status));
    626509                } else {
     
    634517                        usb_hub_over_current(hub,port);
    635518                }else{
    636                         usb_log_info("over current condition was auto-resolved on port %d",
     519                        usb_log_debug("over current condition was auto-resolved on port %d\n",
    637520                                        port);
    638521                }
     
    640523        //port reset
    641524        if (usb_port_reset_completed(&status)) {
    642                 usb_log_info("port reset complete");
     525                usb_log_debug("port reset complete\n");
    643526                if (usb_port_enabled(&status)) {
    644                         usb_hub_finalize_add_device(hub, port, usb_port_low_speed(&status));
     527                        usb_hub_finalize_add_device(hub, port, usb_port_speed(&status));
    645528                } else {
    646                         usb_log_warning("port reset, but port still not enabled");
     529                        usb_log_warning("port reset, but port still not enabled\n");
    647530                }
    648531        }
     
    653536        usb_port_set_dev_connected(&status, false);
    654537        if (status>>16) {
    655                 usb_log_info("there was some unsupported change on port %d: %X",
     538                usb_log_info("there was some unsupported change on port %d: %X\n",
    656539                                port,status);
    657540
    658541        }
    659         /// \TODO handle other changes - is there any?
    660542}
    661543
     
    668550int usb_hub_check_hub_changes(usb_hub_info_t * hub_info){
    669551        int opResult;
    670         opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
     552        opResult = usb_pipe_start_session(
     553                        hub_info->status_change_pipe);
    671554        if(opResult != EOK){
    672                 usb_log_error("could not initialize communication for hub; %d",
     555                usb_log_error("could not initialize communication for hub; %d\n",
    673556                                opResult);
    674557                return opResult;
     
    685568         * Send the request.
    686569         */
    687         opResult = usb_endpoint_pipe_read(
    688                         &hub_info->endpoints.status_change,
     570        opResult = usb_pipe_read(
     571                        hub_info->status_change_pipe,
    689572                        change_bitmap, byte_length, &actual_size
    690573                        );
     
    692575        if (opResult != EOK) {
    693576                free(change_bitmap);
    694                 usb_log_warning("something went wrong while getting status of hub");
    695                 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
     577                usb_log_warning("something went wrong while getting status of hub\n");
     578                usb_pipe_end_session(hub_info->status_change_pipe);
    696579                return opResult;
    697580        }
    698581        unsigned int port;
    699         opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
    700         if(opResult!=EOK){
    701                 usb_log_error("could not start control pipe session %d", opResult);
    702                 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
     582        opResult = usb_pipe_start_session(hub_info->control_pipe);
     583        if(opResult!=EOK){
     584                usb_log_error("could not start control pipe session %d\n", opResult);
     585                usb_pipe_end_session(hub_info->status_change_pipe);
    703586                return opResult;
    704587        }
    705588        opResult = usb_hc_connection_open(&hub_info->connection);
    706589        if(opResult!=EOK){
    707                 usb_log_error("could not start host controller session %d",
     590                usb_log_error("could not start host controller session %d\n",
    708591                                opResult);
    709                 usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
    710                 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
     592                usb_pipe_end_session(hub_info->control_pipe);
     593                usb_pipe_end_session(hub_info->status_change_pipe);
    711594                return opResult;
    712595        }
     
    722605        }
    723606        usb_hc_connection_close(&hub_info->connection);
    724         usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
    725         usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
     607        usb_pipe_end_session(hub_info->control_pipe);
     608        usb_pipe_end_session(hub_info->status_change_pipe);
    726609        free(change_bitmap);
    727610        return EOK;
  • uspace/drv/usbhub/usbhub.h

    r4fb6d9ee re099f26  
    4545
    4646#include <usb/pipes.h>
    47 
    48 /* Hub endpoints. */
    49 typedef struct {
    50         usb_endpoint_pipe_t control;
    51         usb_endpoint_pipe_t status_change;
    52 } usb_hub_endpoints_t;
    53 
     47#include <usb/devdrv.h>
    5448
    5549
     
    5852        /** Number of ports. */
    5953        int port_count;
     54
    6055        /** attached device handles, for each port one */
    6156        usb_hc_attached_device_t * attached_devs;
    62         /** General usb device info. */
    63         //usb_hcd_attached_device_info_t * usb_device;
    64         /** General device info*/
    65         ddf_dev_t * device;
     57       
    6658        /** connection to hcd */
    67         //usb_device_connection_t connection;
    6859        usb_hc_connection_t connection;
    69         /** */
    70         usb_device_connection_t device_connection;
    71         /** hub endpoints */
    72         usb_hub_endpoints_t endpoints;
    7360
     61        /** default address is used indicator
     62         *
     63         * If default address is requested by this device, it cannot
     64         * be requested by the same hub again, otherwise a deadlock will occur.
     65         */
    7466        bool is_default_address_used;
     67
     68        /** convenience pointer to status change pipe
     69         *
     70         * Status change pipe is initialized in usb_device structure. This is
     71         * pointer into this structure, so that it does not have to be
     72         * searched again and again for the 'right pipe'.
     73         */
     74        usb_pipe_t * status_change_pipe;
     75
     76        /** convenience pointer to control pipe
     77         *
     78         * Control pipe is initialized in usb_device structure. This is
     79         * pointer into this structure, so that it does not have to be
     80         * searched again and again for the 'right pipe'.
     81         */
     82        usb_pipe_t * control_pipe;
     83
     84        /** generic usb device data*/
     85        usb_device_t * usb_device;
    7586} usb_hub_info_t;
    7687
     
    8091 */
    8192int usb_hub_control_loop(void * hub_info_param);
    82 
    83 /** Callback when new hub device is detected.
    84  *
    85  * @param dev New device.
    86  * @return Error code.
    87  */
    88 int usb_add_hub_device(ddf_dev_t *dev);
    8993
    9094/**
     
    97101
    98102
    99 
    100 
     103int usb_hub_add_device(usb_device_t * usb_dev);
    101104
    102105#endif
  • uspace/drv/usbhub/usbhub_private.h

    r4fb6d9ee re099f26  
    5858
    5959
    60 //************
    61 //
    62 // convenience debug printf for usb hub
    63 //
    64 //************
    65 #define dprintf(level, format, ...) \
    66         usb_log_printf((level), format "\n", ##__VA_ARGS__)
    67 
    68 
    6960/**
    7061 * Create hub structure instance
     
    7768 */
    7869usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device);
    79 
    80 /** List of hubs maanged by this driver */
    81 extern usb_general_list_t usb_hub_list;
    82 
    83 /** Lock for hub list*/
    84 extern fibril_mutex_t usb_hub_list_lock;
    85 
    86 
    87 /**
    88  * Perform complete control read transaction
    89  *
    90  * Manages all three steps of transaction: setup, read and finalize
    91  * @param phone
    92  * @param target
    93  * @param request Request packet
    94  * @param rcvd_buffer Received data
    95  * @param rcvd_size
    96  * @param actual_size Actual size of received data
    97  * @return error code
    98  */
    99 /*
    100 int usb_drv_sync_control_read(
    101     usb_endpoint_pipe_t *pipe,
    102     usb_device_request_setup_packet_t * request,
    103     void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
    104 );*/
    105 
    106 /**
    107  * Perform complete control write transaction
    108  *
    109  * Manages all three steps of transaction: setup, write and finalize
    110  * @param phone
    111  * @param target
    112  * @param request Request packet to send data
    113  * @param sent_buffer
    114  * @param sent_size
    115  * @return error code
    116  */
    117 /*int usb_drv_sync_control_write(
    118     usb_endpoint_pipe_t *pipe,
    119     usb_device_request_setup_packet_t * request,
    120     void * sent_buffer, size_t sent_size
    121 );*/
    12270
    12371/**
     
    14795 * @return Operation result
    14896 */
    149 static inline int usb_hub_clear_port_feature(usb_endpoint_pipe_t *pipe,
     97static inline int usb_hub_clear_port_feature(usb_pipe_t *pipe,
    15098    int port_index,
    15199    usb_hub_class_feature_t feature) {
     
    158106        };
    159107        clear_request.value = feature;
    160         return usb_endpoint_pipe_control_write(pipe, &clear_request,
     108        return usb_pipe_control_write(pipe, &clear_request,
    161109            sizeof(clear_request), NULL, 0);
    162110}
    163111
    164112/**
    165  * @brief create uint8_t array with serialized descriptor
     113 * create uint8_t array with serialized descriptor
    166114 *
    167115 * @param descriptor
     
    171119
    172120/**
    173  * @brief create deserialized desriptor structure out of serialized descriptor
     121 * create deserialized desriptor structure out of serialized descriptor
    174122 *
    175123 * The serialized descriptor must be proper usb hub descriptor,
  • uspace/drv/usbhub/utils.c

    r4fb6d9ee re099f26  
    8888
    8989        if (sdescriptor[1] != USB_DESCTYPE_HUB) {
    90                 dprintf(1,"[usb_hub] wrong descriptor %x\n",sdescriptor[1]);
     90                usb_log_warning("trying to deserialize wrong descriptor %x\n",sdescriptor[1]);
    9191                return NULL;
    9292        }
     
    103103                        ? 1 : 0);
    104104        result->devices_removable = (uint8_t*) malloc(var_size);
    105         //printf("[usb_hub] getting removable devices data \n");
     105
    106106        size_t i;
    107107        for (i = 0; i < var_size; ++i) {
     
    111111}
    112112
    113 //control transactions
    114 /*
    115 int usb_drv_sync_control_read(
    116     int phone, usb_target_t target,
    117     usb_device_request_setup_packet_t * request,
    118     void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
    119 ) {
    120         usb_handle_t handle;
    121         int opResult;
    122         //setup
    123         opResult = usb_drv_async_control_read_setup(phone, target,
    124             request, sizeof (usb_device_request_setup_packet_t),
    125             &handle);
    126         if (opResult != EOK) {
    127                 return opResult;
    128         }
    129         opResult = usb_drv_async_wait_for(handle);
    130         if (opResult != EOK) {
    131                 return opResult;
    132         }
    133         //read
    134         opResult = usb_drv_async_control_read_data(phone, target,
    135                         rcvd_buffer, rcvd_size, actual_size,
    136                         &handle);
    137         if (opResult != EOK) {
    138                 return opResult;
    139         }
    140         opResult = usb_drv_async_wait_for(handle);
    141         if (opResult != EOK) {
    142                 return opResult;
    143         }
    144         //finalize
    145         opResult = usb_drv_async_control_read_status(phone, target,
    146                         &handle);
    147         if (opResult != EOK) {
    148                 return opResult;
    149         }
    150         opResult = usb_drv_async_wait_for(handle);
    151         if (opResult != EOK) {
    152                 return opResult;
    153         }
    154         return EOK;
    155 }
    156 
    157 int usb_drv_sync_control_write(
    158     int phone, usb_target_t target,
    159     usb_device_request_setup_packet_t * request,
    160     void * sent_buffer, size_t sent_size
    161 ) {
    162         usb_handle_t handle;
    163         int opResult;
    164         //setup
    165         opResult = usb_drv_async_control_write_setup(phone, target,
    166             request, sizeof (usb_device_request_setup_packet_t),
    167             &handle);
    168         if (opResult != EOK) {
    169                 return opResult;
    170         }
    171         opResult = usb_drv_async_wait_for(handle);
    172         if (opResult != EOK) {
    173                 return opResult;
    174         }
    175         //write
    176         opResult = usb_drv_async_control_write_data(phone, target,
    177                         sent_buffer, sent_size,
    178                         &handle);
    179         if (opResult != EOK) {
    180                 return opResult;
    181         }
    182         opResult = usb_drv_async_wait_for(handle);
    183         if (opResult != EOK) {
    184                 return opResult;
    185         }
    186         //finalize
    187         opResult = usb_drv_async_control_write_status(phone, target,
    188             &handle);
    189         if (opResult != EOK) {
    190                 return opResult;
    191         }
    192         opResult = usb_drv_async_wait_for(handle);
    193         if (opResult != EOK) {
    194                 return opResult;
    195         }
    196         return EOK;
    197 }
    198 
    199 */
    200 
    201113
    202114
  • uspace/drv/usbmid/main.c

    r4fb6d9ee re099f26  
    6161        int rc;
    6262
    63         rc = usb_endpoint_pipe_start_session(&dev->ctrl_pipe);
     63        rc = usb_pipe_start_session(&dev->ctrl_pipe);
    6464        if (rc != EOK) {
    6565                usb_log_error("Failed to start session on control pipe: %s.\n",
     
    7070        bool accept = usbmid_explore_device(dev);
    7171
    72         rc = usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
     72        rc = usb_pipe_end_session(&dev->ctrl_pipe);
    7373        if (rc != EOK) {
    7474                usb_log_warning("Failed to end session on control pipe: %s.\n",
     
    106106        printf(NAME ": USB multi interface device driver.\n");
    107107
    108         usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
     108        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    109109        return ddf_driver_main(&mid_driver);
    110110}
  • uspace/drv/usbmid/usbmid.c

    r4fb6d9ee re099f26  
    108108        }
    109109
    110         rc = usb_endpoint_pipe_initialize_default_control(&mid->ctrl_pipe,
     110        rc = usb_pipe_initialize_default_control(&mid->ctrl_pipe,
    111111            &mid->wire);
    112112        if (rc != EOK) {
     
    116116                return NULL;
    117117        }
    118         rc = usb_endpoint_pipe_probe_default_control(&mid->ctrl_pipe);
     118        rc = usb_pipe_probe_default_control(&mid->ctrl_pipe);
    119119        if (rc != EOK) {
    120120                usb_log_error("Probing default control pipe failed: %s.\n",
  • uspace/drv/usbmid/usbmid.h

    r4fb6d9ee re099f26  
    5252        usb_device_connection_t wire;
    5353        /** Default control pipe. */
    54         usb_endpoint_pipe_t ctrl_pipe;
     54        usb_pipe_t ctrl_pipe;
    5555} usbmid_device_t;
    5656
  • uspace/drv/usbmouse/init.c

    r4fb6d9ee re099f26  
    126126       
    127127        /* Open the control pipe. */
    128         rc = usb_endpoint_pipe_start_session(&dev->ctrl_pipe);
     128        rc = usb_pipe_start_session(&dev->ctrl_pipe);
    129129        if (rc != EOK) {
    130130                goto leave;
     
    141141       
    142142        /* Close the control pipe (ignore errors). */
    143         usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
     143        usb_pipe_end_session(&dev->ctrl_pipe);
    144144
    145145
  • uspace/drv/usbmouse/main.c

    r4fb6d9ee re099f26  
    9090int main(int argc, char *argv[])
    9191{
    92         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     92        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    9393
    9494        return usb_driver_main(&mouse_driver);
  • uspace/drv/vhc/hcd.c

    r4fb6d9ee re099f26  
    122122        //sleep(5);
    123123
    124         usb_log_enable(USB_LOG_LEVEL_DEBUG, NAME);
     124        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    125125
    126126        printf(NAME ": virtual USB host controller driver.\n");
  • uspace/lib/usb/Makefile

    r4fb6d9ee re099f26  
    4949        src/request.c \
    5050        src/usb.c \
    51         src/usbdevice.c
     51        src/usbdevice.c \
     52        src/host/device_keeper.c \
     53        src/host/batch.c
    5254
    5355include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/usb/include/usb/classes/hub.h

    r4fb6d9ee re099f26  
    6060} usb_hub_class_feature_t;
    6161
     62/** Header of standard hub descriptor without the "variadic" part. */
     63typedef struct {
     64        /** Descriptor length. */
     65        uint8_t length;
     66        /** Descriptor type (0x29). */
     67        uint8_t descriptor_type;
     68        /** Number of downstream ports. */
     69        uint8_t port_count;
     70        /** Characteristics bitmask. */
     71        uint16_t characteristics;
     72        /** Time from power-on to stabilization of current on the port. */
     73        uint8_t power_good_time;
     74        /** Maximum current requirements in mA. */
     75        uint8_t max_current;
     76} __attribute__ ((packed)) usb_hub_descriptor_header_t;
    6277
    6378/**
  • uspace/lib/usb/include/usb/debug.h

    r4fb6d9ee re099f26  
    7979} usb_log_level_t;
    8080
     81/** Default log level. */
     82#define USB_LOG_LEVEL_DEFAULT USB_LOG_LEVEL_DEBUG
     83
    8184
    8285void usb_log_enable(usb_log_level_t, const char *);
  • uspace/lib/usb/include/usb/devdrv.h

    r4fb6d9ee re099f26  
    3838#include <usb/pipes.h>
    3939
     40/** Descriptors for USB device. */
     41typedef struct {
     42        /** Standard device descriptor. */
     43        usb_standard_device_descriptor_t device;
     44        /** Full configuration descriptor of current configuration. */
     45        uint8_t *configuration;
     46        size_t configuration_size;
     47} usb_device_descriptors_t;
     48
    4049/** USB device structure. */
    4150typedef struct {
    4251        /** The default control pipe. */
    43         usb_endpoint_pipe_t ctrl_pipe;
     52        usb_pipe_t ctrl_pipe;
    4453        /** Other endpoint pipes.
    4554         * This is an array of other endpoint pipes in the same order as
     
    5261         */
    5362        int interface_no;
     63
     64        /** Some useful descriptors. */
     65        usb_device_descriptors_t descriptors;
     66
    5467        /** Generic DDF device backing this one. */
    5568        ddf_dev_t *ddf_dev;
     
    7992         */
    8093        const char *name;
    81         /** Expected endpoints description. */
     94        /** Expected endpoints description, excluding default control endpoint.
     95         *
     96         * It MUST be of size expected_enpoints_count(excluding default ctrl) + 1
     97         * where the last record MUST BE NULL, otherwise catastrophic things may
     98         * happen.
     99         */
    82100        usb_endpoint_description_t **endpoints;
    83101        /** Driver ops. */
  • uspace/lib/usb/include/usb/pipes.h

    r4fb6d9ee re099f26  
    8080         */
    8181        int hc_phone;
    82 } usb_endpoint_pipe_t;
     82} usb_pipe_t;
    8383
    8484
     
    102102typedef struct {
    103103        /** Endpoint pipe. */
    104         usb_endpoint_pipe_t *pipe;
     104        usb_pipe_t *pipe;
    105105        /** Endpoint description. */
    106106        const usb_endpoint_description_t *description;
     
    125125usb_address_t usb_device_get_assigned_address(devman_handle_t);
    126126
    127 int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *,
    128     usb_device_connection_t *,
     127int usb_pipe_initialize(usb_pipe_t *, usb_device_connection_t *,
    129128    usb_endpoint_t, usb_transfer_type_t, size_t, usb_direction_t);
    130 int usb_endpoint_pipe_initialize_default_control(usb_endpoint_pipe_t *,
     129int usb_pipe_initialize_default_control(usb_pipe_t *,
    131130    usb_device_connection_t *);
    132 int usb_endpoint_pipe_probe_default_control(usb_endpoint_pipe_t *);
    133 int usb_endpoint_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
     131int usb_pipe_probe_default_control(usb_pipe_t *);
     132int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
    134133    size_t, uint8_t *, size_t, usb_device_connection_t *);
    135 int usb_endpoint_pipe_register(usb_endpoint_pipe_t *, unsigned int,
    136     usb_hc_connection_t *);
    137 int usb_endpoint_pipe_unregister(usb_endpoint_pipe_t *, usb_hc_connection_t *);
     134int usb_pipe_register(usb_pipe_t *, unsigned int, usb_hc_connection_t *);
     135int usb_pipe_unregister(usb_pipe_t *, usb_hc_connection_t *);
    138136
    139 int usb_endpoint_pipe_start_session(usb_endpoint_pipe_t *);
    140 int usb_endpoint_pipe_end_session(usb_endpoint_pipe_t *);
    141 bool usb_endpoint_pipe_is_session_started(usb_endpoint_pipe_t *);
     137int usb_pipe_start_session(usb_pipe_t *);
     138int usb_pipe_end_session(usb_pipe_t *);
     139bool usb_pipe_is_session_started(usb_pipe_t *);
    142140
    143 int usb_endpoint_pipe_read(usb_endpoint_pipe_t *, void *, size_t, size_t *);
    144 int usb_endpoint_pipe_write(usb_endpoint_pipe_t *, void *, size_t);
     141int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
     142int usb_pipe_write(usb_pipe_t *, void *, size_t);
    145143
    146 int usb_endpoint_pipe_control_read(usb_endpoint_pipe_t *, void *, size_t,
     144int usb_pipe_control_read(usb_pipe_t *, void *, size_t,
    147145    void *, size_t, size_t *);
    148 int usb_endpoint_pipe_control_write(usb_endpoint_pipe_t *, void *, size_t,
     146int usb_pipe_control_write(usb_pipe_t *, void *, size_t,
    149147    void *, size_t);
    150148
  • uspace/lib/usb/include/usb/recognise.h

    r4fb6d9ee re099f26  
    4848    const usb_standard_interface_descriptor_t *, match_id_list_t *);
    4949
    50 int usb_device_create_match_ids(usb_endpoint_pipe_t *, match_id_list_t *);
     50int usb_device_create_match_ids(usb_pipe_t *, match_id_list_t *);
    5151
    5252int usb_device_register_child_in_devman(usb_address_t, devman_handle_t,
  • uspace/lib/usb/include/usb/request.h

    r4fb6d9ee re099f26  
    8686} __attribute__ ((packed)) usb_device_request_setup_packet_t;
    8787
    88 int usb_control_request_set(usb_endpoint_pipe_t *,
     88int usb_control_request_set(usb_pipe_t *,
    8989    usb_request_type_t, usb_request_recipient_t, uint8_t,
    9090    uint16_t, uint16_t, void *, size_t);
    9191
    92 int usb_control_request_get(usb_endpoint_pipe_t *,
     92int usb_control_request_get(usb_pipe_t *,
    9393    usb_request_type_t, usb_request_recipient_t, uint8_t,
    9494    uint16_t, uint16_t, void *, size_t, size_t *);
    9595
    96 int usb_request_set_address(usb_endpoint_pipe_t *, usb_address_t);
    97 int usb_request_get_descriptor(usb_endpoint_pipe_t *, usb_request_type_t,
     96int usb_request_get_status(usb_pipe_t *, usb_request_recipient_t,
     97    uint16_t, uint16_t *);
     98int usb_request_clear_feature(usb_pipe_t *, usb_request_type_t,
     99    usb_request_recipient_t, uint16_t, uint16_t);
     100int usb_request_set_feature(usb_pipe_t *, usb_request_type_t,
     101    usb_request_recipient_t, uint16_t, uint16_t);
     102int usb_request_set_address(usb_pipe_t *, usb_address_t);
     103int usb_request_get_descriptor(usb_pipe_t *, usb_request_type_t,
    98104    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t,
    99105    size_t *);
    100 int usb_request_get_descriptor_alloc(usb_endpoint_pipe_t *, usb_request_type_t,
     106int usb_request_get_descriptor_alloc(usb_pipe_t *, usb_request_type_t,
    101107    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void **, size_t *);
    102 int usb_request_get_device_descriptor(usb_endpoint_pipe_t *,
     108int usb_request_get_device_descriptor(usb_pipe_t *,
    103109    usb_standard_device_descriptor_t *);
    104 int usb_request_get_bare_configuration_descriptor(usb_endpoint_pipe_t *, int,
     110int usb_request_get_bare_configuration_descriptor(usb_pipe_t *, int,
    105111    usb_standard_configuration_descriptor_t *);
    106 int usb_request_get_full_configuration_descriptor(usb_endpoint_pipe_t *, int,
     112int usb_request_get_full_configuration_descriptor(usb_pipe_t *, int,
    107113    void *, size_t, size_t *);
    108 int usb_request_get_full_configuration_descriptor_alloc(usb_endpoint_pipe_t *,
     114int usb_request_get_full_configuration_descriptor_alloc(usb_pipe_t *,
    109115    int, void **, size_t *);
    110 int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t);
     116int usb_request_set_descriptor(usb_pipe_t *, usb_request_type_t,
     117    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t);
     118int usb_request_get_configuration(usb_pipe_t *, uint8_t *);
     119int usb_request_set_configuration(usb_pipe_t *, uint8_t);
     120int usb_request_get_interface(usb_pipe_t *, uint8_t, uint8_t *);
     121int usb_request_set_interface(usb_pipe_t *, uint8_t, uint8_t);
    111122
    112 int usb_request_get_supported_languages(usb_endpoint_pipe_t *,
     123int usb_request_get_supported_languages(usb_pipe_t *,
    113124    l18_win_locales_t **, size_t *);
    114 int usb_request_get_string(usb_endpoint_pipe_t *, size_t, l18_win_locales_t,
     125int usb_request_get_string(usb_pipe_t *, size_t, l18_win_locales_t,
    115126    char **);
    116127
  • uspace/lib/usb/include/usb/usb.h

    r4fb6d9ee re099f26  
    6161
    6262const char * usb_str_transfer_type(usb_transfer_type_t t);
     63const char * usb_str_transfer_type_short(usb_transfer_type_t t);
    6364
    6465/** USB data transfer direction. */
     
    7879        USB_SPEED_HIGH
    7980} usb_speed_t;
     81
     82const char *usb_str_speed(usb_speed_t);
     83
    8084
    8185/** USB request type target. */
  • uspace/lib/usb/src/devdrv.c

    r4fb6d9ee re099f26  
    126126
    127127        for (i = 0; i < pipe_count; i++) {
    128                 dev->pipes[i].pipe = malloc(sizeof(usb_endpoint_pipe_t));
     128                dev->pipes[i].pipe = malloc(sizeof(usb_pipe_t));
    129129                if (dev->pipes[i].pipe == NULL) {
    130130                        usb_log_oom(dev->ddf_dev);
     
    137137        }
    138138
    139         void *config_descriptor;
    140         size_t config_descriptor_size;
    141         rc = usb_request_get_full_configuration_descriptor_alloc(
    142             &dev->ctrl_pipe, 0, &config_descriptor, &config_descriptor_size);
    143         if (rc != EOK) {
    144                 usb_log_error("Failed retrieving configuration of `%s': %s.\n",
    145                     dev->ddf_dev->name, str_error(rc));
    146                 goto rollback;
    147         }
    148 
    149         rc = usb_endpoint_pipe_initialize_from_configuration(dev->pipes,
    150            pipe_count, config_descriptor, config_descriptor_size, &dev->wire);
     139        rc = usb_pipe_initialize_from_configuration(dev->pipes, pipe_count,
     140            dev->descriptors.configuration, dev->descriptors.configuration_size,
     141            &dev->wire);
    151142        if (rc != EOK) {
    152143                usb_log_error("Failed initializing USB endpoints: %s.\n",
     
    172163        for (i = 0; i < pipe_count; i++) {
    173164                if (dev->pipes[i].present) {
    174                         rc = usb_endpoint_pipe_register(dev->pipes[i].pipe,
     165                        rc = usb_pipe_register(dev->pipes[i].pipe,
    175166                            dev->pipes[i].descriptor->poll_interval,
    176167                            &hc_conn);
     
    206197 * @return Error code.
    207198 */
    208 static int initialize_pipes(usb_driver_t *drv, usb_device_t *dev)
     199static int initialize_pipes(usb_device_t *dev)
    209200{
    210201        int rc;
     
    219210        }
    220211
    221         rc = usb_endpoint_pipe_initialize_default_control(&dev->ctrl_pipe,
     212        rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe,
    222213            &dev->wire);
    223214        if (rc != EOK) {
     
    228219        }
    229220
    230         rc = usb_endpoint_pipe_probe_default_control(&dev->ctrl_pipe);
     221        rc = usb_pipe_probe_default_control(&dev->ctrl_pipe);
    231222        if (rc != EOK) {
    232223                usb_log_error(
     
    237228
    238229        /*
    239          * Initialization of other pipes requires open session on
    240          * default control pipe.
     230         * For further actions, we need open session on default control pipe.
    241231         */
    242         rc = usb_endpoint_pipe_start_session(&dev->ctrl_pipe);
     232        rc = usb_pipe_start_session(&dev->ctrl_pipe);
    243233        if (rc != EOK) {
    244234                usb_log_error("Failed to start an IPC session: %s.\n",
    245235                    str_error(rc));
     236                return rc;
     237        }
     238
     239        /* Get the device descriptor. */
     240        rc = usb_request_get_device_descriptor(&dev->ctrl_pipe,
     241            &dev->descriptors.device);
     242        if (rc != EOK) {
     243                usb_log_error("Failed to retrieve device descriptor: %s.\n",
     244                    str_error(rc));
     245                return rc;
     246        }
     247
     248        /* Get the full configuration descriptor. */
     249        rc = usb_request_get_full_configuration_descriptor_alloc(
     250            &dev->ctrl_pipe, 0, (void **) &dev->descriptors.configuration,
     251            &dev->descriptors.configuration_size);
     252        if (rc != EOK) {
     253                usb_log_error("Failed retrieving configuration descriptor: %s.\n",
     254                    dev->ddf_dev->name, str_error(rc));
    246255                return rc;
    247256        }
     
    252261
    253262        /* No checking here. */
    254         usb_endpoint_pipe_end_session(&dev->ctrl_pipe);
     263        usb_pipe_end_session(&dev->ctrl_pipe);
     264
     265        /* Rollback actions. */
     266        if (rc != EOK) {
     267                if (dev->descriptors.configuration != NULL) {
     268                        free(dev->descriptors.configuration);
     269                }
     270        }
    255271
    256272        return rc;
     
    283299        dev->ddf_dev->driver_data = dev;
    284300        dev->driver_data = NULL;
    285 
    286         rc = initialize_pipes(driver, dev);
     301        dev->descriptors.configuration = NULL;
     302
     303        rc = initialize_pipes(dev);
    287304        if (rc != EOK) {
    288305                free(dev);
  • uspace/lib/usb/src/devpoll.c

    r4fb6d9ee re099f26  
    6464        assert(polling_data);
    6565
    66         usb_endpoint_pipe_t *pipe
     66        usb_pipe_t *pipe
    6767            = polling_data->dev->pipes[polling_data->pipe_index].pipe;
    6868
     
    7171                int rc;
    7272
    73                 rc = usb_endpoint_pipe_start_session(pipe);
     73                rc = usb_pipe_start_session(pipe);
    7474                if (rc != EOK) {
    7575                        failed_attempts++;
     
    7878
    7979                size_t actual_size;
    80                 rc = usb_endpoint_pipe_read(pipe, polling_data->buffer,
     80                rc = usb_pipe_read(pipe, polling_data->buffer,
    8181                    polling_data->request_size, &actual_size);
    8282
    8383                /* Quit the session regardless of errors. */
    84                 usb_endpoint_pipe_end_session(pipe);
     84                usb_pipe_end_session(pipe);
    8585
    8686                if (rc != EOK) {
  • uspace/lib/usb/src/host/device_keeper.c

    r4fb6d9ee re099f26  
    2727 */
    2828
    29 /** @addtogroup drvusbuhcihc
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief UHCI driver
     33 * Device keeper structure and functions (implementation).
    3434 */
    3535#include <assert.h>
    3636#include <errno.h>
    3737#include <usb/debug.h>
    38 
    39 #include "device_keeper.h"
     38#include <usb/host/device_keeper.h>
    4039
    4140/*----------------------------------------------------------------------------*/
     
    4645 * Set all values to false/0.
    4746 */
    48 void device_keeper_init(device_keeper_t *instance)
     47void usb_device_keeper_init(usb_device_keeper_t *instance)
    4948{
    5049        assert(instance);
     
    5655                instance->devices[i].occupied = false;
    5756                instance->devices[i].handle = 0;
    58                 instance->devices[i].toggle_status = 0;
     57                instance->devices[i].toggle_status[0] = 0;
     58                instance->devices[i].toggle_status[1] = 0;
    5959        }
    6060}
     
    6565 * @param[in] speed Speed of the device requesting default address.
    6666 */
    67 void device_keeper_reserve_default(device_keeper_t *instance, usb_speed_t speed)
     67void usb_device_keeper_reserve_default_address(usb_device_keeper_t *instance,
     68    usb_speed_t speed)
    6869{
    6970        assert(instance);
     
    8384 * @param[in] speed Speed of the device requesting default address.
    8485 */
    85 void device_keeper_release_default(device_keeper_t *instance)
     86void usb_device_keeper_release_default_address(usb_device_keeper_t *instance)
    8687{
    8788        assert(instance);
     
    100101 * Really ugly one.
    101102 */
    102 void device_keeper_reset_if_need(
    103     device_keeper_t *instance, usb_target_t target, const unsigned char *data)
     103void usb_device_keeper_reset_if_need(usb_device_keeper_t *instance,
     104    usb_target_t target, const uint8_t *data)
    104105{
    105106        assert(instance);
     
    119120                if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
    120121                        /* endpoint number is < 16, thus first byte is enough */
    121                         instance->devices[target.address].toggle_status &=
     122                        instance->devices[target.address].toggle_status[0] &=
     123                            ~(1 << data[4]);
     124                        instance->devices[target.address].toggle_status[1] &=
    122125                            ~(1 << data[4]);
    123126                }
     
    128131                /* target must be device */
    129132                if ((data[0] & 0xf) == 0) {
    130                         instance->devices[target.address].toggle_status = 0;
     133                        instance->devices[target.address].toggle_status[0] = 0;
     134                        instance->devices[target.address].toggle_status[1] = 0;
    131135                }
    132136        break;
     
    141145 * @return Error code
    142146 */
    143 int device_keeper_get_toggle(device_keeper_t *instance, usb_target_t target)
    144 {
    145         assert(instance);
     147int usb_device_keeper_get_toggle(usb_device_keeper_t *instance,
     148    usb_target_t target, usb_direction_t direction)
     149{
     150        assert(instance);
     151        /* only control pipes are bi-directional and those do not need toggle */
     152        if (direction == USB_DIRECTION_BOTH)
     153                return ENOENT;
    146154        int ret;
    147155        fibril_mutex_lock(&instance->guard);
     
    152160                ret = EINVAL;
    153161        } else {
    154                 ret = (instance->devices[target.address].toggle_status
     162                ret = (instance->devices[target.address].toggle_status[direction]
    155163                        >> target.endpoint) & 1;
    156164        }
     
    166174 * @return Error code.
    167175 */
    168 int device_keeper_set_toggle(
    169     device_keeper_t *instance, usb_target_t target, bool toggle)
    170 {
    171         assert(instance);
     176int usb_device_keeper_set_toggle(usb_device_keeper_t *instance,
     177    usb_target_t target, usb_direction_t direction, bool toggle)
     178{
     179        assert(instance);
     180        /* only control pipes are bi-directional and those do not need toggle */
     181        if (direction == USB_DIRECTION_BOTH)
     182                return ENOENT;
    172183        int ret;
    173184        fibril_mutex_lock(&instance->guard);
     
    179190        } else {
    180191                if (toggle) {
    181                         instance->devices[target.address].toggle_status |=
    182                             (1 << target.endpoint);
     192                        instance->devices[target.address].toggle_status[direction]
     193                            |= (1 << target.endpoint);
    183194                } else {
    184                         instance->devices[target.address].toggle_status &=
    185                             ~(1 << target.endpoint);
     195                        instance->devices[target.address].toggle_status[direction]
     196                            &= ~(1 << target.endpoint);
    186197                }
    187198                ret = EOK;
     
    197208 * @return Free address, or error code.
    198209 */
    199 usb_address_t device_keeper_request(
    200     device_keeper_t *instance, usb_speed_t speed)
     210usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance,
     211    usb_speed_t speed)
    201212{
    202213        assert(instance);
     
    218229        instance->devices[new_address].occupied = true;
    219230        instance->devices[new_address].speed = speed;
    220         instance->devices[new_address].toggle_status = 0;
     231        instance->devices[new_address].toggle_status[0] = 0;
     232        instance->devices[new_address].toggle_status[1] = 0;
    221233        instance->last_address = new_address;
    222234        fibril_mutex_unlock(&instance->guard);
     
    230242 * @param[in] handle Devman handle of the device.
    231243 */
    232 void device_keeper_bind(
    233     device_keeper_t *instance, usb_address_t address, devman_handle_t handle)
     244void usb_device_keeper_bind(usb_device_keeper_t *instance,
     245    usb_address_t address, devman_handle_t handle)
    234246{
    235247        assert(instance);
     
    247259 * @param[in] address Device address
    248260 */
    249 void device_keeper_release(device_keeper_t *instance, usb_address_t address)
     261void usb_device_keeper_release(usb_device_keeper_t *instance,
     262    usb_address_t address)
    250263{
    251264        assert(instance);
     
    265278 * @return USB Address, or error code.
    266279 */
    267 usb_address_t device_keeper_find(
    268     device_keeper_t *instance, devman_handle_t handle)
     280usb_address_t usb_device_keeper_find(usb_device_keeper_t *instance,
     281    devman_handle_t handle)
    269282{
    270283        assert(instance);
     
    288301 * @return USB speed.
    289302 */
    290 usb_speed_t device_keeper_speed(
    291     device_keeper_t *instance, usb_address_t address)
     303usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance,
     304    usb_address_t address)
    292305{
    293306        assert(instance);
     
    296309        return instance->devices[address].speed;
    297310}
     311
    298312/**
    299313 * @}
  • uspace/lib/usb/src/hub.c

    r4fb6d9ee re099f26  
    228228        }
    229229
    230         usb_endpoint_pipe_t ctrl_pipe;
    231         rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe,
     230        usb_pipe_t ctrl_pipe;
     231        rc = usb_pipe_initialize_default_control(&ctrl_pipe,
    232232            &dev_conn);
    233233        if (rc != EOK) {
     
    235235                goto leave_release_default_address;
    236236        }
    237         rc = usb_endpoint_pipe_probe_default_control(&ctrl_pipe);
     237        rc = usb_pipe_probe_default_control(&ctrl_pipe);
    238238        if (rc != EOK) {
    239239                rc = ENOTCONN;
     
    241241        }
    242242
    243         rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
     243        rc = usb_pipe_start_session(&ctrl_pipe);
    244244        if (rc != EOK) {
    245245                rc = ENOTCONN;
     
    253253        }
    254254
    255         usb_endpoint_pipe_end_session(&ctrl_pipe);
     255        usb_pipe_end_session(&ctrl_pipe);
    256256
    257257        /*
     
    306306
    307307leave_stop_session:
    308         usb_endpoint_pipe_end_session(&ctrl_pipe);
     308        usb_pipe_end_session(&ctrl_pipe);
    309309
    310310leave_release_default_address:
  • uspace/lib/usb/src/pipes.c

    r4fb6d9ee re099f26  
    4242#include <assert.h>
    4343
     44#define IPC_AGAIN_DELAY (1000 * 2) /* 2ms */
     45
    4446/** Tell USB address assigned to given device.
    4547 *
     
    150152        }
    151153
    152         my_address = get_my_address(parent_phone, dev);
    153         if (my_address < 0) {
    154                 rc = my_address;
    155                 goto leave;
    156         }
     154        /*
     155         * Asking for "my" address may require several attempts.
     156         * That is because following scenario may happen:
     157         *  - parent driver (i.e. driver of parent device) announces new device
     158         *    and devman launches current driver
     159         *  - parent driver is preempted and thus does not send address-handle
     160         *    binding to HC driver
     161         *  - this driver gets here and wants the binding
     162         *  - the HC does not know the binding yet and thus it answers ENOENT
     163         *  So, we need to wait for the HC to learn the binding.
     164         */
     165        do {
     166                my_address = get_my_address(parent_phone, dev);
     167
     168                if (my_address == ENOENT) {
     169                        /* Be nice, let other fibrils run and try again. */
     170                        async_usleep(IPC_AGAIN_DELAY);
     171                } else if (my_address < 0) {
     172                        /* Some other problem, no sense trying again. */
     173                        rc = my_address;
     174                        goto leave;
     175                }
     176
     177        } while (my_address < 0);
    157178
    158179        rc = usb_device_connection_initialize(connection,
     
    212233 * A session is something inside what any communication occurs.
    213234 * It is expected that sessions would be started right before the transfer
    214  * and ended - see usb_endpoint_pipe_end_session() - after the last
     235 * and ended - see usb_pipe_end_session() - after the last
    215236 * transfer.
    216237 * The reason for this is that session actually opens some communication
     
    223244 * @return Error code.
    224245 */
    225 int usb_endpoint_pipe_start_session(usb_endpoint_pipe_t *pipe)
     246int usb_pipe_start_session(usb_pipe_t *pipe)
    226247{
    227248        assert(pipe);
    228249
    229         if (usb_endpoint_pipe_is_session_started(pipe)) {
     250        if (usb_pipe_is_session_started(pipe)) {
    230251                return EBUSY;
    231252        }
     
    244265/** Ends a session on the endpoint pipe.
    245266 *
    246  * @see usb_endpoint_pipe_start_session
     267 * @see usb_pipe_start_session
    247268 *
    248269 * @param pipe Endpoint pipe to end the session on.
    249270 * @return Error code.
    250271 */
    251 int usb_endpoint_pipe_end_session(usb_endpoint_pipe_t *pipe)
     272int usb_pipe_end_session(usb_pipe_t *pipe)
    252273{
    253274        assert(pipe);
    254275
    255         if (!usb_endpoint_pipe_is_session_started(pipe)) {
     276        if (!usb_pipe_is_session_started(pipe)) {
    256277                return ENOENT;
    257278        }
     
    275296 * @return Whether @p pipe has opened a session.
    276297 */
    277 bool usb_endpoint_pipe_is_session_started(usb_endpoint_pipe_t *pipe)
     298bool usb_pipe_is_session_started(usb_pipe_t *pipe)
    278299{
    279300        return (pipe->hc_phone >= 0);
  • uspace/lib/usb/src/pipesinit.c

    r4fb6d9ee re099f26  
    193193        }
    194194
    195         int rc = usb_endpoint_pipe_initialize(ep_mapping->pipe, wire,
     195        int rc = usb_pipe_initialize(ep_mapping->pipe, wire,
    196196            ep_no, description.transfer_type, endpoint->max_packet_size,
    197197            description.direction);
     
    276276 * @return Error code.
    277277 */
    278 int usb_endpoint_pipe_initialize_from_configuration(
     278int usb_pipe_initialize_from_configuration(
    279279    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    280280    uint8_t *configuration_descriptor, size_t configuration_descriptor_size,
     
    342342 * @return Error code.
    343343 */
    344 int usb_endpoint_pipe_initialize(usb_endpoint_pipe_t *pipe,
     344int usb_pipe_initialize(usb_pipe_t *pipe,
    345345    usb_device_connection_t *connection, usb_endpoint_t endpoint_no,
    346346    usb_transfer_type_t transfer_type, size_t max_packet_size,
     
    367367 * @return Error code.
    368368 */
    369 int usb_endpoint_pipe_initialize_default_control(usb_endpoint_pipe_t *pipe,
     369int usb_pipe_initialize_default_control(usb_pipe_t *pipe,
    370370    usb_device_connection_t *connection)
    371371{
     
    373373        assert(connection);
    374374
    375         int rc = usb_endpoint_pipe_initialize(pipe, connection,
     375        int rc = usb_pipe_initialize(pipe, connection,
    376376            0, USB_TRANSFER_CONTROL, CTRL_PIPE_MIN_PACKET_SIZE,
    377377            USB_DIRECTION_BOTH);
     
    390390 * @return Error code.
    391391 */
    392 int usb_endpoint_pipe_probe_default_control(usb_endpoint_pipe_t *pipe)
     392int usb_pipe_probe_default_control(usb_pipe_t *pipe)
    393393{
    394394        assert(pipe);
     
    408408
    409409        TRY_LOOP(failed_attempts) {
    410                 rc = usb_endpoint_pipe_start_session(pipe);
     410                rc = usb_pipe_start_session(pipe);
    411411                if (rc == EOK) {
    412412                        break;
     
    433433                }
    434434        }
    435         usb_endpoint_pipe_end_session(pipe);
     435        usb_pipe_end_session(pipe);
    436436        if (rc != EOK) {
    437437                return rc;
     
    451451 * @return Error code.
    452452 */
    453 int usb_endpoint_pipe_register(usb_endpoint_pipe_t *pipe,
     453int usb_pipe_register(usb_pipe_t *pipe,
    454454    unsigned int interval,
    455455    usb_hc_connection_t *hc_connection)
     
    479479 * @return Error code.
    480480 */
    481 int usb_endpoint_pipe_unregister(usb_endpoint_pipe_t *pipe,
     481int usb_pipe_unregister(usb_pipe_t *pipe,
    482482    usb_hc_connection_t *hc_connection)
    483483{
  • uspace/lib/usb/src/pipesio.c

    r4fb6d9ee re099f26  
    5858 * @return Error code.
    5959 */
    60 static int usb_endpoint_pipe_read_no_checks(usb_endpoint_pipe_t *pipe,
     60static int usb_pipe_read_no_checks(usb_pipe_t *pipe,
    6161    void *buffer, size_t size, size_t *size_transfered)
    6262{
     
    140140 * @return Error code.
    141141 */
    142 int usb_endpoint_pipe_read(usb_endpoint_pipe_t *pipe,
     142int usb_pipe_read(usb_pipe_t *pipe,
    143143    void *buffer, size_t size, size_t *size_transfered)
    144144{
     
    153153        }
    154154
    155         if (!usb_endpoint_pipe_is_session_started(pipe)) {
     155        if (!usb_pipe_is_session_started(pipe)) {
    156156                return EBADF;
    157157        }
     
    168168        int rc;
    169169
    170         rc = usb_endpoint_pipe_read_no_checks(pipe, buffer, size, &act_size);
     170        rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size);
    171171        if (rc != EOK) {
    172172                return rc;
     
    190190 * @return Error code.
    191191 */
    192 static int usb_endpoint_pipe_write_no_check(usb_endpoint_pipe_t *pipe,
     192static int usb_pipe_write_no_check(usb_pipe_t *pipe,
    193193    void *buffer, size_t size)
    194194{
     
    247247 * @return Error code.
    248248 */
    249 int usb_endpoint_pipe_write(usb_endpoint_pipe_t *pipe,
     249int usb_pipe_write(usb_pipe_t *pipe,
    250250    void *buffer, size_t size)
    251251{
     
    260260        }
    261261
    262         if (!usb_endpoint_pipe_is_session_started(pipe)) {
     262        if (!usb_pipe_is_session_started(pipe)) {
    263263                return EBADF;
    264264        }
     
    272272        }
    273273
    274         int rc = usb_endpoint_pipe_write_no_check(pipe, buffer, size);
     274        int rc = usb_pipe_write_no_check(pipe, buffer, size);
    275275
    276276        return rc;
     
    289289 * @return Error code.
    290290 */
    291 static int usb_endpoint_pipe_control_read_no_check(usb_endpoint_pipe_t *pipe,
     291static int usb_pipe_control_read_no_check(usb_pipe_t *pipe,
    292292    void *setup_buffer, size_t setup_buffer_size,
    293293    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
     
    365365 * @return Error code.
    366366 */
    367 int usb_endpoint_pipe_control_read(usb_endpoint_pipe_t *pipe,
     367int usb_pipe_control_read(usb_pipe_t *pipe,
    368368    void *setup_buffer, size_t setup_buffer_size,
    369369    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
     
    379379        }
    380380
    381         if (!usb_endpoint_pipe_is_session_started(pipe)) {
     381        if (!usb_pipe_is_session_started(pipe)) {
    382382                return EBADF;
    383383        }
     
    389389
    390390        size_t act_size = 0;
    391         int rc = usb_endpoint_pipe_control_read_no_check(pipe,
     391        int rc = usb_pipe_control_read_no_check(pipe,
    392392            setup_buffer, setup_buffer_size,
    393393            data_buffer, data_buffer_size, &act_size);
     
    414414 * @return Error code.
    415415 */
    416 static int usb_endpoint_pipe_control_write_no_check(usb_endpoint_pipe_t *pipe,
     416static int usb_pipe_control_write_no_check(usb_pipe_t *pipe,
    417417    void *setup_buffer, size_t setup_buffer_size,
    418418    void *data_buffer, size_t data_buffer_size)
     
    473473 * @return Error code.
    474474 */
    475 int usb_endpoint_pipe_control_write(usb_endpoint_pipe_t *pipe,
     475int usb_pipe_control_write(usb_pipe_t *pipe,
    476476    void *setup_buffer, size_t setup_buffer_size,
    477477    void *data_buffer, size_t data_buffer_size)
     
    491491        }
    492492
    493         if (!usb_endpoint_pipe_is_session_started(pipe)) {
     493        if (!usb_pipe_is_session_started(pipe)) {
    494494                return EBADF;
    495495        }
     
    500500        }
    501501
    502         int rc = usb_endpoint_pipe_control_write_no_check(pipe,
     502        int rc = usb_pipe_control_write_no_check(pipe,
    503503            setup_buffer, setup_buffer_size, data_buffer, data_buffer_size);
    504504
  • uspace/lib/usb/src/recognise.c

    r4fb6d9ee re099f26  
    247247#undef VENDOR_ONLY_FMT
    248248#undef VENDOR_ONLY_ARGS
     249
     250        /* As a last resort, try fallback driver. */
     251        ADD_MATCHID_OR_RETURN(matches, 10, "usb&interface&fallback");
    249252
    250253        return EOK;
     
    291294        }
    292295       
     296        /* As a last resort, try fallback driver. */
     297        ADD_MATCHID_OR_RETURN(matches, 10, "usb&fallback");
     298
    293299        return EOK;
    294300}
     
    305311 * @return Error code.
    306312 */
    307 int usb_device_create_match_ids(usb_endpoint_pipe_t *ctrl_pipe,
     313int usb_device_create_match_ids(usb_pipe_t *ctrl_pipe,
    308314    match_id_list_t *matches)
    309315{
     
    357363        int rc;
    358364        usb_device_connection_t dev_connection;
    359         usb_endpoint_pipe_t ctrl_pipe;
     365        usb_pipe_t ctrl_pipe;
    360366
    361367        rc = usb_device_connection_initialize(&dev_connection, hc_handle, address);
     
    364370        }
    365371
    366         rc = usb_endpoint_pipe_initialize_default_control(&ctrl_pipe,
     372        rc = usb_pipe_initialize_default_control(&ctrl_pipe,
    367373            &dev_connection);
    368374        if (rc != EOK) {
    369375                goto failure;
    370376        }
    371         rc = usb_endpoint_pipe_probe_default_control(&ctrl_pipe);
     377        rc = usb_pipe_probe_default_control(&ctrl_pipe);
    372378        if (rc != EOK) {
    373379                goto failure;
     
    398404        child->driver_data = dev_data;
    399405
    400         rc = usb_endpoint_pipe_start_session(&ctrl_pipe);
     406        rc = usb_pipe_start_session(&ctrl_pipe);
    401407        if (rc != EOK) {
    402408                goto failure;
     
    408414        }
    409415
    410         rc = usb_endpoint_pipe_end_session(&ctrl_pipe);
     416        rc = usb_pipe_end_session(&ctrl_pipe);
    411417        if (rc != EOK) {
    412418                goto failure;
  • uspace/lib/usb/src/request.c

    r4fb6d9ee re099f26  
    4242/** Generic wrapper for SET requests using standard control request format.
    4343 *
    44  * @see usb_endpoint_pipe_control_write
     44 * @see usb_pipe_control_write
    4545 *
    4646 * @param pipe Pipe used for the communication.
     
    6060 * @retval ERANGE Data buffer too large.
    6161 */
    62 int usb_control_request_set(usb_endpoint_pipe_t *pipe,
     62int usb_control_request_set(usb_pipe_t *pipe,
    6363    usb_request_type_t request_type, usb_request_recipient_t recipient,
    6464    uint8_t request,
     
    9090        setup_packet.length = (uint16_t) data_size;
    9191
    92         int rc = usb_endpoint_pipe_control_write(pipe,
     92        int rc = usb_pipe_control_write(pipe,
    9393            &setup_packet, sizeof(setup_packet),
    9494            data, data_size);
     
    9999 /** Generic wrapper for GET requests using standard control request format.
    100100  *
    101   * @see usb_endpoint_pipe_control_read
     101  * @see usb_pipe_control_read
    102102  *
    103103  * @param pipe Pipe used for the communication.
     
    120120  * @retval ERANGE Data buffer too large.
    121121  */
    122 int usb_control_request_get(usb_endpoint_pipe_t *pipe,
     122int usb_control_request_get(usb_pipe_t *pipe,
    123123    usb_request_type_t request_type, usb_request_recipient_t recipient,
    124124    uint8_t request,
     
    150150        setup_packet.length = (uint16_t) data_size;
    151151
    152         int rc = usb_endpoint_pipe_control_read(pipe,
     152        int rc = usb_pipe_control_read(pipe,
    153153            &setup_packet, sizeof(setup_packet),
    154154            data, data_size, actual_data_size);
     155
     156        return rc;
     157}
     158
     159/** Retrieve status of a USB device.
     160 *
     161 * @param[in] pipe Control endpoint pipe (session must be already started).
     162 * @param[in] index Recipient index (in native endianness).
     163 * @param[in] recipient Recipient of the GET_STATUS request.
     164 * @param[out] status Recipient status (in native endianness).
     165 * @return Error code.
     166 */
     167int usb_request_get_status(usb_pipe_t *pipe,
     168    usb_request_recipient_t recipient, uint16_t index,
     169    uint16_t *status)
     170{
     171        if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0)) {
     172                return EINVAL;
     173        }
     174
     175        if (status == NULL) {
     176                return EBADMEM;
     177        }
     178
     179        uint16_t status_usb_endianess;
     180        size_t data_transfered_size;
     181        int rc = usb_control_request_get(pipe, USB_REQUEST_TYPE_STANDARD,
     182            recipient, USB_DEVREQ_GET_STATUS, 0, uint16_host2usb(index),
     183            &status_usb_endianess, 2, &data_transfered_size);
     184        if (rc != EOK) {
     185                return rc;
     186        }
     187        if (data_transfered_size != 2) {
     188                return ELIMIT;
     189        }
     190
     191        *status = uint16_usb2host(status_usb_endianess);
     192
     193        return EOK;
     194}
     195
     196/** Clear or disable specific device feature.
     197 *
     198 * @param[in] pipe Control endpoint pipe (session must be already started).
     199 * @param[in] request_type Request type (standard/class/vendor).
     200 * @param[in] recipient Recipient of the CLEAR_FEATURE request.
     201 * @param[in] feature_selector Feature selector (in native endianness).
     202 * @param[in] index Recipient index (in native endianness).
     203 * @return Error code.
     204 */
     205int usb_request_clear_feature(usb_pipe_t *pipe,
     206    usb_request_type_t request_type, usb_request_recipient_t recipient,
     207    uint16_t feature_selector, uint16_t index)
     208{
     209        if (request_type == USB_REQUEST_TYPE_STANDARD) {
     210                if ((recipient == USB_REQUEST_RECIPIENT_DEVICE)
     211                    && (index != 0)) {
     212                        return EINVAL;
     213                }
     214        }
     215
     216        int rc = usb_control_request_set(pipe, request_type, recipient,
     217            USB_DEVREQ_CLEAR_FEATURE,
     218            uint16_host2usb(feature_selector), uint16_host2usb(index),
     219            NULL, 0);
     220
     221        return rc;
     222}
     223
     224/** Set or enable specific device feature.
     225 *
     226 * @param[in] pipe Control endpoint pipe (session must be already started).
     227 * @param[in] request_type Request type (standard/class/vendor).
     228 * @param[in] recipient Recipient of the SET_FEATURE request.
     229 * @param[in] feature_selector Feature selector (in native endianness).
     230 * @param[in] index Recipient index (in native endianness).
     231 * @return Error code.
     232 */
     233int usb_request_set_feature(usb_pipe_t *pipe,
     234    usb_request_type_t request_type, usb_request_recipient_t recipient,
     235    uint16_t feature_selector, uint16_t index)
     236{
     237        if (request_type == USB_REQUEST_TYPE_STANDARD) {
     238                if ((recipient == USB_REQUEST_RECIPIENT_DEVICE)
     239                    && (index != 0)) {
     240                        return EINVAL;
     241                }
     242        }
     243
     244        int rc = usb_control_request_set(pipe, request_type, recipient,
     245            USB_DEVREQ_SET_FEATURE,
     246            uint16_host2usb(feature_selector), uint16_host2usb(index),
     247            NULL, 0);
    155248
    156249        return rc;
     
    165258 * @return Error code.
    166259 */
    167 int usb_request_set_address(usb_endpoint_pipe_t *pipe,
     260int usb_request_set_address(usb_pipe_t *pipe,
    168261    usb_address_t new_address)
    169262{
     
    204297 * @return Error code.
    205298 */
    206 int usb_request_get_descriptor(usb_endpoint_pipe_t *pipe,
     299int usb_request_get_descriptor(usb_pipe_t *pipe,
    207300    usb_request_type_t request_type, usb_request_recipient_t recipient,
    208301    uint8_t descriptor_type, uint8_t descriptor_index,
     
    238331 * @return
    239332 */
    240 int usb_request_get_descriptor_alloc(usb_endpoint_pipe_t * pipe,
     333int usb_request_get_descriptor_alloc(usb_pipe_t * pipe,
    241334    usb_request_type_t request_type, usb_request_recipient_t recipient,
    242335    uint8_t descriptor_type, uint8_t descriptor_index,
     
    307400 * @return Error code.
    308401 */
    309 int usb_request_get_device_descriptor(usb_endpoint_pipe_t *pipe,
     402int usb_request_get_device_descriptor(usb_pipe_t *pipe,
    310403    usb_standard_device_descriptor_t *descriptor)
    311404{
     
    349442 * @return Error code.
    350443 */
    351 int usb_request_get_bare_configuration_descriptor(usb_endpoint_pipe_t *pipe,
     444int usb_request_get_bare_configuration_descriptor(usb_pipe_t *pipe,
    352445    int index, usb_standard_configuration_descriptor_t *descriptor)
    353446{
     
    395488 * @return Error code.
    396489 */
    397 int usb_request_get_full_configuration_descriptor(usb_endpoint_pipe_t *pipe,
     490int usb_request_get_full_configuration_descriptor(usb_pipe_t *pipe,
    398491    int index, void *descriptor, size_t descriptor_size, size_t *actual_size)
    399492{
     
    421514 */
    422515int usb_request_get_full_configuration_descriptor_alloc(
    423     usb_endpoint_pipe_t *pipe, int index,
     516    usb_pipe_t *pipe, int index,
    424517    void **descriptor_ptr, size_t *descriptor_size)
    425518{
     
    473566}
    474567
     568/** Update existing or add new USB descriptor to a USB device.
     569 *
     570 * @param[in] pipe Control endpoint pipe (session must be already started).
     571 * @param[in] request_type Request type (standard/class/vendor).
     572 * @param[in] recipient Request recipient (device/interface/endpoint).
     573 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...).
     574 * @param[in] descriptor_index Descriptor index.
     575 * @param[in] language Language index (in native endianness).
     576 * @param[in] buffer Buffer with the new descriptor (in USB endianness).
     577 * @param[in] size Size of the @p buffer in bytes (in native endianness).
     578 * @return Error code.
     579 */
     580int usb_request_set_descriptor(usb_pipe_t *pipe,
     581    usb_request_type_t request_type, usb_request_recipient_t recipient,
     582    uint8_t descriptor_type, uint8_t descriptor_index,
     583    uint16_t language,
     584    void *buffer, size_t size)
     585{
     586        if (buffer == NULL) {
     587                return EBADMEM;
     588        }
     589        if (size == 0) {
     590                return EINVAL;
     591        }
     592
     593        /* FIXME: proper endianness. */
     594        uint16_t wValue = descriptor_index | (descriptor_type << 8);
     595
     596        return usb_control_request_set(pipe,
     597            request_type, recipient,
     598            USB_DEVREQ_SET_DESCRIPTOR,
     599            wValue, language,
     600            buffer, size);
     601}
     602
     603/** Get current configuration value of USB device.
     604 *
     605 * @param[in] pipe Control endpoint pipe (session must be already started).
     606 * @param[out] configuration_value Current configuration value.
     607 * @return Error code.
     608 */
     609int usb_request_get_configuration(usb_pipe_t *pipe,
     610    uint8_t *configuration_value)
     611{
     612        uint8_t value;
     613        size_t actual_size;
     614
     615        int rc = usb_control_request_get(pipe,
     616            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
     617            USB_DEVREQ_GET_CONFIGURATION,
     618            0, 0,
     619            &value, 1, &actual_size);
     620
     621        if (rc != EOK) {
     622                return rc;
     623        }
     624        if (actual_size != 1) {
     625                return ELIMIT;
     626        }
     627
     628        if (configuration_value != NULL) {
     629                *configuration_value = value;
     630        }
     631
     632        return EOK;
     633}
     634
    475635/** Set configuration of USB device.
    476636 *
     
    479639 * @return Error code.
    480640 */
    481 int usb_request_set_configuration(usb_endpoint_pipe_t *pipe,
     641int usb_request_set_configuration(usb_pipe_t *pipe,
    482642    uint8_t configuration_value)
    483643{
     
    491651}
    492652
     653/** Get selected alternate setting for USB interface.
     654 *
     655 * @param[in] pipe Control endpoint pipe (session must be already started).
     656 * @param[in] interface_index Interface index.
     657 * @param[out] alternate_setting Alternate setting for the interface.
     658 * @return Error code.
     659 */
     660int usb_request_get_interface(usb_pipe_t *pipe,
     661    uint8_t interface_index, uint8_t *alternate_setting)
     662{
     663        uint8_t value;
     664        size_t actual_size;
     665
     666        int rc = usb_control_request_get(pipe,
     667            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
     668            USB_DEVREQ_GET_INTERFACE,
     669            0, uint16_host2usb((uint16_t) interface_index),
     670            &value, 1, &actual_size);
     671
     672        if (rc != EOK) {
     673                return rc;
     674        }
     675        if (actual_size != 1) {
     676                return ELIMIT;
     677        }
     678
     679        if (alternate_setting != NULL) {
     680                *alternate_setting = value;
     681        }
     682
     683        return EOK;
     684}
     685
     686/** Select alternate setting for USB interface.
     687 *
     688 * @param[in] pipe Control endpoint pipe (session must be already started).
     689 * @param[in] interface_index Interface index.
     690 * @param[in] alternate_setting Alternate setting to select.
     691 * @return Error code.
     692 */
     693int usb_request_set_interface(usb_pipe_t *pipe,
     694    uint8_t interface_index, uint8_t alternate_setting)
     695{
     696        return usb_control_request_set(pipe,
     697            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
     698            USB_DEVREQ_SET_INTERFACE,
     699            uint16_host2usb((uint16_t) alternate_setting),
     700            uint16_host2usb((uint16_t) interface_index),
     701            NULL, 0);
     702}
     703
    493704/** Get list of supported languages by USB device.
    494705 *
     
    499710 * @return Error code.
    500711 */
    501 int usb_request_get_supported_languages(usb_endpoint_pipe_t *pipe,
     712int usb_request_get_supported_languages(usb_pipe_t *pipe,
    502713    l18_win_locales_t **languages_ptr, size_t *languages_count)
    503714{
     
    571782 * @return Error code.
    572783 */
    573 int usb_request_get_string(usb_endpoint_pipe_t *pipe,
     784int usb_request_get_string(usb_pipe_t *pipe,
    574785    size_t index, l18_win_locales_t lang, char **string_ptr)
    575786{
  • uspace/lib/usb/src/usb.c

    r4fb6d9ee re099f26  
    3636#include <errno.h>
    3737
     38#define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
     39
     40static const char *str_speed[] = {
     41        "low",
     42        "full",
     43        "high"
     44};
     45
     46static const char *str_transfer_type[] = {
     47        "control",
     48        "isochronous",
     49        "bulk",
     50        "interrupt"
     51};
     52
     53static const char *str_transfer_type_short[] = {
     54        "ctrl",
     55        "iso",
     56        "bulk",
     57        "intr"
     58};
    3859
    3960/** String representation for USB transfer type.
     
    4263 * @return Transfer type as a string (in English).
    4364 */
    44 const char * usb_str_transfer_type(usb_transfer_type_t t)
     65const char *usb_str_transfer_type(usb_transfer_type_t t)
    4566{
    46         switch (t) {
    47                 case USB_TRANSFER_ISOCHRONOUS:
    48                         return "isochronous";
    49                 case USB_TRANSFER_INTERRUPT:
    50                         return "interrupt";
    51                 case USB_TRANSFER_CONTROL:
    52                         return "control";
    53                 case USB_TRANSFER_BULK:
    54                         return "bulk";
    55                 default:
    56                         return "unknown";
     67        if (t >= ARR_SIZE(str_transfer_type)) {
     68                return "invalid";
    5769        }
     70        return str_transfer_type[t];
     71}
     72
     73/** String representation for USB transfer type (short version).
     74 *
     75 * @param t Transfer type.
     76 * @return Transfer type as a short string for debugging messages.
     77 */
     78const char *usb_str_transfer_type_short(usb_transfer_type_t t)
     79{
     80        if (t >= ARR_SIZE(str_transfer_type_short)) {
     81                return "invl";
     82        }
     83        return str_transfer_type_short[t];
     84}
     85
     86/** String representation of USB speed.
     87 *
     88 * @param s The speed.
     89 * @return USB speed as a string (in English).
     90 */
     91const char *usb_str_speed(usb_speed_t s)
     92{
     93        if (s >= ARR_SIZE(str_speed)) {
     94                return "invalid";
     95        }
     96        return str_speed[s];
    5897}
    5998
Note: See TracChangeset for help on using the changeset viewer.