Changes in / [beee81a:bc02b83] in mainline


Ignore:
Files:
2 added
3 deleted
24 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/ddi/irq.h

    rbeee81a rbc02b83  
    7777         */
    7878        CMD_PIO_WRITE_A_32,
    79        
     79
     80        /** Read 1 byte from the memory space. */
     81        CMD_MEM_READ_8,
     82        /** Read 2 bytes from the memory space. */
     83        CMD_MEM_READ_16,
     84        /** Read 4 bytes from the memory space. */
     85        CMD_MEM_READ_32,
     86
     87        /** Write 1 byte to the memory space. */
     88        CMD_MEM_WRITE_8,
     89        /** Write 2 bytes to the memory space. */
     90        CMD_MEM_WRITE_16,
     91        /** Write 4 bytes to the memory space. */
     92        CMD_MEM_WRITE_32,
     93
     94        /** Write 1 byte from the source argument to the memory space. */
     95        CMD_MEM_WRITE_A_8,
     96        /** Write 2 bytes from the source argument to the memory space. */
     97        CMD_MEM_WRITE_A_16,
     98        /** Write 4 bytes from the source argument to the memory space. */
     99        CMD_MEM_WRITE_A_32,
     100
    80101        /**
    81102         * Perform a bit masking on the source argument
     
    203224        /** Notification configuration structure. */
    204225        ipc_notif_cfg_t notif_cfg;
     226
     227        as_t *driver_as;
    205228} irq_t;
    206229
  • kernel/generic/src/ipc/irq.c

    rbeee81a rbc02b83  
    174174        irq->notif_cfg.code = code;
    175175        irq->notif_cfg.counter = 0;
     176        irq->driver_as = AS;
    176177       
    177178        /*
     
    364365                return IRQ_DECLINE;
    365366       
     367#define CMD_MEM_READ(target) \
     368do { \
     369        void *va = code->cmds[i].addr; \
     370        if (AS != irq->driver_as) \
     371                as_switch(AS, irq->driver_as); \
     372        printf("Copying data from address: %p.\n", va); \
     373        memcpy_from_uspace(&target, va, (sizeof(target))); \
     374        if (dstarg) \
     375                scratch[dstarg] = target; \
     376} while(0)
     377
     378#define CMD_MEM_WRITE(val) \
     379do { \
     380        void *va = code->cmds[i].addr; \
     381        if (AS != irq->driver_as) \
     382                as_switch(AS, irq->driver_as); \
     383        printf("Writing data to address: %p.\n", va); \
     384        memcpy_to_uspace(va, &val, sizeof(val)); \
     385} while (0)
     386
     387        as_t *current_as = AS;
    366388        size_t i;
    367389        for (i = 0; i < code->cmdcount; i++) {
     
    422444                        }
    423445                        break;
     446                case CMD_MEM_READ_8: {
     447                        uint8_t val;
     448                        CMD_MEM_READ(val);
     449                        break;
     450                        }
     451                case CMD_MEM_READ_16: {
     452                        uint16_t val;
     453                        CMD_MEM_READ(val);
     454                        break;
     455                        }
     456                case CMD_MEM_READ_32: {
     457                        uint32_t val;
     458                        CMD_MEM_READ(val);
     459                        printf("mem READ value: %x.\n", val);
     460                        break;
     461                        }
     462                case CMD_MEM_WRITE_8: {
     463                        uint8_t val = code->cmds[i].value;
     464                        CMD_MEM_WRITE(val);
     465                        break;
     466                        }
     467                case CMD_MEM_WRITE_16: {
     468                        uint16_t val = code->cmds[i].value;
     469                        CMD_MEM_WRITE(val);
     470                        break;
     471                        }
     472                case CMD_MEM_WRITE_32: {
     473                        uint32_t val = code->cmds[i].value;
     474                        CMD_MEM_WRITE(val);
     475                        break;
     476                        }
     477                case CMD_MEM_WRITE_A_8:
     478                        if (srcarg) {
     479                                uint8_t val = scratch[srcarg];
     480                                CMD_MEM_WRITE(val);
     481                        }
     482                        break;
     483                case CMD_MEM_WRITE_A_16:
     484                        if (srcarg) {
     485                                uint16_t val = scratch[srcarg];
     486                                CMD_MEM_WRITE(val);
     487                        }
     488                        break;
     489                case CMD_MEM_WRITE_A_32:
     490                        if (srcarg) {
     491                                uint32_t val = scratch[srcarg];
     492                                CMD_MEM_WRITE(val);
     493                        }
     494                        break;
    424495                case CMD_BTEST:
    425496                        if ((srcarg) && (dstarg)) {
     
    435506                        break;
    436507                case CMD_ACCEPT:
     508                        if (AS != current_as)
     509                                as_switch(AS, current_as);
    437510                        return IRQ_ACCEPT;
    438511                case CMD_DECLINE:
    439512                default:
     513                        if (AS != current_as)
     514                                as_switch(AS, current_as);
    440515                        return IRQ_DECLINE;
    441516                }
    442517        }
     518        if (AS != current_as)
     519                as_switch(AS, current_as);
    443520       
    444521        return IRQ_DECLINE;
  • uspace/drv/ehci-hcd/ehci-hcd.ma

    rbeee81a rbc02b83  
    2210 pci/ven=1002&dev=4386
    3310 pci/ven=1002&dev=4396
     410 pci/ven=1002&dev=4373
    4510 pci/ven=1022&dev=7463
    5610 pci/ven=1022&dev=7808
  • uspace/drv/ehci-hcd/pci.c

    rbeee81a rbc02b83  
    186186        CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) to read PCI config space.\n",
    187187            ret);
    188         usb_log_info("Register space BAR at %p:%" PRIxn ".\n", (void *) address, value);
     188        usb_log_info("Register space BAR at %p:%" PRIxn ".\n",
     189            (void *) address, value);
    189190
    190191        /* clear lower byte, it's not part of the BASE address */
  • uspace/drv/ohci/hc.c

    rbeee81a rbc02b83  
    4545#include "hcd_endpoint.h"
    4646
     47#define OHCI_USED_INTERRUPTS \
     48    (I_SO | I_WDH | I_UE | I_RHSC)
    4749static int interrupt_emulator(hc_t *instance);
    4850static void hc_gain_control(hc_t *instance);
     
    285287{
    286288        assert(instance);
    287         if ((status & ~IS_SF) == 0) /* ignore sof status */
     289        usb_log_debug("OHCI interrupt: %x.\n", status);
     290        if ((status & ~I_SF) == 0) /* ignore sof status */
    288291                return;
    289         if (status & IS_RHSC)
     292        if (status & I_RHSC)
    290293                rh_interrupt(&instance->rh);
    291294
    292         usb_log_debug("OHCI interrupt: %x.\n", status);
    293 
    294         if (status & IS_WDH) {
     295
     296        if (status & I_WDH) {
    295297                fibril_mutex_lock(&instance->guard);
    296298                usb_log_debug2("HCCA: %p-%#" PRIx32 " (%p).\n", instance->hcca,
     
    332334{
    333335        assert(instance);
     336        usb_log_debug("Requesting OHCI control.\n");
    334337        /* Turn off legacy emulation */
    335338        volatile uint32_t *ohci_emulation_reg =
     
    337340        usb_log_debug("OHCI legacy register %p: %x.\n",
    338341                ohci_emulation_reg, *ohci_emulation_reg);
    339         *ohci_emulation_reg = 0;
     342        *ohci_emulation_reg &= ~0x1;
    340343
    341344        /* Interrupt routing enabled => smm driver is active */
     
    421424            instance->registers->control);
    422425
    423         /* Disable interrupts */
    424         instance->registers->interrupt_disable = I_SF | I_OC;
    425         usb_log_debug2("Disabling interrupts: %x.\n",
    426             instance->registers->interrupt_disable);
    427         instance->registers->interrupt_disable = I_MI;
     426        /* Enable interrupts */
     427        instance->registers->interrupt_enable = OHCI_USED_INTERRUPTS;
    428428        usb_log_debug2("Enabled interrupts: %x.\n",
    429429            instance->registers->interrupt_enable);
     430        instance->registers->interrupt_enable = I_MI;
    430431
    431432        /* Set periodic start to 90% */
     
    492493            instance->lists[USB_TRANSFER_INTERRUPT].list_head_pa);
    493494
     495        /* Init interrupt code */
     496        instance->interrupt_code.cmds = instance->interrupt_commands;
     497        {
     498                /* Read status register */
     499                instance->interrupt_commands[0].cmd = CMD_MEM_READ_32;
     500                instance->interrupt_commands[0].dstarg = 1;
     501                instance->interrupt_commands[0].addr =
     502                    (void*)&instance->registers->interrupt_status;
     503
     504                /* Test whether we are the interrupt cause */
     505                instance->interrupt_commands[1].cmd = CMD_BTEST;
     506                instance->interrupt_commands[1].value =
     507                    OHCI_USED_INTERRUPTS;
     508                instance->interrupt_commands[1].srcarg = 1;
     509                instance->interrupt_commands[1].dstarg = 2;
     510
     511                /* Predicate cleaning and accepting */
     512                instance->interrupt_commands[2].cmd = CMD_PREDICATE;
     513                instance->interrupt_commands[2].value = 2;
     514                instance->interrupt_commands[2].srcarg = 2;
     515
     516                /* Write clean status register */
     517                instance->interrupt_commands[3].cmd = CMD_MEM_WRITE_A_32;
     518                instance->interrupt_commands[3].srcarg = 1;
     519                instance->interrupt_commands[3].addr =
     520                    (void*)&instance->registers->interrupt_status;
     521
     522                /* Accept interrupt */
     523                instance->interrupt_commands[4].cmd = CMD_ACCEPT;
     524
     525                instance->interrupt_code.cmdcount = OHCI_NEEDED_IRQ_COMMANDS;
     526        }
     527
    494528        return EOK;
    495529}
  • uspace/drv/ohci/hc.h

    rbeee81a rbc02b83  
    5151#include "hw_struct/hcca.h"
    5252
     53#define OHCI_NEEDED_IRQ_COMMANDS 5
     54
    5355typedef struct hc {
    5456        ohci_regs_t *registers;
     
    6567        fid_t interrupt_emulator;
    6668        fibril_mutex_t guard;
     69
     70        /** Code to be executed in kernel interrupt handler */
     71        irq_code_t interrupt_code;
     72
     73        /** Commands that form interrupt code */
     74        irq_cmd_t interrupt_commands[OHCI_NEEDED_IRQ_COMMANDS];
    6775} hc_t;
    6876
  • uspace/drv/ohci/ohci.c

    rbeee81a rbc02b83  
    202202
    203203        /* It does no harm if we register this on polling */
    204         ret = register_interrupt_handler(device, irq, irq_handler, NULL);
     204        ret = register_interrupt_handler(device, irq, irq_handler,
     205            &instance->hc.interrupt_code);
    205206        CHECK_RET_FINI_RETURN(ret,
    206207            "Failed(%d) to register interrupt handler.\n", ret);
  • uspace/drv/ohci/ohci.ma

    rbeee81a rbc02b83  
    1110 pci/ven=106b&dev=003f
    2210 pci/ven=10de&dev=0aa5
    3 10 pci/ven=10de&dev=0aa5
     3
     410 pci/ven=1002&dev=4374
     510 pci/ven=1002&dev=4375
     6
     710 pci/ven=1002&dev=4387
     810 pci/ven=1002&dev=4388
     910 pci/ven=1002&dev=4389
     1010 pci/ven=1002&dev=438a
     1110 pci/ven=1002&dev=438b
  • uspace/drv/ohci/ohci_regs.h

    rbeee81a rbc02b83  
    7272#define CS_SOC_SHIFT (16)
    7373
     74        /** Interupt enable/disable/status,
     75         * reads give the same value,
     76         * writing causes enable/disable,
     77         * status is write-clean (writing 1 clears the bit*/
    7478        volatile uint32_t interrupt_status;
    75 #define IS_SO   (1 << 0)  /* Scheduling overrun */
    76 #define IS_WDH  (1 << 1)  /* Write-back done head */
    77 #define IS_SF   (1 << 2)  /* Start of frame */
    78 #define IS_RD   (1 << 3)  /* Resume detected */
    79 #define IS_UE   (1 << 4)  /* Unrecoverable error */
    80 #define IS_FNO  (1 << 5)  /* Frame number overflow */
    81 #define IS_RHSC (1 << 6)  /* Root hub status change */
    82 #define IS_OC   (1 << 30) /* Ownership change */
    83 
    84         /** Interupt enable/disable, reads give the same value, writing causes
    85          * enable/disable */
    8679        volatile uint32_t interrupt_enable;
    8780        volatile uint32_t interrupt_disable;
  • uspace/drv/ohci/pci.c

    rbeee81a rbc02b83  
    4646
    4747#include "pci.h"
    48 
    49 #define PAGE_SIZE_MASK 0xfffff000
    50 
    51 #define HCC_PARAMS_OFFSET 0x8
    52 #define HCC_PARAMS_EECP_MASK 0xff
    53 #define HCC_PARAMS_EECP_OFFSET 8
    54 
    55 #define CMD_OFFSET 0x0
    56 #define CONFIGFLAG_OFFSET 0x40
    57 
    58 #define USBCMD_RUN 1
    59 
    60 #define USBLEGSUP_OFFSET 0
    61 #define USBLEGSUP_BIOS_CONTROL (1 << 16)
    62 #define USBLEGSUP_OS_CONTROL (1 << 24)
    63 #define USBLEGCTLSTS_OFFSET 4
    64 
    65 #define DEFAULT_WAIT 10000
    66 #define WAIT_STEP 10
    6748
    6849/** Get address of registers and IRQ for given device.
     
    146127int pci_enable_interrupts(ddf_dev_t *device)
    147128{
    148         return ENOTSUP;
    149129        int parent_phone =
    150130            devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING);
  • uspace/drv/usbhid/generic/hiddev.c

    rbeee81a rbc02b83  
    3939#include <errno.h>
    4040#include <str_error.h>
     41#include <bool.h>
    4142
    4243#include <usbhid_iface.h>
     
    6465    size_t size, size_t *act_size, unsigned int flags);
    6566
     67static int usb_generic_hid_client_connected(ddf_fun_t *fun);
     68
    6669/*----------------------------------------------------------------------------*/
    6770
     
    7275
    7376static ddf_dev_ops_t usb_generic_hid_ops = {
    74         .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface
     77        .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface,
     78        .open = usb_generic_hid_client_connected
    7579};
    7680
     
    104108       
    105109        /*! @todo This should probably be atomic. */
    106         memcpy(buffer, hid_dev->input_report, hid_dev->input_report_size);
    107         *act_size = hid_dev->input_report_size;
     110        if (usb_hid_report_ready()) {
     111                memcpy(buffer, hid_dev->input_report,
     112                    hid_dev->input_report_size);
     113                *act_size = hid_dev->input_report_size;
     114                usb_hid_report_received();
     115        }
    108116       
    109117        // clear the buffer so that it will not be received twice
    110         memset(hid_dev->input_report, 0, hid_dev->input_report_size);
     118        //memset(hid_dev->input_report, 0, hid_dev->input_report_size);
    111119       
     120        // note that we already received this report
     121//      report_received = true;
     122       
     123        return EOK;
     124}
     125
     126/*----------------------------------------------------------------------------*/
     127
     128static int usb_generic_hid_client_connected(ddf_fun_t *fun)
     129{
     130        usb_hid_report_received();
    112131        return EOK;
    113132}
  • uspace/drv/usbhid/kbd/kbddev.c

    rbeee81a rbc02b83  
    255255       
    256256        if (hid_dev == NULL || hid_dev->data == NULL) {
     257                usb_log_debug("default_connection_handler: "
     258                    "Missing parameter.\n");
    257259                async_answer_0(icallid, EINVAL);
    258260                return;
     
    267269
    268270                if (kbd_dev->console_phone != -1) {
     271                        usb_log_debug("default_connection_handler: "
     272                            "console phone already set\n");
    269273                        async_answer_0(icallid, ELIMIT);
    270274                        return;
     
    272276
    273277                kbd_dev->console_phone = callback;
     278               
     279                usb_log_debug("default_connection_handler: OK\n");
    274280                async_answer_0(icallid, EOK);
    275281                return;
    276282        }
    277283       
     284        usb_log_debug("default_connection_handler: Wrong function.\n");
    278285        async_answer_0(icallid, EINVAL);
    279286}
     
    555562                        usb_log_debug2("Key pressed: %d (keycode: %d)\n", key,
    556563                            kbd_dev->keys[i]);
    557                         usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, key);
    558564                        if (!usb_kbd_is_lock(key)) {
    559565                                usb_kbd_repeat_start(kbd_dev, key);
    560566                        }
     567                        usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, key);
    561568                } else {
    562569                        // found, nothing happens
  • uspace/drv/usbhid/mouse/mousedev.c

    rbeee81a rbc02b83  
    4343#include <str_error.h>
    4444#include <ipc/mouse.h>
     45#include <io/console.h>
     46
     47#include <ipc/kbd.h>
     48#include <io/keycode.h>
    4549
    4650#include "mousedev.h"
     
    6165
    6266const char *HID_MOUSE_FUN_NAME = "mouse";
     67const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";
    6368const char *HID_MOUSE_CLASS_NAME = "mouse";
     69const char *HID_MOUSE_WHEEL_CLASS_NAME = "keyboard";
    6470
    6571/** Default idle rate for mouses. */
     
    119125       
    120126        if (hid_dev == NULL || hid_dev->data == NULL) {
     127                usb_log_debug("default_connection_handler: Missing "
     128                    "parameters.\n");
    121129                async_answer_0(icallid, EINVAL);
    122130                return;
     
    127135        usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
    128136       
     137        int *phone = (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0)
     138                     ? &mouse_dev->mouse_phone : &mouse_dev->wheel_phone;
     139       
    129140        if (method == IPC_M_CONNECT_TO_ME) {
    130141                int callback = IPC_GET_ARG5(*icall);
    131142
    132                 if (mouse_dev->console_phone != -1) {
     143                if (*phone != -1) {
     144                        usb_log_debug("default_connection_handler: Console "
     145                            "phone to mouse already set.\n");
    133146                        async_answer_0(icallid, ELIMIT);
     147                        //async_answer_0(icallid, EOK);
    134148                        return;
    135149                }
    136150
    137                 mouse_dev->console_phone = callback;
     151                *phone = callback;
    138152                usb_log_debug("Console phone to mouse set ok (%d).\n", callback);
    139153                async_answer_0(icallid, EOK);
     
    141155        }
    142156
     157        usb_log_debug("default_connection_handler: Invalid function.\n");
    143158        async_answer_0(icallid, EINVAL);
    144159}
     
    152167                return NULL;
    153168        }
    154         mouse->console_phone = -1;
     169        mouse->mouse_phone = -1;
     170        mouse->wheel_phone = -1;
    155171       
    156172        return mouse;
     
    164180       
    165181        // hangup phone to the console
    166         if ((*mouse_dev)->console_phone >= 0) {
    167                 async_hangup((*mouse_dev)->console_phone);
     182        if ((*mouse_dev)->mouse_phone >= 0) {
     183                async_hangup((*mouse_dev)->mouse_phone);
     184        }
     185       
     186        if ((*mouse_dev)->wheel_phone >= 0) {
     187                async_hangup((*mouse_dev)->wheel_phone);
    168188        }
    169189       
     
    174194/*----------------------------------------------------------------------------*/
    175195
    176 static bool usb_mouse_process_boot_report(usb_hid_dev_t *hid_dev,
    177     uint8_t *buffer, size_t buffer_size)
     196static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel)
     197{
     198        console_event_t ev;
     199       
     200        ev.type = KEY_PRESS;
     201        ev.key = (wheel > 0) ? KC_UP : (wheel < 0) ? KC_DOWN : 0;
     202        ev.mods = 0;
     203        ev.c = 0;
     204
     205        if (mouse_dev->wheel_phone < 0) {
     206                usb_log_warning(
     207                    "Connection to console not ready, key discarded.\n");
     208                return;
     209        }
     210       
     211        int count = (wheel < 0) ? -wheel : wheel;
     212        int i;
     213       
     214        for (i = 0; i < count * 3; ++i) {
     215                usb_log_debug2("Sending key %d to the console\n", ev.key);
     216                async_msg_4(mouse_dev->wheel_phone, KBD_EVENT, ev.type,
     217                    ev.key, ev.mods, ev.c);
     218                // send key release right away
     219                async_msg_4(mouse_dev->wheel_phone, KBD_EVENT, KEY_RELEASE,
     220                    ev.key, ev.mods, ev.c);
     221        }
     222}
     223
     224/*----------------------------------------------------------------------------*/
     225
     226static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, uint8_t *buffer,
     227    size_t buffer_size)
    178228{
    179229        usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
     
    182232            usb_debug_str_buffer(buffer, buffer_size, 0));
    183233       
    184         if (mouse_dev->console_phone < 0) {
     234        if (mouse_dev->mouse_phone < 0) {
    185235                usb_log_error(NAME " No console phone.\n");
    186236                return false;   // ??
     
    252302       
    253303        if ((shift_x != 0) || (shift_y != 0)) {
    254                 async_req_2_0(mouse_dev->console_phone,
     304                async_req_2_0(mouse_dev->mouse_phone,
    255305                    MEVENT_MOVE, shift_x, shift_y);
    256306        }
     307       
     308        /*
     309         * Wheel
     310         */
     311        int wheel = 0;
     312       
     313        path = usb_hid_report_path();
     314        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
     315            USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
     316
     317        usb_hid_report_path_set_report_id(path, report_id);
     318       
     319        field = usb_hid_report_get_sibling(
     320            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
     321            USB_HID_REPORT_TYPE_INPUT);
     322
     323        if (field != NULL) {
     324                usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
     325                    field->usage);
     326                wheel = field->value;
     327        }
     328
     329        usb_hid_report_path_free(path);
     330       
     331        // send arrow up for positive direction and arrow down for negative
     332        // direction; three arrows for difference of 1
     333        usb_mouse_send_wheel(mouse_dev, wheel);
     334       
    257335       
    258336        /*
     
    274352                if (mouse_dev->buttons[field->usage - field->usage_minimum] == 0
    275353                    && field->value != 0) {
    276                         async_req_2_0(mouse_dev->console_phone,
     354                        async_req_2_0(mouse_dev->mouse_phone,
    277355                            MEVENT_BUTTON, field->usage, 1);
    278356                        mouse_dev->buttons[field->usage - field->usage_minimum]
     
    281359                    mouse_dev->buttons[field->usage - field->usage_minimum] != 0
    282360                    && field->value == 0) {
    283                        async_req_2_0(mouse_dev->console_phone,
     361                       async_req_2_0(mouse_dev->mouse_phone,
    284362                           MEVENT_BUTTON, field->usage, 0);
    285363                       mouse_dev->buttons[field->usage - field->usage_minimum]
     
    337415        }
    338416       
     417        /*
     418         * Special function for acting as keyboard (wheel)
     419         */
     420        usb_log_debug("Creating DDF function %s...\n",
     421                      HID_MOUSE_WHEEL_FUN_NAME);
     422        fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     423            HID_MOUSE_WHEEL_FUN_NAME);
     424        if (fun == NULL) {
     425                usb_log_error("Could not create DDF function node.\n");
     426                return ENOMEM;
     427        }
     428       
     429        /*
     430         * Store the initialized HID device and HID ops
     431         * to the DDF function.
     432         */
     433        fun->ops = &hid_dev->ops;
     434        fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
     435
     436        rc = ddf_fun_bind(fun);
     437        if (rc != EOK) {
     438                usb_log_error("Could not bind DDF function: %s.\n",
     439                    str_error(rc));
     440                ddf_fun_destroy(fun);
     441                return rc;
     442        }
     443       
     444        usb_log_debug("Adding DDF function to class %s...\n",
     445            HID_MOUSE_WHEEL_CLASS_NAME);
     446        rc = ddf_fun_add_to_class(fun, HID_MOUSE_WHEEL_CLASS_NAME);
     447        if (rc != EOK) {
     448                usb_log_error(
     449                    "Could not add DDF function to class %s: %s.\n",
     450                    HID_MOUSE_WHEEL_CLASS_NAME, str_error(rc));
     451                ddf_fun_destroy(fun);
     452                return rc;
     453        }
     454       
    339455        return EOK;
    340456}
     
    407523        }
    408524       
    409         return usb_mouse_process_boot_report(hid_dev, buffer, buffer_size);
     525        return usb_mouse_process_report(hid_dev, buffer, buffer_size);
    410526}
    411527
  • uspace/drv/usbhid/mouse/mousedev.h

    rbeee81a rbc02b83  
    4848        //suseconds_t poll_interval_us;
    4949        /** IPC phone to console (consumer). */
    50         int console_phone;
     50        int mouse_phone;
     51        int wheel_phone;
    5152       
    5253        int32_t *buttons;
  • uspace/drv/usbhid/subdrivers.c

    rbeee81a rbc02b83  
    3636#include "subdrivers.h"
    3737#include "usb/classes/hidut.h"
     38#include "usb/classes/hidpath.h"
    3839
    3940#include "lgtch-ultrax/lgtch-ultrax.h"
     41#include "mouse/mousedev.h"
    4042
    4143static usb_hid_subdriver_usage_t path_kbd[] = {
    4244        {USB_HIDUT_PAGE_KEYBOARD, 0},
     45        {0, 0}
     46};
     47
     48static usb_hid_subdriver_usage_t path_mouse2[] = {
     49        {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_X},
    4350        {0, 0}
    4451};
     
    7986                }
    8087        },
     88        {
     89                path_mouse2,
     90                -1,
     91                USB_HID_PATH_COMPARE_END
     92                | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     93                -1,
     94                -1,
     95                {
     96                        .init = usb_mouse_init,
     97                        .deinit = usb_mouse_deinit,
     98                        .poll = usb_mouse_polling_callback,
     99                        .poll_end = NULL
     100                }
     101        },
    81102        {NULL, -1, 0, -1, -1, {NULL, NULL, NULL, NULL}}
    82103};
  • uspace/drv/usbhid/usbhid.c

    rbeee81a rbc02b83  
    6363static const int USB_HID_MAX_SUBDRIVERS = 10;
    6464
     65static fibril_local bool report_received;
     66
    6567/*----------------------------------------------------------------------------*/
    6668
     
    412414        }
    413415       
    414         // TODO: remove the mouse hack
    415         if (hid_dev->poll_pipe_index == USB_HID_MOUSE_POLL_EP_NO ||
    416             fallback) {
     416        if (fallback) {
    417417                // fall back to boot protocol
    418418                switch (hid_dev->poll_pipe_index) {
     
    509509                                free(input_old);
    510510                        }
     511                        usb_hid_new_report();
    511512                }
    512513        }
     
    589590/*----------------------------------------------------------------------------*/
    590591
     592void usb_hid_new_report(void)
     593{
     594        report_received = false;
     595}
     596
     597/*----------------------------------------------------------------------------*/
     598
     599void usb_hid_report_received(void)
     600{
     601        report_received = true;
     602}
     603
     604/*----------------------------------------------------------------------------*/
     605
     606bool usb_hid_report_ready(void)
     607{
     608        return !report_received;
     609}
     610
     611/*----------------------------------------------------------------------------*/
     612
    591613void usb_hid_free(usb_hid_dev_t **hid_dev)
    592614{
  • uspace/drv/usbhid/usbhid.h

    rbeee81a rbc02b83  
    4444#include <usb/devdrv.h>
    4545#include <usb/classes/hid.h>
     46#include <bool.h>
    4647
    4748struct usb_hid_dev;
     
    128129//const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev);
    129130
     131void usb_hid_new_report(void);
     132
     133void usb_hid_report_received(void);
     134
     135bool usb_hid_report_ready(void);
     136
    130137void usb_hid_free(usb_hid_dev_t **hid_dev);
    131138
  • uspace/lib/usb/include/usb/classes/hiddescriptor.h

    rbeee81a rbc02b83  
    7878uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size);
    7979
     80usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path);
    8081#endif
    8182/**
  • uspace/lib/usb/include/usb/classes/hidpath.h

    rbeee81a rbc02b83  
    4343 * Description of path of usage pages and usages in report descriptor
    4444 */
    45 #define USB_HID_PATH_COMPARE_STRICT                             0
    46 #define USB_HID_PATH_COMPARE_END                                1
    47 #define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY    4
    48 #define USB_HID_PATH_COMPARE_COLLECTION_ONLY    2 /* porovnava jenom cestu z Kolekci */
     45/** Wanted usage path must be exactly the same as the searched one */
     46#define USB_HID_PATH_COMPARE_STRICT             0
     47/** Wanted usage path must be the suffix in the searched one */
     48#define USB_HID_PATH_COMPARE_END                1
     49/** */
     50#define USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY    2
     51/** Searched usage page must be prefix of the other one */
     52#define USB_HID_PATH_COMPARE_BEGIN              4
     53/** Searched couple of usage page and usage can be anywhere in usage path */
     54#define USB_HID_PATH_COMPARE_ANYWHERE           8
    4955
    5056
  • uspace/lib/usb/include/usb/classes/hidtypes.h

    rbeee81a rbc02b83  
    165165        /** */ 
    166166        link_t link;
     167
     168        int in_delimiter;
    167169} usb_hid_report_item_t;
    168170
  • uspace/lib/usb/src/hiddescriptor.c

    rbeee81a rbc02b83  
    4141#include <assert.h>
    4242
     43
     44#define OUTSIDE_DELIMITER_SET   0
     45#define START_DELIMITER_SET     1
     46#define INSIDE_DELIMITER_SET    2
     47       
    4348/** The new report item flag. Used to determine when the item is completly
    4449 * configured and should be added to the report structure
     
    5661#define USB_HID_UNKNOWN_TAG             -99
    5762
    58 
    59 /**
    60  * Initialize the report descriptor parser structure
    61  *
    62  * @param parser Report descriptor parser structure
    63  * @return Error code
    64  */
    65 int usb_hid_report_init(usb_hid_report_t *report)
    66 {
    67         if(report == NULL) {
    68                 return EINVAL;
    69         }
    70 
    71         memset(report, 0, sizeof(usb_hid_report_t));
    72         list_initialize(&report->reports);
    73         list_initialize(&report->collection_paths);
    74 
    75         report->use_report_ids = 0;
    76     return EOK;   
    77 }
    78 
    79 int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
    80 {
    81         usb_hid_report_field_t *field;
    82         int i;
    83 
    84 
     63usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report, usb_hid_report_path_t *cmp_path)
     64{
    8565        /* find or append current collection path to the list */
    8666        link_t *path_it = report->collection_paths.next;
     
    8969                path = list_get_instance(path_it, usb_hid_report_path_t, link);
    9070               
    91                 if(usb_hid_report_compare_usage_path(path, report_item->usage_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
     71                if(usb_hid_report_compare_usage_path(path, cmp_path, USB_HID_PATH_COMPARE_STRICT) == EOK){
    9272                        break;
    9373                }                       
     
    9575        }
    9676        if(path_it == &report->collection_paths) {
    97                 path = usb_hid_report_path_clone(report_item->usage_path);                     
     77                path = usb_hid_report_path_clone(cmp_path);                     
    9878                list_append(&path->link, &report->collection_paths);                                   
    9979                report->collection_paths_count++;
    100         }
     80
     81                return path;
     82        }
     83        else {
     84                return list_get_instance(path_it, usb_hid_report_path_t, link);
     85        }
     86}
     87
     88/**
     89 * Initialize the report descriptor parser structure
     90 *
     91 * @param parser Report descriptor parser structure
     92 * @return Error code
     93 */
     94int usb_hid_report_init(usb_hid_report_t *report)
     95{
     96        if(report == NULL) {
     97                return EINVAL;
     98        }
     99
     100        memset(report, 0, sizeof(usb_hid_report_t));
     101        list_initialize(&report->reports);
     102        list_initialize(&report->collection_paths);
     103
     104        report->use_report_ids = 0;
     105    return EOK;   
     106}
     107
     108
     109/*
     110 *
     111 *
     112 */
     113int usb_hid_report_append_fields(usb_hid_report_t *report, usb_hid_report_item_t *report_item)
     114{
     115        usb_hid_report_field_t *field;
     116        int i;
    101117
    102118        for(i=0; i<report_item->usages_count; i++){
     
    104120        }
    105121
    106        
     122        usb_hid_report_path_t *path = report_item->usage_path; 
    107123        for(i=0; i<report_item->count; i++){
    108124
     
    112128
    113129                /* fill the attributes */               
    114                 field->collection_path = path;
    115130                field->logical_minimum = report_item->logical_minimum;
    116131                field->logical_maximum = report_item->logical_maximum;
     
    129144                if(report_item->usages_count > 0 && ((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0))) {
    130145                        uint32_t usage;
    131                         if(report_item->type != USB_HID_REPORT_TYPE_OUTPUT) {
    132                                 if(i < report_item->usages_count){
    133                                         usage = report_item->usages[i];
    134                                 }
    135                                 else {
    136                                         usage = report_item->usages[report_item->usages_count - 1];
    137                                 }
     146                        if(i < report_item->usages_count){
     147                                usage = report_item->usages[i];
    138148                        }
    139149                        else {
    140                                 if((report_item->count - i - 1) < report_item->usages_count){
    141                                         usage = report_item->usages[(report_item->count - i - 1)];
    142                                 }
    143                                 else {
    144                                         usage = report_item->usages[report_item->usages_count - 1];
    145                                 }
     150                                usage = report_item->usages[report_item->usages_count - 1];
    146151                        }
    147152
     
    159164
    160165                if((USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) != 0) && (!((report_item->usage_minimum == 0) && (report_item->usage_maximum == 0)))) {
    161                         if(report_item->type == USB_HID_REPORT_TYPE_INPUT) {
    162                                 field->usage = report_item->usage_maximum - i;
    163                         }
    164                         else {
    165                                 field->usage = report_item->usage_minimum + i;                                 
    166                         }
    167 
    168                 }
    169                
     166                        field->usage = report_item->usage_minimum + i;                                 
     167                }
     168               
     169                usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL, field->usage_page);
     170                usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL, field->usage);
     171
     172                field->collection_path = usb_hid_report_path_try_insert(report, path);
     173
    170174                field->size = report_item->size;
    171                 field->offset = report_item->offset + (i * report_item->size);
     175               
     176                size_t offset_byte = (report_item->offset + (i * report_item->size)) / 8;
     177                size_t offset_bit = 8 - ((report_item->offset + (i * report_item->size)) % 8) - report_item->size;
     178
     179                field->offset = 8 * offset_byte + offset_bit;
    172180                if(report_item->id != 0) {
    173181                        field->offset += 8;
     
    264272                return ENOMEM;
    265273        }
     274        usb_hid_report_path_append_item(usage_path, 0, 0);     
    266275       
    267276        while(i<size){ 
     
    349358                                        tmp_usage_path = list_get_instance(report_item->usage_path->link.prev, usb_hid_report_usage_path_t, link);
    350359                                       
    351                                         usb_hid_report_set_last_item(usage_path, tmp_usage_path->usage_page, tmp_usage_path->usage);
     360                                        usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, tmp_usage_path->usage_page);
     361                                        usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, tmp_usage_path->usage);
    352362
    353363                                        usb_hid_report_path_free(report_item->usage_path);
     
    427437int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, size_t item_size,
    428438                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
    429 {               
     439{
     440        usb_hid_report_usage_path_t *path_item;
     441       
    430442        switch(tag)
    431443        {
     
    438450                       
    439451                case USB_HID_REPORT_TAG_COLLECTION:
    440                         // TODO usage_path->flags = *data;
    441                         usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);                                         
     452                        // store collection atributes
     453                        path_item = list_get_instance(usage_path->head.prev, usb_hid_report_usage_path_t, link);
     454                        path_item->flags = *data;       
     455                       
     456                        // set last item
     457                        usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_GLOBAL, report_item->usage_page);
     458                        usb_hid_report_set_last_item(usage_path, USB_HID_TAG_CLASS_LOCAL, report_item->usages[report_item->usages_count-1]);
     459                       
     460                        // append the new one which will be set by common
     461                        // usage/usage page
     462                        usb_hid_report_path_append_item(usage_path, report_item->usage_page, report_item->usages[report_item->usages_count-1]);
    442463                        usb_hid_report_reset_local_items (report_item);
    443464                        return USB_HID_NO_ACTION;
     
    530551                             usb_hid_report_item_t *report_item, usb_hid_report_path_t *usage_path)
    531552{
    532         switch(tag)
    533         {
     553        switch(tag) {
    534554                case USB_HID_REPORT_TAG_USAGE:
    535                         report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size);
    536                         report_item->usages_count++;
     555                        switch(report_item->in_delimiter) {
     556                                case INSIDE_DELIMITER_SET:
     557                                        // nothing to do
     558                                        break;
     559                                case START_DELIMITER_SET:
     560                                        report_item->in_delimiter = INSIDE_DELIMITER_SET;
     561                                case OUTSIDE_DELIMITER_SET:
     562                                        report_item->usages[report_item->usages_count] = usb_hid_report_tag_data_uint32(data,item_size);
     563                                        report_item->usages_count++;
     564                                        break;
     565                        }
    537566                        break;
    538567                case USB_HID_REPORT_TAG_USAGE_MINIMUM:
     
    575604                        break;                 
    576605                case USB_HID_REPORT_TAG_DELIMITER:
    577                         //report_item->delimiter = usb_hid_report_tag_data_uint32(data,item_size);
    578                         //TODO:
    579                         //      DELIMITER STUFF
    580                         break;
    581                
     606                        report_item->in_delimiter = usb_hid_report_tag_data_uint32(data,item_size);
     607                        break;
     608
    582609                default:
    583610                        return USB_HID_NO_ACTION;
    584611        }
    585        
     612
    586613        return EOK;
    587614}
     
    629656
    630657                usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
    631                 usb_log_debug("\t\tSIZE: %zu\n", report_item->size);
     658                usb_log_debug("\t\tSIZE: %zu\n", report_item->size);                           
    632659                usb_log_debug("\t\tLOGMIN: %d\n", report_item->logical_minimum);
    633660                usb_log_debug("\t\tLOGMAX: %d\n", report_item->logical_maximum);               
     
    640667                usb_log_debug("\t\ttUSAGE: %X\n", report_item->usage);
    641668                usb_log_debug("\t\tUSAGE PAGE: %X\n", report_item->usage_page);
    642                                                
    643 //              usb_log_debug("\n");           
     669               
     670                //usb_hid_print_usage_path(report_item->collection_path);
     671
     672                usb_log_debug("\n");           
    644673
    645674        }
     
    666695                usb_log_debug("Report ID: %d\n", report_des->report_id);
    667696                usb_log_debug("\tType: %d\n", report_des->type);
    668                 usb_log_debug("\tLength: %zu\n", report_des->bit_length);
    669                 usb_log_debug("\tItems: %zu\n", report_des->item_length);
     697                usb_log_debug("\tLength: %zu\n", report_des->bit_length);               
     698                usb_log_debug("\tItems: %zu\n", report_des->item_length);               
    670699
    671700                usb_hid_descriptor_print_list(&report_des->report_items);
  • uspace/lib/usb/src/hidparser.c

    rbeee81a rbc02b83  
    405405                                }
    406406
    407                                 size_t shift = offset%8;
     407                                size_t shift = 8 - offset%8 - length;
    408408
    409409                                value = value << shift;                                                 
  • uspace/lib/usb/src/hidpath.c

    rbeee81a rbc02b83  
    149149                usb_log_debug("\tFLAGS: %d\n", path_item->flags);               
    150150               
    151                 item = item->next;
     151                item = item->next;
    152152        }
    153153}
     
    156156 * Compares two usage paths structures
    157157 *
    158  * If USB_HID_PATH_COMPARE_COLLECTION_ONLY flag is given, the last item in report_path structure is forgotten
    159  *
    160  * @param report_path usage path structure to compare
     158 *
     159 * @param report_path usage path structure to compare with @path
    161160 * @param path usage patrh structure to compare
    162161 * @param flags Flags determining the mode of comparison
     
    179178        }
    180179
     180        // Empty path match all others
    181181        if(path->depth == 0){
    182182                return EOK;
     
    189189       
    190190        switch(flags){
    191                 /* path must be completly identical */
     191                /* path is somewhere in report_path */
     192                case USB_HID_PATH_COMPARE_ANYWHERE:
     193                        if(path->depth != 1){
     194                                return 1;
     195                        }
     196
     197                        // projit skrz cestu a kdyz nekde sedi tak vratim EOK
     198                        // dojduli az za konec tak nnesedi
     199                        report_link = report_path->head.next;
     200                        path_link = path->head.next;
     201                        path_item = list_get_instance(path_link, usb_hid_report_usage_path_t, link);
     202
     203                        while(report_link != &report_path->head) {
     204                                report_item = list_get_instance(report_link, usb_hid_report_usage_path_t, link);
     205                                if(report_item->usage_page == path_item->usage_page){
     206                                        if(only_page == 0){
     207                                                if(report_item->usage == path_item->usage) {
     208                                                        return EOK;
     209                                                }
     210                                        }
     211                                        else {
     212                                                return EOK;
     213                                        }
     214                                }
     215
     216                                report_link = report_link->next;
     217                        }
     218
     219                        return 1;
     220                        break;
     221                /* the paths must be identical */
    192222                case USB_HID_PATH_COMPARE_STRICT:
    193223                                if(report_path->depth != path->depth){
    194224                                        return 1;
    195225                                }
    196 
     226               
     227                /* path is prefix of the report_path */
     228                case USB_HID_PATH_COMPARE_BEGIN:
     229       
    197230                                report_link = report_path->head.next;
    198231                                path_link = path->head.next;
     
    221254                                }
    222255
    223                                 if(((report_link == &report_path->head) && (path_link == &path->head)) ||
    224                                    (((flags & USB_HID_PATH_COMPARE_COLLECTION_ONLY) != 0) &&
    225                                     (path_link = &path->head) &&
    226                                     (report_link == report_path->head.prev))) {
     256                                if((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) && (path_link == &path->head)) ||
     257                                   ((report_link == &report_path->head) && (path_link == &path->head))) {
    227258                                        return EOK;
    228259                                }
     
    232263                        break;
    233264
    234                 /* compare with only the end of path*/
     265                /* path is suffix of report_path */
    235266                case USB_HID_PATH_COMPARE_END:
    236267
    237                                 if((flags & USB_HID_PATH_COMPARE_COLLECTION_ONLY) != 0) {
    238                                         report_link = report_path->head.prev->prev;
    239                                 }
    240                                 else {
    241                                         report_link = report_path->head.prev;
    242                                 }
     268                                report_link = report_path->head.prev;
    243269                                path_link = path->head.prev;
    244270
  • uspace/lib/usb/src/host/batch.c

    rbeee81a rbc02b83  
    128128        memcpy(instance->buffer, instance->data_buffer, instance->buffer_size);
    129129
    130         usb_log_debug("Batch %p done (T%d.%d, %s %s in, %zuB): %s (%d).\n",
     130        usb_log_debug("Batch(%p) done (T%d.%d, %s %s in, %zuB): %s (%d).\n",
    131131            instance, instance->ep->address, instance->ep->endpoint,
    132132            usb_str_speed(instance->ep->speed),
    133133            usb_str_transfer_type_short(instance->ep->transfer_type),
    134             instance->transfered_size, str_error(instance->error), instance->error);
     134            instance->transfered_size, str_error(instance->error),
     135            instance->error);
    135136
    136137        instance->callback_in(instance->fun, instance->error,
     
    147148        assert(instance->callback_out);
    148149
    149         usb_log_debug("Batch %p done (T%d.%d, %s %s out): %s (%d).\n",
     150        usb_log_debug("Batch(%p) done (T%d.%d, %s %s out): %s (%d).\n",
    150151            instance, instance->ep->address, instance->ep->endpoint,
    151152            usb_str_speed(instance->ep->speed),
Note: See TracChangeset for help on using the changeset viewer.