Changeset 49ff5f3 in mainline for uspace/lib/c


Ignore:
Timestamp:
2012-04-18T20:55:21Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7769ec9
Parents:
e895352 (diff), 63920b0 (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/c
Files:
13 added
14 deleted
56 edited
12 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    re895352 r49ff5f3  
    7070        generic/device/char_dev.c \
    7171        generic/device/nic.c \
     72        generic/device/pci.c \
    7273        generic/elf/elf_load.c \
    7374        generic/event.c \
     
    8687        generic/task.c \
    8788        generic/futex.c \
     89        generic/inet.c \
     90        generic/inetcfg.c \
     91        generic/inetping.c \
    8892        generic/io/asprintf.c \
    8993        generic/io/io.c \
     
    96100        generic/io/printf_core.c \
    97101        generic/io/console.c \
     102        generic/iplink.c \
     103        generic/iplink_srv.c \
    98104        generic/malloc.c \
    99105        generic/sysinfo.c \
     
    107113        generic/adt/hash_set.c \
    108114        generic/adt/dynamic_fifo.c \
    109         generic/adt/measured_strings.c \
    110115        generic/adt/char_map.c \
    111116        generic/adt/prodcons.c \
     
    117122        generic/vfs/canonify.c \
    118123        generic/net/inet.c \
    119         generic/net/icmp_common.c \
    120         generic/net/icmp_api.c \
    121124        generic/net/modules.c \
    122         generic/net/packet.c \
    123125        generic/net/socket_client.c \
    124126        generic/net/socket_parse.c \
  • uspace/lib/c/arch/amd64/include/fibril.h

    re895352 r49ff5f3  
    3838#include <sys/types.h>
    3939
    40 /* According to ABI the stack MUST be aligned on
     40/*
     41 * According to ABI the stack MUST be aligned on
    4142 * 16-byte boundary. If it is not, the va_arg calling will
    4243 * panic sooner or later
    4344 */
    44 #define SP_DELTA     16
     45#define SP_DELTA  16
    4546
    4647#define context_set(c, _pc, stack, size, ptls) \
  • uspace/lib/c/arch/arm32/Makefile.common

    re895352 r49ff5f3  
    2828#
    2929
    30 GCC_CFLAGS += -ffixed-r9 -mtp=soft -mapcs-frame -fno-omit-frame-pointer
     30GCC_CFLAGS += -ffixed-r9 -mtp=soft -fno-omit-frame-pointer -march=armv4
    3131
    3232ENDIANESS = LE
  • uspace/lib/c/arch/arm32/include/fibril.h

    re895352 r49ff5f3  
    2727 */
    2828
    29 /** @addtogroup libcarm32       
     29/** @addtogroup libcarm32
    3030 * @{
    3131 */
     
    4242
    4343/** Size of a stack item */
    44 #define STACK_ITEM_SIZE         4
     44#define STACK_ITEM_SIZE  4
    4545
    4646/** Stack alignment - see <a href="http://www.arm.com/support/faqdev/14269.html">ABI</a> for details */
    47 #define STACK_ALIGNMENT         8
     47#define STACK_ALIGNMENT  8
    4848
    49 #define SP_DELTA        (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     49#define SP_DELTA  (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
    5050
    5151
    52 /** Sets data to the context. 
    53  * 
     52/** Sets data to the context.
     53 *
    5454 *  @param c     Context (#context_t).
    5555 *  @param _pc   Program counter.
     
    6262                (c)->pc = (sysarg_t) (_pc); \
    6363                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
    64                 (c)->tls = ((sysarg_t)(ptls)) + sizeof(tcb_t) + ARM_TP_OFFSET; \
     64                (c)->tls = ((sysarg_t)(ptls)) + sizeof(tcb_t) + ARM_TP_OFFSET; \
    6565                (c)->fp = 0; \
    6666        } while (0)
    6767
    68 /** Fibril context. 
     68/** Fibril context.
    6969 *
    7070 *  Only registers preserved accross function calls are included. r9 is used
     
    9191}
    9292
    93 
    9493#endif
    9594
  • uspace/lib/c/arch/arm32/src/eabi.S

    re895352 r49ff5f3  
    11#
    2 # Copyright (c) 2007 Pavel Jancik
     2# Copyright (c) 2012 Martin Decky
    33# All rights reserved.
    44#
     
    3131.global __aeabi_read_tp
    3232
     33.global __aeabi_idiv
     34.global __aeabi_uidiv
     35
     36.global __aeabi_idivmod
     37.global __aeabi_uidivmod
     38
     39.global __aeabi_ldivmod
     40.global __aeabi_uldivmod
     41
    3342__aeabi_read_tp:
    3443        mov r0, r9
    3544        mov pc, lr
     45
     46__aeabi_idiv:
     47        push {lr}
     48        bl __divsi3
     49        pop {lr}
     50        mov pc, lr
     51
     52__aeabi_uidiv:
     53        push {lr}
     54        bl __udivsi3
     55        pop {lr}
     56        mov pc, lr
     57
     58__aeabi_idivmod:
     59        push {lr}
     60        sub sp, sp, #12
     61        add r2, sp, #4
     62        bl __udivmodsi3
     63        ldr r1, [sp, #4]
     64        add sp, sp, #12
     65        pop {lr}
     66        mov pc, lr
     67
     68__aeabi_uidivmod:
     69        push {lr}
     70        sub sp, sp, #12
     71        add r2, sp, #4
     72        bl __udivmodsi3
     73        ldr r1, [sp, #4]
     74        add sp, sp, #12
     75        pop {lr}
     76        mov pc, lr
     77
     78__aeabi_ldivmod:
     79        push {lr}
     80        sub sp, sp, #24
     81        push {sp}
     82        bl __divmoddi3
     83        add sp, sp, #4
     84        pop {r2, r3}
     85        add sp, sp, #16
     86        pop {lr}
     87        mov pc, lr
     88
     89__aeabi_uldivmod:
     90        push {lr}
     91        sub sp, sp, #24
     92        push {sp}
     93        bl __udivmoddi3
     94        add sp, sp, #4
     95        pop {r2, r3}
     96        add sp, sp, #16
     97        pop {lr}
     98        mov pc, lr
  • uspace/lib/c/arch/ia32/include/fibril.h

    re895352 r49ff5f3  
    3838#include <sys/types.h>
    3939
    40 /* According to ABI the stack MUST be aligned on
     40/*
     41 * According to ABI the stack MUST be aligned on
    4142 * 16-byte boundary. If it is not, the va_arg calling will
    4243 * panic sooner or later
  • uspace/lib/c/arch/ia64/include/ddi.h

    re895352 r49ff5f3  
    6262
    6363        asm volatile ("mf\n" ::: "memory");
     64        asm volatile ("mf.a\n" ::: "memory");
    6465}
    6566
     
    7677
    7778        asm volatile ("mf\n" ::: "memory");
     79        asm volatile ("mf.a\n" ::: "memory");
    7880}
    7981
     
    9092
    9193        asm volatile ("mf\n" ::: "memory");
     94        asm volatile ("mf.a\n" ::: "memory");
    9295}
    9396
     
    106109                v = *port;
    107110        }
     111
     112        asm volatile ("mf.a\n" ::: "memory");
    108113
    109114        return v;
     
    125130        }
    126131
     132        asm volatile ("mf.a\n" ::: "memory");
     133
    127134        return v;
    128135}
     
    134141        asm volatile ("mf\n" ::: "memory");
    135142
    136         if (port < (ioport32_t *) port) {
     143        if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
    137144                uintptr_t prt = (uintptr_t) port;
    138145
     
    143150        }
    144151
     152        asm volatile ("mf.a\n" ::: "memory");
     153
    145154        return v;
    146155}
  • uspace/lib/c/arch/ia64/include/fibril.h

    re895352 r49ff5f3  
    2727 */
    2828
    29 /** @addtogroup libcia64       
     29/** @addtogroup libcia64
    3030 * @{
    3131 */
     
    4545 * No need to allocate scratch area.
    4646 */
    47 #define SP_DELTA        (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     47#define SP_DELTA  (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
    4848
    49 #define PFM_MASK        (~0x3fffffffff)
     49#define PFM_MASK  (~0x3fffffffff)
    5050
    51 #define PSTHREAD_INITIAL_STACK_PAGES_NO 2
     51#define PSTHREAD_INITIAL_STACK_PAGES_NO  2
     52
    5253/* Stack is divided into two equal parts (for memory stack and register stack). */
    53 #define PSTHREAD_INITIAL_STACK_DIVISION
     54#define PSTHREAD_INITIAL_STACK_DIVISION  2
    5455
    55 #define context_set(c, _pc, stack, size, tls)                                                           \
    56         do {                                                                                            \
    57                 (c)->pc = (uint64_t) _pc;                                                               \
    58                 (c)->bsp = ((uint64_t) stack) + size / PSTHREAD_INITIAL_STACK_DIVISION;                                                         \
    59                 (c)->ar_pfs &= PFM_MASK;                                                                \
    60                 (c)->sp = ((uint64_t) stack) + ALIGN_UP((size / PSTHREAD_INITIAL_STACK_DIVISION), STACK_ALIGNMENT) - SP_DELTA;          \
    61                 (c)->tp = (uint64_t) tls;                                                               \
    62         } while (0);
    63        
     56#define context_set(c, _pc, stack, size, tls) \
     57        do { \
     58                (c)->pc = (uint64_t) _pc; \
     59                (c)->bsp = ((uint64_t) stack) + \
     60                    size / PSTHREAD_INITIAL_STACK_DIVISION; \
     61                (c)->ar_pfs &= PFM_MASK; \
     62                (c)->sp = ((uint64_t) stack) + \
     63                    ALIGN_UP((size / PSTHREAD_INITIAL_STACK_DIVISION), STACK_ALIGNMENT) - \
     64                    SP_DELTA; \
     65                (c)->tp = (uint64_t) tls; \
     66        } while (0)
    6467
    6568/*
  • uspace/lib/c/arch/mips32/Makefile.inc

    re895352 r49ff5f3  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
    31         arch/$(UARCH)/src/entryjmp.s \
    32         arch/$(UARCH)/src/thread_entry.s \
     30        arch/$(UARCH)/src/entry.S \
     31        arch/$(UARCH)/src/entryjmp.S \
     32        arch/$(UARCH)/src/thread_entry.S \
    3333        arch/$(UARCH)/src/syscall.c \
    3434        arch/$(UARCH)/src/fibril.S \
  • uspace/lib/c/arch/mips32/include/atomic.h

    re895352 r49ff5f3  
    6767                "       ll %0, %1\n"
    6868                "       addu %0, %0, %3\n"      /* same as add, but never traps on overflow */
    69                 "       move %2, %0\n"
     69                "       move %2, %0\n"
    7070                "       sc %0, %1\n"
    7171                "       beq %0, %4, 1b\n"       /* if the atomic operation failed, try again */
  • uspace/lib/c/arch/mips32/include/config.h

    re895352 r49ff5f3  
    3636#define LIBC_mips32_CONFIG_H_
    3737
    38 #define PAGE_WIDTH      14
    39 #define PAGE_SIZE       (1 << PAGE_WIDTH)
     38#define PAGE_WIDTH  14
     39#define PAGE_SIZE   (1 << PAGE_WIDTH)
    4040
    4141#endif
  • uspace/lib/c/arch/mips32/include/faddr.h

    re895352 r49ff5f3  
    3838#include <libarch/types.h>
    3939
    40 #define FADDR(fptr)             ((uintptr_t) (fptr))
     40#define FADDR(fptr)  ((uintptr_t) (fptr))
    4141
    4242#endif
  • uspace/lib/c/arch/mips32/include/fibril.h

    re895352 r49ff5f3  
    3838
    3939#include <sys/types.h>
     40#include <libarch/stack.h>
     41#include <align.h>
    4042
    41 /* We define our own context_set, because we need to set
    42  * the TLS pointer to the tcb+0x7000
     43#define SP_DELTA  (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     44
     45/*
     46 * We define our own context_set, because we need to set
     47 * the TLS pointer to the tcb + 0x7000
    4348 *
    4449 * See tls_set in thread.h
    4550 */
    46 #define context_set(c, _pc, stack, size, ptls)                  \
    47         (c)->pc = (sysarg_t) (_pc);                             \
    48         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA;     \
    49         (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t);
    50 
    51 
    52 /* +16 is just for sure that the called function
    53  * have space to store it's arguments
    54  */
    55 #define SP_DELTA        (8+16)
     51#define context_set(c, _pc, stack, size, ptls) \
     52        do { \
     53                (c)->pc = (sysarg_t) (_pc); \
     54                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
     55                (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t); \
     56        } while (0)
    5657
    5758typedef struct  {
  • uspace/lib/c/arch/mips32/src/entry.S

    re895352 r49ff5f3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .init, "ax"
     
    4143.ent __entry
    4244__entry:
    43         .frame $sp, 32, $31
    44         .cpload $25
     45        .frame $sp, ABI_STACK_FRAME, $ra
     46        .cpload $t9
    4547       
    46         # FIXME: Reflect exactly ABI specs here
     48        # Allocate the stack frame.
     49        addiu $sp, -ABI_STACK_FRAME
    4750       
    48         addiu $sp, -32
    49         .cprestore 16   # Allow PIC code
     51        # Allow PIC code
     52        .cprestore 16
    5053       
    51         # Pass pcb_ptr to __main() as the first argument. pcb_ptr is already
     54        # Pass pcb_ptr to __main() as the first argument. It is already
    5255        # in $a0. As the first argument is passed in $a0, no operation
    5356        # is needed.
     
    5558        jal __main
    5659        nop
    57 .end
     60       
     61        #
     62        # Not reached.
     63        #
     64        addiu $sp, ABI_STACK_FRAME
     65.end __entry
  • uspace/lib/c/arch/mips32/src/entryjmp.S

    re895352 r49ff5f3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .text
     
    4143entry_point_jmp:
    4244        # tmp := entry_point
    43         move $25, $a0
     45        move $t9, $a0
    4446       
    4547        # Pass pcb to the entry point in $a0
    4648        move $a0, $a1
    47         jr $25
    48         nop
    49 .end
     49       
     50        jr $t9
     51        addiu $sp, -ABI_STACK_FRAME
     52        addiu $sp, ABI_STACK_FRAME
     53.end entry_point_jmp
  • uspace/lib/c/arch/mips32/src/fibril.S

    re895352 r49ff5f3  
    3333
    3434#include <libarch/context_offset.h>
    35        
     35
    3636.global context_save
    3737.global context_restore
    38        
     38
    3939context_save:
    4040        CONTEXT_SAVE_ARCH_CORE $a0
    41 
     41       
    4242        # context_save returns 1
    4343        j $ra
    44         li $v0, 1       
    45        
     44        li $v0, 1
     45
    4646context_restore:
    4747        CONTEXT_RESTORE_ARCH_CORE $a0
    48 
    49         # Just for the jump into first function, but one instruction
    50         # should not bother us
    51         move $t9, $ra   
     48       
     49        # Just for the jump into first function,
     50        # but one instruction should not bother us
     51        move $t9, $ra
     52       
    5253        # context_restore returns 0
    5354        j $ra
    54         xor $v0, $v0   
    55 
     55        xor $v0, $v0
  • uspace/lib/c/arch/mips32/src/syscall.c

    re895352 r49ff5f3  
    5757                  "r" (__mips_reg_t1),
    5858                  "r" (__mips_reg_v0)
    59                 : "%ra" /* We are a function call, although C does not
    60                          * know it */
     59                /*
     60                 * We are a function call, although C
     61                 * does not know it.
     62                 */
     63                : "%ra"
    6164        );
    6265       
  • uspace/lib/c/arch/mips32/src/thread_entry.S

    re895352 r49ff5f3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032
     
    4042.ent __thread_entry
    4143__thread_entry:
    42         .frame $sp, 32, $31
    43         .cpload $25
     44        .frame $sp, ABI_STACK_FRAME, $ra
     45        .cpload $t9
    4446       
    4547        #
    4648        # v0 contains address of uarg.
    4749        #
    48         add $4, $2, 0
     50        add $a0, $v0, 0
    4951       
    50         addiu $sp, -32
     52        # Allocate the stack frame.
     53        addiu $sp, -ABI_STACK_FRAME
     54       
     55        # Allow PIC code
    5156        .cprestore 16
    5257       
     
    5762        # Not reached.
    5863        #
     64        addiu $sp, ABI_STACK_FRAME
    5965.end __thread_entry
  • uspace/lib/c/arch/mips32eb/Makefile.inc

    re895352 r49ff5f3  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
    31         arch/$(UARCH)/src/entryjmp.s \
    32         arch/$(UARCH)/src/thread_entry.s \
     30        arch/$(UARCH)/src/entry.S \
     31        arch/$(UARCH)/src/entryjmp.S \
     32        arch/$(UARCH)/src/thread_entry.S \
    3333        arch/$(UARCH)/src/syscall.c \
    3434        arch/$(UARCH)/src/fibril.S \
  • uspace/lib/c/arch/mips64/Makefile.inc

    re895352 r49ff5f3  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
    31         arch/$(UARCH)/src/entryjmp.s \
    32         arch/$(UARCH)/src/thread_entry.s \
     30        arch/$(UARCH)/src/entry.S \
     31        arch/$(UARCH)/src/entryjmp.S \
     32        arch/$(UARCH)/src/thread_entry.S \
    3333        arch/$(UARCH)/src/syscall.c \
    3434        arch/$(UARCH)/src/fibril.S \
  • uspace/lib/c/arch/mips64/include/fibril.h

    re895352 r49ff5f3  
    3838
    3939#include <sys/types.h>
     40#include <libarch/stack.h>
     41#include <align.h>
    4042
    41 /* We define our own context_set, because we need to set
    42  * the TLS pointer to the tcb+0x7000
     43#define SP_DELTA  (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     44
     45/*
     46 * We define our own context_set, because we need to set
     47 * the TLS pointer to the tcb + 0x7000
    4348 *
    4449 * See tls_set in thread.h
    4550 */
    4651#define context_set(c, _pc, stack, size, ptls) \
    47         (c)->pc = (sysarg_t) (_pc); \
    48         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
    49         (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t);
    50 
    51 /* +16 is just for sure that the called function
    52  * have space to store it's arguments
    53  */
    54 #define SP_DELTA  (8 + 16)
     52        do { \
     53                (c)->pc = (sysarg_t) (_pc); \
     54                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
     55                (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t); \
     56        } while (0)
    5557
    5658typedef struct {
  • uspace/lib/c/arch/mips64/src/entry.S

    re895352 r49ff5f3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .init, "ax"
     
    4143.ent __entry
    4244__entry:
    43         .frame $sp, 32, $31
    44         .cpload $25
    45 
    46         # Mips o32 may store its arguments on stack, make space (16 bytes),
    47         # so that it could work with -O0
    48         # Make space additional 16 bytes for the stack frame
    49 
    50         addiu $sp, -32
    51         .cprestore 16   # Allow PIC code
    52 
    53         # Pass pcb_ptr to __main() as the first argument. pcb_ptr is already
     45        .frame $sp, ABI_STACK_FRAME, $ra
     46        .cpload $t9
     47       
     48        # Allocate the stack frame.
     49        addiu $sp, -ABI_STACK_FRAME
     50       
     51        # Allow PIC code
     52        .cprestore 16
     53       
     54        # Pass pcb_ptr to __main() as the first argument. It is already
    5455        # in $a0. As the first argument is passed in $a0, no operation
    5556        # is needed.
    56 
     57       
    5758        jal __main
    5859        nop
    59 .end
     60       
     61        #
     62        # Not reached.
     63        #
     64        addiu $sp, ABI_STACK_FRAME
     65.end __entry
  • uspace/lib/c/arch/mips64/src/entryjmp.S

    re895352 r49ff5f3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .text
     
    3436## void entry_point_jmp(void *entry_point, void *pcb);
    3537#
    36 # $a0 (=$4)     contains entry_point
    37 # $a1 (=$5)     contains pcb
     38# $a0 (=$4) contains entry_point
     39# $a1 (=$5) contains pcb
    3840#
    3941# Jump to program entry point
     
    4143entry_point_jmp:
    4244        # tmp := entry_point
    43         move $25, $a0
    44 
     45        move $t9, $a0
     46       
    4547        # Pass pcb to the entry point in $a0
    4648        move $a0, $a1
    47         jr $25
    48         nop
    49 .end
     49       
     50        jr $t9
     51        addiu $sp, -ABI_STACK_FRAME
     52        addiu $sp, ABI_STACK_FRAME
     53.end entry_point_jmp
  • uspace/lib/c/arch/mips64/src/thread_entry.S

    re895352 r49ff5f3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    30        
     32
    3133.set noat
    3234.set noreorder
    3335.option pic2
    34        
     36
    3537.globl __thread_entry
    3638
     
    4042.ent __thread_entry
    4143__thread_entry:
    42         .frame $sp, 32, $31
    43         .cpload $25
    44 
     44        .frame $sp, ABI_STACK_FRAME, $ra
     45        .cpload $t9
     46       
    4547        #
    4648        # v0 contains address of uarg.
    4749        #
    48         add $4, $2, 0
    49         # Mips o32 may store its arguments on stack, make space
    50         addiu $sp, -32
     50        add $a0, $v0, 0
     51       
     52        # Allocate the stack frame.
     53        addiu $sp, -ABI_STACK_FRAME
     54       
     55        # Allow PIC code
    5156        .cprestore 16
    5257       
    5358        jal __thread_main
    5459        nop
    55                
     60       
    5661        #
    5762        # Not reached.
    5863        #
     64        addiu $sp, ABI_STACK_FRAME
    5965.end __thread_entry
  • uspace/lib/c/arch/ppc32/include/fibril.h

    re895352 r49ff5f3  
    2727 */
    2828
    29 /** @addtogroup libcppc32       
     29/** @addtogroup libcppc32
    3030 * @{
    3131 */
     
    3838#include <sys/types.h>
    3939
    40 /* We define our own context_set, because we need to set
    41  * the TLS pointer to the tcb+0x7000
     40#define SP_DELTA  16
     41
     42/*
     43 * We define our own context_set, because we need to set
     44 * the TLS pointer to the tcb + 0x7000
    4245 *
    4346 * See tls_set in thread.h
    4447 */
    45 #define context_set(c, _pc, stack, size, ptls)                  \
    46         (c)->pc = (sysarg_t) (_pc);                             \
    47         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA;     \
    48         (c)->tls = ((sysarg_t) (ptls)) + 0x7000 + sizeof(tcb_t);
    49 
    50 #define SP_DELTA        16
     48#define context_set(c, _pc, stack, size, ptls) \
     49        do { \
     50                (c)->pc = (sysarg_t) (_pc); \
     51                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
     52                (c)->tls = ((sysarg_t) (ptls)) + 0x7000 + sizeof(tcb_t); \
     53        } while (0)
    5154
    5255typedef struct {
  • uspace/lib/c/arch/sparc64/include/fibril.h

    re895352 r49ff5f3  
    4040#include <align.h>
    4141
    42 #define SP_DELTA        (STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE)
     42#define SP_DELTA  (STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE)
    4343
    4444#define context_set(c, _pc, stack, size, ptls) \
     
    5050                (c)->tp = (uint64_t) ptls; \
    5151        } while (0)
    52        
     52
    5353/*
    5454 * Save only registers that must be preserved across
  • uspace/lib/c/generic/as.c

    re895352 r49ff5f3  
    4545/** Create address space area.
    4646 *
    47  * @param address Virtual address where to place new address space area.
    48  * @param size    Size of the area.
    49  * @param flags   Flags describing type of the area.
     47 * @param base  Starting virtual address of the area.
     48 *              If set to (void *) -1, the kernel finds
     49 *              a mappable area.
     50 * @param size  Size of the area.
     51 * @param flags Flags describing type of the area.
    5052 *
    51  * @return address on success, (void *) -1 otherwise.
     53 * @return Starting virtual address of the created area on success.
     54 * @return (void *) -1 otherwise.
    5255 *
    5356 */
    54 void *as_area_create(void *address, size_t size, unsigned int flags)
     57void *as_area_create(void *base, size_t size, unsigned int flags)
    5558{
    56         return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address,
    57             (sysarg_t) size, (sysarg_t) flags);
     59        return (void *) __SYSCALL4(SYS_AS_AREA_CREATE, (sysarg_t) base,
     60            (sysarg_t) size, (sysarg_t) flags, (sysarg_t) __entry);
    5861}
    5962
     
    102105}
    103106
    104 /** Return pointer to unmapped address space area
     107/** Find mapping to physical address.
    105108 *
    106  * @param size Requested size of the allocation.
     109 * @param      virt Virtual address to find mapping for.
     110 * @param[out] phys Physical adress.
    107111 *
    108  * @return Pointer to the beginning of unmapped address space area.
     112 * @return EOK on no error.
     113 * @retval ENOENT if no mapping was found.
    109114 *
    110115 */
    111 void *as_get_mappable_page(size_t size)
     116int as_get_physical_mapping(const void *virt, uintptr_t *phys)
    112117{
    113         return (void *) __SYSCALL2(SYS_AS_GET_UNMAPPED_AREA,
    114             (sysarg_t) __entry, (sysarg_t) size);
    115 }
    116 
    117 /** Find mapping to physical address.
    118  *
    119  * @param address Virtual address in question (virtual).
    120  * @param[out] frame Frame address (physical).
    121  * @return Error code.
    122  * @retval EOK No error, @p frame holds the translation.
    123  * @retval ENOENT Mapping not found.
    124  */
    125 int as_get_physical_mapping(const void *address, uintptr_t *frame)
    126 {
    127         uintptr_t tmp_frame;
    128         uintptr_t virt = (uintptr_t) address;
    129        
    130         int rc = (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING,
    131             (sysarg_t) virt, (sysarg_t) &tmp_frame);
    132         if (rc != EOK) {
    133                 return rc;
    134         }
    135        
    136         if (frame != NULL) {
    137                 *frame = tmp_frame;
    138         }
    139        
    140         return EOK;
     118        return (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING, (sysarg_t) virt,
     119            (sysarg_t) phys);
    141120}
    142121
  • uspace/lib/c/generic/async.c

    re895352 r49ff5f3  
    189189        /** If reply was received. */
    190190        bool done;
     191
     192        /** If the message / reply should be discarded on arrival. */
     193        bool forget;
     194
     195        /** If already destroyed. */
     196        bool destroyed;
    191197       
    192198        /** Pointer to where the answer data is stored. */
     
    241247static fibril_local connection_t *fibril_connection;
    242248
     249static void to_event_initialize(to_event_t *to)
     250{
     251        struct timeval tv = { 0, 0 };
     252
     253        to->inlist = false;
     254        to->occurred = false;
     255        link_initialize(&to->link);
     256        to->expires = tv;
     257}
     258
     259static void wu_event_initialize(wu_event_t *wu)
     260{
     261        wu->inlist = false;
     262        link_initialize(&wu->link);
     263}
     264
     265void awaiter_initialize(awaiter_t *aw)
     266{
     267        aw->fid = 0;
     268        aw->active = false;
     269        to_event_initialize(&aw->to_event);
     270        wu_event_initialize(&aw->wu_event);
     271}
     272
     273static amsg_t *amsg_create(void)
     274{
     275        amsg_t *msg;
     276
     277        msg = malloc(sizeof(amsg_t));
     278        if (msg) {
     279                msg->done = false;
     280                msg->forget = false;
     281                msg->destroyed = false;
     282                msg->dataptr = NULL;
     283                msg->retval = (sysarg_t) EINVAL;
     284                awaiter_initialize(&msg->wdata);
     285        }
     286
     287        return msg;
     288}
     289
     290static void amsg_destroy(amsg_t *msg)
     291{
     292        assert(!msg->destroyed);
     293        msg->destroyed = true;
     294        free(msg);
     295}
     296
    243297static void *default_client_data_constructor(void)
    244298{
     
    257311void async_set_client_data_constructor(async_client_data_ctor_t ctor)
    258312{
     313        assert(async_client_data_create == default_client_data_constructor);
    259314        async_client_data_create = ctor;
    260315}
     
    262317void async_set_client_data_destructor(async_client_data_dtor_t dtor)
    263318{
     319        assert(async_client_data_destroy == default_client_data_destructor);
    264320        async_client_data_destroy = dtor;
    265321}
     
    303359void async_set_client_connection(async_client_conn_t conn)
    304360{
     361        assert(client_connection == default_client_connection);
    305362        client_connection = conn;
    306363}
     
    9601017               
    9611018                suseconds_t timeout;
     1019                unsigned int flags = SYNCH_FLAGS_NONE;
    9621020                if (!list_empty(&timeout_list)) {
    9631021                        awaiter_t *waiter = list_get_instance(
     
    9701028                                futex_up(&async_futex);
    9711029                                handle_expired_timeouts();
    972                                 continue;
    973                         } else
     1030                                /*
     1031                                 * Notice that even if the event(s) already
     1032                                 * expired (and thus the other fibril was
     1033                                 * supposed to be running already),
     1034                                 * we check for incoming IPC.
     1035                                 *
     1036                                 * Otherwise, a fibril that continuously
     1037                                 * creates (almost) expired events could
     1038                                 * prevent IPC retrieval from the kernel.
     1039                                 */
     1040                                timeout = 0;
     1041                                flags = SYNCH_FLAGS_NON_BLOCKING;
     1042
     1043                        } else {
    9741044                                timeout = tv_sub(&waiter->to_event.expires, &tv);
    975                 } else
     1045                                futex_up(&async_futex);
     1046                        }
     1047                } else {
     1048                        futex_up(&async_futex);
    9761049                        timeout = SYNCH_NO_TIMEOUT;
    977                
    978                 futex_up(&async_futex);
     1050                }
    9791051               
    9801052                atomic_inc(&threads_in_ipc_wait);
    9811053               
    9821054                ipc_call_t call;
    983                 ipc_callid_t callid = ipc_wait_cycle(&call, timeout,
    984                     SYNCH_FLAGS_NONE);
     1055                ipc_callid_t callid = ipc_wait_cycle(&call, timeout, flags);
    9851056               
    9861057                atomic_dec(&threads_in_ipc_wait);
     
    10971168       
    10981169        msg->done = true;
    1099         if (!msg->wdata.active) {
     1170
     1171        if (msg->forget) {
     1172                assert(msg->wdata.active);
     1173                amsg_destroy(msg);
     1174        } else if (!msg->wdata.active) {
    11001175                msg->wdata.active = true;
    11011176                fibril_add_ready(msg->wdata.fid);
    11021177        }
    1103        
     1178
    11041179        futex_up(&async_futex);
    11051180}
     
    11281203                return 0;
    11291204       
    1130         amsg_t *msg = malloc(sizeof(amsg_t));
     1205        amsg_t *msg = amsg_create();
    11311206        if (msg == NULL)
    11321207                return 0;
    11331208       
    1134         msg->done = false;
    11351209        msg->dataptr = dataptr;
    1136        
    1137         msg->wdata.to_event.inlist = false;
    1138        
    1139         /*
    1140          * We may sleep in the next method,
    1141          * but it will use its own means
    1142          */
    11431210        msg->wdata.active = true;
    11441211       
     
    11741241                return 0;
    11751242       
    1176         amsg_t *msg = malloc(sizeof(amsg_t));
    1177        
     1243        amsg_t *msg = amsg_create();
    11781244        if (msg == NULL)
    11791245                return 0;
    11801246       
    1181         msg->done = false;
    11821247        msg->dataptr = dataptr;
    1183        
    1184         msg->wdata.to_event.inlist = false;
    1185        
    1186         /*
    1187          * We may sleep in the next method,
    1188          * but it will use its own means
    1189          */
    11901248        msg->wdata.active = true;
    11911249       
     
    12101268       
    12111269        futex_down(&async_futex);
     1270
     1271        assert(!msg->forget);
     1272        assert(!msg->destroyed);
     1273
    12121274        if (msg->done) {
    12131275                futex_up(&async_futex);
     
    12281290                *retval = msg->retval;
    12291291       
    1230         free(msg);
     1292        amsg_destroy(msg);
    12311293}
    12321294
    12331295/** Wait for a message sent by the async framework, timeout variant.
     1296 *
     1297 * If the wait times out, the caller may choose to either wait again by calling
     1298 * async_wait_for() or async_wait_timeout(), or forget the message via
     1299 * async_forget().
    12341300 *
    12351301 * @param amsgid  Hash of the message to wait for.
     
    12461312       
    12471313        amsg_t *msg = (amsg_t *) amsgid;
    1248        
    1249         /* TODO: Let it go through the event read at least once */
    1250         if (timeout < 0)
    1251                 return ETIMEOUT;
    1252        
     1314
    12531315        futex_down(&async_futex);
     1316
     1317        assert(!msg->forget);
     1318        assert(!msg->destroyed);
     1319
    12541320        if (msg->done) {
    12551321                futex_up(&async_futex);
     
    12571323        }
    12581324       
     1325        /*
     1326         * Negative timeout is converted to zero timeout to avoid
     1327         * using tv_add with negative augmenter.
     1328         */
     1329        if (timeout < 0)
     1330                timeout = 0;
     1331
    12591332        gettimeofday(&msg->wdata.to_event.expires, NULL);
    12601333        tv_add(&msg->wdata.to_event.expires, timeout);
    12611334       
     1335        /*
     1336         * Current fibril is inserted as waiting regardless of the
     1337         * "size" of the timeout.
     1338         *
     1339         * Checking for msg->done and immediately bailing out when
     1340         * timeout == 0 would mean that the manager fibril would never
     1341         * run (consider single threaded program).
     1342         * Thus the IPC answer would be never retrieved from the kernel.
     1343         *
     1344         * Notice that the actual delay would be very small because we
     1345         * - switch to manager fibril
     1346         * - the manager sees expired timeout
     1347         * - and thus adds us back to ready queue
     1348         * - manager switches back to some ready fibril
     1349         *   (prior it, it checks for incoming IPC).
     1350         *
     1351         */
    12621352        msg->wdata.fid = fibril_get_id();
    12631353        msg->wdata.active = false;
     
    12761366                *retval = msg->retval;
    12771367       
    1278         free(msg);
     1368        amsg_destroy(msg);
    12791369       
    12801370        return 0;
    12811371}
     1372 
     1373/** Discard the message / reply on arrival.
     1374 *
     1375 * The message will be marked to be discarded once the reply arrives in
     1376 * reply_received(). It is not allowed to call async_wait_for() or
     1377 * async_wait_timeout() on this message after a call to this function.
     1378 *
     1379 * @param amsgid  Hash of the message to forget.
     1380 */
     1381void async_forget(aid_t amsgid)
     1382{
     1383        amsg_t *msg = (amsg_t *) amsgid;
     1384
     1385        assert(msg);
     1386        assert(!msg->forget);
     1387        assert(!msg->destroyed);
     1388
     1389        futex_down(&async_futex);
     1390        if (msg->done)
     1391                amsg_destroy(msg);
     1392        else
     1393                msg->forget = true;
     1394        futex_up(&async_futex);
     1395}
    12821396
    12831397/** Wait for specified time.
     
    12901404void async_usleep(suseconds_t timeout)
    12911405{
    1292         amsg_t *msg = malloc(sizeof(amsg_t));
    1293        
     1406        amsg_t *msg = amsg_create();
    12941407        if (!msg)
    12951408                return;
    12961409       
    12971410        msg->wdata.fid = fibril_get_id();
    1298         msg->wdata.active = false;
    12991411       
    13001412        gettimeofday(&msg->wdata.to_event.expires, NULL);
     
    13101422        /* Futex is up automatically after fibril_switch() */
    13111423       
    1312         free(msg);
     1424        amsg_destroy(msg);
    13131425}
    13141426
     
    15811693        ipc_call_t result;
    15821694       
    1583         amsg_t *msg = malloc(sizeof(amsg_t));
    1584         if (msg == NULL) {
     1695        amsg_t *msg = amsg_create();
     1696        if (!msg) {
    15851697                free(sess);
    15861698                errno = ENOMEM;
     
    15881700        }
    15891701       
    1590         msg->done = false;
    15911702        msg->dataptr = &result;
    1592        
    1593         msg->wdata.to_event.inlist = false;
    1594        
    1595         /*
    1596          * We may sleep in the next method,
    1597          * but it will use its own means
    1598          */
    15991703        msg->wdata.active = true;
    16001704       
     
    16401744        ipc_call_t result;
    16411745       
    1642         amsg_t *msg = malloc(sizeof(amsg_t));
    1643         if (msg == NULL)
     1746        amsg_t *msg = amsg_create();
     1747        if (!msg)
    16441748                return ENOENT;
    16451749       
    1646         msg->done = false;
    16471750        msg->dataptr = &result;
    1648        
    1649         msg->wdata.to_event.inlist = false;
    1650        
    1651         /*
    1652          * We may sleep in the next method,
    1653          * but it will use its own means
    1654          */
    16551751        msg->wdata.active = true;
    16561752       
     
    18461942       
    18471943        fibril_mutex_lock(&async_sess_mutex);
    1848 
     1944       
    18491945        int rc = async_hangup_internal(sess->phone);
    18501946       
     
    19982094 *
    19992095 * @param exch  Exchange for sending the message.
    2000  * @param dst   Destination address space area base.
    20012096 * @param size  Size of the destination address space area.
    20022097 * @param arg   User defined argument.
    20032098 * @param flags Storage for the received flags. Can be NULL.
     2099 * @param dst   Destination address space area base. Cannot be NULL.
    20042100 *
    20052101 * @return Zero on success or a negative error code from errno.h.
    20062102 *
    20072103 */
    2008 int async_share_in_start(async_exch_t *exch, void *dst, size_t size,
    2009     sysarg_t arg, unsigned int *flags)
     2104int async_share_in_start(async_exch_t *exch, size_t size, sysarg_t arg,
     2105    unsigned int *flags, void **dst)
    20102106{
    20112107        if (exch == NULL)
    20122108                return ENOENT;
    20132109       
    2014         sysarg_t tmp_flags;
    2015         int res = async_req_3_2(exch, IPC_M_SHARE_IN, (sysarg_t) dst,
    2016             (sysarg_t) size, arg, NULL, &tmp_flags);
     2110        sysarg_t _flags = 0;
     2111        sysarg_t _dst = (sysarg_t) -1;
     2112        int res = async_req_2_4(exch, IPC_M_SHARE_IN, (sysarg_t) size,
     2113            arg, NULL, &_flags, NULL, &_dst);
    20172114       
    20182115        if (flags)
    2019                 *flags = (unsigned int) tmp_flags;
    2020        
     2116                *flags = (unsigned int) _flags;
     2117       
     2118        *dst = (void *) _dst;
    20212119        return res;
    20222120}
     
    20472145                return false;
    20482146       
    2049         *size = (size_t) IPC_GET_ARG2(data);
     2147        *size = (size_t) IPC_GET_ARG1(data);
    20502148        return true;
    20512149}
     
    20532151/** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework.
    20542152 *
    2055  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
     2153 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_IN
    20562154 * calls so that the user doesn't have to remember the meaning of each IPC
    20572155 * argument.
     
    21312229 *
    21322230 */
    2133 int async_share_out_finalize(ipc_callid_t callid, void *dst)
     2231int async_share_out_finalize(ipc_callid_t callid, void **dst)
    21342232{
    21352233        return ipc_share_out_finalize(callid, dst);
     
    22462344            IPC_FF_ROUTE_FROM_ME);
    22472345        if (retval != EOK) {
    2248                 async_wait_for(msg, NULL);
     2346                async_forget(msg);
    22492347                ipc_answer_0(callid, retval);
    22502348                return retval;
     
    24402538            IPC_FF_ROUTE_FROM_ME);
    24412539        if (retval != EOK) {
    2442                 async_wait_for(msg, NULL);
     2540                async_forget(msg);
    24432541                ipc_answer_0(callid, retval);
    24442542                return retval;
  • uspace/lib/c/generic/ddi.c

    re895352 r49ff5f3  
    3333 */
    3434
     35#include <assert.h>
     36#include <unistd.h>
     37#include <errno.h>
    3538#include <sys/types.h>
    3639#include <abi/ddi/arg.h>
     
    4245#include <align.h>
    4346#include <libarch/config.h>
     47#include "private/libc.h"
    4448
    4549/** Return unique device number.
     
    5357}
    5458
    55 /** Map piece of physical memory to task.
     59/** Map a piece of physical memory to task.
    5660 *
    5761 * Caller of this function must have the CAP_MEM_MANAGER capability.
    5862 *
    59  * @param pf            Physical address of the starting frame.
    60  * @param vp            Virtual address of the starting page.
    61  * @param pages         Number of pages to map.
    62  * @param flags         Flags for the new address space area.
     63 * @param phys  Physical address of the starting frame.
     64 * @param pages Number of pages to map.
     65 * @param flags Flags for the new address space area.
     66 * @param virt  Virtual address of the starting page.
    6367 *
    64  * @return              0 on success, EPERM if the caller lacks the
    65  *                      CAP_MEM_MANAGER capability, ENOENT if there is no task
    66  *                      with specified ID and ENOMEM if there was some problem
    67  *                      in creating address space area.
     68 * @return EOK on success
     69 * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability
     70 * @return ENOENT if there is no task with specified ID
     71 * @return ENOMEM if there was some problem in creating
     72 *         the address space area.
     73 *
    6874 */
    69 int physmem_map(void *pf, void *vp, unsigned long pages, int flags)
     75int physmem_map(void *phys, size_t pages, unsigned int flags, void **virt)
    7076{
    71         return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp, pages,
    72             flags);
     77        return __SYSCALL5(SYS_PHYSMEM_MAP, (sysarg_t) phys,
     78            pages, flags, (sysarg_t) virt, (sysarg_t) __entry);
     79}
     80
     81int dmamem_map(void *virt, size_t size, unsigned int map_flags,
     82    unsigned int flags, void **phys)
     83{
     84        return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size,
     85            (sysarg_t) map_flags, (sysarg_t) flags & ~DMAMEM_FLAGS_ANONYMOUS,
     86            (sysarg_t) phys, (sysarg_t) virt, 0);
     87}
     88
     89int dmamem_map_anonymous(size_t size, unsigned int map_flags,
     90    unsigned int flags, void **phys, void **virt)
     91{
     92        return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size,
     93            (sysarg_t) map_flags, (sysarg_t) flags | DMAMEM_FLAGS_ANONYMOUS,
     94            (sysarg_t) phys, (sysarg_t) virt, (sysarg_t) __entry);
     95}
     96
     97int dmamem_unmap(void *virt, size_t size)
     98{
     99        return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, (sysarg_t) size, 0);
     100}
     101
     102int dmamem_unmap_anonymous(void *virt)
     103{
     104        return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, 0,
     105            DMAMEM_FLAGS_ANONYMOUS);
    73106}
    74107
     
    77110 * Caller of this function must have the IO_MEM_MANAGER capability.
    78111 *
    79  * @param id            Task ID.
    80  * @param ioaddr        Starting address of the I/O range.
    81  * @param size          Size of the range.
     112 * @param id     Task ID.
     113 * @param ioaddr Starting address of the I/O range.
     114 * @param size   Size of the range.
    82115 *
    83  * @return              0 on success, EPERM if the caller lacks the
    84  *                      CAP_IO_MANAGER capability, ENOENT if there is no task
    85  *                      with specified ID and ENOMEM if there was some problem
    86  *                      in allocating memory.
     116 * @return EOK on success
     117 * @return EPERM if the caller lacks the CAP_IO_MANAGER capability
     118 * @return ENOENT if there is no task with specified ID
     119 * @return ENOMEM if there was some problem in allocating memory.
     120 *
    87121 */
    88122int iospace_enable(task_id_t id, void *ioaddr, unsigned long size)
    89123{
    90124        ddi_ioarg_t arg;
    91 
     125       
    92126        arg.task_id = id;
    93127        arg.ioaddr = ioaddr;
    94128        arg.size = size;
    95 
     129       
    96130        return __SYSCALL1(SYS_IOSPACE_ENABLE, (sysarg_t) &arg);
    97131}
     
    99133/** Enable PIO for specified I/O range.
    100134 *
    101  * @param pio_addr      I/O start address.
    102  * @param size          Size of the I/O region.
    103  * @param use_addr      Address where the final address for application's PIO
    104  *                      will be stored.
     135 * @param pio_addr I/O start address.
     136 * @param size     Size of the I/O region.
     137 * @param virt     Virtual address for application's
     138 *                 PIO operations.
    105139 *
    106  * @return              Zero on success or negative error code.
     140 * @return EOK on success.
     141 * @return Negative error code on failure.
     142 *
    107143 */
    108 int pio_enable(void *pio_addr, size_t size, void **use_addr)
     144int pio_enable(void *pio_addr, size_t size, void **virt)
    109145{
    110         void *phys;
    111         void *virt;
    112         size_t offset;
    113         unsigned int pages;
    114 
    115146#ifdef IO_SPACE_BOUNDARY
    116147        if (pio_addr < IO_SPACE_BOUNDARY) {
    117                 *use_addr = pio_addr;
     148                *virt = pio_addr;
    118149                return iospace_enable(task_get_id(), pio_addr, size);
    119150        }
    120151#endif
    121 
    122         phys = (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
    123         offset = pio_addr - phys;
    124         pages = ALIGN_UP(offset + size, PAGE_SIZE) >> PAGE_WIDTH;
    125         virt = as_get_mappable_page(pages << PAGE_WIDTH);
    126         *use_addr = virt + offset;
    127         return physmem_map(phys, virt, pages, AS_AREA_READ | AS_AREA_WRITE);
     152       
     153        void *phys_frame =
     154            (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
     155        size_t offset = pio_addr - phys_frame;
     156        size_t pages = SIZE2PAGES(offset + size);
     157       
     158        void *virt_page;
     159        int rc = physmem_map(phys_frame, pages,
     160            AS_AREA_READ | AS_AREA_WRITE, &virt_page);
     161        if (rc != EOK)
     162                return rc;
     163       
     164        *virt = virt_page + offset;
     165        return EOK;
    128166}
    129167
     
    138176 *
    139177 */
    140 int register_irq(int inr, int devno, int method, irq_code_t *ucode)
     178int irq_register(int inr, int devno, int method, irq_code_t *ucode)
    141179{
    142         return __SYSCALL4(SYS_REGISTER_IRQ, inr, devno, method,
     180        return __SYSCALL4(SYS_IRQ_REGISTER, inr, devno, method,
    143181            (sysarg_t) ucode);
    144182}
     
    152190 *
    153191 */
    154 int unregister_irq(int inr, int devno)
     192int irq_unregister(int inr, int devno)
    155193{
    156         return __SYSCALL2(SYS_UNREGISTER_IRQ, inr, devno);
     194        return __SYSCALL2(SYS_IRQ_UNREGISTER, inr, devno);
    157195}
    158196
  • uspace/lib/c/generic/device/nic.c

    re895352 r49ff5f3  
    4444#include <ipc/services.h>
    4545
    46 /** Send a packet through the device
    47  *
    48  * @param[in] dev_sess
    49  * @param[in] packet_id Id of the sent packet
    50  *
    51  * @return EOK If the operation was successfully completed
    52  *
    53  */
    54 int nic_send_message(async_sess_t *dev_sess, packet_id_t packet_id)
    55 {
    56         async_exch_t *exch = async_exchange_begin(dev_sess);
    57         int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
    58             NIC_SEND_MESSAGE, packet_id);
    59         async_exchange_end(exch);
    60        
    61         return rc;
    62 }
    63 
    64 /** Connect the driver to the NET and NIL services
    65  *
    66  * @param[in] dev_sess
    67  * @param[in] nil_service Service identifier for the NIL service
     46/** Send frame from NIC
     47 *
     48 * @param[in] dev_sess
     49 * @param[in] data     Frame data
     50 * @param[in] size     Frame size in bytes
     51 *
     52 * @return EOK If the operation was successfully completed
     53 *
     54 */
     55int nic_send_frame(async_sess_t *dev_sess, void *data, size_t size)
     56{
     57        async_exch_t *exch = async_exchange_begin(dev_sess);
     58       
     59        ipc_call_t answer;
     60        aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     61            NIC_SEND_MESSAGE, &answer);
     62        sysarg_t retval = async_data_write_start(exch, data, size);
     63       
     64        async_exchange_end(exch);
     65       
     66        if (retval != EOK) {
     67                async_wait_for(req, NULL);
     68                return retval;
     69        }
     70
     71        async_wait_for(req, &retval);
     72        return retval;
     73}
     74
     75/** Create callback connection from NIC service
     76 *
     77 * @param[in] dev_sess
    6878 * @param[in] device_id
    6979 *
     
    7181 *
    7282 */
    73 int nic_connect_to_nil(async_sess_t *dev_sess, services_t nil_service,
    74     nic_device_id_t device_id)
    75 {
    76         async_exch_t *exch = async_exchange_begin(dev_sess);
    77         int rc = async_req_3_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
    78             NIC_CONNECT_TO_NIL, nil_service, device_id);
    79         async_exchange_end(exch);
    80        
    81         return rc;
     83int nic_callback_create(async_sess_t *dev_sess, async_client_conn_t cfun,
     84    void *carg)
     85{
     86        ipc_call_t answer;
     87        int rc;
     88        sysarg_t retval;
     89       
     90        async_exch_t *exch = async_exchange_begin(dev_sess);
     91        aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
     92            NIC_CALLBACK_CREATE, &answer);
     93       
     94        rc = async_connect_to_me(exch, 0, 0, 0, cfun, carg);
     95        if (rc != EOK) {
     96                async_wait_for(req, NULL);
     97                return rc;
     98        }
     99        async_exchange_end(exch);
     100       
     101        async_wait_for(req, &retval);
     102        return (int) retval;
    82103}
    83104
     
    324345 * it can never force the NIC to advertise unsupported modes.
    325346 *
    326  * The allowed modes are defined in "net/eth_phys.h" in the C library.
     347 * The allowed modes are defined in "nic/eth_phys.h" in the C library.
    327348 *
    328349 * @param[in] dev_sess
     
    361382/** Probe current state of auto-negotiation.
    362383 *
    363  * Modes are defined in the "net/eth_phys.h" in the C library.
     384 * Modes are defined in the "nic/eth_phys.h" in the C library.
    364385 *
    365386 * @param[in]  dev_sess
     
    895916 *
    896917 */
    897 int nic_vlan_set_tag(async_sess_t *dev_sess, uint16_t tag, int add, int strip)
     918int nic_vlan_set_tag(async_sess_t *dev_sess, uint16_t tag, bool add, bool strip)
    898919{
    899920        async_exch_t *exch = async_exchange_begin(dev_sess);
  • uspace/lib/c/generic/devman.c

    re895352 r49ff5f3  
    177177
    178178/** Register running driver with device manager. */
    179 int devman_driver_register(const char *name, async_client_conn_t conn)
     179int devman_driver_register(const char *name)
    180180{
    181181        async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
     
    192192        }
    193193       
    194         async_set_client_connection(conn);
    195        
    196194        exch = devman_exchange_begin(DEVMAN_DRIVER);
    197         async_connect_to_me(exch, 0, 0, 0, conn, NULL);
     195        async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
    198196        devman_exchange_end(exch);
    199197       
  • uspace/lib/c/generic/elf/elf_load.c

    re895352 r49ff5f3  
    364364         * and writeable.
    365365         */
    366         a = as_area_create((uint8_t *)base + bias, mem_sz,
     366        a = as_area_create((uint8_t *) base + bias, mem_sz,
    367367            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    368         if (a == (void *)(-1)) {
     368        if (a == (void *) -1) {
    369369                DPRINTF("memory mapping failed (0x%x, %d)\n",
    370                         base+bias, mem_sz);
     370                    base + bias, mem_sz);
    371371                return EE_MEMORY;
    372372        }
  • uspace/lib/c/generic/fibril_synch.c

    re895352 r49ff5f3  
    112112                awaiter_t wdata;
    113113
     114                awaiter_initialize(&wdata);
    114115                wdata.fid = fibril_get_id();
    115                 wdata.active = false;
    116116                wdata.wu_event.inlist = true;
    117                 link_initialize(&wdata.wu_event.link);
    118117                list_append(&wdata.wu_event.link, &fm->waiters);
    119118                check_for_deadlock(&fm->oi);
     
    205204                awaiter_t wdata;
    206205
     206                awaiter_initialize(&wdata);
    207207                wdata.fid = (fid_t) f;
    208                 wdata.active = false;
    209208                wdata.wu_event.inlist = true;
    210                 link_initialize(&wdata.wu_event.link);
    211209                f->flags &= ~FIBRIL_WRITER;
    212210                list_append(&wdata.wu_event.link, &frw->waiters);
     
    233231                awaiter_t wdata;
    234232
     233                awaiter_initialize(&wdata);
    235234                wdata.fid = (fid_t) f;
    236                 wdata.active = false;
    237235                wdata.wu_event.inlist = true;
    238                 link_initialize(&wdata.wu_event.link);
    239236                f->flags |= FIBRIL_WRITER;
    240237                list_append(&wdata.wu_event.link, &frw->waiters);
     
    375372                return ETIMEOUT;
    376373
     374        awaiter_initialize(&wdata);
    377375        wdata.fid = fibril_get_id();
    378         wdata.active = false;
    379        
    380376        wdata.to_event.inlist = timeout > 0;
    381         wdata.to_event.occurred = false;
    382         link_initialize(&wdata.to_event.link);
    383 
    384377        wdata.wu_event.inlist = true;
    385         link_initialize(&wdata.wu_event.link);
    386378
    387379        futex_down(&async_futex);
     
    447439}
    448440
     441/** Timer fibril.
     442 *
     443 * @param arg   Timer
     444 */
     445static int fibril_timer_func(void *arg)
     446{
     447        fibril_timer_t *timer = (fibril_timer_t *) arg;
     448        int rc;
     449
     450        fibril_mutex_lock(&timer->lock);
     451
     452        while (true) {
     453                while (timer->state != fts_active &&
     454                    timer->state != fts_cleanup) {
     455
     456                        if (timer->state == fts_cleanup)
     457                                break;
     458
     459                        fibril_condvar_wait(&timer->cv, &timer->lock);
     460                }
     461
     462                if (timer->state == fts_cleanup)
     463                        break;
     464
     465                rc = fibril_condvar_wait_timeout(&timer->cv, &timer->lock,
     466                    timer->delay);
     467                if (rc == ETIMEOUT) {
     468                        timer->state = fts_fired;
     469                        fibril_mutex_unlock(&timer->lock);
     470                        timer->fun(timer->arg);
     471                        fibril_mutex_lock(&timer->lock);
     472                }
     473        }
     474
     475        fibril_mutex_unlock(&timer->lock);
     476        return 0;
     477}
     478
     479/** Create new timer.
     480 *
     481 * @return              New timer on success, @c NULL if out of memory.
     482 */
     483fibril_timer_t *fibril_timer_create(void)
     484{
     485        fid_t fid;
     486        fibril_timer_t *timer;
     487
     488        timer = calloc(1, sizeof(fibril_timer_t));
     489        if (timer == NULL)
     490                return NULL;
     491
     492        fid = fibril_create(fibril_timer_func, (void *) timer);
     493        if (fid == 0) {
     494                free(timer);
     495                return NULL;
     496        }
     497
     498        fibril_mutex_initialize(&timer->lock);
     499        fibril_condvar_initialize(&timer->cv);
     500
     501        timer->fibril = fid;
     502        timer->state = fts_not_set;
     503
     504        fibril_add_ready(fid);
     505
     506        return timer;
     507}
     508
     509/** Destroy timer.
     510 *
     511 * @param timer         Timer, must not be active or accessed by other threads.
     512 */
     513void fibril_timer_destroy(fibril_timer_t *timer)
     514{
     515        fibril_mutex_lock(&timer->lock);
     516        assert(timer->state != fts_active);
     517        timer->state = fts_cleanup;
     518        fibril_condvar_broadcast(&timer->cv);
     519        fibril_mutex_unlock(&timer->lock);
     520}
     521
     522/** Set timer.
     523 *
     524 * Set timer to execute a callback function after the specified
     525 * interval.
     526 *
     527 * @param timer         Timer
     528 * @param delay         Delay in microseconds
     529 * @param fun           Callback function
     530 * @param arg           Argument for @a fun
     531 */
     532void fibril_timer_set(fibril_timer_t *timer, suseconds_t delay,
     533    fibril_timer_fun_t fun, void *arg)
     534{
     535        fibril_mutex_lock(&timer->lock);
     536        timer->state = fts_active;
     537        timer->delay = delay;
     538        timer->fun = fun;
     539        timer->arg = arg;
     540        fibril_condvar_broadcast(&timer->cv);
     541        fibril_mutex_unlock(&timer->lock);
     542}
     543
     544/** Clear timer.
     545 *
     546 * Clears (cancels) timer and returns last state of the timer.
     547 * This can be one of:
     548 *    - fts_not_set     If the timer has not been set or has been cleared
     549 *    - fts_active      Timer was set but did not fire
     550 *    - fts_fired       Timer fired
     551 *
     552 * @param timer         Timer
     553 * @return              Last timer state
     554 */
     555fibril_timer_state_t fibril_timer_clear(fibril_timer_t *timer)
     556{
     557        fibril_timer_state_t old_state;
     558
     559        fibril_mutex_lock(&timer->lock);
     560        old_state = timer->state;
     561        timer->state = fts_not_set;
     562
     563        timer->delay = 0;
     564        timer->fun = NULL;
     565        timer->arg = NULL;
     566        fibril_condvar_broadcast(&timer->cv);
     567        fibril_mutex_unlock(&timer->lock);
     568
     569        return old_state;
     570}
     571
    449572/** @}
    450573 */
  • uspace/lib/c/generic/io/printf_core.c

    re895352 r49ff5f3  
    283283        /* Print leading spaces. */
    284284        size_t strw = str_length(str);
    285         if (precision == 0)
     285        if ((precision == 0) || (precision > strw))
    286286                precision = strw;
    287287       
     
    331331        /* Print leading spaces. */
    332332        size_t strw = wstr_length(str);
    333         if (precision == 0)
     333        if ((precision == 0) || (precision > strw))
    334334                precision = strw;
    335335       
  • uspace/lib/c/generic/ipc.c

    re895352 r49ff5f3  
    4848#include <fibril.h>
    4949#include <macros.h>
     50#include "private/libc.h"
    5051
    5152/**
     
    760761 *
    761762 * @param phoneid Phone that will be used to contact the receiving side.
    762  * @param dst     Destination address space area base.
    763763 * @param size    Size of the destination address space area.
    764764 * @param arg     User defined argument.
    765765 * @param flags   Storage for received flags. Can be NULL.
     766 * @param dst     Destination address space area base. Cannot be NULL.
    766767 *
    767768 * @return Zero on success or a negative error code from errno.h.
    768769 *
    769770 */
    770 int ipc_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
    771     unsigned int *flags)
    772 {
    773         sysarg_t tmp_flags = 0;
    774         int res = ipc_call_sync_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
    775             (sysarg_t) size, arg, NULL, &tmp_flags);
     771int ipc_share_in_start(int phoneid, size_t size, sysarg_t arg,
     772    unsigned int *flags, void **dst)
     773{
     774        sysarg_t _flags = 0;
     775        sysarg_t _dst = (sysarg_t) -1;
     776        int res = ipc_call_sync_2_4(phoneid, IPC_M_SHARE_IN, (sysarg_t) size,
     777            arg, NULL, &_flags, NULL, &_dst);
    776778       
    777779        if (flags)
    778                 *flags = (unsigned int) tmp_flags;
    779        
     780                *flags = (unsigned int) _flags;
     781       
     782        *dst = (void *) _dst;
    780783        return res;
    781784}
     
    783786/** Wrapper for answering the IPC_M_SHARE_IN calls.
    784787 *
    785  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
     788 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_IN
    786789 * calls so that the user doesn't have to remember the meaning of each
    787790 * IPC argument.
     
    796799int ipc_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
    797800{
    798         return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) flags);
     801        return ipc_answer_3(callid, EOK, (sysarg_t) src, (sysarg_t) flags,
     802            (sysarg_t) __entry);
    799803}
    800804
     
    826830 *
    827831 */
    828 int ipc_share_out_finalize(ipc_callid_t callid, void *dst)
    829 {
    830         return ipc_answer_1(callid, EOK, (sysarg_t) dst);
     832int ipc_share_out_finalize(ipc_callid_t callid, void **dst)
     833{
     834        return ipc_answer_2(callid, EOK, (sysarg_t) __entry, (sysarg_t) dst);
    831835}
    832836
  • uspace/lib/c/generic/loc.c

    re895352 r49ff5f3  
    4747static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex);
    4848static bool loc_callback_created = false;
     49static loc_cat_change_cb_t cat_change_cb = NULL;
    4950
    5051static async_sess_t *loc_supp_block_sess = NULL;
     
    5455static async_sess_t *loc_consumer_sess = NULL;
    5556
    56 static loc_cat_change_cb_t cat_change_cb = NULL;
    57 
    5857static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    5958{
    60         loc_cat_change_cb_t cb_fun;
    61        
    6259        while (true) {
    6360                ipc_call_t call;
     
    6966                }
    7067               
    71                 int retval;
    72                
    7368                switch (IPC_GET_IMETHOD(call)) {
    7469                case LOC_EVENT_CAT_CHANGE:
    7570                        fibril_mutex_lock(&loc_callback_mutex);
    76                         cb_fun = cat_change_cb;
    77                         if (cb_fun != NULL) {
     71                        loc_cat_change_cb_t cb_fun = cat_change_cb;
     72                        fibril_mutex_unlock(&loc_callback_mutex);
     73                       
     74                        async_answer_0(callid, EOK);
     75                       
     76                        if (cb_fun != NULL)
    7877                                (*cb_fun)();
    79                         }
    80                         fibril_mutex_unlock(&loc_callback_mutex);
    81                         retval = 0;
     78                       
    8279                        break;
    8380                default:
    84                         retval = ENOTSUP;
     81                        async_answer_0(callid, ENOTSUP);
    8582                }
    86                
    87                 async_answer_0(callid, retval);
    8883        }
    8984}
     
    10196}
    10297
     98/** Create callback
     99 *
     100 * Must be called with loc_callback_mutex locked.
     101 *
     102 * @return EOK on success.
     103 *
     104 */
    103105static int loc_callback_create(void)
    104106{
    105         async_exch_t *exch;
    106         sysarg_t retval;
    107         int rc = EOK;
    108 
    109         fibril_mutex_lock(&loc_callback_mutex);
    110        
    111107        if (!loc_callback_created) {
    112                 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     108                async_exch_t *exch =
     109                    loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
    113110               
    114111                ipc_call_t answer;
    115112                aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer);
    116                 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
     113                int rc = async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
    117114                loc_exchange_end(exch);
    118115               
     116                if (rc != EOK)
     117                        return rc;
     118               
     119                sysarg_t retval;
    119120                async_wait_for(req, &retval);
    120                 if (rc != EOK)
    121                         goto done;
    122                
    123                 if (retval != EOK) {
    124                         rc = retval;
    125                         goto done;
    126                 }
     121                if (retval != EOK)
     122                        return retval;
    127123               
    128124                loc_callback_created = true;
    129125        }
    130126       
    131         rc = EOK;
    132 done:
    133         fibril_mutex_unlock(&loc_callback_mutex);
    134         return rc;
     127        return EOK;
    135128}
    136129
     
    242235
    243236/** Register new driver with loc. */
    244 int loc_server_register(const char *name, async_client_conn_t conn)
     237int loc_server_register(const char *name)
    245238{
    246239        async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     
    256249                return retval;
    257250        }
    258        
    259         async_set_client_connection(conn);
    260251       
    261252        exch = loc_exchange_begin(LOC_PORT_SUPPLIER);
     
    797788    sysarg_t **data, size_t *count)
    798789{
    799         service_id_t *ids;
    800         size_t act_size;
    801         size_t alloc_size;
    802         int rc;
    803 
    804790        *data = NULL;
    805         act_size = 0;   /* silence warning */
    806 
    807         rc = loc_category_get_ids_once(method, arg1, NULL, 0,
     791        *count = 0;
     792       
     793        size_t act_size = 0;
     794        int rc = loc_category_get_ids_once(method, arg1, NULL, 0,
    808795            &act_size);
    809796        if (rc != EOK)
    810797                return rc;
    811 
    812         alloc_size = act_size;
    813         ids = malloc(alloc_size);
     798       
     799        size_t alloc_size = act_size;
     800        service_id_t *ids = malloc(alloc_size);
    814801        if (ids == NULL)
    815802                return ENOMEM;
    816 
     803       
    817804        while (true) {
    818805                rc = loc_category_get_ids_once(method, arg1, ids, alloc_size,
     
    820807                if (rc != EOK)
    821808                        return rc;
    822 
     809               
    823810                if (act_size <= alloc_size)
    824811                        break;
    825 
    826                 alloc_size *= 2;
    827                 free(ids);
    828 
    829                 ids = malloc(alloc_size);
     812               
     813                alloc_size = act_size;
     814                ids = realloc(ids, alloc_size);
    830815                if (ids == NULL)
    831816                        return ENOMEM;
    832817        }
    833 
     818       
    834819        *count = act_size / sizeof(category_id_t);
    835820        *data = ids;
     
    869854int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
    870855{
    871         if (loc_callback_create() != EOK)
     856        fibril_mutex_lock(&loc_callback_mutex);
     857        if (loc_callback_create() != EOK) {
     858                fibril_mutex_unlock(&loc_callback_mutex);
    872859                return EIO;
    873 
     860        }
     861       
    874862        cat_change_cb = cb_fun;
     863        fibril_mutex_unlock(&loc_callback_mutex);
     864       
    875865        return EOK;
    876866}
  • uspace/lib/c/generic/malloc.c

    re895352 r49ff5f3  
    283283static bool area_create(size_t size)
    284284{
    285         void *start = as_get_mappable_page(size);
    286         if (start == NULL)
    287                 return false;
    288        
    289         /* Align the heap area on page boundary */
    290         void *astart = (void *) ALIGN_UP((uintptr_t) start, PAGE_SIZE);
     285        /* Align the heap area size on page boundary */
    291286        size_t asize = ALIGN_UP(size, PAGE_SIZE);
    292        
    293         astart = as_area_create(astart, asize, AS_AREA_WRITE | AS_AREA_READ);
     287        void *astart = as_area_create((void *) -1, asize,
     288            AS_AREA_WRITE | AS_AREA_READ);
    294289        if (astart == (void *) -1)
    295290                return false;
  • uspace/lib/c/generic/mman.c

    re895352 r49ff5f3  
    4242{
    4343        if (!start)
    44                 start = as_get_mappable_page(length);
     44                start = (void *) -1;
    4545       
    4646//      if (!((flags & MAP_SHARED) ^ (flags & MAP_PRIVATE)))
  • uspace/lib/c/generic/private/async.h

    re895352 r49ff5f3  
    8181} awaiter_t;
    8282
     83extern void awaiter_initialize(awaiter_t *);
     84
    8385extern void __async_init(void);
    8486extern void async_insert_timeout(awaiter_t *);
  • uspace/lib/c/generic/str.c

    re895352 r49ff5f3  
    4646#include <mem.h>
    4747#include <str.h>
     48
     49/** Check the condition if wchar_t is signed */
     50#ifdef WCHAR_IS_UNSIGNED
     51        #define WCHAR_SIGNED_CHECK(cond)  (true)
     52#else
     53        #define WCHAR_SIGNED_CHECK(cond)  (cond)
     54#endif
    4855
    4956/** Byte mask consisting of lowest @n bits (out of 8) */
     
    261268}
    262269
     270/** Get size of string with size limit.
     271 *
     272 * Get the number of bytes which are used by the string @a str
     273 * (excluding the NULL-terminator), but no more than @max_size bytes.
     274 *
     275 * @param str      String to consider.
     276 * @param max_size Maximum number of bytes to measure.
     277 *
     278 * @return Number of bytes used by the string
     279 *
     280 */
     281size_t str_nsize(const char *str, size_t max_size)
     282{
     283        size_t size = 0;
     284       
     285        while ((*str++ != 0) && (size < max_size))
     286                size++;
     287       
     288        return size;
     289}
     290
     291/** Get size of wide string with size limit.
     292 *
     293 * Get the number of bytes which are used by the wide string @a str
     294 * (excluding the NULL-terminator), but no more than @max_size bytes.
     295 *
     296 * @param str      Wide string to consider.
     297 * @param max_size Maximum number of bytes to measure.
     298 *
     299 * @return Number of bytes used by the wide string
     300 *
     301 */
     302size_t wstr_nsize(const wchar_t *str, size_t max_size)
     303{
     304        return (wstr_nlength(str, max_size) * sizeof(wchar_t));
     305}
     306
    263307/** Get size of wide string with length limit.
    264308 *
     
    362406bool ascii_check(wchar_t ch)
    363407{
    364         if ((ch >= 0) && (ch <= 127))
     408        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
    365409                return true;
    366410       
     
    375419bool chr_check(wchar_t ch)
    376420{
    377         if ((ch >= 0) && (ch <= 1114111))
     421        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
    378422                return true;
    379423       
     
    476520 * @param count Size of the destination buffer (must be > 0).
    477521 * @param src   Source string.
     522 *
    478523 */
    479524void str_cpy(char *dest, size_t size, const char *src)
     
    508553 * @param src   Source string.
    509554 * @param n     Maximum number of bytes to read from @a src.
     555 *
    510556 */
    511557void str_ncpy(char *dest, size_t size, const char *src, size_t n)
     
    14981544 *
    14991545 */
    1500 int str_uint64(const char *nptr, char **endptr, unsigned int base,
     1546int str_uint64_t(const char *nptr, char **endptr, unsigned int base,
    15011547    bool strict, uint64_t *result)
    15021548{
  • uspace/lib/c/generic/sysinfo.c

    re895352 r49ff5f3  
    4040#include <bool.h>
    4141
     42/** Get sysinfo keys size
     43 *
     44 * @param path  Sysinfo path.
     45 * @param value Pointer to store the keys size.
     46 *
     47 * @return EOK if the keys were successfully read.
     48 *
     49 */
     50static int sysinfo_get_keys_size(const char *path, size_t *size)
     51{
     52        return (int) __SYSCALL3(SYS_SYSINFO_GET_KEYS_SIZE, (sysarg_t) path,
     53            (sysarg_t) str_size(path), (sysarg_t) size);
     54}
     55
     56/** Get sysinfo keys
     57 *
     58 * @param path  Sysinfo path.
     59 * @param value Pointer to store the keys size.
     60 *
     61 * @return Keys read from sysinfo or NULL if the
     62 *         sysinfo item has no subkeys.
     63 *         The returned non-NULL pointer should be
     64 *         freed by free().
     65 *
     66 */
     67char *sysinfo_get_keys(const char *path, size_t *size)
     68{
     69        /*
     70         * The size of the keys might change during time.
     71         * Unfortunatelly we cannot allocate the buffer
     72         * and transfer the keys as a single atomic operation.
     73         */
     74       
     75        /* Get the keys size */
     76        int ret = sysinfo_get_keys_size(path, size);
     77        if ((ret != EOK) || (size == 0)) {
     78                /*
     79                 * Item with no subkeys.
     80                 */
     81                *size = 0;
     82                return NULL;
     83        }
     84       
     85        char *data = malloc(*size);
     86        if (data == NULL) {
     87                *size = 0;
     88                return NULL;
     89        }
     90       
     91        /* Get the data */
     92        size_t sz;
     93        ret = __SYSCALL5(SYS_SYSINFO_GET_KEYS, (sysarg_t) path,
     94            (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size,
     95            (sysarg_t) &sz);
     96        if (ret == EOK) {
     97                *size = sz;
     98                return data;
     99        }
     100       
     101        free(data);
     102        *size = 0;
     103        return NULL;
     104}
     105
    42106/** Get sysinfo item type
    43107 *
     
    70134/** Get sysinfo binary data size
    71135 *
    72  * @param path  Sysinfo path.
    73  * @param value Pointer to store the binary data size.
     136 * @param path Sysinfo path.
     137 * @param size Pointer to store the binary data size.
    74138 *
    75139 * @return EOK if the value was successfully read and
     
    85149/** Get sysinfo binary data
    86150 *
    87  * @param path  Sysinfo path.
    88  * @param value Pointer to store the binary data size.
     151 * @param path Sysinfo path.
     152 * @param size Pointer to store the binary data size.
    89153 *
    90154 * @return Binary data read from sysinfo or NULL if the
     
    134198}
    135199
     200/** Get sysinfo property
     201 *
     202 * @param path Sysinfo path.
     203 * @param name Property name.
     204 * @param size Pointer to store the binary data size.
     205 *
     206 * @return Property value read from sysinfo or NULL if the
     207 *         sysinfo item value type is not binary data.
     208 *         The returned non-NULL pointer should be
     209 *         freed by free().
     210 *
     211 */
     212void *sysinfo_get_property(const char *path, const char *name, size_t *size)
     213{
     214        size_t total_size;
     215        void *data = sysinfo_get_data(path, &total_size);
     216        if ((data == NULL) || (total_size == 0)) {
     217                *size = 0;
     218                return NULL;
     219        }
     220       
     221        size_t pos = 0;
     222        while (pos < total_size) {
     223                /* Process each property with sanity checks */
     224                size_t cur_size = str_nsize(data + pos, total_size - pos);
     225                if (((char *) data)[pos + cur_size] != 0)
     226                        break;
     227               
     228                bool found = (str_cmp(data + pos, name) == 0);
     229               
     230                pos += cur_size + 1;
     231                if (pos >= total_size)
     232                        break;
     233               
     234                /* Process value size */
     235                size_t value_size;
     236                memcpy(&value_size, data + pos, sizeof(value_size));
     237               
     238                pos += sizeof(value_size);
     239                if ((pos >= total_size) || (pos + value_size > total_size))
     240                        break;
     241               
     242                if (found) {
     243                        void *value = malloc(value_size);
     244                        if (value == NULL)
     245                                break;
     246                       
     247                        memcpy(value, data + pos, value_size);
     248                        free(data);
     249                       
     250                        *size = value_size;
     251                        return value;
     252                }
     253               
     254                pos += value_size;
     255        }
     256       
     257        free(data);
     258       
     259        *size = 0;
     260        return NULL;
     261}
     262
    136263/** @}
    137264 */
  • uspace/lib/c/generic/time.c

    re895352 r49ff5f3  
    147147                }
    148148               
    149                 void *addr = as_get_mappable_page(PAGE_SIZE);
    150                 if (addr == NULL) {
    151                         errno = ENOMEM;
    152                         return -1;
    153                 }
    154                
    155                 rc = physmem_map((void *) faddr, addr, 1,
    156                     AS_AREA_READ | AS_AREA_CACHEABLE);
     149                void *addr;
     150                rc = physmem_map((void *) faddr, 1,
     151                    AS_AREA_READ | AS_AREA_CACHEABLE, &addr);
    157152                if (rc != EOK) {
    158153                        as_area_destroy(addr);
  • uspace/lib/c/include/as.h

    re895352 r49ff5f3  
    5959extern int as_area_destroy(void *);
    6060extern void *set_maxheapsize(size_t);
    61 extern void *as_get_mappable_page(size_t);
    6261extern int as_get_physical_mapping(const void *, uintptr_t *);
    6362
  • uspace/lib/c/include/async.h

    re895352 r49ff5f3  
    139139extern void async_wait_for(aid_t, sysarg_t *);
    140140extern int async_wait_timeout(aid_t, sysarg_t *, suseconds_t);
     141extern void async_forget(aid_t);
    141142
    142143extern fid_t async_new_connection(task_id_t, sysarg_t, ipc_callid_t,
     
    346347 */
    347348
    348 #define async_share_in_start_0_0(exch, dst, size) \
    349         async_share_in_start(exch, dst, size, 0, NULL)
    350 #define async_share_in_start_0_1(exch, dst, size, flags) \
    351         async_share_in_start(exch, dst, size, 0, flags)
    352 #define async_share_in_start_1_0(exch, dst, size, arg) \
    353         async_share_in_start(exch, dst, size, arg, NULL)
    354 #define async_share_in_start_1_1(exch, dst, size, arg, flags) \
    355         async_share_in_start(exch, dst, size, arg, flags)
    356 
    357 extern int async_share_in_start(async_exch_t *, void *, size_t, sysarg_t,
    358     unsigned int *);
     349#define async_share_in_start_0_0(exch, size, dst) \
     350        async_share_in_start(exch, size, 0, NULL, dst)
     351#define async_share_in_start_0_1(exch, size, flags, dst) \
     352        async_share_in_start(exch, size, 0, flags, dst)
     353#define async_share_in_start_1_0(exch, size, arg, dst) \
     354        async_share_in_start(exch, size, arg, NULL, dst)
     355#define async_share_in_start_1_1(exch, size, arg, flags, dst) \
     356        async_share_in_start(exch, size, arg, flags, dst)
     357
     358extern int async_share_in_start(async_exch_t *, size_t, sysarg_t,
     359    unsigned int *, void **);
    359360extern bool async_share_in_receive(ipc_callid_t *, size_t *);
    360361extern int async_share_in_finalize(ipc_callid_t, void *, unsigned int);
     
    362363extern int async_share_out_start(async_exch_t *, void *, unsigned int);
    363364extern bool async_share_out_receive(ipc_callid_t *, size_t *, unsigned int *);
    364 extern int async_share_out_finalize(ipc_callid_t, void *);
     365extern int async_share_out_finalize(ipc_callid_t, void **);
    365366
    366367/*
  • uspace/lib/c/include/bitops.h

    re895352 r49ff5f3  
    4040/** Mask with bit @a n set. */
    4141#define BIT_V(type, n) \
    42     ((type)1 << ((n) - 1))
     42    ((type) 1 << (n))
    4343
    4444/** Mask with rightmost @a n bits set. */
    4545#define BIT_RRANGE(type, n) \
    46     (BIT_V(type, (n) + 1) - 1)
     46    (BIT_V(type, (n)) - 1)
    4747
    4848/** Mask with bits @a hi .. @a lo set. @a hi >= @a lo. */
  • uspace/lib/c/include/ddi.h

    re895352 r49ff5f3  
    4141
    4242extern int device_assign_devno(void);
    43 extern int physmem_map(void *, void *, unsigned long, int);
     43
     44extern int physmem_map(void *, size_t, unsigned int, void **);
     45
     46extern int dmamem_map(void *, size_t, unsigned int, unsigned int, void **);
     47extern int dmamem_map_anonymous(size_t, unsigned int, unsigned int, void **,
     48    void **);
     49extern int dmamem_unmap(void *, size_t);
     50extern int dmamem_unmap_anonymous(void *);
     51
    4452extern int iospace_enable(task_id_t, void *, unsigned long);
    4553extern int pio_enable(void *, size_t, void **);
    46 extern int register_irq(int, int, int, irq_code_t *);
    47 extern int unregister_irq(int, int);
     54
     55extern int irq_register(int, int, int, irq_code_t *);
     56extern int irq_unregister(int, int);
    4857
    4958#endif
  • uspace/lib/c/include/device/hw_res.h

    re895352 r49ff5f3  
    4040#include <bool.h>
    4141
     42#define DMA_MODE_ON_DEMAND  0
     43#define DMA_MODE_WRITE      (1 << 2)
     44#define DMA_MODE_READ       (1 << 3)
     45#define DMA_MODE_AUTO       (1 << 4)
     46#define DMA_MODE_DOWN       (1 << 5)
     47#define DMA_MODE_SINGLE     (1 << 6)
     48#define DMA_MODE_BLOCK      (1 << 7)
     49
    4250/** HW resource provider interface */
    4351typedef enum {
    4452        HW_RES_GET_RESOURCE_LIST = 0,
    45         HW_RES_ENABLE_INTERRUPT
     53        HW_RES_ENABLE_INTERRUPT,
     54        HW_RES_DMA_CHANNEL_SETUP,
    4655} hw_res_method_t;
    4756
     
    5059        INTERRUPT,
    5160        IO_RANGE,
    52         MEM_RANGE
     61        MEM_RANGE,
     62        DMA_CHANNEL_8,
     63        DMA_CHANNEL_16,
    5364} hw_res_type_t;
    5465
     
    7788                        int irq;
    7889                } interrupt;
     90               
     91                union {
     92                        unsigned int dma8;
     93                        unsigned int dma16;
     94                } dma_channel;
    7995        } res;
    8096} hw_resource_t;
     
    98114extern bool hw_res_enable_interrupt(async_sess_t *);
    99115
     116extern int hw_res_dma_channel_setup(async_sess_t *, unsigned int, uint32_t,
     117    uint16_t, uint8_t);
     118
    100119#endif
    101120
  • uspace/lib/c/include/device/hw_res_parsed.h

    re895352 r49ff5f3  
    7272} irq_list_t;
    7373
     74/** List of ISA DMA channels */
     75typedef struct dma_list {
     76        /** Channel count */
     77        size_t count;
     78
     79        /** Array of channels */
     80        unsigned int *channels;
     81} dma_list_t;
     82
    7483/** List of memory areas */
    7584typedef struct addr_range_list {
     
    91100        /** List of IRQs */
    92101        irq_list_t irqs;
     102       
     103        /** List of DMA channels */
     104        dma_list_t dma_channels;
    93105       
    94106        /** List of memory areas */
     
    113125        free(list->io_ranges.ranges);
    114126        free(list->mem_ranges.ranges);
     127        free(list->dma_channels.channels);
    115128       
    116129        bzero(list, sizeof(hw_res_list_parsed_t));
  • uspace/lib/c/include/device/nic.h

    re895352 r49ff5f3  
    3737
    3838#include <async.h>
    39 #include <net/device.h>
    40 #include <net/packet.h>
    41 #include <ipc/services.h>
     39#include <nic/nic.h>
     40#include <ipc/common.h>
    4241
    4342typedef enum {
    4443        NIC_SEND_MESSAGE = 0,
    45         NIC_CONNECT_TO_NIL,
     44        NIC_CALLBACK_CREATE,
    4645        NIC_GET_STATE,
    4746        NIC_SET_STATE,
     
    8584} nic_funcs_t;
    8685
    87 extern int nic_send_message(async_sess_t *, packet_id_t);
    88 extern int nic_connect_to_nil(async_sess_t *, services_t, nic_device_id_t);
     86typedef enum {
     87        NIC_EV_ADDR_CHANGED = IPC_FIRST_USER_METHOD,
     88        NIC_EV_RECEIVED,
     89        NIC_EV_DEVICE_STATE
     90} nic_event_t;
     91
     92extern int nic_send_frame(async_sess_t *, void *, size_t);
     93extern int nic_callback_create(async_sess_t *, async_client_conn_t, void *);
    8994extern int nic_get_state(async_sess_t *, nic_device_state_t *);
    9095extern int nic_set_state(async_sess_t *, nic_device_state_t);
     
    127132extern int nic_vlan_get_mask(async_sess_t *, nic_vlan_mask_t *);
    128133extern int nic_vlan_set_mask(async_sess_t *, const nic_vlan_mask_t *);
    129 extern int nic_vlan_set_tag(async_sess_t *, uint16_t, int, int);
     134extern int nic_vlan_set_tag(async_sess_t *, uint16_t, bool, bool);
    130135
    131136extern int nic_wol_virtue_add(async_sess_t *, nic_wv_type_t, const void *,
  • uspace/lib/c/include/device/pci.h

    re895352 r49ff5f3  
    11/*
    2  * Copyright (c) 2009 Lukas Mejdrech
     2 * Copyright (c) 2011 Jiri Michalec
    33 * All rights reserved.
    44 *
     
    3030 * @{
    3131 */
    32 
    3332/** @file
    34  * Networking subsystem central module messages.
    35  * @see net_interface.h
    3633 */
    3734
    38 #ifndef LIBC_NET_NET_MESSAGES_H_
    39 #define LIBC_NET_NET_MESSAGES_H_
     35#ifndef LIBC_DEVICE_PCI_H_
     36#define LIBC_DEVICE_PCI_H_
    4037
    41 #include <ipc/net.h>
     38#include <async.h>
    4239
    43 /** Networking subsystem central module messages. */
     40#define PCI_DEVICE_ID  0x02
     41
    4442typedef enum {
    45         /** Return general configuration
    46          * @see net_get_conf_req()
    47          */
    48         NET_NET_GET_CONF = NET_FIRST,
    49         /** Return device specific configuration
    50          * @see net_get_device_conf_req()
    51          */
    52         NET_NET_GET_DEVICE_CONF,
    53         /** Return number of mastered devices */
    54         NET_NET_GET_DEVICES_COUNT,
    55         /** Return names and device IDs of all devices */
    56         NET_NET_GET_DEVICES,
    57         /** Notify the networking service about a ready device */
    58         NET_NET_DRIVER_READY
    59 } net_messages;
     43        IPC_M_CONFIG_SPACE_READ_8,
     44        IPC_M_CONFIG_SPACE_READ_16,
     45        IPC_M_CONFIG_SPACE_READ_32,
     46       
     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;
     51
     52extern int pci_config_space_read_8(async_sess_t *, uint32_t, uint8_t *);
     53extern int pci_config_space_read_16(async_sess_t *, uint32_t, uint16_t *);
     54extern int pci_config_space_read_32(async_sess_t *, uint32_t, uint32_t *);
     55
     56extern int pci_config_space_write_8(async_sess_t *, uint32_t, uint8_t);
     57extern int pci_config_space_write_16(async_sess_t *, uint32_t, uint16_t);
     58extern int pci_config_space_write_32(async_sess_t *, uint32_t, uint32_t);
    6059
    6160#endif
  • uspace/lib/c/include/devman.h

    re895352 r49ff5f3  
    4646extern void devman_exchange_end(async_exch_t *);
    4747
    48 extern int devman_driver_register(const char *, async_client_conn_t);
     48extern int devman_driver_register(const char *);
    4949extern int devman_add_function(const char *, fun_type_t, match_id_list_t *,
    5050    devman_handle_t, devman_handle_t *);
  • uspace/lib/c/include/errno.h

    re895352 r49ff5f3  
    9696#define ENOTCONN  (-10057)
    9797
     98#define ECONNREFUSED  (-10058)
     99
     100#define ECONNABORTED  (-10059)
     101
    98102/** The requested operation was not performed. Try again later. */
    99103#define EAGAIN  (-11002)
  • uspace/lib/c/include/fibril.h

    re895352 r49ff5f3  
    4141
    4242#define context_set_generic(c, _pc, stack, size, ptls) \
    43         (c)->pc = (sysarg_t) (_pc); \
    44         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
    45         (c)->tls = (sysarg_t) (ptls);
     43        do { \
     44                (c)->pc = (sysarg_t) (_pc); \
     45                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
     46                (c)->tls = (sysarg_t) (ptls); \
     47        } while (0)
    4648
    4749#define FIBRIL_SERIALIZED  1
  • uspace/lib/c/include/fibril_synch.h

    re895352 r49ff5f3  
    107107        fibril_condvar_t name = FIBRIL_CONDVAR_INITIALIZER(name)
    108108
     109typedef void (*fibril_timer_fun_t)(void *);
     110
     111typedef enum {
     112        /** Timer has not been set or has been cleared */
     113        fts_not_set,
     114        /** Timer was set but did not fire yet */
     115        fts_active,
     116        /** Timer has fired and has not been cleared since */
     117        fts_fired,
     118        /** Timer is being destroyed */
     119        fts_cleanup
     120} fibril_timer_state_t;
     121
     122/** Fibril timer.
     123 *
     124 * When a timer is set it executes a callback function (in a separate
     125 * fibril) after a specified time interval. The timer can be cleared
     126 * (canceled) before that. From the return value of fibril_timer_clear()
     127 * one can tell whether the timer fired or not.
     128 */
     129typedef struct {
     130        fibril_mutex_t lock;
     131        fibril_condvar_t cv;
     132        fid_t fibril;
     133        fibril_timer_state_t state;
     134
     135        suseconds_t delay;
     136        fibril_timer_fun_t fun;
     137        void *arg;
     138} fibril_timer_t;
     139
    109140extern void fibril_mutex_initialize(fibril_mutex_t *);
    110141extern void fibril_mutex_lock(fibril_mutex_t *);
     
    129160extern void fibril_condvar_broadcast(fibril_condvar_t *);
    130161
     162extern fibril_timer_t *fibril_timer_create(void);
     163extern void fibril_timer_destroy(fibril_timer_t *);
     164extern void fibril_timer_set(fibril_timer_t *, suseconds_t, fibril_timer_fun_t,
     165    void *);
     166extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *);
     167
    131168#endif
    132169
  • uspace/lib/c/include/inet/inet.h

    re895352 r49ff5f3  
    11/*
    2  * Copyright (c) 2009 Lukas Mejdrech
     2 * Copyright (c) 2012 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libnet
     29/** @addtogroup libc
    3030 * @{
    3131 */
    32 
    3332/** @file
    34  * Hardware types according to the on-line IANA - Address Resolution Protocol
    35  * (ARP) Parameters
    36  * http://www.iana.org/assignments/arp-parameters/arp-parameters.xml,
    37  * cited January 14 2009.
    3833 */
    3934
    40 #ifndef LIBNET_NET_HARDWARE_H_
    41 #define LIBNET_NET_HARDWARE_H_
     35#ifndef LIBC_INET_INET_H_
     36#define LIBC_INET_INET_H_
    4237
    4338#include <sys/types.h>
    4439
    45 /** Network interface layer type type definition. */
    46 typedef uint8_t hw_type_t;
     40#define INET_TTL_MAX 255
    4741
    48 /** @name Network interface layer types definitions */
    49 /*@{*/
     42typedef struct {
     43        uint32_t ipv4;
     44} inet_addr_t;
    5045
    51 /** Ethernet (10Mb) hardware type. */
    52 #define HW_ETHER                1
     46typedef struct {
     47        inet_addr_t src;
     48        inet_addr_t dest;
     49        uint8_t tos;
     50        void *data;
     51        size_t size;
     52} inet_dgram_t;
    5353
    54 /*@}*/
     54typedef struct {
     55        int (*recv)(inet_dgram_t *);
     56} inet_ev_ops_t;
     57
     58typedef enum {
     59        INET_DF = 1
     60} inet_df_t;
     61
     62extern int inet_init(uint8_t, inet_ev_ops_t *);
     63extern int inet_send(inet_dgram_t *, uint8_t, inet_df_t);
     64extern int inet_get_srcaddr(inet_addr_t *, uint8_t, inet_addr_t *);
    5565
    5666#endif
     
    5868/** @}
    5969 */
    60 
  • uspace/lib/c/include/inet/inetping.h

    re895352 r49ff5f3  
    11/*
    2  * Copyright (c) 2006 Josef Cejka
     2 * Copyright (c) 2012 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup kbd_port
    30  * @ingroup  kbd
     29/** @addtogroup libc
    3130 * @{
    3231 */
    33 
    3432/** @file
    35  * @brief i8042 port driver.
    3633 */
    3734
    38 #ifndef i8042_H_
    39 #define i8042_H_
     35#ifndef LIBC_INET_INETPING_H_
     36#define LIBC_INET_INETPING_H_
    4037
     38#include <inet/inet.h>
    4139#include <sys/types.h>
    42 #include <libarch/ddi.h>
    43 #include <async.h>
    4440
    45 /** i8042 HW I/O interface */
    46 struct i8042 {
    47         ioport8_t data;
    48         uint8_t pad[3];
    49         ioport8_t status;
    50 } __attribute__ ((packed));
    51 typedef struct i8042 i8042_t;
     41typedef struct {
     42        inet_addr_t src;
     43        inet_addr_t dest;
     44        uint16_t seq_no;
     45        void *data;
     46        size_t size;
     47} inetping_sdu_t;
    5248
    53 /** Softstate structure, one for each serial port (primary and aux). */
    54 typedef struct {
    55         service_id_t service_id;
    56         async_sess_t *client_sess;
    57 } i8042_port_t;
     49typedef struct inetping_ev_ops {
     50        int (*recv)(inetping_sdu_t *);
     51} inetping_ev_ops_t;
     52
     53extern int inetping_init(inetping_ev_ops_t *);
     54extern int inetping_send(inetping_sdu_t *);
     55extern int inetping_get_srcaddr(inet_addr_t *, inet_addr_t *);
     56
    5857
    5958#endif
    6059
    61 /**
    62  * @}
     60/** @}
    6361 */
  • uspace/lib/c/include/ipc/devman.h

    re895352 r49ff5f3  
    146146typedef enum {
    147147        DRIVER_DEV_ADD = IPC_FIRST_USER_METHOD,
    148         DRIVER_DEV_ADDED,
    149148        DRIVER_DEV_REMOVE,
    150149        DRIVER_DEV_GONE,
  • uspace/lib/c/include/ipc/inet.h

    re895352 r49ff5f3  
    11/*
    2  * Copyright (c) 2009 Lukas Mejdrech
    3  * Copyright (c) 2011 Radim Vansa
     2 * Copyright (c) 2012 Jiri Svoboda
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
    30 /** @addtogroup libpacket
     29/** @addtogroup libcipc
    3130 * @{
    3231 */
    33 
    3432/** @file
    35  * Packet server.
    36  * The hosting module has to be compiled with both the packet.c and the
    37  * packet_server.c source files. To function correctly, initialization of the
    38  * packet map by the pm_init() function has to happen at the first place. Then
    39  * the packet messages have to be processed by the packet_server_message()
    40  * function. The packet map should be released by the pm_destroy() function
    41  * during the module termination.
    42  * @see IS_NET_PACKET_MESSAGE()
    4333 */
    4434
    45 #ifndef NET_PACKET_SERVER_H_
    46 #define NET_PACKET_SERVER_H_
     35#ifndef LIBC_IPC_INET_H_
     36#define LIBC_IPC_INET_H_
    4737
    4838#include <ipc/common.h>
    4939
    50 extern int packet_server_init(void);
    51 extern int packet_server_message(ipc_callid_t, ipc_call_t *, ipc_call_t *,
    52     size_t *);
     40/** Inet ports */
     41typedef enum {
     42        /** Default port */
     43        INET_PORT_DEFAULT = 1,
     44        /** Configuration port */
     45        INET_PORT_CFG,
     46        /** Ping service port */
     47        INET_PORT_PING
     48} inet_port_t;
     49
     50/** Requests on Inet default port */
     51typedef enum {
     52        INET_CALLBACK_CREATE = IPC_FIRST_USER_METHOD,
     53        INET_GET_SRCADDR,
     54        INET_SEND,
     55        INET_SET_PROTO
     56} inet_request_t;
     57
     58/** Events on Inet default port */
     59typedef enum {
     60        INET_EV_RECV = IPC_FIRST_USER_METHOD
     61} inet_event_t;
     62
     63/** Requests on Inet configuration port */
     64typedef enum {
     65        INETCFG_ADDR_CREATE_STATIC = IPC_FIRST_USER_METHOD,
     66        INETCFG_ADDR_DELETE,
     67        INETCFG_ADDR_GET,
     68        INETCFG_ADDR_GET_ID,
     69        INETCFG_GET_ADDR_LIST,
     70        INETCFG_GET_LINK_LIST,
     71        INETCFG_GET_SROUTE_LIST,
     72        INETCFG_LINK_GET,
     73        INETCFG_SROUTE_CREATE,
     74        INETCFG_SROUTE_DELETE,
     75        INETCFG_SROUTE_GET,
     76        INETCFG_SROUTE_GET_ID
     77} inetcfg_request_t;
     78
     79/** Events on Inet ping port */
     80typedef enum {
     81        INETPING_EV_RECV = IPC_FIRST_USER_METHOD
     82} inetping_event_t;
     83
     84/** Requests on Inet ping port */
     85typedef enum {
     86        INETPING_SEND = IPC_FIRST_USER_METHOD,
     87        INETPING_GET_SRCADDR
     88} inetping_request_t;
    5389
    5490#endif
    5591
    56 /** @}
     92/**
     93 * @}
    5794 */
  • uspace/lib/c/include/ipc/ipc.h

    re895352 r49ff5f3  
    271271 */
    272272
    273 #define ipc_share_in_start_0_0(phoneid, dst, size) \
    274         ipc_share_in_start((phoneid), (dst), (size), 0, NULL)
    275 #define ipc_share_in_start_0_1(phoneid, dst, size, flags) \
    276         ipc_share_in_start((phoneid), (dst), (size), 0, (flags))
    277 #define ipc_share_in_start_1_0(phoneid, dst, size, arg) \
    278         ipc_share_in_start((phoneid), (dst), (size), (arg), NULL)
    279 #define ipc_share_in_start_1_1(phoneid, dst, size, arg, flags) \
    280         ipc_share_in_start((phoneid), (dst), (size), (arg), (flags))
    281 
    282 extern int ipc_share_in_start(int, void *, size_t, sysarg_t, unsigned int *);
     273#define ipc_share_in_start_0_0(phoneid, size, dst) \
     274        ipc_share_in_start((phoneid), (size), 0, NULL, (dst))
     275#define ipc_share_in_start_0_1(phoneid, size, flags, dst) \
     276        ipc_share_in_start((phoneid), (size), 0, (flags), (dst))
     277#define ipc_share_in_start_1_0(phoneid, size, arg, dst) \
     278        ipc_share_in_start((phoneid), (size), (arg), NULL, (dst))
     279#define ipc_share_in_start_1_1(phoneid, size, arg, flags, dst) \
     280        ipc_share_in_start((phoneid), (size), (arg), (flags), (dst))
     281
     282extern int ipc_share_in_start(int, size_t, sysarg_t, unsigned int *, void **);
    283283extern int ipc_share_in_finalize(ipc_callid_t, void *, unsigned int);
    284284extern int ipc_share_out_start(int, void *, unsigned int);
    285 extern int ipc_share_out_finalize(ipc_callid_t, void *);
     285extern int ipc_share_out_finalize(ipc_callid_t, void **);
    286286extern int ipc_data_read_start(int, void *, size_t);
    287287extern int ipc_data_read_finalize(ipc_callid_t, const void *, size_t);
  • uspace/lib/c/include/ipc/iplink.h

    re895352 r49ff5f3  
    11/*
    2  * Copyright (c) 2009 Lukas Mejdrech
     2 * Copyright (c) 2012 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libc
     29/** @addtogroup libcipc
    3030 * @{
    3131 */
    32 
    3332/** @file
    34  * Transport layer modules messages.
    35  * @see tl_interface.h
    3633 */
    3734
    38 #ifndef LIBC_TL_MESSAGES_H_
    39 #define LIBC_TL_MESSAGES_H_
     35#ifndef LIBC_IPC_IPLINK_H_
     36#define LIBC_IPC_IPLINK_H_
    4037
    41 #include <ipc/net.h>
     38#include <ipc/common.h>
    4239
    43 /** Transport layer modules messages. */
    4440typedef enum {
    45         /** Packet received message.
    46          * @see tl_received_msg()
    47          */
    48         NET_TL_RECEIVED = NET_TL_FIRST
    49 } tl_messages;
     41        IPLINK_GET_MTU = IPC_FIRST_USER_METHOD,
     42        IPLINK_SEND,
     43        IPLINK_ADDR_ADD,
     44        IPLINK_ADDR_REMOVE
     45} iplink_request_t;
     46
     47typedef enum {
     48        IPLINK_EV_RECV = IPC_FIRST_USER_METHOD
     49} iplink_event_t;
    5050
    5151#endif
    5252
    53 /** @}
     53/**
     54 * @}
    5455 */
  • uspace/lib/c/include/ipc/services.h

    re895352 r49ff5f3  
    4848        SERVICE_IRC        = FOURCC('i', 'r', 'c', ' '),
    4949        SERVICE_CLIPBOARD  = FOURCC('c', 'l', 'i', 'p'),
    50         SERVICE_NETWORKING = FOURCC('n', 'e', 't', ' '),
    51         SERVICE_ETHERNET   = FOURCC('e', 't', 'h', ' '),
    52         SERVICE_NILDUMMY   = FOURCC('n', 'i', 'l', 'd'),
    53         SERVICE_IP         = FOURCC('i', 'p', 'v', '4'),
    54         SERVICE_ARP        = FOURCC('a', 'r', 'p', ' '),
    55         SERVICE_ICMP       = FOURCC('i', 'c', 'm', 'p'),
    5650        SERVICE_UDP        = FOURCC('u', 'd', 'p', ' '),
    5751        SERVICE_TCP        = FOURCC('t', 'c', 'p', ' ')
    5852} services_t;
     53
     54#define SERVICE_NAME_INET     "net/inet"
     55#define SERVICE_NAME_INETCFG  "net/inetcfg"
     56#define SERVICE_NAME_INETPING "net/inetping"
    5957
    6058#endif
  • uspace/lib/c/include/ipc/socket.h

    re895352 r49ff5f3  
    3838#define LIBC_SOCKET_MESSAGES_H_
    3939
    40 #include <ipc/net.h>
    41 
    4240/** Socket client messages. */
    4341typedef enum {
    4442        /** Creates a new socket. @see socket() */
    45         NET_SOCKET = NET_SOCKET_FIRST,
     43        NET_SOCKET = IPC_FIRST_USER_METHOD,
    4644        /** Binds the socket. @see bind() */
    4745        NET_SOCKET_BIND,
  • uspace/lib/c/include/loc.h

    re895352 r49ff5f3  
    4646extern void loc_exchange_end(async_exch_t *);
    4747
    48 extern int loc_server_register(const char *, async_client_conn_t);
     48extern int loc_server_register(const char *);
    4949extern int loc_service_register(const char *, service_id_t *);
    5050extern int loc_service_register_with_iface(const char *, service_id_t *,
  • uspace/lib/c/include/net/device.h

    re895352 r49ff5f3  
    11/*
    22 * Copyright (c) 2009 Lukas Mejdrech
    3  * Copyright (c) 2011 Radim Vansa
    43 * All rights reserved.
    54 *
     
    3332
    3433/** @file
    35  * Device identifier, state and usage statistics.
     34 * Network device.
    3635 */
    3736
    38 #ifndef LIBC_DEVICE_ID_TYPE_H_
    39 #define LIBC_DEVICE_ID_TYPE_H_
     37#ifndef LIBC_NET_DEVICE_H_
     38#define LIBC_NET_DEVICE_H_
    4039
    4140#include <adt/int_map.h>
    42 #include <net/eth_phys.h>
    43 #include <bool.h>
    44 
    45 /** Ethernet address length. */
    46 #define ETH_ADDR  6
    47 
    48 /** MAC printing format */
    49 #define PRIMAC  "%02x:%02x:%02x:%02x:%02x:%02x"
    50 
    51 /** MAC arguments */
    52 #define ARGSMAC(__a) \
    53         (__a)[0], (__a)[1], (__a)[2], (__a)[3], (__a)[4], (__a)[5]
    54 
    55 /* Compare MAC address with specific value */
    56 #define MAC_EQUALS_VALUE(__a, __a0, __a1, __a2, __a3, __a4, __a5) \
    57         ((__a)[0] == (__a0) && (__a)[1] == (__a1) && (__a)[2] == (__a2) \
    58         && (__a)[3] == (__a3) && (__a)[4] == (__a4) && (__a)[5] == (__a5))
    59 
    60 #define MAC_IS_ZERO(__x) \
    61         MAC_EQUALS_VALUE(__x, 0, 0, 0, 0, 0, 0)
     41#include <nic/nic.h>
    6242
    6343/** Device identifier to generic type map declaration. */
     
    6747#define DEVICE_MAP_IMPLEMENT  INT_MAP_IMPLEMENT
    6848
    69 /** Max length of any hw nic address (currently only eth) */
    70 #define NIC_MAX_ADDRESS_LENGTH  16
     49/** Device identifier type. */
     50typedef int nic_device_id_t;
    7151
    7252/** Invalid device identifier. */
    7353#define NIC_DEVICE_INVALID_ID  (-1)
    74 
    75 #define NIC_VENDOR_MAX_LENGTH         64
    76 #define NIC_MODEL_MAX_LENGTH          64
    77 #define NIC_PART_NUMBER_MAX_LENGTH    64
    78 #define NIC_SERIAL_NUMBER_MAX_LENGTH  64
    79 
    80 /**
    81  * The bitmap uses single bit for each of the 2^12 = 4096 possible VLAN tags.
    82  * This means its size is 4096/8 = 512 bytes.
    83  */
    84 #define NIC_VLAN_BITMAP_SIZE  512
    85 
    86 #define NIC_DEVICE_PRINT_FMT  "%x"
    87 
    88 /** Device identifier type. */
    89 typedef int nic_device_id_t;
    90 
    91 /**
    92  * Structure covering the MAC address.
    93  */
    94 typedef struct nic_address {
    95         uint8_t address[ETH_ADDR];
    96 } nic_address_t;
    97 
    98 /** Device state. */
    99 typedef enum nic_device_state {
    100         /**
    101          * Device present and stopped. Moving device to this state means to discard
    102          * all settings and WOL virtues, rebooting the NIC to state as if the
    103          * computer just booted (or the NIC was just inserted in case of removable
    104          * NIC).
    105          */
    106         NIC_STATE_STOPPED,
    107         /**
    108          * If the NIC is in this state no packets (frames) are transmitted nor
    109          * received. However, the settings are not restarted. You can use this state
    110          * to temporarily disable transmition/reception or atomically (with respect
    111          * to incoming/outcoming packets) change frames acceptance etc.
    112          */
    113         NIC_STATE_DOWN,
    114         /** Device is normally operating. */
    115         NIC_STATE_ACTIVE,
    116         /** Just a constant to limit the state numbers */
    117         NIC_STATE_MAX,
    118 } nic_device_state_t;
    119 
    120 /**
    121  * Channel operating mode used on the medium.
    122  */
    123 typedef enum {
    124         NIC_CM_UNKNOWN,
    125         NIC_CM_FULL_DUPLEX,
    126         NIC_CM_HALF_DUPLEX,
    127         NIC_CM_SIMPLEX
    128 } nic_channel_mode_t;
    129 
    130 /**
    131  * Role for the device (used e.g. for 1000Gb ethernet)
    132  */
    133 typedef enum {
    134         NIC_ROLE_UNKNOWN,
    135         NIC_ROLE_AUTO,
    136         NIC_ROLE_MASTER,
    137         NIC_ROLE_SLAVE
    138 } nic_role_t;
    139 
    140 /**
    141  * Current state of the cable in the device
    142  */
    143 typedef enum {
    144         NIC_CS_UNKNOWN,
    145         NIC_CS_PLUGGED,
    146         NIC_CS_UNPLUGGED
    147 } nic_cable_state_t;
    148 
    149 /**
    150  * Result of the requested operation
    151  */
    152 typedef enum {
    153         /** Successfully disabled */
    154         NIC_RESULT_DISABLED,
    155         /** Successfully enabled */
    156         NIC_RESULT_ENABLED,
    157         /** Not supported at all */
    158         NIC_RESULT_NOT_SUPPORTED,
    159         /** Temporarily not available */
    160         NIC_RESULT_NOT_AVAILABLE,
    161         /** Result extensions */
    162         NIC_RESULT_FIRST_EXTENSION
    163 } nic_result_t;
    164 
    165 /** Device usage statistics. */
    166 typedef struct nic_device_stats {
    167         /** Total packets received (accepted). */
    168         unsigned long receive_packets;
    169         /** Total packets transmitted. */
    170         unsigned long send_packets;
    171         /** Total bytes received (accepted). */
    172         unsigned long receive_bytes;
    173         /** Total bytes transmitted. */
    174         unsigned long send_bytes;
    175         /** Bad packets received counter. */
    176         unsigned long receive_errors;
    177         /** Packet transmition problems counter. */
    178         unsigned long send_errors;
    179         /** Number of frames dropped due to insufficient space in RX buffers */
    180         unsigned long receive_dropped;
    181         /** Number of frames dropped due to insufficient space in TX buffers */
    182         unsigned long send_dropped;
    183         /** Total multicast packets received (accepted). */
    184         unsigned long receive_multicast;
    185         /** Total broadcast packets received (accepted). */
    186         unsigned long receive_broadcast;
    187         /** The number of collisions due to congestion on the medium. */
    188         unsigned long collisions;
    189         /** Unicast packets received but not accepted (filtered) */
    190         unsigned long receive_filtered_unicast;
    191         /** Multicast packets received but not accepted (filtered) */
    192         unsigned long receive_filtered_multicast;
    193         /** Broadcast packets received but not accepted (filtered) */
    194         unsigned long receive_filtered_broadcast;
    195 
    196         /* detailed receive_errors */
    197 
    198         /** Received packet length error counter. */
    199         unsigned long receive_length_errors;
    200         /** Receiver buffer overflow counter. */
    201         unsigned long receive_over_errors;
    202         /** Received packet with crc error counter. */
    203         unsigned long receive_crc_errors;
    204         /** Received frame alignment error counter. */
    205         unsigned long receive_frame_errors;
    206         /** Receiver fifo overrun counter. */
    207         unsigned long receive_fifo_errors;
    208         /** Receiver missed packet counter. */
    209         unsigned long receive_missed_errors;
    210 
    211         /* detailed send_errors */
    212 
    213         /** Transmitter aborted counter. */
    214         unsigned long send_aborted_errors;
    215         /** Transmitter carrier errors counter. */
    216         unsigned long send_carrier_errors;
    217         /** Transmitter fifo overrun counter. */
    218         unsigned long send_fifo_errors;
    219         /** Transmitter carrier errors counter. */
    220         unsigned long send_heartbeat_errors;
    221         /** Transmitter window errors counter. */
    222         unsigned long send_window_errors;
    223 
    224         /* for cslip etc */
    225        
    226         /** Total compressed packets received. */
    227         unsigned long receive_compressed;
    228         /** Total compressed packet transmitted. */
    229         unsigned long send_compressed;
    230 } nic_device_stats_t;
    231 
    232 /** Errors corresponding to those in the nic_device_stats_t */
    233 typedef enum {
    234         NIC_SEC_BUFFER_FULL,
    235         NIC_SEC_ABORTED,
    236         NIC_SEC_CARRIER_LOST,
    237         NIC_SEC_FIFO_OVERRUN,
    238         NIC_SEC_HEARTBEAT,
    239         NIC_SEC_WINDOW_ERROR,
    240         /* Error encountered during TX but with other type of error */
    241         NIC_SEC_OTHER
    242 } nic_send_error_cause_t;
    243 
    244 /** Errors corresponding to those in the nic_device_stats_t */
    245 typedef enum {
    246         NIC_REC_BUFFER_FULL,
    247         NIC_REC_LENGTH,
    248         NIC_REC_BUFFER_OVERFLOW,
    249         NIC_REC_CRC,
    250         NIC_REC_FRAME_ALIGNMENT,
    251         NIC_REC_FIFO_OVERRUN,
    252         NIC_REC_MISSED,
    253         /* Error encountered during RX but with other type of error */
    254         NIC_REC_OTHER
    255 } nic_receive_error_cause_t;
    256 
    257 /**
    258  * Information about the NIC that never changes - name, vendor, model,
    259  * capabilites and so on.
    260  */
    261 typedef struct nic_device_info {
    262         /* Device identification */
    263         char vendor_name[NIC_VENDOR_MAX_LENGTH];
    264         char model_name[NIC_MODEL_MAX_LENGTH];
    265         char part_number[NIC_PART_NUMBER_MAX_LENGTH];
    266         char serial_number[NIC_SERIAL_NUMBER_MAX_LENGTH];
    267         uint16_t vendor_id;
    268         uint16_t device_id;
    269         uint16_t subsystem_vendor_id;
    270         uint16_t subsystem_id;
    271         /* Device capabilities */
    272         uint16_t ethernet_support[ETH_PHYS_LAYERS];
    273 
    274         /** The mask of all modes which the device can advertise
    275          *
    276          *  see ETH_AUTONEG_ macros in net/eth_phys.h of libc
    277          */
    278         uint32_t autoneg_support;
    279 } nic_device_info_t;
    280 
    281 /**
    282  * Type of the ethernet frame
    283  */
    284 typedef enum nic_frame_type {
    285         NIC_FRAME_UNICAST,
    286         NIC_FRAME_MULTICAST,
    287         NIC_FRAME_BROADCAST
    288 } nic_frame_type_t;
    289 
    290 /**
    291  * Specifies which unicast frames is the NIC receiving.
    292  */
    293 typedef enum nic_unicast_mode {
    294         NIC_UNICAST_UNKNOWN,
    295         /** No unicast frames are received */
    296         NIC_UNICAST_BLOCKED,
    297         /** Only the frames with this NIC's MAC as destination are received */
    298         NIC_UNICAST_DEFAULT,
    299         /**
    300          * Both frames with this NIC's MAC and those specified in the list are
    301          * received
    302          */
    303         NIC_UNICAST_LIST,
    304         /** All unicast frames are received */
    305         NIC_UNICAST_PROMISC
    306 } nic_unicast_mode_t;
    307 
    308 typedef enum nic_multicast_mode {
    309         NIC_MULTICAST_UNKNOWN,
    310         /** No multicast frames are received */
    311         NIC_MULTICAST_BLOCKED,
    312         /** Frames with multicast addresses specified in this list are received */
    313         NIC_MULTICAST_LIST,
    314         /** All multicast frames are received */
    315         NIC_MULTICAST_PROMISC
    316 } nic_multicast_mode_t;
    317 
    318 typedef enum nic_broadcast_mode {
    319         NIC_BROADCAST_UNKNOWN,
    320         /** Broadcast frames are dropped */
    321         NIC_BROADCAST_BLOCKED,
    322         /** Broadcast frames are received */
    323         NIC_BROADCAST_ACCEPTED
    324 } nic_broadcast_mode_t;
    325 
    326 /**
    327  * Structure covering the bitmap with VLAN tags.
    328  */
    329 typedef struct nic_vlan_mask {
    330         uint8_t bitmap[NIC_VLAN_BITMAP_SIZE];
    331 } nic_vlan_mask_t;
    332 
    333 /* WOL virtue identifier */
    334 typedef unsigned int nic_wv_id_t;
    335 
    336 /**
    337  * Structure passed as argument for virtue NIC_WV_MAGIC_PACKET.
    338  */
    339 typedef struct nic_wv_magic_packet_data {
    340         uint8_t password[6];
    341 } nic_wv_magic_packet_data_t;
    342 
    343 /**
    344  * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV4
    345  */
    346 typedef struct nic_wv_ipv4_data {
    347         uint8_t address[4];
    348 } nic_wv_ipv4_data_t;
    349 
    350 /**
    351  * Structure passed as argument for virtue NIC_WV_DIRECTED_IPV6
    352  */
    353 typedef struct nic_wv_ipv6_data {
    354         uint8_t address[16];
    355 } nic_wv_ipv6_data_t;
    356 
    357 /**
    358  * WOL virtue types defining the interpretation of data passed to the virtue.
    359  * Those tagged with S can have only single virtue active at one moment, those
    360  * tagged with M can have multiple ones.
    361  */
    362 typedef enum nic_wv_type {
    363         /**
    364          * Used for deletion of the virtue - in this case the mask, data and length
    365          * arguments are ignored.
    366          */
    367         NIC_WV_NONE,
    368         /** S
    369          * Enabled <=> wakeup upon link change
    370          */
    371         NIC_WV_LINK_CHANGE,
    372         /** S
    373          * If this virtue is set up, wakeup can be issued by a magic packet frame.
    374          * If the data argument is not NULL, it must contain
    375          * nic_wv_magic_packet_data structure with the SecureOn password.
    376          */
    377         NIC_WV_MAGIC_PACKET,
    378         /** M
    379          * If the virtue is set up, wakeup can be issued by a frame targeted to
    380          * device with MAC address specified in data. The data must contain
    381          * nic_address_t structure.
    382          */
    383         NIC_WV_DESTINATION,
    384         /** S
    385          * Enabled <=> wakeup upon receiving broadcast frame
    386          */
    387         NIC_WV_BROADCAST,
    388         /** S
    389          * Enabled <=> wakeup upon receiving ARP Request
    390          */
    391         NIC_WV_ARP_REQUEST,
    392         /** M
    393          * If enabled, the wakeup is issued upon receiving frame with an IPv4 packet
    394          * with IPv4 address specified in data. The data must contain
    395          * nic_wv_ipv4_data structure.
    396          */
    397         NIC_WV_DIRECTED_IPV4,
    398         /** M
    399          * If enabled, the wakeup is issued upon receiving frame with an IPv4 packet
    400          * with IPv6 address specified in data. The data must contain
    401          * nic_wv_ipv6_data structure.
    402          */
    403         NIC_WV_DIRECTED_IPV6,
    404         /** M
    405          * First length/2 bytes in the argument are interpreted as mask, second
    406          * length/2 bytes are interpreted as content.
    407          * If enabled, the wakeup is issued upon receiving frame where the bytes
    408          * with non-zero value in the mask equal to those in the content.
    409          */
    410         NIC_WV_FULL_MATCH,
    411         /**
    412          * Dummy value, do not use.
    413          */
    414         NIC_WV_MAX
    415 } nic_wv_type_t;
    416 
    417 /**
    418  * Specifies the interrupt/polling mode used by the driver and NIC
    419  */
    420 typedef enum nic_poll_mode {
    421         /**
    422          * NIC issues interrupts upon events.
    423          */
    424         NIC_POLL_IMMEDIATE,
    425         /**
    426          * Some uspace app calls nic_poll_now(...) in order to check the NIC state
    427          * - no interrupts are received from the NIC.
    428          */
    429         NIC_POLL_ON_DEMAND,
    430         /**
    431          * The driver itself issues a poll request in a periodic manner. It is
    432          * allowed to use hardware timer if the NIC supports it.
    433          */
    434         NIC_POLL_PERIODIC,
    435         /**
    436          * The driver itself issued a poll request in a periodic manner. The driver
    437          * must create software timer, internal hardware timer of NIC must not be
    438          * used even if the NIC supports it.
    439          */
    440         NIC_POLL_SOFTWARE_PERIODIC
    441 } nic_poll_mode_t;
    442 
    443 /**
    444  * Says if this virtue type is a multi-virtue (there can be multiple virtues of
    445  * this type at once).
    446  *
    447  * @param type
    448  *
    449  * @return true or false
    450  */
    451 static inline int nic_wv_is_multi(nic_wv_type_t type) {
    452         switch (type) {
    453         case NIC_WV_FULL_MATCH:
    454         case NIC_WV_DESTINATION:
    455         case NIC_WV_DIRECTED_IPV4:
    456         case NIC_WV_DIRECTED_IPV6:
    457                 return true;
    458         default:
    459                 return false;
    460         }
    461 }
    462 
    463 static inline const char *nic_device_state_to_string(nic_device_state_t state)
    464 {
    465         switch (state) {
    466         case NIC_STATE_STOPPED:
    467                 return "stopped";
    468         case NIC_STATE_DOWN:
    469                 return "down";
    470         case NIC_STATE_ACTIVE:
    471                 return "active";
    472         default:
    473                 return "undefined";
    474         }
    475 }
    47654
    47755#endif
  • uspace/lib/c/include/net/in.h

    re895352 r49ff5f3  
    4545#define INET_ADDRSTRLEN  (4 * 3 + 3 + 1)
    4646
     47#define INADDR_ANY 0
     48
    4749/** Type definition of the INET address.
    4850 * @see in_addr
  • uspace/lib/c/include/nic/eth_phys.h

    re895352 r49ff5f3  
    2828 */
    2929
    30 #ifndef LIBC_NET_ETH_PHYS_H_
    31 #define LIBC_NET_ETH_PHYS_H_
     30#ifndef LIBC_NIC_ETH_PHYS_H_
     31#define LIBC_NIC_ETH_PHYS_H_
    3232
    3333#include <sys/types.h>
  • uspace/lib/c/include/str.h

    re895352 r49ff5f3  
    6161extern size_t wstr_size(const wchar_t *str);
    6262
     63extern size_t str_nsize(const char *str, size_t max_size);
     64extern size_t wstr_nsize(const wchar_t *str, size_t max_size);
     65
    6366extern size_t str_lsize(const char *str, size_t max_len);
    6467extern size_t wstr_lsize(const wchar_t *str, size_t max_len);
     
    103106extern int str_uint16_t(const char *, char **, unsigned int, bool, uint16_t *);
    104107extern int str_uint32_t(const char *, char **, unsigned int, bool, uint32_t *);
    105 extern int str_uint64(const char *, char **, unsigned int, bool, uint64_t *);
     108extern int str_uint64_t(const char *, char **, unsigned int, bool, uint64_t *);
    106109extern int str_size_t(const char *, char **, unsigned int, bool, size_t *);
    107110
  • uspace/lib/c/include/sysinfo.h

    re895352 r49ff5f3  
    4040#include <abi/sysinfo.h>
    4141
     42extern char *sysinfo_get_keys(const char *, size_t *);
    4243extern sysinfo_item_val_type_t sysinfo_get_val_type(const char *);
    4344extern int sysinfo_get_value(const char *, sysarg_t *);
    4445extern void *sysinfo_get_data(const char *, size_t *);
     46extern void *sysinfo_get_property(const char *, const char *, size_t *);
    4547
    4648#endif
Note: See TracChangeset for help on using the changeset viewer.