Changeset 4687fcd4 in mainline for uspace/drv


Ignore:
Timestamp:
2011-01-29T10:19:04Z (15 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
72e19f50
Parents:
67a1b78 (diff), a09128c (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:

Changes from devel, break stuff.

Location:
uspace/drv
Files:
5 added
11 edited
7 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/Makefile

    r67a1b78 r4687fcd4  
    4141        transfer_list.c \
    4242        uhci.c \
    43         uhci_struct/transfer_descriptor.c
     43        uhci_struct/transfer_descriptor.c \
     44        pci.c
    4445
    4546include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/uhci/main.c

    r67a1b78 r4687fcd4  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28#include <driver.h>
     29#include <errno.h>
     30#include <str_error.h>
    2831#include <usb_iface.h>
    29 #include <errno.h>
    3032
    3133#include "debug.h"
     
    5759        device->ops = &uhci_ops;
    5860
    59         // TODO: get this value out of pci driver
    60         return uhci_init(device, (void*)0xc020);
     61        uintptr_t io_reg_base;
     62        size_t io_reg_size;
     63        int irq;
     64
     65        int rc = pci_get_my_registers(device,
     66            &io_reg_base, &io_reg_size, &irq);
     67
     68        if (rc != EOK) {
     69                uhci_print_fatal("failed to get I/O registers addresses: %s.\n",
     70                    str_error(rc));
     71                return rc;
     72        }
     73
     74        uhci_print_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
     75            io_reg_base, io_reg_size, irq);
     76
     77        return uhci_init(device, (void*)io_reg_base, io_reg_size);
    6178}
    6279
  • uspace/drv/uhci/uhci.c

    r67a1b78 r4687fcd4  
    1313static int uhci_debug_checker(void *arg);
    1414
    15 int uhci_init(device_t *device, void *regs)
     15int uhci_init(device_t *device, void *regs, size_t reg_size)
    1616{
    1717        assert(device);
     
    4040        /* allow access to hc control registers */
    4141        regs_t *io;
    42         ret = pio_enable(regs, sizeof(regs_t), (void**)&io);
     42        assert(reg_size >= sizeof(regs_t));
     43        ret = pio_enable(regs, reg_size, (void**)&io);
    4344        CHECK_RET_FREE_INSTANCE("Failed to gain access to registers at %p.\n", io);
    4445        instance->registers = io;
  • uspace/drv/uhci/uhci.h

    r67a1b78 r4687fcd4  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 /** @addtogroup usb
     28
     29/** @addtogroup drvusbuhci
    2930 * @{
    3031 */
     
    8687
    8788/* init uhci specifics in device.driver_data */
    88 int uhci_init( device_t *device, void *regs );
     89int uhci_init( device_t *device, void *regs, size_t reg_size );
    8990
    9091int uhci_destroy( device_t *device );
     
    101102  void *arg );
    102103
     104int pci_get_my_registers(device_t *, uintptr_t *, size_t *, int *);
     105
    103106#endif
    104107/**
  • uspace/drv/usbhid/Makefile

    r67a1b78 r4687fcd4  
    11#
    2 # Copyright (c) 2010 Vojtech Horky
     2# Copyright (c) 2010-2011 Vojtech Horky
    33# All rights reserved.
    44#
     
    2929USPACE_PREFIX = ../..
    3030LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a
    31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include
    32 BINARY = usbkbd
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I.
     32BINARY = usbhid
     33
     34STOLEN_LAYOUT_SOURCES = \
     35        layout/us_qwerty.c \
     36        layout/us_dvorak.c \
     37        layout/cz.c
    3338
    3439SOURCES = \
    3540        main.c \
    3641        descparser.c \
    37         descdump.c
     42        descdump.c \
     43        conv.c \
     44        $(STOLEN_LAYOUT_SOURCES)
     45
     46EXTRA_CLEAN = $(STOLEN_LAYOUT_SOURCES)
     47
     48SRV_KBD = $(USPACE_PREFIX)/srv/hid/kbd
    3849
    3950include $(USPACE_PREFIX)/Makefile.common
     51
     52layout/%.c: $(SRV_KBD)/layout/%.c
     53        ln -sfn ../$< $@
  • uspace/drv/usbhid/descdump.c

    r67a1b78 r4687fcd4  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/** @addtogroup drvusbhid
    2930 * @{
     31 */
     32/** @file
     33 * Descriptor dumping.
    3034 */
    3135
  • uspace/drv/usbhid/descdump.h

    r67a1b78 r4687fcd4  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/** @addtogroup drvusbhid
    2930 * @{
    3031 */
     32/** @file
     33 * Descriptor dumping.
     34 */
     35
    3136#ifndef USBHID_DESCDUMP_H_
    3237#define USBHID_DESCDUMP_H_
  • uspace/drv/usbhid/descparser.c

    r67a1b78 r4687fcd4  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/** @addtogroup drvusbhid
    2930 * @{
     31 */
     32/** @file
     33 * Descriptor parser.
    3034 */
    3135
  • uspace/drv/usbhid/descparser.h

    r67a1b78 r4687fcd4  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/** @addtogroup drvusbhid
    2930 * @{
     31 */
     32/** @file
     33 * Descriptor parser.
    3034 */
    3135
  • uspace/drv/usbhid/main.c

    r67a1b78 r4687fcd4  
    11/*
    22 * Copyright (c) 2010 Vojtech Horky
     3 * Copyright (c) 2011 Lubos Slovak
    34 * All rights reserved.
    45 *
     
    2627 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2728 */
     29
    2830/** @addtogroup drvusbhid
    2931 * @{
    3032 */
     33/**
     34 * @file
     35 * Main routines of USB HID driver.
     36 */
     37
    3138#include <usb/usbdrv.h>
    3239#include <driver.h>
     
    4148#include <usb/devreq.h>
    4249#include <usb/descriptor.h>
     50#include <io/console.h>
    4351#include "descparser.h"
    4452#include "descdump.h"
     53#include "conv.h"
     54#include "layout.h"
    4555
    4656#define BUFFER_SIZE 32
    47 #define NAME "usbkbd"
     57#define NAME "usbhid"
    4858
    4959#define GUESSED_POLL_ENDPOINT 1
     
    91101
    92102/*
     103 * TODO: Move somewhere else
     104 */
     105/*
     106#define BYTES_PER_LINE 12
     107
     108static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
     109{
     110        printf("%s\n", msg);
     111       
     112        size_t i;
     113        for (i = 0; i < length; i++) {
     114                printf("  0x%02X", buffer[i]);
     115                if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
     116                    || (i + 1 == length)) {
     117                        printf("\n");
     118                }
     119        }
     120}
     121*/
     122/*
     123 * Copy-paste from srv/hid/kbd/generic/kbd.c
     124 */
     125
     126/** Currently active modifiers.
     127 *
     128 * TODO: put to device?
     129 */
     130static unsigned mods = KM_NUM_LOCK;
     131
     132/** Currently pressed lock keys. We track these to tackle autorepeat. 
     133 *
     134 * TODO: put to device?
     135 */
     136static unsigned lock_keys;
     137
     138#define NUM_LAYOUTS 3
     139
     140static layout_op_t *layout[NUM_LAYOUTS] = {
     141        &us_qwerty_op,
     142        &us_dvorak_op,
     143        &cz_op
     144};
     145
     146static int active_layout = 0;
     147
     148static void kbd_push_ev(int type, unsigned int key)
     149{
     150        console_event_t ev;
     151        unsigned mod_mask;
     152
     153        // TODO: replace by our own parsing?? or are the key codes identical??
     154        switch (key) {
     155        case KC_LCTRL: mod_mask = KM_LCTRL; break;
     156        case KC_RCTRL: mod_mask = KM_RCTRL; break;
     157        case KC_LSHIFT: mod_mask = KM_LSHIFT; break;
     158        case KC_RSHIFT: mod_mask = KM_RSHIFT; break;
     159        case KC_LALT: mod_mask = KM_LALT; break;
     160        case KC_RALT: mod_mask = KM_RALT; break;
     161        default: mod_mask = 0; break;
     162        }
     163
     164        if (mod_mask != 0) {
     165                if (type == KEY_PRESS)
     166                        mods = mods | mod_mask;
     167                else
     168                        mods = mods & ~mod_mask;
     169        }
     170
     171        switch (key) {
     172        case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;
     173        case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;
     174        case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;
     175        default: mod_mask = 0; break;
     176        }
     177
     178        if (mod_mask != 0) {
     179                if (type == KEY_PRESS) {
     180                        /*
     181                         * Only change lock state on transition from released
     182                         * to pressed. This prevents autorepeat from messing
     183                         * up the lock state.
     184                         */
     185                        mods = mods ^ (mod_mask & ~lock_keys);
     186                        lock_keys = lock_keys | mod_mask;
     187
     188                        /* Update keyboard lock indicator lights. */
     189                        // TODO
     190                        //kbd_ctl_set_ind(mods);
     191                } else {
     192                        lock_keys = lock_keys & ~mod_mask;
     193                }
     194        }
     195/*
     196        printf("type: %d\n", type);
     197        printf("mods: 0x%x\n", mods);
     198        printf("keycode: %u\n", key);
     199*/
     200       
     201        if (type == KEY_PRESS && (mods & KM_LCTRL) &&
     202                key == KC_F1) {
     203                active_layout = 0;
     204                layout[active_layout]->reset();
     205                return;
     206        }
     207
     208        if (type == KEY_PRESS && (mods & KM_LCTRL) &&
     209                key == KC_F2) {
     210                active_layout = 1;
     211                layout[active_layout]->reset();
     212                return;
     213        }
     214
     215        if (type == KEY_PRESS && (mods & KM_LCTRL) &&
     216                key == KC_F3) {
     217                active_layout = 2;
     218                layout[active_layout]->reset();
     219                return;
     220        }
     221       
     222        ev.type = type;
     223        ev.key = key;
     224        ev.mods = mods;
     225
     226        ev.c = layout[active_layout]->parse_ev(&ev);
     227
     228        printf("Sending key %d to the console\n", ev.key);
     229        assert(console_callback_phone != -1);
     230        async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
     231}
     232/*
     233 * End of copy-paste
     234 */
     235
     236        /*
     237         * TODO:
     238         * 1) key press / key release - how does the keyboard notify about release?
     239         * 2) layouts (use the already defined), not important now
     240         * 3)
     241         */
     242
     243/*
    93244 * Callbacks for parser
    94245 */
    95246static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count,
    96                                     uint8_t modifiers, void *arg)
     247    uint8_t modifiers, void *arg)
    97248{
    98249        printf("Got keys: ");
     
    100251        for (i = 0; i < count; ++i) {
    101252                printf("%d ", key_codes[i]);
     253                // TODO: Key press / release
     254
     255                // TODO: NOT WORKING
     256                unsigned int key = usbkbd_parse_scancode(key_codes[i]);
     257                kbd_push_ev(KEY_PRESS, key);
    102258        }
    103259        printf("\n");
     
    267423        //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
    268424        //    NULL);
    269         printf("Calling usb_hid_boot_keyboard_input_report()...\n)");
    270         usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL);
     425        printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n",
     426            actual_size);
     427        //dump_buffer("bufffer: ", buffer, actual_size);
     428        int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks,
     429            NULL);
     430        if (rc != EOK) {
     431                printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc);
     432        }
    271433}
    272434
    273435static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    274436{
    275         return;
    276        
    277437        int rc;
    278438        usb_handle_t handle;
     
    292452        };
    293453
     454        printf("Polling keyboard...\n");
     455
    294456        while (true) {
    295                 async_usleep(1000 * 1000);
     457                async_usleep(1000 * 1000 * 2);
    296458                rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
    297459                    poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
    298460
    299461                if (rc != EOK) {
     462                        printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);
    300463                        continue;
    301464                }
     
    303466                rc = usb_drv_async_wait_for(handle);
    304467                if (rc != EOK) {
     468                        printf("Error in usb_drv_async_wait_for(): %d\n", rc);
    305469                        continue;
    306470                }
     
    311475                 */
    312476                if (actual_size == 0) {
     477                        printf("Keyboard returned NAK\n");
    313478                        continue;
    314479                }
     
    317482                 * TODO: Process pressed keys.
    318483                 */
     484                printf("Calling usbkbd_process_interrupt_in()\n");
    319485                usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size);
    320486        }
     
    337503        // initialize device (get and process descriptors, get address, etc.)
    338504        usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev);
     505        if (kbd_dev == NULL) {
     506                printf("Error while initializing device.\n");
     507                return -1;
     508        }
    339509
    340510        usbkbd_poll_keyboard(kbd_dev);
  • uspace/drv/usbhub/main.c

    r67a1b78 r4687fcd4  
    4242
    4343usb_general_list_t usb_hub_list;
    44 futex_t usb_hub_list_lock;
     44fibril_mutex_t usb_hub_list_lock;
    4545
    4646static driver_ops_t hub_driver_ops = {
     
    6565{
    6666        usb_dprintf_enable(NAME, 0);
    67 
    68         futex_initialize(&usb_hub_list_lock, 0);
     67       
     68        fibril_mutex_initialize(&usb_hub_list_lock);
     69        fibril_mutex_lock(&usb_hub_list_lock);
    6970        usb_lst_init(&usb_hub_list);
    70         futex_up(&usb_hub_list_lock);
     71        fibril_mutex_unlock(&usb_hub_list_lock);
    7172
    7273        fid_t fid = fibril_create(usb_hub_control_loop, NULL);
  • uspace/drv/usbhub/usbhub.c

    r67a1b78 r4687fcd4  
    203203
    204204        //add the hub to list
    205         futex_down(&usb_hub_list_lock);
     205        fibril_mutex_lock(&usb_hub_list_lock);
    206206        usb_lst_append(&usb_hub_list, hub_info);
    207         futex_up(&usb_hub_list_lock);
     207        fibril_mutex_unlock(&usb_hub_list_lock);
    208208
    209209        dprintf(1, "hub info added to list");
     
    445445         */
    446446        usb_general_list_t * lst_item;
    447         futex_down(&usb_hub_list_lock);
     447        fibril_mutex_lock(&usb_hub_list_lock);
    448448        for (lst_item = usb_hub_list.next;
    449449                        lst_item != &usb_hub_list;
    450450                        lst_item = lst_item->next) {
    451                 futex_up(&usb_hub_list_lock);
     451                fibril_mutex_unlock(&usb_hub_list_lock);
    452452                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
    453453                /*
     
    488488
    489489                if (opResult != EOK) {
     490                        free(change_bitmap);
    490491                        dprintf(1, "something went wrong while getting status of hub");
    491492                        continue;
     
    503504
    504505                ipc_hangup(hc);
    505                 futex_down(&usb_hub_list_lock);
    506         }
    507         futex_up(&usb_hub_list_lock);
     506                fibril_mutex_lock(&usb_hub_list_lock);
     507        }
     508        fibril_mutex_unlock(&usb_hub_list_lock);
    508509}
    509510
  • uspace/drv/usbhub/usbhub_private.h

    r67a1b78 r4687fcd4  
    4343#include <bool.h>
    4444#include <driver.h>
    45 #include <futex.h>
     45#include <fibril_synch.h>
    4646
    4747#include <usb/usb.h>
     
    8282
    8383/** Lock for hub list*/
    84 extern futex_t usb_hub_list_lock;
     84extern fibril_mutex_t usb_hub_list_lock;
    8585
    8686
  • uspace/drv/vhc/hub.c

    r67a1b78 r4687fcd4  
    6363            = fibril_create(hub_register_in_devman_fibril, hc_dev);
    6464        if (root_hub_registration == 0) {
    65                 printf(NAME ": failed to register root hub\n");
     65                printf(NAME ": failed to create hub registration fibril\n");
    6666                return;
    6767        }
     
    7979        device_t *hc_dev = (device_t *) arg;
    8080
    81         int hc = usb_drv_hc_connect(hc_dev, hc_dev->handle, IPC_FLAG_BLOCKING);
    82         if (hc < 0) {
    83                 printf(NAME ": failed to register root hub\n");
    84                 return hc;
    85         }
     81        int hc;
     82        do {
     83                hc = usb_drv_hc_connect(hc_dev, hc_dev->handle,
     84                    IPC_FLAG_BLOCKING);
     85        } while (hc < 0);
    8686
    8787        usb_drv_reserve_default_address(hc);
  • uspace/drv/vhc/hub/hub.h

    r67a1b78 r4687fcd4  
    3838#include <fibril_synch.h>
    3939
     40#ifndef HUB_PORT_COUNT
    4041#define HUB_PORT_COUNT 2
     42#endif
    4143#define BITS2BYTES(bits) (bits ? ((((bits)-1)>>3)+1) : 0)
    4244
  • uspace/drv/vhc/hub/virthub.c

    r67a1b78 r4687fcd4  
    164164        dev->device_data = hub;
    165165
    166         usbvirt_connect_local(dev);
    167 
    168         return EOK;
     166        int rc;
     167#ifdef STANDALONE_HUB
     168        dev->name = "hub";
     169        rc = usbvirt_connect(dev);
     170#else
     171        rc = usbvirt_connect_local(dev);
     172#endif
     173
     174        return rc;
    169175}
    170176
  • uspace/drv/vhc/hub/virthub.h

    r67a1b78 r4687fcd4  
    3737
    3838#include <usbvirt/device.h>
     39#include "hub.h"
     40
     41#ifdef STANDALONE_HUB
     42#define virtdev_connection_t int
     43#else
    3944#include "../devices.h"
    40 #include "hub.h"
     45#endif
    4146
    4247/** Endpoint number for status change pipe. */
Note: See TracChangeset for help on using the changeset viewer.