Changeset 5828554 in mainline for uspace/lib
- Timestamp:
- 2014-01-19T14:37:22Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cf982ff
- Parents:
- 2f591127 (diff), 476f62c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/lib
- Files:
-
- 47 added
- 6 deleted
- 65 edited
- 20 moved
-
c/Makefile (modified) (5 diffs)
-
c/arch/abs32le/include/libarch/atomic.h (modified) (2 diffs)
-
c/arch/amd64/_link.ld.in (modified) (1 diff)
-
c/arch/ia32/Makefile.inc (modified) (1 diff)
-
c/arch/sparc32/Makefile.common (added)
-
c/arch/sparc32/Makefile.inc (added)
-
c/arch/sparc32/_link.ld.in (added)
-
c/arch/sparc32/include/libarch/atomic.h (added)
-
c/arch/sparc32/include/libarch/barrier.h (added)
-
c/arch/sparc32/include/libarch/config.h (added)
-
c/arch/sparc32/include/libarch/context_offset.h (added)
-
c/arch/sparc32/include/libarch/ddi.h (added)
-
c/arch/sparc32/include/libarch/elf.h (added)
-
c/arch/sparc32/include/libarch/elf_linux.h (added)
-
c/arch/sparc32/include/libarch/faddr.h (added)
-
c/arch/sparc32/include/libarch/fibril.h (added)
-
c/arch/sparc32/include/libarch/inttypes.h (added)
-
c/arch/sparc32/include/libarch/istate.h (added)
-
c/arch/sparc32/include/libarch/stack.h (added)
-
c/arch/sparc32/include/libarch/stackarg.h (added)
-
c/arch/sparc32/include/libarch/syscall.h (added)
-
c/arch/sparc32/include/libarch/thread.h (added)
-
c/arch/sparc32/include/libarch/tls.h (added)
-
c/arch/sparc32/include/libarch/types.h (added)
-
c/arch/sparc32/src/entry.s (added)
-
c/arch/sparc32/src/entryjmp.s (added)
-
c/arch/sparc32/src/fibril.S (added)
-
c/arch/sparc32/src/stacktrace.c (added)
-
c/arch/sparc32/src/stacktrace_asm.S (moved) (moved from uspace/lib/c/arch/ia32/src/setjmp.S ) (2 diffs)
-
c/arch/sparc32/src/thread_entry.s (added)
-
c/arch/sparc32/src/tls.c (added)
-
c/generic/adt/checksum.c (added)
-
c/generic/assert.c (modified) (2 diffs)
-
c/generic/ddi.c (modified) (1 diff)
-
c/generic/device/ahci.c (deleted)
-
c/generic/device/char_dev.c (deleted)
-
c/generic/device/nic.c (deleted)
-
c/generic/device/pci.c (deleted)
-
c/generic/io/io.c (modified) (12 diffs)
-
c/generic/io/kio.c (added)
-
c/generic/io/klog.c (modified) (3 diffs)
-
c/generic/io/window.c (modified) (2 diffs)
-
c/generic/private/stdio.h (modified) (1 diff)
-
c/generic/setjmp.c (added)
-
c/include/adt/checksum.h (added)
-
c/include/bitops.h (modified) (1 diff)
-
c/include/ddi.h (modified) (1 diff)
-
c/include/io/kio.h (added)
-
c/include/io/klog.h (modified) (2 diffs)
-
c/include/io/log.h (modified) (1 diff)
-
c/include/io/window.h (modified) (4 diffs)
-
c/include/math.h (added)
-
c/include/setjmp.h (modified) (3 diffs)
-
c/include/stdio.h (modified) (2 diffs)
-
draw/cursor/embedded.c (modified) (3 diffs)
-
drv/Makefile (modified) (1 diff)
-
drv/generic/dev_iface.c (modified) (2 diffs)
-
drv/generic/driver.c (modified) (3 diffs)
-
drv/generic/interrupt.c (modified) (4 diffs)
-
drv/generic/private/remote_ahci.h (moved) (moved from uspace/lib/drv/include/remote_ahci.h )
-
drv/generic/private/remote_audio_mixer.h (moved) (moved from uspace/lib/drv/include/remote_audio_mixer.h )
-
drv/generic/private/remote_audio_pcm.h (moved) (moved from uspace/lib/drv/include/remote_audio_pcm.h )
-
drv/generic/private/remote_battery_dev.h (moved) (moved from uspace/lib/drv/include/remote_battery_dev.h )
-
drv/generic/private/remote_char_dev.h (moved) (moved from uspace/lib/drv/include/remote_char_dev.h )
-
drv/generic/private/remote_clock_dev.h (moved) (moved from uspace/lib/drv/include/remote_clock_dev.h )
-
drv/generic/private/remote_graph_dev.h (moved) (moved from uspace/lib/drv/include/remote_graph_dev.h )
-
drv/generic/private/remote_hw_res.h (moved) (moved from uspace/lib/drv/include/remote_hw_res.h )
-
drv/generic/private/remote_nic.h (moved) (moved from uspace/lib/drv/include/remote_nic.h )
-
drv/generic/private/remote_pci.h (moved) (moved from uspace/lib/drv/include/remote_pci.h )
-
drv/generic/private/remote_pio_window.h (moved) (moved from uspace/lib/drv/include/remote_pio_window.h )
-
drv/generic/private/remote_usb.h (moved) (moved from uspace/lib/drv/include/remote_usb.h )
-
drv/generic/private/remote_usbhc.h (moved) (moved from uspace/lib/drv/include/remote_usbhc.h )
-
drv/generic/private/remote_usbhid.h (moved) (moved from uspace/lib/drv/include/remote_usbhid.h )
-
drv/generic/remote_ahci.c (modified) (5 diffs)
-
drv/generic/remote_audio_mixer.c (modified) (3 diffs)
-
drv/generic/remote_audio_pcm.c (modified) (3 diffs)
-
drv/generic/remote_battery_dev.c (modified) (3 diffs)
-
drv/generic/remote_char_dev.c (modified) (3 diffs)
-
drv/generic/remote_clock_dev.c (modified) (3 diffs)
-
drv/generic/remote_graph_dev.c (modified) (1 diff)
-
drv/generic/remote_hw_res.c (modified) (3 diffs)
-
drv/generic/remote_nic.c (modified) (3 diffs)
-
drv/generic/remote_pci.c (modified) (2 diffs)
-
drv/generic/remote_pio_window.c (modified) (2 diffs)
-
drv/generic/remote_usb.c (modified) (3 diffs)
-
drv/generic/remote_usbhc.c (modified) (3 diffs)
-
drv/generic/remote_usbhid.c (modified) (2 diffs)
-
drv/include/ahci_iface.h (modified) (1 diff)
-
drv/include/battery_iface.h (moved) (moved from uspace/lib/c/include/device/battery_dev.h ) (1 diff)
-
drv/include/char_dev_iface.h (moved) (moved from uspace/lib/c/include/device/char_dev.h ) (1 diff)
-
drv/include/ddf/driver.h (modified) (2 diffs)
-
drv/include/ddf/interrupt.h (modified) (1 diff)
-
drv/include/dev_iface.h (modified) (1 diff)
-
drv/include/graph_iface.h (moved) (moved from uspace/lib/c/include/device/graph_dev.h ) (1 diff)
-
drv/include/nic_iface.h (moved) (moved from uspace/lib/c/include/device/nic.h ) (2 diffs)
-
drv/include/ops/battery_dev.h (modified) (1 diff)
-
drv/include/pci_dev_iface.h (modified) (1 diff)
-
drv/include/usbhid_iface.h (modified) (1 diff)
-
gpt/Makefile (added)
-
gpt/global.c (added)
-
gpt/gpt.h (added)
-
gpt/libgpt.c (added)
-
gpt/libgpt.h (added)
-
gui/Makefile (modified) (1 diff)
-
gui/button.c (modified) (5 diffs)
-
gui/button.h (modified) (2 diffs)
-
gui/canvas.c (modified) (1 diff)
-
gui/canvas.h (modified) (1 diff)
-
gui/common.c (added)
-
gui/common.h (added)
-
gui/connection.c (modified) (1 diff)
-
gui/label.c (modified) (5 diffs)
-
gui/label.h (modified) (2 diffs)
-
gui/window.c (modified) (14 diffs)
-
gui/window.h (modified) (2 diffs)
-
math/Makefile (added)
-
math/src/dummy.c (added)
-
mbr/Makefile (added)
-
mbr/libmbr.c (added)
-
mbr/libmbr.h (added)
-
mbr/mbr.h (added)
-
nic/Makefile (modified) (1 diff)
-
nic/src/nic_ev.c (modified) (1 diff)
-
posix/Makefile (modified) (1 diff)
-
posix/include/posix/float.h (modified) (2 diffs)
-
posix/include/posix/math.h (modified) (1 diff)
-
posix/include/posix/setjmp.h (moved) (moved from uspace/lib/c/generic/bitops.c ) (1 diff)
-
posix/include/posix/stdlib.h (modified) (1 diff)
-
posix/source/math.c (deleted)
-
softfloat/softfloat.c (modified) (4 diffs)
-
softfloat/softfloat.h (modified) (2 diffs)
-
softint/Makefile (modified) (1 diff)
-
softint/generic/bits.c (added)
-
softint/generic/shift.c (modified) (1 diff)
-
softint/include/bits.h (added)
-
softint/include/shift.h (modified) (1 diff)
-
usbhid/Makefile (modified) (1 diff)
-
usbhid/src/hidiface.c (deleted)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
r2f591127 r5828554 61 61 generic/bd.c \ 62 62 generic/bd_srv.c \ 63 generic/bitops.c \64 63 generic/cap.c \ 65 64 generic/cfg.c \ … … 70 69 generic/device/hw_res_parsed.c \ 71 70 generic/device/pio_window.c \ 72 generic/device/char_dev.c \73 71 generic/device/clock_dev.c \ 74 generic/device/battery_dev.c \75 generic/device/graph_dev.c \76 generic/device/nic.c \77 generic/device/pci.c \78 generic/device/ahci.c \79 72 generic/dhcp.c \ 80 73 generic/dnsr.c \ … … 108 101 generic/io/log.c \ 109 102 generic/io/logctl.c \ 103 generic/io/kio.c \ 110 104 generic/io/klog.c \ 111 105 generic/io/snprintf.c \ … … 129 123 generic/loader.c \ 130 124 generic/getopt.c \ 125 generic/adt/checksum.c \ 131 126 generic/adt/list.c \ 132 127 generic/adt/hash_table.c \ … … 143 138 generic/net/socket_client.c \ 144 139 generic/net/socket_parse.c \ 140 generic/setjmp.c \ 145 141 generic/stack.c \ 146 142 generic/stacktrace.c \ -
uspace/lib/c/arch/abs32le/include/libarch/atomic.h
r2f591127 r5828554 53 53 } 54 54 55 static inline void atomic_inc(atomic_t *val) { 55 static inline void atomic_inc(atomic_t *val) 56 { 56 57 /* On real hardware the increment has to be done 57 58 as an atomic action. */ … … 60 61 } 61 62 62 static inline void atomic_dec(atomic_t *val) { 63 static inline void atomic_dec(atomic_t *val) 64 { 63 65 /* On real hardware the decrement has to be done 64 66 as an atomic action. */ -
uspace/lib/c/arch/amd64/_link.ld.in
r2f591127 r5828554 39 39 .data : { 40 40 *(.data); 41 *(.data.rel*); 41 42 } :data 42 43 -
uspace/lib/c/arch/ia32/Makefile.inc
r2f591127 r5828554 34 34 arch/$(UARCH)/src/fibril.S \ 35 35 arch/$(UARCH)/src/tls.c \ 36 arch/$(UARCH)/src/setjmp.S \37 36 arch/$(UARCH)/src/stacktrace.c \ 38 37 arch/$(UARCH)/src/stacktrace_asm.S \ -
uspace/lib/c/arch/sparc32/src/stacktrace_asm.S
r2f591127 r5828554 1 1 # 2 # Copyright (c) 200 8 Josef Cejka2 # Copyright (c) 2009 Jakub Jermar 3 3 # All rights reserved. 4 4 # … … 27 27 # 28 28 29 #include <libarch/ context_offset.h>29 #include <libarch/stack.h> 30 30 31 31 .text 32 .global setjmp33 .global longjmp34 32 35 .type setjmp,@function 36 setjmp: 37 movl 0(%esp), %eax # save pc value into eax 38 movl 4(%esp), %edx # address of the jmp_buf structure to save context to 33 .global stacktrace_prepare 34 .global stacktrace_fp_get 35 .global stacktrace_pc_get 36 37 stacktrace_prepare: 38 save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE+STACK_ARG_SAVE_AREA_SIZE), %sp 39 39 40 # save registers to the jmp_buf structure 41 CONTEXT_SAVE_ARCH_CORE %edx %eax 40 # Flush all other windows to memory so that we can read their contents. 42 41 43 xorl %eax, %eax # set_jmp returns 0 42 mov 7, %g1 43 1: 44 subcc %g1, 1, %g1 45 bg 1b 46 save %sp, -64, %sp 47 48 mov 7, %g1 49 1: 50 subcc %g1, 1, %g1 51 bg 1b 52 44 53 ret 54 restore 45 55 46 .type longjmp,@function 47 longjmp: 48 movl 4(%esp), %ecx # put address of jmp_buf into ecx 49 movl 8(%esp), %eax # put return value into eax 50 51 # restore registers from the jmp_buf structure 52 CONTEXT_RESTORE_ARCH_CORE %ecx %edx 53 54 movl %edx, 0(%esp) # put saved pc on stack 55 ret 56 stacktrace_fp_get: 57 # Add the stack bias to %sp to get the actual address. 58 retl 59 mov %sp, %o0 60 61 stacktrace_pc_get: 62 retl 63 mov %o7, %o0 -
uspace/lib/c/generic/assert.c
r2f591127 r5828554 33 33 #include <assert.h> 34 34 #include <stdio.h> 35 #include <io/k log.h>35 #include <io/kio.h> 36 36 #include <stdlib.h> 37 37 #include <atomic.h> … … 44 44 { 45 45 /* 46 * Send the message safely to k log. Nested asserts should not occur.46 * Send the message safely to kio. Nested asserts should not occur. 47 47 */ 48 k log_printf("Assertion failed (%s) in file \"%s\", line %u.\n",48 kio_printf("Assertion failed (%s) in file \"%s\", line %u.\n", 49 49 cond, file, line); 50 50 -
uspace/lib/c/generic/ddi.c
r2f591127 r5828554 280 280 * 281 281 */ 282 int irq_register(int inr, int devno, int method, irq_code_t *ucode)282 int irq_register(int inr, int devno, int method, const irq_code_t *ucode) 283 283 { 284 284 return __SYSCALL4(SYS_IRQ_REGISTER, inr, devno, method, -
uspace/lib/c/generic/io/io.c
r2f591127 r5828554 42 42 #include <malloc.h> 43 43 #include <async.h> 44 #include <io/k log.h>44 #include <io/kio.h> 45 45 #include <vfs/vfs.h> 46 46 #include <vfs/vfs_sess.h> … … 57 57 .error = true, 58 58 .eof = true, 59 .k log= false,59 .kio = false, 60 60 .sess = NULL, 61 61 .btype = _IONBF, … … 67 67 }; 68 68 69 static FILE stdout_k log= {69 static FILE stdout_kio = { 70 70 .fd = -1, 71 71 .error = false, 72 72 .eof = false, 73 .k log= true,73 .kio = true, 74 74 .sess = NULL, 75 75 .btype = _IOLBF, … … 81 81 }; 82 82 83 static FILE stderr_k log= {83 static FILE stderr_kio = { 84 84 .fd = -1, 85 85 .error = false, 86 86 .eof = false, 87 .k log= true,87 .kio = true, 88 88 .sess = NULL, 89 89 .btype = _IONBF, … … 113 113 stdout = fdopen(1, "w"); 114 114 } else { 115 stdout = &stdout_k log;115 stdout = &stdout_kio; 116 116 list_append(&stdout->link, &files); 117 117 } … … 120 120 stderr = fdopen(2, "w"); 121 121 } else { 122 stderr = &stderr_k log;122 stderr = &stderr_kio; 123 123 list_append(&stderr->link, &files); 124 124 } … … 267 267 stream->error = false; 268 268 stream->eof = false; 269 stream->k log= false;269 stream->kio = false; 270 270 stream->sess = NULL; 271 271 stream->need_sync = false; … … 289 289 stream->error = false; 290 290 stream->eof = false; 291 stream->k log= false;291 stream->kio = false; 292 292 stream->sess = NULL; 293 293 stream->need_sync = false; … … 314 314 315 315 if ((stream != &stdin_null) 316 && (stream != &stdout_k log)317 && (stream != &stderr_k log))316 && (stream != &stdout_kio) 317 && (stream != &stderr_kio)) 318 318 free(stream); 319 319 … … 382 382 ssize_t wr; 383 383 384 if (stream->k log)385 wr = k log_write(buf + done, left);384 if (stream->kio) 385 wr = kio_write(buf + done, left); 386 386 else 387 387 wr = write(stream->fd, buf + done, left); … … 705 705 _fflushbuf(stream); 706 706 707 if (stream->k log) {708 k log_update();707 if (stream->kio) { 708 kio_update(); 709 709 return EOK; 710 710 } … … 740 740 int fileno(FILE *stream) 741 741 { 742 if (stream->k log) {742 if (stream->kio) { 743 743 errno = EBADF; 744 744 return -1; -
uspace/lib/c/generic/io/klog.c
r2f591127 r5828554 1 1 /* 2 * Copyright (c) 2006 Josef Cejka 3 * Copyright (c) 2006 Jakub Vana 2 * Copyright (c) 2013 Martin Sucha 4 3 * All rights reserved. 5 4 * … … 41 40 #include <abi/klog.h> 42 41 #include <io/klog.h> 43 #include < io/printf_core.h>42 #include <abi/log.h> 44 43 45 size_t klog_write( const void *buf, size_t size)44 size_t klog_write(log_level_t lvl, const void *buf, size_t size) 46 45 { 47 ssize_t ret = (ssize_t) __SYSCALL3(SYS_KLOG, KLOG_WRITE, (sysarg_t) buf, size); 46 ssize_t ret = (ssize_t) __SYSCALL4(SYS_KLOG, KLOG_WRITE, (sysarg_t) buf, 47 size, lvl); 48 48 49 49 if (ret >= 0) … … 53 53 } 54 54 55 void klog_update(void)55 int klog_read(void *data, size_t size) 56 56 { 57 (void) __SYSCALL3(SYS_KLOG, KLOG_UPDATE, (uintptr_t) NULL, 0); 58 } 59 60 void klog_command(const void *buf, size_t size) 61 { 62 (void) __SYSCALL3(SYS_KLOG, KLOG_COMMAND, (sysarg_t) buf, (sysarg_t) size); 63 } 64 65 /** Print formatted text to klog. 66 * 67 * @param fmt Format string 68 * 69 * \see For more details about format string see printf_core. 70 * 71 */ 72 int klog_printf(const char *fmt, ...) 73 { 74 va_list args; 75 va_start(args, fmt); 76 77 int ret = klog_vprintf(fmt, args); 78 79 va_end(args); 80 81 return ret; 82 } 83 84 static int klog_vprintf_str_write(const char *str, size_t size, void *data) 85 { 86 size_t wr = klog_write(str, size); 87 return str_nlength(str, wr); 88 } 89 90 static int klog_vprintf_wstr_write(const wchar_t *str, size_t size, void *data) 91 { 92 size_t offset = 0; 93 size_t chars = 0; 94 95 while (offset < size) { 96 char buf[STR_BOUNDS(1)]; 97 size_t sz = 0; 98 99 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK) 100 klog_write(buf, sz); 101 102 chars++; 103 offset += sizeof(wchar_t); 104 } 105 106 return chars; 107 } 108 109 /** Print formatted text to klog. 110 * 111 * @param fmt Format string 112 * @param ap Format parameters 113 * 114 * \see For more details about format string see printf_core. 115 * 116 */ 117 int klog_vprintf(const char *fmt, va_list ap) 118 { 119 printf_spec_t ps = { 120 klog_vprintf_str_write, 121 klog_vprintf_wstr_write, 122 NULL 123 }; 124 125 return printf_core(fmt, &ps, ap); 57 return (int) __SYSCALL4(SYS_KLOG, KLOG_READ, (uintptr_t) data, size, 0); 126 58 } 127 59 -
uspace/lib/c/generic/io/window.c
r2f591127 r5828554 40 40 #include <stdio.h> 41 41 42 int win_register(async_sess_t *sess, service_id_t *in, service_id_t *out, 43 sysarg_t x_offset, sysarg_t y_offset) 42 int win_register(async_sess_t *sess, service_id_t *in, service_id_t *out) 44 43 { 45 44 async_exch_t *exch = async_exchange_begin(sess); 46 int ret = async_req_ 2_2(exch, WINDOW_REGISTER, x_offset, y_offset, in, out);45 int ret = async_req_0_2(exch, WINDOW_REGISTER, in, out); 47 46 async_exchange_end(exch); 48 47 49 48 return ret; 50 49 } … … 92 91 } 93 92 94 int win_resize(async_sess_t *sess, sysarg_t width, sysarg_t height, void *cells) 93 int win_resize(async_sess_t *sess, sysarg_t x, sysarg_t y, sysarg_t width, 94 sysarg_t height, window_placement_flags_t placement_flags, void *cells) 95 95 { 96 96 async_exch_t *exch = async_exchange_begin(sess); 97 97 98 98 ipc_call_t answer; 99 aid_t req = async_send_2(exch, WINDOW_RESIZE, width, height, &answer); 100 99 aid_t req = async_send_5(exch, WINDOW_RESIZE, x, y, width, height, 100 (sysarg_t) placement_flags, &answer); 101 101 102 int rc = async_share_out_start(exch, cells, AS_AREA_READ | AS_AREA_CACHEABLE); 102 103 103 104 async_exchange_end(exch); 104 105 105 106 sysarg_t ret; 106 107 async_wait_for(req, &ret); 107 108 if (rc != EOK) {108 109 if (rc != EOK) 109 110 return rc; 110 } else if (ret != EOK) {111 else if (ret != EOK) 111 112 return ret; 112 } else { 113 return EOK; 114 } 113 114 return EOK; 115 115 } 116 116 -
uspace/lib/c/generic/private/stdio.h
r2f591127 r5828554 53 53 int eof; 54 54 55 /** K logindicator */56 int k log;55 /** KIO indicator */ 56 int kio; 57 57 58 58 /** Session to the file provider */ -
uspace/lib/c/include/bitops.h
r2f591127 r5828554 107 107 } 108 108 109 extern int __popcountsi2(int);110 111 109 #endif 112 110 -
uspace/lib/c/include/ddi.h
r2f591127 r5828554 130 130 } 131 131 132 extern int irq_register(int, int, int, irq_code_t *);132 extern int irq_register(int, int, int, const irq_code_t *); 133 133 extern int irq_unregister(int, int); 134 134 -
uspace/lib/c/include/io/klog.h
r2f591127 r5828554 1 1 /* 2 * Copyright (c) 20 06 Jakub Vana2 * Copyright (c) 2013 Martin Sucha 3 3 * All rights reserved. 4 4 * … … 39 39 #include <stdarg.h> 40 40 #include <io/verify.h> 41 #include <stdio.h> 42 #include <stdlib.h> 43 #include <str.h> 44 #include <abi/log.h> 41 45 42 extern size_t klog_write(const void *, size_t); 43 extern void klog_update(void); 44 extern void klog_command(const void *, size_t); 45 extern int klog_printf(const char *, ...) 46 PRINTF_ATTRIBUTE(1, 2); 47 extern int klog_vprintf(const char *, va_list); 46 extern size_t klog_write(log_level_t, const void *, size_t); 47 extern int klog_read(void *, size_t); 48 49 #define KLOG_PRINTF(lvl, fmt, ...) ({ \ 50 char *_fmt = str_dup(fmt); \ 51 size_t _fmtsize = str_size(_fmt); \ 52 if (_fmtsize > 0 && _fmt[_fmtsize - 1] == '\n') \ 53 _fmt[_fmtsize - 1] = 0; \ 54 char *_s; \ 55 int _c = asprintf(&_s, _fmt, ##__VA_ARGS__); \ 56 free(_fmt); \ 57 if (_c >= 0) { \ 58 _c = klog_write((lvl), _s, str_size(_s)); \ 59 free(_s); \ 60 }; \ 61 (_c >= 0); \ 62 }) 48 63 49 64 #endif -
uspace/lib/c/include/io/log.h
r2f591127 r5828554 39 39 #include <io/verify.h> 40 40 41 /** Log message level. */ 42 typedef enum { 43 /** Fatal error, program is not able to recover at all. */ 44 LVL_FATAL, 45 /** Serious error but the program can recover from it. */ 46 LVL_ERROR, 47 /** Easily recoverable problem. */ 48 LVL_WARN, 49 /** Information message that ought to be printed by default. */ 50 LVL_NOTE, 51 /** Debugging purpose message. */ 52 LVL_DEBUG, 53 /** More detailed debugging message. */ 54 LVL_DEBUG2, 55 56 /** For checking range of values */ 57 LVL_LIMIT 58 } log_level_t; 41 #include <abi/log.h> 59 42 60 43 /** Log itself (logging target). */ -
uspace/lib/c/include/io/window.h
r2f591127 r5828554 43 43 #include <io/pos_event.h> 44 44 45 typedef enum { 46 GF_EMPTY = 0, 47 GF_MOVE_X = 1, 48 GF_MOVE_Y = 2, 49 GF_RESIZE_X = 4, 50 GF_RESIZE_Y = 8, 51 GF_SCALE_X = 16, 52 GF_SCALE_Y = 32 53 } window_grab_flags_t; 54 55 typedef enum { 56 WINDOW_PLACEMENT_ANY = 0, 57 WINDOW_PLACEMENT_CENTER_X = 1, 58 WINDOW_PLACEMENT_CENTER_Y = 2, 59 WINDOW_PLACEMENT_CENTER = 60 WINDOW_PLACEMENT_CENTER_X | WINDOW_PLACEMENT_CENTER_Y, 61 WINDOW_PLACEMENT_LEFT = 4, 62 WINDOW_PLACEMENT_RIGHT = 8, 63 WINDOW_PLACEMENT_TOP = 16, 64 WINDOW_PLACEMENT_BOTTOM = 32, 65 WINDOW_PLACEMENT_ABSOLUTE_X = 64, 66 WINDOW_PLACEMENT_ABSOLUTE_Y = 128, 67 WINDOW_PLACEMENT_ABSOLUTE = 68 WINDOW_PLACEMENT_ABSOLUTE_X | WINDOW_PLACEMENT_ABSOLUTE_Y 69 } window_placement_flags_t; 70 45 71 typedef struct { 46 72 sysarg_t object; 47 73 sysarg_t slot; 48 74 sysarg_t argument; 49 } sig _event_t;75 } signal_event_t; 50 76 51 77 typedef struct { 78 sysarg_t offset_x; 79 sysarg_t offset_y; 52 80 sysarg_t width; 53 81 sysarg_t height; 54 } rsz_event_t; 82 window_placement_flags_t placement_flags; 83 } resize_event_t; 55 84 56 85 typedef enum { … … 69 98 kbd_event_t kbd; 70 99 pos_event_t pos; 71 sig _event_t sig;72 r sz_event_t rsz;100 signal_event_t signal; 101 resize_event_t resize; 73 102 } window_event_data_t; 74 103 … … 79 108 } window_event_t; 80 109 81 typedef enum { 82 GF_EMPTY = 0, 83 GF_MOVE_X = 1, 84 GF_MOVE_Y = 2, 85 GF_RESIZE_X = 4, 86 GF_RESIZE_Y = 8, 87 GF_SCALE_X = 16, 88 GF_SCALE_Y = 32 89 } window_grab_flags_t; 90 91 extern int win_register(async_sess_t *, service_id_t *, service_id_t *, sysarg_t, sysarg_t); 110 extern int win_register(async_sess_t *, service_id_t *, service_id_t *); 92 111 93 112 extern int win_get_event(async_sess_t *, window_event_t *); … … 95 114 extern int win_damage(async_sess_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t); 96 115 extern int win_grab(async_sess_t *, sysarg_t, sysarg_t); 97 extern int win_resize(async_sess_t *, sysarg_t, sysarg_t, void *); 116 extern int win_resize(async_sess_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 117 window_placement_flags_t, void *); 98 118 extern int win_close(async_sess_t *); 99 119 extern int win_close_request(async_sess_t *); -
uspace/lib/c/include/setjmp.h
r2f591127 r5828554 1 1 /* 2 2 * Copyright (c) 2008 Josef Cejka 3 * Copyright (c) 2013 Vojtech Horky 3 4 * All rights reserved. 4 5 * … … 30 31 * @{ 31 32 */ 32 /** @file 33 /** @file Long jump implementation. 34 * 35 * Implementation inspired by Jiri Zarevucky's code from 36 * http://bazaar.launchpad.net/~zarevucky-jiri/helenos/stdc/revision/1544/uspace/lib/posix/setjmp.h 33 37 */ 34 38 … … 38 42 #include <libarch/fibril.h> 39 43 40 typedef context_t jmp_buf[1]; 44 struct jmp_buf_interal { 45 context_t context; 46 int return_value; 47 }; 48 typedef struct jmp_buf_interal jmp_buf[1]; 41 49 42 extern int setjmp(jmp_buf env); 50 /* 51 * Specified as extern to minimize number of included headers 52 * because this file is used as is in libposix too. 53 */ 54 extern int context_save(context_t *ctx) __attribute__((returns_twice)); 55 56 /** 57 * Save current environment (registers). 58 * 59 * This function may return twice. 60 * 61 * @param env Variable where to save the environment (of type jmp_buf). 62 * @return Whether the call returned after longjmp. 63 * @retval 0 Environment was saved, normal execution. 64 * @retval other longjmp was executed and returned here. 65 */ 66 #define setjmp(env) \ 67 ((env)[0].return_value = 0, \ 68 context_save(&(env)[0].context), \ 69 (env)[0].return_value) 70 43 71 extern void longjmp(jmp_buf env, int val) __attribute__((noreturn)); 44 72 -
uspace/lib/c/include/stdio.h
r2f591127 r5828554 40 40 #include <str.h> 41 41 #include <io/verify.h> 42 #include <abi/k log.h>42 #include <abi/kio.h> 43 43 44 44 #define EOF (-1) … … 52 52 int _n = snprintf(_buf, sizeof(_buf), fmt, ##__VA_ARGS__); \ 53 53 if (_n > 0) \ 54 (void) __SYSCALL3(SYS_K LOG, KLOG_WRITE, (sysarg_t) _buf, str_size(_buf)); \54 (void) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) _buf, str_size(_buf)); \ 55 55 } 56 56 -
uspace/lib/draw/cursor/embedded.c
r2f591127 r5828554 46 46 assert(state_count); 47 47 assert(data); 48 48 49 49 (*state_count) = 1; 50 50 (*data) = NULL; … … 53 53 static surface_t *cde_render(uint8_t state) 54 54 { 55 if (state != 0) {55 if (state != 0) 56 56 return NULL; 57 } 58 57 59 58 surface_t *surface = surface_create(CURSOR_WIDTH, CURSOR_HEIGHT, NULL, 0); 60 61 if (!surface) { 59 if (!surface) 62 60 return NULL; 63 }64 61 65 62 for (unsigned int y = 0; y < CURSOR_HEIGHT; ++y) { … … 69 66 pixel_t pixel = (cursor_texture[offset] & (1 << (x % 8))) ? 70 67 PIXEL(255, 0, 0, 0) : PIXEL(255, 255, 255, 255); 71 surface_put_pixel(surface, x, y, visible ? pixel : PIXEL(0, 0, 0, 0)); 68 69 if (visible) 70 surface_put_pixel(surface, x, y, pixel); 72 71 } 73 72 } 74 73 75 74 return surface; 76 75 } -
uspace/lib/drv/Makefile
r2f591127 r5828554 29 29 30 30 USPACE_PREFIX = ../.. 31 EXTRA_CFLAGS = -Iinclude -I$(LIBUSB_PREFIX)/include -I$(LIBPCM_PREFIX)/include 31 EXTRA_CFLAGS = \ 32 -Iinclude \ 33 -Igeneric/private \ 34 -I$(LIBUSB_PREFIX)/include \ 35 -I$(LIBPCM_PREFIX)/include 32 36 LIBRARY = libdrv 33 37 -
uspace/lib/drv/generic/dev_iface.c
r2f591127 r5828554 69 69 [CLOCK_DEV_IFACE] = &remote_clock_dev_iface, 70 70 [BATTERY_DEV_IFACE] = &remote_battery_dev_iface, 71 [AHCI_DEV_IFACE] = &remote_ahci_iface 71 [AHCI_DEV_IFACE] = &remote_ahci_iface, 72 72 } 73 73 }; 74 74 75 remote_iface_t *get_remote_iface(int idx)75 const remote_iface_t *get_remote_iface(int idx) 76 76 { 77 77 assert(is_valid_iface_idx(idx)); … … 80 80 81 81 remote_iface_func_ptr_t 82 get_remote_method( remote_iface_t *rem_iface, sysarg_t iface_method_idx)82 get_remote_method(const remote_iface_t *rem_iface, sysarg_t iface_method_idx) 83 83 { 84 84 if (iface_method_idx >= rem_iface->method_count) -
uspace/lib/drv/generic/driver.c
r2f591127 r5828554 63 63 64 64 /** Driver structure */ 65 static driver_t *driver;65 static const driver_t *driver; 66 66 67 67 /** Devices */ … … 413 413 * handling ("remote interface"). 414 414 */ 415 remote_iface_t *rem_iface = get_remote_iface(iface_idx);415 const remote_iface_t *rem_iface = get_remote_iface(iface_idx); 416 416 assert(rem_iface != NULL); 417 417 … … 956 956 } 957 957 958 int ddf_driver_main( driver_t *drv)958 int ddf_driver_main(const driver_t *drv) 959 959 { 960 960 /* -
uspace/lib/drv/generic/interrupt.c
r2f591127 r5828554 39 39 #include <errno.h> 40 40 #include <sys/types.h> 41 #include <macros.h> 41 42 42 43 #include "ddf/interrupt.h" … … 55 56 static interrupt_context_t *find_interrupt_context( 56 57 interrupt_context_list_t *list, ddf_dev_t *dev, int irq); 57 int register_interrupt_handler(ddf_dev_t *dev, int irq,58 interrupt_handler_t *handler, irq_code_t *pseudocode);59 int unregister_interrupt_handler(ddf_dev_t *dev, int irq);60 58 61 59 /** Interrupts */ … … 68 66 }; 69 67 70 static irq_code_t default_pseudocode = {68 static const irq_code_t default_pseudocode = { 71 69 0, 72 70 NULL, 73 sizeof(default_cmds) / sizeof(irq_cmd_t),71 ARRAY_SIZE(default_cmds), 74 72 default_cmds 75 73 }; … … 169 167 170 168 int register_interrupt_handler(ddf_dev_t *dev, int irq, 171 interrupt_handler_t *handler, irq_code_t *pseudocode)169 interrupt_handler_t *handler, const irq_code_t *pseudocode) 172 170 { 173 171 interrupt_context_t *ctx = create_interrupt_context(); -
uspace/lib/drv/generic/remote_ahci.c
r2f591127 r5828554 33 33 */ 34 34 35 #include <as.h> 35 36 #include <async.h> 37 #include <devman.h> 36 38 #include <errno.h> 37 39 #include <stdio.h> 40 #include <macros.h> 38 41 #include "ahci_iface.h" 39 42 #include "ddf/driver.h" … … 47 50 } ahci_iface_funcs_t; 48 51 52 #define MAX_NAME_LENGTH 1024 53 49 54 #define LO(ptr) \ 50 55 ((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) & 0xffffffff)) … … 53 58 ((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) >> 32)) 54 59 60 async_sess_t* ahci_get_sess(devman_handle_t funh, char **name) 61 { 62 // FIXME: Use a better way than substring match 63 64 *name = NULL; 65 66 char devn[MAX_NAME_LENGTH]; 67 int rc = devman_fun_get_name(funh, devn, MAX_NAME_LENGTH); 68 if (rc != EOK) 69 return NULL; 70 71 size_t devn_size = str_size(devn); 72 73 if ((devn_size > 5) && (str_lcmp(devn, "ahci_", 5) == 0)) { 74 async_sess_t *sess = devman_device_connect(EXCHANGE_PARALLEL, 75 funh, IPC_FLAG_BLOCKING); 76 77 if (sess) { 78 *name = str_dup(devn); 79 return sess; 80 } 81 } 82 83 return NULL; 84 } 85 86 int ahci_get_sata_device_name(async_sess_t *sess, size_t sata_dev_name_length, 87 char *sata_dev_name) 88 { 89 async_exch_t *exch = async_exchange_begin(sess); 90 if (!exch) 91 return EINVAL; 92 93 aid_t req = async_send_2(exch, DEV_IFACE_ID(AHCI_DEV_IFACE), 94 IPC_M_AHCI_GET_SATA_DEVICE_NAME, sata_dev_name_length, NULL); 95 96 async_data_read_start(exch, sata_dev_name, sata_dev_name_length); 97 98 sysarg_t rc; 99 async_wait_for(req, &rc); 100 101 return rc; 102 } 103 104 int ahci_get_num_blocks(async_sess_t *sess, uint64_t *blocks) 105 { 106 async_exch_t *exch = async_exchange_begin(sess); 107 if (!exch) 108 return EINVAL; 109 110 sysarg_t blocks_hi; 111 sysarg_t blocks_lo; 112 int rc = async_req_1_2(exch, DEV_IFACE_ID(AHCI_DEV_IFACE), 113 IPC_M_AHCI_GET_NUM_BLOCKS, &blocks_hi, &blocks_lo); 114 115 async_exchange_end(exch); 116 117 if (rc == EOK) { 118 *blocks = (((uint64_t) blocks_hi) << 32) 119 | (((uint64_t) blocks_lo) & 0xffffffff); 120 } 121 122 return rc; 123 } 124 125 int ahci_get_block_size(async_sess_t *sess, size_t *blocks_size) 126 { 127 async_exch_t *exch = async_exchange_begin(sess); 128 if (!exch) 129 return EINVAL; 130 131 sysarg_t bs; 132 int rc = async_req_1_1(exch, DEV_IFACE_ID(AHCI_DEV_IFACE), 133 IPC_M_AHCI_GET_BLOCK_SIZE, &bs); 134 135 async_exchange_end(exch); 136 137 if (rc == EOK) 138 *blocks_size = (size_t) bs; 139 140 return rc; 141 } 142 143 int ahci_read_blocks(async_sess_t *sess, uint64_t blocknum, size_t count, 144 void *buf) 145 { 146 async_exch_t *exch = async_exchange_begin(sess); 147 if (!exch) 148 return EINVAL; 149 150 aid_t req; 151 req = async_send_4(exch, DEV_IFACE_ID(AHCI_DEV_IFACE), 152 IPC_M_AHCI_READ_BLOCKS, HI(blocknum), LO(blocknum), count, NULL); 153 154 async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE); 155 156 async_exchange_end(exch); 157 158 sysarg_t rc; 159 async_wait_for(req, &rc); 160 161 return rc; 162 } 163 164 int ahci_write_blocks(async_sess_t *sess, uint64_t blocknum, size_t count, 165 void* buf) 166 { 167 async_exch_t *exch = async_exchange_begin(sess); 168 if (!exch) 169 return EINVAL; 170 171 aid_t req = async_send_4(exch, DEV_IFACE_ID(AHCI_DEV_IFACE), 172 IPC_M_AHCI_WRITE_BLOCKS, HI(blocknum), LO(blocknum), count, NULL); 173 174 async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE); 175 176 async_exchange_end(exch); 177 178 sysarg_t rc; 179 async_wait_for(req, &rc); 180 181 return rc; 182 } 183 55 184 static void remote_ahci_get_sata_device_name(ddf_fun_t *, void *, ipc_callid_t, 56 185 ipc_call_t *); … … 65 194 66 195 /** Remote AHCI interface operations. */ 67 static remote_iface_func_ptr_t remote_ahci_iface_ops [] = {196 static const remote_iface_func_ptr_t remote_ahci_iface_ops [] = { 68 197 [IPC_M_AHCI_GET_SATA_DEVICE_NAME] = remote_ahci_get_sata_device_name, 69 198 [IPC_M_AHCI_GET_NUM_BLOCKS] = remote_ahci_get_num_blocks, … … 75 204 /** Remote AHCI interface structure. 76 205 */ 77 remote_iface_t remote_ahci_iface = { 78 .method_count = sizeof(remote_ahci_iface_ops) / 79 sizeof(remote_ahci_iface_ops[0]), 206 const remote_iface_t remote_ahci_iface = { 207 .method_count = ARRAY_SIZE(remote_ahci_iface_ops), 80 208 .methods = remote_ahci_iface_ops 81 209 }; -
uspace/lib/drv/generic/remote_audio_mixer.c
r2f591127 r5828554 37 37 #include <assert.h> 38 38 #include <str.h> 39 #include <macros.h> 39 40 40 41 #include "audio_mixer_iface.h" … … 204 205 205 206 /** Remote audio mixer interface operations. */ 206 static remote_iface_func_ptr_t remote_audio_mixer_iface_ops[] = {207 static const remote_iface_func_ptr_t remote_audio_mixer_iface_ops[] = { 207 208 [IPC_M_AUDIO_MIXER_GET_INFO] = remote_audio_mixer_get_info, 208 209 [IPC_M_AUDIO_MIXER_GET_ITEM_INFO] = remote_audio_mixer_get_item_info, … … 212 213 213 214 /** Remote audio mixer interface structure. */ 214 remote_iface_t remote_audio_mixer_iface = { 215 .method_count = sizeof(remote_audio_mixer_iface_ops) / 216 sizeof(remote_audio_mixer_iface_ops[0]), 215 const remote_iface_t remote_audio_mixer_iface = { 216 .method_count = ARRAY_SIZE(remote_audio_mixer_iface_ops), 217 217 .methods = remote_audio_mixer_iface_ops 218 218 }; -
uspace/lib/drv/generic/remote_audio_pcm.c
r2f591127 r5828554 38 38 #include <macros.h> 39 39 #include <str.h> 40 #include <as.h>41 40 #include <sys/mman.h> 42 41 … … 611 610 612 611 /** Remote audio pcm buffer interface operations. */ 613 static remote_iface_func_ptr_t remote_audio_pcm_iface_ops[] = {612 static const remote_iface_func_ptr_t remote_audio_pcm_iface_ops[] = { 614 613 [IPC_M_AUDIO_PCM_GET_INFO_STR] = remote_audio_pcm_get_info_str, 615 614 [IPC_M_AUDIO_PCM_QUERY_CAPS] = remote_audio_pcm_query_caps, … … 627 626 628 627 /** Remote audio mixer interface structure. */ 629 remote_iface_t remote_audio_pcm_iface = { 630 .method_count = sizeof(remote_audio_pcm_iface_ops) / 631 sizeof(remote_audio_pcm_iface_ops[0]), 628 const remote_iface_t remote_audio_pcm_iface = { 629 .method_count = ARRAY_SIZE(remote_audio_pcm_iface_ops), 632 630 .methods = remote_audio_pcm_iface_ops 633 631 }; -
uspace/lib/drv/generic/remote_battery_dev.c
r2f591127 r5828554 36 36 #include <errno.h> 37 37 #include <ops/battery_dev.h> 38 #include < device/battery_dev.h>38 #include <battery_iface.h> 39 39 #include <ddf/driver.h> 40 #include <macros.h> 41 42 /** Read the current battery status from the device 43 * 44 * @param sess Session of the device 45 * @param status Current status of the battery 46 * 47 * @return EOK on success or a negative error code 48 */ 49 int 50 battery_status_get(async_sess_t *sess, battery_status_t *batt_status) 51 { 52 sysarg_t status; 53 54 async_exch_t *exch = async_exchange_begin(sess); 55 56 int const rc = async_req_1_1(exch, DEV_IFACE_ID(BATTERY_DEV_IFACE), 57 BATTERY_STATUS_GET, &status); 58 59 async_exchange_end(exch); 60 61 if (rc == EOK) 62 *batt_status = (battery_status_t) status; 63 64 return rc; 65 } 66 67 /** Read the current battery charge level from the device 68 * 69 * @param sess Session of the device 70 * @param level Battery charge level (0 - 100) 71 * 72 * @return EOK on success or a negative error code 73 */ 74 int 75 battery_charge_level_get(async_sess_t *sess, int *level) 76 { 77 sysarg_t charge_level; 78 79 async_exch_t *exch = async_exchange_begin(sess); 80 81 int const rc = async_req_1_1(exch, DEV_IFACE_ID(BATTERY_DEV_IFACE), 82 BATTERY_CHARGE_LEVEL_GET, &charge_level); 83 84 async_exchange_end(exch); 85 86 if (rc == EOK) 87 *level = (int) charge_level; 88 89 return rc; 90 } 40 91 41 92 static void remote_battery_status_get(ddf_fun_t *, void *, ipc_callid_t, … … 45 96 46 97 /** Remote battery interface operations */ 47 static remote_iface_func_ptr_t remote_battery_dev_iface_ops[] = {48 &remote_battery_status_get,49 &remote_battery_charge_level_get,98 static const remote_iface_func_ptr_t remote_battery_dev_iface_ops[] = { 99 [BATTERY_STATUS_GET] = remote_battery_status_get, 100 [BATTERY_CHARGE_LEVEL_GET] = remote_battery_charge_level_get, 50 101 }; 51 102 … … 56 107 * 57 108 */ 58 remote_iface_t remote_battery_dev_iface = { 59 .method_count = sizeof(remote_battery_dev_iface_ops) / 60 sizeof(remote_iface_func_ptr_t), 109 const remote_iface_t remote_battery_dev_iface = { 110 .method_count = ARRAY_SIZE(remote_battery_dev_iface_ops), 61 111 .methods = remote_battery_dev_iface_ops, 62 112 }; -
uspace/lib/drv/generic/remote_char_dev.c
r2f591127 r5828554 35 35 #include <async.h> 36 36 #include <errno.h> 37 #include <macros.h> 37 38 38 39 #include "ops/char_dev.h" 40 #include "char_dev_iface.h" 39 41 #include "ddf/driver.h" 40 42 41 43 #define MAX_CHAR_RW_COUNT 256 44 45 /** Read to or write from device. 46 * 47 * Helper function to read to or write from a device 48 * using its character interface. 49 * 50 * @param sess Session to the device. 51 * @param buf Buffer for the data read from or written to the device. 52 * @param size Maximum size of data (in bytes) to be read or written. 53 * @param read Read from the device if true, write to it otherwise. 54 * 55 * @return Non-negative number of bytes actually read from or 56 * written to the device on success, negative error number 57 * otherwise. 58 * 59 */ 60 static ssize_t char_dev_rw(async_sess_t *sess, void *buf, size_t size, bool read) 61 { 62 ipc_call_t answer; 63 aid_t req; 64 int ret; 65 66 async_exch_t *exch = async_exchange_begin(sess); 67 68 if (read) { 69 req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE), 70 CHAR_DEV_READ, &answer); 71 ret = async_data_read_start(exch, buf, size); 72 } else { 73 req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE), 74 CHAR_DEV_WRITE, &answer); 75 ret = async_data_write_start(exch, buf, size); 76 } 77 78 async_exchange_end(exch); 79 80 sysarg_t rc; 81 if (ret != EOK) { 82 async_wait_for(req, &rc); 83 if (rc == EOK) 84 return (ssize_t) ret; 85 86 return (ssize_t) rc; 87 } 88 89 async_wait_for(req, &rc); 90 91 ret = (int) rc; 92 if (ret != EOK) 93 return (ssize_t) ret; 94 95 return (ssize_t) IPC_GET_ARG1(answer); 96 } 97 98 /** Read from character device. 99 * 100 * @param sess Session to the device. 101 * @param buf Output buffer for the data read from the device. 102 * @param size Maximum size (in bytes) of the data to be read. 103 * 104 * @return Non-negative number of bytes actually read from the 105 * device on success, negative error number otherwise. 106 * 107 */ 108 ssize_t char_dev_read(async_sess_t *sess, void *buf, size_t size) 109 { 110 return char_dev_rw(sess, buf, size, true); 111 } 112 113 /** Write to character device. 114 * 115 * @param sess Session to the device. 116 * @param buf Input buffer containg the data to be written to the 117 * device. 118 * @param size Maximum size (in bytes) of the data to be written. 119 * 120 * @return Non-negative number of bytes actually written to the 121 * device on success, negative error number otherwise. 122 * 123 */ 124 ssize_t char_dev_write(async_sess_t *sess, void *buf, size_t size) 125 { 126 return char_dev_rw(sess, buf, size, false); 127 } 42 128 43 129 static void remote_char_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); … … 45 131 46 132 /** Remote character interface operations. */ 47 static remote_iface_func_ptr_t remote_char_dev_iface_ops[] = {48 &remote_char_read,49 &remote_char_write133 static const remote_iface_func_ptr_t remote_char_dev_iface_ops[] = { 134 [CHAR_DEV_READ] = remote_char_read, 135 [CHAR_DEV_WRITE] = remote_char_write 50 136 }; 51 137 … … 55 141 * character interface. 56 142 */ 57 remote_iface_t remote_char_dev_iface = { 58 .method_count = sizeof(remote_char_dev_iface_ops) / 59 sizeof(remote_iface_func_ptr_t), 143 const remote_iface_t remote_char_dev_iface = { 144 .method_count = ARRAY_SIZE(remote_char_dev_iface_ops), 60 145 .methods = remote_char_dev_iface_ops 61 146 }; -
uspace/lib/drv/generic/remote_clock_dev.c
r2f591127 r5828554 36 36 #include <errno.h> 37 37 #include <time.h> 38 #include <macros.h> 39 #include <device/clock_dev.h> 38 40 39 41 #include <ops/clock_dev.h> … … 46 48 47 49 /** Remote clock interface operations */ 48 static remote_iface_func_ptr_t remote_clock_dev_iface_ops[] = {49 &remote_clock_time_get,50 &remote_clock_time_set,50 static const remote_iface_func_ptr_t remote_clock_dev_iface_ops[] = { 51 [CLOCK_DEV_TIME_GET] = remote_clock_time_get, 52 [CLOCK_DEV_TIME_SET] = remote_clock_time_set, 51 53 }; 52 54 … … 56 58 * addressed by the clock interface. 57 59 */ 58 remote_iface_t remote_clock_dev_iface = { 59 .method_count = sizeof(remote_clock_dev_iface_ops) / 60 sizeof(remote_iface_func_ptr_t), 60 const remote_iface_t remote_clock_dev_iface = { 61 .method_count = ARRAY_SIZE(remote_clock_dev_iface_ops), 61 62 .methods = remote_clock_dev_iface_ops, 62 63 }; -
uspace/lib/drv/generic/remote_graph_dev.c
r2f591127 r5828554 35 35 #include <errno.h> 36 36 #include <async.h> 37 #include <macros.h> 37 38 38 39 #include "ops/graph_dev.h" 40 #include "graph_iface.h" 39 41 #include "ddf/driver.h" 42 43 typedef enum { 44 GRAPH_DEV_CONNECT = 0 45 } graph_dev_method_t; 46 47 int graph_dev_connect(async_sess_t *sess) 48 { 49 async_exch_t *exch = async_exchange_begin(sess); 50 int ret = async_req_1_0(exch, DEV_IFACE_ID(GRAPH_DEV_IFACE), GRAPH_DEV_CONNECT); 51 async_exchange_end(exch); 52 53 return ret; 54 } 40 55 41 56 static void remote_graph_connect(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 42 57 43 static remote_iface_func_ptr_t remote_graph_dev_iface_ops[] = {44 &remote_graph_connect58 static const remote_iface_func_ptr_t remote_graph_dev_iface_ops[] = { 59 [GRAPH_DEV_CONNECT] = remote_graph_connect 45 60 }; 46 61 47 remote_iface_t remote_graph_dev_iface = { 48 .method_count = sizeof(remote_graph_dev_iface_ops) / 49 sizeof(remote_iface_func_ptr_t), 62 const remote_iface_t remote_graph_dev_iface = { 63 .method_count = ARRAY_SIZE(remote_graph_dev_iface_ops), 50 64 .methods = remote_graph_dev_iface_ops 51 65 }; -
uspace/lib/drv/generic/remote_hw_res.c
r2f591127 r5828554 36 36 #include <async.h> 37 37 #include <errno.h> 38 #include <macros.h> 38 39 39 40 #include "ops/hw_res.h" … … 49 50 ipc_call_t *); 50 51 51 static remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {52 static const remote_iface_func_ptr_t remote_hw_res_iface_ops [] = { 52 53 [HW_RES_GET_RESOURCE_LIST] = &remote_hw_res_get_resource_list, 53 54 [HW_RES_ENABLE_INTERRUPT] = &remote_hw_res_enable_interrupt, … … 56 57 }; 57 58 58 remote_iface_t remote_hw_res_iface = { 59 .method_count = sizeof(remote_hw_res_iface_ops) / 60 sizeof(remote_iface_func_ptr_t), 59 const remote_iface_t remote_hw_res_iface = { 60 .method_count = ARRAY_SIZE(remote_hw_res_iface_ops), 61 61 .methods = remote_hw_res_iface_ops 62 62 }; -
uspace/lib/drv/generic/remote_nic.c
r2f591127 r5828554 40 40 #include <ipc/services.h> 41 41 #include <sys/time.h> 42 #include <macros.h> 43 42 44 #include "ops/nic.h" 45 #include "nic_iface.h" 46 47 typedef enum { 48 NIC_SEND_MESSAGE = 0, 49 NIC_CALLBACK_CREATE, 50 NIC_GET_STATE, 51 NIC_SET_STATE, 52 NIC_GET_ADDRESS, 53 NIC_SET_ADDRESS, 54 NIC_GET_STATS, 55 NIC_GET_DEVICE_INFO, 56 NIC_GET_CABLE_STATE, 57 NIC_GET_OPERATION_MODE, 58 NIC_SET_OPERATION_MODE, 59 NIC_AUTONEG_ENABLE, 60 NIC_AUTONEG_DISABLE, 61 NIC_AUTONEG_PROBE, 62 NIC_AUTONEG_RESTART, 63 NIC_GET_PAUSE, 64 NIC_SET_PAUSE, 65 NIC_UNICAST_GET_MODE, 66 NIC_UNICAST_SET_MODE, 67 NIC_MULTICAST_GET_MODE, 68 NIC_MULTICAST_SET_MODE, 69 NIC_BROADCAST_GET_MODE, 70 NIC_BROADCAST_SET_MODE, 71 NIC_DEFECTIVE_GET_MODE, 72 NIC_DEFECTIVE_SET_MODE, 73 NIC_BLOCKED_SOURCES_GET, 74 NIC_BLOCKED_SOURCES_SET, 75 NIC_VLAN_GET_MASK, 76 NIC_VLAN_SET_MASK, 77 NIC_VLAN_SET_TAG, 78 NIC_WOL_VIRTUE_ADD, 79 NIC_WOL_VIRTUE_REMOVE, 80 NIC_WOL_VIRTUE_PROBE, 81 NIC_WOL_VIRTUE_LIST, 82 NIC_WOL_VIRTUE_GET_CAPS, 83 NIC_WOL_LOAD_INFO, 84 NIC_OFFLOAD_PROBE, 85 NIC_OFFLOAD_SET, 86 NIC_POLL_GET_MODE, 87 NIC_POLL_SET_MODE, 88 NIC_POLL_NOW 89 } nic_funcs_t; 90 91 /** Send frame from NIC 92 * 93 * @param[in] dev_sess 94 * @param[in] data Frame data 95 * @param[in] size Frame size in bytes 96 * 97 * @return EOK If the operation was successfully completed 98 * 99 */ 100 int nic_send_frame(async_sess_t *dev_sess, void *data, size_t size) 101 { 102 async_exch_t *exch = async_exchange_begin(dev_sess); 103 104 ipc_call_t answer; 105 aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 106 NIC_SEND_MESSAGE, &answer); 107 sysarg_t retval = async_data_write_start(exch, data, size); 108 109 async_exchange_end(exch); 110 111 if (retval != EOK) { 112 async_forget(req); 113 return retval; 114 } 115 116 async_wait_for(req, &retval); 117 return retval; 118 } 119 120 /** Create callback connection from NIC service 121 * 122 * @param[in] dev_sess 123 * @param[in] device_id 124 * 125 * @return EOK If the operation was successfully completed 126 * 127 */ 128 int nic_callback_create(async_sess_t *dev_sess, async_client_conn_t cfun, 129 void *carg) 130 { 131 ipc_call_t answer; 132 int rc; 133 sysarg_t retval; 134 135 async_exch_t *exch = async_exchange_begin(dev_sess); 136 aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 137 NIC_CALLBACK_CREATE, &answer); 138 139 rc = async_connect_to_me(exch, 0, 0, 0, cfun, carg); 140 if (rc != EOK) { 141 async_forget(req); 142 return rc; 143 } 144 async_exchange_end(exch); 145 146 async_wait_for(req, &retval); 147 return (int) retval; 148 } 149 150 /** Get the current state of the device 151 * 152 * @param[in] dev_sess 153 * @param[out] state Current state 154 * 155 * @return EOK If the operation was successfully completed 156 * 157 */ 158 int nic_get_state(async_sess_t *dev_sess, nic_device_state_t *state) 159 { 160 assert(state); 161 162 sysarg_t _state; 163 164 async_exch_t *exch = async_exchange_begin(dev_sess); 165 int rc = async_req_1_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 166 NIC_GET_STATE, &_state); 167 async_exchange_end(exch); 168 169 *state = (nic_device_state_t) _state; 170 171 return rc; 172 } 173 174 /** Request the device to change its state 175 * 176 * @param[in] dev_sess 177 * @param[in] state New state 178 * 179 * @return EOK If the operation was successfully completed 180 * 181 */ 182 int nic_set_state(async_sess_t *dev_sess, nic_device_state_t state) 183 { 184 async_exch_t *exch = async_exchange_begin(dev_sess); 185 int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 186 NIC_SET_STATE, state); 187 async_exchange_end(exch); 188 189 return rc; 190 } 191 192 /** Request the MAC address of the device 193 * 194 * @param[in] dev_sess 195 * @param[out] address Structure with buffer for the address 196 * 197 * @return EOK If the operation was successfully completed 198 * 199 */ 200 int nic_get_address(async_sess_t *dev_sess, nic_address_t *address) 201 { 202 assert(address); 203 204 async_exch_t *exch = async_exchange_begin(dev_sess); 205 aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 206 NIC_GET_ADDRESS, NULL); 207 int rc = async_data_read_start(exch, address, sizeof(nic_address_t)); 208 async_exchange_end(exch); 209 210 sysarg_t res; 211 async_wait_for(aid, &res); 212 213 if (rc != EOK) 214 return rc; 215 216 return (int) res; 217 } 218 219 /** Set the address of the device (e.g. MAC on Ethernet) 220 * 221 * @param[in] dev_sess 222 * @param[in] address Pointer to the address 223 * 224 * @return EOK If the operation was successfully completed 225 * 226 */ 227 int nic_set_address(async_sess_t *dev_sess, const nic_address_t *address) 228 { 229 assert(address); 230 231 async_exch_t *exch = async_exchange_begin(dev_sess); 232 aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 233 NIC_SET_ADDRESS, NULL); 234 int rc = async_data_write_start(exch, address, sizeof(nic_address_t)); 235 async_exchange_end(exch); 236 237 sysarg_t res; 238 async_wait_for(aid, &res); 239 240 if (rc != EOK) 241 return rc; 242 243 return (int) res; 244 } 245 246 /** Request statistic data about NIC operation. 247 * 248 * @param[in] dev_sess 249 * @param[out] stats Structure with the statistics 250 * 251 * @return EOK If the operation was successfully completed 252 * 253 */ 254 int nic_get_stats(async_sess_t *dev_sess, nic_device_stats_t *stats) 255 { 256 assert(stats); 257 258 async_exch_t *exch = async_exchange_begin(dev_sess); 259 260 int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 261 NIC_GET_STATS); 262 if (rc != EOK) { 263 async_exchange_end(exch); 264 return rc; 265 } 266 267 rc = async_data_read_start(exch, stats, sizeof(nic_device_stats_t)); 268 269 async_exchange_end(exch); 270 271 return rc; 272 } 273 274 /** Request information about the device. 275 * 276 * @see nic_device_info_t 277 * 278 * @param[in] dev_sess 279 * @param[out] device_info Information about the device 280 * 281 * @return EOK If the operation was successfully completed 282 * 283 */ 284 int nic_get_device_info(async_sess_t *dev_sess, nic_device_info_t *device_info) 285 { 286 assert(device_info); 287 288 async_exch_t *exch = async_exchange_begin(dev_sess); 289 290 int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 291 NIC_GET_DEVICE_INFO); 292 if (rc != EOK) { 293 async_exchange_end(exch); 294 return rc; 295 } 296 297 rc = async_data_read_start(exch, device_info, sizeof(nic_device_info_t)); 298 299 async_exchange_end(exch); 300 301 return rc; 302 } 303 304 /** Request status of the cable (plugged/unplugged) 305 * 306 * @param[in] dev_sess 307 * @param[out] cable_state Current cable state 308 * 309 * @return EOK If the operation was successfully completed 310 * 311 */ 312 int nic_get_cable_state(async_sess_t *dev_sess, nic_cable_state_t *cable_state) 313 { 314 assert(cable_state); 315 316 sysarg_t _cable_state; 317 318 async_exch_t *exch = async_exchange_begin(dev_sess); 319 int rc = async_req_1_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 320 NIC_GET_CABLE_STATE, &_cable_state); 321 async_exchange_end(exch); 322 323 *cable_state = (nic_cable_state_t) _cable_state; 324 325 return rc; 326 } 327 328 /** Request current operation mode. 329 * 330 * @param[in] dev_sess 331 * @param[out] speed Current operation speed in Mbps. Can be NULL. 332 * @param[out] duplex Full duplex/half duplex. Can be NULL. 333 * @param[out] role Master/slave/auto. Can be NULL. 334 * 335 * @return EOK If the operation was successfully completed 336 * 337 */ 338 int nic_get_operation_mode(async_sess_t *dev_sess, int *speed, 339 nic_channel_mode_t *duplex, nic_role_t *role) 340 { 341 sysarg_t _speed; 342 sysarg_t _duplex; 343 sysarg_t _role; 344 345 async_exch_t *exch = async_exchange_begin(dev_sess); 346 int rc = async_req_1_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 347 NIC_GET_OPERATION_MODE, &_speed, &_duplex, &_role); 348 async_exchange_end(exch); 349 350 if (speed) 351 *speed = (int) _speed; 352 353 if (duplex) 354 *duplex = (nic_channel_mode_t) _duplex; 355 356 if (role) 357 *role = (nic_role_t) _role; 358 359 return rc; 360 } 361 362 /** Set current operation mode. 363 * 364 * If the NIC has auto-negotiation enabled, this command 365 * disables auto-negotiation and sets the operation mode. 366 * 367 * @param[in] dev_sess 368 * @param[in] speed Operation speed in Mbps 369 * @param[in] duplex Full duplex/half duplex 370 * @param[in] role Master/slave/auto (e.g. in Gbit Ethernet] 371 * 372 * @return EOK If the operation was successfully completed 373 * 374 */ 375 int nic_set_operation_mode(async_sess_t *dev_sess, int speed, 376 nic_channel_mode_t duplex, nic_role_t role) 377 { 378 async_exch_t *exch = async_exchange_begin(dev_sess); 379 int rc = async_req_4_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 380 NIC_SET_OPERATION_MODE, (sysarg_t) speed, (sysarg_t) duplex, 381 (sysarg_t) role); 382 async_exchange_end(exch); 383 384 return rc; 385 } 386 387 /** Enable auto-negotiation. 388 * 389 * The advertisement argument can only limit some modes, 390 * it can never force the NIC to advertise unsupported modes. 391 * 392 * The allowed modes are defined in "nic/eth_phys.h" in the C library. 393 * 394 * @param[in] dev_sess 395 * @param[in] advertisement Allowed advertised modes. Use 0 for all modes. 396 * 397 * @return EOK If the operation was successfully completed 398 * 399 */ 400 int nic_autoneg_enable(async_sess_t *dev_sess, uint32_t advertisement) 401 { 402 async_exch_t *exch = async_exchange_begin(dev_sess); 403 int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 404 NIC_AUTONEG_ENABLE, (sysarg_t) advertisement); 405 async_exchange_end(exch); 406 407 return rc; 408 } 409 410 /** Disable auto-negotiation. 411 * 412 * @param[in] dev_sess 413 * 414 * @return EOK If the operation was successfully completed 415 * 416 */ 417 int nic_autoneg_disable(async_sess_t *dev_sess) 418 { 419 async_exch_t *exch = async_exchange_begin(dev_sess); 420 int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 421 NIC_AUTONEG_DISABLE); 422 async_exchange_end(exch); 423 424 return rc; 425 } 426 427 /** Probe current state of auto-negotiation. 428 * 429 * Modes are defined in the "nic/eth_phys.h" in the C library. 430 * 431 * @param[in] dev_sess 432 * @param[out] our_advertisement Modes advertised by this NIC. 433 * Can be NULL. 434 * @param[out] their_advertisement Modes advertised by the other side. 435 * Can be NULL. 436 * @param[out] result General state of auto-negotiation. 437 * Can be NULL. 438 * @param[out] their_result State of other side auto-negotiation. 439 * Can be NULL. 440 * 441 * @return EOK If the operation was successfully completed 442 * 443 */ 444 int nic_autoneg_probe(async_sess_t *dev_sess, uint32_t *our_advertisement, 445 uint32_t *their_advertisement, nic_result_t *result, 446 nic_result_t *their_result) 447 { 448 sysarg_t _our_advertisement; 449 sysarg_t _their_advertisement; 450 sysarg_t _result; 451 sysarg_t _their_result; 452 453 async_exch_t *exch = async_exchange_begin(dev_sess); 454 int rc = async_req_1_4(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 455 NIC_AUTONEG_PROBE, &_our_advertisement, &_their_advertisement, 456 &_result, &_their_result); 457 async_exchange_end(exch); 458 459 if (our_advertisement) 460 *our_advertisement = (uint32_t) _our_advertisement; 461 462 if (*their_advertisement) 463 *their_advertisement = (uint32_t) _their_advertisement; 464 465 if (result) 466 *result = (nic_result_t) _result; 467 468 if (their_result) 469 *their_result = (nic_result_t) _their_result; 470 471 return rc; 472 } 473 474 /** Restart the auto-negotiation process. 475 * 476 * @param[in] dev_sess 477 * 478 * @return EOK If the operation was successfully completed 479 * 480 */ 481 int nic_autoneg_restart(async_sess_t *dev_sess) 482 { 483 async_exch_t *exch = async_exchange_begin(dev_sess); 484 int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 485 NIC_AUTONEG_RESTART); 486 async_exchange_end(exch); 487 488 return rc; 489 } 490 491 /** Query party's sending and reception of the PAUSE frame. 492 * 493 * @param[in] dev_sess 494 * @param[out] we_send This NIC sends the PAUSE frame (true/false) 495 * @param[out] we_receive This NIC receives the PAUSE frame (true/false) 496 * @param[out] pause The time set to transmitted PAUSE frames. 497 * 498 * @return EOK If the operation was successfully completed 499 * 500 */ 501 int nic_get_pause(async_sess_t *dev_sess, nic_result_t *we_send, 502 nic_result_t *we_receive, uint16_t *pause) 503 { 504 sysarg_t _we_send; 505 sysarg_t _we_receive; 506 sysarg_t _pause; 507 508 async_exch_t *exch = async_exchange_begin(dev_sess); 509 int rc = async_req_1_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 510 NIC_GET_PAUSE, &_we_send, &_we_receive, &_pause); 511 async_exchange_end(exch); 512 513 if (we_send) 514 *we_send = _we_send; 515 516 if (we_receive) 517 *we_receive = _we_receive; 518 519 if (pause) 520 *pause = _pause; 521 522 return rc; 523 } 524 525 /** Control sending and reception of the PAUSE frame. 526 * 527 * @param[in] dev_sess 528 * @param[in] allow_send Allow sending the PAUSE frame (true/false) 529 * @param[in] allow_receive Allow reception of the PAUSE frame (true/false) 530 * @param[in] pause Pause length in 512 bit units written 531 * to transmitted frames. The value 0 means 532 * auto value (the best). If the requested 533 * time cannot be set the driver is allowed 534 * to set the nearest supported value. 535 * 536 * @return EOK If the operation was successfully completed 537 * 538 */ 539 int nic_set_pause(async_sess_t *dev_sess, int allow_send, int allow_receive, 540 uint16_t pause) 541 { 542 async_exch_t *exch = async_exchange_begin(dev_sess); 543 int rc = async_req_4_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 544 NIC_SET_PAUSE, allow_send, allow_receive, pause); 545 async_exchange_end(exch); 546 547 return rc; 548 } 549 550 /** Retrieve current settings of unicast frames reception. 551 * 552 * Note: In case of mode != NIC_UNICAST_LIST the contents of 553 * address_list and address_count are undefined. 554 * 555 * @param[in] dev_sess 556 * @param[out] mode Current operation mode 557 * @param[in] max_count Maximal number of addresses that could 558 * be written into the list buffer. 559 * @param[out] address_list Buffer for the list (array). Can be NULL. 560 * @param[out] address_count Number of addresses in the list before 561 * possible truncation due to the max_count. 562 * 563 * @return EOK If the operation was successfully completed 564 * 565 */ 566 int nic_unicast_get_mode(async_sess_t *dev_sess, nic_unicast_mode_t *mode, 567 size_t max_count, nic_address_t *address_list, size_t *address_count) 568 { 569 assert(mode); 570 571 sysarg_t _mode; 572 sysarg_t _address_count; 573 574 if (!address_list) 575 max_count = 0; 576 577 async_exch_t *exch = async_exchange_begin(dev_sess); 578 579 int rc = async_req_2_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 580 NIC_UNICAST_GET_MODE, max_count, &_mode, &_address_count); 581 if (rc != EOK) { 582 async_exchange_end(exch); 583 return rc; 584 } 585 586 *mode = (nic_unicast_mode_t) _mode; 587 if (address_count) 588 *address_count = (size_t) _address_count; 589 590 if ((max_count) && (_address_count)) 591 rc = async_data_read_start(exch, address_list, 592 max_count * sizeof(nic_address_t)); 593 594 async_exchange_end(exch); 595 596 return rc; 597 } 598 599 /** Set which unicast frames are received. 600 * 601 * @param[in] dev_sess 602 * @param[in] mode Current operation mode 603 * @param[in] address_list The list of addresses. Can be NULL. 604 * @param[in] address_count Number of addresses in the list. 605 * 606 * @return EOK If the operation was successfully completed 607 * 608 */ 609 int nic_unicast_set_mode(async_sess_t *dev_sess, nic_unicast_mode_t mode, 610 const nic_address_t *address_list, size_t address_count) 611 { 612 if (address_list == NULL) 613 address_count = 0; 614 615 async_exch_t *exch = async_exchange_begin(dev_sess); 616 617 aid_t message_id = async_send_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 618 NIC_UNICAST_SET_MODE, (sysarg_t) mode, address_count, NULL); 619 620 int rc; 621 if (address_count) 622 rc = async_data_write_start(exch, address_list, 623 address_count * sizeof(nic_address_t)); 624 else 625 rc = EOK; 626 627 async_exchange_end(exch); 628 629 sysarg_t res; 630 async_wait_for(message_id, &res); 631 632 if (rc != EOK) 633 return rc; 634 635 return (int) res; 636 } 637 638 /** Retrieve current settings of multicast frames reception. 639 * 640 * Note: In case of mode != NIC_MULTICAST_LIST the contents of 641 * address_list and address_count are undefined. 642 * 643 * @param[in] dev_sess 644 * @param[out] mode Current operation mode 645 * @param[in] max_count Maximal number of addresses that could 646 * be written into the list buffer. 647 * @param[out] address_list Buffer for the list (array). Can be NULL. 648 * @param[out] address_count Number of addresses in the list before 649 * possible truncation due to the max_count. 650 * Can be NULL. 651 * 652 * @return EOK If the operation was successfully completed 653 * 654 */ 655 int nic_multicast_get_mode(async_sess_t *dev_sess, nic_multicast_mode_t *mode, 656 size_t max_count, nic_address_t *address_list, size_t *address_count) 657 { 658 assert(mode); 659 660 sysarg_t _mode; 661 662 if (!address_list) 663 max_count = 0; 664 665 async_exch_t *exch = async_exchange_begin(dev_sess); 666 667 sysarg_t ac; 668 int rc = async_req_2_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 669 NIC_MULTICAST_GET_MODE, max_count, &_mode, &ac); 670 if (rc != EOK) { 671 async_exchange_end(exch); 672 return rc; 673 } 674 675 *mode = (nic_multicast_mode_t) _mode; 676 if (address_count) 677 *address_count = (size_t) ac; 678 679 if ((max_count) && (ac)) 680 rc = async_data_read_start(exch, address_list, 681 max_count * sizeof(nic_address_t)); 682 683 async_exchange_end(exch); 684 return rc; 685 } 686 687 /** Set which multicast frames are received. 688 * 689 * @param[in] dev_sess 690 * @param[in] mode Current operation mode 691 * @param[in] address_list The list of addresses. Can be NULL. 692 * @param[in] address_count Number of addresses in the list. 693 * 694 * @return EOK If the operation was successfully completed 695 * 696 */ 697 int nic_multicast_set_mode(async_sess_t *dev_sess, nic_multicast_mode_t mode, 698 const nic_address_t *address_list, size_t address_count) 699 { 700 if (address_list == NULL) 701 address_count = 0; 702 703 async_exch_t *exch = async_exchange_begin(dev_sess); 704 705 aid_t message_id = async_send_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 706 NIC_MULTICAST_SET_MODE, (sysarg_t) mode, address_count, NULL); 707 708 int rc; 709 if (address_count) 710 rc = async_data_write_start(exch, address_list, 711 address_count * sizeof(nic_address_t)); 712 else 713 rc = EOK; 714 715 async_exchange_end(exch); 716 717 sysarg_t res; 718 async_wait_for(message_id, &res); 719 720 if (rc != EOK) 721 return rc; 722 723 return (int) res; 724 } 725 726 /** Determine if broadcast packets are received. 727 * 728 * @param[in] dev_sess 729 * @param[out] mode Current operation mode 730 * 731 * @return EOK If the operation was successfully completed 732 * 733 */ 734 int nic_broadcast_get_mode(async_sess_t *dev_sess, nic_broadcast_mode_t *mode) 735 { 736 assert(mode); 737 738 sysarg_t _mode; 739 740 async_exch_t *exch = async_exchange_begin(dev_sess); 741 int rc = async_req_1_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 742 NIC_BROADCAST_GET_MODE, &_mode); 743 async_exchange_end(exch); 744 745 *mode = (nic_broadcast_mode_t) _mode; 746 747 return rc; 748 } 749 750 /** Set whether broadcast packets are received. 751 * 752 * @param[in] dev_sess 753 * @param[in] mode Current operation mode 754 * 755 * @return EOK If the operation was successfully completed 756 * 757 */ 758 int nic_broadcast_set_mode(async_sess_t *dev_sess, nic_broadcast_mode_t mode) 759 { 760 async_exch_t *exch = async_exchange_begin(dev_sess); 761 int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 762 NIC_BROADCAST_SET_MODE, mode); 763 async_exchange_end(exch); 764 765 return rc; 766 } 767 768 /** Determine if defective (erroneous) packets are received. 769 * 770 * @param[in] dev_sess 771 * @param[out] mode Bitmask specifying allowed errors 772 * 773 * @return EOK If the operation was successfully completed 774 * 775 */ 776 int nic_defective_get_mode(async_sess_t *dev_sess, uint32_t *mode) 777 { 778 assert(mode); 779 780 sysarg_t _mode; 781 782 async_exch_t *exch = async_exchange_begin(dev_sess); 783 int rc = async_req_1_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 784 NIC_DEFECTIVE_GET_MODE, &_mode); 785 async_exchange_end(exch); 786 787 *mode = (uint32_t) _mode; 788 789 return rc; 790 } 791 792 /** Set whether defective (erroneous) packets are received. 793 * 794 * @param[in] dev_sess 795 * @param[out] mode Bitmask specifying allowed errors 796 * 797 * @return EOK If the operation was successfully completed 798 * 799 */ 800 int nic_defective_set_mode(async_sess_t *dev_sess, uint32_t mode) 801 { 802 async_exch_t *exch = async_exchange_begin(dev_sess); 803 int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 804 NIC_DEFECTIVE_SET_MODE, mode); 805 async_exchange_end(exch); 806 807 return rc; 808 } 809 810 /** Retrieve the currently blocked source MAC addresses. 811 * 812 * @param[in] dev_sess 813 * @param[in] max_count Maximal number of addresses that could 814 * be written into the list buffer. 815 * @param[out] address_list Buffer for the list (array). Can be NULL. 816 * @param[out] address_count Number of addresses in the list before 817 * possible truncation due to the max_count. 818 * 819 * @return EOK If the operation was successfully completed 820 * 821 */ 822 int nic_blocked_sources_get(async_sess_t *dev_sess, size_t max_count, 823 nic_address_t *address_list, size_t *address_count) 824 { 825 if (!address_list) 826 max_count = 0; 827 828 async_exch_t *exch = async_exchange_begin(dev_sess); 829 830 sysarg_t ac; 831 int rc = async_req_2_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 832 NIC_BLOCKED_SOURCES_GET, max_count, &ac); 833 if (rc != EOK) { 834 async_exchange_end(exch); 835 return rc; 836 } 837 838 if (address_count) 839 *address_count = (size_t) ac; 840 841 if ((max_count) && (ac)) 842 rc = async_data_read_start(exch, address_list, 843 max_count * sizeof(nic_address_t)); 844 845 async_exchange_end(exch); 846 return rc; 847 } 848 849 /** Set which source MACs are blocked 850 * 851 * @param[in] dev_sess 852 * @param[in] address_list The list of addresses. Can be NULL. 853 * @param[in] address_count Number of addresses in the list. 854 * 855 * @return EOK If the operation was successfully completed 856 * 857 */ 858 int nic_blocked_sources_set(async_sess_t *dev_sess, 859 const nic_address_t *address_list, size_t address_count) 860 { 861 if (address_list == NULL) 862 address_count = 0; 863 864 async_exch_t *exch = async_exchange_begin(dev_sess); 865 866 aid_t message_id = async_send_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 867 NIC_BLOCKED_SOURCES_SET, address_count, NULL); 868 869 int rc; 870 if (address_count) 871 rc = async_data_write_start(exch, address_list, 872 address_count * sizeof(nic_address_t)); 873 else 874 rc = EOK; 875 876 async_exchange_end(exch); 877 878 sysarg_t res; 879 async_wait_for(message_id, &res); 880 881 if (rc != EOK) 882 return rc; 883 884 return (int) res; 885 } 886 887 /** Request current VLAN filtering mask. 888 * 889 * @param[in] dev_sess 890 * @param[out] stats Structure with the statistics 891 * 892 * @return EOK If the operation was successfully completed 893 * 894 */ 895 int nic_vlan_get_mask(async_sess_t *dev_sess, nic_vlan_mask_t *mask) 896 { 897 assert(mask); 898 899 async_exch_t *exch = async_exchange_begin(dev_sess); 900 int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 901 NIC_VLAN_GET_MASK); 902 if (rc != EOK) { 903 async_exchange_end(exch); 904 return rc; 905 } 906 907 rc = async_data_read_start(exch, mask, sizeof(nic_vlan_mask_t)); 908 async_exchange_end(exch); 909 910 return rc; 911 } 912 913 /** Set the mask used for VLAN filtering. 914 * 915 * If NULL, VLAN filtering is disabled. 916 * 917 * @param[in] dev_sess 918 * @param[in] mask Pointer to mask structure or NULL to disable. 919 * 920 * @return EOK If the operation was successfully completed 921 * 922 */ 923 int nic_vlan_set_mask(async_sess_t *dev_sess, const nic_vlan_mask_t *mask) 924 { 925 async_exch_t *exch = async_exchange_begin(dev_sess); 926 927 aid_t message_id = async_send_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 928 NIC_VLAN_SET_MASK, mask != NULL, NULL); 929 930 int rc; 931 if (mask != NULL) 932 rc = async_data_write_start(exch, mask, sizeof(nic_vlan_mask_t)); 933 else 934 rc = EOK; 935 936 async_exchange_end(exch); 937 938 sysarg_t res; 939 async_wait_for(message_id, &res); 940 941 if (rc != EOK) 942 return rc; 943 944 return (int) res; 945 } 946 947 /** Set VLAN (802.1q) tag. 948 * 949 * Set whether the tag is to be signaled in offload info and 950 * if the tag should be stripped from received frames and added 951 * to sent frames automatically. Not every combination of add 952 * and strip must be supported. 953 * 954 * @param[in] dev_sess 955 * @param[in] tag VLAN priority (top 3 bits) and 956 * the VLAN tag (bottom 12 bits) 957 * @param[in] add Add the VLAN tag automatically (boolean) 958 * @param[in] strip Strip the VLAN tag automatically (boolean) 959 * 960 * @return EOK If the operation was successfully completed 961 * 962 */ 963 int nic_vlan_set_tag(async_sess_t *dev_sess, uint16_t tag, bool add, bool strip) 964 { 965 async_exch_t *exch = async_exchange_begin(dev_sess); 966 int rc = async_req_4_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 967 NIC_VLAN_SET_TAG, (sysarg_t) tag, (sysarg_t) add, (sysarg_t) strip); 968 async_exchange_end(exch); 969 970 return rc; 971 } 972 973 /** Add new Wake-On-LAN virtue. 974 * 975 * @param[in] dev_sess 976 * @param[in] type Type of the virtue 977 * @param[in] data Data required for this virtue 978 * (depends on type) 979 * @param[in] length Length of the data 980 * @param[out] id Identifier of the new virtue 981 * 982 * @return EOK If the operation was successfully completed 983 * 984 */ 985 int nic_wol_virtue_add(async_sess_t *dev_sess, nic_wv_type_t type, 986 const void *data, size_t length, nic_wv_id_t *id) 987 { 988 assert(id); 989 990 bool send_data = ((data != NULL) && (length != 0)); 991 async_exch_t *exch = async_exchange_begin(dev_sess); 992 993 ipc_call_t result; 994 aid_t message_id = async_send_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 995 NIC_WOL_VIRTUE_ADD, (sysarg_t) type, send_data, &result); 996 997 sysarg_t res; 998 if (send_data) { 999 int rc = async_data_write_start(exch, data, length); 1000 if (rc != EOK) { 1001 async_exchange_end(exch); 1002 async_wait_for(message_id, &res); 1003 return rc; 1004 } 1005 } 1006 1007 async_exchange_end(exch); 1008 async_wait_for(message_id, &res); 1009 1010 *id = IPC_GET_ARG1(result); 1011 return (int) res; 1012 } 1013 1014 /** Remove Wake-On-LAN virtue. 1015 * 1016 * @param[in] dev_sess 1017 * @param[in] id Virtue identifier 1018 * 1019 * @return EOK If the operation was successfully completed 1020 * 1021 */ 1022 int nic_wol_virtue_remove(async_sess_t *dev_sess, nic_wv_id_t id) 1023 { 1024 async_exch_t *exch = async_exchange_begin(dev_sess); 1025 int rc = async_req_2_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 1026 NIC_WOL_VIRTUE_REMOVE, (sysarg_t) id); 1027 async_exchange_end(exch); 1028 1029 return rc; 1030 } 1031 1032 /** Get information about virtue. 1033 * 1034 * @param[in] dev_sess 1035 * @param[in] id Virtue identifier 1036 * @param[out] type Type of the filter. Can be NULL. 1037 * @param[out] max_length Size of the data buffer. 1038 * @param[out] data Buffer for data used when the 1039 * virtue was created. Can be NULL. 1040 * @param[out] length Length of the data. Can be NULL. 1041 * 1042 * @return EOK If the operation was successfully completed 1043 * 1044 */ 1045 int nic_wol_virtue_probe(async_sess_t *dev_sess, nic_wv_id_t id, 1046 nic_wv_type_t *type, size_t max_length, void *data, size_t *length) 1047 { 1048 sysarg_t _type; 1049 sysarg_t _length; 1050 1051 if (data == NULL) 1052 max_length = 0; 1053 1054 async_exch_t *exch = async_exchange_begin(dev_sess); 1055 1056 int rc = async_req_3_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 1057 NIC_WOL_VIRTUE_PROBE, (sysarg_t) id, max_length, 1058 &_type, &_length); 1059 if (rc != EOK) { 1060 async_exchange_end(exch); 1061 return rc; 1062 } 1063 1064 if (type) 1065 *type = _type; 1066 1067 if (length) 1068 *length = _length; 1069 1070 if ((max_length) && (_length != 0)) 1071 rc = async_data_read_start(exch, data, max_length); 1072 1073 async_exchange_end(exch); 1074 return rc; 1075 } 1076 1077 /** Get a list of all virtues of the specified type. 1078 * 1079 * When NIC_WV_NONE is specified as the virtue type the function 1080 * lists virtues of all types. 1081 * 1082 * @param[in] dev_sess 1083 * @param[in] type Type of the virtues 1084 * @param[in] max_count Maximum number of ids that can be 1085 * written into the list buffer. 1086 * @param[out] id_list Buffer for to the list of virtue ids. 1087 * Can be NULL. 1088 * @param[out] id_count Number of virtue identifiers in the list 1089 * before possible truncation due to the 1090 * max_count. Can be NULL. 1091 * 1092 * @return EOK If the operation was successfully completed 1093 * 1094 */ 1095 int nic_wol_virtue_list(async_sess_t *dev_sess, nic_wv_type_t type, 1096 size_t max_count, nic_wv_id_t *id_list, size_t *id_count) 1097 { 1098 if (id_list == NULL) 1099 max_count = 0; 1100 1101 async_exch_t *exch = async_exchange_begin(dev_sess); 1102 1103 sysarg_t count; 1104 int rc = async_req_3_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 1105 NIC_WOL_VIRTUE_LIST, (sysarg_t) type, max_count, &count); 1106 1107 if (id_count) 1108 *id_count = (size_t) count; 1109 1110 if ((rc != EOK) || (!max_count)) { 1111 async_exchange_end(exch); 1112 return rc; 1113 } 1114 1115 rc = async_data_read_start(exch, id_list, 1116 max_count * sizeof(nic_wv_id_t)); 1117 1118 async_exchange_end(exch); 1119 return rc; 1120 } 1121 1122 /** Get number of virtues that can be enabled yet. 1123 * 1124 * Count: < 0 => Virtue of this type can be never used 1125 * = 0 => No more virtues can be enabled 1126 * > 0 => #count virtues can be enabled yet 1127 * 1128 * @param[in] dev_sess 1129 * @param[in] type Virtue type 1130 * @param[out] count Number of virtues 1131 * 1132 * @return EOK If the operation was successfully completed 1133 * 1134 */ 1135 int nic_wol_virtue_get_caps(async_sess_t *dev_sess, nic_wv_type_t type, 1136 int *count) 1137 { 1138 assert(count); 1139 1140 sysarg_t _count; 1141 1142 async_exch_t *exch = async_exchange_begin(dev_sess); 1143 int rc = async_req_2_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 1144 NIC_WOL_VIRTUE_GET_CAPS, (sysarg_t) type, &_count); 1145 async_exchange_end(exch); 1146 1147 *count = (int) _count; 1148 return rc; 1149 } 1150 1151 /** Load the frame that issued the wakeup. 1152 * 1153 * The NIC can support only matched_type, only part of the frame 1154 * can be available or not at all. Sometimes even the type can be 1155 * uncertain -- in this case the matched_type contains NIC_WV_NONE. 1156 * 1157 * Frame_length can be greater than max_length, but at most max_length 1158 * bytes will be copied into the frame buffer. 1159 * 1160 * Note: Only the type of the filter can be detected, not the concrete 1161 * filter, because the driver is probably not running when the wakeup 1162 * is issued. 1163 * 1164 * @param[in] dev_sess 1165 * @param[out] matched_type Type of the filter that issued wakeup. 1166 * @param[in] max_length Size of the buffer 1167 * @param[out] frame Buffer for the frame. Can be NULL. 1168 * @param[out] frame_length Length of the stored frame. Can be NULL. 1169 * 1170 * @return EOK If the operation was successfully completed 1171 * 1172 */ 1173 int nic_wol_load_info(async_sess_t *dev_sess, nic_wv_type_t *matched_type, 1174 size_t max_length, uint8_t *frame, size_t *frame_length) 1175 { 1176 assert(matched_type); 1177 1178 sysarg_t _matched_type; 1179 sysarg_t _frame_length; 1180 1181 if (frame == NULL) 1182 max_length = 0; 1183 1184 async_exch_t *exch = async_exchange_begin(dev_sess); 1185 1186 int rc = async_req_2_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 1187 NIC_WOL_LOAD_INFO, max_length, &_matched_type, &_frame_length); 1188 if (rc != EOK) { 1189 async_exchange_end(exch); 1190 return rc; 1191 } 1192 1193 *matched_type = (nic_wv_type_t) _matched_type; 1194 if (frame_length) 1195 *frame_length = (size_t) _frame_length; 1196 1197 if ((max_length != 0) && (_frame_length != 0)) 1198 rc = async_data_read_start(exch, frame, max_length); 1199 1200 async_exchange_end(exch); 1201 return rc; 1202 } 1203 1204 /** Probe supported options and current setting of offload computations 1205 * 1206 * @param[in] dev_sess 1207 * @param[out] supported Supported offload options 1208 * @param[out] active Currently active offload options 1209 * 1210 * @return EOK If the operation was successfully completed 1211 * 1212 */ 1213 int nic_offload_probe(async_sess_t *dev_sess, uint32_t *supported, 1214 uint32_t *active) 1215 { 1216 assert(supported); 1217 assert(active); 1218 1219 sysarg_t _supported; 1220 sysarg_t _active; 1221 1222 async_exch_t *exch = async_exchange_begin(dev_sess); 1223 int rc = async_req_1_2(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 1224 NIC_OFFLOAD_PROBE, &_supported, &_active); 1225 async_exchange_end(exch); 1226 1227 *supported = (uint32_t) _supported; 1228 *active = (uint32_t) _active; 1229 return rc; 1230 } 1231 1232 /** Set which offload computations can be performed on the NIC. 1233 * 1234 * @param[in] dev_sess 1235 * @param[in] mask Mask for the options (only those set here will be set) 1236 * @param[in] active Which options should be enabled and which disabled 1237 * 1238 * @return EOK If the operation was successfully completed 1239 * 1240 */ 1241 int nic_offload_set(async_sess_t *dev_sess, uint32_t mask, uint32_t active) 1242 { 1243 async_exch_t *exch = async_exchange_begin(dev_sess); 1244 int rc = async_req_3_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 1245 NIC_AUTONEG_RESTART, (sysarg_t) mask, (sysarg_t) active); 1246 async_exchange_end(exch); 1247 1248 return rc; 1249 } 1250 1251 /** Query the current interrupt/poll mode of the NIC 1252 * 1253 * @param[in] dev_sess 1254 * @param[out] mode Current poll mode 1255 * @param[out] period Period used in periodic polling. 1256 * Can be NULL. 1257 * 1258 * @return EOK If the operation was successfully completed 1259 * 1260 */ 1261 int nic_poll_get_mode(async_sess_t *dev_sess, nic_poll_mode_t *mode, 1262 struct timeval *period) 1263 { 1264 assert(mode); 1265 1266 sysarg_t _mode; 1267 1268 async_exch_t *exch = async_exchange_begin(dev_sess); 1269 1270 int rc = async_req_2_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 1271 NIC_POLL_GET_MODE, period != NULL, &_mode); 1272 if (rc != EOK) { 1273 async_exchange_end(exch); 1274 return rc; 1275 } 1276 1277 *mode = (nic_poll_mode_t) _mode; 1278 1279 if (period != NULL) 1280 rc = async_data_read_start(exch, period, sizeof(struct timeval)); 1281 1282 async_exchange_end(exch); 1283 return rc; 1284 } 1285 1286 /** Set the interrupt/poll mode of the NIC. 1287 * 1288 * @param[in] dev_sess 1289 * @param[in] mode New poll mode 1290 * @param[in] period Period used in periodic polling. Can be NULL. 1291 * 1292 * @return EOK If the operation was successfully completed 1293 * 1294 */ 1295 int nic_poll_set_mode(async_sess_t *dev_sess, nic_poll_mode_t mode, 1296 const struct timeval *period) 1297 { 1298 async_exch_t *exch = async_exchange_begin(dev_sess); 1299 1300 aid_t message_id = async_send_3(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 1301 NIC_POLL_SET_MODE, (sysarg_t) mode, period != NULL, NULL); 1302 1303 int rc; 1304 if (period) 1305 rc = async_data_write_start(exch, period, sizeof(struct timeval)); 1306 else 1307 rc = EOK; 1308 1309 async_exchange_end(exch); 1310 1311 sysarg_t res; 1312 async_wait_for(message_id, &res); 1313 1314 if (rc != EOK) 1315 return rc; 1316 1317 return (int) res; 1318 } 1319 1320 /** Request the driver to poll the NIC. 1321 * 1322 * @param[in] dev_sess 1323 * 1324 * @return EOK If the operation was successfully completed 1325 * 1326 */ 1327 int nic_poll_now(async_sess_t *dev_sess) 1328 { 1329 async_exch_t *exch = async_exchange_begin(dev_sess); 1330 int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), NIC_POLL_NOW); 1331 async_exchange_end(exch); 1332 1333 return rc; 1334 } 43 1335 44 1336 static void remote_nic_send_frame(ddf_fun_t *dev, void *iface, … … 1198 2490 * 1199 2491 */ 1200 static remote_iface_func_ptr_t remote_nic_iface_ops[] = {1201 &remote_nic_send_frame,1202 &remote_nic_callback_create,1203 &remote_nic_get_state,1204 &remote_nic_set_state,1205 &remote_nic_get_address,1206 &remote_nic_set_address,1207 &remote_nic_get_stats,1208 &remote_nic_get_device_info,1209 &remote_nic_get_cable_state,1210 &remote_nic_get_operation_mode,1211 &remote_nic_set_operation_mode,1212 &remote_nic_autoneg_enable,1213 &remote_nic_autoneg_disable,1214 &remote_nic_autoneg_probe,1215 &remote_nic_autoneg_restart,1216 &remote_nic_get_pause,1217 &remote_nic_set_pause,1218 &remote_nic_unicast_get_mode,1219 &remote_nic_unicast_set_mode,1220 &remote_nic_multicast_get_mode,1221 &remote_nic_multicast_set_mode,1222 &remote_nic_broadcast_get_mode,1223 &remote_nic_broadcast_set_mode,1224 &remote_nic_defective_get_mode,1225 &remote_nic_defective_set_mode,1226 &remote_nic_blocked_sources_get,1227 &remote_nic_blocked_sources_set,1228 &remote_nic_vlan_get_mask,1229 &remote_nic_vlan_set_mask,1230 &remote_nic_vlan_set_tag,1231 &remote_nic_wol_virtue_add,1232 &remote_nic_wol_virtue_remove,1233 &remote_nic_wol_virtue_probe,1234 &remote_nic_wol_virtue_list,1235 &remote_nic_wol_virtue_get_caps,1236 &remote_nic_wol_load_info,1237 &remote_nic_offload_probe,1238 &remote_nic_offload_set,1239 &remote_nic_poll_get_mode,1240 &remote_nic_poll_set_mode,1241 &remote_nic_poll_now2492 static const remote_iface_func_ptr_t remote_nic_iface_ops[] = { 2493 [NIC_SEND_MESSAGE] = remote_nic_send_frame, 2494 [NIC_CALLBACK_CREATE] = remote_nic_callback_create, 2495 [NIC_GET_STATE] = remote_nic_get_state, 2496 [NIC_SET_STATE] = remote_nic_set_state, 2497 [NIC_GET_ADDRESS] = remote_nic_get_address, 2498 [NIC_SET_ADDRESS] = remote_nic_set_address, 2499 [NIC_GET_STATS] = remote_nic_get_stats, 2500 [NIC_GET_DEVICE_INFO] = remote_nic_get_device_info, 2501 [NIC_GET_CABLE_STATE] = remote_nic_get_cable_state, 2502 [NIC_GET_OPERATION_MODE] = remote_nic_get_operation_mode, 2503 [NIC_SET_OPERATION_MODE] = remote_nic_set_operation_mode, 2504 [NIC_AUTONEG_ENABLE] = remote_nic_autoneg_enable, 2505 [NIC_AUTONEG_DISABLE] = remote_nic_autoneg_disable, 2506 [NIC_AUTONEG_PROBE] = remote_nic_autoneg_probe, 2507 [NIC_AUTONEG_RESTART] = remote_nic_autoneg_restart, 2508 [NIC_GET_PAUSE] = remote_nic_get_pause, 2509 [NIC_SET_PAUSE] = remote_nic_set_pause, 2510 [NIC_UNICAST_GET_MODE] = remote_nic_unicast_get_mode, 2511 [NIC_UNICAST_SET_MODE] = remote_nic_unicast_set_mode, 2512 [NIC_MULTICAST_GET_MODE] = remote_nic_multicast_get_mode, 2513 [NIC_MULTICAST_SET_MODE] = remote_nic_multicast_set_mode, 2514 [NIC_BROADCAST_GET_MODE] = remote_nic_broadcast_get_mode, 2515 [NIC_BROADCAST_SET_MODE] = remote_nic_broadcast_set_mode, 2516 [NIC_DEFECTIVE_GET_MODE] = remote_nic_defective_get_mode, 2517 [NIC_DEFECTIVE_SET_MODE] = remote_nic_defective_set_mode, 2518 [NIC_BLOCKED_SOURCES_GET] = remote_nic_blocked_sources_get, 2519 [NIC_BLOCKED_SOURCES_SET] = remote_nic_blocked_sources_set, 2520 [NIC_VLAN_GET_MASK] = remote_nic_vlan_get_mask, 2521 [NIC_VLAN_SET_MASK] = remote_nic_vlan_set_mask, 2522 [NIC_VLAN_SET_TAG] = remote_nic_vlan_set_tag, 2523 [NIC_WOL_VIRTUE_ADD] = remote_nic_wol_virtue_add, 2524 [NIC_WOL_VIRTUE_REMOVE] = remote_nic_wol_virtue_remove, 2525 [NIC_WOL_VIRTUE_PROBE] = remote_nic_wol_virtue_probe, 2526 [NIC_WOL_VIRTUE_LIST] = remote_nic_wol_virtue_list, 2527 [NIC_WOL_VIRTUE_GET_CAPS] = remote_nic_wol_virtue_get_caps, 2528 [NIC_WOL_LOAD_INFO] = remote_nic_wol_load_info, 2529 [NIC_OFFLOAD_PROBE] = remote_nic_offload_probe, 2530 [NIC_OFFLOAD_SET] = remote_nic_offload_set, 2531 [NIC_POLL_GET_MODE] = remote_nic_poll_get_mode, 2532 [NIC_POLL_SET_MODE] = remote_nic_poll_set_mode, 2533 [NIC_POLL_NOW] = remote_nic_poll_now 1242 2534 }; 1243 2535 … … 1248 2540 * 1249 2541 */ 1250 remote_iface_t remote_nic_iface = { 1251 .method_count = sizeof(remote_nic_iface_ops) / 1252 sizeof(remote_iface_func_ptr_t), 2542 const remote_iface_t remote_nic_iface = { 2543 .method_count = ARRAY_SIZE(remote_nic_iface_ops), 1253 2544 .methods = remote_nic_iface_ops 1254 2545 }; -
uspace/lib/drv/generic/remote_pci.c
r2f591127 r5828554 36 36 #include <async.h> 37 37 #include <errno.h> 38 #include <macros.h> 38 39 39 40 #include "pci_dev_iface.h" 40 41 #include "ddf/driver.h" 42 43 typedef enum { 44 IPC_M_CONFIG_SPACE_READ_8, 45 IPC_M_CONFIG_SPACE_READ_16, 46 IPC_M_CONFIG_SPACE_READ_32, 47 48 IPC_M_CONFIG_SPACE_WRITE_8, 49 IPC_M_CONFIG_SPACE_WRITE_16, 50 IPC_M_CONFIG_SPACE_WRITE_32 51 } pci_dev_iface_funcs_t; 52 53 int pci_config_space_read_8(async_sess_t *sess, uint32_t address, uint8_t *val) 54 { 55 sysarg_t res = 0; 56 57 async_exch_t *exch = async_exchange_begin(sess); 58 int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE), 59 IPC_M_CONFIG_SPACE_READ_8, address, &res); 60 async_exchange_end(exch); 61 62 *val = (uint8_t) res; 63 return rc; 64 } 65 66 int pci_config_space_read_16(async_sess_t *sess, uint32_t address, 67 uint16_t *val) 68 { 69 sysarg_t res = 0; 70 71 async_exch_t *exch = async_exchange_begin(sess); 72 int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE), 73 IPC_M_CONFIG_SPACE_READ_16, address, &res); 74 async_exchange_end(exch); 75 76 *val = (uint16_t) res; 77 return rc; 78 } 79 80 int pci_config_space_read_32(async_sess_t *sess, uint32_t address, 81 uint32_t *val) 82 { 83 sysarg_t res = 0; 84 85 async_exch_t *exch = async_exchange_begin(sess); 86 int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE), 87 IPC_M_CONFIG_SPACE_READ_32, address, &res); 88 async_exchange_end(exch); 89 90 *val = (uint32_t) res; 91 return rc; 92 } 93 94 int pci_config_space_write_8(async_sess_t *sess, uint32_t address, uint8_t val) 95 { 96 async_exch_t *exch = async_exchange_begin(sess); 97 int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE), 98 IPC_M_CONFIG_SPACE_WRITE_8, address, val); 99 async_exchange_end(exch); 100 101 return rc; 102 } 103 104 int pci_config_space_write_16(async_sess_t *sess, uint32_t address, 105 uint16_t val) 106 { 107 async_exch_t *exch = async_exchange_begin(sess); 108 int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE), 109 IPC_M_CONFIG_SPACE_WRITE_16, address, val); 110 async_exchange_end(exch); 111 112 return rc; 113 } 114 115 int pci_config_space_write_32(async_sess_t *sess, uint32_t address, 116 uint32_t val) 117 { 118 async_exch_t *exch = async_exchange_begin(sess); 119 int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE), 120 IPC_M_CONFIG_SPACE_WRITE_32, address, val); 121 async_exchange_end(exch); 122 123 return rc; 124 } 41 125 42 126 static void remote_config_space_read_8(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); … … 49 133 50 134 /** Remote USB interface operations. */ 51 static remote_iface_func_ptr_t remote_pci_iface_ops [] = {52 remote_config_space_read_8,53 remote_config_space_read_16,54 remote_config_space_read_32,55 56 remote_config_space_write_8,57 remote_config_space_write_16,58 remote_config_space_write_32135 static const remote_iface_func_ptr_t remote_pci_iface_ops [] = { 136 [IPC_M_CONFIG_SPACE_READ_8] = remote_config_space_read_8, 137 [IPC_M_CONFIG_SPACE_READ_16] = remote_config_space_read_16, 138 [IPC_M_CONFIG_SPACE_READ_32] = remote_config_space_read_32, 139 140 [IPC_M_CONFIG_SPACE_WRITE_8] = remote_config_space_write_8, 141 [IPC_M_CONFIG_SPACE_WRITE_16] = remote_config_space_write_16, 142 [IPC_M_CONFIG_SPACE_WRITE_32] = remote_config_space_write_32 59 143 }; 60 144 61 145 /** Remote USB interface structure. 62 146 */ 63 remote_iface_t remote_pci_iface = { 64 .method_count = sizeof(remote_pci_iface_ops) / 65 sizeof(remote_pci_iface_ops[0]), 147 const remote_iface_t remote_pci_iface = { 148 .method_count = ARRAY_SIZE(remote_pci_iface_ops), 66 149 .methods = remote_pci_iface_ops 67 150 }; -
uspace/lib/drv/generic/remote_pio_window.c
r2f591127 r5828554 35 35 #include <async.h> 36 36 #include <errno.h> 37 #include <macros.h> 37 38 38 39 #include "ops/pio_window.h" … … 42 43 ipc_call_t *); 43 44 44 static remote_iface_func_ptr_t remote_pio_window_iface_ops [] = {45 static const remote_iface_func_ptr_t remote_pio_window_iface_ops [] = { 45 46 [PIO_WINDOW_GET] = &remote_pio_window_get 46 47 }; 47 48 48 remote_iface_t remote_pio_window_iface = { 49 .method_count = sizeof(remote_pio_window_iface_ops) / 50 sizeof(remote_iface_func_ptr_t), 49 const remote_iface_t remote_pio_window_iface = { 50 .method_count = ARRAY_SIZE(remote_pio_window_iface_ops), 51 51 .methods = remote_pio_window_iface_ops 52 52 }; -
uspace/lib/drv/generic/remote_usb.c
r2f591127 r5828554 36 36 #include <async.h> 37 37 #include <errno.h> 38 #include <macros.h> 38 39 39 40 #include "usb_iface.h" … … 107 108 108 109 /** Remote USB interface operations. */ 109 static remote_iface_func_ptr_t remote_usb_iface_ops [] = {110 static const remote_iface_func_ptr_t remote_usb_iface_ops [] = { 110 111 [IPC_M_USB_GET_MY_ADDRESS] = remote_usb_get_my_address, 111 112 [IPC_M_USB_GET_MY_INTERFACE] = remote_usb_get_my_interface, … … 115 116 /** Remote USB interface structure. 116 117 */ 117 remote_iface_t remote_usb_iface = { 118 .method_count = sizeof(remote_usb_iface_ops) / 119 sizeof(remote_usb_iface_ops[0]), 118 const remote_iface_t remote_usb_iface = { 119 .method_count = ARRAY_SIZE(remote_usb_iface_ops), 120 120 .methods = remote_usb_iface_ops 121 121 }; -
uspace/lib/drv/generic/remote_usbhc.c
r2f591127 r5828554 37 37 #include <errno.h> 38 38 #include <assert.h> 39 #include <macros.h> 39 40 40 41 #include "usbhc_iface.h" … … 334 335 335 336 /** Remote USB host controller interface operations. */ 336 static remote_iface_func_ptr_t remote_usbhc_iface_ops[] = {337 static const remote_iface_func_ptr_t remote_usbhc_iface_ops[] = { 337 338 [IPC_M_USBHC_REQUEST_ADDRESS] = remote_usbhc_request_address, 338 339 [IPC_M_USBHC_RELEASE_ADDRESS] = remote_usbhc_release_address, … … 349 350 /** Remote USB host controller interface structure. 350 351 */ 351 remote_iface_t remote_usbhc_iface = { 352 .method_count = sizeof(remote_usbhc_iface_ops) / 353 sizeof(remote_usbhc_iface_ops[0]), 352 const remote_iface_t remote_usbhc_iface = { 353 .method_count = ARRAY_SIZE(remote_usbhc_iface_ops), 354 354 .methods = remote_usbhc_iface_ops 355 355 }; -
uspace/lib/drv/generic/remote_usbhid.c
r2f591127 r5828554 37 37 #include <assert.h> 38 38 #include <stdio.h> 39 #include <macros.h> 39 40 40 41 #include "usbhid_iface.h" 41 42 #include "ddf/driver.h" 43 44 /** IPC methods for USB HID device interface. */ 45 typedef enum { 46 /** Get number of events reported in single burst. 47 * Parameters: none 48 * Answer: 49 * - Size of one report in bytes. 50 */ 51 IPC_M_USBHID_GET_EVENT_LENGTH, 52 /** Get single event from the HID device. 53 * The word single refers to set of individual events that were 54 * available at particular point in time. 55 * Parameters: 56 * - flags 57 * The call is followed by data read expecting two concatenated 58 * arrays. 59 * Answer: 60 * - EOK - events returned 61 * - EAGAIN - no event ready (only in non-blocking mode) 62 * 63 * It is okay if the client requests less data. Extra data must 64 * be truncated by the driver. 65 * 66 * @todo Change this comment. 67 */ 68 IPC_M_USBHID_GET_EVENT, 69 70 /** Get the size of the report descriptor from the HID device. 71 * 72 * Parameters: 73 * - none 74 * Answer: 75 * - EOK - method is implemented (expected always) 76 * Parameters of the answer: 77 * - Size of the report in bytes. 78 */ 79 IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, 80 81 /** Get the report descriptor from the HID device. 82 * 83 * Parameters: 84 * - none 85 * The call is followed by data read expecting the descriptor itself. 86 * Answer: 87 * - EOK - report descriptor returned. 88 */ 89 IPC_M_USBHID_GET_REPORT_DESCRIPTOR 90 } usbhid_iface_funcs_t; 91 92 /** Ask for event array length. 93 * 94 * @param dev_sess Session to DDF device providing USB HID interface. 95 * 96 * @return Number of usages returned or negative error code. 97 * 98 */ 99 int usbhid_dev_get_event_length(async_sess_t *dev_sess, size_t *size) 100 { 101 if (!dev_sess) 102 return EINVAL; 103 104 async_exch_t *exch = async_exchange_begin(dev_sess); 105 106 sysarg_t len; 107 int rc = async_req_1_1(exch, DEV_IFACE_ID(USBHID_DEV_IFACE), 108 IPC_M_USBHID_GET_EVENT_LENGTH, &len); 109 110 async_exchange_end(exch); 111 112 if (rc == EOK) { 113 if (size != NULL) 114 *size = (size_t) len; 115 } 116 117 return rc; 118 } 119 120 /** Request for next event from HID device. 121 * 122 * @param[in] dev_sess Session to DDF device providing USB HID interface. 123 * @param[out] usage_pages Where to store usage pages. 124 * @param[out] usages Where to store usages (actual data). 125 * @param[in] usage_count Length of @p usage_pages and @p usages buffer 126 * (in items, not bytes). 127 * @param[out] actual_usage_count Number of usages actually returned by the 128 * device driver. 129 * @param[in] flags Flags (see USBHID_IFACE_FLAG_*). 130 * 131 * @return Error code. 132 * 133 */ 134 int usbhid_dev_get_event(async_sess_t *dev_sess, uint8_t *buf, 135 size_t size, size_t *actual_size, int *event_nr, unsigned int flags) 136 { 137 if (!dev_sess) 138 return EINVAL; 139 140 if (buf == NULL) 141 return ENOMEM; 142 143 if (size == 0) 144 return EINVAL; 145 146 size_t buffer_size = size; 147 uint8_t *buffer = malloc(buffer_size); 148 if (buffer == NULL) 149 return ENOMEM; 150 151 async_exch_t *exch = async_exchange_begin(dev_sess); 152 153 ipc_call_t opening_request_call; 154 aid_t opening_request = async_send_2(exch, 155 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_EVENT, 156 flags, &opening_request_call); 157 158 if (opening_request == 0) { 159 async_exchange_end(exch); 160 free(buffer); 161 return ENOMEM; 162 } 163 164 ipc_call_t data_request_call; 165 aid_t data_request = async_data_read(exch, buffer, buffer_size, 166 &data_request_call); 167 168 async_exchange_end(exch); 169 170 if (data_request == 0) { 171 async_forget(opening_request); 172 free(buffer); 173 return ENOMEM; 174 } 175 176 sysarg_t data_request_rc; 177 sysarg_t opening_request_rc; 178 async_wait_for(data_request, &data_request_rc); 179 async_wait_for(opening_request, &opening_request_rc); 180 181 if (data_request_rc != EOK) { 182 /* Prefer return code of the opening request. */ 183 if (opening_request_rc != EOK) 184 return (int) opening_request_rc; 185 else 186 return (int) data_request_rc; 187 } 188 189 if (opening_request_rc != EOK) 190 return (int) opening_request_rc; 191 192 size_t act_size = IPC_GET_ARG2(data_request_call); 193 194 /* Copy the individual items. */ 195 memcpy(buf, buffer, act_size); 196 197 if (actual_size != NULL) 198 *actual_size = act_size; 199 200 if (event_nr != NULL) 201 *event_nr = IPC_GET_ARG1(opening_request_call); 202 203 return EOK; 204 } 205 206 int usbhid_dev_get_report_descriptor_length(async_sess_t *dev_sess, 207 size_t *size) 208 { 209 if (!dev_sess) 210 return EINVAL; 211 212 async_exch_t *exch = async_exchange_begin(dev_sess); 213 214 sysarg_t arg_size; 215 int rc = async_req_1_1(exch, DEV_IFACE_ID(USBHID_DEV_IFACE), 216 IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, &arg_size); 217 218 async_exchange_end(exch); 219 220 if (rc == EOK) { 221 if (size != NULL) 222 *size = (size_t) arg_size; 223 } 224 225 return rc; 226 } 227 228 int usbhid_dev_get_report_descriptor(async_sess_t *dev_sess, uint8_t *buf, 229 size_t size, size_t *actual_size) 230 { 231 if (!dev_sess) 232 return EINVAL; 233 234 if (buf == NULL) 235 return ENOMEM; 236 237 if (size == 0) 238 return EINVAL; 239 240 async_exch_t *exch = async_exchange_begin(dev_sess); 241 242 aid_t opening_request = async_send_1(exch, 243 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_REPORT_DESCRIPTOR, 244 NULL); 245 if (opening_request == 0) { 246 async_exchange_end(exch); 247 return ENOMEM; 248 } 249 250 ipc_call_t data_request_call; 251 aid_t data_request = async_data_read(exch, buf, size, 252 &data_request_call); 253 254 async_exchange_end(exch); 255 256 if (data_request == 0) { 257 async_forget(opening_request); 258 return ENOMEM; 259 } 260 261 sysarg_t data_request_rc; 262 sysarg_t opening_request_rc; 263 async_wait_for(data_request, &data_request_rc); 264 async_wait_for(opening_request, &opening_request_rc); 265 266 if (data_request_rc != EOK) { 267 /* Prefer return code of the opening request. */ 268 if (opening_request_rc != EOK) 269 return (int) opening_request_rc; 270 else 271 return (int) data_request_rc; 272 } 273 274 if (opening_request_rc != EOK) 275 return (int) opening_request_rc; 276 277 size_t act_size = IPC_GET_ARG2(data_request_call); 278 279 if (actual_size != NULL) 280 *actual_size = act_size; 281 282 return EOK; 283 } 42 284 43 285 static void remote_usbhid_get_event_length(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); … … 48 290 49 291 /** Remote USB HID interface operations. */ 50 static remote_iface_func_ptr_t remote_usbhid_iface_ops [] = { 51 remote_usbhid_get_event_length, 52 remote_usbhid_get_event, 53 remote_usbhid_get_report_descriptor_length, 54 remote_usbhid_get_report_descriptor 292 static const remote_iface_func_ptr_t remote_usbhid_iface_ops [] = { 293 [IPC_M_USBHID_GET_EVENT_LENGTH] = remote_usbhid_get_event_length, 294 [IPC_M_USBHID_GET_EVENT] = remote_usbhid_get_event, 295 [IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH] = 296 remote_usbhid_get_report_descriptor_length, 297 [IPC_M_USBHID_GET_REPORT_DESCRIPTOR] = remote_usbhid_get_report_descriptor 55 298 }; 56 299 57 300 /** Remote USB HID interface structure. 58 301 */ 59 remote_iface_t remote_usbhid_iface = { 60 .method_count = sizeof(remote_usbhid_iface_ops) / 61 sizeof(remote_usbhid_iface_ops[0]), 302 const remote_iface_t remote_usbhid_iface = { 303 .method_count = ARRAY_SIZE(remote_usbhid_iface_ops), 62 304 .methods = remote_usbhid_iface_ops 63 305 }; -
uspace/lib/drv/include/ahci_iface.h
r2f591127 r5828554 41 41 #include <async.h> 42 42 43 extern async_sess_t* ahci_get_sess(devman_handle_t, char **); 44 45 extern int ahci_get_sata_device_name(async_sess_t *, size_t, char *); 46 extern int ahci_get_num_blocks(async_sess_t *, uint64_t *); 47 extern int ahci_get_block_size(async_sess_t *, size_t *); 48 extern int ahci_read_blocks(async_sess_t *, uint64_t, size_t, void *); 49 extern int ahci_write_blocks(async_sess_t *, uint64_t, size_t, void *); 50 43 51 /** AHCI device communication interface. */ 44 52 typedef struct { -
uspace/lib/drv/include/battery_iface.h
r2f591127 r5828554 33 33 */ 34 34 35 #ifndef LIB C_DEVICE_BATTERY_DEV_H_36 #define LIB C_DEVICE_BATTERY_DEV_H_35 #ifndef LIBDRV_BATTERY_IFACE_H_ 36 #define LIBDRV_BATTERY_IFACE_H_ 37 37 38 38 #include <async.h> -
uspace/lib/drv/include/char_dev_iface.h
r2f591127 r5828554 33 33 */ 34 34 35 #ifndef LIB C_DEVICE_CHAR_DEV_H_36 #define LIB C_DEVICE_CHAR_DEV_H_35 #ifndef LIBDRV_CHAR_DEV_IFACE_H_ 36 #define LIBDRV_CHAR_DEV_IFACE_H_ 37 37 38 38 #include <async.h> -
uspace/lib/drv/include/ddf/driver.h
r2f591127 r5828554 108 108 const char *name; 109 109 /** Generic device driver operations */ 110 driver_ops_t *driver_ops;110 const driver_ops_t *driver_ops; 111 111 } driver_t; 112 112 … … 116 116 #endif 117 117 118 extern int ddf_driver_main( driver_t *);118 extern int ddf_driver_main(const driver_t *); 119 119 120 120 extern void *ddf_dev_data_alloc(ddf_dev_t *, size_t); -
uspace/lib/drv/include/ddf/interrupt.h
r2f591127 r5828554 67 67 extern void interrupt_init(void); 68 68 extern int register_interrupt_handler(ddf_dev_t *, int, interrupt_handler_t *, 69 irq_code_t *);69 const irq_code_t *); 70 70 extern int unregister_interrupt_handler(ddf_dev_t *, int); 71 71 -
uspace/lib/drv/include/dev_iface.h
r2f591127 r5828554 55 55 56 56 typedef struct { 57 size_t method_count;58 remote_iface_func_ptr_t *methods;57 const size_t method_count; 58 const remote_iface_func_ptr_t *methods; 59 59 } remote_iface_t; 60 60 61 61 typedef struct { 62 remote_iface_t *ifaces[DEV_IFACE_COUNT];62 const remote_iface_t *ifaces[DEV_IFACE_COUNT]; 63 63 } iface_dipatch_table_t; 64 64 65 extern remote_iface_t *get_remote_iface(int);66 extern remote_iface_func_ptr_t get_remote_method( remote_iface_t *, sysarg_t);65 extern const remote_iface_t *get_remote_iface(int); 66 extern remote_iface_func_ptr_t get_remote_method(const remote_iface_t *, sysarg_t); 67 67 68 68 -
uspace/lib/drv/include/graph_iface.h
r2f591127 r5828554 38 38 #include <async.h> 39 39 40 typedef enum {41 GRAPH_DEV_CONNECT = 042 } graph_dev_method_t;43 44 40 extern int graph_dev_connect(async_sess_t *); 45 41 -
uspace/lib/drv/include/nic_iface.h
r2f591127 r5828554 33 33 */ 34 34 35 #ifndef LIB C_DEVICE_NIC_H_36 #define LIB C_DEVICE_NIC_H_35 #ifndef LIBDRV_NIC_IFACE_H_ 36 #define LIBDRV_NIC_IFACE_H_ 37 37 38 38 #include <async.h> … … 40 40 #include <ipc/common.h> 41 41 42 typedef enum {43 NIC_SEND_MESSAGE = 0,44 NIC_CALLBACK_CREATE,45 NIC_GET_STATE,46 NIC_SET_STATE,47 NIC_GET_ADDRESS,48 NIC_SET_ADDRESS,49 NIC_GET_STATS,50 NIC_GET_DEVICE_INFO,51 NIC_GET_CABLE_STATE,52 NIC_GET_OPERATION_MODE,53 NIC_SET_OPERATION_MODE,54 NIC_AUTONEG_ENABLE,55 NIC_AUTONEG_DISABLE,56 NIC_AUTONEG_PROBE,57 NIC_AUTONEG_RESTART,58 NIC_GET_PAUSE,59 NIC_SET_PAUSE,60 NIC_UNICAST_GET_MODE,61 NIC_UNICAST_SET_MODE,62 NIC_MULTICAST_GET_MODE,63 NIC_MULTICAST_SET_MODE,64 NIC_BROADCAST_GET_MODE,65 NIC_BROADCAST_SET_MODE,66 NIC_DEFECTIVE_GET_MODE,67 NIC_DEFECTIVE_SET_MODE,68 NIC_BLOCKED_SOURCES_GET,69 NIC_BLOCKED_SOURCES_SET,70 NIC_VLAN_GET_MASK,71 NIC_VLAN_SET_MASK,72 NIC_VLAN_SET_TAG,73 NIC_WOL_VIRTUE_ADD,74 NIC_WOL_VIRTUE_REMOVE,75 NIC_WOL_VIRTUE_PROBE,76 NIC_WOL_VIRTUE_LIST,77 NIC_WOL_VIRTUE_GET_CAPS,78 NIC_WOL_LOAD_INFO,79 NIC_OFFLOAD_PROBE,80 NIC_OFFLOAD_SET,81 NIC_POLL_GET_MODE,82 NIC_POLL_SET_MODE,83 NIC_POLL_NOW84 } nic_funcs_t;85 42 86 43 typedef enum { -
uspace/lib/drv/include/ops/battery_dev.h
r2f591127 r5828554 37 37 38 38 #include "../ddf/driver.h" 39 #include " device/battery_dev.h"39 #include "battery_iface.h" 40 40 41 41 typedef struct { -
uspace/lib/drv/include/pci_dev_iface.h
r2f591127 r5828554 40 40 #include "ddf/driver.h" 41 41 42 typedef enum { 43 IPC_M_CONFIG_SPACE_READ_8, 44 IPC_M_CONFIG_SPACE_READ_16, 45 IPC_M_CONFIG_SPACE_READ_32, 42 #define PCI_DEVICE_ID 0x02 46 43 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; 44 extern int pci_config_space_read_8(async_sess_t *, uint32_t, uint8_t *); 45 extern int pci_config_space_read_16(async_sess_t *, uint32_t, uint16_t *); 46 extern int pci_config_space_read_32(async_sess_t *, uint32_t, uint32_t *); 47 48 extern int pci_config_space_write_8(async_sess_t *, uint32_t, uint8_t); 49 extern int pci_config_space_write_16(async_sess_t *, uint32_t, uint16_t); 50 extern int pci_config_space_write_32(async_sess_t *, uint32_t, uint32_t); 51 51 52 52 /** PCI device communication interface. */ -
uspace/lib/drv/include/usbhid_iface.h
r2f591127 r5828554 40 40 #include <usb/usb.h> 41 41 42 /** IPC methods for USB HID device interface. */ 43 typedef enum { 44 /** Get number of events reported in single burst. 45 * Parameters: none 46 * Answer: 47 * - Size of one report in bytes. 48 */ 49 IPC_M_USBHID_GET_EVENT_LENGTH, 50 /** Get single event from the HID device. 51 * The word single refers to set of individual events that were 52 * available at particular point in time. 53 * Parameters: 54 * - flags 55 * The call is followed by data read expecting two concatenated 56 * arrays. 57 * Answer: 58 * - EOK - events returned 59 * - EAGAIN - no event ready (only in non-blocking mode) 60 * 61 * It is okay if the client requests less data. Extra data must 62 * be truncated by the driver. 63 * 64 * @todo Change this comment. 65 */ 66 IPC_M_USBHID_GET_EVENT, 67 68 /** Get the size of the report descriptor from the HID device. 69 * 70 * Parameters: 71 * - none 72 * Answer: 73 * - EOK - method is implemented (expected always) 74 * Parameters of the answer: 75 * - Size of the report in bytes. 76 */ 77 IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, 78 79 /** Get the report descriptor from the HID device. 80 * 81 * Parameters: 82 * - none 83 * The call is followed by data read expecting the descriptor itself. 84 * Answer: 85 * - EOK - report descriptor returned. 86 */ 87 IPC_M_USBHID_GET_REPORT_DESCRIPTOR 88 } usbhid_iface_funcs_t; 89 90 /** USB HID interface flag - return immediately if no data are available. */ 91 #define USBHID_IFACE_FLAG_NON_BLOCKING (1 << 0) 42 extern int usbhid_dev_get_event_length(async_sess_t *, size_t *); 43 extern int usbhid_dev_get_event(async_sess_t *, uint8_t *, size_t, size_t *, 44 int *, unsigned int); 45 extern int usbhid_dev_get_report_descriptor_length(async_sess_t *, size_t *); 46 extern int usbhid_dev_get_report_descriptor(async_sess_t *, uint8_t *, size_t, 47 size_t *); 92 48 93 49 /** USB HID device communication interface. */ -
uspace/lib/gui/Makefile
r2f591127 r5828554 34 34 35 35 SOURCES = \ 36 common.c \ 36 37 button.c \ 37 38 canvas.c \ -
uspace/lib/gui/button.c
r2f591127 r5828554 36 36 #include <str.h> 37 37 #include <malloc.h> 38 39 38 #include <drawctx.h> 40 39 #include <surface.h> 41 40 #include "common.h" 42 41 #include "window.h" 43 42 #include "button.h" 44 43 45 static void paint_internal(widget_t *w) 46 { 47 button_t *btn = (button_t *) w; 48 44 static pixel_t color_highlight = PIXEL(255, 255, 255, 255); 45 static pixel_t color_shadow = PIXEL(255, 85, 85, 85); 46 47 static void paint_internal(widget_t *widget) 48 { 49 button_t *btn = (button_t *) widget; 50 49 51 surface_t *surface = window_claim(btn->widget.window); 50 if (!surface) {52 if (!surface) 51 53 window_yield(btn->widget.window); 54 55 source_t source; 56 source_init(&source); 57 58 drawctx_t drawctx; 59 drawctx_init(&drawctx, surface); 60 61 drawctx_set_source(&drawctx, &btn->background); 62 drawctx_transfer(&drawctx, widget->hpos, widget->vpos, 63 widget->width, widget->height); 64 65 if ((widget->width >= 8) && (widget->height >= 8)) { 66 drawctx_set_source(&drawctx, &source); 67 draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3, 68 widget->width - 6, widget->height - 6, color_highlight, 69 color_shadow); 70 71 drawctx_set_source(&drawctx, &btn->foreground); 72 drawctx_transfer(&drawctx, widget->hpos + 4, widget->vpos + 4, 73 widget->width - 8, widget->height - 8); 52 74 } 53 54 drawctx_t drawctx; 55 56 drawctx_init(&drawctx, surface); 57 drawctx_set_source(&drawctx, &btn->foreground); 58 drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height); 59 60 if (w->width >= 6 && w->height >= 6) { 61 drawctx_set_source(&drawctx, &btn->background); 62 drawctx_transfer(&drawctx, 63 w->hpos + 3, w->vpos + 3, w->width - 6, w->height - 6); 64 } 65 75 66 76 sysarg_t cpt_width; 67 77 sysarg_t cpt_height; 68 78 font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height); 69 if (w->width >= cpt_width && w->height >= cpt_height) { 70 drawctx_set_source(&drawctx, &btn->foreground); 79 80 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { 81 sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos; 82 sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos; 83 84 drawctx_set_source(&drawctx, &btn->text); 71 85 drawctx_set_font(&drawctx, &btn->font); 72 sysarg_t x = ((w->width - cpt_width) / 2) + w->hpos; 73 sysarg_t y = ((w->height - cpt_height) / 2) + w->vpos; 74 if (btn->caption) { 86 87 if (btn->caption) 75 88 drawctx_print(&drawctx, btn->caption, x, y); 76 }77 89 } 78 90 79 91 window_yield(btn->widget.window); 80 92 } … … 90 102 { 91 103 button_t *btn = (button_t *) widget; 92 104 93 105 deinit_button(btn); 94 95 106 free(btn); 96 107 } … … 117 128 { 118 129 button_t *btn = (button_t *) widget; 119 if (event.key == KC_ENTER && event.type == KEY_PRESS) { 130 131 if (event.key == KC_ENTER && event.type == KEY_PRESS) 120 132 sig_send(&btn->clicked, NULL); 121 }122 133 } 123 134 … … 126 137 button_t *btn = (button_t *) widget; 127 138 widget->window->focus = widget; 128 139 129 140 // TODO make the click logic more robust (mouse grabbing, mouse moves) 130 141 if (event.btn_num == 1) { 131 if (event.type == POS_RELEASE) {142 if (event.type == POS_RELEASE) 132 143 sig_send(&btn->clicked, NULL); 133 }134 144 } 135 145 } 136 146 137 bool init_button(button_t *btn, widget_t *parent, 138 const char *caption, uint16_t points, pixel_t background, pixel_t foreground)147 bool init_button(button_t *btn, widget_t *parent, const char *caption, 148 uint16_t points, pixel_t background, pixel_t foreground, pixel_t text) 139 149 { 140 150 widget_init(&btn->widget, parent); 141 151 142 152 btn->widget.destroy = button_destroy; 143 153 btn->widget.reconfigure = button_reconfigure; … … 146 156 btn->widget.handle_keyboard_event = button_handle_keyboard_event; 147 157 btn->widget.handle_position_event = button_handle_position_event; 148 158 149 159 source_init(&btn->background); 150 160 source_set_color(&btn->background, background); 161 151 162 source_init(&btn->foreground); 152 163 source_set_color(&btn->foreground, foreground); 153 154 if (caption == NULL) { 164 165 source_init(&btn->text); 166 source_set_color(&btn->text, text); 167 168 if (caption == NULL) 155 169 btn->caption = NULL; 156 } else {170 else 157 171 btn->caption = str_dup(caption); 158 }172 159 173 font_init(&btn->font, FONT_DECODER_EMBEDDED, NULL, points); 160 174 161 175 sysarg_t cpt_width; 162 176 sysarg_t cpt_height; 163 177 font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height); 164 btn->widget.width_min = cpt_width + 8;165 btn->widget.height_min = cpt_height + 8;166 btn->widget.width_ideal = cpt_width + 28;167 btn->widget.height_ideal = cpt_height + 8;168 178 btn->widget.width_min = cpt_width + 10; 179 btn->widget.height_min = cpt_height + 10; 180 btn->widget.width_ideal = cpt_width + 30; 181 btn->widget.height_ideal = cpt_height + 10; 182 169 183 return true; 170 184 } 171 185 172 button_t *create_button(widget_t *parent, 173 const char *caption, uint16_t points, pixel_t background, pixel_t foreground)186 button_t *create_button(widget_t *parent, const char *caption, uint16_t points, 187 pixel_t background, pixel_t foreground, pixel_t text) 174 188 { 175 189 button_t *btn = (button_t *) malloc(sizeof(button_t)); 176 if (!btn) {190 if (!btn) 177 191 return NULL; 178 }179 180 if (init_button(btn, parent, caption, points, background, foreground)) {192 193 if (init_button(btn, parent, caption, points, background, foreground, 194 text)) 181 195 return btn; 182 } else { 183 free(btn); 184 return NULL; 185 } 196 197 free(btn); 198 return NULL; 186 199 } 187 200 -
uspace/lib/gui/button.h
r2f591127 r5828554 50 50 source_t background; 51 51 source_t foreground; 52 source_t text; 52 53 char *caption; 53 54 font_t font; … … 55 56 } button_t; 56 57 57 extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t, pixel_t); 58 extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t, pixel_t); 58 extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t, 59 pixel_t, pixel_t); 60 extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t, 61 pixel_t, pixel_t); 59 62 extern void deinit_button(button_t *); 60 63 -
uspace/lib/gui/canvas.c
r2f591127 r5828554 112 112 static void canvas_handle_position_event(widget_t *widget, pos_event_t event) 113 113 { 114 /* No-op */ 114 canvas_t *canvas = (canvas_t *) widget; 115 pos_event_t tevent; 116 117 tevent = event; 118 tevent.hpos -= widget->hpos; 119 tevent.vpos -= widget->vpos; 120 121 sig_send(&canvas->position_event, &tevent); 115 122 } 116 123 -
uspace/lib/gui/canvas.h
r2f591127 r5828554 50 50 surface_t *surface; 51 51 signal_t keyboard_event; 52 signal_t position_event; 52 53 } canvas_t; 53 54 -
uspace/lib/gui/connection.c
r2f591127 r5828554 210 210 link_initialize(&event->link); 211 211 event->type = ET_SIGNAL_EVENT; 212 event->data.sig .object = (sysarg_t) cur->widget;213 event->data.sig .slot = (sysarg_t) cur->slot;214 event->data.sig .argument = (sysarg_t) data_copy;212 event->data.signal.object = (sysarg_t) cur->widget; 213 event->data.signal.slot = (sysarg_t) cur->slot; 214 event->data.signal.argument = (sysarg_t) data_copy; 215 215 prodcons_produce(&cur->widget->window->events, &event->link); 216 216 } else { -
uspace/lib/gui/label.c
r2f591127 r5828554 36 36 #include <str.h> 37 37 #include <malloc.h> 38 39 38 #include <drawctx.h> 40 39 #include <surface.h> 41 42 40 #include "window.h" 43 41 #include "label.h" 44 42 45 static void paint_internal(widget_t *w )43 static void paint_internal(widget_t *widget) 46 44 { 47 label_t *lbl = (label_t *) w ;45 label_t *lbl = (label_t *) widget; 48 46 49 47 surface_t *surface = window_claim(lbl->widget.window); 50 if (!surface) {48 if (!surface) 51 49 window_yield(lbl->widget.window); 52 } 53 50 54 51 drawctx_t drawctx; 55 56 52 drawctx_init(&drawctx, surface); 53 57 54 drawctx_set_source(&drawctx, &lbl->background); 58 drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, w->height); 59 55 drawctx_transfer(&drawctx, widget->hpos, widget->vpos, widget->width, 56 widget->height); 57 60 58 sysarg_t cpt_width; 61 59 sysarg_t cpt_height; 62 60 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 63 if (w->width >= cpt_width && w->height >= cpt_height) { 64 drawctx_set_source(&drawctx, &lbl->foreground); 61 62 if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) { 63 sysarg_t x = ((widget->width - cpt_width) / 2) + widget->hpos; 64 sysarg_t y = ((widget->height - cpt_height) / 2) + widget->vpos; 65 66 drawctx_set_source(&drawctx, &lbl->text); 65 67 drawctx_set_font(&drawctx, &lbl->font); 66 sysarg_t x = ((w->width - cpt_width) / 2) + w->hpos; 67 sysarg_t y = ((w->height - cpt_height) / 2) + w->vpos; 68 if (lbl->caption) { 68 69 if (lbl->caption) 69 70 drawctx_print(&drawctx, lbl->caption, x, y); 70 }71 71 } 72 72 73 73 window_yield(lbl->widget.window); 74 74 } … … 78 78 if (data != NULL) { 79 79 label_t *lbl = (label_t *) widget; 80 80 81 const char *new_caption = (const char *) data; 81 82 lbl->caption = str_dup(new_caption); 82 83 83 84 sysarg_t cpt_width; 84 85 sysarg_t cpt_height; 85 86 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 87 86 88 lbl->widget.width_min = cpt_width + 4; 87 89 lbl->widget.height_min = cpt_height + 4; 88 90 lbl->widget.width_ideal = lbl->widget.width_min; 89 91 lbl->widget.height_ideal = lbl->widget.height_min; 90 92 91 93 window_refresh(lbl->widget.window); 92 94 } … … 103 105 { 104 106 label_t *lbl = (label_t *) widget; 105 107 106 108 deinit_label(lbl); 107 108 109 free(lbl); 109 110 } … … 137 138 } 138 139 139 bool init_label(label_t *lbl, widget_t *parent, 140 const char *caption, uint16_t points, pixel_t background, pixel_t foreground)140 bool init_label(label_t *lbl, widget_t *parent, const char *caption, 141 uint16_t points, pixel_t background, pixel_t text) 141 142 { 142 143 widget_init(&lbl->widget, parent); 143 144 144 145 lbl->widget.destroy = label_destroy; 145 146 lbl->widget.reconfigure = label_reconfigure; … … 148 149 lbl->widget.handle_keyboard_event = label_handle_keyboard_event; 149 150 lbl->widget.handle_position_event = label_handle_position_event; 150 151 151 152 source_init(&lbl->background); 152 153 source_set_color(&lbl->background, background); 153 source_init(&lbl->foreground); 154 source_set_color(&lbl->foreground, foreground); 155 156 if (caption == NULL) { 154 155 source_init(&lbl->text); 156 source_set_color(&lbl->text, text); 157 158 if (caption == NULL) 157 159 lbl->caption = NULL; 158 } else {160 else 159 161 lbl->caption = str_dup(caption); 160 }162 161 163 font_init(&lbl->font, FONT_DECODER_EMBEDDED, NULL, points); 162 164 163 165 sysarg_t cpt_width; 164 166 sysarg_t cpt_height; 165 167 font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height); 168 166 169 lbl->widget.width_min = cpt_width + 4; 167 170 lbl->widget.height_min = cpt_height + 4; 168 171 lbl->widget.width_ideal = lbl->widget.width_min; 169 172 lbl->widget.height_ideal = lbl->widget.height_min; 170 173 171 174 lbl->rewrite = on_rewrite; 172 175 173 176 return true; 174 177 } 175 178 176 label_t *create_label(widget_t *parent, 177 const char *caption, uint16_t points, pixel_t background, pixel_t foreground)179 label_t *create_label(widget_t *parent, const char *caption, uint16_t points, 180 pixel_t background, pixel_t text) 178 181 { 179 182 label_t *lbl = (label_t *) malloc(sizeof(label_t)); 180 if (!lbl) {183 if (!lbl) 181 184 return NULL; 182 } 183 184 if (init_label(lbl, parent, caption, points, background, foreground)) { 185 186 if (init_label(lbl, parent, caption, points, background, text)) 185 187 return lbl; 186 } else { 187 free(lbl); 188 return NULL; 189 } 188 189 free(lbl); 190 return NULL; 190 191 } 191 192 192 193 /** @} 193 194 */ 194 -
uspace/lib/gui/label.h
r2f591127 r5828554 49 49 widget_t widget; 50 50 source_t background; 51 source_t foreground;51 source_t text; 52 52 char *caption; 53 53 font_t font; … … 55 55 } label_t; 56 56 57 extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t, pixel_t); 58 extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t, pixel_t); 57 extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t, 58 pixel_t); 59 extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t, 60 pixel_t); 59 61 extern void deinit_label(label_t *); 60 62 -
uspace/lib/gui/window.c
r2f591127 r5828554 56 56 #include <surface.h> 57 57 58 #include "common.h" 58 59 #include "connection.h" 59 60 #include "widget.h" 60 61 #include "window.h" 61 62 62 static sysarg_t border_thickness = 5; 63 static sysarg_t border_thickness = 4; 64 static sysarg_t bevel_thickness = 1; 63 65 static sysarg_t header_height = 20; 64 66 static sysarg_t header_min_width = 40; 65 static sysarg_t close_width = 20; 66 67 static pixel_t border_color = PIXEL(255, 0, 0, 0); 68 static pixel_t header_bg_focus_color = PIXEL(255, 88, 106, 196); 69 static pixel_t header_fg_focus_color = PIXEL(255, 255, 255, 255); 70 static pixel_t header_bg_unfocus_color = PIXEL(255, 12, 57, 92); 71 static pixel_t header_fg_unfocus_color = PIXEL(255, 255, 255, 255); 72 73 static void paint_internal(widget_t *w) 74 { 75 surface_t *surface = window_claim(w->window); 76 if (!surface) { 77 window_yield(w->window); 78 } 79 67 static sysarg_t close_thickness = 20; 68 69 static pixel_t color_highlight = PIXEL(255, 255, 255, 255); 70 static pixel_t color_shadow = PIXEL(255, 85, 85, 85); 71 static pixel_t color_surface = PIXEL(255, 186, 186, 186); 72 73 static pixel_t color_header_focus_highlight = PIXEL(255, 120, 145, 255); 74 static pixel_t color_header_focus_shadow = PIXEL(255, 40, 48, 89); 75 static pixel_t color_header_focus_surface = PIXEL(255, 88, 106, 196); 76 77 static pixel_t color_header_unfocus_highlight = PIXEL(255, 16, 78, 126); 78 static pixel_t color_header_unfocus_shadow = PIXEL(255, 5, 26, 42); 79 static pixel_t color_header_unfocus_surface = PIXEL(255, 12, 57, 92); 80 81 static pixel_t color_caption_focus = PIXEL(255, 255, 255, 255); 82 static pixel_t color_caption_unfocus = PIXEL(255, 207, 207, 207); 83 84 static void paint_internal(widget_t *widget) 85 { 86 surface_t *surface = window_claim(widget->window); 87 if (!surface) 88 window_yield(widget->window); 89 80 90 source_t source; 81 font_t font; 91 source_init(&source); 92 82 93 drawctx_t drawctx; 83 84 source_init(&source);85 font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);86 94 drawctx_init(&drawctx, surface); 87 95 drawctx_set_source(&drawctx, &source); 96 97 /* Window border outer bevel */ 98 99 draw_bevel(&drawctx, &source, widget->vpos, widget->hpos, 100 widget->width, widget->height, color_highlight, color_shadow); 101 102 /* Window border surface */ 103 104 source_set_color(&source, color_surface); 105 drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1, 106 widget->width - 2, 2); 107 drawctx_transfer(&drawctx, widget->hpos + 1, widget->vpos + 1, 108 2, widget->height - 2); 109 drawctx_transfer(&drawctx, widget->hpos + 1, 110 widget->vpos + widget->height - 3, widget->width - 2, 2); 111 drawctx_transfer(&drawctx, widget->hpos + widget->width - 3, 112 widget->vpos + 1, 2, widget->height - 4); 113 114 /* Window border inner bevel */ 115 116 draw_bevel(&drawctx, &source, widget->hpos + 3, widget->vpos + 3, 117 widget->width - 6, widget->height - 6, color_shadow, 118 color_highlight); 119 120 /* Header bevel */ 121 122 sysarg_t header_hpos = widget->hpos + border_thickness; 123 sysarg_t header_vpos = widget->vpos + border_thickness; 124 sysarg_t header_width = widget->width - 2 * border_thickness - 125 close_thickness; 126 127 draw_bevel(&drawctx, &source, header_hpos, header_vpos, 128 header_width, header_height, widget->window->is_focused ? 129 color_header_focus_highlight : color_header_unfocus_highlight, 130 widget->window->is_focused ? 131 color_header_focus_shadow : color_header_unfocus_shadow); 132 133 /* Header surface */ 134 135 source_set_color(&source, widget->window->is_focused ? 136 color_header_focus_surface : color_header_unfocus_surface); 137 drawctx_transfer(&drawctx, header_hpos + 1, header_vpos + 1, 138 header_width - 2, header_height - 2); 139 140 /* Close button bevel */ 141 142 sysarg_t close_hpos = widget->hpos + widget->width - 143 border_thickness - close_thickness; 144 sysarg_t close_vpos = widget->vpos + border_thickness; 145 146 draw_bevel(&drawctx, &source, close_hpos, close_vpos, 147 close_thickness, close_thickness, color_highlight, color_shadow); 148 149 /* Close button surface */ 150 151 source_set_color(&source, color_surface); 152 drawctx_transfer(&drawctx, close_hpos + 1, close_vpos + 1, 153 close_thickness - 2, close_thickness - 2); 154 155 /* Close button icon */ 156 157 draw_icon_cross(surface, close_hpos + 3, close_vpos + 3, 158 color_highlight, color_shadow); 159 160 /* Window caption */ 161 162 font_t font; 163 font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16); 164 88 165 drawctx_set_font(&drawctx, &font); 89 90 source_set_color(&source, border_color); 91 drawctx_transfer(&drawctx, w->hpos, w->vpos, border_thickness, w->height); 92 drawctx_transfer(&drawctx, w->hpos + w->width - border_thickness, 93 w->vpos, border_thickness, w->height); 94 drawctx_transfer(&drawctx, w->hpos, w->vpos, w->width, border_thickness); 95 drawctx_transfer(&drawctx, w->hpos, 96 w->vpos + w->height - border_thickness, w->width, border_thickness); 97 98 source_set_color(&source, 99 w->window->is_focused ? header_bg_focus_color : header_bg_unfocus_color); 100 drawctx_transfer(&drawctx, 101 w->hpos + border_thickness, w->vpos + border_thickness, 102 w->width - 2 * border_thickness, header_height); 103 166 source_set_color(&source, widget->window->is_focused ? 167 color_caption_focus : color_caption_unfocus); 168 104 169 sysarg_t cpt_width; 105 170 sysarg_t cpt_height; 106 font_get_box(&font, w->window->caption, &cpt_width, &cpt_height); 107 sysarg_t cls_width; 108 sysarg_t cls_height; 109 char cls_pict[] = "x"; 110 font_get_box(&font, cls_pict, &cls_width, &cls_height); 111 source_set_color(&source, 112 w->window->is_focused ? header_fg_focus_color : header_fg_unfocus_color); 113 sysarg_t cls_x = ((close_width - cls_width) / 2) + w->hpos + w->width - 114 border_thickness - close_width; 115 sysarg_t cls_y = ((header_height - cls_height) / 2) + w->vpos + border_thickness; 116 drawctx_print(&drawctx, cls_pict, cls_x, cls_y); 117 118 bool draw_title = (w->width >= 2 * border_thickness + close_width + cpt_width); 171 font_get_box(&font, widget->window->caption, &cpt_width, &cpt_height); 172 173 bool draw_title = 174 (widget->width >= 2 * border_thickness + 2 * bevel_thickness + 175 close_thickness + cpt_width); 119 176 if (draw_title) { 120 sysarg_t cpt_x = ((w->width - cpt_width) / 2) + w->hpos; 121 sysarg_t cpt_y = ((header_height - cpt_height) / 2) + w->vpos + border_thickness; 122 if (w->window->caption) { 123 drawctx_print(&drawctx, w->window->caption, cpt_x, cpt_y); 124 } 125 } 126 177 sysarg_t cpt_x = ((widget->width - cpt_width) / 2) + widget->hpos; 178 sysarg_t cpt_y = ((header_height - cpt_height) / 2) + 179 widget->vpos + border_thickness; 180 181 if (widget->window->caption) 182 drawctx_print(&drawctx, widget->window->caption, cpt_x, cpt_y); 183 } 184 127 185 font_release(&font); 128 window_yield(w ->window);186 window_yield(widget->window); 129 187 } 130 188 … … 138 196 if (widget->window->is_decorated) { 139 197 list_foreach(widget->children, link, widget_t, child) { 140 child->rearrange(child, 198 child->rearrange(child, 141 199 widget->hpos + border_thickness, 142 200 widget->vpos + border_thickness + header_height, … … 211 269 (event.vpos >= border_thickness) && 212 270 (event.vpos < border_thickness + header_height); 213 bool close = header && (event.hpos >= width - border_thickness - close_width); 271 bool close = (header) && 272 (event.hpos >= width - border_thickness - close_thickness); 214 273 215 274 if (top && left && allowed_button) { … … 292 351 } 293 352 294 static void handle_signal_event(window_t *win, sig _event_t event)353 static void handle_signal_event(window_t *win, signal_event_t event) 295 354 { 296 355 widget_t *widget = (widget_t *) event.object; … … 303 362 } 304 363 305 static void handle_resize(window_t *win, sysarg_t width, sysarg_t height) 306 { 307 int rc; 308 surface_t *old_surface; 309 surface_t *new_surface; 310 364 static void handle_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y, 365 sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags) 366 { 311 367 if (width < 2 * border_thickness + header_min_width) { 312 368 win_damage(win->osess, 0, 0, 0, 0); 313 369 return; 314 370 } 315 371 316 372 if (height < 2 * border_thickness + header_height) { 317 373 win_damage(win->osess, 0, 0, 0, 0); 318 374 return; 319 375 } 320 376 321 377 /* Allocate resources for new surface. */ 322 new_surface = surface_create(width, height, NULL, SURFACE_FLAG_SHARED); 323 if (!new_surface) { 378 surface_t *new_surface = surface_create(width, height, NULL, 379 SURFACE_FLAG_SHARED); 380 if (!new_surface) 324 381 return; 325 } 326 382 327 383 /* Switch new and old surface. */ 328 384 fibril_mutex_lock(&win->guard); 329 old_surface = win->surface;385 surface_t *old_surface = win->surface; 330 386 win->surface = new_surface; 331 387 fibril_mutex_unlock(&win->guard); 332 333 /* Let all widgets in the tree alter their position and size. Widgets might 334 * also paint themselves onto the new surface. */ 388 389 /* 390 * Let all widgets in the tree alter their position and size. 391 * Widgets might also paint themselves onto the new surface. 392 */ 335 393 win->root.rearrange(&win->root, 0, 0, width, height); 336 394 337 395 fibril_mutex_lock(&win->guard); 338 396 surface_reset_damaged_region(win->surface); 339 397 fibril_mutex_unlock(&win->guard); 340 398 341 399 /* Inform compositor about new surface. */ 342 rc = win_resize(win->osess,343 width, height, surface_direct_access(new_surface));344 400 int rc = win_resize(win->osess, offset_x, offset_y, width, height, 401 placement_flags, surface_direct_access(new_surface)); 402 345 403 if (rc != EOK) { 346 404 /* Rollback to old surface. Reverse all changes. */ 347 405 348 406 sysarg_t old_width = 0; 349 407 sysarg_t old_height = 0; 350 if (old_surface) {408 if (old_surface) 351 409 surface_get_resolution(old_surface, &old_width, &old_height); 352 } 353 410 354 411 fibril_mutex_lock(&win->guard); 355 412 new_surface = win->surface; 356 413 win->surface = old_surface; 357 414 fibril_mutex_unlock(&win->guard); 358 415 359 416 win->root.rearrange(&win->root, 0, 0, old_width, old_height); 360 417 … … 364 421 fibril_mutex_unlock(&win->guard); 365 422 } 366 423 367 424 surface_destroy(new_surface); 368 return; 369 } 370 371 /* Finally deallocate old surface. */ 372 if (old_surface) { 373 surface_destroy(old_surface); 425 } else { 426 /* Deallocate old surface. */ 427 if (old_surface) 428 surface_destroy(old_surface); 374 429 } 375 430 } … … 453 508 break; 454 509 case ET_SIGNAL_EVENT: 455 handle_signal_event(win, event->data.sig );510 handle_signal_event(win, event->data.signal); 456 511 break; 457 512 case ET_WINDOW_RESIZE: 458 handle_resize(win, event->data.rsz.width, event->data.rsz.height); 513 handle_resize(win, event->data.resize.offset_x, 514 event->data.resize.offset_y, event->data.resize.width, 515 event->data.resize.height, event->data.resize.placement_flags); 459 516 break; 460 517 case ET_WINDOW_FOCUS: … … 530 587 531 588 window_t *window_open(const char *winreg, bool is_main, bool is_decorated, 532 const char *caption, sysarg_t x_offset, sysarg_t y_offset) 533 { 534 int rc; 535 589 const char *caption) 590 { 536 591 window_t *win = (window_t *) malloc(sizeof(window_t)); 537 if (!win) {592 if (!win) 538 593 return NULL; 539 } 540 594 541 595 win->is_main = is_main; 542 596 win->is_decorated = is_decorated; … … 544 598 prodcons_initialize(&win->events); 545 599 fibril_mutex_initialize(&win->guard); 600 546 601 widget_init(&win->root, NULL); 547 602 win->root.window = win; … … 555 610 win->focus = NULL; 556 611 win->surface = NULL; 557 612 558 613 service_id_t reg_dsid; 559 async_sess_t *reg_sess; 560 561 rc = loc_service_get_id(winreg, ®_dsid, 0); 614 int rc = loc_service_get_id(winreg, ®_dsid, 0); 562 615 if (rc != EOK) { 563 616 free(win); 564 617 return NULL; 565 618 } 566 567 reg_sess = loc_service_connect(EXCHANGE_SERIALIZE, reg_dsid, 0); 619 620 async_sess_t *reg_sess = loc_service_connect(EXCHANGE_SERIALIZE, 621 reg_dsid, 0); 568 622 if (reg_sess == NULL) { 569 623 free(win); 570 624 return NULL; 571 625 } 572 626 573 627 service_id_t in_dsid; 574 628 service_id_t out_dsid; 575 576 rc = win_register(reg_sess, &in_dsid, &out_dsid, x_offset, y_offset); 629 rc = win_register(reg_sess, &in_dsid, &out_dsid); 577 630 async_hangup(reg_sess); 578 631 if (rc != EOK) { … … 580 633 return NULL; 581 634 } 582 635 583 636 win->osess = loc_service_connect(EXCHANGE_SERIALIZE, out_dsid, 0); 584 637 if (win->osess == NULL) { … … 586 639 return NULL; 587 640 } 588 641 589 642 win->isess = loc_service_connect(EXCHANGE_SERIALIZE, in_dsid, 0); 590 643 if (win->isess == NULL) { … … 593 646 return NULL; 594 647 } 595 596 if (caption == NULL) {648 649 if (caption == NULL) 597 650 win->caption = NULL; 598 } else {651 else 599 652 win->caption = str_dup(caption); 600 } 601 653 602 654 return win; 603 655 } 604 656 605 void window_resize(window_t *win, sysarg_t width, sysarg_t height) 657 void window_resize(window_t *win, sysarg_t offset_x, sysarg_t offset_y, 658 sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags) 606 659 { 607 660 window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t)); … … 609 662 link_initialize(&event->link); 610 663 event->type = ET_WINDOW_RESIZE; 611 event->data.rsz.width = width; 612 event->data.rsz.height = height; 664 event->data.resize.offset_x = offset_x; 665 event->data.resize.offset_y = offset_y; 666 event->data.resize.width = width; 667 event->data.resize.height = height; 668 event->data.resize.placement_flags = placement_flags; 613 669 prodcons_produce(&win->events, &event->link); 614 670 } -
uspace/lib/gui/window.h
r2f591127 r5828554 66 66 * If the window is declared as main, its closure causes termination of the 67 67 * whole application. Note that opened window does not have any surface yet. */ 68 extern window_t *window_open(const char *, bool, bool, const char *, sysarg_t, 69 sysarg_t); 68 extern window_t *window_open(const char *, bool, bool, const char *); 70 69 71 70 /** … … 74 73 * and to paint themselves on the new surface (top-bottom order). Should be 75 74 * called also after opening new window to obtain surface. */ 76 extern void window_resize(window_t *, sysarg_t, sysarg_t); 75 extern void window_resize(window_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 76 window_placement_flags_t); 77 77 78 78 /** -
uspace/lib/nic/Makefile
r2f591127 r5828554 30 30 LIBRARY = libnic 31 31 EXTRA_CFLAGS += -DLIBNIC_INTERNAL -Iinclude -I$(LIBDRV_PREFIX)/include 32 LIBS = $(LIBDRV_PREFIX)/libdrv.a 32 33 33 34 SOURCES = \ -
uspace/lib/nic/src/nic_ev.c
r2f591127 r5828554 37 37 38 38 #include <async.h> 39 #include < device/nic.h>39 #include <nic_iface.h> 40 40 #include <errno.h> 41 41 #include "nic_ev.h" -
uspace/lib/posix/Makefile
r2f591127 r5828554 60 60 source/getopt.c \ 61 61 source/locale.c \ 62 source/math.c \63 62 source/pthread/condvar.c \ 64 63 source/pthread/keys.c \ -
uspace/lib/posix/include/posix/float.h
r2f591127 r5828554 59 59 #undef DBL_EPSILON 60 60 #define DBL_EPSILON __DBL_EPSILON__ 61 #undef LDBL_EPSILON 62 #define LDBL_EPSILON __LDBL_EPSILON__ 61 63 #undef FLT_RADIX 62 64 #define FLT_RADIX __FLT_RADIX__ … … 69 71 #undef FLT_MANT_DIG 70 72 #define FLT_MANT_DIG __FLT_MANT_DIG__ 73 #undef LDBL_MIN 74 #define LDBL_MIN __LDBL_MIN__ 75 #undef LDBL_MAX 76 #define LDBL_MAX __LDBL_MAX__ 71 77 #undef LDBL_MANT_DIG 72 78 #define LDBL_MANT_DIG __LDBL_MANT_DIG__ -
uspace/lib/posix/include/posix/math.h
r2f591127 r5828554 36 36 #define POSIX_MATH_H_ 37 37 38 #ifndef __POSIX_DEF__ 39 #define __POSIX_DEF__(x) x 40 #endif 41 42 #ifdef __GNUC__ 43 #define HUGE_VAL (__builtin_huge_val()) 44 #endif 45 46 /* Normalization Functions */ 47 extern double __POSIX_DEF__(ldexp)(double x, int exp); 48 extern double __POSIX_DEF__(frexp)(double num, int *exp); 49 50 double __POSIX_DEF__(fabs)(double x); 51 double __POSIX_DEF__(floor)(double x); 52 double __POSIX_DEF__(modf)(double x, double *iptr); 53 double __POSIX_DEF__(fmod)(double x, double y); 54 double __POSIX_DEF__(pow)(double x, double y); 55 double __POSIX_DEF__(exp)(double x); 56 double __POSIX_DEF__(sqrt)(double x); 57 double __POSIX_DEF__(log)(double x); 58 double __POSIX_DEF__(sin)(double x); 59 double __POSIX_DEF__(cos)(double x); 60 double __POSIX_DEF__(atan2)(double y, double x); 38 #include "libc/math.h" 61 39 62 40 #endif /* POSIX_MATH_H_ */ -
uspace/lib/posix/include/posix/setjmp.h
r2f591127 r5828554 27 27 */ 28 28 29 /** @addtogroup lib c29 /** @addtogroup libposix 30 30 * @{ 31 31 */ 32 32 33 #include <bitops.h> 34 35 int __popcountsi2(int a) 36 { 37 int bits = 0; 38 for (unsigned int i = 0; i < sizeof(a) * 8; i++) { 39 if (((a >> i) & 1) != 0) { 40 bits++; 41 } 42 } 43 return bits; 44 } 45 33 /* 34 * Just a pass-through to libc setjmp. 35 */ 36 #include "libc/setjmp.h" 46 37 47 38 /** @} -
uspace/lib/posix/include/posix/stdlib.h
r2f591127 r5828554 56 56 #define _Exit exit 57 57 extern int __POSIX_DEF__(atexit)(void (*func)(void)); 58 extern void exit(int status) ;58 extern void exit(int status) __attribute__((noreturn)); 59 59 extern void abort(void) __attribute__((noreturn)); 60 60 -
uspace/lib/softfloat/softfloat.c
r2f591127 r5828554 1265 1265 } 1266 1266 1267 float __aeabi_d2f(double a) 1268 { 1269 return __truncdfsf2(a); 1270 } 1271 1272 double __aeabi_f2d(float a) 1273 { 1274 return __extendsfdf2(a); 1275 } 1276 1277 1267 1278 float __aeabi_i2f(int i) 1268 1279 { … … 1285 1296 } 1286 1297 1298 double __aeabi_l2d(long long i) 1299 { 1300 return __floattidf(i); 1301 } 1302 1303 float __aeabi_l2f(long long i) 1304 { 1305 return __floattisf(i); 1306 } 1307 1308 float __aeabi_ul2f(unsigned long long u) 1309 { 1310 return __floatuntisf(u); 1311 } 1312 1287 1313 int __aeabi_f2iz(float a) 1288 1314 { … … 1305 1331 } 1306 1332 1333 long long __aeabi_d2lz(double a) 1334 { 1335 return __fixdfti(a); 1336 } 1337 1307 1338 int __aeabi_fcmpge(float a, float b) 1308 1339 { … … 1339 1370 return __ltdf2(a, b); 1340 1371 } 1372 1373 int __aeabi_dcmple(double a, double b) 1374 { 1375 return __ledf2(a, b); 1376 } 1377 1341 1378 1342 1379 int __aeabi_dcmpeq(double a, double b) -
uspace/lib/softfloat/softfloat.h
r2f591127 r5828554 204 204 205 205 /* ARM EABI */ 206 extern float __aeabi_d2f(double); 207 extern double __aeabi_f2d(float); 206 208 extern float __aeabi_i2f(int); 207 209 extern float __aeabi_ui2f(int); 208 210 extern double __aeabi_i2d(int); 209 211 extern double __aeabi_ui2d(unsigned int); 212 extern double __aeabi_l2d(long long); 213 extern float __aeabi_l2f(long long); 214 extern float __aeabi_ul2f(unsigned long long); 210 215 extern unsigned int __aeabi_d2uiz(double); 216 extern long long __aeabi_d2lz(double); 211 217 212 218 extern int __aeabi_f2iz(float); … … 222 228 extern int __aeabi_dcmpgt(double, double); 223 229 extern int __aeabi_dcmplt(double, double); 230 extern int __aeabi_dcmple(double, double); 224 231 extern int __aeabi_dcmpeq(double, double); 225 232 -
uspace/lib/softint/Makefile
r2f591127 r5828554 35 35 36 36 SOURCES = \ 37 generic/bits.c \ 37 38 generic/comparison.c \ 38 39 generic/division.c \ -
uspace/lib/softint/generic/shift.c
r2f591127 r5828554 123 123 } 124 124 125 long long __aeabi_llsl(long long val, int shift) 126 { 127 return __ashldi3(val, shift); 128 } 129 125 130 /** @} 126 131 */ -
uspace/lib/softint/include/shift.h
r2f591127 r5828554 46 46 extern long long __lshrdi3(long long, int); 47 47 48 49 /* ARM EABI */ 50 extern long long __aeabi_llsl(long long, int); 51 48 52 #endif 49 53 -
uspace/lib/usbhid/Makefile
r2f591127 r5828554 37 37 SOURCES = \ 38 38 src/hiddescriptor.c \ 39 src/hidiface.c \40 39 src/hidparser.c \ 41 40 src/hidpath.c \
Note:
See TracChangeset
for help on using the changeset viewer.
