Changes in / [9e195e2c:456aea3] in mainline


Ignore:
Files:
63 added
64 deleted
81 edited

Legend:

Unmodified
Added
Removed
  • .bzrignore

    r9e195e2c r456aea3  
    4949./uspace/app/killall/killall
    5050./uspace/app/klog/klog
    51 ./uspace/app/lsusb/lsusb
    5251./uspace/app/mkfat/mkfat
    5352./uspace/app/netstart/netstart
  • boot/Makefile.common

    r9e195e2c r456aea3  
    128128        $(USPACE_PATH)/app/killall/killall \
    129129        $(USPACE_PATH)/app/mkfat/mkfat \
    130         $(USPACE_PATH)/app/lsusb/lsusb \
    131130        $(USPACE_PATH)/app/sbi/sbi \
    132131        $(USPACE_PATH)/app/redir/redir \
     
    141140        $(USPACE_PATH)/app/stats/stats \
    142141        $(USPACE_PATH)/app/sysinfo/sysinfo \
     142        $(USPACE_PATH)/app/tasks/tasks \
    143143        $(USPACE_PATH)/app/top/top \
    144144        $(USPACE_PATH)/app/usbinfo/usbinfo \
     145        $(USPACE_PATH)/app/virtusbkbd/vuk \
    145146        $(USPACE_PATH)/app/vuhid/vuh \
    146147        $(USPACE_PATH)/app/websrv/websrv
  • uspace/Makefile

    r9e195e2c r456aea3  
    4141        app/killall \
    4242        app/klog \
    43         app/lsusb \
    4443        app/mkfat \
    4544        app/redir \
     
    5251        app/top \
    5352        app/usbinfo \
     53        app/virtusbkbd \
    5454        app/vuhid \
    5555        app/netecho \
     
    177177ifeq ($(UARCH),amd64)
    178178        LIBS += lib/usb
    179         LIBS += lib/usbhost
    180         LIBS += lib/usbdev
    181         LIBS += lib/usbhid
    182179        LIBS += lib/usbvirt
    183180endif
     
    185182ifeq ($(UARCH),ia32)
    186183        LIBS += lib/usb
    187         LIBS += lib/usbhost
    188         LIBS += lib/usbdev
    189         LIBS += lib/usbhid
    190184        LIBS += lib/usbvirt
    191185endif
  • uspace/Makefile.common

    r9e195e2c r456aea3  
    8888
    8989LIBUSB_PREFIX = $(LIB_PREFIX)/usb
    90 LIBUSBHOST_PREFIX = $(LIB_PREFIX)/usbhost
    91 LIBUSBDEV_PREFIX = $(LIB_PREFIX)/usbdev
    92 LIBUSBHID_PREFIX = $(LIB_PREFIX)/usbhid
    9390LIBUSBVIRT_PREFIX = $(LIB_PREFIX)/usbvirt
    9491LIBDRV_PREFIX = $(LIB_PREFIX)/drv
  • uspace/app/tester/Makefile

    r9e195e2c r456aea3  
    3131BINARY = tester
    3232
     33LIBS += $(LIBUSB_PREFIX)/libusb.a
     34EXTRA_CFLAGS += -I$(LIBUSB_PREFIX)/include
     35
    3336SOURCES = \
    3437        tester.c \
     38        adt/usbaddrkeep.c \
    3539        thread/thread1.c \
    3640        print/print1.c \
  • uspace/app/tester/tester.c

    r9e195e2c r456aea3  
    6464#include "mm/mapping1.def"
    6565#include "hw/serial/serial1.def"
     66#include "adt/usbaddrkeep.def"
    6667#include "hw/misc/virtchar1.def"
    6768#include "devs/devman1.def"
  • uspace/app/tester/tester.h

    r9e195e2c r456aea3  
    8080extern const char *test_mapping1(void);
    8181extern const char *test_serial1(void);
     82extern const char *test_usbaddrkeep(void);
    8283extern const char *test_virtchar1(void);
    8384extern const char *test_devman1(void);
  • uspace/app/usbinfo/Makefile

    r9e195e2c r456aea3  
    3030BINARY = usbinfo
    3131
    32 LIBS = \
    33         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    34         $(LIBUSB_PREFIX)/libusb.a \
    35         $(LIBDRV_PREFIX)/libdrv.a
    36 EXTRA_CFLAGS = \
    37         -I$(LIBUSB_PREFIX)/include \
    38         -I$(LIBUSBDEV_PREFIX)/include \
    39         -I$(LIBDRV_PREFIX)/include
     32LIBS = $(LIBUSB_PREFIX)/libusb.a $(LIBDRV_PREFIX)/libdrv.a
     33EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIBDRV_PREFIX)/include
    4034
    4135SOURCES = \
  • uspace/app/usbinfo/dev.c

    r9e195e2c r456aea3  
    4040#include "usbinfo.h"
    4141
    42 usbinfo_device_t *prepare_device(const char *name,
    43     devman_handle_t hc_handle, usb_address_t dev_addr)
     42usbinfo_device_t *prepare_device(devman_handle_t hc_handle,
     43    usb_address_t dev_addr)
    4444{
    4545        usbinfo_device_t *dev = malloc(sizeof(usbinfo_device_t));
     
    5555        if (rc != EOK) {
    5656                fprintf(stderr,
    57                     NAME ": failed to create connection to device %s: %s.\n",
    58                     name, str_error(rc));
     57                    NAME ": failed to create connection to the device: %s.\n",
     58                    str_error(rc));
    5959                goto leave;
    6060        }
     
    6464        if (rc != EOK) {
    6565                fprintf(stderr,
    66                     NAME ": failed to create default control pipe to %s: %s.\n",
    67                     name, str_error(rc));
     66                    NAME ": failed to create default control pipe: %s.\n",
     67                    str_error(rc));
    6868                goto leave;
    6969        }
     
    7171        rc = usb_pipe_probe_default_control(&dev->ctrl_pipe);
    7272        if (rc != EOK) {
    73                 if (rc == ENOENT) {
    74                         fprintf(stderr, NAME ": " \
    75                             "device %s not present or malfunctioning.\n",
    76                             name);
    77                 } else {
    78                         fprintf(stderr, NAME ": " \
    79                             "probing default control pipe of %s failed: %s.\n",
    80                             name, str_error(rc));
    81                 }
     73                fprintf(stderr,
     74                    NAME ": probing default control pipe failed: %s.\n",
     75                    str_error(rc));
    8276                goto leave;
    8377        }
     
    9084        if (rc != EOK) {
    9185                fprintf(stderr,
    92                     NAME ": failed to retrieve device descriptor of %s: %s.\n",
    93                     name, str_error(rc));
     86                    NAME ": failed to retrieve device descriptor: %s.\n",
     87                    str_error(rc));
    9488                goto leave;
    9589        }
     
    9993            &dev->full_configuration_descriptor_size);
    10094        if (rc != EOK) {
    101                 fprintf(stderr, NAME ": " \
    102                     "failed to retrieve configuration descriptor of %s: %s.\n",
    103                     name, str_error(rc));
     95                fprintf(stderr,
     96                    NAME ": failed to retrieve configuration descriptor: %s.\n",
     97                    str_error(rc));
    10498                goto leave;
    10599        }
  • uspace/app/usbinfo/info.c

    r9e195e2c r456aea3  
    4141#include <usb/request.h>
    4242#include <usb/classes/classes.h>
     43#include <usb/classes/hid.h>
    4344#include <usb/classes/hub.h>
    4445#include "usbinfo.h"
  • uspace/app/usbinfo/main.c

    r9e195e2c r456aea3  
    4545#include <usb/usbdevice.h>
    4646#include <usb/pipes.h>
    47 #include <usb/host.h>
    48 #include <usb/driver.h>
    4947#include "usbinfo.h"
    50 
    51 static bool try_parse_class_and_address(const char *path,
    52     devman_handle_t *out_hc_handle, usb_address_t *out_device_address)
    53 {
    54         size_t class_index;
    55         size_t address;
    56         int rc;
    57         char *ptr;
    58 
    59         rc = str_size_t(path, &ptr, 10, false, &class_index);
    60         if (rc != EOK) {
    61                 return false;
    62         }
    63         if ((*ptr == ':') || (*ptr == '.')) {
    64                 ptr++;
    65         } else {
    66                 return false;
    67         }
    68         rc = str_size_t(ptr, NULL, 10, true, &address);
    69         if (rc != EOK) {
    70                 return false;
    71         }
    72         rc = usb_ddf_get_hc_handle_by_class(class_index, out_hc_handle);
    73         if (rc != EOK) {
    74                 return false;
    75         }
    76         if (out_device_address != NULL) {
    77                 *out_device_address = (usb_address_t) address;
    78         }
    79         return true;
    80 }
    8148
    8249static bool resolve_hc_handle_and_dev_addr(const char *devpath,
     
    9360        if (str_cmp(devpath, "virt") == 0) {
    9461                devpath = "/virt/usbhc/usb00_a1/usb00_a2";
    95         }
    96 
    97         if (try_parse_class_and_address(devpath,
    98             out_hc_handle, out_device_address)) {
    99                 return true;
    10062        }
    10163
     
    309271                }
    310272
    311                 usbinfo_device_t *dev = prepare_device(devpath,
    312                     hc_handle, dev_addr);
     273                usbinfo_device_t *dev = prepare_device(hc_handle, dev_addr);
    313274                if (dev == NULL) {
    314275                        continue;
  • uspace/app/usbinfo/usbinfo.h

    r9e195e2c r456aea3  
    7171}
    7272
    73 usbinfo_device_t *prepare_device(const char *, devman_handle_t, usb_address_t);
     73usbinfo_device_t *prepare_device(devman_handle_t, usb_address_t);
    7474void destroy_device(usbinfo_device_t *);
    7575
  • uspace/app/vuhid/Makefile

    r9e195e2c r456aea3  
    3434LIBS = \
    3535        $(LIBUSBVIRT_PREFIX)/libusbvirt.a \
    36         $(LIBUSBHID_PREFIX)/libusbhid.a \
    37         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    3836        $(LIBUSB_PREFIX)/libusb.a
    3937EXTRA_CFLAGS = \
    4038        -I$(LIBUSB_PREFIX)/include \
    41         -I$(LIBUSBDEV_PREFIX)/include \
    42         -I$(LIBUSBHID_PREFIX)/include \
    4339        -I$(LIBUSBVIRT_PREFIX)/include \
    4440        -I$(LIBDRV_PREFIX)/include
  • uspace/app/vuhid/device.c

    r9e195e2c r456aea3  
    7777{
    7878        vuhid_interface_t *iface = arg;
    79         vuhid_data_t *hid_data = iface->vuhid_data;
    8079
    8180        if (iface->live != NULL) {
    8281                iface->live(iface);
    8382        }
    84 
    85         fibril_mutex_lock(&hid_data->iface_count_mutex);
    86         hid_data->iface_died_count++;
    87         fibril_condvar_broadcast(&hid_data->iface_count_cv);
    88         fibril_mutex_unlock(&hid_data->iface_count_mutex);
    8983
    9084        return EOK;
     
    116110        if ((iface->in_data_size == 0) && (iface->out_data_size == 0)) {
    117111                return EEMPTY;
    118         }
    119 
    120         // FIXME - we shall set vuhid_data to NULL in the main() rather
    121         // than to depend on individual interfaces
    122         /* Already used interface. */
    123         if (iface->vuhid_data != NULL) {
    124                 return EEXISTS;
    125112        }
    126113
     
    265252
    266253        /* Launch the "life" fibril. */
    267         iface->vuhid_data = hid_data;
    268254        fid_t life_fibril = fibril_create(interface_life_fibril, iface);
    269255        if (life_fibril == 0) {
     
    324310            += total_descr_size;
    325311
    326         hid_data->iface_count++;
    327312        fibril_add_ready(life_fibril);
    328313
     
    346331}
    347332
    348 void wait_for_interfaces_death(usbvirt_device_t *dev)
    349 {
    350         vuhid_data_t *hid_data = dev->device_data;
    351 
    352         fibril_mutex_lock(&hid_data->iface_count_mutex);
    353         while (hid_data->iface_died_count < hid_data->iface_count) {
    354                 fibril_condvar_wait(&hid_data->iface_count_cv,
    355                     &hid_data->iface_count_mutex);
    356         }
    357         fibril_mutex_unlock(&hid_data->iface_count_mutex);
    358 }
    359333
    360334/** @}
  • uspace/app/vuhid/hids/bootkbd.c

    r9e195e2c r456aea3  
    3939#include <usb/classes/hidut.h>
    4040
    41 #include "../report.h"
     41#include "../../virtusbkbd/report.h"
    4242
    4343uint8_t report_descriptor[] = {
     
    169169        .on_data_out = on_data_out,
    170170
    171         .live = live,
    172 
    173         .vuhid_data = NULL
     171        .live = live
    174172};
    175173
  • uspace/app/vuhid/main.c

    r9e195e2c r456aea3  
    132132        .in_endpoint_first_free = 1,
    133133        .out_endpoints_mapping = { NULL },
    134         .out_endpoint_first_free = 1,
    135 
    136         .iface_count = 0,
    137         .iface_died_count = 0
    138         // mutex and CV must be initialized elsewhere
     134        .out_endpoint_first_free = 1
    139135};
    140 
    141136
    142137/** Keyboard device.
     
    156151
    157152        usb_log_enable(USB_LOG_LEVEL_DEBUG2, "vusbhid");
    158 
    159         fibril_mutex_initialize(&vuhid_data.iface_count_mutex);
    160         fibril_condvar_initialize(&vuhid_data.iface_count_cv);
    161153
    162154        /* Determine which interfaces to initialize. */
     
    190182        printf("Connected to VHCD...\n");
    191183
    192         wait_for_interfaces_death(&hid_dev);
     184        while (true) {
     185                async_usleep(10 * 1000 * 1000);
     186        }
    193187       
    194188        printf("Terminating...\n");
    195189       
    196         usbvirt_device_unplug(&hid_dev);
    197 
    198190        return 0;
    199191}
  • uspace/app/vuhid/virthid.h

    r9e195e2c r456aea3  
    3838#include <usb/usb.h>
    3939#include <usbvirt/device.h>
    40 #include <fibril_synch.h>
    4140
    4241#define VUHID_ENDPOINT_MAX USB11_ENDPOINT_MAX
     
    4443
    4544typedef struct vuhid_interface vuhid_interface_t;
    46 
    47 typedef struct {
    48         vuhid_interface_t *in_endpoints_mapping[VUHID_ENDPOINT_MAX];
    49         size_t in_endpoint_first_free;
    50         vuhid_interface_t *out_endpoints_mapping[VUHID_ENDPOINT_MAX];
    51         size_t out_endpoint_first_free;
    52         vuhid_interface_t *interface_mapping[VUHID_INTERFACE_MAX];
    53 
    54         fibril_mutex_t iface_count_mutex;
    55         fibril_condvar_t iface_count_cv;
    56         size_t iface_count;
    57         size_t iface_died_count;
    58 } vuhid_data_t;
    5945
    6046struct vuhid_interface {
     
    7763
    7864        void *interface_data;
     65};
    7966
    80         vuhid_data_t *vuhid_data;
    81 };
     67typedef struct {
     68        vuhid_interface_t *in_endpoints_mapping[VUHID_ENDPOINT_MAX];
     69        size_t in_endpoint_first_free;
     70        vuhid_interface_t *out_endpoints_mapping[VUHID_ENDPOINT_MAX];
     71        size_t out_endpoint_first_free;
     72        vuhid_interface_t *interface_mapping[VUHID_INTERFACE_MAX];
     73} vuhid_data_t;
    8274
    8375typedef struct {
     
    9284
    9385int add_interface_by_id(vuhid_interface_t **, const char *, usbvirt_device_t *);
    94 void wait_for_interfaces_death(usbvirt_device_t *);
    9586
    9687#endif
  • uspace/doc/doxygroups.h

    r9e195e2c r456aea3  
    220220
    221221        /**
    222          * @defgroup lsusb HelenOS version of lsusb command
    223          * @ingroup usb
    224          * @brief Application for listing USB host controllers.
    225          * @details
    226          * List all found host controllers.
    227          */
    228 
    229         /**
    230222         * @defgroup drvusbmid USB multi interface device driver
    231223         * @ingroup usb
  • uspace/drv/ehci-hcd/Makefile

    r9e195e2c r456aea3  
    2828
    2929USPACE_PREFIX = ../..
    30 
    31 LIBS = \
    32         $(LIBUSBHOST_PREFIX)/libusbhost.a \
    33         $(LIBUSB_PREFIX)/libusb.a \
    34         $(LIBDRV_PREFIX)/libdrv.a
    35 EXTRA_CFLAGS += \
    36         -I$(LIBUSB_PREFIX)/include \
    37         -I$(LIBUSBHOST_PREFIX)/include \
    38         -I$(LIBDRV_PREFIX)/include
    39 
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
    4032BINARY = ehci-hcd
    4133
  • uspace/drv/ehci-hcd/hc_iface.c

    r9e195e2c r456aea3  
    106106}
    107107
    108 /** Find device handle by USB address.
    109  *
    110  * @param[in] fun DDF function that was called.
    111  * @param[in] address Address in question.
    112  * @param[out] handle Where to store device handle if found.
    113  * @return Error code.
    114  */
    115 static int find_by_address(ddf_fun_t *fun, usb_address_t address,
    116     devman_handle_t *handle)
    117 {
    118         UNSUPPORTED("find_by_address");
    119 
    120         return ENOTSUP;
    121 }
    122 
    123108/** Release previously requested address.
    124109 *
     
    336321        .request_address = request_address,
    337322        .bind_address = bind_address,
    338         .find_by_address = find_by_address,
    339323        .release_address = release_address,
    340324
  • uspace/drv/ehci-hcd/main.c

    r9e195e2c r456aea3  
    9797        }
    9898        hc_fun->ops = &hc_ops;
     99        ret = ddf_fun_bind(hc_fun);
    99100
    100         ret = ddf_fun_bind(hc_fun);
    101101        CHECK_RET_RETURN(ret,
    102102            "Failed to bind EHCI function: %s.\n",
    103             str_error(ret));
    104         ret = ddf_fun_add_to_class(hc_fun, USB_HC_DDF_CLASS_NAME);
    105         CHECK_RET_RETURN(ret,
    106             "Failed to add EHCI to HC class: %s.\n",
    107103            str_error(ret));
    108104
  • uspace/drv/ehci-hcd/pci.c

    r9e195e2c r456aea3  
    5454
    5555#define CMD_OFFSET 0x0
    56 #define STS_OFFSET 0x4
    57 #define CFG_OFFSET 0x40
     56#define CONFIGFLAG_OFFSET 0x40
    5857
    5958#define USBCMD_RUN 1
     
    265264         * It would prevent pre-OS code from interfering. */
    266265        ret = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE),
    267            IPC_M_CONFIG_SPACE_WRITE_32, eecp + USBLEGCTLSTS_OFFSET,
    268            0xe0000000);
     266           IPC_M_CONFIG_SPACE_WRITE_32, eecp + USBLEGCTLSTS_OFFSET, 0);
    269267        CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) zero USBLEGCTLSTS.\n", ret);
     268        usb_log_debug("Zeroed USBLEGCTLSTS register.\n");
    270269
    271270        /* Read again Legacy Support and Control register */
     
    292291        volatile uint32_t *usbcmd =
    293292            (uint32_t*)((uint8_t*)registers + operation_offset + CMD_OFFSET);
    294         volatile uint32_t *usbsts =
    295             (uint32_t*)((uint8_t*)registers + operation_offset + STS_OFFSET);
    296293        volatile uint32_t *usbconfigured =
    297             (uint32_t*)((uint8_t*)registers + operation_offset + CFG_OFFSET);
     294            (uint32_t*)((uint8_t*)registers + operation_offset
     295            + CONFIGFLAG_OFFSET);
    298296        usb_log_debug("USBCMD value: %x.\n", *usbcmd);
    299297        if (*usbcmd & USBCMD_RUN) {
    300298                *usbcmd = 0;
    301                 while (!(*usbsts & (1 << 12))); /*wait until hc is halted */
    302299                *usbconfigured = 0;
    303300                usb_log_info("EHCI turned off.\n");
     
    305302                usb_log_info("EHCI was not running.\n");
    306303        }
    307         usb_log_debug("Registers: %x(0x00080000):%x(0x00001000):%x(0x0).\n",
    308             *usbcmd, *usbsts, *usbconfigured);
    309304
    310305        async_hangup(parent_phone);
  • uspace/drv/ohci/Makefile

    r9e195e2c r456aea3  
    2828
    2929USPACE_PREFIX = ../..
    30 
    31 LIBS = \
    32         $(LIBUSBHOST_PREFIX)/libusbhost.a \
    33         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    34         $(LIBUSB_PREFIX)/libusb.a \
    35         $(LIBDRV_PREFIX)/libdrv.a
    36 EXTRA_CFLAGS += \
    37         -I$(LIBUSB_PREFIX)/include \
    38         -I$(LIBUSBDEV_PREFIX)/include \
    39         -I$(LIBUSBHOST_PREFIX)/include \
    40         -I$(LIBDRV_PREFIX)/include
    41 
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
    4232BINARY = ohci
    4333
  • uspace/drv/ohci/hc.c

    r9e195e2c r456aea3  
    4040#include <usb/usb.h>
    4141#include <usb/ddfiface.h>
     42#include <usb/usbdevice.h>
    4243
    4344#include "hc.h"
     
    4849static int interrupt_emulator(hc_t *instance);
    4950static void hc_gain_control(hc_t *instance);
     51static void hc_init_hw(hc_t *instance);
    5052static int hc_init_transfer_lists(hc_t *instance);
    5153static int hc_init_memory(hc_t *instance);
     
    9092                usb_log_error("Failed add root hub match-id.\n");
    9193        }
    92         ret = ddf_fun_bind(hub_fun);
    9394        return ret;
    9495}
    9596/*----------------------------------------------------------------------------*/
    96 int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts)
     97int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
     98    uintptr_t regs, size_t reg_size, bool interrupts)
    9799{
    98100        assert(instance);
     
    109111            ret, str_error(ret));
    110112
    111         list_initialize(&instance->pending_batches);
    112113        usb_device_keeper_init(&instance->manager);
    113114        ret = usb_endpoint_manager_init(&instance->ep_manager,
     
    116117            str_error(ret));
    117118
     119        hc_gain_control(instance);
    118120        ret = hc_init_memory(instance);
    119121        CHECK_RET_RETURN(ret, "Failed to create OHCI memory structures: %s.\n",
    120122            str_error(ret));
    121 #undef CHECK_RET_RETURN
    122 
    123 
    124 //      hc_init_hw(instance);
    125         hc_gain_control(instance);
     123        hc_init_hw(instance);
    126124        fibril_mutex_initialize(&instance->guard);
    127125
     
    134132        }
    135133
     134        list_initialize(&instance->pending_batches);
     135#undef CHECK_RET_RETURN
    136136        return EOK;
    137137}
     
    287287{
    288288        assert(instance);
    289         usb_log_debug("OHCI(%p) interrupt: %x.\n", instance, status);
     289        usb_log_debug("OHCI interrupt: %x.\n", status);
    290290        if ((status & ~I_SF) == 0) /* ignore sof status */
    291291                return;
     
    339339            (uint32_t*)((char*)instance->registers + 0x100);
    340340        usb_log_debug("OHCI legacy register %p: %x.\n",
    341             ohci_emulation_reg, *ohci_emulation_reg);
    342         /* Do not change A20 state */
    343         *ohci_emulation_reg &= 0x100;
    344         usb_log_debug("OHCI legacy register %p: %x.\n",
    345             ohci_emulation_reg, *ohci_emulation_reg);
     341                ohci_emulation_reg, *ohci_emulation_reg);
     342        *ohci_emulation_reg &= ~0x1;
    346343
    347344        /* Interrupt routing enabled => smm driver is active */
     
    353350                }
    354351                usb_log_info("SMM driver: Ownership taken.\n");
    355                 instance->registers->control &= (C_HCFS_RESET << C_HCFS_SHIFT);
    356                 async_usleep(50000);
    357352                return;
    358353        }
     
    380375}
    381376/*----------------------------------------------------------------------------*/
    382 void hc_start_hw(hc_t *instance)
     377void hc_init_hw(hc_t *instance)
    383378{
    384379        /* OHCI guide page 42 */
     
    479474{
    480475        assert(instance);
    481 
    482         bzero(&instance->rh, sizeof(instance->rh));
    483476        /* Init queues */
    484477        hc_init_transfer_lists(instance);
  • uspace/drv/ohci/hc.h

    r9e195e2c r456aea3  
    7777int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun);
    7878
    79 int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts);
    80 
    81 void hc_start_hw(hc_t *instance);
     79int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
     80     uintptr_t regs, size_t reg_size, bool interrupts);
    8281
    8382/** Safely dispose host controller internal structures
  • uspace/drv/ohci/hw_struct/endpoint_descriptor.h

    r9e195e2c r456aea3  
    4040#include <usb/host/endpoint.h>
    4141
    42 #include "../utils/malloc32.h"
     42#include "utils/malloc32.h"
    4343#include "transfer_descriptor.h"
    4444
  • uspace/drv/ohci/hw_struct/transfer_descriptor.c

    r9e195e2c r456aea3  
    3333 */
    3434#include <usb/usb.h>
     35#include "utils/malloc32.h"
     36
    3537#include "transfer_descriptor.h"
    3638
  • uspace/drv/ohci/hw_struct/transfer_descriptor.h

    r9e195e2c r456aea3  
    3737#include <bool.h>
    3838#include <stdint.h>
    39 #include "../utils/malloc32.h"
     39#include "utils/malloc32.h"
    4040
    4141#include "completion_codes.h"
  • uspace/drv/ohci/iface.c

    r9e195e2c r456aea3  
    122122        return EOK;
    123123}
    124 
    125 
    126 /** Find device handle by address interface function.
    127  *
    128  * @param[in] fun DDF function that was called.
    129  * @param[in] address Address in question.
    130  * @param[out] handle Where to store device handle if found.
    131  * @return Error code.
    132  */
    133 static int find_by_address(ddf_fun_t *fun, usb_address_t address,
    134     devman_handle_t *handle)
    135 {
    136         assert(fun);
    137         hc_t *hc = fun_to_hc(fun);
    138         assert(hc);
    139         bool found =
    140             usb_device_keeper_find_by_address(&hc->manager, address, handle);
    141         return found ? EOK : ENOENT;
    142 }
    143 
    144124/*----------------------------------------------------------------------------*/
    145125/** Release address interface function
     
    422402        .request_address = request_address,
    423403        .bind_address = bind_address,
    424         .find_by_address = find_by_address,
    425404        .release_address = release_address,
    426405
  • uspace/drv/ohci/main.c

    r9e195e2c r456aea3  
    4343#define NAME "ohci"
    4444
    45 /** Initializes a new ddf driver instance of OHCI hcd.
    46  *
    47  * @param[in] device DDF instance of the device to initialize.
    48  * @return Error code.
    49  */
    50 static int ohci_add_device(ddf_dev_t *device)
    51 {
    52         usb_log_debug("ohci_add_device() called\n");
    53         assert(device);
    54 
    55         int ret = device_setup_ohci(device);
    56         if (ret != EOK) {
    57                 usb_log_error("Failed to initialize OHCI driver: %s.\n",
    58                     str_error(ret));
    59                 return ret;
    60         }
    61         usb_log_info("Controlling new OHCI device '%s'.\n", device->name);
    62 
    63         return EOK;
    64 }
     45static int ohci_add_device(ddf_dev_t *device);
    6546/*----------------------------------------------------------------------------*/
    6647static driver_ops_t ohci_driver_ops = {
     
    7253        .driver_ops = &ohci_driver_ops
    7354};
     55/*----------------------------------------------------------------------------*/
     56/** Initializes a new ddf driver instance of OHCI hcd.
     57 *
     58 * @param[in] device DDF instance of the device to initialize.
     59 * @return Error code.
     60 */
     61int ohci_add_device(ddf_dev_t *device)
     62{
     63        usb_log_debug("ohci_add_device() called\n");
     64        assert(device);
     65        ohci_t *ohci = malloc(sizeof(ohci_t));
     66        if (ohci == NULL) {
     67                usb_log_error("Failed to allocate OHCI driver.\n");
     68                return ENOMEM;
     69        }
     70
     71        int ret = ohci_init(ohci, device);
     72        if (ret != EOK) {
     73                usb_log_error("Failed to initialize OHCI driver: %s.\n",
     74                    str_error(ret));
     75                return ret;
     76        }
     77        device->driver_data = ohci;
     78
     79        usb_log_info("Controlling new OHCI device `%s'.\n", device->name);
     80
     81        return EOK;
     82}
    7483/*----------------------------------------------------------------------------*/
    7584/** Initializes global driver structures (NONE).
     
    8493{
    8594        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
     95        sleep(5);
    8696        return ddf_driver_main(&ohci_driver);
    8797}
  • uspace/drv/ohci/ohci.c

    r9e195e2c r456aea3  
    4444#include "iface.h"
    4545#include "pci.h"
    46 #include "hc.h"
    47 #include "root_hub.h"
    48 
    49 typedef struct ohci {
    50         ddf_fun_t *hc_fun;
    51         ddf_fun_t *rh_fun;
    52 
    53         hc_t hc;
    54         rh_t rh;
    55 } ohci_t;
    56 
    57 static inline ohci_t * dev_to_ohci(ddf_dev_t *dev)
    58 {
    59         assert(dev);
    60         assert(dev->driver_data);
    61         return dev->driver_data;
    62 }
    6346
    6447/** IRQ handling callback, identifies device
     
    7053static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
    7154{
    72         hc_t *hc = &dev_to_ohci(dev)->hc;
     55        assert(dev);
     56        hc_t *hc = &((ohci_t*)dev->driver_data)->hc;
     57        uint16_t status = IPC_GET_ARG1(*call);
    7358        assert(hc);
    74         const uint16_t status = IPC_GET_ARG1(*call);
    7559        hc_interrupt(hc, status);
    7660}
     
    8670{
    8771        assert(fun);
    88         usb_device_keeper_t *manager = &dev_to_ohci(fun->dev)->hc.manager;
     72        usb_device_keeper_t *manager = &((ohci_t*)fun->dev->driver_data)->hc.manager;
    8973
    9074        usb_address_t addr = usb_device_keeper_find(manager, handle);
     
    10993    ddf_fun_t *fun, devman_handle_t *handle)
    11094{
    111         assert(fun);
    112         ddf_fun_t *hc_fun = dev_to_ohci(fun->dev)->hc_fun;
    113         assert(hc_fun);
    114 
    115         if (handle != NULL)
    116                 *handle = hc_fun->handle;
     95        assert(handle);
     96        ddf_fun_t *hc_fun = ((ohci_t*)fun->dev->driver_data)->hc_fun;
     97        assert(hc_fun != NULL);
     98
     99        *handle = hc_fun->handle;
    117100        return EOK;
    118101}
    119102/*----------------------------------------------------------------------------*/
    120 /** Root hub USB interface */
     103/** This iface is generic for both RH and HC. */
    121104static usb_iface_t usb_iface = {
    122105        .get_hc_handle = usb_iface_get_hc_handle,
     
    124107};
    125108/*----------------------------------------------------------------------------*/
    126 /** Standard USB HC options (HC interface) */
    127109static ddf_dev_ops_t hc_ops = {
    128110        .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
    129111};
    130112/*----------------------------------------------------------------------------*/
    131 /** Standard USB RH options (RH interface) */
    132113static ddf_dev_ops_t rh_ops = {
    133114        .interfaces[USB_DEV_IFACE] = &usb_iface,
     
    136117/** Initialize hc and rh ddf structures and their respective drivers.
    137118 *
     119 * @param[in] instance OHCI structure to use.
    138120 * @param[in] device DDF instance of the device to use.
    139  * @param[in] instance OHCI structure to use.
    140121 *
    141122 * This function does all the preparatory work for hc and rh drivers:
     
    145126 *  - registers interrupt handler
    146127 */
    147 int device_setup_ohci(ddf_dev_t *device)
    148 {
    149         ohci_t *instance = malloc(sizeof(ohci_t));
    150         if (instance == NULL) {
    151                 usb_log_error("Failed to allocate OHCI driver.\n");
    152                 return ENOMEM;
    153         }
    154 
    155 #define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
     128int ohci_init(ohci_t *instance, ddf_dev_t *device)
     129{
     130        assert(instance);
     131        instance->hc_fun = NULL;
     132        instance->rh_fun = NULL;
     133#define CHECK_RET_DEST_FUN_RETURN(ret, message...) \
    156134if (ret != EOK) { \
    157         if (instance->hc_fun) { \
    158                 instance->hc_fun->ops = NULL; \
    159                 instance->hc_fun->driver_data = NULL; \
     135        usb_log_error(message); \
     136        if (instance->hc_fun) \
    160137                ddf_fun_destroy(instance->hc_fun); \
    161         } \
    162         if (instance->rh_fun) { \
    163                 instance->rh_fun->ops = NULL; \
    164                 instance->rh_fun->driver_data = NULL; \
     138        if (instance->rh_fun) \
    165139                ddf_fun_destroy(instance->rh_fun); \
    166         } \
    167         free(instance); \
    168         usb_log_error(message); \
    169140        return ret; \
    170 } else (void)0
    171 
    172         instance->rh_fun = NULL;
    173         instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc");
    174         int ret = instance->hc_fun ? EOK : ENOMEM;
    175         CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create OHCI HC function.\n");
    176         instance->hc_fun->ops = &hc_ops;
    177         instance->hc_fun->driver_data = &instance->hc;
    178 
    179         instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci-rh");
    180         ret = instance->rh_fun ? EOK : ENOMEM;
    181         CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create OHCI RH function.\n");
    182         instance->rh_fun->ops = &rh_ops;
    183 
    184         uintptr_t reg_base = 0;
    185         size_t reg_size = 0;
     141}
     142
     143        uintptr_t mem_reg_base = 0;
     144        size_t mem_reg_size = 0;
    186145        int irq = 0;
    187146
    188         ret = pci_get_my_registers(device, &reg_base, &reg_size, &irq);
    189         CHECK_RET_DEST_FREE_RETURN(ret,
     147        int ret =
     148            pci_get_my_registers(device, &mem_reg_base, &mem_reg_size, &irq);
     149        CHECK_RET_DEST_FUN_RETURN(ret,
    190150            "Failed to get memory addresses for %" PRIun ": %s.\n",
    191151            device->handle, str_error(ret));
    192152        usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n",
    193             (void *) reg_base, reg_size, irq);
     153            (void *) mem_reg_base, mem_reg_size, irq);
     154
     155        ret = pci_disable_legacy(device);
     156        CHECK_RET_DEST_FUN_RETURN(ret,
     157            "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
    194158
    195159        bool interrupts = false;
    196160#ifdef CONFIG_USBHC_NO_INTERRUPTS
    197         usb_log_warning("Interrupts disabled in OS config, "
     161        usb_log_warning("Interrupts disabled in OS config, " \
    198162            "falling back to polling.\n");
    199163#else
     
    202166                usb_log_warning("Failed to enable interrupts: %s.\n",
    203167                    str_error(ret));
    204                 usb_log_info("HW interrupts not available, "
     168                usb_log_info("HW interrupts not available, " \
    205169                    "falling back to polling.\n");
    206170        } else {
     
    210174#endif
    211175
    212         ret = hc_init(&instance->hc, reg_base, reg_size, interrupts);
    213         CHECK_RET_DEST_FREE_RETURN(ret, "Failed(%d) to init ohci-hcd.\n", ret);
     176        instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc");
     177        ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
     178        CHECK_RET_DEST_FUN_RETURN(ret,
     179            "Failed(%d) to create HC function.\n", ret);
     180
     181        ret = hc_init(&instance->hc, instance->hc_fun, device,
     182            mem_reg_base, mem_reg_size, interrupts);
     183        CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init ohci-hcd.\n", ret);
     184        instance->hc_fun->ops = &hc_ops;
     185        instance->hc_fun->driver_data = &instance->hc;
     186        ret = ddf_fun_bind(instance->hc_fun);
     187        CHECK_RET_DEST_FUN_RETURN(ret,
     188            "Failed(%d) to bind OHCI device function: %s.\n",
     189            ret, str_error(ret));
     190#undef CHECK_RET_HC_RETURN
    214191
    215192#define CHECK_RET_FINI_RETURN(ret, message...) \
    216193if (ret != EOK) { \
     194        usb_log_error(message); \
     195        if (instance->hc_fun) \
     196                ddf_fun_destroy(instance->hc_fun); \
     197        if (instance->rh_fun) \
     198                ddf_fun_destroy(instance->rh_fun); \
    217199        hc_fini(&instance->hc); \
    218         CHECK_RET_DEST_FREE_RETURN(ret, message); \
    219 } else (void)0
     200        return ret; \
     201}
    220202
    221203        /* It does no harm if we register this on polling */
     
    225207            "Failed(%d) to register interrupt handler.\n", ret);
    226208
    227         ret = ddf_fun_bind(instance->hc_fun);
     209        instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci-rh");
     210        ret = (instance->rh_fun == NULL) ? ENOMEM : EOK;
    228211        CHECK_RET_FINI_RETURN(ret,
    229             "Failed(%d) to bind OHCI device function: %s.\n",
    230             ret, str_error(ret));
    231 
    232         ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME);
     212            "Failed(%d) to create root hub function.\n", ret);
     213
     214        hc_register_hub(&instance->hc, instance->rh_fun);
     215
     216        instance->rh_fun->ops = &rh_ops;
     217        instance->rh_fun->driver_data = NULL;
     218        ret = ddf_fun_bind(instance->rh_fun);
    233219        CHECK_RET_FINI_RETURN(ret,
    234             "Failed to add OHCI to HC class: %s.\n", str_error(ret));
    235 
    236         device->driver_data = instance;
    237 
    238         hc_start_hw(&instance->hc);
    239         hc_register_hub(&instance->hc, instance->rh_fun);
     220            "Failed(%d) to register OHCI root hub.\n", ret);
     221
    240222        return EOK;
    241 
    242 #undef CHECK_RET_DEST_FUN_RETURN
    243223#undef CHECK_RET_FINI_RETURN
    244224}
  • uspace/drv/ohci/ohci.h

    r9e195e2c r456aea3  
    3838#include <ddf/driver.h>
    3939
    40 int device_setup_ohci(ddf_dev_t *device);
     40#include "hc.h"
     41#include "root_hub.h"
     42
     43typedef struct ohci {
     44        ddf_fun_t *hc_fun;
     45        ddf_fun_t *rh_fun;
     46
     47        hc_t hc;
     48        rh_t rh;
     49} ohci_t;
     50
     51int ohci_init(ohci_t *instance, ddf_dev_t *device);
    4152
    4253#endif
  • uspace/drv/ohci/pci.c

    r9e195e2c r456aea3  
    5858    uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no)
    5959{
    60         assert(dev);
    61         assert(mem_reg_address);
    62         assert(mem_reg_size);
    63         assert(irq_no);
     60        assert(dev != NULL);
    6461
    6562        int parent_phone = devman_parent_device_connect(dev->handle,
     
    139136        return enabled ? EOK : EIO;
    140137}
     138/*----------------------------------------------------------------------------*/
     139/** Implements BIOS handoff routine as decribed in OHCI spec
     140 *
     141 * @param[in] device Device asking for interrupts
     142 * @return Error code.
     143 */
     144int pci_disable_legacy(ddf_dev_t *device)
     145{
     146        /* TODO: implement */
     147        return EOK;
     148}
     149/*----------------------------------------------------------------------------*/
    141150/**
    142151 * @}
  • uspace/drv/ohci/root_hub.c

    r9e195e2c r456aea3  
    4545
    4646/**
    47  * standart device descriptor for ohci root hub
     47 *      standart device descriptor for ohci root hub
    4848 */
    4949static const usb_standard_device_descriptor_t ohci_rh_device_descriptor = {
     
    6969 */
    7070static const usb_standard_configuration_descriptor_t ohci_rh_conf_descriptor = {
     71        /// \TODO some values are default or guessed
    7172        .attributes = 1 << 7,
    7273        .configuration_number = 1,
     
    8687        .endpoint_count = 1,
    8788        .interface_class = USB_CLASS_HUB,
     89        /// \TODO is this correct?
    8890        .interface_number = 1,
    8991        .interface_protocol = 0,
     
    105107};
    106108
    107 /**
    108  * bitmask of hub features that are valid to be cleared
    109  */
    110109static const uint32_t hub_clear_feature_valid_mask =
    111     (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) |
     110        (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) |
    112111(1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    113112
    114 /**
    115  * bitmask of hub features that are cleared by writing 1 (and not 0)
    116  */
    117113static const uint32_t hub_clear_feature_by_writing_one_mask =
    118     1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
    119 
    120 /**
    121  * bitmask of hub features that are valid to be set
    122  */
     114        1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
     115
    123116static const uint32_t hub_set_feature_valid_mask =
    124     (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) |
     117        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) |
    125118(1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
    126119
    127 /**
    128  * bitmask of hub features that are set by writing 1 and cleared by writing 0
    129  */
     120
    130121static const uint32_t hub_set_feature_direct_mask =
    131     (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    132 
    133 /**
    134  * bitmask of port features that are valid to be set
    135  */
     122        (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     123
    136124static const uint32_t port_set_feature_valid_mask =
    137     (1 << USB_HUB_FEATURE_PORT_ENABLE) |
     125        (1 << USB_HUB_FEATURE_PORT_ENABLE) |
    138126(1 << USB_HUB_FEATURE_PORT_SUSPEND) |
    139127(1 << USB_HUB_FEATURE_PORT_RESET) |
    140128(1 << USB_HUB_FEATURE_PORT_POWER);
    141129
    142 /**
    143  * bitmask of port features that can be cleared
    144  */
    145130static const uint32_t port_clear_feature_valid_mask =
    146     (1 << USB_HUB_FEATURE_PORT_CONNECTION) |
     131        (1 << USB_HUB_FEATURE_PORT_CONNECTION) |
    147132(1 << USB_HUB_FEATURE_PORT_SUSPEND) |
    148133(1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) |
     
    156141//USB_HUB_FEATURE_PORT_LOW_SPEED
    157142
    158 /**
    159  * bitmask with port status changes
    160  */
    161143static const uint32_t port_status_change_mask =
    162     (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) |
    163 (1 << USB_HUB_FEATURE_C_PORT_ENABLE) |
    164 (1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
    165 (1 << USB_HUB_FEATURE_C_PORT_RESET) |
    166 (1 << USB_HUB_FEATURE_C_PORT_SUSPEND);
     144(1<< USB_HUB_FEATURE_C_PORT_CONNECTION) |
     145(1<< USB_HUB_FEATURE_C_PORT_ENABLE) |
     146(1<< USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
     147(1<< USB_HUB_FEATURE_C_PORT_RESET) |
     148(1<< USB_HUB_FEATURE_C_PORT_SUSPEND);
    167149
    168150
     
    172154
    173155static int process_get_port_status_request(rh_t *instance, uint16_t port,
    174     usb_transfer_batch_t * request);
     156        usb_transfer_batch_t * request);
    175157
    176158static int process_get_hub_status_request(rh_t *instance,
    177     usb_transfer_batch_t * request);
     159        usb_transfer_batch_t * request);
    178160
    179161static int process_get_status_request(rh_t *instance,
    180     usb_transfer_batch_t * request);
     162        usb_transfer_batch_t * request);
    181163
    182164static void create_interrupt_mask_in_instance(rh_t *instance);
    183165
    184166static int process_get_descriptor_request(rh_t *instance,
    185     usb_transfer_batch_t *request);
     167        usb_transfer_batch_t *request);
    186168
    187169static int process_get_configuration_request(rh_t *instance,
    188     usb_transfer_batch_t *request);
     170        usb_transfer_batch_t *request);
    189171
    190172static int process_hub_feature_set_request(rh_t *instance, uint16_t feature);
    191173
    192174static int process_hub_feature_clear_request(rh_t *instance,
    193     uint16_t feature);
     175        uint16_t feature);
    194176
    195177static int process_port_feature_set_request(rh_t *instance,
    196     uint16_t feature, uint16_t port);
     178        uint16_t feature, uint16_t port);
    197179
    198180static int process_port_feature_clear_request(rh_t *instance,
    199     uint16_t feature, uint16_t port);
     181        uint16_t feature, uint16_t port);
    200182
    201183static int process_address_set_request(rh_t *instance,
    202     uint16_t address);
     184        uint16_t address);
    203185
    204186static int process_request_with_output(rh_t *instance,
    205     usb_transfer_batch_t *request);
     187        usb_transfer_batch_t *request);
    206188
    207189static int process_request_with_input(rh_t *instance,
    208     usb_transfer_batch_t *request);
     190        usb_transfer_batch_t *request);
    209191
    210192static int process_request_without_data(rh_t *instance,
    211     usb_transfer_batch_t *request);
     193        usb_transfer_batch_t *request);
    212194
    213195static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request);
     
    216198
    217199static bool is_zeros(void * buffer, size_t size);
     200
     201
    218202
    219203/** Root hub initialization
     
    226210            (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK;
    227211        int opResult = rh_init_descriptors(instance);
    228         if (opResult != EOK) {
     212        if(opResult != EOK){
    229213                return opResult;
    230214        }
     
    232216        instance->registers->rh_desc_a |= RHDA_NPS_FLAG;
    233217        instance->unfinished_interrupt_transfer = NULL;
    234         instance->interrupt_mask_size = (instance->port_count + 8) / 8;
     218        instance->interrupt_mask_size = (instance->port_count + 8)/8;
    235219        instance->interrupt_buffer = malloc(instance->interrupt_mask_size);
    236         if (!instance->interrupt_buffer)
     220        if(!instance->interrupt_buffer)
    237221                return ENOMEM;
    238 
    239         usb_log_info("OHCI root hub with %zu ports initialized.\n",
    240             instance->port_count);
    241 
     222       
     223
     224        usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
    242225        return EOK;
    243226}
     
    262245                usb_log_info("Root hub got INTERRUPT packet\n");
    263246                create_interrupt_mask_in_instance(instance);
    264                 if (is_zeros(instance->interrupt_buffer,
    265                     instance->interrupt_mask_size)) {
     247                if(is_zeros(instance->interrupt_buffer,
     248                    instance->interrupt_mask_size)){
    266249                        usb_log_debug("no changes..\n");
    267250                        instance->unfinished_interrupt_transfer = request;
    268251                        //will be finished later
    269                 } else {
     252                }else{
    270253                        usb_log_debug("processing changes..\n");
    271254                        process_interrupt_mask_in_instance(instance, request);
     
    273256                opResult = EOK;
    274257        } else {
    275 
    276258                opResult = EINVAL;
    277259                usb_transfer_batch_finish_error(request, opResult);
     
    289271 */
    290272void rh_interrupt(rh_t *instance) {
    291         if (!instance->unfinished_interrupt_transfer) {
     273        if(!instance->unfinished_interrupt_transfer){
    292274                return;
    293275        }
     
    310292static int create_serialized_hub_descriptor(rh_t *instance) {
    311293        size_t size = 7 +
    312             ((instance->port_count + 7) / 8) * 2;
    313         size_t var_size = (instance->port_count + 7) / 8;
     294            ((instance->port_count +7 )/ 8) * 2;
     295        size_t var_size = (instance->port_count +7 )/ 8;
    314296        uint8_t * result = (uint8_t*) malloc(size);
    315         if (!result) return ENOMEM;
     297        if(!result) return ENOMEM;
    316298
    317299        bzero(result, size);
     
    323305        uint32_t hub_desc_reg = instance->registers->rh_desc_a;
    324306        result[3] =
    325             ((hub_desc_reg >> 8) % 2) +
    326             (((hub_desc_reg >> 9) % 2) << 1) +
    327             (((hub_desc_reg >> 10) % 2) << 2) +
    328             (((hub_desc_reg >> 11) % 2) << 3) +
    329             (((hub_desc_reg >> 12) % 2) << 4);
     307                ((hub_desc_reg >> 8) % 2) +
     308                (((hub_desc_reg >> 9) % 2) << 1) +
     309                (((hub_desc_reg >> 10) % 2) << 2) +
     310                (((hub_desc_reg >> 11) % 2) << 3) +
     311                (((hub_desc_reg >> 12) % 2) << 4);
    330312        result[4] = 0;
    331313        result[5] = /*descriptor->pwr_on_2_good_time*/ 50;
    332314        result[6] = 50;
    333315
    334         size_t port;
     316        int port;
    335317        for (port = 1; port <= instance->port_count; ++port) {
    336318                uint8_t is_non_removable =
    337                     instance->registers->rh_desc_b >> port % 2;
     319                        instance->registers->rh_desc_b >> port % 2;
    338320                result[7 + port / 8] +=
    339                     is_non_removable << (port % 8);
     321                        is_non_removable << (port % 8);
    340322        }
    341323        size_t i;
     
    345327        instance->hub_descriptor = result;
    346328        instance->descriptor_size = size;
    347 
    348329        return EOK;
    349330}
     
    359340static int rh_init_descriptors(rh_t *instance) {
    360341        memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
    361             sizeof (ohci_rh_device_descriptor)
    362             );
     342                sizeof (ohci_rh_device_descriptor)
     343                );
    363344        usb_standard_configuration_descriptor_t descriptor;
    364345        memcpy(&descriptor, &ohci_rh_conf_descriptor,
    365             sizeof (ohci_rh_conf_descriptor));
     346                sizeof (ohci_rh_conf_descriptor));
    366347
    367348        int opResult = create_serialized_hub_descriptor(instance);
    368         if (opResult != EOK) {
     349        if(opResult != EOK){
    369350                return opResult;
    370351        }
    371352        descriptor.total_length =
    372             sizeof (usb_standard_configuration_descriptor_t) +
    373             sizeof (usb_standard_endpoint_descriptor_t) +
    374             sizeof (usb_standard_interface_descriptor_t) +
    375             instance->descriptor_size;
     353                sizeof (usb_standard_configuration_descriptor_t) +
     354                sizeof (usb_standard_endpoint_descriptor_t) +
     355                sizeof (usb_standard_interface_descriptor_t) +
     356                instance->descriptor_size;
    376357
    377358        uint8_t * full_config_descriptor =
    378             (uint8_t*) malloc(descriptor.total_length);
    379         if (!full_config_descriptor) {
     359                (uint8_t*) malloc(descriptor.total_length);
     360        if(!full_config_descriptor){
    380361                return ENOMEM;
    381362        }
    382363        memcpy(full_config_descriptor, &descriptor, sizeof (descriptor));
    383364        memcpy(full_config_descriptor + sizeof (descriptor),
    384             &ohci_rh_iface_descriptor, sizeof (ohci_rh_iface_descriptor));
     365                &ohci_rh_iface_descriptor, sizeof (ohci_rh_iface_descriptor));
    385366        memcpy(full_config_descriptor + sizeof (descriptor) +
    386             sizeof (ohci_rh_iface_descriptor),
    387             &ohci_rh_ep_descriptor, sizeof (ohci_rh_ep_descriptor));
     367                sizeof (ohci_rh_iface_descriptor),
     368                &ohci_rh_ep_descriptor, sizeof (ohci_rh_ep_descriptor));
    388369        memcpy(full_config_descriptor + sizeof (descriptor) +
    389             sizeof (ohci_rh_iface_descriptor) +
    390             sizeof (ohci_rh_ep_descriptor),
    391             instance->hub_descriptor, instance->descriptor_size);
    392 
     370                sizeof (ohci_rh_iface_descriptor) +
     371                sizeof (ohci_rh_ep_descriptor),
     372                instance->hub_descriptor, instance->descriptor_size);
     373       
    393374        instance->descriptors.configuration = full_config_descriptor;
    394375        instance->descriptors.configuration_size = descriptor.total_length;
    395 
    396376        return EOK;
    397377}
     
    409389 */
    410390static int process_get_port_status_request(rh_t *instance, uint16_t port,
    411     usb_transfer_batch_t * request) {
     391        usb_transfer_batch_t * request) {
    412392        if (port < 1 || port > instance->port_count)
    413393                return EINVAL;
     
    418398        int i;
    419399        for (i = 0; i < instance->port_count; ++i) {
    420 
    421400                usb_log_debug("port status %d,x%x\n",
    422                     instance->registers->rh_port_status[i],
    423                     instance->registers->rh_port_status[i]);
     401                        instance->registers->rh_port_status[i],
     402                        instance->registers->rh_port_status[i]);
    424403        }
    425404#endif
     
    438417 */
    439418static int process_get_hub_status_request(rh_t *instance,
    440     usb_transfer_batch_t * request) {
     419        usb_transfer_batch_t * request) {
    441420        uint32_t * uint32_buffer = (uint32_t*) request->data_buffer;
    442421        request->transfered_size = 4;
     
    444423        uint32_t mask = 1 | (1 << 1) | (1 << 16) | (1 << 17);
    445424        uint32_buffer[0] = mask & instance->registers->rh_status;
    446 
    447425        return EOK;
    448426}
     
    459437 */
    460438static int process_get_status_request(rh_t *instance,
    461     usb_transfer_batch_t * request) {
     439        usb_transfer_batch_t * request) {
    462440        size_t buffer_size = request->buffer_size;
    463441        usb_device_request_setup_packet_t * request_packet =
    464             (usb_device_request_setup_packet_t*)
    465             request->setup_buffer;
     442                (usb_device_request_setup_packet_t*)
     443                request->setup_buffer;
    466444
    467445        usb_hub_bm_request_type_t request_type = request_packet->request_type;
     
    475453        if (request_type == USB_HUB_REQ_TYPE_GET_PORT_STATUS)
    476454                return process_get_port_status_request(instance,
    477             request_packet->index,
    478             request);
    479 
     455                request_packet->index,
     456                request);
    480457        return ENOTSUP;
    481458}
     
    495472        uint8_t * bitmap = (uint8_t*) (instance->interrupt_buffer);
    496473        uint32_t mask = (1 << (USB_HUB_FEATURE_C_HUB_LOCAL_POWER + 16))
    497             | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16));
     474                | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16));
    498475        bzero(bitmap, instance->interrupt_mask_size);
    499476        if (instance->registers->rh_status & mask) {
    500477                bitmap[0] = 1;
    501478        }
    502         size_t port;
     479        int port;
    503480        mask = port_status_change_mask;
    504481        for (port = 1; port <= instance->port_count; ++port) {
    505482                if (mask & instance->registers->rh_port_status[port - 1]) {
    506 
    507483                        bitmap[(port) / 8] += 1 << (port % 8);
    508484                }
     
    521497 */
    522498static int process_get_descriptor_request(rh_t *instance,
    523     usb_transfer_batch_t *request) {
     499        usb_transfer_batch_t *request) {
    524500        usb_device_request_setup_packet_t * setup_request =
    525             (usb_device_request_setup_packet_t*) request->setup_buffer;
     501                (usb_device_request_setup_packet_t*) request->setup_buffer;
    526502        size_t size;
    527503        const void * result_descriptor = NULL;
     
    567543                {
    568544                        usb_log_debug("USB_DESCTYPE_EINVAL %d \n",
    569                             setup_request->value);
     545                                setup_request->value);
    570546                        usb_log_debug("\ttype %d\n\trequest %d\n\tvalue "
    571                             "%d\n\tindex %d\n\tlen %d\n ",
    572                             setup_request->request_type,
    573                             setup_request->request,
    574                             setup_request_value,
    575                             setup_request->index,
    576                             setup_request->length
    577                             );
     547                                "%d\n\tindex %d\n\tlen %d\n ",
     548                                setup_request->request_type,
     549                                setup_request->request,
     550                                setup_request_value,
     551                                setup_request->index,
     552                                setup_request->length
     553                                );
    578554                        return EINVAL;
    579555                }
     
    584560        request->transfered_size = size;
    585561        memcpy(request->data_buffer, result_descriptor, size);
    586 
    587562        return EOK;
    588563}
     
    598573 */
    599574static int process_get_configuration_request(rh_t *instance,
    600     usb_transfer_batch_t *request) {
     575        usb_transfer_batch_t *request) {
    601576        //set and get configuration requests do not have any meaning, only dummy
    602577        //values are returned
     
    605580        request->data_buffer[0] = 1;
    606581        request->transfered_size = 1;
    607 
    608582        return EOK;
    609583}
     
    618592 */
    619593static int process_hub_feature_set_request(rh_t *instance,
    620     uint16_t feature) {
     594        uint16_t feature) {
    621595        if (!((1 << feature) & hub_set_feature_valid_mask))
    622596                return EINVAL;
    623         if (feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER)
     597        if(feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER)
    624598                feature = USB_HUB_FEATURE_C_HUB_LOCAL_POWER << 16;
    625599        instance->registers->rh_status =
    626             (instance->registers->rh_status | (1 << feature))
    627             & (~hub_clear_feature_by_writing_one_mask);
    628 
     600                (instance->registers->rh_status | (1 << feature))
     601                & (~hub_clear_feature_by_writing_one_mask);
    629602        return EOK;
    630603}
     
    639612 */
    640613static int process_hub_feature_clear_request(rh_t *instance,
    641     uint16_t feature) {
     614        uint16_t feature) {
    642615        if (!((1 << feature) & hub_clear_feature_valid_mask))
    643616                return EINVAL;
     
    645618        if ((1 << feature) & hub_set_feature_direct_mask) {
    646619                instance->registers->rh_status =
    647                     (instance->registers->rh_status & (~(1 << feature)))
    648                     & (~hub_clear_feature_by_writing_one_mask);
     620                        (instance->registers->rh_status & (~(1 << feature)))
     621                        & (~hub_clear_feature_by_writing_one_mask);
    649622        } else {//the feature is cleared by writing '1'
    650 
    651623                instance->registers->rh_status =
    652                     (instance->registers->rh_status
    653                     & (~hub_clear_feature_by_writing_one_mask))
    654                     | (1 << feature);
     624                        (instance->registers->rh_status
     625                        & (~hub_clear_feature_by_writing_one_mask))
     626                        | (1 << feature);
    655627        }
    656628        return EOK;
     
    668640 */
    669641static int process_port_feature_set_request(rh_t *instance,
    670     uint16_t feature, uint16_t port) {
     642        uint16_t feature, uint16_t port) {
    671643        if (!((1 << feature) & port_set_feature_valid_mask))
    672644                return EINVAL;
     
    674646                return EINVAL;
    675647        instance->registers->rh_port_status[port - 1] =
    676             (instance->registers->rh_port_status[port - 1] | (1 << feature))
    677             & (~port_clear_feature_valid_mask);
     648                (instance->registers->rh_port_status[port - 1] | (1 << feature))
     649                & (~port_clear_feature_valid_mask);
    678650        /// \TODO any error?
    679 
    680651        return EOK;
    681652}
     
    692663 */
    693664static int process_port_feature_clear_request(rh_t *instance,
    694     uint16_t feature, uint16_t port) {
     665        uint16_t feature, uint16_t port) {
    695666        if (!((1 << feature) & port_clear_feature_valid_mask))
    696667                return EINVAL;
     
    702673                feature = USB_HUB_FEATURE_PORT_OVER_CURRENT;
    703674        instance->registers->rh_port_status[port - 1] =
    704             (instance->registers->rh_port_status[port - 1]
    705             & (~port_clear_feature_valid_mask))
    706             | (1 << feature);
     675                (instance->registers->rh_port_status[port - 1]
     676                & (~port_clear_feature_valid_mask))
     677                | (1 << feature);
    707678        /// \TODO any error?
    708 
    709679        return EOK;
    710680}
     
    719689 */
    720690static int process_address_set_request(rh_t *instance,
    721     uint16_t address) {
     691        uint16_t address) {
    722692        instance->address = address;
    723 
    724693        return EOK;
    725694}
     
    736705 */
    737706static int process_request_with_output(rh_t *instance,
    738     usb_transfer_batch_t *request) {
     707        usb_transfer_batch_t *request) {
    739708        usb_device_request_setup_packet_t * setup_request =
    740             (usb_device_request_setup_packet_t*) request->setup_buffer;
     709                (usb_device_request_setup_packet_t*) request->setup_buffer;
    741710        if (setup_request->request == USB_DEVREQ_GET_STATUS) {
    742711                usb_log_debug("USB_DEVREQ_GET_STATUS\n");
     
    749718        if (setup_request->request == USB_DEVREQ_GET_CONFIGURATION) {
    750719                usb_log_debug("USB_DEVREQ_GET_CONFIGURATION\n");
    751 
    752720                return process_get_configuration_request(instance, request);
    753721        }
     
    766734 */
    767735static int process_request_with_input(rh_t *instance,
    768     usb_transfer_batch_t *request) {
     736        usb_transfer_batch_t *request) {
    769737        usb_device_request_setup_packet_t * setup_request =
    770             (usb_device_request_setup_packet_t*) request->setup_buffer;
     738                (usb_device_request_setup_packet_t*) request->setup_buffer;
    771739        request->transfered_size = 0;
    772740        if (setup_request->request == USB_DEVREQ_SET_DESCRIPTOR) {
     
    776744                //set and get configuration requests do not have any meaning,
    777745                //only dummy values are returned
    778 
    779746                return EOK;
    780747        }
     
    793760 */
    794761static int process_request_without_data(rh_t *instance,
    795     usb_transfer_batch_t *request) {
     762        usb_transfer_batch_t *request) {
    796763        usb_device_request_setup_packet_t * setup_request =
    797             (usb_device_request_setup_packet_t*) request->setup_buffer;
     764                (usb_device_request_setup_packet_t*) request->setup_buffer;
    798765        request->transfered_size = 0;
    799766        if (setup_request->request == USB_DEVREQ_CLEAR_FEATURE) {
     
    801768                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    802769                        return process_hub_feature_clear_request(instance,
    803                             setup_request->value);
     770                                setup_request->value);
    804771                }
    805772                if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
    806773                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    807774                        return process_port_feature_clear_request(instance,
    808                             setup_request->value,
    809                             setup_request->index);
     775                                setup_request->value,
     776                                setup_request->index);
    810777                }
    811778                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
    812                     setup_request->request_type);
     779                        setup_request->request_type);
    813780                return EINVAL;
    814781        }
     
    817784                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    818785                        return process_hub_feature_set_request(instance,
    819                             setup_request->value);
     786                                setup_request->value);
    820787                }
    821788                if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
    822789                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    823790                        return process_port_feature_set_request(instance,
    824                             setup_request->value,
    825                             setup_request->index);
     791                                setup_request->value,
     792                                setup_request->index);
    826793                }
    827794                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
    828                     setup_request->request_type);
     795                        setup_request->request_type);
    829796                return EINVAL;
    830797        }
     
    832799                usb_log_debug("USB_DEVREQ_SET_ADDRESS\n");
    833800                return process_address_set_request(instance,
    834                     setup_request->value);
     801                        setup_request->value);
    835802        }
    836803        usb_log_debug("USB_DEVREQ_SET_ENOTSUP %d\n",
    837             setup_request->request_type);
    838 
     804                setup_request->request_type);
    839805        return ENOTSUP;
    840806}
     
    870836        }
    871837        usb_log_info("CTRL packet: %s.\n",
    872             usb_debug_str_buffer(
    873             (const uint8_t *) request->setup_buffer, 8, 8));
     838                usb_debug_str_buffer(
     839                (const uint8_t *) request->setup_buffer, 8, 8));
    874840        usb_device_request_setup_packet_t * setup_request =
    875             (usb_device_request_setup_packet_t*)
    876             request->setup_buffer;
     841                (usb_device_request_setup_packet_t*)
     842                request->setup_buffer;
    877843        switch (setup_request->request) {
    878844                case USB_DEVREQ_GET_STATUS:
     
    881847                        usb_log_debug("processing request with output\n");
    882848                        opResult = process_request_with_output(
    883                             instance, request);
     849                                instance, request);
    884850                        break;
    885851                case USB_DEVREQ_CLEAR_FEATURE:
     
    887853                case USB_DEVREQ_SET_ADDRESS:
    888854                        usb_log_debug("processing request without "
    889                             "additional data\n");
     855                                "additional data\n");
    890856                        opResult = process_request_without_data(
    891                             instance, request);
     857                                instance, request);
    892858                        break;
    893859                case USB_DEVREQ_SET_DESCRIPTOR:
    894860                case USB_DEVREQ_SET_CONFIGURATION:
    895861                        usb_log_debug("processing request with "
    896                             "input\n");
     862                                "input\n");
    897863                        opResult = process_request_with_input(
    898                             instance, request);
    899 
     864                                instance, request);
    900865                        break;
    901866                default:
    902867                        usb_log_warning("received unsuported request: "
    903                             "%d\n",
    904                             setup_request->request
    905                             );
     868                                "%d\n",
     869                                setup_request->request
     870                                );
    906871                        opResult = ENOTSUP;
    907872        }
     
    923888 * @return
    924889 */
    925 static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request) {
     890static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request){
    926891        memcpy(request->data_buffer, instance->interrupt_buffer,
    927892            instance->interrupt_mask_size);
     
    929894        instance->unfinished_interrupt_transfer = NULL;
    930895        usb_transfer_batch_finish_error(request, EOK);
    931 
    932896        return EOK;
    933897}
     
    943907 * @return
    944908 */
    945 static bool is_zeros(void * buffer, size_t size) {
    946         if (!buffer) return true;
    947         if (!size) return true;
     909static bool is_zeros(void * buffer, size_t size){
     910        if(!buffer) return true;
     911        if(!size) return true;
    948912        size_t i;
    949         for (i = 0; i < size; ++i) {
    950                 if (((char*) buffer)[i])
     913        for(i=0;i<size;++i){
     914                if(((char*)buffer)[i])
    951915                        return false;
    952916        }
  • uspace/drv/ohci/root_hub.h

    r9e195e2c r456aea3  
    5151        usb_address_t address;
    5252        /** hub port count */
    53         size_t port_count;
     53        int port_count;
    5454        /** hubs descriptors */
    5555        usb_device_descriptors_t descriptors;
  • uspace/drv/uhci-hcd/Makefile

    r9e195e2c r456aea3  
    2828
    2929USPACE_PREFIX = ../..
    30 
    31 LIBS = \
    32         $(LIBUSBHOST_PREFIX)/libusbhost.a \
    33         $(LIBUSB_PREFIX)/libusb.a \
    34         $(LIBDRV_PREFIX)/libdrv.a
    35 EXTRA_CFLAGS += \
    36         -I$(LIBUSB_PREFIX)/include \
    37         -I$(LIBUSBHOST_PREFIX)/include \
    38         -I$(LIBDRV_PREFIX)/include
    39 
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
    4032BINARY = uhci-hcd
    4133
  • uspace/drv/uhci-hcd/hc.c

    r9e195e2c r456aea3  
    6060 *
    6161 * @param[in] instance Memory place to initialize.
     62 * @param[in] fun DDF function.
    6263 * @param[in] regs Address of I/O control registers.
    6364 * @param[in] size Size of I/O control registers.
     
    6869 * interrupt fibrils.
    6970 */
    70 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interrupts)
     71int hc_init(hc_t *instance, ddf_fun_t *fun,
     72    void *regs, size_t reg_size, bool interrupts)
    7173{
    7274        assert(reg_size >= sizeof(regs_t));
  • uspace/drv/uhci-hcd/hc.h

    r9e195e2c r456aea3  
    136136} hc_t;
    137137
    138 int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interupts);
     138int hc_init(hc_t *instance, ddf_fun_t *fun,
     139    void *regs, size_t reg_size, bool interupts);
    139140
    140141int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch);
  • uspace/drv/uhci-hcd/hw_struct/queue_head.h

    r9e195e2c r456aea3  
    3838#include "link_pointer.h"
    3939#include "transfer_descriptor.h"
    40 #include "../utils/malloc32.h"
     40#include "utils/malloc32.h"
    4141
    4242/** This structure is defined in UHCI design guide p. 31 */
  • uspace/drv/uhci-hcd/hw_struct/transfer_descriptor.c

    r9e195e2c r456aea3  
    3636
    3737#include "transfer_descriptor.h"
    38 #include "../utils/malloc32.h"
     38#include "utils/malloc32.h"
    3939
    4040/** Initialize Transfer Descriptor
  • uspace/drv/uhci-hcd/iface.c

    r9e195e2c r456aea3  
    122122        return EOK;
    123123}
    124 
    125 /** Find device handle by address interface function.
    126  *
    127  * @param[in] fun DDF function that was called.
    128  * @param[in] address Address in question.
    129  * @param[out] handle Where to store device handle if found.
    130  * @return Error code.
    131  */
    132 static int find_by_address(ddf_fun_t *fun, usb_address_t address,
    133     devman_handle_t *handle)
    134 {
    135         assert(fun);
    136         hc_t *hc = fun_to_hc(fun);
    137         assert(hc);
    138         bool found =
    139             usb_device_keeper_find_by_address(&hc->manager, address, handle);
    140         return found ? EOK : ENOENT;
    141 }
    142 
    143124/*----------------------------------------------------------------------------*/
    144125/** Release address interface function
     
    371352        .request_address = request_address,
    372353        .bind_address = bind_address,
    373         .find_by_address = find_by_address,
    374354        .release_address = release_address,
    375355
  • uspace/drv/uhci-hcd/main.c

    r9e195e2c r456aea3  
    6464        assert(device);
    6565
    66         int ret = device_setup_uhci(device);
     66        uhci_t *uhci = malloc(sizeof(uhci_t));
     67        if (uhci == NULL) {
     68                usb_log_error("Failed to allocate UHCI driver.\n");
     69                return ENOMEM;
     70        }
     71
     72        int ret = uhci_init(uhci, device);
    6773        if (ret != EOK) {
    6874                usb_log_error("Failed to initialize UHCI driver: %s.\n",
     
    7076                return ret;
    7177        }
     78        device->driver_data = uhci;
     79
    7280        usb_log_info("Controlling new UHCI device '%s'.\n", device->name);
    7381
  • uspace/drv/uhci-hcd/uhci.c

    r9e195e2c r456aea3  
    4444#include "pci.h"
    4545
    46 #include "hc.h"
    47 #include "root_hub.h"
    48 
    49 /** Structure representing both functions of UHCI hc, USB host controller
    50  * and USB root hub */
    51 typedef struct uhci {
    52         /** Pointer to DDF represenation of UHCI host controller */
    53         ddf_fun_t *hc_fun;
    54         /** Pointer to DDF represenation of UHCI root hub */
    55         ddf_fun_t *rh_fun;
    56 
    57         /** Internal driver's represenation of UHCI host controller */
    58         hc_t hc;
    59         /** Internal driver's represenation of UHCI root hub */
    60         rh_t rh;
    61 } uhci_t;
    62 
    63 static inline uhci_t * dev_to_uhci(ddf_dev_t *dev)
    64 {
    65         assert(dev);
    66         assert(dev->driver_data);
    67         return dev->driver_data;
    68 }
    69 /*----------------------------------------------------------------------------*/
    7046/** IRQ handling callback, forward status from call to diver structure.
    7147 *
     
    9369{
    9470        assert(fun);
    95         usb_device_keeper_t *manager = &dev_to_uhci(fun->dev)->hc.manager;
     71        usb_device_keeper_t *manager =
     72            &((uhci_t*)fun->dev->driver_data)->hc.manager;
     73
    9674        usb_address_t addr = usb_device_keeper_find(manager, handle);
    97 
    9875        if (addr < 0) {
    9976                return addr;
     
    11693    ddf_fun_t *fun, devman_handle_t *handle)
    11794{
    118         assert(fun);
    119         ddf_fun_t *hc_fun = dev_to_uhci(fun->dev)->hc_fun;
    120         assert(hc_fun);
    121 
    122         if (handle != NULL)
    123                 *handle = hc_fun->handle;
     95        assert(handle);
     96        ddf_fun_t *hc_fun = ((uhci_t*)fun->dev->driver_data)->hc_fun;
     97        assert(hc_fun != NULL);
     98
     99        *handle = hc_fun->handle;
    124100        return EOK;
    125101}
     
    150126static hw_res_ops_t hw_res_iface = {
    151127        .get_resource_list = get_resource_list,
    152         .enable_interrupt = NULL,
     128        .enable_interrupt = NULL
    153129};
    154130/*----------------------------------------------------------------------------*/
     
    170146 *  - registers interrupt handler
    171147 */
    172 int device_setup_uhci(ddf_dev_t *device)
    173 {
    174         assert(device);
    175         uhci_t *instance = malloc(sizeof(uhci_t));
    176         if (instance == NULL) {
    177                 usb_log_error("Failed to allocate OHCI driver.\n");
    178                 return ENOMEM;
    179         }
    180 
    181 #define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
     148int uhci_init(uhci_t *instance, ddf_dev_t *device)
     149{
     150        assert(instance);
     151        instance->hc_fun = NULL;
     152        instance->rh_fun = NULL;
     153#define CHECK_RET_DEST_FUN_RETURN(ret, message...) \
    182154if (ret != EOK) { \
     155        usb_log_error(message); \
    183156        if (instance->hc_fun) \
    184                 instance->hc_fun->ops = NULL; \
    185                 instance->hc_fun->driver_data = NULL; \
    186157                ddf_fun_destroy(instance->hc_fun); \
    187         if (instance->rh_fun) {\
    188                 instance->rh_fun->ops = NULL; \
    189                 instance->rh_fun->driver_data = NULL; \
     158        if (instance->rh_fun) \
    190159                ddf_fun_destroy(instance->rh_fun); \
    191         } \
    192         free(instance); \
    193         usb_log_error(message); \
    194160        return ret; \
    195 } else (void)0
    196 
    197         instance->rh_fun = NULL;
    198         instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci-hc");
    199         int ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
    200         CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI HC function.\n");
    201         instance->hc_fun->ops = &hc_ops;
    202         instance->hc_fun->driver_data = &instance->hc;
    203 
    204         instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci-rh");
    205         ret = (instance->rh_fun == NULL) ? ENOMEM : EOK;
    206         CHECK_RET_DEST_FREE_RETURN(ret, "Failed to create UHCI RH function.\n");
    207         instance->rh_fun->ops = &rh_ops;
    208         instance->rh_fun->driver_data = &instance->rh;
    209 
    210         uintptr_t reg_base = 0;
    211         size_t reg_size = 0;
     161}
     162
     163        uintptr_t io_reg_base = 0;
     164        size_t io_reg_size = 0;
    212165        int irq = 0;
    213166
    214         ret = pci_get_my_registers(device, &reg_base, &reg_size, &irq);
    215         CHECK_RET_DEST_FREE_RETURN(ret,
     167        int ret =
     168            pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
     169        CHECK_RET_DEST_FUN_RETURN(ret,
    216170            "Failed to get I/O addresses for %" PRIun ": %s.\n",
    217171            device->handle, str_error(ret));
    218172        usb_log_debug("I/O regs at 0x%p (size %zu), IRQ %d.\n",
    219             (void *) reg_base, reg_size, irq);
     173            (void *) io_reg_base, io_reg_size, irq);
    220174
    221175        ret = pci_disable_legacy(device);
    222         CHECK_RET_DEST_FREE_RETURN(ret,
     176        CHECK_RET_DEST_FUN_RETURN(ret,
    223177            "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
    224178
     
    240194#endif
    241195
    242 
    243         ret = hc_init(&instance->hc, (void*)reg_base, reg_size, interrupts);
    244         CHECK_RET_DEST_FREE_RETURN(ret,
     196        instance->hc_fun = ddf_fun_create(device, fun_exposed, "uhci-hc");
     197        ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
     198        CHECK_RET_DEST_FUN_RETURN(ret,
     199            "Failed(%d) to create HC function: %s.\n", ret, str_error(ret));
     200
     201        ret = hc_init(&instance->hc, instance->hc_fun,
     202            (void*)io_reg_base, io_reg_size, interrupts);
     203        CHECK_RET_DEST_FUN_RETURN(ret,
    245204            "Failed(%d) to init uhci-hcd: %s.\n", ret, str_error(ret));
     205
     206        instance->hc_fun->ops = &hc_ops;
     207        instance->hc_fun->driver_data = &instance->hc;
     208        ret = ddf_fun_bind(instance->hc_fun);
     209        CHECK_RET_DEST_FUN_RETURN(ret,
     210            "Failed(%d) to bind UHCI device function: %s.\n",
     211            ret, str_error(ret));
     212#undef CHECK_RET_HC_RETURN
    246213
    247214#define CHECK_RET_FINI_RETURN(ret, message...) \
    248215if (ret != EOK) { \
     216        usb_log_error(message); \
     217        if (instance->hc_fun) \
     218                ddf_fun_destroy(instance->hc_fun); \
     219        if (instance->rh_fun) \
     220                ddf_fun_destroy(instance->rh_fun); \
    249221        hc_fini(&instance->hc); \
    250         CHECK_RET_DEST_FREE_RETURN(ret, message); \
    251222        return ret; \
    252 } else (void)0
     223}
    253224
    254225        /* It does no harm if we register this on polling */
     
    259230            ret, str_error(ret));
    260231
    261         ret = ddf_fun_bind(instance->hc_fun);
    262         CHECK_RET_FINI_RETURN(ret,
    263             "Failed(%d) to bind UHCI device function: %s.\n",
     232        instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci-rh");
     233        ret = (instance->rh_fun == NULL) ? ENOMEM : EOK;
     234        CHECK_RET_FINI_RETURN(ret,
     235            "Failed(%d) to create root hub function: %s.\n",
    264236            ret, str_error(ret));
    265 
    266         ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME);
    267         CHECK_RET_FINI_RETURN(ret,
    268             "Failed to add UHCI to HC class: %s.\n", str_error(ret));
    269237
    270238        ret = rh_init(&instance->rh, instance->rh_fun,
     
    273241            "Failed(%d) to setup UHCI root hub: %s.\n", ret, str_error(ret));
    274242
     243        instance->rh_fun->ops = &rh_ops;
     244        instance->rh_fun->driver_data = &instance->rh;
    275245        ret = ddf_fun_bind(instance->rh_fun);
    276246        CHECK_RET_FINI_RETURN(ret,
    277247            "Failed(%d) to register UHCI root hub: %s.\n", ret, str_error(ret));
    278248
    279         device->driver_data = instance;
    280249        return EOK;
    281250#undef CHECK_RET_FINI_RETURN
  • uspace/drv/uhci-hcd/uhci.h

    r9e195e2c r456aea3  
    3838#include <ddf/driver.h>
    3939
    40 int device_setup_uhci(ddf_dev_t *device);
     40#include "hc.h"
     41#include "root_hub.h"
     42
     43/** Structure representing both functions of UHCI hc, USB host controller
     44 * and USB root hub */
     45typedef struct uhci {
     46        /** Pointer to DDF represenation of UHCI host controller */
     47        ddf_fun_t *hc_fun;
     48        /** Pointer to DDF represenation of UHCI root hub */
     49        ddf_fun_t *rh_fun;
     50
     51        /** Internal driver's represenation of UHCI host controller */
     52        hc_t hc;
     53        /** Internal driver's represenation of UHCI root hub */
     54        rh_t rh;
     55} uhci_t;
     56
     57int uhci_init(uhci_t *instance, ddf_dev_t *device);
    4158#endif
    4259/**
  • uspace/drv/uhci-rhd/Makefile

    r9e195e2c r456aea3  
    2828
    2929USPACE_PREFIX = ../..
    30 
    31 LIBS = \
    32         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    33         $(LIBUSB_PREFIX)/libusb.a \
    34         $(LIBDRV_PREFIX)/libdrv.a
    35 EXTRA_CFLAGS += \
    36         -I$(LIBUSB_PREFIX)/include \
    37         -I$(LIBUSBDEV_PREFIX)/include \
    38         -I$(LIBDRV_PREFIX)/include
    39 
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
    4032BINARY = uhci-rhd
    4133
  • uspace/drv/uhci-rhd/port.c

    r9e195e2c r456aea3  
    3232 * @brief UHCI root hub port routines
    3333 */
    34 #include <libarch/ddi.h>  /* pio_read and pio_write */
    35 #include <fibril_synch.h> /* async_usleep */
     34#include <libarch/ddi.h> /* pio_read and pio_write */
    3635#include <errno.h>
    3736#include <str_error.h>
     37#include <fibril_synch.h>
    3838
    3939#include <usb/usb.h>    /* usb_address_t */
    40 #include <usb/hub.h>    /* usb_hc_new_device_wrapper */
     40#include <usb/hub.h>
    4141#include <usb/debug.h>
    4242
     
    212212
    213213        /*
    214          * Resets from root ports should be nominally 50ms (USB spec 7.1.7.3)
     214         * The host then waits for at least 100 ms to allow completion of
     215         * an insertion process and for power at the device to become stable.
     216         */
     217        async_usleep(100000);
     218
     219        /*
     220         * Resets from root ports should be nominally 50ms
    215221         */
    216222        {
     
    223229                port_status &= ~STATUS_IN_RESET;
    224230                uhci_port_write_status(port, port_status);
    225                 while (uhci_port_read_status(port) & STATUS_IN_RESET);
    226                 // TODO: find a better way to waste time (it should be less than
    227                 // 10ms, if we reschedule it takes too much time (random
    228                 // interrupts can be solved by multiple attempts).
    229                 usb_log_debug2("%s: Reset Signal stop.\n", port->id_string);
    230         }
     231                usb_log_debug("%s: Reset Signal stop.\n", port->id_string);
     232        }
     233
     234        /* the reset recovery time 10ms */
     235        async_usleep(10000);
     236
    231237        /* Enable the port. */
    232238        uhci_port_set_enabled(port, true);
    233 
    234         /* Reset recovery period,
    235          * devices do not have to respond during this period
    236          */
    237         async_usleep(10000);
    238239        return EOK;
    239240}
     
    254255        usb_log_debug("%s: Detected new device.\n", port->id_string);
    255256
    256         int ret, count = 0;
    257257        usb_address_t dev_addr;
    258         do {
    259                 ret = usb_hc_new_device_wrapper(port->rh, &port->hc_connection,
    260                     speed, uhci_port_reset_enable, port->number, port,
    261                     &dev_addr, &port->attached_device, NULL, NULL, NULL);
    262         } while (ret != EOK && ++count < 4);
     258        int ret = usb_hc_new_device_wrapper(port->rh, &port->hc_connection,
     259            speed, uhci_port_reset_enable, port->number, port,
     260            &dev_addr, &port->attached_device, NULL, NULL, NULL);
    263261
    264262        if (ret != EOK) {
     
    315313        /* Wait for port to become enabled */
    316314        do {
     315                async_usleep(1000);
    317316                port_status = uhci_port_read_status(port);
    318317        } while ((port_status & STATUS_CONNECTED) &&
  • uspace/drv/usbflbk/Makefile

    r9e195e2c r456aea3  
    2828
    2929USPACE_PREFIX = ../..
    30 
    31 LIBS = \
    32         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    33         $(LIBUSB_PREFIX)/libusb.a \
    34         $(LIBDRV_PREFIX)/libdrv.a
    35 EXTRA_CFLAGS += \
    36         -I$(LIBUSB_PREFIX)/include \
    37         -I$(LIBUSBDEV_PREFIX)/include \
    38         -I$(LIBDRV_PREFIX)/include
    39 
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include
    4032BINARY = usbflbk
    4133
  • uspace/drv/usbhid/Makefile

    r9e195e2c r456aea3  
    2828
    2929USPACE_PREFIX = ../..
    30 
    31 LIBS = \
    32         $(LIBUSBHID_PREFIX)/libusbhid.a \
    33         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    34         $(LIBUSB_PREFIX)/libusb.a \
    35         $(LIBDRV_PREFIX)/libdrv.a
    36 EXTRA_CFLAGS += \
    37         -I. \
    38         -I$(LIBUSB_PREFIX)/include \
    39         -I$(LIBUSBDEV_PREFIX)/include \
    40         -I$(LIBUSBHID_PREFIX)/include \
    41         -I$(LIBDRV_PREFIX)/include
    42 
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
    4332BINARY = usbhid
    4433
  • uspace/drv/usbhid/mouse/mousedev.c

    r9e195e2c r456aea3  
    309309         * Wheel
    310310         */
    311         int wheel = 0;
     311        int wheel;
    312312       
    313313        path = usb_hid_report_path();
  • uspace/drv/usbhub/Makefile

    r9e195e2c r456aea3  
    2828
    2929USPACE_PREFIX = ../..
    30 
    31 LIBS = \
    32         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    33         $(LIBUSB_PREFIX)/libusb.a \
    34         $(LIBDRV_PREFIX)/libdrv.a
    35 EXTRA_CFLAGS += \
    36         -I$(LIBUSB_PREFIX)/include \
    37         -I$(LIBUSBDEV_PREFIX)/include \
    38         -I$(LIBDRV_PREFIX)/include
    39 
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include
    4032BINARY = usbhub
    4133
  • uspace/drv/usbhub/ports.c

    r9e195e2c r456aea3  
    5353        size_t port;
    5454        usb_speed_t speed;
    55 };
    56 
    57 /**
    58  * count of port status changes that are not explicitly handled by
    59  * any function here and must be cleared by hand
    60  */
    61 static const unsigned int non_handled_changes_count = 2;
    62 
    63 /**
    64  * port status changes that are not explicitly handled by
    65  * any function here and must be cleared by hand
    66  */
    67 static const int non_handled_changes[] =  {
    68         USB_HUB_FEATURE_C_PORT_ENABLE,
    69         USB_HUB_FEATURE_C_PORT_SUSPEND
    7055};
    7156
     
    146131            &status, USB_HUB_FEATURE_C_PORT_CONNECTION,false);
    147132        usb_port_status_set_bit(
     133            &status, USB_HUB_FEATURE_PORT_RESET,false);
     134        usb_port_status_set_bit(
    148135            &status, USB_HUB_FEATURE_C_PORT_RESET,false);
    149136        usb_port_status_set_bit(
    150137            &status, USB_HUB_FEATURE_C_PORT_OVER_CURRENT,false);
    151        
    152         //clearing not yet handled changes     
    153         unsigned int feature_idx;
    154         for(feature_idx = 0;feature_idx<non_handled_changes_count;
    155             ++feature_idx){
    156                 unsigned int bit_idx = non_handled_changes[feature_idx];
    157                 if(status & (1<<bit_idx)){
    158                         usb_log_info(
    159                             "there was not yet handled change on port %d: %d"
    160                             ";clearing it\n",
    161                         port, bit_idx);
    162                         int opResult = usb_hub_clear_port_feature(
    163                             hub->control_pipe,
    164                             port, bit_idx);
    165                         if (opResult != EOK) {
    166                                 usb_log_warning(
    167                                     "could not clear port flag %d: %d\n",
    168                                     bit_idx, opResult
    169                                     );
    170                         }
    171                         usb_port_status_set_bit(
    172                             &status, bit_idx,false);
    173                 }
    174         }
    175         if(status>>16){
    176                 usb_log_info("there is still some unhandled change %X\n",
    177                     status);
     138        /// \TODO what about port power change?
     139        if (status >> 16) {
     140                usb_log_info("there was unsupported change on port %d: %X\n",
     141                        port, status);
     142
    178143        }
    179144}
     
    257222                    "Port %zu reset complete but port not enabled.\n",
    258223                    (size_t) port);
    259         }
    260         /* Clear the port reset change. */
    261         int rc = usb_hub_clear_port_feature(hub->control_pipe,
    262             port, USB_HUB_FEATURE_C_PORT_RESET);
    263         if (rc != EOK) {
    264                 usb_log_error("Failed to clear port %d reset feature: %s.\n",
    265                     port, str_error(rc));
    266224        }
    267225}
     
    361319        fibril_mutex_unlock(&my_port->reset_mutex);
    362320
     321        /* Clear the port reset change. */
     322        rc = usb_hub_clear_port_feature(hub->control_pipe,
     323            port_no, USB_HUB_FEATURE_C_PORT_RESET);
     324        if (rc != EOK) {
     325                usb_log_error("Failed to clear port %d reset feature: %s.\n",
     326                    port_no, str_error(rc));
     327                return rc;
     328        }
     329
    363330        if (my_port->reset_okay) {
    364331                return EOK;
  • uspace/drv/usbmast/Makefile

    r9e195e2c r456aea3  
    2828
    2929USPACE_PREFIX = ../..
    30 
    31 LIBS = \
    32         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    33         $(LIBUSB_PREFIX)/libusb.a \
    34         $(LIBDRV_PREFIX)/libdrv.a
    35 EXTRA_CFLAGS += \
    36         -I$(LIBUSB_PREFIX)/include \
    37         -I$(LIBUSBDEV_PREFIX)/include \
    38         -I$(LIBDRV_PREFIX)/include
    39 
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include
    4032BINARY = usbmast
    4133
    4234SOURCES = \
    43         inquiry.c \
    4435        main.c \
    4536        mast.c
  • uspace/drv/usbmast/main.c

    r9e195e2c r456aea3  
    7575};
    7676
     77#define BITS_GET_MASK(type, bitcount) (((type)(1 << (bitcount)))-1)
     78#define BITS_GET_MID_MASK(type, bitcount, offset) \
     79        ((type)( BITS_GET_MASK(type, (bitcount) + (offset)) - BITS_GET_MASK(type, bitcount) ))
     80#define BITS_GET(type, number, bitcount, offset) \
     81        ((type)( (number) & (BITS_GET_MID_MASK(type, bitcount, offset)) ) >> (offset))
     82
     83#define INQUIRY_RESPONSE_LENGTH 35
     84
     85static void try_inquiry(usb_device_t *dev)
     86{
     87        scsi_cmd_inquiry_t inquiry = {
     88                .op_code = 0x12,
     89                .lun_evpd = 0,
     90                .page_code = 0,
     91                .alloc_length = INQUIRY_RESPONSE_LENGTH,
     92                .ctrl = 0
     93        };
     94        size_t response_len;
     95        uint8_t response[INQUIRY_RESPONSE_LENGTH];
     96
     97        int rc;
     98
     99        rc = usb_massstor_data_in(GET_BULK_IN(dev), GET_BULK_OUT(dev),
     100            0xDEADBEEF, 0, (uint8_t *) &inquiry, sizeof(inquiry),
     101            response, INQUIRY_RESPONSE_LENGTH, &response_len);
     102
     103        if (rc != EOK) {
     104                usb_log_error("Failed to probe device %s using %s: %s.\n",
     105                   dev->ddf_dev->name, "SCSI:INQUIRY", str_error(rc));
     106                return;
     107        }
     108
     109        if (response_len < 8) {
     110                usb_log_error("The SCSI response is too short.\n");
     111                return;
     112        }
     113
     114        /*
     115         * This is an ugly part of the code. We will parse the returned
     116         * data by hand and try to get as many useful data as possible.
     117         */
     118        int device_type = BITS_GET(uint8_t, response[0], 5, 0);
     119        int removable = BITS_GET(uint8_t, response[1], 1, 7);
     120
     121        usb_log_info("SCSI information for device `%s':\n", dev->ddf_dev->name);
     122        usb_log_info("  - peripheral device type: %d\n", device_type);
     123        usb_log_info("  - removable: %s\n", removable ? "yes" : "no");
     124
     125        if (response_len < 32) {
     126                return;
     127        }
     128
     129        char dev_vendor[9];
     130        str_ncpy(dev_vendor, 9, (const char *) &response[8], 8);
     131        usb_log_info("  - vendor: '%s'\n", dev_vendor);
     132
     133        char dev_product[9];
     134        str_ncpy(dev_product, 9, (const char *) &response[16], 8);
     135        usb_log_info("  - product: '%s'\n", dev_vendor);
     136}
     137
    77138/** Callback when new device is attached and recognized as a mass storage.
    78139 *
     
    107168            (size_t) dev->pipes[BULK_OUT_EP].descriptor->max_packet_size);
    108169
    109         size_t lun_count = usb_masstor_get_lun_count(dev);
    110 
    111         usb_massstor_inquiry_result_t inquiry;
    112         rc = usb_massstor_inquiry(dev, BULK_IN_EP, BULK_OUT_EP, &inquiry);
    113         if (rc != EOK) {
    114                 usb_log_warning("Failed to inquiry device `%s': %s.\n",
    115                     dev->ddf_dev->name, str_error(rc));
    116                 return EOK;
    117         }
    118 
    119         usb_log_info("Mass storage `%s': " \
    120             "`%s' by `%s' is %s (%s), %zu LUN(s).\n",
    121             dev->ddf_dev->name,
    122             inquiry.product_and_revision, inquiry.vendor_id,
    123             usb_str_masstor_scsi_peripheral_device_type(inquiry.peripheral_device_type),
    124             inquiry.removable ? "removable" : "non-removable",
    125             lun_count);
     170        try_inquiry(dev);
    126171
    127172        return EOK;
  • uspace/drv/usbmast/mast.c

    r9e195e2c r456aea3  
    4040#include <str_error.h>
    4141#include <usb/debug.h>
    42 #include <usb/request.h>
    4342
    4443bool usb_mast_verbose = true;
     
    6463 * @return Error code.
    6564 */
    66 int usb_massstor_data_in(usb_device_t *dev,
    67     size_t bulk_in_pipe_index, size_t bulk_out_pipe_index,
     65int usb_massstor_data_in(usb_pipe_t *bulk_in_pipe, usb_pipe_t *bulk_out_pipe,
    6866    uint32_t tag, uint8_t lun, void *cmd, size_t cmd_size,
    6967    void *in_buffer, size_t in_buffer_size, size_t *received_size)
     
    7169        int rc;
    7270        size_t act_size;
    73         usb_pipe_t *bulk_in_pipe = dev->pipes[bulk_in_pipe_index].pipe;
    74         usb_pipe_t *bulk_out_pipe = dev->pipes[bulk_out_pipe_index].pipe;
    7571
    7672        /* Prepare CBW - command block wrapper */
     
    139135}
    140136
    141 /** Perform bulk-only mass storage reset.
    142  *
    143  * @param dev Device to be reseted.
    144  * @return Error code.
    145  */
    146 int usb_massstor_reset(usb_device_t *dev)
    147 {
    148         return usb_control_request_set(&dev->ctrl_pipe,
    149             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    150             0xFF, 0, dev->interface_no, NULL, 0);
    151 }
    152 
    153 /** Perform complete reset recovery of bulk-only mass storage.
    154  *
    155  * Notice that no error is reported because if this fails, the error
    156  * would reappear on next transaction somehow.
    157  *
    158  * @param dev Device to be reseted.
    159  * @param bulk_in_idx Index of bulk in pipe.
    160  * @param bulk_out_idx Index of bulk out pipe.
    161  */
    162 void usb_massstor_reset_recovery(usb_device_t *dev,
    163     size_t bulk_in_idx, size_t bulk_out_idx)
    164 {
    165         /* We would ignore errors here because if this fails
    166          * we are doomed anyway and any following transaction would fail.
    167          */
    168         usb_massstor_reset(dev);
    169         usb_pipe_clear_halt(&dev->ctrl_pipe, dev->pipes[bulk_in_idx].pipe);
    170         usb_pipe_clear_halt(&dev->ctrl_pipe, dev->pipes[bulk_out_idx].pipe);
    171 }
    172 
    173 /** Get max LUN of a mass storage device.
    174  *
    175  * @see usb_masstor_get_lun_count
    176  *
    177  * @warning Error from this command does not necessarily indicate malfunction
    178  * of the device. Device does not need to support this request.
    179  * You shall rather use usb_masstor_get_lun_count.
    180  *
    181  * @param dev Mass storage device.
    182  * @return Error code of maximum LUN (index, not count).
    183  */
    184 int usb_massstor_get_max_lun(usb_device_t *dev)
    185 {
    186         uint8_t max_lun;
    187         size_t data_recv_len;
    188         int rc = usb_control_request_get(&dev->ctrl_pipe,
    189             USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
    190             0xFE, 0, dev->interface_no, &max_lun, 1, &data_recv_len);
    191         if (rc != EOK) {
    192                 return rc;
    193         }
    194         if (data_recv_len != 1) {
    195                 return EEMPTY;
    196         }
    197         return (int) max_lun;
    198 }
    199 
    200 /** Get number of LUNs supported by mass storage device.
    201  *
    202  * @warning This function hides any error during the request
    203  * (typically that shall not be a problem).
    204  *
    205  * @param dev Mass storage device.
    206  * @return Number of LUNs.
    207  */
    208 size_t usb_masstor_get_lun_count(usb_device_t *dev)
    209 {
    210         int max_lun = usb_massstor_get_max_lun(dev);
    211         if (max_lun < 0) {
    212                 max_lun = 1;
    213         } else {
    214                 max_lun++;
    215         }
    216 
    217         return (size_t) max_lun;
    218 }
    219 
    220137/**
    221138 * @}
  • uspace/drv/usbmast/mast.h

    r9e195e2c r456aea3  
    4040#include <usb/usb.h>
    4141#include <usb/pipes.h>
    42 #include <usb/devdrv.h>
    4342
    44 /** Result of SCSI INQUIRY command.
    45  * This is already parsed structure, not the original buffer returned by
    46  * the device.
    47  */
    48 typedef struct {
    49         /** SCSI peripheral device type. */
    50         int peripheral_device_type;
    51         /** Whether the device is removable. */
    52         bool removable;
    53         /** Vendor ID string. */
    54         char vendor_id[9];
    55         /** Product ID and product revision string. */
    56         char product_and_revision[12];
    57 } usb_massstor_inquiry_result_t;
    58 
    59 int usb_massstor_data_in(usb_device_t *dev, size_t, size_t,
    60     uint32_t, uint8_t, void *, size_t, void *, size_t, size_t *);
    61 int usb_massstor_reset(usb_device_t *);
    62 void usb_massstor_reset_recovery(usb_device_t *, size_t, size_t);
    63 int usb_massstor_get_max_lun(usb_device_t *);
    64 size_t usb_masstor_get_lun_count(usb_device_t *);
    65 int usb_massstor_inquiry(usb_device_t *, size_t, size_t,
    66     usb_massstor_inquiry_result_t *);
    67 const char *usb_str_masstor_scsi_peripheral_device_type(int);
     43int usb_massstor_data_in(usb_pipe_t *, usb_pipe_t *, uint32_t, uint8_t,
     44    void *, size_t, void *, size_t, size_t *);
    6845
    6946#endif
  • uspace/drv/usbmid/Makefile

    r9e195e2c r456aea3  
    2828
    2929USPACE_PREFIX = ../..
    30 
    31 LIBS = \
    32         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    33         $(LIBUSB_PREFIX)/libusb.a \
    34         $(LIBDRV_PREFIX)/libdrv.a
    35 EXTRA_CFLAGS += \
    36         -I$(LIBUSB_PREFIX)/include \
    37         -I$(LIBUSBDEV_PREFIX)/include \
    38         -I$(LIBDRV_PREFIX)/include
    39        
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include
    4032BINARY = usbmid
    4133
  • uspace/drv/usbmouse/Makefile

    r9e195e2c r456aea3  
    2828
    2929USPACE_PREFIX = ../..
    30 
    31 LIBS = \
    32         $(LIBUSBHID_PREFIX)/libusbhid.a \
    33         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    34         $(LIBUSB_PREFIX)/libusb.a \
    35         $(LIBDRV_PREFIX)/libdrv.a
    36 EXTRA_CFLAGS += \
    37         -I$(LIBUSB_PREFIX)/include \
    38         -I$(LIBUSBDEV_PREFIX)/include \
    39         -I$(LIBUSBHID_PREFIX)/include \
    40         -I$(LIBDRV_PREFIX)/include
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
    4132
    4233BINARY = usbmouse
  • uspace/drv/vhc/Makefile

    r9e195e2c r456aea3  
    2929USPACE_PREFIX = ../..
    3030LIBS = \
    31         $(LIBUSBDEV_PREFIX)/libusbdev.a \
    32         $(LIBUSBHOST_PREFIX)/libusbhost.a \
    3331        $(LIBUSB_PREFIX)/libusb.a \
    3432        $(LIBUSBVIRT_PREFIX)/libusbvirt.a \
     
    3634EXTRA_CFLAGS += \
    3735        -I$(LIBUSBVIRT_PREFIX)/include \
    38         -I$(LIBUSBDEV_PREFIX)/include \
    39         -I$(LIBUSBHOST_PREFIX)/include \
    4036        -I$(LIBUSB_PREFIX)/include \
    4137        -I$(LIBDRV_PREFIX)/include
  • uspace/drv/vhc/connhost.c

    r9e195e2c r456aea3  
    9494}
    9595
    96 /** Find device handle by address interface function.
    97  *
    98  * @param[in] fun DDF function that was called.
    99  * @param[in] address Address in question.
    100  * @param[out] handle Where to store device handle if found.
    101  * @return Error code.
    102  */
    103 static int find_by_address(ddf_fun_t *fun, usb_address_t address,
    104     devman_handle_t *handle)
    105 {
    106         VHC_DATA(vhc, fun);
    107         bool found =
    108             usb_device_keeper_find_by_address(&vhc->dev_keeper, address, handle);
    109         return found ? EOK : ENOENT;
    110 }
    111 
    11296/** Release previously requested address.
    11397 *
     
    460444        .request_address = request_address,
    461445        .bind_address = bind_address,
    462         .find_by_address = find_by_address,
    463446        .release_address = release_address,
    464447
  • uspace/drv/vhc/main.c

    r9e195e2c r456aea3  
    104104        }
    105105
    106         rc = ddf_fun_add_to_class(hc, USB_HC_DDF_CLASS_NAME);
    107         if (rc != EOK) {
    108                 usb_log_fatal("Failed to add function to HC class: %s.\n",
    109                     str_error(rc));
    110                 free(data);
    111                 return rc;
    112         }
     106        ddf_fun_add_to_class(hc, "usbhc");
    113107
    114108        virtual_hub_device_init(hc);
  • uspace/drv/vhc/transfer.c

    r9e195e2c r456aea3  
    135135                if (transfer->direction == USB_DIRECTION_IN) {
    136136                        rc = usbvirt_ipc_send_control_read(phone,
     137                            transfer->endpoint,
    137138                            transfer->setup_buffer, transfer->setup_buffer_size,
    138139                            transfer->data_buffer, transfer->data_buffer_size,
     
    141142                        assert(transfer->direction == USB_DIRECTION_OUT);
    142143                        rc = usbvirt_ipc_send_control_write(phone,
     144                            transfer->endpoint,
    143145                            transfer->setup_buffer, transfer->setup_buffer_size,
    144146                            transfer->data_buffer, transfer->data_buffer_size);
  • uspace/lib/c/generic/devman.c

    r9e195e2c r456aea3  
    374374}
    375375
    376 int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size)
    377 {
    378         int phone = devman_get_phone(DEVMAN_CLIENT, 0);
    379 
    380         if (phone < 0)
    381                 return phone;
    382 
    383         async_serialize_start();
    384 
    385         ipc_call_t answer;
    386         aid_t req = async_send_1(phone, DEVMAN_DEVICE_GET_DEVICE_PATH,
    387             handle, &answer);
    388 
    389         ipc_call_t data_request_call;
    390         aid_t data_request = async_data_read(phone, path, path_size,
    391             &data_request_call);
    392         if (data_request == 0) {
    393                 async_wait_for(req, NULL);
    394                 async_serialize_end();
    395                 return ENOMEM;
    396         }
    397 
    398         sysarg_t data_request_rc;
    399         sysarg_t opening_request_rc;
    400         async_wait_for(data_request, &data_request_rc);
    401         async_wait_for(req, &opening_request_rc);
    402 
    403         async_serialize_end();
    404 
    405         if (data_request_rc != EOK) {
    406                 /* Prefer the return code of the opening request. */
    407                 if (opening_request_rc != EOK) {
    408                         return (int) opening_request_rc;
    409                 } else {
    410                         return (int) data_request_rc;
    411                 }
    412         }
    413         if (opening_request_rc != EOK) {
    414                 return (int) opening_request_rc;
    415         }
    416 
    417         path[path_size - 1] = 0;
    418 
    419         if (IPC_GET_ARG2(data_request_call) >= path_size) {
    420                 return ELIMIT;
    421         }
    422 
    423         return EOK;
    424 }
    425 
    426376
    427377/** @}
  • uspace/lib/c/include/devman.h

    r9e195e2c r456aea3  
    5555extern int devman_device_get_handle_by_class(const char *, const char *,
    5656    devman_handle_t *, unsigned int);
    57 extern int devman_get_device_path(devman_handle_t, char *, size_t);
    5857
    5958extern int devman_add_device_to_class(devman_handle_t, const char *);
  • uspace/lib/c/include/ipc/devman.h

    r9e195e2c r456aea3  
    149149typedef enum {
    150150        DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
    151         DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
    152         DEVMAN_DEVICE_GET_DEVICE_PATH
     151        DEVMAN_DEVICE_GET_HANDLE_BY_CLASS
    153152} client_to_devman_t;
    154153
  • uspace/lib/drv/generic/remote_usbhc.c

    r9e195e2c r456aea3  
    5252static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    5353static void remote_usbhc_bind_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    54 static void remote_usbhc_find_by_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    5554static void remote_usbhc_release_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    5655static void remote_usbhc_register_endpoint(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     
    6261        remote_usbhc_request_address,
    6362        remote_usbhc_bind_address,
    64         remote_usbhc_find_by_address,
    6563        remote_usbhc_release_address,
    6664
     
    165163}
    166164
    167 void remote_usbhc_find_by_address(ddf_fun_t *fun, void *iface,
    168     ipc_callid_t callid, ipc_call_t *call)
    169 {
    170         usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
    171 
    172         if (!usb_iface->find_by_address) {
    173                 async_answer_0(callid, ENOTSUP);
    174                 return;
    175         }
    176 
    177         usb_address_t address = (usb_address_t) DEV_IPC_GET_ARG1(*call);
    178         devman_handle_t handle;
    179         int rc = usb_iface->find_by_address(fun, address, &handle);
    180 
    181         if (rc == EOK) {
    182                 async_answer_1(callid, EOK, handle);
    183         } else {
    184                 async_answer_0(callid, rc);
    185         }
    186 }
    187 
    188165void remote_usbhc_release_address(ddf_fun_t *fun, void *iface,
    189166    ipc_callid_t callid, ipc_call_t *call)
     
    325302        async_transaction_t *trans = async_transaction_create(callid);
    326303        if (trans == NULL) {
    327                 async_answer_0(data_callid, ENOMEM);
    328304                async_answer_0(callid, ENOMEM);
    329305                return;
     
    338314
    339315        if (rc != EOK) {
    340                 async_answer_0(data_callid, rc);
    341316                async_answer_0(callid, rc);
    342317                async_transaction_destroy(trans);
     
    485460        async_transaction_t *trans = async_transaction_create(callid);
    486461        if (trans == NULL) {
    487                 async_answer_0(data_callid, ENOMEM);
    488462                async_answer_0(callid, ENOMEM);
    489463                free(setup_packet);
     
    495469        trans->buffer = malloc(data_len);
    496470        if (trans->buffer == NULL) {
    497                 async_answer_0(data_callid, ENOMEM);
    498471                async_answer_0(callid, ENOMEM);
    499472                async_transaction_destroy(trans);
     
    507480
    508481        if (rc != EOK) {
    509                 async_answer_0(data_callid, rc);
    510482                async_answer_0(callid, rc);
    511483                async_transaction_destroy(trans);
  • uspace/lib/drv/include/usb_iface.h

    r9e195e2c r456aea3  
    4949         * - arbitrary error code if returned by remote implementation
    5050         * - EOK - handle found, first parameter contains the USB address
    51          *
    52          * The handle must be the one used for binding USB address with
    53          * it (IPC_M_USBHC_BIND_ADDRESS), otherwise the host controller
    54          * (that this request would eventually reach) would not be able
    55          * to find it.
    56          * The problem is that this handle is actually assigned to the
    57          * function inside driver of the parent device (usually hub driver).
    58          * To bypass this problem, the initial caller specify handle as
    59          * zero and the first parent assigns the actual value.
    60          * See usb_iface_get_address_hub_child_impl() implementation
    61          * that could be assigned to device ops of a child device of in a
    62          * hub driver.
    63          * For example, the USB multi interface device driver (MID)
    64          * passes this initial zero without any modification because the
    65          * handle must be resolved by its parent.
    6651         */
    6752        IPC_M_USB_GET_ADDRESS,
  • uspace/lib/drv/include/usbhc_iface.h

    r9e195e2c r456aea3  
    105105        IPC_M_USBHC_BIND_ADDRESS,
    106106
    107         /** Get handle binded with given USB address.
    108          * Parameters
    109          * - USB address
    110          * Answer:
    111          * - EOK - address binded, first parameter is the devman handle
    112          * - ENOENT - address is not in use at the moment
    113          */
    114         IPC_M_USBHC_GET_HANDLE_BY_ADDRESS,
    115 
    116107        /** Release address in use.
    117108         * Arguments:
     
    216207        int (*request_address)(ddf_fun_t *, usb_speed_t, usb_address_t *);
    217208        int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t);
    218         int (*find_by_address)(ddf_fun_t *, usb_address_t, devman_handle_t *);
    219209        int (*release_address)(ddf_fun_t *, usb_address_t);
    220210
  • uspace/lib/usb/Makefile

    r9e195e2c r456aea3  
    2929USPACE_PREFIX = ../..
    3030LIBRARY = libusb
    31 EXTRA_CFLAGS += \
    32         -I$(LIBDRV_PREFIX)/include \
    33         -Iinclude
     31LIBS = $(LIBDRV_PREFIX)/libdrv.a
     32EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -Iinclude
    3433
    3534SOURCES = \
     35        src/addrkeep.c \
     36        src/altiface.c \
    3637        src/class.c \
    3738        src/ddfiface.c \
    3839        src/debug.c \
    39         src/driver.c \
     40        src/devdrv.c \
     41        src/devpoll.c \
     42        src/dp.c \
    4043        src/dump.c \
    41         src/host.c \
    42         src/usb.c
     44        src/hidiface.c \
     45        src/hidpath.c \
     46        src/hidparser.c \
     47        src/hiddescriptor.c \
     48        src/hub.c \
     49        src/pipepriv.c \
     50        src/pipes.c \
     51        src/pipesinit.c \
     52        src/pipesio.c \
     53        src/recognise.c \
     54        src/request.c \
     55        src/usb.c \
     56        src/usbdevice.c \
     57        src/hidreq.c \
     58        src/hidreport.c \
     59        src/host/device_keeper.c \
     60        src/host/batch.c \
     61        src/host/endpoint.c \
     62        src/host/usb_endpoint_manager.c
    4363
    4464include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/usb/include/usb/ddfiface.h

    r9e195e2c r456aea3  
    3737
    3838#include <sys/types.h>
     39#include <usb/usbdevice.h>
    3940#include <usb_iface.h>
    4041
  • uspace/lib/usb/include/usb/descriptor.h

    r9e195e2c r456aea3  
    167167} __attribute__ ((packed)) usb_standard_endpoint_descriptor_t;
    168168
    169 /** Part of standard USB HID descriptor specifying one class descriptor.
    170  *
    171  * (See HID Specification, p.22)
    172  */
    173 typedef struct {
    174         /** Type of class-specific descriptor (Report or Physical). */
    175         uint8_t type;
    176         /** Length of class-specific descriptor in bytes. */
    177         uint16_t length;
    178 } __attribute__ ((packed)) usb_standard_hid_class_descriptor_info_t;
    179 
    180 /** Standard USB HID descriptor.
    181  *
    182  * (See HID Specification, p.22)
    183  *
    184  * It is actually only the "header" of the descriptor, it does not contain
    185  * the last two mandatory fields (type and length of the first class-specific
    186  * descriptor).
    187  */
    188 typedef struct {
    189         /** Total size of this descriptor in bytes.
    190          *
    191          * This includes all class-specific descriptor info - type + length
    192          * for each descriptor.
    193          */
    194         uint8_t length;
    195         /** Descriptor type (USB_DESCTYPE_HID). */
    196         uint8_t descriptor_type;
    197         /** HID Class Specification release. */
    198         uint16_t spec_release;
    199         /** Country code of localized hardware. */
    200         uint8_t country_code;
    201         /** Total number of class-specific (i.e. Report and Physical)
    202          * descriptors.
    203          *
    204          * @note There is always only one Report descriptor.
    205          */
    206         uint8_t class_desc_count;
    207         /** First mandatory class descriptor (Report) info. */
    208         usb_standard_hid_class_descriptor_info_t report_desc_info;
    209 } __attribute__ ((packed)) usb_standard_hid_descriptor_t;
    210 
    211169#endif
    212170/**
  • uspace/lib/usb/include/usb/usb.h

    r9e195e2c r456aea3  
    172172} usb_packet_id;
    173173
    174 /** Class name for USB host controllers. */
    175 #define USB_HC_DDF_CLASS_NAME "usbhc"
    176 
    177174#endif
    178175/**
  • uspace/lib/usb/src/ddfiface.c

    r9e195e2c r456aea3  
    3737#include <async.h>
    3838#include <usb/ddfiface.h>
    39 #include <usb/driver.h>
    4039#include <usb/debug.h>
    4140#include <errno.h>
  • uspace/lib/usb/src/dump.c

    r9e195e2c r456aea3  
    4141#include <usb/descriptor.h>
    4242#include <usb/classes/classes.h>
     43#include <usb/classes/hid.h>
    4344
    4445/** Mapping between descriptor id and dumping function. */
  • uspace/lib/usbvirt/Makefile

    r9e195e2c r456aea3  
    3030LIBRARY = libusbvirt
    3131
    32 EXTRA_CFLAGS = \
    33         -I$(LIBDRV_PREFIX)/include \
    34         -I$(LIBUSB_PREFIX)/include \
    35         -I$(LIBUSBDEV_PREFIX)/include \
    36         -Iinclude
     32EXTRA_CFLAGS = -I$(LIBUSB_PREFIX)/include -I$(LIBDRV_PREFIX)/include -Iinclude
    3733
    3834SOURCES = \
     35        src/ipc.c \
    3936        src/ctrltransfer.c \
    40         src/device.c \
    41         src/ipc_dev.c \
    42         src/ipc_hc.c \
    4337        src/stdreq.c \
    4438        src/transfer.c
  • uspace/lib/usbvirt/include/usbvirt/device.h

    r9e195e2c r456aea3  
    3131 */
    3232/** @file
    33  * Virtual USB device.
     33 * @brief Virtual USB device.
    3434 */
    3535#ifndef LIBUSBVIRT_DEVICE_H_
     
    3939#include <usb/request.h>
    4040
    41 /** Maximum number of endpoints supported by virtual USB. */
    4241#define USBVIRT_ENDPOINT_MAX 16
    4342
    4443typedef struct usbvirt_device usbvirt_device_t;
    4544
    46 /** Callback for data to device (OUT transaction).
    47  *
    48  * @param dev Virtual device to which the transaction belongs.
    49  * @param endpoint Target endpoint number.
    50  * @param transfer_type Transfer type.
    51  * @param buffer Data buffer.
    52  * @param buffer_size Size of the buffer in bytes.
    53  * @return Error code.
    54  */
    55 typedef int (*usbvirt_on_data_to_device_t)(usbvirt_device_t *dev,
    56     usb_endpoint_t endpoint, usb_transfer_type_t transfer_type,
    57     void *buffer, size_t buffer_size);
     45typedef int (*usbvirt_on_data_to_device_t)(usbvirt_device_t *, usb_endpoint_t,
     46    usb_transfer_type_t, void *, size_t);
     47typedef int (*usbvirt_on_data_from_device_t)(usbvirt_device_t *, usb_endpoint_t,
     48    usb_transfer_type_t, void *, size_t, size_t *);
     49typedef int (*usbvirt_on_control_t)(usbvirt_device_t *,
     50    const usb_device_request_setup_packet_t *, uint8_t *, size_t *);
    5851
    59 /** Callback for data from device (IN transaction).
    60  *
    61  * @param dev Virtual device to which the transaction belongs.
    62  * @param endpoint Target endpoint number.
    63  * @param transfer_type Transfer type.
    64  * @param buffer Data buffer to write answer to.
    65  * @param buffer_size Size of the buffer in bytes.
    66  * @param act_buffer_size Write here how many bytes were actually written.
    67  * @return Error code.
    68  */
    69 typedef int (*usbvirt_on_data_from_device_t)(usbvirt_device_t *dev,
    70     usb_endpoint_t endpoint, usb_transfer_type_t transfer_type,
    71     void *buffer, size_t buffer_size, size_t *act_buffer_size);
    72 
    73 /** Callback for control transfer on endpoint zero.
    74  *
    75  * Notice that size of the data buffer is expected to be read from the
    76  * setup packet.
    77  *
    78  * @param dev Virtual device to which the transaction belongs.
    79  * @param setup_packet Standard setup packet.
    80  * @param data Data (might be NULL).
    81  * @param act_data_size Size of returned data in bytes.
    82  * @return Error code.
    83  */
    84 typedef int (*usbvirt_on_control_t)(usbvirt_device_t *dev,
    85     const usb_device_request_setup_packet_t *setup_packet,
    86     uint8_t *data, size_t *act_data_size);
    87 
    88 /** Callback for control request on a virtual USB device.
    89  *
    90  * See usbvirt_control_reply_helper() for simple way of answering
    91  * control read requests.
    92  */
    9352typedef struct {
    94         /** Request direction (in or out). */
    9553        usb_direction_t req_direction;
    96         /** Request recipient (device, interface or endpoint). */
    9754        usb_request_recipient_t req_recipient;
    98         /** Request type (standard, class or vendor). */
    9955        usb_request_type_t req_type;
    100         /** Actual request code. */
    10156        uint8_t request;
    102         /** Request handler name for debugging purposes. */
    10357        const char *name;
    104         /** Callback to be executed on matching request. */
    10558        usbvirt_on_control_t callback;
    10659} usbvirt_control_request_handler_t;
     
    12477} usbvirt_device_configuration_t;
    12578
    126 /** Standard USB descriptors for virtual device. */
     79/** Standard USB descriptors. */
    12780typedef struct {
    12881        /** Standard device descriptor.
     
    149102} usbvirt_device_state_t;
    150103
    151 /** Ops structure for virtual USB device. */
    152104typedef struct {
    153         /** Callbacks for data to device.
    154          * Index zero is ignored.
    155          */
    156105        usbvirt_on_data_to_device_t data_out[USBVIRT_ENDPOINT_MAX];
    157         /** Callbacks for data from device.
    158          * Index zero is ignored.
    159          */
    160106        usbvirt_on_data_from_device_t data_in[USBVIRT_ENDPOINT_MAX];
    161         /** Array of control handlers.
    162          * Last handler is expected to have the @c callback field set to NULL
    163          */
    164107        usbvirt_control_request_handler_t *control;
    165         /** Callback when device changes state.
    166          *
    167          * The value of @c state attribute of @p dev device is not
    168          * defined during call of this function.
    169          *
    170          * @param dev The virtual USB device.
    171          * @param old_state Old device state.
    172          * @param new_state New device state.
    173          */
    174108        void (*state_changed)(usbvirt_device_t *dev,
    175109            usbvirt_device_state_t old_state, usbvirt_device_state_t new_state);
    176110} usbvirt_device_ops_t;
    177111
    178 /** Virtual USB device. */
    179112struct usbvirt_device {
    180         /** Name for debugging purposes. */
    181113        const char *name;
    182         /** Custom device data. */
    183114        void *device_data;
    184         /** Device ops. */
    185115        usbvirt_device_ops_t *ops;
    186         /** Device descriptors. */
    187116        usbvirt_descriptors_t *descriptors;
    188         /** Current device address.
    189          * You shall treat this field as read only in your code.
    190          */
    191117        usb_address_t address;
    192         /** Current device state.
    193          * You shall treat this field as read only in your code.
    194          */
    195118        usbvirt_device_state_t state;
    196         /** Phone to the host controller.
    197          * You shall treat this field as read only in your code.
    198          */
    199         int vhc_phone;
    200119};
    201120
    202121int usbvirt_device_plug(usbvirt_device_t *, const char *);
    203 void usbvirt_device_unplug(usbvirt_device_t *);
    204122
    205123void usbvirt_control_reply_helper(const usb_device_request_setup_packet_t *,
  • uspace/lib/usbvirt/include/usbvirt/ipc.h

    r9e195e2c r456aea3  
    11/*
    2  * Copyright (c) 2011 Vojtech Horky
     2 * Copyright (c) 2010 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/** @file
    33  * IPC wrappers for virtual USB.
     33 * @brief Virtual USB device.
    3434 */
    3535#ifndef LIBUSBVIRT_IPC_H_
     
    4040#include <bool.h>
    4141
    42 /** IPC methods communication between host controller and virtual device. */
    4342typedef enum {
    4443        IPC_M_USBVIRT_GET_NAME = IPC_FIRST_USER_METHOD + 80,
     
    4645        IPC_M_USBVIRT_CONTROL_WRITE,
    4746        IPC_M_USBVIRT_INTERRUPT_IN,
    48         IPC_M_USBVIRT_INTERRUPT_OUT,
    49         IPC_M_USBVIRT_BULK_IN,
    50         IPC_M_USBVIRT_BULK_OUT
    51 } usbvirt_hc_to_device_method_t;
     47        IPC_M_USBVIRT_INTERRUPT_OUT
     48} usbvirt_ipc_t;
    5249
    53 int usbvirt_ipc_send_control_read(int, void *, size_t,
     50int usbvirt_ipc_send_control_read(int, usb_endpoint_t, void *, size_t,
    5451    void *, size_t, size_t *);
    55 int usbvirt_ipc_send_control_write(int, void *, size_t,
     52int usbvirt_ipc_send_control_write(int, usb_endpoint_t, void *, size_t,
    5653    void *, size_t);
    5754int usbvirt_ipc_send_data_in(int, usb_endpoint_t, usb_transfer_type_t,
  • uspace/lib/usbvirt/src/ctrltransfer.c

    r9e195e2c r456aea3  
    1 /*
    2  * Copyright (c) 2011 Vojtech Horky
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  *
    9  * - Redistributions of source code must retain the above copyright
    10  *   notice, this list of conditions and the following disclaimer.
    11  * - Redistributions in binary form must reproduce the above copyright
    12  *   notice, this list of conditions and the following disclaimer in the
    13  *   documentation and/or other materials provided with the distribution.
    14  * - The name of the author may not be used to endorse or promote products
    15  *   derived from this software without specific prior written permission.
    16  *
    17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    27  */
    28 
    29 /** @addtogroup libusbvirt
    30  * @{
    31  */
    32 /** @file
    33  * Control transfer handling.
    34  */
    351#include "private.h"
    362#include <usb/request.h>
     
    395#include <errno.h>
    406
    41 /** Find and execute control transfer handler for virtual USB device.
    42  *
    43  * @param dev Target virtual device.
    44  * @param control_handlers Array of control request handlers.
    45  * @param setup Setup packet.
    46  * @param data Extra data.
    47  * @param data_sent_size Size of extra data in bytes.
    48  * @return Error code.
    49  * @retval EFORWARD No suitable handler found.
    50  */
    517int process_control_transfer(usbvirt_device_t *dev,
    528    usbvirt_control_request_handler_t *control_handlers,
     
    9652        return EFORWARD;
    9753}
    98 
    99 
    100 /**
    101  * @}
    102  */
  • uspace/lib/usbvirt/src/private.h

    r9e195e2c r456aea3  
    1 /*
    2  * Copyright (c) 2011 Vojtech Horky
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  *
    9  * - Redistributions of source code must retain the above copyright
    10  *   notice, this list of conditions and the following disclaimer.
    11  * - Redistributions in binary form must reproduce the above copyright
    12  *   notice, this list of conditions and the following disclaimer in the
    13  *   documentation and/or other materials provided with the distribution.
    14  * - The name of the author may not be used to endorse or promote products
    15  *   derived from this software without specific prior written permission.
    16  *
    17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    27  */
    28 
    29 /** @addtogroup libusbvirt
    30  * @{
    31  */
    32 /** @file
    33  * Private definitions.
    34  */
    35 #ifndef USBVIRT_PRIVATE_H_
    36 #define USBVIRT_PRIVATE_H_
    37 
    381#include <usbvirt/device.h>
    392
     
    447
    458extern usbvirt_control_request_handler_t library_handlers[];
    46 
    47 #endif
    48 /**
    49  * @}
    50  */
  • uspace/lib/usbvirt/src/stdreq.c

    r9e195e2c r456aea3  
    1 /*
    2  * Copyright (c) 2011 Vojtech Horky
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  *
    9  * - Redistributions of source code must retain the above copyright
    10  *   notice, this list of conditions and the following disclaimer.
    11  * - Redistributions in binary form must reproduce the above copyright
    12  *   notice, this list of conditions and the following disclaimer in the
    13  *   documentation and/or other materials provided with the distribution.
    14  * - The name of the author may not be used to endorse or promote products
    15  *   derived from this software without specific prior written permission.
    16  *
    17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    27  */
    28 
    29 /** @addtogroup libusbvirt
    30  * @{
    31  */
    32 /** @file
    33  * Standard control request handlers.
    34  */
    351#include "private.h"
    362#include <usb/request.h>
     
    384#include <errno.h>
    395
    40 /** Helper for replying to control read transfer from virtual USB device.
    41  *
    42  * This function takes care of copying data to answer buffer taking care
    43  * of buffer sizes properly.
    44  *
    45  * @param setup_packet The setup packet.
    46  * @param data Data buffer to write to.
    47  * @param act_size Where to write actual size of returned data.
    48  * @param actual_data Data to be returned.
    49  * @param actual_data_size Size of answer data (@p actual_data) in bytes.
    50  */
    516void usbvirt_control_reply_helper(const usb_device_request_setup_packet_t *setup_packet,
    527    uint8_t *data, size_t *act_size,
     
    189144}
    190145
    191 /** Standard request handlers. */
    192146usbvirt_control_request_handler_t library_handlers[] = {
    193147        {
     
    219173};
    220174
    221 /**
    222  * @}
    223  */
  • uspace/lib/usbvirt/src/transfer.c

    r9e195e2c r456aea3  
    3131 */
    3232/** @file
    33  * Transfer handling.
     33 *
    3434 */
    3535#include <usbvirt/device.h>
     
    3939#include "private.h"
    4040
    41 /** Process a control transfer to the virtual USB device.
    42  *
    43  * @param dev Target device.
    44  * @param setup Setup packet data.
    45  * @param setup_size Size of setup packet.
    46  * @param data Extra data (DATA stage).
    47  * @param data_size Size of extra data in bytes.
    48  * @param data_size_sent Number of actually send bytes during the transfer
    49  *      (only used for READ transfers).
    50  * @return Error code.
    51  */
    5241static int usbvirt_control_transfer(usbvirt_device_t *dev,
    5342    void *setup, size_t setup_size,
     
    8978}
    9079
    91 /** Issue a control write transfer to virtual USB device.
    92  *
    93  * @see usbvirt_control_transfer
    94  *
    95  * @param dev Target virtual device.
    96  * @param setup Setup data.
    97  * @param setup_size Size of setup packet.
    98  * @param data Extra data (DATA stage).
    99  * @param data_size Size of extra data buffer in bytes.
    100  * @return Error code.
    101  */
    10280int usbvirt_control_write(usbvirt_device_t *dev, void *setup, size_t setup_size,
    10381    void *data, size_t data_size)
     
    10785}
    10886
    109 /** Issue a control read transfer to virtual USB device.
    110  *
    111  * @see usbvirt_control_transfer
    112  *
    113  * @param dev Target virtual device.
    114  * @param setup Setup data.
    115  * @param setup_size Size of setup packet.
    116  * @param data Extra data (DATA stage).
    117  * @param data_size Size of extra data buffer in bytes.
    118  * @param data_size_sent Number of actually send bytes during the transfer.
    119  * @return Error code.
    120  */
    12187int usbvirt_control_read(usbvirt_device_t *dev, void *setup, size_t setup_size,
    12288    void *data, size_t data_size, size_t *data_size_sent)
     
    12692}
    12793
    128 /** Send data to virtual USB device.
    129  *
    130  * @param dev Target virtual device.
    131  * @param transf_type Transfer type (interrupt, bulk).
    132  * @param endpoint Endpoint number.
    133  * @param data Data sent from the driver to the device.
    134  * @param data_size Size of the @p data buffer in bytes.
    135  * @return Error code.
    136  */
    13794int usbvirt_data_out(usbvirt_device_t *dev, usb_transfer_type_t transf_type,
    13895    usb_endpoint_t endpoint, void *data, size_t data_size)
     
    151108}
    152109
    153 /** Request data from virtual USB device.
    154  *
    155  * @param dev Target virtual device.
    156  * @param transf_type Transfer type (interrupt, bulk).
    157  * @param endpoint Endpoint number.
    158  * @param data Where to stored data the device returns to the driver.
    159  * @param data_size Size of the @p data buffer in bytes.
    160  * @param data_size_sent Number of actually written bytes.
    161  * @return Error code.
    162  */
    163110int usbvirt_data_in(usbvirt_device_t *dev, usb_transfer_type_t transf_type,
    164111    usb_endpoint_t endpoint, void *data, size_t data_size, size_t *data_size_sent)
  • uspace/srv/devman/main.c

    r9e195e2c r456aea3  
    515515}
    516516
    517 /** Find device path by its handle. */
    518 static void devman_get_device_path_by_handle(ipc_callid_t iid,
    519     ipc_call_t *icall)
    520 {
    521         devman_handle_t handle = IPC_GET_ARG1(*icall);
    522 
    523         fun_node_t *fun = find_fun_node(&device_tree, handle);
    524         if (fun == NULL) {
    525                 async_answer_0(iid, ENOMEM);
    526                 return;
    527         }
    528 
    529         ipc_callid_t data_callid;
    530         size_t data_len;
    531         if (!async_data_read_receive(&data_callid, &data_len)) {
    532                 async_answer_0(iid, EINVAL);
    533                 return;
    534         }
    535 
    536         void *buffer = malloc(data_len);
    537         if (buffer == NULL) {
    538                 async_answer_0(data_callid, ENOMEM);
    539                 async_answer_0(iid, ENOMEM);
    540                 return;
    541         }
    542 
    543         size_t sent_length = str_size(fun->pathname);
    544         if (sent_length > data_len) {
    545                 sent_length = data_len;
    546         }
    547 
    548         async_data_read_finalize(data_callid, fun->pathname, sent_length);
    549         async_answer_0(iid, EOK);
    550 
    551         free(buffer);
    552 }
    553 
    554517
    555518/** Function for handling connections from a client to the device manager. */
     
    573536                case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
    574537                        devman_function_get_handle_by_class(callid, &call);
    575                         break;
    576                 case DEVMAN_DEVICE_GET_DEVICE_PATH:
    577                         devman_get_device_path_by_handle(callid, &call);
    578538                        break;
    579539                default:
Note: See TracChangeset for help on using the changeset viewer.