Changes in / [22ceff3a:25696fea] in mainline


Ignore:
Location:
uspace
Files:
36 edited

Legend:

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

    r22ceff3a r25696fea  
    6969        int rc = usb_hid_report_init(*report);
    7070        if (rc != EOK) {
    71                 usb_hid_report_deinit(*report);
     71                usb_hid_free_report(*report);
    7272                *report = NULL;
    7373                return rc;
     
    7979            &report_desc_size);
    8080        if (rc != EOK) {
    81                 usb_hid_report_deinit(*report);
     81                usb_hid_free_report(*report);
    8282                *report = NULL;
    8383                return rc;
     
    8585       
    8686        if (report_desc_size == 0) {
    87                 usb_hid_report_deinit(*report);
     87                usb_hid_free_report(*report);
    8888                *report = NULL;
    8989                // TODO: other error code?
     
    9393        uint8_t *desc = (uint8_t *) malloc(report_desc_size);
    9494        if (desc == NULL) {
    95                 usb_hid_report_deinit(*report);
     95                usb_hid_free_report(*report);
    9696                *report = NULL;
    9797                return ENOMEM;
     
    103103            &actual_size);
    104104        if (rc != EOK) {
    105                 usb_hid_report_deinit(*report);
     105                usb_hid_free_report(*report);
    106106                *report = NULL;
    107107                free(desc);
     
    110110       
    111111        if (actual_size != report_desc_size) {
    112                 usb_hid_report_deinit(*report);
     112                usb_hid_free_report(*report);
    113113                *report = NULL;
    114114                free(desc);
  • uspace/app/usbinfo/hid.c

    r22ceff3a r25696fea  
    167167
    168168        free(raw_report);
    169         usb_hid_report_deinit(&report);
     169        usb_hid_free_report(&report);
    170170}
    171171
  • uspace/drv/bus/usb/ohci/endpoint_list.c

    r22ceff3a r25696fea  
    6060            name, instance->list_head, instance->list_head_pa);
    6161
    62         ed_init(instance->list_head, NULL, NULL);
     62        ed_init(instance->list_head, NULL);
    6363        list_initialize(&instance->endpoint_list);
    6464        fibril_mutex_initialize(&instance->guard);
  • uspace/drv/bus/usb/ohci/hc.c

    r22ceff3a r25696fea  
    565565
    566566        /*Init HCCA */
    567         instance->hcca = hcca_get();
     567        instance->hcca = malloc32(sizeof(hcca_t));
    568568        if (instance->hcca == NULL)
    569569                return ENOMEM;
  • uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c

    r22ceff3a r25696fea  
    3434#include "endpoint_descriptor.h"
    3535
    36 /** USB direction to OHCI values translation table. */
    37 static const uint32_t dir[] = {
    38         [USB_DIRECTION_IN] = ED_STATUS_D_IN,
    39         [USB_DIRECTION_OUT] = ED_STATUS_D_OUT,
    40         [USB_DIRECTION_BOTH] = ED_STATUS_D_TD,
    41 };
     36static unsigned direc[3] =
     37    { ED_STATUS_D_IN, ED_STATUS_D_OUT, ED_STATUS_D_TRANSFER };
    4238
    43 /**
    44  * Initialize ED.
    45  *
    46  * @param instance ED structure to initialize.
    47  * @param ep Driver endpoint to use.
    48  * @param td TD to put in the list.
    49  *
    50  * If @param ep is NULL, dummy ED is initalized with only skip flag set.
    51  */
    52 void ed_init(ed_t *instance, const endpoint_t *ep, const td_t *td)
     39void ed_init(ed_t *instance, endpoint_t *ep)
    5340{
    5441        assert(instance);
    5542        bzero(instance, sizeof(ed_t));
    56 
    5743        if (ep == NULL) {
    58                 /* Mark as dead, used for dummy EDs at the beginning of
    59                  * endpoint lists. */
    6044                instance->status = ED_STATUS_K_FLAG;
    6145                return;
    6246        }
    63         /* Non-dummy ED must have TD assigned */
    64         assert(td);
    65 
    66         /* Status: address, endpoint nr, direction mask and max packet size. */
     47        assert(ep);
    6748        instance->status = 0
    6849            | ((ep->address & ED_STATUS_FA_MASK) << ED_STATUS_FA_SHIFT)
    6950            | ((ep->endpoint & ED_STATUS_EN_MASK) << ED_STATUS_EN_SHIFT)
    70             | ((dir[ep->direction] & ED_STATUS_D_MASK) << ED_STATUS_D_SHIFT)
     51            | ((direc[ep->direction] & ED_STATUS_D_MASK) << ED_STATUS_D_SHIFT)
    7152            | ((ep->max_packet_size & ED_STATUS_MPS_MASK)
    7253                << ED_STATUS_MPS_SHIFT);
    7354
    74         /* Low speed flag */
     55
    7556        if (ep->speed == USB_SPEED_LOW)
    7657                instance->status |= ED_STATUS_S_FLAG;
    77 
    78         /* Isochronous format flag */
    7958        if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS)
    8059                instance->status |= ED_STATUS_F_FLAG;
    8160
    82         /* Set TD to the list */
    83         const uintptr_t pa = addr_to_phys(td);
    84         instance->td_head = pa & ED_TDHEAD_PTR_MASK;
    85         instance->td_tail = pa & ED_TDTAIL_PTR_MASK;
    86 
    87         /* Set toggle bit */
    8861        if (ep->toggle)
    8962                instance->td_head |= ED_TDHEAD_TOGGLE_CARRY;
    90 
    9163}
    9264/**
  • uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.h

    r22ceff3a r25696fea  
    4545#include "completion_codes.h"
    4646
    47 /**
    48  * OHCI Endpoint Descriptor representation.
    49  *
    50  * See OHCI spec. Chapter 4.2, page 16 (pdf page 30) for details */
    5147typedef struct ed {
    52         /**
    53          * Status field.
    54          *
    55          * See table 4-1, p. 17 OHCI spec (pdf page 31).
    56          */
    5748        volatile uint32_t status;
    5849#define ED_STATUS_FA_MASK (0x7f)   /* USB device address   */
     
    6051#define ED_STATUS_EN_MASK (0xf)    /* USB endpoint address */
    6152#define ED_STATUS_EN_SHIFT (7)
    62 #define ED_STATUS_D_MASK (0x3)     /* Direction */
     53#define ED_STATUS_D_MASK (0x3)     /* direction */
    6354#define ED_STATUS_D_SHIFT (11)
    6455#define ED_STATUS_D_OUT (0x1)
    6556#define ED_STATUS_D_IN (0x2)
    66 #define ED_STATUS_D_TD (0x3) /* Direction is specified by TD */
     57#define ED_STATUS_D_TRANSFER (0x3)
    6758
    68 #define ED_STATUS_S_FLAG (1 << 13) /* Speed flag: 1 = low */
    69 #define ED_STATUS_K_FLAG (1 << 14) /* Skip flag (no not execute this ED) */
    70 #define ED_STATUS_F_FLAG (1 << 15) /* Format: 1 = isochronous */
    71 #define ED_STATUS_MPS_MASK (0x3ff) /* Maximum packet size */
     59#define ED_STATUS_S_FLAG (1 << 13) /* speed flag: 1 = low */
     60#define ED_STATUS_K_FLAG (1 << 14) /* skip flag (no not execute this ED) */
     61#define ED_STATUS_F_FLAG (1 << 15) /* format: 1 = isochronous*/
     62#define ED_STATUS_MPS_MASK (0x3ff) /* max_packet_size*/
    7263#define ED_STATUS_MPS_SHIFT (16)
    7364
    74         /**
    75          * Pointer to the last TD.
    76          *
    77          * OHCI hw never changes this field and uses it only for a reference.
    78          */
    7965        volatile uint32_t td_tail;
    8066#define ED_TDTAIL_PTR_MASK (0xfffffff0)
    8167#define ED_TDTAIL_PTR_SHIFT (0)
    8268
    83         /**
    84          * Pointer to the first TD.
    85          *
    86          * Driver should not change this field if the ED is active.
    87          * This field is updated by OHCI hw and points to the next TD
    88          * to be executed.
    89          */
    9069        volatile uint32_t td_head;
    9170#define ED_TDHEAD_PTR_MASK (0xfffffff0)
     
    9675#define ED_TDHEAD_HALTED_FLAG (0x1)
    9776
    98         /**
    99          * Pointer to the next ED.
    100          *
    101          * Driver should not change this field on active EDs.
    102          */
    10377        volatile uint32_t next;
    10478#define ED_NEXT_PTR_MASK (0xfffffff0)
     
    10680} __attribute__((packed)) ed_t;
    10781
    108 void ed_init(ed_t *instance, const endpoint_t *ep, const td_t *td);
     82void ed_init(ed_t *instance, endpoint_t *ep);
    10983
    110 /**
    111  * Check for SKIP or HALTED flag being set.
    112  * @param instance ED
    113  * @return true if either SKIP or HALTED flag is set, false otherwise.
    114  */
    115 static inline bool ed_inactive(const ed_t *instance)
     84static inline void ed_set_td(ed_t *instance, td_t *td)
    11685{
    11786        assert(instance);
    118         return (instance->td_head & ED_TDHEAD_HALTED_FLAG)
    119             || (instance->status & ED_STATUS_K_FLAG);
    120 }
    121 
    122 /**
    123  * Check whether this ED contains TD to be executed.
    124  * @param instance ED
    125  * @return true if there are pending TDs, false otherwise.
    126  */
    127 static inline bool ed_transfer_pending(const ed_t *instance)
    128 {
    129         assert(instance);
    130         return (instance->td_head & ED_TDHEAD_PTR_MASK)
    131             != (instance->td_tail & ED_TDTAIL_PTR_MASK);
    132 }
    133 
    134 /**
    135  * Set the last element of TD list
    136  * @param instance ED
    137  * @param instance TD to set as the last item.
    138  */
    139 static inline void ed_set_tail_td(ed_t *instance, const td_t *td)
    140 {
    141         assert(instance);
    142         const uintptr_t pa = addr_to_phys(td);
     87        uintptr_t pa = addr_to_phys(td);
     88        instance->td_head =
     89            ((pa & ED_TDHEAD_PTR_MASK)
     90            | (instance->td_head & ~ED_TDHEAD_PTR_MASK));
    14391        instance->td_tail = pa & ED_TDTAIL_PTR_MASK;
    14492}
    14593
    146 /**
    147  * Set next ED in ED chain.
    148  * @param instance ED to modify
    149  * @param next ED to append
    150  */
    151 static inline void ed_append_ed(ed_t *instance, const ed_t *next)
     94static inline void ed_set_end_td(ed_t *instance, td_t *td)
     95{
     96        assert(instance);
     97        uintptr_t pa = addr_to_phys(td);
     98        instance->td_tail = pa & ED_TDTAIL_PTR_MASK;
     99}
     100
     101static inline void ed_append_ed(ed_t *instance, ed_t *next)
    152102{
    153103        assert(instance);
    154104        assert(next);
    155         const uint32_t pa = addr_to_phys(next);
     105        uint32_t pa = addr_to_phys(next);
    156106        assert((pa & ED_NEXT_PTR_MASK) << ED_NEXT_PTR_SHIFT == pa);
    157107        instance->next = pa;
    158108}
    159109
    160 /**
    161  * Get toggle bit value stored in this ED
    162  * @param instance ED
    163  * @return Toggle bit value
    164  */
    165 static inline int ed_toggle_get(const ed_t *instance)
     110static inline int ed_toggle_get(ed_t *instance)
    166111{
    167112        assert(instance);
     
    169114}
    170115
    171 /**
    172  * Set toggle bit value stored in this ED
    173  * @param instance ED
    174  * @param toggle Toggle bit value
    175  */
    176 static inline void ed_toggle_set(ed_t *instance, bool toggle)
     116static inline void ed_toggle_set(ed_t *instance, int toggle)
    177117{
    178118        assert(instance);
    179         if (toggle) {
     119        assert(toggle == 0 || toggle == 1);
     120        if (toggle == 1) {
    180121                instance->td_head |= ED_TDHEAD_TOGGLE_CARRY;
    181122        } else {
    182                 /* Clear halted flag when reseting toggle TODO: Why? */
     123                /* clear halted flag when reseting toggle */
    183124                instance->td_head &= ~ED_TDHEAD_TOGGLE_CARRY;
    184125                instance->td_head &= ~ED_TDHEAD_HALTED_FLAG;
  • uspace/drv/bus/usb/ohci/hw_struct/hcca.h

    r22ceff3a r25696fea  
    3636
    3737#include <stdint.h>
    38 #include <malloc.h>
    3938
    4039/** Host controller communication area.
     
    4948} __attribute__((packed, aligned)) hcca_t;
    5049
    51 static inline void * hcca_get(void)
    52 {
    53         assert(sizeof(hcca_t) == 256);
    54         return memalign(256, sizeof(hcca_t));
    55 }
    5650#endif
    5751/**
  • uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.c

    r22ceff3a r25696fea  
    3535#include "transfer_descriptor.h"
    3636
    37 /** USB direction to OHCI TD values translation table */
    38 static const uint32_t dir[] = {
    39         [USB_DIRECTION_IN] = TD_STATUS_DP_IN,
    40         [USB_DIRECTION_OUT] = TD_STATUS_DP_OUT,
    41         [USB_DIRECTION_BOTH] = TD_STATUS_DP_SETUP,
    42 };
     37static unsigned dp[3] =
     38    { TD_STATUS_DP_IN, TD_STATUS_DP_OUT, TD_STATUS_DP_SETUP };
     39static unsigned togg[2] = { TD_STATUS_T_0, TD_STATUS_T_1 };
    4340
    44 /**
    45  * Initialize OHCI TD.
    46  * @param instance TD structure to initialize.
    47  * @param next Next TD in ED list.
    48  * @param direction Used to determine PID, BOTH means setup PID.
    49  * @param buffer Pointer to the first byte of transferred data.
    50  * @param size Size of the buffer.
    51  * @param toggle Toggle bit value, use 0/1 to set explicitly,
    52  *        any other value means that ED toggle will be used.
    53  */
    54 void td_init(td_t *instance, const td_t *next,
    55     usb_direction_t direction, const void *buffer, size_t size, int toggle)
     41void td_init(td_t *instance,
     42    usb_direction_t dir, const void *buffer, size_t size, int toggle)
    5643{
    5744        assert(instance);
    5845        bzero(instance, sizeof(td_t));
    59         /* Set PID and Error code */
    6046        instance->status = 0
    61             | ((dir[direction] & TD_STATUS_DP_MASK) << TD_STATUS_DP_SHIFT)
     47            | ((dp[dir] & TD_STATUS_DP_MASK) << TD_STATUS_DP_SHIFT)
    6248            | ((CC_NOACCESS2 & TD_STATUS_CC_MASK) << TD_STATUS_CC_SHIFT);
    63 
    6449        if (toggle == 0 || toggle == 1) {
    65                 /* Set explicit toggle bit */
    66                 instance->status |= TD_STATUS_T_USE_TD_FLAG;
    67                 instance->status |= toggle ? TD_STATUS_T_FLAG : 0;
     50                instance->status |= togg[toggle] << TD_STATUS_T_SHIFT;
    6851        }
    69 
    70         /* Alow less data on input. */
    7152        if (dir == USB_DIRECTION_IN) {
    7253                instance->status |= TD_STATUS_ROUND_FLAG;
    7354        }
    74 
    7555        if (buffer != NULL) {
    7656                assert(size != 0);
     
    7858                instance->be = addr_to_phys(buffer + size - 1);
    7959        }
    80 
    81         instance->next = addr_to_phys(next) & TD_NEXT_PTR_MASK;
    82 
    8360}
    8461/**
  • uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.h

    r22ceff3a r25696fea  
    3737#include <bool.h>
    3838#include <stdint.h>
     39#include "../utils/malloc32.h"
    3940
    40 #include "../utils/malloc32.h"
    4141#include "completion_codes.h"
    4242
     
    4646#define OHCI_TD_MAX_TRANSFER (4 * 1024)
    4747
    48 /**
    49  * Transfer Descriptor representation.
    50  *
    51  * See OHCI spec chapter 4.3.1 General Transfer Descriptor on page 19
    52  * (pdf page 33) for details.
    53  */
    5448typedef struct td {
    55         /** Status field. Do not touch on active TDs. */
    5649        volatile uint32_t status;
    5750#define TD_STATUS_ROUND_FLAG (1 << 18)
    58 #define TD_STATUS_DP_MASK (0x3) /* Direction/PID */
     51#define TD_STATUS_DP_MASK (0x3) /* direction/PID */
    5952#define TD_STATUS_DP_SHIFT (19)
    6053#define TD_STATUS_DP_SETUP (0x0)
    6154#define TD_STATUS_DP_OUT (0x1)
    6255#define TD_STATUS_DP_IN (0x2)
    63 #define TD_STATUS_DI_MASK (0x7) /* Delay interrupt, wait n frames before irq */
     56#define TD_STATUS_DI_MASK (0x7) /* delay interrupt, wait DI frames before int */
    6457#define TD_STATUS_DI_SHIFT (21)
    6558#define TD_STATUS_DI_NO_INTERRUPT (0x7)
    66 #define TD_STATUS_T_FLAG (1 << 24) /* Explicit toggle bit value for this TD */
    67 #define TD_STATUS_T_USE_TD_FLAG (1 << 25) /* 1 = use bit 24 as toggle bit */
    68 #define TD_STATUS_EC_MASK (0x3) /* Error count */
     59#define TD_STATUS_T_MASK (0x3)  /* data toggle 1x = use ED toggle carry */
     60#define TD_STATUS_T_SHIFT (24)
     61#define TD_STATUS_T_0 (0x2)
     62#define TD_STATUS_T_1 (0x3)
     63#define TD_STATUS_T_ED (0)
     64#define TD_STATUS_EC_MASK (0x3) /* error count */
    6965#define TD_STATUS_EC_SHIFT (26)
    70 #define TD_STATUS_CC_MASK (0xf) /* Condition code */
     66#define TD_STATUS_CC_MASK (0xf) /* condition code */
    7167#define TD_STATUS_CC_SHIFT (28)
    7268
    73         /**
    74          * Current buffer pointer.
    75          * Phys address of the first byte to be transferred. */
    76         volatile uint32_t cbp;
    77 
    78         /** Pointer to the next TD in chain. 16-byte aligned. */
     69        volatile uint32_t cbp; /* current buffer ptr, data to be transfered */
    7970        volatile uint32_t next;
    8071#define TD_NEXT_PTR_MASK (0xfffffff0)
    8172#define TD_NEXT_PTR_SHIFT (0)
    8273
    83         /**
    84          * Buffer end.
    85          * Phys address of the last byte of the transfer.
    86          * @note this does not have to be on the same page as cbp.
    87          */
    88         volatile uint32_t be;
     74        volatile uint32_t be; /* buffer end, address of the last byte */
    8975} __attribute__((packed)) td_t;
    9076
    91 void td_init(td_t *instance, const td_t *next,
     77void td_init(td_t *instance,
    9278    usb_direction_t dir, const void *buffer, size_t size, int toggle);
    9379
    94 /**
    95  * Check TD for completion.
    96  * @param instance TD structure.
    97  * @return true if the TD was accessed and processed by hw, false otherwise.
    98  */
    99 inline static bool td_is_finished(const td_t *instance)
     80inline static void td_set_next(td_t *instance, td_t *next)
    10081{
    10182        assert(instance);
    102         const int cc =
    103             (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
    104         /* This value is changed on transfer completion,
    105          * either to CC_NOERROR or and error code.
    106          * See OHCI spec 4.3.1.3.5 p. 23 (pdf 37) */
     83        instance->next = addr_to_phys(next) & TD_NEXT_PTR_MASK;
     84}
     85
     86inline static bool td_is_finished(td_t *instance)
     87{
     88        assert(instance);
     89        int cc = (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
     90        /* something went wrong, error code is set */
    10791        if (cc != CC_NOACCESS1 && cc != CC_NOACCESS2) {
     92                return true;
     93        }
     94        /* everything done */
     95        if (cc == CC_NOERROR && instance->cbp == 0) {
    10896                return true;
    10997        }
     
    11199}
    112100
    113 /**
    114  * Get error code that indicates transfer status.
    115  * @param instance TD structure.
    116  * @return Error code.
    117  */
    118 static inline int td_error(const td_t *instance)
     101static inline int td_error(td_t *instance)
    119102{
    120103        assert(instance);
    121         const int cc =
    122             (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
     104        int cc = (instance->status >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
    123105        return cc_to_rc(cc);
    124106}
    125107
    126 /**
    127  * Get remaining portion of buffer to be read/written
    128  * @param instance TD structure
    129  * @return size of remaining buffer.
    130  */
    131108static inline size_t td_remain_size(td_t *instance)
    132109{
    133110        assert(instance);
    134         /* Current buffer pointer is cleared on successful transfer */
    135111        if (instance->cbp == 0)
    136112                return 0;
    137         /* Buffer end points to the last byte of transfer buffer, so add 1 */
    138113        return instance->be - instance->cbp + 1;
    139114}
  • uspace/drv/bus/usb/ohci/ohci_batch.c

    r22ceff3a r25696fea  
    163163            ohci_batch->ed->td_tail, ohci_batch->ed->next);
    164164
    165         if (!ed_inactive(ohci_batch->ed) && ed_transfer_pending(ohci_batch->ed))
    166                 return false;
    167 
    168         /* Now we may be sure that either the ED is inactive because of errors
    169          * or all transfer descriptors completed successfully */
    170 
    171         /* Assume all data got through */
    172         ohci_batch->usb_batch->transfered_size =
    173             ohci_batch->usb_batch->buffer_size;
    174 
    175         /* Assume we will leave the last(unused) TD behind */
    176         ohci_batch->leave_td = ohci_batch->td_count;
    177 
    178         /* Check all TDs */
    179         for (size_t i = 0; i < ohci_batch->td_count; ++i) {
     165        size_t i = 0;
     166        for (; i < ohci_batch->td_count; ++i) {
    180167                assert(ohci_batch->tds[i] != NULL);
    181168                usb_log_debug("TD %zu: %08x:%08x:%08x:%08x.\n", i,
    182169                    ohci_batch->tds[i]->status, ohci_batch->tds[i]->cbp,
    183170                    ohci_batch->tds[i]->next, ohci_batch->tds[i]->be);
    184 
    185                 /* If the TD got all its data through, it will report 0 bytes
    186                  * remain, the sole exception is INPUT with data rounding flag
    187                  * (short), i.e. every INPUT. Nice thing is that short packets
    188                  * will correctly report remaining data, thus making
    189                  * this computation correct (short packets need to be produced
    190                  * by the last TD)
    191                  * NOTE: This also works for CONTROL transfer as
    192                  * the first TD will return 0 remain.
    193                  * NOTE: Short packets don't break the assumption that
    194                  * we leave the very last(unused) TD behind.
    195                  */
    196                 ohci_batch->usb_batch->transfered_size
    197                     -= td_remain_size(ohci_batch->tds[i]);
    198 
     171                if (!td_is_finished(ohci_batch->tds[i])) {
     172                        return false;
     173                }
    199174                ohci_batch->usb_batch->error = td_error(ohci_batch->tds[i]);
    200175                if (ohci_batch->usb_batch->error != EOK) {
     
    202177                            ohci_batch->usb_batch, i,
    203178                            ohci_batch->tds[i]->status);
    204 
    205                         /* ED should be stopped because of errors */
    206                         assert((ohci_batch->ed->td_head & ED_TDHEAD_HALTED_FLAG) != 0);
    207 
    208                         /* Now we have a problem: we don't know what TD
    209                          * the head pointer points to, the retiring rules
    210                          * described in specs say it should be the one after
    211                          * the failed one so set the tail pointer accordingly.
    212                          * It will be the one TD we leave behind.
    213                          */
    214                         ohci_batch->leave_td = i + 1;
    215 
    216                         /* Check TD assumption */
    217                         const uint32_t pa = addr_to_phys(
    218                             ohci_batch->tds[ohci_batch->leave_td]);
    219                         assert((ohci_batch->ed->td_head & ED_TDTAIL_PTR_MASK)
    220                             == pa);
    221 
    222                         ed_set_tail_td(ohci_batch->ed,
    223                             ohci_batch->tds[ohci_batch->leave_td]);
    224 
    225                         /* Clear possible ED HALT */
    226                         ohci_batch->ed->td_head &= ~ED_TDHEAD_HALTED_FLAG;
     179                        /* Make sure TD queue is empty (one TD),
     180                         * ED should be marked as halted */
     181                        ohci_batch->ed->td_tail =
     182                            (ohci_batch->ed->td_head & ED_TDTAIL_PTR_MASK);
     183                        ++i;
    227184                        break;
    228185                }
    229186        }
    230         assert(ohci_batch->usb_batch->transfered_size <=
    231             ohci_batch->usb_batch->buffer_size);
    232 
    233         /* Store the remaining TD */
     187
     188        assert(i <= ohci_batch->td_count);
     189        ohci_batch->leave_td = i;
     190
    234191        ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ohci_batch->usb_batch->ep);
    235192        assert(ohci_ep);
    236193        ohci_ep->td = ohci_batch->tds[ohci_batch->leave_td];
    237 
    238         /* Make sure that we are leaving the right TD behind */
     194        assert(i > 0);
     195        ohci_batch->usb_batch->transfered_size =
     196            ohci_batch->usb_batch->buffer_size;
     197        for (--i;i < ohci_batch->td_count; ++i) {
     198                ohci_batch->usb_batch->transfered_size
     199                    -= td_remain_size(ohci_batch->tds[i]);
     200        }
     201
     202        /* Clear possible ED HALT */
     203        ohci_batch->ed->td_head &= ~ED_TDHEAD_HALTED_FLAG;
     204        /* just make sure that we are leaving the right TD behind */
    239205        const uint32_t pa = addr_to_phys(ohci_ep->td);
    240206        assert(pa == (ohci_batch->ed->td_head & ED_TDHEAD_PTR_MASK));
     
    251217{
    252218        assert(ohci_batch);
    253         ed_set_tail_td(ohci_batch->ed, ohci_batch->tds[ohci_batch->td_count]);
     219        ed_set_end_td(ohci_batch->ed, ohci_batch->tds[ohci_batch->td_count]);
    254220}
    255221/*----------------------------------------------------------------------------*/
     
    281247        const usb_direction_t status_dir = reverse_dir[dir];
    282248
    283         /* Setup stage */
    284         td_init(
    285             ohci_batch->tds[0], ohci_batch->tds[1], USB_DIRECTION_BOTH,
    286             buffer, ohci_batch->usb_batch->setup_size, toggle);
     249        /* setup stage */
     250        td_init(ohci_batch->tds[0], USB_DIRECTION_BOTH, buffer,
     251                ohci_batch->usb_batch->setup_size, toggle);
     252        td_set_next(ohci_batch->tds[0], ohci_batch->tds[1]);
    287253        usb_log_debug("Created CONTROL SETUP TD: %08x:%08x:%08x:%08x.\n",
    288254            ohci_batch->tds[0]->status, ohci_batch->tds[0]->cbp,
     
    290256        buffer += ohci_batch->usb_batch->setup_size;
    291257
    292         /* Data stage */
     258        /* data stage */
    293259        size_t td_current = 1;
    294260        size_t remain_size = ohci_batch->usb_batch->buffer_size;
     
    299265                toggle = 1 - toggle;
    300266
    301                 td_init(ohci_batch->tds[td_current],
    302                     ohci_batch->tds[td_current + 1],
    303                     data_dir, buffer, transfer_size, toggle);
     267                td_init(ohci_batch->tds[td_current], data_dir, buffer,
     268                    transfer_size, toggle);
     269                td_set_next(ohci_batch->tds[td_current],
     270                    ohci_batch->tds[td_current + 1]);
    304271                usb_log_debug("Created CONTROL DATA TD: %08x:%08x:%08x:%08x.\n",
    305272                    ohci_batch->tds[td_current]->status,
     
    314281        }
    315282
    316         /* Status stage */
     283        /* status stage */
    317284        assert(td_current == ohci_batch->td_count - 1);
    318         td_init(ohci_batch->tds[td_current], ohci_batch->tds[td_current + 1],
    319             status_dir, NULL, 0, 1);
     285        td_init(ohci_batch->tds[td_current], status_dir, NULL, 0, 1);
     286        td_set_next(ohci_batch->tds[td_current],
     287            ohci_batch->tds[td_current + 1]);
    320288        usb_log_debug("Created CONTROL STATUS TD: %08x:%08x:%08x:%08x.\n",
    321289            ohci_batch->tds[td_current]->status,
     
    355323                    ? OHCI_TD_MAX_TRANSFER : remain_size;
    356324
    357                 td_init(
    358                     ohci_batch->tds[td_current], ohci_batch->tds[td_current + 1],
    359                     dir, buffer, transfer_size, -1);
     325                td_init(ohci_batch->tds[td_current], dir, buffer,
     326                    transfer_size, -1);
     327                td_set_next(ohci_batch->tds[td_current],
     328                    ohci_batch->tds[td_current + 1]);
    360329
    361330                usb_log_debug("Created DATA TD: %08x:%08x:%08x:%08x.\n",
  • uspace/drv/bus/usb/ohci/ohci_endpoint.c

    r22ceff3a r25696fea  
    102102        }
    103103
    104         ed_init(ohci_ep->ed, ep, ohci_ep->td);
     104        ed_init(ohci_ep->ed, ep);
     105        ed_set_td(ohci_ep->ed, ohci_ep->td);
    105106        endpoint_set_hc_data(
    106107            ep, ohci_ep, ohci_endpoint_fini, ohci_ep_toggle_get, ohci_ep_toggle_set);
  • uspace/drv/bus/usb/ohci/root_hub.c

    r22ceff3a r25696fea  
    3535#include <errno.h>
    3636#include <str_error.h>
    37 #include <fibril_synch.h>
    3837
    3938#include <usb/debug.h>
    40 #include <usb/dev/request.h>
    41 #include <usb/classes/hub.h>
    4239
    4340#include "root_hub.h"
     
    4643#include <usb/dev/driver.h>
    4744#include "ohci_regs.h"
     45
     46#include <usb/dev/request.h>
     47#include <usb/classes/hub.h>
    4848
    4949/**
     
    108108static void create_serialized_hub_descriptor(rh_t *instance);
    109109static void rh_init_descriptors(rh_t *instance);
    110 static uint16_t create_interrupt_mask(const rh_t *instance);
    111 static int get_status(const rh_t *instance, usb_transfer_batch_t *request);
    112 static int get_descriptor(const rh_t *instance, usb_transfer_batch_t *request);
    113 static int set_feature(const rh_t *instance, usb_transfer_batch_t *request);
    114 static int clear_feature(const rh_t *instance, usb_transfer_batch_t *request);
    115 static int set_feature_port(
    116     const rh_t *instance, uint16_t feature, uint16_t port);
    117 static int clear_feature_port(
    118     const rh_t *instance, uint16_t feature, uint16_t port);
     110static uint16_t create_interrupt_mask(rh_t *instance);
     111static int get_status(rh_t *instance, usb_transfer_batch_t *request);
     112static int get_descriptor(rh_t *instance, usb_transfer_batch_t *request);
     113static int set_feature(rh_t *instance, usb_transfer_batch_t *request);
     114static int clear_feature(rh_t *instance, usb_transfer_batch_t *request);
     115static int set_feature_port(rh_t *instance, uint16_t feature, uint16_t port);
     116static int clear_feature_port(rh_t *instance, uint16_t feature, uint16_t port);
    119117static int control_request(rh_t *instance, usb_transfer_batch_t *request);
    120118static inline void interrupt_request(
     
    155153        instance->unfinished_interrupt_transfer = NULL;
    156154
    157 #if defined OHCI_POWER_SWITCH_no
     155#ifdef OHCI_POWER_SWITCH_no
    158156        /* Set port power mode to no power-switching. (always on) */
    159157        instance->registers->rh_desc_a |= RHDA_NPS_FLAG;
    160 
    161158        /* Set to no over-current reporting */
    162159        instance->registers->rh_desc_a |= RHDA_NOCP_FLAG;
    163 
    164160#elif defined OHCI_POWER_SWITCH_ganged
    165161        /* Set port power mode to no ganged power-switching. */
     
    167163        instance->registers->rh_desc_a &= ~RHDA_PSM_FLAG;
    168164        instance->registers->rh_status = RHS_CLEAR_GLOBAL_POWER;
    169 
    170165        /* Set to global over-current */
    171166        instance->registers->rh_desc_a &= ~RHDA_NOCP_FLAG;
     
    179174        instance->registers->rh_desc_b &= (RHDB_PCC_MASK << RHDB_PCC_SHIFT);
    180175        instance->registers->rh_status = RHS_CLEAR_GLOBAL_POWER;
    181 
    182176        /* Return control to per port state */
    183177        instance->registers->rh_desc_b |=
    184178                ((1 << (instance->port_count + 1)) - 1) << RHDB_PCC_SHIFT;
    185 
    186179        /* Set per port over-current */
    187180        instance->registers->rh_desc_a &= ~RHDA_NOCP_FLAG;
     
    189182#endif
    190183
    191         fibril_mutex_initialize(&instance->guard);
    192184        rh_init_descriptors(instance);
    193185
     
    217209        case USB_TRANSFER_INTERRUPT:
    218210                usb_log_debug("Root hub got INTERRUPT packet\n");
    219                 fibril_mutex_lock(&instance->guard);
    220                 assert(instance->unfinished_interrupt_transfer == NULL);
    221211                const uint16_t mask = create_interrupt_mask(instance);
    222212                if (mask == 0) {
    223213                        usb_log_debug("No changes..\n");
     214                        assert(instance->unfinished_interrupt_transfer == NULL);
    224215                        instance->unfinished_interrupt_transfer = request;
    225                         fibril_mutex_unlock(&instance->guard);
    226216                        return;
    227217                }
    228218                usb_log_debug("Processing changes...\n");
    229219                interrupt_request(request, mask, instance->interrupt_mask_size);
    230                 fibril_mutex_unlock(&instance->guard);
    231220                break;
    232221
     
    248237        assert(instance);
    249238
    250         fibril_mutex_lock(&instance->guard);
    251         if (instance->unfinished_interrupt_transfer) {
    252                 usb_log_debug("Finalizing interrupt transfer\n");
    253                 const uint16_t mask = create_interrupt_mask(instance);
    254                 interrupt_request(instance->unfinished_interrupt_transfer,
    255                     mask, instance->interrupt_mask_size);
    256                 usb_transfer_batch_dispose(
    257                     instance->unfinished_interrupt_transfer);
    258                 instance->unfinished_interrupt_transfer = NULL;
    259         }
    260         fibril_mutex_unlock(&instance->guard);
     239        if (!instance->unfinished_interrupt_transfer)
     240                return;
     241
     242        usb_log_debug("Finalizing interrupt transfer\n");
     243        const uint16_t mask = create_interrupt_mask(instance);
     244        interrupt_request(instance->unfinished_interrupt_transfer,
     245            mask, instance->interrupt_mask_size);
     246        usb_transfer_batch_dispose(instance->unfinished_interrupt_transfer);
     247
     248        instance->unfinished_interrupt_transfer = NULL;
    261249}
    262250/*----------------------------------------------------------------------------*/
     
    354342 * @return Mask of changes.
    355343 */
    356 uint16_t create_interrupt_mask(const rh_t *instance)
     344uint16_t create_interrupt_mask(rh_t *instance)
    357345{
    358346        assert(instance);
     
    384372 * @return error code
    385373 */
    386 int get_status(const rh_t *instance, usb_transfer_batch_t *request)
     374int get_status(rh_t *instance, usb_transfer_batch_t *request)
    387375{
    388376        assert(instance);
     
    430418 * @return Error code
    431419 */
    432 int get_descriptor(const rh_t *instance, usb_transfer_batch_t *request)
     420int get_descriptor(rh_t *instance, usb_transfer_batch_t *request)
    433421{
    434422        assert(instance);
     
    508496 * @return error code
    509497 */
    510 int set_feature_port(const rh_t *instance, uint16_t feature, uint16_t port)
     498int set_feature_port(rh_t *instance, uint16_t feature, uint16_t port)
    511499{
    512500        assert(instance);
     
    547535 * @return error code
    548536 */
    549 int clear_feature_port(const rh_t *instance, uint16_t feature, uint16_t port)
     537int clear_feature_port(rh_t *instance, uint16_t feature, uint16_t port)
    550538{
    551539        assert(instance);
     
    604592 * @return error code
    605593 */
    606 int set_feature(const rh_t *instance, usb_transfer_batch_t *request)
     594int set_feature(rh_t *instance, usb_transfer_batch_t *request)
    607595{
    608596        assert(instance);
     
    640628 * @return error code
    641629 */
    642 int clear_feature(const rh_t *instance, usb_transfer_batch_t *request)
     630int clear_feature(rh_t *instance, usb_transfer_batch_t *request)
    643631{
    644632        assert(instance);
     
    647635        const usb_device_request_setup_packet_t *setup_request =
    648636            (usb_device_request_setup_packet_t *) request->setup_buffer;
    649 
    650637        request->transfered_size = 0;
    651 
    652638        switch (setup_request->request_type)
    653639        {
     
    661647                /*
    662648                 * Chapter 11.16.2 specifies that only C_HUB_LOCAL_POWER and
    663                  * C_HUB_OVER_CURRENT are supported.
    664                  * C_HUB_OVER_CURRENT is represented by OHCI RHS_OCIC_FLAG.
    665                  * C_HUB_LOCAL_POWER is not supported
     649                 * C_HUB_OVER_CURRENT are supported. C_HUB_OVER_CURRENT is represented
     650                 * by OHCI RHS_OCIC_FLAG. C_HUB_LOCAL_POWER is not supported
    666651                 * as root hubs do not support local power status feature.
    667652                 * (OHCI pg. 127) */
     
    735720                    "additional data\n");
    736721                return clear_feature(instance, request);
    737 
    738722        case USB_DEVREQ_SET_FEATURE:
    739723                usb_log_debug2("Processing request without "
  • uspace/drv/bus/usb/ohci/root_hub.h

    r22ceff3a r25696fea  
    4747 */
    4848typedef struct rh {
    49         fibril_mutex_t guard;
    5049        /** pointer to ohci driver registers */
    5150        ohci_regs_t *registers;
  • uspace/drv/bus/usb/ohci/utils/malloc32.h

    r22ceff3a r25696fea  
    4141#include <as.h>
    4242
    43 /* Generic TDs and EDs require 16byte alignment,
    44  * Isochronous TD require 32byte alignment,
    45  * buffers do not have to be aligned.
    46  */
    47 #define OHCI_ALIGN 32
    48 
    4943/** Get physical address translation
    5044 *
     
    6862 */
    6963static inline void * malloc32(size_t size)
    70         { return memalign(OHCI_ALIGN, size); }
     64        { return memalign(size, size); }
    7165/*----------------------------------------------------------------------------*/
    7266/** Physical mallocator simulator
  • uspace/drv/bus/usb/usbhid/generic/hiddev.c

    r22ceff3a r25696fea  
    4848/*----------------------------------------------------------------------------*/
    4949
    50 const usb_endpoint_description_t usb_hid_generic_poll_endpoint_description = {
     50usb_endpoint_description_t usb_hid_generic_poll_endpoint_description = {
    5151        .transfer_type = USB_TRANSFER_INTERRUPT,
    5252        .direction = USB_DIRECTION_IN,
  • uspace/drv/bus/usb/usbhid/generic/hiddev.h

    r22ceff3a r25696fea  
    4141struct usb_hid_dev;
    4242
    43 extern const usb_endpoint_description_t
    44     usb_hid_generic_poll_endpoint_description;
     43usb_endpoint_description_t usb_hid_generic_poll_endpoint_description;
    4544
    4645const char *HID_GENERIC_FUN_NAME;
  • uspace/drv/bus/usb/usbhid/kbd/kbddev.c

    r22ceff3a r25696fea  
    8888
    8989/** Keyboard polling endpoint description for boot protocol class. */
    90 const usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description = {
     90usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description = {
    9191        .transfer_type = USB_TRANSFER_INTERRUPT,
    9292        .direction = USB_DIRECTION_IN,
     
    237237
    238238        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    239             &hid_dev->report, NULL, kbd_dev->led_path,
     239            hid_dev->report, NULL, kbd_dev->led_path,
    240240            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    241241            USB_HID_REPORT_TYPE_OUTPUT);
    242242
    243243        while (field != NULL) {
    244 
    245                 if ((field->usage == USB_HID_LED_NUM_LOCK)
     244               
     245                if ((field->usage == USB_HID_LED_NUM_LOCK) 
    246246                    && (kbd_dev->mods & KM_NUM_LOCK)){
    247247                        field->value = 1;
    248248                }
    249249
    250                 if ((field->usage == USB_HID_LED_CAPS_LOCK)
     250                if ((field->usage == USB_HID_LED_CAPS_LOCK) 
    251251                    && (kbd_dev->mods & KM_CAPS_LOCK)){
    252252                        field->value = 1;
    253253                }
    254254
    255                 if ((field->usage == USB_HID_LED_SCROLL_LOCK)
     255                if ((field->usage == USB_HID_LED_SCROLL_LOCK) 
    256256                    && (kbd_dev->mods & KM_SCROLL_LOCK)){
    257257                        field->value = 1;
    258258                }
    259 
    260                 field = usb_hid_report_get_sibling(
    261                     &hid_dev->report, field, kbd_dev->led_path,
    262                 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    263                     USB_HID_REPORT_TYPE_OUTPUT);
     259               
     260                field = usb_hid_report_get_sibling(hid_dev->report, field,
     261                    kbd_dev->led_path, 
     262                USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     263                        USB_HID_REPORT_TYPE_OUTPUT);
    264264        }
    265265
    266266        // TODO: what about the Report ID?
    267         int rc = usb_hid_report_output_translate(&hid_dev->report, 0,
     267        int rc = usb_hid_report_output_translate(hid_dev->report, 0,
    268268            kbd_dev->output_buffer, kbd_dev->output_size);
    269269
     
    432432static void usb_kbd_process_data(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev)
    433433{
     434        assert(hid_dev->report != NULL);
    434435        assert(hid_dev != NULL);
    435436        assert(kbd_dev != NULL);
     
    443444
    444445        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    445             &hid_dev->report, NULL, path,
    446             USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     446            hid_dev->report, NULL, path,
     447            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
    447448            USB_HID_REPORT_TYPE_INPUT);
    448449        unsigned i = 0;
     
    453454               
    454455                assert(i < kbd_dev->key_count);
    455 
     456               
    456457                // save the key usage
    457458                if (field->value != 0) {
     
    462463                }
    463464                usb_log_debug2("Saved %u. key usage %d\n", i, kbd_dev->keys[i]);
    464 
     465               
    465466                ++i;
    466                 field = usb_hid_report_get_sibling(
    467                     &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
    468                         | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     467                field = usb_hid_report_get_sibling(hid_dev->report, field, path,
     468                    USB_HID_PATH_COMPARE_END
     469                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    469470                    USB_HID_REPORT_TYPE_INPUT);
    470471        }
     
    615616
    616617        kbd_dev->key_count = usb_hid_report_size(
    617             &hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
     618            hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
    618619        usb_hid_report_path_free(path);
    619620
    620621        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    621622
    622         kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t));
     623        kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t));
    623624
    624625        if (kbd_dev->keys == NULL) {
     
    642643         */
    643644        kbd_dev->output_size = 0;
    644         kbd_dev->output_buffer = usb_hid_report_output(&hid_dev->report,
     645        kbd_dev->output_buffer = usb_hid_report_output(hid_dev->report,
    645646            &kbd_dev->output_size, 0);
    646647        if (kbd_dev->output_buffer == NULL) {
     
    656657            kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
    657658
    658         kbd_dev->led_output_size = usb_hid_report_size(
    659             &hid_dev->report, 0, USB_HID_REPORT_TYPE_OUTPUT);
     659        kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report,
     660            0, USB_HID_REPORT_TYPE_OUTPUT);
    660661
    661662        usb_log_debug("Output report size (in items): %zu\n",
     
    825826int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev)
    826827{
    827         int rc = usb_hid_parse_report_descriptor(
    828             &hid_dev->report, USB_KBD_BOOT_REPORT_DESCRIPTOR,
     828        int rc = usb_hid_parse_report_descriptor(hid_dev->report,
     829            USB_KBD_BOOT_REPORT_DESCRIPTOR,
    829830            USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE);
    830831
     
    835836        }
    836837
    837         rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
     838        rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 
    838839            hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
    839840
  • uspace/drv/bus/usb/usbhid/kbd/kbddev.h

    r22ceff3a r25696fea  
    118118/*----------------------------------------------------------------------------*/
    119119
    120 extern const usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description;
     120usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description;
    121121
    122122const char *HID_KBD_FUN_NAME;
  • uspace/drv/bus/usb/usbhid/main.c

    r22ceff3a r25696fea  
    9292        if (rc != EOK) {
    9393                usb_log_error("Failed to initialize USB/HID device.\n");
    94                 usb_hid_deinit(hid_dev);
     94                usb_hid_destroy(hid_dev);
    9595                return rc;
    9696        }
     
    128128                usb_log_error("Failed to start polling fibril for `%s'.\n",
    129129                    dev->ddf_dev->name);
    130                 usb_hid_deinit(hid_dev);
     130                usb_hid_destroy(hid_dev);
    131131                return rc;
    132132        }
    133133        hid_dev->running = true;
     134        dev->driver_data = hid_dev;
    134135
    135136        /*
     
    203204
    204205        assert(!hid_dev->running);
    205         usb_hid_deinit(hid_dev);
     206        usb_hid_destroy(hid_dev);
    206207        usb_log_debug2("%s destruction complete.\n", dev->ddf_dev->name);
    207208        return EOK;
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    r22ceff3a r25696fea  
    5959/*----------------------------------------------------------------------------*/
    6060
    61 const usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description = {
     61usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description = {
    6262        .transfer_type = USB_TRANSFER_INTERRUPT,
    6363        .direction = USB_DIRECTION_IN,
     
    268268
    269269        int shift_x = get_mouse_axis_move_value(hid_dev->report_id,
    270             &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
     270            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
    271271        int shift_y = get_mouse_axis_move_value(hid_dev->report_id,
    272             &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
     272            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
    273273        int wheel = get_mouse_axis_move_value(hid_dev->report_id,
    274             &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
     274            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    275275
    276276        if ((shift_x != 0) || (shift_y != 0)) {
    277                 async_exch_t *exch =
    278                     async_exchange_begin(mouse_dev->mouse_sess);
     277                async_exch_t *exch = async_exchange_begin(mouse_dev->mouse_sess);
    279278                async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y);
    280279                async_exchange_end(exch);
     
    292291
    293292        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    294             &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
    295             | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, USB_HID_REPORT_TYPE_INPUT);
     293            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
     294            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     295            USB_HID_REPORT_TYPE_INPUT);
    296296
    297297        while (field != NULL) {
     
    314314                        async_req_2_0(exch, MOUSEEV_BUTTON_EVENT, field->usage, 0);
    315315                        async_exchange_end(exch);
    316 
     316                       
    317317                        mouse_dev->buttons[field->usage - field->usage_minimum] =
    318318                           field->value;
    319319                }
    320 
     320               
    321321                field = usb_hid_report_get_sibling(
    322                     &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
    323                     | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     322                    hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
     323                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
    324324                    USB_HID_REPORT_TYPE_INPUT);
    325325        }
     
    474474        // that the current solution is good enough.
    475475        /* Adding 1 because we will be accessing buttons[highest]. */
    476         mouse_dev->buttons_count = 1 + usb_mouse_get_highest_button(
    477             &hid_dev->report, hid_dev->report_id);
     476        mouse_dev->buttons_count = usb_mouse_get_highest_button(hid_dev->report,
     477            hid_dev->report_id) + 1;
    478478        mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t));
    479479
     
    532532int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev)
    533533{
    534         int rc = usb_hid_parse_report_descriptor(
    535             &hid_dev->report, USB_MOUSE_BOOT_REPORT_DESCRIPTOR,
     534        int rc = usb_hid_parse_report_descriptor(hid_dev->report,
     535            USB_MOUSE_BOOT_REPORT_DESCRIPTOR,
    536536            USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE);
    537537
     
    542542        }
    543543
    544         rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
     544        rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 
    545545            hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
    546546
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.h

    r22ceff3a r25696fea  
    6363/*----------------------------------------------------------------------------*/
    6464
    65 extern const usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description;
     65usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description;
    6666
    6767const char *HID_MOUSE_FUN_NAME;
  • uspace/drv/bus/usb/usbhid/multimedia/multimedia.c

    r22ceff3a r25696fea  
    161161/*----------------------------------------------------------------------------*/
    162162
    163 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data)
    164 {
    165         if (hid_dev == NULL || hid_dev->usb_dev == NULL) {
    166                 return EINVAL; /*! @todo Other return code? */
    167         }
    168 
    169         usb_log_debug(NAME " Initializing HID/multimedia structure...\n");
    170 
     163static int usb_multimedia_create_function(usb_hid_dev_t *hid_dev,
     164    usb_multimedia_t *multim_dev)
     165{
    171166        /* Create the exposed function. */
    172         ddf_fun_t *fun = ddf_fun_create(
    173             hid_dev->usb_dev->ddf_dev, fun_exposed, NAME);
     167        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     168            NAME);
    174169        if (fun == NULL) {
    175170                usb_log_error("Could not create DDF function node.\n");
     
    178173
    179174        fun->ops = &multimedia_ops;
    180 
    181         usb_multimedia_t *multim_dev =
    182             ddf_fun_data_alloc(fun, sizeof(usb_multimedia_t));
    183         if (multim_dev == NULL) {
    184                 ddf_fun_destroy(fun);
    185                 return ENOMEM;
    186         }
    187 
    188         multim_dev->console_sess = NULL;
    189         multim_dev->fun = fun;
    190 
    191         //todo Autorepeat?
     175        fun->driver_data = multim_dev;   // TODO: maybe change to hid_dev->data
    192176
    193177        int rc = ddf_fun_bind(fun);
     
    210194                return rc;
    211195        }
    212 
    213         /* Save the KBD device structure into the HID device structure. */
     196        multim_dev->fun = fun;
     197
     198        return EOK;
     199}
     200
     201/*----------------------------------------------------------------------------*/
     202
     203int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data)
     204{
     205        if (hid_dev == NULL || hid_dev->usb_dev == NULL) {
     206                return EINVAL; /*! @todo Other return code? */
     207        }
     208
     209        usb_log_debug(NAME " Initializing HID/multimedia structure...\n");
     210
     211        usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc(
     212            sizeof(usb_multimedia_t));
     213        if (multim_dev == NULL) {
     214                return ENOMEM;
     215        }
     216
     217        multim_dev->console_sess = NULL;
     218
     219        /*! @todo Autorepeat */
     220
     221        // save the KBD device structure into the HID device structure
    214222        *data = multim_dev;
    215223
     224        usb_log_debug(NAME " HID/multimedia device structure initialized.\n");
     225
     226        int rc = usb_multimedia_create_function(hid_dev, multim_dev);
     227        if (rc != EOK)
     228                return rc;
     229
    216230        usb_log_debug(NAME " HID/multimedia structure initialized.\n");
     231
    217232        return EOK;
    218233}
     
    257272
    258273        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    259             &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
    260             | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     274            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
     275            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
    261276            USB_HID_REPORT_TYPE_INPUT);
    262277
     
    278293
    279294                field = usb_hid_report_get_sibling(
    280                     &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
     295                    hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
    281296                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    282297                    USB_HID_REPORT_TYPE_INPUT);
  • uspace/drv/bus/usb/usbhid/subdrivers.c

    r22ceff3a r25696fea  
    4242#include "generic/hiddev.h"
    4343
    44 static const usb_hid_subdriver_usage_t path_kbd[] = {
    45         {USB_HIDUT_PAGE_GENERIC_DESKTOP,
    46          USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD},
     44static usb_hid_subdriver_usage_t path_kbd[] = {
     45        {USB_HIDUT_PAGE_GENERIC_DESKTOP, 
     46         USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD}, 
    4747        {0, 0}
    4848};
    4949
    50 static const usb_hid_subdriver_usage_t path_mouse[] = {
     50static usb_hid_subdriver_usage_t path_mouse[] = {
    5151        {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_MOUSE},
    5252        {0, 0}
    5353};
    5454
    55 static const usb_hid_subdriver_usage_t multim_key_path[] = {
     55static usb_hid_subdriver_usage_t multim_key_path[] = {
    5656        {USB_HIDUT_PAGE_CONSUMER, USB_HIDUT_USAGE_CONSUMER_CONSUMER_CONTROL},
    5757        {0, 0}
     
    7171                        .poll_end = NULL
    7272                },
     73               
    7374        },
    7475        {
     
    101102};
    102103
    103 const int USB_HID_MAX_SUBDRIVERS =
    104     sizeof(usb_hid_subdrivers) / sizeof(usb_hid_subdrivers[0]);
    105 
    106104/**
    107105 * @}
  • uspace/drv/bus/usb/usbhid/subdrivers.h

    r22ceff3a r25696fea  
    7878
    7979        /** Subdriver for controlling this device. */
    80         const usb_hid_subdriver_t subdriver;
     80        usb_hid_subdriver_t subdriver;
    8181} usb_hid_subdriver_mapping_t;
    8282
     
    8484
    8585extern const usb_hid_subdriver_mapping_t usb_hid_subdrivers[];
    86 extern const int USB_HID_MAX_SUBDRIVERS;
    8786
    8887/*----------------------------------------------------------------------------*/
  • uspace/drv/bus/usb/usbhid/usbhid.c

    r22ceff3a r25696fea  
    5454
    5555/* Array of endpoints expected on the device, NULL terminated. */
    56 const usb_endpoint_description_t *usb_hid_endpoints[] = {
     56usb_endpoint_description_t *usb_hid_endpoints[] = {
    5757        &usb_hid_kbd_poll_endpoint_description,
    5858        &usb_hid_mouse_poll_endpoint_description,
     
    6161};
    6262
     63static const int USB_HID_MAX_SUBDRIVERS = 10;
     64
    6365/*----------------------------------------------------------------------------*/
    6466
    6567static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev)
    6668{
    67         assert(hid_dev != NULL);
    68         assert(hid_dev->subdriver_count == 0);
    69 
    70         hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t));
     69        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
     70
     71        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
     72            sizeof(usb_hid_subdriver_t));
    7173        if (hid_dev->subdrivers == NULL) {
    7274                return ENOMEM;
    7375        }
    74         hid_dev->subdriver_count = 1;
    75         // TODO 0 should be keyboard, but find a better way
    76         hid_dev->subdrivers[0] = usb_hid_subdrivers[0].subdriver;
     76
     77        assert(hid_dev->subdriver_count >= 0);
     78
     79        // set the init callback
     80        hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_kbd_init;
     81
     82        // set the polling callback
     83        hid_dev->subdrivers[hid_dev->subdriver_count].poll =
     84            usb_kbd_polling_callback;
     85
     86        // set the polling ended callback
     87        hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
     88
     89        // set the deinit callback
     90        hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_kbd_deinit;
     91
     92        // set subdriver count
     93        ++hid_dev->subdriver_count;
    7794
    7895        return EOK;
     
    83100static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev)
    84101{
    85         assert(hid_dev != NULL);
    86         assert(hid_dev->subdriver_count == 0);
    87 
    88         hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t));
     102        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
     103
     104        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
     105            sizeof(usb_hid_subdriver_t));
    89106        if (hid_dev->subdrivers == NULL) {
    90107                return ENOMEM;
    91108        }
    92         hid_dev->subdriver_count = 1;
    93         // TODO 2 should be mouse, but find a better way
    94         hid_dev->subdrivers[2] = usb_hid_subdrivers[0].subdriver;
     109
     110        assert(hid_dev->subdriver_count >= 0);
     111
     112        // set the init callback
     113        hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_mouse_init;
     114
     115        // set the polling callback
     116        hid_dev->subdrivers[hid_dev->subdriver_count].poll =
     117            usb_mouse_polling_callback;
     118
     119        // set the polling ended callback
     120        hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
     121
     122        // set the deinit callback
     123        hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_mouse_deinit;
     124
     125        // set subdriver count
     126        ++hid_dev->subdriver_count;
    95127
    96128        return EOK;
     
    103135        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
    104136
    105         hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t));
     137        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
     138            sizeof(usb_hid_subdriver_t));
    106139        if (hid_dev->subdrivers == NULL) {
    107140                return ENOMEM;
    108141        }
    109         hid_dev->subdriver_count = 1;
    110 
    111         /* Set generic hid subdriver routines */
    112         hid_dev->subdrivers[0].init = usb_generic_hid_init;
    113         hid_dev->subdrivers[0].poll = usb_generic_hid_polling_callback;
    114         hid_dev->subdrivers[0].poll_end = NULL;
    115         hid_dev->subdrivers[0].deinit = usb_generic_hid_deinit;
     142
     143        assert(hid_dev->subdriver_count >= 0);
     144
     145        // set the init callback
     146        hid_dev->subdrivers[hid_dev->subdriver_count].init =
     147            usb_generic_hid_init;
     148
     149        // set the polling callback
     150        hid_dev->subdrivers[hid_dev->subdriver_count].poll =
     151            usb_generic_hid_polling_callback;
     152
     153        // set the polling ended callback
     154        hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
     155
     156        // set the deinit callback
     157        hid_dev->subdrivers[hid_dev->subdriver_count].deinit =
     158            usb_generic_hid_deinit;
     159
     160        // set subdriver count
     161        ++hid_dev->subdriver_count;
    116162
    117163        return EOK;
     
    120166/*----------------------------------------------------------------------------*/
    121167
    122 static bool usb_hid_ids_match(const usb_hid_dev_t *hid_dev,
     168static bool usb_hid_ids_match(usb_hid_dev_t *hid_dev,
    123169    const usb_hid_subdriver_mapping_t *mapping)
    124170{
     
    126172        assert(hid_dev->usb_dev != NULL);
    127173
    128         return (hid_dev->usb_dev->descriptors.device.vendor_id
     174        return (hid_dev->usb_dev->descriptors.device.vendor_id 
    129175            == mapping->vendor_id
    130176            && hid_dev->usb_dev->descriptors.device.product_id
     
    134180/*----------------------------------------------------------------------------*/
    135181
    136 static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev,
     182static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev, 
    137183    const usb_hid_subdriver_mapping_t *mapping)
    138184{
     
    146192        }
    147193        int i = 0;
    148         while (mapping->usage_path[i].usage != 0
     194        while (mapping->usage_path[i].usage != 0 
    149195            || mapping->usage_path[i].usage_page != 0) {
    150                 if (usb_hid_report_path_append_item(usage_path,
    151                     mapping->usage_path[i].usage_page,
     196                if (usb_hid_report_path_append_item(usage_path, 
     197                    mapping->usage_path[i].usage_page, 
    152198                    mapping->usage_path[i].usage) != EOK) {
    153199                        usb_log_debug("Failed to append to usage path.\n");
     
    158204        }
    159205
     206        assert(hid_dev->report != NULL);
     207
    160208        usb_log_debug("Compare flags: %d\n", mapping->compare);
    161209
     
    165213        do {
    166214                usb_log_debug("Trying report id %u\n", report_id);
    167 
     215               
    168216                if (report_id != 0) {
    169217                        usb_hid_report_path_set_report_id(usage_path,
     
    172220
    173221                usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    174                     &hid_dev->report, NULL, usage_path, mapping->compare,
     222                    hid_dev->report,
     223                    NULL, usage_path, mapping->compare,
    175224                    USB_HID_REPORT_TYPE_INPUT);
    176 
     225               
    177226                usb_log_debug("Field: %p\n", field);
    178227
     
    181230                        break;
    182231                }
    183 
     232               
    184233                report_id = usb_hid_get_next_report_id(
    185                     &hid_dev->report, report_id, USB_HID_REPORT_TYPE_INPUT);
     234                    hid_dev->report, report_id,
     235                    USB_HID_REPORT_TYPE_INPUT);
    186236        } while (!matches && report_id != 0);
    187237
     
    193243/*----------------------------------------------------------------------------*/
    194244
    195 static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev,
     245static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev, 
    196246    const usb_hid_subdriver_t **subdrivers, int count)
    197247{
     
    204254        }
    205255
    206         /* +1 for generic hid subdriver */
    207         hid_dev->subdrivers = calloc((count + 1), sizeof(usb_hid_subdriver_t));
     256        // add one generic HID subdriver per device
     257
     258        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) *
     259            sizeof(usb_hid_subdriver_t));
    208260        if (hid_dev->subdrivers == NULL) {
    209261                return ENOMEM;
     
    217269        }
    218270
    219         /* Add one generic HID subdriver per device */
    220271        hid_dev->subdrivers[count].init = usb_generic_hid_init;
    221272        hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback;
     
    256307                        return EINVAL;
    257308                }
    258 
     309               
    259310                ids_matched = false;
    260311                matched = false;
    261 
     312               
    262313                if (mapping->vendor_id >= 0) {
    263314                        assert(mapping->product_id >= 0);
     
    270321                        }
    271322                }
    272 
     323               
    273324                if (mapping->usage_path != NULL) {
    274325                        usb_log_debug("Comparing device against usage path.\n");
     
    281332                        matched = ids_matched;
    282333                }
    283 
     334               
    284335                if (matched) {
    285336                        usb_log_debug("Subdriver matched.\n");
    286337                        subdrivers[count++] = &mapping->subdriver;
    287338                }
    288 
     339               
    289340                mapping = &usb_hid_subdrivers[++i];
    290341        }
    291342
    292         /* We have all subdrivers determined, save them into the hid device */
    293         // TODO Dowe really need this complicated stuff if there is
    294         // max_subdrivers limitation?
     343        // we have all subdrivers determined, save them into the hid device
    295344        return usb_hid_save_subdrivers(hid_dev, subdrivers, count);
    296345}
     
    298347/*----------------------------------------------------------------------------*/
    299348
    300 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, const usb_device_t *dev)
    301 {
    302         assert(hid_dev);
    303         assert(dev);
     349static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
     350{
     351        assert(hid_dev != NULL && dev != NULL);
     352
     353        int rc = EOK;
    304354
    305355        if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) {
     
    318368                usb_log_error("None of supported endpoints found - probably"
    319369                    " not a supported device.\n");
    320                 return ENOTSUP;
    321         }
    322 
    323         return EOK;
     370                rc = ENOTSUP;
     371        }
     372
     373        return rc;
    324374}
    325375
     
    328378static int usb_hid_init_report(usb_hid_dev_t *hid_dev)
    329379{
    330         assert(hid_dev != NULL);
     380        assert(hid_dev != NULL && hid_dev->report != NULL);
    331381
    332382        uint8_t report_id = 0;
     383        size_t size;
     384
    333385        size_t max_size = 0;
    334386
    335387        do {
    336388                usb_log_debug("Getting size of the report.\n");
    337                 const size_t size =
    338                     usb_hid_report_byte_size(&hid_dev->report, report_id,
    339                         USB_HID_REPORT_TYPE_INPUT);
     389                size = usb_hid_report_byte_size(hid_dev->report, report_id,
     390                    USB_HID_REPORT_TYPE_INPUT);
    340391                usb_log_debug("Report ID: %u, size: %zu\n", report_id, size);
    341392                max_size = (size > max_size) ? size : max_size;
    342393                usb_log_debug("Getting next report ID\n");
    343                 report_id = usb_hid_get_next_report_id(&hid_dev->report,
     394                report_id = usb_hid_get_next_report_id(hid_dev->report,
    344395                    report_id, USB_HID_REPORT_TYPE_INPUT);
    345396        } while (report_id != 0);
     
    347398        usb_log_debug("Max size of input report: %zu\n", max_size);
    348399
     400        hid_dev->max_input_report_size = max_size;
    349401        assert(hid_dev->input_report == NULL);
    350402
    351         hid_dev->input_report = calloc(1, max_size);
     403        hid_dev->input_report = malloc(max_size);
    352404        if (hid_dev->input_report == NULL) {
    353405                return ENOMEM;
    354406        }
    355         hid_dev->max_input_report_size = max_size;
     407        memset(hid_dev->input_report, 0, max_size);
    356408
    357409        return EOK;
     
    378430        }
    379431
    380         usb_hid_report_init(&hid_dev->report);
     432        hid_dev->report = (usb_hid_report_t *)(malloc(sizeof(
     433            usb_hid_report_t)));
     434        if (hid_dev->report == NULL) {
     435                usb_log_error("No memory!\n");
     436                return ENOMEM;
     437        }
     438        usb_hid_report_init(hid_dev->report);
    381439
    382440        /* The USB device should already be initialized, save it in structure */
     
    388446                return rc;
    389447        }
    390 
     448               
    391449        /* Get the report descriptor and parse it. */
    392         rc = usb_hid_process_report_descriptor(hid_dev->usb_dev,
    393             &hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size);
     450        rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 
     451            hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size);
    394452
    395453        bool fallback = false;
     
    430488                        break;
    431489                default:
    432                         assert(hid_dev->poll_pipe_index
     490                        assert(hid_dev->poll_pipe_index 
    433491                            == USB_HID_GENERIC_POLL_EP_NO);
    434 
     492                       
    435493                        usb_log_info("Falling back to generic HID driver.\n");
    436494                        rc = usb_hid_set_generic_hid_subdriver(hid_dev);
     
    441499                usb_log_error("No subdriver for handling this device could be"
    442500                    " initialized: %s.\n", str_error(rc));
    443                 usb_log_debug("Subdriver count: %d\n",
     501                usb_log_debug("Subdriver count: %d\n", 
    444502                    hid_dev->subdriver_count);
     503               
    445504        } else {
    446505                bool ok = false;
    447 
    448                 usb_log_debug("Subdriver count: %d\n",
     506               
     507                usb_log_debug("Subdriver count: %d\n", 
    449508                    hid_dev->subdriver_count);
    450 
     509               
    451510                for (i = 0; i < hid_dev->subdriver_count; ++i) {
    452511                        if (hid_dev->subdrivers[i].init != NULL) {
     
    465524                        }
    466525                }
    467 
     526               
    468527                rc = (ok) ? EOK : -1;   // what error to report
    469528        }
     
    479538        }
    480539
     540
    481541        return rc;
    482542}
     
    484544/*----------------------------------------------------------------------------*/
    485545
    486 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
     546bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 
    487547    size_t buffer_size, void *arg)
    488548{
     549        int i;
     550
    489551        if (dev == NULL || arg == NULL || buffer == NULL) {
    490552                usb_log_error("Missing arguments to polling callback.\n");
    491553                return false;
    492554        }
    493         usb_hid_dev_t *hid_dev = arg;
     555
     556        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
    494557
    495558        assert(hid_dev->input_report != NULL);
    496 
    497559        usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size,
    498560            hid_dev->max_input_report_size,
     
    506568        }
    507569
    508         /* Parse the input report */
    509         const int rc = usb_hid_parse_report(
    510             &hid_dev->report, buffer, buffer_size, &hid_dev->report_id);
     570        // parse the input report
     571
     572        int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size,
     573            &hid_dev->report_id);
     574
    511575        if (rc != EOK) {
    512576                usb_log_warning("Error in usb_hid_parse_report():"
    513577                    "%s\n", str_error(rc));
    514         }
     578        }       
    515579
    516580        bool cont = false;
    517         /* Continue if at least one of the subdrivers want to continue */
    518         for (int i = 0; i < hid_dev->subdriver_count; ++i) {
    519                 if (hid_dev->subdrivers[i].poll != NULL) {
    520                         cont = cont || hid_dev->subdrivers[i].poll(
    521                             hid_dev, hid_dev->subdrivers[i].data);
     581
     582        // continue if at least one of the subdrivers want to continue
     583        for (i = 0; i < hid_dev->subdriver_count; ++i) {
     584                if (hid_dev->subdrivers[i].poll != NULL
     585                    && hid_dev->subdrivers[i].poll(hid_dev,
     586                        hid_dev->subdrivers[i].data)) {
     587                        cont = true;
    522588                }
    523589        }
     
    528594/*----------------------------------------------------------------------------*/
    529595
    530 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg)
    531 {
    532         assert(dev);
    533         assert(arg);
    534 
    535         usb_hid_dev_t *hid_dev = arg;
    536 
    537         for (int i = 0; i < hid_dev->subdriver_count; ++i) {
     596void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason,
     597     void *arg)
     598{
     599        int i;
     600
     601        if (dev == NULL || arg == NULL) {
     602                return;
     603        }
     604
     605        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
     606
     607        for (i = 0; i < hid_dev->subdriver_count; ++i) {
    538608                if (hid_dev->subdrivers[i].poll_end != NULL) {
    539                         hid_dev->subdrivers[i].poll_end(
    540                             hid_dev, hid_dev->subdrivers[i].data, reason);
     609                        hid_dev->subdrivers[i].poll_end(hid_dev,
     610                            hid_dev->subdrivers[i].data, reason);
    541611                }
    542612        }
     
    554624/*----------------------------------------------------------------------------*/
    555625
    556 int usb_hid_report_number(const usb_hid_dev_t *hid_dev)
     626int usb_hid_report_number(usb_hid_dev_t *hid_dev)
    557627{
    558628        return hid_dev->report_nr;
     
    561631/*----------------------------------------------------------------------------*/
    562632
    563 void usb_hid_deinit(usb_hid_dev_t *hid_dev)
    564 {
    565         assert(hid_dev);
    566         assert(hid_dev->subdrivers != NULL || hid_dev->subdriver_count == 0);
    567 
     633void usb_hid_destroy(usb_hid_dev_t *hid_dev)
     634{
     635        int i;
     636
     637        if (hid_dev == NULL) {
     638                return;
     639        }
    568640
    569641        usb_log_debug("Subdrivers: %p, subdriver count: %d\n",
    570642            hid_dev->subdrivers, hid_dev->subdriver_count);
    571643
    572         for (int i = 0; i < hid_dev->subdriver_count; ++i) {
     644        assert(hid_dev->subdrivers != NULL
     645            || hid_dev->subdriver_count == 0);
     646
     647        for (i = 0; i < hid_dev->subdriver_count; ++i) {
    573648                if (hid_dev->subdrivers[i].deinit != NULL) {
    574649                        hid_dev->subdrivers[i].deinit(hid_dev,
     
    582657
    583658        /* Destroy the parser */
    584         usb_hid_report_deinit(&hid_dev->report);
     659        if (hid_dev->report != NULL) {
     660                usb_hid_free_report(hid_dev->report);
     661        }
    585662
    586663}
  • uspace/drv/bus/usb/usbhid/usbhid.h

    r22ceff3a r25696fea  
    119119
    120120        /** HID Report parser. */
    121         usb_hid_report_t report;
     121        usb_hid_report_t *report;
    122122
    123123        uint8_t report_id;
     
    141141};
    142142
    143 extern const usb_endpoint_description_t *usb_hid_endpoints[];
     143extern usb_endpoint_description_t *usb_hid_endpoints[];
    144144
    145145/*----------------------------------------------------------------------------*/
     
    147147int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
    148148
    149 void usb_hid_deinit(usb_hid_dev_t *hid_dev);
     149bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
     150    size_t buffer_size, void *arg);
    150151
    151 bool usb_hid_polling_callback(usb_device_t *dev,
    152     uint8_t *buffer, size_t buffer_size, void *arg);
    153 
    154 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg);
     152void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason,
     153     void *arg);
    155154
    156155void usb_hid_new_report(usb_hid_dev_t *hid_dev);
    157156
    158 int usb_hid_report_number(const usb_hid_dev_t *hid_dev);
     157int usb_hid_report_number(usb_hid_dev_t *hid_dev);
     158
     159void usb_hid_destroy(usb_hid_dev_t *hid_dev);
    159160
    160161#endif /* USB_HID_USBHID_H_ */
  • uspace/drv/bus/usb/usbhub/main.c

    r22ceff3a r25696fea  
    6767
    6868/** Hub endpoints, excluding control endpoint. */
    69 static const usb_endpoint_description_t *usb_hub_endpoints[] = {
     69static usb_endpoint_description_t *usb_hub_endpoints[] = {
    7070        &hub_status_change_endpoint_description,
    7171        NULL,
  • uspace/drv/bus/usb/usbmast/main.c

    r22ceff3a r25696fea  
    7272};
    7373
    74 static const usb_endpoint_description_t *mast_endpoints[] = {
     74usb_endpoint_description_t *mast_endpoints[] = {
    7575        &bulk_in_ep,
    7676        &bulk_out_ep,
  • uspace/drv/bus/usb/usbmouse/init.c

    r22ceff3a r25696fea  
    4444
    4545/** Mouse polling endpoint description for boot protocol subclass. */
    46 const usb_endpoint_description_t poll_endpoint_description = {
     46usb_endpoint_description_t poll_endpoint_description = {
    4747        .transfer_type = USB_TRANSFER_INTERRUPT,
    4848        .direction = USB_DIRECTION_IN,
  • uspace/drv/bus/usb/usbmouse/main.c

    r22ceff3a r25696fea  
    8383};
    8484
    85 static const usb_endpoint_description_t *endpoints[] = {
     85static usb_endpoint_description_t *endpoints[] = {
    8686        &poll_endpoint_description,
    8787        NULL
  • uspace/drv/bus/usb/usbmouse/mouse.c

    r22ceff3a r25696fea  
    124124        mouse->console_sess = NULL;
    125125       
    126         usb_device_deinit(dev);
     126        usb_device_destroy(dev);
    127127}
    128128
  • uspace/drv/bus/usb/usbmouse/mouse.h

    r22ceff3a r25696fea  
    6161} usb_mouse_t;
    6262
    63 extern const usb_endpoint_description_t poll_endpoint_description;
     63extern usb_endpoint_description_t poll_endpoint_description;
    6464
    6565extern int usb_mouse_create(usb_device_t *);
  • uspace/lib/usbdev/include/usb/dev/driver.h

    r22ceff3a r25696fea  
    156156\endcode
    157157         */
    158         const usb_endpoint_description_t **endpoints;
     158        usb_endpoint_description_t **endpoints;
    159159        /** Driver ops. */
    160160        const usb_driver_ops_t *ops;
     
    164164
    165165int usb_device_select_interface(usb_device_t *, uint8_t,
    166     const usb_endpoint_description_t **);
     166    usb_endpoint_description_t **);
    167167
    168168int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *);
    169169int usb_device_create_pipes(const ddf_dev_t *, usb_device_connection_t *,
    170     const usb_endpoint_description_t **, const uint8_t *, size_t, int, int,
     170    usb_endpoint_description_t **, const uint8_t *, size_t, int, int,
    171171    usb_endpoint_mapping_t **, size_t *);
    172172int usb_device_destroy_pipes(const ddf_dev_t *, usb_endpoint_mapping_t *, size_t);
    173 int usb_device_create(ddf_dev_t *, const usb_endpoint_description_t **,
    174     usb_device_t **, const char **);
    175 void usb_device_deinit(usb_device_t *);
     173int usb_device_create(ddf_dev_t *, usb_endpoint_description_t **, usb_device_t **, const char **);
     174void usb_device_destroy(usb_device_t *);
    176175void * usb_device_data_alloc(usb_device_t *, size_t);
    177176
  • uspace/lib/usbdev/src/devdrv.c

    r22ceff3a r25696fea  
    8181 * @return Number of pipes (excluding default control pipe).
    8282 */
    83 static size_t count_other_pipes(const usb_endpoint_description_t **endpoints)
     83static size_t count_other_pipes(usb_endpoint_description_t **endpoints)
    8484{
    8585        size_t count = 0;
     
    101101 * @return Error code.
    102102 */
    103 static int initialize_other_pipes(const usb_endpoint_description_t **endpoints,
     103static int initialize_other_pipes(usb_endpoint_description_t **endpoints,
    104104    usb_device_t *dev, int alternate_setting)
    105105{
     
    154154        rc = driver->ops->device_add(dev);
    155155        if (rc != EOK)
    156                 usb_device_deinit(dev);
     156                usb_device_destroy(dev);
    157157        return rc;
    158158}
     
    191191        const int ret = driver->ops->device_gone(usb_dev);
    192192        if (ret == EOK)
    193                 usb_device_deinit(usb_dev);
     193                usb_device_destroy(usb_dev);
    194194
    195195        return ret;
     
    238238 */
    239239int usb_device_select_interface(usb_device_t *dev, uint8_t alternate_setting,
    240     const usb_endpoint_description_t **endpoints)
     240    usb_endpoint_description_t **endpoints)
    241241{
    242242        if (dev->interface_no < 0) {
     
    321321 */
    322322int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire,
    323     const usb_endpoint_description_t **endpoints,
     323    usb_endpoint_description_t **endpoints,
    324324    const uint8_t *config_descr, size_t config_descr_size,
    325325    int interface_no, int interface_setting,
     
    526526 */
    527527int usb_device_create(ddf_dev_t *ddf_dev,
    528     const usb_endpoint_description_t **endpoints,
     528    usb_endpoint_description_t **endpoints,
    529529    usb_device_t **dev_ptr, const char **errstr_ptr)
    530530{
     
    590590/** Destroy instance of a USB device.
    591591 *
    592  * @param dev Device to be de-initialized.
    593  *
    594  * Does not free/destroy supplied pointer.
    595  */
    596 void usb_device_deinit(usb_device_t *dev)
     592 * @param dev Device to be destroyed.
     593 */
     594void usb_device_destroy(usb_device_t *dev)
    597595{
    598596        if (dev == NULL) {
  • uspace/lib/usbhid/include/usb/hid/hiddescriptor.h

    r22ceff3a r25696fea  
    4242#include <usb/hid/hidtypes.h>
    4343
    44 int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
     44int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 
    4545                const uint8_t *data, size_t size);
     46
     47void usb_hid_free_report(usb_hid_report_t *report);
    4648
    4749void usb_hid_descriptor_print(usb_hid_report_t *report);
    4850
    4951int usb_hid_report_init(usb_hid_report_t *report);
    50 
    51 void usb_hid_report_deinit(usb_hid_report_t *report);
    5252
    5353int usb_hid_report_append_fields(usb_hid_report_t *report,
  • uspace/lib/usbhid/src/hiddescriptor.c

    r22ceff3a r25696fea  
    10161016 * @return void
    10171017 */
    1018 void usb_hid_report_deinit(usb_hid_report_t *report)
     1018void usb_hid_free_report(usb_hid_report_t *report)
    10191019{
    10201020        if(report == NULL){
Note: See TracChangeset for help on using the changeset viewer.