Changeset 400735e in mainline for uspace/lib/drv


Ignore:
Timestamp:
2011-05-28T14:30:58Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3fb5a3e
Parents:
e8f826b (diff), 48141f0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge development/ changes

Location:
uspace/lib/drv
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/Makefile

    re8f826b r400735e  
    4040        generic/remote_usb.c \
    4141        generic/remote_pci.c \
    42         generic/remote_usbhc.c
     42        generic/remote_usbhc.c \
     43        generic/remote_usbhid.c
    4344
    4445include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/drv/generic/dev_iface.c

    re8f826b r400735e  
    4646#include "remote_pci.h"
    4747
     48#include <stdio.h>
     49
    4850static iface_dipatch_table_t remote_ifaces = {
    4951        .ifaces = {
     
    6062{
    6163        assert(is_valid_iface_idx(idx));
     64       
    6265        return remote_ifaces.ifaces[idx];
    6366}
  • uspace/lib/drv/generic/driver.c

    re8f826b r400735e  
    405405                                /* The interface has not such method */
    406406                                printf("%s: driver_connection_gen error - "
    407                                     "invalid interface method.", driver->name);
     407                                    "invalid interface method "
     408                                    "(index %" PRIun ").\n",
     409                                    driver->name, iface_method_idx);
    408410                                async_answer_0(callid, ENOTSUP);
    409411                                break;
  • uspace/lib/drv/generic/remote_usbhid.c

    re8f826b r400735e  
    3636#include <errno.h>
    3737#include <assert.h>
     38#include <stdio.h>
    3839
    3940#include "usbhid_iface.h"
     
    4243static void remote_usbhid_get_event_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4344static void remote_usbhid_get_event(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     45static void remote_usbhid_get_report_descriptor_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     46static void remote_usbhid_get_report_descriptor(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4447// static void remote_usbhid_(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4548
     
    4750static remote_iface_func_ptr_t remote_usbhid_iface_ops [] = {
    4851        remote_usbhid_get_event_length,
    49         remote_usbhid_get_event
     52        remote_usbhid_get_event,
     53        remote_usbhid_get_report_descriptor_length,
     54        remote_usbhid_get_report_descriptor
    5055};
    5156
     
    5863};
    5964
    60 usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
     65//usbhc_iface_t *usb_iface = (usbhc_iface_t *) iface;
    6166
    6267
     
    6469    ipc_callid_t callid, ipc_call_t *call)
    6570{
     71        printf("remote_usbhid_get_event_length()\n");
     72       
    6673        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
    6774
    6875        if (!hid_iface->get_event_length) {
    69                 async_answer_0(callid, ENOTSUP);
    70                 return;
    71         }
    72 
    73         int len = hid_iface->get_event_length(fun);
    74         if (len == 0) {
    75                 len = EEMPTY;
    76         }
    77         if (len < 0) {
    78                 async_answer_0(callid, len);
    79         } else {
    80                 async_answer_1(callid, EOK, len);
    81         }
     76                printf("Get event length not set!\n");
     77                async_answer_0(callid, ENOTSUP);
     78                return;
     79        }
     80
     81        size_t len = hid_iface->get_event_length(fun);
     82//      if (len == 0) {
     83//              len = EEMPTY;
     84//      }
     85        async_answer_1(callid, EOK, len);
     86       
     87//      if (len < 0) {
     88//              async_answer_0(callid, len);
     89//      } else {
     90//              async_answer_1(callid, EOK, len);
     91//      }
    8292}
    8393
     
    100110                return;
    101111        }
    102         /* Check that length is even number. Truncate otherwise. */
    103         if ((len % 2) == 1) {
    104                 len--;
    105         }
     112//      /* Check that length is even number. Truncate otherwise. */
     113//      if ((len % 2) == 1) {
     114//              len--;
     115//      }
    106116        if (len == 0) {
    107117                async_answer_0(data_callid, EINVAL);
    108118                async_answer_0(callid, EINVAL);
     119                return;
    109120        }
    110121
    111122        int rc;
    112123
    113         size_t items = len / 2;
    114         uint16_t *usage_pages_and_usages = malloc(sizeof(uint16_t) * len);
    115         if (usage_pages_and_usages == NULL) {
     124        uint8_t *data = malloc(len);
     125        if (data == NULL) {
    116126                async_answer_0(data_callid, ENOMEM);
    117127                async_answer_0(callid, ENOMEM);
    118         }
    119 
    120         size_t act_items;
    121         int rc = hid_iface->get_event(fun, usage_pages_and_usages,
    122             usage_pages_and_usages + items, items, &act_items, flags);
     128                return;
     129        }
     130
     131        size_t act_length;
     132        int event_nr;
     133        rc = hid_iface->get_event(fun, data, len, &act_length, &event_nr, flags);
    123134        if (rc != EOK) {
    124                 free(usage_pages_and_usages);
     135                free(data);
    125136                async_answer_0(data_callid, rc);
    126137                async_answer_0(callid, rc);
    127         }
    128         if (act_items >= items) {
     138                return;
     139        }
     140        if (act_length >= len) {
    129141                /* This shall not happen. */
    130142                // FIXME: how about an assert here?
    131                 act_items = items;
    132         }
    133 
    134         async_data_read_finalize(data_callid, usage_pages_and_usages,
    135             act_items * 2 * sizeof(uint16_t));
    136 
    137         free(usage_pages_and_usages);
    138 
     143                act_length = len;
     144        }
     145
     146        async_data_read_finalize(data_callid, data, act_length);
     147
     148        free(data);
     149
     150        async_answer_1(callid, EOK, event_nr);
     151}
     152
     153void remote_usbhid_get_report_descriptor_length(ddf_fun_t *fun, void *iface,
     154    ipc_callid_t callid, ipc_call_t *call)
     155{
     156        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
     157
     158        if (!hid_iface->get_report_descriptor_length) {
     159                async_answer_0(callid, ENOTSUP);
     160                return;
     161        }
     162
     163        size_t len = hid_iface->get_report_descriptor_length(fun);
     164        async_answer_1(callid, EOK, (sysarg_t) len);
     165}
     166
     167void remote_usbhid_get_report_descriptor(ddf_fun_t *fun, void *iface,
     168    ipc_callid_t callid, ipc_call_t *call)
     169{
     170        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
     171
     172        if (!hid_iface->get_report_descriptor) {
     173                async_answer_0(callid, ENOTSUP);
     174                return;
     175        }
     176
     177        size_t len;
     178        ipc_callid_t data_callid;
     179        if (!async_data_read_receive(&data_callid, &len)) {
     180                async_answer_0(callid, EINVAL);
     181                return;
     182        }
     183
     184        if (len == 0) {
     185                async_answer_0(data_callid, EINVAL);
     186                async_answer_0(callid, EINVAL);
     187                return;
     188        }
     189
     190        uint8_t *descriptor = malloc(len);
     191        if (descriptor == NULL) {
     192                async_answer_0(data_callid, ENOMEM);
     193                async_answer_0(callid, ENOMEM);
     194                return;
     195        }
     196
     197        size_t act_len = 0;
     198        int rc = hid_iface->get_report_descriptor(fun, descriptor, len,
     199            &act_len);
     200        if (act_len > len) {
     201                rc = ELIMIT;
     202        }
     203        if (rc != EOK) {
     204                free(descriptor);
     205                async_answer_0(data_callid, rc);
     206                async_answer_0(callid, rc);
     207                return;
     208        }
     209
     210        async_data_read_finalize(data_callid, descriptor, act_len);
    139211        async_answer_0(callid, EOK);
    140 }
     212
     213        free(descriptor);
     214}
     215
     216
    141217
    142218/**
  • uspace/lib/drv/include/remote_pci.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_PCI_H_
    3737
    38 remote_iface_t remote_pci_iface;
     38extern remote_iface_t remote_pci_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/remote_usb.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_USB_H_
    3737
    38 remote_iface_t remote_usb_iface;
     38extern remote_iface_t remote_usb_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/remote_usbhc.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_USBHC_H_
    3737
    38 remote_iface_t remote_usbhc_iface;
     38extern remote_iface_t remote_usbhc_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/remote_usbhid.h

    re8f826b r400735e  
    3636#define LIBDRV_REMOTE_USBHID_H_
    3737
    38 remote_iface_t remote_usbhid_iface;
     38extern remote_iface_t remote_usbhid_iface;
    3939
    4040#endif
  • uspace/lib/drv/include/usbhid_iface.h

    re8f826b r400735e  
    4545         * Parameters: none
    4646         * Answer:
    47          * - EOK (expected always as long as device support USB HID interface)
    48          * Parameters of the answer:
    49          * - number of items
     47         * - Size of one report in bytes.
    5048         */
    5149        IPC_M_USBHID_GET_EVENT_LENGTH,
     
    6361         * It is okay if the client requests less data. Extra data must
    6462         * be truncated by the driver.
     63         *
     64         * @todo Change this comment.
    6565         */
    66         IPC_M_USBHID_GET_EVENT
     66        IPC_M_USBHID_GET_EVENT,
     67       
     68        /** Get the size of the report descriptor from the HID device.
     69         *
     70         * Parameters:
     71         * - none
     72         * Answer:
     73         * - EOK - method is implemented (expected always)
     74         * Parameters of the answer:
     75         * - Size of the report in bytes.
     76         */
     77        IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH,
     78       
     79        /** Get the report descriptor from the HID device.
     80         *
     81         * Parameters:
     82         * - none
     83         * The call is followed by data read expecting the descriptor itself.
     84         * Answer:
     85         * - EOK - report descriptor returned.
     86         */
     87        IPC_M_USBHID_GET_REPORT_DESCRIPTOR
    6788} usbhid_iface_funcs_t;
    6889
     
    7596         *
    7697         * @param[in] fun DDF function answering the request.
    77          * @return Number of events or error code.
     98         * @return Size of the event in bytes.
    7899         */
    79100        size_t (*get_event_length)(ddf_fun_t *fun);
     
    87108         * @return Error code.
    88109         */
    89         int (*get_event)(ddf_fun_t *fun, int32_t *buffer, size_t size,
    90             size_t *act_size, unsigned int flags);
     110        int (*get_event)(ddf_fun_t *fun, uint8_t *buffer, size_t size,
     111            size_t *act_size, int *event_nr, unsigned int flags);
     112       
     113        /** Get size of the report descriptor in bytes.
     114         *
     115         * @param[in] fun DDF function answering the request.
     116         * @return Size of the report descriptor in bytes.
     117         */
     118        size_t (*get_report_descriptor_length)(ddf_fun_t *fun);
     119       
     120        /** Get the report descriptor from the HID device.
     121         *
     122         * @param[in] fun DDF function answering the request.
     123         * @param[out] desc Buffer with the report descriptor.
     124         * @param[in] size Size of the allocated @p desc buffer.
     125         * @param[out] act_size Actual size of the report descriptor returned.
     126         * @return Error code.
     127         */
     128        int (*get_report_descriptor)(ddf_fun_t *fun, uint8_t *desc,
     129            size_t size, size_t *act_size);
    91130} usbhid_iface_t;
    92131
Note: See TracChangeset for help on using the changeset viewer.