Changes in / [0f3744d:b69e4c0] in mainline


Ignore:
Files:
30 added
7 deleted
27 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/mips32/src/Makefile

    r0f3744d rb69e4c0  
    3232.PHONY: all clean
    3333
    34 all: ../../../../version ../../../../Makefile.common ../../../../Makefile.config ../../../../config.h
     34all: ../../../../version ../../../../Makefile.config ../../../../config.h ../../../../config.defs
    3535        -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    3636        $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
    3737
    3838clean:
    39         rm -f $(USPACEDIR)/dist/srv/*
    40         rm -f $(USPACEDIR)/dist/app/*
    41         rm -f $(USPACEDIR)/dist/cfg/net/*
    42 
    4339        for file in $(RD_SRVS) ; do \
    4440                rm -f $(USPACEDIR)/dist/srv/`basename $$file` ; \
     
    4743                rm -f $(USPACEDIR)/dist/app/`basename $$file` ; \
    4844        done
    49         for file in $(NET_CFG) ; do \
    50                 rm -f $(USPACEDIR)/dist/cfg/net/`basename $$file` ; \
    51         done
    5245        rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(RAW) $(COMPS).h $(COMPS).c $(LINK) $(INITRD).img $(INITRD).fs
    5346        find . -name '*.o' -follow -exec rm \{\} \;
  • boot/arch/mips32/src/Makefile.build

    r0f3744d rb69e4c0  
    3232
    3333include ../../../../version
    34 include ../../../../Makefile.common
    3534include ../../../../Makefile.config
     35include ../../../../config.defs
    3636include Makefile.common
    3737include Makefile.toolchain
     
    7777
    7878$(DEPEND):
    79         rm -f $(USPACEDIR)/dist/srv/*
    80         rm -f $(USPACEDIR)/dist/app/*
    81         rm -f $(USPACEDIR)/dist/cfg/net/*
    82 
    8379        for file in $(RD_SRVS) ; do \
    8480                cp $$file $(USPACEDIR)/dist/srv/ ; \
     
    8682        for file in $(RD_APPS) ; do \
    8783                cp $$file $(USPACEDIR)/dist/app/ ; \
    88         done
    89         for file in $(NET_CFG) ; do \
    90                 cp $$file $(USPACEDIR)/dist/cfg/net/ ; \
    9184        done
    9285ifeq ($(RDFMT),tmpfs)
  • boot/arch/mips32/src/Makefile.toolchain

    r0f3744d rb69e4c0  
    2727#
    2828
     29## Toolchain configuration
     30#
     31
     32ifndef CROSS_PREFIX
     33        CROSS_PREFIX = /usr/local
     34endif
     35
    2936BFD_ARCH = mips
     37TARGET = mipsel-linux-gnu
     38TOOLCHAIN_DIR = $(CROSS_PREFIX)/mips32/bin
    3039
    3140JOBFILE = ../../../../tools/jobfile.py
     
    3948        BFD_NAME = elf32-tradbigmips
    4049        BFD = ecoff-bigmips
     50        TOOLCHAIN_DIR = $(CROSS_PREFIX)/mips32eb/bin
     51        TARGET = mips-linux-gnu
    4152endif
    4253
     
    4455        BFD_NAME = elf32-tradlittlemips
    4556        BFD = binary
     57endif
     58
     59ifeq ($(COMPILER),gcc_native)
     60        CC = gcc
     61        AS = as
     62        LD = ld
     63        OBJCOPY = objcopy
     64        OBJDUMP = objdump
     65endif
     66
     67ifeq ($(COMPILER),gcc_cross)
     68        CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
     69        AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
     70        LD = $(TOOLCHAIN_DIR)/$(TARGET)-ld
     71        OBJCOPY = $(TOOLCHAIN_DIR)/$(TARGET)-objcopy
     72        OBJDUMP = $(TOOLCHAIN_DIR)/$(TARGET)-objdump
    4673endif
    4774
  • kernel/arch/ia32/src/boot/boot.S

    r0f3744d rb69e4c0  
    22 * Copyright (c) 2001 Jakub Jermar
    33 * Copyright (c) 2005 Martin Decky
    4  * Copyright (c) 2011 Martin Sucha
    54 * All rights reserved.
    65 *
     
    125124                /* Map kernel and turn paging on */
    126125                pm_status $status_non_pse
    127                 call map_kernel_non_pse
     126                call map_kernel
    128127       
    129128        stack_init:
     
    196195 *
    197196 */
    198 map_kernel_non_pse:
     197.global map_kernel
     198map_kernel:
    199199        /* Paging features */
    200200        movl %cr4, %ecx
  • kernel/arch/ia32/src/smp/ap.S

    r0f3744d rb69e4c0  
    2828#
    2929
    30 /*
    31  * Init code for application processors.
    32  */
     30#
     31# Init code for application processors.
     32#
    3333
    3434#include <arch/boot/boot.h>
     
    4646KDATA=16
    4747
    48 /*
    49  * This piece of code is real-mode and is meant to be aligned at 4K boundary.
    50  * The requirement for such an alignment comes from MP Specification's
    51  * STARTUP IPI requirements.
    52  */
     48# This piece of code is real-mode and is meant to be aligned at 4K boundary.
     49# The requirement for such an alignment comes from MP Specification's STARTUP IPI
     50# requirements.
    5351
    5452.align 4096
     
    5957        movw %ax, %ds
    6058
    61         /* initialize Global Descriptor Table register */
    62         lgdtl ap_gdtr
     59        lgdtl ap_gdtr           # initialize Global Descriptor Table register
    6360       
    64         /* switch to protected mode */
    6561        movl %cr0, %eax
    6662        orl $1, %eax
    67         movl %eax, %cr0
     63        movl %eax, %cr0                         # switch to protected mode
    6864        jmpl $KTEXT, $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET
    6965       
     
    7470        movw %ax, %es
    7571        movw %ax, %ss
    76         movl $KA2PA(ctx), %eax  /* KA2PA((uintptr_t) &ctx) */
     72        movl $KA2PA(ctx), %eax                  # KA2PA((uintptr_t) &ctx)
    7773        movl (%eax), %esp
    78         subl $0x80000000, %esp  /* KA2PA(ctx.sp) */
     74        subl $0x80000000, %esp                  # KA2PA(ctx.sp)
    7975
    80         /*
    81          * Map kernel and turn paging on.
    82          * We assume that when using SMP, PSE is always available
    83          */
    84         call map_kernel_pse
     76        call map_kernel                                 # map kernel and turn paging on
    8577       
    86         addl $0x80000000, %esp  /*  PA2KA(ctx.sp) */
     78        addl $0x80000000, %esp                  # PA2KA(ctx.sp)
    8779       
    88         /* create the first stack frame */
    89         pushl $0
     80        pushl $0                                # create the first stack frame
    9081        movl %esp, %ebp
    9182
  • kernel/arch/ia64/include/asm.h

    r0f3744d rb69e4c0  
    4444#define IA64_IOSPACE_ADDRESS  0xE001000000000000ULL
    4545
    46 #define IO_SPACE_BOUNDARY       ((void *) (64 * 1024))
    47 
    4846NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t v)
    4947{
    50         if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
    51                 uintptr_t prt = (uintptr_t) port;
    52        
    53                 *((ioport8_t *) (IA64_IOSPACE_ADDRESS +
    54                     ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    55         } else {
    56                 *port = v;
    57         }
     48        uintptr_t prt = (uintptr_t) port;
     49       
     50        *((ioport8_t *) (IA64_IOSPACE_ADDRESS +
     51            ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    5852       
    5953        asm volatile (
     
    6559NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t v)
    6660{
    67         if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
    68                 uintptr_t prt = (uintptr_t) port;
    69        
    70                 *((ioport16_t *) (IA64_IOSPACE_ADDRESS +
    71                     ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    72         } else {
    73                 *port = v;
    74         }
     61        uintptr_t prt = (uintptr_t) port;
     62       
     63        *((ioport16_t *) (IA64_IOSPACE_ADDRESS +
     64            ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    7565       
    7666        asm volatile (
     
    8272NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t v)
    8373{
    84         if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
    85                 uintptr_t prt = (uintptr_t) port;
    86        
    87                 *((ioport32_t *) (IA64_IOSPACE_ADDRESS +
    88                     ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    89         } else {
    90                 *port = v;
    91         }
     74        uintptr_t prt = (uintptr_t) port;
     75       
     76        *((ioport32_t *) (IA64_IOSPACE_ADDRESS +
     77            ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    9278       
    9379        asm volatile (
     
    9985NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
    10086{
    101         uint8_t v;
    102 
    103         asm volatile (
    104                 "mf\n"
    105                 ::: "memory"
    106         );
    107 
    108         if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
    109                 uintptr_t prt = (uintptr_t) port;
    110 
    111                 v = *((ioport8_t *) (IA64_IOSPACE_ADDRESS +
    112                     ((prt & 0xfff) | ((prt >> 2) << 12))));
    113         } else {
    114                 v = *port;
    115         }
    116        
    117         return v;
     87        uintptr_t prt = (uintptr_t) port;
     88       
     89        asm volatile (
     90                "mf\n"
     91                ::: "memory"
     92        );
     93       
     94        return *((ioport8_t *) (IA64_IOSPACE_ADDRESS +
     95            ((prt & 0xfff) | ((prt >> 2) << 12))));
    11896}
    11997
    12098NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
    12199{
    122         uint16_t v;
    123 
    124         asm volatile (
    125                 "mf\n"
    126                 ::: "memory"
    127         );
    128 
    129         if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
    130                 uintptr_t prt = (uintptr_t) port;
    131 
    132                 v = *((ioport16_t *) (IA64_IOSPACE_ADDRESS +
    133                     ((prt & 0xfff) | ((prt >> 2) << 12))));
    134         } else {
    135                 v = *port;
    136         }
    137        
    138         return v;
     100        uintptr_t prt = (uintptr_t) port;
     101       
     102        asm volatile (
     103                "mf\n"
     104                ::: "memory"
     105        );
     106       
     107        return *((ioport16_t *) (IA64_IOSPACE_ADDRESS +
     108            ((prt & 0xfff) | ((prt >> 2) << 12))));
    139109}
    140110
    141111NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
    142112{
    143         uint32_t v;
    144        
    145         asm volatile (
    146                 "mf\n"
    147                 ::: "memory"
    148         );
    149        
    150         if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
    151                 uintptr_t prt = (uintptr_t) port;
    152                
    153                 v = *((ioport32_t *) (IA64_IOSPACE_ADDRESS +
    154                     ((prt & 0xfff) | ((prt >> 2) << 12))));
    155         } else {
    156                 v = *port;
    157         }
    158 
    159         return v;
     113        uintptr_t prt = (uintptr_t) port;
     114       
     115        asm volatile (
     116                "mf\n"
     117                ::: "memory"
     118        );
     119       
     120        return *((ioport32_t *) (IA64_IOSPACE_ADDRESS +
     121            ((prt & 0xfff) | ((prt >> 2) << 12))));
    160122}
    161123
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    r0f3744d rb69e4c0  
    5454static struct option const long_options[] = {
    5555        {"size", required_argument, 0, 's'},
    56         {"sparse", no_argument, 0, 'p'},
    5756        {"help", no_argument, 0, 'h'},
    5857        {0, 0, 0, 0}
     
    7069                "  -h, --help       A short option summary\n"
    7170                "  -s, --size sz    Size of the file\n"
    72                 "  -p, --sparse     Create a sparse file\n"
    7371                "\n"
    7472                "Size is a number followed by 'k', 'm' or 'g' for kB, MB, GB.\n"
     
    117115        ssize_t file_size;
    118116        ssize_t total_written;
    119         ssize_t to_write, rc, rc2 = 0;
     117        ssize_t to_write, rc;
    120118        char *file_name;
    121119        void *buffer;
    122         bool create_sparse = false;
    123120
    124121        file_size = 0;
     
    127124
    128125        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
    129                 c = getopt_long(argc, argv, "ps:h", long_options, &opt_ind);
     126                c = getopt_long(argc, argv, "s:h", long_options, &opt_ind);
    130127                switch (c) {
    131128                case 'h':
    132129                        help_cmd_mkfile(HELP_LONG);
    133130                        return CMD_SUCCESS;
    134                 case 'p':
    135                         create_sparse = true;
    136                         break;
    137131                case 's':
    138132                        file_size = read_size(optarg);
     
    162156        }
    163157
    164         if (create_sparse && file_size > 0) {
    165                 const char byte = 0x00;
    166 
    167                 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0)
    168                         goto exit;
    169 
    170                 rc2 = write(fd, &byte, sizeof(char));
    171                 goto exit;
    172         }
    173 
    174158        buffer = calloc(BUFFER_SIZE, 1);
    175159        if (buffer == NULL) {
     
    190174        }
    191175
    192         free(buffer);
    193 exit:
    194176        rc = close(fd);
    195 
    196         if (rc != 0 || rc2 < 0) {
     177        if (rc != 0) {
    197178                printf("%s: Error writing file (%zd).\n", cmdname, rc);
    198179                return CMD_FAILURE;
    199180        }
    200181
     182        free(buffer);
     183
    201184        return CMD_SUCCESS;
    202185}
  • uspace/app/vuhid/Makefile

    r0f3744d rb69e4c0  
    4747
    4848SOURCES_INTERFACES = \
    49         hids/bootkbd.c \
    50         hids/logitech_wireless.c
     49        hids/bootkbd.c
    5150
    5251SOURCES = \
     
    5453        device.c \
    5554        ifaces.c \
    56         life.c \
    5755        stdreq.c \
    5856        $(SOURCES_INTERFACES)
  • uspace/app/vuhid/hids/bootkbd.c

    r0f3744d rb69e4c0  
    9393             0, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    9494};
    95 static vuhid_interface_life_t boot_life = {
    96         .data_in = in_data,
    97         .data_in_count = sizeof(in_data)/INPUT_SIZE,
    98         .data_in_pos_change_delay = 500,
    99         .msg_born = "Boot keyboard comes to life...",
    100         .msg_die = "Boot keyboard died."
    101 };
     95static size_t in_data_count = sizeof(in_data)/INPUT_SIZE;
     96// FIXME - locking
     97static size_t in_data_position = 0;
     98
     99static int on_data_in(vuhid_interface_t *iface,
     100    void *buffer, size_t buffer_size, size_t *act_buffer_size)
     101{
     102        static size_t last_pos = (size_t) -1;
     103        size_t pos = in_data_position;
     104        if (pos >= in_data_count) {
     105                return EBADCHECKSUM;
     106        }
     107
     108        if (last_pos == pos) {
     109                return ENAK;
     110        }
     111
     112        if (buffer_size > INPUT_SIZE) {
     113                buffer_size = INPUT_SIZE;
     114        }
     115
     116        if (act_buffer_size != NULL) {
     117                *act_buffer_size = buffer_size;
     118        }
     119
     120        memcpy(buffer, in_data + pos * INPUT_SIZE, buffer_size);
     121        last_pos = pos;
     122
     123        return EOK;
     124}
    102125
    103126static int on_data_out(vuhid_interface_t *iface,
     
    118141}
    119142
     143
     144static void live(vuhid_interface_t *iface)
     145{
     146        async_usleep(1000 * 1000 * 5);
     147        usb_log_debug("Boot keyboard comes to life...\n");
     148        while (in_data_position < in_data_count) {
     149                async_usleep(1000 * 500);
     150                in_data_position++;
     151        }
     152        usb_log_debug("Boot keyboard died.\n");
     153}
     154
     155
    120156vuhid_interface_t vuhid_interface_bootkbd = {
    121157        .id = "boot",
     
    128164
    129165        .in_data_size = INPUT_SIZE,
    130         .on_data_in = interface_live_on_data_in,
     166        .on_data_in = on_data_in,
    131167
    132168        .out_data_size = 1,
    133169        .on_data_out = on_data_out,
    134170
    135         .live = interface_life_live,
     171        .live = live,
    136172
    137         .interface_data = &boot_life,
    138173        .vuhid_data = NULL
    139174};
  • uspace/app/vuhid/ifaces.c

    r0f3744d rb69e4c0  
    3838
    3939extern vuhid_interface_t vuhid_interface_bootkbd;
    40 extern vuhid_interface_t vuhid_interface_logitech_wireless_1;
    4140
    4241vuhid_interface_t *available_hid_interfaces[] = {
    4342        &vuhid_interface_bootkbd,
    44         &vuhid_interface_logitech_wireless_1,
    4543        NULL
    4644};
  • uspace/app/vuhid/virthid.h

    r0f3744d rb69e4c0  
    8282
    8383typedef struct {
    84         /** Buffer with data from device to the host. */
    85         uint8_t *data_in;
    86         /** Number of items in @c data_in.
    87          * The total size of @c data_in buffer shall be
    88          * <code>data_in_count * vuhid_interface_t.in_data_size</code>.
    89          */
    90         size_t data_in_count;
    91 
    92         /** Current position in the data buffer. */
    93         size_t data_in_pos;
    94         /** Previous position. */
    95         size_t data_in_last_pos;
    96 
    97         /** Delay between transition to "next" input buffer (in ms). */
    98         size_t data_in_pos_change_delay;
    99 
    100         /** Message to print when interface becomes alive. */
    101         const char *msg_born;
    102         /** Message to print when interface dies. */
    103         const char *msg_die;
    104 } vuhid_interface_life_t;
    105 
    106 typedef struct {
    10784        uint8_t length;
    10885        uint8_t type;
     
    11794void wait_for_interfaces_death(usbvirt_device_t *);
    11895
    119 void interface_life_live(vuhid_interface_t *);
    120 int interface_live_on_data_in(vuhid_interface_t *, void *, size_t, size_t *);
    121 
    122 
    12396#endif
    12497/**
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    r0f3744d rb69e4c0  
    7575/** Default idle rate for mouses. */
    7676static const uint8_t IDLE_RATE = 0;
     77static const size_t USB_MOUSE_BUTTON_COUNT = 3;
    7778
    7879/*----------------------------------------------------------------------------*/
     
    396397/*----------------------------------------------------------------------------*/
    397398
    398 /** Get highest index of a button mentioned in given report.
    399  *
    400  * @param report HID report.
    401  * @param report_id Report id we are interested in.
    402  * @return Highest button mentioned in the report.
    403  * @retval 1 No button was mentioned.
    404  *
    405  */
    406 static size_t usb_mouse_get_highest_button(usb_hid_report_t *report, uint8_t report_id)
    407 {
    408         size_t highest_button = 0;
    409 
    410         usb_hid_report_path_t *path = usb_hid_report_path();
    411         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    412         usb_hid_report_path_set_report_id(path, report_id);
    413 
    414         usb_hid_report_field_t *field = NULL;
    415 
    416         /* Break from within. */
    417         while (1) {
    418                 field = usb_hid_report_get_sibling(
    419                     report, field, path,
    420                     USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    421                     USB_HID_REPORT_TYPE_INPUT);
    422                 /* No more buttons? */
    423                 if (field == NULL) {
    424                         break;
    425                 }
    426 
    427                 size_t current_button = field->usage - field->usage_minimum;
    428                 if (current_button > highest_button) {
    429                         highest_button = current_button;
    430                 }
    431         }
    432 
    433         usb_hid_report_path_free(path);
    434 
    435         return highest_button;
    436 }
    437 
    438 /*----------------------------------------------------------------------------*/
    439 
    440399int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
    441400{
     
    455414        }
    456415       
    457         // FIXME: This may not be optimal since stupid hardware vendor may
    458         // use buttons 1, 2, 3 and 6000 and we would allocate array of
    459         // 6001*4B and use only 4 items in it.
    460         // Since I doubt that hardware producers would do that, I think
    461         // that the current solution is good enough.
    462         /* Adding 1 because we will be accessing buttons[highest]. */
    463         mouse_dev->buttons_count = usb_mouse_get_highest_button(hid_dev->report,
    464             hid_dev->report_id) + 1;
    465         mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t));
     416        mouse_dev->buttons = (int32_t *)calloc(USB_MOUSE_BUTTON_COUNT,
     417            sizeof(int32_t));
    466418       
    467419        if (mouse_dev->buttons == NULL) {
    468                 usb_log_error(NAME ": out of memory, giving up on device!\n");
     420                usb_log_fatal("No memory!\n");
    469421                free(mouse_dev);
    470422                return ENOMEM;
    471423        }
    472 
    473 
     424       
    474425        // save the Mouse device structure into the HID device structure
    475426        *data = mouse_dev;
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.h

    r0f3744d rb69e4c0  
    5050        async_sess_t *wheel_sess;
    5151       
    52         /* Mouse buttons statuses. */
    5352        int32_t *buttons;
    54         size_t buttons_count;
    5553       
    5654        ddf_dev_ops_t ops;
  • uspace/drv/bus/usb/usbhub/Makefile

    r0f3744d rb69e4c0  
    11#
    22# Copyright (c) 2010 Vojtech Horky
    3 # Copyright (c) 2011 Jan Vesely
    43# All rights reserved.
    54#
     
    4443SOURCES = \
    4544        main.c \
     45        utils.c \
    4646        usbhub.c \
    47         port.c
     47        ports.c
    4848
    4949include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/bus/usb/usbhub/main.c

    r0f3744d rb69e4c0  
    11/*
    22 * Copyright (c) 2010 Vojtech Horky
    3  * Copyright (c) 2011 Jan Vesely
    43 * All rights reserved.
    54 *
     
    3938#include <usb/dev/driver.h>
    4039#include <usb/classes/classes.h>
    41 #include <usb/debug.h>
    4240
    4341#include "usbhub.h"
     42#include "usbhub_private.h"
    4443
    4544/** Hub status-change endpoint description.
     
    5756
    5857/**
    59  * USB hub driver operations
     58 * usb hub driver operations
    6059 *
    6160 * The most important one is add_device, which is set to usb_hub_add_device.
     
    6564};
    6665
    67 /** Hub endpoints, excluding control endpoint. */
     66/**
     67 * hub endpoints, excluding control endpoint
     68 */
    6869static usb_endpoint_description_t *usb_hub_endpoints[] = {
    6970        &hub_status_change_endpoint_description,
    70         NULL,
     71        NULL
    7172};
    72 /** Static usb hub driver information. */
     73
     74/**
     75 * static usb hub driver information
     76 */
    7377static usb_driver_t usb_hub_driver = {
    7478        .name = NAME,
     
    8185{
    8286        printf(NAME ": HelenOS USB hub driver.\n");
     87
    8388        usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
    8489
     
    8994 * @}
    9095 */
     96
  • uspace/drv/bus/usb/usbhub/usbhub.c

    r0f3744d rb69e4c0  
    11/*
    22 * Copyright (c) 2010 Matus Dekanek
    3  * Copyright (c) 2011 Jan Vesely
    43 * All rights reserved.
    54 *
     
    3938#include <str_error.h>
    4039#include <inttypes.h>
    41 #include <stdio.h>
    42 
    43 #include <usb/usb.h>
    44 #include <usb/debug.h>
    45 #include <usb/dev/pipes.h>
    46 #include <usb/classes/classes.h>
     40
     41#include <usb_iface.h>
    4742#include <usb/ddfiface.h>
    4843#include <usb/descriptor.h>
     
    5146#include <usb/classes/hub.h>
    5247#include <usb/dev/poll.h>
    53 #include <usb_iface.h>
     48#include <stdio.h>
    5449
    5550#include "usbhub.h"
    56 #include "status.h"
    57 
    58 #define HUB_FNC_NAME "hub"
    59 
    60 /** Standard get hub global status request */
    61 static const usb_device_request_setup_packet_t get_hub_status_request = {
    62         .request_type = USB_HUB_REQ_TYPE_GET_HUB_STATUS,
    63         .request = USB_HUB_REQUEST_GET_STATUS,
    64         .index = 0,
    65         .value = 0,
    66         .length = sizeof(usb_hub_status_t),
    67 };
    68 
    69 static int usb_set_first_configuration(usb_device_t *usb_device);
     51#include "usbhub_private.h"
     52#include "port_status.h"
     53#include <usb/usb.h>
     54#include <usb/dev/pipes.h>
     55#include <usb/classes/classes.h>
     56
     57
    7058static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev);
     59
    7160static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info);
    72 static void usb_hub_over_current(const usb_hub_info_t *hub_info,
     61
     62static int usb_hub_set_configuration(usb_hub_info_t *hub_info);
     63
     64static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info);
     65
     66static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
    7367    usb_hub_status_t status);
    74 static void usb_hub_global_interrupt(const usb_hub_info_t *hub_info);
     68
     69static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info,
     70    usb_hub_status_t status);
     71
     72static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info);
     73
    7574static void usb_hub_polling_terminated_callback(usb_device_t *device,
    7675    bool was_error, void *data);
    7776
     77
     78//*********************************************
     79//
     80//  hub driver code, initialization
     81//
     82//*********************************************
     83
    7884/**
    7985 * Initialize hub device driver fibril
    8086 *
    81  * Creates hub representation and fibril that periodically checks hub's status.
     87 * Creates hub representation and fibril that periodically checks hub`s status.
    8288 * Hub representation is passed to the fibril.
    8389 * @param usb_dev generic usb device information
    8490 * @return error code
    8591 */
    86 int usb_hub_add_device(usb_device_t *usb_dev)
    87 {
    88         assert(usb_dev);
    89         /* Create driver soft-state structure */
     92int usb_hub_add_device(usb_device_t *usb_dev) {
     93        if (!usb_dev) return EINVAL;
    9094        usb_hub_info_t *hub_info = usb_hub_info_create(usb_dev);
    91         if (hub_info == NULL) {
    92                 usb_log_error("Failed to create hun driver structure.\n");
    93                 return ENOMEM;
    94         }
    95 
    96         /* Create hc connection */
     95        //create hc connection
    9796        usb_log_debug("Initializing USB wire abstraction.\n");
    9897        int opResult = usb_hc_connection_initialize_from_device(
    99             &hub_info->connection, hub_info->usb_device->ddf_dev);
    100         if (opResult != EOK) {
    101                 usb_log_error("Could not initialize connection to device: %s\n",
     98            &hub_info->connection,
     99            hub_info->usb_device->ddf_dev);
     100        if (opResult != EOK) {
     101                usb_log_error("Could not initialize connection to device, "
     102                    " %s\n",
    102103                    str_error(opResult));
    103104                free(hub_info);
     
    105106        }
    106107
    107         /* Set hub's first configuration. (There should be only one) */
    108         opResult = usb_set_first_configuration(usb_dev);
    109         if (opResult != EOK) {
    110                 usb_log_error("Could not set hub configuration: %s\n",
     108        //set hub configuration
     109        opResult = usb_hub_set_configuration(hub_info);
     110        if (opResult != EOK) {
     111                usb_log_error("Could not set hub configuration, %s\n",
    111112                    str_error(opResult));
    112113                free(hub_info);
    113114                return opResult;
    114115        }
    115 
    116116        //get port count and create attached_devs
    117117        opResult = usb_hub_process_hub_specific_info(hub_info);
     
    123123        }
    124124
    125         usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n");
     125        usb_log_debug("Creating 'hub' function in DDF.\n");
    126126        ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,
    127             fun_exposed, HUB_FNC_NAME);
    128         if (hub_fun == NULL) {
    129                 usb_log_error("Failed to create hub function.\n");
     127            fun_exposed, "hub");
     128        assert(hub_fun != NULL);
     129        hub_fun->ops = NULL;
     130
     131        opResult = ddf_fun_bind(hub_fun);
     132        assert(opResult == EOK);
     133
     134        opResult = usb_hub_start_hub_fibril(hub_info);
     135        if (opResult != EOK)
    130136                free(hub_info);
    131                 return ENOMEM;
    132         }
    133 
    134         opResult = ddf_fun_bind(hub_fun);
    135         if (opResult != EOK) {
    136                 usb_log_error("Failed to bind hub function: %s.\n",
    137                    str_error(opResult));
    138                 free(hub_info);
    139                 ddf_fun_destroy(hub_fun);
    140                 return opResult;
    141         }
    142 
    143         opResult = usb_device_auto_poll(hub_info->usb_device, 0,
    144             hub_port_changes_callback, ((hub_info->port_count + 1) / 8) + 1,
    145             usb_hub_polling_terminated_callback, hub_info);
    146         if (opResult != EOK) {
    147                 ddf_fun_destroy(hub_fun);
    148                 free(hub_info);
    149                 usb_log_error("Failed to create polling fibril: %s.\n",
    150                     str_error(opResult));
    151                 return opResult;
    152         }
    153         usb_log_info("Controlling hub '%s' (%zu ports).\n",
    154             hub_info->usb_device->ddf_dev->name, hub_info->port_count);
    155 
    156         return EOK;
    157 }
    158 /*----------------------------------------------------------------------------*/
     137        return opResult;
     138}
     139
    159140/** Callback for polling hub for changes.
    160141 *
     
    166147 */
    167148bool hub_port_changes_callback(usb_device_t *dev,
    168     uint8_t *change_bitmap, size_t change_bitmap_size, void *arg)
    169 {
     149    uint8_t *change_bitmap, size_t change_bitmap_size, void *arg) {
    170150        usb_log_debug("hub_port_changes_callback\n");
    171         usb_hub_info_t *hub = arg;
    172         assert(hub);
    173 
    174         /* It is an error condition if we didn't receive enough data */
     151        usb_hub_info_t *hub = (usb_hub_info_t *) arg;
     152
     153        /* FIXME: check that we received enough bytes. */
    175154        if (change_bitmap_size == 0) {
    176                 return false;
    177         }
    178 
    179         /* Lowest bit indicates global change */
    180         const bool change = change_bitmap[0] & 1;
     155                goto leave;
     156        }
     157
     158        bool change;
     159        change = ((uint8_t*) change_bitmap)[0] & 1;
    181160        if (change) {
    182                 usb_hub_global_interrupt(hub);
    183         }
    184 
    185         /* N + 1 bit indicates change on port N */
    186         size_t port = 1;
    187         for (; port < hub->port_count + 1; port++) {
    188                 const bool change = (change_bitmap[port / 8] >> (port % 8)) & 1;
     161                usb_hub_process_global_interrupt(hub);
     162        }
     163
     164        size_t port;
     165        for (port = 1; port < hub->port_count + 1; port++) {
     166                bool change = (change_bitmap[port / 8] >> (port % 8)) % 2;
    189167                if (change) {
    190                         usb_hub_port_process_interrupt(&hub->ports[port], hub);
     168                        usb_hub_process_port_interrupt(hub, port);
    191169                }
    192170        }
     171leave:
     172        /* FIXME: proper interval. */
     173        async_usleep(1000 * 250);
     174
    193175        return true;
    194176}
    195 /*----------------------------------------------------------------------------*/
     177
     178
     179//*********************************************
     180//
     181//  support functions
     182//
     183//*********************************************
     184
    196185/**
    197186 * create usb_hub_info_t structure
     
    201190 * @return basic usb_hub_info_t structure
    202191 */
    203 static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev)
    204 {
    205         assert(usb_dev);
    206         usb_hub_info_t *info = malloc(sizeof(usb_hub_info_t));
    207         if (!info)
    208             return NULL;
    209 
    210         info->usb_device = usb_dev;
    211 
    212         info->ports = NULL;
    213         info->port_count = -1;
    214         fibril_mutex_initialize(&info->pending_ops_mutex);
    215         fibril_condvar_initialize(&info->pending_ops_cv);
    216         info->pending_ops_count = 0;
    217 
    218         return info;
    219 }
    220 /*----------------------------------------------------------------------------*/
     192static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev) {
     193        usb_hub_info_t * result = malloc(sizeof (usb_hub_info_t));
     194        if (!result) return NULL;
     195        result->usb_device = usb_dev;
     196        result->status_change_pipe = usb_dev->pipes[0].pipe;
     197        result->control_pipe = &usb_dev->ctrl_pipe;
     198        result->is_default_address_used = false;
     199
     200        result->ports = NULL;
     201        result->port_count = (size_t) - 1;
     202        fibril_mutex_initialize(&result->port_mutex);
     203
     204        fibril_mutex_initialize(&result->pending_ops_mutex);
     205        fibril_condvar_initialize(&result->pending_ops_cv);
     206        result->pending_ops_count = 0;
     207        return result;
     208}
     209
    221210/**
    222211 * Load hub-specific information into hub_info structure and process if needed
    223212 *
    224  * Read port count and initialize structures holding per port information.
    225  * If there are any non-removable devices, start initializing them.
     213 * Particularly read port count and initialize structure holding port
     214 * information. If there are non-removable devices, start initializing them.
    226215 * This function is hub-specific and should be run only after the hub is
    227  * configured using usb_set_first_configuration function.
     216 * configured using usb_hub_set_configuration function.
    228217 * @param hub_info hub representation
    229218 * @return error code
    230219 */
    231 static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info)
     220int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info)
    232221{
    233         assert(hub_info);
    234 
    235         /* Get hub descriptor. */
     222        // get hub descriptor
    236223        usb_log_debug("Retrieving descriptor\n");
    237         usb_pipe_t *control_pipe = &hub_info->usb_device->ctrl_pipe;
    238 
    239         usb_hub_descriptor_header_t descriptor;
     224        uint8_t serialized_descriptor[USB_HUB_MAX_DESCRIPTOR_SIZE];
     225        int opResult;
     226
    240227        size_t received_size;
    241         int opResult = usb_request_get_descriptor(control_pipe,
     228        opResult = usb_request_get_descriptor(hub_info->control_pipe,
    242229            USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE,
    243             USB_DESCTYPE_HUB, 0, 0, &descriptor,
    244             sizeof(usb_hub_descriptor_t), &received_size);
     230            USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
     231            USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
     232
    245233        if (opResult != EOK) {
    246234                usb_log_error("Failed to receive hub descriptor: %s.\n",
     
    248236                return opResult;
    249237        }
    250 
    251         usb_log_debug("Setting port count to %d.\n", descriptor.port_count);
    252         hub_info->port_count = descriptor.port_count;
    253 
    254         // TODO: +1 hack is no longer necessary
     238        usb_log_debug2("Parsing descriptor\n");
     239        usb_hub_descriptor_t descriptor;
     240        opResult = usb_deserialize_hub_desriptor(
     241                serialized_descriptor, received_size, &descriptor);
     242        if (opResult != EOK) {
     243                usb_log_error("Could not parse descriptor: %s\n",
     244                    str_error(opResult));
     245                return opResult;
     246        }
     247        usb_log_debug("Setting port count to %d.\n", descriptor.ports_count);
     248        hub_info->port_count = descriptor.ports_count;
     249
    255250        hub_info->ports =
    256251            malloc(sizeof(usb_hub_port_t) * (hub_info->port_count + 1));
     
    261256        size_t port;
    262257        for (port = 0; port < hub_info->port_count + 1; ++port) {
    263                 usb_hub_port_init(&hub_info->ports[port], port, control_pipe);
     258                usb_hub_port_init(&hub_info->ports[port]);
    264259        }
    265260
    266261        const bool is_power_switched =
    267             !(descriptor.characteristics & HUB_CHAR_NO_POWER_SWITCH_FLAG);
     262            !(descriptor.hub_characteristics & HUB_CHAR_NO_POWER_SWITCH_FLAG);
    268263        if (is_power_switched) {
    269264                usb_log_debug("Hub power switched\n");
    270                 const bool per_port_power = descriptor.characteristics
     265                const bool per_port_power = descriptor.hub_characteristics
    271266                    & HUB_CHAR_POWER_PER_PORT_FLAG;
    272267
    273268                for (port = 1; port <= hub_info->port_count; ++port) {
    274269                        usb_log_debug("Powering port %zu.\n", port);
    275                         opResult = usb_hub_port_set_feature(
    276                             &hub_info->ports[port], USB_HUB_FEATURE_PORT_POWER);
     270                        opResult = usb_hub_set_port_feature(
     271                            hub_info->control_pipe,
     272                            port, USB_HUB_FEATURE_PORT_POWER);
    277273                        if (opResult != EOK) {
    278274                                usb_log_error("Cannot power on port %zu: %s.\n",
     
    287283                        }
    288284                }
     285
    289286        } else {
    290                 usb_log_debug("Power not switched, ports always powered\n");
     287                usb_log_debug("Power not switched, not going to be powered\n");
    291288        }
    292289        return EOK;
    293290}
    294 /*----------------------------------------------------------------------------*/
    295 /**
    296  * Set configuration of and USB device
     291
     292/**
     293 * Set configuration of hub
    297294 *
    298295 * Check whether there is at least one configuration and sets the first one.
    299296 * This function should be run prior to running any hub-specific action.
    300  * @param usb_device usb device representation
     297 * @param hub_info hub representation
    301298 * @return error code
    302299 */
    303 static int usb_set_first_configuration(usb_device_t *usb_device)
    304 {
    305         assert(usb_device);
    306         /* Get number of possible configurations from device descriptor */
    307         const size_t configuration_count =
    308             usb_device->descriptors.device.configuration_count;
    309         usb_log_debug("Hub has %zu configurations.\n", configuration_count);
    310 
    311         if (configuration_count < 1) {
     300static int usb_hub_set_configuration(usb_hub_info_t *hub_info) {
     301        //device descriptor
     302        usb_standard_device_descriptor_t *std_descriptor
     303            = &hub_info->usb_device->descriptors.device;
     304        usb_log_debug("Hub has %d configurations\n",
     305            std_descriptor->configuration_count);
     306        if (std_descriptor->configuration_count < 1) {
    312307                usb_log_error("There are no configurations available\n");
    313308                return EINVAL;
    314309        }
    315310
    316         // TODO: Make sure that there is enough data and the cast is correct
    317311        usb_standard_configuration_descriptor_t *config_descriptor
    318312            = (usb_standard_configuration_descriptor_t *)
    319             usb_device->descriptors.configuration;
    320 
    321         /* Set configuration. Use the configuration that was in
    322          * usb_device->descriptors.configuration i.e. The first one. */
    323         const int opResult = usb_request_set_configuration(
    324             &usb_device->ctrl_pipe, config_descriptor->configuration_number);
     313            hub_info->usb_device->descriptors.configuration;
     314
     315        /* Set configuration. */
     316        int opResult = usb_request_set_configuration(
     317            &hub_info->usb_device->ctrl_pipe,
     318            config_descriptor->configuration_number);
     319
    325320        if (opResult != EOK) {
    326321                usb_log_error("Failed to set hub configuration: %s.\n",
    327322                    str_error(opResult));
    328         } else {
    329                 usb_log_debug("\tUsed configuration %d\n",
    330                     config_descriptor->configuration_number);
    331         }
    332         return opResult;
    333 }
    334 /*----------------------------------------------------------------------------*/
    335 /**
    336  * Process hub over current change
     323                return opResult;
     324        }
     325        usb_log_debug("\tUsed configuration %d\n",
     326            config_descriptor->configuration_number);
     327
     328        return EOK;
     329}
     330
     331/**
     332 * create and start fibril with hub control loop
     333 *
     334 * Before the fibril is started, the control pipe and host controller
     335 * connection of the hub is open.
     336 *
     337 * @param hub_info hub representing structure
     338 * @return error code
     339 */
     340static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info) {
     341        int rc;
     342
     343        rc = usb_device_auto_poll(hub_info->usb_device, 0,
     344            hub_port_changes_callback, ((hub_info->port_count + 1) / 8) + 1,
     345            usb_hub_polling_terminated_callback, hub_info);
     346        if (rc != EOK) {
     347                usb_log_error("Failed to create polling fibril: %s.\n",
     348                    str_error(rc));
     349                free(hub_info);
     350                return rc;
     351        }
     352
     353        usb_log_info("Controlling hub `%s' (%zu ports).\n",
     354            hub_info->usb_device->ddf_dev->name, hub_info->port_count);
     355        return EOK;
     356}
     357
     358//*********************************************
     359//
     360//  change handling functions
     361//
     362//*********************************************
     363
     364/**
     365 * process hub over current change
    337366 *
    338367 * This means either to power off the hub or power it on.
     
    341370 * @return error code
    342371 */
    343 static void usb_hub_over_current(const usb_hub_info_t *hub_info,
    344     usb_hub_status_t status)
    345 {
    346         if (status & USB_HUB_STATUS_OVER_CURRENT) {
    347                 /* Hub should remove power from all ports if it detects OC */
    348                 usb_log_warning("Detected hub over-current condition, "
    349                     "all ports should be powered off.");
    350         } else {
    351                 /* Over-current condition is gone, it is safe to turn the
    352                  * ports on. */
    353                 size_t port;
     372static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
     373    usb_hub_status_t status) {
     374        int opResult;
     375        if (usb_hub_is_status(status, USB_HUB_FEATURE_HUB_OVER_CURRENT)) {
     376                //poweroff all ports
     377                unsigned int port;
    354378                for (port = 1; port <= hub_info->port_count; ++port) {
    355                         const int opResult = usb_hub_port_set_feature(
    356                             &hub_info->ports[port], USB_HUB_FEATURE_PORT_POWER);
     379                        opResult = usb_hub_clear_port_feature(
     380                            hub_info->control_pipe, port,
     381                            USB_HUB_FEATURE_PORT_POWER);
    357382                        if (opResult != EOK) {
    358383                                usb_log_warning(
    359                                     "HUB OVER-CURRENT GONE: Cannot power on "
    360                                     "port %zu;  %s\n",
     384                                    "Cannot power off port %d;  %s\n",
    361385                                    port, str_error(opResult));
    362386                        }
    363387                }
    364         }
    365         const int opResult = usb_request_clear_feature(
    366             &hub_info->usb_device->ctrl_pipe, USB_REQUEST_TYPE_CLASS,
    367             USB_REQUEST_RECIPIENT_DEVICE,
    368             USB_HUB_FEATURE_C_HUB_LOCAL_POWER, 0);
    369         if (opResult != EOK) {
    370                 usb_log_error(
    371                     "Failed to clear hub over-current change flag: %s.\n",
    372                     str_error(opResult));
    373         }
    374 }
    375 /*----------------------------------------------------------------------------*/
    376 /**
    377  * Process hub interrupts.
    378  *
    379  * The change can be either in the over-current condition or local-power change.
     388        } else {
     389                //power all ports
     390                unsigned int port;
     391                for (port = 1; port <= hub_info->port_count; ++port) {
     392                        opResult = usb_hub_set_port_feature(
     393                            hub_info->control_pipe, port,
     394                            USB_HUB_FEATURE_PORT_POWER);
     395                        if (opResult != EOK) {
     396                                usb_log_warning(
     397                                    "Cannot power off port %d;  %s\n",
     398                                    port, str_error(opResult));
     399                        }
     400                }
     401        }
     402        return opResult;
     403}
     404
     405/**
     406 * process hub local power change
     407 *
     408 * This change is ignored.
    380409 * @param hub_info hub instance
    381  */
    382 static void usb_hub_global_interrupt(const usb_hub_info_t *hub_info)
    383 {
    384         assert(hub_info);
    385         assert(hub_info->usb_device);
     410 * @param status hub status bitmask
     411 * @return error code
     412 */
     413static int usb_process_hub_local_power_change(usb_hub_info_t *hub_info,
     414    usb_hub_status_t status) {
     415        int opResult = EOK;
     416        opResult = usb_hub_clear_feature(hub_info->control_pipe,
     417            USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
     418        if (opResult != EOK) {
     419                usb_log_error("Cannnot clear hub power change flag: "
     420                    "%s\n",
     421                    str_error(opResult));
     422        }
     423        return opResult;
     424}
     425
     426/**
     427 * process hub interrupts
     428 *
     429 * The change can be either in the over-current condition or
     430 * local-power change.
     431 * @param hub_info hub instance
     432 */
     433static void usb_hub_process_global_interrupt(usb_hub_info_t *hub_info) {
    386434        usb_log_debug("Global interrupt on a hub\n");
    387         usb_pipe_t *control_pipe = &hub_info->usb_device->ctrl_pipe;
    388 
    389         usb_hub_status_t status;
     435        usb_pipe_t *pipe = hub_info->control_pipe;
     436        int opResult;
     437
     438        usb_port_status_t status;
    390439        size_t rcvd_size;
    391         /* NOTE: We can't use standard USB GET_STATUS request, because
    392          * hubs reply is 4byte instead of 2 */
    393         const int opResult = usb_pipe_control_read(control_pipe,
    394             &get_hub_status_request, sizeof(get_hub_status_request),
    395             &status, sizeof(usb_hub_status_t), &rcvd_size);
     440        usb_device_request_setup_packet_t request;
     441        //int opResult;
     442        usb_hub_set_hub_status_request(&request);
     443        //endpoint 0
     444
     445        opResult = usb_pipe_control_read(
     446            pipe,
     447            &request, sizeof (usb_device_request_setup_packet_t),
     448            &status, 4, &rcvd_size
     449            );
    396450        if (opResult != EOK) {
    397451                usb_log_error("Could not get hub status: %s\n",
     
    399453                return;
    400454        }
    401         if (rcvd_size != sizeof(usb_hub_status_t)) {
     455        if (rcvd_size != sizeof (usb_port_status_t)) {
    402456                usb_log_error("Received status has incorrect size\n");
    403457                return;
    404458        }
    405 
    406         /* Handle status changes */
    407         if (status & USB_HUB_STATUS_C_OVER_CURRENT) {
    408                 usb_hub_over_current(hub_info, status);
    409         }
    410 
    411         if (status & USB_HUB_STATUS_C_LOCAL_POWER) {
    412                 /* NOTE: Handling this is more complicated.
    413                  * If the transition is from bus power to local power, all
    414                  * is good and we may signal the parent hub that we don't
    415                  * need the power.
    416                  * If the transition is from local power to bus power
    417                  * the hub should turn off all the ports and devices need
    418                  * to be reinitialized taking into account the limited power
    419                  * that is now available.
    420                  * There is no support for power distribution in HelenOS,
    421                  * (or other OSes/hub devices that I've seen) so this is not
    422                  * implemented.
    423                  * Just ACK the change.
    424                  */
    425                 const int opResult = usb_request_clear_feature(
    426                     control_pipe, USB_REQUEST_TYPE_CLASS,
    427                     USB_REQUEST_RECIPIENT_DEVICE,
    428                     USB_HUB_FEATURE_C_HUB_LOCAL_POWER, 0);
    429                 if (opResult != EOK) {
    430                         usb_log_error(
    431                             "Failed to clear hub power change flag: %s.\n",
    432                             str_error(opResult));
    433                 }
    434         }
    435 }
    436 /*----------------------------------------------------------------------------*/
     459        //port reset
     460        if (
     461            usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_OVER_CURRENT)) {
     462                usb_process_hub_over_current(hub_info, status);
     463        }
     464        if (
     465            usb_hub_is_status(status, 16 + USB_HUB_FEATURE_C_HUB_LOCAL_POWER)) {
     466                usb_process_hub_local_power_change(hub_info, status);
     467        }
     468}
     469
    437470/**
    438471 * callback called from hub polling fibril when the fibril terminates
     
    444477 */
    445478static void usb_hub_polling_terminated_callback(usb_device_t *device,
    446     bool was_error, void *data)
    447 {
    448         usb_hub_info_t *hub = data;
     479    bool was_error, void *data) {
     480        usb_hub_info_t * hub = data;
    449481        assert(hub);
    450482
     
    460492         */
    461493        if (hub->pending_ops_count > 0) {
     494                fibril_mutex_lock(&hub->port_mutex);
    462495                size_t port;
    463496                for (port = 0; port < hub->port_count; port++) {
    464                         usb_hub_port_reset_fail(&hub->ports[port]);
     497                        usb_hub_port_t *the_port = hub->ports + port;
     498                        fibril_mutex_lock(&the_port->reset_mutex);
     499                        the_port->reset_completed = true;
     500                        the_port->reset_okay = false;
     501                        fibril_condvar_broadcast(&the_port->reset_cv);
     502                        fibril_mutex_unlock(&the_port->reset_mutex);
    465503                }
     504                fibril_mutex_unlock(&hub->port_mutex);
    466505        }
    467506        /* And now wait for them. */
     
    477516        free(hub);
    478517}
     518
     519
     520
     521
    479522/**
    480523 * @}
  • uspace/drv/bus/usb/usbhub/usbhub.h

    r0f3744d rb69e4c0  
    11/*
    22 * Copyright (c) 2010 Vojtech Horky
    3  * Copyright (c) 2011 Vojtech Horky
    43 * All rights reserved.
    54 *
     
    2726 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2827 */
     28
    2929/** @addtogroup drvusbhub
    3030 * @{
     
    4949#define NAME "usbhub"
    5050
    51 #include "port.h"
     51#include "ports.h"
    5252
    5353/** Information about attached hub. */
     
    5656        size_t port_count;
    5757
    58         /** Attached device handles, for each port one */
     58        /** attached device handles, for each port one */
    5959        usb_hub_port_t *ports;
    6060
    61         /** Connection to hcd */
     61        fibril_mutex_t port_mutex;
     62
     63        /** connection to hcd */
    6264        usb_hc_connection_t connection;
    6365
    64         /** Generic usb device data*/
    65         usb_device_t *usb_device;
     66        /** default address is used indicator
     67         *
     68         * If default address is requested by this device, it cannot
     69         * be requested by the same hub again, otherwise a deadlock will occur.
     70         */
     71        bool is_default_address_used;
     72
     73        /** convenience pointer to status change pipe
     74         *
     75         * Status change pipe is initialized in usb_device structure. This is
     76         * pointer into this structure, so that it does not have to be
     77         * searched again and again for the 'right pipe'.
     78         */
     79        usb_pipe_t * status_change_pipe;
     80
     81        /** convenience pointer to control pipe
     82         *
     83         * Control pipe is initialized in usb_device structure. This is
     84         * pointer into this structure, so that it does not have to be
     85         * searched again and again for the 'right pipe'.
     86         */
     87        usb_pipe_t * control_pipe;
     88
     89        /** generic usb device data*/
     90        usb_device_t * usb_device;
    6691
    6792        /** Number of pending operations on the mutex to prevent shooting
     
    76101        /** Condition variable for pending_ops_count. */
    77102        fibril_condvar_t pending_ops_cv;
     103
    78104};
    79105
  • uspace/drv/bus/usb/vhc/connhost.c

    r0f3744d rb69e4c0  
    440440        int rc = vhc_virtdev_add_transfer(vhc, transfer);
    441441        if (rc != EOK) {
    442                 if (transfer->setup_buffer != NULL) {
    443                         free(transfer->setup_buffer);
    444                 }
     442                free(transfer->setup_buffer);
    445443                free(transfer);
    446444                return rc;
  • uspace/lib/c/arch/ia64/include/ddi.h

    r0f3744d rb69e4c0  
    5252static inline void pio_write_8(ioport8_t *port, uint8_t v)
    5353{
    54         if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
    55                 uintptr_t prt = (uintptr_t) port;
     54        uintptr_t prt = (uintptr_t) port;
    5655
    57                 *((ioport8_t *)(IA64_IOSPACE_ADDRESS +
    58                     ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    59         } else {
    60                 *port = v;
    61         }
     56        *((ioport8_t *)(IA64_IOSPACE_ADDRESS +
     57            ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    6258
    6359        asm volatile ("mf\n" ::: "memory");
     
    6662static inline void pio_write_16(ioport16_t *port, uint16_t v)
    6763{
    68         if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
    69                 uintptr_t prt = (uintptr_t) port;
     64        uintptr_t prt = (uintptr_t) port;
    7065
    71                 *((ioport16_t *)(IA64_IOSPACE_ADDRESS +
    72                     ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    73         } else {
    74                 *port = v;
    75         }
     66        *((ioport16_t *)(IA64_IOSPACE_ADDRESS +
     67            ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    7668
    7769        asm volatile ("mf\n" ::: "memory");
     
    8072static inline void pio_write_32(ioport32_t *port, uint32_t v)
    8173{
    82         if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
    83                 uintptr_t prt = (uintptr_t) port;
     74        uintptr_t prt = (uintptr_t) port;
    8475
    85                 *((ioport32_t *)(IA64_IOSPACE_ADDRESS +
    86                     ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    87         } else {
    88                 *port = v;
    89         }
     76        *((ioport32_t *)(IA64_IOSPACE_ADDRESS +
     77            ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
    9078
    9179        asm volatile ("mf\n" ::: "memory");
     
    9482static inline uint8_t pio_read_8(ioport8_t *port)
    9583{
    96         uint8_t v;
     84        uintptr_t prt = (uintptr_t) port;
    9785
    9886        asm volatile ("mf\n" ::: "memory");
    9987
    100         if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
    101                 uintptr_t prt = (uintptr_t) port;
    102 
    103                 v = *((ioport8_t *)(IA64_IOSPACE_ADDRESS +
    104                     ((prt & 0xfff) | ((prt >> 2) << 12))));
    105         } else {
    106                 v = *port;
    107         }
    108 
    109         return v;
     88        return *((ioport8_t *)(IA64_IOSPACE_ADDRESS +
     89            ((prt & 0xfff) | ((prt >> 2) << 12))));
    11090}
    11191
    11292static inline uint16_t pio_read_16(ioport16_t *port)
    11393{
    114         uint16_t v;
     94        uintptr_t prt = (uintptr_t) port;
    11595
    11696        asm volatile ("mf\n" ::: "memory");
    11797
    118         if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
    119                 uintptr_t prt = (uintptr_t) port;
    120 
    121                 v = *((ioport16_t *)(IA64_IOSPACE_ADDRESS +
    122                     ((prt & 0xfff) | ((prt >> 2) << 12))));
    123         } else {
    124                 v = *port;
    125         }
    126 
    127         return v;
     98        return *((ioport16_t *)(IA64_IOSPACE_ADDRESS +
     99            ((prt & 0xfff) | ((prt >> 2) << 12))));
    128100}
    129101
    130102static inline uint32_t pio_read_32(ioport32_t *port)
    131103{
    132         uint32_t v;
     104        uintptr_t prt = (uintptr_t) port;
    133105
    134106        asm volatile ("mf\n" ::: "memory");
    135107
    136         if (port < (ioport32_t *) port) {
    137                 uintptr_t prt = (uintptr_t) port;
    138 
    139                 v = *((ioport32_t *)(IA64_IOSPACE_ADDRESS +
    140                     ((prt & 0xfff) | ((prt >> 2) << 12))));
    141         } else {
    142                 v = *port;
    143         }
    144 
    145         return v;
     108        return *((ioport32_t *)(IA64_IOSPACE_ADDRESS +
     109            ((prt & 0xfff) | ((prt >> 2) << 12))));
    146110}
    147111
  • uspace/lib/usb/include/usb/classes/hub.h

    r0f3744d rb69e4c0  
    7272        uint8_t port_count;
    7373        /** Characteristics bitmask. */
    74         uint8_t characteristics;
    75 #define HUB_CHAR_POWER_PER_PORT_FLAG  (1 << 0)
    76 #define HUB_CHAR_NO_POWER_SWITCH_FLAG (1 << 1)
    77         /* Unused part of characteristics field */
    78         uint8_t characteristics_reserved;
     74        uint16_t characteristics;
    7975        /** Time from power-on to stabilization of current on the port. */
    8076        uint8_t power_good_time;
     
    9692
    9793    /** Number of downstream ports that this hub supports */
    98     uint8_t port_count;
     94    uint8_t ports_count;
    9995
    10096    /**
     
    123119     */
    124120    uint16_t hub_characteristics;
     121#define HUB_CHAR_POWER_PER_PORT_FLAG  (1 << 0)
     122#define HUB_CHAR_NO_POWER_SWITCH_FLAG (1 << 1)
    125123
    126124    /**
     
    216214 *      Maximum size of usb hub descriptor in bytes
    217215 */
    218 /* 7 (basic size) + 2*32 (port bitmasks) */
    219 #define USB_HUB_MAX_DESCRIPTOR_SIZE 71
     216extern size_t USB_HUB_MAX_DESCRIPTOR_SIZE;
     217
     218
     219
     220
     221
     222
    220223
    221224#endif
  • uspace/lib/usbdev/include/usb/dev/pipes.h

    r0f3744d rb69e4c0  
    183183int usb_pipe_write(usb_pipe_t *, void *, size_t);
    184184
    185 int usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
     185int usb_pipe_control_read(usb_pipe_t *, void *, size_t,
    186186    void *, size_t, size_t *);
    187187int usb_pipe_control_write(usb_pipe_t *, void *, size_t,
  • uspace/lib/usbdev/src/pipesio.c

    r0f3744d rb69e4c0  
    328328 */
    329329static int usb_pipe_control_read_no_check(usb_pipe_t *pipe,
    330     const void *setup_buffer, size_t setup_buffer_size,
     330    void *setup_buffer, size_t setup_buffer_size,
    331331    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
    332332{
     
    411411 */
    412412int usb_pipe_control_read(usb_pipe_t *pipe,
    413     const void *setup_buffer, size_t setup_buffer_size,
     413    void *setup_buffer, size_t setup_buffer_size,
    414414    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
    415415{
  • uspace/lib/usbhid/src/hidpath.c

    r0f3744d rb69e4c0  
    7676                                    int32_t usage_page, int32_t usage)
    7777{       
    78         usb_hid_report_usage_path_t *item
    79                 = malloc(sizeof(usb_hid_report_usage_path_t));
    80 
    81         if (item == NULL) {
     78        usb_hid_report_usage_path_t *item;
     79
     80        if(!(item=malloc(sizeof(usb_hid_report_usage_path_t)))) {
    8281                return ENOMEM;
    8382        }
  • uspace/srv/fs/mfs/mfs_ops.c

    r0f3744d rb69e4c0  
    143143{
    144144        enum cache_mode cmode;
    145         struct mfs_superblock *sb = NULL;
    146         struct mfs3_superblock *sb3 = NULL;
    147         struct mfs_sb_info *sbi = NULL;
    148         struct mfs_instance *instance = NULL;
     145        struct mfs_superblock *sb;
     146        struct mfs3_superblock *sb3;
     147        struct mfs_sb_info *sbi;
     148        struct mfs_instance *instance;
    149149        bool native, longnames;
    150150        mfs_version_t version;
     
    166166        sbi = malloc(sizeof(*sbi));
    167167        if (!sbi) {
    168                 rc = ENOMEM;
    169                 goto out_error;
     168                block_fini(service_id);
     169                return ENOMEM;
    170170        }
    171171
     
    173173        instance = malloc(sizeof(*instance));
    174174        if (!instance) {
    175                 rc = ENOMEM;
    176                 goto out_error;
     175                free(sbi);
     176                block_fini(service_id);
     177                return ENOMEM;
    177178        }
    178179
    179180        sb = malloc(MFS_SUPERBLOCK_SIZE);
    180181        if (!sb) {
    181                 rc = ENOMEM;
    182                 goto out_error;
     182                free(instance);
     183                free(sbi);
     184                block_fini(service_id);
     185                return ENOMEM;
    183186        }
    184187
    185188        /* Read the superblock */
    186189        rc = block_read_direct(service_id, MFS_SUPERBLOCK << 1, 2, sb);
    187         if (rc != EOK)
    188                 goto out_error;
     190        if (rc != EOK) {
     191                free(instance);
     192                free(sbi);
     193                free(sb);
     194                block_fini(service_id);
     195                return rc;
     196        }
    189197
    190198        sb3 = (struct mfs3_superblock *) sb;
     
    199207                /*Not recognized*/
    200208                mfsdebug("magic number not recognized\n");
    201                 rc = ENOTSUP;
    202                 goto out_error;
     209                free(instance);
     210                free(sbi);
     211                free(sb);
     212                block_fini(service_id);
     213                return ENOTSUP;
    203214        }
    204215
     
    245256                                    MFS_MAX_NAME_LEN;
    246257        }
    247 
    248         if (sbi->log2_zone_size != 0) {
    249                 /* In MFS, file space is allocated per zones.
    250                  * Zones are a collection of consecutive blocks on disk.
    251                  *
    252                  * The current MFS implementation supports only filesystems
    253                  * where the size of a zone is equal to the
    254                  * size of a block.
    255                  */
    256                 rc = ENOTSUP;
    257                 goto out_error;
    258         }
    259 
    260258        sbi->itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks;
     259
     260        free(sb);
    261261
    262262        rc = block_cache_init(service_id, sbi->block_size, 0, cmode);
    263263        if (rc != EOK) {
     264                free(instance);
     265                free(sbi);
     266                block_cache_fini(service_id);
     267                block_fini(service_id);
    264268                mfsdebug("block cache initialization failed\n");
    265                 rc = EINVAL;
    266                 goto out_error;
     269                return EINVAL;
    267270        }
    268271
     
    292295        *linkcnt = 1;
    293296
    294         free(sb);
    295 
    296297        return mfs_node_put(fn);
    297 
    298 out_error:
    299         block_fini(service_id);
    300         if (sb)
    301                 free(sb);
    302         if (sbi)
    303                 free(sbi);
    304         if(instance)
    305                 free(instance);
    306         return rc;
    307298}
    308299
     
    889880        struct mfs_ino_info *ino_i = mnode->ino_i;
    890881        const size_t bs = sbi->block_size;
    891         size_t bytes = min(len, bs - (pos % bs));
     882        size_t bytes = min(len, bs - pos % bs);
     883        size_t boundary = ROUND_UP(ino_i->i_size, bs);
    892884        uint32_t block;
    893885
     
    895887                flags = BLOCK_FLAGS_NOREAD;
    896888
    897         r = mfs_read_map(&block, mnode, pos);
    898         if (r != EOK)
    899                 goto out_err;
    900 
    901         if (block == 0) {
    902                 /*Writing in a sparse block*/
     889        if (pos < boundary) {
     890                r = mfs_read_map(&block, mnode, pos);
     891                if (r != EOK)
     892                        goto out_err;
     893
     894                if (block == 0) {
     895                        /*Writing in a sparse block*/
     896                        r = mfs_alloc_zone(mnode->instance, &block);
     897                        if (r != EOK)
     898                                goto out_err;
     899                        flags = BLOCK_FLAGS_NOREAD;
     900                }
     901        } else {
    903902                uint32_t dummy;
    904903
     
    906905                if (r != EOK)
    907906                        goto out_err;
    908                
     907
    909908                r = mfs_write_map(mnode, pos, block, &dummy);
    910909                if (r != EOK)
    911910                        goto out_err;
    912 
    913                 flags = BLOCK_FLAGS_NOREAD;
    914911        }
    915912
     
    919916                goto out_err;
    920917
    921         if (flags == BLOCK_FLAGS_NOREAD)
    922                 memset(b->data, 0, sbi->block_size);
    923 
    924         async_data_write_finalize(callid, b->data + (pos % bs), bytes);
     918        async_data_write_finalize(callid, b->data + pos % bs, bytes);
    925919        b->dirty = true;
    926920
     
    931925        }
    932926
    933         if (pos + bytes > ino_i->i_size) {
    934                 ino_i->i_size = pos + bytes;
    935                 ino_i->dirty = true;
    936         }
     927        ino_i->i_size = pos + bytes;
     928        ino_i->dirty = true;
    937929        r = mfs_node_put(fn);
    938         *nsize = ino_i->i_size;
     930        *nsize = pos + bytes;
    939931        *wbytes = bytes;
    940932        return r;
  • uspace/srv/fs/mfs/mfs_rw.c

    r0f3744d rb69e4c0  
    3131 */
    3232
    33 #include <align.h>
    3433#include "mfs.h"
    3534
     
    7170        int rblock = pos / block_size;
    7271
    73         if (ROUND_UP(mnode->ino_i->i_size, sbi->block_size) < pos) {
     72        if (mnode->ino_i->i_size < pos) {
    7473                /*Trying to read beyond the end of file*/
    7574                r = EOK;
  • uspace/srv/hid/console/console.c

    r0f3744d rb69e4c0  
    344344}
    345345
    346 static console_t *cons_get_active_uspace(void)
    347 {
    348         fibril_mutex_lock(&switch_mtx);
    349 
    350         console_t *active_uspace = active_console;
    351         if (active_uspace == kernel_console) {
    352                 active_uspace = prev_console;
    353         }
    354         assert(active_uspace != kernel_console);
    355 
    356         fibril_mutex_unlock(&switch_mtx);
    357 
    358         return active_uspace;
    359 }
    360 
    361346static ssize_t limit(ssize_t val, ssize_t lo, ssize_t hi)
    362347{
     
    481466                                event->c = c;
    482467                               
    483                                 /* Kernel console does not read events
    484                                  * from us, so we will redirect them
    485                                  * to the (last) active userspace console
    486                                  * if necessary.
    487                                  */
    488                                 console_t *target_console = cons_get_active_uspace();
    489 
    490                                 prodcons_produce(&target_console->input_pc,
    491                                     &event->link);
     468                                prodcons_produce(&active_console->input_pc, &event->link);
    492469                        }
    493470                       
     
    927904                atomic_set(&consoles[i].refcnt, 0);
    928905                fibril_mutex_initialize(&consoles[i].mtx);
    929                 prodcons_initialize(&consoles[i].input_pc);
    930906               
    931907                if (graphics_state == GRAPHICS_FULL) {
     
    966942                }
    967943               
     944                prodcons_initialize(&consoles[i].input_pc);
    968945                cons_redraw_state(&consoles[i]);
    969946               
  • uspace/srv/hw/irc/apic/apic.c

    r0f3744d rb69e4c0  
    206206        }
    207207
    208         int rc = pio_enable((void *) IO_APIC_BASE, IO_APIC_SIZE,
    209                 (void **) &io_apic);
    210         if (rc != EOK) {
    211                 printf("%s: Failed to enable PIO for APIC: %d\n", NAME, rc);
     208        if (pio_enable((void *) IO_APIC_BASE, IO_APIC_SIZE,
     209            (void **) &io_apic) != EOK)
    212210                return false;   
    213         }
    214211       
    215212        async_set_client_connection(apic_connection);
Note: See TracChangeset for help on using the changeset viewer.