Changeset 252cf2a in mainline


Ignore:
Timestamp:
2011-05-08T15:53:44Z (13 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f55ded3
Parents:
cc5908e
Message:

Development changes merge
Correct parsing of usages in case of array items

Location:
uspace
Files:
22 edited

Legend:

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

    rcc5908e r252cf2a  
    4040#include "usbinfo.h"
    4141
    42 usbinfo_device_t *prepare_device(devman_handle_t hc_handle,
    43     usb_address_t dev_addr)
     42usbinfo_device_t *prepare_device(const char *name,
     43    devman_handle_t hc_handle, 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 the device: %s.\n",
    58                     str_error(rc));
     57                    NAME ": failed to create connection to device %s: %s.\n",
     58                    name, str_error(rc));
    5959                goto leave;
    6060        }
     
    6464        if (rc != EOK) {
    6565                fprintf(stderr,
    66                     NAME ": failed to create default control pipe: %s.\n",
    67                     str_error(rc));
     66                    NAME ": failed to create default control pipe to %s: %s.\n",
     67                    name, str_error(rc));
    6868                goto leave;
    6969        }
     
    7171        rc = usb_pipe_probe_default_control(&dev->ctrl_pipe);
    7272        if (rc != EOK) {
    73                 fprintf(stderr,
    74                     NAME ": probing default control pipe failed: %s.\n",
    75                     str_error(rc));
     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                }
    7682                goto leave;
    7783        }
     
    8490        if (rc != EOK) {
    8591                fprintf(stderr,
    86                     NAME ": failed to retrieve device descriptor: %s.\n",
    87                     str_error(rc));
     92                    NAME ": failed to retrieve device descriptor of %s: %s.\n",
     93                    name, str_error(rc));
    8894                goto leave;
    8995        }
     
    9399            &dev->full_configuration_descriptor_size);
    94100        if (rc != EOK) {
    95                 fprintf(stderr,
    96                     NAME ": failed to retrieve configuration descriptor: %s.\n",
    97                     str_error(rc));
     101                fprintf(stderr, NAME ": " \
     102                    "failed to retrieve configuration descriptor of %s: %s.\n",
     103                    name, str_error(rc));
    98104                goto leave;
    99105        }
  • uspace/app/usbinfo/main.c

    rcc5908e r252cf2a  
    308308                }
    309309
    310                 usbinfo_device_t *dev = prepare_device(hc_handle, dev_addr);
     310                usbinfo_device_t *dev = prepare_device(devpath,
     311                    hc_handle, dev_addr);
    311312                if (dev == NULL) {
    312313                        continue;
  • uspace/app/usbinfo/usbinfo.h

    rcc5908e r252cf2a  
    7171}
    7272
    73 usbinfo_device_t *prepare_device(devman_handle_t, usb_address_t);
     73usbinfo_device_t *prepare_device(const char *, devman_handle_t, usb_address_t);
    7474void destroy_device(usbinfo_device_t *);
    7575
  • uspace/drv/ohci/hc.c

    rcc5908e r252cf2a  
    9595}
    9696/*----------------------------------------------------------------------------*/
    97 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
    98     uintptr_t regs, size_t reg_size, bool interrupts)
     97int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts)
    9998{
    10099        assert(instance);
  • uspace/drv/ohci/hc.h

    rcc5908e r252cf2a  
    7777int hc_register_hub(hc_t *instance, ddf_fun_t *hub_fun);
    7878
    79 int hc_init(hc_t *instance, ddf_fun_t *fun, ddf_dev_t *dev,
    80      uintptr_t regs, size_t reg_size, bool interrupts);
     79int hc_init(hc_t *instance, uintptr_t regs, size_t reg_size, bool interrupts);
    8180
    8281void hc_start_hw(hc_t *instance);
  • uspace/drv/ohci/main.c

    rcc5908e r252cf2a  
    4343#define NAME "ohci"
    4444
    45 static int ohci_add_device(ddf_dev_t *device);
     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 */
     50static 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}
    4665/*----------------------------------------------------------------------------*/
    4766static driver_ops_t ohci_driver_ops = {
     
    5372        .driver_ops = &ohci_driver_ops
    5473};
    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  */
    61 int 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         hc_register_hub(&ohci->hc, ohci->rh_fun);
    79 
    80         usb_log_info("Controlling new OHCI device `%s'.\n", device->name);
    81 
    82         return EOK;
    83 }
    8474/*----------------------------------------------------------------------------*/
    8575/** Initializes global driver structures (NONE).
  • uspace/drv/ohci/ohci.c

    rcc5908e r252cf2a  
    4444#include "iface.h"
    4545#include "pci.h"
     46#include "hc.h"
     47#include "root_hub.h"
     48
     49typedef 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
     57static 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}
    4663
    4764/** IRQ handling callback, identifies device
     
    5370static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
    5471{
    55         assert(dev);
    56         assert(dev->driver_data);
    57         hc_t *hc = &((ohci_t*)dev->driver_data)->hc;
    58         uint16_t status = IPC_GET_ARG1(*call);
     72        hc_t *hc = &dev_to_ohci(dev)->hc;
    5973        assert(hc);
     74        const uint16_t status = IPC_GET_ARG1(*call);
    6075        hc_interrupt(hc, status);
    6176}
     
    7186{
    7287        assert(fun);
    73         usb_device_keeper_t *manager = &((ohci_t*)fun->dev->driver_data)->hc.manager;
     88        usb_device_keeper_t *manager = &dev_to_ohci(fun->dev)->hc.manager;
    7489
    7590        usb_address_t addr = usb_device_keeper_find(manager, handle);
     
    94109    ddf_fun_t *fun, devman_handle_t *handle)
    95110{
    96         assert(handle);
    97         ddf_fun_t *hc_fun = ((ohci_t*)fun->dev->driver_data)->hc_fun;
    98         assert(hc_fun != NULL);
    99 
    100         *handle = hc_fun->handle;
     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;
    101117        return EOK;
    102118}
    103119/*----------------------------------------------------------------------------*/
    104 /** This iface is generic for both RH and HC. */
     120/** Root hub USB interface */
    105121static usb_iface_t usb_iface = {
    106122        .get_hc_handle = usb_iface_get_hc_handle,
     
    108124};
    109125/*----------------------------------------------------------------------------*/
     126/** Standard USB HC options (HC interface) */
    110127static ddf_dev_ops_t hc_ops = {
    111128        .interfaces[USBHC_DEV_IFACE] = &hc_iface, /* see iface.h/c */
    112129};
    113130/*----------------------------------------------------------------------------*/
     131/** Standard USB RH options (RH interface) */
    114132static ddf_dev_ops_t rh_ops = {
    115133        .interfaces[USB_DEV_IFACE] = &usb_iface,
     
    118136/** Initialize hc and rh ddf structures and their respective drivers.
    119137 *
     138 * @param[in] device DDF instance of the device to use.
    120139 * @param[in] instance OHCI structure to use.
    121  * @param[in] device DDF instance of the device to use.
    122140 *
    123141 * This function does all the preparatory work for hc and rh drivers:
     
    127145 *  - registers interrupt handler
    128146 */
    129 int ohci_init(ohci_t *instance, ddf_dev_t *device)
    130 {
    131         assert(instance);
    132         instance->hc_fun = NULL;
     147int 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...) \
     156if (ret != EOK) { \
     157        if (instance->hc_fun) { \
     158                instance->hc_fun->ops = NULL; \
     159                instance->hc_fun->driver_data = NULL; \
     160                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; \
     165                ddf_fun_destroy(instance->rh_fun); \
     166        } \
     167        free(instance); \
     168        usb_log_error(message); \
     169        return ret; \
     170} else (void)0
     171
    133172        instance->rh_fun = NULL;
    134 #define CHECK_RET_DEST_FUN_RETURN(ret, message...) \
    135 if (ret != EOK) { \
    136         usb_log_error(message); \
    137         if (instance->hc_fun) \
    138                 ddf_fun_destroy(instance->hc_fun); \
    139         if (instance->rh_fun) \
    140                 ddf_fun_destroy(instance->rh_fun); \
    141         return ret; \
    142 }
    143 
    144         uintptr_t mem_reg_base = 0;
    145         size_t mem_reg_size = 0;
     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;
    146186        int irq = 0;
    147187
    148         int ret =
    149             pci_get_my_registers(device, &mem_reg_base, &mem_reg_size, &irq);
    150         CHECK_RET_DEST_FUN_RETURN(ret,
     188        ret = pci_get_my_registers(device, &reg_base, &reg_size, &irq);
     189        CHECK_RET_DEST_FREE_RETURN(ret,
    151190            "Failed to get memory addresses for %" PRIun ": %s.\n",
    152191            device->handle, str_error(ret));
    153192        usb_log_debug("Memory mapped regs at %p (size %zu), IRQ %d.\n",
    154             (void *) mem_reg_base, mem_reg_size, irq);
     193            (void *) reg_base, reg_size, irq);
    155194
    156195        bool interrupts = false;
    157196#ifdef CONFIG_USBHC_NO_INTERRUPTS
    158         usb_log_warning("Interrupts disabled in OS config, " \
     197        usb_log_warning("Interrupts disabled in OS config, "
    159198            "falling back to polling.\n");
    160199#else
     
    163202                usb_log_warning("Failed to enable interrupts: %s.\n",
    164203                    str_error(ret));
    165                 usb_log_info("HW interrupts not available, " \
     204                usb_log_info("HW interrupts not available, "
    166205                    "falling back to polling.\n");
    167206        } else {
     
    171210#endif
    172211
    173         instance->hc_fun = ddf_fun_create(device, fun_exposed, "ohci-hc");
    174         ret = (instance->hc_fun == NULL) ? ENOMEM : EOK;
    175         CHECK_RET_DEST_FUN_RETURN(ret,
    176             "Failed(%d) to create HC function.\n", ret);
    177 
    178         ret = hc_init(&instance->hc, instance->hc_fun, device,
    179             mem_reg_base, mem_reg_size, interrupts);
    180         CHECK_RET_DEST_FUN_RETURN(ret, "Failed(%d) to init ohci-hcd.\n", ret);
    181         instance->hc_fun->ops = &hc_ops;
    182         instance->hc_fun->driver_data = &instance->hc;
    183         ret = ddf_fun_bind(instance->hc_fun);
    184         CHECK_RET_DEST_FUN_RETURN(ret,
    185             "Failed(%d) to bind OHCI device function: %s.\n",
    186             ret, str_error(ret));
    187         ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME);
    188         CHECK_RET_DEST_FUN_RETURN(ret,
    189             "Failed to add OHCI to HC class: %s.\n", str_error(ret));
    190 
    191 #undef CHECK_RET_HC_RETURN
     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);
    192214
    193215#define CHECK_RET_FINI_RETURN(ret, message...) \
    194216if (ret != EOK) { \
    195         usb_log_error(message); \
    196         if (instance->hc_fun) \
    197                 ddf_fun_destroy(instance->hc_fun); \
    198         if (instance->rh_fun) \
    199                 ddf_fun_destroy(instance->rh_fun); \
    200217        hc_fini(&instance->hc); \
    201         return ret; \
    202 }
     218        CHECK_RET_DEST_FREE_RETURN(ret, message); \
     219} else (void)0
    203220
    204221        /* It does no harm if we register this on polling */
     
    208225            "Failed(%d) to register interrupt handler.\n", ret);
    209226
    210         instance->rh_fun = ddf_fun_create(device, fun_inner, "ohci-rh");
    211         ret = (instance->rh_fun == NULL) ? ENOMEM : EOK;
     227        ret = ddf_fun_bind(instance->hc_fun);
    212228        CHECK_RET_FINI_RETURN(ret,
    213             "Failed(%d) to create root hub function.\n", ret);
    214 
    215 
    216         instance->rh_fun->ops = &rh_ops;
    217         instance->rh_fun->driver_data = NULL;
    218        
     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);
     233        CHECK_RET_FINI_RETURN(ret,
     234            "Failed to add OHCI to HC class: %s.\n", str_error(ret));
     235
    219236        device->driver_data = instance;
    220237
    221238        hc_start_hw(&instance->hc);
     239        hc_register_hub(&instance->hc, instance->rh_fun);
    222240        return EOK;
     241
     242#undef CHECK_RET_DEST_FUN_RETURN
    223243#undef CHECK_RET_FINI_RETURN
    224244}
  • uspace/drv/ohci/ohci.h

    rcc5908e r252cf2a  
    3838#include <ddf/driver.h>
    3939
    40 #include "hc.h"
    41 #include "root_hub.h"
    42 
    43 typedef 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 
    51 int ohci_init(ohci_t *instance, ddf_dev_t *device);
     40int device_setup_ohci(ddf_dev_t *device);
    5241
    5342#endif
  • uspace/drv/ohci/pci.c

    rcc5908e r252cf2a  
    5858    uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no)
    5959{
    60         assert(dev != NULL);
     60        assert(dev);
     61        assert(mem_reg_address);
     62        assert(mem_reg_size);
     63        assert(irq_no);
    6164
    6265        int parent_phone = devman_parent_device_connect(dev->handle,
  • uspace/drv/uhci-hcd/hc.c

    rcc5908e r252cf2a  
    6060 *
    6161 * @param[in] instance Memory place to initialize.
    62  * @param[in] fun DDF function.
    6362 * @param[in] regs Address of I/O control registers.
    6463 * @param[in] size Size of I/O control registers.
     
    6968 * interrupt fibrils.
    7069 */
    71 int hc_init(hc_t *instance, ddf_fun_t *fun,
    72     void *regs, size_t reg_size, bool interrupts)
     70int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interrupts)
    7371{
    7472        assert(reg_size >= sizeof(regs_t));
  • uspace/drv/uhci-hcd/hc.h

    rcc5908e r252cf2a  
    136136} hc_t;
    137137
    138 int hc_init(hc_t *instance, ddf_fun_t *fun,
    139     void *regs, size_t reg_size, bool interupts);
     138int hc_init(hc_t *instance, void *regs, size_t reg_size, bool interupts);
    140139
    141140int hc_schedule(hc_t *instance, usb_transfer_batch_t *batch);
  • uspace/drv/uhci-hcd/main.c

    rcc5908e r252cf2a  
    6464        assert(device);
    6565
    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);
     66        int ret = device_setup_uhci(device);
    7367        if (ret != EOK) {
    7468                usb_log_error("Failed to initialize UHCI driver: %s.\n",
     
    7670                return ret;
    7771        }
    78         device->driver_data = uhci;
    79 
    8072        usb_log_info("Controlling new UHCI device '%s'.\n", device->name);
    8173
  • uspace/drv/uhci-hcd/uhci.c

    rcc5908e r252cf2a  
    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 */
     51typedef 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
     63static 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/*----------------------------------------------------------------------------*/
    4670/** IRQ handling callback, forward status from call to diver structure.
    4771 *
     
    6993{
    7094        assert(fun);
    71         usb_device_keeper_t *manager =
    72             &((uhci_t*)fun->dev->driver_data)->hc.manager;
    73 
     95        usb_device_keeper_t *manager = &dev_to_uhci(fun->dev)->hc.manager;
    7496        usb_address_t addr = usb_device_keeper_find(manager, handle);
     97
    7598        if (addr < 0) {
    7699                return addr;
     
    93116    ddf_fun_t *fun, devman_handle_t *handle)
    94117{
    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;
     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;
    100124        return EOK;
    101125}
     
    126150static hw_res_ops_t hw_res_iface = {
    127151        .get_resource_list = get_resource_list,
    128         .enable_interrupt = NULL
     152        .enable_interrupt = NULL,
    129153};
    130154/*----------------------------------------------------------------------------*/
     
    146170 *  - registers interrupt handler
    147171 */
    148 int uhci_init(uhci_t *instance, ddf_dev_t *device)
    149 {
    150         assert(instance);
    151         instance->hc_fun = NULL;
     172int 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...) \
     182if (ret != EOK) { \
     183        if (instance->hc_fun) \
     184                instance->hc_fun->ops = NULL; \
     185                instance->hc_fun->driver_data = NULL; \
     186                ddf_fun_destroy(instance->hc_fun); \
     187        if (instance->rh_fun) {\
     188                instance->rh_fun->ops = NULL; \
     189                instance->rh_fun->driver_data = NULL; \
     190                ddf_fun_destroy(instance->rh_fun); \
     191        } \
     192        free(instance); \
     193        usb_log_error(message); \
     194        return ret; \
     195} else (void)0
     196
    152197        instance->rh_fun = NULL;
    153 #define CHECK_RET_DEST_FUN_RETURN(ret, message...) \
    154 if (ret != EOK) { \
    155         usb_log_error(message); \
    156         if (instance->hc_fun) \
    157                 ddf_fun_destroy(instance->hc_fun); \
    158         if (instance->rh_fun) \
    159                 ddf_fun_destroy(instance->rh_fun); \
    160         return ret; \
    161 }
    162 
    163         uintptr_t io_reg_base = 0;
    164         size_t io_reg_size = 0;
     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;
    165212        int irq = 0;
    166213
    167         int ret =
    168             pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
    169         CHECK_RET_DEST_FUN_RETURN(ret,
     214        ret = pci_get_my_registers(device, &reg_base, &reg_size, &irq);
     215        CHECK_RET_DEST_FREE_RETURN(ret,
    170216            "Failed to get I/O addresses for %" PRIun ": %s.\n",
    171217            device->handle, str_error(ret));
    172218        usb_log_debug("I/O regs at 0x%p (size %zu), IRQ %d.\n",
    173             (void *) io_reg_base, io_reg_size, irq);
     219            (void *) reg_base, reg_size, irq);
    174220
    175221        ret = pci_disable_legacy(device);
    176         CHECK_RET_DEST_FUN_RETURN(ret,
     222        CHECK_RET_DEST_FREE_RETURN(ret,
    177223            "Failed(%d) to disable legacy USB: %s.\n", ret, str_error(ret));
    178224
     
    194240#endif
    195241
    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,
     242
     243        ret = hc_init(&instance->hc, (void*)reg_base, reg_size, interrupts);
     244        CHECK_RET_DEST_FREE_RETURN(ret,
    204245            "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         ret = ddf_fun_add_to_class(instance->hc_fun, USB_HC_DDF_CLASS_NAME);
    213         CHECK_RET_DEST_FUN_RETURN(ret,
    214             "Failed to add UHCI to HC class: %s.\n", str_error(ret));
    215 
    216 #undef CHECK_RET_HC_RETURN
    217246
    218247#define CHECK_RET_FINI_RETURN(ret, message...) \
    219248if (ret != EOK) { \
    220         usb_log_error(message); \
    221         if (instance->hc_fun) \
    222                 ddf_fun_destroy(instance->hc_fun); \
    223         if (instance->rh_fun) \
    224                 ddf_fun_destroy(instance->rh_fun); \
    225249        hc_fini(&instance->hc); \
     250        CHECK_RET_DEST_FREE_RETURN(ret, message); \
    226251        return ret; \
    227 }
     252} else (void)0
    228253
    229254        /* It does no harm if we register this on polling */
     
    234259            ret, str_error(ret));
    235260
    236         instance->rh_fun = ddf_fun_create(device, fun_inner, "uhci-rh");
    237         ret = (instance->rh_fun == NULL) ? ENOMEM : EOK;
    238         CHECK_RET_FINI_RETURN(ret,
    239             "Failed(%d) to create root hub function: %s.\n",
     261        ret = ddf_fun_bind(instance->hc_fun);
     262        CHECK_RET_FINI_RETURN(ret,
     263            "Failed(%d) to bind UHCI device function: %s.\n",
    240264            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));
    241269
    242270        ret = rh_init(&instance->rh, instance->rh_fun,
     
    245273            "Failed(%d) to setup UHCI root hub: %s.\n", ret, str_error(ret));
    246274
    247         instance->rh_fun->ops = &rh_ops;
    248         instance->rh_fun->driver_data = &instance->rh;
    249275        ret = ddf_fun_bind(instance->rh_fun);
    250276        CHECK_RET_FINI_RETURN(ret,
    251277            "Failed(%d) to register UHCI root hub: %s.\n", ret, str_error(ret));
    252278
     279        device->driver_data = instance;
    253280        return EOK;
    254281#undef CHECK_RET_FINI_RETURN
  • uspace/drv/uhci-hcd/uhci.h

    rcc5908e r252cf2a  
    3838#include <ddf/driver.h>
    3939
    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 */
    45 typedef 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 
    57 int uhci_init(uhci_t *instance, ddf_dev_t *device);
     40int device_setup_uhci(ddf_dev_t *device);
    5841#endif
    5942/**
  • uspace/drv/usbhid/kbd/kbddev.c

    rcc5908e r252cf2a  
    677677//          callbacks, kbd_dev);
    678678        usb_hid_report_path_t *path = usb_hid_report_path();
    679         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
     679        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 6);
    680680        //usb_hid_report_path_set_report_id(path, 0);
    681681
     
    695695        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    696696            hid_dev->report, NULL, path,
    697             USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     697            USB_HID_PATH_COMPARE_BEGIN,
    698698            USB_HID_REPORT_TYPE_INPUT);
    699699        unsigned i = 0;
    700        
     700
    701701        while (field != NULL) {
    702702                //usb_log_debug2("FIELD (%p) - VALUE(%d) USAGE(%u)\n",
     
    716716                 *       two parts of the Report somehow.
    717717                 */
     718                usb_log_debug("value(%x), usage(%x)\n", field->value, field->usage);
    718719                if (field->value != 0) {
    719                         kbd_dev->keys[i] = field->usage;
     720                        //kbd_dev->keys[i] = field->usage;
    720721                }
    721722                else {
    722                         kbd_dev->keys[i] = 0;
     723                        //kbd_dev->keys[i] = 0;
    723724                }
    724                 usb_log_debug2("Saved %u. key usage %d\n", i, kbd_dev->keys[i]);
     725                //usb_log_debug2("Saved %u. key usage %d\n", i, kbd_dev->keys[i]);
    725726               
    726727                ++i;
    727728                field = usb_hid_report_get_sibling(hid_dev->report, field, path,
    728                     USB_HID_PATH_COMPARE_END
    729                     | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     729                    USB_HID_PATH_COMPARE_BEGIN,
    730730                    USB_HID_REPORT_TYPE_INPUT);
     731                usb_log_debug("field -- %p\n", field);
    731732        }
    732733       
     
    860861         * TODO: make more general
    861862         */
    862         usb_hid_report_path_t *path = usb_hid_report_path();
    863         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    864        
    865         usb_hid_report_path_set_report_id(path, 0);
    866        
    867863        kbd_dev->key_count = usb_hid_report_size(
    868864            hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
    869         usb_hid_report_path_free(path);
    870        
    871         usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    872        
     865       
     866        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);   
    873867        kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t));
    874868       
     
    986980                return rc;
    987981        }
    988        
     982
    989983        return EOK;
    990984}
  • uspace/drv/usbhid/lgtch-ultrax/lgtch-ultrax.c

    rcc5908e r252cf2a  
    180180 * @param key Key code of the key according to HID Usage Tables.
    181181 */
     182/*
    182183static void usb_lgtch_push_ev(usb_hid_dev_t *hid_dev, int type,
    183184    unsigned int key)
     
    206207            ev.mods, ev.c);
    207208}
    208 
     209*/
    209210/*----------------------------------------------------------------------------*/
    210211
     
    396397
    397398        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    398             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
     399            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_BEGIN
    399400            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    400401            USB_HID_REPORT_TYPE_INPUT);
    401402       
    402         unsigned int key;
     403//      unsigned int key;
    403404       
    404405        /*! @todo Is this iterating OK if done multiple times?
     
    409410                    field->usage);
    410411               
    411                 key = usb_lgtch_map_usage(field->usage);
    412                 usb_lgtch_push_ev(hid_dev, KEY_PRESS, key);
     412//              key = usb_lgtch_map_usage(field->usage);
     413//              usb_lgtch_push_ev(hid_dev, KEY_PRESS, key);
    413414               
    414415                field = usb_hid_report_get_sibling(
    415                     hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
     416                    hid_dev->report, field, path, USB_HID_PATH_COMPARE_BEGIN
    416417                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    417418                    USB_HID_REPORT_TYPE_INPUT);
  • uspace/drv/usbhid/subdrivers.c

    rcc5908e r252cf2a  
    4242
    4343static usb_hid_subdriver_usage_t path_kbd[] = {
    44         {USB_HIDUT_PAGE_KEYBOARD, 0},
     44        {USB_HIDUT_PAGE_GENERIC_DESKTOP, 6},
    4545        {0, 0}
    4646};
    4747
    4848static usb_hid_subdriver_usage_t path_mouse2[] = {
    49         {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_X},
     49        {USB_HIDUT_PAGE_GENERIC_DESKTOP, 2},
    5050        {0, 0}
    5151};
     
    6060                path_kbd,
    6161                -1,
    62                 USB_HID_PATH_COMPARE_END
    63                 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     62                USB_HID_PATH_COMPARE_BEGIN ,
    6463                -1,
    6564                -1,
     
    7574                lgtch_path,
    7675                1,
    77                 USB_HID_PATH_COMPARE_END
    78                 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     76                USB_HID_PATH_COMPARE_BEGIN,
    7977                0x046d,
    8078                0xc30e,
     
    8987                path_mouse2,
    9088                -1,
    91                 USB_HID_PATH_COMPARE_END
    92                 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     89                USB_HID_PATH_COMPARE_BEGIN,
    9390                -1,
    9491                -1,
  • uspace/drv/usbhid/usbhid.c

    rcc5908e r252cf2a  
    199199                    mapping->report_id);
    200200        }
    201        
     201
     202        uint8_t report_id = (mapping->report_id >= 0) ? mapping->report_id : 0;
    202203        assert(hid_dev->report != NULL);
    203204       
    204205        usb_log_debug("Compare flags: %d\n", mapping->compare);
    205         size_t size = usb_hid_report_size(hid_dev->report, mapping->report_id,
     206        size_t size = usb_hid_report_size(hid_dev->report, report_id,
    206207            USB_HID_REPORT_TYPE_INPUT);
    207208        usb_log_debug("Size of the input report: %zuB\n", size);
    208        
     209
    209210        usb_hid_report_path_free(usage_path);
    210211       
  • uspace/lib/drv/generic/remote_usbhc.c

    rcc5908e r252cf2a  
    302302        async_transaction_t *trans = async_transaction_create(callid);
    303303        if (trans == NULL) {
     304                async_answer_0(data_callid, ENOMEM);
    304305                async_answer_0(callid, ENOMEM);
    305306                return;
     
    314315
    315316        if (rc != EOK) {
     317                async_answer_0(data_callid, rc);
    316318                async_answer_0(callid, rc);
    317319                async_transaction_destroy(trans);
     
    460462        async_transaction_t *trans = async_transaction_create(callid);
    461463        if (trans == NULL) {
     464                async_answer_0(data_callid, ENOMEM);
    462465                async_answer_0(callid, ENOMEM);
    463466                free(setup_packet);
     
    469472        trans->buffer = malloc(data_len);
    470473        if (trans->buffer == NULL) {
     474                async_answer_0(data_callid, ENOMEM);
    471475                async_answer_0(callid, ENOMEM);
    472476                async_transaction_destroy(trans);
     
    480484
    481485        if (rc != EOK) {
     486                async_answer_0(data_callid, rc);
    482487                async_answer_0(callid, rc);
    483488                async_transaction_destroy(trans);
  • uspace/lib/usb/src/hiddescriptor.c

    rcc5908e r252cf2a  
    6464{
    6565        /* find or append current collection path to the list */
    66         link_t *path_it = report->collection_paths.next;
     66        //link_t *path_it = report->collection_paths.next;
     67        link_t *path_it = report->collection_paths.prev->next;
    6768        usb_hid_report_path_t *path = NULL;
     69       
     70       
    6871        while(path_it != &report->collection_paths) {
    6972                path = list_get_instance(path_it, usb_hid_report_path_t, link);
     
    115118        usb_hid_report_field_t *field;
    116119        int i;
    117 
    118         usb_log_debug("usages_count  - %zu\n", report_item->usages_count);
    119120
    120121        uint32_t *usages;
     
    147148                        */
    148149                        field->usage = 0;
    149                         field->usage_page = report_item->usage_page;
     150                        field->usage_page = 0; //report_item->usage_page;
    150151
    151152                        field->usages_count = report_item->usages_count;
     
    168169                        }
    169170                        else {
     171                                // should not occur
    170172                                field->usage = usage;
    171173                                field->usage_page = report_item->usage_page;
     
    465467                       
    466468                        // set last item
    467                         usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, report_item->usage_page);
    468                         usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, report_item->usages[report_item->usages_count-1]);
     469                        usb_hid_report_set_last_item(usage_path,
     470                                                     USB_HID_TAG_CLASS_GLOBAL,
     471                                                     USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[report_item->usages_count-1]));
     472                        usb_hid_report_set_last_item(usage_path,
     473                                                     USB_HID_TAG_CLASS_LOCAL,
     474                                                     USB_HID_EXTENDED_USAGE(report_item->usages[report_item->usages_count-1]));
    469475                       
    470476                        // append the new one which will be set by common
     
    561567                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
    562568{
     569        int32_t extended_usage;
     570       
    563571        switch(tag) {
    564572                case USB_HID_REPORT_TAG_USAGE:
     
    570578                                        report_item->in_delimiter = INSIDE_DELIMITER_SET;
    571579                                case OUTSIDE_DELIMITER_SET:
    572                                         report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size);
     580                                        extended_usage = ((report_item->usage_page) << 16);
     581                                        extended_usage += usb_hid_report_tag_data_uint32(data,item_size);
     582                                        report_item->usages[report_item->usages_count] = extended_usage;
    573583                                        report_item->usages_count++;
    574584                                        break;
     
    607617                                }
    608618                                else {
    609                                         report_item->usages[report_item->usages_count++] = i;
     619                                       
     620                                        report_item->usages[report_item->usages_count++] = (report_item->usage_page << 16) + i;
    610621                                }
    611622                        }
     
    691702                usb_log_debug("\t\ttUSAGEMIN: %X\n", report_item->usage_minimum);
    692703                usb_log_debug("\t\tUSAGEMAX: %X\n", report_item->usage_maximum);
     704                usb_log_debug("\t\tUSAGES COUNT: %zu\n", report_item->usages_count);
    693705
    694706                usb_log_debug("\t\tVALUE: %X\n", report_item->value);
     
    696708                usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
    697709               
    698                 //usb_hid_print_usage_path(report_item->collection_path);
     710                usb_hid_print_usage_path(report_item->collection_path);
    699711
    700712                usb_log_debug("\n");           
     
    728740                usb_hid_descriptor_print_list(&report_des->report_items);
    729741
    730 
     742/*
    731743                link_t *path_it = report->collection_paths.next;
    732744                while(path_it != &report->collection_paths) {
     
    734746                        path_it = path_it->next;
    735747                }
    736                
     748*/             
    737749                report_it = report_it->next;
    738750        }
  • uspace/lib/usb/src/hidparser.c

    rcc5908e r252cf2a  
    111111        usb_hid_report_description_t *report_des;
    112112        usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
    113 
     113       
    114114        if(report == NULL) {
    115115                return EINVAL;
     
    140140               
    141141                                item->usage = USB_HID_EXTENDED_USAGE(item->usages[item->value - item->physical_minimum]);
    142                                 item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(item->usages[item->value - item->physical_minimum]);
    143 
     142                                item->usage_page = USB_HID_EXTENDED_USAGE_PAGE(item->usages[item->value - item->physical_minimum]);                             
     143
     144                                usb_hid_report_set_last_item (item->collection_path,
     145                                                              USB_HID_TAG_CLASS_GLOBAL,
     146                                                              item->usage_page);
     147                                usb_hid_report_set_last_item (item->collection_path,
     148                                                              USB_HID_TAG_CLASS_LOCAL,
     149                                                              item->usage);
     150                               
    144151                        }
    145152                        else {
     
    150157                list_item = list_item->next;
    151158        }
    152            
     159       
    153160        return EOK;
    154161       
  • uspace/lib/usb/src/hidpath.c

    rcc5908e r252cf2a  
    4242
    4343
     44#define USB_HID_SAME_USAGE(usage1, usage2)      ((usage1 == usage2) || (usage1 == 0) || (usage2 == 0))
     45#define USB_HID_SAME_USAGE_PAGE(page1, page2)   ((page1 == page2) || (page1 == 0) || (page2 == 0))
     46
    4447/**
    4548 * Appends one item (couple of usage_path and usage) into the usage path
     
    203206                        while(report_link != &report_path->head) {
    204207                                report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
    205                                 if(report_item->usage_page == path_item->usage_page){
     208                                if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page)){
    206209                                        if(only_page == 0){
    207                                                 if(report_item->usage == path_item->usage) {
     210                                                if(USB_HID_SAME_USAGE(report_item->usage, path_item->usage)) {
    208211                                                        return EOK;
    209212                                                }
     
    242245                                                                      link);           
    243246
    244                                         if((report_item->usage_page != path_item->usage_page) ||
     247                                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) ||
    245248                                           ((only_page == 0) &&
    246                                             (report_item->usage != path_item->usage))) {
     249                                            !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) {
    247250                                                       
    248251                                                   return 1;
     
    282285                                                                      usb_hid_report_usage_path_t,
    283286                                                                      link);           
    284 
    285                                         if((report_item->usage_page != path_item->usage_page) ||
     287                                                 
     288                                        if(!USB_HID_SAME_USAGE_PAGE(report_item->usage_page, path_item->usage_page) ||
    286289                                           ((only_page == 0) &&
    287                                             (report_item->usage != path_item->usage))) {
    288                                                    return 1;
     290                                            !USB_HID_SAME_USAGE(report_item->usage, path_item->usage))) {
     291                                                        return 1;
    289292                                        } else {
    290293                                                report_link = report_link->prev;
Note: See TracChangeset for help on using the changeset viewer.