Changeset 5828554 in mainline for uspace/lib


Ignore:
Timestamp:
2014-01-19T14:37:22Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cf982ff
Parents:
2f591127 (diff), 476f62c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge mainline changes

Location:
uspace/lib
Files:
47 added
6 deleted
65 edited
20 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    r2f591127 r5828554  
    6161        generic/bd.c \
    6262        generic/bd_srv.c \
    63         generic/bitops.c \
    6463        generic/cap.c \
    6564        generic/cfg.c \
     
    7069        generic/device/hw_res_parsed.c \
    7170        generic/device/pio_window.c \
    72         generic/device/char_dev.c \
    7371        generic/device/clock_dev.c \
    74         generic/device/battery_dev.c \
    75         generic/device/graph_dev.c \
    76         generic/device/nic.c \
    77         generic/device/pci.c \
    78         generic/device/ahci.c \
    7972        generic/dhcp.c \
    8073        generic/dnsr.c \
     
    108101        generic/io/log.c \
    109102        generic/io/logctl.c \
     103        generic/io/kio.c \
    110104        generic/io/klog.c \
    111105        generic/io/snprintf.c \
     
    129123        generic/loader.c \
    130124        generic/getopt.c \
     125        generic/adt/checksum.c \
    131126        generic/adt/list.c \
    132127        generic/adt/hash_table.c \
     
    143138        generic/net/socket_client.c \
    144139        generic/net/socket_parse.c \
     140        generic/setjmp.c \
    145141        generic/stack.c \
    146142        generic/stacktrace.c \
  • uspace/lib/c/arch/abs32le/include/libarch/atomic.h

    r2f591127 r5828554  
    5353}
    5454
    55 static inline void atomic_inc(atomic_t *val) {
     55static inline void atomic_inc(atomic_t *val)
     56{
    5657        /* On real hardware the increment has to be done
    5758           as an atomic action. */
     
    6061}
    6162
    62 static inline void atomic_dec(atomic_t *val) {
     63static inline void atomic_dec(atomic_t *val)
     64{
    6365        /* On real hardware the decrement has to be done
    6466           as an atomic action. */
  • uspace/lib/c/arch/amd64/_link.ld.in

    r2f591127 r5828554  
    3939        .data : {
    4040                *(.data);
     41                *(.data.rel*);
    4142        } :data
    4243       
  • uspace/lib/c/arch/ia32/Makefile.inc

    r2f591127 r5828554  
    3434        arch/$(UARCH)/src/fibril.S \
    3535        arch/$(UARCH)/src/tls.c \
    36         arch/$(UARCH)/src/setjmp.S \
    3736        arch/$(UARCH)/src/stacktrace.c \
    3837        arch/$(UARCH)/src/stacktrace_asm.S \
  • uspace/lib/c/arch/sparc32/src/stacktrace_asm.S

    r2f591127 r5828554  
    11#
    2 # Copyright (c) 2008 Josef Cejka
     2# Copyright (c) 2009 Jakub Jermar
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 #include <libarch/context_offset.h>
     29#include <libarch/stack.h>
    3030
    3131.text
    32 .global setjmp
    33 .global longjmp
    3432
    35 .type setjmp,@function
    36 setjmp:
    37         movl 0(%esp), %eax  # save pc value into eax
    38         movl 4(%esp), %edx  # address of the jmp_buf structure to save context to
     33.global stacktrace_prepare
     34.global stacktrace_fp_get
     35.global stacktrace_pc_get
     36
     37stacktrace_prepare:
     38        save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE+STACK_ARG_SAVE_AREA_SIZE), %sp
    3939       
    40         # save registers to the jmp_buf structure
    41         CONTEXT_SAVE_ARCH_CORE %edx %eax
     40        # Flush all other windows to memory so that we can read their contents.
    4241       
    43         xorl %eax, %eax     # set_jmp returns 0
     42        mov 7, %g1
     43        1:
     44                subcc %g1, 1, %g1
     45                bg 1b
     46                save %sp, -64, %sp
     47       
     48        mov 7, %g1
     49        1:
     50                subcc %g1, 1, %g1
     51                bg 1b
     52       
    4453        ret
     54        restore
    4555
    46 .type longjmp,@function
    47 longjmp:
    48         movl 4(%esp), %ecx  # put address of jmp_buf into ecx
    49         movl 8(%esp), %eax  # put return value into eax
    50        
    51         # restore registers from the jmp_buf structure
    52         CONTEXT_RESTORE_ARCH_CORE %ecx %edx
    53        
    54         movl %edx, 0(%esp)  # put saved pc on stack
    55         ret
     56stacktrace_fp_get:
     57        # Add the stack bias to %sp to get the actual address.
     58        retl
     59        mov %sp,  %o0
     60
     61stacktrace_pc_get:
     62        retl
     63        mov %o7, %o0
  • uspace/lib/c/generic/assert.c

    r2f591127 r5828554  
    3333#include <assert.h>
    3434#include <stdio.h>
    35 #include <io/klog.h>
     35#include <io/kio.h>
    3636#include <stdlib.h>
    3737#include <atomic.h>
     
    4444{
    4545        /*
    46          * Send the message safely to klog. Nested asserts should not occur.
     46         * Send the message safely to kio. Nested asserts should not occur.
    4747         */
    48         klog_printf("Assertion failed (%s) in file \"%s\", line %u.\n",
     48        kio_printf("Assertion failed (%s) in file \"%s\", line %u.\n",
    4949            cond, file, line);
    5050       
  • uspace/lib/c/generic/ddi.c

    r2f591127 r5828554  
    280280 *
    281281 */
    282 int irq_register(int inr, int devno, int method, irq_code_t *ucode)
     282int irq_register(int inr, int devno, int method, const irq_code_t *ucode)
    283283{
    284284        return __SYSCALL4(SYS_IRQ_REGISTER, inr, devno, method,
  • uspace/lib/c/generic/io/io.c

    r2f591127 r5828554  
    4242#include <malloc.h>
    4343#include <async.h>
    44 #include <io/klog.h>
     44#include <io/kio.h>
    4545#include <vfs/vfs.h>
    4646#include <vfs/vfs_sess.h>
     
    5757        .error = true,
    5858        .eof = true,
    59         .klog = false,
     59        .kio = false,
    6060        .sess = NULL,
    6161        .btype = _IONBF,
     
    6767};
    6868
    69 static FILE stdout_klog = {
     69static FILE stdout_kio = {
    7070        .fd = -1,
    7171        .error = false,
    7272        .eof = false,
    73         .klog = true,
     73        .kio = true,
    7474        .sess = NULL,
    7575        .btype = _IOLBF,
     
    8181};
    8282
    83 static FILE stderr_klog = {
     83static FILE stderr_kio = {
    8484        .fd = -1,
    8585        .error = false,
    8686        .eof = false,
    87         .klog = true,
     87        .kio = true,
    8888        .sess = NULL,
    8989        .btype = _IONBF,
     
    113113                stdout = fdopen(1, "w");
    114114        } else {
    115                 stdout = &stdout_klog;
     115                stdout = &stdout_kio;
    116116                list_append(&stdout->link, &files);
    117117        }
     
    120120                stderr = fdopen(2, "w");
    121121        } else {
    122                 stderr = &stderr_klog;
     122                stderr = &stderr_kio;
    123123                list_append(&stderr->link, &files);
    124124        }
     
    267267        stream->error = false;
    268268        stream->eof = false;
    269         stream->klog = false;
     269        stream->kio = false;
    270270        stream->sess = NULL;
    271271        stream->need_sync = false;
     
    289289        stream->error = false;
    290290        stream->eof = false;
    291         stream->klog = false;
     291        stream->kio = false;
    292292        stream->sess = NULL;
    293293        stream->need_sync = false;
     
    314314       
    315315        if ((stream != &stdin_null)
    316             && (stream != &stdout_klog)
    317             && (stream != &stderr_klog))
     316            && (stream != &stdout_kio)
     317            && (stream != &stderr_kio))
    318318                free(stream);
    319319       
     
    382382                ssize_t wr;
    383383               
    384                 if (stream->klog)
    385                         wr = klog_write(buf + done, left);
     384                if (stream->kio)
     385                        wr = kio_write(buf + done, left);
    386386                else
    387387                        wr = write(stream->fd, buf + done, left);
     
    705705        _fflushbuf(stream);
    706706       
    707         if (stream->klog) {
    708                 klog_update();
     707        if (stream->kio) {
     708                kio_update();
    709709                return EOK;
    710710        }
     
    740740int fileno(FILE *stream)
    741741{
    742         if (stream->klog) {
     742        if (stream->kio) {
    743743                errno = EBADF;
    744744                return -1;
  • uspace/lib/c/generic/io/klog.c

    r2f591127 r5828554  
    11/*
    2  * Copyright (c) 2006 Josef Cejka
    3  * Copyright (c) 2006 Jakub Vana
     2 * Copyright (c) 2013 Martin Sucha
    43 * All rights reserved.
    54 *
     
    4140#include <abi/klog.h>
    4241#include <io/klog.h>
    43 #include <io/printf_core.h>
     42#include <abi/log.h>
    4443
    45 size_t klog_write(const void *buf, size_t size)
     44size_t klog_write(log_level_t lvl, const void *buf, size_t size)
    4645{
    47         ssize_t ret = (ssize_t) __SYSCALL3(SYS_KLOG, KLOG_WRITE, (sysarg_t) buf, size);
     46        ssize_t ret = (ssize_t) __SYSCALL4(SYS_KLOG, KLOG_WRITE, (sysarg_t) buf,
     47            size, lvl);
    4848       
    4949        if (ret >= 0)
     
    5353}
    5454
    55 void klog_update(void)
     55int klog_read(void *data, size_t size)
    5656{
    57         (void) __SYSCALL3(SYS_KLOG, KLOG_UPDATE, (uintptr_t) NULL, 0);
    58 }
    59 
    60 void klog_command(const void *buf, size_t size)
    61 {
    62         (void) __SYSCALL3(SYS_KLOG, KLOG_COMMAND, (sysarg_t) buf, (sysarg_t) size);
    63 }
    64 
    65 /** Print formatted text to klog.
    66  *
    67  * @param fmt Format string
    68  *
    69  * \see For more details about format string see printf_core.
    70  *
    71  */
    72 int klog_printf(const char *fmt, ...)
    73 {
    74         va_list args;
    75         va_start(args, fmt);
    76        
    77         int ret = klog_vprintf(fmt, args);
    78        
    79         va_end(args);
    80        
    81         return ret;
    82 }
    83 
    84 static int klog_vprintf_str_write(const char *str, size_t size, void *data)
    85 {
    86         size_t wr = klog_write(str, size);
    87         return str_nlength(str, wr);
    88 }
    89 
    90 static int klog_vprintf_wstr_write(const wchar_t *str, size_t size, void *data)
    91 {
    92         size_t offset = 0;
    93         size_t chars = 0;
    94        
    95         while (offset < size) {
    96                 char buf[STR_BOUNDS(1)];
    97                 size_t sz = 0;
    98                
    99                 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK)
    100                         klog_write(buf, sz);
    101                
    102                 chars++;
    103                 offset += sizeof(wchar_t);
    104         }
    105        
    106         return chars;
    107 }
    108 
    109 /** Print formatted text to klog.
    110  *
    111  * @param fmt Format string
    112  * @param ap  Format parameters
    113  *
    114  * \see For more details about format string see printf_core.
    115  *
    116  */
    117 int klog_vprintf(const char *fmt, va_list ap)
    118 {
    119         printf_spec_t ps = {
    120                 klog_vprintf_str_write,
    121                 klog_vprintf_wstr_write,
    122                 NULL
    123         };
    124        
    125         return printf_core(fmt, &ps, ap);
     57        return (int) __SYSCALL4(SYS_KLOG, KLOG_READ, (uintptr_t) data, size, 0);
    12658}
    12759
  • uspace/lib/c/generic/io/window.c

    r2f591127 r5828554  
    4040#include <stdio.h>
    4141
    42 int win_register(async_sess_t *sess, service_id_t *in, service_id_t *out,
    43     sysarg_t x_offset, sysarg_t y_offset)
     42int win_register(async_sess_t *sess, service_id_t *in, service_id_t *out)
    4443{
    4544        async_exch_t *exch = async_exchange_begin(sess);
    46         int ret = async_req_2_2(exch, WINDOW_REGISTER, x_offset, y_offset, in, out);
     45        int ret = async_req_0_2(exch, WINDOW_REGISTER, in, out);
    4746        async_exchange_end(exch);
    48 
     47       
    4948        return ret;
    5049}
     
    9291}
    9392
    94 int win_resize(async_sess_t *sess, sysarg_t width, sysarg_t height, void *cells)
     93int win_resize(async_sess_t *sess, sysarg_t x, sysarg_t y, sysarg_t width,
     94    sysarg_t height, window_placement_flags_t placement_flags, void *cells)
    9595{
    9696        async_exch_t *exch = async_exchange_begin(sess);
    97 
     97       
    9898        ipc_call_t answer;
    99         aid_t req = async_send_2(exch, WINDOW_RESIZE, width, height, &answer);
    100 
     99        aid_t req = async_send_5(exch, WINDOW_RESIZE, x, y, width, height,
     100            (sysarg_t) placement_flags, &answer);
     101       
    101102        int rc = async_share_out_start(exch, cells, AS_AREA_READ | AS_AREA_CACHEABLE);
    102 
     103       
    103104        async_exchange_end(exch);
    104 
     105       
    105106        sysarg_t ret;
    106107        async_wait_for(req, &ret);
    107 
    108         if (rc != EOK) {
     108       
     109        if (rc != EOK)
    109110                return rc;
    110         } else if (ret != EOK) {
     111        else if (ret != EOK)
    111112                return ret;
    112         } else {
    113                 return EOK;
    114         }
     113       
     114        return EOK;
    115115}
    116116
  • uspace/lib/c/generic/private/stdio.h

    r2f591127 r5828554  
    5353        int eof;
    5454       
    55         /** Klog indicator */
    56         int klog;
     55        /** KIO indicator */
     56        int kio;
    5757       
    5858        /** Session to the file provider */
  • uspace/lib/c/include/bitops.h

    r2f591127 r5828554  
    107107}
    108108
    109 extern int __popcountsi2(int);
    110 
    111109#endif
    112110
  • uspace/lib/c/include/ddi.h

    r2f591127 r5828554  
    130130}
    131131
    132 extern int irq_register(int, int, int, irq_code_t *);
     132extern int irq_register(int, int, int, const irq_code_t *);
    133133extern int irq_unregister(int, int);
    134134
  • uspace/lib/c/include/io/klog.h

    r2f591127 r5828554  
    11/*
    2  * Copyright (c) 2006 Jakub Vana
     2 * Copyright (c) 2013 Martin Sucha
    33 * All rights reserved.
    44 *
     
    3939#include <stdarg.h>
    4040#include <io/verify.h>
     41#include <stdio.h>
     42#include <stdlib.h>
     43#include <str.h>
     44#include <abi/log.h>
    4145
    42 extern size_t klog_write(const void *, size_t);
    43 extern void klog_update(void);
    44 extern void klog_command(const void *, size_t);
    45 extern int klog_printf(const char *, ...)
    46     PRINTF_ATTRIBUTE(1, 2);
    47 extern int klog_vprintf(const char *, va_list);
     46extern size_t klog_write(log_level_t, const void *, size_t);
     47extern int klog_read(void *, size_t);
     48
     49#define KLOG_PRINTF(lvl, fmt, ...) ({ \
     50        char *_fmt = str_dup(fmt); \
     51        size_t _fmtsize = str_size(_fmt); \
     52        if (_fmtsize > 0 && _fmt[_fmtsize - 1] == '\n') \
     53                _fmt[_fmtsize - 1] = 0; \
     54        char *_s; \
     55        int _c = asprintf(&_s, _fmt, ##__VA_ARGS__); \
     56        free(_fmt); \
     57        if (_c >= 0) { \
     58                _c = klog_write((lvl), _s, str_size(_s)); \
     59                free(_s); \
     60        }; \
     61        (_c >= 0); \
     62})
    4863
    4964#endif
  • uspace/lib/c/include/io/log.h

    r2f591127 r5828554  
    3939#include <io/verify.h>
    4040
    41 /** Log message level. */
    42 typedef enum {
    43         /** Fatal error, program is not able to recover at all. */
    44         LVL_FATAL,
    45         /** Serious error but the program can recover from it. */
    46         LVL_ERROR,
    47         /** Easily recoverable problem. */
    48         LVL_WARN,
    49         /** Information message that ought to be printed by default. */
    50         LVL_NOTE,
    51         /** Debugging purpose message. */
    52         LVL_DEBUG,
    53         /** More detailed debugging message. */
    54         LVL_DEBUG2,
    55        
    56         /** For checking range of values */
    57         LVL_LIMIT
    58 } log_level_t;
     41#include <abi/log.h>
    5942
    6043/** Log itself (logging target). */
  • uspace/lib/c/include/io/window.h

    r2f591127 r5828554  
    4343#include <io/pos_event.h>
    4444
     45typedef enum {
     46        GF_EMPTY = 0,
     47        GF_MOVE_X = 1,
     48        GF_MOVE_Y = 2,
     49        GF_RESIZE_X = 4,
     50        GF_RESIZE_Y = 8,
     51        GF_SCALE_X = 16,
     52        GF_SCALE_Y = 32
     53} window_grab_flags_t;
     54
     55typedef enum {
     56        WINDOW_PLACEMENT_ANY = 0,
     57        WINDOW_PLACEMENT_CENTER_X = 1,
     58        WINDOW_PLACEMENT_CENTER_Y = 2,
     59        WINDOW_PLACEMENT_CENTER =
     60            WINDOW_PLACEMENT_CENTER_X | WINDOW_PLACEMENT_CENTER_Y,
     61        WINDOW_PLACEMENT_LEFT = 4,
     62        WINDOW_PLACEMENT_RIGHT = 8,
     63        WINDOW_PLACEMENT_TOP = 16,
     64        WINDOW_PLACEMENT_BOTTOM = 32,
     65        WINDOW_PLACEMENT_ABSOLUTE_X = 64,
     66        WINDOW_PLACEMENT_ABSOLUTE_Y = 128,
     67        WINDOW_PLACEMENT_ABSOLUTE =
     68            WINDOW_PLACEMENT_ABSOLUTE_X | WINDOW_PLACEMENT_ABSOLUTE_Y
     69} window_placement_flags_t;
     70
    4571typedef struct {
    4672        sysarg_t object;
    4773        sysarg_t slot;
    4874        sysarg_t argument;
    49 } sig_event_t;
     75} signal_event_t;
    5076
    5177typedef struct {
     78        sysarg_t offset_x;
     79        sysarg_t offset_y;
    5280        sysarg_t width;
    5381        sysarg_t height;
    54 } rsz_event_t;
     82        window_placement_flags_t placement_flags;
     83} resize_event_t;
    5584
    5685typedef enum {
     
    6998        kbd_event_t kbd;
    7099        pos_event_t pos;
    71         sig_event_t sig;
    72         rsz_event_t rsz;
     100        signal_event_t signal;
     101        resize_event_t resize;
    73102} window_event_data_t;
    74103
     
    79108} window_event_t;
    80109
    81 typedef enum {
    82         GF_EMPTY = 0,
    83         GF_MOVE_X = 1,
    84         GF_MOVE_Y = 2,
    85         GF_RESIZE_X = 4,
    86         GF_RESIZE_Y = 8,
    87         GF_SCALE_X = 16,
    88         GF_SCALE_Y = 32
    89 } window_grab_flags_t;
    90 
    91 extern int win_register(async_sess_t *, service_id_t *, service_id_t *, sysarg_t, sysarg_t);
     110extern int win_register(async_sess_t *, service_id_t *, service_id_t *);
    92111
    93112extern int win_get_event(async_sess_t *, window_event_t *);
     
    95114extern int win_damage(async_sess_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t);
    96115extern int win_grab(async_sess_t *, sysarg_t, sysarg_t);
    97 extern int win_resize(async_sess_t *, sysarg_t, sysarg_t, void *);
     116extern int win_resize(async_sess_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
     117    window_placement_flags_t, void *);
    98118extern int win_close(async_sess_t *);
    99119extern int win_close_request(async_sess_t *);
  • uspace/lib/c/include/setjmp.h

    r2f591127 r5828554  
    11/*
    22 * Copyright (c) 2008 Josef Cejka
     3 * Copyright (c) 2013 Vojtech Horky
    34 * All rights reserved.
    45 *
     
    3031 * @{
    3132 */
    32 /** @file
     33/** @file Long jump implementation.
     34 *
     35 * Implementation inspired by Jiri Zarevucky's code from
     36 * http://bazaar.launchpad.net/~zarevucky-jiri/helenos/stdc/revision/1544/uspace/lib/posix/setjmp.h
    3337 */
    3438
     
    3842#include <libarch/fibril.h>
    3943
    40 typedef context_t jmp_buf[1];
     44struct jmp_buf_interal {
     45        context_t context;
     46        int return_value;
     47};
     48typedef struct jmp_buf_interal jmp_buf[1];
    4149
    42 extern int setjmp(jmp_buf env);
     50/*
     51 * Specified as extern to minimize number of included headers
     52 * because this file is used as is in libposix too.
     53 */
     54extern int context_save(context_t *ctx) __attribute__((returns_twice));
     55
     56/**
     57 * Save current environment (registers).
     58 *
     59 * This function may return twice.
     60 *
     61 * @param env Variable where to save the environment (of type jmp_buf).
     62 * @return Whether the call returned after longjmp.
     63 * @retval 0 Environment was saved, normal execution.
     64 * @retval other longjmp was executed and returned here.
     65 */
     66#define setjmp(env) \
     67        ((env)[0].return_value = 0, \
     68        context_save(&(env)[0].context), \
     69        (env)[0].return_value)
     70
    4371extern void longjmp(jmp_buf env, int val) __attribute__((noreturn));
    4472
  • uspace/lib/c/include/stdio.h

    r2f591127 r5828554  
    4040#include <str.h>
    4141#include <io/verify.h>
    42 #include <abi/klog.h>
     42#include <abi/kio.h>
    4343
    4444#define EOF  (-1)
     
    5252                int _n = snprintf(_buf, sizeof(_buf), fmt, ##__VA_ARGS__); \
    5353                if (_n > 0) \
    54                         (void) __SYSCALL3(SYS_KLOG, KLOG_WRITE, (sysarg_t) _buf, str_size(_buf)); \
     54                        (void) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) _buf, str_size(_buf)); \
    5555        }
    5656
  • uspace/lib/draw/cursor/embedded.c

    r2f591127 r5828554  
    4646        assert(state_count);
    4747        assert(data);
    48 
     48       
    4949        (*state_count) = 1;
    5050        (*data) = NULL;
     
    5353static surface_t *cde_render(uint8_t state)
    5454{
    55         if (state != 0) {
     55        if (state != 0)
    5656                return NULL;
    57         }
    58 
     57       
    5958        surface_t *surface = surface_create(CURSOR_WIDTH, CURSOR_HEIGHT, NULL, 0);
    60 
    61         if (!surface) {
     59        if (!surface)
    6260                return NULL;
    63         }
    6461       
    6562        for (unsigned int y = 0; y < CURSOR_HEIGHT; ++y) {
     
    6966                        pixel_t pixel = (cursor_texture[offset] & (1 << (x % 8))) ?
    7067                            PIXEL(255, 0, 0, 0) : PIXEL(255, 255, 255, 255);
    71                         surface_put_pixel(surface, x, y, visible ? pixel : PIXEL(0, 0, 0, 0));
     68                       
     69                        if (visible)
     70                                surface_put_pixel(surface, x, y, pixel);
    7271                }
    7372        }
    74 
     73       
    7574        return surface;
    7675}
  • uspace/lib/drv/Makefile

    r2f591127 r5828554  
    2929
    3030USPACE_PREFIX = ../..
    31 EXTRA_CFLAGS = -Iinclude -I$(LIBUSB_PREFIX)/include -I$(LIBPCM_PREFIX)/include
     31EXTRA_CFLAGS = \
     32        -Iinclude \
     33        -Igeneric/private \
     34        -I$(LIBUSB_PREFIX)/include \
     35        -I$(LIBPCM_PREFIX)/include
    3236LIBRARY = libdrv
    3337
  • uspace/lib/drv/generic/dev_iface.c

    r2f591127 r5828554  
    6969                [CLOCK_DEV_IFACE] = &remote_clock_dev_iface,
    7070                [BATTERY_DEV_IFACE] = &remote_battery_dev_iface,
    71                 [AHCI_DEV_IFACE] = &remote_ahci_iface
     71                [AHCI_DEV_IFACE] = &remote_ahci_iface,
    7272        }
    7373};
    7474
    75 remote_iface_t *get_remote_iface(int idx)
     75const remote_iface_t *get_remote_iface(int idx)
    7676{
    7777        assert(is_valid_iface_idx(idx));
     
    8080
    8181remote_iface_func_ptr_t
    82 get_remote_method(remote_iface_t *rem_iface, sysarg_t iface_method_idx)
     82get_remote_method(const remote_iface_t *rem_iface, sysarg_t iface_method_idx)
    8383{
    8484        if (iface_method_idx >= rem_iface->method_count)
  • uspace/lib/drv/generic/driver.c

    r2f591127 r5828554  
    6363
    6464/** Driver structure */
    65 static driver_t *driver;
     65static const driver_t *driver;
    6666
    6767/** Devices */
     
    413413                 * handling ("remote interface").
    414414                 */
    415                 remote_iface_t *rem_iface = get_remote_iface(iface_idx);
     415                const remote_iface_t *rem_iface = get_remote_iface(iface_idx);
    416416                assert(rem_iface != NULL);
    417417               
     
    956956}
    957957
    958 int ddf_driver_main(driver_t *drv)
     958int ddf_driver_main(const driver_t *drv)
    959959{
    960960        /*
  • uspace/lib/drv/generic/interrupt.c

    r2f591127 r5828554  
    3939#include <errno.h>
    4040#include <sys/types.h>
     41#include <macros.h>
    4142
    4243#include "ddf/interrupt.h"
     
    5556static interrupt_context_t *find_interrupt_context(
    5657    interrupt_context_list_t *list, ddf_dev_t *dev, int irq);
    57 int register_interrupt_handler(ddf_dev_t *dev, int irq,
    58     interrupt_handler_t *handler, irq_code_t *pseudocode);
    59 int unregister_interrupt_handler(ddf_dev_t *dev, int irq);
    6058
    6159/** Interrupts */
     
    6866};
    6967
    70 static irq_code_t default_pseudocode = {
     68static const irq_code_t default_pseudocode = {
    7169        0,
    7270        NULL,
    73         sizeof(default_cmds) / sizeof(irq_cmd_t),
     71        ARRAY_SIZE(default_cmds),
    7472        default_cmds
    7573};
     
    169167
    170168int register_interrupt_handler(ddf_dev_t *dev, int irq,
    171     interrupt_handler_t *handler, irq_code_t *pseudocode)
     169    interrupt_handler_t *handler, const irq_code_t *pseudocode)
    172170{
    173171        interrupt_context_t *ctx = create_interrupt_context();
  • uspace/lib/drv/generic/remote_ahci.c

    r2f591127 r5828554  
    3333 */
    3434
     35#include <as.h>
    3536#include <async.h>
     37#include <devman.h>
    3638#include <errno.h>
    3739#include <stdio.h>
     40#include <macros.h>
    3841#include "ahci_iface.h"
    3942#include "ddf/driver.h"
     
    4750} ahci_iface_funcs_t;
    4851
     52#define MAX_NAME_LENGTH  1024
     53
    4954#define LO(ptr) \
    5055        ((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) & 0xffffffff))
     
    5358        ((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) >> 32))
    5459
     60async_sess_t* ahci_get_sess(devman_handle_t funh, char **name)
     61{
     62        // FIXME: Use a better way than substring match
     63       
     64        *name = NULL;
     65       
     66        char devn[MAX_NAME_LENGTH];
     67        int rc = devman_fun_get_name(funh, devn, MAX_NAME_LENGTH);
     68        if (rc != EOK)
     69                return NULL;
     70       
     71        size_t devn_size = str_size(devn);
     72       
     73        if ((devn_size > 5) && (str_lcmp(devn, "ahci_", 5) == 0)) {
     74                async_sess_t *sess = devman_device_connect(EXCHANGE_PARALLEL,
     75                    funh, IPC_FLAG_BLOCKING);
     76               
     77                if (sess) {
     78                        *name = str_dup(devn);
     79                        return sess;
     80                }
     81        }
     82       
     83        return NULL;
     84}
     85
     86int ahci_get_sata_device_name(async_sess_t *sess, size_t sata_dev_name_length,
     87    char *sata_dev_name)
     88{
     89        async_exch_t *exch = async_exchange_begin(sess);
     90        if (!exch)
     91                return EINVAL;
     92       
     93        aid_t req = async_send_2(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
     94            IPC_M_AHCI_GET_SATA_DEVICE_NAME, sata_dev_name_length, NULL);
     95       
     96        async_data_read_start(exch, sata_dev_name, sata_dev_name_length);
     97       
     98        sysarg_t rc;
     99        async_wait_for(req, &rc);
     100       
     101        return rc;
     102}
     103
     104int ahci_get_num_blocks(async_sess_t *sess, uint64_t *blocks)
     105{
     106        async_exch_t *exch = async_exchange_begin(sess);
     107        if (!exch)
     108                return EINVAL;
     109       
     110        sysarg_t blocks_hi;
     111        sysarg_t blocks_lo;
     112        int rc = async_req_1_2(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
     113            IPC_M_AHCI_GET_NUM_BLOCKS, &blocks_hi, &blocks_lo);
     114       
     115        async_exchange_end(exch);
     116       
     117        if (rc == EOK) {
     118                *blocks = (((uint64_t) blocks_hi) << 32)
     119                    | (((uint64_t) blocks_lo) & 0xffffffff);
     120        }
     121       
     122        return rc;
     123}
     124
     125int ahci_get_block_size(async_sess_t *sess, size_t *blocks_size)
     126{
     127        async_exch_t *exch = async_exchange_begin(sess);
     128        if (!exch)
     129                return EINVAL;
     130       
     131        sysarg_t bs;
     132        int rc = async_req_1_1(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
     133            IPC_M_AHCI_GET_BLOCK_SIZE, &bs);
     134       
     135        async_exchange_end(exch);
     136       
     137        if (rc == EOK)
     138                *blocks_size = (size_t) bs;
     139       
     140        return rc;
     141}
     142
     143int ahci_read_blocks(async_sess_t *sess, uint64_t blocknum, size_t count,
     144    void *buf)
     145{
     146        async_exch_t *exch = async_exchange_begin(sess);
     147        if (!exch)
     148                return EINVAL;
     149       
     150        aid_t req;
     151        req = async_send_4(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
     152            IPC_M_AHCI_READ_BLOCKS, HI(blocknum),  LO(blocknum), count, NULL);
     153       
     154        async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE);
     155       
     156        async_exchange_end(exch);
     157       
     158        sysarg_t rc;
     159        async_wait_for(req, &rc);
     160       
     161        return rc;
     162}
     163
     164int ahci_write_blocks(async_sess_t *sess, uint64_t blocknum, size_t count,
     165    void* buf)
     166{
     167        async_exch_t *exch = async_exchange_begin(sess);
     168        if (!exch)
     169                return EINVAL;
     170       
     171        aid_t req = async_send_4(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
     172            IPC_M_AHCI_WRITE_BLOCKS, HI(blocknum),  LO(blocknum), count, NULL);
     173       
     174        async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE);
     175       
     176        async_exchange_end(exch);
     177       
     178        sysarg_t rc;
     179        async_wait_for(req, &rc);
     180       
     181        return rc;
     182}
     183
    55184static void remote_ahci_get_sata_device_name(ddf_fun_t *, void *, ipc_callid_t,
    56185    ipc_call_t *);
     
    65194
    66195/** Remote AHCI interface operations. */
    67 static remote_iface_func_ptr_t remote_ahci_iface_ops [] = {
     196static const remote_iface_func_ptr_t remote_ahci_iface_ops [] = {
    68197        [IPC_M_AHCI_GET_SATA_DEVICE_NAME] = remote_ahci_get_sata_device_name,
    69198        [IPC_M_AHCI_GET_NUM_BLOCKS] = remote_ahci_get_num_blocks,
     
    75204/** Remote AHCI interface structure.
    76205 */
    77 remote_iface_t remote_ahci_iface = {
    78         .method_count = sizeof(remote_ahci_iface_ops) /
    79             sizeof(remote_ahci_iface_ops[0]),
     206const remote_iface_t remote_ahci_iface = {
     207        .method_count = ARRAY_SIZE(remote_ahci_iface_ops),
    80208        .methods = remote_ahci_iface_ops
    81209};
  • uspace/lib/drv/generic/remote_audio_mixer.c

    r2f591127 r5828554  
    3737#include <assert.h>
    3838#include <str.h>
     39#include <macros.h>
    3940
    4041#include "audio_mixer_iface.h"
     
    204205
    205206/** Remote audio mixer interface operations. */
    206 static remote_iface_func_ptr_t remote_audio_mixer_iface_ops[] = {
     207static const remote_iface_func_ptr_t remote_audio_mixer_iface_ops[] = {
    207208        [IPC_M_AUDIO_MIXER_GET_INFO] = remote_audio_mixer_get_info,
    208209        [IPC_M_AUDIO_MIXER_GET_ITEM_INFO] = remote_audio_mixer_get_item_info,
     
    212213
    213214/** Remote audio mixer interface structure. */
    214 remote_iface_t remote_audio_mixer_iface = {
    215         .method_count = sizeof(remote_audio_mixer_iface_ops) /
    216             sizeof(remote_audio_mixer_iface_ops[0]),
     215const remote_iface_t remote_audio_mixer_iface = {
     216        .method_count = ARRAY_SIZE(remote_audio_mixer_iface_ops),
    217217        .methods = remote_audio_mixer_iface_ops
    218218};
  • uspace/lib/drv/generic/remote_audio_pcm.c

    r2f591127 r5828554  
    3838#include <macros.h>
    3939#include <str.h>
    40 #include <as.h>
    4140#include <sys/mman.h>
    4241
     
    611610
    612611/** Remote audio pcm buffer interface operations. */
    613 static remote_iface_func_ptr_t remote_audio_pcm_iface_ops[] = {
     612static const remote_iface_func_ptr_t remote_audio_pcm_iface_ops[] = {
    614613        [IPC_M_AUDIO_PCM_GET_INFO_STR] = remote_audio_pcm_get_info_str,
    615614        [IPC_M_AUDIO_PCM_QUERY_CAPS] = remote_audio_pcm_query_caps,
     
    627626
    628627/** Remote audio mixer interface structure. */
    629 remote_iface_t remote_audio_pcm_iface = {
    630         .method_count = sizeof(remote_audio_pcm_iface_ops) /
    631             sizeof(remote_audio_pcm_iface_ops[0]),
     628const remote_iface_t remote_audio_pcm_iface = {
     629        .method_count = ARRAY_SIZE(remote_audio_pcm_iface_ops),
    632630        .methods = remote_audio_pcm_iface_ops
    633631};
  • uspace/lib/drv/generic/remote_battery_dev.c

    r2f591127 r5828554  
    3636#include <errno.h>
    3737#include <ops/battery_dev.h>
    38 #include <device/battery_dev.h>
     38#include <battery_iface.h>
    3939#include <ddf/driver.h>
     40#include <macros.h>
     41
     42/** Read the current battery status from the device
     43 *
     44 * @param sess     Session of the device
     45 * @param status   Current status of the battery
     46 *
     47 * @return         EOK on success or a negative error code
     48 */
     49int
     50battery_status_get(async_sess_t *sess, battery_status_t *batt_status)
     51{
     52        sysarg_t status;
     53
     54        async_exch_t *exch = async_exchange_begin(sess);
     55
     56        int const rc = async_req_1_1(exch, DEV_IFACE_ID(BATTERY_DEV_IFACE),
     57            BATTERY_STATUS_GET, &status);
     58
     59        async_exchange_end(exch);
     60
     61        if (rc == EOK)
     62                *batt_status = (battery_status_t) status;
     63
     64        return rc;
     65}
     66
     67/** Read the current battery charge level from the device
     68 *
     69 * @param sess     Session of the device
     70 * @param level    Battery charge level (0 - 100)
     71 *
     72 * @return         EOK on success or a negative error code
     73 */
     74int
     75battery_charge_level_get(async_sess_t *sess, int *level)
     76{
     77        sysarg_t charge_level;
     78
     79        async_exch_t *exch = async_exchange_begin(sess);
     80
     81        int const rc = async_req_1_1(exch, DEV_IFACE_ID(BATTERY_DEV_IFACE),
     82            BATTERY_CHARGE_LEVEL_GET, &charge_level);
     83
     84        async_exchange_end(exch);
     85
     86        if (rc == EOK)
     87                *level = (int) charge_level;
     88
     89        return rc;
     90}
    4091
    4192static void remote_battery_status_get(ddf_fun_t *, void *, ipc_callid_t,
     
    4596
    4697/** Remote battery interface operations */
    47 static remote_iface_func_ptr_t remote_battery_dev_iface_ops[] = {
    48         &remote_battery_status_get,
    49         &remote_battery_charge_level_get,
     98static const remote_iface_func_ptr_t remote_battery_dev_iface_ops[] = {
     99        [BATTERY_STATUS_GET] = remote_battery_status_get,
     100        [BATTERY_CHARGE_LEVEL_GET] = remote_battery_charge_level_get,
    50101};
    51102
     
    56107 *
    57108 */
    58 remote_iface_t remote_battery_dev_iface = {
    59         .method_count = sizeof(remote_battery_dev_iface_ops) /
    60             sizeof(remote_iface_func_ptr_t),
     109const remote_iface_t remote_battery_dev_iface = {
     110        .method_count = ARRAY_SIZE(remote_battery_dev_iface_ops),
    61111        .methods = remote_battery_dev_iface_ops,
    62112};
  • uspace/lib/drv/generic/remote_char_dev.c

    r2f591127 r5828554  
    3535#include <async.h>
    3636#include <errno.h>
     37#include <macros.h>
    3738
    3839#include "ops/char_dev.h"
     40#include "char_dev_iface.h"
    3941#include "ddf/driver.h"
    4042
    4143#define MAX_CHAR_RW_COUNT 256
     44
     45/** Read to or write from device.
     46 *
     47 * Helper function to read to or write from a device
     48 * using its character interface.
     49 *
     50 * @param sess Session to the device.
     51 * @param buf  Buffer for the data read from or written to the device.
     52 * @param size Maximum size of data (in bytes) to be read or written.
     53 * @param read Read from the device if true, write to it otherwise.
     54 *
     55 * @return Non-negative number of bytes actually read from or
     56 *         written to the device on success, negative error number
     57 *         otherwise.
     58 *
     59 */
     60static ssize_t char_dev_rw(async_sess_t *sess, void *buf, size_t size, bool read)
     61{
     62        ipc_call_t answer;
     63        aid_t req;
     64        int ret;
     65       
     66        async_exch_t *exch = async_exchange_begin(sess);
     67       
     68        if (read) {
     69                req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE),
     70                    CHAR_DEV_READ, &answer);
     71                ret = async_data_read_start(exch, buf, size);
     72        } else {
     73                req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE),
     74                    CHAR_DEV_WRITE, &answer);
     75                ret = async_data_write_start(exch, buf, size);
     76        }
     77       
     78        async_exchange_end(exch);
     79       
     80        sysarg_t rc;
     81        if (ret != EOK) {
     82                async_wait_for(req, &rc);
     83                if (rc == EOK)
     84                        return (ssize_t) ret;
     85               
     86                return (ssize_t) rc;
     87        }
     88       
     89        async_wait_for(req, &rc);
     90       
     91        ret = (int) rc;
     92        if (ret != EOK)
     93                return (ssize_t) ret;
     94       
     95        return (ssize_t) IPC_GET_ARG1(answer);
     96}
     97
     98/** Read from character device.
     99 *
     100 * @param sess Session to the device.
     101 * @param buf  Output buffer for the data read from the device.
     102 * @param size Maximum size (in bytes) of the data to be read.
     103 *
     104 * @return Non-negative number of bytes actually read from the
     105 *         device on success, negative error number otherwise.
     106 *
     107 */
     108ssize_t char_dev_read(async_sess_t *sess, void *buf, size_t size)
     109{
     110        return char_dev_rw(sess, buf, size, true);
     111}
     112
     113/** Write to character device.
     114 *
     115 * @param sess Session to the device.
     116 * @param buf  Input buffer containg the data to be written to the
     117 *             device.
     118 * @param size Maximum size (in bytes) of the data to be written.
     119 *
     120 * @return Non-negative number of bytes actually written to the
     121 *         device on success, negative error number otherwise.
     122 *
     123 */
     124ssize_t char_dev_write(async_sess_t *sess, void *buf, size_t size)
     125{
     126        return char_dev_rw(sess, buf, size, false);
     127}
    42128
    43129static void remote_char_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     
    45131
    46132/** Remote character interface operations. */
    47 static remote_iface_func_ptr_t remote_char_dev_iface_ops[] = {
    48         &remote_char_read,
    49         &remote_char_write
     133static const remote_iface_func_ptr_t remote_char_dev_iface_ops[] = {
     134        [CHAR_DEV_READ] = remote_char_read,
     135        [CHAR_DEV_WRITE] = remote_char_write
    50136};
    51137
     
    55141 * character interface.
    56142 */
    57 remote_iface_t remote_char_dev_iface = {
    58         .method_count = sizeof(remote_char_dev_iface_ops) /
    59             sizeof(remote_iface_func_ptr_t),
     143const remote_iface_t remote_char_dev_iface = {
     144        .method_count = ARRAY_SIZE(remote_char_dev_iface_ops),
    60145        .methods = remote_char_dev_iface_ops
    61146};
  • uspace/lib/drv/generic/remote_clock_dev.c

    r2f591127 r5828554  
    3636#include <errno.h>
    3737#include <time.h>
     38#include <macros.h>
     39#include <device/clock_dev.h>
    3840
    3941#include <ops/clock_dev.h>
     
    4648
    4749/** Remote clock interface operations */
    48 static remote_iface_func_ptr_t remote_clock_dev_iface_ops[] = {
    49         &remote_clock_time_get,
    50         &remote_clock_time_set,
     50static const remote_iface_func_ptr_t remote_clock_dev_iface_ops[] = {
     51        [CLOCK_DEV_TIME_GET] = remote_clock_time_get,
     52        [CLOCK_DEV_TIME_SET] = remote_clock_time_set,
    5153};
    5254
     
    5658 * addressed by the clock interface.
    5759 */
    58 remote_iface_t remote_clock_dev_iface = {
    59         .method_count = sizeof(remote_clock_dev_iface_ops) /
    60             sizeof(remote_iface_func_ptr_t),
     60const remote_iface_t remote_clock_dev_iface = {
     61        .method_count = ARRAY_SIZE(remote_clock_dev_iface_ops),
    6162        .methods = remote_clock_dev_iface_ops,
    6263};
  • uspace/lib/drv/generic/remote_graph_dev.c

    r2f591127 r5828554  
    3535#include <errno.h>
    3636#include <async.h>
     37#include <macros.h>
    3738
    3839#include "ops/graph_dev.h"
     40#include "graph_iface.h"
    3941#include "ddf/driver.h"
     42
     43typedef enum {
     44        GRAPH_DEV_CONNECT = 0
     45} graph_dev_method_t;
     46
     47int graph_dev_connect(async_sess_t *sess)
     48{
     49        async_exch_t *exch = async_exchange_begin(sess);
     50        int ret = async_req_1_0(exch, DEV_IFACE_ID(GRAPH_DEV_IFACE), GRAPH_DEV_CONNECT);
     51        async_exchange_end(exch);
     52
     53        return ret;
     54}
    4055
    4156static void remote_graph_connect(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    4257
    43 static remote_iface_func_ptr_t remote_graph_dev_iface_ops[] = {
    44         &remote_graph_connect
     58static const remote_iface_func_ptr_t remote_graph_dev_iface_ops[] = {
     59        [GRAPH_DEV_CONNECT] = remote_graph_connect
    4560};
    4661
    47 remote_iface_t remote_graph_dev_iface = {
    48         .method_count = sizeof(remote_graph_dev_iface_ops) /
    49             sizeof(remote_iface_func_ptr_t),
     62const remote_iface_t remote_graph_dev_iface = {
     63        .method_count = ARRAY_SIZE(remote_graph_dev_iface_ops),
    5064        .methods = remote_graph_dev_iface_ops
    5165};
  • uspace/lib/drv/generic/remote_hw_res.c

    r2f591127 r5828554  
    3636#include <async.h>
    3737#include <errno.h>
     38#include <macros.h>
    3839
    3940#include "ops/hw_res.h"
     
    4950    ipc_call_t *);
    5051
    51 static remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
     52static const remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
    5253        [HW_RES_GET_RESOURCE_LIST] = &remote_hw_res_get_resource_list,
    5354        [HW_RES_ENABLE_INTERRUPT] = &remote_hw_res_enable_interrupt,
     
    5657};
    5758
    58 remote_iface_t remote_hw_res_iface = {
    59         .method_count = sizeof(remote_hw_res_iface_ops) /
    60             sizeof(remote_iface_func_ptr_t),
     59const remote_iface_t remote_hw_res_iface = {
     60        .method_count = ARRAY_SIZE(remote_hw_res_iface_ops),
    6161        .methods = remote_hw_res_iface_ops
    6262};
  • uspace/lib/drv/generic/remote_nic.c

    r2f591127 r5828554  
    4040#include <ipc/services.h>
    4141#include <sys/time.h>
     42#include <macros.h>
     43
    4244#include "ops/nic.h"
     45#include "nic_iface.h"
     46
     47typedef enum {
     48        NIC_SEND_MESSAGE = 0,
     49        NIC_CALLBACK_CREATE,
     50        NIC_GET_STATE,
     51        NIC_SET_STATE,
     52        NIC_GET_ADDRESS,
     53        NIC_SET_ADDRESS,
     54        NIC_GET_STATS,
     55        NIC_GET_DEVICE_INFO,
     56        NIC_GET_CABLE_STATE,
     57        NIC_GET_OPERATION_MODE,
     58        NIC_SET_OPERATION_MODE,
     59        NIC_AUTONEG_ENABLE,
     60        NIC_AUTONEG_DISABLE,
     61        NIC_AUTONEG_PROBE,
     62        NIC_AUTONEG_RESTART,
     63        NIC_GET_PAUSE,
     64        NIC_SET_PAUSE,
     65        NIC_UNICAST_GET_MODE,
     66        NIC_UNICAST_SET_MODE,
     67        NIC_MULTICAST_GET_MODE,
     68        NIC_MULTICAST_SET_MODE,
     69        NIC_BROADCAST_GET_MODE,
     70        NIC_BROADCAST_SET_MODE,
     71        NIC_DEFECTIVE_GET_MODE,
     72        NIC_DEFECTIVE_SET_MODE,
     73        NIC_BLOCKED_SOURCES_GET,
     74        NIC_BLOCKED_SOURCES_SET,
     75        NIC_VLAN_GET_MASK,
     76        NIC_VLAN_SET_MASK,
     77        NIC_VLAN_SET_TAG,
     78        NIC_WOL_VIRTUE_ADD,
     79        NIC_WOL_VIRTUE_REMOVE,
     80        NIC_WOL_VIRTUE_PROBE,
     81        NIC_WOL_VIRTUE_LIST,
     82        NIC_WOL_VIRTUE_GET_CAPS,
     83        NIC_WOL_LOAD_INFO,
     84        NIC_OFFLOAD_PROBE,
     85        NIC_OFFLOAD_SET,
     86        NIC_POLL_GET_MODE,
     87        NIC_POLL_SET_MODE,
     88        NIC_POLL_NOW
     89} nic_funcs_t;
     90
     91/** Send frame from NIC
     92 *
     93 * @param[in] dev_sess
     94 * @param[in] data     Frame data
     95 * @param[in] size     Frame size in bytes
     96 *
     97 * @return EOK If the operation was successfully completed
     98 *
     99 */
     100int nic_send_frame(async_sess_t *dev_sess, void *data, size_t size)
     101{
     102        async_exch_t *exch = async_exchange_begin(dev_sess);
     103       
     104        ipc_call_t answer;
     105        aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     106            NIC_SEND_MESSAGE, &answer);
     107        sysarg_t retval = async_data_write_start(exch, data, size);
     108       
     109        async_exchange_end(exch);
     110       
     111        if (retval != EOK) {
     112                async_forget(req);
     113                return retval;
     114        }
     115
     116        async_wait_for(req, &retval);
     117        return retval;
     118}
     119
     120/** Create callback connection from NIC service
     121 *
     122 * @param[in] dev_sess
     123 * @param[in] device_id
     124 *
     125 * @return EOK If the operation was successfully completed
     126 *
     127 */
     128int nic_callback_create(async_sess_t *dev_sess, async_client_conn_t cfun,
     129    void *carg)
     130{
     131        ipc_call_t answer;
     132        int rc;
     133        sysarg_t retval;
     134       
     135        async_exch_t *exch = async_exchange_begin(dev_sess);
     136        aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     137            NIC_CALLBACK_CREATE, &answer);
     138       
     139        rc = async_connect_to_me(exch, 0, 0, 0, cfun, carg);
     140        if (rc != EOK) {
     141                async_forget(req);
     142                return rc;
     143        }
     144        async_exchange_end(exch);
     145       
     146        async_wait_for(req, &retval);
     147        return (int) retval;
     148}
     149
     150/** Get the current state of the device
     151 *
     152 * @param[in]  dev_sess
     153 * @param[out] state    Current state
     154 *
     155 * @return EOK If the operation was successfully completed
     156 *
     157 */
     158int nic_get_state(async_sess_t *dev_sess, nic_device_state_t *state)
     159{
     160        assert(state);
     161       
     162        sysarg_t _state;
     163       
     164        async_exch_t *exch = async_exchange_begin(dev_sess);
     165        int rc = async_req_1_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     166            NIC_GET_STATE, &_state);
     167        async_exchange_end(exch);
     168       
     169        *state = (nic_device_state_t) _state;
     170       
     171        return rc;
     172}
     173
     174/** Request the device to change its state
     175 *
     176 * @param[in] dev_sess
     177 * @param[in] state    New state
     178 *
     179 * @return EOK If the operation was successfully completed
     180 *
     181 */
     182int nic_set_state(async_sess_t *dev_sess, nic_device_state_t state)
     183{
     184        async_exch_t *exch = async_exchange_begin(dev_sess);
     185        int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     186            NIC_SET_STATE, state);
     187        async_exchange_end(exch);
     188       
     189        return rc;
     190}
     191
     192/** Request the MAC address of the device
     193 *
     194 * @param[in]  dev_sess
     195 * @param[out] address  Structure with buffer for the address
     196 *
     197 * @return EOK If the operation was successfully completed
     198 *
     199 */
     200int nic_get_address(async_sess_t *dev_sess, nic_address_t *address)
     201{
     202        assert(address);
     203       
     204        async_exch_t *exch = async_exchange_begin(dev_sess);
     205        aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     206            NIC_GET_ADDRESS, NULL);
     207        int rc = async_data_read_start(exch, address, sizeof(nic_address_t));
     208        async_exchange_end(exch);
     209       
     210        sysarg_t res;
     211        async_wait_for(aid, &res);
     212       
     213        if (rc != EOK)
     214                return rc;
     215       
     216        return (int) res;
     217}
     218
     219/** Set the address of the device (e.g. MAC on Ethernet)
     220 *
     221 * @param[in] dev_sess
     222 * @param[in] address  Pointer to the address
     223 *
     224 * @return EOK If the operation was successfully completed
     225 *
     226 */
     227int nic_set_address(async_sess_t *dev_sess, const nic_address_t *address)
     228{
     229        assert(address);
     230       
     231        async_exch_t *exch = async_exchange_begin(dev_sess);
     232        aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     233            NIC_SET_ADDRESS, NULL);
     234        int rc = async_data_write_start(exch, address, sizeof(nic_address_t));
     235        async_exchange_end(exch);
     236       
     237        sysarg_t res;
     238        async_wait_for(aid, &res);
     239       
     240        if (rc != EOK)
     241                return rc;
     242       
     243        return (int) res;
     244}
     245
     246/** Request statistic data about NIC operation.
     247 *
     248 * @param[in]  dev_sess
     249 * @param[out] stats    Structure with the statistics
     250 *
     251 * @return EOK If the operation was successfully completed
     252 *
     253 */
     254int nic_get_stats(async_sess_t *dev_sess, nic_device_stats_t *stats)
     255{
     256        assert(stats);
     257       
     258        async_exch_t *exch = async_exchange_begin(dev_sess);
     259       
     260        int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     261            NIC_GET_STATS);
     262        if (rc != EOK) {
     263                async_exchange_end(exch);
     264                return rc;
     265        }
     266       
     267        rc = async_data_read_start(exch, stats, sizeof(nic_device_stats_t));
     268       
     269        async_exchange_end(exch);
     270       
     271        return rc;
     272}
     273
     274/** Request information about the device.
     275 *
     276 * @see nic_device_info_t
     277 *
     278 * @param[in]  dev_sess
     279 * @param[out] device_info Information about the device
     280 *
     281 * @return EOK If the operation was successfully completed
     282 *
     283 */
     284int nic_get_device_info(async_sess_t *dev_sess, nic_device_info_t *device_info)
     285{
     286        assert(device_info);
     287       
     288        async_exch_t *exch = async_exchange_begin(dev_sess);
     289       
     290        int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     291            NIC_GET_DEVICE_INFO);
     292        if (rc != EOK) {
     293                async_exchange_end(exch);
     294                return rc;
     295        }
     296       
     297        rc = async_data_read_start(exch, device_info, sizeof(nic_device_info_t));
     298       
     299        async_exchange_end(exch);
     300       
     301        return rc;
     302}
     303
     304/** Request status of the cable (plugged/unplugged)
     305 *
     306 * @param[in]  dev_sess
     307 * @param[out] cable_state Current cable state
     308 *
     309 * @return EOK If the operation was successfully completed
     310 *
     311 */
     312int nic_get_cable_state(async_sess_t *dev_sess, nic_cable_state_t *cable_state)
     313{
     314        assert(cable_state);
     315       
     316        sysarg_t _cable_state;
     317       
     318        async_exch_t *exch = async_exchange_begin(dev_sess);
     319        int rc = async_req_1_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     320            NIC_GET_CABLE_STATE, &_cable_state);
     321        async_exchange_end(exch);
     322       
     323        *cable_state = (nic_cable_state_t) _cable_state;
     324       
     325        return rc;
     326}
     327
     328/** Request current operation mode.
     329 *
     330 * @param[in]  dev_sess
     331 * @param[out] speed    Current operation speed in Mbps. Can be NULL.
     332 * @param[out] duplex   Full duplex/half duplex. Can be NULL.
     333 * @param[out] role     Master/slave/auto. Can be NULL.
     334 *
     335 * @return EOK If the operation was successfully completed
     336 *
     337 */
     338int nic_get_operation_mode(async_sess_t *dev_sess, int *speed,
     339   nic_channel_mode_t *duplex, nic_role_t *role)
     340{
     341        sysarg_t _speed;
     342        sysarg_t _duplex;
     343        sysarg_t _role;
     344       
     345        async_exch_t *exch = async_exchange_begin(dev_sess);
     346        int rc = async_req_1_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     347            NIC_GET_OPERATION_MODE, &_speed, &_duplex, &_role);
     348        async_exchange_end(exch);
     349       
     350        if (speed)
     351                *speed = (int) _speed;
     352       
     353        if (duplex)
     354                *duplex = (nic_channel_mode_t) _duplex;
     355       
     356        if (role)
     357                *role = (nic_role_t) _role;
     358       
     359        return rc;
     360}
     361
     362/** Set current operation mode.
     363 *
     364 * If the NIC has auto-negotiation enabled, this command
     365 * disables auto-negotiation and sets the operation mode.
     366 *
     367 * @param[in] dev_sess
     368 * @param[in] speed    Operation speed in Mbps
     369 * @param[in] duplex   Full duplex/half duplex
     370 * @param[in] role     Master/slave/auto (e.g. in Gbit Ethernet]
     371 *
     372 * @return EOK If the operation was successfully completed
     373 *
     374 */
     375int nic_set_operation_mode(async_sess_t *dev_sess, int speed,
     376    nic_channel_mode_t duplex, nic_role_t role)
     377{
     378        async_exch_t *exch = async_exchange_begin(dev_sess);
     379        int rc = async_req_4_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     380            NIC_SET_OPERATION_MODE, (sysarg_t) speed, (sysarg_t) duplex,
     381            (sysarg_t) role);
     382        async_exchange_end(exch);
     383       
     384        return rc;
     385}
     386
     387/** Enable auto-negotiation.
     388 *
     389 * The advertisement argument can only limit some modes,
     390 * it can never force the NIC to advertise unsupported modes.
     391 *
     392 * The allowed modes are defined in "nic/eth_phys.h" in the C library.
     393 *
     394 * @param[in] dev_sess
     395 * @param[in] advertisement Allowed advertised modes. Use 0 for all modes.
     396 *
     397 * @return EOK If the operation was successfully completed
     398 *
     399 */
     400int nic_autoneg_enable(async_sess_t *dev_sess, uint32_t advertisement)
     401{
     402        async_exch_t *exch = async_exchange_begin(dev_sess);
     403        int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     404            NIC_AUTONEG_ENABLE, (sysarg_t) advertisement);
     405        async_exchange_end(exch);
     406       
     407        return rc;
     408}
     409
     410/** Disable auto-negotiation.
     411 *
     412 * @param[in] dev_sess
     413 *
     414 * @return EOK If the operation was successfully completed
     415 *
     416 */
     417int nic_autoneg_disable(async_sess_t *dev_sess)
     418{
     419        async_exch_t *exch = async_exchange_begin(dev_sess);
     420        int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     421            NIC_AUTONEG_DISABLE);
     422        async_exchange_end(exch);
     423       
     424        return rc;
     425}
     426
     427/** Probe current state of auto-negotiation.
     428 *
     429 * Modes are defined in the "nic/eth_phys.h" in the C library.
     430 *
     431 * @param[in]  dev_sess
     432 * @param[out] our_advertisement   Modes advertised by this NIC.
     433 *                                 Can be NULL.
     434 * @param[out] their_advertisement Modes advertised by the other side.
     435 *                                 Can be NULL.
     436 * @param[out] result              General state of auto-negotiation.
     437 *                                 Can be NULL.
     438 * @param[out]  their_result       State of other side auto-negotiation.
     439 *                                 Can be NULL.
     440 *
     441 * @return EOK If the operation was successfully completed
     442 *
     443 */
     444int nic_autoneg_probe(async_sess_t *dev_sess, uint32_t *our_advertisement,
     445    uint32_t *their_advertisement, nic_result_t *result,
     446    nic_result_t *their_result)
     447{
     448        sysarg_t _our_advertisement;
     449        sysarg_t _their_advertisement;
     450        sysarg_t _result;
     451        sysarg_t _their_result;
     452       
     453        async_exch_t *exch = async_exchange_begin(dev_sess);
     454        int rc = async_req_1_4(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     455            NIC_AUTONEG_PROBE, &_our_advertisement, &_their_advertisement,
     456            &_result, &_their_result);
     457        async_exchange_end(exch);
     458       
     459        if (our_advertisement)
     460                *our_advertisement = (uint32_t) _our_advertisement;
     461       
     462        if (*their_advertisement)
     463                *their_advertisement = (uint32_t) _their_advertisement;
     464       
     465        if (result)
     466                *result = (nic_result_t) _result;
     467       
     468        if (their_result)
     469                *their_result = (nic_result_t) _their_result;
     470       
     471        return rc;
     472}
     473
     474/** Restart the auto-negotiation process.
     475 *
     476 * @param[in] dev_sess
     477 *
     478 * @return EOK If the operation was successfully completed
     479 *
     480 */
     481int nic_autoneg_restart(async_sess_t *dev_sess)
     482{
     483        async_exch_t *exch = async_exchange_begin(dev_sess);
     484        int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     485            NIC_AUTONEG_RESTART);
     486        async_exchange_end(exch);
     487       
     488        return rc;
     489}
     490
     491/** Query party's sending and reception of the PAUSE frame.
     492 *
     493 * @param[in]  dev_sess
     494 * @param[out] we_send    This NIC sends the PAUSE frame (true/false)
     495 * @param[out] we_receive This NIC receives the PAUSE frame (true/false)
     496 * @param[out] pause      The time set to transmitted PAUSE frames.
     497 *
     498 * @return EOK If the operation was successfully completed
     499 *
     500 */
     501int nic_get_pause(async_sess_t *dev_sess, nic_result_t *we_send,
     502    nic_result_t *we_receive, uint16_t *pause)
     503{
     504        sysarg_t _we_send;
     505        sysarg_t _we_receive;
     506        sysarg_t _pause;
     507       
     508        async_exch_t *exch = async_exchange_begin(dev_sess);
     509        int rc = async_req_1_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     510            NIC_GET_PAUSE, &_we_send, &_we_receive, &_pause);
     511        async_exchange_end(exch);
     512       
     513        if (we_send)
     514                *we_send = _we_send;
     515       
     516        if (we_receive)
     517                *we_receive = _we_receive;
     518       
     519        if (pause)
     520                *pause = _pause;
     521       
     522        return rc;
     523}
     524
     525/** Control sending and reception of the PAUSE frame.
     526 *
     527 * @param[in] dev_sess
     528 * @param[in] allow_send    Allow sending the PAUSE frame (true/false)
     529 * @param[in] allow_receive Allow reception of the PAUSE frame (true/false)
     530 * @param[in] pause         Pause length in 512 bit units written
     531 *                          to transmitted frames. The value 0 means
     532 *                          auto value (the best). If the requested
     533 *                          time cannot be set the driver is allowed
     534 *                          to set the nearest supported value.
     535 *
     536 * @return EOK If the operation was successfully completed
     537 *
     538 */
     539int nic_set_pause(async_sess_t *dev_sess, int allow_send, int allow_receive,
     540    uint16_t pause)
     541{
     542        async_exch_t *exch = async_exchange_begin(dev_sess);
     543        int rc = async_req_4_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     544            NIC_SET_PAUSE, allow_send, allow_receive, pause);
     545        async_exchange_end(exch);
     546       
     547        return rc;
     548}
     549
     550/** Retrieve current settings of unicast frames reception.
     551 *
     552 * Note: In case of mode != NIC_UNICAST_LIST the contents of
     553 * address_list and address_count are undefined.
     554 *
     555 * @param[in]   dev_sess
     556 * @param[out]  mode          Current operation mode
     557 * @param[in]   max_count     Maximal number of addresses that could
     558 *                            be written into the list buffer.
     559 * @param[out]  address_list  Buffer for the list (array). Can be NULL.
     560 * @param[out]  address_count Number of addresses in the list before
     561 *                            possible truncation due to the max_count.
     562 *
     563 * @return EOK If the operation was successfully completed
     564 *
     565 */
     566int nic_unicast_get_mode(async_sess_t *dev_sess, nic_unicast_mode_t *mode,
     567    size_t max_count, nic_address_t *address_list, size_t *address_count)
     568{
     569        assert(mode);
     570       
     571        sysarg_t _mode;
     572        sysarg_t _address_count;
     573       
     574        if (!address_list)
     575                max_count = 0;
     576       
     577        async_exch_t *exch = async_exchange_begin(dev_sess);
     578       
     579        int rc = async_req_2_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     580            NIC_UNICAST_GET_MODE, max_count, &_mode, &_address_count);
     581        if (rc != EOK) {
     582                async_exchange_end(exch);
     583                return rc;
     584        }
     585       
     586        *mode = (nic_unicast_mode_t) _mode;
     587        if (address_count)
     588                *address_count = (size_t) _address_count;
     589       
     590        if ((max_count) && (_address_count))
     591                rc = async_data_read_start(exch, address_list,
     592                    max_count * sizeof(nic_address_t));
     593       
     594        async_exchange_end(exch);
     595       
     596        return rc;
     597}
     598
     599/** Set which unicast frames are received.
     600 *
     601 * @param[in] dev_sess
     602 * @param[in] mode          Current operation mode
     603 * @param[in] address_list  The list of addresses. Can be NULL.
     604 * @param[in] address_count Number of addresses in the list.
     605 *
     606 * @return EOK If the operation was successfully completed
     607 *
     608 */
     609int nic_unicast_set_mode(async_sess_t *dev_sess, nic_unicast_mode_t mode,
     610    const nic_address_t *address_list, size_t address_count)
     611{
     612        if (address_list == NULL)
     613                address_count = 0;
     614       
     615        async_exch_t *exch = async_exchange_begin(dev_sess);
     616       
     617        aid_t message_id = async_send_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     618            NIC_UNICAST_SET_MODE, (sysarg_t) mode, address_count, NULL);
     619       
     620        int rc;
     621        if (address_count)
     622                rc = async_data_write_start(exch, address_list,
     623                    address_count * sizeof(nic_address_t));
     624        else
     625                rc = EOK;
     626       
     627        async_exchange_end(exch);
     628       
     629        sysarg_t res;
     630        async_wait_for(message_id, &res);
     631       
     632        if (rc != EOK)
     633                return rc;
     634       
     635        return (int) res;
     636}
     637
     638/** Retrieve current settings of multicast frames reception.
     639 *
     640 * Note: In case of mode != NIC_MULTICAST_LIST the contents of
     641 * address_list and address_count are undefined.
     642 *
     643 * @param[in]  dev_sess
     644 * @param[out] mode          Current operation mode
     645 * @param[in]  max_count     Maximal number of addresses that could
     646 *                           be written into the list buffer.
     647 * @param[out] address_list  Buffer for the list (array). Can be NULL.
     648 * @param[out] address_count Number of addresses in the list before
     649 *                           possible truncation due to the max_count.
     650 *                           Can be NULL.
     651 *
     652 * @return EOK If the operation was successfully completed
     653 *
     654 */
     655int nic_multicast_get_mode(async_sess_t *dev_sess, nic_multicast_mode_t *mode,
     656    size_t max_count, nic_address_t *address_list, size_t *address_count)
     657{
     658        assert(mode);
     659       
     660        sysarg_t _mode;
     661       
     662        if (!address_list)
     663                max_count = 0;
     664       
     665        async_exch_t *exch = async_exchange_begin(dev_sess);
     666       
     667        sysarg_t ac;
     668        int rc = async_req_2_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     669            NIC_MULTICAST_GET_MODE, max_count, &_mode, &ac);
     670        if (rc != EOK) {
     671                async_exchange_end(exch);
     672                return rc;
     673        }
     674       
     675        *mode = (nic_multicast_mode_t) _mode;
     676        if (address_count)
     677                *address_count = (size_t) ac;
     678       
     679        if ((max_count) && (ac))
     680                rc = async_data_read_start(exch, address_list,
     681                    max_count * sizeof(nic_address_t));
     682       
     683        async_exchange_end(exch);
     684        return rc;
     685}
     686
     687/** Set which multicast frames are received.
     688 *
     689 * @param[in] dev_sess
     690 * @param[in] mode          Current operation mode
     691 * @param[in] address_list  The list of addresses. Can be NULL.
     692 * @param[in] address_count Number of addresses in the list.
     693 *
     694 * @return EOK If the operation was successfully completed
     695 *
     696 */
     697int nic_multicast_set_mode(async_sess_t *dev_sess, nic_multicast_mode_t mode,
     698    const nic_address_t *address_list, size_t address_count)
     699{
     700        if (address_list == NULL)
     701                address_count = 0;
     702       
     703        async_exch_t *exch = async_exchange_begin(dev_sess);
     704       
     705        aid_t message_id = async_send_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     706            NIC_MULTICAST_SET_MODE, (sysarg_t) mode, address_count, NULL);
     707       
     708        int rc;
     709        if (address_count)
     710                rc = async_data_write_start(exch, address_list,
     711                    address_count * sizeof(nic_address_t));
     712        else
     713                rc = EOK;
     714       
     715        async_exchange_end(exch);
     716       
     717        sysarg_t res;
     718        async_wait_for(message_id, &res);
     719       
     720        if (rc != EOK)
     721                return rc;
     722       
     723        return (int) res;
     724}
     725
     726/** Determine if broadcast packets are received.
     727 *
     728 * @param[in]  dev_sess
     729 * @param[out] mode     Current operation mode
     730 *
     731 * @return EOK If the operation was successfully completed
     732 *
     733 */
     734int nic_broadcast_get_mode(async_sess_t *dev_sess, nic_broadcast_mode_t *mode)
     735{
     736        assert(mode);
     737       
     738        sysarg_t _mode;
     739       
     740        async_exch_t *exch = async_exchange_begin(dev_sess);
     741        int rc = async_req_1_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     742            NIC_BROADCAST_GET_MODE, &_mode);
     743        async_exchange_end(exch);
     744       
     745        *mode = (nic_broadcast_mode_t) _mode;
     746       
     747        return rc;
     748}
     749
     750/** Set whether broadcast packets are received.
     751 *
     752 * @param[in] dev_sess
     753 * @param[in] mode     Current operation mode
     754 *
     755 * @return EOK If the operation was successfully completed
     756 *
     757 */
     758int nic_broadcast_set_mode(async_sess_t *dev_sess, nic_broadcast_mode_t mode)
     759{
     760        async_exch_t *exch = async_exchange_begin(dev_sess);
     761        int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     762            NIC_BROADCAST_SET_MODE, mode);
     763        async_exchange_end(exch);
     764       
     765        return rc;
     766}
     767
     768/** Determine if defective (erroneous) packets are received.
     769 *
     770 * @param[in]  dev_sess
     771 * @param[out] mode     Bitmask specifying allowed errors
     772 *
     773 * @return EOK If the operation was successfully completed
     774 *
     775 */
     776int nic_defective_get_mode(async_sess_t *dev_sess, uint32_t *mode)
     777{
     778        assert(mode);
     779       
     780        sysarg_t _mode;
     781       
     782        async_exch_t *exch = async_exchange_begin(dev_sess);
     783        int rc = async_req_1_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     784            NIC_DEFECTIVE_GET_MODE, &_mode);
     785        async_exchange_end(exch);
     786       
     787        *mode = (uint32_t) _mode;
     788       
     789        return rc;
     790}
     791
     792/** Set whether defective (erroneous) packets are received.
     793 *
     794 * @param[in]  dev_sess
     795 * @param[out] mode     Bitmask specifying allowed errors
     796 *
     797 * @return EOK If the operation was successfully completed
     798 *
     799 */
     800int nic_defective_set_mode(async_sess_t *dev_sess, uint32_t mode)
     801{
     802        async_exch_t *exch = async_exchange_begin(dev_sess);
     803        int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     804            NIC_DEFECTIVE_SET_MODE, mode);
     805        async_exchange_end(exch);
     806       
     807        return rc;
     808}
     809
     810/** Retrieve the currently blocked source MAC addresses.
     811 *
     812 * @param[in]  dev_sess
     813 * @param[in]  max_count     Maximal number of addresses that could
     814 *                           be written into the list buffer.
     815 * @param[out] address_list  Buffer for the list (array). Can be NULL.
     816 * @param[out] address_count Number of addresses in the list before
     817 *                           possible truncation due to the max_count.
     818 *
     819 * @return EOK If the operation was successfully completed
     820 *
     821 */
     822int nic_blocked_sources_get(async_sess_t *dev_sess, size_t max_count,
     823    nic_address_t *address_list, size_t *address_count)
     824{
     825        if (!address_list)
     826                max_count = 0;
     827       
     828        async_exch_t *exch = async_exchange_begin(dev_sess);
     829       
     830        sysarg_t ac;
     831        int rc = async_req_2_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     832            NIC_BLOCKED_SOURCES_GET, max_count, &ac);
     833        if (rc != EOK) {
     834                async_exchange_end(exch);
     835                return rc;
     836        }
     837       
     838        if (address_count)
     839                *address_count = (size_t) ac;
     840       
     841        if ((max_count) && (ac))
     842                rc = async_data_read_start(exch, address_list,
     843                    max_count * sizeof(nic_address_t));
     844       
     845        async_exchange_end(exch);
     846        return rc;
     847}
     848
     849/** Set which source MACs are blocked
     850 *
     851 * @param[in] dev_sess
     852 * @param[in] address_list  The list of addresses. Can be NULL.
     853 * @param[in] address_count Number of addresses in the list.
     854 *
     855 * @return EOK If the operation was successfully completed
     856 *
     857 */
     858int nic_blocked_sources_set(async_sess_t *dev_sess,
     859    const nic_address_t *address_list, size_t address_count)
     860{
     861        if (address_list == NULL)
     862                address_count = 0;
     863       
     864        async_exch_t *exch = async_exchange_begin(dev_sess);
     865       
     866        aid_t message_id = async_send_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     867            NIC_BLOCKED_SOURCES_SET, address_count, NULL);
     868       
     869        int rc;
     870        if (address_count)
     871                rc = async_data_write_start(exch, address_list,
     872                        address_count * sizeof(nic_address_t));
     873        else
     874                rc = EOK;
     875       
     876        async_exchange_end(exch);
     877       
     878        sysarg_t res;
     879        async_wait_for(message_id, &res);
     880       
     881        if (rc != EOK)
     882                return rc;
     883       
     884        return (int) res;
     885}
     886
     887/** Request current VLAN filtering mask.
     888 *
     889 * @param[in]  dev_sess
     890 * @param[out] stats    Structure with the statistics
     891 *
     892 * @return EOK If the operation was successfully completed
     893 *
     894 */
     895int nic_vlan_get_mask(async_sess_t *dev_sess, nic_vlan_mask_t *mask)
     896{
     897        assert(mask);
     898       
     899        async_exch_t *exch = async_exchange_begin(dev_sess);
     900        int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     901            NIC_VLAN_GET_MASK);
     902        if (rc != EOK) {
     903                async_exchange_end(exch);
     904                return rc;
     905        }
     906       
     907        rc = async_data_read_start(exch, mask, sizeof(nic_vlan_mask_t));
     908        async_exchange_end(exch);
     909       
     910        return rc;
     911}
     912
     913/** Set the mask used for VLAN filtering.
     914 *
     915 * If NULL, VLAN filtering is disabled.
     916 *
     917 * @param[in] dev_sess
     918 * @param[in] mask     Pointer to mask structure or NULL to disable.
     919 *
     920 * @return EOK If the operation was successfully completed
     921 *
     922 */
     923int nic_vlan_set_mask(async_sess_t *dev_sess, const nic_vlan_mask_t *mask)
     924{
     925        async_exch_t *exch = async_exchange_begin(dev_sess);
     926       
     927        aid_t message_id = async_send_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     928            NIC_VLAN_SET_MASK, mask != NULL, NULL);
     929       
     930        int rc;
     931        if (mask != NULL)
     932                rc = async_data_write_start(exch, mask, sizeof(nic_vlan_mask_t));
     933        else
     934                rc = EOK;
     935       
     936        async_exchange_end(exch);
     937       
     938        sysarg_t res;
     939        async_wait_for(message_id, &res);
     940       
     941        if (rc != EOK)
     942                return rc;
     943       
     944        return (int) res;
     945}
     946
     947/** Set VLAN (802.1q) tag.
     948 *
     949 * Set whether the tag is to be signaled in offload info and
     950 * if the tag should be stripped from received frames and added
     951 * to sent frames automatically. Not every combination of add
     952 * and strip must be supported.
     953 *
     954 * @param[in] dev_sess
     955 * @param[in] tag      VLAN priority (top 3 bits) and
     956 *                     the VLAN tag (bottom 12 bits)
     957 * @param[in] add      Add the VLAN tag automatically (boolean)
     958 * @param[in] strip    Strip the VLAN tag automatically (boolean)
     959 *
     960 * @return EOK If the operation was successfully completed
     961 *
     962 */
     963int nic_vlan_set_tag(async_sess_t *dev_sess, uint16_t tag, bool add, bool strip)
     964{
     965        async_exch_t *exch = async_exchange_begin(dev_sess);
     966        int rc = async_req_4_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     967            NIC_VLAN_SET_TAG, (sysarg_t) tag, (sysarg_t) add, (sysarg_t) strip);
     968        async_exchange_end(exch);
     969       
     970        return rc;
     971}
     972
     973/** Add new Wake-On-LAN virtue.
     974 *
     975 * @param[in]  dev_sess
     976 * @param[in]  type     Type of the virtue
     977 * @param[in]  data     Data required for this virtue
     978 *                      (depends on type)
     979 * @param[in]  length   Length of the data
     980 * @param[out] id       Identifier of the new virtue
     981 *
     982 * @return EOK If the operation was successfully completed
     983 *
     984 */
     985int nic_wol_virtue_add(async_sess_t *dev_sess, nic_wv_type_t type,
     986    const void *data, size_t length, nic_wv_id_t *id)
     987{
     988        assert(id);
     989       
     990        bool send_data = ((data != NULL) && (length != 0));
     991        async_exch_t *exch = async_exchange_begin(dev_sess);
     992       
     993        ipc_call_t result;
     994        aid_t message_id = async_send_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     995            NIC_WOL_VIRTUE_ADD, (sysarg_t) type, send_data, &result);
     996       
     997        sysarg_t res;
     998        if (send_data) {
     999                int rc = async_data_write_start(exch, data, length);
     1000                if (rc != EOK) {
     1001                        async_exchange_end(exch);
     1002                        async_wait_for(message_id, &res);
     1003                        return rc;
     1004                }
     1005        }
     1006       
     1007        async_exchange_end(exch);
     1008        async_wait_for(message_id, &res);
     1009       
     1010        *id = IPC_GET_ARG1(result);
     1011        return (int) res;
     1012}
     1013
     1014/** Remove Wake-On-LAN virtue.
     1015 *
     1016 * @param[in] dev_sess
     1017 * @param[in] id       Virtue identifier
     1018 *
     1019 * @return EOK If the operation was successfully completed
     1020 *
     1021 */
     1022int nic_wol_virtue_remove(async_sess_t *dev_sess, nic_wv_id_t id)
     1023{
     1024        async_exch_t *exch = async_exchange_begin(dev_sess);
     1025        int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     1026            NIC_WOL_VIRTUE_REMOVE, (sysarg_t) id);
     1027        async_exchange_end(exch);
     1028       
     1029        return rc;
     1030}
     1031
     1032/** Get information about virtue.
     1033 *
     1034 * @param[in]  dev_sess
     1035 * @param[in]  id         Virtue identifier
     1036 * @param[out] type       Type of the filter. Can be NULL.
     1037 * @param[out] max_length Size of the data buffer.
     1038 * @param[out] data       Buffer for data used when the
     1039 *                        virtue was created. Can be NULL.
     1040 * @param[out] length     Length of the data. Can be NULL.
     1041 *
     1042 * @return EOK If the operation was successfully completed
     1043 *
     1044 */
     1045int nic_wol_virtue_probe(async_sess_t *dev_sess, nic_wv_id_t id,
     1046    nic_wv_type_t *type, size_t max_length, void *data, size_t *length)
     1047{
     1048        sysarg_t _type;
     1049        sysarg_t _length;
     1050       
     1051        if (data == NULL)
     1052                max_length = 0;
     1053       
     1054        async_exch_t *exch = async_exchange_begin(dev_sess);
     1055       
     1056        int rc = async_req_3_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     1057            NIC_WOL_VIRTUE_PROBE, (sysarg_t) id, max_length,
     1058            &_type, &_length);
     1059        if (rc != EOK) {
     1060                async_exchange_end(exch);
     1061                return rc;
     1062        }
     1063       
     1064        if (type)
     1065                *type = _type;
     1066       
     1067        if (length)
     1068                *length = _length;
     1069       
     1070        if ((max_length) && (_length != 0))
     1071                rc = async_data_read_start(exch, data, max_length);
     1072       
     1073        async_exchange_end(exch);
     1074        return rc;
     1075}
     1076
     1077/** Get a list of all virtues of the specified type.
     1078 *
     1079 * When NIC_WV_NONE is specified as the virtue type the function
     1080 * lists virtues of all types.
     1081 *
     1082 * @param[in]  dev_sess
     1083 * @param[in]  type      Type of the virtues
     1084 * @param[in]  max_count Maximum number of ids that can be
     1085 *                       written into the list buffer.
     1086 * @param[out] id_list   Buffer for to the list of virtue ids.
     1087 *                       Can be NULL.
     1088 * @param[out] id_count  Number of virtue identifiers in the list
     1089 *                       before possible truncation due to the
     1090 *                       max_count. Can be NULL.
     1091 *
     1092 * @return EOK If the operation was successfully completed
     1093 *
     1094 */
     1095int nic_wol_virtue_list(async_sess_t *dev_sess, nic_wv_type_t type,
     1096    size_t max_count, nic_wv_id_t *id_list, size_t *id_count)
     1097{
     1098        if (id_list == NULL)
     1099                max_count = 0;
     1100       
     1101        async_exch_t *exch = async_exchange_begin(dev_sess);
     1102       
     1103        sysarg_t count;
     1104        int rc = async_req_3_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     1105            NIC_WOL_VIRTUE_LIST, (sysarg_t) type, max_count, &count);
     1106       
     1107        if (id_count)
     1108                *id_count = (size_t) count;
     1109       
     1110        if ((rc != EOK) || (!max_count)) {
     1111                async_exchange_end(exch);
     1112                return rc;
     1113        }
     1114       
     1115        rc = async_data_read_start(exch, id_list,
     1116            max_count * sizeof(nic_wv_id_t));
     1117       
     1118        async_exchange_end(exch);
     1119        return rc;
     1120}
     1121
     1122/** Get number of virtues that can be enabled yet.
     1123 *
     1124 * Count: < 0 => Virtue of this type can be never used
     1125 *        = 0 => No more virtues can be enabled
     1126 *        > 0 => #count virtues can be enabled yet
     1127 *
     1128 * @param[in]  dev_sess
     1129 * @param[in]  type     Virtue type
     1130 * @param[out] count    Number of virtues
     1131 *
     1132 * @return EOK If the operation was successfully completed
     1133 *
     1134 */
     1135int nic_wol_virtue_get_caps(async_sess_t *dev_sess, nic_wv_type_t type,
     1136    int *count)
     1137{
     1138        assert(count);
     1139       
     1140        sysarg_t _count;
     1141       
     1142        async_exch_t *exch = async_exchange_begin(dev_sess);
     1143        int rc = async_req_2_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     1144            NIC_WOL_VIRTUE_GET_CAPS, (sysarg_t) type, &_count);
     1145        async_exchange_end(exch);
     1146       
     1147        *count = (int) _count;
     1148        return rc;
     1149}
     1150
     1151/** Load the frame that issued the wakeup.
     1152 *
     1153 * The NIC can support only matched_type,  only part of the frame
     1154 * can be available or not at all. Sometimes even the type can be
     1155 * uncertain -- in this case the matched_type contains NIC_WV_NONE.
     1156 *
     1157 * Frame_length can be greater than max_length, but at most max_length
     1158 * bytes will be copied into the frame buffer.
     1159 *
     1160 * Note: Only the type of the filter can be detected, not the concrete
     1161 * filter, because the driver is probably not running when the wakeup
     1162 * is issued.
     1163 *
     1164 * @param[in]  dev_sess
     1165 * @param[out] matched_type Type of the filter that issued wakeup.
     1166 * @param[in]  max_length   Size of the buffer
     1167 * @param[out] frame        Buffer for the frame. Can be NULL.
     1168 * @param[out] frame_length Length of the stored frame. Can be NULL.
     1169 *
     1170 * @return EOK If the operation was successfully completed
     1171 *
     1172 */
     1173int nic_wol_load_info(async_sess_t *dev_sess, nic_wv_type_t *matched_type,
     1174    size_t max_length, uint8_t *frame, size_t *frame_length)
     1175{
     1176        assert(matched_type);
     1177       
     1178        sysarg_t _matched_type;
     1179        sysarg_t _frame_length;
     1180       
     1181        if (frame == NULL)
     1182                max_length = 0;
     1183       
     1184        async_exch_t *exch = async_exchange_begin(dev_sess);
     1185       
     1186        int rc = async_req_2_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     1187            NIC_WOL_LOAD_INFO, max_length, &_matched_type, &_frame_length);
     1188        if (rc != EOK) {
     1189                async_exchange_end(exch);
     1190                return rc;
     1191        }
     1192       
     1193        *matched_type = (nic_wv_type_t) _matched_type;
     1194        if (frame_length)
     1195                *frame_length = (size_t) _frame_length;
     1196       
     1197        if ((max_length != 0) && (_frame_length != 0))
     1198                rc = async_data_read_start(exch, frame, max_length);
     1199       
     1200        async_exchange_end(exch);
     1201        return rc;
     1202}
     1203
     1204/** Probe supported options and current setting of offload computations
     1205 *
     1206 * @param[in]  dev_sess
     1207 * @param[out] supported Supported offload options
     1208 * @param[out] active    Currently active offload options
     1209 *
     1210 * @return EOK If the operation was successfully completed
     1211 *
     1212 */
     1213int nic_offload_probe(async_sess_t *dev_sess, uint32_t *supported,
     1214    uint32_t *active)
     1215{
     1216        assert(supported);
     1217        assert(active);
     1218       
     1219        sysarg_t _supported;
     1220        sysarg_t _active;
     1221       
     1222        async_exch_t *exch = async_exchange_begin(dev_sess);
     1223        int rc = async_req_1_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     1224            NIC_OFFLOAD_PROBE, &_supported, &_active);
     1225        async_exchange_end(exch);
     1226       
     1227        *supported = (uint32_t) _supported;
     1228        *active = (uint32_t) _active;
     1229        return rc;
     1230}
     1231
     1232/** Set which offload computations can be performed on the NIC.
     1233 *
     1234 * @param[in] dev_sess
     1235 * @param[in] mask     Mask for the options (only those set here will be set)
     1236 * @param[in] active   Which options should be enabled and which disabled
     1237 *
     1238 * @return EOK If the operation was successfully completed
     1239 *
     1240 */
     1241int nic_offload_set(async_sess_t *dev_sess, uint32_t mask, uint32_t active)
     1242{
     1243        async_exch_t *exch = async_exchange_begin(dev_sess);
     1244        int rc = async_req_3_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     1245            NIC_AUTONEG_RESTART, (sysarg_t) mask, (sysarg_t) active);
     1246        async_exchange_end(exch);
     1247       
     1248        return rc;
     1249}
     1250
     1251/** Query the current interrupt/poll mode of the NIC
     1252 *
     1253 * @param[in]  dev_sess
     1254 * @param[out] mode     Current poll mode
     1255 * @param[out] period   Period used in periodic polling.
     1256 *                      Can be NULL.
     1257 *
     1258 * @return EOK If the operation was successfully completed
     1259 *
     1260 */
     1261int nic_poll_get_mode(async_sess_t *dev_sess, nic_poll_mode_t *mode,
     1262    struct timeval *period)
     1263{
     1264        assert(mode);
     1265       
     1266        sysarg_t _mode;
     1267       
     1268        async_exch_t *exch = async_exchange_begin(dev_sess);
     1269       
     1270        int rc = async_req_2_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     1271            NIC_POLL_GET_MODE, period != NULL, &_mode);
     1272        if (rc != EOK) {
     1273                async_exchange_end(exch);
     1274                return rc;
     1275        }
     1276       
     1277        *mode = (nic_poll_mode_t) _mode;
     1278       
     1279        if (period != NULL)
     1280                rc = async_data_read_start(exch, period, sizeof(struct timeval));
     1281       
     1282        async_exchange_end(exch);
     1283        return rc;
     1284}
     1285
     1286/** Set the interrupt/poll mode of the NIC.
     1287 *
     1288 * @param[in] dev_sess
     1289 * @param[in] mode     New poll mode
     1290 * @param[in] period   Period used in periodic polling. Can be NULL.
     1291 *
     1292 * @return EOK If the operation was successfully completed
     1293 *
     1294 */
     1295int nic_poll_set_mode(async_sess_t *dev_sess, nic_poll_mode_t mode,
     1296    const struct timeval *period)
     1297{
     1298        async_exch_t *exch = async_exchange_begin(dev_sess);
     1299       
     1300        aid_t message_id = async_send_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     1301            NIC_POLL_SET_MODE, (sysarg_t) mode, period != NULL, NULL);
     1302       
     1303        int rc;
     1304        if (period)
     1305                rc = async_data_write_start(exch, period, sizeof(struct timeval));
     1306        else
     1307                rc = EOK;
     1308       
     1309        async_exchange_end(exch);
     1310       
     1311        sysarg_t res;
     1312        async_wait_for(message_id, &res);
     1313       
     1314        if (rc != EOK)
     1315                return rc;
     1316       
     1317        return (int) res;
     1318}
     1319
     1320/** Request the driver to poll the NIC.
     1321 *
     1322 * @param[in] dev_sess
     1323 *
     1324 * @return EOK If the operation was successfully completed
     1325 *
     1326 */
     1327int nic_poll_now(async_sess_t *dev_sess)
     1328{
     1329        async_exch_t *exch = async_exchange_begin(dev_sess);
     1330        int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), NIC_POLL_NOW);
     1331        async_exchange_end(exch);
     1332       
     1333        return rc;
     1334}
    431335
    441336static void remote_nic_send_frame(ddf_fun_t *dev, void *iface,
     
    11982490 *
    11992491 */
    1200 static remote_iface_func_ptr_t remote_nic_iface_ops[] = {
    1201         &remote_nic_send_frame,
    1202         &remote_nic_callback_create,
    1203         &remote_nic_get_state,
    1204         &remote_nic_set_state,
    1205         &remote_nic_get_address,
    1206         &remote_nic_set_address,
    1207         &remote_nic_get_stats,
    1208         &remote_nic_get_device_info,
    1209         &remote_nic_get_cable_state,
    1210         &remote_nic_get_operation_mode,
    1211         &remote_nic_set_operation_mode,
    1212         &remote_nic_autoneg_enable,
    1213         &remote_nic_autoneg_disable,
    1214         &remote_nic_autoneg_probe,
    1215         &remote_nic_autoneg_restart,
    1216         &remote_nic_get_pause,
    1217         &remote_nic_set_pause,
    1218         &remote_nic_unicast_get_mode,
    1219         &remote_nic_unicast_set_mode,
    1220         &remote_nic_multicast_get_mode,
    1221         &remote_nic_multicast_set_mode,
    1222         &remote_nic_broadcast_get_mode,
    1223         &remote_nic_broadcast_set_mode,
    1224         &remote_nic_defective_get_mode,
    1225         &remote_nic_defective_set_mode,
    1226         &remote_nic_blocked_sources_get,
    1227         &remote_nic_blocked_sources_set,
    1228         &remote_nic_vlan_get_mask,
    1229         &remote_nic_vlan_set_mask,
    1230         &remote_nic_vlan_set_tag,
    1231         &remote_nic_wol_virtue_add,
    1232         &remote_nic_wol_virtue_remove,
    1233         &remote_nic_wol_virtue_probe,
    1234         &remote_nic_wol_virtue_list,
    1235         &remote_nic_wol_virtue_get_caps,
    1236         &remote_nic_wol_load_info,
    1237         &remote_nic_offload_probe,
    1238         &remote_nic_offload_set,
    1239         &remote_nic_poll_get_mode,
    1240         &remote_nic_poll_set_mode,
    1241         &remote_nic_poll_now
     2492static const remote_iface_func_ptr_t remote_nic_iface_ops[] = {
     2493        [NIC_SEND_MESSAGE] = remote_nic_send_frame,
     2494        [NIC_CALLBACK_CREATE] = remote_nic_callback_create,
     2495        [NIC_GET_STATE] = remote_nic_get_state,
     2496        [NIC_SET_STATE] = remote_nic_set_state,
     2497        [NIC_GET_ADDRESS] = remote_nic_get_address,
     2498        [NIC_SET_ADDRESS] = remote_nic_set_address,
     2499        [NIC_GET_STATS] = remote_nic_get_stats,
     2500        [NIC_GET_DEVICE_INFO] = remote_nic_get_device_info,
     2501        [NIC_GET_CABLE_STATE] = remote_nic_get_cable_state,
     2502        [NIC_GET_OPERATION_MODE] = remote_nic_get_operation_mode,
     2503        [NIC_SET_OPERATION_MODE] = remote_nic_set_operation_mode,
     2504        [NIC_AUTONEG_ENABLE] = remote_nic_autoneg_enable,
     2505        [NIC_AUTONEG_DISABLE] = remote_nic_autoneg_disable,
     2506        [NIC_AUTONEG_PROBE] = remote_nic_autoneg_probe,
     2507        [NIC_AUTONEG_RESTART] = remote_nic_autoneg_restart,
     2508        [NIC_GET_PAUSE] = remote_nic_get_pause,
     2509        [NIC_SET_PAUSE] = remote_nic_set_pause,
     2510        [NIC_UNICAST_GET_MODE] = remote_nic_unicast_get_mode,
     2511        [NIC_UNICAST_SET_MODE] = remote_nic_unicast_set_mode,
     2512        [NIC_MULTICAST_GET_MODE] = remote_nic_multicast_get_mode,
     2513        [NIC_MULTICAST_SET_MODE] = remote_nic_multicast_set_mode,
     2514        [NIC_BROADCAST_GET_MODE] = remote_nic_broadcast_get_mode,
     2515        [NIC_BROADCAST_SET_MODE] = remote_nic_broadcast_set_mode,
     2516        [NIC_DEFECTIVE_GET_MODE] = remote_nic_defective_get_mode,
     2517        [NIC_DEFECTIVE_SET_MODE] = remote_nic_defective_set_mode,
     2518        [NIC_BLOCKED_SOURCES_GET] = remote_nic_blocked_sources_get,
     2519        [NIC_BLOCKED_SOURCES_SET] = remote_nic_blocked_sources_set,
     2520        [NIC_VLAN_GET_MASK] = remote_nic_vlan_get_mask,
     2521        [NIC_VLAN_SET_MASK] = remote_nic_vlan_set_mask,
     2522        [NIC_VLAN_SET_TAG] = remote_nic_vlan_set_tag,
     2523        [NIC_WOL_VIRTUE_ADD] = remote_nic_wol_virtue_add,
     2524        [NIC_WOL_VIRTUE_REMOVE] = remote_nic_wol_virtue_remove,
     2525        [NIC_WOL_VIRTUE_PROBE] = remote_nic_wol_virtue_probe,
     2526        [NIC_WOL_VIRTUE_LIST] = remote_nic_wol_virtue_list,
     2527        [NIC_WOL_VIRTUE_GET_CAPS] = remote_nic_wol_virtue_get_caps,
     2528        [NIC_WOL_LOAD_INFO] = remote_nic_wol_load_info,
     2529        [NIC_OFFLOAD_PROBE] = remote_nic_offload_probe,
     2530        [NIC_OFFLOAD_SET] = remote_nic_offload_set,
     2531        [NIC_POLL_GET_MODE] = remote_nic_poll_get_mode,
     2532        [NIC_POLL_SET_MODE] = remote_nic_poll_set_mode,
     2533        [NIC_POLL_NOW] = remote_nic_poll_now
    12422534};
    12432535
     
    12482540 *
    12492541 */
    1250 remote_iface_t remote_nic_iface = {
    1251         .method_count = sizeof(remote_nic_iface_ops) /
    1252             sizeof(remote_iface_func_ptr_t),
     2542const remote_iface_t remote_nic_iface = {
     2543        .method_count = ARRAY_SIZE(remote_nic_iface_ops),
    12532544        .methods = remote_nic_iface_ops
    12542545};
  • uspace/lib/drv/generic/remote_pci.c

    r2f591127 r5828554  
    3636#include <async.h>
    3737#include <errno.h>
     38#include <macros.h>
    3839
    3940#include "pci_dev_iface.h"
    4041#include "ddf/driver.h"
     42
     43typedef enum {
     44        IPC_M_CONFIG_SPACE_READ_8,
     45        IPC_M_CONFIG_SPACE_READ_16,
     46        IPC_M_CONFIG_SPACE_READ_32,
     47
     48        IPC_M_CONFIG_SPACE_WRITE_8,
     49        IPC_M_CONFIG_SPACE_WRITE_16,
     50        IPC_M_CONFIG_SPACE_WRITE_32
     51} pci_dev_iface_funcs_t;
     52
     53int pci_config_space_read_8(async_sess_t *sess, uint32_t address, uint8_t *val)
     54{
     55        sysarg_t res = 0;
     56       
     57        async_exch_t *exch = async_exchange_begin(sess);
     58        int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     59            IPC_M_CONFIG_SPACE_READ_8, address, &res);
     60        async_exchange_end(exch);
     61       
     62        *val = (uint8_t) res;
     63        return rc;
     64}
     65
     66int pci_config_space_read_16(async_sess_t *sess, uint32_t address,
     67    uint16_t *val)
     68{
     69        sysarg_t res = 0;
     70       
     71        async_exch_t *exch = async_exchange_begin(sess);
     72        int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     73            IPC_M_CONFIG_SPACE_READ_16, address, &res);
     74        async_exchange_end(exch);
     75       
     76        *val = (uint16_t) res;
     77        return rc;
     78}
     79
     80int pci_config_space_read_32(async_sess_t *sess, uint32_t address,
     81    uint32_t *val)
     82{
     83        sysarg_t res = 0;
     84       
     85        async_exch_t *exch = async_exchange_begin(sess);
     86        int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     87            IPC_M_CONFIG_SPACE_READ_32, address, &res);
     88        async_exchange_end(exch);
     89       
     90        *val = (uint32_t) res;
     91        return rc;
     92}
     93
     94int pci_config_space_write_8(async_sess_t *sess, uint32_t address, uint8_t val)
     95{
     96        async_exch_t *exch = async_exchange_begin(sess);
     97        int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     98            IPC_M_CONFIG_SPACE_WRITE_8, address, val);
     99        async_exchange_end(exch);
     100       
     101        return rc;
     102}
     103
     104int pci_config_space_write_16(async_sess_t *sess, uint32_t address,
     105    uint16_t val)
     106{
     107        async_exch_t *exch = async_exchange_begin(sess);
     108        int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     109            IPC_M_CONFIG_SPACE_WRITE_16, address, val);
     110        async_exchange_end(exch);
     111       
     112        return rc;
     113}
     114
     115int pci_config_space_write_32(async_sess_t *sess, uint32_t address,
     116    uint32_t val)
     117{
     118        async_exch_t *exch = async_exchange_begin(sess);
     119        int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     120            IPC_M_CONFIG_SPACE_WRITE_32, address, val);
     121        async_exchange_end(exch);
     122       
     123        return rc;
     124}
    41125
    42126static void remote_config_space_read_8(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     
    49133
    50134/** Remote USB interface operations. */
    51 static remote_iface_func_ptr_t remote_pci_iface_ops [] = {
    52         remote_config_space_read_8,
    53         remote_config_space_read_16,
    54         remote_config_space_read_32,
    55 
    56         remote_config_space_write_8,
    57         remote_config_space_write_16,
    58         remote_config_space_write_32
     135static const remote_iface_func_ptr_t remote_pci_iface_ops [] = {
     136        [IPC_M_CONFIG_SPACE_READ_8] = remote_config_space_read_8,
     137        [IPC_M_CONFIG_SPACE_READ_16] = remote_config_space_read_16,
     138        [IPC_M_CONFIG_SPACE_READ_32] = remote_config_space_read_32,
     139
     140        [IPC_M_CONFIG_SPACE_WRITE_8] = remote_config_space_write_8,
     141        [IPC_M_CONFIG_SPACE_WRITE_16] = remote_config_space_write_16,
     142        [IPC_M_CONFIG_SPACE_WRITE_32] = remote_config_space_write_32
    59143};
    60144
    61145/** Remote USB interface structure.
    62146 */
    63 remote_iface_t remote_pci_iface = {
    64         .method_count = sizeof(remote_pci_iface_ops) /
    65             sizeof(remote_pci_iface_ops[0]),
     147const remote_iface_t remote_pci_iface = {
     148        .method_count = ARRAY_SIZE(remote_pci_iface_ops),
    66149        .methods = remote_pci_iface_ops
    67150};
  • uspace/lib/drv/generic/remote_pio_window.c

    r2f591127 r5828554  
    3535#include <async.h>
    3636#include <errno.h>
     37#include <macros.h>
    3738
    3839#include "ops/pio_window.h"
     
    4243    ipc_call_t *);
    4344
    44 static remote_iface_func_ptr_t remote_pio_window_iface_ops [] = {
     45static const remote_iface_func_ptr_t remote_pio_window_iface_ops [] = {
    4546        [PIO_WINDOW_GET] = &remote_pio_window_get
    4647};
    4748
    48 remote_iface_t remote_pio_window_iface = {
    49         .method_count = sizeof(remote_pio_window_iface_ops) /
    50             sizeof(remote_iface_func_ptr_t),
     49const remote_iface_t remote_pio_window_iface = {
     50        .method_count = ARRAY_SIZE(remote_pio_window_iface_ops),
    5151        .methods = remote_pio_window_iface_ops
    5252};
  • uspace/lib/drv/generic/remote_usb.c

    r2f591127 r5828554  
    3636#include <async.h>
    3737#include <errno.h>
     38#include <macros.h>
    3839
    3940#include "usb_iface.h"
     
    107108
    108109/** Remote USB interface operations. */
    109 static remote_iface_func_ptr_t remote_usb_iface_ops [] = {
     110static const remote_iface_func_ptr_t remote_usb_iface_ops [] = {
    110111        [IPC_M_USB_GET_MY_ADDRESS] = remote_usb_get_my_address,
    111112        [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface,
     
    115116/** Remote USB interface structure.
    116117 */
    117 remote_iface_t remote_usb_iface = {
    118         .method_count = sizeof(remote_usb_iface_ops) /
    119             sizeof(remote_usb_iface_ops[0]),
     118const remote_iface_t remote_usb_iface = {
     119        .method_count = ARRAY_SIZE(remote_usb_iface_ops),
    120120        .methods = remote_usb_iface_ops
    121121};
  • uspace/lib/drv/generic/remote_usbhc.c

    r2f591127 r5828554  
    3737#include <errno.h>
    3838#include <assert.h>
     39#include <macros.h>
    3940
    4041#include "usbhc_iface.h"
     
    334335
    335336/** Remote USB host controller interface operations. */
    336 static remote_iface_func_ptr_t remote_usbhc_iface_ops[] = {
     337static const remote_iface_func_ptr_t remote_usbhc_iface_ops[] = {
    337338        [IPC_M_USBHC_REQUEST_ADDRESS] = remote_usbhc_request_address,
    338339        [IPC_M_USBHC_RELEASE_ADDRESS] = remote_usbhc_release_address,
     
    349350/** Remote USB host controller interface structure.
    350351 */
    351 remote_iface_t remote_usbhc_iface = {
    352         .method_count = sizeof(remote_usbhc_iface_ops) /
    353             sizeof(remote_usbhc_iface_ops[0]),
     352const remote_iface_t remote_usbhc_iface = {
     353        .method_count = ARRAY_SIZE(remote_usbhc_iface_ops),
    354354        .methods = remote_usbhc_iface_ops
    355355};
  • uspace/lib/drv/generic/remote_usbhid.c

    r2f591127 r5828554  
    3737#include <assert.h>
    3838#include <stdio.h>
     39#include <macros.h>
    3940
    4041#include "usbhid_iface.h"
    4142#include "ddf/driver.h"
     43
     44/** IPC methods for USB HID device interface. */
     45typedef enum {
     46        /** Get number of events reported in single burst.
     47         * Parameters: none
     48         * Answer:
     49         * - Size of one report in bytes.
     50         */
     51        IPC_M_USBHID_GET_EVENT_LENGTH,
     52        /** Get single event from the HID device.
     53         * The word single refers to set of individual events that were
     54         * available at particular point in time.
     55         * Parameters:
     56         * - flags
     57         * The call is followed by data read expecting two concatenated
     58         * arrays.
     59         * Answer:
     60         * - EOK - events returned
     61         * - EAGAIN - no event ready (only in non-blocking mode)
     62         *
     63         * It is okay if the client requests less data. Extra data must
     64         * be truncated by the driver.
     65         *
     66         * @todo Change this comment.
     67         */
     68        IPC_M_USBHID_GET_EVENT,
     69       
     70        /** Get the size of the report descriptor from the HID device.
     71         *
     72         * Parameters:
     73         * - none
     74         * Answer:
     75         * - EOK - method is implemented (expected always)
     76         * Parameters of the answer:
     77         * - Size of the report in bytes.
     78         */
     79        IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH,
     80       
     81        /** Get the report descriptor from the HID device.
     82         *
     83         * Parameters:
     84         * - none
     85         * The call is followed by data read expecting the descriptor itself.
     86         * Answer:
     87         * - EOK - report descriptor returned.
     88         */
     89        IPC_M_USBHID_GET_REPORT_DESCRIPTOR
     90} usbhid_iface_funcs_t;
     91
     92/** Ask for event array length.
     93 *
     94 * @param dev_sess Session to DDF device providing USB HID interface.
     95 *
     96 * @return Number of usages returned or negative error code.
     97 *
     98 */
     99int usbhid_dev_get_event_length(async_sess_t *dev_sess, size_t *size)
     100{
     101        if (!dev_sess)
     102                return EINVAL;
     103       
     104        async_exch_t *exch = async_exchange_begin(dev_sess);
     105       
     106        sysarg_t len;
     107        int rc = async_req_1_1(exch, DEV_IFACE_ID(USBHID_DEV_IFACE),
     108            IPC_M_USBHID_GET_EVENT_LENGTH, &len);
     109       
     110        async_exchange_end(exch);
     111       
     112        if (rc == EOK) {
     113                if (size != NULL)
     114                        *size = (size_t) len;
     115        }
     116       
     117        return rc;
     118}
     119
     120/** Request for next event from HID device.
     121 *
     122 * @param[in]  dev_sess    Session to DDF device providing USB HID interface.
     123 * @param[out] usage_pages Where to store usage pages.
     124 * @param[out] usages      Where to store usages (actual data).
     125 * @param[in]  usage_count Length of @p usage_pages and @p usages buffer
     126 *                         (in items, not bytes).
     127 * @param[out] actual_usage_count Number of usages actually returned by the
     128 *                                device driver.
     129 * @param[in] flags        Flags (see USBHID_IFACE_FLAG_*).
     130 *
     131 * @return Error code.
     132 *
     133 */
     134int usbhid_dev_get_event(async_sess_t *dev_sess, uint8_t *buf,
     135    size_t size, size_t *actual_size, int *event_nr, unsigned int flags)
     136{
     137        if (!dev_sess)
     138                return EINVAL;
     139       
     140        if (buf == NULL)
     141                return ENOMEM;
     142       
     143        if (size == 0)
     144                return EINVAL;
     145       
     146        size_t buffer_size =  size;
     147        uint8_t *buffer = malloc(buffer_size);
     148        if (buffer == NULL)
     149                return ENOMEM;
     150       
     151        async_exch_t *exch = async_exchange_begin(dev_sess);
     152       
     153        ipc_call_t opening_request_call;
     154        aid_t opening_request = async_send_2(exch,
     155            DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_EVENT,
     156            flags, &opening_request_call);
     157       
     158        if (opening_request == 0) {
     159                async_exchange_end(exch);
     160                free(buffer);
     161                return ENOMEM;
     162        }
     163       
     164        ipc_call_t data_request_call;
     165        aid_t data_request = async_data_read(exch, buffer, buffer_size,
     166            &data_request_call);
     167       
     168        async_exchange_end(exch);
     169       
     170        if (data_request == 0) {
     171                async_forget(opening_request);
     172                free(buffer);
     173                return ENOMEM;
     174        }
     175       
     176        sysarg_t data_request_rc;
     177        sysarg_t opening_request_rc;
     178        async_wait_for(data_request, &data_request_rc);
     179        async_wait_for(opening_request, &opening_request_rc);
     180       
     181        if (data_request_rc != EOK) {
     182                /* Prefer return code of the opening request. */
     183                if (opening_request_rc != EOK)
     184                        return (int) opening_request_rc;
     185                else
     186                        return (int) data_request_rc;
     187        }
     188       
     189        if (opening_request_rc != EOK)
     190                return (int) opening_request_rc;
     191       
     192        size_t act_size = IPC_GET_ARG2(data_request_call);
     193       
     194        /* Copy the individual items. */
     195        memcpy(buf, buffer, act_size);
     196       
     197        if (actual_size != NULL)
     198                *actual_size = act_size;
     199       
     200        if (event_nr != NULL)
     201                *event_nr = IPC_GET_ARG1(opening_request_call);
     202       
     203        return EOK;
     204}
     205
     206int usbhid_dev_get_report_descriptor_length(async_sess_t *dev_sess,
     207    size_t *size)
     208{
     209        if (!dev_sess)
     210                return EINVAL;
     211       
     212        async_exch_t *exch = async_exchange_begin(dev_sess);
     213       
     214        sysarg_t arg_size;
     215        int rc = async_req_1_1(exch, DEV_IFACE_ID(USBHID_DEV_IFACE),
     216            IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, &arg_size);
     217       
     218        async_exchange_end(exch);
     219       
     220        if (rc == EOK) {
     221                if (size != NULL)
     222                        *size = (size_t) arg_size;
     223        }
     224       
     225        return rc;
     226}
     227
     228int usbhid_dev_get_report_descriptor(async_sess_t *dev_sess, uint8_t *buf,
     229    size_t size, size_t *actual_size)
     230{
     231        if (!dev_sess)
     232                return EINVAL;
     233       
     234        if (buf == NULL)
     235                return ENOMEM;
     236       
     237        if (size == 0)
     238                return EINVAL;
     239       
     240        async_exch_t *exch = async_exchange_begin(dev_sess);
     241       
     242        aid_t opening_request = async_send_1(exch,
     243            DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_REPORT_DESCRIPTOR,
     244            NULL);
     245        if (opening_request == 0) {
     246                async_exchange_end(exch);
     247                return ENOMEM;
     248        }
     249       
     250        ipc_call_t data_request_call;
     251        aid_t data_request = async_data_read(exch, buf, size,
     252            &data_request_call);
     253       
     254        async_exchange_end(exch);
     255       
     256        if (data_request == 0) {
     257                async_forget(opening_request);
     258                return ENOMEM;
     259        }
     260       
     261        sysarg_t data_request_rc;
     262        sysarg_t opening_request_rc;
     263        async_wait_for(data_request, &data_request_rc);
     264        async_wait_for(opening_request, &opening_request_rc);
     265       
     266        if (data_request_rc != EOK) {
     267                /* Prefer return code of the opening request. */
     268                if (opening_request_rc != EOK)
     269                        return (int) opening_request_rc;
     270                else
     271                        return (int) data_request_rc;
     272        }
     273       
     274        if (opening_request_rc != EOK)
     275                return (int) opening_request_rc;
     276       
     277        size_t act_size = IPC_GET_ARG2(data_request_call);
     278       
     279        if (actual_size != NULL)
     280                *actual_size = act_size;
     281       
     282        return EOK;
     283}
    42284
    43285static void remote_usbhid_get_event_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     
    48290
    49291/** Remote USB HID interface operations. */
    50 static remote_iface_func_ptr_t remote_usbhid_iface_ops [] = {
    51         remote_usbhid_get_event_length,
    52         remote_usbhid_get_event,
    53         remote_usbhid_get_report_descriptor_length,
    54         remote_usbhid_get_report_descriptor
     292static const remote_iface_func_ptr_t remote_usbhid_iface_ops [] = {
     293        [IPC_M_USBHID_GET_EVENT_LENGTH] = remote_usbhid_get_event_length,
     294        [IPC_M_USBHID_GET_EVENT] = remote_usbhid_get_event,
     295        [IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH] =
     296            remote_usbhid_get_report_descriptor_length,
     297        [IPC_M_USBHID_GET_REPORT_DESCRIPTOR] = remote_usbhid_get_report_descriptor
    55298};
    56299
    57300/** Remote USB HID interface structure.
    58301 */
    59 remote_iface_t remote_usbhid_iface = {
    60         .method_count = sizeof(remote_usbhid_iface_ops) /
    61             sizeof(remote_usbhid_iface_ops[0]),
     302const remote_iface_t remote_usbhid_iface = {
     303        .method_count = ARRAY_SIZE(remote_usbhid_iface_ops),
    62304        .methods = remote_usbhid_iface_ops
    63305};
  • uspace/lib/drv/include/ahci_iface.h

    r2f591127 r5828554  
    4141#include <async.h>
    4242
     43extern async_sess_t* ahci_get_sess(devman_handle_t, char **);
     44
     45extern int ahci_get_sata_device_name(async_sess_t *, size_t, char *);
     46extern int ahci_get_num_blocks(async_sess_t *, uint64_t *);
     47extern int ahci_get_block_size(async_sess_t *, size_t *);
     48extern int ahci_read_blocks(async_sess_t *, uint64_t, size_t, void *);
     49extern int ahci_write_blocks(async_sess_t *, uint64_t, size_t, void *);
     50
    4351/** AHCI device communication interface. */
    4452typedef struct {
  • uspace/lib/drv/include/battery_iface.h

    r2f591127 r5828554  
    3333 */
    3434
    35 #ifndef LIBC_DEVICE_BATTERY_DEV_H_
    36 #define LIBC_DEVICE_BATTERY_DEV_H_
     35#ifndef LIBDRV_BATTERY_IFACE_H_
     36#define LIBDRV_BATTERY_IFACE_H_
    3737
    3838#include <async.h>
  • uspace/lib/drv/include/char_dev_iface.h

    r2f591127 r5828554  
    3333 */
    3434
    35 #ifndef LIBC_DEVICE_CHAR_DEV_H_
    36 #define LIBC_DEVICE_CHAR_DEV_H_
     35#ifndef LIBDRV_CHAR_DEV_IFACE_H_
     36#define LIBDRV_CHAR_DEV_IFACE_H_
    3737
    3838#include <async.h>
  • uspace/lib/drv/include/ddf/driver.h

    r2f591127 r5828554  
    108108        const char *name;
    109109        /** Generic device driver operations */
    110         driver_ops_t *driver_ops;
     110        const driver_ops_t *driver_ops;
    111111} driver_t;
    112112
     
    116116#endif
    117117
    118 extern int ddf_driver_main(driver_t *);
     118extern int ddf_driver_main(const driver_t *);
    119119
    120120extern void *ddf_dev_data_alloc(ddf_dev_t *, size_t);
  • uspace/lib/drv/include/ddf/interrupt.h

    r2f591127 r5828554  
    6767extern void interrupt_init(void);
    6868extern int register_interrupt_handler(ddf_dev_t *, int, interrupt_handler_t *,
    69     irq_code_t *);
     69    const irq_code_t *);
    7070extern int unregister_interrupt_handler(ddf_dev_t *, int);
    7171
  • uspace/lib/drv/include/dev_iface.h

    r2f591127 r5828554  
    5555
    5656typedef struct {
    57         size_t method_count;
    58         remote_iface_func_ptr_t *methods;
     57        const size_t method_count;
     58        const remote_iface_func_ptr_t *methods;
    5959} remote_iface_t;
    6060
    6161typedef struct {
    62         remote_iface_t *ifaces[DEV_IFACE_COUNT];
     62        const remote_iface_t *ifaces[DEV_IFACE_COUNT];
    6363} iface_dipatch_table_t;
    6464
    65 extern remote_iface_t *get_remote_iface(int);
    66 extern remote_iface_func_ptr_t get_remote_method(remote_iface_t *, sysarg_t);
     65extern const remote_iface_t *get_remote_iface(int);
     66extern remote_iface_func_ptr_t get_remote_method(const remote_iface_t *, sysarg_t);
    6767
    6868
  • uspace/lib/drv/include/graph_iface.h

    r2f591127 r5828554  
    3838#include <async.h>
    3939
    40 typedef enum {
    41         GRAPH_DEV_CONNECT = 0
    42 } graph_dev_method_t;
    43 
    4440extern int graph_dev_connect(async_sess_t *);
    4541
  • uspace/lib/drv/include/nic_iface.h

    r2f591127 r5828554  
    3333 */
    3434
    35 #ifndef LIBC_DEVICE_NIC_H_
    36 #define LIBC_DEVICE_NIC_H_
     35#ifndef LIBDRV_NIC_IFACE_H_
     36#define LIBDRV_NIC_IFACE_H_
    3737
    3838#include <async.h>
     
    4040#include <ipc/common.h>
    4141
    42 typedef enum {
    43         NIC_SEND_MESSAGE = 0,
    44         NIC_CALLBACK_CREATE,
    45         NIC_GET_STATE,
    46         NIC_SET_STATE,
    47         NIC_GET_ADDRESS,
    48         NIC_SET_ADDRESS,
    49         NIC_GET_STATS,
    50         NIC_GET_DEVICE_INFO,
    51         NIC_GET_CABLE_STATE,
    52         NIC_GET_OPERATION_MODE,
    53         NIC_SET_OPERATION_MODE,
    54         NIC_AUTONEG_ENABLE,
    55         NIC_AUTONEG_DISABLE,
    56         NIC_AUTONEG_PROBE,
    57         NIC_AUTONEG_RESTART,
    58         NIC_GET_PAUSE,
    59         NIC_SET_PAUSE,
    60         NIC_UNICAST_GET_MODE,
    61         NIC_UNICAST_SET_MODE,
    62         NIC_MULTICAST_GET_MODE,
    63         NIC_MULTICAST_SET_MODE,
    64         NIC_BROADCAST_GET_MODE,
    65         NIC_BROADCAST_SET_MODE,
    66         NIC_DEFECTIVE_GET_MODE,
    67         NIC_DEFECTIVE_SET_MODE,
    68         NIC_BLOCKED_SOURCES_GET,
    69         NIC_BLOCKED_SOURCES_SET,
    70         NIC_VLAN_GET_MASK,
    71         NIC_VLAN_SET_MASK,
    72         NIC_VLAN_SET_TAG,
    73         NIC_WOL_VIRTUE_ADD,
    74         NIC_WOL_VIRTUE_REMOVE,
    75         NIC_WOL_VIRTUE_PROBE,
    76         NIC_WOL_VIRTUE_LIST,
    77         NIC_WOL_VIRTUE_GET_CAPS,
    78         NIC_WOL_LOAD_INFO,
    79         NIC_OFFLOAD_PROBE,
    80         NIC_OFFLOAD_SET,
    81         NIC_POLL_GET_MODE,
    82         NIC_POLL_SET_MODE,
    83         NIC_POLL_NOW
    84 } nic_funcs_t;
    8542
    8643typedef enum {
  • uspace/lib/drv/include/ops/battery_dev.h

    r2f591127 r5828554  
    3737
    3838#include "../ddf/driver.h"
    39 #include "device/battery_dev.h"
     39#include "battery_iface.h"
    4040
    4141typedef struct {
  • uspace/lib/drv/include/pci_dev_iface.h

    r2f591127 r5828554  
    4040#include "ddf/driver.h"
    4141
    42 typedef enum {
    43         IPC_M_CONFIG_SPACE_READ_8,
    44         IPC_M_CONFIG_SPACE_READ_16,
    45         IPC_M_CONFIG_SPACE_READ_32,
     42#define PCI_DEVICE_ID  0x02
    4643
    47         IPC_M_CONFIG_SPACE_WRITE_8,
    48         IPC_M_CONFIG_SPACE_WRITE_16,
    49         IPC_M_CONFIG_SPACE_WRITE_32
    50 } pci_dev_iface_funcs_t;
     44extern int pci_config_space_read_8(async_sess_t *, uint32_t, uint8_t *);
     45extern int pci_config_space_read_16(async_sess_t *, uint32_t, uint16_t *);
     46extern int pci_config_space_read_32(async_sess_t *, uint32_t, uint32_t *);
     47
     48extern int pci_config_space_write_8(async_sess_t *, uint32_t, uint8_t);
     49extern int pci_config_space_write_16(async_sess_t *, uint32_t, uint16_t);
     50extern int pci_config_space_write_32(async_sess_t *, uint32_t, uint32_t);
    5151
    5252/** PCI device communication interface. */
  • uspace/lib/drv/include/usbhid_iface.h

    r2f591127 r5828554  
    4040#include <usb/usb.h>
    4141
    42 /** IPC methods for USB HID device interface. */
    43 typedef enum {
    44         /** Get number of events reported in single burst.
    45          * Parameters: none
    46          * Answer:
    47          * - Size of one report in bytes.
    48          */
    49         IPC_M_USBHID_GET_EVENT_LENGTH,
    50         /** Get single event from the HID device.
    51          * The word single refers to set of individual events that were
    52          * available at particular point in time.
    53          * Parameters:
    54          * - flags
    55          * The call is followed by data read expecting two concatenated
    56          * arrays.
    57          * Answer:
    58          * - EOK - events returned
    59          * - EAGAIN - no event ready (only in non-blocking mode)
    60          *
    61          * It is okay if the client requests less data. Extra data must
    62          * be truncated by the driver.
    63          *
    64          * @todo Change this comment.
    65          */
    66         IPC_M_USBHID_GET_EVENT,
    67        
    68         /** Get the size of the report descriptor from the HID device.
    69          *
    70          * Parameters:
    71          * - none
    72          * Answer:
    73          * - EOK - method is implemented (expected always)
    74          * Parameters of the answer:
    75          * - Size of the report in bytes.
    76          */
    77         IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH,
    78        
    79         /** Get the report descriptor from the HID device.
    80          *
    81          * Parameters:
    82          * - none
    83          * The call is followed by data read expecting the descriptor itself.
    84          * Answer:
    85          * - EOK - report descriptor returned.
    86          */
    87         IPC_M_USBHID_GET_REPORT_DESCRIPTOR
    88 } usbhid_iface_funcs_t;
    89 
    90 /** USB HID interface flag - return immediately if no data are available. */
    91 #define USBHID_IFACE_FLAG_NON_BLOCKING (1 << 0)
     42extern int usbhid_dev_get_event_length(async_sess_t *, size_t *);
     43extern int usbhid_dev_get_event(async_sess_t *, uint8_t *, size_t, size_t *,
     44    int *, unsigned int);
     45extern int usbhid_dev_get_report_descriptor_length(async_sess_t *, size_t *);
     46extern int usbhid_dev_get_report_descriptor(async_sess_t *, uint8_t *, size_t,
     47    size_t *);
    9248
    9349/** USB HID device communication interface. */
  • uspace/lib/gui/Makefile

    r2f591127 r5828554  
    3434
    3535SOURCES = \
     36        common.c \
    3637        button.c \
    3738        canvas.c \
  • uspace/lib/gui/button.c

    r2f591127 r5828554  
    3636#include <str.h>
    3737#include <malloc.h>
    38 
    3938#include <drawctx.h>
    4039#include <surface.h>
    41 
     40#include "common.h"
    4241#include "window.h"
    4342#include "button.h"
    4443
    45 static void paint_internal(widget_t *w)
    46 {
    47         button_t *btn = (button_t *) w;
    48 
     44static pixel_t color_highlight = PIXEL(255, 255, 255, 255);
     45static pixel_t color_shadow = PIXEL(255, 85, 85, 85);
     46
     47static void paint_internal(widget_t *widget)
     48{
     49        button_t *btn = (button_t *) widget;
     50       
    4951        surface_t *surface = window_claim(btn->widget.window);
    50         if (!surface) {
     52        if (!surface)
    5153                window_yield(btn->widget.window);
     54       
     55        source_t source;
     56        source_init(&source);
     57       
     58        drawctx_t drawctx;
     59        drawctx_init(&drawctx, surface);
     60       
     61        drawctx_set_source(&drawctx, &btn->background);
     62        drawctx_transfer(&drawctx, widget->hpos, widget->vpos,
     63            widget->width, widget->height);
     64       
     65        if ((widget->width >= 8) && (widget->height >= 8)) {
     66                drawctx_set_source(&drawctx, &source);
     67                draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3,
     68                    widget->width - 6, widget->height - 6, color_highlight,
     69                    color_shadow);
     70               
     71                drawctx_set_source(&drawctx, &btn->foreground);
     72                drawctx_transfer(&drawctx, widget->hpos + 4, widget->vpos + 4,
     73                    widget->width - 8, widget->height - 8);
    5274        }
    53 
    54         drawctx_t drawctx;
    55 
    56         drawctx_init(&drawctx, surface);
    57         drawctx_set_source(&drawctx, &btn->foreground);
    58         drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height);
    59 
    60         if (w->width >= 6 && w->height >= 6) {
    61                 drawctx_set_source(&drawctx, &btn->background);
    62                 drawctx_transfer(&drawctx,
    63                     w->hpos + 3, w->vpos + 3, w->width - 6, w->height - 6);
    64         }
    65 
     75       
    6676        sysarg_t cpt_width;
    6777        sysarg_t cpt_height;
    6878        font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height);
    69         if (w->width >= cpt_width && w->height >= cpt_height) {
    70                 drawctx_set_source(&drawctx, &btn->foreground);
     79       
     80        if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) {
     81                sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos;
     82                sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos;
     83               
     84                drawctx_set_source(&drawctx, &btn->text);
    7185                drawctx_set_font(&drawctx, &btn->font);
    72                 sysarg_t x = ((w->width - cpt_width) / 2) + w->hpos;
    73                 sysarg_t y = ((w->height - cpt_height) / 2) + w->vpos;
    74                 if (btn->caption) {
     86               
     87                if (btn->caption)
    7588                        drawctx_print(&drawctx, btn->caption, x, y);
    76                 }
    7789        }
    78 
     90       
    7991        window_yield(btn->widget.window);
    8092}
     
    90102{
    91103        button_t *btn = (button_t *) widget;
    92 
     104       
    93105        deinit_button(btn);
    94        
    95106        free(btn);
    96107}
     
    117128{
    118129        button_t *btn = (button_t *) widget;
    119         if (event.key == KC_ENTER && event.type == KEY_PRESS) {
     130       
     131        if (event.key == KC_ENTER && event.type == KEY_PRESS)
    120132                sig_send(&btn->clicked, NULL);
    121         }
    122133}
    123134
     
    126137        button_t *btn = (button_t *) widget;
    127138        widget->window->focus = widget;
    128 
     139       
    129140        // TODO make the click logic more robust (mouse grabbing, mouse moves)
    130141        if (event.btn_num == 1) {
    131                 if (event.type == POS_RELEASE) {
     142                if (event.type == POS_RELEASE)
    132143                        sig_send(&btn->clicked, NULL);
    133                 }
    134144        }
    135145}
    136146
    137 bool init_button(button_t *btn, widget_t *parent,
    138     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     147bool init_button(button_t *btn, widget_t *parent, const char *caption,
     148    uint16_t points, pixel_t background, pixel_t foreground, pixel_t text)
    139149{
    140150        widget_init(&btn->widget, parent);
    141 
     151       
    142152        btn->widget.destroy = button_destroy;
    143153        btn->widget.reconfigure = button_reconfigure;
     
    146156        btn->widget.handle_keyboard_event = button_handle_keyboard_event;
    147157        btn->widget.handle_position_event = button_handle_position_event;
    148 
     158       
    149159        source_init(&btn->background);
    150160        source_set_color(&btn->background, background);
     161       
    151162        source_init(&btn->foreground);
    152163        source_set_color(&btn->foreground, foreground);
    153 
    154         if (caption == NULL) {
     164       
     165        source_init(&btn->text);
     166        source_set_color(&btn->text, text);
     167       
     168        if (caption == NULL)
    155169                btn->caption = NULL;
    156         } else {
     170        else
    157171                btn->caption = str_dup(caption);
    158         }
     172       
    159173        font_init(&btn->font, FONT_DECODER_EMBEDDED, NULL, points);
    160 
     174       
    161175        sysarg_t cpt_width;
    162176        sysarg_t cpt_height;
    163177        font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height);
    164         btn->widget.width_min = cpt_width + 8;
    165         btn->widget.height_min = cpt_height + 8;
    166         btn->widget.width_ideal = cpt_width + 28;
    167         btn->widget.height_ideal = cpt_height + 8;
    168 
     178        btn->widget.width_min = cpt_width + 10;
     179        btn->widget.height_min = cpt_height + 10;
     180        btn->widget.width_ideal = cpt_width + 30;
     181        btn->widget.height_ideal = cpt_height + 10;
     182       
    169183        return true;
    170184}
    171185
    172 button_t *create_button(widget_t *parent,
    173     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     186button_t *create_button(widget_t *parent, const char *caption, uint16_t points,
     187    pixel_t background, pixel_t foreground, pixel_t text)
    174188{
    175189        button_t *btn = (button_t *) malloc(sizeof(button_t));
    176         if (!btn) {
     190        if (!btn)
    177191                return NULL;
    178         }
    179 
    180         if (init_button(btn, parent, caption, points, background, foreground)) {
     192       
     193        if (init_button(btn, parent, caption, points, background, foreground,
     194            text))
    181195                return btn;
    182         } else {
    183                 free(btn);
    184                 return NULL;
    185         }
     196       
     197        free(btn);
     198        return NULL;
    186199}
    187200
  • uspace/lib/gui/button.h

    r2f591127 r5828554  
    5050        source_t background;
    5151        source_t foreground;
     52        source_t text;
    5253        char *caption;
    5354        font_t font;
     
    5556} button_t;
    5657
    57 extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t, pixel_t);
    58 extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t, pixel_t);
     58extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t,
     59    pixel_t, pixel_t);
     60extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t,
     61    pixel_t, pixel_t);
    5962extern void deinit_button(button_t *);
    6063
  • uspace/lib/gui/canvas.c

    r2f591127 r5828554  
    112112static void canvas_handle_position_event(widget_t *widget, pos_event_t event)
    113113{
    114         /* No-op */
     114        canvas_t *canvas = (canvas_t *) widget;
     115        pos_event_t tevent;
     116       
     117        tevent = event;
     118        tevent.hpos -= widget->hpos;
     119        tevent.vpos -= widget->vpos;
     120       
     121        sig_send(&canvas->position_event, &tevent);
    115122}
    116123
  • uspace/lib/gui/canvas.h

    r2f591127 r5828554  
    5050        surface_t *surface;
    5151        signal_t keyboard_event;
     52        signal_t position_event;
    5253} canvas_t;
    5354
  • uspace/lib/gui/connection.c

    r2f591127 r5828554  
    210210                        link_initialize(&event->link);
    211211                        event->type = ET_SIGNAL_EVENT;
    212                         event->data.sig.object = (sysarg_t) cur->widget;
    213                         event->data.sig.slot = (sysarg_t) cur->slot;
    214                         event->data.sig.argument = (sysarg_t) data_copy;
     212                        event->data.signal.object = (sysarg_t) cur->widget;
     213                        event->data.signal.slot = (sysarg_t) cur->slot;
     214                        event->data.signal.argument = (sysarg_t) data_copy;
    215215                        prodcons_produce(&cur->widget->window->events, &event->link);
    216216                } else {
  • uspace/lib/gui/label.c

    r2f591127 r5828554  
    3636#include <str.h>
    3737#include <malloc.h>
    38 
    3938#include <drawctx.h>
    4039#include <surface.h>
    41 
    4240#include "window.h"
    4341#include "label.h"
    4442
    45 static void paint_internal(widget_t *w)
     43static void paint_internal(widget_t *widget)
    4644{
    47         label_t *lbl = (label_t *) w;
     45        label_t *lbl = (label_t *) widget;
    4846
    4947        surface_t *surface = window_claim(lbl->widget.window);
    50         if (!surface) {
     48        if (!surface)
    5149                window_yield(lbl->widget.window);
    52         }
    53 
     50       
    5451        drawctx_t drawctx;
    55 
    5652        drawctx_init(&drawctx, surface);
     53       
    5754        drawctx_set_source(&drawctx, &lbl->background);
    58         drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height);
    59 
     55        drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width,
     56            widget->height);
     57       
    6058        sysarg_t cpt_width;
    6159        sysarg_t cpt_height;
    6260        font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
    63         if (w->width >= cpt_width && w->height >= cpt_height) {
    64                 drawctx_set_source(&drawctx, &lbl->foreground);
     61       
     62        if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) {
     63                sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos;
     64                sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos;
     65               
     66                drawctx_set_source(&drawctx, &lbl->text);
    6567                drawctx_set_font(&drawctx, &lbl->font);
    66                 sysarg_t x = ((w->width - cpt_width) / 2) + w->hpos;
    67                 sysarg_t y = ((w->height - cpt_height) / 2) + w->vpos;
    68                 if (lbl->caption) {
     68               
     69                if (lbl->caption)
    6970                        drawctx_print(&drawctx, lbl->caption, x, y);
    70                 }
    7171        }
    72 
     72       
    7373        window_yield(lbl->widget.window);
    7474}
     
    7878        if (data != NULL) {
    7979                label_t *lbl = (label_t *) widget;
     80               
    8081                const char *new_caption = (const char *) data;
    8182                lbl->caption = str_dup(new_caption);
    82 
     83               
    8384                sysarg_t cpt_width;
    8485                sysarg_t cpt_height;
    8586                font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
     87               
    8688                lbl->widget.width_min = cpt_width + 4;
    8789                lbl->widget.height_min = cpt_height + 4;
    8890                lbl->widget.width_ideal = lbl->widget.width_min;
    8991                lbl->widget.height_ideal = lbl->widget.height_min;
    90 
     92               
    9193                window_refresh(lbl->widget.window);
    9294        }
     
    103105{
    104106        label_t *lbl = (label_t *) widget;
    105 
     107       
    106108        deinit_label(lbl);
    107        
    108109        free(lbl);
    109110}
     
    137138}
    138139
    139 bool init_label(label_t *lbl, widget_t *parent,
    140     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     140bool init_label(label_t *lbl, widget_t *parent, const char *caption,
     141    uint16_t points, pixel_t background, pixel_t text)
    141142{
    142143        widget_init(&lbl->widget, parent);
    143 
     144       
    144145        lbl->widget.destroy = label_destroy;
    145146        lbl->widget.reconfigure = label_reconfigure;
     
    148149        lbl->widget.handle_keyboard_event = label_handle_keyboard_event;
    149150        lbl->widget.handle_position_event = label_handle_position_event;
    150 
     151       
    151152        source_init(&lbl->background);
    152153        source_set_color(&lbl->background, background);
    153         source_init(&lbl->foreground);
    154         source_set_color(&lbl->foreground, foreground);
    155 
    156         if (caption == NULL) {
     154       
     155        source_init(&lbl->text);
     156        source_set_color(&lbl->text, text);
     157       
     158        if (caption == NULL)
    157159                lbl->caption = NULL;
    158         } else {
     160        else
    159161                lbl->caption = str_dup(caption);
    160         }
     162       
    161163        font_init(&lbl->font, FONT_DECODER_EMBEDDED, NULL, points);
    162 
     164       
    163165        sysarg_t cpt_width;
    164166        sysarg_t cpt_height;
    165167        font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
     168       
    166169        lbl->widget.width_min = cpt_width + 4;
    167170        lbl->widget.height_min = cpt_height + 4;
    168171        lbl->widget.width_ideal = lbl->widget.width_min;
    169172        lbl->widget.height_ideal = lbl->widget.height_min;
    170 
     173       
    171174        lbl->rewrite = on_rewrite;
    172 
     175       
    173176        return true;
    174177}
    175178
    176 label_t *create_label(widget_t *parent,
    177     const char *caption, uint16_t points, pixel_t background, pixel_t foreground)
     179label_t *create_label(widget_t *parent, const char *caption, uint16_t points,
     180    pixel_t background, pixel_t text)
    178181{
    179182        label_t *lbl = (label_t *) malloc(sizeof(label_t));
    180         if (!lbl) {
     183        if (!lbl)
    181184                return NULL;
    182         }
    183 
    184         if (init_label(lbl, parent, caption, points, background, foreground)) {
     185       
     186        if (init_label(lbl, parent, caption, points, background, text))
    185187                return lbl;
    186         } else {
    187                 free(lbl);
    188                 return NULL;
    189         }
     188       
     189        free(lbl);
     190        return NULL;
    190191}
    191192
    192193/** @}
    193194 */
    194 
  • uspace/lib/gui/label.h

    r2f591127 r5828554  
    4949        widget_t widget;
    5050        source_t background;
    51         source_t foreground;
     51        source_t text;
    5252        char *caption;
    5353        font_t font;
     
    5555} label_t;
    5656
    57 extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t, pixel_t);
    58 extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t, pixel_t);
     57extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t,
     58    pixel_t);
     59extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t,
     60    pixel_t);
    5961extern void deinit_label(label_t *);
    6062
  • uspace/lib/gui/window.c

    r2f591127 r5828554  
    5656#include <surface.h>
    5757
     58#include "common.h"
    5859#include "connection.h"
    5960#include "widget.h"
    6061#include "window.h"
    6162
    62 static sysarg_t border_thickness = 5;
     63static sysarg_t border_thickness = 4;
     64static sysarg_t bevel_thickness = 1;
    6365static sysarg_t header_height = 20;
    6466static sysarg_t header_min_width = 40;
    65 static sysarg_t close_width = 20;
    66 
    67 static pixel_t border_color = PIXEL(255, 0, 0, 0);
    68 static pixel_t header_bg_focus_color = PIXEL(255, 88, 106, 196);
    69 static pixel_t header_fg_focus_color = PIXEL(255, 255, 255, 255);
    70 static pixel_t header_bg_unfocus_color = PIXEL(255, 12, 57, 92);
    71 static pixel_t header_fg_unfocus_color = PIXEL(255, 255, 255, 255);
    72 
    73 static void paint_internal(widget_t *w)
    74 {
    75         surface_t *surface = window_claim(w->window);
    76         if (!surface) {
    77                 window_yield(w->window);
    78         }
    79 
     67static sysarg_t close_thickness = 20;
     68
     69static pixel_t color_highlight = PIXEL(255, 255, 255, 255);
     70static pixel_t color_shadow = PIXEL(255, 85, 85, 85);
     71static pixel_t color_surface = PIXEL(255, 186, 186, 186);
     72
     73static pixel_t color_header_focus_highlight = PIXEL(255, 120, 145, 255);
     74static pixel_t color_header_focus_shadow = PIXEL(255, 40, 48, 89);
     75static pixel_t color_header_focus_surface = PIXEL(255, 88, 106, 196);
     76
     77static pixel_t color_header_unfocus_highlight = PIXEL(255, 16, 78, 126);
     78static pixel_t color_header_unfocus_shadow = PIXEL(255, 5, 26, 42);
     79static pixel_t color_header_unfocus_surface = PIXEL(255, 12, 57, 92);
     80
     81static pixel_t color_caption_focus = PIXEL(255, 255, 255, 255);
     82static pixel_t color_caption_unfocus = PIXEL(255, 207, 207, 207);
     83
     84static void paint_internal(widget_t *widget)
     85{
     86        surface_t *surface = window_claim(widget->window);
     87        if (!surface)
     88                window_yield(widget->window);
     89       
    8090        source_t source;
    81         font_t font;
     91        source_init(&source);
     92       
    8293        drawctx_t drawctx;
    83 
    84         source_init(&source);
    85         font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);
    8694        drawctx_init(&drawctx, surface);
    8795        drawctx_set_source(&drawctx, &source);
     96       
     97        /* Window border outer bevel */
     98       
     99        draw_bevel(&drawctx, &source, widget->vpos, widget->hpos,
     100            widget->width, widget->height, color_highlight, color_shadow);
     101       
     102        /* Window border surface */
     103       
     104        source_set_color(&source, color_surface);
     105        drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
     106            widget->width - 2, 2);
     107        drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1,
     108            2, widget->height - 2);
     109        drawctx_transfer(&drawctx, widget->hpos + 1,
     110            widget->vpos + widget->height - 3, widget->width - 2, 2);
     111        drawctx_transfer(&drawctx, widget->hpos + widget->width - 3,
     112            widget->vpos + 1, 2, widget->height - 4);
     113       
     114        /* Window border inner bevel */
     115       
     116        draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3,
     117            widget->width - 6, widget->height - 6, color_shadow,
     118            color_highlight);
     119       
     120        /* Header bevel */
     121       
     122        sysarg_t header_hpos = widget->hpos + border_thickness;
     123        sysarg_t header_vpos = widget->vpos + border_thickness;
     124        sysarg_t header_width = widget->width - 2 * border_thickness -
     125            close_thickness;
     126       
     127        draw_bevel(&drawctx, &source, header_hpos, header_vpos,
     128            header_width, header_height, widget->window->is_focused ?
     129            color_header_focus_highlight : color_header_unfocus_highlight,
     130            widget->window->is_focused ?
     131            color_header_focus_shadow : color_header_unfocus_shadow);
     132       
     133        /* Header surface */
     134       
     135        source_set_color(&source, widget->window->is_focused ?
     136            color_header_focus_surface : color_header_unfocus_surface);
     137        drawctx_transfer(&drawctx, header_hpos + 1, header_vpos + 1,
     138            header_width - 2, header_height - 2);
     139       
     140        /* Close button bevel */
     141       
     142        sysarg_t close_hpos = widget->hpos + widget->width -
     143            border_thickness - close_thickness;
     144        sysarg_t close_vpos = widget->vpos + border_thickness;
     145       
     146        draw_bevel(&drawctx, &source, close_hpos, close_vpos,
     147            close_thickness, close_thickness, color_highlight, color_shadow);
     148       
     149        /* Close button surface */
     150       
     151        source_set_color(&source, color_surface);
     152        drawctx_transfer(&drawctx, close_hpos + 1, close_vpos + 1,
     153            close_thickness - 2, close_thickness - 2);
     154       
     155        /* Close button icon */
     156       
     157        draw_icon_cross(surface, close_hpos + 3, close_vpos + 3,
     158            color_highlight, color_shadow);
     159       
     160        /* Window caption */
     161       
     162        font_t font;
     163        font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);
     164       
    88165        drawctx_set_font(&drawctx, &font);
    89 
    90         source_set_color(&source, border_color);
    91         drawctx_transfer(&drawctx, w->hpos, w->vpos, border_thickness, w->height);
    92         drawctx_transfer(&drawctx, w->hpos + w->width - border_thickness,
    93             w->vpos, border_thickness, w->height);
    94         drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, border_thickness);
    95         drawctx_transfer(&drawctx, w->hpos,
    96             w->vpos + w->height - border_thickness, w->width, border_thickness);
    97 
    98         source_set_color(&source,
    99             w->window->is_focused ? header_bg_focus_color : header_bg_unfocus_color);
    100         drawctx_transfer(&drawctx,
    101             w->hpos + border_thickness, w->vpos + border_thickness,
    102                 w->width - 2 * border_thickness, header_height);
    103 
     166        source_set_color(&source, widget->window->is_focused ?
     167            color_caption_focus : color_caption_unfocus);
     168       
    104169        sysarg_t cpt_width;
    105170        sysarg_t cpt_height;
    106         font_get_box(&font, w->window->caption, &cpt_width, &cpt_height);
    107         sysarg_t cls_width;
    108         sysarg_t cls_height;
    109         char cls_pict[] = "x";
    110         font_get_box(&font, cls_pict, &cls_width, &cls_height);
    111         source_set_color(&source,
    112             w->window->is_focused ? header_fg_focus_color : header_fg_unfocus_color);
    113         sysarg_t cls_x = ((close_width - cls_width) / 2) + w->hpos + w->width -
    114             border_thickness - close_width;
    115         sysarg_t cls_y = ((header_height - cls_height) / 2) + w->vpos + border_thickness;
    116         drawctx_print(&drawctx, cls_pict, cls_x, cls_y);
    117 
    118         bool draw_title = (w->width >= 2 * border_thickness + close_width + cpt_width);
     171        font_get_box(&font, widget->window->caption, &cpt_width, &cpt_height);
     172       
     173        bool draw_title =
     174            (widget->width >= 2 * border_thickness + 2 * bevel_thickness +
     175            close_thickness + cpt_width);
    119176        if (draw_title) {
    120                 sysarg_t cpt_x = ((w->width - cpt_width) / 2) + w->hpos;
    121                 sysarg_t cpt_y = ((header_height - cpt_height) / 2) + w->vpos + border_thickness;
    122                 if (w->window->caption) {
    123                         drawctx_print(&drawctx, w->window->caption, cpt_x, cpt_y);
    124                 }
    125         }
    126 
     177                sysarg_t cpt_x = ((widget->width - cpt_width) / 2) + widget->hpos;
     178                sysarg_t cpt_y = ((header_height - cpt_height) / 2) +
     179                    widget->vpos + border_thickness;
     180               
     181                if (widget->window->caption)
     182                        drawctx_print(&drawctx, widget->window->caption, cpt_x, cpt_y);
     183        }
     184       
    127185        font_release(&font);
    128         window_yield(w->window);
     186        window_yield(widget->window);
    129187}
    130188
     
    138196        if (widget->window->is_decorated) {
    139197                list_foreach(widget->children, link, widget_t, child) {
    140                         child->rearrange(child, 
     198                        child->rearrange(child,
    141199                            widget->hpos + border_thickness,
    142200                            widget->vpos + border_thickness + header_height,
     
    211269                    (event.vpos >= border_thickness) &&
    212270                    (event.vpos < border_thickness + header_height);
    213                 bool close = header && (event.hpos >= width - border_thickness - close_width);
     271                bool close = (header) &&
     272                    (event.hpos >= width - border_thickness - close_thickness);
    214273
    215274                if (top && left && allowed_button) {
     
    292351}
    293352
    294 static void handle_signal_event(window_t *win, sig_event_t event)
     353static void handle_signal_event(window_t *win, signal_event_t event)
    295354{
    296355        widget_t *widget = (widget_t *) event.object;
     
    303362}
    304363
    305 static void handle_resize(window_t *win, sysarg_t width, sysarg_t height)
    306 {
    307         int rc;
    308         surface_t *old_surface;
    309         surface_t *new_surface;
    310 
     364static void handle_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y,
     365    sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
     366{
    311367        if (width < 2 * border_thickness + header_min_width) {
    312368                win_damage(win->osess, 0, 0, 0, 0);
    313369                return;
    314370        }
    315 
     371       
    316372        if (height < 2 * border_thickness + header_height) {
    317373                win_damage(win->osess, 0, 0, 0, 0);
    318374                return;
    319375        }
    320 
     376       
    321377        /* Allocate resources for new surface. */
    322         new_surface = surface_create(width, height, NULL, SURFACE_FLAG_SHARED);
    323         if (!new_surface) {
     378        surface_t *new_surface = surface_create(width, height, NULL,
     379            SURFACE_FLAG_SHARED);
     380        if (!new_surface)
    324381                return;
    325         }
    326 
     382       
    327383        /* Switch new and old surface. */
    328384        fibril_mutex_lock(&win->guard);
    329         old_surface = win->surface;
     385        surface_t *old_surface = win->surface;
    330386        win->surface = new_surface;
    331387        fibril_mutex_unlock(&win->guard);
    332 
    333         /* Let all widgets in the tree alter their position and size. Widgets might
    334          * also paint themselves onto the new surface. */
     388       
     389        /*
     390         * Let all widgets in the tree alter their position and size.
     391         * Widgets might also paint themselves onto the new surface.
     392         */
    335393        win->root.rearrange(&win->root, 0, 0, width, height);
    336 
     394       
    337395        fibril_mutex_lock(&win->guard);
    338396        surface_reset_damaged_region(win->surface);
    339397        fibril_mutex_unlock(&win->guard);
    340 
     398       
    341399        /* Inform compositor about new surface. */
    342         rc = win_resize(win->osess,
    343                 width, height, surface_direct_access(new_surface));
    344 
     400        int rc = win_resize(win->osess, offset_x, offset_y, width, height,
     401            placement_flags, surface_direct_access(new_surface));
     402       
    345403        if (rc != EOK) {
    346404                /* Rollback to old surface. Reverse all changes. */
    347 
     405               
    348406                sysarg_t old_width = 0;
    349407                sysarg_t old_height = 0;
    350                 if (old_surface) {
     408                if (old_surface)
    351409                        surface_get_resolution(old_surface, &old_width, &old_height);
    352                 }
    353 
     410               
    354411                fibril_mutex_lock(&win->guard);
    355412                new_surface = win->surface;
    356413                win->surface = old_surface;
    357414                fibril_mutex_unlock(&win->guard);
    358 
     415               
    359416                win->root.rearrange(&win->root, 0, 0, old_width, old_height);
    360417               
     
    364421                        fibril_mutex_unlock(&win->guard);
    365422                }
    366 
     423               
    367424                surface_destroy(new_surface);
    368                 return;
    369         }
    370 
    371         /* Finally deallocate old surface. */
    372         if (old_surface) {
    373                 surface_destroy(old_surface);
     425        } else {
     426                /* Deallocate old surface. */
     427                if (old_surface)
     428                        surface_destroy(old_surface);
    374429        }
    375430}
     
    453508                        break;
    454509                case ET_SIGNAL_EVENT:
    455                         handle_signal_event(win, event->data.sig);
     510                        handle_signal_event(win, event->data.signal);
    456511                        break;
    457512                case ET_WINDOW_RESIZE:
    458                         handle_resize(win, event->data.rsz.width, event->data.rsz.height);
     513                        handle_resize(win, event->data.resize.offset_x,
     514                            event->data.resize.offset_y, event->data.resize.width,
     515                            event->data.resize.height, event->data.resize.placement_flags);
    459516                        break;
    460517                case ET_WINDOW_FOCUS:
     
    530587
    531588window_t *window_open(const char *winreg, bool is_main, bool is_decorated,
    532     const char *caption, sysarg_t x_offset, sysarg_t y_offset)
    533 {
    534         int rc;
    535 
     589    const char *caption)
     590{
    536591        window_t *win = (window_t *) malloc(sizeof(window_t));
    537         if (!win) {
     592        if (!win)
    538593                return NULL;
    539         }
    540 
     594       
    541595        win->is_main = is_main;
    542596        win->is_decorated = is_decorated;
     
    544598        prodcons_initialize(&win->events);
    545599        fibril_mutex_initialize(&win->guard);
     600       
    546601        widget_init(&win->root, NULL);
    547602        win->root.window = win;
     
    555610        win->focus = NULL;
    556611        win->surface = NULL;
    557 
     612       
    558613        service_id_t reg_dsid;
    559         async_sess_t *reg_sess;
    560 
    561         rc = loc_service_get_id(winreg, &reg_dsid, 0);
     614        int rc = loc_service_get_id(winreg, &reg_dsid, 0);
    562615        if (rc != EOK) {
    563616                free(win);
    564617                return NULL;
    565618        }
    566 
    567         reg_sess = loc_service_connect(EXCHANGE_SERIALIZE, reg_dsid, 0);
     619       
     620        async_sess_t *reg_sess = loc_service_connect(EXCHANGE_SERIALIZE,
     621            reg_dsid, 0);
    568622        if (reg_sess == NULL) {
    569623                free(win);
    570624                return NULL;
    571625        }
    572 
     626       
    573627        service_id_t in_dsid;
    574628        service_id_t out_dsid;
    575        
    576         rc = win_register(reg_sess, &in_dsid, &out_dsid, x_offset, y_offset);
     629        rc = win_register(reg_sess, &in_dsid, &out_dsid);
    577630        async_hangup(reg_sess);
    578631        if (rc != EOK) {
     
    580633                return NULL;
    581634        }
    582 
     635       
    583636        win->osess = loc_service_connect(EXCHANGE_SERIALIZE, out_dsid, 0);
    584637        if (win->osess == NULL) {
     
    586639                return NULL;
    587640        }
    588 
     641       
    589642        win->isess = loc_service_connect(EXCHANGE_SERIALIZE, in_dsid, 0);
    590643        if (win->isess == NULL) {
     
    593646                return NULL;
    594647        }
    595 
    596         if (caption == NULL) {
     648       
     649        if (caption == NULL)
    597650                win->caption = NULL;
    598         } else {
     651        else
    599652                win->caption = str_dup(caption);
    600         }
    601 
     653       
    602654        return win;
    603655}
    604656
    605 void window_resize(window_t *win, sysarg_t width, sysarg_t height)
     657void window_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y,
     658    sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
    606659{
    607660        window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
     
    609662                link_initialize(&event->link);
    610663                event->type = ET_WINDOW_RESIZE;
    611                 event->data.rsz.width = width;
    612                 event->data.rsz.height = height;
     664                event->data.resize.offset_x = offset_x;
     665                event->data.resize.offset_y = offset_y;
     666                event->data.resize.width = width;
     667                event->data.resize.height = height;
     668                event->data.resize.placement_flags = placement_flags;
    613669                prodcons_produce(&win->events, &event->link);
    614670        }
  • uspace/lib/gui/window.h

    r2f591127 r5828554  
    6666 * If the window is declared as main, its closure causes termination of the
    6767 * whole application. Note that opened window does not have any surface yet. */
    68 extern window_t *window_open(const char *, bool, bool, const char *, sysarg_t,
    69     sysarg_t);
     68extern window_t *window_open(const char *, bool, bool, const char *);
    7069
    7170/**
     
    7473 * and to paint themselves on the new surface (top-bottom order). Should be
    7574 * called also after opening new window to obtain surface. */
    76 extern void window_resize(window_t *, sysarg_t, sysarg_t);
     75extern void window_resize(window_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
     76    window_placement_flags_t);
    7777
    7878/**
  • uspace/lib/nic/Makefile

    r2f591127 r5828554  
    3030LIBRARY = libnic
    3131EXTRA_CFLAGS += -DLIBNIC_INTERNAL -Iinclude -I$(LIBDRV_PREFIX)/include
     32LIBS = $(LIBDRV_PREFIX)/libdrv.a
    3233
    3334SOURCES = \
  • uspace/lib/nic/src/nic_ev.c

    r2f591127 r5828554  
    3737
    3838#include <async.h>
    39 #include <device/nic.h>
     39#include <nic_iface.h>
    4040#include <errno.h>
    4141#include "nic_ev.h"
  • uspace/lib/posix/Makefile

    r2f591127 r5828554  
    6060        source/getopt.c \
    6161        source/locale.c \
    62         source/math.c \
    6362        source/pthread/condvar.c \
    6463        source/pthread/keys.c \
  • uspace/lib/posix/include/posix/float.h

    r2f591127 r5828554  
    5959        #undef DBL_EPSILON
    6060        #define DBL_EPSILON __DBL_EPSILON__
     61        #undef LDBL_EPSILON
     62        #define LDBL_EPSILON __LDBL_EPSILON__
    6163        #undef FLT_RADIX
    6264        #define FLT_RADIX __FLT_RADIX__
     
    6971        #undef FLT_MANT_DIG
    7072        #define FLT_MANT_DIG __FLT_MANT_DIG__
     73        #undef LDBL_MIN
     74        #define LDBL_MIN __LDBL_MIN__
     75        #undef LDBL_MAX
     76        #define LDBL_MAX __LDBL_MAX__
    7177        #undef LDBL_MANT_DIG
    7278        #define LDBL_MANT_DIG __LDBL_MANT_DIG__
  • uspace/lib/posix/include/posix/math.h

    r2f591127 r5828554  
    3636#define POSIX_MATH_H_
    3737
    38 #ifndef __POSIX_DEF__
    39 #define __POSIX_DEF__(x) x
    40 #endif
    41 
    42 #ifdef __GNUC__
    43         #define HUGE_VAL (__builtin_huge_val())
    44 #endif
    45 
    46 /* Normalization Functions */
    47 extern double __POSIX_DEF__(ldexp)(double x, int exp);
    48 extern double __POSIX_DEF__(frexp)(double num, int *exp);
    49 
    50 double __POSIX_DEF__(fabs)(double x);
    51 double __POSIX_DEF__(floor)(double x);
    52 double __POSIX_DEF__(modf)(double x, double *iptr);
    53 double __POSIX_DEF__(fmod)(double x, double y);
    54 double __POSIX_DEF__(pow)(double x, double y);
    55 double __POSIX_DEF__(exp)(double x);
    56 double __POSIX_DEF__(sqrt)(double x);
    57 double __POSIX_DEF__(log)(double x);
    58 double __POSIX_DEF__(sin)(double x);
    59 double __POSIX_DEF__(cos)(double x);
    60 double __POSIX_DEF__(atan2)(double y, double x);
     38#include "libc/math.h"
    6139
    6240#endif /* POSIX_MATH_H_ */
  • uspace/lib/posix/include/posix/setjmp.h

    r2f591127 r5828554  
    2727 */
    2828
    29 /** @addtogroup libc
     29/** @addtogroup libposix
    3030 * @{
    3131 */
    3232
    33 #include <bitops.h>
    34 
    35 int __popcountsi2(int a)
    36 {
    37         int bits = 0;
    38         for (unsigned int i = 0; i < sizeof(a) * 8; i++)         {
    39                 if (((a >> i) & 1) != 0) {
    40                         bits++;
    41                 }
    42         }
    43         return bits;                                                                   
    44 }
    45 
     33/*
     34 * Just a pass-through to libc setjmp.
     35 */
     36#include "libc/setjmp.h"
    4637
    4738/** @}
  • uspace/lib/posix/include/posix/stdlib.h

    r2f591127 r5828554  
    5656#define _Exit exit
    5757extern int __POSIX_DEF__(atexit)(void (*func)(void));
    58 extern void exit(int status);
     58extern void exit(int status) __attribute__((noreturn));
    5959extern void abort(void) __attribute__((noreturn));
    6060
  • uspace/lib/softfloat/softfloat.c

    r2f591127 r5828554  
    12651265}
    12661266
     1267float __aeabi_d2f(double a)
     1268{
     1269        return __truncdfsf2(a);
     1270}
     1271
     1272double __aeabi_f2d(float a)
     1273{
     1274        return __extendsfdf2(a);
     1275}
     1276
     1277
    12671278float __aeabi_i2f(int i)
    12681279{
     
    12851296}
    12861297
     1298double __aeabi_l2d(long long i)
     1299{
     1300        return __floattidf(i);
     1301}
     1302
     1303float __aeabi_l2f(long long i)
     1304{
     1305        return __floattisf(i);
     1306}
     1307
     1308float __aeabi_ul2f(unsigned long long u)
     1309{
     1310        return __floatuntisf(u);
     1311}
     1312
    12871313int __aeabi_f2iz(float a)
    12881314{
     
    13051331}
    13061332
     1333long long __aeabi_d2lz(double a)
     1334{
     1335        return __fixdfti(a);
     1336}
     1337
    13071338int __aeabi_fcmpge(float a, float b)
    13081339{
     
    13391370        return __ltdf2(a, b);
    13401371}
     1372
     1373int __aeabi_dcmple(double a, double b)
     1374{
     1375        return __ledf2(a, b);
     1376}
     1377
    13411378
    13421379int __aeabi_dcmpeq(double a, double b)
  • uspace/lib/softfloat/softfloat.h

    r2f591127 r5828554  
    204204
    205205/* ARM EABI */
     206extern float __aeabi_d2f(double);
     207extern double __aeabi_f2d(float);
    206208extern float __aeabi_i2f(int);
    207209extern float __aeabi_ui2f(int);
    208210extern double __aeabi_i2d(int);
    209211extern double __aeabi_ui2d(unsigned int);
     212extern double __aeabi_l2d(long long);
     213extern float __aeabi_l2f(long long);
     214extern float __aeabi_ul2f(unsigned long long);
    210215extern unsigned int __aeabi_d2uiz(double);
     216extern long long __aeabi_d2lz(double);
    211217
    212218extern int __aeabi_f2iz(float);
     
    222228extern int __aeabi_dcmpgt(double, double);
    223229extern int __aeabi_dcmplt(double, double);
     230extern int __aeabi_dcmple(double, double);
    224231extern int __aeabi_dcmpeq(double, double);
    225232
  • uspace/lib/softint/Makefile

    r2f591127 r5828554  
    3535
    3636SOURCES = \
     37        generic/bits.c \
    3738        generic/comparison.c \
    3839        generic/division.c \
  • uspace/lib/softint/generic/shift.c

    r2f591127 r5828554  
    123123}
    124124
     125long long __aeabi_llsl(long long val, int shift)
     126{
     127        return __ashldi3(val, shift);
     128}
     129
    125130/** @}
    126131 */
  • uspace/lib/softint/include/shift.h

    r2f591127 r5828554  
    4646extern long long __lshrdi3(long long, int);
    4747
     48
     49/* ARM EABI */
     50extern long long __aeabi_llsl(long long, int);
     51
    4852#endif
    4953
  • uspace/lib/usbhid/Makefile

    r2f591127 r5828554  
    3737SOURCES = \
    3838        src/hiddescriptor.c \
    39         src/hidiface.c \
    4039        src/hidparser.c \
    4140        src/hidpath.c \
Note: See TracChangeset for help on using the changeset viewer.